Skip to content

Commit 94a42e3

Browse files
committed
feat(card-browser): show 'preview' before 'add' in new UI
'add' only appears if there are 0 cards selected so preview is hidden From a review comment on 20454
1 parent 96c5860 commit 94a42e3

5 files changed

Lines changed: 13 additions & 3 deletions

File tree

AnkiDroid/src/main/java/com/ichi2/anki/browser/CardBrowserFragment.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,16 @@ class CardBrowserFragment :
762762
viewLifecycleOwner,
763763
)
764764

765+
// searchview specific logic
765766
menuHost.addPrepareMenuProvider { menu ->
766767
if (!useSearchView) return@addPrepareMenuProvider
768+
769+
// reorder 'preview' to appear before 'add'
770+
val preview = menu.findItem(R.id.action_preview_many)
771+
if (activityViewModel.cards.size > 0) {
772+
preview?.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
773+
}
774+
767775
menu.findItem(R.id.action_search)?.isVisible = false
768776
menu.findItem(R.id.action_list_my_searches)?.isVisible = false
769777
menu.findItem(R.id.action_save_search)?.isVisible = false

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<vector android:height="24dp" android:tint="#FFFFFF"
1+
<vector android:height="24dp" android:tint="?attr/colorControlNormal"
22
android:viewportHeight="24.0" android:viewportWidth="24.0"
33
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
44
<path android:fillColor="#FF000000" android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"/>

AnkiDroid/src/main/res/menu/card_browser.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
<item
5555
android:id="@+id/action_preview_many"
56+
android:icon="@drawable/ic_remove_red_eye_white"
5657
android:title="@string/card_editor_preview_card"/>
5758

5859
<item

AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,6 @@ class CardBrowserTest : RobolectricTest() {
17691769
}
17701770

17711771
@Test
1772-
@Ignore("pending PR 20454")
17731772
fun `options menu - new ui - no notes`() =
17741773
withOptionsMenu(
17751774
OptionsMenuType(
@@ -1802,7 +1801,6 @@ class CardBrowserTest : RobolectricTest() {
18021801
}
18031802

18041803
@Test
1805-
@Ignore("pending PR 20454")
18061804
fun `options menu - new ui - add is first if no results`() =
18071805
withOptionsMenu(
18081806
OptionsMenuType(

AnkiDroid/src/test/java/com/ichi2/anki/RobolectricTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import android.app.Application
2222
import android.content.Context
2323
import android.content.Intent
2424
import android.content.SharedPreferences
25+
import android.content.res.Resources
2526
import android.os.Looper
2627
import android.widget.TextView
2728
import androidx.annotation.CallSuper
@@ -300,6 +301,8 @@ open class RobolectricTest :
300301
val targetContext: Context
301302
get() = ApplicationProvider.getApplicationContext()
302303

304+
val resources: Resources get() = targetContext.resources
305+
303306
/**
304307
* Returns an instance of [SharedPreferences] using the test context
305308
* @see [editPreferences] for editing

0 commit comments

Comments
 (0)