forked from penguin86/luna-tracker
Compare commits
11 Commits
bottle_tim
...
341d2c5229
| Author | SHA1 | Date | |
|---|---|---|---|
| 341d2c5229 | |||
| 2709050496 | |||
| 5fe383e488 | |||
| 7d480d6e1c | |||
| bbf3b0ce8e | |||
| 38f2a27c38 | |||
| 6d63ad54f2 | |||
| 553e1c351f | |||
| f8f5d68bb6 | |||
| 280d4558ad | |||
| d74310fad5 |
@@ -86,6 +86,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
recyclerView = findViewById(R.id.list_events)
|
recyclerView = findViewById(R.id.list_events)
|
||||||
recyclerView.setLayoutManager(LinearLayoutManager(applicationContext))
|
recyclerView.setLayoutManager(LinearLayoutManager(applicationContext))
|
||||||
|
|
||||||
|
// set defaults
|
||||||
populateHeaderMenu()
|
populateHeaderMenu()
|
||||||
|
|
||||||
// Set listeners
|
// Set listeners
|
||||||
@@ -108,11 +109,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
loadLogbookList()
|
loadLogbookList()
|
||||||
}
|
}
|
||||||
findViewById<View>(R.id.button_sync).setOnClickListener {
|
findViewById<View>(R.id.button_sync).setOnClickListener {
|
||||||
if (logbook != null) {
|
loadLogbookList()
|
||||||
loadLogbook(logbook!!.name)
|
|
||||||
} else {
|
|
||||||
loadLogbookList()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,6 +139,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
populateHeaderMenu()
|
populateHeaderMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// populate action rows
|
||||||
private fun populateHeaderMenu() {
|
private fun populateHeaderMenu() {
|
||||||
val settingsRepository = LocalSettingsRepository(this)
|
val settingsRepository = LocalSettingsRepository(this)
|
||||||
val dynamicMenu = settingsRepository.loadDynamicMenu()
|
val dynamicMenu = settingsRepository.loadDynamicMenu()
|
||||||
@@ -187,7 +185,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
fun show(vararg tvs: TextView) {
|
fun show(vararg tvs: TextView) {
|
||||||
for (tv in tvs) {
|
for (tv in tvs) {
|
||||||
val type = sortedEventTypes[showCounter]
|
val type = sortedEventTypes[showCounter]
|
||||||
tv.text = LunaEvent.getHeaderEmoji(applicationContext, type)
|
tv.text = LunaEvent.getTypeEmoji(applicationContext, type)
|
||||||
tv.setOnClickListener { showCreateDialog(type) }
|
tv.setOnClickListener { showCreateDialog(type) }
|
||||||
tv.visibility = View.VISIBLE
|
tv.visibility = View.VISIBLE
|
||||||
// show parent row
|
// show parent row
|
||||||
@@ -264,7 +262,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
fun askBabyBottleContent(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
fun askBabyBottleContent(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
||||||
val d = AlertDialog.Builder(this)
|
val d = AlertDialog.Builder(this)
|
||||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_bottle, null)
|
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_bottle, null)
|
||||||
d.setTitle(event.getDialogTitle(this))
|
d.setTitle(event.getTypeDescription(this))
|
||||||
d.setMessage(event.getDialogMessage(this))
|
d.setMessage(event.getDialogMessage(this))
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
@@ -306,7 +304,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// Show number picker dialog
|
// Show number picker dialog
|
||||||
val d = AlertDialog.Builder(this)
|
val d = AlertDialog.Builder(this)
|
||||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_weight, null)
|
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_weight, null)
|
||||||
d.setTitle(event.getDialogTitle(this))
|
d.setTitle(event.getTypeDescription(this))
|
||||||
d.setMessage(event.getDialogMessage(this))
|
d.setMessage(event.getDialogMessage(this))
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
@@ -350,7 +348,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// Show number picker dialog
|
// Show number picker dialog
|
||||||
val d = AlertDialog.Builder(this)
|
val d = AlertDialog.Builder(this)
|
||||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_temperature, null)
|
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_temperature, null)
|
||||||
d.setTitle(event.getDialogTitle(this))
|
d.setTitle(event.getTypeDescription(this))
|
||||||
d.setMessage(event.getDialogMessage(this))
|
d.setMessage(event.getDialogMessage(this))
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
@@ -438,7 +436,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
fun askSleepValue(event: LunaEvent, onPositive: () -> Unit) {
|
fun askSleepValue(event: LunaEvent, onPositive: () -> Unit) {
|
||||||
val d = AlertDialog.Builder(this)
|
val d = AlertDialog.Builder(this)
|
||||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_duration, null)
|
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_duration, null)
|
||||||
d.setTitle(event.getDialogTitle(this))
|
d.setTitle(event.getTypeDescription(this))
|
||||||
d.setMessage(event.getDialogMessage(this))
|
d.setMessage(event.getDialogMessage(this))
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
@@ -454,8 +452,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
var duration = event.quantity
|
var duration = event.quantity
|
||||||
|
|
||||||
fun isValidTime(timeSeconds: Long, durationSeconds: Int): Boolean {
|
fun isValidTime(timeSeconds: Long, durationSeconds: Int): Boolean {
|
||||||
val now = System.currentTimeMillis() / 1000
|
val now = Calendar.getInstance().time.time / 1000
|
||||||
return (timeSeconds + durationSeconds) <= now && durationSeconds < (24 * 60 * 60)
|
return (timeSeconds + durationSeconds) <= now && durationSeconds < (12 * 60 * 60)
|
||||||
}
|
}
|
||||||
|
|
||||||
val onDateChange = { time: Long ->
|
val onDateChange = { time: Long ->
|
||||||
@@ -488,7 +486,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
durationPlus5Button.setOnClickListener { adjust(5) }
|
durationPlus5Button.setOnClickListener { adjust(5) }
|
||||||
|
|
||||||
durationNowButton.setOnClickListener {
|
durationNowButton.setOnClickListener {
|
||||||
val now = System.currentTimeMillis() / 1000
|
val now = Calendar.getInstance().time.time / 1000
|
||||||
val start = pickedDateTime.time.time / 1000
|
val start = pickedDateTime.time.time / 1000
|
||||||
if (now > start) {
|
if (now > start) {
|
||||||
duration = (now - start).toInt()
|
duration = (now - start).toInt()
|
||||||
@@ -499,6 +497,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
||||||
val time = pickedDateTime.time.time / 1000
|
val time = pickedDateTime.time.time / 1000
|
||||||
|
|
||||||
if (isValidTime(time, duration)) {
|
if (isValidTime(time, duration)) {
|
||||||
event.time = time
|
event.time = time
|
||||||
event.quantity = duration
|
event.quantity = duration
|
||||||
@@ -524,7 +523,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
fun askAmountValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
fun askAmountValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
||||||
val d = AlertDialog.Builder(this)
|
val d = AlertDialog.Builder(this)
|
||||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_amount, null)
|
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_amount, null)
|
||||||
d.setTitle(event.getDialogTitle(this))
|
d.setTitle(event.getTypeDescription(this))
|
||||||
d.setMessage(event.getDialogMessage(this))
|
d.setMessage(event.getDialogMessage(this))
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
@@ -566,7 +565,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
fun askDateValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
fun askDateValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
||||||
val d = AlertDialog.Builder(this)
|
val d = AlertDialog.Builder(this)
|
||||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_plain, null)
|
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_plain, null)
|
||||||
d.setTitle(event.getDialogTitle(this))
|
d.setTitle(event.getTypeDescription(this))
|
||||||
d.setMessage(event.getDialogMessage(this))
|
d.setMessage(event.getDialogMessage(this))
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
@@ -599,7 +598,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
val d = AlertDialog.Builder(this)
|
val d = AlertDialog.Builder(this)
|
||||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_notes, null)
|
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_notes, null)
|
||||||
d.setTitle(event.getDialogTitle(this))
|
d.setTitle(event.getTypeDescription(this))
|
||||||
d.setMessage(event.getDialogMessage(this))
|
d.setMessage(event.getDialogMessage(this))
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
val notesET = dialogView.findViewById<EditText>(R.id.notes_edittext)
|
val notesET = dialogView.findViewById<EditText>(R.id.notes_edittext)
|
||||||
@@ -777,8 +776,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val quantityTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_quantity)
|
val quantityTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_quantity)
|
||||||
val notesTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_notes)
|
val notesTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_notes)
|
||||||
|
|
||||||
emojiTextView.text = event.getHeaderEmoji(this)
|
emojiTextView.text = event.getTypeEmoji(this)
|
||||||
descriptionTextView.text = event.getDialogTitle(this)
|
descriptionTextView.text = event.getTypeDescription(this)
|
||||||
|
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
@@ -875,7 +874,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val previousTextView = dialogView.findViewById<TextView>(R.id.dialog_event_previous)
|
val previousTextView = dialogView.findViewById<TextView>(R.id.dialog_event_previous)
|
||||||
val previousEvent = getPreviousSameEvent(event, allEvents)
|
val previousEvent = getPreviousSameEvent(event, allEvents)
|
||||||
if (previousEvent != null) {
|
if (previousEvent != null) {
|
||||||
val emoji = previousEvent.getHeaderEmoji(applicationContext)
|
val emoji = previousEvent.getTypeEmoji(applicationContext)
|
||||||
val time = DateUtils.formatTimeDuration(applicationContext, event.time - previousEvent.time)
|
val time = DateUtils.formatTimeDuration(applicationContext, event.time - previousEvent.time)
|
||||||
previousTextView.text = String.format("⬅️ %s %s", emoji, time)
|
previousTextView.text = String.format("⬅️ %s %s", emoji, time)
|
||||||
previousTextView.setOnClickListener {
|
previousTextView.setOnClickListener {
|
||||||
@@ -890,7 +889,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val nextTextView = dialogView.findViewById<TextView>(R.id.dialog_event_next)
|
val nextTextView = dialogView.findViewById<TextView>(R.id.dialog_event_next)
|
||||||
val nextEvent = getNextSameEvent(event, allEvents)
|
val nextEvent = getNextSameEvent(event, allEvents)
|
||||||
if (nextEvent != null) {
|
if (nextEvent != null) {
|
||||||
val emoji = nextEvent.getHeaderEmoji(applicationContext)
|
val emoji = nextEvent.getTypeEmoji(applicationContext)
|
||||||
val time = DateUtils.formatTimeDuration(applicationContext, nextEvent.time - event.time)
|
val time = DateUtils.formatTimeDuration(applicationContext, nextEvent.time - event.time)
|
||||||
nextTextView.text = String.format("%s %s ➡️", time, emoji)
|
nextTextView.text = String.format("%s %s ➡️", time, emoji)
|
||||||
nextTextView.setOnClickListener {
|
nextTextView.setOnClickListener {
|
||||||
@@ -1061,7 +1060,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
if (DEBUG_CHECK_LOGBOOK_CONSISTENCY) {
|
if (DEBUG_CHECK_LOGBOOK_CONSISTENCY) {
|
||||||
for (e in logbook?.logs ?: listOf()) {
|
for (e in logbook?.logs ?: listOf()) {
|
||||||
val em = e.getHeaderEmoji(this@MainActivity)
|
val em = e.getTypeEmoji(this@MainActivity)
|
||||||
if (em == getString(R.string.event_unknown_type)) {
|
if (em == getString(R.string.event_unknown_type)) {
|
||||||
Log.e(TAG, "UNKNOWN: ${e.type}")
|
Log.e(TAG, "UNKNOWN: ${e.type}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
|
|||||||
)
|
)
|
||||||
holder.quantity.setTextColor(ContextCompat.getColor(context, R.color.textColor))
|
holder.quantity.setTextColor(ContextCompat.getColor(context, R.color.textColor))
|
||||||
// Contents
|
// Contents
|
||||||
holder.type.text = item.getHeaderEmoji(context)
|
holder.type.text = item.getTypeEmoji(context)
|
||||||
holder.description.text = when (item.type) {
|
holder.description.text = when (item.type) {
|
||||||
LunaEvent.Type.MEDICINE -> item.notes
|
LunaEvent.Type.MEDICINE -> item.notes
|
||||||
LunaEvent.Type.NOTE -> item.notes
|
LunaEvent.Type.NOTE -> item.notes
|
||||||
else -> item.getRowItemTitle(context)
|
else -> item.getTypeDescription(context)
|
||||||
}
|
}
|
||||||
val endTime = if (item.type == LunaEvent.Type.SLEEP) {
|
val endTime = if (item.type == LunaEvent.Type.SLEEP) {
|
||||||
item.quantity + item.time
|
item.quantity + item.time
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import java.util.Date
|
|||||||
* release, it is simply ignored by previous ones).
|
* release, it is simply ignored by previous ones).
|
||||||
*/
|
*/
|
||||||
class LunaEvent: Comparable<LunaEvent> {
|
class LunaEvent: Comparable<LunaEvent> {
|
||||||
|
|
||||||
enum class Type {
|
enum class Type {
|
||||||
BABY_BOTTLE,
|
BABY_BOTTLE,
|
||||||
FOOD,
|
FOOD,
|
||||||
@@ -99,16 +100,12 @@ class LunaEvent: Comparable<LunaEvent> {
|
|||||||
this.quantity = quantity
|
this.quantity = quantity
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getHeaderEmoji(context: Context): String {
|
fun getTypeEmoji(context: Context): String {
|
||||||
return getHeaderEmoji(context, type)
|
return getTypeEmoji(context, type)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDialogTitle(context: Context): String {
|
fun getTypeDescription(context: Context): String {
|
||||||
return getDialogTitle(context, type)
|
return getTypeDescription(context, type)
|
||||||
}
|
|
||||||
|
|
||||||
fun getRowItemTitle(context: Context): String {
|
|
||||||
return getPopupItemTitle(context, type).split(" ", limit = 2).last() // remove emoji
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDialogMessage(context: Context): String {
|
fun getDialogMessage(context: Context): String {
|
||||||
@@ -128,7 +125,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun getHeaderEmoji(context: Context, type: Type): String {
|
fun getTypeEmoji(context: Context, type: Type): String {
|
||||||
return context.getString(
|
return context.getString(
|
||||||
when (type) {
|
when (type) {
|
||||||
Type.BABY_BOTTLE -> R.string.event_bottle_type
|
Type.BABY_BOTTLE -> R.string.event_bottle_type
|
||||||
@@ -168,7 +165,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDialogTitle(context: Context, type: Type): String {
|
fun getTypeDescription(context: Context, type: Type): String {
|
||||||
return context.getString(
|
return context.getString(
|
||||||
when (type) {
|
when (type) {
|
||||||
Type.BABY_BOTTLE -> R.string.event_bottle_desc
|
Type.BABY_BOTTLE -> R.string.event_bottle_desc
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ class NumericUtils (val context: Context) {
|
|||||||
else -> ""
|
else -> ""
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return formatted.toString().trim()
|
return formatted.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -29,8 +29,8 @@
|
|||||||
<string name="event_type_item_breastfeeding_left">🤱⬅️ Nursing</string>
|
<string name="event_type_item_breastfeeding_left">🤱⬅️ Nursing</string>
|
||||||
<string name="event_type_item_breastfeeding_both">🤱↔️ 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_breastfeeding_right">🤱➡️️ Nursing</string>
|
||||||
<string name="event_type_item_diaperchange_poo">🚼💩 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_diaperchange_pee">💧 Diaper</string>
|
||||||
<string name="event_type_item_medicine">💊 Medicine</string>
|
<string name="event_type_item_medicine">💊 Medicine</string>
|
||||||
<string name="event_type_item_enema">🪠 Enema</string>
|
<string name="event_type_item_enema">🪠 Enema</string>
|
||||||
<string name="event_type_item_note">📝 Note</string>
|
<string name="event_type_item_note">📝 Note</string>
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
<string name="event_type_item_unknown">❓ Unknown</string>
|
<string name="event_type_item_unknown">❓ Unknown</string>
|
||||||
|
|
||||||
<!-- dialog titles -->
|
<!-- dialog titles -->
|
||||||
<string name="event_bottle_desc">Milk Bottle</string>
|
<string name="event_bottle_desc">Bottle</string>
|
||||||
<string name="event_food_desc">Food</string>
|
<string name="event_food_desc">Food</string>
|
||||||
<string name="event_weight_desc">Weight</string>
|
<string name="event_weight_desc">Weight</string>
|
||||||
<string name="event_breastfeeding_left_desc">Nursing (left)</string>
|
<string name="event_breastfeeding_left_desc">Nursing (left)</string>
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
<string name="event_puke_desc">Puke</string>
|
<string name="event_puke_desc">Puke</string>
|
||||||
<string name="event_bath_desc">Bath</string>
|
<string name="event_bath_desc">Bath</string>
|
||||||
<string name="event_sleep_desc">Sleep</string>
|
<string name="event_sleep_desc">Sleep</string>
|
||||||
<string name="event_unknown_desc">Unknown</string>
|
<string name="event_unknown_desc"></string>
|
||||||
|
|
||||||
<string name="toast_event_added">Event logged</string>
|
<string name="toast_event_added">Event logged</string>
|
||||||
<string name="toast_logbook_saved">Logbook saved</string>
|
<string name="toast_logbook_saved">Logbook saved</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user