-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
28 changed files
with
982 additions
and
153 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/data/json/AppUserDataJson.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package indi.dmzz_yyhyy.lightnovelreader.data.json | ||
|
||
import com.google.gson.Gson | ||
import com.google.gson.GsonBuilder | ||
import com.google.gson.annotations.SerializedName | ||
import indi.dmzz_yyhyy.lightnovelreader.data.bookshelf.BookshelfSortType | ||
import java.time.LocalDateTime | ||
|
||
data class AppUserDataJson( | ||
val id: Int? = null, | ||
val data: List<AppUserDataContent> | ||
) { | ||
companion object { | ||
val gson: Gson = GsonBuilder() | ||
.registerTypeAdapter(LocalDateTime::class.java, LocalTimeDataTypeAdapter) | ||
.registerTypeAdapter(BookshelfSortType::class.java, BookshelfSortTypeTypeAdapter) | ||
.create() | ||
|
||
fun fromJson(json: String): AppUserDataJson = gson.fromJson(json, AppUserDataJson::class.java) | ||
} | ||
|
||
fun toJson(): String = gson.toJson(this) | ||
} | ||
|
||
data class AppUserDataContent( | ||
@SerializedName("web_data_source_id") | ||
val webDataSourceId: Int, | ||
@SerializedName("book_user_data") | ||
val bookUserData: List<BookUserData>? = null, | ||
@SerializedName("book_shelf") | ||
val bookshelf: List<BookshelfData>? = null, | ||
@SerializedName("book_shelf_book_metadata") | ||
val bookShelfBookMetadata: List<BookShelfBookMetadataData>? = null, | ||
@SerializedName("user_data") | ||
val userData: List<UserDataData>? = null, | ||
) | ||
|
||
class AppUserDataJsonBuilder() { | ||
private var id: Int? = null | ||
private var data: MutableList<AppUserDataContent> = mutableListOf() | ||
|
||
fun build(): AppUserDataJson = AppUserDataJson( | ||
id = id, | ||
data = data | ||
) | ||
|
||
fun data(data: AppUserDataContentBuilder.() -> Unit): AppUserDataJsonBuilder { | ||
this.data.add( | ||
AppUserDataContentBuilder() | ||
.let { | ||
data.invoke(it) | ||
it.build() | ||
} | ||
) | ||
return this | ||
} | ||
} | ||
|
||
class AppUserDataContentBuilder() { | ||
private var webDataSourceId: Int? = null | ||
private var bookUserData: MutableList<BookUserData> = mutableListOf() | ||
private var bookshelf: MutableList<BookshelfData> = mutableListOf() | ||
private var bookShelfBookMetadata: MutableList<BookShelfBookMetadataData> = mutableListOf() | ||
private var userData: MutableList<UserDataData> = mutableListOf() | ||
|
||
fun build(): AppUserDataContent { | ||
if (webDataSourceId == null) { | ||
throw NullPointerException("webDataSourceId can not be null") | ||
} | ||
return AppUserDataContent( | ||
webDataSourceId = webDataSourceId!!, | ||
bookUserData = bookUserData.ifEmpty { null }, | ||
bookshelf = bookshelf.ifEmpty { null }, | ||
bookShelfBookMetadata = bookShelfBookMetadata.ifEmpty { null }, | ||
userData = userData.ifEmpty { null }, | ||
) | ||
} | ||
|
||
fun webDataSourceId(webDataSourceId: Int): AppUserDataContentBuilder { | ||
this.webDataSourceId = webDataSourceId | ||
return this | ||
} | ||
|
||
fun bookUserData(bookUserData: BookUserData): AppUserDataContentBuilder { | ||
this.bookUserData.add(bookUserData) | ||
return this | ||
} | ||
|
||
fun bookshelf(bookshelf: BookshelfData): AppUserDataContentBuilder { | ||
this.bookshelf.add(bookshelf) | ||
return this | ||
} | ||
|
||
fun bookshelfBookMetaData(bookshelfBookMetadata: BookShelfBookMetadataData): AppUserDataContentBuilder { | ||
this.bookShelfBookMetadata.add(bookshelfBookMetadata) | ||
return this | ||
} | ||
|
||
fun userData(userData: UserDataData): AppUserDataContentBuilder { | ||
this.userData.add(userData) | ||
return this | ||
} | ||
} | ||
|
20 changes: 20 additions & 0 deletions
20
app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/data/json/BookShelfBookMetadataData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package indi.dmzz_yyhyy.lightnovelreader.data.json | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import indi.dmzz_yyhyy.lightnovelreader.data.bookshelf.BookshelfBookMetadata | ||
import java.time.LocalDateTime | ||
|
||
data class BookShelfBookMetadataData( | ||
val id: Int, | ||
@SerializedName("last_update") | ||
val lastUpdate: LocalDateTime, | ||
@SerializedName("book_shelf_ids") | ||
val bookShelfIds: List<Int>, | ||
) | ||
|
||
fun BookshelfBookMetadata.toJsonData() = | ||
BookShelfBookMetadataData( | ||
id = id, | ||
lastUpdate = lastUpdate, | ||
bookShelfIds = bookShelfIds, | ||
) |
22 changes: 22 additions & 0 deletions
22
app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/data/json/BookUserData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package indi.dmzz_yyhyy.lightnovelreader.data.json | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import java.time.LocalDateTime | ||
|
||
data class BookUserData( | ||
val id: Int, | ||
@SerializedName("last_read_time") | ||
val lastReadTime: LocalDateTime, | ||
@SerializedName("total_read_time") | ||
val totalReadTime: Int, | ||
@SerializedName("reading_progress") | ||
val readingProgress: Float, | ||
@SerializedName("last_read_chapter_id") | ||
val lastReadChapterId: Int, | ||
@SerializedName("last_read_chapter_title") | ||
val lastReadChapterTitle: String, | ||
@SerializedName("last_read_chapter_progress") | ||
val lastReadChapterProgress: Float, | ||
@SerializedName("read_completed_chapter_ids") | ||
val readCompletedChapterIds: List<Int>, | ||
) |
34 changes: 34 additions & 0 deletions
34
app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/data/json/BookshelfData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package indi.dmzz_yyhyy.lightnovelreader.data.json | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import indi.dmzz_yyhyy.lightnovelreader.data.bookshelf.Bookshelf | ||
import indi.dmzz_yyhyy.lightnovelreader.data.bookshelf.BookshelfSortType | ||
|
||
data class BookshelfData( | ||
val id: Int, | ||
val name: String, | ||
@SerializedName("sort_type") | ||
val sortType: BookshelfSortType, | ||
@SerializedName("auto_cache") | ||
val autoCache: Boolean, | ||
@SerializedName("system_update_reminder") | ||
val systemUpdateReminder: Boolean, | ||
@SerializedName("all_book_ids") | ||
val allBookIds: List<Int>, | ||
@SerializedName("pinned_book_ids") | ||
val pinnedBookIds: List<Int>, | ||
@SerializedName("updatedBookIds") | ||
val updatedBookIds: List<Int>, | ||
) | ||
|
||
fun Bookshelf.toJsonData(): BookshelfData = | ||
BookshelfData( | ||
id = id, | ||
name = name, | ||
sortType = sortType, | ||
autoCache = autoCache, | ||
systemUpdateReminder = systemUpdateReminder, | ||
allBookIds = allBookIds, | ||
pinnedBookIds = pinnedBookIds, | ||
updatedBookIds = updatedBookIds, | ||
) |
16 changes: 16 additions & 0 deletions
16
...rc/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/data/json/BookshelfSortTypeTypeAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package indi.dmzz_yyhyy.lightnovelreader.data.json | ||
|
||
import com.google.gson.TypeAdapter | ||
import com.google.gson.stream.JsonReader | ||
import com.google.gson.stream.JsonWriter | ||
import indi.dmzz_yyhyy.lightnovelreader.data.bookshelf.BookshelfSortType | ||
|
||
object BookshelfSortTypeTypeAdapter : TypeAdapter<BookshelfSortType>() { | ||
override fun write(out: JsonWriter?, value: BookshelfSortType?) { | ||
out?.value(value?.key) | ||
} | ||
|
||
override fun read(`in`: JsonReader?): BookshelfSortType { | ||
return `in`?.nextString()?.let { BookshelfSortType.map(it) } ?: BookshelfSortType.Default | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/data/json/LocalTimeDataTypeAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package indi.dmzz_yyhyy.lightnovelreader.data.json | ||
|
||
import com.google.gson.TypeAdapter | ||
import com.google.gson.stream.JsonReader | ||
import com.google.gson.stream.JsonWriter | ||
import java.time.LocalDateTime | ||
|
||
object LocalTimeDataTypeAdapter : TypeAdapter<LocalDateTime>() { | ||
override fun write(out: JsonWriter?, value: LocalDateTime?) { | ||
out?.value(value.toString()) | ||
} | ||
|
||
override fun read(`in`: JsonReader?): LocalDateTime { | ||
return LocalDateTime.parse(`in`?.nextString()) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/data/json/UserDataData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package indi.dmzz_yyhyy.lightnovelreader.data.json | ||
|
||
data class UserDataData( | ||
val path: String, | ||
val group: String, | ||
val type: String, | ||
val value: String | ||
) |
Oops, something went wrong.