Alerter: upgrade lib and change status icon color when alert is displayed

This commit is contained in:
Benoit Marty 2019-06-12 16:30:30 +02:00
parent af1a48d918
commit a7c0e87f40
3 changed files with 53 additions and 26 deletions

View File

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


View File

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

View File

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