Skip to content

Commit ba6fffe

Browse files
authored
Merge branch 'ankidroid:main' into setup-codeql
2 parents 46198cd + 65d0568 commit ba6fffe

8 files changed

Lines changed: 76 additions & 2 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2025 Brayan Oliveira <69634269+brayandso@users.noreply.github.com>
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 FOR A
11+
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
package com.ichi2.anki.pages
17+
18+
import android.content.Context
19+
import android.content.Intent
20+
import com.ichi2.anki.utils.Destination
21+
22+
class StatisticsDestination : Destination {
23+
override fun toIntent(context: Context): Intent = PageFragment.getIntent(context, "graphs", null, Statistics::class)
24+
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.ichi2.anki.CollectionManager.TR
2525
import com.ichi2.anki.R
2626
import com.ichi2.anki.cardviewer.ViewerCommand
2727
import com.ichi2.anki.common.annotations.NeedsTest
28+
import com.ichi2.anki.preferences.reviewer.ViewerAction
2829
import com.ichi2.anki.previewer.PreviewerAction
2930
import com.ichi2.anki.reviewer.MappableAction
3031
import com.ichi2.anki.reviewer.MappableBinding.Companion.toPreferenceString
@@ -135,6 +136,20 @@ class ControlsSettingsFragment :
135136
val key = getString(keyRes)
136137
findPreference<Preference>(key)?.isVisible = false
137138
}
139+
requirePreference<ControlPreference>(R.string.browse_command_key).apply {
140+
title = TR.qtMiscBrowse()
141+
isVisible = true
142+
if (value == null) {
143+
value = ViewerAction.BROWSE.getBindings(sharedPrefs()).toPreferenceString()
144+
}
145+
}
146+
requirePreference<ControlPreference>(R.string.statistics_command_key).apply {
147+
title = TR.statisticsTitle()
148+
isVisible = true
149+
if (value == null) {
150+
value = ViewerAction.STATISTICS.getBindings(sharedPrefs()).toPreferenceString()
151+
}
152+
}
138153
}
139154

140155
companion object {

AnkiDroid/src/main/java/com/ichi2/anki/preferences/reviewer/ViewerAction.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ enum class ViewerAction(
6464
DELETE(R.id.action_delete, R.drawable.ic_delete_white, R.string.menu_delete_note, MENU_ONLY),
6565

6666
// Disabled
67+
BROWSE(R.id.action_browse, R.drawable.ic_flashcard_black, R.string.empty_string, DISABLED),
68+
STATISTICS(R.id.action_statistics, R.drawable.ic_bar_chart_black, R.string.empty_string, DISABLED),
6769
DECK_OPTIONS(R.id.action_deck_options, R.drawable.ic_tune_white, R.string.menu__deck_options, DISABLED),
6870
CARD_INFO(R.id.action_card_info, R.drawable.ic_dialog_info, R.string.card_info_title, DISABLED),
6971
ADD_NOTE(R.id.action_add_note, R.drawable.ic_add, R.string.menu_add_note, DISABLED),
@@ -137,6 +139,8 @@ enum class ViewerAction(
137139
SHOW_ALL_HINTS -> listOf(keycode(KeyEvent.KEYCODE_G))
138140
RECORD_VOICE -> listOf(keycode(KeyEvent.KEYCODE_V, shift()))
139141
REPLAY_VOICE -> listOf(keycode(KeyEvent.KEYCODE_V))
142+
BROWSE -> listOf(keycode(KeyEvent.KEYCODE_B))
143+
STATISTICS -> listOf(keycode(KeyEvent.KEYCODE_T))
140144
TOGGLE_FLAG_RED ->
141145
listOf(
142146
keycode(KeyEvent.KEYCODE_1, ctrl()),
@@ -237,6 +241,8 @@ enum class ViewerAction(
237241

238242
fun title(context: Context): String =
239243
when (this) {
244+
BROWSE -> TR.qtMiscBrowse()
245+
STATISTICS -> TR.statisticsTitle()
240246
RESCHEDULE_NOTE -> TR.actionsSetDueDate().toSentenceCase(context, R.string.sentence_set_due_date)
241247
else -> context.getString(titleRes)
242248
}

AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.ichi2.anki.CollectionManager.withCol
2626
import com.ichi2.anki.Flag
2727
import com.ichi2.anki.Reviewer
2828
import com.ichi2.anki.asyncIO
29+
import com.ichi2.anki.browser.BrowserDestination
2930
import com.ichi2.anki.common.time.TimeManager
3031
import com.ichi2.anki.launchCatchingIO
3132
import com.ichi2.anki.libanki.Card
@@ -44,6 +45,7 @@ import com.ichi2.anki.observability.undoableOp
4445
import com.ichi2.anki.pages.AnkiServer
4546
import com.ichi2.anki.pages.CardInfoDestination
4647
import com.ichi2.anki.pages.DeckOptionsDestination
48+
import com.ichi2.anki.pages.StatisticsDestination
4749
import com.ichi2.anki.preferences.reviewer.ViewerAction
4850
import com.ichi2.anki.previewer.CardViewerViewModel
4951
import com.ichi2.anki.previewer.TypeAnswer
@@ -254,6 +256,13 @@ class ReviewerViewModel :
254256
destinationFlow.emit(destination)
255257
}
256258

259+
private suspend fun emitBrowseDestination() {
260+
val deckId = withCol { decks.getCurrentId() }
261+
val destination = BrowserDestination(deckId)
262+
Timber.i("Launching 'browse options' for deck %d", deckId)
263+
destinationFlow.emit(destination)
264+
}
265+
257266
private suspend fun deleteNote() {
258267
val cardId = currentCard.await().id
259268
val noteCount =
@@ -672,6 +681,8 @@ class ReviewerViewModel :
672681
ViewerAction.USER_ACTION_9 -> userAction(9)
673682
ViewerAction.SUSPEND_MENU -> suspendCard()
674683
ViewerAction.BURY_MENU -> buryCard()
684+
ViewerAction.STATISTICS -> destinationFlow.emit(StatisticsDestination())
685+
ViewerAction.BROWSE -> emitBrowseDestination()
675686
ViewerAction.FLAG_MENU -> {}
676687
}
677688
}

AnkiDroid/src/main/res/drawable/ic_bar_chart_black.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
android:width="24dp"
2424
android:height="24dp"
2525
android:viewportWidth="24"
26-
android:viewportHeight="24">
26+
android:viewportHeight="24"
27+
android:tint="?colorControlNormal"
28+
>
2729
<path
28-
android:fillColor="#FF000000"
30+
android:fillColor="#FFFFFF"
2931
android:pathData="M5,13.2h3L8,19L5,19zM10.6,5h2.8v14h-2.8zM16.2,9L19,9v10h-2.8z"/>
3032
</vector>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
<item type="id" name="action_toggle_auto_advance"/>
4242
<item type="id" name="action_record_voice"/>
4343
<item type="id" name="action_set_due_date"/>
44+
<item type="id" name="action_browse"/>
45+
<item type="id" name="action_statistics"/>
4446

4547
<item type="id" name="user_action_1"/>
4648
<item type="id" name="user_action_2"/>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@
122122
<string name="remove_flag_command_key">binding_UNSET_FLAG</string>
123123
<string name="page_up_command_key">binding_PAGE_UP</string>
124124
<string name="page_down_command_key">binding_PAGE_DOWN</string>
125+
<string name="browse_command_key">binding_BROWSE</string>
126+
<string name="statistics_command_key">binding_STATISTICS</string>
125127
<string name="tag_command_key">binding_TAG</string>
126128
<string name="card_info_command_key">binding_CARD_INFO</string>
127129
<string name="record_voice_command_key">binding_RECORD_VOICE</string>

AnkiDroid/src/main/res/xml/preferences_reviewer_controls.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@
148148
android:title="@string/gesture_page_down"
149149
android:icon="@drawable/ic_double_arrow_down"
150150
/>
151+
<com.ichi2.preferences.ReviewerControlPreference
152+
android:key="@string/browse_command_key"
153+
android:icon="@drawable/ic_flashcard_black"
154+
app:isPreferenceVisible="false"
155+
tools:title="Browse"
156+
/>
157+
<com.ichi2.preferences.ReviewerControlPreference
158+
android:key="@string/statistics_command_key"
159+
android:icon="@drawable/ic_bar_chart_black"
160+
app:isPreferenceVisible="false"
161+
tools:title="Statistics"
162+
/>
151163
<com.ichi2.preferences.ReviewerControlPreference
152164
android:key="@string/abort_command_key"
153165
android:title="@string/gesture_abort_learning"

0 commit comments

Comments
 (0)