diff --git a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt index 5136186..a600c8d 100644 --- a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt +++ b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt @@ -83,7 +83,7 @@ class MainActivity : AppCompatActivity() { recyclerView.adapter = adapter // Set listeners - findViewById(R.id.logbooks_add_button).setOnClickListener { showAddLogbookDialog() } + findViewById(R.id.logbooks_add_button).setOnClickListener { showAddLogbookDialog(true) } findViewById(R.id.button_bottle).setOnClickListener { askBabyBottleContent() } findViewById(R.id.button_scale).setOnClickListener { askWeightValue() } findViewById(R.id.button_nipple_left).setOnClickListener { logEvent( @@ -311,14 +311,22 @@ class MainActivity : AppCompatActivity() { alertDialog.show() } - fun showAddLogbookDialog() { + fun showAddLogbookDialog(requestedByUser: Boolean) { val d = AlertDialog.Builder(this) d.setTitle(R.string.dialog_add_logbook_title) val dialogView = layoutInflater.inflate(R.layout.dialog_add_logbook, null) + dialogView.findViewById(R.id.dialog_add_logbook_message).text = getString( + if (requestedByUser) R.string.dialog_add_logbook_message else R.string.dialog_add_logbook_message_intro + ) val logbookNameEditText = dialogView.findViewById(R.id.dialog_add_logbook_logbookname) d.setView(dialogView) d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> addLogbook(logbookNameEditText.text.toString()) } - d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() } + if (requestedByUser) { + d.setCancelable(true) + d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() } + } else { + d.setCancelable(false) + } val alertDialog = d.create() alertDialog.show() } @@ -328,6 +336,11 @@ class MainActivity : AppCompatActivity() { logbookRepo?.listLogbooks(this, object: LogbookListObtainedListener { override fun onLogbookListObtained(logbooksNames: ArrayList) { runOnUiThread({ + if (logbooksNames.isEmpty()) { + // First run, no logbook: create one + showAddLogbookDialog(false) + return@runOnUiThread + } // Show logbooks dropdown val spinner = findViewById(R.id.logbooks_spinner) val sAdapter = ArrayAdapter(this@MainActivity, android.R.layout.simple_spinner_item) diff --git a/app/src/main/java/it/danieleverducci/lunatracker/repository/FileLogbookRepository.kt b/app/src/main/java/it/danieleverducci/lunatracker/repository/FileLogbookRepository.kt index 7d38816..dbcdcfc 100644 --- a/app/src/main/java/it/danieleverducci/lunatracker/repository/FileLogbookRepository.kt +++ b/app/src/main/java/it/danieleverducci/lunatracker/repository/FileLogbookRepository.kt @@ -80,8 +80,10 @@ class FileLogbookRepository: LogbookRepository { } }) - if (logbooksFileNames == null || logbooksFileNames.isEmpty()) + if (logbooksFileNames == null || logbooksFileNames.isEmpty()) { listener.onLogbookListObtained(arrayListOf()) + return + } val logbooksNames = arrayListOf() logbooksFileNames.forEach { it -> diff --git a/app/src/main/res/layout/dialog_add_logbook.xml b/app/src/main/res/layout/dialog_add_logbook.xml index 74298e3..cccc9cd 100644 --- a/app/src/main/res/layout/dialog_add_logbook.xml +++ b/app/src/main/res/layout/dialog_add_logbook.xml @@ -6,6 +6,7 @@ android:padding="20dp"> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 66fa8bc..d5db0a4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -106,6 +106,7 @@ Add logbook 👶 Logbook name Write a name to identify this logbook. This name will appear on top of the screen and, if you use WebDAV, will be in the save file name as well. + Welcome! To use this app you need to create at least one logbook. You would probably want to call it with your child\'s name. 👶 My first logbook New logbook created: