Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(browse): more than 2 columns #17781

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

david-allison
Copy link
Member

@david-allison david-allison commented Jan 9, 2025

Purpose / Description

Anki Desktop allows more than 2 columns in the Browse screen. Let's do the same for AnkiDroid

Fixes

⚠️ This changes the default columns, I believe to match AnkiMobile

Approach

  • Remove 'column1' and 'column2' and instead use 'availableColumns'
  • Replace column spinners with TextViews, to allow more horizontal space
  • Either modify columns from the settings, or long press a header to open the options item
  • Add a settings screen

The settings screen allows a user to reorder and 'select' usable columns

A full-screen dialog fragment with two headings: 'displayed' & 'available'
Headings are implemented as RecyclerView items, so dragging feels natural. Headings may not be dragged.

It has two primary functions:

  • Drag to reorder
  • +/- to quickly add/remove from 'displayed'

A 'preview' is obtained from the first row of the Browse window. If there are no rows, there is no preview

How Has This Been Tested?

Unit tested, and tested on an API 32 emulator

Screenshot 2025-01-09 at 20 28 34 Screenshot 2025-01-09 at 20 28 21 Screenshot 2025-01-08 at 23 32 41 Screenshot 2025-01-09 at 21 13 36 Screenshot 2025-01-09 at 21 13 46

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

Prep for a variable column count

* replace `setColumn1` with `setColumn(0`

Issue 17780
@david-allison david-allison added Anki Ecosystem Compatibility Blocked by dependency Currently blocked by some other dependent / related change labels Jan 9, 2025
Copy link
Contributor

github-actions bot commented Jan 9, 2025

Important

Maintainers: This PR contains Strings changes

  1. Sync Translations before merging this PR and wait for the action to complete
  2. Review and merge the auto-generated PR in order to sync all user-submitted translations
  3. Sync Translations again and merge the PR so the huge automated string changes caused by merging this PR are by themselves and easy to review


for (column in columnCollection.columns) {
Timber.d("setting up column %s", column)
TextView(this).apply {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want a custom layout?

Comment on lines +150 to +162
// setup back button handling
requireActivity().onBackPressedDispatcher.addCallback(onCloseDialogCallback)
requireActivity().onBackPressedDispatcher.addCallback(discardChangesCallback)

// stop the back button closing the dialog, and use the back dispatcher
this.isCancelable = false
dialog?.setOnKeyListener { _: DialogInterface?, keyCode: Int, e: KeyEvent? ->
if (keyCode == KeyEvent.KEYCODE_BACK) {
requireActivity().onBackPressedDispatcher.onBackPressed()
true
}
false
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels janky, improvements requested

Comment on lines +300 to +338
runBlocking {
var oldColumns: MutableList<CardBrowserColumn?> = mutableListOf()

// save the current columns
BrowserColumnCollection
.update(sharedPrefs(), cardsOrNotes) { cols ->
oldColumns = cols.toMutableList()
cols.clear()
cols.addAll(CardBrowserColumn.entries)
true
}?.apply {
withCol { backend.setActiveBrowserColumns(backendKeys) }
}

// obtain a sample row
sampleRow = withCol { browserRowForId(id.cardOrNoteId) }
Timber.d("got sample row")

// restore the past values
BrowserColumnCollection
.update(sharedPrefs(), cardsOrNotes) { cols ->
cols.clear()
cols.addAll(oldColumns)
true
}?.apply {
withCol { backend.setActiveBrowserColumns(backendKeys) }
}
}

return sampleRow
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't great, patches to make this more 'Kotlin' would be fantastic

Comment on lines +95 to +101
// TODO: 4, 2, 1 on other
setPaddingRelative(
start = 3.dp,
top = 1.dp,
end = 3.dp,
bottom = 1.dp,
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work, but open for review

Comment on lines +106 to +112
View(context).apply {
layoutParams =
LinearLayout.LayoutParams(
0.5.dp.toPx(context),
LinearLayout.LayoutParams.MATCH_PARENT,
)
setBackgroundResource(getResFromAttr(context, R.attr.cardBrowserDivider))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise: should these be layouts?

@david-allison

This comment was marked as resolved.

@david-allison david-allison force-pushed the card-browser-column branch 2 times, most recently from c84c591 to cc173fb Compare January 9, 2025 23:09
We introduce BrowserColumnSelectionFragment: a full screen
dialog which allows a user to select and reorder the available
columns in the Browse window

There are two headings: 'displayed' & 'available'
Headings are implemented as RecyclerView items, so dragging
feels natural. Headings may not be dragged.

It has two primary functions:
* Drag to reorder
* +/- to quickly add/remove from 'displayed'

A 'preview' is obtained from the first row of the Browse window
If there are no rows, there is no preview

Issue 17780
A user can long press the column headings
or edit them from the options to add/remove multiple columns

Issue 17780
If a user is editing options and changes 'cards/notes'
then they should be editing columns for their provided selection

If a user saves columns, then reverts the switch, columns
should not be updated

Issue 17780
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Anki Ecosystem Compatibility Blocked by dependency Currently blocked by some other dependent / related change Strings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Card Browser: Support many columns
1 participant