From 4ddc8e706dbfaa02c8e7d1794b27089e38d03b1f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 16 Dec 2020 12:45:22 +0100 Subject: [PATCH] Fix issue with coordinator Layout --- .../debug/DebugMaterialThemeActivity.kt | 2 +- .../im/vector/app/core/extensions/Activity.kt | 27 ++++++++++--------- .../im/vector/app/core/extensions/Fragment.kt | 13 +++++---- .../vector/app/core/extensions/Parcelable.kt | 25 +++++++++++++++++ .../app/core/platform/VectorBaseActivity.kt | 6 ----- .../app/core/platform/VectorBaseFragment.kt | 7 +---- .../app/features/home/HomeDetailFragment.kt | 1 + .../roomdirectory/PublicRoomsFragment.kt | 2 +- .../RoomPreviewNoPreviewFragment.kt | 2 +- 9 files changed, 50 insertions(+), 35 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/core/extensions/Parcelable.kt diff --git a/vector/src/debug/java/im/vector/app/features/debug/DebugMaterialThemeActivity.kt b/vector/src/debug/java/im/vector/app/features/debug/DebugMaterialThemeActivity.kt index d290cc42fa..8df1feab1e 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/DebugMaterialThemeActivity.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/DebugMaterialThemeActivity.kt @@ -35,7 +35,7 @@ abstract class DebugMaterialThemeActivity : AppCompatActivity() { setContentView(views.root) views.debugShowSnackbar.setOnClickListener { - Snackbar.make(views.debugMaterialCoordinator, "Snackbar!", Snackbar.LENGTH_SHORT) + Snackbar.make(views.coordinatorLayout, "Snackbar!", Snackbar.LENGTH_SHORT) .setAction("Action") { } .show() } diff --git a/vector/src/main/java/im/vector/app/core/extensions/Activity.kt b/vector/src/main/java/im/vector/app/core/extensions/Activity.kt index ef191d5110..5b36e4e628 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/Activity.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/Activity.kt @@ -23,15 +23,15 @@ import androidx.activity.ComponentActivity import androidx.activity.result.ActivityResult import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts +import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentTransaction -import im.vector.app.core.platform.VectorBaseActivity fun ComponentActivity.registerStartForActivityResult(onResult: (ActivityResult) -> Unit): ActivityResultLauncher { return registerForActivityResult(ActivityResultContracts.StartActivityForResult(), onResult) } -fun VectorBaseActivity<*>.addFragment( +fun AppCompatActivity.addFragment( frameId: Int, fragment: Fragment, allowStateLoss: Boolean = false @@ -39,7 +39,7 @@ fun VectorBaseActivity<*>.addFragment( supportFragmentManager.commitTransaction(allowStateLoss) { add(frameId, fragment) } } -fun VectorBaseActivity<*>.addFragment( +fun AppCompatActivity.addFragment( frameId: Int, fragmentClass: Class, params: Parcelable? = null, @@ -51,7 +51,7 @@ fun VectorBaseActivity<*>.addFragment( } } -fun VectorBaseActivity<*>.replaceFragment( +fun AppCompatActivity.replaceFragment( frameId: Int, fragment: Fragment, tag: String? = null, @@ -60,7 +60,7 @@ fun VectorBaseActivity<*>.replaceFragment( supportFragmentManager.commitTransaction(allowStateLoss) { replace(frameId, fragment, tag) } } -fun VectorBaseActivity<*>.replaceFragment( +fun AppCompatActivity.replaceFragment( frameId: Int, fragmentClass: Class, params: Parcelable? = null, @@ -72,7 +72,7 @@ fun VectorBaseActivity<*>.replaceFragment( } } -fun VectorBaseActivity<*>.addFragmentToBackstack( +fun AppCompatActivity.addFragmentToBackstack( frameId: Int, fragment: Fragment, tag: String? = null, @@ -81,19 +81,20 @@ fun VectorBaseActivity<*>.addFragmentToBackstack( supportFragmentManager.commitTransaction(allowStateLoss) { replace(frameId, fragment).addToBackStack(tag) } } -fun VectorBaseActivity<*>.addFragmentToBackstack(frameId: Int, - fragmentClass: Class, - params: Parcelable? = null, - tag: String? = null, - allowStateLoss: Boolean = false, - option: ((FragmentTransaction) -> Unit)? = null) { +fun AppCompatActivity.addFragmentToBackstack( + frameId: Int, + fragmentClass: Class, + params: Parcelable? = null, + tag: String? = null, + allowStateLoss: Boolean = false, + option: ((FragmentTransaction) -> Unit)? = null) { supportFragmentManager.commitTransaction(allowStateLoss) { option?.invoke(this) replace(frameId, fragmentClass, params.toMvRxBundle(), tag).addToBackStack(tag) } } -fun VectorBaseActivity<*>.hideKeyboard() { +fun AppCompatActivity.hideKeyboard() { currentFocus?.hideKeyboard() } diff --git a/vector/src/main/java/im/vector/app/core/extensions/Fragment.kt b/vector/src/main/java/im/vector/app/core/extensions/Fragment.kt index c33aa577f5..0f59207bfe 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/Fragment.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/Fragment.kt @@ -24,7 +24,6 @@ import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.fragment.app.Fragment import im.vector.app.R -import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.utils.selectTxtFileToWrite import java.text.SimpleDateFormat import java.util.Date @@ -42,7 +41,7 @@ fun Fragment.addFragment( parentFragmentManager.commitTransaction(allowStateLoss) { add(frameId, fragment) } } -fun VectorBaseFragment<*>.addFragment( +fun Fragment.addFragment( frameId: Int, fragmentClass: Class, params: Parcelable? = null, @@ -62,7 +61,7 @@ fun Fragment.replaceFragment( parentFragmentManager.commitTransaction(allowStateLoss) { replace(frameId, fragment) } } -fun VectorBaseFragment<*>.replaceFragment( +fun Fragment.replaceFragment( frameId: Int, fragmentClass: Class, params: Parcelable? = null, @@ -83,7 +82,7 @@ fun Fragment.addFragmentToBackstack( parentFragmentManager.commitTransaction(allowStateLoss) { replace(frameId, fragment, tag).addToBackStack(tag) } } -fun VectorBaseFragment<*>.addFragmentToBackstack( +fun Fragment.addFragmentToBackstack( frameId: Int, fragmentClass: Class, params: Parcelable? = null, @@ -104,7 +103,7 @@ fun Fragment.addChildFragment( childFragmentManager.commitTransaction(allowStateLoss) { add(frameId, fragment, tag) } } -fun VectorBaseFragment<*>.addChildFragment( +fun Fragment.addChildFragment( frameId: Int, fragmentClass: Class, params: Parcelable? = null, @@ -125,7 +124,7 @@ fun Fragment.replaceChildFragment( childFragmentManager.commitTransaction(allowStateLoss) { replace(frameId, fragment, tag) } } -fun VectorBaseFragment<*>.replaceChildFragment( +fun Fragment.replaceChildFragment( frameId: Int, fragmentClass: Class, params: Parcelable? = null, @@ -146,7 +145,7 @@ fun Fragment.addChildFragmentToBackstack( childFragmentManager.commitTransaction(allowStateLoss) { replace(frameId, fragment).addToBackStack(tag) } } -fun VectorBaseFragment<*>.addChildFragmentToBackstack( +fun Fragment.addChildFragmentToBackstack( frameId: Int, fragmentClass: Class, params: Parcelable? = null, diff --git a/vector/src/main/java/im/vector/app/core/extensions/Parcelable.kt b/vector/src/main/java/im/vector/app/core/extensions/Parcelable.kt new file mode 100644 index 0000000000..6ca0144601 --- /dev/null +++ b/vector/src/main/java/im/vector/app/core/extensions/Parcelable.kt @@ -0,0 +1,25 @@ +/* + * 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.core.extensions + +import android.os.Bundle +import android.os.Parcelable +import com.airbnb.mvrx.MvRx + +fun Parcelable?.toMvRxBundle(): Bundle? { + return this?.let { Bundle().apply { putParcelable(MvRx.KEY_ARG, it) } } +} diff --git a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt index f7cd21b875..2d88606b60 100644 --- a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt +++ b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt @@ -20,7 +20,6 @@ import android.app.Activity import android.content.Context import android.content.res.Configuration import android.os.Bundle -import android.os.Parcelable import android.view.Menu import android.view.MenuItem import android.view.View @@ -40,7 +39,6 @@ import androidx.fragment.app.FragmentManager import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.viewbinding.ViewBinding -import com.airbnb.mvrx.MvRx import com.bumptech.glide.util.Util import com.google.android.material.snackbar.Snackbar import im.vector.app.BuildConfig @@ -502,10 +500,6 @@ abstract class VectorBaseActivity : AppCompatActivity(), HasScr } } - fun Parcelable?.toMvRxBundle(): Bundle? { - return this?.let { Bundle().apply { putParcelable(MvRx.KEY_ARG, it) } } - } - // ============================================================================================== // Handle loading view (also called waiting view or spinner view) // ============================================================================================== diff --git a/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt b/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt index 1d05f15101..6f41a6a846 100644 --- a/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt +++ b/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt @@ -34,7 +34,6 @@ import androidx.appcompat.widget.Toolbar import androidx.lifecycle.ViewModelProvider import androidx.viewbinding.ViewBinding import com.airbnb.mvrx.BaseMvRxFragment -import com.airbnb.mvrx.MvRx import com.bumptech.glide.util.Util.assertMainThread import com.google.android.material.snackbar.Snackbar import com.jakewharton.rxbinding3.view.clicks @@ -44,6 +43,7 @@ import im.vector.app.core.di.HasScreenInjector import im.vector.app.core.di.ScreenComponent import im.vector.app.core.dialogs.UnrecognizedCertificateDialog import im.vector.app.core.error.ErrorFormatter +import im.vector.app.core.extensions.toMvRxBundle import im.vector.app.features.navigation.Navigator import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable @@ -185,11 +185,6 @@ abstract class VectorBaseFragment : BaseMvRxFragment(), HasScre arguments = args.toMvRxBundle() } - // TODO BMA Extract this and use simple type in Fragment.kt - fun Parcelable?.toMvRxBundle(): Bundle? { - return this?.let { Bundle().apply { putParcelable(MvRx.KEY_ARG, it) } } - } - @MainThread protected fun T.register(): T { assertMainThread() diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt index 84d2459895..db9fb61cb3 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt @@ -28,6 +28,7 @@ import com.airbnb.mvrx.withState import com.google.android.material.badge.BadgeDrawable import im.vector.app.R import im.vector.app.core.extensions.commitTransaction +import im.vector.app.core.extensions.toMvRxBundle import im.vector.app.core.glide.GlideApp import im.vector.app.core.platform.ToolbarConfigurable import im.vector.app.core.platform.VectorBaseActivity diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/PublicRoomsFragment.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/PublicRoomsFragment.kt index cd16488937..d200129ed9 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/PublicRoomsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/PublicRoomsFragment.kt @@ -95,7 +95,7 @@ class PublicRoomsFragment @Inject constructor( private fun handleViewEvents(viewEvents: RoomDirectoryViewEvents) { when (viewEvents) { is RoomDirectoryViewEvents.Failure -> { - Snackbar.make(views.publicRoomsCoordinator, errorFormatter.toHumanReadable(viewEvents.throwable), Snackbar.LENGTH_SHORT) + Snackbar.make(views.coordinatorLayout, errorFormatter.toHumanReadable(viewEvents.throwable), Snackbar.LENGTH_SHORT) .show() } }.exhaustive diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt index 5a1d0393e2..5757bc1b9e 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewNoPreviewFragment.kt @@ -70,7 +70,7 @@ class RoomPreviewNoPreviewFragment @Inject constructor( } override fun invalidate() = withState(roomPreviewViewModel) { state -> - TransitionManager.beginDelayedTransition(views.roomPreviewNoPreviewRoot) + TransitionManager.beginDelayedTransition(views.coordinatorLayout) views.roomPreviewNoPreviewJoin.render( when (state.roomJoinState) {