forked from penguin86/luna-tracker
Compare commits
14 Commits
3e64da2e2e
...
bottle_tim
| Author | SHA1 | Date | |
|---|---|---|---|
| 4f0416e1c1 | |||
| 8c2fcaaef5 | |||
| 01907d7c4e | |||
| 3a3dc2faf4 | |||
| 2518118759 | |||
| d8b67531db | |||
| 0a424e8807 | |||
| 8adacd3bfe | |||
| 508c14ff6e | |||
| 7d67a2e33b | |||
| a0dc023941 | |||
| 6759956461 | |||
| c521a3373f | |||
| 1ad5f31b32 |
@@ -86,7 +86,6 @@ class MainActivity : AppCompatActivity() {
|
||||
recyclerView = findViewById(R.id.list_events)
|
||||
recyclerView.setLayoutManager(LinearLayoutManager(applicationContext))
|
||||
|
||||
// set defaults
|
||||
populateHeaderMenu()
|
||||
|
||||
// Set listeners
|
||||
@@ -109,9 +108,13 @@ class MainActivity : AppCompatActivity() {
|
||||
loadLogbookList()
|
||||
}
|
||||
findViewById<View>(R.id.button_sync).setOnClickListener {
|
||||
if (logbook != null) {
|
||||
loadLogbook(logbook!!.name)
|
||||
} else {
|
||||
loadLogbookList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setListAdapter(items: ArrayList<LunaEvent>) {
|
||||
val adapter = LunaEventRecyclerAdapter(this, items)
|
||||
@@ -139,7 +142,6 @@ class MainActivity : AppCompatActivity() {
|
||||
populateHeaderMenu()
|
||||
}
|
||||
|
||||
// populate action rows
|
||||
private fun populateHeaderMenu() {
|
||||
val settingsRepository = LocalSettingsRepository(this)
|
||||
val dynamicMenu = settingsRepository.loadDynamicMenu()
|
||||
@@ -185,7 +187,7 @@ class MainActivity : AppCompatActivity() {
|
||||
fun show(vararg tvs: TextView) {
|
||||
for (tv in tvs) {
|
||||
val type = sortedEventTypes[showCounter]
|
||||
tv.text = LunaEvent.getTypeEmoji(applicationContext, type)
|
||||
tv.text = LunaEvent.getHeaderEmoji(applicationContext, type)
|
||||
tv.setOnClickListener { showCreateDialog(type) }
|
||||
tv.visibility = View.VISIBLE
|
||||
// show parent row
|
||||
@@ -262,7 +264,7 @@ class MainActivity : AppCompatActivity() {
|
||||
fun askBabyBottleContent(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
||||
val d = AlertDialog.Builder(this)
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_bottle, null)
|
||||
d.setTitle(event.getTypeDescription(this))
|
||||
d.setTitle(event.getDialogTitle(this))
|
||||
d.setMessage(event.getDialogMessage(this))
|
||||
d.setView(dialogView)
|
||||
|
||||
@@ -304,7 +306,7 @@ class MainActivity : AppCompatActivity() {
|
||||
// Show number picker dialog
|
||||
val d = AlertDialog.Builder(this)
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_weight, null)
|
||||
d.setTitle(event.getTypeDescription(this))
|
||||
d.setTitle(event.getDialogTitle(this))
|
||||
d.setMessage(event.getDialogMessage(this))
|
||||
d.setView(dialogView)
|
||||
|
||||
@@ -348,7 +350,7 @@ class MainActivity : AppCompatActivity() {
|
||||
// Show number picker dialog
|
||||
val d = AlertDialog.Builder(this)
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_temperature, null)
|
||||
d.setTitle(event.getTypeDescription(this))
|
||||
d.setTitle(event.getDialogTitle(this))
|
||||
d.setMessage(event.getDialogMessage(this))
|
||||
d.setView(dialogView)
|
||||
|
||||
@@ -436,7 +438,7 @@ class MainActivity : AppCompatActivity() {
|
||||
fun askSleepValue(event: LunaEvent, onPositive: () -> Unit) {
|
||||
val d = AlertDialog.Builder(this)
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_duration, null)
|
||||
d.setTitle(event.getTypeDescription(this))
|
||||
d.setTitle(event.getDialogTitle(this))
|
||||
d.setMessage(event.getDialogMessage(this))
|
||||
d.setView(dialogView)
|
||||
|
||||
@@ -452,8 +454,8 @@ class MainActivity : AppCompatActivity() {
|
||||
var duration = event.quantity
|
||||
|
||||
fun isValidTime(timeSeconds: Long, durationSeconds: Int): Boolean {
|
||||
val now = Calendar.getInstance().time.time / 1000
|
||||
return (timeSeconds + durationSeconds) <= now && durationSeconds < (12 * 60 * 60)
|
||||
val now = System.currentTimeMillis() / 1000
|
||||
return (timeSeconds + durationSeconds) <= now && durationSeconds < (24 * 60 * 60)
|
||||
}
|
||||
|
||||
val onDateChange = { time: Long ->
|
||||
@@ -486,7 +488,7 @@ class MainActivity : AppCompatActivity() {
|
||||
durationPlus5Button.setOnClickListener { adjust(5) }
|
||||
|
||||
durationNowButton.setOnClickListener {
|
||||
val now = Calendar.getInstance().time.time / 1000
|
||||
val now = System.currentTimeMillis() / 1000
|
||||
val start = pickedDateTime.time.time / 1000
|
||||
if (now > start) {
|
||||
duration = (now - start).toInt()
|
||||
@@ -497,7 +499,6 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
||||
val time = pickedDateTime.time.time / 1000
|
||||
|
||||
if (isValidTime(time, duration)) {
|
||||
event.time = time
|
||||
event.quantity = duration
|
||||
@@ -523,7 +524,7 @@ class MainActivity : AppCompatActivity() {
|
||||
fun askAmountValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
||||
val d = AlertDialog.Builder(this)
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_amount, null)
|
||||
d.setTitle(event.getTypeDescription(this))
|
||||
d.setTitle(event.getDialogTitle(this))
|
||||
d.setMessage(event.getDialogMessage(this))
|
||||
d.setView(dialogView)
|
||||
|
||||
@@ -565,7 +566,7 @@ class MainActivity : AppCompatActivity() {
|
||||
fun askDateValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
||||
val d = AlertDialog.Builder(this)
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_plain, null)
|
||||
d.setTitle(event.getTypeDescription(this))
|
||||
d.setTitle(event.getDialogTitle(this))
|
||||
d.setMessage(event.getDialogMessage(this))
|
||||
d.setView(dialogView)
|
||||
|
||||
@@ -598,7 +599,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
val d = AlertDialog.Builder(this)
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_notes, null)
|
||||
d.setTitle(event.getTypeDescription(this))
|
||||
d.setTitle(event.getDialogTitle(this))
|
||||
d.setMessage(event.getDialogMessage(this))
|
||||
d.setView(dialogView)
|
||||
val notesET = dialogView.findViewById<EditText>(R.id.notes_edittext)
|
||||
@@ -776,8 +777,8 @@ class MainActivity : AppCompatActivity() {
|
||||
val quantityTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_quantity)
|
||||
val notesTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_notes)
|
||||
|
||||
emojiTextView.text = event.getTypeEmoji(this)
|
||||
descriptionTextView.text = event.getTypeDescription(this)
|
||||
emojiTextView.text = event.getHeaderEmoji(this)
|
||||
descriptionTextView.text = event.getDialogTitle(this)
|
||||
|
||||
d.setView(dialogView)
|
||||
|
||||
@@ -874,7 +875,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val previousTextView = dialogView.findViewById<TextView>(R.id.dialog_event_previous)
|
||||
val previousEvent = getPreviousSameEvent(event, allEvents)
|
||||
if (previousEvent != null) {
|
||||
val emoji = previousEvent.getTypeEmoji(applicationContext)
|
||||
val emoji = previousEvent.getHeaderEmoji(applicationContext)
|
||||
val time = DateUtils.formatTimeDuration(applicationContext, event.time - previousEvent.time)
|
||||
previousTextView.text = String.format("⬅️ %s %s", emoji, time)
|
||||
previousTextView.setOnClickListener {
|
||||
@@ -889,7 +890,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val nextTextView = dialogView.findViewById<TextView>(R.id.dialog_event_next)
|
||||
val nextEvent = getNextSameEvent(event, allEvents)
|
||||
if (nextEvent != null) {
|
||||
val emoji = nextEvent.getTypeEmoji(applicationContext)
|
||||
val emoji = nextEvent.getHeaderEmoji(applicationContext)
|
||||
val time = DateUtils.formatTimeDuration(applicationContext, nextEvent.time - event.time)
|
||||
nextTextView.text = String.format("%s %s ➡️", time, emoji)
|
||||
nextTextView.setOnClickListener {
|
||||
@@ -1060,7 +1061,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
if (DEBUG_CHECK_LOGBOOK_CONSISTENCY) {
|
||||
for (e in logbook?.logs ?: listOf()) {
|
||||
val em = e.getTypeEmoji(this@MainActivity)
|
||||
val em = e.getHeaderEmoji(this@MainActivity)
|
||||
if (em == getString(R.string.event_unknown_type)) {
|
||||
Log.e(TAG, "UNKNOWN: ${e.type}")
|
||||
}
|
||||
@@ -1293,7 +1294,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// Add buttons to create other events
|
||||
for (type in currentPopupItems) {
|
||||
val view = inflater.inflate(R.layout.more_events_popup_item, null)
|
||||
val view = layoutInflater.inflate(R.layout.more_events_popup_item, linearLayout, false)
|
||||
val textView = view.findViewById<TextView>(R.id.tv)
|
||||
textView.text = LunaEvent.getPopupItemTitle(applicationContext, type)
|
||||
textView.setOnClickListener {
|
||||
|
||||
@@ -52,11 +52,11 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
|
||||
)
|
||||
holder.quantity.setTextColor(ContextCompat.getColor(context, R.color.textColor))
|
||||
// Contents
|
||||
holder.type.text = item.getTypeEmoji(context)
|
||||
holder.type.text = item.getHeaderEmoji(context)
|
||||
holder.description.text = when (item.type) {
|
||||
LunaEvent.Type.MEDICINE -> item.notes
|
||||
LunaEvent.Type.NOTE -> item.notes
|
||||
else -> item.getTypeDescription(context)
|
||||
else -> item.getRowItemTitle(context)
|
||||
}
|
||||
val endTime = if (item.type == LunaEvent.Type.SLEEP) {
|
||||
item.quantity + item.time
|
||||
|
||||
@@ -12,7 +12,6 @@ import java.util.Date
|
||||
* release, it is simply ignored by previous ones).
|
||||
*/
|
||||
class LunaEvent: Comparable<LunaEvent> {
|
||||
|
||||
enum class Type {
|
||||
BABY_BOTTLE,
|
||||
FOOD,
|
||||
@@ -100,12 +99,16 @@ class LunaEvent: Comparable<LunaEvent> {
|
||||
this.quantity = quantity
|
||||
}
|
||||
|
||||
fun getTypeEmoji(context: Context): String {
|
||||
return getTypeEmoji(context, type)
|
||||
fun getHeaderEmoji(context: Context): String {
|
||||
return getHeaderEmoji(context, type)
|
||||
}
|
||||
|
||||
fun getTypeDescription(context: Context): String {
|
||||
return getTypeDescription(context, type)
|
||||
fun getDialogTitle(context: Context): String {
|
||||
return getDialogTitle(context, type)
|
||||
}
|
||||
|
||||
fun getRowItemTitle(context: Context): String {
|
||||
return getPopupItemTitle(context, type).split(" ", limit = 2).last() // remove emoji
|
||||
}
|
||||
|
||||
fun getDialogMessage(context: Context): String {
|
||||
@@ -125,7 +128,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getTypeEmoji(context: Context, type: Type): String {
|
||||
fun getHeaderEmoji(context: Context, type: Type): String {
|
||||
return context.getString(
|
||||
when (type) {
|
||||
Type.BABY_BOTTLE -> R.string.event_bottle_type
|
||||
@@ -165,7 +168,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
||||
)
|
||||
}
|
||||
|
||||
fun getTypeDescription(context: Context, type: Type): String {
|
||||
fun getDialogTitle(context: Context, type: Type): String {
|
||||
return context.getString(
|
||||
when (type) {
|
||||
Type.BABY_BOTTLE -> R.string.event_bottle_desc
|
||||
|
||||
@@ -101,7 +101,7 @@ class NumericUtils (val context: Context) {
|
||||
else -> ""
|
||||
})
|
||||
}
|
||||
return formatted.toString()
|
||||
return formatted.toString().trim()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
android:id="@+id/button_statistics"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="10dp"
|
||||
android:padding="10dp"
|
||||
android:background="@drawable/dropdown_list_item_background"
|
||||
style="@style/OverflowMenuText"
|
||||
|
||||
11
app/src/main/res/layout/more_events_popup_item.xml
Normal file
11
app/src/main/res/layout/more_events_popup_item.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/tv"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="10dp"
|
||||
android:padding="10dp"
|
||||
android:background="@drawable/dropdown_list_item_background"
|
||||
style="@style/OverflowMenuText"
|
||||
android:text="Item Template"/>
|
||||
@@ -29,8 +29,8 @@
|
||||
<string name="event_type_item_breastfeeding_left">🤱⬅️ Nursing</string>
|
||||
<string name="event_type_item_breastfeeding_both">🤱↔️ Nursing</string>
|
||||
<string name="event_type_item_breastfeeding_right">🤱➡️️ Nursing</string>
|
||||
<string name="event_type_item_diaperchange_poo">💩 Diaper</string>
|
||||
<string name="event_type_item_diaperchange_pee">💧 Diaper</string>
|
||||
<string name="event_type_item_diaperchange_poo">🚼💩 Diaper</string>
|
||||
<string name="event_type_item_diaperchange_pee">🚼💧 Diaper</string>
|
||||
<string name="event_type_item_medicine">💊 Medicine</string>
|
||||
<string name="event_type_item_enema">🪠 Enema</string>
|
||||
<string name="event_type_item_note">📝 Note</string>
|
||||
@@ -42,7 +42,7 @@
|
||||
<string name="event_type_item_unknown">❓ Unknown</string>
|
||||
|
||||
<!-- dialog titles -->
|
||||
<string name="event_bottle_desc">Bottle</string>
|
||||
<string name="event_bottle_desc">Milk Bottle</string>
|
||||
<string name="event_food_desc">Food</string>
|
||||
<string name="event_weight_desc">Weight</string>
|
||||
<string name="event_breastfeeding_left_desc">Nursing (left)</string>
|
||||
@@ -58,7 +58,7 @@
|
||||
<string name="event_puke_desc">Puke</string>
|
||||
<string name="event_bath_desc">Bath</string>
|
||||
<string name="event_sleep_desc">Sleep</string>
|
||||
<string name="event_unknown_desc"></string>
|
||||
<string name="event_unknown_desc">Unknown</string>
|
||||
|
||||
<string name="toast_event_added">Event logged</string>
|
||||
<string name="toast_logbook_saved">Logbook saved</string>
|
||||
|
||||
Reference in New Issue
Block a user