Extract displaymode, clear adapter on roomList/timeline and use commitNow when possible

This commit is contained in:
ganfra 2019-11-12 15:13:20 +01:00
parent 6463f3439f
commit 19b415871d
22 changed files with 169 additions and 111 deletions

View file

@ -21,31 +21,31 @@ import androidx.fragment.app.Fragment
import im.vector.riotx.core.platform.VectorBaseActivity import im.vector.riotx.core.platform.VectorBaseActivity
fun VectorBaseActivity.addFragment(frameId: Int, fragment: Fragment) { fun VectorBaseActivity.addFragment(frameId: Int, fragment: Fragment) {
supportFragmentManager.inTransaction { add(frameId, fragment) } supportFragmentManager.commitTransactionNow { add(frameId, fragment) }
} }
fun <T : Fragment> VectorBaseActivity.addFragment(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) { fun <T : Fragment> VectorBaseActivity.addFragment(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) {
supportFragmentManager.inTransaction { supportFragmentManager.commitTransactionNow {
add(frameId, fragmentClass, params.toMvRxBundle(), tag) add(frameId, fragmentClass, params.toMvRxBundle(), tag)
} }
} }
fun VectorBaseActivity.replaceFragment(frameId: Int, fragment: Fragment, tag: String? = null) { fun VectorBaseActivity.replaceFragment(frameId: Int, fragment: Fragment, tag: String? = null) {
supportFragmentManager.inTransaction { replace(frameId, fragment, tag) } supportFragmentManager.commitTransactionNow { replace(frameId, fragment, tag) }
} }
fun <T : Fragment> VectorBaseActivity.replaceFragment(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) { fun <T : Fragment> VectorBaseActivity.replaceFragment(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) {
supportFragmentManager.inTransaction { supportFragmentManager.commitTransactionNow {
replace(frameId, fragmentClass, params.toMvRxBundle(), tag) replace(frameId, fragmentClass, params.toMvRxBundle(), tag)
} }
} }
fun VectorBaseActivity.addFragmentToBackstack(frameId: Int, fragment: Fragment, tag: String? = null) { fun VectorBaseActivity.addFragmentToBackstack(frameId: Int, fragment: Fragment, tag: String? = null) {
supportFragmentManager.inTransaction { replace(frameId, fragment).addToBackStack(tag) } supportFragmentManager.commitTransaction { replace(frameId, fragment).addToBackStack(tag) }
} }
fun <T : Fragment> VectorBaseActivity.addFragmentToBackstack(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) { fun <T : Fragment> VectorBaseActivity.addFragmentToBackstack(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) {
supportFragmentManager.inTransaction { supportFragmentManager.commitTransaction {
replace(frameId, fragmentClass, params.toMvRxBundle(), tag).addToBackStack(tag) replace(frameId, fragmentClass, params.toMvRxBundle(), tag).addToBackStack(tag)
} }
} }

View file

@ -21,61 +21,61 @@ import androidx.fragment.app.Fragment
import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.platform.VectorBaseFragment
fun VectorBaseFragment.addFragment(frameId: Int, fragment: Fragment) { fun VectorBaseFragment.addFragment(frameId: Int, fragment: Fragment) {
parentFragmentManager.inTransaction { add(frameId, fragment) } parentFragmentManager.commitTransactionNow { add(frameId, fragment) }
} }
fun <T : Fragment> VectorBaseFragment.addFragment(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) { fun <T : Fragment> VectorBaseFragment.addFragment(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) {
parentFragmentManager.inTransaction { parentFragmentManager.commitTransactionNow {
add(frameId, fragmentClass, params.toMvRxBundle(), tag) add(frameId, fragmentClass, params.toMvRxBundle(), tag)
} }
} }
fun VectorBaseFragment.replaceFragment(frameId: Int, fragment: Fragment) { fun VectorBaseFragment.replaceFragment(frameId: Int, fragment: Fragment) {
parentFragmentManager.inTransaction { replace(frameId, fragment) } parentFragmentManager.commitTransactionNow { replace(frameId, fragment) }
} }
fun <T : Fragment> VectorBaseFragment.replaceFragment(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) { fun <T : Fragment> VectorBaseFragment.replaceFragment(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) {
parentFragmentManager.inTransaction { parentFragmentManager.commitTransactionNow {
replace(frameId, fragmentClass, params.toMvRxBundle(), tag) replace(frameId, fragmentClass, params.toMvRxBundle(), tag)
} }
} }
fun VectorBaseFragment.addFragmentToBackstack(frameId: Int, fragment: Fragment, tag: String? = null) { fun VectorBaseFragment.addFragmentToBackstack(frameId: Int, fragment: Fragment, tag: String? = null) {
parentFragmentManager.inTransaction { replace(frameId, fragment, tag).addToBackStack(tag) } parentFragmentManager.commitTransaction { replace(frameId, fragment, tag).addToBackStack(tag) }
} }
fun <T : Fragment> VectorBaseFragment.addFragmentToBackstack(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) { fun <T : Fragment> VectorBaseFragment.addFragmentToBackstack(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) {
parentFragmentManager.inTransaction { parentFragmentManager.commitTransaction {
replace(frameId, fragmentClass, params.toMvRxBundle(), tag).addToBackStack(tag) replace(frameId, fragmentClass, params.toMvRxBundle(), tag).addToBackStack(tag)
} }
} }
fun VectorBaseFragment.addChildFragment(frameId: Int, fragment: Fragment, tag: String? = null) { fun VectorBaseFragment.addChildFragment(frameId: Int, fragment: Fragment, tag: String? = null) {
childFragmentManager.inTransaction { add(frameId, fragment, tag) } childFragmentManager.commitTransactionNow { add(frameId, fragment, tag) }
} }
fun <T : Fragment> VectorBaseFragment.addChildFragment(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) { fun <T : Fragment> VectorBaseFragment.addChildFragment(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) {
childFragmentManager.inTransaction { childFragmentManager.commitTransactionNow {
add(frameId, fragmentClass, params.toMvRxBundle(), tag) add(frameId, fragmentClass, params.toMvRxBundle(), tag)
} }
} }
fun VectorBaseFragment.replaceChildFragment(frameId: Int, fragment: Fragment, tag: String? = null) { fun VectorBaseFragment.replaceChildFragment(frameId: Int, fragment: Fragment, tag: String? = null) {
childFragmentManager.inTransaction { replace(frameId, fragment, tag) } childFragmentManager.commitTransactionNow { replace(frameId, fragment, tag) }
} }
fun <T : Fragment> VectorBaseFragment.replaceChildFragment(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) { fun <T : Fragment> VectorBaseFragment.replaceChildFragment(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) {
childFragmentManager.inTransaction { childFragmentManager.commitTransactionNow {
replace(frameId, fragmentClass, params.toMvRxBundle(), tag) replace(frameId, fragmentClass, params.toMvRxBundle(), tag)
} }
} }
fun VectorBaseFragment.addChildFragmentToBackstack(frameId: Int, fragment: Fragment, tag: String? = null) { fun VectorBaseFragment.addChildFragmentToBackstack(frameId: Int, fragment: Fragment, tag: String? = null) {
childFragmentManager.inTransaction { replace(frameId, fragment).addToBackStack(tag) } childFragmentManager.commitTransaction { replace(frameId, fragment).addToBackStack(tag) }
} }
fun <T : Fragment> VectorBaseFragment.addChildFragmentToBackstack(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) { fun <T : Fragment> VectorBaseFragment.addChildFragmentToBackstack(frameId: Int, fragmentClass: Class<T>, params: Parcelable? = null, tag: String? = null) {
childFragmentManager.inTransaction { childFragmentManager.commitTransaction {
replace(frameId, fragmentClass, params.toMvRxBundle(), tag).addToBackStack(tag) replace(frameId, fragmentClass, params.toMvRxBundle(), tag).addToBackStack(tag)
} }
} }

View file

@ -18,6 +18,10 @@ package im.vector.riotx.core.extensions
import androidx.fragment.app.FragmentTransaction import androidx.fragment.app.FragmentTransaction
inline fun androidx.fragment.app.FragmentManager.inTransaction(func: FragmentTransaction.() -> FragmentTransaction) { inline fun androidx.fragment.app.FragmentManager.commitTransactionNow(func: FragmentTransaction.() -> FragmentTransaction) {
beginTransaction().func().commitNow()
}
inline fun androidx.fragment.app.FragmentManager.commitTransaction(func: FragmentTransaction.() -> FragmentTransaction) {
beginTransaction().func().commit() beginTransaction().func().commit()
} }

View file

@ -26,7 +26,7 @@ import im.vector.matrix.android.api.session.crypto.sas.IncomingSasVerificationTr
import im.vector.matrix.android.api.session.crypto.sas.OutgoingSasVerificationRequest import im.vector.matrix.android.api.session.crypto.sas.OutgoingSasVerificationRequest
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.extensions.inTransaction import im.vector.riotx.core.extensions.commitTransaction
import im.vector.riotx.core.extensions.observeEvent import im.vector.riotx.core.extensions.observeEvent
import im.vector.riotx.core.platform.SimpleFragmentActivity import im.vector.riotx.core.platform.SimpleFragmentActivity
import im.vector.riotx.core.platform.WaitingViewData import im.vector.riotx.core.platform.WaitingViewData
@ -102,20 +102,20 @@ class SASVerificationActivity : SimpleFragmentActivity() {
IncomingSasVerificationTransaction.UxState.SHOW_ACCEPT, IncomingSasVerificationTransaction.UxState.SHOW_ACCEPT,
IncomingSasVerificationTransaction.UxState.WAIT_FOR_KEY_AGREEMENT -> { IncomingSasVerificationTransaction.UxState.WAIT_FOR_KEY_AGREEMENT -> {
supportActionBar?.setTitle(R.string.sas_incoming_request_title) supportActionBar?.setTitle(R.string.sas_incoming_request_title)
supportFragmentManager.inTransaction { supportFragmentManager.commitTransaction {
setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out)
replace(R.id.container, SASVerificationIncomingFragment::class.java, null) replace(R.id.container, SASVerificationIncomingFragment::class.java, null)
} }
} }
IncomingSasVerificationTransaction.UxState.WAIT_FOR_VERIFICATION, IncomingSasVerificationTransaction.UxState.WAIT_FOR_VERIFICATION,
IncomingSasVerificationTransaction.UxState.SHOW_SAS -> { IncomingSasVerificationTransaction.UxState.SHOW_SAS -> {
supportFragmentManager.inTransaction { supportFragmentManager.commitTransaction {
setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out)
replace(R.id.container, SASVerificationShortCodeFragment::class.java, null) replace(R.id.container, SASVerificationShortCodeFragment::class.java, null)
} }
} }
IncomingSasVerificationTransaction.UxState.VERIFIED -> { IncomingSasVerificationTransaction.UxState.VERIFIED -> {
supportFragmentManager.inTransaction { supportFragmentManager.commitTransaction {
setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out)
replace(R.id.container, SASVerificationVerifiedFragment::class.java, null) replace(R.id.container, SASVerificationVerifiedFragment::class.java, null)
} }
@ -133,20 +133,20 @@ class SASVerificationActivity : SimpleFragmentActivity() {
OutgoingSasVerificationRequest.UxState.UNKNOWN, OutgoingSasVerificationRequest.UxState.UNKNOWN,
OutgoingSasVerificationRequest.UxState.WAIT_FOR_START, OutgoingSasVerificationRequest.UxState.WAIT_FOR_START,
OutgoingSasVerificationRequest.UxState.WAIT_FOR_KEY_AGREEMENT -> { OutgoingSasVerificationRequest.UxState.WAIT_FOR_KEY_AGREEMENT -> {
supportFragmentManager.inTransaction { supportFragmentManager.commitTransaction {
setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out)
replace(R.id.container, SASVerificationStartFragment::class.java, null) replace(R.id.container, SASVerificationStartFragment::class.java, null)
} }
} }
OutgoingSasVerificationRequest.UxState.SHOW_SAS, OutgoingSasVerificationRequest.UxState.SHOW_SAS,
OutgoingSasVerificationRequest.UxState.WAIT_FOR_VERIFICATION -> { OutgoingSasVerificationRequest.UxState.WAIT_FOR_VERIFICATION -> {
supportFragmentManager.inTransaction { supportFragmentManager.commitTransaction {
setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out)
replace(R.id.container, SASVerificationShortCodeFragment::class.java, null) replace(R.id.container, SASVerificationShortCodeFragment::class.java, null)
} }
} }
OutgoingSasVerificationRequest.UxState.VERIFIED -> { OutgoingSasVerificationRequest.UxState.VERIFIED -> {
supportFragmentManager.inTransaction { supportFragmentManager.commitTransaction {
setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out) setCustomAnimations(R.anim.no_anim, R.anim.exit_fade_out)
replace(R.id.container, SASVerificationVerifiedFragment::class.java, null) replace(R.id.container, SASVerificationVerifiedFragment::class.java, null)
} }
@ -172,13 +172,13 @@ class SASVerificationActivity : SimpleFragmentActivity() {
finish() finish()
} }
SasVerificationViewModel.NAVIGATE_SAS_DISPLAY -> { SasVerificationViewModel.NAVIGATE_SAS_DISPLAY -> {
supportFragmentManager.inTransaction { supportFragmentManager.commitTransaction {
setCustomAnimations(R.anim.enter_from_right, R.anim.exit_fade_out) setCustomAnimations(R.anim.enter_from_right, R.anim.exit_fade_out)
replace(R.id.container, SASVerificationShortCodeFragment::class.java, null) replace(R.id.container, SASVerificationShortCodeFragment::class.java, null)
} }
} }
SasVerificationViewModel.NAVIGATE_SUCCESS -> { SasVerificationViewModel.NAVIGATE_SUCCESS -> {
supportFragmentManager.inTransaction { supportFragmentManager.commitTransaction {
setCustomAnimations(R.anim.enter_from_right, R.anim.exit_fade_out) setCustomAnimations(R.anim.enter_from_right, R.anim.exit_fade_out)
replace(R.id.container, SASVerificationVerifiedFragment::class.java, null) replace(R.id.container, SASVerificationVerifiedFragment::class.java, null)
} }

View file

@ -20,5 +20,5 @@ import im.vector.riotx.core.platform.VectorViewModelAction
import im.vector.riotx.features.home.room.list.RoomListFragment import im.vector.riotx.features.home.room.list.RoomListFragment
sealed class HomeDetailAction : VectorViewModelAction { sealed class HomeDetailAction : VectorViewModelAction {
data class SwitchDisplayMode(val displayMode: RoomListFragment.DisplayMode) : HomeDetailAction() data class SwitchDisplayMode(val displayMode: RoomListDisplayMode) : HomeDetailAction()
} }

View file

@ -29,8 +29,8 @@ import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupState import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupState
import im.vector.matrix.android.api.session.group.model.GroupSummary import im.vector.matrix.android.api.session.group.model.GroupSummary
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.extensions.inTransaction import im.vector.riotx.core.extensions.commitTransaction
import im.vector.riotx.core.extensions.replaceChildFragment import im.vector.riotx.core.extensions.commitTransactionNow
import im.vector.riotx.core.platform.ToolbarConfigurable import im.vector.riotx.core.platform.ToolbarConfigurable
import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.core.ui.views.KeysBackupBanner import im.vector.riotx.core.ui.views.KeysBackupBanner
@ -134,10 +134,10 @@ class HomeDetailFragment @Inject constructor(
private fun setupBottomNavigationView() { private fun setupBottomNavigationView() {
bottomNavigationView.setOnNavigationItemSelectedListener { bottomNavigationView.setOnNavigationItemSelectedListener {
val displayMode = when (it.itemId) { val displayMode = when (it.itemId) {
R.id.bottom_action_home -> RoomListFragment.DisplayMode.HOME R.id.bottom_action_home -> RoomListDisplayMode.HOME
R.id.bottom_action_people -> RoomListFragment.DisplayMode.PEOPLE R.id.bottom_action_people -> RoomListDisplayMode.PEOPLE
R.id.bottom_action_rooms -> RoomListFragment.DisplayMode.ROOMS R.id.bottom_action_rooms -> RoomListDisplayMode.ROOMS
else -> RoomListFragment.DisplayMode.HOME else -> RoomListDisplayMode.HOME
} }
viewModel.handle(HomeDetailAction.SwitchDisplayMode(displayMode)) viewModel.handle(HomeDetailAction.SwitchDisplayMode(displayMode))
true true
@ -153,22 +153,26 @@ class HomeDetailFragment @Inject constructor(
} }
} }
private fun switchDisplayMode(displayMode: RoomListFragment.DisplayMode) { private fun switchDisplayMode(displayMode: RoomListDisplayMode) {
groupToolbarTitleView.setText(displayMode.titleRes) groupToolbarTitleView.setText(displayMode.titleRes)
updateSelectedFragment(displayMode) updateSelectedFragment(displayMode)
// Update the navigation view (for when we restore the tabs) // Update the navigation view (for when we restore the tabs)
bottomNavigationView.selectedItemId = when (displayMode) { bottomNavigationView.selectedItemId = when (displayMode) {
RoomListFragment.DisplayMode.PEOPLE -> R.id.bottom_action_people RoomListDisplayMode.PEOPLE -> R.id.bottom_action_people
RoomListFragment.DisplayMode.ROOMS -> R.id.bottom_action_rooms RoomListDisplayMode.ROOMS -> R.id.bottom_action_rooms
else -> R.id.bottom_action_home else -> R.id.bottom_action_home
} }
} }
private fun updateSelectedFragment(displayMode: RoomListFragment.DisplayMode) { private fun updateSelectedFragment(displayMode: RoomListDisplayMode) {
val fragmentTag = "FRAGMENT_TAG_${displayMode.name}" val fragmentTag = "FRAGMENT_TAG_${displayMode.name}"
val fragmentToShow = childFragmentManager.findFragmentByTag(fragmentTag) val fragmentToShow = childFragmentManager.findFragmentByTag(fragmentTag)
childFragmentManager.inTransaction { childFragmentManager.commitTransactionNow {
childFragmentManager.fragments.forEach { hide(it) } childFragmentManager.fragments
.filter { it != fragmentToShow }
.forEach {
hide(it)
}
if (fragmentToShow == null) { if (fragmentToShow == null) {
val params = RoomListParams(displayMode) val params = RoomListParams(displayMode)
add(R.id.roomListContainer, RoomListFragment::class.java, params.toMvRxBundle(), fragmentTag) add(R.id.roomListContainer, RoomListFragment::class.java, params.toMvRxBundle(), fragmentTag)

View file

@ -22,11 +22,17 @@ import com.airbnb.mvrx.ViewModelContext
import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject import com.squareup.inject.assisted.AssistedInject
import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.room.model.Membership
import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.matrix.android.api.session.room.model.tag.RoomTag
import im.vector.matrix.rx.rx import im.vector.matrix.rx.rx
import im.vector.riotx.core.di.HasScreenInjector import im.vector.riotx.core.di.HasScreenInjector
import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.platform.VectorViewModel
import im.vector.riotx.core.resources.StringProvider import im.vector.riotx.core.resources.StringProvider
import im.vector.riotx.features.home.group.SelectedGroupDataSource import im.vector.riotx.features.home.group.SelectedGroupDataSource
import im.vector.riotx.features.home.room.list.RoomCategory
import im.vector.riotx.features.home.room.list.RoomListFragment
import im.vector.riotx.features.home.room.list.RoomSummaries
import im.vector.riotx.features.ui.UiStateRepository import im.vector.riotx.features.ui.UiStateRepository
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
@ -144,4 +150,5 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
} }
.disposeOnClear() .disposeOnClear()
} }
} }

View file

@ -17,14 +17,19 @@
package im.vector.riotx.features.home package im.vector.riotx.features.home
import arrow.core.Option import arrow.core.Option
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.MvRxState
import com.airbnb.mvrx.Uninitialized
import im.vector.matrix.android.api.session.group.model.GroupSummary import im.vector.matrix.android.api.session.group.model.GroupSummary
import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.matrix.android.api.session.sync.SyncState import im.vector.matrix.android.api.session.sync.SyncState
import im.vector.riotx.features.home.room.list.RoomListFragment import im.vector.riotx.features.home.room.list.RoomListFragment
import im.vector.riotx.features.home.room.list.RoomSummaries
data class HomeDetailViewState( data class HomeDetailViewState(
val groupSummary: Option<GroupSummary> = Option.empty(), val groupSummary: Option<GroupSummary> = Option.empty(),
val displayMode: RoomListFragment.DisplayMode = RoomListFragment.DisplayMode.HOME, val asyncRooms: Async<List<RoomSummary>> = Uninitialized,
val displayMode: RoomListDisplayMode = RoomListDisplayMode.HOME,
val notificationCountCatchup: Int = 0, val notificationCountCatchup: Int = 0,
val notificationHighlightCatchup: Boolean = false, val notificationHighlightCatchup: Boolean = false,
val notificationCountPeople: Int = 0, val notificationCountPeople: Int = 0,

View file

@ -0,0 +1,28 @@
/*
* Copyright 2019 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.riotx.features.home
import androidx.annotation.StringRes
import im.vector.riotx.R
enum class RoomListDisplayMode(@StringRes val titleRes: Int) {
HOME(R.string.bottom_action_home),
PEOPLE(R.string.bottom_action_people_x),
ROOMS(R.string.bottom_action_rooms),
FILTERED(/* Not used */ 0),
SHARE(/* Not used */ 0)
}

View file

@ -286,6 +286,11 @@ class RoomDetailFragment @Inject constructor(
} }
} }
override fun onDestroyView() {
super.onDestroyView()
recyclerView.adapter = null
}
override fun onDestroy() { override fun onDestroy() {
debouncer.cancelAll() debouncer.cancelAll()
super.onDestroy() super.onDestroy()
@ -472,6 +477,7 @@ class RoomDetailFragment @Inject constructor(
} }
} }
recyclerView.adapter = timelineEventController.adapter recyclerView.adapter = timelineEventController.adapter
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
if (recyclerView.scrollState == RecyclerView.SCROLL_STATE_IDLE) { if (recyclerView.scrollState == RecyclerView.SCROLL_STATE_IDLE) {
@ -492,6 +498,7 @@ class RoomDetailFragment @Inject constructor(
} }
} }
}) })
timelineEventController.callback = this timelineEventController.callback = this
if (vectorPreferences.swipeToReplyIsEnabled()) { if (vectorPreferences.swipeToReplyIsEnabled()) {

View file

@ -24,6 +24,7 @@ import im.vector.riotx.R
import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.di.ScreenComponent
import im.vector.riotx.core.extensions.replaceFragment import im.vector.riotx.core.extensions.replaceFragment
import im.vector.riotx.core.platform.VectorBaseActivity import im.vector.riotx.core.platform.VectorBaseActivity
import im.vector.riotx.features.home.RoomListDisplayMode
import im.vector.riotx.features.home.room.list.RoomListFragment import im.vector.riotx.features.home.room.list.RoomListFragment
import im.vector.riotx.features.home.room.list.RoomListParams import im.vector.riotx.features.home.room.list.RoomListParams
import kotlinx.android.synthetic.main.activity_filtered_rooms.* import kotlinx.android.synthetic.main.activity_filtered_rooms.*
@ -47,7 +48,7 @@ class FilteredRoomsActivity : VectorBaseActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
configureToolbar(filteredRoomsToolbar) configureToolbar(filteredRoomsToolbar)
if (isFirstCreation()) { if (isFirstCreation()) {
val params = RoomListParams(RoomListFragment.DisplayMode.FILTERED) val params = RoomListParams(RoomListDisplayMode.FILTERED)
replaceFragment(R.id.filteredRoomsFragmentContainer, RoomListFragment::class.java, params, FRAGMENT_TAG) replaceFragment(R.id.filteredRoomsFragmentContainer, RoomListFragment::class.java, params, FRAGMENT_TAG)
} }
filteredRoomsSearchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { filteredRoomsSearchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {

View file

@ -18,21 +18,22 @@ package im.vector.riotx.features.home.room.list
import im.vector.matrix.android.api.session.room.model.Membership import im.vector.matrix.android.api.session.room.model.Membership
import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.riotx.features.home.RoomListDisplayMode
import io.reactivex.functions.Predicate import io.reactivex.functions.Predicate
class RoomListDisplayModeFilter(private val displayMode: RoomListFragment.DisplayMode) : Predicate<RoomSummary> { class RoomListDisplayModeFilter(private val displayMode: RoomListDisplayMode) : Predicate<RoomSummary> {
override fun test(roomSummary: RoomSummary): Boolean { override fun test(roomSummary: RoomSummary): Boolean {
if (roomSummary.membership.isLeft()) { if (roomSummary.membership.isLeft()) {
return false return false
} }
return when (displayMode) { return when (displayMode) {
RoomListFragment.DisplayMode.HOME -> RoomListDisplayMode.HOME ->
roomSummary.notificationCount > 0 || roomSummary.membership == Membership.INVITE || roomSummary.userDrafts.isNotEmpty() roomSummary.notificationCount > 0 || roomSummary.membership == Membership.INVITE || roomSummary.userDrafts.isNotEmpty()
RoomListFragment.DisplayMode.PEOPLE -> roomSummary.isDirect && roomSummary.membership == Membership.JOIN RoomListDisplayMode.PEOPLE -> roomSummary.isDirect && roomSummary.membership == Membership.JOIN
RoomListFragment.DisplayMode.ROOMS -> !roomSummary.isDirect && roomSummary.membership == Membership.JOIN RoomListDisplayMode.ROOMS -> !roomSummary.isDirect && roomSummary.membership == Membership.JOIN
RoomListFragment.DisplayMode.FILTERED -> roomSummary.membership == Membership.JOIN RoomListDisplayMode.FILTERED -> roomSummary.membership == Membership.JOIN
RoomListFragment.DisplayMode.SHARE -> roomSummary.membership == Membership.JOIN RoomListDisplayMode.SHARE -> roomSummary.membership == Membership.JOIN
} }
} }
} }

View file

@ -39,6 +39,7 @@ import im.vector.riotx.core.error.ErrorFormatter
import im.vector.riotx.core.platform.OnBackPressed import im.vector.riotx.core.platform.OnBackPressed
import im.vector.riotx.core.platform.StateView import im.vector.riotx.core.platform.StateView
import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.features.home.RoomListDisplayMode
import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsSharedAction import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsSharedAction
import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsBottomSheet import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsBottomSheet
import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsSharedActionViewModel import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsSharedActionViewModel
@ -46,15 +47,13 @@ import im.vector.riotx.features.home.room.list.widget.FabMenuView
import im.vector.riotx.features.notifications.NotificationDrawerManager import im.vector.riotx.features.notifications.NotificationDrawerManager
import im.vector.riotx.features.share.SharedData import im.vector.riotx.features.share.SharedData
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
import kotlinx.android.synthetic.main.fragment_room_list.* import kotlinx.android.synthetic.main.fragment_room_list.*
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@Parcelize @Parcelize
data class RoomListParams( data class RoomListParams(
val displayMode: RoomListFragment.DisplayMode, val displayMode: RoomListDisplayMode,
val sharedData: SharedData? = null val sharedData: SharedData? = null
) : Parcelable ) : Parcelable
@ -66,14 +65,6 @@ class RoomListFragment @Inject constructor(
) : VectorBaseFragment(), RoomSummaryController.Listener, OnBackPressed, FabMenuView.Listener { ) : VectorBaseFragment(), RoomSummaryController.Listener, OnBackPressed, FabMenuView.Listener {
enum class DisplayMode(@StringRes val titleRes: Int) {
HOME(R.string.bottom_action_home),
PEOPLE(R.string.bottom_action_people_x),
ROOMS(R.string.bottom_action_rooms),
FILTERED(/* Not used */ 0),
SHARE(/* Not used */ 0)
}
private lateinit var sharedActionViewModel: RoomListQuickActionsSharedActionViewModel private lateinit var sharedActionViewModel: RoomListQuickActionsSharedActionViewModel
private val roomListParams: RoomListParams by args() private val roomListParams: RoomListParams by args()
private val roomListViewModel: RoomListViewModel by fragmentViewModel() private val roomListViewModel: RoomListViewModel by fragmentViewModel()
@ -126,8 +117,13 @@ class RoomListFragment @Inject constructor(
.disposeOnDestroyView() .disposeOnDestroyView()
} }
override fun onDestroyView() {
super.onDestroyView()
roomListView.adapter = null
}
private fun openSelectedRoom(event: RoomListViewEvents.SelectRoom) { private fun openSelectedRoom(event: RoomListViewEvents.SelectRoom) {
if (roomListParams.displayMode == DisplayMode.SHARE) { if (roomListParams.displayMode == RoomListDisplayMode.SHARE) {
val sharedData = roomListParams.sharedData ?: return val sharedData = roomListParams.sharedData ?: return
navigator.openRoomForSharing(requireActivity(), event.roomId, sharedData) navigator.openRoomForSharing(requireActivity(), event.roomId, sharedData)
} else { } else {
@ -144,9 +140,9 @@ class RoomListFragment @Inject constructor(
private fun setupCreateRoomButton() { private fun setupCreateRoomButton() {
when (roomListParams.displayMode) { when (roomListParams.displayMode) {
DisplayMode.HOME -> createChatFabMenu.isVisible = true RoomListDisplayMode.HOME -> createChatFabMenu.isVisible = true
DisplayMode.PEOPLE -> createChatRoomButton.isVisible = true RoomListDisplayMode.PEOPLE -> createChatRoomButton.isVisible = true
DisplayMode.ROOMS -> createGroupRoomButton.isVisible = true RoomListDisplayMode.ROOMS -> createGroupRoomButton.isVisible = true
else -> Unit // No button in this mode else -> Unit // No button in this mode
} }
@ -158,7 +154,7 @@ class RoomListFragment @Inject constructor(
} }
// Hide FAB when list is scrolling // Hide FAB when list is scrolling
roomListEpoxyRecyclerView.addOnScrollListener( roomListView.addOnScrollListener(
object : RecyclerView.OnScrollListener() { object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
createChatFabMenu.removeCallbacks(showFabRunnable) createChatFabMenu.removeCallbacks(showFabRunnable)
@ -170,9 +166,9 @@ class RoomListFragment @Inject constructor(
RecyclerView.SCROLL_STATE_DRAGGING, RecyclerView.SCROLL_STATE_DRAGGING,
RecyclerView.SCROLL_STATE_SETTLING -> { RecyclerView.SCROLL_STATE_SETTLING -> {
when (roomListParams.displayMode) { when (roomListParams.displayMode) {
DisplayMode.HOME -> createChatFabMenu.hide() RoomListDisplayMode.HOME -> createChatFabMenu.hide()
DisplayMode.PEOPLE -> createChatRoomButton.hide() RoomListDisplayMode.PEOPLE -> createChatRoomButton.hide()
DisplayMode.ROOMS -> createGroupRoomButton.hide() RoomListDisplayMode.ROOMS -> createGroupRoomButton.hide()
else -> Unit else -> Unit
} }
} }
@ -183,7 +179,7 @@ class RoomListFragment @Inject constructor(
fun filterRoomsWith(filter: String) { fun filterRoomsWith(filter: String) {
// Scroll the list to top // Scroll the list to top
roomListEpoxyRecyclerView.scrollToPosition(0) roomListView.scrollToPosition(0)
roomListViewModel.handle(RoomListAction.FilterWith(filter)) roomListViewModel.handle(RoomListAction.FilterWith(filter))
} }
@ -199,20 +195,20 @@ class RoomListFragment @Inject constructor(
private fun setupRecyclerView() { private fun setupRecyclerView() {
val layoutManager = LinearLayoutManager(context) val layoutManager = LinearLayoutManager(context)
val stateRestorer = LayoutManagerStateRestorer(layoutManager).register() val stateRestorer = LayoutManagerStateRestorer(layoutManager).register()
roomListEpoxyRecyclerView.layoutManager = layoutManager roomListView.layoutManager = layoutManager
roomListEpoxyRecyclerView.itemAnimator = RoomListAnimator() roomListView.itemAnimator = RoomListAnimator()
roomController.listener = this roomController.listener = this
roomController.addModelBuildListener { it.dispatchTo(stateRestorer) } roomController.addModelBuildListener { it.dispatchTo(stateRestorer) }
stateView.contentView = roomListEpoxyRecyclerView roomListView.adapter = roomController.adapter
roomListEpoxyRecyclerView.setController(roomController) stateView.contentView = roomListView
} }
private val showFabRunnable = Runnable { private val showFabRunnable = Runnable {
if (isAdded) { if (isAdded) {
when (roomListParams.displayMode) { when (roomListParams.displayMode) {
DisplayMode.HOME -> createChatFabMenu.show() RoomListDisplayMode.HOME -> createChatFabMenu.show()
DisplayMode.PEOPLE -> createChatRoomButton.show() RoomListDisplayMode.PEOPLE -> createChatRoomButton.show()
DisplayMode.ROOMS -> createGroupRoomButton.show() RoomListDisplayMode.ROOMS -> createGroupRoomButton.show()
else -> Unit else -> Unit
} }
} }
@ -258,9 +254,9 @@ class RoomListFragment @Inject constructor(
// Mark all as read menu // Mark all as read menu
when (roomListParams.displayMode) { when (roomListParams.displayMode) {
DisplayMode.HOME, RoomListDisplayMode.HOME,
DisplayMode.PEOPLE, RoomListDisplayMode.PEOPLE,
DisplayMode.ROOMS -> { RoomListDisplayMode.ROOMS -> {
val newValue = state.hasUnread val newValue = state.hasUnread
if (hasUnreadRooms != newValue) { if (hasUnreadRooms != newValue) {
hasUnreadRooms = newValue hasUnreadRooms = newValue
@ -288,7 +284,7 @@ class RoomListFragment @Inject constructor(
} }
.isNullOrEmpty() .isNullOrEmpty()
val emptyState = when (roomListParams.displayMode) { val emptyState = when (roomListParams.displayMode) {
DisplayMode.HOME -> { RoomListDisplayMode.HOME -> {
if (hasNoRoom) { if (hasNoRoom) {
StateView.State.Empty( StateView.State.Empty(
getString(R.string.room_list_catchup_welcome_title), getString(R.string.room_list_catchup_welcome_title),
@ -302,13 +298,13 @@ class RoomListFragment @Inject constructor(
getString(R.string.room_list_catchup_empty_body)) getString(R.string.room_list_catchup_empty_body))
} }
} }
DisplayMode.PEOPLE -> RoomListDisplayMode.PEOPLE ->
StateView.State.Empty( StateView.State.Empty(
getString(R.string.room_list_people_empty_title), getString(R.string.room_list_people_empty_title),
ContextCompat.getDrawable(requireContext(), R.drawable.ic_home_bottom_chat), ContextCompat.getDrawable(requireContext(), R.drawable.ic_home_bottom_chat),
getString(R.string.room_list_people_empty_body) getString(R.string.room_list_people_empty_body)
) )
DisplayMode.ROOMS -> RoomListDisplayMode.ROOMS ->
StateView.State.Empty( StateView.State.Empty(
getString(R.string.room_list_rooms_empty_title), getString(R.string.room_list_rooms_empty_title),
ContextCompat.getDrawable(requireContext(), R.drawable.ic_home_bottom_group), ContextCompat.getDrawable(requireContext(), R.drawable.ic_home_bottom_group),

View file

@ -27,6 +27,7 @@ import im.vector.matrix.android.api.session.room.model.tag.RoomTag
import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.platform.VectorViewModel
import im.vector.riotx.core.utils.DataSource import im.vector.riotx.core.utils.DataSource
import im.vector.riotx.core.utils.PublishDataSource import im.vector.riotx.core.utils.PublishDataSource
import im.vector.riotx.features.home.RoomListDisplayMode
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -232,11 +233,11 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
} }
val roomComparator = when (displayMode) { val roomComparator = when (displayMode) {
RoomListFragment.DisplayMode.HOME -> chronologicalRoomComparator RoomListDisplayMode.HOME -> chronologicalRoomComparator
RoomListFragment.DisplayMode.PEOPLE -> chronologicalRoomComparator RoomListDisplayMode.PEOPLE -> chronologicalRoomComparator
RoomListFragment.DisplayMode.ROOMS -> chronologicalRoomComparator RoomListDisplayMode.ROOMS -> chronologicalRoomComparator
RoomListFragment.DisplayMode.FILTERED -> chronologicalRoomComparator RoomListDisplayMode.FILTERED -> chronologicalRoomComparator
RoomListFragment.DisplayMode.SHARE -> chronologicalRoomComparator RoomListDisplayMode.SHARE -> chronologicalRoomComparator
} }
return RoomSummaries().apply { return RoomSummaries().apply {

View file

@ -18,6 +18,7 @@ package im.vector.riotx.features.home.room.list
import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
import im.vector.riotx.features.home.HomeRoomListDataSource import im.vector.riotx.features.home.HomeRoomListDataSource
import im.vector.riotx.features.home.RoomListDisplayMode
import im.vector.riotx.features.share.ShareRoomListDataSource import im.vector.riotx.features.share.ShareRoomListDataSource
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Provider import javax.inject.Provider
@ -32,7 +33,7 @@ class RoomListViewModelFactory @Inject constructor(private val session: Provider
return RoomListViewModel( return RoomListViewModel(
initialState, initialState,
session.get(), session.get(),
if (initialState.displayMode == RoomListFragment.DisplayMode.SHARE) shareRoomListDataSource.get() else homeRoomListDataSource.get(), if (initialState.displayMode == RoomListDisplayMode.SHARE) shareRoomListDataSource.get() else homeRoomListDataSource.get(),
alphabeticalRoomComparator.get(), alphabeticalRoomComparator.get(),
chronologicalRoomComparator.get()) chronologicalRoomComparator.get())
} }

View file

@ -23,9 +23,10 @@ import com.airbnb.mvrx.Uninitialized
import im.vector.matrix.android.api.session.room.model.Membership import im.vector.matrix.android.api.session.room.model.Membership
import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.features.home.RoomListDisplayMode
data class RoomListViewState( data class RoomListViewState(
val displayMode: RoomListFragment.DisplayMode, val displayMode: RoomListDisplayMode,
val asyncRooms: Async<List<RoomSummary>> = Uninitialized, val asyncRooms: Async<List<RoomSummary>> = Uninitialized,
val roomFilter: String = "", val roomFilter: String = "",
val asyncFilteredRooms: Async<RoomSummaries> = Uninitialized, val asyncFilteredRooms: Async<RoomSummaries> = Uninitialized,

View file

@ -23,6 +23,7 @@ import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.epoxy.noResultItem import im.vector.riotx.core.epoxy.noResultItem
import im.vector.riotx.core.resources.StringProvider import im.vector.riotx.core.resources.StringProvider
import im.vector.riotx.features.home.RoomListDisplayMode
import im.vector.riotx.features.home.room.filtered.FilteredRoomFooterItem import im.vector.riotx.features.home.room.filtered.FilteredRoomFooterItem
import im.vector.riotx.features.home.room.filtered.filteredRoomFooterItem import im.vector.riotx.features.home.room.filtered.filteredRoomFooterItem
import javax.inject.Inject import javax.inject.Inject
@ -50,8 +51,8 @@ class RoomSummaryController @Inject constructor(private val stringProvider: Stri
override fun buildModels() { override fun buildModels() {
val nonNullViewState = viewState ?: return val nonNullViewState = viewState ?: return
when (nonNullViewState.displayMode) { when (nonNullViewState.displayMode) {
RoomListFragment.DisplayMode.FILTERED, RoomListDisplayMode.FILTERED,
RoomListFragment.DisplayMode.SHARE -> { RoomListDisplayMode.SHARE -> {
buildFilteredRooms(nonNullViewState) buildFilteredRooms(nonNullViewState)
} }
else -> { else -> {
@ -92,7 +93,7 @@ class RoomSummaryController @Inject constructor(private val stringProvider: Stri
viewState.rejectingErrorRoomsIds) viewState.rejectingErrorRoomsIds)
when { when {
viewState.displayMode == RoomListFragment.DisplayMode.FILTERED -> addFilterFooter(viewState) viewState.displayMode == RoomListDisplayMode.FILTERED -> addFilterFooter(viewState)
filteredSummaries.isEmpty() -> addEmptyFooter() filteredSummaries.isEmpty() -> addEmptyFooter()
} }
} }

View file

@ -31,6 +31,7 @@ import im.vector.riotx.core.extensions.replaceFragment
import im.vector.riotx.core.platform.VectorBaseActivity import im.vector.riotx.core.platform.VectorBaseActivity
import im.vector.riotx.features.attachments.AttachmentsHelper import im.vector.riotx.features.attachments.AttachmentsHelper
import im.vector.riotx.features.home.LoadingFragment import im.vector.riotx.features.home.LoadingFragment
import im.vector.riotx.features.home.RoomListDisplayMode
import im.vector.riotx.features.home.room.list.RoomListFragment import im.vector.riotx.features.home.room.list.RoomListFragment
import im.vector.riotx.features.home.room.list.RoomListParams import im.vector.riotx.features.home.room.list.RoomListParams
import im.vector.riotx.features.login.LoginActivity import im.vector.riotx.features.login.LoginActivity
@ -97,7 +98,7 @@ class IncomingShareActivity :
} }
override fun onContentAttachmentsReady(attachments: List<ContentAttachmentData>) { override fun onContentAttachmentsReady(attachments: List<ContentAttachmentData>) {
val roomListParams = RoomListParams(RoomListFragment.DisplayMode.SHARE, sharedData = SharedData.Attachments(attachments)) val roomListParams = RoomListParams(RoomListDisplayMode.SHARE, sharedData = SharedData.Attachments(attachments))
replaceFragment(R.id.shareRoomListFragmentContainer, RoomListFragment::class.java, roomListParams) replaceFragment(R.id.shareRoomListFragmentContainer, RoomListFragment::class.java, roomListParams)
} }
@ -116,7 +117,7 @@ class IncomingShareActivity :
return if (sharedText.isNullOrEmpty()) { return if (sharedText.isNullOrEmpty()) {
false false
} else { } else {
val roomListParams = RoomListParams(RoomListFragment.DisplayMode.SHARE, sharedData = SharedData.Text(sharedText)) val roomListParams = RoomListParams(RoomListDisplayMode.SHARE, sharedData = SharedData.Text(sharedText))
replaceFragment(R.id.shareRoomListFragmentContainer, RoomListFragment::class.java, roomListParams) replaceFragment(R.id.shareRoomListFragmentContainer, RoomListFragment::class.java, roomListParams)
true true
} }

View file

@ -18,7 +18,7 @@ package im.vector.riotx.features.ui
import android.content.SharedPreferences import android.content.SharedPreferences
import androidx.core.content.edit import androidx.core.content.edit
import im.vector.riotx.features.home.room.list.RoomListFragment import im.vector.riotx.features.home.RoomListDisplayMode
import javax.inject.Inject import javax.inject.Inject
/** /**
@ -26,21 +26,21 @@ import javax.inject.Inject
*/ */
class SharedPreferencesUiStateRepository @Inject constructor(private val sharedPreferences: SharedPreferences) : UiStateRepository { class SharedPreferencesUiStateRepository @Inject constructor(private val sharedPreferences: SharedPreferences) : UiStateRepository {
override fun getDisplayMode(): RoomListFragment.DisplayMode { override fun getDisplayMode(): RoomListDisplayMode {
return when (sharedPreferences.getInt(KEY_DISPLAY_MODE, VALUE_DISPLAY_MODE_CATCHUP)) { return when (sharedPreferences.getInt(KEY_DISPLAY_MODE, VALUE_DISPLAY_MODE_CATCHUP)) {
VALUE_DISPLAY_MODE_PEOPLE -> RoomListFragment.DisplayMode.PEOPLE VALUE_DISPLAY_MODE_PEOPLE -> RoomListDisplayMode.PEOPLE
VALUE_DISPLAY_MODE_ROOMS -> RoomListFragment.DisplayMode.ROOMS VALUE_DISPLAY_MODE_ROOMS -> RoomListDisplayMode.ROOMS
else -> RoomListFragment.DisplayMode.HOME else -> RoomListDisplayMode.HOME
} }
} }
override fun storeDisplayMode(displayMode: RoomListFragment.DisplayMode) { override fun storeDisplayMode(displayMode: RoomListDisplayMode) {
sharedPreferences.edit { sharedPreferences.edit {
putInt(KEY_DISPLAY_MODE, putInt(KEY_DISPLAY_MODE,
when (displayMode) { when (displayMode) {
RoomListFragment.DisplayMode.PEOPLE -> VALUE_DISPLAY_MODE_PEOPLE RoomListDisplayMode.PEOPLE -> VALUE_DISPLAY_MODE_PEOPLE
RoomListFragment.DisplayMode.ROOMS -> VALUE_DISPLAY_MODE_ROOMS RoomListDisplayMode.ROOMS -> VALUE_DISPLAY_MODE_ROOMS
else -> VALUE_DISPLAY_MODE_CATCHUP else -> VALUE_DISPLAY_MODE_CATCHUP
}) })
} }
} }

View file

@ -16,14 +16,14 @@
package im.vector.riotx.features.ui package im.vector.riotx.features.ui
import im.vector.riotx.features.home.room.list.RoomListFragment import im.vector.riotx.features.home.RoomListDisplayMode
/** /**
* This interface is used to persist UI state across application restart * This interface is used to persist UI state across application restart
*/ */
interface UiStateRepository { interface UiStateRepository {
fun getDisplayMode(): RoomListFragment.DisplayMode fun getDisplayMode(): RoomListDisplayMode
fun storeDisplayMode(displayMode: RoomListFragment.DisplayMode) fun storeDisplayMode(displayMode: RoomListDisplayMode)
} }

View file

@ -7,8 +7,8 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?riotx_header_panel_background"> android:background="?riotx_header_panel_background">
<com.airbnb.epoxy.EpoxyRecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/roomListEpoxyRecyclerView" android:id="@+id/roomListView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:overScrollMode="always" /> android:overScrollMode="always" />
@ -30,7 +30,7 @@
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:accessibilityTraversalBefore="@+id/roomListEpoxyRecyclerView" android:accessibilityTraversalBefore="@+id/roomListView"
android:contentDescription="@string/a11y_create_direct_message" android:contentDescription="@string/a11y_create_direct_message"
android:scaleType="center" android:scaleType="center"
android:src="@drawable/ic_fab_add_chat" android:src="@drawable/ic_fab_add_chat"
@ -47,7 +47,7 @@
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:accessibilityTraversalBefore="@+id/roomListEpoxyRecyclerView" android:accessibilityTraversalBefore="@+id/roomListView"
android:contentDescription="@string/a11y_create_room" android:contentDescription="@string/a11y_create_room"
android:src="@drawable/ic_fab_add_room" android:src="@drawable/ic_fab_add_room"
android:visibility="gone" android:visibility="gone"

View file

@ -24,7 +24,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:accessibilityTraversalBefore="@+id/roomListEpoxyRecyclerView" android:accessibilityTraversalBefore="@+id/roomListView"
android:contentDescription="@string/a11y_create_room" android:contentDescription="@string/a11y_create_room"
android:src="@drawable/ic_fab_add_room" android:src="@drawable/ic_fab_add_room"
app:backgroundTint="#FFFFFF" app:backgroundTint="#FFFFFF"