Skip to content

Commit 2b2fa59

Browse files
committed
Refactor DeckPicker Screen to be resizable in X-Large
1 parent e6fb581 commit 2b2fa59

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ import androidx.draganddrop.DropHelper
7878
import androidx.fragment.app.commit
7979
import androidx.lifecycle.flowWithLifecycle
8080
import androidx.lifecycle.lifecycleScope
81-
import androidx.recyclerview.widget.DividerItemDecoration
8281
import androidx.recyclerview.widget.LinearLayoutManager
8382
import androidx.recyclerview.widget.RecyclerView
8483
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
@@ -160,6 +159,7 @@ import com.ichi2.anki.settings.Prefs
160159
import com.ichi2.anki.snackbar.BaseSnackbarBuilderProvider
161160
import com.ichi2.anki.snackbar.SnackbarBuilder
162161
import com.ichi2.anki.snackbar.showSnackbar
162+
import com.ichi2.anki.ui.ResizablePaneManager
163163
import com.ichi2.anki.utils.ext.dismissAllDialogFragments
164164
import com.ichi2.anki.utils.ext.setFragmentResultListener
165165
import com.ichi2.anki.utils.ext.showDialogFragment
@@ -528,6 +528,28 @@ open class DeckPicker :
528528
// Open StudyOptionsFragment if in fragmented mode
529529
if (fragmented && !startupError) {
530530
loadStudyOptionsFragment(false)
531+
532+
val resizingDivider = findViewById<View>(R.id.resizing_divider)
533+
val parentLayout = findViewById<LinearLayout>(R.id.deckpicker_xl_view)
534+
535+
// Get references to the panes
536+
val deckPickerPane = findViewById<View>(R.id.deck_picker_pane)
537+
val studyOptionsPane = findViewById<View>(R.id.studyoptions_fragment)
538+
539+
if (deckPickerPane == null || studyOptionsPane == null) {
540+
Timber.w("DeckPicker or StudyOptions pane not found. Resizing divider will not function.")
541+
} else {
542+
// Initialize the ResizablePaneManager
543+
ResizablePaneManager(
544+
parentLayout = parentLayout,
545+
divider = resizingDivider,
546+
leftPane = deckPickerPane,
547+
rightPane = studyOptionsPane,
548+
sharedPrefs = this.sharedPrefs(),
549+
leftPaneWeightKey = PREF_DECK_PICKER_PANE_WEIGHT,
550+
rightPaneWeightKey = PREF_STUDY_OPTIONS_PANE_WEIGHT,
551+
)
552+
}
531553
}
532554
registerReceiver()
533555

@@ -542,15 +564,9 @@ open class DeckPicker :
542564
deckPickerContent.visibility = View.GONE
543565
noDecksPlaceholder.visibility = View.GONE
544566

545-
// specify a LinearLayoutManager and set up item dividers for the RecyclerView
567+
// specify a LinearLayoutManager for the RecyclerView
546568
recyclerViewLayoutManager = LinearLayoutManager(this)
547569
recyclerView.layoutManager = recyclerViewLayoutManager
548-
val ta = this.obtainStyledAttributes(intArrayOf(R.attr.deckDivider))
549-
val divider = ta.getDrawable(0)
550-
ta.recycle()
551-
val dividerDecorator = DividerItemDecoration(this, recyclerViewLayoutManager.orientation)
552-
dividerDecorator.setDrawable(divider!!)
553-
recyclerView.addItemDecoration(dividerDecorator)
554570

555571
// Add background to Deckpicker activity
556572
val view = if (fragmented) findViewById(R.id.deckpicker_xl_view) else findViewById<View>(R.id.root_layout)
@@ -2565,6 +2581,9 @@ open class DeckPicker :
25652581
private const val AUTOMATIC_SYNC_MINIMAL_INTERVAL_IN_MINUTES: Long = 10
25662582
private const val SWIPE_TO_SYNC_TRIGGER_DISTANCE = 400
25672583

2584+
private const val PREF_DECK_PICKER_PANE_WEIGHT = "deckPickerPaneWeight"
2585+
private const val PREF_STUDY_OPTIONS_PANE_WEIGHT = "studyOptionsPaneWeight"
2586+
25682587
// Animation utility methods used by renderPage() method
25692588
fun fadeIn(
25702589
view: View?,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
<corners android:radius="2dp" />
5+
<solid android:color="#4D4D4D" />
6+
</shape>
7+

AnkiDroid/src/main/res/layout-xlarge/homescreen.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,25 @@
1616
android:background="?android:attr/colorBackground"
1717
android:orientation="horizontal">
1818
<include layout="@layout/deck_picker"
19+
android:id="@+id/deck_picker_pane" />
1920
android:layout_width="1dip"
2021
android:layout_weight="3"
2122
android:layout_height="match_parent"/>
23+
24+
<FrameLayout
25+
android:id="@+id/resizing_divider"
26+
android:layout_width="6dp"
27+
android:layout_height="match_parent"
28+
android:background="#B0B0B0">
29+
<View
30+
android:id="@+id/divider_handle"
31+
android:layout_width="2dp"
32+
android:layout_height="30dp"
33+
android:layout_gravity="center"
34+
android:background="@drawable/divider_handle_background"
35+
android:elevation="2dp" />
36+
</FrameLayout>
37+
2238
<androidx.fragment.app.FragmentContainerView
2339
android:id="@+id/studyoptions_fragment"
2440
android:layout_weight="2"

0 commit comments

Comments
 (0)