0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 20:03:05 +02:00

[GSoC] Add Use new backend (persistent) preference (#11977)

* Add `Use the new backend` (persistent) preference
And remove the old temporary "Use V16 backend" preference
* Add a stronger warning before changing to the new backend
This commit is contained in:
Brayan Oliveira 2022-08-11 13:45:18 -03:00 committed by GitHub
parent 7283426dec
commit 1c87ec046c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 18 deletions

View File

@ -173,6 +173,15 @@ public class AnkiDroidApp extends Application {
// Get preferences
SharedPreferences preferences = getSharedPrefs(this);
// TODO remove the following if-block once AnkiDroid uses the new schema by default
if (BuildConfig.LEGACY_SCHEMA) {
boolean isNewSchemaEnabledByPref = preferences.getBoolean(getString(R.string.pref_rust_backend_key), false);
if (isNewSchemaEnabledByPref) {
Timber.i("New schema enabled by preference");
BackendFactory.setDefaultLegacySchema(false);
}
}
CrashReportService.initialize(this);
if (BuildConfig.DEBUG) {

View File

@ -22,6 +22,7 @@ import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import androidx.annotation.StringRes
import androidx.preference.EditTextPreference
import androidx.preference.Preference
import androidx.preference.SwitchPreference
@ -30,6 +31,7 @@ import com.ichi2.anki.*
import com.ichi2.anki.exception.StorageAccessException
import com.ichi2.anki.provider.CardContentProvider
import com.ichi2.compat.CompatHelper
import net.ankiweb.rsdroid.BackendFactory
import timber.log.Timber
class AdvancedSettingsFragment : SettingsFragment() {
@ -110,6 +112,45 @@ class AdvancedSettingsFragment : SettingsFragment() {
}
requireActivity().packageManager.setComponentEnabledSetting(providerName, state, PackageManager.DONT_KILL_APP)
}
// Use V16 backend
requirePreference<SwitchPreference>(R.string.pref_rust_backend_key).apply {
if (!BuildConfig.LEGACY_SCHEMA) {
title = "New schema already enabled on local.properties"
isEnabled = false
}
setOnPreferenceChangeListener { newValue ->
if (newValue == true) {
confirmExperimentalChange(
R.string.use_rust_backend_title,
R.string.use_rust_backend_warning,
onCancel = { isChecked = false },
onConfirm = {
BackendFactory.defaultLegacySchema = false
(requireActivity() as Preferences).restartWithNewDeckPicker()
}
)
} else {
BackendFactory.defaultLegacySchema = true
(requireActivity() as Preferences).restartWithNewDeckPicker()
}
}
}
}
/**
* Shows a dialog to confirm if the user wants to enable an experimental preference
*/
private fun confirmExperimentalChange(@StringRes prefTitle: Int, @StringRes message: Int? = null, onCancel: () -> Unit, onConfirm: () -> Unit) {
val prefTitleString = getString(prefTitle)
val dialogTitle = getString(R.string.experimental_pref_confirmation, prefTitleString)
MaterialDialog(requireContext()).show {
title(text = dialogTitle)
message(message)
positiveButton(R.string.dialog_ok) { onConfirm() }
negativeButton(R.string.dialog_cancel) { onCancel() }
cancelOnTouchOutside(false) // to avoid `onCancel` not being triggered on outside cancels
}
}
private fun removeUnnecessaryAdvancedPrefs() {

View File

@ -22,7 +22,6 @@ import androidx.preference.SwitchPreference
import com.afollestad.materialdialogs.MaterialDialog
import com.ichi2.anki.*
import com.ichi2.anki.analytics.UsageAnalytics
import net.ankiweb.rsdroid.BackendFactory
import timber.log.Timber
/**
@ -74,15 +73,6 @@ class DevOptionsFragment : SettingsFragment() {
OnboardingUtils.reset(requireContext())
true
}
// Use V16 Backend
requirePreference<Preference>(getString(R.string.pref_rust_backend_key)).apply {
setDefaultValue(!BackendFactory.defaultLegacySchema)
setOnPreferenceClickListener {
BackendFactory.defaultLegacySchema = false
(requireActivity() as Preferences).restartWithNewDeckPicker()
true
}
}
// Use scoped storage
requirePreference<Preference>(getString(R.string.pref_scoped_storage_key)).apply {
setDefaultValue(AnkiDroidApp.TESTING_SCOPED_STORAGE)

View File

@ -333,6 +333,13 @@ this formatter is used if the bind only applies to both the question and the ans
Keys cannot be translated yet.">Remove %s</string>
<string name="bindings_already_bound">Already bound to %s</string>
<!-- Advanced -->
<string name="pref_cat_experimental" maxLength="41">Experimental</string>
<string name="experimental_pref_confirmation" maxLength="41">Enable %s</string>
<string name="use_rust_backend_title" maxLength="41">Use the new backend</string>
<string name="use_rust_backend_summary">Enables newer Anki features, such as the v3 scheduler\nUNSTABLE. Do not use on a collection you care about. NOT reverted on app close</string>
<string name="use_rust_backend_warning">There is a chance this could corrupt your installation completely, requiring app uninstall and deletion of the AnkiDroid folder, and has a chance of propagating corruption via sync to AnkiWeb.\n\nWe welcome the testing, but please make sure you have a valid non-AnkiWeb backup.</string>
<!-- Developer options -->
<string name="pref_cat_dev_options" maxLength="41">Developer options</string>
<string name="dev_options_enabled_pref" maxLength="41">Enable developer options</string>

View File

@ -147,4 +147,12 @@
android:title="@string/thirdparty_apps_title">
</Preference>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_cat_experimental">
<SwitchPreference
android:key="@string/pref_rust_backend_key"
android:title="@string/use_rust_backend_title"
android:summary="@string/use_rust_backend_summary"
android:defaultValue="false"/>
</PreferenceCategory>
</PreferenceScreen>

View File

@ -46,16 +46,12 @@
android:summary="@string/show_onboarding_desc"
android:key="@string/pref_show_onboarding_key"
android:defaultValue="false"/>
<Preference
android:title="@string/reset_onboarding"
android:summary="@string/reset_onboarding_desc"
android:key="@string/pref_reset_onboarding_key"/>
<Preference
android:title="Use V16 Backend"
android:summary="UNSTABLE. DO NOT USE ON A COLLECTION YOU CARE ABOUT. REVERTED ON APP CLOSE"
android:key="@string/pref_rust_backend_key"/>
<Preference
android:title="Enable Scoped Storage"
android:summary="UNSTABLE. DO NOT USE ON A COLLECTION YOU CARE ABOUT. REVERTED ON APP CLOSE"
android:key="@string/pref_scoped_storage_key"/>
<Preference
android:title="@string/reset_onboarding"
android:summary="@string/reset_onboarding_desc"
android:key="@string/pref_reset_onboarding_key"/>
</PreferenceScreen>