mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 20:03:05 +02:00
Move CustomButtonsSettingsFragment to a new file
This commit is contained in:
parent
89fcddef97
commit
1e3f04f1d7
@ -49,7 +49,6 @@ import com.ichi2.themes.Themes.setThemeLegacy
|
||||
import net.ankiweb.rsdroid.BackendFactory
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import kotlin.collections.HashSet
|
||||
|
||||
/**
|
||||
* Preferences dialog.
|
||||
@ -197,68 +196,6 @@ class Preferences : AnkiActivity() {
|
||||
// Inner classes
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class CustomButtonsSettingsFragment : SettingsFragment() {
|
||||
override val preferenceResource: Int
|
||||
get() = R.xml.preferences_custom_buttons
|
||||
override val analyticsScreenNameConstant: String
|
||||
get() = "prefs.custom_buttons"
|
||||
|
||||
override fun initSubscreen() {
|
||||
// Reset toolbar button customizations
|
||||
val resetCustomButtons = requirePreference<Preference>("reset_custom_buttons")
|
||||
resetCustomButtons.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
AnkiDroidApp.getSharedPrefs(requireContext()).edit {
|
||||
remove("customButtonUndo")
|
||||
remove("customButtonScheduleCard")
|
||||
remove("customButtonEditCard")
|
||||
remove("customButtonTags")
|
||||
remove("customButtonAddCard")
|
||||
remove("customButtonReplay")
|
||||
remove("customButtonCardInfo")
|
||||
remove("customButtonSelectTts")
|
||||
remove("customButtonDeckOptions")
|
||||
remove("customButtonMarkCard")
|
||||
remove("customButtonToggleMicToolBar")
|
||||
remove("customButtonBury")
|
||||
remove("customButtonSuspend")
|
||||
remove("customButtonFlag")
|
||||
remove("customButtonDelete")
|
||||
remove("customButtonEnableWhiteboard")
|
||||
remove("customButtonSaveWhiteboard")
|
||||
remove("customButtonWhiteboardPenColor")
|
||||
remove("customButtonClearWhiteboard")
|
||||
remove("customButtonShowHideWhiteboard")
|
||||
}
|
||||
// #9263: refresh the screen to display the changes
|
||||
refreshScreen()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
fun allKeys(): HashSet<String> {
|
||||
val allKeys = HashSet<String>()
|
||||
for (i in 0 until preferenceScreen.preferenceCount) {
|
||||
val pref = preferenceScreen.getPreference(i)
|
||||
if (pref is PreferenceCategory) {
|
||||
for (j in 0 until pref.preferenceCount) {
|
||||
allKeys.add(pref.getPreference(j).key)
|
||||
}
|
||||
} else {
|
||||
allKeys.add(pref.key)
|
||||
}
|
||||
}
|
||||
return allKeys
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getSubscreenIntent(context: Context?): Intent {
|
||||
return getSubscreenIntent(context, CustomButtonsSettingsFragment::class.java.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AdvancedStatisticsSettingsFragment : SettingsFragment() {
|
||||
override val preferenceResource: Int
|
||||
get() = R.xml.preferences_advanced_statistics
|
||||
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Brayan Oliveira <brayandso.dev@gmail.com>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.ichi2.anki.preferences
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.core.content.edit
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceCategory
|
||||
import com.ichi2.anki.AnkiDroidApp
|
||||
import com.ichi2.anki.R
|
||||
|
||||
class CustomButtonsSettingsFragment : SettingsFragment() {
|
||||
override val preferenceResource: Int
|
||||
get() = R.xml.preferences_custom_buttons
|
||||
override val analyticsScreenNameConstant: String
|
||||
get() = "prefs.custom_buttons"
|
||||
|
||||
override fun initSubscreen() {
|
||||
// Reset toolbar button customizations
|
||||
val resetCustomButtons = requirePreference<Preference>("reset_custom_buttons")
|
||||
resetCustomButtons.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
AnkiDroidApp.getSharedPrefs(requireContext()).edit {
|
||||
remove("customButtonUndo")
|
||||
remove("customButtonScheduleCard")
|
||||
remove("customButtonEditCard")
|
||||
remove("customButtonTags")
|
||||
remove("customButtonAddCard")
|
||||
remove("customButtonReplay")
|
||||
remove("customButtonCardInfo")
|
||||
remove("customButtonSelectTts")
|
||||
remove("customButtonDeckOptions")
|
||||
remove("customButtonMarkCard")
|
||||
remove("customButtonToggleMicToolBar")
|
||||
remove("customButtonBury")
|
||||
remove("customButtonSuspend")
|
||||
remove("customButtonFlag")
|
||||
remove("customButtonDelete")
|
||||
remove("customButtonEnableWhiteboard")
|
||||
remove("customButtonSaveWhiteboard")
|
||||
remove("customButtonWhiteboardPenColor")
|
||||
remove("customButtonClearWhiteboard")
|
||||
remove("customButtonShowHideWhiteboard")
|
||||
}
|
||||
// #9263: refresh the screen to display the changes
|
||||
refreshScreen()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
fun allKeys(): HashSet<String> {
|
||||
val allKeys = HashSet<String>()
|
||||
for (i in 0 until preferenceScreen.preferenceCount) {
|
||||
val pref = preferenceScreen.getPreference(i)
|
||||
if (pref is PreferenceCategory) {
|
||||
for (j in 0 until pref.preferenceCount) {
|
||||
allKeys.add(pref.getPreference(j).key)
|
||||
}
|
||||
} else {
|
||||
allKeys.add(pref.key)
|
||||
}
|
||||
}
|
||||
return allKeys
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getSubscreenIntent(context: Context?): Intent {
|
||||
return getSubscreenIntent(context, CustomButtonsSettingsFragment::class.java.name)
|
||||
}
|
||||
}
|
||||
}
|
@ -65,7 +65,7 @@
|
||||
android:summary="@string/custom_buttons_summary"
|
||||
android:title="@string/custom_buttons"
|
||||
android:key="@string/custom_buttons_link_preference"
|
||||
android:fragment="com.ichi2.anki.Preferences$CustomButtonsSettingsFragment" />
|
||||
android:fragment="com.ichi2.anki.preferences.CustomButtonsSettingsFragment" />
|
||||
<ListPreference
|
||||
android:defaultValue="0"
|
||||
android:key="@string/fullscreen_mode_preference"
|
||||
|
@ -19,18 +19,19 @@ import android.content.Context
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import com.ichi2.anki.Preferences
|
||||
import com.ichi2.anki.preferences.CustomButtonsSettingsFragment
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
object PreferenceUtils {
|
||||
@JvmStatic
|
||||
fun getAllCustomButtonKeys(context: Context?): Set<String> {
|
||||
val ret = AtomicReference<Set<String>>()
|
||||
val i = Preferences.CustomButtonsSettingsFragment.getSubscreenIntent(context)
|
||||
val i = CustomButtonsSettingsFragment.getSubscreenIntent(context)
|
||||
ActivityScenario.launch<Preferences>(i).use { scenario ->
|
||||
scenario.moveToState(Lifecycle.State.STARTED)
|
||||
scenario.onActivity { a: Preferences ->
|
||||
val customButtonsFragment = a.supportFragmentManager
|
||||
.findFragmentByTag(Preferences.CustomButtonsSettingsFragment::class.java.name) as Preferences.CustomButtonsSettingsFragment
|
||||
.findFragmentByTag(CustomButtonsSettingsFragment::class.java.name) as CustomButtonsSettingsFragment
|
||||
ret.set(customButtonsFragment.allKeys())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user