From b91e7e9fb8fb1998969e49497b6d8cd45e923be0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 29 May 2019 09:39:55 +0200 Subject: [PATCH] Cleanup --- .../riotredesign/features/home/HomeActivity.kt | 2 +- .../features/home/room/detail/RoomDetailActivity.kt | 2 +- .../features/home/room/detail/RoomDetailFragment.kt | 12 +++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt index ff2232ae..7b64bb39 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt @@ -64,7 +64,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { bindScope(getOrCreateScope(HomeModule.HOME_SCOPE)) homeNavigator.activity = this drawerLayout.addDrawerListener(drawerListener) - if (savedInstanceState == null) { + if (isFirstCreation()) { val homeDrawerFragment = HomeDrawerFragment.newInstance() val loadingDetail = LoadingFragment.newInstance() replaceFragment(loadingDetail, R.id.homeDetailFragmentContainer) diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailActivity.kt index 9d888ce1..d3dc4aad 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailActivity.kt @@ -35,7 +35,7 @@ class RoomDetailActivity : VectorBaseActivity(), ToolbarConfigurable { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (savedInstanceState == null) { + if (isFirstCreation()) { val roomDetailArgs: RoomDetailArgs = intent?.extras?.getParcelable(EXTRA_ROOM_DETAIL_ARGS) ?: return val roomDetailFragment = RoomDetailFragment.newInstance(roomDetailArgs) diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt index e0e650ac..c8bb7326 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt @@ -41,7 +41,7 @@ import androidx.lifecycle.ViewModelProviders import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.airbnb.epoxy.EpoxyVisibilityTracker -import com.airbnb.mvrx.MvRx +import com.airbnb.mvrx.args import com.airbnb.mvrx.fragmentViewModel import com.github.piasy.biv.BigImageViewer import com.github.piasy.biv.loader.ImageLoader @@ -64,7 +64,6 @@ import im.vector.riotredesign.core.epoxy.LayoutManagerStateRestorer import im.vector.riotredesign.core.extensions.hideKeyboard import im.vector.riotredesign.core.extensions.observeEvent import im.vector.riotredesign.core.glide.GlideApp -import im.vector.riotredesign.core.platform.ToolbarConfigurable import im.vector.riotredesign.core.platform.VectorBaseFragment import im.vector.riotredesign.core.utils.* import im.vector.riotredesign.features.autocomplete.command.AutocompleteCommandPresenter @@ -147,6 +146,7 @@ class RoomDetailFragment : } } + private val roomDetailArgs: RoomDetailArgs by args() private val session by inject() private val glideRequests by lazy { GlideApp.with(this) @@ -180,6 +180,7 @@ class RoomDetailFragment : roomDetailViewModel.nonBlockingPopAlert.observe(this, Observer { liveEvent -> liveEvent.getContentIfNotHandled()?.let { + // TODO Valere: what is the aim of `*` ? val message = requireContext().getString(it.first, *it.second.toTypedArray()) showSnackWithMessage(message, Snackbar.LENGTH_LONG) } @@ -478,8 +479,9 @@ class RoomDetailFragment : override fun onEventLongClicked(informationData: MessageInformationData, messageContent: MessageContent, view: View): Boolean { view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) - val roomId = (arguments?.get(MvRx.KEY_ARG) as? RoomDetailArgs)?.roomId - if (roomId.isNullOrBlank()) { + val roomId = roomDetailArgs.roomId + if (roomId.isBlank()) { + // Benoit to Valere: can this happen? Timber.e("Missing RoomId, cannot open bottomsheet") return false } @@ -643,7 +645,7 @@ class RoomDetailFragment : } fun showSnackWithMessage(message: String, duration: Int = Snackbar.LENGTH_SHORT) { - val snack = Snackbar.make(view!!, message, Snackbar.LENGTH_SHORT) + val snack = Snackbar.make(view!!, message, duration) snack.view.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.notification_accent_color)) snack.show() }