Enable customization of column count for application drawer

This commit is contained in:
Ensar Sarajčić 2023-07-13 12:19:33 +02:00
parent 552b7e561a
commit 7bbdf581de
9 changed files with 91 additions and 17 deletions

View file

@ -11,7 +11,7 @@ import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.adapters.HiddenIconsAdapter
import com.simplemobiletools.launcher.extensions.getColumnCount
import com.simplemobiletools.launcher.extensions.getDrawerColumnCount
import com.simplemobiletools.launcher.extensions.getDrawableForPackageName
import com.simplemobiletools.launcher.extensions.hiddenIconsDB
import com.simplemobiletools.launcher.models.HiddenIcon
@ -28,7 +28,7 @@ class HiddenIconsActivity : SimpleActivity(), RefreshRecyclerViewListener {
setupMaterialScrollListener(manage_hidden_icons_list, manage_hidden_icons_toolbar)
val layoutManager = manage_hidden_icons_list.layoutManager as MyGridLayoutManager
layoutManager.spanCount = getColumnCount()
layoutManager.spanCount = getDrawerColumnCount()
}
override fun onResume() {

View file

@ -208,6 +208,8 @@ class MainActivity : SimpleActivity(), FlingListener {
if (window.navigationBarColor != resources.getColor(R.color.semitransparent_navigation)) {
window.navigationBarColor = Color.TRANSPARENT
}
(all_apps_fragment as? AllAppsFragment)?.onResume()
}
override fun onStop() {

View file

@ -2,15 +2,19 @@ package com.simplemobiletools.launcher.activities
import android.content.Intent
import android.os.Bundle
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.NavigationIcon
import com.simplemobiletools.commons.helpers.isTiramisuPlus
import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.launcher.BuildConfig
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.extensions.config
import com.simplemobiletools.launcher.extensions.getDrawerColumnCount
import com.simplemobiletools.launcher.helpers.MAX_COLUMN_COUNT
import kotlinx.android.synthetic.main.activity_settings.*
import java.util.*
import java.util.Locale
import kotlin.system.exitProcess
class SettingsActivity : SimpleActivity() {
@ -32,6 +36,7 @@ class SettingsActivity : SimpleActivity() {
setupPurchaseThankYou()
setupCustomizeColors()
setupUseEnglish()
setupDrawerColumnCount()
setupLanguage()
setupManageHiddenIcons()
updateTextColors(settings_holder)
@ -82,6 +87,29 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupDrawerColumnCount() {
val currentColumnCount = getDrawerColumnCount()
settings_drawer_column_count.text = currentColumnCount.toString()
settings_drawer_column_count_holder.setOnClickListener {
val items = ArrayList<RadioItem>()
for (i in 1..MAX_COLUMN_COUNT) {
items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i)))
}
RadioGroupDialog(this, items, currentColumnCount) {
val newColumnCount = it as Int
if (currentColumnCount != newColumnCount) {
if (portrait) {
config.portraitDrawerColumnCount = newColumnCount
} else {
config.landscapeDrawerColumnCount = newColumnCount
}
setupDrawerColumnCount()
}
}
}
}
private fun setupLanguage() {
settings_language.text = Locale.getDefault().displayLanguage
settings_language_holder.beVisibleIf(isTiramisuPlus())

View file

@ -11,10 +11,10 @@ import com.bumptech.glide.request.transition.DrawableCrossFadeFactory
import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
import com.simplemobiletools.commons.extensions.getProperTextColor
import com.simplemobiletools.commons.extensions.portrait
import com.simplemobiletools.commons.extensions.realScreenSize
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.activities.SimpleActivity
import com.simplemobiletools.launcher.extensions.getDrawerColumnCount
import com.simplemobiletools.launcher.interfaces.AllAppsListener
import com.simplemobiletools.launcher.models.AppLauncher
import com.simplemobiletools.launcher.models.HomeScreenGridItem
@ -47,13 +47,7 @@ class LaunchersAdapter(
override fun getItemCount() = launchers.size
private fun calculateIconWidth() {
val currentColumnCount = activity.resources.getInteger(
if (activity.portrait) {
R.integer.portrait_column_count
} else {
R.integer.landscape_column_count
}
)
val currentColumnCount = activity.getDrawerColumnCount()
val iconWidth = activity.realScreenSize.x / currentColumnCount
iconPadding = (iconWidth * 0.1f).toInt()

View file

@ -23,11 +23,11 @@ val Context.homeScreenGridItemsDB: HomeScreenGridItemsDao get() = AppsDatabase.g
val Context.hiddenIconsDB: HiddenIconsDao get() = AppsDatabase.getInstance(applicationContext).HiddenIconsDao()
fun Context.getColumnCount(): Int {
fun Context.getDrawerColumnCount(): Int {
return if (portrait) {
resources.getInteger(R.integer.portrait_column_count)
config.portraitDrawerColumnCount
} else {
resources.getInteger(R.integer.landscape_column_count)
config.landscapeDrawerColumnCount
}
}

View file

@ -13,7 +13,7 @@ import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.launcher.R
import com.simplemobiletools.launcher.activities.MainActivity
import com.simplemobiletools.launcher.adapters.LaunchersAdapter
import com.simplemobiletools.launcher.extensions.getColumnCount
import com.simplemobiletools.launcher.extensions.getDrawerColumnCount
import com.simplemobiletools.launcher.extensions.launchApp
import com.simplemobiletools.launcher.helpers.ITEM_TYPE_ICON
import com.simplemobiletools.launcher.interfaces.AllAppsListener
@ -40,6 +40,20 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
}
}
@SuppressLint("NotifyDataSetChanged")
fun onResume() {
if (all_apps_grid?.layoutManager == null || all_apps_grid?.adapter == null) {
return
}
val layoutManager = all_apps_grid.layoutManager as MyGridLayoutManager
if (layoutManager.spanCount != context.getDrawerColumnCount()) {
onConfigurationChanged()
// Force redraw due to changed item size
(all_apps_grid.adapter as LaunchersAdapter).notifyDataSetChanged()
}
}
fun onConfigurationChanged() {
if (all_apps_grid == null) {
return
@ -50,7 +64,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
setupViews()
val layoutManager = all_apps_grid.layoutManager as MyGridLayoutManager
layoutManager.spanCount = context.getColumnCount()
layoutManager.spanCount = context.getDrawerColumnCount()
val launchers = (all_apps_grid.adapter as LaunchersAdapter).launchers
setupAdapter(launchers)
}
@ -100,7 +114,7 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
private fun setupAdapter(launchers: ArrayList<AppLauncher>) {
activity?.runOnUiThread {
val layoutManager = all_apps_grid.layoutManager as MyGridLayoutManager
layoutManager.spanCount = context.getColumnCount()
layoutManager.spanCount = context.getDrawerColumnCount()
val currAdapter = all_apps_grid.adapter
if (currAdapter == null) {

View file

@ -2,6 +2,7 @@ package com.simplemobiletools.launcher.helpers
import android.content.Context
import com.simplemobiletools.commons.helpers.BaseConfig
import com.simplemobiletools.launcher.R
class Config(context: Context) : BaseConfig(context) {
companion object {
@ -11,4 +12,12 @@ class Config(context: Context) : BaseConfig(context) {
var wasHomeScreenInit: Boolean
get() = prefs.getBoolean(WAS_HOME_SCREEN_INIT, false)
set(wasHomeScreenInit) = prefs.edit().putBoolean(WAS_HOME_SCREEN_INIT, wasHomeScreenInit).apply()
var portraitDrawerColumnCount: Int
get() = prefs.getInt(PORTRAIT_DRAWER_COLUMN_COUNT, context.resources.getInteger(R.integer.portrait_column_count))
set(portraitDrawerColumnCount) = prefs.edit().putInt(PORTRAIT_DRAWER_COLUMN_COUNT, portraitDrawerColumnCount).apply()
var landscapeDrawerColumnCount: Int
get() = prefs.getInt(LANDSCAPE_DRAWER_COLUMN_COUNT, context.resources.getInteger(R.integer.landscape_column_count))
set(landscapeDrawerColumnCount) = prefs.edit().putInt(LANDSCAPE_DRAWER_COLUMN_COUNT, landscapeDrawerColumnCount).apply()
}

View file

@ -5,10 +5,13 @@ const val WIDGET_LIST_ITEMS_HOLDER = 1
// shared prefs
const val WAS_HOME_SCREEN_INIT = "was_home_screen_init"
const val PORTRAIT_DRAWER_COLUMN_COUNT = "portrait_drawer_column_count"
const val LANDSCAPE_DRAWER_COLUMN_COUNT = "landscape_drawer_column_count"
// default home screen grid size
const val ROW_COUNT = 6
const val COLUMN_COUNT = 5
const val MAX_COLUMN_COUNT = 15
const val UNINSTALL_APP_REQUEST_CODE = 50
const val REQUEST_CONFIGURE_WIDGET = 51

View file

@ -120,6 +120,30 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_drawer_column_count_holder"
style="@style/SettingsHolderTextViewOneLinerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_bottom_corners">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_drawer_column_count_label"
style="@style/SettingsTextLabelStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drawer column count" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_drawer_column_count"
style="@style/SettingsTextValueStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/settings_drawer_column_count_label"
tools:text="3" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_manage_hidden_icons_holder"
style="@style/SettingsHolderTextViewOneLinerStyle"