forked from penguin86/luna-tracker
MainActivity: small code cleanup
This commit is contained in:
@@ -74,9 +74,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// Show view
|
// Show view
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
progressIndicator = findViewById<LinearProgressIndicator>(R.id.progress_indicator)
|
progressIndicator = findViewById(R.id.progress_indicator)
|
||||||
buttonsContainer = findViewById<ViewGroup>(R.id.buttons_container)
|
buttonsContainer = findViewById(R.id.buttons_container)
|
||||||
recyclerView = findViewById<RecyclerView>(R.id.list_events)
|
recyclerView = findViewById(R.id.list_events)
|
||||||
recyclerView.setLayoutManager(LinearLayoutManager(applicationContext))
|
recyclerView.setLayoutManager(LinearLayoutManager(applicationContext))
|
||||||
|
|
||||||
// Set listeners
|
// Set listeners
|
||||||
@@ -311,22 +311,21 @@ class MainActivity : AppCompatActivity() {
|
|||||||
fun showEventDetailDialog(event: LunaEvent) {
|
fun showEventDetailDialog(event: LunaEvent) {
|
||||||
// Do not update list while the detail is shown, to avoid changing the object below while it is changed by the user
|
// Do not update list while the detail is shown, to avoid changing the object below while it is changed by the user
|
||||||
pauseLogbookUpdate = true
|
pauseLogbookUpdate = true
|
||||||
val dateFormat = DateFormat.getDateTimeInstance();
|
val dateFormat = DateFormat.getDateTimeInstance()
|
||||||
val d = AlertDialog.Builder(this)
|
val d = AlertDialog.Builder(this)
|
||||||
d.setTitle(R.string.dialog_event_detail_title)
|
d.setTitle(R.string.dialog_event_detail_title)
|
||||||
val dialogView = layoutInflater.inflate(R.layout.dialog_event_detail, null)
|
val dialogView = layoutInflater.inflate(R.layout.dialog_event_detail, null)
|
||||||
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_emoji).setText(event.getTypeEmoji(this))
|
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_emoji).text = event.getTypeEmoji(this)
|
||||||
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_description).setText(event.getTypeDescription(this))
|
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_description).text = event.getTypeDescription(this)
|
||||||
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_quantity).setText(
|
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_quantity).text =
|
||||||
NumericUtils(this).formatEventQuantity(event)
|
NumericUtils(this).formatEventQuantity(event)
|
||||||
)
|
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_notes).text = event.notes
|
||||||
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_notes).setText(event.notes)
|
|
||||||
|
|
||||||
val currentDateTime = Calendar.getInstance()
|
val currentDateTime = Calendar.getInstance()
|
||||||
currentDateTime.time = Date(event.time * 1000)
|
currentDateTime.time = Date(event.time * 1000)
|
||||||
val dateTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_date)
|
val dateTextView = dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_date)
|
||||||
dateTextView.text = String.format(getString(R.string.dialog_event_detail_datetime_icon), dateFormat.format(currentDateTime.time))
|
dateTextView.text = String.format(getString(R.string.dialog_event_detail_datetime_icon), dateFormat.format(currentDateTime.time))
|
||||||
dateTextView.setOnClickListener({
|
dateTextView.setOnClickListener {
|
||||||
// Show datetime picker
|
// Show datetime picker
|
||||||
val startYear = currentDateTime.get(Calendar.YEAR)
|
val startYear = currentDateTime.get(Calendar.YEAR)
|
||||||
val startMonth = currentDateTime.get(Calendar.MONTH)
|
val startMonth = currentDateTime.get(Calendar.MONTH)
|
||||||
@@ -334,8 +333,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val startHour = currentDateTime.get(Calendar.HOUR_OF_DAY)
|
val startHour = currentDateTime.get(Calendar.HOUR_OF_DAY)
|
||||||
val startMinute = currentDateTime.get(Calendar.MINUTE)
|
val startMinute = currentDateTime.get(Calendar.MINUTE)
|
||||||
|
|
||||||
DatePickerDialog(this, DatePickerDialog.OnDateSetListener { _, year, month, day ->
|
DatePickerDialog(this, { _, year, month, day ->
|
||||||
TimePickerDialog(this, TimePickerDialog.OnTimeSetListener { _, hour, minute ->
|
TimePickerDialog(this, { _, hour, minute ->
|
||||||
val pickedDateTime = Calendar.getInstance()
|
val pickedDateTime = Calendar.getInstance()
|
||||||
pickedDateTime.set(year, month, day, hour, minute)
|
pickedDateTime.set(year, month, day, hour, minute)
|
||||||
currentDateTime.time = pickedDateTime.time
|
currentDateTime.time = pickedDateTime.time
|
||||||
@@ -348,7 +347,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
saveLogbook()
|
saveLogbook()
|
||||||
}, startHour, startMinute, false).show()
|
}, startHour, startMinute, false).show()
|
||||||
}, startYear, startMonth, startDay).show()
|
}, startYear, startMonth, startDay).show()
|
||||||
})
|
}
|
||||||
|
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
d.setPositiveButton(R.string.dialog_event_detail_close_button) { dialogInterface, i -> dialogInterface.dismiss() }
|
d.setPositiveButton(R.string.dialog_event_detail_close_button) { dialogInterface, i -> dialogInterface.dismiss() }
|
||||||
@@ -398,7 +397,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
sAdapter.setDropDownViewResource(R.layout.row_logbook_spinner)
|
sAdapter.setDropDownViewResource(R.layout.row_logbook_spinner)
|
||||||
for (ln in logbooksNames) {
|
for (ln in logbooksNames) {
|
||||||
sAdapter.add(
|
sAdapter.add(
|
||||||
if (ln.isEmpty()) getString(R.string.default_logbook_name) else ln
|
ln.ifEmpty { getString(R.string.default_logbook_name) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
spinner.adapter = sAdapter
|
spinner.adapter = sAdapter
|
||||||
@@ -416,7 +415,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onNothingSelected(parent: AdapterView<*>?) {}
|
override fun onNothingSelected(parent: AdapterView<*>?) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -566,7 +564,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
onRepoError(getString(R.string.settings_generic_error) + error.toString())
|
onRepoError(getString(R.string.settings_generic_error) + error.toString())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -714,10 +711,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
isOutsideTouchable = true
|
isOutsideTouchable = true
|
||||||
val inflater = LayoutInflater.from(anchor.context)
|
val inflater = LayoutInflater.from(anchor.context)
|
||||||
contentView = inflater.inflate(R.layout.more_events_popup, null)
|
contentView = inflater.inflate(R.layout.more_events_popup, null)
|
||||||
contentView.findViewById<View>(R.id.button_medicine).setOnClickListener({
|
contentView.findViewById<View>(R.id.button_medicine).setOnClickListener {
|
||||||
askNotes(LunaEvent(LunaEvent.TYPE_MEDICINE))
|
askNotes(LunaEvent(LunaEvent.TYPE_MEDICINE))
|
||||||
dismiss()
|
dismiss()
|
||||||
})
|
}
|
||||||
contentView.findViewById<View>(R.id.button_enema).setOnClickListener({
|
contentView.findViewById<View>(R.id.button_enema).setOnClickListener({
|
||||||
logEvent(LunaEvent(LunaEvent.TYPE_ENEMA))
|
logEvent(LunaEvent(LunaEvent.TYPE_ENEMA))
|
||||||
dismiss()
|
dismiss()
|
||||||
|
Reference in New Issue
Block a user