Fix: Set default colors depending on if nightMode or not.
Signed-off-by: HeCodes2Much <wayne6324@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package com.github.droidworksstudio.launcher.helper
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import android.content.res.Configuration
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import com.github.droidworksstudio.launcher.utils.Constants
|
import com.github.droidworksstudio.launcher.utils.Constants
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
@@ -11,6 +12,8 @@ class PreferenceHelper @Inject constructor(@ApplicationContext context: Context)
|
|||||||
|
|
||||||
private val prefs: SharedPreferences = context.getSharedPreferences(Constants.PREFS_FILENAME, 0)
|
private val prefs: SharedPreferences = context.getSharedPreferences(Constants.PREFS_FILENAME, 0)
|
||||||
|
|
||||||
|
private val setColor = getColor(context)
|
||||||
|
|
||||||
var firstLaunch: Boolean
|
var firstLaunch: Boolean
|
||||||
get() = prefs.getBoolean(Constants.FIRST_LAUNCH, true)
|
get() = prefs.getBoolean(Constants.FIRST_LAUNCH, true)
|
||||||
set(value) = prefs.edit().putBoolean(Constants.FIRST_LAUNCH, value).apply()
|
set(value) = prefs.edit().putBoolean(Constants.FIRST_LAUNCH, value).apply()
|
||||||
@@ -47,19 +50,19 @@ class PreferenceHelper @Inject constructor(@ApplicationContext context: Context)
|
|||||||
set(value) = prefs.edit().putBoolean(Constants.SHOW_BATTERY_WIDGET, value).apply()
|
set(value) = prefs.edit().putBoolean(Constants.SHOW_BATTERY_WIDGET, value).apply()
|
||||||
|
|
||||||
var dateColor: Int
|
var dateColor: Int
|
||||||
get() = prefs.getInt(Constants.DATE_COLOR, 0xFFFFFFFF.toInt())
|
get() = prefs.getInt(Constants.DATE_COLOR, setColor.toInt())
|
||||||
set(value) = prefs.edit().putInt(Constants.DATE_COLOR, value).apply()
|
set(value) = prefs.edit().putInt(Constants.DATE_COLOR, value).apply()
|
||||||
|
|
||||||
var timeColor: Int
|
var timeColor: Int
|
||||||
get() = prefs.getInt(Constants.TIME_COLOR, 0xFFFFFFFF.toInt())
|
get() = prefs.getInt(Constants.TIME_COLOR, setColor.toInt())
|
||||||
set(value) = prefs.edit().putInt(Constants.TIME_COLOR, value).apply()
|
set(value) = prefs.edit().putInt(Constants.TIME_COLOR, value).apply()
|
||||||
|
|
||||||
var batteryColor: Int
|
var batteryColor: Int
|
||||||
get() = prefs.getInt(Constants.BATTERY_COLOR, 0xFFFFFFFF.toInt())
|
get() = prefs.getInt(Constants.BATTERY_COLOR, setColor.toInt())
|
||||||
set(value) = prefs.edit().putInt(Constants.BATTERY_COLOR, value).apply()
|
set(value) = prefs.edit().putInt(Constants.BATTERY_COLOR, value).apply()
|
||||||
|
|
||||||
var dailyWordColor: Int
|
var dailyWordColor: Int
|
||||||
get() = prefs.getInt(Constants.DAILY_WORD_COLOR, 0xFFFFFFFF.toInt())
|
get() = prefs.getInt(Constants.DAILY_WORD_COLOR, setColor.toInt())
|
||||||
set(value) = prefs.edit().putInt(Constants.DAILY_WORD_COLOR, value).apply()
|
set(value) = prefs.edit().putInt(Constants.DAILY_WORD_COLOR, value).apply()
|
||||||
|
|
||||||
var widgetBackgroundColor: Int
|
var widgetBackgroundColor: Int
|
||||||
@@ -67,11 +70,11 @@ class PreferenceHelper @Inject constructor(@ApplicationContext context: Context)
|
|||||||
set(value) = prefs.edit().putInt(Constants.WIDGET_BACKGROUND_COLOR, value).apply()
|
set(value) = prefs.edit().putInt(Constants.WIDGET_BACKGROUND_COLOR, value).apply()
|
||||||
|
|
||||||
var widgetTextColor: Int
|
var widgetTextColor: Int
|
||||||
get() = prefs.getInt(Constants.WIDGET_TEXT_COLOR, 0xFFFFFFFF.toInt())
|
get() = prefs.getInt(Constants.WIDGET_TEXT_COLOR, setColor.toInt())
|
||||||
set(value) = prefs.edit().putInt(Constants.WIDGET_TEXT_COLOR, value).apply()
|
set(value) = prefs.edit().putInt(Constants.WIDGET_TEXT_COLOR, value).apply()
|
||||||
|
|
||||||
var appColor: Int
|
var appColor: Int
|
||||||
get() = prefs.getInt(Constants.APP_COLOR, 0xFFFFFFFF.toInt())
|
get() = prefs.getInt(Constants.APP_COLOR, setColor.toInt())
|
||||||
set(value) = prefs.edit().putInt(Constants.APP_COLOR, value).apply()
|
set(value) = prefs.edit().putInt(Constants.APP_COLOR, value).apply()
|
||||||
|
|
||||||
var showAppIcon: Boolean
|
var showAppIcon: Boolean
|
||||||
@@ -238,4 +241,20 @@ class PreferenceHelper @Inject constructor(@ApplicationContext context: Context)
|
|||||||
private fun storeAction(prefString: String, value: Constants.Action) {
|
private fun storeAction(prefString: String, value: Constants.Action) {
|
||||||
prefs.edit().putString(prefString, value.name).apply()
|
prefs.edit().putString(prefString, value.name).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getColor(context: Context): Long {
|
||||||
|
return when (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
|
||||||
|
Configuration.UI_MODE_NIGHT_YES -> {
|
||||||
|
0xFFFFFFFF
|
||||||
|
}
|
||||||
|
|
||||||
|
Configuration.UI_MODE_NIGHT_NO -> {
|
||||||
|
0xFF000000
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
0xFFFFFFFF
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,7 @@ import androidx.navigation.findNavController
|
|||||||
import androidx.navigation.fragment.NavHostFragment
|
import androidx.navigation.fragment.NavHostFragment
|
||||||
import androidx.navigation.ui.AppBarConfiguration
|
import androidx.navigation.ui.AppBarConfiguration
|
||||||
import androidx.navigation.ui.navigateUp
|
import androidx.navigation.ui.navigateUp
|
||||||
|
import com.github.droidworksstudio.common.hasInternetPermission
|
||||||
import com.github.droidworksstudio.common.isTablet
|
import com.github.droidworksstudio.common.isTablet
|
||||||
import com.github.droidworksstudio.common.showLongToast
|
import com.github.droidworksstudio.common.showLongToast
|
||||||
import com.github.droidworksstudio.launcher.R
|
import com.github.droidworksstudio.launcher.R
|
||||||
@@ -99,8 +100,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupLocationManager() {
|
private fun setupLocationManager() {
|
||||||
if (!isLocationPermissionDenied()) {
|
if (applicationContext.hasInternetPermission()) {
|
||||||
checkLocationPermission()
|
if (!isLocationPermissionDenied()) {
|
||||||
|
checkLocationPermission()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +281,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
} else {
|
} else {
|
||||||
// Permission denied, show a message to the user
|
// Permission denied, show a message to the user
|
||||||
setLocationPermissionDenied(true)
|
setLocationPermissionDenied(true)
|
||||||
this.showLongToast("Location permission denied")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user