replace lovelyDialog with MaterialAlert

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-08-11 16:31:05 +02:00
parent 53f0779a44
commit 9298de0d43
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
2 changed files with 23 additions and 9 deletions

View File

@ -27,8 +27,10 @@ import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.WindowManager import android.view.WindowManager
import android.webkit.SslErrorHandler import android.webkit.SslErrorHandler
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import autodagger.AutoInjector import autodagger.AutoInjector
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.nextcloud.talk.R import com.nextcloud.talk.R
import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.events.CertificateEvent import com.nextcloud.talk.events.CertificateEvent
@ -36,7 +38,6 @@ import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.utils.SecurityUtils import com.nextcloud.talk.utils.SecurityUtils
import com.nextcloud.talk.utils.preferences.AppPreferences import com.nextcloud.talk.utils.preferences.AppPreferences
import com.nextcloud.talk.utils.ssl.MagicTrustManager import com.nextcloud.talk.utils.ssl.MagicTrustManager
import com.yarolegovich.lovelydialog.LovelyStandardDialog
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode import org.greenrobot.eventbus.ThreadMode
@ -114,21 +115,26 @@ open class BaseActivity : AppCompatActivity() {
issuedBy, issuedFor, validFrom, validUntil issuedBy, issuedFor, validFrom, validUntil
) )
LovelyStandardDialog(this) val dialogBuilder = MaterialAlertDialogBuilder(this)
.setTopColorRes(R.color.nc_darkRed) .setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_security_white_24dp))
.setNegativeButtonColorRes(R.color.nc_darkRed)
.setPositiveButtonColor(viewThemeUtils.getScheme(this).primary)
.setIcon(R.drawable.ic_security_white_24dp)
.setTitle(R.string.nc_certificate_dialog_title) .setTitle(R.string.nc_certificate_dialog_title)
.setMessage(dialogText) .setMessage(dialogText)
.setPositiveButton(R.string.nc_yes) { v -> .setPositiveButton(R.string.nc_yes) { _, _ ->
magicTrustManager.addCertInTrustStore(cert) magicTrustManager.addCertInTrustStore(cert)
sslErrorHandler?.proceed() sslErrorHandler?.proceed()
} }
.setNegativeButton(R.string.nc_no) { view1 -> .setNegativeButton(R.string.nc_no) { _, _ ->
sslErrorHandler?.cancel() sslErrorHandler?.cancel()
} }
.show()
viewThemeUtils.colorMaterialAlertDialogBackground(context, dialogBuilder)
val dialog = dialogBuilder.show()
viewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
)
} catch (e: CertificateParsingException) { } catch (e: CertificateParsingException) {
Log.d(TAG, "Failed to parse the certificate") Log.d(TAG, "Failed to parse the certificate")
} }

View File

@ -801,6 +801,14 @@ class ViewThemeUtils @Inject constructor(private val theme: ServerTheme, private
return spannable return spannable
} }
fun colorMaterialAlertDialogIcon(context: Context, drawableId: Int): Drawable {
val drawable = AppCompatResources.getDrawable(context, drawableId)!!
withScheme(context) { scheme ->
DrawableCompat.setTint(drawable, scheme.secondary)
}
return drawable
}
companion object { companion object {
private val THEMEABLE_PLACEHOLDER_IDS = listOf( private val THEMEABLE_PLACEHOLDER_IDS = listOf(
R.drawable.ic_mimetype_package_x_generic, R.drawable.ic_mimetype_package_x_generic,