Skip to content

Commit 8bd5876

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 9cf5d61 commit 8bd5876

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
@@ -758,8 +758,16 @@ class CardBrowserFragment :
758758
viewLifecycleOwner,
759759
)
760760

761+
// searchview specific logic
761762
menuHost.addPrepareMenuProvider { menu ->
762763
if (!useSearchView) return@addPrepareMenuProvider
764+
765+
// reorder 'preview' to appear before 'add'
766+
val preview = menu.findItem(R.id.action_preview_many)
767+
if (activityViewModel.cards.size > 0) {
768+
preview?.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
769+
}
770+
763771
menu.findItem(R.id.action_search)?.isVisible = false
764772
menu.findItem(R.id.action_list_my_searches)?.isVisible = false
765773
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
@@ -1745,7 +1745,6 @@ class CardBrowserTest : RobolectricTest() {
17451745
}
17461746

17471747
@Test
1748-
@Ignore("pending PR 20454")
17491748
fun `options menu - new ui - no notes`() =
17501749
withOptionsMenu(
17511750
OptionsMenuType(
@@ -1778,7 +1777,6 @@ class CardBrowserTest : RobolectricTest() {
17781777
}
17791778

17801779
@Test
1781-
@Ignore("pending PR 20454")
17821780
fun `options menu - new ui - add is first if no results`() =
17831781
withOptionsMenu(
17841782
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
@@ -309,6 +310,8 @@ open class RobolectricTest :
309310
val targetContext: Context
310311
get() = ApplicationProvider.getApplicationContext()
311312

313+
val resources: Resources get() = targetContext.resources
314+
312315
/**
313316
* Returns an instance of [SharedPreferences] using the test context
314317
* @see [editPreferences] for editing

0 commit comments

Comments
 (0)