aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/androidTest/kotlin/com/pitchedapps/frost/db/CacheDbTest.kt2
-rw-r--r--app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt12
-rw-r--r--app/src/androidTest/kotlin/com/pitchedapps/frost/db/NotificationDbTest.kt14
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt6
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/db/Database.kt5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt6
-rw-r--r--app/src/schemas/com.pitchedapps.frost.db.FrostPrivateDatabase/1.json189
-rw-r--r--app/src/schemas/com.pitchedapps.frost.db.FrostPublicDatabase/1.json40
11 files changed, 32 insertions, 250 deletions
diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CacheDbTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CacheDbTest.kt
index 780bbd3e..1fe7bbc4 100644
--- a/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CacheDbTest.kt
+++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CacheDbTest.kt
@@ -19,7 +19,7 @@ class CacheDbTest : BaseDbTest() {
val type = "test"
val content = "long test".repeat(10000)
runBlocking {
- cookieDao.insertCookie(cookie)
+ cookieDao.save(cookie)
dao.save(cookie.id, type, content)
val cache = dao.select(cookie.id, type) ?: fail("Cache not found")
assertEquals(content, cache.contents, "Content mismatch")
diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt
index 5ec771f5..122e3205 100644
--- a/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt
+++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/CookieDbTest.kt
@@ -13,7 +13,7 @@ class CookieDbTest : BaseDbTest() {
fun basicCookie() {
val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
runBlocking {
- dao.insertCookie(cookie)
+ dao.save(cookie)
val cookies = dao.selectAll()
assertEquals(listOf(cookie), cookies, "Cookie mismatch")
}
@@ -24,7 +24,7 @@ class CookieDbTest : BaseDbTest() {
val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
runBlocking {
- dao.insertCookie(cookie)
+ dao.save(cookie)
dao.deleteById(cookie.id + 1)
assertEquals(
listOf(cookie),
@@ -40,15 +40,15 @@ class CookieDbTest : BaseDbTest() {
fun insertReplaceCookie() {
val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
runBlocking {
- dao.insertCookie(cookie)
+ dao.save(cookie)
assertEquals(listOf(cookie), dao.selectAll(), "Cookie insertion failed")
- dao.insertCookie(cookie.copy(name = "testName2"))
+ dao.save(cookie.copy(name = "testName2"))
assertEquals(
listOf(cookie.copy(name = "testName2")),
dao.selectAll(),
"Cookie replacement failed"
)
- dao.insertCookie(cookie.copy(id = 123L))
+ dao.save(cookie.copy(id = 123L))
assertEquals(
setOf(cookie.copy(id = 123L), cookie.copy(name = "testName2")),
dao.selectAll().toSet(),
@@ -61,7 +61,7 @@ class CookieDbTest : BaseDbTest() {
fun selectCookie() {
val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
runBlocking {
- dao.insertCookie(cookie)
+ dao.save(cookie)
assertEquals(cookie, dao.selectById(cookie.id), "Cookie selection failed")
assertNull(dao.selectById(cookie.id + 1), "Inexistent cookie selection failed")
}
diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/db/NotificationDbTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/NotificationDbTest.kt
index 176d0d3a..25c29db4 100644
--- a/app/src/androidTest/kotlin/com/pitchedapps/frost/db/NotificationDbTest.kt
+++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/db/NotificationDbTest.kt
@@ -31,7 +31,7 @@ class NotificationDbTest : BaseDbTest() {
// Unique unsorted ids
val notifs = listOf(0L, 4L, 2L, 6L, 99L, 3L).map { notifContent(it, cookie) }
runBlocking {
- db.cookieDao().insertCookie(cookie)
+ db.cookieDao().save(cookie)
dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs)
val dbNotifs = dao.selectNotifications(cookie.id, NOTIF_CHANNEL_GENERAL)
assertEquals(notifs.sortedByDescending { it.timestamp }, dbNotifs, "Incorrect notification list received")
@@ -45,8 +45,8 @@ class NotificationDbTest : BaseDbTest() {
val cookie2 = cookie(12L)
val notifs1 = (0L..2L).map { notifContent(it, cookie1) }
val notifs2 = (5L..10L).map { notifContent(it, cookie2) }
- db.cookieDao().insertCookie(cookie1)
- db.cookieDao().insertCookie(cookie2)
+ db.cookieDao().save(cookie1)
+ db.cookieDao().save(cookie2)
dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs1)
dao.saveNotifications(NOTIF_CHANNEL_MESSAGES, notifs2)
assertEquals(
@@ -82,8 +82,8 @@ class NotificationDbTest : BaseDbTest() {
val cookie2 = cookie(12L)
val notifs1 = (0L..2L).map { notifContent(it, cookie1) }
val notifs2 = notifs1.map { it.copy(data = cookie2) }
- db.cookieDao().insertCookie(cookie1)
- db.cookieDao().insertCookie(cookie2)
+ db.cookieDao().save(cookie1)
+ db.cookieDao().save(cookie2)
assertTrue(dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs1), "Notif1 save failed")
assertTrue(dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs2), "Notif2 save failed")
}
@@ -95,7 +95,7 @@ class NotificationDbTest : BaseDbTest() {
// Unique unsorted ids
val notifs = listOf(0L, 4L, 2L, 6L, 99L, 3L).map { notifContent(it, cookie) }
runBlocking {
- db.cookieDao().insertCookie(cookie)
+ db.cookieDao().save(cookie)
dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs)
db.cookieDao().deleteById(cookie.id)
val dbNotifs = dao.selectNotifications(cookie.id, NOTIF_CHANNEL_GENERAL)
@@ -110,7 +110,7 @@ class NotificationDbTest : BaseDbTest() {
val notifs = listOf(0L, 4L, 2L, 6L, 99L, 3L).map { notifContent(it, cookie) }
runBlocking {
assertEquals(-1L, dao.latestEpoch(cookie.id, NOTIF_CHANNEL_GENERAL), "Default epoch failed")
- db.cookieDao().insertCookie(cookie)
+ db.cookieDao().save(cookie)
dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs)
assertEquals(99L, dao.latestEpoch(cookie.id, NOTIF_CHANNEL_GENERAL), "Latest epoch failed")
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
index 3b7418e1..24e9c548 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
@@ -38,6 +38,7 @@ import com.pitchedapps.frost.db.CookieModel
import com.pitchedapps.frost.db.FbTabDao
import com.pitchedapps.frost.db.FbTabModel
import com.pitchedapps.frost.db.save
+import com.pitchedapps.frost.db.selectAll
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.utils.EXTRA_COOKIES
import com.pitchedapps.frost.utils.L
@@ -94,6 +95,7 @@ class StartActivity : KauBaseActivity() {
})
}
} catch (e: Exception) {
+ L._e(e) { "Load start failed" }
showInvalidWebView()
}
}
@@ -106,9 +108,11 @@ class StartActivity : KauBaseActivity() {
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) }
- cookieDao.insertCookies(cookies)
+ cookieDao.save(cookies)
val tabs = (select from FbTabModel::class).queryList().map(FbTabModel::tab)
tabDao.save(tabs)
+ L._d { "Migrated cookies ${cookieDao.selectAll()}" }
+ L._d { "Migrated tabs ${tabDao.selectAll()}" }
}
private fun showInvalidWebView() =
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt
index 27dbc37a..e5a50543 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt
@@ -184,7 +184,7 @@ class LoginActivity : BaseActivity() {
}
if (cookie.name?.isNotBlank() == false && result != cookie.name) {
- cookieDao.insertCookie(cookie.copy(name = result))
+ cookieDao.save(cookie.copy(name = result))
}
cookie.name ?: ""
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 c6c983fb..7e929370 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt
@@ -59,10 +59,10 @@ interface CookieDao {
suspend fun selectById(id: Long): CookieEntity?
@Insert(onConflict = OnConflictStrategy.REPLACE)
- suspend fun insertCookie(cookie: CookieEntity)
+ suspend fun save(cookie: CookieEntity)
@Insert(onConflict = OnConflictStrategy.REPLACE)
- suspend fun insertCookies(cookies: List<CookieEntity>)
+ suspend fun save(cookies: List<CookieEntity>)
@Query("DELETE FROM cookies WHERE cookie_id = :id")
suspend fun deleteById(id: Long)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/db/Database.kt b/app/src/main/kotlin/com/pitchedapps/frost/db/Database.kt
index 29296494..ae96b696 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/db/Database.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/db/Database.kt
@@ -5,6 +5,7 @@ import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
+import org.koin.core.Koin
import org.koin.dsl.module.module
import org.koin.standalone.StandAloneContext
@@ -59,11 +60,11 @@ class FrostDatabase(private val privateDb: FrostPrivateDatabase, private val pub
val privateDb = Room.databaseBuilder(
context, FrostPrivateDatabase::class.java,
FrostPrivateDatabase.DATABASE_NAME
- ).build()
+ ).fallbackToDestructiveMigration().build()
val publicDb = Room.databaseBuilder(
context, FrostPublicDatabase::class.java,
FrostPublicDatabase.DATABASE_NAME
- ).build()
+ ).fallbackToDestructiveMigration().build()
return FrostDatabase(privateDb, publicDb)
}
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 02718b78..6afbea4b 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
@@ -85,7 +85,7 @@ object FbCookie {
Prefs.userId = id
CookieManager.getInstance().flush()
val cookie = CookieEntity(Prefs.userId, null, webCookie)
- cookieDao.insertCookie(cookie)
+ cookieDao.save(cookie)
}
suspend fun reset() {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt
index 8364c34e..7d2e0e08 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt
@@ -20,6 +20,7 @@ import android.util.Log
import ca.allanwang.kau.logging.KauLogger
import com.bugsnag.android.Bugsnag
import com.pitchedapps.frost.BuildConfig
+import java.lang.Exception
/**
* Created by Allan Wang on 2017-05-28.
@@ -50,6 +51,11 @@ object L : KauLogger("Frost", {
d(message)
}
+ inline fun _e(e: Throwable?, message: () -> Any?) {
+ if (BuildConfig.DEBUG)
+ e(e, message)
+ }
+
override fun logImpl(priority: Int, message: String?, t: Throwable?) {
if (BuildConfig.DEBUG)
super.logImpl(priority, message, t)
diff --git a/app/src/schemas/com.pitchedapps.frost.db.FrostPrivateDatabase/1.json b/app/src/schemas/com.pitchedapps.frost.db.FrostPrivateDatabase/1.json
deleted file mode 100644
index 60d5cddd..00000000
--- a/app/src/schemas/com.pitchedapps.frost.db.FrostPrivateDatabase/1.json
+++ /dev/null
@@ -1,189 +0,0 @@
-{
- "formatVersion": 1,
- "database": {
- "version": 1,
- "identityHash": "0a9d994786b7e07fea95c11d9210ce0e",
- "entities": [
- {
- "tableName": "cookies",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`cookie_id` INTEGER NOT NULL, `name` TEXT, `cookie` TEXT, PRIMARY KEY(`cookie_id`))",
- "fields": [
- {
- "fieldPath": "id",
- "columnName": "cookie_id",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "name",
- "columnName": "name",
- "affinity": "TEXT",
- "notNull": false
- },
- {
- "fieldPath": "cookie",
- "columnName": "cookie",
- "affinity": "TEXT",
- "notNull": false
- }
- ],
- "primaryKey": {
- "columnNames": [
- "cookie_id"
- ],
- "autoGenerate": false
- },
- "indices": [],
- "foreignKeys": []
- },
- {
- "tableName": "notifications",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`notif_id` INTEGER NOT NULL, `userId` INTEGER NOT NULL, `href` TEXT NOT NULL, `title` TEXT, `text` TEXT NOT NULL, `timestamp` INTEGER NOT NULL, `profileUrl` TEXT, `type` TEXT NOT NULL, PRIMARY KEY(`notif_id`, `userId`), FOREIGN KEY(`userId`) REFERENCES `cookies`(`cookie_id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
- "fields": [
- {
- "fieldPath": "id",
- "columnName": "notif_id",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "userId",
- "columnName": "userId",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "href",
- "columnName": "href",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "title",
- "columnName": "title",
- "affinity": "TEXT",
- "notNull": false
- },
- {
- "fieldPath": "text",
- "columnName": "text",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "timestamp",
- "columnName": "timestamp",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "profileUrl",
- "columnName": "profileUrl",
- "affinity": "TEXT",
- "notNull": false
- },
- {
- "fieldPath": "type",
- "columnName": "type",
- "affinity": "TEXT",
- "notNull": true
- }
- ],
- "primaryKey": {
- "columnNames": [
- "notif_id",
- "userId"
- ],
- "autoGenerate": false
- },
- "indices": [
- {
- "name": "index_notifications_notif_id",
- "unique": false,
- "columnNames": [
- "notif_id"
- ],
- "createSql": "CREATE INDEX `index_notifications_notif_id` ON `${TABLE_NAME}` (`notif_id`)"
- },
- {
- "name": "index_notifications_userId",
- "unique": false,
- "columnNames": [
- "userId"
- ],
- "createSql": "CREATE INDEX `index_notifications_userId` ON `${TABLE_NAME}` (`userId`)"
- }
- ],
- "foreignKeys": [
- {
- "table": "cookies",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "userId"
- ],
- "referencedColumns": [
- "cookie_id"
- ]
- }
- ]
- },
- {
- "tableName": "frost_cache",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `type` TEXT NOT NULL, `lastUpdated` INTEGER NOT NULL, `contents` TEXT NOT NULL, PRIMARY KEY(`id`, `type`), FOREIGN KEY(`id`) REFERENCES `cookies`(`cookie_id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
- "fields": [
- {
- "fieldPath": "id",
- "columnName": "id",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "type",
- "columnName": "type",
- "affinity": "TEXT",
- "notNull": true
- },
- {
- "fieldPath": "lastUpdated",
- "columnName": "lastUpdated",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "contents",
- "columnName": "contents",
- "affinity": "TEXT",
- "notNull": true
- }
- ],
- "primaryKey": {
- "columnNames": [
- "id",
- "type"
- ],
- "autoGenerate": false
- },
- "indices": [],
- "foreignKeys": [
- {
- "table": "cookies",
- "onDelete": "CASCADE",
- "onUpdate": "NO ACTION",
- "columns": [
- "id"
- ],
- "referencedColumns": [
- "cookie_id"
- ]
- }
- ]
- }
- ],
- "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, \"0a9d994786b7e07fea95c11d9210ce0e\")"
- ]
- }
-} \ No newline at end of file
diff --git a/app/src/schemas/com.pitchedapps.frost.db.FrostPublicDatabase/1.json b/app/src/schemas/com.pitchedapps.frost.db.FrostPublicDatabase/1.json
deleted file mode 100644
index fe2aa83e..00000000
--- a/app/src/schemas/com.pitchedapps.frost.db.FrostPublicDatabase/1.json
+++ /dev/null
@@ -1,40 +0,0 @@
-{
- "formatVersion": 1,
- "database": {
- "version": 1,
- "identityHash": "fde868470836ff9230f1d406922d7563",
- "entities": [
- {
- "tableName": "tabs",
- "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`position` INTEGER NOT NULL, `tab` TEXT NOT NULL, PRIMARY KEY(`position`))",
- "fields": [
- {
- "fieldPath": "position",
- "columnName": "position",
- "affinity": "INTEGER",
- "notNull": true
- },
- {
- "fieldPath": "tab",
- "columnName": "tab",
- "affinity": "TEXT",
- "notNull": true
- }
- ],
- "primaryKey": {
- "columnNames": [
- "position"
- ],
- "autoGenerate": false
- },
- "indices": [],
- "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, \"fde868470836ff9230f1d406922d7563\")"
- ]
- }
-} \ No newline at end of file