Skip to content
Merged
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
37 changes: 15 additions & 22 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import androidx.appcompat.widget.ThemeUtils
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import androidx.fragment.app.FragmentContainerView
import androidx.fragment.app.commit
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
Expand All @@ -69,6 +68,7 @@ import com.ichi2.anki.browser.registerFindReplaceHandler
import com.ichi2.anki.browser.toCardBrowserLaunchOptions
import com.ichi2.anki.common.annotations.NeedsTest
import com.ichi2.anki.common.utils.annotation.KotlinCleanup
import com.ichi2.anki.databinding.CardBrowserBinding
import com.ichi2.anki.dialogs.DeckSelectionDialog.DeckSelectionListener
import com.ichi2.anki.dialogs.DiscardChangesDialog
import com.ichi2.anki.dialogs.GradeNowDialog
Expand Down Expand Up @@ -146,12 +146,9 @@ open class CardBrowser :

lateinit var viewModel: CardBrowserViewModel

lateinit var cardBrowserFragment: CardBrowserFragment
private lateinit var binding: CardBrowserBinding

/**
* The frame containing the NoteEditor. Non null only in layout x-large.
*/
private var noteEditorFrame: FragmentContainerView? = null
lateinit var cardBrowserFragment: CardBrowserFragment

private var actionBarTitle: TextView? = null

Expand All @@ -171,9 +168,11 @@ open class CardBrowser :
}

// Dev option for Issue 18709
// TODO: Broken currently; needs R.layout.card_browser_searchview
val useSearchView: Boolean
get() = Prefs.devUsingCardBrowserSearchView

@Suppress("unused")
@get:LayoutRes
private val layout: Int
get() = if (useSearchView) R.layout.card_browser_searchview else R.layout.card_browser
Expand Down Expand Up @@ -299,6 +298,7 @@ open class CardBrowser :
}
tagsDialogFactory = TagsDialogFactory(this).attachToActivity<TagsDialogFactory>(this)
super.onCreate(savedInstanceState)
binding = CardBrowserBinding.inflate(layoutInflater)
if (!ensureStoragePermissions()) {
return
}
Expand All @@ -314,10 +314,8 @@ open class CardBrowser :

val launchOptions = intent?.toCardBrowserLaunchOptions() // must be called after super.onCreate()

setContentView(layout)
initNavigationDrawer()

noteEditorFrame = findViewById(R.id.note_editor_frame)
setViewBinding(binding)
initNavigationDrawer(findViewById(android.R.id.content))

/**
* Check if noteEditorFrame is not null and if its visibility is set to VISIBLE.
Expand All @@ -328,20 +326,15 @@ open class CardBrowser :
val fragmented =
Prefs.devIsCardBrowserFragmented &&
!useSearchView &&
noteEditorFrame?.visibility == View.VISIBLE
binding.noteEditorFrame?.visibility == View.VISIBLE
Timber.i("Using split Browser: %b", fragmented)

if (fragmented) {
val parentLayout = findViewById<LinearLayout>(R.id.card_browser_xl_view)
val divider = findViewById<View>(R.id.card_browser_resizing_divider)
val cardBrowserPane = findViewById<View>(R.id.card_browser_frame)
val noteEditorPane = findViewById<View>(R.id.note_editor_frame)

ResizablePaneManager(
parentLayout = parentLayout,
divider = divider,
leftPane = cardBrowserPane,
rightPane = noteEditorPane,
parentLayout = requireNotNull(binding.cardBrowserXlView),
divider = requireNotNull(binding.cardBrowserResizingDivider),
leftPane = requireNotNull(binding.cardBrowserFrame),
rightPane = requireNotNull(binding.noteEditorFrame),
sharedPrefs = Prefs.getUiConfig(this),
leftPaneWeightKey = PREF_CARD_BROWSER_PANE_WEIGHT,
rightPaneWeightKey = PREF_NOTE_EDITOR_PANE_WEIGHT,
Expand Down Expand Up @@ -459,7 +452,7 @@ open class CardBrowser :
return
}
// Show note editor frame
noteEditorFrame!!.isVisible = true
binding.noteEditorFrame!!.isVisible = true

// If there are unsaved changes in NoteEditor then show dialog for confirmation
if (fragment?.hasUnsavedChanges() == true) {
Expand Down Expand Up @@ -1172,7 +1165,7 @@ open class CardBrowser :
// Check whether deck is empty or not
val isDeckEmpty = viewModel.rowCount == 0
// Hide note editor frame if deck is empty and fragmented
noteEditorFrame?.visibility =
binding.noteEditorFrame?.visibility =
if (fragmented && !isDeckEmpty) {
viewModel.currentCardId = (viewModel.focusedRow ?: viewModel.cards[0]).toCardId(viewModel.cardsOrNotes)
loadNoteEditorFragmentIfFragmented()
Expand Down