mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Merge pull request #1963 from Bnyro/master
Preview App icons in Appearance Settings
This commit is contained in:
commit
440d2554ba
@ -0,0 +1,71 @@
|
||||
package com.github.libretube.ui.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.databinding.AppIconItemBinding
|
||||
import com.github.libretube.ui.viewholders.IconsSheetViewHolder
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
|
||||
class IconsSheetAdapter : RecyclerView.Adapter<IconsSheetViewHolder>() {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): IconsSheetViewHolder {
|
||||
val binding = AppIconItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return IconsSheetViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return availableIcons.size
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: IconsSheetViewHolder, position: Int) {
|
||||
val appIcon = availableIcons[position]
|
||||
holder.binding.apply { iconIV.setImageResource(appIcon.iconResource)
|
||||
iconName.text = root.context.getString(appIcon.nameResource)
|
||||
root.setOnClickListener {
|
||||
PreferenceHelper.putString(PreferenceKeys.APP_ICON, appIcon.activityAlias)
|
||||
ThemeHelper.changeIcon(root.context, appIcon.activityAlias)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
sealed class AppIcon(
|
||||
@StringRes val nameResource: Int,
|
||||
@DrawableRes val iconResource: Int,
|
||||
val activityAlias: String
|
||||
) {
|
||||
object Default :
|
||||
AppIcon(R.string.defaultIcon, R.mipmap.ic_launcher, "ui.activities.MainActivity")
|
||||
|
||||
object DefaultLight :
|
||||
AppIcon(R.string.defaultIconLight, R.mipmap.ic_launcher_light, "DefaultLight")
|
||||
|
||||
object Legacy : AppIcon(R.string.legacyIcon, R.mipmap.ic_legacy, "IconLegacy")
|
||||
object Gradient :
|
||||
AppIcon(R.string.gradientIcon, R.mipmap.ic_gradient, "IconGradient")
|
||||
|
||||
object Fire : AppIcon(R.string.fireIcon, R.mipmap.ic_fire, "IconFire")
|
||||
object Torch : AppIcon(R.string.torchIcon, R.mipmap.ic_torch, "IconTorch")
|
||||
object Shaped : AppIcon(R.string.shapedIcon, R.mipmap.ic_shaped, "IconShaped")
|
||||
object Flame : AppIcon(R.string.flameIcon, R.mipmap.ic_flame, "IconFlame")
|
||||
object Bird : AppIcon(R.string.birdIcon, R.mipmap.ic_bird, "IconBird")
|
||||
}
|
||||
|
||||
val availableIcons = listOf(
|
||||
AppIcon.Default,
|
||||
AppIcon.DefaultLight,
|
||||
AppIcon.Legacy,
|
||||
AppIcon.Gradient,
|
||||
AppIcon.Fire,
|
||||
AppIcon.Torch,
|
||||
AppIcon.Shaped,
|
||||
AppIcon.Flame,
|
||||
AppIcon.Bird
|
||||
)
|
||||
}
|
||||
}
|
@ -7,10 +7,12 @@ import androidx.preference.SwitchPreferenceCompat
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.ui.activities.SettingsActivity
|
||||
import com.github.libretube.ui.adapters.IconsSheetAdapter
|
||||
import com.github.libretube.ui.base.BasePreferenceFragment
|
||||
import com.github.libretube.ui.dialogs.NavBarOptionsDialog
|
||||
import com.github.libretube.ui.dialogs.RequireRestartDialog
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
import com.github.libretube.ui.sheets.IconsBottomSheet
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.google.android.material.color.DynamicColors
|
||||
|
||||
class AppearanceSettings : BasePreferenceFragment() {
|
||||
@ -42,9 +44,13 @@ class AppearanceSettings : BasePreferenceFragment() {
|
||||
true
|
||||
}
|
||||
|
||||
val iconChange = findPreference<ListPreference>(PreferenceKeys.APP_ICON)
|
||||
iconChange?.setOnPreferenceChangeListener { _, newValue ->
|
||||
ThemeHelper.changeIcon(requireContext(), newValue.toString())
|
||||
val changeIcon = findPreference<Preference>(PreferenceKeys.APP_ICON)
|
||||
val iconPref = PreferenceHelper.getString(PreferenceKeys.APP_ICON, IconsSheetAdapter.Companion.AppIcon.Default.activityAlias)
|
||||
IconsSheetAdapter.availableIcons.firstOrNull { it.activityAlias == iconPref }?.let {
|
||||
changeIcon?.summary = getString(it.nameResource)
|
||||
}
|
||||
changeIcon?.setOnPreferenceClickListener {
|
||||
IconsBottomSheet().show(childFragmentManager)
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,27 @@
|
||||
package com.github.libretube.ui.sheets
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.github.libretube.databinding.BottomSheetBinding
|
||||
import com.github.libretube.ui.adapters.IconsSheetAdapter
|
||||
|
||||
class IconsBottomSheet : ExpandedBottomSheet() {
|
||||
private lateinit var binding: BottomSheetBinding
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
binding = BottomSheetBinding.inflate(layoutInflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
binding.optionsRecycler.layoutManager = GridLayoutManager(context, 3)
|
||||
binding.optionsRecycler.adapter = IconsSheetAdapter()
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.github.libretube.ui.viewholders
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.databinding.AppIconItemBinding
|
||||
|
||||
class IconsSheetViewHolder(
|
||||
val binding: AppIconItemBinding
|
||||
) : RecyclerView.ViewHolder(binding.root)
|
@ -11,6 +11,7 @@ import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.text.HtmlCompat
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.ui.adapters.IconsSheetAdapter
|
||||
import com.google.android.material.color.DynamicColors
|
||||
|
||||
object ThemeHelper {
|
||||
@ -93,15 +94,9 @@ object ThemeHelper {
|
||||
* change the app icon
|
||||
*/
|
||||
fun changeIcon(context: Context, newLogoActivityAlias: String) {
|
||||
val activityAliases = context.resources.getStringArray(R.array.iconsValue)
|
||||
// Disable Old Icon(s)
|
||||
for (activityAlias in activityAliases) {
|
||||
val activityClass = "com.github.libretube." +
|
||||
if (activityAlias == activityAliases[0]) {
|
||||
"ui.activities.MainActivity" // default icon/activity
|
||||
} else {
|
||||
activityAlias
|
||||
}
|
||||
for (appIcon in IconsSheetAdapter.availableIcons) {
|
||||
val activityClass = "com.github.libretube." + appIcon.activityAlias
|
||||
|
||||
// remove old icons
|
||||
context.packageManager.setComponentEnabledSetting(
|
||||
@ -112,12 +107,7 @@ object ThemeHelper {
|
||||
}
|
||||
|
||||
// set the class name for the activity alias
|
||||
val newLogoActivityClass = "com.github.libretube." +
|
||||
if (newLogoActivityAlias == activityAliases[0]) {
|
||||
"ui.activities.MainActivity" // default icon/activity
|
||||
} else {
|
||||
newLogoActivityAlias
|
||||
}
|
||||
val newLogoActivityClass = "com.github.libretube." + newLogoActivityAlias
|
||||
// Enable New Icon
|
||||
context.packageManager.setComponentEnabledSetting(
|
||||
ComponentName(context.packageName, newLogoActivityClass),
|
||||
|
28
app/src/main/res/layout/app_icon_item.xml
Normal file
28
app/src/main/res/layout/app_icon_item.xml
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:background="@drawable/rounded_ripple"
|
||||
android:orientation="vertical"
|
||||
android:paddingVertical="10dp">
|
||||
|
||||
<de.hdodenhof.circleimageview.CircleImageView
|
||||
android:id="@+id/iconIV"
|
||||
android:layout_width="75dp"
|
||||
android:layout_height="75dp"
|
||||
android:layout_gravity="center"
|
||||
android:padding="10dp"
|
||||
tools:src="@mipmap/ic_gradient" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/iconName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textSize="11sp" />
|
||||
|
||||
</LinearLayout>
|
@ -217,29 +217,6 @@
|
||||
<item>5</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="icons">
|
||||
<item>@string/defaultIcon</item>
|
||||
<item>@string/defaultIconLight</item>
|
||||
<item>@string/legacyIcon</item>
|
||||
<item>@string/gradientIcon</item>
|
||||
<item>@string/fireIcon</item>
|
||||
<item>@string/torchIcon</item>
|
||||
<item>@string/shapedIcon</item>
|
||||
<item>@string/flameIcon</item>
|
||||
<item>@string/birdIcon</item>
|
||||
</string-array>
|
||||
<string-array name="iconsValue">
|
||||
<item>MainActivity</item>
|
||||
<item>DefaultLight</item>
|
||||
<item>IconLegacy</item>
|
||||
<item>IconGradient</item>
|
||||
<item>IconFire</item>
|
||||
<item>IconTorch</item>
|
||||
<item>IconShaped</item>
|
||||
<item>IconFlame</item>
|
||||
<item>IconBird</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="videoFormats">
|
||||
<item>MP4</item>
|
||||
<item>MKV</item>
|
||||
|
@ -29,14 +29,10 @@
|
||||
app:title="@string/color_accent"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<ListPreference
|
||||
<Preference
|
||||
android:icon="@drawable/ic_frame"
|
||||
app:defaultValue="MainActivity"
|
||||
app:entries="@array/icons"
|
||||
app:entryValues="@array/iconsValue"
|
||||
app:key="icon_change"
|
||||
app:title="@string/app_icon"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
app:title="@string/app_icon" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user