couple tweaks related to shared theme handling
This commit is contained in:
parent
800dd9710a
commit
45ef26d05a
5 changed files with 41 additions and 41 deletions
|
@ -6,7 +6,7 @@ buildscript {
|
|||
propMinSdkVersion = 16
|
||||
propTargetSdkVersion = propCompileSdkVersion
|
||||
propVersionCode = 1
|
||||
propVersionName = '3.18.0'
|
||||
propVersionName = '3.18.5'
|
||||
kotlin_version = '1.2.31'
|
||||
support_libs = '27.1.0'
|
||||
}
|
||||
|
|
|
@ -36,6 +36,10 @@ class CustomizationActivity : BaseSimpleActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_customization)
|
||||
storedSharedTheme = getSharedThemeSync(getMyContentProviderCursorLoader())
|
||||
if (storedSharedTheme != null) {
|
||||
baseConfig.wasSharedThemeEverActivated = true
|
||||
}
|
||||
|
||||
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))
|
||||
|
@ -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_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))
|
||||
|
||||
if (storedSharedTheme != null) {
|
||||
put(THEME_SHARED, MyTheme(R.string.shared, 0, 0, 0))
|
||||
}
|
||||
}
|
||||
|
||||
if (!isThankYouInstalled()) {
|
||||
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)
|
||||
updateTextColors(customization_holder)
|
||||
initColorVariables()
|
||||
|
|
|
@ -677,14 +677,13 @@ fun BaseSimpleActivity.createDirectorySync(directory: String): Boolean {
|
|||
|
||||
fun Activity.isActivityDestroyed() = isJellyBean1Plus() && isDestroyed
|
||||
|
||||
fun Activity.updateSharedTheme(sharedTheme: SharedTheme): Int {
|
||||
fun Activity.updateSharedTheme(sharedTheme: SharedTheme) {
|
||||
try {
|
||||
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) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
fun Activity.copyToClipboard(text: String) {
|
||||
|
|
|
@ -314,29 +314,32 @@ fun Context.getFilenameFromContentUri(uri: Uri): String? {
|
|||
}
|
||||
|
||||
fun Context.getSharedTheme(callback: (sharedTheme: SharedTheme?) -> Unit) {
|
||||
var wasSharedThemeReturned = false
|
||||
val cursorLoader = CursorLoader(this, MyContentProvider.CONTENT_URI, null, null, null, null)
|
||||
val cursorLoader = getMyContentProviderCursorLoader()
|
||||
Thread {
|
||||
val cursor = cursorLoader.loadInBackground()
|
||||
|
||||
cursor?.use {
|
||||
if (cursor.moveToFirst()) {
|
||||
val textColor = cursor.getIntValue(COL_TEXT_COLOR)
|
||||
val backgroundColor = cursor.getIntValue(COL_BACKGROUND_COLOR)
|
||||
val primaryColor = cursor.getIntValue(COL_PRIMARY_COLOR)
|
||||
val lastUpdatedTS = cursor.getIntValue(COL_LAST_UPDATED_TS)
|
||||
val sharedTheme = SharedTheme(textColor, backgroundColor, primaryColor, lastUpdatedTS)
|
||||
callback(sharedTheme)
|
||||
wasSharedThemeReturned = true
|
||||
}
|
||||
}
|
||||
|
||||
if (!wasSharedThemeReturned) {
|
||||
callback(null)
|
||||
}
|
||||
callback(getSharedThemeSync(cursorLoader))
|
||||
}.start()
|
||||
}
|
||||
|
||||
fun Context.getSharedThemeSync(cursorLoader: CursorLoader): SharedTheme? {
|
||||
if (!isThankYouInstalled()) {
|
||||
return null
|
||||
}
|
||||
|
||||
val cursor = cursorLoader.loadInBackground()
|
||||
cursor?.use {
|
||||
if (cursor.moveToFirst()) {
|
||||
val textColor = cursor.getIntValue(COL_TEXT_COLOR)
|
||||
val backgroundColor = cursor.getIntValue(COL_BACKGROUND_COLOR)
|
||||
val primaryColor = cursor.getIntValue(COL_PRIMARY_COLOR)
|
||||
val lastUpdatedTS = cursor.getIntValue(COL_LAST_UPDATED_TS)
|
||||
return SharedTheme(textColor, backgroundColor, primaryColor, lastUpdatedTS)
|
||||
}
|
||||
}
|
||||
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.getCurrentFormattedDateTime(): String {
|
||||
|
|
|
@ -6,16 +6,15 @@ import com.simplemobiletools.commons.models.SharedTheme
|
|||
|
||||
class MyContentProvider {
|
||||
companion object {
|
||||
val AUTHORITY = "com.simplemobiletools.commons.provider"
|
||||
val CONTENT_URI = Uri.parse("content://$AUTHORITY/themes")
|
||||
val SHARED_THEME_ACTIVATED = "com.simplemobiletools.commons.SHARED_THEME_ACTIVATED"
|
||||
val SHARED_THEME_UPDATED = "com.simplemobiletools.commons.SHARED_THEME_UPDATED"
|
||||
private const val AUTHORITY = "com.simplemobiletools.commons.provider"
|
||||
const val SHARED_THEME_ACTIVATED = "com.simplemobiletools.commons.SHARED_THEME_ACTIVATED"
|
||||
const val SHARED_THEME_UPDATED = "com.simplemobiletools.commons.SHARED_THEME_UPDATED"
|
||||
val MY_CONTENT_URI = Uri.parse("content://$AUTHORITY/themes")
|
||||
|
||||
val COL_ID = "_id"
|
||||
val COL_TEXT_COLOR = "text_color"
|
||||
val COL_BACKGROUND_COLOR = "background_color"
|
||||
val COL_PRIMARY_COLOR = "primary_color"
|
||||
val COL_LAST_UPDATED_TS = "last_updated_ts"
|
||||
const val COL_TEXT_COLOR = "text_color"
|
||||
const val COL_BACKGROUND_COLOR = "background_color"
|
||||
const val COL_PRIMARY_COLOR = "primary_color"
|
||||
const val COL_LAST_UPDATED_TS = "last_updated_ts"
|
||||
|
||||
fun fillThemeContentValues(sharedTheme: SharedTheme) = ContentValues().apply {
|
||||
put(COL_TEXT_COLOR, sharedTheme.textColor)
|
||||
|
|
Loading…
Reference in a new issue