3 Commits

3 changed files with 32 additions and 15 deletions

View File

@ -12,8 +12,8 @@ android {
applicationId = "it.danieleverducci.lunatracker"
minSdk = 21
targetSdk = 34
versionCode = 2
versionName = "0.3"
versionCode = 3
versionName = "0.5"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

View File

@ -49,7 +49,7 @@ class MainActivity : AppCompatActivity() {
val DEBUG_CHECK_LOGBOOK_CONSISTENCY = false
}
lateinit var logbook: Logbook
var logbook: Logbook? = null
lateinit var adapter: LunaEventRecyclerAdapter
lateinit var progressIndicator: LinearProgressIndicator
lateinit var buttonsContainer: ViewGroup
@ -57,7 +57,8 @@ class MainActivity : AppCompatActivity() {
lateinit var handler: Handler
var savingEvent = false
val updateListRunnable: Runnable = Runnable {
loadLogbook(logbook.name)
if (logbook != null)
loadLogbook(logbook!!.name)
handler.postDelayed(updateListRunnable, 1000*60)
}
var logbookRepo: LogbookRepository? = null
@ -123,10 +124,11 @@ class MainActivity : AppCompatActivity() {
showSettings()
})
findViewById<View>(R.id.button_no_connection_retry).setOnClickListener({
// This may happen at start, when logbook is still null: better ask the logbook list
loadLogbookList()
})
findViewById<View>(R.id.button_sync).setOnClickListener({
loadLogbook(logbook.name)
loadLogbookList()
})
}
@ -137,8 +139,11 @@ class MainActivity : AppCompatActivity() {
fun showLogbook() {
// Show logbook
if (logbook == null)
Log.w(TAG, "showLogbook(): logbook is null!")
adapter.items.clear()
adapter.items.addAll(logbook.logs)
adapter.items.addAll(logbook?.logs ?: listOf())
adapter.notifyDataSetChanged()
}
@ -163,8 +168,13 @@ class MainActivity : AppCompatActivity() {
// Update list dates
adapter.notifyDataSetChanged()
// Reload data
loadLogbookList()
if (logbook != null) {
// Already running: reload data for currently selected logbook
loadLogbook(logbook!!.name)
} else {
// First start: load logbook list
loadLogbookList()
}
}
override fun onStop() {
@ -284,7 +294,7 @@ class MainActivity : AppCompatActivity() {
}
)
d.setPositiveButton(R.string.trim_logbook_dialog_button_ok) { dialogInterface, i ->
logbook.trim()
logbook?.trim()
saveLogbook()
}
d.setNegativeButton(R.string.trim_logbook_dialog_button_cancel) { dialogInterface, i ->
@ -307,7 +317,7 @@ class MainActivity : AppCompatActivity() {
)
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_notes).setText(event.notes)
d.setView(dialogView)
d.setPositiveButton(R.string.dialog_event_detail_save_button) { dialogInterface, i -> dialogInterface.dismiss() }
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> dialogInterface.dismiss() }
d.setNeutralButton(R.string.dialog_event_detail_delete_button) { dialogInterface, i -> deleteEvent(event) }
val alertDialog = d.create()
alertDialog.show()
@ -474,7 +484,7 @@ class MainActivity : AppCompatActivity() {
showLogbook()
if (DEBUG_CHECK_LOGBOOK_CONSISTENCY) {
for (e in logbook.logs) {
for (e in logbook?.logs ?: listOf()) {
val em = e.getTypeEmoji(this@MainActivity)
if (em == getString(R.string.event_unknown_type)) {
Log.e(TAG, "UNKNOWN: ${e.type}")
@ -538,11 +548,11 @@ class MainActivity : AppCompatActivity() {
recyclerView.smoothScrollToPosition(0)
setLoading(true)
logbook.logs.add(0, event)
logbook?.logs?.add(0, event)
saveLogbook(event)
// Check logbook size to avoid OOM errors
if (logbook.isTooBig()) {
if (logbook?.isTooBig() == true) {
askToTrimLogbook()
}
}
@ -555,7 +565,7 @@ class MainActivity : AppCompatActivity() {
// Update data
setLoading(true)
logbook.logs.remove(event)
logbook?.logs?.remove(event)
saveLogbook()
}
@ -564,7 +574,11 @@ class MainActivity : AppCompatActivity() {
* of error can be removed from the list.
*/
fun saveLogbook(lastEventAdded: LunaEvent? = null) {
logbookRepo?.saveLogbook(this, logbook, object: LogbookSavedListener{
if (logbook == null) {
Log.e(TAG, "Trying to save logbook, but logbook is null!")
return
}
logbookRepo?.saveLogbook(this, logbook!!, object: LogbookSavedListener{
override fun onLogbookSaved() {
Log.d(TAG, "Logbook saved")
runOnUiThread({

View File

@ -0,0 +1,3 @@
Multiple children support
Fixed interface in devices with big font size