历史记录数据库表新增字段
This commit is contained in:
@ -15,7 +15,7 @@ import com.gh.gamecenter.room.converter.*
|
||||
import com.gh.gamecenter.room.dao.*
|
||||
import com.halo.assistant.HaloApp
|
||||
|
||||
@Database(entities = [AnswerEntity::class, ArticleEntity::class, NewsEntity::class, HistoryGameEntity::class, MyVideoEntity::class], version = 5, exportSchema = false)
|
||||
@Database(entities = [AnswerEntity::class, ArticleEntity::class, NewsEntity::class, HistoryGameEntity::class, MyVideoEntity::class], version = 6, exportSchema = false)
|
||||
@TypeConverters(CountConverter::class,
|
||||
CommunityConverter::class,
|
||||
TimeConverter::class,
|
||||
@ -23,7 +23,8 @@ import com.halo.assistant.HaloApp
|
||||
ThumbnailConverter::class,
|
||||
TagStyleListConverter::class,
|
||||
StringArrayListConverter::class,
|
||||
CommunityVideoConverter::class)
|
||||
CommunityVideoConverter::class,
|
||||
UserConverter::class)
|
||||
|
||||
abstract class HistoryDatabase : RoomDatabase() {
|
||||
|
||||
@ -54,11 +55,20 @@ abstract class HistoryDatabase : RoomDatabase() {
|
||||
}
|
||||
}
|
||||
|
||||
val MIGRATION_5_6: Migration = object : Migration(5, 6) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("Alter TABLE MyVideoEntity add title TEXT NOT NULL DEFAULT ''")
|
||||
database.execSQL("Alter TABLE MyVideoEntity add commentCount INTEGER NOT NULL DEFAULT 0")
|
||||
database.execSQL("Alter TABLE MyVideoEntity add user TEXT NOT NULL DEFAULT ''")
|
||||
}
|
||||
}
|
||||
|
||||
val instance by lazy {
|
||||
Room.databaseBuilder(HaloApp.getInstance().application, HistoryDatabase::class.java, "USER_TRACK_HISTORY_DATABASE")
|
||||
.addMigrations(MIGRATION_2_3)
|
||||
.addMigrations(MIGRATION_3_4)
|
||||
.addMigrations(MIGRATION_4_5)
|
||||
.addMigrations(MIGRATION_5_6)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,8 @@ import android.os.Parcelable
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Ignore
|
||||
import androidx.room.PrimaryKey
|
||||
import androidx.room.TypeConverters
|
||||
import com.gh.gamecenter.room.converter.UserConverter
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
|
||||
@ -19,6 +21,11 @@ class MyVideoEntity(
|
||||
var length: Long = 0,
|
||||
// 有三种状态 pass通过,fail未通过,pending审核中
|
||||
var status: String = "",
|
||||
var title: String = "",
|
||||
@SerializedName("comment_count")
|
||||
var commentCount: Int = 0,
|
||||
@TypeConverters(UserConverter::class)
|
||||
var user: User = User(),
|
||||
@Ignore
|
||||
@SerializedName("game_id")
|
||||
var gameId: String = "",
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
package com.gh.gamecenter.room.converter
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.gh.gamecenter.entity.User
|
||||
import com.gh.gamecenter.entity.UserEntity
|
||||
import com.google.gson.Gson
|
||||
|
||||
class UserConverter {
|
||||
@TypeConverter
|
||||
fun toUserString(data: User?): String {
|
||||
return Gson().toJson(data) ?: ""
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun toUser(token: String?): User {
|
||||
return Gson().fromJson(token, User::class.java) ?: User()
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,7 @@ import com.gh.common.util.createRequestBodyAny
|
||||
import com.gh.download.DownloadManager
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.entity.MyVideoEntity
|
||||
import com.gh.gamecenter.entity.User
|
||||
import com.gh.gamecenter.entity.VideoEntity
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.retrofit.BiResponse
|
||||
@ -376,6 +377,10 @@ class VideoDetailContainerViewModel(application: Application) : AndroidViewModel
|
||||
vote = videoEntity.vote
|
||||
length = videoEntity.length
|
||||
time = System.currentTimeMillis()
|
||||
title = videoEntity.title
|
||||
user = User(videoEntity.user.id ?: "", videoEntity.user.name
|
||||
?: "", videoEntity.user.icon ?: "")
|
||||
commentCount = videoEntity.commentCount
|
||||
videoStreamRecord = if (location == Location.VIDEO_CHOICENESS.value || location == Location.VIDEO_HOT.value) 1 else 0
|
||||
}
|
||||
runOnIoThread {
|
||||
|
||||
Reference in New Issue
Block a user