Refactoring and comments omfg

This commit is contained in:
ottoptj 2024-08-11 18:37:18 +03:00
commit 033fff6820
10 changed files with 165 additions and 135 deletions

View file

@ -24,7 +24,7 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
i i
) && app.applicationInfo.packageName != context.applicationInfo.packageName // Hide the launcher itself ) && app.applicationInfo.packageName != context.applicationInfo.packageName // Hide the launcher itself
) { ) {
allApps.add(Triple(app, launcherApps.profiles[i], i)) allApps.add(Triple(app, launcherApps.profiles[i], i)) // The i variable gets used to determine whether an app is in the personal profile or work profile
} }
} }
} }

View file

@ -77,19 +77,19 @@ class LocationFragment : Fragment(), LocationListAdapter.OnItemClickListener {
} }
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}
override fun afterTextChanged(s: Editable?) {
// Filtering is not needed since we are creating a list with data pulled from the Open-Meteo api instead of searching an existing list
lifecycleScope.launch(Dispatchers.IO){ lifecycleScope.launch(Dispatchers.IO){
val locations = weatherSystem.getSearchedLocations( val locations = weatherSystem.getSearchedLocations(
searchView.text.toString() searchView.text.toString()
) )
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
adapter?.updateApps(locations) adapter?.updateLocations(locations)
} }
} }
}
override fun afterTextChanged(s: Editable?) {
} }
}) })

View file

@ -11,7 +11,7 @@ import androidx.recyclerview.widget.RecyclerView
class LocationListAdapter( class LocationListAdapter(
private val context: Context, private val context: Context,
private var apps: MutableList<Map<String, String>>, private var locations: MutableList<Map<String, String>>,
private val itemClickListener: OnItemClickListener private val itemClickListener: OnItemClickListener
) : ) :
RecyclerView.Adapter<LocationListAdapter.AppViewHolder>() { RecyclerView.Adapter<LocationListAdapter.AppViewHolder>() {
@ -31,9 +31,9 @@ class LocationListAdapter(
listItem.setOnClickListener { listItem.setOnClickListener {
val position = bindingAdapterPosition val position = bindingAdapterPosition
val name = apps[position]["name"] val name = locations[position]["name"]
val latitude = apps[position]["latitude"] val latitude = locations[position]["latitude"]
val longitude = apps[position]["longitude"] val longitude = locations[position]["longitude"]
itemClickListener.onItemClick(name, latitude, longitude) itemClickListener.onItemClick(name, latitude, longitude)
} }
@ -47,26 +47,26 @@ class LocationListAdapter(
} }
override fun onBindViewHolder(holder: AppViewHolder, position: Int) { override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
val app = apps[position] val location = locations[position]
uiUtils.setAppAlignment(holder.textView, null, holder.regionText) uiUtils.setAppAlignment(holder.textView, null, holder.regionText)
uiUtils.setAppSize(holder.textView, null, holder.regionText) uiUtils.setAppSize(holder.textView, null, holder.regionText)
holder.textView.text = app["name"] holder.textView.text = location["name"]
holder.regionText.text = context.getString(R.string.region_text, app["region"], app["country"]) holder.regionText.text = context.getString(R.string.region_text, location["region"], location["country"])
holder.textView.visibility = View.VISIBLE holder.textView.visibility = View.VISIBLE
} }
override fun getItemCount(): Int { override fun getItemCount(): Int {
return apps.size return locations.size
} }
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
fun updateApps(newApps: MutableList<Map<String, String>>) { fun updateLocations(newApps: MutableList<Map<String, String>>) {
apps.clear() locations.clear()
apps = newApps locations = newApps
notifyDataSetChanged() notifyDataSetChanged()
} }
} }

View file

@ -100,6 +100,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
setHomeListeners() setHomeListeners()
// Task to update the app menu every 5 seconds
lifecycleScope.launch { lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
while (true) { while (true) {
@ -109,6 +110,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
} }
} }
// Task to update the weather every 10 minutes
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
repeatOnLifecycle(Lifecycle.State.STARTED) { repeatOnLifecycle(Lifecycle.State.STARTED) {
while (true) { while (true) {
@ -171,9 +173,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
for (i in shortcuts.indices) { for (i in shortcuts.indices) {
val textView = findViewById<TextView>(shortcuts[i]) val textView = findViewById<TextView>(shortcuts[i])
val shortcutNo = sharedPreferenceManager.getShortcutNumber() val shortcutNo = sharedPreferenceManager.getShortcutNumber()
// Only show the chosen number of shortcuts (default 4). Hide the rest.
if (i >= shortcutNo!!) { if (i >= shortcutNo!!) {
textView.visibility = View.GONE textView.visibility = View.GONE
} }
@ -181,37 +183,35 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
else { else {
textView.visibility = View.VISIBLE textView.visibility = View.VISIBLE
unsetShortcutSetup(textView)
val savedView = sharedPreferenceManager.getShortcut(textView) val savedView = sharedPreferenceManager.getShortcut(textView)
// Set the non-work profile drawable by default
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null)
shortcutListeners(textView)
if (savedView?.get(1) != "e") { if (savedView?.get(1) != "e") {
setShortcutSetup(textView, savedView) setShortcutSetup(textView, savedView)
} }
else {
unsetShortcutSetup(textView)
}
uiUtils.setShortcutsAlignment(binding.homeView) uiUtils.setShortcutsAlignment(binding.homeView)
} }
} }
} }
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
private fun unsetShortcutSetup(textView: TextView) { private fun shortcutListeners(textView: TextView) {
// Don't go to settings on long click, but keep other gestures functional
textView.setOnTouchListener {_, event -> textView.setOnTouchListener {_, event ->
shortcutGestureDetector.onTouchEvent(event) shortcutGestureDetector.onTouchEvent(event)
super.onTouchEvent(event) super.onTouchEvent(event)
} }
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null)
unsetShortcutListeners(textView)
}
private fun unsetShortcutListeners(textView: TextView) {
textView.setOnClickListener {
Toast.makeText(this, "Long click to select an app", Toast.LENGTH_SHORT).show()
}
textView.setOnLongClickListener { textView.setOnLongClickListener {
uiUtils.setMenuTitleAlignment(binding.menuTitle) uiUtils.setMenuTitleAlignment(binding.menuTitle)
binding.menuTitle.visibility = View.VISIBLE binding.menuTitle.visibility = View.VISIBLE
@ -225,6 +225,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
private fun toAppMenu() { private fun toAppMenu() {
try { try {
// The menu opens from the top
recyclerView.scrollToPosition(0) recyclerView.scrollToPosition(0)
} }
catch (_: UninitializedPropertyAccessException) { catch (_: UninitializedPropertyAccessException) {
@ -240,13 +241,22 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
} }
} }
private fun unsetShortcutSetup(textView: TextView) {
unsetShortcutListeners(textView)
}
private fun unsetShortcutListeners(textView: TextView) {
textView.setOnClickListener {
Toast.makeText(this, "Long click to select an app", Toast.LENGTH_SHORT).show()
}
}
private fun setShortcutSetup(textView: TextView, savedView: List<String>?) { private fun setShortcutSetup(textView: TextView, savedView: List<String>?) {
// Set the work profile drawable for work profile apps
if (savedView?.get(1) != "0") { if (savedView?.get(1) != "0") {
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_work_app, null),null,null,null) textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_work_app, null),null,null,null)
} }
else {
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null)
}
textView.text = savedView?.get(2) textView.text = savedView?.get(2)
setShortcutListeners(textView, savedView) setShortcutListeners(textView, savedView)
} }
@ -278,6 +288,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
true true
} }
// Return to home on back
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) { onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() { override fun handleOnBackPressed() {
backToHome() backToHome()
@ -299,6 +310,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
} }
} }
// Only reload items that have had preferences changed
override fun onSharedPreferenceChanged(preferences: SharedPreferences?, key: String?) { override fun onSharedPreferenceChanged(preferences: SharedPreferences?, key: String?) {
if (preferences != null) { if (preferences != null) {
when (key) { when (key) {
@ -368,6 +380,11 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
} }
fun modifyDate(value: String, index: Int) { fun modifyDate(value: String, index: Int) {
/*Indexes:
0 = 12h time
1 = 24h time
2 = Weather
3 = Battery level*/
dateElements[index] = value dateElements[index] = value
dateText.format12Hour = "${dateElements[0]}${stringUtils.addStartTextIfNotEmpty(dateElements[2], " | ")}${stringUtils.addStartTextIfNotEmpty(dateElements[3], " | ")}" dateText.format12Hour = "${dateElements[0]}${stringUtils.addStartTextIfNotEmpty(dateElements[2], " | ")}${stringUtils.addStartTextIfNotEmpty(dateElements[3], " | ")}"
dateText.format24Hour = "${dateElements[1]}${stringUtils.addStartTextIfNotEmpty(dateElements[2], " | ")}${stringUtils.addStartTextIfNotEmpty(dateElements[3], " | ")}" dateText.format24Hour = "${dateElements[1]}${stringUtils.addStartTextIfNotEmpty(dateElements[2], " | ")}${stringUtils.addStartTextIfNotEmpty(dateElements[3], " | ")}"
@ -378,6 +395,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
animations.showHome(binding.homeView, binding.appView) animations.showHome(binding.homeView, binding.appView)
animations.backgroundOut(this@MainActivity) animations.backgroundOut(this@MainActivity)
val animSpeed = sharedPreferenceManager.getAnimationSpeed() val animSpeed = sharedPreferenceManager.getAnimationSpeed()
// Delay app menu changes so that the user doesn't see them
val handler = Handler(Looper.getMainLooper()) val handler = Handler(Looper.getMainLooper())
handler.postDelayed({ handler.postDelayed({
try { try {
@ -405,6 +425,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
suspend fun refreshAppMenu() { suspend fun refreshAppMenu() {
try { try {
// Don't reset app menu while under a search
if (isJobActive) { if (isJobActive) {
val updatedApps = appUtils.getInstalledApps() val updatedApps = appUtils.getInstalledApps()
if (!listsEqual(installedApps, updatedApps)) { if (!listsEqual(installedApps, updatedApps)) {
@ -487,6 +509,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
setupRecyclerListener() setupRecyclerListener()
} }
// Inform the layout manager of scroll states to calculate whether the menu is on the top
private fun setupRecyclerListener() { private fun setupRecyclerListener() {
recyclerView.addOnScrollListener(object: RecyclerView.OnScrollListener() { recyclerView.addOnScrollListener(object: RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
@ -502,10 +525,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
binding.appView.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom -> binding.appView.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
if (bottom - top > oldBottom - oldTop) { if (bottom - top > oldBottom - oldTop) {
// Allow the app menu to be closed after the keyboard is closed
canExit = true canExit = true
searchView.clearFocus() searchView.clearFocus()
} }
else if (bottom - top < oldBottom - oldTop) { else if (bottom - top < oldBottom - oldTop) {
// The app menu can't be closed with the keyboard open
canExit = false canExit = false
} }
} }
@ -572,6 +597,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
} }
} }
// On home key or swipe, return to home screen
override fun onNewIntent(intent: Intent) { override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent) super.onNewIntent(intent)
backToHome() backToHome()

View file

@ -7,11 +7,9 @@ import android.view.accessibility.AccessibilityEvent
class ScreenLockService : AccessibilityService() { class ScreenLockService : AccessibilityService() {
override fun onAccessibilityEvent(event: AccessibilityEvent?) { override fun onAccessibilityEvent(event: AccessibilityEvent?) {
// Handle accessibility events if needed
} }
override fun onInterrupt() { override fun onInterrupt() {
// Handle interrupt
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {

View file

@ -1,8 +1,6 @@
package eu.ottop.yamlauncher package eu.ottop.yamlauncher
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.clearFragmentResultListener
import androidx.fragment.app.setFragmentResultListener
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference import androidx.preference.SwitchPreference
@ -26,10 +24,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
val aboutPref = findPreference<Preference?>("aboutPage") val aboutPref = findPreference<Preference?>("aboutPage")
val hiddenPref = findPreference<Preference?>("hiddenApps") val hiddenPref = findPreference<Preference?>("hiddenApps")
manualLocationPref?.summary = sharedPreferenceManager.getWeatherRegion()
leftSwipePref?.summary = sharedPreferenceManager.getGestureName("left")
rightSwipePref?.summary = sharedPreferenceManager.getGestureName("right")
// Only enable manual location when gps location is disabled // Only enable manual location when gps location is disabled
if (gpsLocationPref != null && manualLocationPref != null) { if (gpsLocationPref != null && manualLocationPref != null) {
manualLocationPref?.isEnabled = !gpsLocationPref.isChecked manualLocationPref?.isEnabled = !gpsLocationPref.isChecked

View file

@ -9,6 +9,40 @@ class SharedPreferenceManager (context: Context) {
private val preferences = PreferenceManager.getDefaultSharedPreferences(context) private val preferences = PreferenceManager.getDefaultSharedPreferences(context)
// General UI
fun getBgColor(): Int {
return Color.parseColor(preferences.getString("bgColor", "#00000000"))
}
fun getTextColor(): Int {
return Color.parseColor(preferences.getString("textColor", "#FFF3F3F3"))
}
fun isBarVisible(): Boolean {
return preferences.getBoolean("barVisibility", false)
}
fun getAnimationSpeed(): Long {
val animSpeed = preferences.getString("animationSpeed", "200")?.toLong()
if (animSpeed != null) {
return animSpeed
}
return 200
}
// Home Screen
fun getClockAlignment(): String? {
return preferences.getString("clockAlignment", "left")
}
fun getClockSize(): String? {
return preferences.getString("clockSize","medium")
}
fun getDateSize(): String? {
return preferences.getString("dateSize", "medium")
}
fun setShortcut(textView: TextView, packageName: String, profile: Int) { fun setShortcut(textView: TextView, packageName: String, profile: Int) {
val editor = preferences.edit() val editor = preferences.edit()
editor.putString("shortcut${textView.id}", "$packageName§splitter§$profile§splitter§${textView.text}") editor.putString("shortcut${textView.id}", "$packageName§splitter§$profile§splitter§${textView.text}")
@ -24,36 +58,25 @@ class SharedPreferenceManager (context: Context) {
return preferences.getString("shortcutNo", "4")?.toInt() return preferences.getString("shortcutNo", "4")?.toInt()
} }
fun setAppHidden(packageName: String, profile: Int, hidden: Boolean) { fun getShortcutAlignment(): String? {
val editor = preferences.edit() return preferences.getString("shortcutAlignment", "left")
editor.putBoolean("hidden$packageName-$profile", hidden)
editor.apply()
} }
fun isAppHidden(packageName: String, profile: Int): Boolean { fun getShortcutSize(): String? {
return preferences.getBoolean("hidden$packageName-$profile", false) // Default to false (visible) return preferences.getString("shortcutSize", "medium")
} }
fun setAppVisible(packageName: String, profile: Int) { fun isBatteryEnabled(): Boolean {
val editor = preferences.edit() return preferences.getBoolean("batteryEnabled", false)
editor.remove("hidden$packageName-$profile")
editor.apply()
} }
fun setAppName(packageName: String, profile: Int, newName: String) { // Weather
val editor = preferences.edit() fun isWeatherEnabled(): Boolean {
editor.putString("name$packageName-$profile", newName) return preferences.getBoolean("weatherEnabled", false)
editor.apply()
} }
fun getAppName(packageName: String, profile: Int, appName: CharSequence): CharSequence? { fun isWeatherGPS(): Boolean {
return preferences.getString("name$packageName-$profile", appName.toString()) return preferences.getBoolean("gpsLocation", false)
}
fun resetAppName(packageName: String, profile: Int) {
val editor = preferences.edit()
editor.remove("name$packageName-$profile")
editor.apply()
} }
fun setWeatherLocation(location: String, region: String?) { fun setWeatherLocation(location: String, region: String?) {
@ -71,6 +94,11 @@ class SharedPreferenceManager (context: Context) {
return preferences.getString("locationRegion", "") return preferences.getString("locationRegion", "")
} }
fun getTempUnits(): String? {
return preferences.getString("tempUnits", "celsius")
}
// Gestures
fun setGestures(direction: String, appName: String?) { fun setGestures(direction: String, appName: String?) {
val editor = preferences.edit() val editor = preferences.edit()
editor.putString("${direction}SwipeApp", appName) editor.putString("${direction}SwipeApp", appName)
@ -94,79 +122,58 @@ class SharedPreferenceManager (context: Context) {
return preferences.getBoolean("doubleTap", false) return preferences.getBoolean("doubleTap", false)
} }
fun getBgColor(): Int { // Application Menu
return Color.parseColor(preferences.getString("bgColor", "#00000000"))
}
fun getTextColor(): Int {
return Color.parseColor(preferences.getString("textColor", "#FFF3F3F3"))
}
fun getClockAlignment(): String? {
return preferences.getString("clockAlignment", "left")
}
fun getShortcutAlignment(): String? {
return preferences.getString("shortcutAlignment", "left")
}
fun getAppAlignment(): String? { fun getAppAlignment(): String? {
return preferences.getString("appMenuAlignment", "left") return preferences.getString("appMenuAlignment", "left")
} }
fun getSearchAlignment(): String? {
return preferences.getString("searchAlignment", "left")
}
fun getClockSize(): String? {
return preferences.getString("clockSize","medium")
}
fun getDateSize(): String? {
return preferences.getString("dateSize", "medium")
}
fun getShortcutSize(): String? {
return preferences.getString("shortcutSize", "medium")
}
fun getAppSize(): String? { fun getAppSize(): String? {
return preferences.getString("appMenuSize", "medium") return preferences.getString("appMenuSize", "medium")
} }
fun getSearchSize(): String? { fun getSearchAlignment(): String? {
return preferences.getString("searchSize", "medium") return preferences.getString("searchAlignment", "left")
} }
fun isBarVisible(): Boolean { fun getSearchSize(): String? {
return preferences.getBoolean("barVisibility", false) return preferences.getString("searchSize", "medium")
} }
fun isAutoKeyboardEnabled(): Boolean { fun isAutoKeyboardEnabled(): Boolean {
return preferences.getBoolean("autoKeyboard", false) return preferences.getBoolean("autoKeyboard", false)
} }
fun getTempUnits(): String? { // Hidden Apps
return preferences.getString("tempUnits", "celsius") fun setAppHidden(packageName: String, profile: Int, hidden: Boolean) {
val editor = preferences.edit()
editor.putBoolean("hidden$packageName-$profile", hidden)
editor.apply()
} }
fun isWeatherEnabled(): Boolean { fun isAppHidden(packageName: String, profile: Int): Boolean {
return preferences.getBoolean("weatherEnabled", false) return preferences.getBoolean("hidden$packageName-$profile", false) // Default to false (visible)
} }
fun isWeatherGPS(): Boolean { fun setAppVisible(packageName: String, profile: Int) {
return preferences.getBoolean("gpsLocation", false) val editor = preferences.edit()
editor.remove("hidden$packageName-$profile")
editor.apply()
} }
fun isBatteryEnabled(): Boolean { //Renaming apps
return preferences.getBoolean("batteryEnabled", false) fun setAppName(packageName: String, profile: Int, newName: String) {
val editor = preferences.edit()
editor.putString("name$packageName-$profile", newName)
editor.apply()
} }
fun getAnimationSpeed(): Long { fun getAppName(packageName: String, profile: Int, appName: CharSequence): CharSequence? {
val animSpeed = preferences.getString("animationSpeed", "200")?.toLong() return preferences.getString("name$packageName-$profile", appName.toString())
if (animSpeed != null) {
return animSpeed
} }
return 200
fun resetAppName(packageName: String, profile: Int) {
val editor = preferences.edit()
editor.remove("name$packageName-$profile")
editor.apply()
} }
} }

View file

@ -22,6 +22,7 @@ class UIUtils(context: Context) {
private val sharedPreferenceManager = SharedPreferenceManager(context) private val sharedPreferenceManager = SharedPreferenceManager(context)
// Colors
fun setBackground(window: Window) { fun setBackground(window: Window) {
window.decorView.setBackgroundColor( window.decorView.setBackgroundColor(
sharedPreferenceManager.getBgColor() sharedPreferenceManager.getBgColor()
@ -70,7 +71,6 @@ class UIUtils(context: Context) {
val globalLayoutListener = object : ViewTreeObserver.OnGlobalLayoutListener { val globalLayoutListener = object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() { override fun onGlobalLayout() {
searchView.viewTreeObserver.removeOnGlobalLayoutListener(this) searchView.viewTreeObserver.removeOnGlobalLayoutListener(this)
println("yoooooooo")
val color = sharedPreferenceManager.getTextColor() val color = sharedPreferenceManager.getTextColor()
searchView.setTextColor(color) searchView.setTextColor(color)
searchView.setHintTextColor(setAlpha(color, "A9")) searchView.setHintTextColor(setAlpha(color, "A9"))
@ -83,6 +83,7 @@ class UIUtils(context: Context) {
} }
} }
// Alignment
fun setClockAlignment(clock: TextClock, dateText: TextClock) { fun setClockAlignment(clock: TextClock, dateText: TextClock) {
val alignment = sharedPreferenceManager.getClockAlignment() val alignment = sharedPreferenceManager.getClockAlignment()
setTextAlignment(clock, alignment) setTextAlignment(clock, alignment)
@ -190,6 +191,7 @@ class UIUtils(context: Context) {
} catch (_: Exception) {} } catch (_: Exception) {}
} }
// Size
fun setClockSize(clock: TextClock) { fun setClockSize(clock: TextClock) {
setTextSize(clock, sharedPreferenceManager.getClockSize(), 58F, 68F, 78F) setTextSize(clock, sharedPreferenceManager.getClockSize(), 58F, 68F, 78F)
} }
@ -288,6 +290,7 @@ class UIUtils(context: Context) {
} catch (_: Exception) {} } catch (_: Exception) {}
} }
// Status bar visibility
fun setStatusBar(window: Window) { fun setStatusBar(window: Window) {
val windowInsetsController = window.insetsController val windowInsetsController = window.insetsController

View file

@ -32,23 +32,24 @@ class WeatherSystem(private val context: Context) {
} }
locationManager.getCurrentLocation( locationManager.getCurrentLocation(
LocationManager.GPS_PROVIDER, // Use GPS provider LocationManager.GPS_PROVIDER, // Only GPS provider functions on my phone with CalyxOS, so that's what you get.
null, // No cancellation signal null,
ContextCompat.getMainExecutor(context) ContextCompat.getMainExecutor(context)
) )
{ location: Location? -> // Lambda expression for the callback { location: Location? ->
if (location != null) { if (location != null) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
val latitude = location.latitude val latitude = location.latitude
val longitude = location.longitude val longitude = location.longitude
sharedPreferenceManager.setWeatherLocation("latitude=${latitude}&longitude=${longitude}", sharedPreferenceManager.getWeatherRegion()) sharedPreferenceManager.setWeatherLocation("latitude=${latitude}&longitude=${longitude}", sharedPreferenceManager.getWeatherRegion())
activity.updateWeatherText()} activity.updateWeatherText()
}
} }
} }
} }
// Run within Dispatchers.IO from the outside (doesn't refresh properly otherwise) // Run within Dispatchers.IO from the outside (doesn't seem to refresh properly otherwise)
fun getSearchedLocations(searchTerm: String?) : MutableList<Map<String, String>> { fun getSearchedLocations(searchTerm: String?) : MutableList<Map<String, String>> {
val foundLocations = mutableListOf<Map<String, String>>() val foundLocations = mutableListOf<Map<String, String>>()
@ -79,6 +80,7 @@ class WeatherSystem(private val context: Context) {
return foundLocations return foundLocations
} }
// Run with Dispatchers.IO from the outside
fun getTemp() : String { fun getTemp() : String {
val tempUnits = sharedPreferenceManager.getTempUnits() val tempUnits = sharedPreferenceManager.getTempUnits()
@ -103,19 +105,19 @@ class WeatherSystem(private val context: Context) {
when (currentData.getInt("weather_code")) { when (currentData.getInt("weather_code")) {
0, 1 -> { 0, 1 -> {
weatherType = "\uFE0E" weatherType = "\uFE0E" // Sunny
} }
2, 3, 45, 48 -> { 2, 3, 45, 48 -> {
weatherType = "\uFE0E" weatherType = "\uFE0E" // Sunny
} }
51, 53, 55, 56, 57, 61, 63, 65, 67, 80, 81, 82 -> { 51, 53, 55, 56, 57, 61, 63, 65, 67, 80, 81, 82 -> {
weatherType = "\uFE0E" weatherType = "\uFE0E" // Rain
} }
71, 73, 75, 77, 85, 86 -> { 71, 73, 75, 77, 85, 86 -> {
weatherType = "\uFE0E" weatherType = "\uFE0E" // Snow
} }
95, 96, 99 -> { 95, 96, 99 -> {
weatherType = "\uFE0E" weatherType = "\uFE0E" // Thunder
} }
} }

View file

@ -45,15 +45,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:allowDividerAbove="false" app:allowDividerAbove="false"
app:title="Home Screen"> app:title="Home Screen">
<ListPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:defaultValue="4"
app:entries="@array/shortcut_options"
app:entryValues="@array/shortcut_options"
app:key="shortcutNo"
app:title="Number of Shortcuts"
app:useSimpleSummaryProvider="true" />
<ListPreference <ListPreference
app:defaultValue="left" app:defaultValue="left"
app:entries="@array/h_alignment_options" app:entries="@array/h_alignment_options"
@ -79,6 +70,15 @@
app:key="dateSize" app:key="dateSize"
app:title="Date Size" app:title="Date Size"
app:useSimpleSummaryProvider="true" /> app:useSimpleSummaryProvider="true" />
<ListPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:defaultValue="4"
app:entries="@array/shortcut_options"
app:entryValues="@array/shortcut_options"
app:key="shortcutNo"
app:title="Number of Shortcuts"
app:useSimpleSummaryProvider="true" />
<ListPreference <ListPreference
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"