Merge remote-tracking branch 'origin/master'

# Conflicts:
#	app/src/main/java/io/legado/app/ui/main/MainActivity.kt
pull/32/head
Invinciblelee 6 years ago
commit fdf684c431
  1. 19
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  3. 8
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceFragment.kt
  4. 10
      app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt

@ -1,7 +1,6 @@
package io.legado.app.ui.main package io.legado.app.ui.main
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.MenuItem import android.view.MenuItem
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
@ -26,8 +25,8 @@ import io.legado.app.utils.getCompatColor
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavigationItemSelectedListener, class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavigationItemSelectedListener,
ViewPager.OnPageChangeListener { ViewPager.OnPageChangeListener {
@ -63,15 +62,13 @@ class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavig
} }
private fun importYueDu() { private fun importYueDu() {
launch(IO) { launch {
if (App.db.bookDao().allBookCount == 0) { if (withContext(IO) { App.db.bookDao().allBookCount == 0 }) {
launch(Main) { PermissionsCompat.Builder(this@MainActivity)
PermissionsCompat.Builder(this@MainActivity) .addPermissions(*Permissions.Group.STORAGE)
.addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage)
.rationale(R.string.tip_perm_request_storage) .onGranted { viewModel.restore() }
.onGranted { viewModel.restore() } .request()
.request()
}
} }
} }
} }

@ -21,7 +21,7 @@ import io.legado.app.ui.bookshelf.BookshelfActivity
import io.legado.app.utils.disableAutoFill import io.legado.app.utils.disableAutoFill
import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.fragment_bookshelf.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import kotlinx.coroutines.GlobalScope 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.textColor import org.jetbrains.anko.textColor
@ -88,7 +88,7 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf), BookGroupAd
title(text = "新建分组") title(text = "新建分组")
input(hint = "分组名称") { _, charSequence -> input(hint = "分组名称") { _, charSequence ->
run { run {
GlobalScope.launch { launch(IO) {
App.db.bookGroupDao().insert( App.db.bookGroupDao().insert(
BookGroup( BookGroup(
App.db.bookGroupDao().maxId + 1, App.db.bookGroupDao().maxId + 1,

@ -21,7 +21,7 @@ import io.legado.app.ui.qrcode.QrCodeActivity
import io.legado.app.ui.sourceedit.SourceEditActivity import io.legado.app.ui.sourceedit.SourceEditActivity
import kotlinx.android.synthetic.main.fragment_book_source.* import kotlinx.android.synthetic.main.fragment_book_source.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
@ -99,15 +99,15 @@ class BookSourceFragment : BaseFragment(R.layout.fragment_book_source), BookSour
} }
override fun del(bookSource: BookSource) { override fun del(bookSource: BookSource) {
GlobalScope.launch { App.db.bookSourceDao().delete(bookSource) } launch(IO) { App.db.bookSourceDao().delete(bookSource) }
} }
override fun update(bookSource: BookSource) { override fun update(bookSource: BookSource) {
GlobalScope.launch { App.db.bookSourceDao().update(bookSource) } launch(IO) { App.db.bookSourceDao().update(bookSource) }
} }
override fun update(vararg bookSource: BookSource) { override fun update(vararg bookSource: BookSource) {
GlobalScope.launch { App.db.bookSourceDao().update(*bookSource) } launch(IO) { App.db.bookSourceDao().update(*bookSource) }
} }
override fun edit(bookSource: BookSource) { override fun edit(bookSource: BookSource) {

@ -10,9 +10,9 @@ import io.legado.app.base.BaseActivity
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_source_edit.* import kotlinx.android.synthetic.main.activity_source_edit.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
class SourceEditActivity : BaseActivity<SourceEditViewModel>() { class SourceEditActivity : BaseActivity<SourceEditViewModel>() {
@ -53,9 +53,9 @@ class SourceEditActivity : BaseActivity<SourceEditViewModel>() {
if (bookSource == null) { if (bookSource == null) {
toast("书源名称和URL不能为空") toast("书源名称和URL不能为空")
} else { } else {
GlobalScope.launch { launch {
viewModel.save(bookSource) withContext(IO) { viewModel.save(bookSource) }
GlobalScope.launch(Dispatchers.Main) { finish() } finish()
} }
} }
} }

Loading…
Cancel
Save