forked from penguin86/luna-tracker
LunaEvent: reorganize event text getters
Use method names that better reflect the use of the returned text.
This commit is contained in:
@@ -183,7 +183,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.getTypeEmoji(applicationContext, type)
|
tv.text = LunaEvent.getHeaderEmoji(applicationContext, type)
|
||||||
tv.setOnClickListener { showCreateDialog(type) }
|
tv.setOnClickListener { showCreateDialog(type) }
|
||||||
tv.visibility = View.VISIBLE
|
tv.visibility = View.VISIBLE
|
||||||
// show parent row
|
// show parent row
|
||||||
@@ -260,7 +260,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.getTypeDescription(this))
|
d.setTitle(event.getDialogTitle(this))
|
||||||
d.setMessage(event.getDialogMessage(this))
|
d.setMessage(event.getDialogMessage(this))
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
@@ -302,7 +302,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.getTypeDescription(this))
|
d.setTitle(event.getDialogTitle(this))
|
||||||
d.setMessage(event.getDialogMessage(this))
|
d.setMessage(event.getDialogMessage(this))
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
@@ -346,7 +346,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.getTypeDescription(this))
|
d.setTitle(event.getDialogTitle(this))
|
||||||
d.setMessage(event.getDialogMessage(this))
|
d.setMessage(event.getDialogMessage(this))
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
@@ -434,7 +434,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.getTypeDescription(this))
|
d.setTitle(event.getDialogTitle(this))
|
||||||
d.setMessage(event.getDialogMessage(this))
|
d.setMessage(event.getDialogMessage(this))
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
@@ -521,7 +521,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.getTypeDescription(this))
|
d.setTitle(event.getDialogTitle(this))
|
||||||
d.setMessage(event.getDialogMessage(this))
|
d.setMessage(event.getDialogMessage(this))
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
@@ -563,7 +563,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.getTypeDescription(this))
|
d.setTitle(event.getDialogTitle(this))
|
||||||
d.setMessage(event.getDialogMessage(this))
|
d.setMessage(event.getDialogMessage(this))
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
@@ -596,7 +596,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.getTypeDescription(this))
|
d.setTitle(event.getDialogTitle(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)
|
||||||
@@ -774,8 +774,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.getTypeEmoji(this)
|
emojiTextView.text = event.getHeaderEmoji(this)
|
||||||
descriptionTextView.text = event.getTypeDescription(this)
|
descriptionTextView.text = event.getDialogTitle(this)
|
||||||
|
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
@@ -872,7 +872,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.getTypeEmoji(applicationContext)
|
val emoji = previousEvent.getHeaderEmoji(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 {
|
||||||
@@ -887,7 +887,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.getTypeEmoji(applicationContext)
|
val emoji = nextEvent.getHeaderEmoji(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 {
|
||||||
@@ -1058,7 +1058,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.getTypeEmoji(this@MainActivity)
|
val em = e.getHeaderEmoji(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.getTypeEmoji(context)
|
holder.type.text = item.getHeaderEmoji(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.getTypeDescription(context)
|
else -> item.getRowItemTitle(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,7 +12,6 @@ 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,
|
||||||
@@ -100,14 +99,18 @@ class LunaEvent: Comparable<LunaEvent> {
|
|||||||
this.quantity = quantity
|
this.quantity = quantity
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTypeEmoji(context: Context): String {
|
fun getHeaderEmoji(context: Context): String {
|
||||||
return getTypeEmoji(context, type)
|
return getHeaderEmoji(context, type)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTypeDescription(context: Context): String {
|
fun getDialogTitle(context: Context): String {
|
||||||
return getTypeDescription(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 {
|
||||||
return getDialogMessage(context, type)
|
return getDialogMessage(context, type)
|
||||||
}
|
}
|
||||||
@@ -125,7 +128,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun getTypeEmoji(context: Context, type: Type): String {
|
fun getHeaderEmoji(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
|
||||||
|
|||||||
Reference in New Issue
Block a user