From 43946902504c1aa5c1217e3fe802697566db4c03 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 16 Sep 2017 01:34:45 -0400 Subject: Feature/recents (#290) * Create toggle for aggressive recents * Add toggle --- app/src/main/kotlin/com/pitchedapps/frost/enums/FeedSort.kt | 9 +++++---- .../main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt | 10 +--------- app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt | 7 +++++++ app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt | 2 ++ .../kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt | 5 +++-- app/src/main/res/values/strings_pref_feed.xml | 2 ++ 6 files changed, 20 insertions(+), 15 deletions(-) (limited to 'app') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/enums/FeedSort.kt b/app/src/main/kotlin/com/pitchedapps/frost/enums/FeedSort.kt index 65b3c101..d2de9988 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/enums/FeedSort.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/enums/FeedSort.kt @@ -2,14 +2,15 @@ package com.pitchedapps.frost.enums import android.support.annotation.StringRes import com.pitchedapps.frost.R +import com.pitchedapps.frost.facebook.FbItem /** * Created by Allan Wang on 2017-06-23. */ -enum class FeedSort(@StringRes val textRes: Int) { - DEFAULT(R.string.kau_default), - MOST_RECENT(R.string.most_recent), - TOP(R.string.top_stories); +enum class FeedSort(@StringRes val textRes: Int, val item: FbItem) { + DEFAULT(R.string.kau_default, FbItem.FEED), + MOST_RECENT(R.string.most_recent, FbItem.FEED_MOST_RECENT), + TOP(R.string.top_stories, FbItem.FEED_TOP_STORIES); companion object { val values = values() //save one instance diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt index f0bf2efa..4286be86 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt @@ -31,15 +31,7 @@ class WebFragment : Fragment() { const val REQUEST_REFRESH = 99 operator fun invoke(data: FbItem, position: Int) = WebFragment().apply { - val d = when (data) { - //If is feed, check if sorting method is specified - FbItem.FEED -> when (FeedSort(Prefs.feedSort)) { - FeedSort.DEFAULT -> data - FeedSort.MOST_RECENT -> FbItem.FEED_MOST_RECENT - FeedSort.TOP -> FbItem.FEED_TOP_STORIES - } - else -> data - } + val d = if (data == FbItem.FEED) FeedSort(Prefs.feedSort).item else data withArguments( ARG_URL to d.url, ARG_POSITION to position, 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 cfc2bb6f..3676d39c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt @@ -34,6 +34,13 @@ fun SettingsActivity.getFeedPrefs(): KPrefAdapterBuilder.() -> Unit = { textGetter = { string(FeedSort(it).textRes) } } + checkbox(R.string.aggressive_recents, { Prefs.aggressiveRecents }, { + Prefs.aggressiveRecents = it + setFrostResult(MainActivity.REQUEST_REFRESH) + }) { + descRes = R.string.aggressive_recents_desc + } + plainText(R.string.autoplay_settings) { descRes = R.string.autoplay_settings_desc onClick = { _, _, _ -> launchWebOverlay("https://touch.facebook.com/settings/videos"); true } 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 af605388..18ab874a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -86,6 +86,8 @@ object Prefs : KPref() { var feedSort: Int by kpref("feed_sort", FeedSort.DEFAULT.ordinal) + var aggressiveRecents: Boolean by kpref("aggressive_recents", true) + var showRoundedIcons: Boolean by kpref("rounded_icons", true) var showSuggestedFriends: Boolean by kpref("suggested_friends_feed", true) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt index a961972f..253b4a9b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -11,8 +11,8 @@ import com.pitchedapps.frost.activities.LoginActivity import com.pitchedapps.frost.activities.MainActivity import com.pitchedapps.frost.activities.SelectorActivity import com.pitchedapps.frost.activities.WebOverlayActivity +import com.pitchedapps.frost.enums.FeedSort import com.pitchedapps.frost.facebook.FB_URL_BASE -import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.injectors.* import com.pitchedapps.frost.utils.* @@ -74,7 +74,8 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient CssHider.CORE, CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!Prefs.showSuggestedFriends && IS_FROST_PRO), Prefs.themeInjector, - CssHider.NON_RECENT.maybe(webCore.url?.contains("?sk=h_chr") ?: false)) + CssHider.NON_RECENT.maybe((webCore.url?.contains("?sk=h_chr") ?: false) + && Prefs.aggressiveRecents)) } override fun onPageFinished(view: WebView, url: String?) { diff --git a/app/src/main/res/values/strings_pref_feed.xml b/app/src/main/res/values/strings_pref_feed.xml index 0bd0792b..42aefbbc 100644 --- a/app/src/main/res/values/strings_pref_feed.xml +++ b/app/src/main/res/values/strings_pref_feed.xml @@ -3,6 +3,8 @@ Newsfeed Order Defines the order in which the posts are shown + Aggressive Recents + Filter out additional old posts from Facebook\'s original most recents feed. Disable this if your feed is empty. Video Autoplay Settings Enable/disable video autoplays on data or at all times.\nThese settings are independent of your settings for desktop. Pro Features -- cgit v1.2.3