From a0a9be33582237b409ac1139b4826a700e97fc1e Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 12 Oct 2019 17:27:05 +0800 Subject: [PATCH] up --- .../book/source/manage/BookSourceActivity.kt | 10 ++-- .../ui/rss/source/manage/RssSourceActivity.kt | 53 +++++++++++++++++-- 2 files changed, 53 insertions(+), 10 deletions(-) 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 4d1fe668b..db9405b0d 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 @@ -75,12 +75,8 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.menu_add_book_source -> { - this.startActivity() - } - R.id.menu_import_source_qr -> { - this.startActivityForResult(qrRequestCode) - } + R.id.menu_add_book_source -> startActivity() + R.id.menu_import_source_qr -> startActivityForResult(qrRequestCode) R.id.menu_group_manage -> GroupManageDialog().show( supportFragmentManager, "groupManage" @@ -248,7 +244,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity when (requestCode) { qrRequestCode -> if (resultCode == RESULT_OK) { data?.getStringExtra("result")?.let { - + viewModel.importSource(it) } } importSource -> if (resultCode == Activity.RESULT_OK) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index aa3f3413d..7c9aaa35b 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.rss.source.manage +import android.annotation.SuppressLint import android.app.Activity import android.content.Intent import android.os.Bundle @@ -19,16 +20,22 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.RssSource import io.legado.app.help.ItemTouchCallback +import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.cancelButton +import io.legado.app.lib.dialogs.customView +import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor +import io.legado.app.lib.theme.view.ATEAutoCompleteTextView +import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity -import io.legado.app.utils.FileUtils -import io.legado.app.utils.getViewModel -import io.legado.app.utils.splitNotBlank +import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_rss_source.* +import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.startActivity +import org.jetbrains.anko.startActivityForResult class RssSourceActivity : VMBaseActivity(R.layout.activity_rss_source), @@ -37,6 +44,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r override val viewModel: RssSourceViewModel get() = getViewModel(RssSourceViewModel::class.java) + private val qrRequestCode = 101 private val importSource = 13141 private lateinit var adapter: RssSourceAdapter private var sourceLiveData: LiveData>? = null @@ -71,6 +79,8 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds()) R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds()) R.id.menu_import_source_local -> selectFile() + R.id.menu_import_source_onLine -> showImportDialog() + R.id.menu_import_source_qr -> startActivityForResult(qrRequestCode) } return super.onCompatOptionsItemSelected(item) } @@ -141,6 +151,38 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r }) } + @SuppressLint("InflateParams") + private fun showImportDialog() { + val aCache = ACache.get(this, cacheDir = false) + val cacheUrls: MutableList = aCache + .getAsString("sourceUrl") + ?.splitNotBlank(",") + ?.toMutableList() ?: mutableListOf() + alert(titleResource = R.string.import_book_source_on_line) { + var editText: ATEAutoCompleteTextView? = null + customView { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { + editText = edit_view + edit_view.setFilterValues(cacheUrls) { + cacheUrls.remove(it) + aCache.put("sourceUrl", cacheUrls.joinToString(",")) + } + } + } + okButton { + val text = editText?.text?.toString() + text?.let { + if (!cacheUrls.contains(it)) { + cacheUrls.add(0, it) + aCache.put("sourceUrl", cacheUrls.joinToString(",")) + } + viewModel.importSource(it) + } + } + cancelButton() + }.show().applyTint() + } + private fun selectFile() { val intent = Intent(Intent.ACTION_GET_CONTENT) intent.addCategory(Intent.CATEGORY_OPENABLE) @@ -158,6 +200,11 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r } } } + qrRequestCode -> if (resultCode == RESULT_OK) { + data?.getStringExtra("result")?.let { + viewModel.importSource(it) + } + } } }