aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-12-27 00:28:33 -0800
committerAllan Wang <me@allanwang.ca>2019-12-27 00:28:33 -0800
commit44524ce6eea7b0d0998bbabc8d72ea8b43f55f02 (patch)
treebbcdc7a3d3c54048f838635280ac0d1a3f341133 /app/src/main/kotlin/com/pitchedapps
parent454872d712a0496e97b7138b30cc2fccac037b2f (diff)
downloadfrost-44524ce6eea7b0d0998bbabc8d72ea8b43f55f02.tar.gz
frost-44524ce6eea7b0d0998bbabc8d72ea8b43f55f02.tar.bz2
frost-44524ce6eea7b0d0998bbabc8d72ea8b43f55f02.zip
Add nav items programmatically
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt89
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt18
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt4
4 files changed, 104 insertions, 12 deletions
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 3fa65ba3..5e79c93f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
@@ -18,9 +18,11 @@ package com.pitchedapps.frost.activities
import android.annotation.SuppressLint
import android.app.ActivityOptions
+import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.PointF
+import android.graphics.drawable.RippleDrawable
import android.net.Uri
import android.os.Bundle
import android.view.Menu
@@ -30,6 +32,8 @@ import android.webkit.ValueCallback
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.widget.FrameLayout
+import androidx.annotation.ColorInt
+import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
@@ -37,6 +41,8 @@ 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.adjustAlpha
+import ca.allanwang.kau.utils.drawable
import ca.allanwang.kau.utils.fadeScaleTransition
import ca.allanwang.kau.utils.materialDialog
import ca.allanwang.kau.utils.restart
@@ -45,6 +51,7 @@ import ca.allanwang.kau.utils.setMenuIcons
import ca.allanwang.kau.utils.showIf
import ca.allanwang.kau.utils.string
import ca.allanwang.kau.utils.tint
+import ca.allanwang.kau.utils.toDrawable
import ca.allanwang.kau.utils.withMinAlpha
import com.afollestad.materialdialogs.checkbox.checkBoxPrompt
import com.google.android.material.appbar.AppBarLayout
@@ -204,6 +211,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
}
// setupDrawer(savedInstanceState)
L.i { "Main started in ${System.currentTimeMillis() - start} ms" }
+ drawerWrapperBinding.initDrawer()
contentBinding.initFab()
lastAccessTime = System.currentTimeMillis()
}
@@ -216,6 +224,85 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
private var hasFab = false
private var shouldShow = false
+ private class FrostMenuBuilder(private val context: Context, private val menu: Menu) {
+ private var order: Int = 0
+ private var groupId: Int = 13
+ private val items: MutableList<Menu> = mutableListOf()
+
+ fun primaryFrostItem(fbItem: FbItem) {
+ val item = menu.add(groupId, fbItem.ordinal, order++, context.string(fbItem.titleId))
+ item.icon = fbItem.icon.toDrawable(context, 18)
+ }
+
+ fun divider() {
+ groupId++
+ }
+
+ fun secondaryFrostItem(fbItem: FbItem) {
+ menu.add(groupId, fbItem.ordinal, order++, context.string(fbItem.titleId))
+ }
+ }
+
+ private fun ActivityMainDrawerWrapperBinding.initDrawer() {
+
+ fun createNavDrawable(@ColorInt foregroundColor: Int): RippleDrawable {
+ val drawable = drawable(R.drawable.nav_item_background) as RippleDrawable
+ drawable.setColor(
+ ColorStateList(
+ arrayOf(intArrayOf()),
+ intArrayOf(foregroundColor.adjustAlpha(0.16f))
+ )
+ )
+ return drawable
+ }
+
+ val toggle = ActionBarDrawerToggle(
+ this@BaseMainActivity, drawer, contentBinding.toolbar,
+ R.string.open,
+ R.string.close
+ )
+ toggle.isDrawerSlideAnimationEnabled = false
+ drawer.addDrawerListener(toggle)
+ toggle.syncState()
+
+ val foregroundColor = ColorStateList.valueOf(Prefs.textColor)
+
+ with(navigation) {
+ FrostMenuBuilder(this@BaseMainActivity, menu).apply {
+ primaryFrostItem(FbItem.FEED_MOST_RECENT)
+ primaryFrostItem(FbItem.FEED_TOP_STORIES)
+ primaryFrostItem(FbItem.ACTIVITY_LOG)
+ divider()
+ primaryFrostItem(FbItem.PHOTOS)
+ primaryFrostItem(FbItem.GROUPS)
+ primaryFrostItem(FbItem.FRIENDS)
+ primaryFrostItem(FbItem.CHAT)
+ primaryFrostItem(FbItem.PAGES)
+ divider()
+ primaryFrostItem(FbItem.EVENTS)
+ primaryFrostItem(FbItem.BIRTHDAYS)
+ primaryFrostItem(FbItem.ON_THIS_DAY)
+ divider()
+ primaryFrostItem(FbItem.NOTES)
+ primaryFrostItem(FbItem.SAVED)
+ primaryFrostItem(FbItem.MARKETPLACE)
+ }
+ setNavigationItemSelectedListener {
+ val item = FbItem.values[it.itemId]
+ frostEvent("Drawer Tab", "name" to item.name)
+ drawer.closeDrawer(navigation)
+ launchWebOverlay(item.url)
+ false
+ }
+ val navBg = Prefs.bgColor.withMinAlpha(200)
+ setBackgroundColor(navBg)
+ itemBackground = createNavDrawable(Prefs.accentColor)
+ itemTextColor = foregroundColor
+ itemIconTintList = foregroundColor
+
+ }
+ }
+
private fun ActivityMainContentBinding.initFab() {
hasFab = false
shouldShow = false
@@ -565,7 +652,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
}
override fun backConsumer(): Boolean {
- with (drawerWrapperBinding) {
+ with(drawerWrapperBinding) {
if (drawer.isDrawerOpen(navigation)) {
drawer.closeDrawer(navigation)
return true
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
index fc9eca37..e0053402 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
@@ -37,12 +37,14 @@ class MainActivity : BaseMainActivity() {
override val headerBadgeChannel = BroadcastChannel<String>(Channel.CONFLATED)
override fun onNestedCreate(savedInstanceState: Bundle?) {
- setupTabs()
- setupViewPager()
+ with(contentBinding) {
+ setupTabs()
+ setupViewPager()
+ }
}
- private fun setupViewPager() {
- viewPager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
+ private fun ActivityMainContentBinding.setupViewPager() {
+ viewpager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
if (lastPosition == position) {
@@ -75,9 +77,9 @@ class MainActivity : BaseMainActivity() {
})
}
- private fun setupTabs() {
- viewPager.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabs))
- tabs.addOnTabSelectedListener(object : TabLayout.ViewPagerOnTabSelectedListener(viewPager) {
+ private fun ActivityMainContentBinding.setupTabs() {
+ viewpager.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabs))
+ tabs.addOnTabSelectedListener(object : TabLayout.ViewPagerOnTabSelectedListener(viewpager) {
override fun onTabReselected(tab: TabLayout.Tab) {
super.onTabReselected(tab)
currentFragment.onTabClick()
@@ -88,7 +90,7 @@ class MainActivity : BaseMainActivity() {
(tab.customView as BadgedIcon).badgeText = null
}
})
- headerBadgeChannel.subscribeDuringJob(this, Dispatchers.IO) { html ->
+ headerBadgeChannel.subscribeDuringJob(this@MainActivity, Dispatchers.IO) { html ->
try {
val doc = Jsoup.parse(html)
if (doc.select("[data-sigil=count]").isEmpty())
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt
index 9089d891..becc9f02 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt
@@ -47,7 +47,10 @@ fun Context.showWebContextMenu(wc: WebContext) {
}
onDismiss {
// showing the dialog interrupts the touch down event, so we must ensure that the viewpager's swipe is enabled
- (this@showWebContextMenu as? MainActivity)?.viewPager?.enableSwipe = true
+ (this@showWebContextMenu as? MainActivity)
+ ?.contentBinding
+ ?.viewpager
+ ?.enableSwipe = true
}
}
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
index 0988e331..c8e551a3 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
@@ -88,7 +88,7 @@ class FrostJSI(val web: FrostWebView) {
*/
@JavascriptInterface
fun longClick(start: Boolean) {
- activity?.viewPager?.enableSwipe = !start
+ activity?.contentBinding?.viewpager?.enableSwipe = !start
if (web.frostWebClient.urlSupportsRefresh) {
web.parent.swipeEnabled = !start
}
@@ -151,7 +151,7 @@ class FrostJSI(val web: FrostWebView) {
@JavascriptInterface
fun allowHorizontalScrolling(enable: Boolean) {
- activity?.viewPager?.enableSwipe = enable
+ activity?.contentBinding?.viewpager?.enableSwipe = enable
(context as? WebOverlayActivityBase)?.swipeBack?.disallowIntercept = !enable
}
}