1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-09-20 07:31:40 +02:00

Merge pull request #1500 from AllanWang/toggle-main-fab

Allow disabling main fab
This commit is contained in:
Allan Wang 2019-08-05 00:38:25 -07:00 committed by GitHub
commit e5b3dbf51b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 70 additions and 23 deletions

View File

@ -88,6 +88,7 @@ import com.pitchedapps.frost.utils.EXTRA_COOKIES
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.MAIN_TIMEOUT_DURATION
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.REQUEST_FAB
import com.pitchedapps.frost.utils.REQUEST_NAV
import com.pitchedapps.frost.utils.REQUEST_REFRESH
import com.pitchedapps.frost.utils.REQUEST_RESTART
@ -113,6 +114,7 @@ import kotlinx.android.synthetic.main.view_main_viewpager.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
import kotlin.math.abs
/**
* Created by Allan Wang on 20/12/17.
@ -206,7 +208,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
fab.hide()
appBar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
if (!hasFab) return@OnOffsetChangedListener
val percent = Math.abs(verticalOffset.toFloat() / appBarLayout.totalScrollRange)
val percent = abs(verticalOffset.toFloat() / appBarLayout.totalScrollRange)
val shouldShow = percent < 0.2
if (this.shouldShow != shouldShow) {
this.shouldShow = shouldShow
@ -457,6 +459,9 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (onActivityResultWeb(requestCode, resultCode, data)) return
super.onActivityResult(requestCode, resultCode, data)
fun hasRequest(flag: Int) = resultCode and flag > 0
if (requestCode == ACTIVITY_SETTINGS) {
if (resultCode and REQUEST_RESTART_APPLICATION > 0) { //completely restart application
L.d { "Restart Application Requested" }
@ -473,10 +478,21 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
/*
* These results can be stacked
*/
if (resultCode and REQUEST_REFRESH > 0) fragmentChannel.offer(REQUEST_REFRESH)
if (resultCode and REQUEST_NAV > 0) frostNavigationBar()
if (resultCode and REQUEST_TEXT_ZOOM > 0) fragmentChannel.offer(REQUEST_TEXT_ZOOM)
if (resultCode and REQUEST_SEARCH > 0) invalidateOptionsMenu()
if (hasRequest(REQUEST_REFRESH)) {
fragmentChannel.offer(REQUEST_REFRESH)
}
if (hasRequest(REQUEST_NAV)) {
frostNavigationBar()
}
if (hasRequest(REQUEST_TEXT_ZOOM)) {
fragmentChannel.offer(REQUEST_TEXT_ZOOM)
}
if (hasRequest(REQUEST_SEARCH)) {
invalidateOptionsMenu()
}
if (hasRequest(REQUEST_FAB)) {
fragmentChannel.offer(lastPosition)
}
}
}
@ -578,8 +594,9 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
viewPager.setCurrentItem(0, false)
viewPager.offscreenPageLimit = pages.size
viewPager.post {
if (!fragmentChannel.isClosedForSend)
if (!fragmentChannel.isClosedForSend) {
fragmentChannel.offer(0)
}
} //trigger hook so title is set
}

View File

@ -45,13 +45,21 @@ class MainActivity : BaseMainActivity() {
viewPager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
if (lastPosition == position) return
if (lastPosition != -1) fragmentChannel.offer(-(lastPosition + 1))
if (lastPosition == position) {
return
}
if (lastPosition != -1) {
fragmentChannel.offer(-(lastPosition + 1))
}
fragmentChannel.offer(position)
lastPosition = position
}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
override fun onPageScrolled(
position: Int,
positionOffset: Float,
positionOffsetPixels: Int
) {
super.onPageScrolled(position, positionOffset, positionOffsetPixels)
val delta = positionOffset * (SELECTED_TAB_ALPHA - UNSELECTED_TAB_ALPHA)
tabsForEachView { tabPosition, view ->

View File

@ -51,6 +51,7 @@ import com.pitchedapps.frost.settings.getSecurityPrefs
import com.pitchedapps.frost.settings.sendDebug
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.REQUEST_REFRESH
import com.pitchedapps.frost.utils.REQUEST_RESTART
import com.pitchedapps.frost.utils.cookies
import com.pitchedapps.frost.utils.frostChangelog
@ -104,7 +105,11 @@ class SettingsActivity : KPrefActivity() {
val uriString: String = uri?.toString() ?: ""
if (uri != null) {
try {
grantUriPermission("com.android.systemui", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
grantUriPermission(
"com.android.systemui",
uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION
)
} catch (e: Exception) {
L.e(e) { "grantUriPermission" }
}
@ -193,10 +198,18 @@ class SettingsActivity : KPrefActivity() {
}
}
fun setFrostResult(flag: Int) {
resultFlag = resultFlag or flag
}
fun shouldRestartMain() {
setFrostResult(REQUEST_RESTART)
}
fun shouldRefreshMain() {
setFrostResult(REQUEST_REFRESH)
}
@SuppressLint("MissingSuperCall")
override fun onCreate(savedInstanceState: Bundle?) {
setFrostTheme(true)
@ -247,8 +260,4 @@ class SettingsActivity : KPrefActivity() {
}
return true
}
fun setFrostResult(flag: Int) {
resultFlag = resultFlag or flag
}
}

View File

@ -23,6 +23,7 @@ import com.pitchedapps.frost.contracts.MainFabContract
import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.injectors.JsActions
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.views.FrostWebView
import com.pitchedapps.frost.web.FrostWebViewClient
import com.pitchedapps.frost.web.FrostWebViewClientMenu
@ -51,7 +52,7 @@ class WebFragment : BaseFragment() {
L.e { "Webview not found in fragment $baseEnum" }
return super.updateFab(contract)
}
if (baseEnum.isFeed) {
if (baseEnum.isFeed && Prefs.showCreateFab) {
contract.showFab(GoogleMaterial.Icon.gmd_edit) {
JsActions.CREATE_POST.inject(web)
}

View File

@ -40,7 +40,7 @@ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = {
checkbox(
R.string.overlay_swipe,
Prefs::overlayEnabled,
{ Prefs.overlayEnabled = it; setFrostResult(REQUEST_REFRESH) }) {
{ Prefs.overlayEnabled = it; shouldRefreshMain() }) {
descRes = R.string.overlay_swipe_desc
}

View File

@ -24,7 +24,7 @@ import com.pitchedapps.frost.R
import com.pitchedapps.frost.activities.SettingsActivity
import com.pitchedapps.frost.enums.FeedSort
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.REQUEST_REFRESH
import com.pitchedapps.frost.utils.REQUEST_FAB
/**
* Created by Allan Wang on 2017-06-29.
@ -52,42 +52,49 @@ fun SettingsActivity.getFeedPrefs(): KPrefAdapterBuilder.() -> Unit = {
checkbox(R.string.aggressive_recents, Prefs::aggressiveRecents, {
Prefs.aggressiveRecents = it
setFrostResult(REQUEST_REFRESH)
shouldRefreshMain()
}) {
descRes = R.string.aggressive_recents_desc
}
checkbox(R.string.composer, Prefs::showComposer, {
Prefs.showComposer = it
setFrostResult(REQUEST_REFRESH)
shouldRefreshMain()
}) {
descRes = R.string.composer_desc
}
checkbox(R.string.create_fab, Prefs::showCreateFab, {
Prefs.showCreateFab = it
setFrostResult(REQUEST_FAB)
}) {
descRes = R.string.create_fab_desc
}
checkbox(R.string.suggested_friends, Prefs::showSuggestedFriends, {
Prefs.showSuggestedFriends = it
setFrostResult(REQUEST_REFRESH)
shouldRefreshMain()
}) {
descRes = R.string.suggested_friends_desc
}
checkbox(R.string.suggested_groups, Prefs::showSuggestedGroups, {
Prefs.showSuggestedGroups = it
setFrostResult(REQUEST_REFRESH)
shouldRefreshMain()
}) {
descRes = R.string.suggested_groups_desc
}
checkbox(R.string.show_stories, Prefs::showStories, {
Prefs.showStories = it
setFrostResult(REQUEST_REFRESH)
shouldRefreshMain()
}) {
descRes = R.string.show_stories_desc
}
checkbox(R.string.facebook_ads, Prefs::showFacebookAds, {
Prefs.showFacebookAds = it
setFrostResult(REQUEST_REFRESH)
shouldRefreshMain()
}) {
descRes = R.string.facebook_ads_desc
}

View File

@ -31,5 +31,6 @@ const val REQUEST_REFRESH = 1 shl 7
const val REQUEST_TEXT_ZOOM = 1 shl 8
const val REQUEST_NAV = 1 shl 9
const val REQUEST_SEARCH = 1 shl 10
const val REQUEST_FAB = 1 shl 11
const val MAIN_TIMEOUT_DURATION = 30 * 60 * 1000 // 30 min

View File

@ -189,6 +189,8 @@ object Prefs : KPref() {
var autoRefreshFeed: Boolean by kpref("auto_refresh_feed", false)
var showCreateFab: Boolean by kpref("show_create_fab", true)
inline val mainActivityLayout: MainActivityLayout
get() = MainActivityLayout(mainActivityLayoutType)

View File

@ -7,6 +7,8 @@
<string name="aggressive_recents_desc">Filter out additional old posts from Facebook\'s original most recents feed. Disable this if your feed is empty.</string>
<string name="composer">Status Composer</string>
<string name="composer_desc">Show status composer in the feed</string>
<string name="create_fab">Create FAB</string>
<string name="create_fab_desc">Show FAB in feed to create new post</string>
<string name="suggested_friends">Suggested Friends</string>
<string name="suggested_friends_desc">Show "People You May Know" in the feed</string>