Skip to content

Commit

Permalink
Merge pull request #3229 from Discut/master
Browse files Browse the repository at this point in the history
Add Comprehensive Sort
  • Loading branch information
gedoor authored Jul 16, 2023
2 parents 2d413b5 + 0a7760c commit 42e004f
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ class BookshelfFragment1() : BaseBookshelfFragment(R.layout.fragment_bookshelf1)
if (data != bookGroups) {
bookGroups.clear()
bookGroups.addAll(data)
/**
* 在书架布局对话框修改排序后,会导致书架页面刷新。但是在分组标签未修改的情况下,此处的adapter.notifyDataSetChanged()调用不会引起
* [io.legado.app.ui.main.bookshelf.style1.BookshelfFragment1.TabFragmentPageAdapter.getItemPosition]
* 被调用。
* 有关方法:
* [androidx.viewpager.widget.ViewPager.dataSetChanged]
*/
adapter.notifyDataSetChanged()
selectLastTab()
for (i in 0 until adapter.count) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ import kotlin.math.max
class BooksFragment() : BaseFragment(R.layout.fragment_books),
BaseBooksAdapter.CallBack {

lateinit var group: BookGroup

constructor(position: Int, group: BookGroup) : this() {
val bundle = Bundle()
this.group = group
bundle.putInt("position", position)
bundle.putLong("groupId", group.groupId)
bundle.putInt("bookSort", group.getRealBookSort())
Expand Down Expand Up @@ -80,6 +83,9 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
bookSort = it.getInt("bookSort", 0)
binding.refreshLayout.isEnabled = it.getBoolean("enableRefresh", true)
}
appDb.bookGroupDao.getByID(groupId)?.apply {
group = this
}
initRecyclerView()
upRecyclerData()
}
Expand Down Expand Up @@ -129,6 +135,9 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
binding.refreshLayout.isEnabled = enableRefresh
}

/**
* 更新书籍列表信息
*/
private fun upRecyclerData() {
booksFlowJob?.cancel()
booksFlowJob = launch {
Expand All @@ -140,13 +149,22 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
AppConst.bookGroupLocalNoneId -> appDb.bookDao.flowLocalNoGroup()
AppConst.bookGroupErrorId -> appDb.bookDao.flowUpdateError()
else -> appDb.bookDao.flowByGroup(groupId)
// 书籍排序
}.conflate().map { list ->
when (bookSort) {
1 -> list.sortedByDescending { it.latestChapterTime }
2 -> list.sortedWith { o1, o2 ->
o1.name.cnCompare(o2.name)
}

3 -> list.sortedBy { it.order }

// 综合排序 issue #3192
4 -> {
list.sortedByDescending {
if(it.latestChapterTime>it.durChapterTime) it.latestChapterTime else it.durChapterTime
}
}
else -> list.sortedByDescending { it.durChapterTime }
}
}.flowOn(Dispatchers.Default).catch {
Expand Down Expand Up @@ -181,6 +199,9 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),

override fun onResume() {
super.onResume()
if (::group.isInitialized) {
bookSort = group.getRealBookSort()
}
startLastUpdateTimeJob()
upRecyclerData()
}
Expand Down Expand Up @@ -244,6 +265,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
startActivity<AudioPlayActivity> {
putExtra("bookUrl", book.bookUrl)
}

else -> startActivity<ReadBookActivity> {
putExtra("bookUrl", book.bookUrl)
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/dialog_bookshelf_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@
android:text="@string/bookshelf_px_3"
tools:ignore="TouchTargetSizeCheck" />

<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/bookshelf_px_4"
tools:ignore="TouchTargetSizeCheck" />

</RadioGroup>

</LinearLayout>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1120,4 +1120,5 @@
<string name="add_all_to_bookshelf">全部加入书架</string>
<string name="page_to">页至</string>
<string name="result_analyzed">Analyzed</string>
<string name="bookshelf_px_4" >Comprehensive</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1123,4 +1123,5 @@
<string name="add_all_to_bookshelf">全部加入书架</string>
<string name="page_to">页至</string>
<string name="result_analyzed">Analyzed</string>
<string name="bookshelf_px_4" >Comprehensive</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1123,4 +1123,5 @@
<string name="add_all_to_bookshelf">全部加入书架</string>
<string name="page_to">页至</string>
<string name="result_analyzed">Analyzed</string>
<string name="bookshelf_px_4" >Comprehensive</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1119,4 +1119,5 @@ Còn </string>
<string name="add_all_to_bookshelf">Thêm tất cả vào giá sách</string>
<string name="page_to">Trang tới</string>
<string name="result_analyzed">Analyzed</string>
<string name="bookshelf_px_4" >Comprehensive</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1120,4 +1120,5 @@
<string name="add_all_to_bookshelf">全部加入书架</string>
<string name="page_to">页至</string>
<string name="result_analyzed">解析示例</string>
<string name="bookshelf_px_4" >綜合排序</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1122,4 +1122,5 @@
<string name="add_all_to_bookshelf">全部加入书架</string>
<string name="page_to">页至</string>
<string name="result_analyzed">解析示例</string>
<string name="bookshelf_px_4" >綜合排序</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1122,4 +1122,5 @@
<string name="add_all_to_bookshelf">全部加入书架</string>
<string name="page_to">页至</string>
<string name="result_analyzed">解析示例</string>
<string name="bookshelf_px_4" >综合排序</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1123,4 +1123,5 @@
<string name="add_all_to_bookshelf">全部加入书架</string>
<string name="page_to">页至</string>
<string name="result_analyzed">Analyzed</string>
<string name="bookshelf_px_4" >Comprehensive</string>
</resources>

0 comments on commit 42e004f

Please sign in to comment.