sync bottom bar when customizing bottom bar and switch checkbox to toggles in mib logins

This commit is contained in:
2026-05-19 19:23:03 +05:00
parent b1e73533f6
commit 28e5878668
2 changed files with 32 additions and 10 deletions
@@ -248,6 +248,19 @@ class HomeActivity : AppCompatActivity() {
} }
menu.add(Menu.NONE, R.id.nav_more, 4, R.string.nav_more) menu.add(Menu.NONE, R.id.nav_more, 4, R.string.nav_more)
.setIcon(R.drawable.ic_nav_more) .setIcon(R.drawable.ic_nav_more)
// Restore selection to current destination after menu rebuild
val currentId = binding.navigationView.checkedItem?.itemId
if (currentId != null) {
val bottomNavIds = (0 until menu.size()).map { menu.getItem(it).itemId }.toSet()
val selectId = if (currentId in bottomNavIds) currentId
else if (R.id.nav_more in bottomNavIds) R.id.nav_more
else null
if (selectId != null) {
suppressBottomNavCallback = true
binding.bottomNavigation.selectedItemId = selectId
suppressBottomNavCallback = false
}
}
} }
fun applyNavLabelVisibility() { fun applyNavLabelVisibility() {
@@ -7,12 +7,12 @@ import android.view.Gravity
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.ImageView import android.widget.ImageView
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.materialswitch.MaterialSwitch
import sh.sar.basedbank.BasedBankApp import sh.sar.basedbank.BasedBankApp
import sh.sar.basedbank.R import sh.sar.basedbank.R
import sh.sar.basedbank.api.mib.MibProfile import sh.sar.basedbank.api.mib.MibProfile
@@ -195,8 +195,8 @@ class SettingsLoginsFragment : Fragment() {
}) })
} }
// Build checkbox rows — wired up after dialog.show() so we can reference the Save button // Build toggle rows — wired up after dialog.show() so we can reference the Save button
val checkboxRows = mibProfiles.map { p -> val toggleRows = mibProfiles.map { p ->
val row = LinearLayout(ctx).apply { val row = LinearLayout(ctx).apply {
orientation = LinearLayout.HORIZONTAL orientation = LinearLayout.HORIZONTAL
gravity = Gravity.CENTER_VERTICAL gravity = Gravity.CENTER_VERTICAL
@@ -219,11 +219,20 @@ class SettingsLoginsFragment : Fragment() {
alpha = 0.6f alpha = 0.6f
}) })
} }
val cb = CheckBox(ctx).apply { isChecked = p.profileId !in hidden } val toggle = MaterialSwitch(ctx).apply { isChecked = p.profileId !in hidden }
row.addView(textCol) row.addView(textCol)
row.addView(cb) row.addView(toggle)
container.addView(row) container.addView(row)
p to cb p to toggle
}
fun updateToggleStates(saveBtn: android.widget.Button) {
val visibleCount = mibProfiles.count { it.profileId !in hidden }
toggleRows.forEach { (p, toggle) ->
// Disable the sole remaining visible toggle so it can't be turned off
toggle.isEnabled = !(toggle.isChecked && visibleCount == 1)
}
saveBtn.isEnabled = hidden != originalHidden && visibleCount >= 1
} }
val dialog = MaterialAlertDialogBuilder(ctx) val dialog = MaterialAlertDialogBuilder(ctx)
@@ -238,12 +247,12 @@ class SettingsLoginsFragment : Fragment() {
val saveBtn = dialog.getButton(android.app.AlertDialog.BUTTON_POSITIVE) val saveBtn = dialog.getButton(android.app.AlertDialog.BUTTON_POSITIVE)
saveBtn.isEnabled = false saveBtn.isEnabled = false
updateToggleStates(saveBtn)
checkboxRows.forEach { (p, cb) -> toggleRows.forEach { (p, toggle) ->
cb.setOnCheckedChangeListener { _, checked -> toggle.setOnCheckedChangeListener { _, checked ->
if (checked) hidden.remove(p.profileId) else hidden.add(p.profileId) if (checked) hidden.remove(p.profileId) else hidden.add(p.profileId)
val atLeastOneVisible = mibProfiles.any { it.profileId !in hidden } updateToggleStates(saveBtn)
saveBtn.isEnabled = hidden != originalHidden && atLeastOneVisible
} }
} }