Working ugly selector

This commit is contained in:
Daniele Verducci 2025-01-18 07:36:31 +01:00
parent 32fbeac079
commit ecbde64ca1

View File

@ -14,6 +14,8 @@ import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.children
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.progressindicator.LinearProgressIndicator import com.google.android.material.progressindicator.LinearProgressIndicator
@ -335,7 +337,12 @@ class MainActivity : AppCompatActivity() {
lbnButton.setText( lbnButton.setText(
if (lbn.isEmpty()) getString(R.string.default_logbook_name) else lbn if (lbn.isEmpty()) getString(R.string.default_logbook_name) else lbn
) )
lbnButton.setTag(lbn)
lbnButton.setOnClickListener({ lbnButton.setOnClickListener({
// Changed logbook: empty list
adapter.items.clear()
adapter.notifyDataSetChanged()
// Load logbook
loadLogbook(lbn) loadLogbook(lbn)
}) })
logbooksButtonsContainer.addView(lbnButton) logbooksButtonsContainer.addView(lbnButton)
@ -372,15 +379,13 @@ class MainActivity : AppCompatActivity() {
fun addLogbook(logbookName: String) { fun addLogbook(logbookName: String) {
this.logbook = Logbook(logbookName) this.logbook = Logbook(logbookName)
saveLogbook() saveLogbook()
loadLogbookList() loadLogbookList() // TODO: Does not reload logbooks buttons on top, why?
} }
fun loadLogbook(name: String = LogbookRepository.DEFAULT_LOGBOOK_NAME) { fun loadLogbook(name: String = LogbookRepository.DEFAULT_LOGBOOK_NAME) {
if (savingEvent) if (savingEvent)
return return
// TODO: Highlight logbook button
// Reset time counter // Reset time counter
handler.removeCallbacks(updateListRunnable) handler.removeCallbacks(updateListRunnable)
handler.postDelayed(updateListRunnable, UPDATE_EVERY_SECS*1000) handler.postDelayed(updateListRunnable, UPDATE_EVERY_SECS*1000)
@ -394,6 +399,7 @@ class MainActivity : AppCompatActivity() {
findViewById<View>(R.id.no_connection_screen).visibility = View.GONE findViewById<View>(R.id.no_connection_screen).visibility = View.GONE
logbook = lb logbook = lb
showLogbook() showLogbook()
selectLogbookButton(name)
if (DEBUG_CHECK_LOGBOOK_CONSISTENCY) { if (DEBUG_CHECK_LOGBOOK_CONSISTENCY) {
for (e in logbook.logs) { for (e in logbook.logs) {
@ -604,4 +610,20 @@ class MainActivity : AppCompatActivity() {
showingOverflowPopupWindow = true showingOverflowPopupWindow = true
} }
} }
private fun selectLogbookButton(logbookName: String) {
val logbooksButtonsContainer =
findViewById<ViewGroup>(R.id.logbooks_buttons_container)
for (lb in logbooksButtonsContainer.children) {
if (lb.tag != null && lb.tag.toString().equals(logbookName)) {
// Selected
lb.setBackgroundColor(ContextCompat.getColor(this, R.color.accent))
(lb as TextView).setTextColor(ContextCompat.getColor(this, R.color.black))
} else {
// Not selected
lb.setBackgroundColor(ContextCompat.getColor(this, R.color.transparent))
(lb as TextView).setTextColor(ContextCompat.getColor(this, R.color.accent))
}
}
}
} }