Skip to content

Commit

Permalink
DA: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
david-allison committed Jan 13, 2025
1 parent 230336f commit 05d7e71
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 11 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ open class CardBrowser :
* Provides an instance of NoteEditorLauncher for editing a note
*/
private val editNoteLauncher: NoteEditorLauncher
get() = NoteEditorLauncher.EditCard(currentCardId, Direction.DEFAULT, fragmented)
get() =
NoteEditorLauncher.EditCard(currentCardId, Direction.DEFAULT, fragmented).also {
Timber.i("editNoteLauncher: %s", it)
}

override fun onDeckSelected(deck: SelectableDeck?) {
deck?.let {
Expand Down Expand Up @@ -426,7 +429,10 @@ open class CardBrowser :
* If both conditions are true, assign true to the variable [fragmented], otherwise assign false.
* [fragmented] will be true if the view size is large otherwise false
*/
fragmented = noteEditorFrame?.visibility == View.VISIBLE
fragmented =
(noteEditorFrame?.visibility == View.VISIBLE).apply {
Timber.i("Using split Browser: %b", this)
}

// initialize the lateinit variables
// Load reference to action bar title
Expand Down Expand Up @@ -1833,7 +1839,9 @@ open class CardBrowser :
// Hide note editor frame if deck is empty and fragmented
noteEditorFrame?.visibility =
if (fragmented && !isDeckEmpty) {
currentCardId = cardsAdapter.focusedRow?.toCardId(viewModel.cardsOrNotes) ?: 0
currentCardId =
(cardsAdapter.focusedRow ?: viewModel.cards[0])
.toCardId(viewModel.cardsOrNotes)
loadNoteEditorFragmentIfFragmented(editNoteLauncher)
View.VISIBLE
} else {
Expand Down
8 changes: 5 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ class NoteEditor :
* Whether this is displayed in a fragment view.
* If true, this fragment is on the trailing side of the card browser.
*/
private var inFragmentedActivity = false
private val inFragmentedActivity
get() = requireArguments().getBoolean(IN_FRAGMENTED_ACTIVITY)

private val requestAddLauncher =
registerForActivityResult(
Expand Down Expand Up @@ -525,8 +526,6 @@ class NoteEditor :
@Suppress("deprecation", "API35 properly handle edge-to-edge")
requireActivity().window.statusBarColor = Themes.getColorFromAttr(requireContext(), R.attr.appBarColor)
super.onViewCreated(view, savedInstanceState)
// Retrieve the boolean argument "inFragmentedActivity" from the fragment's arguments bundle
inFragmentedActivity = requireArguments().getBoolean(IN_FRAGMENTED_ACTIVITY)
// Set up toolbar
toolbar = view.findViewById(R.id.editor_toolbar)
toolbar.apply {
Expand Down Expand Up @@ -1606,9 +1605,12 @@ class NoteEditor :

// Don't close this fragment if it is in fragmented activity
if (inFragmentedActivity) {
Timber.i("not closing activity: fragmented")
return
}

Timber.i("Closing note editor")

// Set the finish animation if there is one on the intent which created the activity
val animation =
BundleCompat.getParcelable(
Expand Down

0 comments on commit 05d7e71

Please sign in to comment.