mirror of
https://github.com/gedoor/legado.git
synced 2024-09-03 09:55:00 +08:00
优化
This commit is contained in:
parent
0cdaaecacf
commit
7bf0a00b14
@ -144,14 +144,37 @@ class ImportBookSourceDialog() : BaseDialogFragment(R.layout.dialog_recycler_vie
|
|||||||
?.isChecked = AppConfig.importKeepGroup
|
?.isChecked = AppConfig.importKeepGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams", "NotifyDataSetChanged")
|
||||||
override fun onMenuItemClick(item: MenuItem): Boolean {
|
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.menu_new_group -> alertCustomGroup(item)
|
R.id.menu_new_group -> alertCustomGroup(item)
|
||||||
|
R.id.menu_select_new_source -> {
|
||||||
|
val selectAllNew = viewModel.isSelectAllNew
|
||||||
|
viewModel.newSourceStatus.forEachIndexed { index, b ->
|
||||||
|
if (b) {
|
||||||
|
viewModel.selectStatus[index] = !selectAllNew
|
||||||
|
}
|
||||||
|
}
|
||||||
|
adapter.notifyDataSetChanged()
|
||||||
|
upSelectText()
|
||||||
|
}
|
||||||
|
|
||||||
|
R.id.menu_select_update_source -> {
|
||||||
|
val selectAllUpdate = viewModel.isSelectAllUpdate
|
||||||
|
viewModel.updateSourceStatus.forEachIndexed { index, b ->
|
||||||
|
if (b) {
|
||||||
|
viewModel.selectStatus[index] = !selectAllUpdate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
adapter.notifyDataSetChanged()
|
||||||
|
upSelectText()
|
||||||
|
}
|
||||||
|
|
||||||
R.id.menu_keep_original_name -> {
|
R.id.menu_keep_original_name -> {
|
||||||
item.isChecked = !item.isChecked
|
item.isChecked = !item.isChecked
|
||||||
putPrefBoolean(PreferKey.importKeepName, item.isChecked)
|
putPrefBoolean(PreferKey.importKeepName, item.isChecked)
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.menu_keep_group -> {
|
R.id.menu_keep_group -> {
|
||||||
item.isChecked = !item.isChecked
|
item.isChecked = !item.isChecked
|
||||||
putPrefBoolean(PreferKey.importKeepGroup, item.isChecked)
|
putPrefBoolean(PreferKey.importKeepGroup, item.isChecked)
|
||||||
|
@ -29,6 +29,8 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
|
|||||||
val allSources = arrayListOf<BookSource>()
|
val allSources = arrayListOf<BookSource>()
|
||||||
val checkSources = arrayListOf<BookSource?>()
|
val checkSources = arrayListOf<BookSource?>()
|
||||||
val selectStatus = arrayListOf<Boolean>()
|
val selectStatus = arrayListOf<Boolean>()
|
||||||
|
val newSourceStatus = arrayListOf<Boolean>()
|
||||||
|
val updateSourceStatus = arrayListOf<Boolean>()
|
||||||
|
|
||||||
val isSelectAll: Boolean
|
val isSelectAll: Boolean
|
||||||
get() {
|
get() {
|
||||||
@ -40,6 +42,26 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val isSelectAllNew: Boolean
|
||||||
|
get() {
|
||||||
|
newSourceStatus.forEachIndexed { index, b ->
|
||||||
|
if (b && !selectStatus[index]) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSelectAllUpdate: Boolean
|
||||||
|
get() {
|
||||||
|
updateSourceStatus.forEachIndexed { index, b ->
|
||||||
|
if (b && !selectStatus[index]) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
val selectCount: Int
|
val selectCount: Int
|
||||||
get() {
|
get() {
|
||||||
var count = 0
|
var count = 0
|
||||||
@ -109,19 +131,23 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mText.isJsonArray() -> GSON.fromJsonArray<BookSource>(mText).getOrThrow()
|
mText.isJsonArray() -> GSON.fromJsonArray<BookSource>(mText).getOrThrow()
|
||||||
.let { items ->
|
.let { items ->
|
||||||
allSources.addAll(items)
|
allSources.addAll(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
mText.isAbsUrl() -> {
|
mText.isAbsUrl() -> {
|
||||||
importSourceUrl(mText)
|
importSourceUrl(mText)
|
||||||
}
|
}
|
||||||
|
|
||||||
mText.isUri() -> {
|
mText.isUri() -> {
|
||||||
val uri = Uri.parse(mText)
|
val uri = Uri.parse(mText)
|
||||||
uri.inputStream(context).getOrThrow().let {
|
uri.inputStream(context).getOrThrow().let {
|
||||||
allSources.addAll(GSON.fromJsonArray<BookSource>(it).getOrThrow())
|
allSources.addAll(GSON.fromJsonArray<BookSource>(it).getOrThrow())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> throw NoStackTraceException(context.getString(R.string.wrong_format))
|
else -> throw NoStackTraceException(context.getString(R.string.wrong_format))
|
||||||
}
|
}
|
||||||
}.onError {
|
}.onError {
|
||||||
@ -151,6 +177,8 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
|
|||||||
val source = appDb.bookSourceDao.getBookSource(it.bookSourceUrl)
|
val source = appDb.bookSourceDao.getBookSource(it.bookSourceUrl)
|
||||||
checkSources.add(source)
|
checkSources.add(source)
|
||||||
selectStatus.add(source == null || source.lastUpdateTime < it.lastUpdateTime)
|
selectStatus.add(source == null || source.lastUpdateTime < it.lastUpdateTime)
|
||||||
|
newSourceStatus.add(source == null)
|
||||||
|
updateSourceStatus.add(source != null && source.lastUpdateTime < it.lastUpdateTime)
|
||||||
}
|
}
|
||||||
successLiveData.postValue(allSources.size)
|
successLiveData.postValue(allSources.size)
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,16 @@
|
|||||||
app:showAsAction="always"
|
app:showAsAction="always"
|
||||||
tools:ignore="AlwaysShowAction" />
|
tools:ignore="AlwaysShowAction" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_select_new_source"
|
||||||
|
android:title="@string/select_new_source"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_select_update_source"
|
||||||
|
android:title="@string/select_update_source"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_keep_original_name"
|
android:id="@+id/menu_keep_original_name"
|
||||||
android:title="@string/keep_original_name"
|
android:title="@string/keep_original_name"
|
||||||
|
@ -1092,4 +1092,6 @@
|
|||||||
<string name="create_folder">创建文件夹</string>
|
<string name="create_folder">创建文件夹</string>
|
||||||
<string name="allow_drop_down_refresh">允许下拉刷新</string>
|
<string name="allow_drop_down_refresh">允许下拉刷新</string>
|
||||||
<string name="text_underline">文字下划线</string>
|
<string name="text_underline">文字下划线</string>
|
||||||
|
<string name="select_new_source">选中新增源</string>
|
||||||
|
<string name="select_update_source">选中更新源</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1095,4 +1095,6 @@
|
|||||||
<string name="create_folder">创建文件夹</string>
|
<string name="create_folder">创建文件夹</string>
|
||||||
<string name="allow_drop_down_refresh">允许下拉刷新</string>
|
<string name="allow_drop_down_refresh">允许下拉刷新</string>
|
||||||
<string name="text_underline">文字下划线</string>
|
<string name="text_underline">文字下划线</string>
|
||||||
|
<string name="select_new_source">选中新增源</string>
|
||||||
|
<string name="select_update_source">选中更新源</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1095,4 +1095,6 @@
|
|||||||
<string name="create_folder">创建文件夹</string>
|
<string name="create_folder">创建文件夹</string>
|
||||||
<string name="allow_drop_down_refresh">允许下拉刷新</string>
|
<string name="allow_drop_down_refresh">允许下拉刷新</string>
|
||||||
<string name="text_underline">文字下划线</string>
|
<string name="text_underline">文字下划线</string>
|
||||||
|
<string name="select_new_source">选中新增源</string>
|
||||||
|
<string name="select_update_source">选中更新源</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1092,4 +1092,6 @@
|
|||||||
<string name="create_folder">创建文件夹</string>
|
<string name="create_folder">创建文件夹</string>
|
||||||
<string name="allow_drop_down_refresh">允许下拉刷新</string>
|
<string name="allow_drop_down_refresh">允许下拉刷新</string>
|
||||||
<string name="text_underline">文字下划线</string>
|
<string name="text_underline">文字下划线</string>
|
||||||
|
<string name="select_new_source">选中新增源</string>
|
||||||
|
<string name="select_update_source">选中更新源</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1094,4 +1094,6 @@
|
|||||||
<string name="create_folder">创建文件夹</string>
|
<string name="create_folder">创建文件夹</string>
|
||||||
<string name="allow_drop_down_refresh">允许下拉刷新</string>
|
<string name="allow_drop_down_refresh">允许下拉刷新</string>
|
||||||
<string name="text_underline">文字下划线</string>
|
<string name="text_underline">文字下划线</string>
|
||||||
|
<string name="select_new_source">选中新增源</string>
|
||||||
|
<string name="select_update_source">选中更新源</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1094,4 +1094,6 @@
|
|||||||
<string name="create_folder">创建文件夹</string>
|
<string name="create_folder">创建文件夹</string>
|
||||||
<string name="allow_drop_down_refresh">允许下拉刷新</string>
|
<string name="allow_drop_down_refresh">允许下拉刷新</string>
|
||||||
<string name="text_underline">文字下划线</string>
|
<string name="text_underline">文字下划线</string>
|
||||||
|
<string name="select_new_source">选中新增源</string>
|
||||||
|
<string name="select_update_source">选中更新源</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1095,4 +1095,6 @@
|
|||||||
<string name="create_folder">创建文件夹</string>
|
<string name="create_folder">创建文件夹</string>
|
||||||
<string name="allow_drop_down_refresh">允许下拉刷新</string>
|
<string name="allow_drop_down_refresh">允许下拉刷新</string>
|
||||||
<string name="text_underline">文字下划线</string>
|
<string name="text_underline">文字下划线</string>
|
||||||
|
<string name="select_new_source">选中新增源</string>
|
||||||
|
<string name="select_update_source">选中更新源</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user