Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,30 @@ android {
applicationId = "com.sameerasw.essentials"
minSdk = 26
targetSdk = 36
versionCode = 29
versionName = "11.5"
versionCode = 30
versionName = "11.6"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {

// optimized dev build

// debug {
// isMinifyEnabled = true
// isShrinkResources = true
// isDebuggable = false
//
// proguardFiles(
// getDefaultProguardFile("proguard-android-optimize.txt"),
// "proguard-rules.pro"
// )
// }

// end


release {
isMinifyEnabled = true
isShrinkResources = true
Expand Down
1 change: 1 addition & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
# Kotlin Reflect
-keep class kotlin.reflect.** { *; }
-keep class com.sameerasw.essentials.domain.model.** { *; }
-keep class com.sameerasw.essentials.domain.diy.** { *; }

# Prevent over-minification of settings and registry classes
-keep class com.sameerasw.essentials.data.repository.** { *; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ class GitHubRepository {
}
if (connection.responseCode == 200) {
val data = connection.inputStream.bufferedReader().readText()
val listType =
object : com.google.gson.reflect.TypeToken<List<GitHubRelease>>() {}.type
gson.fromJson(data, listType)
gson.fromJson(data, Array<GitHubRelease>::class.java).toList()
} else if (connection.responseCode == 403 || connection.responseCode == 429) {
throw Exception("RATE_LIMIT")
} else emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.sameerasw.essentials.data.repository
import android.content.Context
import android.content.SharedPreferences
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.sameerasw.essentials.domain.HapticFeedbackType
import com.sameerasw.essentials.domain.model.AppSelection
import com.sameerasw.essentials.domain.model.NotificationLightingColorMode
Expand Down Expand Up @@ -247,9 +246,8 @@ class SettingsRepository(private val context: Context) {
fun getNotificationLightingGlowSides(): Set<NotificationLightingSide> {
val json = prefs.getString(KEY_EDGE_LIGHTING_GLOW_SIDES, null)
return if (json != null) {
val type = object : TypeToken<Set<NotificationLightingSide>>() {}.type
try {
gson.fromJson(json, type)
gson.fromJson(json, Array<NotificationLightingSide>::class.java).toSet()
} catch (e: Exception) {
setOf(NotificationLightingSide.LEFT, NotificationLightingSide.RIGHT)
}
Expand All @@ -267,7 +265,7 @@ class SettingsRepository(private val context: Context) {
val json = prefs.getString(KEY_FREEZE_AUTO_EXCLUDED_APPS, null)
return if (json != null) {
try {
gson.fromJson(json, object : TypeToken<Set<String>>() {}.type) ?: emptySet()
gson.fromJson(json, Array<String>::class.java).toSet()
} catch (e: Exception) {
emptySet()
}
Expand Down Expand Up @@ -310,7 +308,7 @@ class SettingsRepository(private val context: Context) {
val json = prefs.getString(KEY_CALENDAR_SYNC_SELECTED_CALENDARS, null)
return if (json != null) {
try {
gson.fromJson(json, object : TypeToken<Set<String>>() {}.type) ?: emptySet()
gson.fromJson(json, Array<String>::class.java).toSet()
} catch (e: Exception) {
emptySet()
}
Expand All @@ -332,9 +330,8 @@ class SettingsRepository(private val context: Context) {
private fun loadAppSelection(key: String): List<AppSelection> {
val json = prefs.getString(key, null)
return if (json != null) {
val type = object : TypeToken<List<AppSelection>>() {}.type
try {
gson.fromJson(json, type) ?: emptyList()
gson.fromJson(json, Array<AppSelection>::class.java).toList()
} catch (e: Exception) {
emptyList()
}
Expand Down Expand Up @@ -413,10 +410,8 @@ class SettingsRepository(private val context: Context) {
fun loadSnoozeDiscoveredChannels(): List<com.sameerasw.essentials.domain.model.SnoozeChannel> {
val json = prefs.getString(KEY_SNOOZE_DISCOVERED_CHANNELS, null)
return if (json != null) {
val type = object :
TypeToken<List<com.sameerasw.essentials.domain.model.SnoozeChannel>>() {}.type
try {
gson.fromJson(json, type) ?: emptyList()
gson.fromJson(json, Array<com.sameerasw.essentials.domain.model.SnoozeChannel>::class.java).toList()
} catch (e: Exception) {
emptyList()
}
Expand All @@ -433,9 +428,8 @@ class SettingsRepository(private val context: Context) {
fun loadSnoozeBlockedChannels(): Set<String> {
val json = prefs.getString(KEY_SNOOZE_BLOCKED_CHANNELS, null)
return if (json != null) {
val type = object : TypeToken<Set<String>>() {}.type
try {
gson.fromJson(json, type) ?: emptySet()
gson.fromJson(json, Array<String>::class.java).toSet()
} catch (e: Exception) {
emptySet()
}
Expand All @@ -453,10 +447,8 @@ class SettingsRepository(private val context: Context) {
fun loadMapsDiscoveredChannels(): List<com.sameerasw.essentials.domain.model.MapsChannel> {
val json = prefs.getString(KEY_MAPS_DISCOVERED_CHANNELS, null)
return if (json != null) {
val type = object :
TypeToken<List<com.sameerasw.essentials.domain.model.MapsChannel>>() {}.type
try {
gson.fromJson(json, type) ?: emptyList()
gson.fromJson(json, Array<com.sameerasw.essentials.domain.model.MapsChannel>::class.java).toList()
} catch (e: Exception) {
emptyList()
}
Expand All @@ -473,9 +465,8 @@ class SettingsRepository(private val context: Context) {
fun loadMapsDetectionChannels(): Set<String> {
val json = prefs.getString(KEY_MAPS_DETECTION_CHANNELS, null)
return if (json != null) {
val type = object : TypeToken<Set<String>>() {}.type
try {
gson.fromJson(json, type) ?: emptySet()
gson.fromJson(json, Array<String>::class.java).toSet()
} catch (e: Exception) {
emptySet()
}
Expand Down Expand Up @@ -510,9 +501,8 @@ class SettingsRepository(private val context: Context) {
val wrapperMap = mutableMapOf<String, Map<String, Any>>()

p.all.forEach { (key, value) ->
// Skip app lists as requested, and stale data
if (key.endsWith("_selected_apps") || key == "freeze_auto_excluded_apps" ||
key.startsWith("mac_battery_") || key == "airsync_mac_connected" ||
if (key == "freeze_auto_excluded_apps" || key.endsWith("_selected_apps")) {
} else if (key.startsWith("mac_battery_") || key == "airsync_mac_connected" ||
key == KEY_SNOOZE_DISCOVERED_CHANNELS || key == KEY_MAPS_DISCOVERED_CHANNELS
) {
return@forEach
Expand Down Expand Up @@ -554,8 +544,7 @@ class SettingsRepository(private val context: Context) {
fun importConfigs(inputStream: java.io.InputStream): Boolean {
return try {
val json = inputStream.bufferedReader().use { it.readText() }
val type = object : TypeToken<Map<String, Map<String, Map<String, Any>>>>() {}.type
val allConfigs: Map<String, Map<String, Map<String, Any>>> = gson.fromJson(json, type)
val allConfigs: Map<String, Map<String, Map<String, Any>>> = gson.fromJson(json, Map::class.java) as Map<String, Map<String, Map<String, Any>>>

allConfigs.forEach { (fileName, prefWrapper) ->
val p = context.getSharedPreferences(fileName, Context.MODE_PRIVATE)
Expand Down Expand Up @@ -599,10 +588,8 @@ class SettingsRepository(private val context: Context) {

fun getBluetoothDevicesBattery(): List<com.sameerasw.essentials.utils.BluetoothBatteryUtils.BluetoothDeviceBattery> {
val json = prefs.getString(KEY_BLUETOOTH_DEVICES_BATTERY, null) ?: return emptyList()
val type = object :
TypeToken<List<com.sameerasw.essentials.utils.BluetoothBatteryUtils.BluetoothDeviceBattery>>() {}.type
return try {
gson.fromJson(json, type) ?: emptyList()
gson.fromJson(json, Array<com.sameerasw.essentials.utils.BluetoothBatteryUtils.BluetoothDeviceBattery>::class.java).toList()
} catch (e: Exception) {
emptyList()
}
Expand Down Expand Up @@ -630,7 +617,7 @@ class SettingsRepository(private val context: Context) {
val json = prefs.getString(KEY_PINNED_FEATURES, null)
return if (json != null) {
try {
gson.fromJson(json, object : TypeToken<List<String>>() {}.type) ?: emptyList()
gson.fromJson(json, Array<String>::class.java).toList()
} catch (e: Exception) {
emptyList()
}
Expand All @@ -644,9 +631,8 @@ class SettingsRepository(private val context: Context) {

fun getTrackedRepos(): List<TrackedRepo> {
val json = prefs.getString(KEY_TRACKED_REPOS, null) ?: return emptyList()
val type = object : TypeToken<List<TrackedRepo>>() {}.type
return try {
gson.fromJson(json, type)
gson.fromJson(json, Array<TrackedRepo>::class.java).toList()
} catch (e: Exception) {
emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.sameerasw.essentials.data.repository

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.sameerasw.essentials.domain.model.UpdateInfo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -30,17 +29,16 @@ class UpdateRepository {
val releaseData = connection.inputStream.bufferedReader().readText()

val release: Map<String, Any>? = if (isPreReleaseCheckEnabled) {
val listType = object : TypeToken<List<Map<String, Any>>>() {}.type
val releases: List<Map<String, Any>> = Gson().fromJson(releaseData, listType)
val releases = Gson().fromJson(releaseData, Array<Any>::class.java)
.filterIsInstance<Map<String, Any>>()

// Find the true latest release using SemanticVersion comparison
releases.maxByOrNull { rel ->
val tagName = (rel["tag_name"] as? String)?.removePrefix("v") ?: "0.0.0"
SemanticVersion.parse(tagName)
}
} else {
val mapType = object : TypeToken<Map<String, Any>>() {}.type
Gson().fromJson(releaseData, mapType)
Gson().fromJson(releaseData, Map::class.java) as? Map<String, Any>
}

if (release == null) return@withContext null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.annotation.StringRes
import com.sameerasw.essentials.R

enum class DIYTabs(@StringRes val title: Int, val subtitle: Any, val iconRes: Int) {
ESSENTIALS(R.string.tab_essentials, "(◍•ᴗ•◍)", R.drawable.ic_stat_name),
ESSENTIALS(R.string.tab_essentials, if (com.sameerasw.essentials.BuildConfig.DEBUG) "ʕ •ᴥ• ʔ Debug" else "(◍•ᴗ•◍)", R.drawable.ic_stat_name),
FREEZE(R.string.tab_freeze, R.string.tab_freeze_subtitle, R.drawable.rounded_mode_cool_24),
DIY(R.string.tab_diy, R.string.tab_diy_subtitle, R.drawable.rounded_experiment_24),
APPS(R.string.tab_apps, R.string.tab_apps_subtitle, R.drawable.rounded_apps_24)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ object DIYRepository {
fun init(context: Context) {
if (prefs != null) return
prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
loadAutomations()
reloadAutomations()
}

private fun loadAutomations() {
fun reloadAutomations() {
val json = prefs?.getString(KEY_AUTOMATIONS, null)
val loadedList: List<Automation> = if (json != null) {
try {
val type = object : TypeToken<List<Automation>>() {}.type
val type = object : com.google.gson.reflect.TypeToken<List<Automation>>() {}.type
gson.fromJson(json, type) ?: emptyList()
} catch (e: Exception) {
emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import com.sameerasw.essentials.data.repository.SettingsRepository
import com.sameerasw.essentials.utils.BatteryRingDrawer
import com.sameerasw.essentials.utils.BluetoothBatteryUtils
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

class BatteryNotificationService : Service() {

Expand Down Expand Up @@ -141,8 +140,7 @@ class BatteryNotificationService : Service() {

if (isShowBluetoothEnabled && !bluetoothJson.isNullOrEmpty() && bluetoothJson != "[]") {
try {
val type = object : TypeToken<List<BluetoothBatteryUtils.BluetoothDeviceBattery>>() {}.type
val devices: List<BluetoothBatteryUtils.BluetoothDeviceBattery> = Gson().fromJson(bluetoothJson, type) ?: emptyList()
val devices: List<BluetoothBatteryUtils.BluetoothDeviceBattery> = Gson().fromJson(bluetoothJson, Array<BluetoothBatteryUtils.BluetoothDeviceBattery>::class.java).toList()
devices.forEach { device ->
val iconRes = when {
device.name.contains("watch", true) || device.name.contains("gear", true) || device.name.contains("fit", true) -> R.drawable.rounded_watch_24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@ class NotificationListener : NotificationListenerService() {
)
val discoveredJson = prefs.getString("maps_discovered_channels", null)
val gson = com.google.gson.Gson()
val type = object :
com.google.gson.reflect.TypeToken<List<com.sameerasw.essentials.domain.model.MapsChannel>>() {}.type
val discoveredChannels: MutableList<com.sameerasw.essentials.domain.model.MapsChannel> =
if (discoveredJson != null) {
try {
gson.fromJson(discoveredJson, type) ?: mutableListOf()
gson.fromJson(discoveredJson, Array<com.sameerasw.essentials.domain.model.MapsChannel>::class.java).toMutableList()
} catch (_: Exception) {
mutableListOf()
}
Expand Down Expand Up @@ -131,12 +129,10 @@ class NotificationListener : NotificationListenerService() {
)
val discoveredJson = prefs.getString("snooze_discovered_channels", null)
val gson = com.google.gson.Gson()
val type = object :
com.google.gson.reflect.TypeToken<List<com.sameerasw.essentials.domain.model.SnoozeChannel>>() {}.type
val discoveredChannels: MutableList<com.sameerasw.essentials.domain.model.SnoozeChannel> =
if (discoveredJson != null) {
try {
gson.fromJson(discoveredJson, type) ?: mutableListOf()
gson.fromJson(discoveredJson, Array<com.sameerasw.essentials.domain.model.SnoozeChannel>::class.java).toMutableList()
} catch (_: Exception) {
mutableListOf()
}
Expand Down Expand Up @@ -566,9 +562,7 @@ class NotificationListener : NotificationListenerService() {
val blockedChannelsJson = prefs.getString("snooze_blocked_channels", null)
val blockedChannels: Set<String> = if (blockedChannelsJson != null) {
try {
val type =
object : com.google.gson.reflect.TypeToken<Set<String>>() {}.type
com.google.gson.Gson().fromJson(blockedChannelsJson, type) ?: emptySet()
com.google.gson.Gson().fromJson(blockedChannelsJson, Array<String>::class.java).toSet()
} catch (_: Exception) {
emptySet()
}
Expand Down Expand Up @@ -665,10 +659,8 @@ class NotificationListener : NotificationListenerService() {
val gson = com.google.gson.Gson()
val glowSidesJson = prefs.getString("edge_lighting_glow_sides", null)
val glowSides: Set<NotificationLightingSide> = if (glowSidesJson != null) {
val type = object :
com.google.gson.reflect.TypeToken<Set<NotificationLightingSide>>() {}.type
try {
gson.fromJson(glowSidesJson, type)
gson.fromJson(glowSidesJson, Array<NotificationLightingSide>::class.java).toSet()
} catch (_: Exception) {
setOf(NotificationLightingSide.LEFT, NotificationLightingSide.RIGHT)
}
Expand Down Expand Up @@ -856,8 +848,7 @@ class NotificationListener : NotificationListenerService() {
val detectionChannelsJson = prefs.getString("maps_detection_channels", null)
val detectionChannels: Set<String> = if (detectionChannelsJson != null) {
try {
val type = object : com.google.gson.reflect.TypeToken<Set<String>>() {}.type
com.google.gson.Gson().fromJson(detectionChannelsJson, type) ?: emptySet()
com.google.gson.Gson().fromJson(detectionChannelsJson, Array<String>::class.java).toSet()
} catch (_: Exception) {
emptySet()
}
Expand Down Expand Up @@ -917,10 +908,8 @@ class NotificationListener : NotificationListenerService() {
// If no saved preferences, allow all apps by default

val gson = com.google.gson.Gson()
val type = object :
com.google.gson.reflect.TypeToken<List<com.sameerasw.essentials.domain.model.AppSelection>>() {}.type
val selectedApps: List<com.sameerasw.essentials.domain.model.AppSelection> =
gson.fromJson(json, type)
gson.fromJson(json, Array<com.sameerasw.essentials.domain.model.AppSelection>::class.java).toList()

// Find the app in the saved list
val app = selectedApps.find { it.packageName == packageName }
Expand Down Expand Up @@ -951,10 +940,8 @@ class NotificationListener : NotificationListenerService() {
}

val gson = com.google.gson.Gson()
val type = object :
com.google.gson.reflect.TypeToken<List<com.sameerasw.essentials.domain.model.AppSelection>>() {}.type
val selectedApps: List<com.sameerasw.essentials.domain.model.AppSelection> =
gson.fromJson(json, type)
gson.fromJson(json, Array<com.sameerasw.essentials.domain.model.AppSelection>::class.java).toList()

// Find the app in the saved list
val app = selectedApps.find { it.packageName == packageName }
Expand Down
Loading