mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Merge branch 'feature/app-list-layout'
This commit is contained in:
commit
172de1f3dd
9 changed files with 161 additions and 17 deletions
|
@ -1,15 +1,11 @@
|
|||
package de.jrpie.android.launcher.preferences;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.jrpie.android.launcher.R;
|
||||
import de.jrpie.android.launcher.apps.AppInfo;
|
||||
|
@ -39,6 +35,9 @@ import eu.jonahbauer.android.preference.annotations.serializer.PreferenceSeriali
|
|||
@Preference(name = "custom_names", type = HashMap.class, serializer = LauncherPreferences$Config.MapAppInfoStringSerializer.class),
|
||||
@Preference(name = "hide_bound_apps", type = boolean.class, defaultValue = "false"),
|
||||
}),
|
||||
@PreferenceGroup(name = "list", prefix = "settings_list_", suffix = "_key", value = {
|
||||
@Preference(name = "layout", type = ListLayout.class, defaultValue = "DEFAULT")
|
||||
}),
|
||||
@PreferenceGroup(name = "gestures", prefix = "settings_gesture_", suffix = "_key", value = {
|
||||
}),
|
||||
@PreferenceGroup(name = "general", prefix = "settings_general_", suffix = "_key", value = {
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package de.jrpie.android.launcher.preferences
|
||||
|
||||
import android.content.Context
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import de.jrpie.android.launcher.R
|
||||
|
||||
|
||||
// TODO: move this to de.jrpie.android.launcher.ui.list.apps ?
|
||||
@Suppress("unused")
|
||||
enum class ListLayout(
|
||||
val layoutManager: (context: Context) -> RecyclerView.LayoutManager,
|
||||
val layoutResource: Int,
|
||||
val useBadgedText: Boolean,
|
||||
) {
|
||||
DEFAULT(
|
||||
{ c -> LinearLayoutManager(c) },
|
||||
R.layout.list_apps_row,
|
||||
false
|
||||
),
|
||||
TEXT(
|
||||
{ c -> LinearLayoutManager(c) },
|
||||
R.layout.list_apps_row_variant_text,
|
||||
true
|
||||
),
|
||||
GRID(
|
||||
{ c ->
|
||||
val displayMetrics = c.resources.displayMetrics
|
||||
val widthSp = displayMetrics.widthPixels / displayMetrics.scaledDensity
|
||||
GridLayoutManager(c, (widthSp / 90).toInt())
|
||||
},
|
||||
R.layout.list_apps_row_variant_grid,
|
||||
false
|
||||
),
|
||||
}
|
|
@ -5,7 +5,6 @@ import android.app.Activity
|
|||
import android.content.Intent
|
||||
import android.graphics.Rect
|
||||
import android.os.AsyncTask
|
||||
import android.text.InputType
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
@ -25,9 +24,11 @@ import de.jrpie.android.launcher.apps.AppFilter
|
|||
import de.jrpie.android.launcher.apps.AppInfo
|
||||
import de.jrpie.android.launcher.apps.DetailedAppInfo
|
||||
import de.jrpie.android.launcher.appsList
|
||||
import de.jrpie.android.launcher.getUserFromId
|
||||
import de.jrpie.android.launcher.loadApps
|
||||
import de.jrpie.android.launcher.openAppSettings
|
||||
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
||||
import de.jrpie.android.launcher.preferences.ListLayout
|
||||
import de.jrpie.android.launcher.transformGrayscale
|
||||
import de.jrpie.android.launcher.ui.list.ListActivity
|
||||
import de.jrpie.android.launcher.uninstallApp
|
||||
|
@ -47,7 +48,8 @@ class AppsRecyclerAdapter(
|
|||
private val intention: ListActivity.ListActivityIntention
|
||||
= ListActivity.ListActivityIntention.VIEW,
|
||||
private val forGesture: String? = "",
|
||||
private var appFilter: AppFilter = AppFilter(activity, "")
|
||||
private var appFilter: AppFilter = AppFilter(activity, ""),
|
||||
private val layout: ListLayout
|
||||
) :
|
||||
RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() {
|
||||
|
||||
|
@ -74,7 +76,15 @@ class AppsRecyclerAdapter(
|
|||
|
||||
|
||||
override fun onBindViewHolder(viewHolder: ViewHolder, i: Int) {
|
||||
val appLabel = appsListDisplayed[i].getCustomLabel(activity).toString()
|
||||
var appLabel = appsListDisplayed[i].label.toString()
|
||||
|
||||
if (layout.useBadgedText) {
|
||||
appLabel = activity.packageManager.getUserBadgedLabel(
|
||||
appLabel,
|
||||
getUserFromId(appsListDisplayed[i].app.user, activity)
|
||||
).toString()
|
||||
}
|
||||
|
||||
val appIcon = appsListDisplayed[i].icon
|
||||
|
||||
viewHolder.textView.text = appLabel
|
||||
|
@ -212,9 +222,12 @@ class AppsRecyclerAdapter(
|
|||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
|
||||
val layout = LauncherPreferences.list().layout()
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val view: View = inflater.inflate(R.layout.list_apps_row, parent, false)
|
||||
return ViewHolder(view)
|
||||
val view: View = inflater.inflate(layout.layoutResource, parent, false)
|
||||
val viewHolder = ViewHolder(view)
|
||||
return viewHolder
|
||||
}
|
||||
|
||||
init {
|
||||
|
|
|
@ -70,15 +70,15 @@ class ListFragmentApps : Fragment(), UIObject {
|
|||
"",
|
||||
favoritesVisibility = favoritesVisibility,
|
||||
hiddenVisibility = hiddenVisibility
|
||||
)
|
||||
),
|
||||
layout = LauncherPreferences.list().layout()
|
||||
)
|
||||
|
||||
// set up the list / recycler
|
||||
binding.listAppsRview.apply {
|
||||
// improve performance (since content changes don't change the layout size)
|
||||
setHasFixedSize(true)
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
// TODO: option to change this to GridLayoutManager(context, numCols)
|
||||
layoutManager = LauncherPreferences.list().layout().layoutManager(context)
|
||||
adapter = appsRViewAdapter
|
||||
}
|
||||
|
||||
|
|
34
app/src/main/res/layout/list_apps_row_variant_grid.xml
Normal file
34
app/src/main/res/layout/list_apps_row_variant_grid.xml
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?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/list_apps_row_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5sp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/list_apps_row_icon"
|
||||
android:layout_width="40sp"
|
||||
android:layout_height="40sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/list_apps_row_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:paddingTop="5dp"
|
||||
android:text=""
|
||||
android:textSize="11sp"
|
||||
tools:text="some app"
|
||||
app:layout_constraintTop_toBottomOf="@id/list_apps_row_icon"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
36
app/src/main/res/layout/list_apps_row_variant_text.xml
Normal file
36
app/src/main/res/layout/list_apps_row_variant_text.xml
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?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/list_apps_row_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5sp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/list_apps_row_icon"
|
||||
android:layout_width="0sp"
|
||||
android:layout_height="0sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:visibility="gone"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/list_apps_row_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="start|center_horizontal"
|
||||
android:padding="5dp"
|
||||
android:paddingStart="20dp"
|
||||
android:text=""
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="some app" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -13,8 +13,21 @@
|
|||
<string name="settings_apps_hidden_key" translatable="false">apps.hidden</string>
|
||||
<string name="settings_apps_custom_names_key" translatable="false">apps.custom_names</string>
|
||||
<string name="settings_apps_hide_bound_apps_key" translatable="false">apps.hide_bound_apps</string>
|
||||
|
||||
<string name="settings_list_layout_key" translatable="false">list.layout</string>
|
||||
<string name="settings_general_choose_home_screen_key" translatable="false">general.select_launcher</string>
|
||||
|
||||
<!-- values of de.jrpie.android.launcher.preferences.ListLayout -->
|
||||
<string-array name="settings_list_layout_values" translatable="false">
|
||||
<item>DEFAULT</item>
|
||||
<item>TEXT</item>
|
||||
<item>GRID</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="settings_list_layout_items" translatable="false">
|
||||
<item>@string/settings_list_layout_item_default</item>
|
||||
<item>@string/settings_list_layout_item_text</item>
|
||||
<item>@string/settings_list_layout_item_grid</item>
|
||||
</string-array>
|
||||
<!--
|
||||
-
|
||||
- Settings : Gestures
|
||||
|
|
|
@ -145,6 +145,11 @@
|
|||
<string name="settings_launcher_section_apps">Apps</string>
|
||||
<string name="settings_apps_hidden">Hidden apps</string>
|
||||
<string name="settings_apps_hide_bound_apps">Don\'t show apps that are bound to a gesture in the app list</string>
|
||||
<string name="settings_list_layout">Layout of app list</string>
|
||||
|
||||
<string name="settings_list_layout_item_default">Default</string>
|
||||
<string name="settings_list_layout_item_text">Text</string>
|
||||
<string name="settings_list_layout_item_grid">Grid</string>
|
||||
|
||||
<!--
|
||||
-
|
||||
|
|
|
@ -135,6 +135,14 @@
|
|||
android:title="@string/settings_apps_hide_bound_apps"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<DropDownPreference
|
||||
android:key="@string/settings_list_layout_key"
|
||||
android:title="@string/settings_list_layout"
|
||||
android:entries="@array/settings_list_layout_items"
|
||||
android:entryValues="@array/settings_list_layout_values"
|
||||
android:summary="%s"
|
||||
android:defaultValue="DEFAULT"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:title="@string/settings_launcher_section_display"
|
||||
|
|
Loading…
Add table
Reference in a new issue