diff options
Diffstat (limited to 'app/src')
8 files changed, 138 insertions, 16 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 } } diff --git a/app/src/main/res/drawable/nav_item_background.xml b/app/src/main/res/drawable/nav_item_background.xml new file mode 100644 index 00000000..7c7a7209 --- /dev/null +++ b/app/src/main/res/drawable/nav_item_background.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="#f0f"> + <item + android:id="@android:id/mask" + android:right="8dp"> + <shape android:shape="rectangle"> + <corners + android:bottomRightRadius="50dp" + android:topRightRadius="50dp" /> + <solid android:color="#fff" /> + </shape> + </item> +</ripple>
\ No newline at end of file diff --git a/app/src/main/res/layout/activity_main_drawer_wrapper.xml b/app/src/main/res/layout/activity_main_drawer_wrapper.xml index 1af2e639..d5efcf0d 100644 --- a/app/src/main/res/layout/activity_main_drawer_wrapper.xml +++ b/app/src/main/res/layout/activity_main_drawer_wrapper.xml @@ -1,9 +1,11 @@ <?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" + xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer" + android:layout_width="match_parent" android:layout_height="match_parent" - android:fitsSystemWindows="true"> + android:fitsSystemWindows="true" + tools:openDrawer="end"> <FrameLayout android:id="@+id/main_container" @@ -15,5 +17,6 @@ android:id="@+id/navigation" android:layout_width="wrap_content" android:layout_height="match_parent" - android:visibility="gone" /> + android:layout_gravity="start" + android:theme="@style/ThemeOverlay.Frost.NavigationView" /> </androidx.drawerlayout.widget.DrawerLayout>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dda6c789..96957c4c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -40,12 +40,14 @@ <string name="show_all_results">Show All Results</string> - <string name="frost_description">Frost is a fully themable, fully functional alternative to the official Facebook app, made from scratch and proudly open sourced.</string> <string name="faq_title">Frost FAQ</string> + <string name="open">Open</string> + <string name="close">Close</string> + <string name="html_extraction_error">An error occurred in the html extraction.</string> <string name="html_extraction_cancelled">The request has been cancelled.</string> <string name="html_extraction_timeout">The request has timed out.</string> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c5179bb1..3cbad6d7 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -128,5 +128,16 @@ <item name="tabMode">fixed</item> </style> + <style name="ThemeOverlay.Frost.NavigationView" parent=""> + <item name="android:colorControlHighlight">@android:color/transparent</item> + </style> + +<!-- <style name="ShapeAppearanceOverlay.Item" parent="">--> +<!-- <item name="cornerFamily">rounded</item>--> +<!-- <item name="cornerSizeTopRight">10dp</item>--> +<!-- <item name="cornerSizeBottomRight">10dp</item>--> +<!-- <item name="cornerSizeBottomLeft">0dp</item>--> +<!-- <item name="cornerSizeTopLeft">0dp</item>--> +<!-- </style>--> </resources> |