Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
LM-Firefly committed Dec 21, 2024
2 parents f2b3749 + f1eeec9 commit d1c1b07
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 6 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/io/legado/app/data/dao/RssStarDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ interface RssStarDao {

@Query("delete from rssStars where origin = :origin and link = :link")
fun delete(origin: String, link: String)

@Query("delete from rssStars where `group` = :group")
fun deleteByGroup(group: String)

@Query("delete from rssStars")
fun deleteAll()
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import android.view.SubMenu
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.lifecycle.lifecycleScope
import androidx.viewpager.widget.ViewPager
import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.constant.AppLog
import io.legado.app.data.appDb
import io.legado.app.databinding.ActivityRssFavoritesBinding
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.gone
import io.legado.app.utils.viewbindingdelegate.viewBinding
Expand All @@ -33,6 +35,7 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>() {
private val adapter by lazy { TabFragmentPageAdapter() }
private var groupList = mutableListOf<String>()
private var groupsMenu: SubMenu? = null
private var currentGroup = ""

override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()
Expand All @@ -41,6 +44,21 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>() {

private fun initView() {
binding.viewPager.adapter = adapter
binding.viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrolled(
position: Int,
positionOffset: Float,
positionOffsetPixels: Int
) {
}

override fun onPageSelected(position: Int) {
currentGroup = groupList[position]
}

override fun onPageScrollStateChanged(state: Int) {}

})
binding.tabLayout.setupWithViewPager(binding.viewPager)
binding.tabLayout.setSelectedTabIndicatorColor(accentColor)
}
Expand All @@ -53,16 +71,20 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>() {
}

private fun upGroupsMenu() = groupsMenu?.let { subMenu ->
subMenu.removeGroup(R.id.menu_group_text)
subMenu.removeGroup(R.id.menu_group)
groupList.forEachIndexed { index, it ->
subMenu.add(R.id.menu_group_text, Menu.NONE, index, it)
subMenu.add(R.id.menu_group, Menu.NONE, index, it)
}
}

override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
super.onCompatOptionsItemSelected(item)
if (item.groupId == R.id.menu_group_text) {
if (item.groupId == R.id.menu_group) {
binding.viewPager.setCurrentItem(item.order)
} else {
when (item.itemId) {
R.id.menu_del_group -> deleteGroup()
R.id.menu_del_all -> deleteAll()
}
}
return super.onCompatOptionsItemSelected(item)
}
Expand All @@ -79,10 +101,38 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>() {
} else {
binding.tabLayout.visible()
}
if (groupsMenu != null){
if (groupsMenu != null) {
upGroupsMenu()
}
adapter.notifyDataSetChanged()
val item = groupList.indexOf(currentGroup)
if (item > -1) {
binding.viewPager.setCurrentItem(item)
} else if (groupList.isNotEmpty()) {
currentGroup = groupList[binding.viewPager.currentItem]
}
}
}
}

private fun deleteGroup() {
alert(R.string.draw) {
val item = binding.viewPager.currentItem
val group = groupList[item]
setMessage(getString(R.string.sure_del) + "\n" + group + " 分组的收藏")
noButton()
yesButton {
appDb.rssStarDao.deleteByGroup(group)
}
}
}

private fun deleteAll() {
alert(R.string.draw) {
setMessage(getString(R.string.sure_del) + "\n" + "所有收藏")
noButton()
yesButton {
appDb.rssStarDao.deleteAll()
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/res/menu/rss_favorites.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="AlwaysShowAction">

<item
android:id="@+id/menu_group"
Expand All @@ -11,5 +13,14 @@
<menu />

</item>
<item
android:id="@+id/menu_del_group"
android:title="@string/delete_select_group"
app:showAsAction="never" />

<item
android:id="@+id/menu_del_all"
android:title="@string/delete_all"
app:showAsAction="never" />

</menu>
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 @@ -32,6 +32,7 @@
<string name="draw">Advertencia</string>
<string name="edit">Editar</string>
<string name="delete">Borrar</string>
<string name="delete_select_group">Delete Select Group</string>
<string name="delete_all">Borrar todo</string>
<string name="replace">Reemplazar</string>
<string name="replace_purify">Reemplazo</string>
Expand Down
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 @@ -32,6 +32,7 @@
<string name="draw">Warning</string>
<string name="edit">Edit</string>
<string name="delete">Delete</string>
<string name="delete_select_group">Delete Select Group</string>
<string name="delete_all">Delete all</string>
<string name="replace">Replace</string>
<string name="replace_purify">Replacement</string>
Expand Down
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 @@ -32,6 +32,7 @@
<string name="draw">Aviso</string>
<string name="edit">Editar</string>
<string name="delete">Excluir</string>
<string name="delete_select_group">Delete Select Group</string>
<string name="delete_all">Excluir tudo</string>
<string name="replace">Substituir</string>
<string name="replace_purify">Substituição</string>
Expand Down
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 @@ -29,6 +29,7 @@
<string name="draw">Cảnh báo</string>
<string name="edit">Sửa đổi</string>
<string name="delete">Xóa</string>
<string name="delete_select_group">Xóa nhóm hiện tại</string>
<string name="delete_all">Xóa tất cả</string>
<string name="custom_export_section">Chương xuất tùy chỉnh của epub</string>
<string name="replace">Thay thế</string>
Expand Down
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 @@ -28,6 +28,7 @@
<string name="draw">提醒</string>
<string name="edit">編輯</string>
<string name="delete">刪除</string>
<string name="delete_select_group">刪除當前分組</string>
<string name="replace">替換</string>
<string name="replace_purify">替換淨化</string>
<string name="replace_purify_desc">配置替換淨化規則</string>
Expand Down
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 @@ -29,6 +29,7 @@
<string name="draw">提醒</string>
<string name="edit">編輯</string>
<string name="delete">刪除</string>
<string name="delete_select_group">刪除當前分組</string>
<string name="delete_all">刪除所有</string>
<string name="replace">取代</string>
<string name="replace_purify">取代淨化</string>
Expand Down
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 @@ -29,6 +29,7 @@
<string name="draw">提醒</string>
<string name="edit">编辑</string>
<string name="delete">删除</string>
<string name="delete_select_group">删除当前分组</string>
<string name="delete_all">删除所有</string>
<string name="replace">替换</string>
<string name="replace_purify">替换净化</string>
Expand Down
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 @@ -32,6 +32,7 @@
<string name="draw">Warning</string>
<string name="edit">Edit</string>
<string name="delete">Delete</string>
<string name="delete_select_group">Delete Select Group</string>
<string name="delete_all">Delete all</string>
<string name="custom_export_section">Custom export chapter of epub</string>
<string name="replace">Replace</string>
Expand Down

0 comments on commit d1c1b07

Please sign in to comment.