mirror of
https://github.com/element-hq/element-android
synced 2024-12-18 23:34:12 +03:00
Stop using ProgressDialog, there is a theme issue with it.
It's not maintain by Google since it's deprecated. Force usage of MaterialAlertDialogBuilder to have the same UI effect. We sometimes need to block the UI :/
This commit is contained in:
parent
43cad8751d
commit
885f5736c9
5 changed files with 95 additions and 14 deletions
|
@ -24,6 +24,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import im.vector.lib.ui.styles.R
|
import im.vector.lib.ui.styles.R
|
||||||
import im.vector.lib.ui.styles.databinding.ActivityDebugMaterialThemeBinding
|
import im.vector.lib.ui.styles.databinding.ActivityDebugMaterialThemeBinding
|
||||||
|
import im.vector.lib.ui.styles.dialogs.MaterialProgressDialog
|
||||||
|
|
||||||
// Rendering is not the same with VectorBaseActivity
|
// Rendering is not the same with VectorBaseActivity
|
||||||
abstract class DebugMaterialThemeActivity : AppCompatActivity() {
|
abstract class DebugMaterialThemeActivity : AppCompatActivity() {
|
||||||
|
@ -61,6 +62,11 @@ abstract class DebugMaterialThemeActivity : AppCompatActivity() {
|
||||||
showTestDialog(R.style.ThemeOverlay_Vector_MaterialAlertDialog_NegativeDestructive)
|
showTestDialog(R.style.ThemeOverlay_Vector_MaterialAlertDialog_NegativeDestructive)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
views.debugShowProgressDialog.setOnClickListener {
|
||||||
|
MaterialProgressDialog(this)
|
||||||
|
.show(message = "Progress Dialog\nLine 2", cancellable = true)
|
||||||
|
}
|
||||||
|
|
||||||
views.debugShowBottomSheet.setOnClickListener {
|
views.debugShowBottomSheet.setOnClickListener {
|
||||||
DebugBottomSheet().show(supportFragmentManager, "TAG")
|
DebugBottomSheet().show(supportFragmentManager, "TAG")
|
||||||
}
|
}
|
||||||
|
|
|
@ -466,6 +466,13 @@
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:text="Show Dialog Neg Destructive" />
|
android:text="Show Dialog Neg Destructive" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/debugShowProgressDialog"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:text="Show Progress Dialog" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/debugShowBottomSheet"
|
android:id="@+id/debugShowBottomSheet"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
37
library/ui-styles/src/main/java/MaterialProgressDialog.kt
Normal file
37
library/ui-styles/src/main/java/MaterialProgressDialog.kt
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 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.lib.ui.styles.dialogs
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import im.vector.lib.ui.styles.R
|
||||||
|
import im.vector.lib.ui.styles.databinding.DialogProgressMaterialBinding
|
||||||
|
|
||||||
|
class MaterialProgressDialog(val context: Context) {
|
||||||
|
fun show(message: CharSequence, cancellable: Boolean = false): AlertDialog {
|
||||||
|
val view = LayoutInflater.from(context).inflate(R.layout.dialog_progress_material, null)
|
||||||
|
val views = DialogProgressMaterialBinding.bind(view)
|
||||||
|
views.message.text = message
|
||||||
|
|
||||||
|
return MaterialAlertDialogBuilder(context)
|
||||||
|
.setCancelable(cancellable)
|
||||||
|
.setView(view)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<!-- Inspired from https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/layout/progress_dialog.xml -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/body"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:baselineAligned="false"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingStart="8dp"
|
||||||
|
android:paddingTop="10dp"
|
||||||
|
android:paddingEnd="8dp"
|
||||||
|
android:paddingBottom="10dp">
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@android:id/progress"
|
||||||
|
style="?android:attr/progressBarStyle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="12dp"
|
||||||
|
android:max="10000" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/message"
|
||||||
|
style="@style/Widget.Vector.TextView.Body"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
tools:text="Content\nLine 2" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
|
@ -14,11 +14,8 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:Suppress("DEPRECATION")
|
|
||||||
|
|
||||||
package im.vector.app.core.platform
|
package im.vector.app.core.platform
|
||||||
|
|
||||||
import android.app.ProgressDialog
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
|
@ -29,11 +26,12 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.annotation.CallSuper
|
import androidx.annotation.CallSuper
|
||||||
import androidx.annotation.MainThread
|
import androidx.annotation.MainThread
|
||||||
import com.google.android.material.appbar.MaterialToolbar
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import com.airbnb.mvrx.BaseMvRxFragment
|
import com.airbnb.mvrx.BaseMvRxFragment
|
||||||
import com.bumptech.glide.util.Util.assertMainThread
|
import com.bumptech.glide.util.Util.assertMainThread
|
||||||
|
import com.google.android.material.appbar.MaterialToolbar
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.jakewharton.rxbinding3.view.clicks
|
import com.jakewharton.rxbinding3.view.clicks
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
|
@ -44,10 +42,10 @@ import im.vector.app.core.dialogs.UnrecognizedCertificateDialog
|
||||||
import im.vector.app.core.error.ErrorFormatter
|
import im.vector.app.core.error.ErrorFormatter
|
||||||
import im.vector.app.core.extensions.toMvRxBundle
|
import im.vector.app.core.extensions.toMvRxBundle
|
||||||
import im.vector.app.features.navigation.Navigator
|
import im.vector.app.features.navigation.Navigator
|
||||||
|
import im.vector.lib.ui.styles.dialogs.MaterialProgressDialog
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@ -67,7 +65,7 @@ abstract class VectorBaseFragment<VB: ViewBinding> : BaseMvRxFragment(), HasScre
|
||||||
protected lateinit var errorFormatter: ErrorFormatter
|
protected lateinit var errorFormatter: ErrorFormatter
|
||||||
protected lateinit var unrecognizedCertificateDialog: UnrecognizedCertificateDialog
|
protected lateinit var unrecognizedCertificateDialog: UnrecognizedCertificateDialog
|
||||||
|
|
||||||
private var progress: ProgressDialog? = null
|
private var progress: AlertDialog? = null
|
||||||
|
|
||||||
/* ==========================================================================================
|
/* ==========================================================================================
|
||||||
* View model
|
* View model
|
||||||
|
@ -203,14 +201,10 @@ abstract class VectorBaseFragment<VB: ViewBinding> : BaseMvRxFragment(), HasScre
|
||||||
vectorBaseActivity.getCoordinatorLayout()?.showOptimizedSnackbar(errorFormatter.toHumanReadable(throwable))
|
vectorBaseActivity.getCoordinatorLayout()?.showOptimizedSnackbar(errorFormatter.toHumanReadable(throwable))
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun showLoadingDialog(message: CharSequence? = null, cancelable: Boolean = false) {
|
protected fun showLoadingDialog(message: CharSequence? = null) {
|
||||||
progress?.dismiss()
|
progress?.dismiss()
|
||||||
progress = ProgressDialog(requireContext()).apply {
|
progress = MaterialProgressDialog(requireContext())
|
||||||
setCancelable(cancelable)
|
.show(message ?: getString(R.string.please_wait))
|
||||||
setMessage(message ?: getString(R.string.please_wait))
|
|
||||||
setProgressStyle(ProgressDialog.STYLE_SPINNER)
|
|
||||||
show()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun dismissLoadingDialog() {
|
protected fun dismissLoadingDialog() {
|
||||||
|
|
Loading…
Reference in a new issue