1 Commits

Author SHA1 Message Date
c52a74c7e3 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 23:08:41 +01:00
3 changed files with 38 additions and 36 deletions

View File

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

View File

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

View File

@@ -15,8 +15,6 @@
<string name="log_puke_dialog_title">Puke</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_food_type" translatable="false">🥣</string>
<string name="event_scale_type" translatable="false">⚖️</string>