From e9e55dfa1ae77f5cc18373f84b7afaf7625c6d5e Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 24 Sep 2021 22:23:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/changesource/ChangeSourceAdapter.kt | 14 ++++++++----- .../book/changesource/ChangeSourceDialog.kt | 20 +++++++++++++++---- .../app/ui/book/info/BookInfoActivity.kt | 2 +- .../source/edit/BookSourceEditViewModel.kt | 6 +++--- .../book/source/manage/BookSourceActivity.kt | 2 +- .../app/ui/main/explore/ExploreFragment.kt | 2 +- app/src/main/res/menu/change_source_item.xml | 12 +++++++---- app/src/main/res/values-es-rES/strings.xml | 2 ++ app/src/main/res/values-ja-rJP/strings.xml | 2 ++ app/src/main/res/values-pt-rBR/strings.xml | 2 ++ app/src/main/res/values-zh-rHK/strings.xml | 2 ++ app/src/main/res/values-zh-rTW/strings.xml | 2 ++ app/src/main/res/values-zh/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 14 files changed, 53 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt index 35eea0a90..ffc51ce84 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt @@ -90,16 +90,19 @@ class ChangeSourceAdapter( popupMenu.inflate(R.menu.change_source_item) popupMenu.setOnMenuItemClickListener { when (it.itemId) { - R.id.menu_disable_book_source -> { - callBack.disableSource(searchBook) - } R.id.menu_top_source -> { callBack.topSource(searchBook) } R.id.menu_bottom_source -> { callBack.bottomSource(searchBook) } - R.id.menu_delete_book_source -> { + R.id.menu_edit_source -> { + callBack.editSource(searchBook) + } + R.id.menu_disable_source -> { + callBack.disableSource(searchBook) + } + R.id.menu_delete_source -> { callBack.deleteSource(searchBook) updateItems(0, itemCount, listOf()) } @@ -112,9 +115,10 @@ class ChangeSourceAdapter( interface CallBack { val bookUrl: String? fun changeTo(searchBook: SearchBook) - fun disableSource(searchBook: SearchBook) fun topSource(searchBook: SearchBook) fun bottomSource(searchBook: SearchBook) + fun editSource(searchBook: SearchBook) + fun disableSource(searchBook: SearchBook) fun deleteSource(searchBook: SearchBook) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index 44426a0ac..906b2ba81 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -20,6 +20,7 @@ import io.legado.app.data.entities.SearchBook import io.legado.app.databinding.DialogChangeSourceBinding import io.legado.app.help.AppConfig import io.legado.app.lib.theme.primaryColor +import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* @@ -44,6 +45,11 @@ class ChangeSourceDialog() : BaseDialogFragment(), private var callBack: CallBack? = null private val viewModel: ChangeSourceViewModel by viewModels() private val adapter by lazy { ChangeSourceAdapter(requireContext(), viewModel, this) } + private val editSourceResult = + registerForActivityResult(StartActivityForResult(BookSourceEditActivity::class.java)) { + + } + override fun onStart() { super.onStart() @@ -198,10 +204,6 @@ class ChangeSourceDialog() : BaseDialogFragment(), override val bookUrl: String? get() = callBack?.oldBook?.bookUrl - override fun disableSource(searchBook: SearchBook) { - viewModel.disableSource(searchBook) - } - override fun topSource(searchBook: SearchBook) { viewModel.topSource(searchBook) } @@ -210,6 +212,16 @@ class ChangeSourceDialog() : BaseDialogFragment(), viewModel.bottomSource(searchBook) } + override fun editSource(searchBook: SearchBook) { + editSourceResult.launch { + putExtra("sourceUrl", searchBook.origin) + } + } + + override fun disableSource(searchBook: SearchBook) { + viewModel.disableSource(searchBook) + } + override fun deleteSource(searchBook: SearchBook) { viewModel.del(searchBook) if (bookUrl == searchBook.bookUrl) { diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index e64704d54..91ef166cb 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -277,7 +277,7 @@ class BookInfoActivity : tvOrigin.setOnClickListener { viewModel.bookData.value?.let { startActivity { - putExtra("data", it.origin) + putExtra("sourceUrl", it.origin) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index d68243a55..592238a6b 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -19,10 +19,10 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat fun initData(intent: Intent, onFinally: () -> Unit) { execute { - val key = intent.getStringExtra("data") + val sourceUrl = intent.getStringExtra("sourceUrl") var source: BookSource? = null - if (key != null) { - source = appDb.bookSourceDao.getBookSource(key) + if (sourceUrl != null) { + source = appDb.bookSourceDao.getBookSource(sourceUrl) } source?.let { oldSourceUrl = it.bookSourceUrl diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 60b2948f0..0f70d4902 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -527,7 +527,7 @@ class BookSourceActivity : VMBaseActivity { - putExtra("data", bookSource.bookSourceUrl) + putExtra("sourceUrl", bookSource.bookSourceUrl) } } diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 7e4cd3841..05da34d6f 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -173,7 +173,7 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo override fun editSource(sourceUrl: String) { startActivity { - putExtra("data", sourceUrl) + putExtra("sourceUrl", sourceUrl) } } diff --git a/app/src/main/res/menu/change_source_item.xml b/app/src/main/res/menu/change_source_item.xml index 2ba189ad5..823f1e506 100644 --- a/app/src/main/res/menu/change_source_item.xml +++ b/app/src/main/res/menu/change_source_item.xml @@ -10,11 +10,15 @@ android:title="@string/to_bottom" /> + android:id="@+id/menu_edit_source" + android:title="@string/edit_source" /> + android:id="@+id/menu_disable_source" + android:title="@string/disable_source" /> + + \ No newline at end of file diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 84839d74a..0c3673abf 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -887,5 +887,7 @@ 下载失败 下载中 未知状态 + 禁用源 + 删除源 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 61be18abf..bbe1e1db7 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -891,5 +891,7 @@ 下载失败 下载中 未知状态 + 禁用源 + 删除源 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 907c61534..2cb7e116c 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -891,5 +891,7 @@ 下载失败 下载中 未知状态 + 禁用源 + 删除源 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index a0222d8bd..824adddc0 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -888,5 +888,7 @@ 下载失败 下载中 未知状态 + 禁用源 + 删除源 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 217793329..c2b0207db 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -890,5 +890,7 @@ 下载失败 下载中 未知状态 + 禁用源 + 删除源 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 05f49bdfd..e9167fffe 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -890,5 +890,7 @@ 下载失败 下载中 未知状态 + 禁用源 + 删除源 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ab189c6d5..6ed219e18 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -891,5 +891,7 @@ 下载失败 下载中 未知状态 + 禁用源 + 删除源