Prepare db migration
This commit is contained in:
parent
2511b9f194
commit
104648af2c
|
@ -72,8 +72,8 @@ class MainActivity : BaseActivity() {
|
||||||
|
|
||||||
//Check if we have logged in and gotten an access token
|
//Check if we have logged in and gotten an access token
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
launchActivity(LoginActivity(), firstTime = true)
|
|
||||||
finish()
|
finish()
|
||||||
|
launchActivity(LoginActivity(), firstTime = true)
|
||||||
} else {
|
} else {
|
||||||
sendTraceDroidStackTracesIfExist("contact@pixeldroid.org", this)
|
sendTraceDroidStackTracesIfExist("contact@pixeldroid.org", this)
|
||||||
|
|
||||||
|
@ -172,6 +172,7 @@ class MainActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun logOut(){
|
private fun logOut(){
|
||||||
|
finish()
|
||||||
db.runInTransaction {
|
db.runInTransaction {
|
||||||
db.userDao().deleteActiveUsers()
|
db.userDao().deleteActiveUsers()
|
||||||
|
|
||||||
|
@ -229,6 +230,8 @@ class MainActivity : BaseActivity() {
|
||||||
apiHolder.setToCurrentUser()
|
apiHolder.setToCurrentUser()
|
||||||
val intent = Intent(this, MainActivity::class.java)
|
val intent = Intent(this, MainActivity::class.java)
|
||||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
|
|
||||||
|
finish()
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -38,8 +38,8 @@ class PostActivity : BaseActivity() {
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
|
||||||
status = intent.getSerializableExtra(POST_TAG) as Status
|
status = intent.getSerializableExtra(POST_TAG) as Status
|
||||||
val viewComments: Boolean = (intent.getSerializableExtra(VIEW_COMMENTS_TAG) ?: false) as Boolean
|
val viewComments: Boolean = intent.getBooleanExtra(VIEW_COMMENTS_TAG, false)
|
||||||
val postComment: Boolean = (intent.getSerializableExtra(POST_COMMENT_TAG) ?: false) as Boolean
|
val postComment: Boolean = intent.getBooleanExtra(POST_COMMENT_TAG, false)
|
||||||
|
|
||||||
val user = db.userDao().getActiveUser()
|
val user = db.userDao().getActiveUser()
|
||||||
|
|
||||||
|
|
|
@ -249,7 +249,7 @@ class NotificationsFragment : CachedFeedFragment<Notification>() {
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||||
val uiModel = getItem(position)
|
val uiModel = getItem(position)
|
||||||
uiModel.let {
|
uiModel?.let {
|
||||||
(holder as NotificationViewHolder).bind(
|
(holder as NotificationViewHolder).bind(
|
||||||
it,
|
it,
|
||||||
apiHolder,
|
apiHolder,
|
||||||
|
|
|
@ -3,6 +3,8 @@ package org.pixeldroid.app.utils.db
|
||||||
import androidx.room.Database
|
import androidx.room.Database
|
||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
import androidx.room.TypeConverters
|
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.*
|
||||||
import org.pixeldroid.app.utils.db.dao.feedContent.NotificationDao
|
import org.pixeldroid.app.utils.db.dao.feedContent.NotificationDao
|
||||||
import org.pixeldroid.app.utils.db.dao.feedContent.posts.HomePostDao
|
import org.pixeldroid.app.utils.db.dao.feedContent.posts.HomePostDao
|
||||||
|
@ -30,3 +32,11 @@ abstract class AppDatabase : RoomDatabase() {
|
||||||
abstract fun publicPostDao(): PublicPostDao
|
abstract fun publicPostDao(): PublicPostDao
|
||||||
abstract fun notificationDao(): NotificationDao
|
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")
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import androidx.room.Room
|
||||||
import org.pixeldroid.app.utils.db.AppDatabase
|
import org.pixeldroid.app.utils.db.AppDatabase
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
|
import org.pixeldroid.app.utils.db.MIGRATION_3_4
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
|
@ -16,6 +17,6 @@ class DatabaseModule(private val context: Context) {
|
||||||
return Room.databaseBuilder(
|
return Room.databaseBuilder(
|
||||||
context,
|
context,
|
||||||
AppDatabase::class.java, "pixeldroid"
|
AppDatabase::class.java, "pixeldroid"
|
||||||
).allowMainThreadQueries().build()
|
).addMigrations(MIGRATION_3_4).allowMainThreadQueries().build()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue