sync bottom bar when customizing bottom bar and switch checkbox to toggles in mib logins
All checks were successful
Auto Tag on Version Change / check-version (push) Successful in 14s
All checks were successful
Auto Tag on Version Change / check-version (push) Successful in 14s
This commit is contained in:
@@ -248,6 +248,19 @@ class HomeActivity : AppCompatActivity() {
|
||||
}
|
||||
menu.add(Menu.NONE, R.id.nav_more, 4, R.string.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() {
|
||||
|
||||
@@ -7,12 +7,12 @@ import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.CheckBox
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.materialswitch.MaterialSwitch
|
||||
import sh.sar.basedbank.BasedBankApp
|
||||
import sh.sar.basedbank.R
|
||||
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
|
||||
val checkboxRows = mibProfiles.map { p ->
|
||||
// Build toggle rows — wired up after dialog.show() so we can reference the Save button
|
||||
val toggleRows = mibProfiles.map { p ->
|
||||
val row = LinearLayout(ctx).apply {
|
||||
orientation = LinearLayout.HORIZONTAL
|
||||
gravity = Gravity.CENTER_VERTICAL
|
||||
@@ -219,11 +219,20 @@ class SettingsLoginsFragment : Fragment() {
|
||||
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(cb)
|
||||
row.addView(toggle)
|
||||
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)
|
||||
@@ -238,12 +247,12 @@ class SettingsLoginsFragment : Fragment() {
|
||||
|
||||
val saveBtn = dialog.getButton(android.app.AlertDialog.BUTTON_POSITIVE)
|
||||
saveBtn.isEnabled = false
|
||||
updateToggleStates(saveBtn)
|
||||
|
||||
checkboxRows.forEach { (p, cb) ->
|
||||
cb.setOnCheckedChangeListener { _, checked ->
|
||||
toggleRows.forEach { (p, toggle) ->
|
||||
toggle.setOnCheckedChangeListener { _, checked ->
|
||||
if (checked) hidden.remove(p.profileId) else hidden.add(p.profileId)
|
||||
val atLeastOneVisible = mibProfiles.any { it.profileId !in hidden }
|
||||
saveBtn.isEnabled = hidden != originalHidden && atLeastOneVisible
|
||||
updateToggleStates(saveBtn)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user