diff options
author | Allan Wang <me@allanwang.ca> | 2019-09-08 00:51:13 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2019-09-08 00:51:13 -0700 |
commit | 8cf499946b0e0b52c8d66b2b213982f75e4ee91d (patch) | |
tree | 851cc6cf0fd295c142be123a19320b578fc8be0a /app/src/main/kotlin/com | |
parent | 329b31175289fc7ad204204e6f7276fd96530f99 (diff) | |
parent | ea3a1968407ef66c3074593d6768a559e18b0675 (diff) | |
download | frost-8cf499946b0e0b52c8d66b2b213982f75e4ee91d.tar.gz frost-8cf499946b0e0b52c8d66b2b213982f75e4ee91d.tar.bz2 frost-8cf499946b0e0b52c8d66b2b213982f75e4ee91d.zip |
Merge branch 'dev' into theme
Diffstat (limited to 'app/src/main/kotlin/com')
27 files changed, 67 insertions, 295 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt index 2ebdd215..7a4472b4 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt @@ -30,10 +30,7 @@ import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.signature.ApplicationVersionSignature import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader import com.mikepenz.materialdrawer.util.DrawerImageLoader -import com.pitchedapps.frost.db.CookiesDb -import com.pitchedapps.frost.db.FbTabsDb import com.pitchedapps.frost.db.FrostDatabase -import com.pitchedapps.frost.db.NotificationDb import com.pitchedapps.frost.glide.GlideApp import com.pitchedapps.frost.services.scheduleNotificationsFromPrefs import com.pitchedapps.frost.services.setupNotificationChannels @@ -42,15 +39,10 @@ import com.pitchedapps.frost.utils.FrostPglAdBlock import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.Showcase -import com.raizlabs.android.dbflow.config.DatabaseConfig -import com.raizlabs.android.dbflow.config.FlowConfig -import com.raizlabs.android.dbflow.config.FlowManager -import com.raizlabs.android.dbflow.runtime.ContentResolverNotifier import org.koin.android.ext.koin.androidContext import org.koin.android.ext.koin.androidLogger import org.koin.core.context.startKoin import java.util.Random -import kotlin.reflect.KClass /** * Created by Allan Wang on 2017-05-28. @@ -63,27 +55,12 @@ class FrostApp : Application() { // lateinit var refWatcher: RefWatcher - private fun FlowConfig.Builder.withDatabase(name: String, klass: KClass<*>) = - addDatabaseConfig( - DatabaseConfig.builder(klass.java) - .databaseName(name) - .modelNotifier(ContentResolverNotifier("${BuildConfig.APPLICATION_ID}.dbflow.provider")) - .build() - ) - override fun onCreate() { if (!buildIsLollipopAndUp) { // not supported super.onCreate() return } - FlowManager.init( - FlowConfig.Builder(this) - .withDatabase(CookiesDb.NAME, CookiesDb::class) - .withDatabase(FbTabsDb.NAME, FbTabsDb::class) - .withDatabase(NotificationDb.NAME, NotificationDb::class) - .build() - ) // if (LeakCanary.isInAnalyzerProcess(this)) return // refWatcher = LeakCanary.install(this) initPrefs() diff --git a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt index 61b4a194..e5b6d49a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt @@ -34,12 +34,7 @@ import com.pitchedapps.frost.activities.MainActivity import com.pitchedapps.frost.activities.SelectorActivity import com.pitchedapps.frost.db.CookieDao import com.pitchedapps.frost.db.CookieEntity -import com.pitchedapps.frost.db.CookieModel -import com.pitchedapps.frost.db.FbTabModel import com.pitchedapps.frost.db.GenericDao -import com.pitchedapps.frost.db.getTabs -import com.pitchedapps.frost.db.save -import com.pitchedapps.frost.db.saveTabs import com.pitchedapps.frost.db.selectAll import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.utils.BiometricUtils @@ -48,11 +43,7 @@ import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.launchNewTask import com.pitchedapps.frost.utils.loadAssets -import com.raizlabs.android.dbflow.kotlinextensions.from -import com.raizlabs.android.dbflow.kotlinextensions.select -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import org.koin.android.ext.android.inject import java.util.ArrayList @@ -82,7 +73,6 @@ class StartActivity : KauBaseActivity() { launch { val authDefer = BiometricUtils.authenticate(this@StartActivity) try { - migrate() FbCookie.switchBackUser() val cookies = ArrayList(cookieDao.selectAll()) L.i { "Cookies loaded at time ${System.currentTimeMillis()}" } @@ -111,27 +101,6 @@ class StartActivity : KauBaseActivity() { } } - /** - * Migrate from dbflow to room - * TODO delete dbflow data - */ - private suspend fun migrate() = withContext(Dispatchers.IO) { - if (cookieDao.selectAll().isNotEmpty()) return@withContext - val cookies = (select from CookieModel::class).queryList() - .map { CookieEntity(it.id, it.name, it.cookie) } - if (cookies.isNotEmpty()) { - cookieDao.save(cookies) - L._d { "Migrated cookies ${cookieDao.selectAll()}" } - } - val tabs = (select from FbTabModel::class).queryList().map(FbTabModel::tab) - if (tabs.isNotEmpty()) { - genericDao.saveTabs(tabs) - L._d { "Migrated tabs ${genericDao.getTabs()}" } - } - deleteDatabase("Cookies.db") - deleteDatabase("FrostTabs.db") - } - private fun showInvalidWebView() = showInvalidView(R.string.error_webview) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt index e2ccb8e5..4b98c6c9 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt @@ -68,7 +68,6 @@ class AboutActivity : AboutActivityBase(null, { val include = arrayOf( "AboutLibraries", "AndroidIconics", - "dbflow", "fastadapter", "glide", "Jsoup", diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt index b3ef9bd4..d82084d5 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt @@ -16,7 +16,6 @@ */ package com.pitchedapps.frost.activities -import android.annotation.SuppressLint import android.content.Intent import android.graphics.PointF import android.net.Uri @@ -60,7 +59,6 @@ import com.pitchedapps.frost.enums.OverlayContext import com.pitchedapps.frost.facebook.FB_URL_BASE import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem -import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.kotlin.subscribeDuringJob import com.pitchedapps.frost.services.FrostRunnable @@ -94,7 +92,7 @@ import okhttp3.HttpUrl * Going back will bring you back to the previous app */ @UseExperimental(ExperimentalCoroutinesApi::class) -class FrostWebActivity : WebOverlayActivityBase(false) { +class FrostWebActivity : WebOverlayActivityBase() { override fun onCreate(savedInstanceState: Bundle?) { val requiresAction = !parseActionSend() @@ -143,19 +141,12 @@ class FrostWebActivity : WebOverlayActivityBase(false) { } /** - * Variant that forces a desktop user agent. This is largely internal, - * and is only necessary when we are launching from an existing [WebOverlayActivityBase] - */ -class WebOverlayDesktopActivity : WebOverlayActivityBase(true) - -/** * Internal overlay for the app; this is tied with the main task and is singleTop as opposed to singleInstance */ -class WebOverlayActivity : WebOverlayActivityBase(false) +class WebOverlayActivity : WebOverlayActivityBase() -@SuppressLint("Registered") @UseExperimental(ExperimentalCoroutinesApi::class) -open class WebOverlayActivityBase(private val forceDesktopAgent: Boolean) : BaseActivity(), +abstract class WebOverlayActivityBase : BaseActivity(), ActivityContract, FrostContentContainer, VideoViewHolder, FileChooserContract by FileChooserDelegate() { @@ -217,8 +208,6 @@ open class WebOverlayActivityBase(private val forceDesktopAgent: Boolean) : Base } with(web) { - if (forceDesktopAgent) //todo check; the webview already adds it dynamically - userAgentString = USER_AGENT_DESKTOP Prefs.prevId = Prefs.userId launch { val authDefer = BiometricUtils.authenticate(this@WebOverlayActivityBase) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt index 82548396..d90ff3de 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt @@ -24,11 +24,6 @@ import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import com.pitchedapps.frost.utils.Prefs -import com.raizlabs.android.dbflow.annotation.ConflictAction -import com.raizlabs.android.dbflow.annotation.Database -import com.raizlabs.android.dbflow.annotation.PrimaryKey -import com.raizlabs.android.dbflow.annotation.Table -import com.raizlabs.android.dbflow.structure.BaseModel import kotlinx.android.parcel.Parcelize /** @@ -74,21 +69,3 @@ suspend fun CookieDao.save(cookie: CookieEntity) = dao { _save(cookie) } suspend fun CookieDao.save(cookies: List<CookieEntity>) = dao { _save(cookies) } suspend fun CookieDao.deleteById(id: Long) = dao { _deleteById(id) } suspend fun CookieDao.currentCookie() = selectById(Prefs.userId) - -@Database(version = CookiesDb.VERSION) -object CookiesDb { - const val NAME = "Cookies" - const val VERSION = 2 -} - -@Parcelize -@Table(database = CookiesDb::class, allFields = true, primaryKeyConflict = ConflictAction.REPLACE) -data class CookieModel( - @PrimaryKey var id: Long = -1L, - var name: String? = null, - var cookie: String? = null -) : - BaseModel(), Parcelable { - - override fun toString(): String = "CookieModel(${hashCode()})" -} diff --git a/app/src/main/kotlin/com/pitchedapps/frost/db/FbTabsDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/db/FbTabsDb.kt deleted file mode 100644 index 475d134f..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/db/FbTabsDb.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2018 Allan Wang - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -package com.pitchedapps.frost.db - -import com.pitchedapps.frost.facebook.FbItem -import com.raizlabs.android.dbflow.annotation.Database -import com.raizlabs.android.dbflow.annotation.PrimaryKey -import com.raizlabs.android.dbflow.annotation.Table -import com.raizlabs.android.dbflow.structure.BaseModel - -/** - * Created by Allan Wang on 2017-05-30. - */ - -const val TAB_COUNT = 4 - -@Database(version = FbTabsDb.VERSION) -object FbTabsDb { - const val NAME = "FrostTabs" - const val VERSION = 1 -} - -@Table(database = FbTabsDb::class, allFields = true) -data class FbTabModel(@PrimaryKey var position: Int = -1, var tab: FbItem = FbItem.FEED) : - BaseModel() diff --git a/app/src/main/kotlin/com/pitchedapps/frost/db/GenericDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/db/GenericDb.kt index f36c8af9..b7274c33 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/db/GenericDb.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/db/GenericDb.kt @@ -56,6 +56,8 @@ interface GenericDao { } } +const val TAB_COUNT = 4 + suspend fun GenericDao.saveTabs(tabs: List<FbItem>) = dao { val content = tabs.joinToString(",") { it.name } _save(GenericEntity(GenericDao.TYPE_TABS, content)) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt index e89bf46d..93df01dc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt @@ -26,22 +26,8 @@ import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import androidx.room.Transaction -import com.pitchedapps.frost.services.NOTIF_CHANNEL_GENERAL -import com.pitchedapps.frost.services.NOTIF_CHANNEL_MESSAGES import com.pitchedapps.frost.services.NotificationContent import com.pitchedapps.frost.utils.L -import com.raizlabs.android.dbflow.annotation.ConflictAction -import com.raizlabs.android.dbflow.annotation.Database -import com.raizlabs.android.dbflow.annotation.Migration -import com.raizlabs.android.dbflow.annotation.PrimaryKey -import com.raizlabs.android.dbflow.annotation.Table -import com.raizlabs.android.dbflow.kotlinextensions.eq -import com.raizlabs.android.dbflow.kotlinextensions.from -import com.raizlabs.android.dbflow.kotlinextensions.select -import com.raizlabs.android.dbflow.kotlinextensions.where -import com.raizlabs.android.dbflow.sql.SQLiteType -import com.raizlabs.android.dbflow.sql.migration.AlterTableMigration -import com.raizlabs.android.dbflow.structure.BaseModel @Entity( tableName = "notifications", @@ -164,46 +150,5 @@ suspend fun NotificationDao.saveNotifications( } suspend fun NotificationDao.latestEpoch(userId: Long, type: String): Long = dao { - _selectEpoch(userId, type) ?: lastNotificationTime(userId).let { - when (type) { - NOTIF_CHANNEL_GENERAL -> it.epoch - NOTIF_CHANNEL_MESSAGES -> it.epochIm - else -> -1L - } - } -} - -/** - * Created by Allan Wang on 2017-05-30. - */ - -@Database(version = NotificationDb.VERSION) -object NotificationDb { - const val NAME = "Notifications" - const val VERSION = 2 + _selectEpoch(userId, type) ?: -1L } - -@Migration(version = 2, database = NotificationDb::class) -class NotificationMigration2(modelClass: Class<NotificationModel>) : - AlterTableMigration<NotificationModel>(modelClass) { - override fun onPreMigrate() { - super.onPreMigrate() - addColumn(SQLiteType.INTEGER, "epochIm") - L.d { "Added column" } - } -} - -@Table( - database = NotificationDb::class, - allFields = true, - primaryKeyConflict = ConflictAction.REPLACE -) -data class NotificationModel( - @PrimaryKey var id: Long = -1L, - var epoch: Long = -1L, - var epochIm: Long = -1L -) : BaseModel() - -internal fun lastNotificationTime(id: Long): NotificationModel = - (select from NotificationModel::class where (NotificationModel_Table.id eq id)).querySingle() - ?: NotificationModel(id = id) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt b/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt index 8215de03..bc453250 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt @@ -19,7 +19,7 @@ package com.pitchedapps.frost.debugger import ca.allanwang.kau.logging.KauLoggerExtension import ca.allanwang.kau.utils.copyFromInputStream import com.pitchedapps.frost.facebook.FB_CSS_URL_MATCHER -import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP +import com.pitchedapps.frost.facebook.USER_AGENT import com.pitchedapps.frost.facebook.get import com.pitchedapps.frost.facebook.requests.call import com.pitchedapps.frost.utils.createFreshDir @@ -59,7 +59,7 @@ class OfflineWebsite( * Directory that holds all the files */ val baseDir: File, - private val userAgent: String = USER_AGENT_DESKTOP + private val userAgent: String = USER_AGENT ) { /** diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt index 032ff31e..c01bce55 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt @@ -28,6 +28,13 @@ fun profilePictureUrl(id: Long) = "https://graph.facebook.com/$id/picture?type=l const val FB_LOGIN_URL = "${FB_URL_BASE}login" const val FB_HOME_URL = "${FB_URL_BASE}home.php" +/* + * User agent candidates. + * For those building from source, you can feel free to set the used agent to one of these options. + * Following https://github.com/AllanWang/Frost-for-Facebook/pull/1531, we do not support multiple + * agents per login session. + */ + // Default user agent private const val USER_AGENT_MOBILE_CONST = "Mozilla/5.0 (Linux; Android 8.0.0; ONEPLUS A3000) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.90 Mobile Safari/537.36" @@ -35,8 +42,7 @@ private const val USER_AGENT_MOBILE_CONST = private const val USER_AGENT_DESKTOP_CONST = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.90 Safari/537.36" -const val USER_AGENT_MOBILE = USER_AGENT_DESKTOP_CONST -const val USER_AGENT_DESKTOP = USER_AGENT_DESKTOP_CONST +const val USER_AGENT = USER_AGENT_DESKTOP_CONST /** * Animation transition delay, just to ensure that the styles diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt index 16cbc9c8..2095f8fd 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt @@ -137,7 +137,20 @@ class FbUrlFormatter(url: String) { * * acontext is not required for "friends interested in" notifications */ - val discardableQueries = arrayOf("ref", "refid", "SharedWith", "fbclid") + val discardableQueries = arrayOf( + "ref", + "refid", + "SharedWith", + "fbclid", + "_ft_", + "_tn_", + "_xt_", + "bacr", + "frefs", + "hc_ref", + "loc_ref", + "pn_ref" + ) val converter = listOf( "\\3C " to "%3C", "\\3E " to "%3E", "\\23 " to "%23", "\\25 " to "%25", diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt index 8a89b973..b948506f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt @@ -22,7 +22,7 @@ import com.pitchedapps.frost.facebook.FB_JSON_URL_MATCHER import com.pitchedapps.frost.facebook.FB_REV_MATCHER import com.pitchedapps.frost.facebook.FB_URL_BASE import com.pitchedapps.frost.facebook.FB_USER_MATCHER -import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP +import com.pitchedapps.frost.facebook.USER_AGENT import com.pitchedapps.frost.facebook.get import com.pitchedapps.frost.kotlin.Flyweight import com.pitchedapps.frost.utils.L @@ -97,7 +97,7 @@ internal fun List<Pair<String, Any?>>.withEmptyData(vararg key: String): List<Pa internal fun String?.requestBuilder(): Request.Builder { val builder = Request.Builder() - .header("User-Agent", USER_AGENT_DESKTOP) + .header("User-Agent", USER_AGENT) if (this != null) builder.header("Cookie", this) // .cacheControl(CacheControl.FORCE_NETWORK) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt index c580c9ed..50bae16c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt @@ -67,7 +67,7 @@ abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract, Dyna data: FbItem, position: Int ): BaseFragment { - val fragment = if (useFallback || Prefs.webOnly) WebFragment() else base() + val fragment = if (useFallback || !Prefs.nativeUi) WebFragment() else base() val d = if (data == FbItem.FEED) FeedSort(Prefs.feedSort).item else data fragment.withArguments( ARG_URL to d.url, diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt index cab1311c..6ff20bfb 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt @@ -144,7 +144,6 @@ enum class NotificationType( if (notifContents.isEmpty()) return 0 val userId = data.id - // Legacy, remove with dbflow val prevLatestEpoch = notifDao.latestEpoch(userId, channelId) L.v { "Notif $name prev epoch $prevLatestEpoch" } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostRequestService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostRequestService.kt index fe59c421..77546971 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostRequestService.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostRequestService.kt @@ -163,8 +163,8 @@ class FrostRequestService : BaseJobService() { override fun onStartJob(params: JobParameters?): Boolean { super.onStartJob(params) - if (Prefs.webOnly) { - L.i { "Web only; skipping request service" } + if (!Prefs.authRequests) { + L.i { "Auth requests disabled; skipping request service" } return false } val bundle = params?.extras diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt index 091fbb4b..95726974 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt @@ -72,10 +72,6 @@ class NotificationService : BaseJobService() { override fun onStartJob(params: JobParameters?): Boolean { super.onStartJob(params) L.i { "Fetching notifications" } - if (Prefs.webOnly) { - L.i { "Web only mode; skipping notification service" } - return false - } launch { try { sendNotifications(params) 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 ba5b839b..a0a8117f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt @@ -79,6 +79,13 @@ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = { } } + checkbox(R.string.native_ui, Prefs::nativeUi, { + Prefs.nativeUi = it + shouldRestartMain() + }) { + descRes = R.string.native_ui_desc + } + checkbox(R.string.exit_confirmation, Prefs::exitConfirmation, { Prefs.exitConfirmation = it }) { descRes = R.string.exit_confirmation_desc } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt index d0963665..5647584e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt @@ -23,7 +23,6 @@ import com.pitchedapps.frost.R import com.pitchedapps.frost.activities.SettingsActivity import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.REQUEST_RESTART_APPLICATION -import com.pitchedapps.frost.utils.Showcase /** * Created by Allan Wang on 2017-06-29. @@ -34,20 +33,10 @@ fun SettingsActivity.getExperimentalPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.experimental_disclaimer_info } - checkbox( - R.string.experimental_by_default, - Showcase::experimentalDefault, - { Showcase.experimentalDefault = it }) { - descRes = R.string.experimental_by_default_desc - } - // Experimental content starts here ------------------ - checkbox(R.string.web_only, Prefs::webOnly, { - Prefs.webOnly = it - shouldRestartMain() - }) { - descRes = R.string.web_only_desc + checkbox(R.string.auth_requests, Prefs::authRequests, { Prefs.authRequests = it }) { + descRes = R.string.auth_requests_desc } // Experimental content ends here -------------------- diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt index ccf04935..9fcf2e96 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt @@ -22,7 +22,6 @@ import android.media.RingtoneManager import android.os.Build import android.provider.Settings import ca.allanwang.kau.kpref.activity.KPrefAdapterBuilder -import ca.allanwang.kau.kpref.activity.KPrefItemActions import ca.allanwang.kau.kpref.activity.items.KPrefText import ca.allanwang.kau.utils.materialDialog import ca.allanwang.kau.utils.minuteToText @@ -48,25 +47,11 @@ import kotlinx.coroutines.launch */ val Prefs.hasNotifications: Boolean - get() = !webOnly && (notificationsGeneral || notificationsInstantMessages) + get() = notificationsGeneral || notificationsInstantMessages @SuppressLint("InlinedApi") fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { - fun KPrefItemActions.leaveWebOnlyDialog() { - if (Prefs.webOnly) { - materialDialog { - title(R.string.leave_web_only_title) - message(R.string.leave_web_only_desc) - positiveButton(R.string.kau_yes) { - Prefs.webOnly = false - reload() - } - negativeButton(R.string.kau_no) - } - } - } - text( R.string.notification_frequency, Prefs::notificationFreq, @@ -86,9 +71,6 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { } } } - onDisabledClick = { - leaveWebOnlyDialog() - } enabler = { Prefs.hasNotifications } textGetter = { minuteToText(it) } } @@ -114,19 +96,12 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { reloadByTitle(R.string.notification_frequency) }) { descRes = R.string.notification_general_desc - enabler = { !Prefs.webOnly } - onDisabledClick = { - leaveWebOnlyDialog() - } } checkbox(R.string.notification_general_all_accounts, Prefs::notificationAllAccounts, { Prefs.notificationAllAccounts = it }) { descRes = R.string.notification_general_all_accounts_desc - enabler = { !Prefs.webOnly && Prefs.notificationsGeneral } - onDisabledClick = { - leaveWebOnlyDialog() - } + enabler = { Prefs.notificationsGeneral } } checkbox(R.string.notification_messages, Prefs::notificationsInstantMessages, @@ -137,19 +112,12 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { reloadByTitle(R.string.notification_frequency) }) { descRes = R.string.notification_messages_desc - enabler = { !Prefs.webOnly } - onDisabledClick = { - leaveWebOnlyDialog() - } } checkbox(R.string.notification_messages_all_accounts, Prefs::notificationsImAllAccounts, { Prefs.notificationsImAllAccounts = it }) { descRes = R.string.notification_messages_all_accounts_desc - enabler = { !Prefs.webOnly && Prefs.notificationsInstantMessages } - onDisabledClick = { - leaveWebOnlyDialog() - } + enabler = { Prefs.notificationsInstantMessages } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt index b0012b0d..5e909b03 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt @@ -31,7 +31,7 @@ import ca.allanwang.kau.utils.string import ca.allanwang.kau.utils.toast import com.pitchedapps.frost.R import com.pitchedapps.frost.db.CookieEntity -import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP +import com.pitchedapps.frost.facebook.USER_AGENT /** * Created by Allan Wang on 2017-08-04. @@ -41,7 +41,7 @@ import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP fun Context.frostDownload( cookie: CookieEntity, url: String?, - userAgent: String = USER_AGENT_DESKTOP, + userAgent: String = USER_AGENT, contentDisposition: String? = null, mimeType: String? = null, contentLength: Long = 0L @@ -53,7 +53,7 @@ fun Context.frostDownload( fun Context.frostDownload( cookie: CookieEntity, uri: Uri?, - userAgent: String = USER_AGENT_DESKTOP, + userAgent: String = USER_AGENT, contentDisposition: String? = null, mimeType: String? = null, contentLength: Long = 0L 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 f17645d0..522e1733 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -191,7 +191,9 @@ object Prefs : KPref() { var showCreateFab: Boolean by kpref("show_create_fab", true) - var webOnly: Boolean by kpref("web_only", false) + var authRequests: Boolean by kpref("web_requests", false) + + var nativeUi: Boolean by kpref("native_ui", true) inline val mainActivityLayout: MainActivityLayout get() = MainActivityLayout(mainActivityLayoutType) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Showcase.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Showcase.kt index df48bfbc..f69af40b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Showcase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Showcase.kt @@ -30,8 +30,5 @@ object Showcase : KPref() { val intro: Boolean by kprefSingle("intro_pages") - //not a showcase but cannot be in the same file as Prefs - var experimentalDefault: Boolean by kpref("experimental_by_default", false) - - override fun deleteKeys() = arrayOf("shown_release") + override fun deleteKeys() = arrayOf("shown_release", "experimental_by_default") } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt index 0367457e..c2f28a4b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -57,14 +57,13 @@ import com.pitchedapps.frost.activities.SettingsActivity import com.pitchedapps.frost.activities.TabCustomizerActivity import com.pitchedapps.frost.activities.WebOverlayActivity import com.pitchedapps.frost.activities.WebOverlayActivityBase -import com.pitchedapps.frost.activities.WebOverlayDesktopActivity import com.pitchedapps.frost.db.CookieEntity import com.pitchedapps.frost.facebook.FACEBOOK_COM import com.pitchedapps.frost.facebook.FBCDN_NET import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.facebook.FbUrlFormatter.Companion.VIDEO_REDIRECT -import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP +import com.pitchedapps.frost.facebook.USER_AGENT import com.pitchedapps.frost.facebook.formattedFbUri import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.injectors.CssAssets @@ -75,6 +74,7 @@ import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import org.apache.commons.text.StringEscapeUtils import org.jsoup.Jsoup +import org.jsoup.nodes.Document import org.jsoup.nodes.Element import java.io.File import java.io.IOException @@ -138,9 +138,6 @@ private inline fun <reified T : WebOverlayActivityBase> Context.launchWebOverlay fun Context.launchWebOverlay(url: String) = launchWebOverlayImpl<WebOverlayActivity>(url) -fun Context.launchWebOverlayDesktop(url: String) = - launchWebOverlayImpl<WebOverlayDesktopActivity>(url) - private fun Context.fadeBundle() = ActivityOptions.makeCustomAnimation( this, android.R.anim.fade_in, android.R.anim.fade_out @@ -392,13 +389,13 @@ fun EmailBuilder.addFrostDetails() { addItem("Locale", Locale.getDefault().displayName) } -fun frostJsoup(url: String) = frostJsoup(FbCookie.webCookie, url) +fun frostJsoup(url: String): Document = frostJsoup(FbCookie.webCookie, url) -fun frostJsoup(cookie: String?, url: String) = +fun frostJsoup(cookie: String?, url: String): Document = Jsoup.connect(url).run { if (cookie.isNullOrBlank()) this else cookie(FACEBOOK_COM, cookie) - }.userAgent(USER_AGENT_DESKTOP).get()!! + }.userAgent(USER_AGENT).get() fun Element.first(vararg select: String): Element? { select.forEach { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt index cbcd1054..5b564102 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt @@ -31,9 +31,7 @@ import com.pitchedapps.frost.contracts.FrostContentParent import com.pitchedapps.frost.db.FrostDatabase import com.pitchedapps.frost.db.currentCookie import com.pitchedapps.frost.facebook.FB_HOME_URL -import com.pitchedapps.frost.facebook.FbItem -import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP -import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE +import com.pitchedapps.frost.facebook.USER_AGENT import com.pitchedapps.frost.fragments.WebFragment import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.ctxCoroutine @@ -42,7 +40,6 @@ import com.pitchedapps.frost.web.FrostChromeClient import com.pitchedapps.frost.web.FrostJSI import com.pitchedapps.frost.web.FrostWebViewClient import com.pitchedapps.frost.web.NestedWebView -import com.pitchedapps.frost.web.shouldUseDesktopAgent import kotlin.math.abs import kotlin.math.max import kotlin.math.min @@ -72,9 +69,7 @@ class FrostWebView @JvmOverloads constructor( @SuppressLint("SetJavaScriptEnabled") override fun bind(container: FrostContentContainer): View { - userAgentString = - if (parent.baseEnum == FbItem.MESSAGES || parent.baseUrl.shouldUseDesktopAgent) USER_AGENT_DESKTOP - else USER_AGENT_MOBILE + userAgentString = USER_AGENT with(settings) { javaScriptEnabled = true mediaPlaybackRequiresUserGesture = false // TODO check if we need this diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt index c66180ed..b71f9950 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt @@ -24,7 +24,7 @@ import android.util.AttributeSet import android.view.View import android.webkit.WebView import ca.allanwang.kau.utils.withAlpha -import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE +import com.pitchedapps.frost.facebook.USER_AGENT import com.pitchedapps.frost.injectors.CssHider import com.pitchedapps.frost.injectors.jsInject import com.pitchedapps.frost.utils.L @@ -55,7 +55,7 @@ class DebugWebView @JvmOverloads constructor( @SuppressLint("SetJavaScriptEnabled") private fun setupWebview() { settings.javaScriptEnabled = true - settings.userAgentString = USER_AGENT_MOBILE + settings.userAgentString = USER_AGENT setLayerType(View.LAYER_TYPE_HARDWARE, null) webViewClient = DebugClient() @Suppress("DEPRECATION") diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt index 4aa43b49..24608a8b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt @@ -22,7 +22,6 @@ import com.pitchedapps.frost.activities.WebOverlayActivityBase import com.pitchedapps.frost.contracts.VideoViewHolder import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem -import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs @@ -32,7 +31,6 @@ import com.pitchedapps.frost.utils.isIndirectImageUrl import com.pitchedapps.frost.utils.isVideoUrl import com.pitchedapps.frost.utils.launchImageActivity import com.pitchedapps.frost.utils.launchWebOverlay -import com.pitchedapps.frost.utils.launchWebOverlayDesktop import com.pitchedapps.frost.views.FrostWebView /** @@ -74,22 +72,7 @@ fun FrostWebView.requestWebOverlay(url: String): Boolean { return false } if (!Prefs.overlayEnabled) return false - if (context is WebOverlayActivityBase) { - val shouldUseDesktop = url.formattedFbUrl.shouldUseDesktopAgent - //already overlay; manage user agent - if (userAgentString != USER_AGENT_DESKTOP && shouldUseDesktop) { - L._i { "Switch to desktop agent overlay" } - context.launchWebOverlayDesktop(url) - return true - } - if (userAgentString == USER_AGENT_DESKTOP && !shouldUseDesktop) { - L._i { "Switch from desktop agent" } - context.launchWebOverlay(url) - return true - } - L._i { "return false switch" } - return false - } + if (context is WebOverlayActivityBase) return false L.v { "Request web overlay passed" } context.launchWebOverlay(url) return true @@ -102,6 +85,7 @@ val messageWhitelist: Set<String> = setOf(FbItem.MESSAGES, FbItem.CHAT, FbItem.FEED_MOST_RECENT, FbItem.FEED_TOP_STORIES) .mapTo(mutableSetOf(), FbItem::url) +@Deprecated(message = "Should not be used in production as we only support one user agent at a time.") val String.shouldUseDesktopAgent: Boolean get() = when { contains("story.php") -> false // do not use desktop for comment section diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt index 8e437c29..857c166d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -33,7 +33,7 @@ import com.pitchedapps.frost.db.CookieEntity import com.pitchedapps.frost.facebook.FB_LOGIN_URL import com.pitchedapps.frost.facebook.FB_USER_MATCHER import com.pitchedapps.frost.facebook.FbCookie -import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE +import com.pitchedapps.frost.facebook.USER_AGENT import com.pitchedapps.frost.facebook.get import com.pitchedapps.frost.injectors.CssHider import com.pitchedapps.frost.injectors.jsInject @@ -58,7 +58,7 @@ class LoginWebView @JvmOverloads constructor( @SuppressLint("SetJavaScriptEnabled") private fun setupWebview() { settings.javaScriptEnabled = true - settings.userAgentString = USER_AGENT_MOBILE + settings.userAgentString = USER_AGENT setLayerType(View.LAYER_TYPE_HARDWARE, null) webViewClient = LoginClient() webChromeClient = LoginChromeClient() |