Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object ApiCompat {
*/
private val groups: List<Set<Int>> = listOf(
setOf(1),
setOf(2, 3)
setOf(2, 3, 4)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api 4存在编译行为大改,无法向下兼容

)

private fun groupOf(v: Int): Int? =
Expand Down
11 changes: 11 additions & 0 deletions api/src/main/kotlin/io/nightfish/lightnovelreader/api/Route.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ object Route {
/** 书架主界面路由 */
@Serializable
object Home
/** 书本排序界面路由
*
* @param id 书架id
*/
@Serializable
data class ReorderBooks(
val id: Int
)
/** 书架排序界面路由 */
@Serializable
object ReorderBookshelves
/**
* 书架编辑界面路由
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import androidx.compose.runtime.setValue
* @property id 书架id
* @property name 书架名称
* @property sortType 书架排序方式
* @property sortReversed 是否反向排序
* @property autoCache 是否开启自动缓存
* @property systemUpdateReminder 是否开启系统更新提醒
* @property systemUpdateReminder 是否通过系统通知提醒更新
* @property allBookIds 书架中所有书本的id列表
* @property pinnedBookIds 置顶的书本的id列表
* @property updatedBookIds 有新章节更新的书本的id列表
Expand All @@ -25,6 +26,7 @@ interface Bookshelf {
val id: Int
val name: String
val sortType: BookshelfSortType
val sortReversed: Boolean
val autoCache: Boolean
val systemUpdateReminder: Boolean
val allBookIds: List<String>
Expand All @@ -48,8 +50,9 @@ interface Bookshelf {
* @property id 书架id,默认为-1表示为空
* @property name 书架名称
* @property sortType 书架排序方式
* @property sortReversed 是否反向排序
* @property autoCache 是否开启自动缓存
* @property systemUpdateReminder 是否开启系统更新提醒
* @property systemUpdateReminder 是否通过系统通知提醒更新
* @property allBookIds 书架中所有书本的id列表
* @property pinnedBookIds 置顶的书本的id列表
* @property updatedBookIds 有新章节更新的书本的id列表
Expand All @@ -60,6 +63,7 @@ class MutableBookshelf : Bookshelf {
override var id by mutableIntStateOf(-1)
override var name by mutableStateOf("")
override var sortType by mutableStateOf(BookshelfSortType.Default)
override var sortReversed by mutableStateOf(false)
override var autoCache by mutableStateOf(false)
override var systemUpdateReminder by mutableStateOf(false)
override var allBookIds by mutableStateOf<List<String>>(listOf())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ interface BookshelfRepositoryApi {
* @param name 书架名称
* @param sortType 书架排序方式
* @param autoCache 是否开启自动缓存
* @param systemUpdateReminder 是否开启系统更新提醒
* @param systemUpdateReminder 是否通过系统通知提醒更新
*
* @return 新建书架的id
*
Expand All @@ -152,6 +152,7 @@ interface BookshelfRepositoryApi {
id: Int = Instant.now().epochSecond.hashCode(),
name: String,
sortType: BookshelfSortType,
sortReversed: Boolean = false,
autoCache: Boolean,
systemUpdateReminder: Boolean
): Int
Expand Down

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

书架的排序包括

  • 默认:按照添加顺序的逆序
  • 字数
  • 名称排序:首字母(A-Z),汉语字符使用tinypinyin获取拼音后按照字母顺序排序
    除了默认排序之外都支持反转顺序

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ enum class BookshelfSortType(val key: String) {
/** 默认排序(添加的逆序) */
Default("default"),
/** 按最新更新时间排序 */
Latest("latest");
Latest("latest"),
/** 按名称排序 */
Name("name"),
/** 按字数排序 */
WordCount("word_count");

/** [BookshelfSortType]的工厂方法集合 */
companion object {
/**
Expand All @@ -23,6 +28,6 @@ enum class BookshelfSortType(val key: String) {
*
* @since Api 2
*/
fun map(key: String): BookshelfSortType = entries.first { it.key == key }
fun map(key: String): BookshelfSortType = entries.firstOrNull { it.key == key } ?: Default
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ sealed class UserDataPath(
}
/** 当前正在阅读的书籍列表路径 @since Api 2 */
data object ReadingBooks : UserDataPath("reading_books")
/** 书架排序路径 @since Api 4 */
data object BookshelfOrder : UserDataPath("bookshelf_order")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

什么叫做排序路径啊

/** 搜索相关用户数据路径组 @since Api 2 */
data object Search: UserDataPath("search") {
/** 搜索历史记录 @since Api 2 */
Expand Down
9 changes: 6 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
minSdk = 24
targetSdk = 36
// 版本号为x.y.z则versionCode为x*1000000+y*10000+z*1000+debug版本号(开发需要时迭代, 三位数)
versionCode = 1_02_01_003
versionCode = 1_02_01_004
versionName = "1.2.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -207,7 +207,10 @@ dependencies {
implementation(libs.re2j)
// Matomo
implementation(libs.matomo.sdk.android)
}
// Reorderable
implementation(libs.reorderable)
// Source: https://mvnrepository.com/artifact/com.github.promeg/tinypinyin
implementation("com.github.promeg:tinypinyin:2.0.3")}

configurations.implementation {
exclude(group = "com.intellij", module = "annotations")
Expand All @@ -223,4 +226,4 @@ tasks.register("printVersionCode") {
doFirst {
println(android.defaultConfig.versionCode)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class MainActivity : ComponentActivity() {
id = 1145140721,
name = "已收藏",
sortType = BookshelfSortType.Default,
sortReversed = false,
autoCache = false,
systemUpdateReminder = false
)
Expand Down Expand Up @@ -241,4 +242,4 @@ class MainActivity : ComponentActivity() {
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class BookshelfRepository @Inject constructor(
MutableBookshelf().apply {
this.id = bookshelfEntity.id
this.name = bookshelfEntity.name
this.sortType = BookshelfSortType.entries.first { it.key == bookshelfEntity.sortType }
this.sortType = BookshelfSortType.map(bookshelfEntity.sortType)
this.sortReversed = bookshelfEntity.sortReversed
this.autoCache = bookshelfEntity.autoCache
this.systemUpdateReminder = bookshelfEntity.systemUpdateReminder
this.allBookIds = bookshelfEntity.allBookIds
Expand All @@ -46,7 +47,8 @@ class BookshelfRepository @Inject constructor(
MutableBookshelf().apply {
this.id = bookshelfEntity.id
this.name = bookshelfEntity.name
this.sortType = BookshelfSortType.entries.first { it.key == bookshelfEntity.sortType }
this.sortType = BookshelfSortType.map(bookshelfEntity.sortType)
this.sortReversed = bookshelfEntity.sortReversed
this.autoCache = bookshelfEntity.autoCache
this.systemUpdateReminder = bookshelfEntity.systemUpdateReminder
this.allBookIds = bookshelfEntity.allBookIds
Expand All @@ -60,7 +62,8 @@ class BookshelfRepository @Inject constructor(
val bookshelfEntity = bookshelfDao.getBookshelf(id) ?: return null
this.id = id
this.name = bookshelfEntity.name
this.sortType = BookshelfSortType.entries.first { it.key == bookshelfEntity.sortType }
this.sortType = BookshelfSortType.map(bookshelfEntity.sortType)
this.sortReversed = bookshelfEntity.sortReversed
this.autoCache = bookshelfEntity.autoCache
this.systemUpdateReminder = bookshelfEntity.systemUpdateReminder
this.allBookIds = bookshelfEntity.allBookIds
Expand All @@ -75,7 +78,8 @@ class BookshelfRepository @Inject constructor(
MutableBookshelf().apply {
this.id = id
this.name = bookshelfEntity.name
this.sortType = BookshelfSortType.entries.first { it.key == bookshelfEntity.sortType }
this.sortType = BookshelfSortType.map(bookshelfEntity.sortType)
this.sortReversed = bookshelfEntity.sortReversed
this.autoCache = bookshelfEntity.autoCache
this.systemUpdateReminder = bookshelfEntity.systemUpdateReminder
this.allBookIds = bookshelfEntity.allBookIds
Expand All @@ -88,13 +92,15 @@ class BookshelfRepository @Inject constructor(
id: Int,
name: String,
sortType: BookshelfSortType,
sortReversed: Boolean,
autoCache: Boolean,
systemUpdateReminder: Boolean,
): Int {
bookshelfDao.createBookshelf(BookshelfEntity(
id = id,
name = name,
sortType = sortType.key,
sortReversed = sortReversed,
autoCache = autoCache,
systemUpdateReminder = systemUpdateReminder,
allBookIds = emptyList(),
Expand Down Expand Up @@ -162,6 +168,7 @@ class BookshelfRepository @Inject constructor(
bookshelfId,
newBookshelf.name,
newBookshelf.sortType.key,
newBookshelf.sortReversed,
newBookshelf.autoCache,
newBookshelf.systemUpdateReminder,
newBookshelf.allBookIds,
Expand Down Expand Up @@ -241,4 +248,4 @@ class BookshelfRepository @Inject constructor(
}

override fun clear() = bookshelfDao.clear()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import io.nightfish.lightnovelreader.api.content.builder.simpleText
DailyCountEntity::class,
FormattingRuleEntity::class
],
version = 16,
version = 17,
exportSchema = false
)
abstract class LightNovelReaderDatabase : RoomDatabase() {
Expand Down Expand Up @@ -89,7 +89,8 @@ abstract class LightNovelReaderDatabase : RoomDatabase() {
MIGRATION_12_13,
MIGRATION_13_14,
MIGRATION_14_15,
MIGRATION_15_16
MIGRATION_15_16,
MIGRATION_16_17
)
.allowMainThreadQueries()
.build()
Expand Down Expand Up @@ -875,5 +876,13 @@ abstract class LightNovelReaderDatabase : RoomDatabase() {
db.execSQL("DROP TABLE IF EXISTS reading_statistics")
}
}

private val MIGRATION_16_17 = object : Migration(16, 17) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL(
"alter table book_shelf add sort_reversed INTEGER NOT NULL DEFAULT 0"
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ data class BookshelfEntity(
val name: String,
@ColumnInfo(name = "sort_type")
val sortType: String,
@ColumnInfo(name = "sort_reversed")
val sortReversed: Boolean = false,
@ColumnInfo(name = "auto_cache")
val autoCache: Boolean,
@ColumnInfo(name = "system_update_reminder")
Expand All @@ -32,6 +34,7 @@ data class BookshelfEntity(
id = new.id,
name = new.name,
sortType = new.sortType,
sortReversed = new.sortReversed,
autoCache = new.autoCache,
systemUpdateReminder = new.systemUpdateReminder,
allBookIds = (this.allBookIds + new.allBookIds).distinct(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.navigation
import indi.dmzz_yyhyy.lightnovelreader.ui.home.bookshelf.edit.bookshelfEditDestination
import indi.dmzz_yyhyy.lightnovelreader.ui.home.bookshelf.home.bookshelfHomeDestination
import indi.dmzz_yyhyy.lightnovelreader.ui.home.bookshelf.reorder.bookshelfReorderDestination
import io.nightfish.lightnovelreader.api.Route

@OptIn(ExperimentalSharedTransitionApi::class)
Expand All @@ -16,6 +17,7 @@ fun NavGraphBuilder.bookshelfNavigation(sharedTransitionScope: SharedTransitionS
) {
bookshelfHomeDestination(sharedTransitionScope)
bookshelfEditDestination()
bookshelfReorderDestination()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fun NavGraphBuilder.bookshelfEditDestination() {
},
onClickDelete = navController::navigateToDeleteBookshelfDialog,
onNameChange = editBookshelfViewModel::onNameChange,
onSortTypeChange = editBookshelfViewModel::onSortTypeChange,
onAutoCacheChange = editBookshelfViewModel::onAutoCacheChange,
onSystemUpdateReminderChange = editBookshelfViewModel::onSystemUpdateReminderChange,
)
Expand Down
Loading
Loading