pull/32/head
kunfei 5 years ago
parent c662e74a20
commit c76ee0f550
  1. 18
      app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt
  2. 34
      app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt
  3. 11
      app/src/main/res/menu/source_debug.xml

@ -1,5 +1,6 @@
package io.legado.app.ui.booksource package io.legado.app.ui.booksource
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
@ -27,6 +28,7 @@ import kotlinx.android.synthetic.main.view_title_bar.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
class BookSourceActivity : VMBaseActivity<BookshelfViewModel>(R.layout.activity_book_source), class BookSourceActivity : VMBaseActivity<BookshelfViewModel>(R.layout.activity_book_source),
BookSourceAdapter.CallBack, BookSourceAdapter.CallBack,
@ -36,6 +38,7 @@ class BookSourceActivity : VMBaseActivity<BookshelfViewModel>(R.layout.activity_
private lateinit var adapter: BookSourceAdapter private lateinit var adapter: BookSourceAdapter
private var bookSourceLiveDate: LiveData<PagedList<BookSource>>? = null private var bookSourceLiveDate: LiveData<PagedList<BookSource>>? = null
val qrRequestCode = 101
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
@ -55,7 +58,7 @@ class BookSourceActivity : VMBaseActivity<BookshelfViewModel>(R.layout.activity_
this.startActivity<SourceEditActivity>() this.startActivity<SourceEditActivity>()
} }
R.id.action_import_book_source_qr -> { R.id.action_import_book_source_qr -> {
this.startActivity<QrCodeActivity>() this.startActivityForResult<QrCodeActivity>(qrRequestCode)
} }
R.id.action_select_all -> { R.id.action_select_all -> {
launch(IO) { launch(IO) {
@ -135,4 +138,17 @@ class BookSourceActivity : VMBaseActivity<BookshelfViewModel>(R.layout.activity_
override fun edit(bookSource: BookSource) { override fun edit(bookSource: BookSource) {
startActivity<SourceEditActivity>(Pair("data", bookSource.bookSourceUrl)) startActivity<SourceEditActivity>(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 {
}
}
}
}
}
} }

@ -1,6 +1,9 @@
package io.legado.app.ui.sourcedebug package io.legado.app.ui.sourcedebug
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View import android.view.View
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.recyclerview.widget.LinearLayoutManager 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.constant.Bus
import io.legado.app.help.EventMessage import io.legado.app.help.EventMessage
import io.legado.app.lib.theme.ATH 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.lib.theme.accentColor
import io.legado.app.ui.qrcode.QrCodeActivity
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
import kotlinx.android.synthetic.main.activity_source_debug.* import kotlinx.android.synthetic.main.activity_source_debug.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
class SourceDebugActivity : VMBaseActivity<SourceDebugModel>(R.layout.activity_source_debug) { class SourceDebugActivity : VMBaseActivity<SourceDebugModel>(R.layout.activity_source_debug) {
@ -23,6 +27,7 @@ class SourceDebugActivity : VMBaseActivity<SourceDebugModel>(R.layout.activity_s
get() = getViewModel(SourceDebugModel::class.java) get() = getViewModel(SourceDebugModel::class.java)
private lateinit var adapter: SourceDebugAdapter private lateinit var adapter: SourceDebugAdapter
val qrRequestCode = 101
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.init(intent.getStringExtra("key")) viewModel.init(intent.getStringExtra("key"))
@ -65,6 +70,33 @@ class SourceDebugActivity : VMBaseActivity<SourceDebugModel>(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<QrCodeActivity>(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() { override fun observeLiveBus() {
observeEvent<EventMessage>(Bus.SOURCE_DEBUG_LOG) { observeEvent<EventMessage>(Bus.SOURCE_DEBUG_LOG) {
adapter.addItem(it.obj as String) adapter.addItem(it.obj as String)

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_scan"
android:icon="@drawable/ic_scan"
android:title="@string/scan_qr_code"
app:showAsAction="ifRoom" />
</menu>
Loading…
Cancel
Save