Merge remote-tracking branch 'origin/master'

pull/332/head
gedoor 4 years ago
commit d9c0dccc2a
  1. 1
      app/src/main/assets/updateLog.md
  2. 44
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  3. 38
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt
  4. 10
      app/src/main/res/menu/book_source_sel.xml
  5. 1
      app/src/main/res/values-zh-rHK/strings.xml
  6. 1
      app/src/main/res/values-zh-rTW/strings.xml
  7. 1
      app/src/main/res/values-zh/strings.xml
  8. 1
      app/src/main/res/values/strings.xml

@ -7,6 +7,7 @@
* 应用被杀死时停止朗读 * 应用被杀死时停止朗读
* 默认封面添加删除操作 * 默认封面添加删除操作
* 备份阅读记录 * 备份阅读记录
* 书源添加移除分组支持多选,多个分组以逗号(中英均可)隔开
**2020/08/22** **2020/08/22**
* 添加阅读时间记录 * 添加阅读时间记录

@ -227,6 +227,8 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
R.id.menu_check_source -> checkSource() R.id.menu_check_source -> checkSource()
R.id.menu_top_sel -> viewModel.topSource(*adapter.getSelection().toTypedArray()) R.id.menu_top_sel -> viewModel.topSource(*adapter.getSelection().toTypedArray())
R.id.menu_bottom_sel -> viewModel.bottomSource(*adapter.getSelection().toTypedArray()) R.id.menu_bottom_sel -> viewModel.bottomSource(*adapter.getSelection().toTypedArray())
R.id.menu_add_group -> selectionAddToGroups()
R.id.menu_remove_group -> selectionRemoveFromGroups()
} }
return true return true
} }
@ -253,6 +255,48 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
}.show().applyTint() }.show().applyTint()
} }
@SuppressLint("InflateParams")
private fun selectionAddToGroups() {
alert(titleResource = R.string.add_group) {
var editText: AutoCompleteTextView? = null
customView {
layoutInflater.inflate(R.layout.dialog_edit_text, null).apply {
editText = edit_view
edit_view.setHint(R.string.group_name)
}
}
okButton {
editText?.text?.toString()?.let {
if (it.isNotEmpty()) {
viewModel.selectionAddToGroups(adapter.getSelection(), it)
}
}
}
noButton { }
}.show().applyTint()
}
@SuppressLint("InflateParams")
private fun selectionRemoveFromGroups() {
alert(titleResource = R.string.remove_group) {
var editText: AutoCompleteTextView? = null
customView {
layoutInflater.inflate(R.layout.dialog_edit_text, null).apply {
editText = edit_view
edit_view.setHint(R.string.group_name)
}
}
okButton {
editText?.text?.toString()?.let {
if (it.isNotEmpty()) {
viewModel.selectionRemoveFromGroups(adapter.getSelection(), it)
}
}
}
noButton { }
}.show().applyTint()
}
private fun upGroupMenu() { private fun upGroupMenu() {
groupMenu?.removeGroup(R.id.source_group) groupMenu?.removeGroup(R.id.source_group)
groups.sortedWith(Collator.getInstance(java.util.Locale.CHINESE)) groups.sortedWith(Collator.getInstance(java.util.Locale.CHINESE))

@ -93,6 +93,44 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun selectionAddToGroups(sources: List<BookSource>, groups: String) {
execute {
val list = arrayListOf<BookSource>()
sources.forEach {
val newGroupList = arrayListOf<String>()
it.bookSourceGroup?.splitNotBlank(",", ";")?.forEach {
newGroupList.add(it)
}
groups.splitNotBlank(",", ";", "").forEach {
newGroupList.add(it)
}
val lh = LinkedHashSet(newGroupList)
val newGroup = ArrayList(lh).joinToString(separator = ",")
list.add(it.copy(bookSourceGroup = newGroup))
}
App.db.bookSourceDao().update(*list.toTypedArray())
}
}
fun selectionRemoveFromGroups(sources: List<BookSource>, groups: String) {
execute {
val list = arrayListOf<BookSource>()
sources.forEach {
val newGroupList = arrayListOf<String>()
it.bookSourceGroup?.splitNotBlank(",", ";")?.forEach {
newGroupList.add(it)
}
groups.splitNotBlank(",", ";", "").forEach {
newGroupList.remove(it)
}
val lh = LinkedHashSet(newGroupList)
val newGroup = ArrayList(lh).joinToString(separator = ",")
list.add(it.copy(bookSourceGroup = newGroup))
}
App.db.bookSourceDao().update(*list.toTypedArray())
}
}
fun delSelection(sources: List<BookSource>) { fun delSelection(sources: List<BookSource>) {
execute { execute {
App.db.bookSourceDao().delete(*sources.toTypedArray()) App.db.bookSourceDao().delete(*sources.toTypedArray())

@ -12,6 +12,16 @@
android:title="@string/disable_selection" android:title="@string/disable_selection"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_add_group"
android:title="@string/add_group"
app:showAsAction="never" />
<item
android:id="@+id/menu_remove_group"
android:title="@string/remove_group"
app:showAsAction="never" />
<item <item
android:id="@+id/menu_enable_explore" android:id="@+id/menu_enable_explore"
android:title="@string/enable_explore" android:title="@string/enable_explore"

@ -553,6 +553,7 @@
<string name="group_edit">編輯分組</string> <string name="group_edit">編輯分組</string>
<string name="move_to_group">移入分組</string> <string name="move_to_group">移入分組</string>
<string name="add_group">添加分組</string> <string name="add_group">添加分組</string>
<string name="remove_group">移除分組</string>
<string name="add_replace_rule">新建替換</string> <string name="add_replace_rule">新建替換</string>
<string name="group">分組</string> <string name="group">分組</string>
<string name="group_s">分組: %s</string> <string name="group_s">分組: %s</string>

@ -554,6 +554,7 @@
<string name="group_edit">編輯分組</string> <string name="group_edit">編輯分組</string>
<string name="move_to_group">移入分組</string> <string name="move_to_group">移入分組</string>
<string name="add_group">添加分組</string> <string name="add_group">添加分組</string>
<string name="remove_group">移除分組</string>
<string name="add_replace_rule">建立取代</string> <string name="add_replace_rule">建立取代</string>
<string name="group">分組</string> <string name="group">分組</string>
<string name="group_s">分組: %s</string> <string name="group_s">分組: %s</string>

@ -555,6 +555,7 @@
<string name="group_edit">编辑分组</string> <string name="group_edit">编辑分组</string>
<string name="move_to_group">移入分组</string> <string name="move_to_group">移入分组</string>
<string name="add_group">添加分组</string> <string name="add_group">添加分组</string>
<string name="remove_group">移除分组</string>
<string name="add_replace_rule">新建替换</string> <string name="add_replace_rule">新建替换</string>
<string name="group">分组</string> <string name="group">分组</string>
<string name="group_s">分组: %s</string> <string name="group_s">分组: %s</string>

@ -557,6 +557,7 @@
<string name="group_edit">Group editing</string> <string name="group_edit">Group editing</string>
<string name="move_to_group">Move to group</string> <string name="move_to_group">Move to group</string>
<string name="add_group">Add to Groups</string> <string name="add_group">Add to Groups</string>
<string name="remove_group">Remove from Groups</string>
<string name="add_replace_rule">New replacement</string> <string name="add_replace_rule">New replacement</string>
<string name="group">Group</string> <string name="group">Group</string>
<string name="group_s">Group: %s</string> <string name="group_s">Group: %s</string>

Loading…
Cancel
Save