Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cf5c342d authored by tibbi's avatar tibbi
Browse files

fix toast message threading

parent e1c00b99
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ buildscript {
        propMinSdkVersion = 21
        propTargetSdkVersion = propCompileSdkVersion
        propVersionCode = 1
        propVersionName = '5.5.4'
        propVersionName = '5.5.5'
        kotlin_version = '1.3.10'
    }

+8 −8
Original line number Diff line number Diff line
@@ -91,18 +91,18 @@ fun Context.isBlackAndWhiteTheme() = baseConfig.textColor == Color.WHITE && base
fun Context.getAdjustedPrimaryColor() = if (isBlackAndWhiteTheme()) Color.WHITE else baseConfig.primaryColor

fun Context.toast(id: Int, length: Int = Toast.LENGTH_SHORT) {
    if (isOnMainThread()) {
        toast(getString(id), length)
    } else {
        Handler(Looper.getMainLooper()).post {
    toast(getString(id), length)
}
    }
}

fun Context.toast(msg: String, length: Int = Toast.LENGTH_SHORT) {
    try {
        if (isOnMainThread()) {
            Toast.makeText(applicationContext, msg, length).show()
        } else {
            Handler(Looper.getMainLooper()).post {
                Toast.makeText(applicationContext, msg, length).show()
            }
        }
    } catch (e: Exception) {
    }
}