diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/ActivityExtensions.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/ActivityExtensions.kt index 42ef9e1c5..dfee848f4 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/ActivityExtensions.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/ActivityExtensions.kt @@ -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 Activity.lazyView(@IdRes viewId: Int): Lazy = lazy { findViewById(viewId) } diff --git a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt index 02b57bc2e..9b0591e5d 100644 --- a/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt +++ b/custom/src/main/java/org/kiwix/kiwixmobile/custom/main/CustomMainActivity.kt @@ -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(R.id.custom_drawer_container).addDrawerListener(drawerToggle) + drawerContainer.addDrawerListener(drawerToggle) drawerToggle.syncState() - findViewById(R.id.drawer_nav_view).setNavigationItemSelectedListener(this) - findViewById(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(R.id.custom_drawer_container).isDrawerOpen( - findViewById( - R.id.drawer_nav_view - ) - ) + drawerContainer.isDrawerOpen(drawerNavView) override fun closeNavigationDrawer() { - findViewById(R.id.custom_drawer_container).closeDrawer( - findViewById( - R.id.drawer_nav_view - ) - ) + drawerContainer.closeDrawer(drawerNavView) } override fun openSettingsActivity() {