aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-03-05 21:25:46 -0500
committerAllan Wang <me@allanwang.ca>2019-03-05 21:25:46 -0500
commit9a1d9719ad6559054ea1bc4f21f8559559eb9cda (patch)
tree9be647741badced75164babd5e411c62c05ea5fc /app/src
parent65bb9233b2a0d8734c1d13e8f3a01bee0f6c3b17 (diff)
downloadfrost-9a1d9719ad6559054ea1bc4f21f8559559eb9cda.tar.gz
frost-9a1d9719ad6559054ea1bc4f21f8559559eb9cda.tar.bz2
frost-9a1d9719ad6559054ea1bc4f21f8559559eb9cda.zip
Port rest of cookie items
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/AndroidManifest.xml1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt12
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt13
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt12
-rw-r--r--app/src/schemas/com.pitchedapps.frost.db.FrostPrivateDatabase/1.json11
6 files changed, 30 insertions, 20 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 68e84e4d..ad1fcbdc 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -17,6 +17,7 @@
<application
android:name=".FrostApp"
android:allowBackup="true"
+ android:fullBackupContent="@xml/frost_backup_rules"
android:icon="@mipmap/ic_launcher_round"
android:label="@string/frost_name"
android:roundIcon="@mipmap/ic_launcher_round"
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
index fe859f95..e81df3fa 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
@@ -35,13 +35,15 @@ 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.loadFbCookiesSync
+import com.pitchedapps.frost.db.FbTabModel
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.utils.EXTRA_COOKIES
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
@@ -97,8 +99,12 @@ class StartActivity : KauBaseActivity() {
/**
* Migrate from dbflow to room
*/
- private suspend fun migrate() {
-
+ private suspend fun migrate() = withContext(Dispatchers.IO) {
+ if (cookieDao.selectAll().isNotEmpty()) return@withContext
+ val cookies = (select from CookieModel::class).queryList()
+ cookieDao.insertCookies(cookies.map { CookieEntity(it.id, it.name, it.cookie) })
+ // TODO
+ val tabs = (select from FbTabModel::class).queryList()
}
private fun showInvalidWebView() =
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 fb240fd3..128abae3 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt
@@ -22,23 +22,13 @@ import androidx.room.Entity
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
-import com.pitchedapps.frost.utils.L
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.kotlinextensions.async
-import com.raizlabs.android.dbflow.kotlinextensions.delete
-import com.raizlabs.android.dbflow.kotlinextensions.eq
-import com.raizlabs.android.dbflow.kotlinextensions.from
-import com.raizlabs.android.dbflow.kotlinextensions.save
-import com.raizlabs.android.dbflow.kotlinextensions.select
-import com.raizlabs.android.dbflow.kotlinextensions.where
import com.raizlabs.android.dbflow.structure.BaseModel
import kotlinx.android.parcel.Parcelize
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.withContext
/**
* Created by Allan Wang on 2017-05-30.
@@ -69,6 +59,9 @@ interface CookieDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertCookie(cookie: CookieEntity)
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ suspend fun insertCookies(cookies: List<CookieEntity>)
+
@Query("DELETE FROM cookies WHERE id = :id")
suspend fun deleteById(id: Long)
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
index 6f79da43..02718b78 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
@@ -22,7 +22,6 @@ import android.webkit.CookieManager
import com.pitchedapps.frost.db.CookieDao
import com.pitchedapps.frost.db.CookieEntity
import com.pitchedapps.frost.db.FrostDatabase
-import com.pitchedapps.frost.db.removeCookie
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.cookies
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 0e9d94e6..594b0acd 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
@@ -24,15 +24,19 @@ import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import ca.allanwang.kau.utils.AnimHolder
+import ca.allanwang.kau.utils.launchMain
import com.pitchedapps.frost.contracts.FrostContentContainer
import com.pitchedapps.frost.contracts.FrostContentCore
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_BASIC
import com.pitchedapps.frost.facebook.USER_AGENT_FULL
import com.pitchedapps.frost.fragments.WebFragment
import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.ctxCoroutine
import com.pitchedapps.frost.utils.frostDownload
import com.pitchedapps.frost.web.FrostChromeClient
import com.pitchedapps.frost.web.FrostJSI
@@ -80,7 +84,13 @@ class FrostWebView @JvmOverloads constructor(
webChromeClient = FrostChromeClient(this)
addJavascriptInterface(FrostJSI(this), "Frost")
setBackgroundColor(Color.TRANSPARENT)
- setDownloadListener(context::frostDownload)
+ val db = FrostDatabase.get()
+ setDownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
+ context.ctxCoroutine.launchMain {
+ val cookie = db.cookieDao().currentCookie() ?: return@launchMain
+ context.frostDownload(cookie, url, userAgent, contentDisposition, mimetype, contentLength)
+ }
+ }
return this
}
diff --git a/app/src/schemas/com.pitchedapps.frost.db.FrostPrivateDatabase/1.json b/app/src/schemas/com.pitchedapps.frost.db.FrostPrivateDatabase/1.json
index 7bc2e5e9..9816651c 100644
--- a/app/src/schemas/com.pitchedapps.frost.db.FrostPrivateDatabase/1.json
+++ b/app/src/schemas/com.pitchedapps.frost.db.FrostPrivateDatabase/1.json
@@ -2,11 +2,11 @@
"formatVersion": 1,
"database": {
"version": 1,
- "identityHash": "6af67964d00193c6a3aa2a20200ea0ea",
+ "identityHash": "ba6f1d7e47823dac6ed1622fec043d5d",
"entities": [
{
"tableName": "cookies",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `cookie` TEXT NOT NULL, PRIMARY KEY(`id`))",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `name` TEXT, `cookie` TEXT, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
@@ -18,13 +18,13 @@
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
- "notNull": true
+ "notNull": false
},
{
"fieldPath": "cookie",
"columnName": "cookie",
"affinity": "TEXT",
- "notNull": true
+ "notNull": false
}
],
"primaryKey": {
@@ -37,9 +37,10 @@
"foreignKeys": []
}
],
+ "views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
- "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"6af67964d00193c6a3aa2a20200ea0ea\")"
+ "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"ba6f1d7e47823dac6ed1622fec043d5d\")"
]
}
} \ No newline at end of file