pull/32/head
Invinciblelee 6 years ago
parent c13e6356a2
commit 0ff5f960d5
  1. 8
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 18
      app/src/main/java/io/legado/app/ui/bookshelf/BookshelfAdapter.kt
  3. 7
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  4. 8
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt
  5. 23
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt
  6. 2
      app/src/main/java/io/legado/app/ui/search/SearchViewModel.kt
  7. 2
      app/src/main/res/layout/item_bookshelf_list.xml

@ -15,9 +15,15 @@ import io.legado.app.utils.disableAutoFill
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.setIconColor
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlin.coroutines.CoroutineContext
abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
abstract class BaseActivity<VM : ViewModel> : AppCompatActivity(), CoroutineScope {
override val coroutineContext: CoroutineContext
get() = Dispatchers.IO
protected abstract val viewModel: VM

@ -11,6 +11,7 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import io.legado.app.R
import io.legado.app.data.entities.Book
import io.legado.app.help.ImageLoader
import io.legado.app.lib.theme.ThemeStore
import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
import kotlinx.android.synthetic.main.item_relace_rule.view.tv_name
@ -60,21 +61,12 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
tv_author.text = book.author
tv_read.text = book.durChapterTitle
tv_last.text = book.latestChapterTitle
val cover = if (isEmpty(book.customCoverUrl)) book.coverUrl else book.customCoverUrl
cover?.let {
if (it.startsWith("http")) {
Glide.with(itemView).load(it)
book.getDisplayCover()?.let {
ImageLoader.load(context, it)//Glide自动识别http://和file:///
.placeholder(R.drawable.img_cover_default)
.error(R.drawable.img_cover_default)
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.into(iv_cover)
} else {
Glide.with(itemView).load(File(it))
.placeholder(R.drawable.img_cover_default)
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.into(iv_cover)
}
.setAsDrawable(iv_cover)
}
itemView.setOnClickListener { callBack?.open(book) }
}

@ -24,8 +24,7 @@ import io.legado.app.ui.main.myconfig.MyConfigFragment
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavigationItemSelectedListener,
@ -62,9 +61,9 @@ class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavig
}
private fun importYueDu() {
GlobalScope.launch {
launch {
if (App.db.bookDao().allBookCount == 0) {
GlobalScope.launch(Dispatchers.Main) {
launch(Main) {
PermissionsCompat.Builder(this@MainActivity)
.addPermissions(*Permissions.Group.STORAGE)
.rationale(R.string.tip_perm_request_storage)

@ -1,15 +1,15 @@
package io.legado.app.ui.main
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import io.legado.app.base.BaseViewModel
import io.legado.app.help.storage.Restore
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
class MainViewModel(application: Application) : AndroidViewModel(application) {
class MainViewModel(application: Application) : BaseViewModel(application) {
fun restore() {
GlobalScope.launch {
launch(IO) {
Restore.importYueDuData(getApplication())
}
}

@ -1,20 +1,17 @@
package io.legado.app.ui.main.bookshelf
import android.text.TextUtils.isEmpty
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import io.legado.app.R
import io.legado.app.data.entities.Book
import io.legado.app.help.ImageLoader
import io.legado.app.lib.theme.ThemeStore
import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
import kotlinx.android.synthetic.main.item_relace_rule.view.tv_name
import java.io.File
class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(DIFF_CALLBACK) {
@ -42,6 +39,7 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
holder.bind(it, callBack)
}
}
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
init {
@ -53,21 +51,12 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
tv_author.text = book.author
tv_read.text = book.durChapterTitle
tv_last.text = book.latestChapterTitle
val cover = if (isEmpty(book.customCoverUrl)) book.coverUrl else book.customCoverUrl
cover?.let {
if (it.startsWith("http")) {
Glide.with(itemView).load(it)
.placeholder(R.drawable.img_cover_default)
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.into(iv_cover)
} else {
Glide.with(itemView).load(File(it))
book.getDisplayCover()?.let {
ImageLoader.load(context, it)//Glide自动识别http://和file://
.placeholder(R.drawable.img_cover_default)
.error(R.drawable.img_cover_default)
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.into(iv_cover)
}
.setAsDrawable(iv_cover)
}
itemView.setOnClickListener { callBack?.open(book) }
}

@ -22,7 +22,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
val searchResponse = withContext(IO) {
HttpHelper.getApiService<CommonHttpApi>(
"http:www.baidu.com"
).get("", mutableMapOf())
).post("", mutableMapOf(Pair("key", "value")))
}
val result = searchResponse.await()

@ -40,7 +40,7 @@
android:includeFontPadding="false"
tools:ignore="RtlHardcoded" />
<io.legado.app.ui.widget.anima.RotateLoading
<io.legado.app.ui.widget.RotateLoading
android:id="@+id/rl_loading"
android:layout_width="26dp"
android:layout_height="26dp"

Loading…
Cancel
Save