From c76ee0f55097d3630c6e93ade34c2e9c2649804c Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 2 Aug 2019 10:53:44 +0800 Subject: [PATCH] up --- .../app/ui/booksource/BookSourceActivity.kt | 18 +++++++++- .../app/ui/sourcedebug/SourceDebugActivity.kt | 34 ++++++++++++++++++- app/src/main/res/menu/source_debug.xml | 11 ++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/menu/source_debug.xml diff --git a/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt index 66ff91a1d..affb09a1f 100644 --- a/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.booksource +import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -27,6 +28,7 @@ import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch import org.jetbrains.anko.startActivity +import org.jetbrains.anko.startActivityForResult class BookSourceActivity : VMBaseActivity(R.layout.activity_book_source), BookSourceAdapter.CallBack, @@ -36,6 +38,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity_ private lateinit var adapter: BookSourceAdapter private var bookSourceLiveDate: LiveData>? = null + val qrRequestCode = 101 override fun onActivityCreated(savedInstanceState: Bundle?) { setSupportActionBar(toolbar) @@ -55,7 +58,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity_ this.startActivity() } R.id.action_import_book_source_qr -> { - this.startActivity() + this.startActivityForResult(qrRequestCode) } R.id.action_select_all -> { launch(IO) { @@ -135,4 +138,17 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity_ override fun edit(bookSource: BookSource) { startActivity(Pair("data", bookSource.bookSourceUrl)) } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + qrRequestCode -> { + if (resultCode == RESULT_OK) { + data?.getStringExtra("result")?.let { + + } + } + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt index 609689873..ee15278ea 100644 --- a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt @@ -1,6 +1,9 @@ package io.legado.app.ui.sourcedebug +import android.content.Intent import android.os.Bundle +import android.view.Menu +import android.view.MenuItem import android.view.View import androidx.appcompat.widget.SearchView import androidx.recyclerview.widget.LinearLayoutManager @@ -9,12 +12,13 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus import io.legado.app.help.EventMessage import io.legado.app.lib.theme.ATH -import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.accentColor +import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.utils.getViewModel import io.legado.app.utils.observeEvent import kotlinx.android.synthetic.main.activity_source_debug.* import kotlinx.android.synthetic.main.view_title_bar.* +import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast class SourceDebugActivity : VMBaseActivity(R.layout.activity_source_debug) { @@ -23,6 +27,7 @@ class SourceDebugActivity : VMBaseActivity(R.layout.activity_s get() = getViewModel(SourceDebugModel::class.java) private lateinit var adapter: SourceDebugAdapter + val qrRequestCode = 101 override fun onActivityCreated(savedInstanceState: Bundle?) { viewModel.init(intent.getStringExtra("key")) @@ -65,6 +70,33 @@ class SourceDebugActivity : VMBaseActivity(R.layout.activity_s }) } + override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.source_debug, menu) + return super.onCompatCreateOptionsMenu(menu) + } + + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.action_scan -> { + startActivityForResult(qrRequestCode) + } + } + return super.onCompatOptionsItemSelected(item) + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + qrRequestCode -> { + if (resultCode == RESULT_OK) { + data?.getStringExtra("result")?.let { + startSearch(it) + } + } + } + } + } + override fun observeLiveBus() { observeEvent(Bus.SOURCE_DEBUG_LOG) { adapter.addItem(it.obj as String) diff --git a/app/src/main/res/menu/source_debug.xml b/app/src/main/res/menu/source_debug.xml new file mode 100644 index 000000000..5b8b467f2 --- /dev/null +++ b/app/src/main/res/menu/source_debug.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file