Skip to content

Commit 129a548

Browse files
committed
feat(card-browser): add a chip to select sort order
Part of 18709
1 parent 2f532b6 commit 129a548

5 files changed

Lines changed: 28 additions & 2 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ class CardBrowserFragment :
206206
private val useNewTaggingLogic get() = tagsChip != null
207207
private var cardStateChip: Chip? = null
208208
private var flagsChip: Chip? = null
209+
private var sortChip: Chip? = null
209210

210211
// region legacy menu handling
211212
var mySearchesItem: MenuItem? = null
@@ -302,6 +303,10 @@ class CardBrowserFragment :
302303
}
303304
}
304305
}
306+
sortChip =
307+
view.findViewById<Chip>(R.id.sort_chip)?.apply {
308+
setOnClickListener { changeDisplayOrder() }
309+
}
305310
searchBar =
306311
view.findViewById<SearchBar>(R.id.search_bar)?.apply {
307312
setNavigationOnClickListener {
@@ -756,6 +761,8 @@ class CardBrowserFragment :
756761
menu.findItem(R.id.action_show_marked)?.isVisible = false
757762
menu.findItem(R.id.action_show_suspended)?.isVisible = false
758763
menu.findItem(R.id.action_search_by_flag)?.isVisible = false
764+
menu.findItem(R.id.action_show_suspended)?.isVisible = false
765+
menu.findItem(R.id.action_sort_by_size)?.isVisible = false
759766
}
760767
}
761768

@@ -969,6 +976,11 @@ class CardBrowserFragment :
969976
searchViewModel.syncState(search)
970977
}
971978

979+
fun reverseDirectionChanged(direction: ReverseDirection) {
980+
sortChip?.scaleY = if (!direction.orderAsc) 1.0f else -1.0f
981+
}
982+
983+
activityViewModel.reverseDirectionFlow.launchCollectionInLifecycleScope(::reverseDirectionChanged)
972984
activityViewModel.flowOfIsTruncated.launchCollectionInLifecycleScope(::onIsTruncatedChanged)
973985
activityViewModel.flowOfSelectedRows.launchCollectionInLifecycleScope(::onSelectedRowsChanged)
974986
activityViewModel.flowOfActiveColumns.launchCollectionInLifecycleScope(::onColumnsChanged)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class CardBrowserViewModel(
199199
private val sortTypeFlow = MutableStateFlow(SortType.NO_SORTING)
200200
val order get() = sortTypeFlow.value
201201

202-
private val reverseDirectionFlow = MutableStateFlow(ReverseDirection(orderAsc = false))
202+
val reverseDirectionFlow = MutableStateFlow(ReverseDirection(orderAsc = false))
203203
val orderAsc get() = reverseDirectionFlow.value.orderAsc
204204

205205
/**
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="?attr/colorControlNormal" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M3,18h6v-2L3,16v2zM3,6v2h18L21,6L3,6zM3,13h12v-2L3,11v2z"/>
4+
5+
</vector>

AnkiDroid/src/main/res/layout/card_browser_searchview_fragment.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@
7373
<com.google.android.material.chip.ChipGroup
7474
android:layout_width="match_parent"
7575
android:layout_height="wrap_content">
76+
77+
<com.google.android.material.chip.Chip
78+
android:id="@+id/sort_chip"
79+
android:layout_width="36dp"
80+
android:layout_height="wrap_content"
81+
app:chipStartPadding="8dp"
82+
app:chipIconSize="22dp"
83+
app:chipIcon="@drawable/ic_sort_24" />
84+
7685
<com.google.android.material.chip.Chip
7786
android:id="@+id/decks_chip"
7887
android:layout_width="wrap_content"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ class CardBrowserTest : RobolectricTest() {
15911591
R.id.action_search to false,
15921592
R.id.action_save_search to false,
15931593
R.id.action_list_my_searches to false,
1594-
R.id.action_sort_by_size to true,
1594+
R.id.action_sort_by_size to false,
15951595
R.id.action_show_marked to false,
15961596
R.id.action_show_suspended to false,
15971597
R.id.action_search_by_tag to false,

0 commit comments

Comments
 (0)