aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt26
-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/settings/Behaviour.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt19
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt1
6 files changed, 59 insertions, 22 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 2e7c16df..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
@@ -458,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" }
@@ -474,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)
+ }
}
}
@@ -579,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/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 cf7b3d09..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,46 +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 }) {
+ 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