pull/32/head
kunfei 5 years ago
parent 99ba9a265d
commit 5ce713f8b4
  1. 13
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 32
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt
  3. 75
      app/src/main/res/layout/activity_book_info.xml

@ -9,6 +9,7 @@ import androidx.room.PrimaryKey
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.splitNotBlank
import kotlinx.android.parcel.IgnoredOnParcel import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
import kotlin.math.max import kotlin.math.max
@ -76,4 +77,16 @@ data class Book(
variableMap?.put(key, value) variableMap?.put(key, value)
variable = GSON.toJson(variableMap) 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
}
} }

@ -7,6 +7,8 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.help.ImageLoader import io.legado.app.help.ImageLoader
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.gone
import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.activity_book_info.* import kotlinx.android.synthetic.main.activity_book_info.*
class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_book_info) { class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_book_info) {
@ -31,6 +33,36 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
.centerCrop() .centerCrop()
.setAsDrawable(iv_cover) .setAsDrawable(iv_cover)
} }
val kinds = book.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()
}
}
}
}
} }

@ -21,30 +21,33 @@
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title_bar" /> app:layout_constraintTop_toBottomOf="@+id/title_bar" />
<TextView <LinearLayout
android:id="@+id/tv_name" android:id="@+id/ll_book_info"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="0dp"
android:layout_marginLeft="6dp" android:layout_marginLeft="6dp"
android:layout_marginRight="6dp" android:layout_marginRight="6dp"
android:singleLine="true" android:orientation="vertical"
app:layout_constraintTop_toTopOf="@+id/iv_cover" app:layout_constraintTop_toTopOf="@+id/iv_cover"
app:layout_constraintLeft_toRightOf="@+id/iv_cover" app:layout_constraintLeft_toRightOf="@+id/iv_cover"
app:layout_constraintRight_toRightOf="parent" /> app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/iv_cover">
<TextView
android:id="@+id/tv_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
<TextView <TextView
android:id="@+id/tv_author" android:id="@+id/tv_author"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:singleLine="true" />
app:layout_constraintTop_toBottomOf="@+id/tv_name"
app:layout_constraintLeft_toLeftOf="@+id/tv_name"
app:layout_constraintRight_toRightOf="@id/tv_name"
app:layout_constraintBottom_toTopOf="@id/tv_origin" />
<TextView <TextView
android:id="@+id/tv_origin" android:id="@+id/tv_origin"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:singleLine="true"
app:layout_constraintTop_toBottomOf="@+id/tv_author" app:layout_constraintTop_toBottomOf="@+id/tv_author"
@ -52,15 +55,57 @@
app:layout_constraintRight_toRightOf="@id/tv_name" app:layout_constraintRight_toRightOf="@id/tv_name"
app:layout_constraintBottom_toTopOf="@id/tv_lasted" /> app:layout_constraintBottom_toTopOf="@id/tv_lasted" />
<LinearLayout
android:id="@+id/ll_kind"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<io.legado.app.lib.theme.view.ATEAccentBgTextView
android:id="@+id/tv_kind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:singleLine="true"
android:text="@string/app_name"
android:textSize="12sp" />
<io.legado.app.lib.theme.view.ATEAccentBgTextView
android:id="@+id/tv_kind_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:singleLine="true"
android:text="@string/app_name"
android:textSize="12sp" />
<io.legado.app.lib.theme.view.ATEAccentBgTextView
android:id="@+id/tv_kind_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:singleLine="true"
android:text="@string/app_name"
android:textSize="12sp" />
</LinearLayout>
<TextView <TextView
android:id="@+id/tv_lasted" android:id="@+id/tv_lasted"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:maxLines="2"
app:layout_constraintLeft_toLeftOf="@+id/tv_name" app:layout_constraintLeft_toLeftOf="@+id/tv_name"
app:layout_constraintRight_toRightOf="@id/tv_name" app:layout_constraintRight_toRightOf="@id/tv_name"
app:layout_constraintBottom_toBottomOf="@+id/iv_cover" /> app:layout_constraintBottom_toBottomOf="@+id/iv_cover" />
</LinearLayout>
<TextView <TextView
android:id="@+id/tv_intro" android:id="@+id/tv_intro"
android:layout_width="match_parent" android:layout_width="match_parent"

Loading…
Cancel
Save