diff --git a/app/src/main/java/com/gh/common/history/HistoryDatabase.kt b/app/src/main/java/com/gh/common/history/HistoryDatabase.kt index a1ff1b2d6d..26d22087f3 100644 --- a/app/src/main/java/com/gh/common/history/HistoryDatabase.kt +++ b/app/src/main/java/com/gh/common/history/HistoryDatabase.kt @@ -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() } } diff --git a/app/src/main/java/com/gh/gamecenter/entity/MyVideoEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/MyVideoEntity.kt index 224a1a562b..a27f6d67ca 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/MyVideoEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/MyVideoEntity.kt @@ -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 = "", diff --git a/app/src/main/java/com/gh/gamecenter/room/converter/UserConverter.kt b/app/src/main/java/com/gh/gamecenter/room/converter/UserConverter.kt new file mode 100644 index 0000000000..99bbb2c891 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/room/converter/UserConverter.kt @@ -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() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/video/detail/VideoDetailContainerViewModel.kt b/app/src/main/java/com/gh/gamecenter/video/detail/VideoDetailContainerViewModel.kt index 1159cf2cc0..706560ccd8 100644 --- a/app/src/main/java/com/gh/gamecenter/video/detail/VideoDetailContainerViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/video/detail/VideoDetailContainerViewModel.kt @@ -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 {