Fix issue with coordinator Layout

This commit is contained in:
Benoit Marty 2020-12-16 12:45:22 +01:00
parent da2a0abf45
commit 4ddc8e706d
9 changed files with 50 additions and 35 deletions

View file

@ -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()
}

View file

@ -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<Intent> {
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 <T : Fragment> VectorBaseActivity<*>.addFragment(
fun <T : Fragment> AppCompatActivity.addFragment(
frameId: Int,
fragmentClass: Class<T>,
params: Parcelable? = null,
@ -51,7 +51,7 @@ fun <T : Fragment> 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 <T : Fragment> VectorBaseActivity<*>.replaceFragment(
fun <T : Fragment> AppCompatActivity.replaceFragment(
frameId: Int,
fragmentClass: Class<T>,
params: Parcelable? = null,
@ -72,7 +72,7 @@ fun <T : Fragment> 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 <T : Fragment> VectorBaseActivity<*>.addFragmentToBackstack(frameId: Int,
fragmentClass: Class<T>,
params: Parcelable? = null,
tag: String? = null,
allowStateLoss: Boolean = false,
option: ((FragmentTransaction) -> Unit)? = null) {
fun <T : Fragment> AppCompatActivity.addFragmentToBackstack(
frameId: Int,
fragmentClass: Class<T>,
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()
}

View file

@ -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 <T : Fragment> VectorBaseFragment<*>.addFragment(
fun <T : Fragment> Fragment.addFragment(
frameId: Int,
fragmentClass: Class<T>,
params: Parcelable? = null,
@ -62,7 +61,7 @@ fun Fragment.replaceFragment(
parentFragmentManager.commitTransaction(allowStateLoss) { replace(frameId, fragment) }
}
fun <T : Fragment> VectorBaseFragment<*>.replaceFragment(
fun <T : Fragment> Fragment.replaceFragment(
frameId: Int,
fragmentClass: Class<T>,
params: Parcelable? = null,
@ -83,7 +82,7 @@ fun Fragment.addFragmentToBackstack(
parentFragmentManager.commitTransaction(allowStateLoss) { replace(frameId, fragment, tag).addToBackStack(tag) }
}
fun <T : Fragment> VectorBaseFragment<*>.addFragmentToBackstack(
fun <T : Fragment> Fragment.addFragmentToBackstack(
frameId: Int,
fragmentClass: Class<T>,
params: Parcelable? = null,
@ -104,7 +103,7 @@ fun Fragment.addChildFragment(
childFragmentManager.commitTransaction(allowStateLoss) { add(frameId, fragment, tag) }
}
fun <T : Fragment> VectorBaseFragment<*>.addChildFragment(
fun <T : Fragment> Fragment.addChildFragment(
frameId: Int,
fragmentClass: Class<T>,
params: Parcelable? = null,
@ -125,7 +124,7 @@ fun Fragment.replaceChildFragment(
childFragmentManager.commitTransaction(allowStateLoss) { replace(frameId, fragment, tag) }
}
fun <T : Fragment> VectorBaseFragment<*>.replaceChildFragment(
fun <T : Fragment> Fragment.replaceChildFragment(
frameId: Int,
fragmentClass: Class<T>,
params: Parcelable? = null,
@ -146,7 +145,7 @@ fun Fragment.addChildFragmentToBackstack(
childFragmentManager.commitTransaction(allowStateLoss) { replace(frameId, fragment).addToBackStack(tag) }
}
fun <T : Fragment> VectorBaseFragment<*>.addChildFragmentToBackstack(
fun <T : Fragment> Fragment.addChildFragmentToBackstack(
frameId: Int,
fragmentClass: Class<T>,
params: Parcelable? = null,

View file

@ -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) } }
}

View file

@ -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<VB: ViewBinding> : 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)
// ==============================================================================================

View file

@ -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<VB: ViewBinding> : 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 : Restorable> T.register(): T {
assertMainThread()

View file

@ -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

View file

@ -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

View file

@ -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) {