From 6779b1118d9fd2f1e659679d9f2cad3127d0c822 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 26 Dec 2019 16:49:06 -0800 Subject: Switch to viewbinding and styles and prepare layout wrapper --- .../main/kotlin/com/pitchedapps/frost/FrostApp.kt | 6 --- .../frost/activities/BaseMainActivity.kt | 62 +++++++++++++++++----- .../pitchedapps/frost/enums/MainActivityLayout.kt | 5 +- 3 files changed, 51 insertions(+), 22 deletions(-) (limited to 'app/src/main/kotlin/com') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt index a5cba69b..75efe637 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt @@ -18,18 +18,12 @@ package com.pitchedapps.frost import android.app.Activity import android.app.Application -import android.graphics.drawable.Drawable -import android.net.Uri import android.os.Bundle -import android.widget.ImageView import ca.allanwang.kau.logging.KL import ca.allanwang.kau.utils.buildIsLollipopAndUp import com.bugsnag.android.Bugsnag import com.bugsnag.android.Configuration -import com.bumptech.glide.request.RequestOptions -import com.bumptech.glide.signature.ApplicationVersionSignature import com.pitchedapps.frost.db.FrostDatabase -import com.pitchedapps.frost.glide.GlideApp import com.pitchedapps.frost.services.scheduleNotificationsFromPrefs import com.pitchedapps.frost.services.setupNotificationChannels import com.pitchedapps.frost.utils.BuildUtils diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt index fef7bfe5..f61e7f3e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt @@ -25,18 +25,18 @@ import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import android.view.View import android.webkit.ValueCallback import android.webkit.WebChromeClient import android.webkit.WebView import android.widget.FrameLayout -import androidx.coordinatorlayout.widget.CoordinatorLayout +import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentPagerAdapter import ca.allanwang.kau.searchview.SearchItem import ca.allanwang.kau.searchview.SearchView import ca.allanwang.kau.searchview.SearchViewHolder import ca.allanwang.kau.searchview.bindSearchView -import ca.allanwang.kau.utils.bindView import ca.allanwang.kau.utils.fadeScaleTransition import ca.allanwang.kau.utils.materialDialog import ca.allanwang.kau.utils.restart @@ -48,6 +48,7 @@ import ca.allanwang.kau.utils.tint import ca.allanwang.kau.utils.withMinAlpha import com.afollestad.materialdialogs.checkbox.checkBoxPrompt import com.google.android.material.appbar.AppBarLayout +import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.tabs.TabLayout import com.mikepenz.iconics.typeface.IIcon import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial @@ -57,6 +58,9 @@ import com.pitchedapps.frost.contracts.FileChooserContract import com.pitchedapps.frost.contracts.FileChooserDelegate import com.pitchedapps.frost.contracts.MainActivityContract import com.pitchedapps.frost.contracts.VideoViewHolder +import com.pitchedapps.frost.databinding.ActivityMainBinding +import com.pitchedapps.frost.databinding.ActivityMainBottomTabsBinding +import com.pitchedapps.frost.databinding.ActivityMainDrawerWrapperBinding import com.pitchedapps.frost.db.CookieDao import com.pitchedapps.frost.db.GenericDao import com.pitchedapps.frost.db.getTabs @@ -92,10 +96,6 @@ import com.pitchedapps.frost.views.BadgedIcon import com.pitchedapps.frost.views.FrostVideoViewer import com.pitchedapps.frost.views.FrostViewPager import com.pitchedapps.frost.widgets.NotificationWidget -import kotlinx.android.synthetic.main.activity_frame_wrapper.* -import kotlinx.android.synthetic.main.view_main_fab.* -import kotlinx.android.synthetic.main.view_main_toolbar.* -import kotlinx.android.synthetic.main.view_main_viewpager.* import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.launch import org.koin.android.ext.android.inject @@ -115,17 +115,29 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, * Note that tabs themselves are initialized through a coroutine during onCreate */ protected val adapter: SectionsPagerAdapter = SectionsPagerAdapter() - override val frameWrapper: FrameLayout get() = frame_wrapper - val viewPager: FrostViewPager get() = container + override val frameWrapper: FrameLayout get() = drawerWrapperBinding.mainContainer + lateinit var drawerWrapperBinding: ActivityMainDrawerWrapperBinding + lateinit var contentBinding: ActivityMainContentBinding + val viewPager: FrostViewPager get() = contentBinding.viewpager + val fab: FloatingActionButton get() =contentBinding.fab + val toolbar: Toolbar get() = contentBinding.toolbar val cookieDao: CookieDao by inject() val genericDao: GenericDao by inject() /* * Components with the same id in multiple layout files */ - val tabs: TabLayout by bindView(R.id.tabs) - val appBar: AppBarLayout by bindView(R.id.appbar) - val coordinator: CoordinatorLayout by bindView(R.id.main_content) + val tabs: TabLayout get() = contentBinding.tabs + val appBar: AppBarLayout get() = contentBinding.appbar + + interface ActivityMainContentBinding { + val root: View + val toolbar: Toolbar + val viewpager: FrostViewPager + val tabs: TabLayout + val appbar: AppBarLayout + val fab: FloatingActionButton + } protected var lastPosition = -1 @@ -141,7 +153,33 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, final override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val start = System.currentTimeMillis() - setFrameContentView(Prefs.mainActivityLayout.layoutRes) + drawerWrapperBinding = ActivityMainDrawerWrapperBinding.inflate(layoutInflater) + setContentView(drawerWrapperBinding.root) + contentBinding = when (Prefs.mainActivityLayout) { + MainActivityLayout.TOP_BAR -> { + val binding = ActivityMainBinding.inflate(layoutInflater) + object : ActivityMainContentBinding { + override val root: View = binding.root + override val toolbar: Toolbar = binding.toolbar + override val viewpager: FrostViewPager = binding.viewpager + override val tabs: TabLayout = binding.tabs + override val appbar: AppBarLayout = binding.appbar + override val fab: FloatingActionButton = binding.fab + } + } + MainActivityLayout.BOTTOM_BAR -> { + val binding = ActivityMainBottomTabsBinding.inflate(layoutInflater) + object : ActivityMainContentBinding { + override val root: View = binding.root + override val toolbar: Toolbar = binding.toolbar + override val viewpager: FrostViewPager = binding.viewpager + override val tabs: TabLayout = binding.tabs + override val appbar: AppBarLayout = binding.appbar + override val fab: FloatingActionButton = binding.fab + } + } + } + drawerWrapperBinding.mainContainer.addView(contentBinding.root) setFrostColors { toolbar(toolbar) themeWindow = false diff --git a/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt b/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt index a3a4c1a4..92aa93ab 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt @@ -24,23 +24,20 @@ import com.pitchedapps.frost.utils.Prefs */ enum class MainActivityLayout( val titleRes: Int, - val layoutRes: Int, val backgroundColor: () -> Int, val iconColor: () -> Int ) { TOP_BAR(R.string.top_bar, - R.layout.activity_main, { Prefs.headerColor }, { Prefs.iconColor }), BOTTOM_BAR(R.string.bottom_bar, - R.layout.activity_main_bottom_tabs, { Prefs.bgColor }, { Prefs.textColor }); companion object { val values = values() // save one instance - operator fun invoke(index: Int) = values[index] + operator fun invoke(index: Int) = values.getOrElse(index) { TOP_BAR } } } -- cgit v1.2.3