Prepare db migration

This commit is contained in:
Matthieu 2021-09-07 13:13:28 +02:00
parent 2511b9f194
commit 104648af2c
5 changed files with 19 additions and 5 deletions

View File

@ -72,8 +72,8 @@ class MainActivity : BaseActivity() {
//Check if we have logged in and gotten an access token
if (user == null) {
launchActivity(LoginActivity(), firstTime = true)
finish()
launchActivity(LoginActivity(), firstTime = true)
} else {
sendTraceDroidStackTracesIfExist("contact@pixeldroid.org", this)
@ -172,6 +172,7 @@ class MainActivity : BaseActivity() {
}
private fun logOut(){
finish()
db.runInTransaction {
db.userDao().deleteActiveUsers()
@ -229,6 +230,8 @@ class MainActivity : BaseActivity() {
apiHolder.setToCurrentUser()
val intent = Intent(this, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
finish()
startActivity(intent)
return false

View File

@ -38,8 +38,8 @@ class PostActivity : BaseActivity() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
status = intent.getSerializableExtra(POST_TAG) as Status
val viewComments: Boolean = (intent.getSerializableExtra(VIEW_COMMENTS_TAG) ?: false) as Boolean
val postComment: Boolean = (intent.getSerializableExtra(POST_COMMENT_TAG) ?: false) as Boolean
val viewComments: Boolean = intent.getBooleanExtra(VIEW_COMMENTS_TAG, false)
val postComment: Boolean = intent.getBooleanExtra(POST_COMMENT_TAG, false)
val user = db.userDao().getActiveUser()

View File

@ -249,7 +249,7 @@ class NotificationsFragment : CachedFeedFragment<Notification>() {
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val uiModel = getItem(position)
uiModel.let {
uiModel?.let {
(holder as NotificationViewHolder).bind(
it,
apiHolder,

View File

@ -3,6 +3,8 @@ package org.pixeldroid.app.utils.db
import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import org.pixeldroid.app.utils.db.dao.*
import org.pixeldroid.app.utils.db.dao.feedContent.NotificationDao
import org.pixeldroid.app.utils.db.dao.feedContent.posts.HomePostDao
@ -29,4 +31,12 @@ abstract class AppDatabase : RoomDatabase() {
abstract fun homePostDao(): HomePostDao
abstract fun publicPostDao(): PublicPostDao
abstract fun notificationDao(): NotificationDao
}
val MIGRATION_3_4 = object : Migration(3, 4) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("DELETE FROM homePosts")
database.execSQL("DELETE FROM publicPosts")
database.execSQL("DELETE FROM notifications")
}
}

View File

@ -5,6 +5,7 @@ import androidx.room.Room
import org.pixeldroid.app.utils.db.AppDatabase
import dagger.Module
import dagger.Provides
import org.pixeldroid.app.utils.db.MIGRATION_3_4
import javax.inject.Singleton
@Module
@ -16,6 +17,6 @@ class DatabaseModule(private val context: Context) {
return Room.databaseBuilder(
context,
AppDatabase::class.java, "pixeldroid"
).allowMainThreadQueries().build()
).addMigrations(MIGRATION_3_4).allowMainThreadQueries().build()
}
}