Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ import com.ichi2.anki.utils.ShortcutUtils
import com.ichi2.anki.utils.ext.dismissAllDialogFragments
import com.ichi2.anki.utils.ext.getSizeOfBitmapFromCollection
import com.ichi2.anki.utils.ext.launchCollectionInLifecycleScope
import com.ichi2.anki.utils.ext.positionIsVisible
import com.ichi2.anki.utils.ext.setFragmentResultListener
import com.ichi2.anki.utils.ext.showDialogFragment
import com.ichi2.anki.utils.runWithOOMCheck
Expand Down Expand Up @@ -784,6 +785,12 @@ open class DeckPicker :

fun onFocusedDeckChanged(deckId: DeckId?) {
val position = deckId?.let { viewModel.findDeckPosition(it) } ?: 0

// Skip centering if the deck is already on screen.
// Scrolling during a tap animation causes deck labels to overlap on older devices.
if (decksLayoutManager.positionIsVisible(position)) {
return
}
// HACK: a small delay is required before scrolling works
deckPickerBinding.decks.postDelayed({
decksLayoutManager.scrollToPositionWithOffset(position, deckPickerBinding.decks.height / 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ val LinearLayoutManager.visibleItemPositions: IntRange
}
return first..last
}

/**
* Returns true if the position is currently visible.
*/
fun LinearLayoutManager.positionIsVisible(position: Int): Boolean = position in visibleItemPositions
Loading