forked from penguin86/luna-tracker
		
	Onboarding, fix in logbook list from file repo
This commit is contained in:
		@@ -83,7 +83,7 @@ class MainActivity : AppCompatActivity() {
 | 
				
			|||||||
        recyclerView.adapter = adapter
 | 
					        recyclerView.adapter = adapter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Set listeners
 | 
					        // Set listeners
 | 
				
			||||||
        findViewById<View>(R.id.logbooks_add_button).setOnClickListener { showAddLogbookDialog() }
 | 
					        findViewById<View>(R.id.logbooks_add_button).setOnClickListener { showAddLogbookDialog(true) }
 | 
				
			||||||
        findViewById<View>(R.id.button_bottle).setOnClickListener { askBabyBottleContent() }
 | 
					        findViewById<View>(R.id.button_bottle).setOnClickListener { askBabyBottleContent() }
 | 
				
			||||||
        findViewById<View>(R.id.button_scale).setOnClickListener { askWeightValue() }
 | 
					        findViewById<View>(R.id.button_scale).setOnClickListener { askWeightValue() }
 | 
				
			||||||
        findViewById<View>(R.id.button_nipple_left).setOnClickListener { logEvent(
 | 
					        findViewById<View>(R.id.button_nipple_left).setOnClickListener { logEvent(
 | 
				
			||||||
@@ -311,14 +311,22 @@ class MainActivity : AppCompatActivity() {
 | 
				
			|||||||
        alertDialog.show()
 | 
					        alertDialog.show()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fun showAddLogbookDialog() {
 | 
					    fun showAddLogbookDialog(requestedByUser: Boolean) {
 | 
				
			||||||
        val d = AlertDialog.Builder(this)
 | 
					        val d = AlertDialog.Builder(this)
 | 
				
			||||||
        d.setTitle(R.string.dialog_add_logbook_title)
 | 
					        d.setTitle(R.string.dialog_add_logbook_title)
 | 
				
			||||||
        val dialogView = layoutInflater.inflate(R.layout.dialog_add_logbook, null)
 | 
					        val dialogView = layoutInflater.inflate(R.layout.dialog_add_logbook, null)
 | 
				
			||||||
 | 
					        dialogView.findViewById<TextView>(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<EditText>(R.id.dialog_add_logbook_logbookname)
 | 
					        val logbookNameEditText = dialogView.findViewById<EditText>(R.id.dialog_add_logbook_logbookname)
 | 
				
			||||||
        d.setView(dialogView)
 | 
					        d.setView(dialogView)
 | 
				
			||||||
        d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> addLogbook(logbookNameEditText.text.toString()) }
 | 
					        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()
 | 
					        val alertDialog = d.create()
 | 
				
			||||||
        alertDialog.show()
 | 
					        alertDialog.show()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -328,6 +336,11 @@ class MainActivity : AppCompatActivity() {
 | 
				
			|||||||
        logbookRepo?.listLogbooks(this, object: LogbookListObtainedListener {
 | 
					        logbookRepo?.listLogbooks(this, object: LogbookListObtainedListener {
 | 
				
			||||||
            override fun onLogbookListObtained(logbooksNames: ArrayList<String>) {
 | 
					            override fun onLogbookListObtained(logbooksNames: ArrayList<String>) {
 | 
				
			||||||
                runOnUiThread({
 | 
					                runOnUiThread({
 | 
				
			||||||
 | 
					                    if (logbooksNames.isEmpty()) {
 | 
				
			||||||
 | 
					                        // First run, no logbook: create one
 | 
				
			||||||
 | 
					                        showAddLogbookDialog(false)
 | 
				
			||||||
 | 
					                        return@runOnUiThread
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                    // Show logbooks dropdown
 | 
					                    // Show logbooks dropdown
 | 
				
			||||||
                    val spinner = findViewById<Spinner>(R.id.logbooks_spinner)
 | 
					                    val spinner = findViewById<Spinner>(R.id.logbooks_spinner)
 | 
				
			||||||
                    val sAdapter = ArrayAdapter<String>(this@MainActivity, android.R.layout.simple_spinner_item)
 | 
					                    val sAdapter = ArrayAdapter<String>(this@MainActivity, android.R.layout.simple_spinner_item)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -80,8 +80,10 @@ class FileLogbookRepository: LogbookRepository {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (logbooksFileNames == null || logbooksFileNames.isEmpty())
 | 
					        if (logbooksFileNames == null || logbooksFileNames.isEmpty()) {
 | 
				
			||||||
            listener.onLogbookListObtained(arrayListOf())
 | 
					            listener.onLogbookListObtained(arrayListOf())
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        val logbooksNames = arrayListOf<String>()
 | 
					        val logbooksNames = arrayListOf<String>()
 | 
				
			||||||
        logbooksFileNames.forEach { it ->
 | 
					        logbooksFileNames.forEach { it ->
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@
 | 
				
			|||||||
    android:padding="20dp">
 | 
					    android:padding="20dp">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <TextView
 | 
					    <TextView
 | 
				
			||||||
 | 
					        android:id="@+id/dialog_add_logbook_message"
 | 
				
			||||||
        android:layout_width="match_parent"
 | 
					        android:layout_width="match_parent"
 | 
				
			||||||
        android:layout_height="wrap_content"
 | 
					        android:layout_height="wrap_content"
 | 
				
			||||||
        android:text="@string/dialog_add_logbook_message"/>
 | 
					        android:text="@string/dialog_add_logbook_message"/>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -106,6 +106,7 @@
 | 
				
			|||||||
    <string name="dialog_add_logbook_title">Add logbook</string>
 | 
					    <string name="dialog_add_logbook_title">Add logbook</string>
 | 
				
			||||||
    <string name="dialog_add_logbook_logbookname">👶 Logbook name</string>
 | 
					    <string name="dialog_add_logbook_logbookname">👶 Logbook name</string>
 | 
				
			||||||
    <string name="dialog_add_logbook_message">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.</string>
 | 
					    <string name="dialog_add_logbook_message">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.</string>
 | 
				
			||||||
 | 
					    <string name="dialog_add_logbook_message_intro">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.</string>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <string name="default_logbook_name">👶 My first logbook</string>
 | 
					    <string name="default_logbook_name">👶 My first logbook</string>
 | 
				
			||||||
    <string name="logbook_created">New logbook created: </string>
 | 
					    <string name="logbook_created">New logbook created: </string>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user