Skip to content

Commit

Permalink
Fix: Tabs editing from single apps
Browse files Browse the repository at this point in the history
  • Loading branch information
machiav3lli committed May 11, 2021
1 parent c4bd0aa commit 81c8f52
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 22 deletions.
73 changes: 73 additions & 0 deletions Omega/src/com/saggitt/omega/preferences/MultiSelectTabDialog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This file is part of Lawnchair Launcher.
*
* Lawnchair Launcher is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Lawnchair Launcher is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Lawnchair Launcher. If not, see <https://www.gnu.org/licenses/>.
*/

package com.saggitt.omega.preferences

import android.app.Dialog
import android.app.DialogFragment
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import com.android.launcher3.R
import com.android.launcher3.util.ComponentKey
import com.saggitt.omega.groups.DrawerTabs
import com.saggitt.omega.groups.ui.AppCategorizationFragment
import com.saggitt.omega.settings.SettingsActivity
import com.saggitt.omega.util.addOrRemove

class MultiSelectTabDialog(
context: Context,
val componentKey: ComponentKey,
val tabs: List<DrawerTabs.CustomTab>,
private val updatePref: () -> Unit
) :
DialogFragment() {

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val entries = tabs.map { it.getTitle() }.toTypedArray()
val checkedEntries = tabs.map {
// entries = entries.plus(customTab.getTitle())
// entryValues = entries.plus(customTab.getTitle())
it.contents.value().contains(componentKey)
}.toBooleanArray()

val selectedItems = checkedEntries.toMutableList()
return AlertDialog.Builder(getActivity())
.setMultiChoiceItems(
entries,
checkedEntries
) { _: DialogInterface?, index: Int, isChecked: Boolean ->
selectedItems[index] =
isChecked
}
.setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int ->
tabs.forEachIndexed { i, tab ->
tab.contents.value().addOrRemove(componentKey, selectedItems[i])
}
updatePref.invoke()
}
.setNeutralButton(R.string.tabs_manage) { _, _ ->
SettingsActivity.startFragment(
context, AppCategorizationFragment::class.java.name,
R.string.title__drawer_categorization
)
}
.setNegativeButton(android.R.string.cancel) { dialog: DialogInterface?, _: Int -> dialog?.cancel() }
.create()
}
}
33 changes: 11 additions & 22 deletions Omega/src/com/saggitt/omega/preferences/MultiSelectTabPreference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,34 @@

package com.saggitt.omega.preferences

import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import androidx.preference.MultiSelectListPreference
import androidx.preference.Preference
import com.android.launcher3.util.ComponentKey
import com.saggitt.omega.groups.DrawerTabs
import com.saggitt.omega.util.omegaPrefs

class MultiSelectTabPreference(context: Context, attrs: AttributeSet?) :
MultiSelectListPreference(context, attrs) {
Preference(context, attrs) {

lateinit var componentKey: ComponentKey
private val tabs =
lateinit var activity: Activity
private val tabs: List<DrawerTabs.CustomTab> =
context.omegaPrefs.drawerTabs.getGroups().mapNotNull { it as? DrawerTabs.CustomTab }
var edited = false
private set

init {
entries = tabs.map { it.getTitle() }.toTypedArray()
entryValues = tabs.map { it.getTitle() }.toTypedArray()
tabs.forEachIndexed { i, customTab ->
selectedItems[i] = customTab.contents.value().contains(componentKey)
setOnPreferenceClickListener {
MultiSelectTabDialog(context, componentKey, tabs) {
callChangeListener(tabs.hashCode())
}.show(activity.fragmentManager, "TABS_MULTISELECT_DIALOG")
true
}
setPositiveButtonText(android.R.string.ok)
setOnPreferenceChangeListener { _, _ ->
updateSummary()
edited = true
true
}
}
Expand All @@ -51,18 +54,4 @@ class MultiSelectTabPreference(context: Context, attrs: AttributeSet?) :
.filter { it.contents.value?.contains(componentKey) == true }
.joinToString(", ") { it.getTitle() }
}

/* TODO maybe integrate the old neutralButton at some point
override fun onPrepareDialogBuilder(builder: AlertDialog.Builder) {
super.onPrepareDialogBuilder(builder)
builder.setNeutralButton(R.string.tabs_manage) { _, _ ->
SettingsActivity.startFragment(
context,
AppCategorizationFragment::class.java.name,
R.string.title__drawer_categorization
)
}
}
*/
}
1 change: 1 addition & 0 deletions Omega/src/com/saggitt/omega/views/CustomBottomSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public void loadForApp(ItemInfo info, Runnable setForceOpen, Runnable unsetForce
screen.removePreference(mTabsPref);
} else {
mTabsPref.setComponentKey(mKey);
mTabsPref.setActivity(getActivity());
mTabsPref.updateSummary();
}

Expand Down

0 comments on commit 81c8f52

Please sign in to comment.