Explorar o código

Add option for opening keyboard after app drawer transition (#107)

Co-authored-by: bakio86 <bakio86@mi.fu-berlin.de>
Co-authored-by: Joshua Kuestersteffen <jkuester@kuester7.com>
Hayri Bakici %!s(int64=3) %!d(string=hai) anos
pai
achega
c8f0e26802

+ 8 - 0
app/src/main/java/com/sduduzog/slimlauncher/datasource/apps/UnlauncherAppsRepository.kt

@@ -139,6 +139,14 @@ class UnlauncherAppsRepository(
         }
     }
 
+    fun updateActivateKeyboardInDrawer(activateKeyboardInDrawer: Boolean) {
+        lifecycleScope.launch {
+            unlauncherAppsStore.updateData {
+                it.toBuilder().setActivateKeyboardInDrawer(activateKeyboardInDrawer).build()
+            }
+        }
+    }
+
     private fun findApp(
         unlauncherApps: List<UnlauncherApp>,
         packageName: String,

+ 21 - 6
app/src/main/java/com/sduduzog/slimlauncher/ui/main/HomeFragment.kt

@@ -12,6 +12,7 @@ import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
 import android.view.inputmethod.InputMethodManager
+import androidx.appcompat.app.AppCompatActivity
 import androidx.constraintlayout.motion.widget.MotionLayout
 import androidx.constraintlayout.motion.widget.MotionLayout.TransitionListener
 import androidx.lifecycle.Observer
@@ -53,7 +54,7 @@ class HomeFragment(private val viewModel: MainViewModel) : BaseFragment(), OnLau
 
         val unlauncherAppsRepo = getUnlauncherDataSource().unlauncherAppsRepo
 
-        viewModel.apps.observe(viewLifecycleOwner, Observer { list ->
+        viewModel.apps.observe(viewLifecycleOwner, { list ->
             list?.let { apps ->
                 adapter1.setItems(apps.filter {
                     it.sortingIndex < 3
@@ -175,11 +176,25 @@ class HomeFragment(private val viewModel: MainViewModel) : BaseFragment(), OnLau
 
         home_fragment.setTransitionListener(object : TransitionListener {
             override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
-                // hide the keyboard and remove focus from the EditText when swiping back up
-                if (currentId == motionLayout?.startState) {
-                    resetAppDrawerEditText()
-                    val inputMethodManager = requireContext().getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
-                    inputMethodManager.hideSoftInputFromWindow(requireView().windowToken, 0)
+                val inputMethodManager = requireContext().getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
+
+                when (currentId) {
+                    motionLayout?.startState -> {
+                        // hide the keyboard and remove focus from the EditText when swiping back up
+                        resetAppDrawerEditText()
+                        inputMethodManager.hideSoftInputFromWindow(requireView().windowToken, 0)
+                    }
+
+                    motionLayout?.endState -> {
+                        // Check for preferences to open the keyboard
+                        getUnlauncherDataSource().unlauncherAppsRepo.liveData().observe(viewLifecycleOwner) {
+                            if (it.activateKeyboardInDrawer) {
+                                // show the keyboard and set focus to the EditText when swiping down
+                                inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0)
+                                app_drawer_edit_text.requestFocus()
+                            }
+                        }
+                    }
                 }
             }
 

+ 39 - 0
app/src/main/java/com/sduduzog/slimlauncher/ui/options/CustomizeAppDrawerAppListFragment.kt

@@ -0,0 +1,39 @@
+package com.sduduzog.slimlauncher.ui.options
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import com.sduduzog.slimlauncher.R
+import com.sduduzog.slimlauncher.adapters.CustomizeAppDrawerAppsAdapter
+import com.sduduzog.slimlauncher.utils.BaseFragment
+import dagger.hilt.android.AndroidEntryPoint
+import kotlinx.android.synthetic.main.customize_app_drawer_app_list_fragment.*
+
+@AndroidEntryPoint
+class CustomizeAppDrawerAppListFragment : BaseFragment() {
+
+    override fun getFragmentView(): ViewGroup = customize_app_drawer_fragment
+
+    override fun onCreateView(
+        inflater: LayoutInflater,
+        container: ViewGroup?,
+        savedInstanceState: Bundle?
+    ): View? {
+        return inflater.inflate(R.layout.customize_app_drawer_app_list_fragment, container, false)
+    }
+
+    override fun onActivityCreated(savedInstanceState: Bundle?) {
+        super.onActivityCreated(savedInstanceState)
+        val unlauncherAppsRepo = getUnlauncherDataSource().unlauncherAppsRepo
+        customize_app_drawer_fragment_app_list.adapter =
+            CustomizeAppDrawerAppsAdapter(viewLifecycleOwner, unlauncherAppsRepo)
+        unlauncherAppsRepo.liveData().observe(viewLifecycleOwner) {
+            it?.let {
+                customize_app_drawer_fragment_app_progress_bar.visibility = View.GONE
+            } ?: run {
+                customize_app_drawer_fragment_app_progress_bar.visibility = View.VISIBLE
+            }
+        }
+    }
+}

+ 11 - 10
app/src/main/java/com/sduduzog/slimlauncher/ui/options/CustomizeAppDrawerFragment.kt

@@ -4,8 +4,8 @@ import android.os.Bundle
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import androidx.navigation.Navigation
 import com.sduduzog.slimlauncher.R
-import com.sduduzog.slimlauncher.adapters.CustomizeAppDrawerAppsAdapter
 import com.sduduzog.slimlauncher.utils.BaseFragment
 import dagger.hilt.android.AndroidEntryPoint
 import kotlinx.android.synthetic.main.customize_app_drawer_fragment.*
@@ -25,15 +25,16 @@ class CustomizeAppDrawerFragment : BaseFragment() {
 
     override fun onActivityCreated(savedInstanceState: Bundle?) {
         super.onActivityCreated(savedInstanceState)
+
+        customize_app_drawer_fragment_visible_apps
+            .setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_customiseAppDrawerFragment_to_customiseAppDrawerAppListFragment))
+
         val unlauncherAppsRepo = getUnlauncherDataSource().unlauncherAppsRepo
-        customize_app_drawer_fragment_app_list.adapter =
-            CustomizeAppDrawerAppsAdapter(viewLifecycleOwner, unlauncherAppsRepo)
-        unlauncherAppsRepo.liveData().observe(viewLifecycleOwner, {
-            it?.let {
-                customize_app_drawer_fragment_app_progress_bar.visibility = View.GONE
-            } ?: run {
-                customize_app_drawer_fragment_app_progress_bar.visibility = View.VISIBLE
-            }
-        })
+        customize_app_drawer_open_keyboard_switch.setOnCheckedChangeListener { _, checked ->
+            unlauncherAppsRepo.updateActivateKeyboardInDrawer(checked)
+        }
+        unlauncherAppsRepo.liveData().observe(viewLifecycleOwner) {
+            customize_app_drawer_open_keyboard_switch.isChecked = it.activateKeyboardInDrawer
+        }
     }
 }

+ 1 - 0
app/src/main/proto/unlauncher_apps.proto

@@ -15,4 +15,5 @@ message UnlauncherApp {
 message UnlauncherApps {
   repeated UnlauncherApp apps = 1;
   int32 version = 2;
+  bool activate_keyboard_in_drawer = 3;
 }

+ 40 - 0
app/src/main/res/layout/customize_app_drawer_app_list_fragment.xml

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/customize_app_drawer_fragment"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".ui.options.CustomizeAppDrawerFragment">
+
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/customize_app_drawer_fragment_app_list"
+        android:layout_width="0dp"
+        android:layout_height="0dp"
+        android:layout_marginStart="8dp"
+        android:layout_marginLeft="8dp"
+        android:layout_marginEnd="8dp"
+        android:layout_marginRight="8dp"
+        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        tools:listitem="@layout/customize_app_drawer_fragment_app_list_item" />
+
+    <ProgressBar
+        android:id="@+id/customize_app_drawer_fragment_app_progress_bar"
+        style="?android:attr/progressBarStyle"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="8dp"
+        android:layout_marginLeft="8dp"
+        android:layout_marginTop="8dp"
+        android:layout_marginEnd="8dp"
+        android:layout_marginRight="8dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintVertical_bias="0.25" />
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 27 - 27
app/src/main/res/layout/customize_app_drawer_fragment.xml

@@ -7,34 +7,34 @@
     android:layout_height="match_parent"
     tools:context=".ui.options.CustomizeAppDrawerFragment">
 
-    <androidx.recyclerview.widget.RecyclerView
-        android:id="@+id/customize_app_drawer_fragment_app_list"
-        android:layout_width="0dp"
-        android:layout_height="0dp"
-        android:layout_marginStart="8dp"
-        android:layout_marginLeft="8dp"
-        android:layout_marginEnd="8dp"
-        android:layout_marginRight="8dp"
-        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent"
-        tools:listitem="@layout/customize_app_drawer_fragment_app_list_item" />
-
-    <ProgressBar
-        android:id="@+id/customize_app_drawer_fragment_app_progress_bar"
-        style="?android:attr/progressBarStyle"
+    <TextView
+        android:id="@+id/customize_app_drawer_fragment_visible_apps"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginStart="8dp"
-        android:layout_marginLeft="8dp"
-        android:layout_marginTop="8dp"
-        android:layout_marginEnd="8dp"
-        android:layout_marginRight="8dp"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
+        android:textAppearance="@style/TextAppearance.AppCompat"
+        android:layout_marginStart="@dimen/_16sdp"
+        android:layout_marginLeft="@dimen/_16sdp"
+        android:layout_marginTop="32dp"
+        android:layout_marginEnd="@dimen/_16sdp"
+        android:layout_marginRight="@dimen/_16sdp"
+        android:textSize="@dimen/_20ssp"
         app:layout_constraintTop_toTopOf="parent"
-        app:layout_constraintVertical_bias="0.25" />
+        app:layout_constraintStart_toStartOf="parent"
+        android:text="@string/customize_app_drawer_fragment_visible_apps" />
+
+    <androidx.appcompat.widget.SwitchCompat
+        android:id="@+id/customize_app_drawer_open_keyboard_switch"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="@dimen/_16sdp"
+        android:layout_marginLeft="@dimen/_16sdp"
+        android:layout_marginTop="32dp"
+        android:layout_marginEnd="@dimen/_16sdp"
+        android:layout_marginRight="@dimen/_16sdp"
+        android:layout_marginBottom="32dp"
+        android:text="@string/customize_app_drawer_fragment_open_keyboard"
+        android:textAppearance="@style/TextAppearance.AppCompat"
+        android:textSize="@dimen/_20ssp"
+        app:layout_constraintTop_toBottomOf="@id/customize_app_drawer_fragment_visible_apps"
+        app:layout_constraintStart_toStartOf="parent"/>
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 10 - 1
app/src/main/res/navigation/nav_graph.xml

@@ -52,6 +52,15 @@
         android:id="@+id/customiseAppDrawerFragment"
         android:name="com.sduduzog.slimlauncher.ui.options.CustomizeAppDrawerFragment"
         android:label="customise_app_drawer_fragment"
-        tools:layout="@layout/customize_app_drawer_fragment" />
+        tools:layout="@layout/customize_app_drawer_fragment">
+        <action
+            android:id="@+id/action_customiseAppDrawerFragment_to_customiseAppDrawerAppListFragment"
+            app:destination="@id/customiseAppDrawerAppListFragment" />
+    </fragment>
+    <fragment
+        android:id="@+id/customiseAppDrawerAppListFragment"
+        android:name="com.sduduzog.slimlauncher.ui.options.CustomizeAppDrawerAppListFragment"
+        android:label="customise_app_drawer_app_list_fragment"
+        tools:layout="@layout/customize_app_drawer_app_list_fragment" />
 
 </navigation>

+ 2 - 0
app/src/main/res/values-de/strings.xml

@@ -16,5 +16,7 @@
     <string name="options_fragment_toggle_status_bar">Statusleiste ein\\aus</string>
     <string name="options_fragment_hide_status_bar">Statusleiste verstecken</string>
     <string name="options_fragment_show_status_bar">Statusleiste zeigen</string>
+    <string name="customize_app_drawer_fragment_open_keyboard">Tastatur anzeigen</string>
+    <string name="customize_app_drawer_fragment_visible_apps">Sichtbare Apps</string>
     <string name="menu_reset">Zurücksetzen</string>
 </resources>

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -43,6 +43,8 @@
     <string name="options_fragment_toggle_status_bar">Toggle Status Bar</string>
     <string name="options_fragment_hide_status_bar">Hide Status Bar</string>
     <string name="options_fragment_show_status_bar">Show Status Bar</string>
+    <string name="customize_app_drawer_fragment_open_keyboard">Open Keyboard</string>
+    <string name="customize_app_drawer_fragment_visible_apps">Visible Apps</string>
     <string name="customise_apps_fragment_add">Add</string>
     <string name="menu_rename">Rename</string>
     <string name="menu_remove">Remove</string>