1 Commits

Author SHA1 Message Date
5ffeff445f allow editing of all events
Allow to set the date of each event
on creation.

Allow to change the date/time and
other relevant values of an event
after it was created.
2025-11-11 22:11:20 +01:00
3 changed files with 35 additions and 37 deletions

View File

@@ -78,7 +78,7 @@ class MainActivity : AppCompatActivity() {
progressIndicator = findViewById(R.id.progress_indicator) progressIndicator = findViewById(R.id.progress_indicator)
buttonsContainer = findViewById(R.id.buttons_container) buttonsContainer = findViewById(R.id.buttons_container)
recyclerView = findViewById(R.id.list_events) recyclerView = findViewById(R.id.list_events)
recyclerView.setLayoutManager(LinearLayoutManager(this)) recyclerView.setLayoutManager(LinearLayoutManager(applicationContext))
// Set listeners // Set listeners
findViewById<View>(R.id.logbooks_add_button).setOnClickListener { findViewById<View>(R.id.logbooks_add_button).setOnClickListener {
@@ -265,11 +265,11 @@ class MainActivity : AppCompatActivity() {
if (weight != null) { if (weight != null) {
event.time = pickedTime.time.time / 1000 event.time = pickedTime.time.time / 1000
event.quantity = weight event.quantity = weight
onPositive()
} else { } else {
Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show() Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show()
} }
onPositive()
dialogInterface.dismiss() dialogInterface.dismiss()
} }
@@ -337,9 +337,9 @@ class MainActivity : AppCompatActivity() {
val startHour = dateTime.get(Calendar.HOUR_OF_DAY) val startHour = dateTime.get(Calendar.HOUR_OF_DAY)
val startMinute = dateTime.get(Calendar.MINUTE) val startMinute = dateTime.get(Calendar.MINUTE)
DatePickerDialog(this, { _, year, month, day -> DatePickerDialog(applicationContext, { _, year, month, day ->
TimePickerDialog( TimePickerDialog(
this, applicationContext,
{ _, hour, minute -> { _, hour, minute ->
dateTime.set(year, month, day, hour, minute) dateTime.set(year, month, day, hour, minute)
dateTextView.text = DateUtils.formatDateTime(dateTime.time.time / 1000) dateTextView.text = DateUtils.formatDateTime(dateTime.time.time / 1000)
@@ -474,13 +474,13 @@ class MainActivity : AppCompatActivity() {
val quantity = qtyET.text.toString().toIntOrNull() val quantity = qtyET.text.toString().toIntOrNull()
if (quantity != null) { if (quantity != null) {
event.time = pickedTime.time.time / 1000 event.time = pickedTime.time.time / 1000
event.notes = notes
event.quantity = quantity event.quantity = quantity
onPositive() event.notes = notes
} else { } else {
Toast.makeText(applicationContext, R.string.toast_integer_error, Toast.LENGTH_SHORT).show() Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show()
} }
onPositive()
} else { } else {
event.time = pickedTime.time.time / 1000 event.time = pickedTime.time.time / 1000
event.notes = notes event.notes = notes
@@ -562,12 +562,12 @@ 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.getTypeEmoji(applicationContext)
descriptionTextView.text = event.getTypeDescription(this) descriptionTextView.text = event.getTypeDescription(applicationContext)
val pickedTime = datePickHelper(event.time, dateTextView) val pickedTime = datePickHelper(event.time, dateTextView)
val updateValues = { val updateValues = {
quantityTextView.text = NumericUtils(this).formatEventQuantity(event) quantityTextView.text = NumericUtils(applicationContext).formatEventQuantity(event)
notesTextView.text = event.notes notesTextView.text = event.notes
} }
updateValues() updateValues()
@@ -591,12 +591,10 @@ class MainActivity : AppCompatActivity() {
} }
d.setView(dialogView) d.setView(dialogView)
d.setNeutralButton(R.string.dialog_event_detail_delete_button) { dialogInterface, i -> d.setNeutralButton(R.string.dialog_event_detail_delete_button) { dialogInterface, i ->
deleteEvent(event) deleteEvent(event)
dialogInterface.dismiss() dialogInterface.dismiss()
} }
d.setPositiveButton(R.string.dialog_event_detail_close_button) { dialogInterface, i -> d.setPositiveButton(R.string.dialog_event_detail_close_button) { dialogInterface, i ->
event.time = pickedTime.time.time / 1000 event.time = pickedTime.time.time / 1000
@@ -612,18 +610,6 @@ class MainActivity : AppCompatActivity() {
dialogInterface.dismiss() dialogInterface.dismiss()
} }
val alertDialog = d.create()
alertDialog.show()
alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(
ContextCompat.getColor(this, R.color.danger)
)
alertDialog.setOnDismissListener {
// Resume logbook update
pauseLogbookUpdate = false
}
// show optional signature // show optional signature
if (event.signature.isNotEmpty()) { if (event.signature.isNotEmpty()) {
val signatureTextEdit = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_signature) val signatureTextEdit = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_signature)
@@ -631,14 +617,19 @@ class MainActivity : AppCompatActivity() {
signatureTextEdit.visibility = View.VISIBLE signatureTextEdit.visibility = View.VISIBLE
} }
val allEvents = getAllEvents() val alertDialog = d.create()
alertDialog.show()
// create link to prevent event of the same type // create next/previous links to events of the same type
val previousTextView = dialogView.findViewById<TextView>(R.id.dialog_event_previous) val previousTextView = dialogView.findViewById<TextView>(R.id.dialog_event_previous)
val nextTextView = dialogView.findViewById<TextView>(R.id.dialog_event_next)
val allEvents = getAllEvents()
val nextEvent = getNextSameEvent(event, allEvents)
val previousEvent = getPreviousSameEvent(event, allEvents) val previousEvent = getPreviousSameEvent(event, allEvents)
if (previousEvent != null) { if (previousEvent != null) {
val emoji = previousEvent.getTypeEmoji(this) val emoji = previousEvent.getTypeEmoji(applicationContext)
val time = DateUtils.formatTimeDuration(this, 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 {
alertDialog.cancel() alertDialog.cancel()
@@ -648,12 +639,9 @@ class MainActivity : AppCompatActivity() {
previousTextView.visibility = View.GONE previousTextView.visibility = View.GONE
} }
// create link to next event of the same type
val nextTextView = dialogView.findViewById<TextView>(R.id.dialog_event_next)
val nextEvent = getNextSameEvent(event, allEvents)
if (nextEvent != null) { if (nextEvent != null) {
val emoji = nextEvent.getTypeEmoji(this) val emoji = nextEvent.getTypeEmoji(applicationContext)
val time = DateUtils.formatTimeDuration(this, 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 {
alertDialog.cancel() alertDialog.cancel()
@@ -662,6 +650,15 @@ class MainActivity : AppCompatActivity() {
} else { } else {
nextTextView.visibility = View.GONE nextTextView.visibility = View.GONE
} }
alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(
ContextCompat.getColor(this, R.color.danger)
)
alertDialog.setOnDismissListener {
// Resume logbook update
pauseLogbookUpdate = false
}
} }
fun showAddLogbookDialog(requestedByUser: Boolean) { fun showAddLogbookDialog(requestedByUser: Boolean) {
@@ -765,7 +762,7 @@ class MainActivity : AppCompatActivity() {
runOnUiThread({ runOnUiThread({
setLoading(false) setLoading(false)
loadLogbookList() loadLogbookList()
Toast.makeText(applicationContext, getString(R.string.logbook_created) + logbookName, Toast.LENGTH_SHORT).show() Toast.makeText(this@MainActivity, getString(R.string.logbook_created) + logbookName, Toast.LENGTH_SHORT).show()
}) })
} }
@@ -922,7 +919,7 @@ class MainActivity : AppCompatActivity() {
setLoading(false) setLoading(false)
Toast.makeText( Toast.makeText(
applicationContext, this@MainActivity,
if (lastEventAdded != null) if (lastEventAdded != null)
R.string.toast_event_added R.string.toast_event_added
else else
@@ -984,7 +981,7 @@ class MainActivity : AppCompatActivity() {
runOnUiThread({ runOnUiThread({
setLoading(false) setLoading(false)
Toast.makeText(applicationContext, R.string.toast_event_add_error, Toast.LENGTH_SHORT).show() Toast.makeText(this@MainActivity, R.string.toast_event_add_error, Toast.LENGTH_SHORT).show()
recyclerView.adapter?.notifyDataSetChanged() recyclerView.adapter?.notifyDataSetChanged()
savingEvent(false) savingEvent(false)
}) })

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"

View File

@@ -15,6 +15,8 @@
<string name="log_puke_dialog_title">Puke</string> <string name="log_puke_dialog_title">Puke</string>
<string name="log_puke_dialog_description">Select the amount</string> <string name="log_puke_dialog_description">Select the amount</string>
<string name="dialog_event_detail_edit_button">Edit</string>
<string name="event_bottle_type" translatable="false">🍼</string> <string name="event_bottle_type" translatable="false">🍼</string>
<string name="event_food_type" translatable="false">🥣</string> <string name="event_food_type" translatable="false">🥣</string>
<string name="event_scale_type" translatable="false">⚖️</string> <string name="event_scale_type" translatable="false">⚖️</string>