From 96cf5d2105127f4e0349556449f498abbe58e905 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 24 Aug 2020 14:32:43 +0200 Subject: [PATCH] Cleanup: propoerly inject things to PushRulesFragment and move PushRulesController to its own file --- .../im/vector/app/core/di/FragmentModule.kt | 6 +++ .../settings/push/PushRulesController.kt | 44 +++++++++++++++++++ .../settings/push/PushRulesFragment.kt | 29 ++---------- 3 files changed, 54 insertions(+), 25 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/features/settings/push/PushRulesController.kt diff --git a/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt b/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt index 1aa9902137..591d1c0474 100644 --- a/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt +++ b/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt @@ -102,6 +102,7 @@ import im.vector.app.features.settings.devtools.OutgoingKeyRequestListFragment import im.vector.app.features.settings.ignored.VectorSettingsIgnoredUsersFragment import im.vector.app.features.settings.locale.LocalePickerFragment import im.vector.app.features.settings.push.PushGatewaysFragment +import im.vector.app.features.settings.push.PushRulesFragment import im.vector.app.features.share.IncomingShareFragment import im.vector.app.features.signout.soft.SoftLogoutFragment import im.vector.app.features.terms.ReviewTermsFragment @@ -282,6 +283,11 @@ interface FragmentModule { @FragmentKey(VectorSettingsLabsFragment::class) fun bindVectorSettingsLabsFragment(fragment: VectorSettingsLabsFragment): Fragment + @Binds + @IntoMap + @FragmentKey(PushRulesFragment::class) + fun bindPushRulesFragment(fragment: PushRulesFragment): Fragment + @Binds @IntoMap @FragmentKey(VectorSettingsPreferencesFragment::class) diff --git a/vector/src/main/java/im/vector/app/features/settings/push/PushRulesController.kt b/vector/src/main/java/im/vector/app/features/settings/push/PushRulesController.kt new file mode 100644 index 0000000000..a8a1ab2e17 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/settings/push/PushRulesController.kt @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 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.push + +import com.airbnb.epoxy.TypedEpoxyController +import im.vector.app.R +import im.vector.app.core.resources.StringProvider +import im.vector.app.core.ui.list.genericFooterItem +import javax.inject.Inject + +class PushRulesController @Inject constructor( + private val stringProvider: StringProvider +) : TypedEpoxyController() { + + override fun buildModels(data: PushRulesViewState?) { + data?.let { + it.rules.forEach { + pushRuleItem { + id(it.ruleId) + pushRule(it) + } + } + } ?: run { + genericFooterItem { + id("footer") + text(stringProvider.getString(R.string.settings_push_rules_no_rules)) + } + } + } +} diff --git a/vector/src/main/java/im/vector/app/features/settings/push/PushRulesFragment.kt b/vector/src/main/java/im/vector/app/features/settings/push/PushRulesFragment.kt index 44cb5d8ea2..c361e21254 100644 --- a/vector/src/main/java/im/vector/app/features/settings/push/PushRulesFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/push/PushRulesFragment.kt @@ -17,7 +17,6 @@ package im.vector.app.features.settings.push import android.os.Bundle import android.view.View -import com.airbnb.epoxy.TypedEpoxyController import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.app.R @@ -25,19 +24,18 @@ import im.vector.app.core.extensions.cleanup import im.vector.app.core.extensions.configureWith import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.platform.VectorBaseFragment -import im.vector.app.core.resources.StringProvider -import im.vector.app.core.ui.list.genericFooterItem import kotlinx.android.synthetic.main.fragment_generic_recycler.* +import javax.inject.Inject // Referenced in vector_settings_notifications.xml -class PushRulesFragment : VectorBaseFragment() { +class PushRulesFragment @Inject constructor( + private val epoxyController: PushRulesController +) : VectorBaseFragment() { override fun getLayoutResId() = R.layout.fragment_generic_recycler private val viewModel: PushRulesViewModel by fragmentViewModel(PushRulesViewModel::class) - private val epoxyController by lazy { PushRulesController(StringProvider(requireContext().resources)) } - override fun onResume() { super.onResume() (activity as? VectorBaseActivity)?.supportActionBar?.setTitle(R.string.settings_push_rules) @@ -56,23 +54,4 @@ class PushRulesFragment : VectorBaseFragment() { override fun invalidate() = withState(viewModel) { state -> epoxyController.setData(state) } - - class PushRulesController(private val stringProvider: StringProvider) : TypedEpoxyController() { - - override fun buildModels(data: PushRulesViewState?) { - data?.let { - it.rules.forEach { - pushRuleItem { - id(it.ruleId) - pushRule(it) - } - } - } ?: run { - genericFooterItem { - id("footer") - text(stringProvider.getString(R.string.settings_push_rules_no_rules)) - } - } - } - } }