aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-12-26 16:49:06 -0800
committerAllan Wang <me@allanwang.ca>2019-12-26 16:49:06 -0800
commit6779b1118d9fd2f1e659679d9f2cad3127d0c822 (patch)
treea85a14a15b3cbd3a4f1bca16d414d91d3e817c1f /app
parent42a23c00ae98a0e4a6f493b7d6ce9a23d717e5f6 (diff)
downloadfrost-6779b1118d9fd2f1e659679d9f2cad3127d0c822.tar.gz
frost-6779b1118d9fd2f1e659679d9f2cad3127d0c822.tar.bz2
frost-6779b1118d9fd2f1e659679d9f2cad3127d0c822.zip
Switch to viewbinding and styles and prepare layout wrapper
Diffstat (limited to 'app')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt6
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt62
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt5
-rw-r--r--app/src/main/res/layout/activity_main.xml16
-rw-r--r--app/src/main/res/layout/activity_main_bottom_tabs.xml23
-rw-r--r--app/src/main/res/layout/activity_main_drawer_wrapper.xml18
-rw-r--r--app/src/main/res/values/styles.xml31
7 files changed, 128 insertions, 33 deletions
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 }
}
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 8fa9283f..f46175d1 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -13,14 +13,22 @@
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
- <include layout="@layout/view_main_toolbar" />
+ <androidx.appcompat.widget.Toolbar
+ android:id="@+id/toolbar"
+ style="@style/Main.Toolbar" />
- <include layout="@layout/view_main_tab_layout" />
+ <com.google.android.material.tabs.TabLayout
+ android:id="@+id/tabs"
+ style="@style/Main.TabLayout" />
</com.google.android.material.appbar.AppBarLayout>
- <include layout="@layout/view_main_viewpager" />
+ <com.pitchedapps.frost.views.FrostViewPager
+ android:id="@+id/viewpager"
+ style="@style/Main.ViewPager" />
- <include layout="@layout/view_main_fab" />
+ <com.google.android.material.floatingactionbutton.FloatingActionButton
+ android:id="@+id/fab"
+ style="@style/Main.Fab" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
diff --git a/app/src/main/res/layout/activity_main_bottom_tabs.xml b/app/src/main/res/layout/activity_main_bottom_tabs.xml
index 2c2527cd..419bbc33 100644
--- a/app/src/main/res/layout/activity_main_bottom_tabs.xml
+++ b/app/src/main/res/layout/activity_main_bottom_tabs.xml
@@ -3,15 +3,16 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:orientation="vertical">
+ android:fitsSystemWindows="true"
+ android:orientation="vertical"
+ tools:context=".activities.MainActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
- android:fitsSystemWindows="true"
- tools:context=".activities.MainActivity">
+ android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
@@ -19,17 +20,25 @@
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
- <include layout="@layout/view_main_toolbar" />
+ <androidx.appcompat.widget.Toolbar
+ android:id="@+id/toolbar"
+ style="@style/Main.Toolbar" />
</com.google.android.material.appbar.AppBarLayout>
- <include layout="@layout/view_main_viewpager" />
+ <com.pitchedapps.frost.views.FrostViewPager
+ android:id="@+id/viewpager"
+ style="@style/Main.ViewPager" />
- <include layout="@layout/view_main_fab" />
+ <com.google.android.material.floatingactionbutton.FloatingActionButton
+ android:id="@+id/fab"
+ style="@style/Main.Fab" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
- <include layout="@layout/view_main_tab_layout" />
+ <com.google.android.material.tabs.TabLayout
+ android:id="@+id/tabs"
+ style="@style/Main.TabLayout" />
</LinearLayout>
diff --git a/app/src/main/res/layout/activity_main_drawer_wrapper.xml b/app/src/main/res/layout/activity_main_drawer_wrapper.xml
new file mode 100644
index 00000000..4eebf56a
--- /dev/null
+++ b/app/src/main/res/layout/activity_main_drawer_wrapper.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:fitsSystemWindows="true">
+
+ <FrameLayout
+ android:id="@+id/main_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:fitsSystemWindows="true" />
+
+ <com.google.android.material.navigation.NavigationView
+ android:id="@+id/navigation"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:visibility="gone" />
+</androidx.drawerlayout.widget.DrawerLayout> \ No newline at end of file
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 4d22ee79..c5179bb1 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -98,4 +98,35 @@
<item name="android:padding">@dimen/kau_padding_large</item>
</style>
+ <!-- Main Activity Styles -->
+
+ <style name="Main.Toolbar" parent="">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">?actionBarSize</item>
+ <item name="layout_scrollFlags">scroll|enterAlways|snap</item>
+ <item name="popupTheme">@style/AppTheme.PopupOverlay</item>
+ </style>
+
+ <style name="Main.ViewPager" parent="" >
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">match_parent</item>
+ <item name="layout_behavior">@string/appbar_scrolling_view_behavior</item>
+ </style>
+
+ <style name="Main.Fab" parent="" >
+ <item name="android:layout_width">wrap_content</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:layout_gravity">end|bottom</item>
+ <item name="android:layout_margin">16dp</item>
+ </style>
+
+ <style name="Main.TabLayout" parent="Widget.Design.TabLayout">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">@dimen/tab_bar_height</item>
+ <item name="tabGravity">fill</item>
+ <item name="tabIndicatorHeight">0dp</item>
+ <item name="tabMode">fixed</item>
+ </style>
+
+
</resources>