pull/32/head
parent
f68342f21f
commit
6da676f74e
@ -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 |
||||
} |
||||
} |
@ -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) |
||||
} |
||||
} |
@ -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…
Reference in new issue