Skip to content

Commit 3a94228

Browse files
committed
chore: enable viewBinding
Issue 11116
1 parent 9736f8d commit 3a94228

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

AnkiDroid/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ android {
4646
buildFeatures {
4747
buildConfig = true
4848
aidl = true
49+
viewBinding = true
4950
}
5051

5152
if (rootProject.testReleaseBuild) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import androidx.fragment.app.Fragment
5252
import androidx.lifecycle.Lifecycle
5353
import androidx.lifecycle.lifecycleScope
5454
import androidx.lifecycle.repeatOnLifecycle
55+
import androidx.viewbinding.ViewBinding
5556
import com.google.android.material.color.MaterialColors
5657
import com.google.android.material.snackbar.Snackbar
5758
import com.ichi2.anim.ActivityTransitionAnimation
@@ -203,6 +204,10 @@ open class AnkiActivity :
203204
dialogHandler.executeMessage()
204205
}
205206

207+
open fun setViewBinding(binding: ViewBinding) {
208+
setContentView(binding.root)
209+
}
210+
206211
/**
207212
* Sets the title of the toolbar (support action bar) for the activity.
208213
*

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import androidx.core.view.size
4242
import androidx.drawerlayout.widget.ClosableDrawerLayout
4343
import androidx.drawerlayout.widget.DrawerLayout
4444
import androidx.fragment.app.Fragment
45+
import androidx.viewbinding.ViewBinding
4546
import com.google.android.material.color.MaterialColors
4647
import com.google.android.material.navigation.NavigationView
4748
import com.ichi2.anki.NoteEditorFragment.Companion.NoteEditorCaller
@@ -84,6 +85,31 @@ abstract class NavigationDrawerActivity :
8485
}
8586
}
8687

88+
override fun setViewBinding(binding: ViewBinding) {
89+
val preferences = baseContext.sharedPrefs()
90+
91+
// Using ClosableDrawerLayout as a parent view.
92+
val closableDrawerLayout =
93+
LayoutInflater.from(this).inflate(
94+
navigationDrawerLayout,
95+
null,
96+
false,
97+
) as ClosableDrawerLayout
98+
99+
val coordinatorLayout = binding.root
100+
if (preferences.getBoolean(FULL_SCREEN_NAVIGATION_DRAWER, false)) {
101+
// If full screen navigation drawer is needed, then add FullDraggableContainer as a child view of closableDrawerLayout.
102+
// Then add coordinatorLayout as a child view of fullDraggableContainer.
103+
val fullDraggableContainer = FullDraggableContainerFix(this)
104+
fullDraggableContainer.addView(coordinatorLayout)
105+
closableDrawerLayout.addView(fullDraggableContainer, 0)
106+
} else {
107+
// If full screen navigation drawer is not needed, then directly add coordinatorLayout as the child view.
108+
closableDrawerLayout.addView(coordinatorLayout, 0)
109+
}
110+
setContentView(closableDrawerLayout)
111+
}
112+
87113
override fun setContentView(
88114
@LayoutRes layoutResID: Int,
89115
) {

0 commit comments

Comments
 (0)