mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-21 10:17:56 +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);
|
||||
|
||||
Reference in New Issue
Block a user