Skip to content

Commit fcd15a5

Browse files
criticalAYlukstbit
authored andcommitted
dev: add multiple profile as developer option
- enables dev option for multiple profile in dev settings - feat: created empty preference screen for multiple profile once the dev option is enabled
1 parent ad61b3a commit fcd15a5

File tree

10 files changed

+85
-0
lines changed

10 files changed

+85
-0
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/preferences/DevOptionsFragment.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ class DevOptionsFragment : SettingsFragment() {
192192
true
193193
}
194194

195+
requirePreference<Preference>(R.string.pref_enable_switch_profile_key).setOnPreferenceChangeListener { _, _ ->
196+
ActivityCompat.recreate(requireActivity())
197+
true
198+
}
199+
195200
setupWebDebugPreference()
196201
}
197202

AnkiDroid/src/main/java/com/ichi2/anki/preferences/HeaderFragment.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.google.android.material.appbar.MaterialToolbar
2727
import com.ichi2.anki.BuildConfig
2828
import com.ichi2.anki.CollectionManager.TR
2929
import com.ichi2.anki.R
30+
import com.ichi2.anki.preferences.profiles.SwitchProfilesFragment
3031
import com.ichi2.anki.preferences.reviewer.ReviewerMenuSettingsFragment
3132
import com.ichi2.anki.reviewreminders.ReviewReminderScope
3233
import com.ichi2.anki.reviewreminders.ScheduleReminders
@@ -68,6 +69,7 @@ class HeaderFragment : SettingsFragment() {
6869

6970
requirePreference<HeaderPreference>(R.string.pref_review_reminders_screen_key).isVisible = Prefs.newReviewRemindersEnabled
7071
requirePreference<HeaderPreference>(R.string.pref_notifications_screen_key).isVisible = !Prefs.newReviewRemindersEnabled
72+
requirePreference<HeaderPreference>(R.string.pref_switch_profile_screen_key).isVisible = Prefs.switchProfileEnabled
7173

7274
configureSearchBar(
7375
requireActivity() as AppCompatActivity,
@@ -253,6 +255,7 @@ class HeaderFragment : SettingsFragment() {
253255
is ReviewerOptionsFragment, is ReviewerMenuSettingsFragment -> R.string.new_reviewer_options_key
254256
is DevOptionsFragment -> R.string.pref_dev_options_screen_key
255257
is AboutFragment -> R.string.about_screen_key
258+
is SwitchProfilesFragment -> R.string.pref_switch_profile_screen_key
256259
else -> null
257260
}
258261
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2025 Ashish Yadav <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify it under
5+
* the terms of the GNU General Public License as published by the Free Software
6+
* Foundation; either version 3 of the License, or (at your option) any later
7+
* version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
10+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12+
* details.
13+
*
14+
* You should have received a copy of the GNU General Public License along with
15+
* this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.ichi2.anki.preferences.profiles
19+
20+
import androidx.fragment.app.Fragment
21+
import com.ichi2.anki.R
22+
23+
class SwitchProfilesFragment : Fragment(R.layout.fragment_switch_profiles)

AnkiDroid/src/main/java/com/ichi2/anki/settings/Prefs.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ object Prefs {
299299
val isWebDebugEnabled: Boolean
300300
get() = (getBoolean(R.string.html_javascript_debugging_key, false) || BuildConfig.DEBUG) && !isRunningAsUnitTest
301301

302+
// ************************************* Switch Profile option ********************************** //
303+
304+
/**
305+
* Whether the switch profile feature is enabled.
306+
*/
307+
val switchProfileEnabled by booleanPref(R.string.pref_enable_switch_profile_key, false)
308+
302309
// **************************************** UI Config *************************************** //
303310

304311
private const val UI_CONFIG_PREFERENCES_NAME = "ui-config"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="960"
5+
android:viewportHeight="960"
6+
android:tint="?attr/colorControlNormal">
7+
<path
8+
android:pathData="M500,478q29,-32 44.5,-73t15.5,-85q0,-44 -15.5,-85T500,162q60,8 100,53t40,105q0,60 -40,105t-100,53ZM720,800v-120q0,-36 -16,-68.5T662,554q51,18 94.5,46.5T800,680v120h-80ZM800,520v-80h-80v-80h80v-80h80v80h80v80h-80v80h-80ZM320,480q-66,0 -113,-47t-47,-113q0,-66 47,-113t113,-47q66,0 113,47t47,113q0,66 -47,113t-113,47ZM0,800v-112q0,-34 17.5,-62.5T64,582q62,-31 126,-46.5T320,520q66,0 130,15.5T576,582q29,15 46.5,43.5T640,688v112L0,800ZM320,400q33,0 56.5,-23.5T400,320q0,-33 -23.5,-56.5T320,240q-33,0 -56.5,23.5T240,320q0,33 23.5,56.5T320,400ZM80,720h480v-32q0,-11 -5.5,-20T540,654q-54,-27 -109,-40.5T320,600q-56,0 -111,13.5T100,654q-9,5 -14.5,14T80,688v32ZM320,320ZM320,720Z"
9+
android:fillColor="#ffffff"/>
10+
</vector>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
~ Copyright (c) 2025 Ashish Yadav <[email protected]>
3+
~
4+
~ This program is free software; you can redistribute it and/or modify it under
5+
~ the terms of the GNU General Public License as published by the Free Software
6+
~ Foundation; either version 3 of the License, or (at your option) any later
7+
~ version.
8+
~
9+
~ This program is distributed in the hope that it will be useful, but WITHOUT ANY
10+
~ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11+
~ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12+
~ details.
13+
~
14+
~ You should have received a copy of the GNU General Public License along with
15+
~ this program. If not, see <http://www.gnu.org/licenses/>.
16+
-->
17+
18+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
19+
android:layout_width="match_parent"
20+
android:layout_height="match_parent">
21+
22+
</androidx.constraintlayout.widget.ConstraintLayout>

AnkiDroid/src/main/res/values/preferences.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<string name="pref_backup_limits_screen_key">backupLimitsScreen</string>
3232
<!-- Editing -->
3333
<string name="paste_png_key">pastePNG</string>
34+
<!-- Switch Profile -->
35+
<string name="pref_switch_profile_screen_key">switchProfileScreen</string>
36+
<string name="pref_enable_switch_profile_key">enableSwitchProfile</string>
3437
<!-- Appearance -->
3538
<string name="pref_appearance_screen_key">appearance_preference_group</string>
3639
<string name="app_theme_key">appTheme</string>

AnkiDroid/src/main/res/xml/preference_headers.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@
8989
app:summaryEntries="@array/appearance_summary_entries">
9090
</com.ichi2.preferences.HeaderPreference>
9191

92+
<!-- Switch Profile Preferences -->
93+
<com.ichi2.preferences.HeaderPreference
94+
android:key="@string/pref_switch_profile_screen_key"
95+
android:title="Switch Profile"
96+
android:icon="@drawable/ic_switch_profile"
97+
android:fragment="com.ichi2.anki.preferences.profiles.SwitchProfilesFragment" />
98+
9299
<!-- Keybinding preferences -->
93100
<com.ichi2.preferences.HeaderPreference
94101
android:fragment="com.ichi2.anki.preferences.ControlsSettingsFragment"

AnkiDroid/src/main/res/xml/preferences_dev_options.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,9 @@
117117
android:title="Enable new notifications"
118118
android:key="@string/pref_new_review_reminders"
119119
android:defaultValue="false"/>
120+
<SwitchPreferenceCompat
121+
android:title="Switch Profile option"
122+
android:key="@string/pref_enable_switch_profile_key"
123+
android:defaultValue="false"/>
120124
</com.ichi2.anki.preferences.ExtendedPreferenceCategory>
121125
</PreferenceScreen>

AnkiDroid/src/test/java/com/ichi2/anki/analytics/PreferencesAnalyticsTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class PreferencesAnalyticsTest : RobolectricTest() {
6161
R.string.pref_review_reminders_screen_key, // reviewRemindersScreen
6262
R.string.pref_backup_limits_screen_key, // backupLimitsScreen
6363
R.string.about_screen_key, // aboutScreen
64+
R.string.pref_switch_profile_screen_key, // switchProfileScreen
6465
// Categories: don't have a value
6566
R.string.study_screen_category_key, // studyScreenAppearance
6667
R.string.pref_appearance_screen_key, // appearance_preference_group

0 commit comments

Comments
 (0)