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

Commit 45ef26d0 authored by tibbi's avatar tibbi
Browse files

couple tweaks related to shared theme handling

parent 800dd971
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -6,7 +6,7 @@ buildscript {
        propMinSdkVersion = 16
        propMinSdkVersion = 16
        propTargetSdkVersion = propCompileSdkVersion
        propTargetSdkVersion = propCompileSdkVersion
        propVersionCode = 1
        propVersionCode = 1
        propVersionName = '3.18.0'
        propVersionName = '3.18.5'
        kotlin_version = '1.2.31'
        kotlin_version = '1.2.31'
        support_libs = '27.1.0'
        support_libs = '27.1.0'
    }
    }
+8 −9
Original line number Original line Diff line number Diff line
@@ -36,6 +36,10 @@ class CustomizationActivity : BaseSimpleActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_customization)
        setContentView(R.layout.activity_customization)
        storedSharedTheme = getSharedThemeSync(getMyContentProviderCursorLoader())
        if (storedSharedTheme != null) {
            baseConfig.wasSharedThemeEverActivated = true
        }


        predefinedThemes.apply {
        predefinedThemes.apply {
            put(THEME_LIGHT, MyTheme(R.string.light_theme, R.color.theme_light_text_color, R.color.theme_light_background_color, R.color.color_primary))
            put(THEME_LIGHT, MyTheme(R.string.light_theme, R.color.theme_light_text_color, R.color.theme_light_background_color, R.color.color_primary))
@@ -44,21 +48,16 @@ class CustomizationActivity : BaseSimpleActivity() {
            put(THEME_DARK_RED, MyTheme(R.string.dark_red, R.color.theme_dark_text_color, R.color.theme_dark_background_color, R.color.theme_dark_red_primary_color))
            put(THEME_DARK_RED, MyTheme(R.string.dark_red, R.color.theme_dark_text_color, R.color.theme_dark_background_color, R.color.theme_dark_red_primary_color))
            put(THEME_BLACK_WHITE, MyTheme(R.string.black_white, android.R.color.white, android.R.color.black, android.R.color.black))
            put(THEME_BLACK_WHITE, MyTheme(R.string.black_white, android.R.color.white, android.R.color.black, android.R.color.black))
            put(THEME_CUSTOM, MyTheme(R.string.custom, 0, 0, 0))
            put(THEME_CUSTOM, MyTheme(R.string.custom, 0, 0, 0))

            if (storedSharedTheme != null) {
                put(THEME_SHARED, MyTheme(R.string.shared, 0, 0, 0))
            }
        }
        }


        if (!isThankYouInstalled()) {
        if (!isThankYouInstalled()) {
            baseConfig.isUsingSharedTheme = false
            baseConfig.isUsingSharedTheme = false
        }
        }


        getSharedTheme {
            if (it != null) {
                storedSharedTheme = it
                baseConfig.wasSharedThemeEverActivated = true
                apply_to_all_holder.beGone()
                predefinedThemes[THEME_SHARED] = MyTheme(R.string.shared, it.textColor, it.backgroundColor, it.primaryColor)
            }
        }

        supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_cross)
        supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_cross)
        updateTextColors(customization_holder)
        updateTextColors(customization_holder)
        initColorVariables()
        initColorVariables()
+2 −3
Original line number Original line Diff line number Diff line
@@ -677,14 +677,13 @@ fun BaseSimpleActivity.createDirectorySync(directory: String): Boolean {


fun Activity.isActivityDestroyed() = isJellyBean1Plus() && isDestroyed
fun Activity.isActivityDestroyed() = isJellyBean1Plus() && isDestroyed


fun Activity.updateSharedTheme(sharedTheme: SharedTheme): Int {
fun Activity.updateSharedTheme(sharedTheme: SharedTheme) {
    try {
    try {
        val contentValues = MyContentProvider.fillThemeContentValues(sharedTheme)
        val contentValues = MyContentProvider.fillThemeContentValues(sharedTheme)
        return applicationContext.contentResolver.update(MyContentProvider.CONTENT_URI, contentValues, null, null)
        applicationContext.contentResolver.update(MyContentProvider.MY_CONTENT_URI, contentValues, null, null)
    } catch (e: Exception) {
    } catch (e: Exception) {
        showErrorToast(e)
        showErrorToast(e)
    }
    }
    return 0
}
}


fun Activity.copyToClipboard(text: String) {
fun Activity.copyToClipboard(text: String) {
+21 −18
Original line number Original line Diff line number Diff line
@@ -314,29 +314,32 @@ fun Context.getFilenameFromContentUri(uri: Uri): String? {
}
}


fun Context.getSharedTheme(callback: (sharedTheme: SharedTheme?) -> Unit) {
fun Context.getSharedTheme(callback: (sharedTheme: SharedTheme?) -> Unit) {
    var wasSharedThemeReturned = false
    val cursorLoader = getMyContentProviderCursorLoader()
    val cursorLoader = CursorLoader(this, MyContentProvider.CONTENT_URI, null, null, null, null)
    Thread {
    Thread {
        val cursor = cursorLoader.loadInBackground()
        callback(getSharedThemeSync(cursorLoader))
    }.start()
}

fun Context.getSharedThemeSync(cursorLoader: CursorLoader): SharedTheme? {
    if (!isThankYouInstalled()) {
        return null
    }


    val cursor = cursorLoader.loadInBackground()
    cursor?.use {
    cursor?.use {
        if (cursor.moveToFirst()) {
        if (cursor.moveToFirst()) {
            val textColor = cursor.getIntValue(COL_TEXT_COLOR)
            val textColor = cursor.getIntValue(COL_TEXT_COLOR)
            val backgroundColor = cursor.getIntValue(COL_BACKGROUND_COLOR)
            val backgroundColor = cursor.getIntValue(COL_BACKGROUND_COLOR)
            val primaryColor = cursor.getIntValue(COL_PRIMARY_COLOR)
            val primaryColor = cursor.getIntValue(COL_PRIMARY_COLOR)
            val lastUpdatedTS = cursor.getIntValue(COL_LAST_UPDATED_TS)
            val lastUpdatedTS = cursor.getIntValue(COL_LAST_UPDATED_TS)
                val sharedTheme = SharedTheme(textColor, backgroundColor, primaryColor, lastUpdatedTS)
            return SharedTheme(textColor, backgroundColor, primaryColor, lastUpdatedTS)
                callback(sharedTheme)
                wasSharedThemeReturned = true
            }
        }
        }

        if (!wasSharedThemeReturned) {
            callback(null)
    }
    }
    }.start()
    return null
}
}


fun Context.getMyContentProviderCursorLoader() = CursorLoader(this, MyContentProvider.MY_CONTENT_URI, null, null, null, null)

fun Context.getDialogTheme() = if (baseConfig.backgroundColor.getContrastColor() == Color.WHITE) R.style.MyDialogTheme_Dark else R.style.MyDialogTheme
fun Context.getDialogTheme() = if (baseConfig.backgroundColor.getContrastColor() == Color.WHITE) R.style.MyDialogTheme_Dark else R.style.MyDialogTheme


fun Context.getCurrentFormattedDateTime(): String {
fun Context.getCurrentFormattedDateTime(): String {
+8 −9
Original line number Original line Diff line number Diff line
@@ -6,16 +6,15 @@ import com.simplemobiletools.commons.models.SharedTheme


class MyContentProvider {
class MyContentProvider {
    companion object {
    companion object {
        val AUTHORITY = "com.simplemobiletools.commons.provider"
        private const val AUTHORITY = "com.simplemobiletools.commons.provider"
        val CONTENT_URI = Uri.parse("content://$AUTHORITY/themes")
        const val SHARED_THEME_ACTIVATED = "com.simplemobiletools.commons.SHARED_THEME_ACTIVATED"
        val SHARED_THEME_ACTIVATED = "com.simplemobiletools.commons.SHARED_THEME_ACTIVATED"
        const val SHARED_THEME_UPDATED = "com.simplemobiletools.commons.SHARED_THEME_UPDATED"
        val SHARED_THEME_UPDATED = "com.simplemobiletools.commons.SHARED_THEME_UPDATED"
        val MY_CONTENT_URI = Uri.parse("content://$AUTHORITY/themes")


        val COL_ID = "_id"
        const val COL_TEXT_COLOR = "text_color"
        val COL_TEXT_COLOR = "text_color"
        const val COL_BACKGROUND_COLOR = "background_color"
        val COL_BACKGROUND_COLOR = "background_color"
        const val COL_PRIMARY_COLOR = "primary_color"
        val COL_PRIMARY_COLOR = "primary_color"
        const val COL_LAST_UPDATED_TS = "last_updated_ts"
        val COL_LAST_UPDATED_TS = "last_updated_ts"


        fun fillThemeContentValues(sharedTheme: SharedTheme) = ContentValues().apply {
        fun fillThemeContentValues(sharedTheme: SharedTheme) = ContentValues().apply {
            put(COL_TEXT_COLOR, sharedTheme.textColor)
            put(COL_TEXT_COLOR, sharedTheme.textColor)