aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-08-15 23:25:54 -0700
committerAllan Wang <me@allanwang.ca>2019-08-15 23:25:54 -0700
commit5d796703e8d69861bbff01bebf079d8401e66f77 (patch)
tree1a1848a213ad9be509de1f68bc48104b62b91a0e
parent0a3339aee3fb058180d9d58e9639ae13973cd96b (diff)
downloadfrost-5d796703e8d69861bbff01bebf079d8401e66f77.tar.gz
frost-5d796703e8d69861bbff01bebf079d8401e66f77.tar.bz2
frost-5d796703e8d69861bbff01bebf079d8401e66f77.zip
Remove dbflow
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt23
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt31
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt23
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/db/FbTabsDb.kt39
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/db/GenericDb.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt57
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt1
-rw-r--r--buildSrc/src/main/kotlin/Versions.kt2
9 files changed, 3 insertions, 176 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/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/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/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt
index a6df6bda..a7a163fe 100644
--- a/buildSrc/src/main/kotlin/Versions.kt
+++ b/buildSrc/src/main/kotlin/Versions.kt
@@ -7,8 +7,6 @@ object Versions {
// https://mvnrepository.com/artifact/org.apache.commons/commons-text
// Updates blocked due to javax.script dependency
const val apacheCommonsText = "1.4"
- // https://github.com/Raizlabs/DBFlow/releases
- const val dbflow = "4.2.4"
// https://github.com/brianwernick/ExoMedia/releases
const val exoMedia = "4.3.0"
// https://github.com/InsertKoinIO/koin/blob/master/CHANGELOG.md