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.getCompatColor
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.setIconColor 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 protected abstract val viewModel: VM

@ -11,6 +11,7 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import io.legado.app.R import io.legado.app.R
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.help.ImageLoader
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import kotlinx.android.synthetic.main.item_bookshelf_list.view.* import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
import kotlinx.android.synthetic.main.item_relace_rule.view.tv_name 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_author.text = book.author
tv_read.text = book.durChapterTitle tv_read.text = book.durChapterTitle
tv_last.text = book.latestChapterTitle tv_last.text = book.latestChapterTitle
val cover = if (isEmpty(book.customCoverUrl)) book.coverUrl else book.customCoverUrl book.getDisplayCover()?.let {
cover?.let { ImageLoader.load(context, it)//Glide自动识别http://和file:///
if (it.startsWith("http")) {
Glide.with(itemView).load(it)
.placeholder(R.drawable.img_cover_default) .placeholder(R.drawable.img_cover_default)
.error(R.drawable.img_cover_default)
.centerCrop() .centerCrop()
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .setAsDrawable(iv_cover)
.into(iv_cover)
} else {
Glide.with(itemView).load(File(it))
.placeholder(R.drawable.img_cover_default)
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.into(iv_cover)
}
} }
itemView.setOnClickListener { callBack?.open(book) } 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.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 import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavigationItemSelectedListener, class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavigationItemSelectedListener,
@ -62,9 +61,9 @@ class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavig
} }
private fun importYueDu() { private fun importYueDu() {
GlobalScope.launch { launch {
if (App.db.bookDao().allBookCount == 0) { if (App.db.bookDao().allBookCount == 0) {
GlobalScope.launch(Dispatchers.Main) { 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)

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

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

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

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

Loading…
Cancel
Save