1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-10 04:52:38 +01:00

Rename some methods

This commit is contained in:
Allan Wang 2019-03-07 17:28:32 -05:00
parent 9e201159fd
commit e617c95e2b
No known key found for this signature in database
GPG Key ID: C93E3F9C679D7A56
11 changed files with 32 additions and 250 deletions

View File

@ -19,7 +19,7 @@ class CacheDbTest : BaseDbTest() {
val type = "test" val type = "test"
val content = "long test".repeat(10000) val content = "long test".repeat(10000)
runBlocking { runBlocking {
cookieDao.insertCookie(cookie) cookieDao.save(cookie)
dao.save(cookie.id, type, content) dao.save(cookie.id, type, content)
val cache = dao.select(cookie.id, type) ?: fail("Cache not found") val cache = dao.select(cookie.id, type) ?: fail("Cache not found")
assertEquals(content, cache.contents, "Content mismatch") assertEquals(content, cache.contents, "Content mismatch")

View File

@ -13,7 +13,7 @@ class CookieDbTest : BaseDbTest() {
fun basicCookie() { fun basicCookie() {
val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie") val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
runBlocking { runBlocking {
dao.insertCookie(cookie) dao.save(cookie)
val cookies = dao.selectAll() val cookies = dao.selectAll()
assertEquals(listOf(cookie), cookies, "Cookie mismatch") assertEquals(listOf(cookie), cookies, "Cookie mismatch")
} }
@ -24,7 +24,7 @@ class CookieDbTest : BaseDbTest() {
val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie") val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
runBlocking { runBlocking {
dao.insertCookie(cookie) dao.save(cookie)
dao.deleteById(cookie.id + 1) dao.deleteById(cookie.id + 1)
assertEquals( assertEquals(
listOf(cookie), listOf(cookie),
@ -40,15 +40,15 @@ class CookieDbTest : BaseDbTest() {
fun insertReplaceCookie() { fun insertReplaceCookie() {
val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie") val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
runBlocking { runBlocking {
dao.insertCookie(cookie) dao.save(cookie)
assertEquals(listOf(cookie), dao.selectAll(), "Cookie insertion failed") assertEquals(listOf(cookie), dao.selectAll(), "Cookie insertion failed")
dao.insertCookie(cookie.copy(name = "testName2")) dao.save(cookie.copy(name = "testName2"))
assertEquals( assertEquals(
listOf(cookie.copy(name = "testName2")), listOf(cookie.copy(name = "testName2")),
dao.selectAll(), dao.selectAll(),
"Cookie replacement failed" "Cookie replacement failed"
) )
dao.insertCookie(cookie.copy(id = 123L)) dao.save(cookie.copy(id = 123L))
assertEquals( assertEquals(
setOf(cookie.copy(id = 123L), cookie.copy(name = "testName2")), setOf(cookie.copy(id = 123L), cookie.copy(name = "testName2")),
dao.selectAll().toSet(), dao.selectAll().toSet(),
@ -61,7 +61,7 @@ class CookieDbTest : BaseDbTest() {
fun selectCookie() { fun selectCookie() {
val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie") val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
runBlocking { runBlocking {
dao.insertCookie(cookie) dao.save(cookie)
assertEquals(cookie, dao.selectById(cookie.id), "Cookie selection failed") assertEquals(cookie, dao.selectById(cookie.id), "Cookie selection failed")
assertNull(dao.selectById(cookie.id + 1), "Inexistent cookie selection failed") assertNull(dao.selectById(cookie.id + 1), "Inexistent cookie selection failed")
} }

View File

@ -31,7 +31,7 @@ class NotificationDbTest : BaseDbTest() {
// Unique unsorted ids // Unique unsorted ids
val notifs = listOf(0L, 4L, 2L, 6L, 99L, 3L).map { notifContent(it, cookie) } val notifs = listOf(0L, 4L, 2L, 6L, 99L, 3L).map { notifContent(it, cookie) }
runBlocking { runBlocking {
db.cookieDao().insertCookie(cookie) db.cookieDao().save(cookie)
dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs) dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs)
val dbNotifs = dao.selectNotifications(cookie.id, NOTIF_CHANNEL_GENERAL) val dbNotifs = dao.selectNotifications(cookie.id, NOTIF_CHANNEL_GENERAL)
assertEquals(notifs.sortedByDescending { it.timestamp }, dbNotifs, "Incorrect notification list received") assertEquals(notifs.sortedByDescending { it.timestamp }, dbNotifs, "Incorrect notification list received")
@ -45,8 +45,8 @@ class NotificationDbTest : BaseDbTest() {
val cookie2 = cookie(12L) val cookie2 = cookie(12L)
val notifs1 = (0L..2L).map { notifContent(it, cookie1) } val notifs1 = (0L..2L).map { notifContent(it, cookie1) }
val notifs2 = (5L..10L).map { notifContent(it, cookie2) } val notifs2 = (5L..10L).map { notifContent(it, cookie2) }
db.cookieDao().insertCookie(cookie1) db.cookieDao().save(cookie1)
db.cookieDao().insertCookie(cookie2) db.cookieDao().save(cookie2)
dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs1) dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs1)
dao.saveNotifications(NOTIF_CHANNEL_MESSAGES, notifs2) dao.saveNotifications(NOTIF_CHANNEL_MESSAGES, notifs2)
assertEquals( assertEquals(
@ -82,8 +82,8 @@ class NotificationDbTest : BaseDbTest() {
val cookie2 = cookie(12L) val cookie2 = cookie(12L)
val notifs1 = (0L..2L).map { notifContent(it, cookie1) } val notifs1 = (0L..2L).map { notifContent(it, cookie1) }
val notifs2 = notifs1.map { it.copy(data = cookie2) } val notifs2 = notifs1.map { it.copy(data = cookie2) }
db.cookieDao().insertCookie(cookie1) db.cookieDao().save(cookie1)
db.cookieDao().insertCookie(cookie2) db.cookieDao().save(cookie2)
assertTrue(dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs1), "Notif1 save failed") assertTrue(dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs1), "Notif1 save failed")
assertTrue(dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs2), "Notif2 save failed") assertTrue(dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs2), "Notif2 save failed")
} }
@ -95,7 +95,7 @@ class NotificationDbTest : BaseDbTest() {
// Unique unsorted ids // Unique unsorted ids
val notifs = listOf(0L, 4L, 2L, 6L, 99L, 3L).map { notifContent(it, cookie) } val notifs = listOf(0L, 4L, 2L, 6L, 99L, 3L).map { notifContent(it, cookie) }
runBlocking { runBlocking {
db.cookieDao().insertCookie(cookie) db.cookieDao().save(cookie)
dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs) dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs)
db.cookieDao().deleteById(cookie.id) db.cookieDao().deleteById(cookie.id)
val dbNotifs = dao.selectNotifications(cookie.id, NOTIF_CHANNEL_GENERAL) 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) } val notifs = listOf(0L, 4L, 2L, 6L, 99L, 3L).map { notifContent(it, cookie) }
runBlocking { runBlocking {
assertEquals(-1L, dao.latestEpoch(cookie.id, NOTIF_CHANNEL_GENERAL), "Default epoch failed") 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) dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs)
assertEquals(99L, dao.latestEpoch(cookie.id, NOTIF_CHANNEL_GENERAL), "Latest epoch failed") assertEquals(99L, dao.latestEpoch(cookie.id, NOTIF_CHANNEL_GENERAL), "Latest epoch failed")
} }

View File

@ -38,6 +38,7 @@ import com.pitchedapps.frost.db.CookieModel
import com.pitchedapps.frost.db.FbTabDao import com.pitchedapps.frost.db.FbTabDao
import com.pitchedapps.frost.db.FbTabModel import com.pitchedapps.frost.db.FbTabModel
import com.pitchedapps.frost.db.save import com.pitchedapps.frost.db.save
import com.pitchedapps.frost.db.selectAll
import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.utils.EXTRA_COOKIES import com.pitchedapps.frost.utils.EXTRA_COOKIES
import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.L
@ -94,6 +95,7 @@ class StartActivity : KauBaseActivity() {
}) })
} }
} catch (e: Exception) { } catch (e: Exception) {
L._e(e) { "Load start failed" }
showInvalidWebView() showInvalidWebView()
} }
} }
@ -106,9 +108,11 @@ class StartActivity : KauBaseActivity() {
private suspend fun migrate() = withContext(Dispatchers.IO) { private suspend fun migrate() = withContext(Dispatchers.IO) {
if (cookieDao.selectAll().isNotEmpty()) return@withContext if (cookieDao.selectAll().isNotEmpty()) return@withContext
val cookies = (select from CookieModel::class).queryList().map { CookieEntity(it.id, it.name, it.cookie) } 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) val tabs = (select from FbTabModel::class).queryList().map(FbTabModel::tab)
tabDao.save(tabs) tabDao.save(tabs)
L._d { "Migrated cookies ${cookieDao.selectAll()}" }
L._d { "Migrated tabs ${tabDao.selectAll()}" }
} }
private fun showInvalidWebView() = private fun showInvalidWebView() =

View File

@ -184,7 +184,7 @@ class LoginActivity : BaseActivity() {
} }
if (cookie.name?.isNotBlank() == false && result != cookie.name) { if (cookie.name?.isNotBlank() == false && result != cookie.name) {
cookieDao.insertCookie(cookie.copy(name = result)) cookieDao.save(cookie.copy(name = result))
} }
cookie.name ?: "" cookie.name ?: ""

View File

@ -59,10 +59,10 @@ interface CookieDao {
suspend fun selectById(id: Long): CookieEntity? suspend fun selectById(id: Long): CookieEntity?
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertCookie(cookie: CookieEntity) suspend fun save(cookie: CookieEntity)
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertCookies(cookies: List<CookieEntity>) suspend fun save(cookies: List<CookieEntity>)
@Query("DELETE FROM cookies WHERE cookie_id = :id") @Query("DELETE FROM cookies WHERE cookie_id = :id")
suspend fun deleteById(id: Long) suspend fun deleteById(id: Long)

View File

@ -5,6 +5,7 @@ import androidx.room.Database
import androidx.room.Room import androidx.room.Room
import androidx.room.RoomDatabase import androidx.room.RoomDatabase
import androidx.room.TypeConverters import androidx.room.TypeConverters
import org.koin.core.Koin
import org.koin.dsl.module.module import org.koin.dsl.module.module
import org.koin.standalone.StandAloneContext import org.koin.standalone.StandAloneContext
@ -59,11 +60,11 @@ class FrostDatabase(private val privateDb: FrostPrivateDatabase, private val pub
val privateDb = Room.databaseBuilder( val privateDb = Room.databaseBuilder(
context, FrostPrivateDatabase::class.java, context, FrostPrivateDatabase::class.java,
FrostPrivateDatabase.DATABASE_NAME FrostPrivateDatabase.DATABASE_NAME
).build() ).fallbackToDestructiveMigration().build()
val publicDb = Room.databaseBuilder( val publicDb = Room.databaseBuilder(
context, FrostPublicDatabase::class.java, context, FrostPublicDatabase::class.java,
FrostPublicDatabase.DATABASE_NAME FrostPublicDatabase.DATABASE_NAME
).build() ).fallbackToDestructiveMigration().build()
return FrostDatabase(privateDb, publicDb) return FrostDatabase(privateDb, publicDb)
} }

View File

@ -85,7 +85,7 @@ object FbCookie {
Prefs.userId = id Prefs.userId = id
CookieManager.getInstance().flush() CookieManager.getInstance().flush()
val cookie = CookieEntity(Prefs.userId, null, webCookie) val cookie = CookieEntity(Prefs.userId, null, webCookie)
cookieDao.insertCookie(cookie) cookieDao.save(cookie)
} }
suspend fun reset() { suspend fun reset() {

View File

@ -20,6 +20,7 @@ import android.util.Log
import ca.allanwang.kau.logging.KauLogger import ca.allanwang.kau.logging.KauLogger
import com.bugsnag.android.Bugsnag import com.bugsnag.android.Bugsnag
import com.pitchedapps.frost.BuildConfig import com.pitchedapps.frost.BuildConfig
import java.lang.Exception
/** /**
* Created by Allan Wang on 2017-05-28. * Created by Allan Wang on 2017-05-28.
@ -50,6 +51,11 @@ object L : KauLogger("Frost", {
d(message) d(message)
} }
inline fun _e(e: Throwable?, message: () -> Any?) {
if (BuildConfig.DEBUG)
e(e, message)
}
override fun logImpl(priority: Int, message: String?, t: Throwable?) { override fun logImpl(priority: Int, message: String?, t: Throwable?) {
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
super.logImpl(priority, message, t) super.logImpl(priority, message, t)

View File

@ -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\")"
]
}
}

View File

@ -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\")"
]
}
}