-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4bd0aa
commit 81c8f52
Showing
3 changed files
with
85 additions
and
22 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
Omega/src/com/saggitt/omega/preferences/MultiSelectTabDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters