-
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.
Merge pull request #120 from dmzz-yyhyy/data_export
数据导出功能
- Loading branch information
Showing
92 changed files
with
3,676 additions
and
1,080 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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
107 changes: 107 additions & 0 deletions
107
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,107 @@ | ||
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 type: String, | ||
val id: Int? = null, | ||
val data: List<AppUserDataContent> | ||
) { | ||
companion object { | ||
val gson: Gson = GsonBuilder() | ||
.serializeSpecialFloatingPointValues() | ||
.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( | ||
type = "light novel reader data file", | ||
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, | ||
) |
Oops, something went wrong.