@@ -43,7 +43,6 @@ import androidx.appcompat.widget.ThemeUtils
4343import androidx.core.view.ViewCompat
4444import androidx.core.view.WindowInsetsCompat
4545import androidx.core.view.isVisible
46- import androidx.fragment.app.FragmentContainerView
4746import androidx.fragment.app.commit
4847import androidx.lifecycle.ViewModelProvider
4948import androidx.lifecycle.lifecycleScope
@@ -69,6 +68,7 @@ import com.ichi2.anki.browser.registerFindReplaceHandler
6968import com.ichi2.anki.browser.toCardBrowserLaunchOptions
7069import com.ichi2.anki.common.annotations.NeedsTest
7170import com.ichi2.anki.common.utils.annotation.KotlinCleanup
71+ import com.ichi2.anki.databinding.CardBrowserBinding
7272import com.ichi2.anki.dialogs.DeckSelectionDialog.DeckSelectionListener
7373import com.ichi2.anki.dialogs.DiscardChangesDialog
7474import com.ichi2.anki.dialogs.GradeNowDialog
@@ -146,12 +146,9 @@ open class CardBrowser :
146146
147147 lateinit var viewModel: CardBrowserViewModel
148148
149- lateinit var cardBrowserFragment : CardBrowserFragment
149+ private lateinit var binding : CardBrowserBinding
150150
151- /* *
152- * The frame containing the NoteEditor. Non null only in layout x-large.
153- */
154- private var noteEditorFrame: FragmentContainerView ? = null
151+ lateinit var cardBrowserFragment: CardBrowserFragment
155152
156153 private var actionBarTitle: TextView ? = null
157154
@@ -171,9 +168,11 @@ open class CardBrowser :
171168 }
172169
173170 // Dev option for Issue 18709
171+ // TODO: Broken currently; needs R.layout.card_browser_searchview
174172 val useSearchView: Boolean
175173 get() = Prefs .devUsingCardBrowserSearchView
176174
175+ @Suppress(" unused" )
177176 @get:LayoutRes
178177 private val layout: Int
179178 get() = if (useSearchView) R .layout.card_browser_searchview else R .layout.card_browser
@@ -299,6 +298,7 @@ open class CardBrowser :
299298 }
300299 tagsDialogFactory = TagsDialogFactory (this ).attachToActivity<TagsDialogFactory >(this )
301300 super .onCreate(savedInstanceState)
301+ binding = CardBrowserBinding .inflate(layoutInflater)
302302 if (! ensureStoragePermissions()) {
303303 return
304304 }
@@ -314,10 +314,8 @@ open class CardBrowser :
314314
315315 val launchOptions = intent?.toCardBrowserLaunchOptions() // must be called after super.onCreate()
316316
317- setContentView(layout)
318- initNavigationDrawer()
319-
320- noteEditorFrame = findViewById(R .id.note_editor_frame)
317+ setViewBinding(binding)
318+ initNavigationDrawer(findViewById(android.R .id.content))
321319
322320 /* *
323321 * Check if noteEditorFrame is not null and if its visibility is set to VISIBLE.
@@ -328,20 +326,15 @@ open class CardBrowser :
328326 val fragmented =
329327 Prefs .devIsCardBrowserFragmented &&
330328 ! useSearchView &&
331- noteEditorFrame?.visibility == View .VISIBLE
329+ binding. noteEditorFrame?.visibility == View .VISIBLE
332330 Timber .i(" Using split Browser: %b" , fragmented)
333331
334332 if (fragmented) {
335- val parentLayout = findViewById<LinearLayout >(R .id.card_browser_xl_view)
336- val divider = findViewById<View >(R .id.card_browser_resizing_divider)
337- val cardBrowserPane = findViewById<View >(R .id.card_browser_frame)
338- val noteEditorPane = findViewById<View >(R .id.note_editor_frame)
339-
340333 ResizablePaneManager (
341- parentLayout = parentLayout ,
342- divider = divider ,
343- leftPane = cardBrowserPane ,
344- rightPane = noteEditorPane ,
334+ parentLayout = requireNotNull(binding.cardBrowserXlView) ,
335+ divider = requireNotNull(binding.cardBrowserResizingDivider) ,
336+ leftPane = requireNotNull(binding.cardBrowserFrame) ,
337+ rightPane = requireNotNull(binding.noteEditorFrame) ,
345338 sharedPrefs = Prefs .getUiConfig(this ),
346339 leftPaneWeightKey = PREF_CARD_BROWSER_PANE_WEIGHT ,
347340 rightPaneWeightKey = PREF_NOTE_EDITOR_PANE_WEIGHT ,
@@ -459,7 +452,7 @@ open class CardBrowser :
459452 return
460453 }
461454 // Show note editor frame
462- noteEditorFrame!! .isVisible = true
455+ binding. noteEditorFrame!! .isVisible = true
463456
464457 // If there are unsaved changes in NoteEditor then show dialog for confirmation
465458 if (fragment?.hasUnsavedChanges() == true ) {
@@ -1174,7 +1167,7 @@ open class CardBrowser :
11741167 // Check whether deck is empty or not
11751168 val isDeckEmpty = viewModel.rowCount == 0
11761169 // Hide note editor frame if deck is empty and fragmented
1177- noteEditorFrame?.visibility =
1170+ binding. noteEditorFrame?.visibility =
11781171 if (fragmented && ! isDeckEmpty) {
11791172 viewModel.currentCardId = (viewModel.focusedRow ? : viewModel.cards[0 ]).toCardId(viewModel.cardsOrNotes)
11801173 loadNoteEditorFragmentIfFragmented()
0 commit comments