aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-03-07 17:28:32 -0500
committerAllan Wang <me@allanwang.ca>2019-03-07 17:28:32 -0500
commite617c95e2b4acfcfbeb1a72a658f19e69eaa3d6c (patch)
tree8a8171b7ab6f743051af7fd71bcd8ba538a486b8 /app/src/main/kotlin
parent9e201159fd6697d83a16b7f7cfc5e7e302d55152 (diff)
downloadfrost-e617c95e2b4acfcfbeb1a72a658f19e69eaa3d6c.tar.gz
frost-e617c95e2b4acfcfbeb1a72a658f19e69eaa3d6c.tar.bz2
frost-e617c95e2b4acfcfbeb1a72a658f19e69eaa3d6c.zip
Rename some methods
Diffstat (limited to 'app/src/main/kotlin')
-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
6 files changed, 18 insertions, 7 deletions
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)