From a08bc25f6ef94e314a0f3193998bc07e63303544 Mon Sep 17 00:00:00 2001 From: ottoptj Date: Fri, 30 Aug 2024 20:59:54 +0300 Subject: [PATCH] Added options to toggle clock, date and search on or off --- .../java/eu/ottop/yamlauncher/MainActivity.kt | 16 +++++++++ .../settings/SharedPreferenceManager.kt | 12 +++++++ .../eu/ottop/yamlauncher/utils/UIUtils.kt | 34 +++++++++++++++++++ app/src/main/res/layout/activity_main.xml | 11 ++++-- app/src/main/res/xml/root_preferences.xml | 20 +++++++++++ 5 files changed, 91 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index 4862f5a..25a23d3 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -289,6 +289,10 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh uiUtils.setMenuItemColors(searchView) uiUtils.setMenuItemColors(binding.menuTitle, "A9") + uiUtils.setClockVisibility(clock) + uiUtils.setDateVisibility(dateText) + uiUtils.setSearchVisibility(searchView, binding.searchReplacement) + uiUtils.setClockAlignment(clock, dateText) uiUtils.setSearchAlignment(searchView) @@ -387,6 +391,18 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh uiUtils.setMenuItemColors(binding.menuTitle, "A9") } + "clockEnabled" -> { + uiUtils.setClockVisibility(clock) + } + + "dateEnabled" -> { + uiUtils.setDateVisibility(dateText) + } + + "searchEnabled" -> { + uiUtils.setSearchVisibility(searchView, binding.searchReplacement) + } + "clockAlignment" -> { uiUtils.setClockAlignment(clock, dateText) } diff --git a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt index 75844de..84b8eb9 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt @@ -48,6 +48,10 @@ class SharedPreferenceManager (private val context: Context) { } // Home Screen + fun isClockEnabled(): Boolean { + return preferences.getBoolean("clockEnabled", true) + } + fun getClockAlignment(): String? { return preferences.getString("clockAlignment", "left") } @@ -56,6 +60,10 @@ class SharedPreferenceManager (private val context: Context) { return preferences.getString("clockSize","medium") } + fun isDateEnabled(): Boolean { + return preferences.getBoolean("dateEnabled", true) + } + fun getDateSize(): String? { return preferences.getString("dateSize", "medium") } @@ -156,6 +164,10 @@ class SharedPreferenceManager (private val context: Context) { return preferences.getString("appMenuSize", "medium") } + fun isSearchEnabled(): Boolean { + return preferences.getBoolean("searchEnabled", true) + } + fun getSearchAlignment(): String? { return preferences.getString("searchAlignment", "left") } diff --git a/app/src/main/java/eu/ottop/yamlauncher/utils/UIUtils.kt b/app/src/main/java/eu/ottop/yamlauncher/utils/UIUtils.kt index 7da9c9a..bb5f7d8 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/utils/UIUtils.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/utils/UIUtils.kt @@ -8,6 +8,7 @@ import android.util.TypedValue import android.view.Gravity import android.view.View import android.view.ViewGroup +import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.view.ViewTreeObserver import android.view.Window import android.view.WindowInsets @@ -94,6 +95,39 @@ class UIUtils(private val context: Context) { return Color.argb(newAlpha, r, g, b) } + // Visibility + fun setClockVisibility(clock: TextClock) { + val layoutParams = clock.layoutParams + + if (sharedPreferenceManager.isClockEnabled()) { + layoutParams.height = WRAP_CONTENT + } else { + layoutParams.height = 1 + } + clock.layoutParams = layoutParams + } + + fun setDateVisibility(dateText: TextClock) { + dateText.visibility = when (sharedPreferenceManager.isDateEnabled()) { + true -> { + View.VISIBLE + } + false -> { + View.GONE + } + } + } + + fun setSearchVisibility(searchView: TextInputEditText, replacementView: View) { + if (sharedPreferenceManager.isSearchEnabled()) { + searchView.visibility = View.VISIBLE + replacementView.visibility = View.GONE + } else { + searchView.visibility = View.GONE + replacementView.visibility = View.VISIBLE + } + } + // Alignment fun setClockAlignment(clock: TextClock, dateText: TextClock) { val alignment = sharedPreferenceManager.getClockAlignment() diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index b7d0ddd..3a0ac47 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -68,6 +68,13 @@ android:textAppearance="@android:style/TextAppearance.DeviceDefault" android:textSize="25sp" /> + + @@ -380,8 +388,7 @@ + android:layout_weight="0.3" /> diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 212e178..df194cc 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -53,6 +53,12 @@ android:layout_height="wrap_content" app:allowDividerAbove="false" app:title="Home Screen"> + + +