1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-10 04:52:38 +01:00

Remove material drawer dependency

This commit is contained in:
Allan Wang 2019-12-26 16:14:44 -08:00
parent ee68ef07ca
commit 42a23c00ae
No known key found for this signature in database
GPG Key ID: C93E3F9C679D7A56
4 changed files with 153 additions and 180 deletions

View File

@ -289,7 +289,7 @@ dependencies {
testImplementation "com.squareup.okhttp3:mockwebserver:${Versions.okhttp}" testImplementation "com.squareup.okhttp3:mockwebserver:${Versions.okhttp}"
androidTestImplementation "com.squareup.okhttp3:mockwebserver:${Versions.okhttp}" androidTestImplementation "com.squareup.okhttp3:mockwebserver:${Versions.okhttp}"
implementation "co.zsmb:materialdrawer-kt:${Versions.materialDrawerKt}" // implementation "co.zsmb:materialdrawer-kt:${Versions.materialDrawerKt}"
implementation kau.Dependencies.bugsnag implementation kau.Dependencies.bugsnag

View File

@ -28,8 +28,6 @@ import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration import com.bugsnag.android.Configuration
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.signature.ApplicationVersionSignature import com.bumptech.glide.signature.ApplicationVersionSignature
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
import com.mikepenz.materialdrawer.util.DrawerImageLoader
import com.pitchedapps.frost.db.FrostDatabase import com.pitchedapps.frost.db.FrostDatabase
import com.pitchedapps.frost.glide.GlideApp import com.pitchedapps.frost.glide.GlideApp
import com.pitchedapps.frost.services.scheduleNotificationsFromPrefs import com.pitchedapps.frost.services.scheduleNotificationsFromPrefs
@ -79,18 +77,18 @@ class FrostApp : Application() {
* Drawer profile loading logic * Drawer profile loading logic
* Reload the image on every version update * Reload the image on every version update
*/ */
DrawerImageLoader.init(object : AbstractDrawerImageLoader() { // DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) { // override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) {
val c = imageView.context // val c = imageView.context
val request = GlideApp.with(c) // val request = GlideApp.with(c)
val old = request.load(uri).apply(RequestOptions().placeholder(placeholder)) // val old = request.load(uri).apply(RequestOptions().placeholder(placeholder))
request.load(uri).apply( // request.load(uri).apply(
RequestOptions() // RequestOptions()
.signature(ApplicationVersionSignature.obtain(c)) // .signature(ApplicationVersionSignature.obtain(c))
) // )
.thumbnail(old).into(imageView) // .thumbnail(old).into(imageView)
} // }
}) // })
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks { registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
override fun onActivityPaused(activity: Activity) {} override fun onActivityPaused(activity: Activity) {}

View File

@ -21,7 +21,6 @@ import android.app.ActivityOptions
import android.content.Intent import android.content.Intent
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.PointF import android.graphics.PointF
import android.graphics.drawable.ColorDrawable
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
@ -30,7 +29,6 @@ import android.webkit.ValueCallback
import android.webkit.WebChromeClient import android.webkit.WebChromeClient
import android.webkit.WebView import android.webkit.WebView
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.annotation.StringRes
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter import androidx.fragment.app.FragmentPagerAdapter
@ -47,26 +45,12 @@ import ca.allanwang.kau.utils.setMenuIcons
import ca.allanwang.kau.utils.showIf import ca.allanwang.kau.utils.showIf
import ca.allanwang.kau.utils.string import ca.allanwang.kau.utils.string
import ca.allanwang.kau.utils.tint import ca.allanwang.kau.utils.tint
import ca.allanwang.kau.utils.toast
import ca.allanwang.kau.utils.withMinAlpha import ca.allanwang.kau.utils.withMinAlpha
import co.zsmb.materialdrawerkt.builders.Builder
import co.zsmb.materialdrawerkt.builders.accountHeader
import co.zsmb.materialdrawerkt.builders.drawer
import co.zsmb.materialdrawerkt.draweritems.badgeable.primaryItem
import co.zsmb.materialdrawerkt.draweritems.badgeable.secondaryItem
import co.zsmb.materialdrawerkt.draweritems.divider
import co.zsmb.materialdrawerkt.draweritems.profile.profile
import co.zsmb.materialdrawerkt.draweritems.profile.profileSetting
import com.afollestad.materialdialogs.checkbox.checkBoxPrompt import com.afollestad.materialdialogs.checkbox.checkBoxPrompt
import com.google.android.material.appbar.AppBarLayout import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import com.mikepenz.iconics.IconicsDrawable
import com.mikepenz.iconics.typeface.IIcon import com.mikepenz.iconics.typeface.IIcon
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import com.mikepenz.iconics.utils.colorInt
import com.mikepenz.iconics.utils.paddingDp
import com.mikepenz.materialdrawer.AccountHeader
import com.mikepenz.materialdrawer.Drawer
import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.R import com.pitchedapps.frost.R
import com.pitchedapps.frost.contracts.FileChooserContract import com.pitchedapps.frost.contracts.FileChooserContract
@ -75,14 +59,12 @@ import com.pitchedapps.frost.contracts.MainActivityContract
import com.pitchedapps.frost.contracts.VideoViewHolder import com.pitchedapps.frost.contracts.VideoViewHolder
import com.pitchedapps.frost.db.CookieDao import com.pitchedapps.frost.db.CookieDao
import com.pitchedapps.frost.db.GenericDao import com.pitchedapps.frost.db.GenericDao
import com.pitchedapps.frost.db.currentCookie
import com.pitchedapps.frost.db.getTabs import com.pitchedapps.frost.db.getTabs
import com.pitchedapps.frost.enums.MainActivityLayout import com.pitchedapps.frost.enums.MainActivityLayout
import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.facebook.parsers.FrostSearch import com.pitchedapps.frost.facebook.parsers.FrostSearch
import com.pitchedapps.frost.facebook.parsers.SearchParser import com.pitchedapps.frost.facebook.parsers.SearchParser
import com.pitchedapps.frost.facebook.profilePictureUrl
import com.pitchedapps.frost.fragments.BaseFragment import com.pitchedapps.frost.fragments.BaseFragment
import com.pitchedapps.frost.fragments.WebFragment import com.pitchedapps.frost.fragments.WebFragment
import com.pitchedapps.frost.services.scheduleNotificationsFromPrefs import com.pitchedapps.frost.services.scheduleNotificationsFromPrefs
@ -104,8 +86,6 @@ import com.pitchedapps.frost.utils.cookies
import com.pitchedapps.frost.utils.frostChangelog import com.pitchedapps.frost.utils.frostChangelog
import com.pitchedapps.frost.utils.frostEvent import com.pitchedapps.frost.utils.frostEvent
import com.pitchedapps.frost.utils.frostNavigationBar import com.pitchedapps.frost.utils.frostNavigationBar
import com.pitchedapps.frost.utils.launchLogin
import com.pitchedapps.frost.utils.launchNewTask
import com.pitchedapps.frost.utils.launchWebOverlay import com.pitchedapps.frost.utils.launchWebOverlay
import com.pitchedapps.frost.utils.setFrostColors import com.pitchedapps.frost.utils.setFrostColors
import com.pitchedapps.frost.views.BadgedIcon import com.pitchedapps.frost.views.BadgedIcon
@ -150,8 +130,8 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
protected var lastPosition = -1 protected var lastPosition = -1
override var videoViewer: FrostVideoViewer? = null override var videoViewer: FrostVideoViewer? = null
private lateinit var drawer: Drawer // private lateinit var drawer: Drawer
private lateinit var drawerHeader: AccountHeader // private lateinit var drawerHeader: AccountHeader
private var lastAccessTime = -1L private var lastAccessTime = -1L
override var searchView: SearchView? = null override var searchView: SearchView? = null
@ -192,7 +172,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
) )
} }
} }
setupDrawer(savedInstanceState) // setupDrawer(savedInstanceState)
L.i { "Main started in ${System.currentTimeMillis() - start} ms" } L.i { "Main started in ${System.currentTimeMillis() - start} ms" }
initFab() initFab()
lastAccessTime = System.currentTimeMillis() lastAccessTime = System.currentTimeMillis()
@ -249,138 +229,138 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
} }
} }
private fun setupDrawer(savedInstanceState: Bundle?) { // private fun setupDrawer(savedInstanceState: Bundle?) {
val navBg = Prefs.bgColor.withMinAlpha(200).toLong() // val navBg = Prefs.bgColor.withMinAlpha(200).toLong()
val navHeader = Prefs.headerColor.withMinAlpha(200) // val navHeader = Prefs.headerColor.withMinAlpha(200)
drawer = drawer { // drawer = drawer {
toolbar = this@BaseMainActivity.toolbar // toolbar = this@BaseMainActivity.toolbar
savedInstance = savedInstanceState // savedInstance = savedInstanceState
translucentStatusBar = false // translucentStatusBar = false
sliderBackgroundColor = navBg // sliderBackgroundColor = navBg
drawerHeader = accountHeader { // drawerHeader = accountHeader {
textColor = Prefs.iconColor.toLong() // textColor = Prefs.iconColor.toLong()
backgroundDrawable = ColorDrawable(navHeader) // backgroundDrawable = ColorDrawable(navHeader)
selectionSecondLineShown = false // selectionSecondLineShown = false
cookies().forEach { (id, name) -> // cookies().forEach { (id, name) ->
profile(name = name ?: "") { // profile(name = name ?: "") {
iconUrl = profilePictureUrl(id) // iconUrl = profilePictureUrl(id)
textColor = Prefs.textColor.toLong() // textColor = Prefs.textColor.toLong()
selectedTextColor = Prefs.textColor.toLong() // selectedTextColor = Prefs.textColor.toLong()
selectedColor = 0x00000001.toLong() // selectedColor = 0x00000001.toLong()
identifier = id // identifier = id
} // }
} // }
profileSetting(nameRes = R.string.kau_logout) { // profileSetting(nameRes = R.string.kau_logout) {
iicon = GoogleMaterial.Icon.gmd_exit_to_app // iicon = GoogleMaterial.Icon.gmd_exit_to_app
iconColor = Prefs.textColor.toLong() // iconColor = Prefs.textColor.toLong()
textColor = Prefs.textColor.toLong() // textColor = Prefs.textColor.toLong()
identifier = -2L // identifier = -2L
} // }
profileSetting(nameRes = R.string.kau_add_account) { // profileSetting(nameRes = R.string.kau_add_account) {
iconDrawable = // iconDrawable =
IconicsDrawable( // IconicsDrawable(
this@BaseMainActivity, // this@BaseMainActivity,
GoogleMaterial.Icon.gmd_add // GoogleMaterial.Icon.gmd_add
).actionBar().paddingDp(5) // ).actionBar().paddingDp(5)
.colorInt(Prefs.textColor) // .colorInt(Prefs.textColor)
textColor = Prefs.textColor.toLong() // textColor = Prefs.textColor.toLong()
identifier = -3L // identifier = -3L
} // }
profileSetting(nameRes = R.string.kau_manage_account) { // profileSetting(nameRes = R.string.kau_manage_account) {
iicon = GoogleMaterial.Icon.gmd_settings // iicon = GoogleMaterial.Icon.gmd_settings
iconColor = Prefs.textColor.toLong() // iconColor = Prefs.textColor.toLong()
textColor = Prefs.textColor.toLong() // textColor = Prefs.textColor.toLong()
identifier = -4L // identifier = -4L
} // }
onProfileChanged { _, profile, current -> // onProfileChanged { _, profile, current ->
if (current) launchWebOverlay(FbItem.PROFILE.url) // if (current) launchWebOverlay(FbItem.PROFILE.url)
else when (profile.identifier) { // else when (profile.identifier) {
-2L -> { // -2L -> {
// TODO no backpressure support // // TODO no backpressure support
this@BaseMainActivity.launch { // this@BaseMainActivity.launch {
val currentCookie = cookieDao.currentCookie() // val currentCookie = cookieDao.currentCookie()
if (currentCookie == null) { // if (currentCookie == null) {
toast(R.string.account_not_found) // toast(R.string.account_not_found)
FbCookie.reset() // FbCookie.reset()
launchLogin(cookies(), true) // launchLogin(cookies(), true)
} else { // } else {
materialDialog { // materialDialog {
title(R.string.kau_logout) // title(R.string.kau_logout)
message( // message(
text = // text =
String.format( // String.format(
string(R.string.kau_logout_confirm_as_x), // string(R.string.kau_logout_confirm_as_x),
currentCookie.name ?: Prefs.userId.toString() // currentCookie.name ?: Prefs.userId.toString()
) // )
) // )
positiveButton(R.string.kau_yes) { // positiveButton(R.string.kau_yes) {
this@BaseMainActivity.launch { // this@BaseMainActivity.launch {
FbCookie.logout(this@BaseMainActivity) // FbCookie.logout(this@BaseMainActivity)
} // }
} // }
negativeButton(R.string.kau_no) // negativeButton(R.string.kau_no)
} // }
} // }
} // }
} // }
-3L -> launchNewTask<LoginActivity>(clearStack = false) // -3L -> launchNewTask<LoginActivity>(clearStack = false)
-4L -> launchNewTask<SelectorActivity>(cookies(), false) // -4L -> launchNewTask<SelectorActivity>(cookies(), false)
else -> { // else -> {
this@BaseMainActivity.launch { // this@BaseMainActivity.launch {
FbCookie.switchUser(profile.identifier) // FbCookie.switchUser(profile.identifier)
tabsForEachView { _, view -> view.badgeText = null } // tabsForEachView { _, view -> view.badgeText = null }
refreshAll() // refreshAll()
} // }
} // }
} // }
false // false
} // }
} // }
drawerHeader.setActiveProfile(Prefs.userId) // drawerHeader.setActiveProfile(Prefs.userId)
primaryFrostItem(FbItem.FEED_MOST_RECENT) // primaryFrostItem(FbItem.FEED_MOST_RECENT)
primaryFrostItem(FbItem.FEED_TOP_STORIES) // primaryFrostItem(FbItem.FEED_TOP_STORIES)
primaryFrostItem(FbItem.ACTIVITY_LOG) // primaryFrostItem(FbItem.ACTIVITY_LOG)
divider() // divider()
primaryFrostItem(FbItem.PHOTOS) // primaryFrostItem(FbItem.PHOTOS)
primaryFrostItem(FbItem.GROUPS) // primaryFrostItem(FbItem.GROUPS)
primaryFrostItem(FbItem.FRIENDS) // primaryFrostItem(FbItem.FRIENDS)
primaryFrostItem(FbItem.CHAT) // primaryFrostItem(FbItem.CHAT)
primaryFrostItem(FbItem.PAGES) // primaryFrostItem(FbItem.PAGES)
divider() // divider()
primaryFrostItem(FbItem.EVENTS) // primaryFrostItem(FbItem.EVENTS)
primaryFrostItem(FbItem.BIRTHDAYS) // primaryFrostItem(FbItem.BIRTHDAYS)
primaryFrostItem(FbItem.ON_THIS_DAY) // primaryFrostItem(FbItem.ON_THIS_DAY)
divider() // divider()
primaryFrostItem(FbItem.NOTES) // primaryFrostItem(FbItem.NOTES)
primaryFrostItem(FbItem.SAVED) // primaryFrostItem(FbItem.SAVED)
primaryFrostItem(FbItem.MARKETPLACE) // primaryFrostItem(FbItem.MARKETPLACE)
} // }
} // }
private fun Builder.primaryFrostItem(item: FbItem) = this.primaryItem(item.titleId) { // private fun Builder.primaryFrostItem(item: FbItem) = this.primaryItem(item.titleId) {
iicon = item.icon // iicon = item.icon
iconColor = Prefs.textColor.toLong() // iconColor = Prefs.textColor.toLong()
textColor = Prefs.textColor.toLong() // textColor = Prefs.textColor.toLong()
selectedIconColor = Prefs.textColor.toLong() // selectedIconColor = Prefs.textColor.toLong()
selectedTextColor = Prefs.textColor.toLong() // selectedTextColor = Prefs.textColor.toLong()
selectedColor = 0x00000001.toLong() // selectedColor = 0x00000001.toLong()
identifier = item.titleId.toLong() // identifier = item.titleId.toLong()
onClick { _ -> // onClick { _ ->
frostEvent("Drawer Tab", "name" to item.name) // frostEvent("Drawer Tab", "name" to item.name)
launchWebOverlay(item.url) // launchWebOverlay(item.url)
false // false
} // }
} // }
//
private fun Builder.secondaryFrostItem(@StringRes title: Int, onClick: () -> Unit) = // private fun Builder.secondaryFrostItem(@StringRes title: Int, onClick: () -> Unit) =
this.secondaryItem(title) { // this.secondaryItem(title) {
textColor = Prefs.textColor.toLong() // textColor = Prefs.textColor.toLong()
selectedIconColor = Prefs.textColor.toLong() // selectedIconColor = Prefs.textColor.toLong()
selectedTextColor = Prefs.textColor.toLong() // selectedTextColor = Prefs.textColor.toLong()
selectedColor = 0x00000001.toLong() // selectedColor = 0x00000001.toLong()
identifier = title.toLong() // identifier = title.toLong()
onClick { _ -> onClick(); false } // onClick { _ -> onClick(); false }
} // }
private fun refreshAll() { private fun refreshAll() {
L.d { "Refresh all" } L.d { "Refresh all" }
@ -549,10 +529,10 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
} }
override fun backConsumer(): Boolean { override fun backConsumer(): Boolean {
if (drawer.isDrawerOpen) { // if (drawer.isDrawerOpen) {
drawer.closeDrawer() // drawer.closeDrawer()
return true // return true
} // }
if (currentFragment.onBackPressed()) return true if (currentFragment.onBackPressed()) return true
if (Prefs.exitConfirmation) { if (Prefs.exitConfirmation) {
materialDialog { materialDialog {

View File

@ -1,6 +1,6 @@
<resources> <resources>
<style name="FrostThemeBase" parent="MaterialDrawerTheme.ActionBar"> <style name="FrostTheme" parent="Theme.MaterialComponents.NoActionBar">
<item name="colorPrimary">@color/facebook_blue</item> <item name="colorPrimary">@color/facebook_blue</item>
<item name="colorPrimaryDark">@color/facebook_blue_dark</item> <item name="colorPrimaryDark">@color/facebook_blue_dark</item>
<item name="colorAccent">@android:color/white</item> <item name="colorAccent">@android:color/white</item>
@ -11,12 +11,7 @@
<item name="md_corner_radius">@dimen/dialog_corner_radius</item> <item name="md_corner_radius">@dimen/dialog_corner_radius</item>
</style> </style>
<style name="FrostTheme" parent="@style/FrostThemeBase"> <style name="FrostTheme.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="FrostTheme.Light" parent="MaterialDrawerTheme.Light.DarkToolbar">
<item name="colorPrimary">@color/facebook_blue</item> <item name="colorPrimary">@color/facebook_blue</item>
<item name="colorPrimaryDark">@color/facebook_blue_dark</item> <item name="colorPrimaryDark">@color/facebook_blue_dark</item>
<item name="colorAccent">@android:color/black</item> <item name="colorAccent">@android:color/black</item>