mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 07:16:04 -04:00
#2227 added lazyView delegate in custom
This commit is contained in:
parent
9061269aaa
commit
0545f1df1e
@ -18,6 +18,9 @@
|
||||
|
||||
package org.kiwix.kiwixmobile.custom
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.View
|
||||
import androidx.annotation.IdRes
|
||||
import org.kiwix.kiwixmobile.core.base.BaseActivity
|
||||
import org.kiwix.kiwixmobile.custom.di.CustomComponent
|
||||
|
||||
@ -33,3 +36,5 @@ private fun BaseActivity.customApp() = applicationContext as? CustomApp ?: appli
|
||||
|
||||
internal inline val BaseActivity.customActivityComponent
|
||||
get() = customComponent.activityComponentBuilder().activity(this).build()
|
||||
|
||||
fun <T : View> Activity.lazyView(@IdRes viewId: Int): Lazy<T> = lazy { findViewById<T>(viewId) }
|
||||
|
@ -29,12 +29,16 @@ import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
||||
import org.kiwix.kiwixmobile.core.utils.REQUEST_PREFERENCES
|
||||
import org.kiwix.kiwixmobile.custom.R
|
||||
import org.kiwix.kiwixmobile.custom.customActivityComponent
|
||||
import org.kiwix.kiwixmobile.custom.lazyView
|
||||
import org.kiwix.kiwixmobile.custom.settings.CustomSettingsActivity
|
||||
|
||||
const val REQUEST_READ_FOR_OBB = 5002
|
||||
|
||||
class CustomMainActivity : CoreMainActivity() {
|
||||
|
||||
private val drawerNavView: NavigationView by lazyView(R.id.drawer_nav_view)
|
||||
private val drawerContainer: DrawerLayout by lazyView(R.id.custom_drawer_container)
|
||||
|
||||
override fun injection(coreComponent: CoreComponent) {
|
||||
customActivityComponent.inject(this)
|
||||
}
|
||||
@ -54,31 +58,23 @@ class CustomMainActivity : CoreMainActivity() {
|
||||
drawerToggle =
|
||||
ActionBarDrawerToggle(
|
||||
this,
|
||||
findViewById(R.id.custom_drawer_container),
|
||||
drawerContainer,
|
||||
toolbar,
|
||||
R.string.open,
|
||||
R.string.close_all_tabs
|
||||
)
|
||||
findViewById<DrawerLayout>(R.id.custom_drawer_container).addDrawerListener(drawerToggle)
|
||||
drawerContainer.addDrawerListener(drawerToggle)
|
||||
drawerToggle.syncState()
|
||||
findViewById<NavigationView>(R.id.drawer_nav_view).setNavigationItemSelectedListener(this)
|
||||
findViewById<NavigationView>(R.id.drawer_nav_view).menu.findItem(R.id.menu_host_books)
|
||||
drawerNavView.setNavigationItemSelectedListener(this)
|
||||
drawerNavView.menu.findItem(R.id.menu_host_books)
|
||||
.isVisible = false
|
||||
}
|
||||
|
||||
override fun navigationDrawerIsOpen(): Boolean =
|
||||
findViewById<DrawerLayout>(R.id.custom_drawer_container).isDrawerOpen(
|
||||
findViewById<NavigationView>(
|
||||
R.id.drawer_nav_view
|
||||
)
|
||||
)
|
||||
drawerContainer.isDrawerOpen(drawerNavView)
|
||||
|
||||
override fun closeNavigationDrawer() {
|
||||
findViewById<DrawerLayout>(R.id.custom_drawer_container).closeDrawer(
|
||||
findViewById<NavigationView>(
|
||||
R.id.drawer_nav_view
|
||||
)
|
||||
)
|
||||
drawerContainer.closeDrawer(drawerNavView)
|
||||
}
|
||||
|
||||
override fun openSettingsActivity() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user