mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
add list layout to preferences.xml
This commit is contained in:
parent
7ee39ba3b8
commit
80cb8e995a
7 changed files with 41 additions and 31 deletions
|
@ -1,20 +1,15 @@
|
||||||
package de.jrpie.android.launcher.preferences;
|
package de.jrpie.android.launcher.preferences;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import de.jrpie.android.launcher.R;
|
import de.jrpie.android.launcher.R;
|
||||||
import de.jrpie.android.launcher.apps.AppInfo;
|
import de.jrpie.android.launcher.apps.AppInfo;
|
||||||
import de.jrpie.android.launcher.actions.lock.LockMethod;
|
import de.jrpie.android.launcher.actions.lock.LockMethod;
|
||||||
import de.jrpie.android.launcher.preferences.theme.AppListLayout;
|
|
||||||
import de.jrpie.android.launcher.preferences.theme.Background;
|
import de.jrpie.android.launcher.preferences.theme.Background;
|
||||||
import de.jrpie.android.launcher.preferences.theme.ColorTheme;
|
import de.jrpie.android.launcher.preferences.theme.ColorTheme;
|
||||||
import de.jrpie.android.launcher.preferences.theme.Font;
|
import de.jrpie.android.launcher.preferences.theme.Font;
|
||||||
|
@ -40,8 +35,8 @@ import eu.jonahbauer.android.preference.annotations.serializer.PreferenceSeriali
|
||||||
@Preference(name = "custom_names", type = HashMap.class, serializer = LauncherPreferences$Config.MapAppInfoStringSerializer.class),
|
@Preference(name = "custom_names", type = HashMap.class, serializer = LauncherPreferences$Config.MapAppInfoStringSerializer.class),
|
||||||
@Preference(name = "hide_bound_apps", type = boolean.class, defaultValue = "false"),
|
@Preference(name = "hide_bound_apps", type = boolean.class, defaultValue = "false"),
|
||||||
}),
|
}),
|
||||||
@PreferenceGroup(name = "list_apps", prefix = "settings_list_apps_", suffix = "_key", value = {
|
@PreferenceGroup(name = "list", prefix = "settings_list_", suffix = "_key", value = {
|
||||||
@Preference(name = "layout", type = AppListLayout.class, defaultValue = "TEXT")
|
@Preference(name = "layout", type = ListLayout.class, defaultValue = "DEFAULT")
|
||||||
}),
|
}),
|
||||||
@PreferenceGroup(name = "gestures", prefix = "settings_gesture_", suffix = "_key", value = {
|
@PreferenceGroup(name = "gestures", prefix = "settings_gesture_", suffix = "_key", value = {
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -1,43 +1,36 @@
|
||||||
package de.jrpie.android.launcher.preferences.theme
|
package de.jrpie.android.launcher.preferences
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import de.jrpie.android.launcher.R
|
import de.jrpie.android.launcher.R
|
||||||
import de.jrpie.android.launcher.ui.list.apps.AppsRecyclerAdapter
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: move this to de.jrpie.android.launcher.ui.list.apps ?
|
// TODO: move this to de.jrpie.android.launcher.ui.list.apps ?
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
enum class AppListLayout(
|
enum class ListLayout(
|
||||||
val layoutManager: (context: Context) -> RecyclerView.LayoutManager,
|
val layoutManager: (context: Context) -> RecyclerView.LayoutManager,
|
||||||
val layoutResource: Int,
|
val layoutResource: Int,
|
||||||
val prepareView: (viewHolder: AppsRecyclerAdapter.ViewHolder) -> Unit,
|
val useBadgedText: Boolean,
|
||||||
val useBadgedText: Boolean
|
|
||||||
|
|
||||||
) {
|
) {
|
||||||
DEFAULT(
|
DEFAULT(
|
||||||
{ c -> LinearLayoutManager(c) },
|
{ c -> LinearLayoutManager(c) },
|
||||||
R.layout.list_apps_row,
|
R.layout.list_apps_row,
|
||||||
{ v -> },
|
|
||||||
false
|
false
|
||||||
),
|
),
|
||||||
|
|
||||||
TEXT(
|
TEXT(
|
||||||
{ c -> LinearLayoutManager(c) },
|
{ c -> LinearLayoutManager(c) },
|
||||||
R.layout.list_apps_row_variant_text,
|
R.layout.list_apps_row_variant_text,
|
||||||
{ v -> },
|
|
||||||
true
|
true
|
||||||
),
|
),
|
||||||
GRID(
|
GRID(
|
||||||
{ c ->
|
{ c ->
|
||||||
val displayMetrics = c.resources.displayMetrics
|
val displayMetrics = c.resources.displayMetrics
|
||||||
val widthSp = displayMetrics.widthPixels / displayMetrics.scaledDensity
|
val widthSp = displayMetrics.widthPixels / displayMetrics.scaledDensity
|
||||||
GridLayoutManager(c, (widthSp / 90).toInt()) },
|
GridLayoutManager(c, (widthSp / 90).toInt())
|
||||||
R.layout.list_apps_row_variant_grid,
|
|
||||||
{ v ->
|
|
||||||
},
|
},
|
||||||
|
R.layout.list_apps_row_variant_grid,
|
||||||
false
|
false
|
||||||
),
|
),
|
||||||
}
|
}
|
|
@ -5,7 +5,6 @@ import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import android.text.InputType
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -21,7 +20,6 @@ import com.google.android.material.snackbar.Snackbar
|
||||||
import de.jrpie.android.launcher.R
|
import de.jrpie.android.launcher.R
|
||||||
import de.jrpie.android.launcher.REQUEST_CHOOSE_APP
|
import de.jrpie.android.launcher.REQUEST_CHOOSE_APP
|
||||||
import de.jrpie.android.launcher.actions.AppAction
|
import de.jrpie.android.launcher.actions.AppAction
|
||||||
import de.jrpie.android.launcher.actions.LauncherDeviceAdmin
|
|
||||||
import de.jrpie.android.launcher.apps.AppFilter
|
import de.jrpie.android.launcher.apps.AppFilter
|
||||||
import de.jrpie.android.launcher.apps.AppInfo
|
import de.jrpie.android.launcher.apps.AppInfo
|
||||||
import de.jrpie.android.launcher.apps.DetailedAppInfo
|
import de.jrpie.android.launcher.apps.DetailedAppInfo
|
||||||
|
@ -30,7 +28,7 @@ import de.jrpie.android.launcher.getUserFromId
|
||||||
import de.jrpie.android.launcher.loadApps
|
import de.jrpie.android.launcher.loadApps
|
||||||
import de.jrpie.android.launcher.openAppSettings
|
import de.jrpie.android.launcher.openAppSettings
|
||||||
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
||||||
import de.jrpie.android.launcher.preferences.theme.AppListLayout
|
import de.jrpie.android.launcher.preferences.ListLayout
|
||||||
import de.jrpie.android.launcher.transformGrayscale
|
import de.jrpie.android.launcher.transformGrayscale
|
||||||
import de.jrpie.android.launcher.ui.list.ListActivity
|
import de.jrpie.android.launcher.ui.list.ListActivity
|
||||||
import de.jrpie.android.launcher.uninstallApp
|
import de.jrpie.android.launcher.uninstallApp
|
||||||
|
@ -50,8 +48,8 @@ class AppsRecyclerAdapter(
|
||||||
private val intention: ListActivity.ListActivityIntention
|
private val intention: ListActivity.ListActivityIntention
|
||||||
= ListActivity.ListActivityIntention.VIEW,
|
= ListActivity.ListActivityIntention.VIEW,
|
||||||
private val forGesture: String? = "",
|
private val forGesture: String? = "",
|
||||||
private var appFilter: AppFilter = AppFilter(activity, "")
|
private var appFilter: AppFilter = AppFilter(activity, ""),
|
||||||
private val layout: AppListLayout
|
private val layout: ListLayout
|
||||||
) :
|
) :
|
||||||
RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() {
|
RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() {
|
||||||
|
|
||||||
|
@ -225,11 +223,10 @@ class AppsRecyclerAdapter(
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
|
|
||||||
val layout = LauncherPreferences.list_apps().layout()
|
val layout = LauncherPreferences.list().layout()
|
||||||
val inflater = LayoutInflater.from(parent.context)
|
val inflater = LayoutInflater.from(parent.context)
|
||||||
val view: View = inflater.inflate(layout.layoutResource, parent, false)
|
val view: View = inflater.inflate(layout.layoutResource, parent, false)
|
||||||
val viewHolder = ViewHolder(view)
|
val viewHolder = ViewHolder(view)
|
||||||
layout.prepareView(viewHolder)
|
|
||||||
return viewHolder
|
return viewHolder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,15 +71,14 @@ class ListFragmentApps : Fragment(), UIObject {
|
||||||
favoritesVisibility = favoritesVisibility,
|
favoritesVisibility = favoritesVisibility,
|
||||||
hiddenVisibility = hiddenVisibility
|
hiddenVisibility = hiddenVisibility
|
||||||
),
|
),
|
||||||
layout = LauncherPreferences.list_apps().layout()
|
layout = LauncherPreferences.list().layout()
|
||||||
)
|
)
|
||||||
|
|
||||||
// set up the list / recycler
|
// set up the list / recycler
|
||||||
binding.listAppsRview.apply {
|
binding.listAppsRview.apply {
|
||||||
// improve performance (since content changes don't change the layout size)
|
// improve performance (since content changes don't change the layout size)
|
||||||
setHasFixedSize(true)
|
setHasFixedSize(true)
|
||||||
layoutManager = LauncherPreferences.list_apps().layout().layoutManager(context)
|
layoutManager = LauncherPreferences.list().layout().layoutManager(context)
|
||||||
// TODO: option to change this to GridLayoutManager(context, numCols)
|
|
||||||
adapter = appsRViewAdapter
|
adapter = appsRViewAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,21 @@
|
||||||
<string name="settings_apps_hidden_key" translatable="false">apps.hidden</string>
|
<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_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_apps_hide_bound_apps_key" translatable="false">apps.hide_bound_apps</string>
|
||||||
<string name="settings_list_apps_layout_key" translatable="false">list.apps.layout</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>
|
<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
|
- Settings : Gestures
|
||||||
|
|
|
@ -145,6 +145,11 @@
|
||||||
<string name="settings_launcher_section_apps">Apps</string>
|
<string name="settings_launcher_section_apps">Apps</string>
|
||||||
<string name="settings_apps_hidden">Hidden 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_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:title="@string/settings_apps_hide_bound_apps"
|
||||||
android:defaultValue="false" />
|
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>
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="@string/settings_launcher_section_display"
|
android:title="@string/settings_launcher_section_display"
|
||||||
|
|
Loading…
Add table
Reference in a new issue