Create RecyclerView extensions and cleanup all the recycler views

This commit is contained in:
Benoit Marty 2019-12-09 18:01:58 +01:00
parent 36aba8554d
commit 742136abe8
25 changed files with 108 additions and 20 deletions

View file

@ -21,6 +21,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import im.vector.matrix.android.api.crypto.getAllVerificationEmojis
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import kotlinx.android.synthetic.main.fragment_generic_recycler.*
class DebugSasEmojiActivity : AppCompatActivity() {
@ -35,7 +36,7 @@ class DebugSasEmojiActivity : AppCompatActivity() {
}
override fun onDestroy() {
recyclerView.adapter = null
recyclerView.cleanup()
super.onDestroy()
}
}

View file

@ -0,0 +1,32 @@
/*
* 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.core.extensions
import android.content.Context
import androidx.recyclerview.widget.RecyclerView
import com.airbnb.epoxy.EpoxyController
fun RecyclerView.configureWith(context: Context, controller: EpoxyController) {
}
/**
* To call from Fragment.onDestroyView()
*/
fun RecyclerView.cleanup() {
adapter = null
}

View file

@ -22,6 +22,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.features.crypto.keysbackup.restore.KeysBackupRestoreActivity
import im.vector.riotx.features.crypto.keysbackup.setup.KeysBackupSetupActivity
@ -45,7 +46,7 @@ class KeysBackupSettingsFragment @Inject constructor(private val keysBackupSetti
override fun onDestroyView() {
keysBackupSettingsRecyclerViewController.listener = null
keysBackupSettingsRecyclerView.adapter = null
keysBackupSettingsRecyclerView.cleanup()
super.onDestroyView()
}

View file

@ -25,6 +25,7 @@ import com.airbnb.mvrx.withState
import com.jakewharton.rxbinding3.widget.textChanges
import im.vector.matrix.android.api.session.user.model.User
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.extensions.hideKeyboard
import im.vector.riotx.core.extensions.setupAsSearch
import im.vector.riotx.core.extensions.showKeyboard
@ -51,7 +52,7 @@ class CreateDirectRoomDirectoryUsersFragment @Inject constructor(
}
override fun onDestroyView() {
recyclerView.adapter = null
recyclerView.cleanup()
directRoomController.callback = null
super.onDestroyView()
}

View file

@ -32,6 +32,7 @@ import com.google.android.material.chip.ChipGroup
import com.jakewharton.rxbinding3.widget.textChanges
import im.vector.matrix.android.api.session.user.model.User
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.extensions.hideKeyboard
import im.vector.riotx.core.extensions.observeEvent
import im.vector.riotx.core.extensions.setupAsSearch
@ -70,7 +71,7 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor(
override fun onDestroyView() {
knownUsersController.callback = null
recyclerView.adapter = null
recyclerView.cleanup()
super.onDestroyView()
}

View file

@ -25,6 +25,7 @@ import com.airbnb.mvrx.Success
import com.airbnb.mvrx.fragmentViewModel
import im.vector.matrix.android.api.session.group.model.GroupSummary
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.extensions.observeEvent
import im.vector.riotx.core.platform.StateView
import im.vector.riotx.core.platform.VectorBaseFragment
@ -58,7 +59,7 @@ class GroupListFragment @Inject constructor(
override fun onDestroyView() {
groupController.callback = null
groupListView.adapter = null
groupListView.cleanup()
super.onDestroyView()
}

View file

@ -21,6 +21,7 @@ import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.airbnb.mvrx.fragmentViewModel
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.features.home.room.detail.RoomDetailSharedAction
import im.vector.riotx.features.home.room.detail.RoomDetailSharedActionViewModel
@ -46,8 +47,8 @@ class BreadcrumbsFragment @Inject constructor(
}
override fun onDestroyView() {
breadcrumbsRecyclerView.cleanup()
super.onDestroyView()
breadcrumbsRecyclerView.adapter = null
}
private fun setupRecyclerView() {

View file

@ -70,10 +70,7 @@ import im.vector.riotx.R
import im.vector.riotx.core.dialogs.withColoredButton
import im.vector.riotx.core.epoxy.LayoutManagerStateRestorer
import im.vector.riotx.core.error.ErrorFormatter
import im.vector.riotx.core.extensions.hideKeyboard
import im.vector.riotx.core.extensions.observeEvent
import im.vector.riotx.core.extensions.setTextOrHide
import im.vector.riotx.core.extensions.showKeyboard
import im.vector.riotx.core.extensions.*
import im.vector.riotx.core.files.addEntryToDownloadManager
import im.vector.riotx.core.glide.GlideApp
import im.vector.riotx.core.platform.VectorBaseFragment
@ -293,7 +290,7 @@ class RoomDetailFragment @Inject constructor(
timelineEventController.removeModelBuildListener(modelBuildListener)
modelBuildListener = null
debouncer.cancelAll()
recyclerView.adapter = null
recyclerView.cleanup()
super.onDestroyView()
}

View file

@ -29,6 +29,7 @@ import com.airbnb.mvrx.MvRx
import com.airbnb.mvrx.args
import im.vector.riotx.R
import im.vector.riotx.core.di.ScreenComponent
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.riotx.features.home.room.detail.timeline.item.ReadReceiptData
import kotlinx.android.parcel.Parcelize
@ -70,6 +71,11 @@ class DisplayReadReceiptsBottomSheet : VectorBaseBottomSheetDialogFragment() {
epoxyController.setData(displayReadReceiptArgs.readReceipts)
}
override fun onDestroyView() {
recyclerView.cleanup()
super.onDestroyView()
}
// we are not using state for this one as it's static, so no need to override invalidate()
companion object {

View file

@ -27,6 +27,7 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import im.vector.riotx.R
import im.vector.riotx.core.di.ScreenComponent
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformationData
import javax.inject.Inject
@ -68,6 +69,11 @@ class MessageActionsBottomSheet : VectorBaseBottomSheetDialogFragment(), Message
messageActionsEpoxyController.listener = this
}
override fun onDestroyView() {
recyclerView.cleanup()
super.onDestroyView()
}
override fun onUrlClicked(url: String): Boolean {
sharedActionViewModel.post(EventSharedAction.OnUrlClicked(url))
// Always consume

View file

@ -30,6 +30,7 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import im.vector.riotx.R
import im.vector.riotx.core.di.ScreenComponent
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.riotx.features.home.room.detail.timeline.action.TimelineEventFragmentArgs
import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformationData
@ -73,6 +74,12 @@ class ViewEditHistoryBottomSheet : VectorBaseBottomSheetDialogFragment() {
bottomSheetTitle.text = context?.getString(R.string.message_edits)
}
override fun onDestroyView() {
recyclerView.cleanup()
super.onDestroyView()
}
override fun invalidate() = withState(viewModel) {
epoxyController.setData(it)
super.invalidate()

View file

@ -29,6 +29,7 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import im.vector.riotx.R
import im.vector.riotx.core.di.ScreenComponent
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.riotx.features.home.room.detail.timeline.action.TimelineEventFragmentArgs
import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformationData
@ -66,6 +67,11 @@ class ViewReactionsBottomSheet : VectorBaseBottomSheetDialogFragment() {
bottomSheetTitle.text = context?.getString(R.string.reactions)
}
override fun onDestroyView() {
recyclerView.cleanup()
super.onDestroyView()
}
override fun invalidate() = withState(viewModel) {
epoxyController.setData(it)
super.invalidate()

View file

@ -36,6 +36,7 @@ import im.vector.matrix.android.api.session.room.notification.RoomNotificationSt
import im.vector.riotx.R
import im.vector.riotx.core.epoxy.LayoutManagerStateRestorer
import im.vector.riotx.core.error.ErrorFormatter
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.OnBackPressed
import im.vector.riotx.core.platform.StateView
import im.vector.riotx.core.platform.VectorBaseFragment
@ -121,7 +122,7 @@ class RoomListFragment @Inject constructor(
override fun onDestroyView() {
roomController.removeModelBuildListener(modelBuildListener)
modelBuildListener = null
roomListView.adapter = null
roomListView.cleanup()
roomController.listener = null
createChatFabMenu.listener = null
super.onDestroyView()

View file

@ -29,6 +29,7 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import im.vector.riotx.R
import im.vector.riotx.core.di.ScreenComponent
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.riotx.features.navigation.Navigator
import kotlinx.android.parcel.Parcelize
@ -76,6 +77,11 @@ class RoomListQuickActionsBottomSheet : VectorBaseBottomSheetDialogFragment(), R
roomListActionsEpoxyController.listener = this
}
override fun onDestroyView() {
recyclerView.cleanup()
super.onDestroyView()
}
override fun invalidate() = withState(viewModel) {
roomListActionsEpoxyController.setData(it)
super.invalidate()

View file

@ -25,6 +25,7 @@ import butterknife.OnClick
import com.airbnb.mvrx.args
import im.vector.riotx.R
import im.vector.riotx.core.error.ErrorFormatter
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.utils.openUrlInExternalBrowser
import im.vector.riotx.features.login.AbstractLoginFragment
import im.vector.riotx.features.login.LoginAction
@ -72,7 +73,7 @@ class LoginTermsFragment @Inject constructor(
}
override fun onDestroyView() {
loginTermsPolicyList.adapter = null
loginTermsPolicyList.cleanup()
policyController.listener = null
super.onDestroyView()
}

View file

@ -19,6 +19,7 @@ import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.VectorBaseFragment
import javax.inject.Inject
@ -37,4 +38,9 @@ class EmojiChooserFragment @Inject constructor() : VectorBaseFragment() {
it.adapter?.notifyDataSetChanged()
}
}
override fun onDestroyView() {
(view as? RecyclerView)?.cleanup()
super.onDestroyView()
}
}

View file

@ -23,6 +23,7 @@ import javax.inject.Inject
class EmojiChooserViewModel @Inject constructor() : ViewModel() {
// TODO Move the adapter out of the ViewModel
var adapter: EmojiRecyclerAdapter? = null
val emojiSourceLiveData: MutableLiveData<EmojiDataSource> = MutableLiveData()

View file

@ -23,6 +23,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.core.utils.LiveEvent
import kotlinx.android.synthetic.main.fragment_generic_recycler.*
@ -58,7 +59,7 @@ class EmojiSearchResultFragment @Inject constructor(
override fun onDestroyView() {
epoxyController.listener = null
recyclerView.adapter = null
recyclerView.cleanup()
super.onDestroyView()
}

View file

@ -28,6 +28,7 @@ import com.jakewharton.rxbinding3.appcompat.queryTextChanges
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom
import im.vector.riotx.R
import im.vector.riotx.core.error.ErrorFormatter
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.extensions.observeEvent
import im.vector.riotx.core.platform.VectorBaseFragment
import io.reactivex.rxkotlin.subscribeBy
@ -84,7 +85,7 @@ class PublicRoomsFragment @Inject constructor(
override fun onDestroyView() {
publicRoomsController.callback = null
publicRoomsList.adapter = null
publicRoomsList.cleanup()
super.onDestroyView()
}

View file

@ -24,6 +24,7 @@ import com.airbnb.mvrx.Success
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.features.roomdirectory.RoomDirectorySharedAction
import im.vector.riotx.features.roomdirectory.RoomDirectorySharedActionViewModel
@ -51,7 +52,7 @@ class CreateRoomFragment @Inject constructor(private val createRoomController: C
}
override fun onDestroyView() {
createRoomForm.adapter = null
createRoomForm.cleanup()
createRoomController.listener = null
super.onDestroyView()
}

View file

@ -25,6 +25,7 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import im.vector.matrix.android.api.session.room.model.thirdparty.RoomDirectoryData
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.features.roomdirectory.RoomDirectoryAction
import im.vector.riotx.features.roomdirectory.RoomDirectorySharedAction
@ -61,7 +62,7 @@ class RoomDirectoryPickerFragment @Inject constructor(val roomDirectoryPickerVie
}
override fun onDestroyView() {
roomDirectoryPickerList.adapter = null
roomDirectoryPickerList.cleanup()
roomDirectoryPickerController.callback = null
super.onDestroyView()
}

View file

@ -29,6 +29,7 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.transition.TransitionManager
import butterknife.BindView
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.VectorBaseActivity
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.features.rageshake.BugReporter
@ -136,6 +137,11 @@ class VectorSettingsNotificationsTroubleshootFragment @Inject constructor(
testManager?.runDiagnostic()
}
override fun onDestroyView() {
mRecyclerView.cleanup()
super.onDestroyView()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == Activity.RESULT_OK && requestCode == NotificationTroubleshootTestManager.REQ_CODE_FIX) {
testManager?.retry()

View file

@ -27,6 +27,7 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import im.vector.riotx.R
import im.vector.riotx.core.error.ErrorFormatter
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.extensions.observeEvent
import im.vector.riotx.core.platform.VectorBaseActivity
import im.vector.riotx.core.platform.VectorBaseFragment
@ -59,7 +60,7 @@ class VectorSettingsIgnoredUsersFragment @Inject constructor(
override fun onDestroyView() {
ignoredUsersController.callback = null
recyclerView.adapter = null
recyclerView.cleanup()
super.onDestroyView()
}

View file

@ -25,6 +25,7 @@ import com.airbnb.epoxy.TypedEpoxyController
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.VectorBaseActivity
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.core.resources.StringProvider
@ -58,7 +59,7 @@ class PushGatewaysFragment @Inject constructor(
}
override fun onDestroyView() {
recyclerView.adapter = null
recyclerView.cleanup()
super.onDestroyView()
}

View file

@ -24,6 +24,7 @@ import com.airbnb.epoxy.TypedEpoxyController
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.platform.VectorBaseActivity
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.core.resources.StringProvider
@ -55,7 +56,7 @@ class PushRulesFragment : VectorBaseFragment() {
}
override fun onDestroyView() {
recyclerView.adapter = null
recyclerView.cleanup()
super.onDestroyView()
}