Cleanup: propoerly inject things to PushRulesFragment and move PushRulesController to its own file
This commit is contained in:
parent
f745e22a52
commit
96cf5d2105
|
@ -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.ignored.VectorSettingsIgnoredUsersFragment
|
||||||
import im.vector.app.features.settings.locale.LocalePickerFragment
|
import im.vector.app.features.settings.locale.LocalePickerFragment
|
||||||
import im.vector.app.features.settings.push.PushGatewaysFragment
|
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.share.IncomingShareFragment
|
||||||
import im.vector.app.features.signout.soft.SoftLogoutFragment
|
import im.vector.app.features.signout.soft.SoftLogoutFragment
|
||||||
import im.vector.app.features.terms.ReviewTermsFragment
|
import im.vector.app.features.terms.ReviewTermsFragment
|
||||||
|
@ -282,6 +283,11 @@ interface FragmentModule {
|
||||||
@FragmentKey(VectorSettingsLabsFragment::class)
|
@FragmentKey(VectorSettingsLabsFragment::class)
|
||||||
fun bindVectorSettingsLabsFragment(fragment: VectorSettingsLabsFragment): Fragment
|
fun bindVectorSettingsLabsFragment(fragment: VectorSettingsLabsFragment): Fragment
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
@IntoMap
|
||||||
|
@FragmentKey(PushRulesFragment::class)
|
||||||
|
fun bindPushRulesFragment(fragment: PushRulesFragment): Fragment
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
@IntoMap
|
@IntoMap
|
||||||
@FragmentKey(VectorSettingsPreferencesFragment::class)
|
@FragmentKey(VectorSettingsPreferencesFragment::class)
|
||||||
|
|
|
@ -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<PushRulesViewState>() {
|
||||||
|
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,7 +17,6 @@ package im.vector.app.features.settings.push
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.airbnb.epoxy.TypedEpoxyController
|
|
||||||
import com.airbnb.mvrx.fragmentViewModel
|
import com.airbnb.mvrx.fragmentViewModel
|
||||||
import com.airbnb.mvrx.withState
|
import com.airbnb.mvrx.withState
|
||||||
import im.vector.app.R
|
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.extensions.configureWith
|
||||||
import im.vector.app.core.platform.VectorBaseActivity
|
import im.vector.app.core.platform.VectorBaseActivity
|
||||||
import im.vector.app.core.platform.VectorBaseFragment
|
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 kotlinx.android.synthetic.main.fragment_generic_recycler.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
// Referenced in vector_settings_notifications.xml
|
// 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
|
override fun getLayoutResId() = R.layout.fragment_generic_recycler
|
||||||
|
|
||||||
private val viewModel: PushRulesViewModel by fragmentViewModel(PushRulesViewModel::class)
|
private val viewModel: PushRulesViewModel by fragmentViewModel(PushRulesViewModel::class)
|
||||||
|
|
||||||
private val epoxyController by lazy { PushRulesController(StringProvider(requireContext().resources)) }
|
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
(activity as? VectorBaseActivity)?.supportActionBar?.setTitle(R.string.settings_push_rules)
|
(activity as? VectorBaseActivity)?.supportActionBar?.setTitle(R.string.settings_push_rules)
|
||||||
|
@ -56,23 +54,4 @@ class PushRulesFragment : VectorBaseFragment() {
|
||||||
override fun invalidate() = withState(viewModel) { state ->
|
override fun invalidate() = withState(viewModel) { state ->
|
||||||
epoxyController.setData(state)
|
epoxyController.setData(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
class PushRulesController(private val stringProvider: StringProvider) : TypedEpoxyController<PushRulesViewState>() {
|
|
||||||
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue