mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-25 05:27:42 +00:00
committed by
Cody Henthorne
parent
b41bf66133
commit
17581a7a5e
@@ -2,24 +2,54 @@
|
||||
|
||||
package org.thoughtcrime.securesms.components
|
||||
|
||||
import android.app.ProgressDialog
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.os.Build
|
||||
import android.view.LayoutInflater
|
||||
import android.view.WindowManager
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.progressindicator.CircularProgressIndicator
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.util.ViewUtil
|
||||
|
||||
/**
|
||||
* Wraps a normal progress dialog for showing blocking in-progress UI.
|
||||
*/
|
||||
class SignalProgressDialog private constructor(val progressDialog: ProgressDialog) {
|
||||
class SignalProgressDialog private constructor(
|
||||
private val dialog: AlertDialog,
|
||||
private val titleView: TextView,
|
||||
private val messageView: TextView,
|
||||
private val progressBar: CircularProgressIndicator
|
||||
) {
|
||||
|
||||
val isShowing: Boolean
|
||||
get() = progressDialog.isShowing
|
||||
get() = dialog.isShowing
|
||||
|
||||
var isIndeterminate: Boolean
|
||||
get() = progressBar.isIndeterminate
|
||||
set(value) = progressBar.setIndeterminate(value)
|
||||
|
||||
var progress: Int
|
||||
get() = progressBar.progress
|
||||
set(value) = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
progressBar.setProgress(value, true)
|
||||
} else {
|
||||
progressBar.setProgress(value)
|
||||
}
|
||||
|
||||
fun setMessage(message: CharSequence?) {
|
||||
messageView.text = message
|
||||
}
|
||||
|
||||
fun hide() {
|
||||
progressDialog.hide()
|
||||
dialog.hide()
|
||||
}
|
||||
|
||||
fun dismiss() {
|
||||
progressDialog.dismiss()
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -33,7 +63,31 @@ class SignalProgressDialog private constructor(val progressDialog: ProgressDialo
|
||||
cancelable: Boolean = false,
|
||||
cancelListener: DialogInterface.OnCancelListener? = null
|
||||
): SignalProgressDialog {
|
||||
return SignalProgressDialog(ProgressDialog.show(context, title, message, indeterminate, cancelable, cancelListener))
|
||||
val builder = MaterialAlertDialogBuilder(context).apply {
|
||||
setTitle(null)
|
||||
setMessage(null)
|
||||
setCancelable(cancelable)
|
||||
setOnCancelListener(cancelListener)
|
||||
}
|
||||
|
||||
val customView = LayoutInflater.from(context).inflate(R.layout.signal_progress_dialog, null) as ConstraintLayout
|
||||
val titleView: TextView = customView.findViewById(R.id.progress_dialog_title)
|
||||
val messageView: TextView = customView.findViewById(R.id.progress_dialog_message)
|
||||
val progressView: CircularProgressIndicator = customView.findViewById(R.id.progress_dialog_progressbar)
|
||||
|
||||
titleView.text = title
|
||||
messageView.text = message
|
||||
progressView.isIndeterminate = indeterminate
|
||||
|
||||
builder.setView(customView)
|
||||
val dialog = builder.show()
|
||||
|
||||
val layoutParams = WindowManager.LayoutParams()
|
||||
layoutParams.copyFrom(dialog.window?.attributes)
|
||||
layoutParams.width = ViewUtil.dpToPx(context, 260)
|
||||
dialog.window?.attributes = layoutParams
|
||||
|
||||
return SignalProgressDialog(dialog, titleView, messageView, progressView)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,9 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* Helper class to show a fullscreen blocking indeterminate progress dialog.
|
||||
* @deprecated Replaced by {@link org.thoughtcrime.securesms.components.SignalProgressDialog}
|
||||
*/
|
||||
@Deprecated
|
||||
public final class SimpleProgressDialog {
|
||||
|
||||
private static final String TAG = Log.tag(SimpleProgressDialog.class);
|
||||
|
||||
42
app/src/main/res/layout/signal_progress_dialog.xml
Normal file
42
app/src/main/res/layout/signal_progress_dialog.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright 2024 Signal Messenger, LLC
|
||||
~ SPDX-License-Identifier: AGPL-3.0-only
|
||||
-->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||
android:id="@+id/progress_dialog_progressbar"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="62dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:indicatorColor="@color/signal_colorPrimary"
|
||||
app:trackColor="@color/signal_colorPrimaryContainer" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/progress_dialog_title"
|
||||
style="@style/Signal.Text.BodyMedium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/progress_dialog_progressbar" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/progress_dialog_message"
|
||||
style="@style/Signal.Text.Caption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="38dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/progress_dialog_title" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user