4 Commits

Author SHA1 Message Date
8e4a5b89c0 NumericUtils: remove possible trailing whitespace 2025-12-12 15:27:13 +01:00
469666cd0f MainActivity: use System.currentTimeMillis
A little better way to get the ms since epoch.
2025-12-12 15:27:13 +01:00
0e980a8c68 MainActivity: do not switch logbook on reload 2025-12-12 15:27:13 +01:00
b1fc3ce890 LunaEvent: reorganize event text getters
Use method names that better reflect
the use of the returned text.
2025-12-12 15:27:08 +01:00
4 changed files with 33 additions and 26 deletions

View File

@@ -108,7 +108,11 @@ class MainActivity : AppCompatActivity() {
loadLogbookList()
}
findViewById<View>(R.id.button_sync).setOnClickListener {
loadLogbookList()
if (logbook != null) {
loadLogbook(logbook!!.name)
} else {
loadLogbookList()
}
}
}
@@ -183,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
@@ -260,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)
@@ -302,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)
@@ -346,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)
@@ -434,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)
@@ -450,7 +454,7 @@ class MainActivity : AppCompatActivity() {
var duration = event.quantity
fun isValidTime(timeSeconds: Long, durationSeconds: Int): Boolean {
val now = Calendar.getInstance().time.time / 1000
val now = System.currentTimeMillis() / 1000
return (timeSeconds + durationSeconds) <= now && durationSeconds < (12 * 60 * 60)
}
@@ -484,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()
@@ -521,7 +525,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)
@@ -563,7 +567,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)
@@ -596,7 +600,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)
@@ -774,8 +778,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)
@@ -872,7 +876,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 {
@@ -887,7 +891,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 {
@@ -1058,7 +1062,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}")
}

View File

@@ -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

View File

@@ -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

View File

@@ -101,7 +101,7 @@ class NumericUtils (val context: Context) {
else -> ""
})
}
return formatted.toString()
return formatted.toString().trim()
}
/**