pull/32/head
kunfei 5 years ago
parent f68342f21f
commit 6da676f74e
  1. 1
      app/src/main/AndroidManifest.xml
  2. 17
      app/src/main/java/io/legado/app/data/entities/BaseBook.kt
  3. 17
      app/src/main/java/io/legado/app/data/entities/Book.kt
  4. 4
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt
  5. 22
      app/src/main/java/io/legado/app/data/entities/SearchShow.kt
  6. 30
      app/src/main/java/io/legado/app/ui/explore/DiffCallBack.kt
  7. 26
      app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt
  8. 75
      app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt
  9. 3
      app/src/main/java/io/legado/app/ui/search/SearchActivity.kt
  10. 5
      app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt
  11. 34
      app/src/main/res/layout/activity_explore_show.xml

@ -61,6 +61,7 @@
<activity android:name=".ui.chapterlist.ChapterListActivity" />
<activity android:name=".ui.readrss.ReadRssActivity" />
<activity android:name=".ui.audio.AudioPlayActivity" />
<activity android:name=".ui.explore.ExploreShowActivity" />
<service android:name=".service.CheckSourceService" />
<service android:name=".service.DownloadService" />

@ -1,6 +1,23 @@
package io.legado.app.data.entities
import io.legado.app.utils.splitNotBlank
interface BaseBook {
var variableMap: HashMap<String, String>?
var kind: String?
var wordCount: String?
fun putVariable(key: String, value: String)
fun getKindList(): List<String> {
val kindList = arrayListOf<String>()
wordCount?.let {
if (it.isNotBlank()) kindList.add(it)
}
kind?.let {
val kinds = it.splitNotBlank(",", "\n")
kindList.addAll(kinds)
}
return kindList
}
}

@ -9,7 +9,6 @@ import androidx.room.PrimaryKey
import io.legado.app.constant.BookType
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.splitNotBlank
import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize
import kotlin.math.max
@ -24,7 +23,7 @@ data class Book(
var originName: String = "", //书源名称
var name: String = "", // 书籍名称(书源获取)
var author: String = "", // 作者名称(书源获取)
var kind: String? = null, // 分类信息(书源获取)
override var kind: String? = null, // 分类信息(书源获取)
var customTag: String? = null, // 分类信息(用户修改)
var coverUrl: String? = null, // 封面Url(书源获取)
var customCoverUrl: String? = null, // 封面Url(用户修改)
@ -42,7 +41,7 @@ data class Book(
var durChapterIndex: Int = 0, // 当前章节索引
var durChapterPos: Int = 0, // 当前阅读的进度(首行字符的索引位置)
var durChapterTime: Long = System.currentTimeMillis(), // 最近一次阅读书籍的时间(打开正文的时间)
var wordCount: String? = null,
override var wordCount: String? = null,
var canUpdate: Boolean = true, // 刷新书架时更新书籍信息
var order: Int = 0, // 手动排序
var originOrder: Int = 0, //书源排序
@ -79,18 +78,6 @@ data class Book(
variable = GSON.toJson(variableMap)
}
fun getKindList(): List<String> {
val kindList = arrayListOf<String>()
wordCount?.let {
if (it.isNotBlank()) kindList.add(it)
}
kind?.let {
val kinds = it.splitNotBlank(",", "\n")
kindList.addAll(kinds)
}
return kindList
}
fun toSearchBook(): SearchBook {
return SearchBook(
name = name,

@ -20,10 +20,10 @@ data class SearchBook(
var originName: String = "",
var name: String = "",
var author: String = "",
var kind: String? = null,
override var kind: String? = null,
var coverUrl: String? = null,
var intro: String? = null,
var wordCount: String? = null,
override var wordCount: String? = null,
var latestChapterTitle: String? = null,
var tocUrl: String = "", // 目录页Url (toc=table of Contents)
var time: Long = System.currentTimeMillis(),

@ -1,27 +1,19 @@
package io.legado.app.data.entities
import io.legado.app.utils.splitNotBlank
data class SearchShow(
var name: String = "",
var author: String = "",
var kind: String? = null,
override var kind: String? = null,
var coverUrl: String? = null,
var intro: String? = null,
var wordCount: String? = null,
override var wordCount: String? = null,
var latestChapterTitle: String? = null,
var time: Long = 0L,
var originCount: Int = 0
) {
fun getKindList(): List<String> {
val kindList = arrayListOf<String>()
wordCount?.let {
if (it.isNotBlank()) kindList.add(it)
}
kind?.let {
val kinds = it.splitNotBlank(",", "\n")
kindList.addAll(kinds)
}
return kindList
) : BaseBook {
override var variableMap: HashMap<String, String>? = null
override fun putVariable(key: String, value: String) {
}
}

@ -0,0 +1,30 @@
package io.legado.app.ui.explore
import androidx.recyclerview.widget.DiffUtil
import io.legado.app.data.entities.SearchShow
class DiffCallBack : DiffUtil.ItemCallback<SearchShow>() {
override fun areItemsTheSame(oldItem: SearchShow, newItem: SearchShow): Boolean {
return oldItem.name == newItem.name
&& oldItem.author == newItem.author
}
override fun areContentsTheSame(oldItem: SearchShow, newItem: SearchShow): Boolean {
return oldItem.originCount == newItem.originCount
&& (oldItem.coverUrl == newItem.coverUrl || !oldItem.coverUrl.isNullOrEmpty())
&& (oldItem.kind == newItem.kind || !oldItem.kind.isNullOrEmpty())
&& (oldItem.latestChapterTitle == newItem.latestChapterTitle || !oldItem.kind.isNullOrEmpty())
&& oldItem.intro?.length ?: 0 > newItem.intro?.length ?: 0
}
override fun getChangePayload(oldItem: SearchShow, newItem: SearchShow): Any? {
return when {
oldItem.originCount != newItem.originCount -> 1
oldItem.coverUrl != newItem.coverUrl -> 2
oldItem.kind != newItem.kind -> 3
oldItem.latestChapterTitle != newItem.latestChapterTitle -> 4
oldItem.intro != newItem.intro -> 5
else -> null
}
}
}

@ -0,0 +1,26 @@
package io.legado.app.ui.explore
import android.os.Bundle
import io.legado.app.R
import io.legado.app.base.BaseActivity
import kotlinx.android.synthetic.main.activity_explore_show.*
class ExploreShowActivity : BaseActivity(R.layout.activity_explore_show) {
override fun onActivityCreated(savedInstanceState: Bundle?) {
intent.getStringExtra("exploreName")?.let {
title_bar.title = it
}
initRecyclerView()
}
private fun initRecyclerView() {
}
private fun initData() {
val sourceUrl = intent.getStringExtra("sourceUrl")
val exploreUrl = intent.getStringExtra("exploreUrl")
}
}

@ -0,0 +1,75 @@
package io.legado.app.ui.explore
import android.content.Context
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.SearchBook
import io.legado.app.help.ImageLoader
import io.legado.app.utils.gone
import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.item_bookshelf_list.view.iv_cover
import kotlinx.android.synthetic.main.item_bookshelf_list.view.tv_name
import kotlinx.android.synthetic.main.item_search.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class ExploreShowAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<SearchBook>(context, R.layout.item_search) {
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) =
with(holder.itemView) {
tv_name.text = item.name
tv_author.text = context.getString(R.string.author_show, item.author)
if (item.latestChapterTitle.isNullOrEmpty()) {
tv_lasted.gone()
} else {
tv_lasted.text = context.getString(R.string.lasted_show, item.latestChapterTitle)
tv_lasted.visible()
}
tv_introduce.text = context.getString(R.string.intro_show, item.intro)
val kinds = item.getKindList()
if (kinds.isEmpty()) {
ll_kind.gone()
} else {
ll_kind.visible()
for (index in 0..2) {
if (kinds.size > index) {
when (index) {
0 -> {
tv_kind.text = kinds[index]
tv_kind.visible()
}
1 -> {
tv_kind_1.text = kinds[index]
tv_kind_1.visible()
}
2 -> {
tv_kind_2.text = kinds[index]
tv_kind_2.visible()
}
}
} else {
when (index) {
0 -> tv_kind.gone()
1 -> tv_kind_1.gone()
2 -> tv_kind_2.gone()
}
}
}
}
item.coverUrl.let {
ImageLoader.load(context, it)//Glide自动识别http://和file://
.placeholder(R.drawable.img_cover_default)
.error(R.drawable.img_cover_default)
.centerCrop()
.setAsDrawable(iv_cover)
}
onClick {
callBack.showBookInfo(item.name, item.author)
}
}
interface CallBack {
fun showBookInfo(name: String, author: String)
}
}

@ -70,8 +70,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
private fun initRecyclerView() {
ATH.applyEdgeEffectColor(rv_search_list)
adapter = SearchAdapter()
adapter.callBack = this
adapter = SearchAdapter(this)
rv_search_list.layoutManager = LinearLayoutManager(this)
rv_search_list.adapter = adapter
}

@ -15,9 +15,8 @@ import kotlinx.android.synthetic.main.item_bookshelf_list.view.tv_name
import kotlinx.android.synthetic.main.item_search.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class SearchAdapter : PagedListAdapter<SearchShow, SearchAdapter.MyViewHolder>(DiffCallBack()) {
var callBack: CallBack? = null
class SearchAdapter(val callBack: CallBack) :
PagedListAdapter<SearchShow, SearchAdapter.MyViewHolder>(DiffCallBack()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_search, parent, false))

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="io.legado.app.ui.search.SearchActivity">
<io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentLayout="@layout/view_search"
app:contentInsetStartWithNavigation="0dp"
app:layout_constraintTop_toTopOf="parent"
app:title="搜索" />
<io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/title_bar">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_search_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save