Finish migrating icon pack selector to Jetpack Compose
This commit is contained in:
1 parent
5a6e901840
commit
9e7017e90a
9 files changed
+3
-305
No files matched your search
@@ -1,42 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge 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:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radio_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon_pack_icon"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginStart="12dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/radio_button"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:srcCompat="@drawable/all_apps_edu_circle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/icon_pack_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:textAppearance="?attr/textAppearanceBody1"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/icon_pack_icon"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Icon Pack" />
|
||||
</merge>
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/icon_packs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#00000000" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,34 +0,0 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="@android:dimen/app_icon_size"
|
||||
android:layout_height="@android:dimen/app_icon_size"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_margin="8dp"
|
||||
android:contentDescription="@null" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:paddingEnd="8dip"
|
||||
android:paddingStart="8dip"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:textSize="19sp" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radio"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:clickable="false"
|
||||
android:duplicateParentState="true"
|
||||
android:focusable="false"
|
||||
android:paddingEnd="8dip" />
|
||||
</LinearLayout>
|
||||
@@ -1,47 +0,0 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:background="?android:attr/activatedBackgroundIndicator">
|
||||
|
||||
<com.android.internal.widget.PreferenceImageView
|
||||
android:id="@android:id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxWidth="48dp"
|
||||
android:maxHeight="48dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView
|
||||
android:id="@+android:id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||
android:ellipsize="marquee"
|
||||
android:fadingEdge="horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@android:id/title"
|
||||
android:layout_alignStart="@android:id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:maxLines="10"
|
||||
android:ellipsize="end" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
@@ -15,9 +15,7 @@
|
||||
</intent>
|
||||
</com.android.launcher3.settings.NotificationDotsPreference>
|
||||
|
||||
<Preference android:title="Icon Pack" android:fragment="ch.deletescape.lawnchair.settings.fragments.IconPackSettingsFragment" />
|
||||
|
||||
<Preference android:title="Icon Pack (Jetpack Compose)">
|
||||
<Preference android:title="Icon Pack">
|
||||
<intent android:action="ch.deletescape.lawnchair.settings.activities.IconPackSettingsActivity" />
|
||||
</Preference>
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,5 @@
|
||||
package ch.deletescape.lawnchair.settings.activities
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.ResolveInfo
|
||||
@@ -28,6 +27,7 @@ import androidx.core.graphics.drawable.toBitmap
|
||||
import ch.deletescape.lawnchair.settings.ui.theme.LawnchairTheme
|
||||
import ch.deletescape.lawnchair.sharedprefs.LawnchairPreferences
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.Utilities
|
||||
|
||||
class IconPackSettingsActivity : AppCompatActivity() {
|
||||
|
||||
@@ -74,7 +74,7 @@ class IconPackSettingsActivity : AppCompatActivity() {
|
||||
return iconPacks
|
||||
}
|
||||
|
||||
private val sharedPref: SharedPreferences by lazy { this.getPreferences(Context.MODE_PRIVATE) }
|
||||
private val sharedPref: SharedPreferences by lazy { Utilities.getPrefs(this) }
|
||||
private val dbSelectedIconPackPackageName by lazy { sharedPref.getString(LawnchairPreferences.ICON_PACK_PACKAGE, "")!! }
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package ch.deletescape.lawnchair.settings.adapters
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import ch.deletescape.lawnchair.settings.views.IconPackListItem
|
||||
import ch.deletescape.lawnchair.sharedprefs.LawnchairPreferences
|
||||
|
||||
class IconPackAdapter(private val dataSet: List<IconPackInfo>, prefs: SharedPreferences) :
|
||||
RecyclerView.Adapter<IconPackAdapter.ViewHolder>() {
|
||||
|
||||
data class IconPackInfo(val name: String, val packageName: String, val icon: Drawable?)
|
||||
|
||||
// TODO: Store package name of currently applied icon pack in settings database. Also see `IconPackSettingsFragment`.
|
||||
private var selectedIconPackPackageName: String = ""
|
||||
|
||||
fun interface CheckListener {
|
||||
fun onItemChecked(id: String)
|
||||
}
|
||||
|
||||
private val checkListener = CheckListener { id ->
|
||||
if (selectedIconPackPackageName != id) {
|
||||
selectedIconPackPackageName = id
|
||||
// TODO: Use `DiffUtil` instead of `notifyDataSetChanged` to fix animations.
|
||||
notifyDataSetChanged()
|
||||
prefs.edit().putString(LawnchairPreferences.ICON_PACK_PACKAGE, id).apply()
|
||||
}
|
||||
}
|
||||
|
||||
class ViewHolder(private val view: IconPackListItem, private val checkListener: CheckListener) :
|
||||
RecyclerView.ViewHolder(view) {
|
||||
fun bind(iconPackInfo: IconPackInfo, selectedIconPackPackageName: String) {
|
||||
view.layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
view.iconPackName = iconPackInfo.name
|
||||
view.iconPackPackageName = iconPackInfo.packageName
|
||||
view.iconPackIcon = iconPackInfo.icon
|
||||
view.isChecked = selectedIconPackPackageName == view.iconPackPackageName
|
||||
itemView.setOnClickListener { checkListener.onItemChecked(view.iconPackPackageName) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val iconPackListItem = IconPackListItem(parent.context)
|
||||
return ViewHolder(iconPackListItem, checkListener)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bind(dataSet[position], selectedIconPackPackageName)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = dataSet.size
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package ch.deletescape.lawnchair.settings.fragments
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.pm.ResolveInfo
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import ch.deletescape.lawnchair.settings.adapters.IconPackAdapter
|
||||
import ch.deletescape.lawnchair.settings.adapters.IconPackAdapter.IconPackInfo
|
||||
import ch.deletescape.lawnchair.settings.interfaces.TitledFragment
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.Utilities
|
||||
import com.google.android.material.transition.MaterialSharedAxis
|
||||
import kotlin.collections.set
|
||||
|
||||
|
||||
class IconPackSettingsFragment : Fragment(R.layout.icon_pack_settings_fragment), TitledFragment {
|
||||
|
||||
override val title: String
|
||||
get() = "Icon Pack"
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, true)
|
||||
returnTransition = MaterialSharedAxis(MaterialSharedAxis.Z, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val recyclerView: RecyclerView = requireView().findViewById(R.id.icon_packs)
|
||||
recyclerView.layoutManager = LinearLayoutManager(context)
|
||||
|
||||
// TODO: Add list entry for each installed icon pack. Also see `IconPackAdapter`.
|
||||
val dataSet: ArrayList<IconPackInfo> = ArrayList()
|
||||
dataSet.add(IconPackAdapter.IconPackInfo("System Icons", "",
|
||||
context?.let { ContextCompat.getDrawable(it, R.drawable.ic_launcher_home) }))
|
||||
dataSet.addAll(loadAvailableIconPacks().values)
|
||||
val prefs = Utilities.getPrefs(context)
|
||||
recyclerView.adapter = IconPackAdapter(dataSet, prefs)
|
||||
}
|
||||
|
||||
private fun loadAvailableIconPacks(): MutableMap<String,IconPackInfo> {
|
||||
val iconPacks: MutableMap<String, IconPackInfo> = HashMap()
|
||||
val list: MutableList<ResolveInfo>
|
||||
val pm = requireContext().packageManager
|
||||
list = pm.queryIntentActivities(Intent("com.novalauncher.THEME"), 0)
|
||||
list.addAll(pm.queryIntentActivities(Intent("org.adw.launcher.icons.ACTION_PICK_ICON"), 0))
|
||||
list.addAll(pm.queryIntentActivities(Intent("com.dlto.atom.launcher.THEME"), 0))
|
||||
list.addAll(pm.queryIntentActivities(Intent("android.intent.action.MAIN").addCategory("com.anddoes.launcher.THEME"), 0))
|
||||
for (info in list) {
|
||||
iconPacks[info.activityInfo.packageName] = IconPackInfo(info.loadLabel(pm).toString(), info.activityInfo.packageName, info.loadIcon(pm))
|
||||
}
|
||||
return iconPacks
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package ch.deletescape.lawnchair.settings.views
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.*
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import ch.deletescape.lawnchair.extensions.getThemeDrawable
|
||||
import com.android.launcher3.R
|
||||
|
||||
class IconPackListItem(context: Context) : ConstraintLayout(context), Checkable {
|
||||
|
||||
private val radioButtonView: RadioButton
|
||||
private val iconPackNameView: TextView
|
||||
private val iconPackIconView: ImageView
|
||||
|
||||
init {
|
||||
LayoutInflater.from(context).inflate(R.layout.icon_pack_list_item, this)
|
||||
radioButtonView = findViewById(R.id.radio_button)
|
||||
iconPackNameView = findViewById(R.id.icon_pack_name)
|
||||
iconPackIconView = findViewById(R.id.icon_pack_icon)
|
||||
background = context.getThemeDrawable(R.attr.selectableItemBackground)
|
||||
}
|
||||
|
||||
var iconPackPackageName: String = ""
|
||||
|
||||
var iconPackName: String? = null
|
||||
set(value) {
|
||||
field = value
|
||||
iconPackNameView.text = value
|
||||
}
|
||||
|
||||
var iconPackIcon: Drawable? = null
|
||||
set(value) {
|
||||
field = value
|
||||
iconPackIconView.setImageDrawable(value)
|
||||
}
|
||||
|
||||
override fun setChecked(checked: Boolean) {
|
||||
radioButtonView.isChecked = checked
|
||||
}
|
||||
|
||||
override fun isChecked(): Boolean = radioButtonView.isChecked
|
||||
|
||||
override fun toggle() {
|
||||
isChecked = !isChecked
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user