From a7c0e87f40a726d01de61646a5395bf962e5b546 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 12 Jun 2019 16:30:30 +0200 Subject: [PATCH] Alerter: upgrade lib and change status icon color when alert is displayed --- vector/build.gradle | 2 +- .../IncomingVerificationRequestHandler.kt | 50 +++++++++---------- .../features/popup/PopupAlertManager.kt | 27 ++++++++++ 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/vector/build.gradle b/vector/build.gradle index 9ee7c5e123..10953eb43f 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -192,7 +192,7 @@ dependencies { implementation 'com.nulab-inc:zxcvbn:1.2.5' //Alerter - implementation 'com.tapadoo.android:alerter:3.0.2' + implementation 'com.tapadoo.android:alerter:4.0.3' implementation 'com.otaliastudios:autocomplete:1.1.0' diff --git a/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/IncomingVerificationRequestHandler.kt b/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/IncomingVerificationRequestHandler.kt index 2e412de377..3f89a16199 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/IncomingVerificationRequestHandler.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/crypto/verification/IncomingVerificationRequestHandler.kt @@ -48,38 +48,38 @@ class IncomingVerificationRequestHandler(val context: Context, "kvr_${tx.transactionId}", context.getString(R.string.sas_incoming_request_notif_title), context.getString(R.string.sas_incoming_request_notif_content, name), - R.drawable.shield - ).apply { - contentAction = Runnable { - val intent = SASVerificationActivity.incomingIntent(context, - session.sessionParams.credentials.userId, - tx.otherUserId, - tx.transactionId) - weakCurrentActivity?.get()?.startActivity(intent) - } - dismissedAction = Runnable { - tx.cancel() - } - addButton( - context.getString(R.string.ignore), - Runnable { - tx.cancel() - } - ) - addButton( - context.getString(R.string.action_open), - Runnable { + R.drawable.shield) + .apply { + contentAction = Runnable { val intent = SASVerificationActivity.incomingIntent(context, session.sessionParams.credentials.userId, tx.otherUserId, tx.transactionId) weakCurrentActivity?.get()?.startActivity(intent) } - ) - //10mn expiration - expirationTimestamp = System.currentTimeMillis() + (10 * 60 * 1000L) + dismissedAction = Runnable { + tx.cancel() + } + addButton( + context.getString(R.string.ignore), + Runnable { + tx.cancel() + } + ) + addButton( + context.getString(R.string.action_open), + Runnable { + val intent = SASVerificationActivity.incomingIntent(context, + session.sessionParams.credentials.userId, + tx.otherUserId, + tx.transactionId) + weakCurrentActivity?.get()?.startActivity(intent) + } + ) + //10mn expiration + expirationTimestamp = System.currentTimeMillis() + (10 * 60 * 1000L) - } + } PopupAlertManager.postVectorAlert(alert) } SasVerificationTxState.Cancelled, diff --git a/vector/src/main/java/im/vector/riotredesign/features/popup/PopupAlertManager.kt b/vector/src/main/java/im/vector/riotredesign/features/popup/PopupAlertManager.kt index f658b4965e..7d547abcd4 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/popup/PopupAlertManager.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/popup/PopupAlertManager.kt @@ -16,6 +16,7 @@ package im.vector.riotredesign.features.popup import android.app.Activity +import android.os.Build import android.os.Handler import android.os.Looper import android.view.View @@ -28,6 +29,7 @@ import im.vector.riotredesign.features.crypto.verification.SASVerificationActivi import timber.log.Timber import java.lang.ref.WeakReference + /** * Responsible of displaying important popup alerts on top of the screen. * Alerts are stacked and will be displayed sequentially @@ -71,6 +73,7 @@ object PopupAlertManager { if (currentAlerter != null) { weakCurrentActivity?.get()?.let { Alerter.clearCurrent(it) + setLightStatusBar() } } @@ -134,7 +137,29 @@ object PopupAlertManager { } } + private fun clearLightStatusBar() { + val view = weakCurrentActivity?.get()?.window?.decorView + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && view != null) { + var flags = view.systemUiVisibility + flags = flags and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() + view.systemUiVisibility = flags + } + } + + private fun setLightStatusBar() { + val view = weakCurrentActivity?.get()?.window?.decorView + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && view != null) { + var flags = view.systemUiVisibility + flags = flags or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR + view.systemUiVisibility = flags + } + } + private fun showAlert(alert: VectorAlert, activity: Activity, animate: Boolean = true) { + clearLightStatusBar() + alert.weakCurrentActivity = WeakReference(activity) Alerter.create(activity) .setTitle(alert.title) @@ -192,6 +217,8 @@ object PopupAlertManager { private fun currentIsDismissed() { //current alert has been hidden + setLightStatusBar() + currentAlerter = null Handler(Looper.getMainLooper()).postDelayed({ displayNextIfPossible()