mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-03-07 12:47:48 +01:00
allow changing the column count with menu buttons
This commit is contained in:
parent
b253e01e15
commit
b04b963ee5
app/src/main
kotlin/com/simplemobiletools/applauncher
res
layout
menu
values-sw400dp
values
@ -19,10 +19,13 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
||||
import com.simplemobiletools.commons.models.FAQItem
|
||||
import com.simplemobiletools.commons.models.Release
|
||||
import com.simplemobiletools.commons.views.MyGridLayoutManager
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import java.util.*
|
||||
|
||||
class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
private val MAX_COLUMN_COUNT = 20
|
||||
|
||||
private var displayedLaunchers = ArrayList<AppLauncher>()
|
||||
private var notDisplayedLaunchers: ArrayList<AppLauncher>? = null
|
||||
private var mStoredPrimaryColor = 0
|
||||
@ -35,6 +38,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
setupLaunchers()
|
||||
checkWhatsNewDialog()
|
||||
storeStateVariables()
|
||||
setupGridLayoutManager()
|
||||
|
||||
fab.setOnClickListener {
|
||||
if (notDisplayedLaunchers != null) {
|
||||
@ -78,6 +82,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.increase_column_count -> increaseColumnCount()
|
||||
R.id.reduce_column_count -> reduceColumnCount()
|
||||
R.id.settings -> launchSettings()
|
||||
R.id.about -> launchAbout()
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
@ -135,6 +141,37 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
}
|
||||
}
|
||||
|
||||
private fun increaseColumnCount() {
|
||||
config.columnCnt = ++(launchers_grid.layoutManager as MyGridLayoutManager).spanCount
|
||||
columnCountChanged()
|
||||
}
|
||||
|
||||
private fun reduceColumnCount() {
|
||||
config.columnCnt = --(launchers_grid.layoutManager as MyGridLayoutManager).spanCount
|
||||
columnCountChanged()
|
||||
}
|
||||
|
||||
private fun columnCountChanged() {
|
||||
invalidateOptionsMenu()
|
||||
launchers_grid.adapter?.notifyDataSetChanged()
|
||||
getGridAdapter()?.launchers?.apply {
|
||||
calculateContentHeight(this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateContentHeight(directories: List<AppLauncher>) {
|
||||
val layoutManager = launchers_grid.layoutManager as MyGridLayoutManager
|
||||
val thumbnailHeight = layoutManager.getChildAt(0)?.height ?: 0
|
||||
val fullHeight = ((directories.size - 1) / layoutManager.spanCount + 1) * thumbnailHeight
|
||||
launchers_fastscroller.setContentHeight(fullHeight)
|
||||
launchers_fastscroller.setScrollToY(launchers_grid.computeVerticalScrollOffset())
|
||||
}
|
||||
|
||||
private fun setupGridLayoutManager() {
|
||||
val layoutManager = launchers_grid.layoutManager as MyGridLayoutManager
|
||||
layoutManager.spanCount = config.columnCnt
|
||||
}
|
||||
|
||||
private fun checkInvalidApps() {
|
||||
val invalidIds = ArrayList<String>()
|
||||
for ((id, name, packageName) in displayedLaunchers) {
|
||||
|
@ -18,7 +18,7 @@ import com.simplemobiletools.commons.views.FastScroller
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import kotlinx.android.synthetic.main.item_app_launcher.view.*
|
||||
|
||||
class LaunchersAdapter(activity: SimpleActivity, val launchers: MutableList<AppLauncher>, val listener: RefreshRecyclerViewListener?,
|
||||
class LaunchersAdapter(activity: SimpleActivity, val launchers: ArrayList<AppLauncher>, val listener: RefreshRecyclerViewListener?,
|
||||
recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.simplemobiletools.applauncher.helpers
|
||||
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||
|
||||
class Config(context: Context) : BaseConfig(context) {
|
||||
@ -15,4 +16,8 @@ class Config(context: Context) : BaseConfig(context) {
|
||||
var closeApp: Boolean
|
||||
get() = prefs.getBoolean(CLOSE_APP, true)
|
||||
set(closeApp) = prefs.edit().putBoolean(CLOSE_APP, closeApp).apply()
|
||||
|
||||
var columnCnt: Int
|
||||
get() = prefs.getInt(COLUMN_CNT, context.resources.getInteger(R.integer.column_count))
|
||||
set(columnCnt) = prefs.edit().putInt(COLUMN_CNT, columnCnt).apply()
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.simplemobiletools.applauncher.helpers
|
||||
|
||||
const val WAS_REMOVE_INFO_SHOWN = "was_remove_info_shown"
|
||||
const val CLOSE_APP = "close_app"
|
||||
const val COLUMN_CNT = "column_cnt"
|
||||
|
||||
val predefinedPackageNames = arrayListOf(
|
||||
"com.simplemobiletools.calculator",
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/coordinator_layout"
|
||||
android:layout_width="match_parent"
|
||||
@ -16,21 +15,21 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager"
|
||||
app:spanCount="@integer/columns"/>
|
||||
app:spanCount="@integer/column_count" />
|
||||
|
||||
<com.simplemobiletools.commons.views.FastScroller
|
||||
android:id="@+id/launchers_fastscroller"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignTop="@+id/launchers_grid"
|
||||
android:layout_alignBottom="@+id/launchers_grid"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignTop="@+id/launchers_grid"
|
||||
android:paddingStart="@dimen/normal_margin">
|
||||
|
||||
<include layout="@layout/fastscroller_handle_vertical"/>
|
||||
<include layout="@layout/fastscroller_handle_vertical" />
|
||||
|
||||
</com.simplemobiletools.commons.views.FastScroller>
|
||||
</RelativeLayout>
|
||||
@ -41,6 +40,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/activity_margin"
|
||||
android:src="@drawable/ic_plus_vector"/>
|
||||
android:src="@drawable/ic_plus_vector" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
@ -8,4 +8,4 @@
|
||||
android:padding="@dimen/small_margin"
|
||||
android:scrollbars="vertical"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager"
|
||||
app:spanCount="@integer/columns"/>
|
||||
app:spanCount="@integer/column_count"/>
|
||||
|
@ -1,12 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/increase_column_count"
|
||||
android:title="@string/increase_column_count"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/reduce_column_count"
|
||||
android:title="@string/reduce_column_count"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/settings"
|
||||
android:title="@string/settings"
|
||||
app:showAsAction="never"/>
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/about"
|
||||
android:title="@string/about"
|
||||
app:showAsAction="never"/>
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
|
@ -1,3 +1,3 @@
|
||||
<resources>
|
||||
<integer name="columns">5</integer>
|
||||
<integer name="column_count">5</integer>
|
||||
</resources>
|
||||
|
@ -1,3 +1,3 @@
|
||||
<resources>
|
||||
<integer name="columns">4</integer>
|
||||
<integer name="column_count">4</integer>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user