Browse Source

fix: folder UI polish - consistent alignment, search includes folder apps, collapse on home

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
User 3 weeks ago
parent
commit
c6a1da9c58

+ 34 - 8
app/src/main/java/com/simplauncher/adapters/AppDrawerAdapter.kt

@@ -9,6 +9,7 @@ import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
 import android.widget.ImageView
+import android.widget.LinearLayout
 import android.widget.TextView
 import androidx.lifecycle.LifecycleOwner
 import androidx.recyclerview.widget.RecyclerView
@@ -114,6 +115,13 @@ class AppDrawerAdapter(
         updateFilteredApps()
     }
 
+    fun collapseAllFolders() {
+        if (expandedFolderIds.isNotEmpty()) {
+            expandedFolderIds.clear()
+            updateFilteredApps()
+        }
+    }
+
     private fun buildFolderRows(): List<AppDrawerRow> {
         val rows = mutableListOf<AppDrawerRow>()
         for (folder in folders.foldersList) {
@@ -147,10 +155,15 @@ class AppDrawerAdapter(
         val corePreferences = unlauncherDataSource.corePreferencesRepo.get()
         val showDrawerHeadings = corePreferences.showDrawerHeadings
         val searchAllApps = corePreferences.searchAllAppsInDrawer && filterQuery != ""
+        val folderAppKeys = if (filterQuery.isNotEmpty()) {
+            folders.foldersList.flatMap { folder ->
+                folder.appsList.map { "${it.packageName}/${it.className}" }
+            }.toSet()
+        } else emptySet()
         val displayableApps = apps
             .filter { app ->
-                (app.displayInDrawer || searchAllApps) && regex.replace(app.displayName, "")
-                        .contains(filterQuery, ignoreCase = true)
+                (app.displayInDrawer || searchAllApps || "${app.packageName}/${app.className}" in folderAppKeys) &&
+                        regex.replace(app.displayName, "").contains(filterQuery, ignoreCase = true)
             }
 
         val includeHeadings = !showDrawerHeadings || filterQuery != ""
@@ -220,6 +233,7 @@ class AppDrawerAdapter(
     }
 
     inner class FolderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
+        private val container: LinearLayout = itemView as LinearLayout
         private val name: TextView = itemView.findViewById(R.id.folder_item_name)
         private val arrowLeft: ImageView = itemView.findViewById(R.id.folder_item_arrow_left)
         private val arrowRight: ImageView = itemView.findViewById(R.id.folder_item_arrow_right)
@@ -228,25 +242,36 @@ class AppDrawerAdapter(
             name.text = folder.name
             name.gravity = gravity
 
+            val nameParams = name.layoutParams as LinearLayout.LayoutParams
             val expandedRotation = 0f // points down
             when (gravity) {
                 Gravity.LEFT, Gravity.START -> {
+                    container.gravity = Gravity.CENTER_VERTICAL
+                    nameParams.weight = 1f
+                    nameParams.width = 0
                     arrowLeft.visibility = View.VISIBLE
                     arrowRight.visibility = View.GONE
                     arrowLeft.animate().rotation(if (isExpanded) expandedRotation else -90f).setDuration(200).start()
                 }
                 Gravity.RIGHT, Gravity.END -> {
+                    container.gravity = Gravity.CENTER_VERTICAL
+                    nameParams.weight = 1f
+                    nameParams.width = 0
                     arrowLeft.visibility = View.GONE
                     arrowRight.visibility = View.VISIBLE
                     arrowRight.animate().rotation(if (isExpanded) expandedRotation else 90f).setDuration(200).start()
                 }
                 else -> { // CENTER_HORIZONTAL (1)
+                    container.gravity = Gravity.CENTER
+                    nameParams.weight = 0f
+                    nameParams.width = LinearLayout.LayoutParams.WRAP_CONTENT
                     arrowLeft.visibility = View.VISIBLE
                     arrowRight.visibility = View.VISIBLE
                     arrowLeft.animate().rotation(if (isExpanded) expandedRotation else -90f).setDuration(200).start()
                     arrowRight.animate().rotation(if (isExpanded) expandedRotation else 90f).setDuration(200).start()
                 }
             }
+            name.layoutParams = nameParams
         }
     }
 
@@ -256,13 +281,14 @@ class AppDrawerAdapter(
         fun bind(app: UnlauncherApp, gravity: Int, isLastInFolder: Boolean) {
             item.text = app.displayName
             item.gravity = gravity
-            val indentPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48f, item.resources.displayMetrics).toInt()
-            val bottomPadPx = if (isLastInFolder) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24f, item.resources.displayMetrics).toInt() else 0
-            val basePad = item.paddingTop
+            val res = item.resources
+            val basePad = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8f, res.displayMetrics).toInt()
+            val indentPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48f, res.displayMetrics).toInt()
+            val bottomPadPx = if (isLastInFolder) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24f, res.displayMetrics).toInt() else basePad
             when (gravity) {
-                Gravity.LEFT, Gravity.START -> item.setPadding(indentPx, basePad, item.paddingRight, bottomPadPx)
-                Gravity.RIGHT, Gravity.END -> item.setPadding(item.paddingLeft, basePad, indentPx, bottomPadPx)
-                else -> item.setPadding(item.paddingLeft, basePad, item.paddingRight, bottomPadPx)
+                Gravity.LEFT, Gravity.START -> item.setPadding(indentPx, basePad, basePad, bottomPadPx)
+                Gravity.RIGHT, Gravity.END -> item.setPadding(basePad, basePad, indentPx, bottomPadPx)
+                else -> item.setPadding(basePad, basePad, basePad, bottomPadPx)
             }
         }
     }

+ 1 - 0
app/src/main/java/com/simplauncher/ui/main/HomeFragment.kt

@@ -309,6 +309,7 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
                         // hide the keyboard and remove focus from the EditText when swiping back up
                         resetAppDrawerEditText()
                         inputMethodManager.hideSoftInputFromWindow(requireView().windowToken, 0)
+                        appDrawerAdapter.collapseAllFolders()
                     }
 
                     motionLayout?.endState -> {