diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml index fe17d2ae21..05283fd7aa 100644 --- a/library/ui-strings/src/main/res/values/strings.xml +++ b/library/ui-strings/src/main/res/values/strings.xml @@ -3259,6 +3259,9 @@ Unverified Not ready for secure messaging Inactive - Inactive for %1$d days or longer + + Inactive for %1$d day or longer + Inactive for %1$d days or longer + diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/filter/DeviceManagerFilterBottomSheet.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/filter/DeviceManagerFilterBottomSheet.kt new file mode 100644 index 0000000000..4848f24b5f --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/filter/DeviceManagerFilterBottomSheet.kt @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.settings.devices.v2.filter + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import dagger.hilt.android.AndroidEntryPoint +import im.vector.app.R +import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment +import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment.ResultListener.Companion.RESULT_OK +import im.vector.app.databinding.BottomSheetDeviceManagerFilterBinding +import im.vector.app.features.settings.devices.v2.list.SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS + +@AndroidEntryPoint +class DeviceManagerFilterBottomSheet : VectorBaseBottomSheetDialogFragment() { + + override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetDeviceManagerFilterBinding { + return BottomSheetDeviceManagerFilterBinding.inflate(inflater, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + initFilterRadioGroup() + } + + private fun initFilterRadioGroup() { + views.filterOptionInactiveRadioButton.text = resources.getQuantityString( + R.plurals.device_manager_filter_option_inactive_description, + SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS, + SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS + ) + + views.filterOptionsRadioGroup.setOnCheckedChangeListener { _, checkedId -> + onFilterTypeChanged(checkedId) + } + } + + private fun onFilterTypeChanged(checkedId: Int) { + val filterType = when (checkedId) { + R.id.filterOptionAllSessionsRadioButton -> DeviceManagerFilterType.ALL_SESSIONS + R.id.filterOptionVerifiedRadioButton -> DeviceManagerFilterType.VERIFIED + R.id.filterOptionUnverifiedRadioButton -> DeviceManagerFilterType.UNVERIFIED + R.id.filterOptionInactiveRadioButton -> DeviceManagerFilterType.INACTIVE + else -> DeviceManagerFilterType.ALL_SESSIONS + } + resultListener?.onBottomSheetResult(RESULT_OK, filterType) + dismiss() + } + + companion object { + fun newInstance(resultListener: ResultListener): DeviceManagerFilterBottomSheet { + val bottomSheet = DeviceManagerFilterBottomSheet() + bottomSheet.resultListener = resultListener + return bottomSheet + } + } +} diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/filter/DeviceManagerFilterType.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/filter/DeviceManagerFilterType.kt new file mode 100644 index 0000000000..a1ef08f7df --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/filter/DeviceManagerFilterType.kt @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.settings.devices.v2.filter + +enum class DeviceManagerFilterType { + ALL_SESSIONS, + VERIFIED, + UNVERIFIED, + INACTIVE, +}