aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt29
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt14
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt19
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt21
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt2
-rw-r--r--app/src/main/res/values/strings_pref_feed.xml2
9 files changed, 70 insertions, 23 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 73bd5b2f..05321b69 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
@@ -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
}
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 34674cb0..fc9eca37 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
@@ -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 ->
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt
index 3007933c..c239bb80 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt
@@ -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
- }
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt
index 72367eaa..7c96235f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt
@@ -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)
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt
index c774892e..31a31238 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt
@@ -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
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt
index c764244b..d1350df5 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt
@@ -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
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt
index c878b6fb..daca9676 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt
@@ -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
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
index 0885109a..eb8e4b35 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
@@ -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)
diff --git a/app/src/main/res/values/strings_pref_feed.xml b/app/src/main/res/values/strings_pref_feed.xml
index d7a15bda..96112059 100644
--- a/app/src/main/res/values/strings_pref_feed.xml
+++ b/app/src/main/res/values/strings_pref_feed.xml
@@ -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>