mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-02-08 15:58:41 +01:00
adding a sorting menu button
This commit is contained in:
parent
32a7d0136a
commit
5dc2346efe
@ -56,7 +56,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:5.31.25'
|
implementation 'com.simplemobiletools:commons:5.31.26'
|
||||||
implementation 'com.facebook.stetho:stetho:1.5.0'
|
implementation 'com.facebook.stetho:stetho:1.5.0'
|
||||||
implementation 'androidx.multidex:multidex:2.0.1'
|
implementation 'androidx.multidex:multidex:2.0.1'
|
||||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
||||||
|
@ -8,6 +8,7 @@ import com.simplemobiletools.applauncher.BuildConfig
|
|||||||
import com.simplemobiletools.applauncher.R
|
import com.simplemobiletools.applauncher.R
|
||||||
import com.simplemobiletools.applauncher.adapters.LaunchersAdapter
|
import com.simplemobiletools.applauncher.adapters.LaunchersAdapter
|
||||||
import com.simplemobiletools.applauncher.dialogs.AddAppLauncherDialog
|
import com.simplemobiletools.applauncher.dialogs.AddAppLauncherDialog
|
||||||
|
import com.simplemobiletools.applauncher.dialogs.ChangeSortingDialog
|
||||||
import com.simplemobiletools.applauncher.extensions.config
|
import com.simplemobiletools.applauncher.extensions.config
|
||||||
import com.simplemobiletools.applauncher.extensions.dbHelper
|
import com.simplemobiletools.applauncher.extensions.dbHelper
|
||||||
import com.simplemobiletools.applauncher.extensions.getNotDisplayedLaunchers
|
import com.simplemobiletools.applauncher.extensions.getNotDisplayedLaunchers
|
||||||
@ -85,6 +86,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
|
R.id.sort -> showSortingDialog()
|
||||||
R.id.increase_column_count -> increaseColumnCount()
|
R.id.increase_column_count -> increaseColumnCount()
|
||||||
R.id.reduce_column_count -> reduceColumnCount()
|
R.id.reduce_column_count -> reduceColumnCount()
|
||||||
R.id.settings -> launchSettings()
|
R.id.settings -> launchSettings()
|
||||||
@ -148,6 +150,12 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showSortingDialog() {
|
||||||
|
ChangeSortingDialog(this) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun increaseColumnCount() {
|
private fun increaseColumnCount() {
|
||||||
config.columnCnt = ++(launchers_grid.layoutManager as MyGridLayoutManager).spanCount
|
config.columnCnt = ++(launchers_grid.layoutManager as MyGridLayoutManager).spanCount
|
||||||
columnCountChanged()
|
columnCountChanged()
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
package com.simplemobiletools.applauncher.dialogs
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import com.simplemobiletools.applauncher.R
|
||||||
|
import com.simplemobiletools.applauncher.extensions.config
|
||||||
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
|
import com.simplemobiletools.commons.extensions.beGoneIf
|
||||||
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
|
import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM
|
||||||
|
import com.simplemobiletools.commons.helpers.SORT_BY_TITLE
|
||||||
|
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||||
|
import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
|
||||||
|
|
||||||
|
class ChangeSortingDialog(val activity: BaseSimpleActivity, private val callback: () -> Unit) {
|
||||||
|
private var currSorting = 0
|
||||||
|
private var config = activity.config
|
||||||
|
private var view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null)
|
||||||
|
|
||||||
|
init {
|
||||||
|
AlertDialog.Builder(activity)
|
||||||
|
.setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() }
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.create().apply {
|
||||||
|
activity.setupDialogStuff(view, this, R.string.sort_by)
|
||||||
|
}
|
||||||
|
|
||||||
|
currSorting = config.sorting
|
||||||
|
setupSortRadio()
|
||||||
|
setupOrderRadio()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupSortRadio() {
|
||||||
|
val sortingRadio = view.sorting_dialog_radio_sorting
|
||||||
|
sortingRadio.setOnCheckedChangeListener { group, checkedId ->
|
||||||
|
val isCustomSorting = checkedId == sortingRadio.sorting_dialog_radio_custom.id
|
||||||
|
view.sorting_dialog_radio_order.beGoneIf(isCustomSorting)
|
||||||
|
view.sorting_dialog_divider.beGoneIf(isCustomSorting)
|
||||||
|
}
|
||||||
|
|
||||||
|
val sortBtn = when {
|
||||||
|
currSorting and SORT_BY_TITLE != 0 -> sortingRadio.sorting_dialog_radio_title
|
||||||
|
else -> sortingRadio.sorting_dialog_radio_custom
|
||||||
|
}
|
||||||
|
sortBtn.isChecked = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupOrderRadio() {
|
||||||
|
val orderRadio = view.sorting_dialog_radio_order
|
||||||
|
var orderBtn = orderRadio.sorting_dialog_radio_ascending
|
||||||
|
|
||||||
|
if (currSorting and SORT_DESCENDING != 0) {
|
||||||
|
orderBtn = orderRadio.sorting_dialog_radio_descending
|
||||||
|
}
|
||||||
|
orderBtn.isChecked = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun dialogConfirmed() {
|
||||||
|
val sortingRadio = view.sorting_dialog_radio_sorting
|
||||||
|
var sorting = when (sortingRadio.checkedRadioButtonId) {
|
||||||
|
R.id.sorting_dialog_radio_title -> SORT_BY_TITLE
|
||||||
|
else -> SORT_BY_CUSTOM
|
||||||
|
}
|
||||||
|
|
||||||
|
if (view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) {
|
||||||
|
sorting = sorting or SORT_DESCENDING
|
||||||
|
}
|
||||||
|
|
||||||
|
config.sorting = sorting
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}
|
68
app/src/main/res/layout/dialog_change_sorting.xml
Normal file
68
app/src/main/res/layout/dialog_change_sorting.xml
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/sorting_dialog_scrollview"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/sorting_dialog_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingStart="@dimen/activity_margin"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
android:paddingEnd="@dimen/activity_margin">
|
||||||
|
|
||||||
|
<RadioGroup
|
||||||
|
android:id="@+id/sorting_dialog_radio_sorting"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="@dimen/medium_margin">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
|
android:id="@+id/sorting_dialog_radio_title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:text="@string/title" />
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
|
android:id="@+id/sorting_dialog_radio_custom"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:text="@string/custom" />
|
||||||
|
|
||||||
|
</RadioGroup>
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/sorting_dialog_divider"
|
||||||
|
layout="@layout/divider" />
|
||||||
|
|
||||||
|
<RadioGroup
|
||||||
|
android:id="@+id/sorting_dialog_radio_order"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/medium_margin"
|
||||||
|
android:paddingBottom="@dimen/medium_margin">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
|
android:id="@+id/sorting_dialog_radio_ascending"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:text="@string/ascending" />
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
|
android:id="@+id/sorting_dialog_radio_descending"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:text="@string/descending" />
|
||||||
|
</RadioGroup>
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
@ -1,6 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<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/sort"
|
||||||
|
android:icon="@drawable/ic_sort_vector"
|
||||||
|
android:title="@string/sort_by"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/increase_column_count"
|
android:id="@+id/increase_column_count"
|
||||||
android:title="@string/increase_column_count"
|
android:title="@string/increase_column_count"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user