Keep initial filter type on bottom sheet.

This commit is contained in:
Onuray Sahin 2022-09-08 19:25:11 +03:00
parent 41ca662dcc
commit 11079afa6b
2 changed files with 28 additions and 7 deletions

View File

@ -17,19 +17,29 @@
package im.vector.app.features.settings.devices.v2.filter package im.vector.app.features.settings.devices.v2.filter
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable
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 com.airbnb.mvrx.args
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment.ResultListener.Companion.RESULT_OK import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment.ResultListener.Companion.RESULT_OK
import im.vector.app.databinding.BottomSheetDeviceManagerFilterBinding import im.vector.app.databinding.BottomSheetDeviceManagerFilterBinding
import im.vector.app.features.settings.devices.v2.list.SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS import im.vector.app.features.settings.devices.v2.list.SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS
import kotlinx.parcelize.Parcelize
@Parcelize
data class DeviceManagerFilterBottomSheetArgs(
val initialFilterType: DeviceManagerFilterType,
) : Parcelable
@AndroidEntryPoint @AndroidEntryPoint
class DeviceManagerFilterBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetDeviceManagerFilterBinding>() { class DeviceManagerFilterBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetDeviceManagerFilterBinding>() {
private val args: DeviceManagerFilterBottomSheetArgs by args()
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetDeviceManagerFilterBinding { override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetDeviceManagerFilterBinding {
return BottomSheetDeviceManagerFilterBinding.inflate(inflater, container, false) return BottomSheetDeviceManagerFilterBinding.inflate(inflater, container, false)
} }
@ -46,6 +56,14 @@ class DeviceManagerFilterBottomSheet : VectorBaseBottomSheetDialogFragment<Botto
SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS
) )
val radioButtonId = when (args.initialFilterType) {
DeviceManagerFilterType.ALL_SESSIONS -> R.id.filterOptionAllSessionsRadioButton
DeviceManagerFilterType.VERIFIED -> R.id.filterOptionVerifiedRadioButton
DeviceManagerFilterType.UNVERIFIED -> R.id.filterOptionUnverifiedRadioButton
DeviceManagerFilterType.INACTIVE -> R.id.filterOptionInactiveRadioButton
}
views.filterOptionsRadioGroup.check(radioButtonId)
views.filterOptionsRadioGroup.setOnCheckedChangeListener { _, checkedId -> views.filterOptionsRadioGroup.setOnCheckedChangeListener { _, checkedId ->
onFilterTypeChanged(checkedId) onFilterTypeChanged(checkedId)
} }
@ -64,10 +82,11 @@ class DeviceManagerFilterBottomSheet : VectorBaseBottomSheetDialogFragment<Botto
} }
companion object { companion object {
fun newInstance(resultListener: ResultListener): DeviceManagerFilterBottomSheet { fun newInstance(initialFilterType: DeviceManagerFilterType, resultListener: ResultListener): DeviceManagerFilterBottomSheet {
val bottomSheet = DeviceManagerFilterBottomSheet() return DeviceManagerFilterBottomSheet().apply {
bottomSheet.resultListener = resultListener this.resultListener = resultListener
return bottomSheet setArguments(DeviceManagerFilterBottomSheetArgs(initialFilterType))
}
} }
} }
} }

View File

@ -58,9 +58,11 @@ class OtherSessionsFragment : VectorBaseFragment<FragmentOtherSessionsBinding>()
private fun initFilterView() { private fun initFilterView() {
views.otherSessionsFilterFrameLayout.debouncedClicks { views.otherSessionsFilterFrameLayout.debouncedClicks {
DeviceManagerFilterBottomSheet withState(viewModel) { state ->
.newInstance(this) DeviceManagerFilterBottomSheet
.show(requireActivity().supportFragmentManager, "SHOW_DEVICE_MANAGER_FILTER_BOTTOM_SHEET") .newInstance(state.currentFilter, this)
.show(requireActivity().supportFragmentManager, "SHOW_DEVICE_MANAGER_FILTER_BOTTOM_SHEET")
}
} }
} }