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)
buttonsContainer = findViewById(R.id.buttons_container)
recyclerView = findViewById(R.id.list_events)
recyclerView.setLayoutManager(LinearLayoutManager(this))
recyclerView.setLayoutManager(LinearLayoutManager(applicationContext))
// 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(this, { _, year, month, day ->
DatePickerDialog(applicationContext, { _, year, month, day ->
TimePickerDialog(
this,
applicationContext,
{ _, 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.notes = notes
event.quantity = quantity
onPositive()
event.notes = notes
} 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 {
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(this)
descriptionTextView.text = event.getTypeDescription(this)
emojiTextView.text = event.getTypeEmoji(applicationContext)
descriptionTextView.text = event.getTypeDescription(applicationContext)
val pickedTime = datePickHelper(event.time, dateTextView)
val updateValues = {
quantityTextView.text = NumericUtils(this).formatEventQuantity(event)
quantityTextView.text = NumericUtils(applicationContext).formatEventQuantity(event)
notesTextView.text = event.notes
}
updateValues()
@@ -591,12 +591,10 @@ 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
@@ -612,18 +610,6 @@ 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)
@@ -631,14 +617,19 @@ class MainActivity : AppCompatActivity() {
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 nextTextView = dialogView.findViewById<TextView>(R.id.dialog_event_next)
val allEvents = getAllEvents()
val nextEvent = getNextSameEvent(event, allEvents)
val previousEvent = getPreviousSameEvent(event, allEvents)
if (previousEvent != null) {
val emoji = previousEvent.getTypeEmoji(this)
val time = DateUtils.formatTimeDuration(this, event.time - previousEvent.time)
val emoji = previousEvent.getTypeEmoji(applicationContext)
val time = DateUtils.formatTimeDuration(applicationContext, event.time - previousEvent.time)
previousTextView.text = String.format("⬅️ %s %s", emoji, time)
previousTextView.setOnClickListener {
alertDialog.cancel()
@@ -648,12 +639,9 @@ 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(this)
val time = DateUtils.formatTimeDuration(this, nextEvent.time - event.time)
val emoji = nextEvent.getTypeEmoji(applicationContext)
val time = DateUtils.formatTimeDuration(applicationContext, nextEvent.time - event.time)
nextTextView.text = String.format("%s %s ➡️", time, emoji)
nextTextView.setOnClickListener {
alertDialog.cancel()
@@ -662,6 +650,15 @@ 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) {
@@ -765,7 +762,7 @@ class MainActivity : AppCompatActivity() {
runOnUiThread({
setLoading(false)
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)
Toast.makeText(
applicationContext,
this@MainActivity,
if (lastEventAdded != null)
R.string.toast_event_added
else
@@ -984,7 +981,7 @@ class MainActivity : AppCompatActivity() {
runOnUiThread({
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()
savingEvent(false)
})

View File

@@ -1,6 +1,5 @@
<?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,6 +15,8 @@
<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>