瀏覽代碼

fix(clocks): fix clock when search box at bottom (#193)

Joshua Kuestersteffen 2 年之前
父節點
當前提交
aa77aba53d

+ 6 - 7
app/src/main/java/com/sduduzog/slimlauncher/datasource/coreprefs/CorePreferencesMigrations.kt

@@ -9,13 +9,12 @@ class CorePreferencesMigrations {
         return listOf(
             object : DataMigration<CorePreferences> {
                 override suspend fun shouldMigrate(currentData: CorePreferences) = !currentData.hasClockType()
-
-                override suspend fun migrate(currentData: CorePreferences): CorePreferences {
-                    val prefBuilder = currentData.toBuilder()
-                    prefBuilder.clockType = ClockType.digital
-                    return prefBuilder.build()
-                }
-
+                override suspend fun migrate(currentData: CorePreferences) = currentData.toBuilder().setClockType(ClockType.digital).build()
+                override suspend fun cleanUp() {}
+            },
+            object : DataMigration<CorePreferences> {
+                override suspend fun shouldMigrate(currentData: CorePreferences) = !currentData.hasShowSearchBar()
+                override suspend fun migrate(currentData: CorePreferences) = currentData.toBuilder().setShowSearchBar(true).build()
                 override suspend fun cleanUp() {}
             }
         )

+ 1 - 12
app/src/main/java/com/sduduzog/slimlauncher/datasource/coreprefs/CorePreferencesRepository.kt

@@ -60,7 +60,7 @@ class CorePreferencesRepository(
         }
     }
 
-    private fun updateShowSearchBar(showSearchBar: Boolean) {
+    fun updateShowSearchBar(showSearchBar: Boolean) {
         lifecycleScope.launch {
             corePreferencesStore.updateData {
                 it.toBuilder().setShowSearchBar(showSearchBar).build()
@@ -68,17 +68,6 @@ class CorePreferencesRepository(
         }
     }
 
-    var showSearchField: Boolean
-        // when upgrading from an older version the property showSearchBar is null
-        // we therefore set default state to true.
-        // This has the reason that protobuf 3 does not allow default values,
-        // see https://stackoverflow.com/a/62435235,
-        // hence making the showSearchBar attribute optional and allow it to be null.
-        // With that we can use a logical implication: hasShowSearchBar -> showSearchBar,
-        // returning true, when the showSearchBar attribute is null.
-        get() = !get().hasShowSearchBar() || get().showSearchBar
-        set(value) = updateShowSearchBar(value)
-
     fun updateSearchBarPosition(searchBarPosition: SearchBarPosition) {
         lifecycleScope.launch {
             corePreferencesStore.updateData {

+ 4 - 8
app/src/main/java/com/sduduzog/slimlauncher/ui/main/HomeFragment.kt

@@ -134,10 +134,9 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
 
         app_drawer_fragment_list.adapter = appDrawerAdapter
 
-        val showSearchBar = unlauncherDataSource.corePreferencesRepo.showSearchField
-        app_drawer_edit_text.visibility = if (showSearchBar) View.VISIBLE else View.GONE
-
         unlauncherDataSource.corePreferencesRepo.liveData().observe(viewLifecycleOwner){ corePreferences ->
+            app_drawer_edit_text.visibility = if (corePreferences.showSearchBar) View.VISIBLE else View.GONE
+
             val clockType = corePreferences.clockType
             home_fragment_time.visibility = if(clockType == ClockType.digital) View.VISIBLE else View.GONE
             home_fragment_analog_time.visibility = if(clockType == ClockType.analog) View.VISIBLE else View.GONE
@@ -280,13 +279,10 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
                     }
 
                     motionLayout?.endState -> {
-                        val repository = unlauncherDataSource.corePreferencesRepo
-                        val showSearchField = repository.showSearchField
-                        val activateKeyboard = repository.get().activateKeyboardInDrawer
-
+                        val preferences = unlauncherDataSource.corePreferencesRepo.get()
                         // Check for preferences to open the keyboard
                         // only if the search field is shown
-                        if (showSearchField && activateKeyboard) {
+                        if (preferences.showSearchBar && preferences.activateKeyboardInDrawer) {
                             app_drawer_edit_text.requestFocus()
                             // show the keyboard and set focus to the EditText when swiping down
                             inputMethodManager.showSoftInput(

+ 2 - 2
app/src/main/java/com/sduduzog/slimlauncher/ui/options/CustomizeSearchFieldFragment.kt

@@ -54,11 +54,11 @@ class CustomizeSearchFieldFragment : BaseFragment() {
     private fun setupShowSearchBarSwitch() {
         val prefsRepo = unlauncherDataSource.corePreferencesRepo
         customize_app_drawer_fragment_show_search_field_switch.setOnCheckedChangeListener { _, checked ->
-            prefsRepo.showSearchField = checked
+            prefsRepo.updateShowSearchBar(checked)
             enableSearchBarOptions(checked)
         }
         prefsRepo.liveData().observe(viewLifecycleOwner) {
-            val checked = prefsRepo.showSearchField
+            val checked = it.showSearchBar
             customize_app_drawer_fragment_show_search_field_switch.isChecked = checked
             enableSearchBarOptions(checked)
         }

+ 52 - 3
app/src/main/res/xml/home_motion_scene_bottom.xml

@@ -13,11 +13,33 @@
     </Transition>
 
     <ConstraintSet android:id="@+id/home_motion_01">
+        <Constraint
+            android:id="@+id/home_fragment_analog_time"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="@dimen/_22sdp"
+            app:visibilityMode="ignore"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintHorizontal_bias="0.5"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent"/>
+        <Constraint
+            android:id="@+id/home_fragment_bin_time"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="@dimen/_42sdp"
+            android:padding="@dimen/_4sdp"
+            app:visibilityMode="ignore"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintHorizontal_bias="0.506"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent"/>
         <Constraint
             android:id="@+id/home_fragment_time"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginTop="@dimen/_42sdp"
+            app:visibilityMode="ignore"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintHorizontal_bias="0.506"
             app:layout_constraintStart_toStartOf="parent"
@@ -28,9 +50,11 @@
             android:layout_height="wrap_content"
             android:padding="@dimen/_4sdp"
             android:textSize="@dimen/_12sdp"
+            android:layout_marginTop="@dimen/_94sdp"
+            app:visibilityMode="ignore"
             app:layout_constraintEnd_toEndOf="@+id/home_fragment_time"
             app:layout_constraintStart_toStartOf="@+id/home_fragment_time"
-            app:layout_constraintTop_toBottomOf="@+id/home_fragment_time" />
+            app:layout_constraintTop_toTopOf="parent" />
         <Constraint
             android:id="@+id/home_fragment_list"
             android:layout_width="0dp"
@@ -118,9 +142,33 @@
             android:id="@+id/home_fragment_time"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_marginTop="@dimen/_64sdp"
+            android:layout_marginTop="@dimen/_44sdp"
             android:alpha="-1"
-            app:layout_constraintBottom_toTopOf="@+id/home_fragment_date"
+            app:visibilityMode="ignore"
+            app:layout_constraintBottom_toTopOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintHorizontal_bias="0.5"
+            app:layout_constraintStart_toStartOf="parent" />
+        <Constraint
+            android:id="@+id/home_fragment_analog_time"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="0px"
+            android:alpha="0"
+            app:visibilityMode="ignore"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintHorizontal_bias="0.5"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintBottom_toTopOf="parent"
+            app:layout_constraintTop_toTopOf="parent"/>
+        <Constraint
+            android:id="@+id/home_fragment_bin_time"
+            android:layout_width="wrap_content"
+            android:layout_height="0px"
+            android:layout_marginTop="0px"
+            android:alpha="-1"
+            app:visibilityMode="ignore"
+            app:layout_constraintBottom_toTopOf="parent"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintHorizontal_bias="0.5"
             app:layout_constraintStart_toStartOf="parent" />
@@ -129,6 +177,7 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:alpha="-1"
+            app:visibilityMode="ignore"
             app:layout_constraintBottom_toTopOf="parent"
             app:layout_constraintEnd_toEndOf="@+id/home_fragment_time"
             app:layout_constraintStart_toStartOf="@+id/home_fragment_time" />