Skip to content

Commit

Permalink
collection box
Browse files Browse the repository at this point in the history
  • Loading branch information
ekibun committed May 3, 2019
1 parent 0c63a66 commit 6f6969e
Show file tree
Hide file tree
Showing 27 changed files with 642 additions and 195 deletions.
18 changes: 15 additions & 3 deletions app/src/main/java/soko/ekibun/bangumi/api/bangumi/Bangumi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ interface Bangumi {
doc.selectFirst("span[property=\"v:votes\"]")?.text()?.toIntOrNull()?:subject.rating?.total?:0,
Subject.RatingBean.CountBean(counts[10]?:0, counts[9]?:0, counts[8]?:0, counts[7]?:0,
counts[6]?:0, counts[5]?:0, counts[4]?:0, counts[3]?:0, counts[2]?:0, counts[1]?:0),
doc.selectFirst(".global_score .number")?.text()?.toDoubleOrNull()?:subject.rating?.score?:0.0
doc.selectFirst(".global_score .number")?.text()?.toDoubleOrNull()?:subject.rating?.score?:0.0,
doc.selectFirst(".frdScore .num")?.text()?.toDoubleOrNull()?:subject.rating?.friend_score?:0.0
)
val rank = doc.selectFirst(".global_score .alarm")?.text()?.trim('#')?.toIntOrNull()?:subject.rank
val img = getImageUrl(doc.selectFirst(".infobox img.cover"))
Expand All @@ -122,7 +123,18 @@ interface Bangumi {
img.replace("/c/", "/m/"),
img.replace("/c/", "/s/"),
img.replace("/c/", "/g/"))
//TODO Collection
//collection
val collection = Subject.CollectionBean()
doc.select("#subjectPanelCollect .tip_i a")?.forEach{
val match = Regex("(\\d+)人(.+)").find(it.text())?.groupValues?:return@forEach
when(match[2]){
"想看" -> collection.wish = match[1].toIntOrNull()?:return@forEach
"看过" -> collection.collect = match[1].toIntOrNull()?:return@forEach
"在看" -> collection.doing = match[1].toIntOrNull()?:return@forEach
"搁置" -> collection.on_hold = match[1].toIntOrNull()?:return@forEach
"抛弃" -> collection.dropped = match[1].toIntOrNull()?:return@forEach
}
}
//prg
val ep_status = doc.selectFirst("input[name=watchedeps]")?.attr("value")?.toIntOrNull()?:0
val vol_status = doc.selectFirst("input[name=watched_vols]")?.attr("value")?.toIntOrNull()?:0
Expand Down Expand Up @@ -263,7 +275,7 @@ interface Bangumi {
}
//formhash
val formhash = if(doc.selectFirst(".guest") != null) "" else doc.selectFirst("input[name=formhash]")?.attr("value")
Subject(subject.id, subject.url, type, name, name_cn, summary, eps_count, air_date, air_weekday, rating, rank, images, infobox = infobox,
Subject(subject.id, subject.url, type, name, name_cn, summary, eps_count, air_date, air_weekday, rating, rank, images, collection, infobox = infobox,
ep_status = ep_status, vol_count = vol_count, vol_status = vol_status, has_vol = has_vol,
crt=crt, topic = topic, blog = blog, linked = linked, commend = commend, tags = tags, typeString = typeString, formhash = formhash, interest = interest)
}
Expand Down
26 changes: 15 additions & 11 deletions app/src/main/java/soko/ekibun/bangumi/api/bangumi/bean/Subject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ data class Subject(
data class RatingBean (
var total: Int = 0,
var count: CountBean? = null,
var score: Double = 0.toDouble()
var score: Double = 0.toDouble(),
var friend_score: Double = 0.toDouble()
){
/**
* total : 3069
Expand All @@ -101,26 +102,29 @@ data class Subject(

data class CountBean(
@SerializedName("10")
var `_$10`: Int = 0,
var c10: Int = 0,
@SerializedName("9")
var `_$9`: Int = 0,
var c9: Int = 0,
@SerializedName("8")
var `_$8`: Int = 0,
var c8: Int = 0,
@SerializedName("7")
var `_$7`: Int = 0,
var c7: Int = 0,
@SerializedName("6")
var `_$6`: Int = 0,
var c6: Int = 0,
@SerializedName("5")
var `_$5`: Int = 0,
var c5: Int = 0,
@SerializedName("4")
var `_$4`: Int = 0,
var c4: Int = 0,
@SerializedName("3")
var `_$3`: Int = 0,
var c3: Int = 0,
@SerializedName("2")
var `_$2`: Int = 0,
var c2: Int = 0,
@SerializedName("1")
var `_$1`: Int = 0
var c1: Int = 0
) {
fun toList(): IntArray{
return intArrayOf(c10, c9, c8, c7, c6, c5, c4, c3, c2, c1)
}
/**
* 10 : 331
* 9 : 335
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ class EpisodeAdapter(data: MutableList<SelectableSectionEntity<Episode>>? = null
else -> android.R.attr.textColorSecondary
})
helper.itemView.item_select.visibility = if(item.isSelected) View.VISIBLE else View.INVISIBLE
helper.itemView.item_ep_box.setPadding(helper.itemView.item_ep_box.paddingLeft,helper.itemView.item_ep_box.paddingTop,
helper.itemView.item_ep_box.paddingLeft * if(item.isSelected) 4 else 1, helper.itemView.item_ep_box.paddingBottom)
helper.itemView.item_title.setTextColor(color)
helper.itemView.item_desc.setTextColor(color)
helper.itemView.item_badge.visibility = if(item.t.progress != null) View.VISIBLE else View.INVISIBLE
Expand All @@ -70,8 +68,8 @@ class EpisodeAdapter(data: MutableList<SelectableSectionEntity<Episode>>? = null
else -> android.R.attr.textColorSecondary
}))
helper.itemView.item_badge.text = item.t.progress?.status?.cn_name?:""
helper.itemView.item_ep_box.backgroundTintList = ColorStateList.valueOf(color)
helper.itemView.item_ep_box.alpha = if((item.t.status?:"") in listOf("Air"))1f else 0.6f
helper.itemView.backgroundTintList = ColorStateList.valueOf(color)
helper.itemView.alpha = if((item.t.status?:"") in listOf("Air"))1f else 0.6f

if(itemHeight == 0){
helper.itemView.measure(0, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ class SmallEpisodeAdapter(data: MutableList<Episode>? = null) :
else -> android.R.attr.textColorSecondary
}))
helper.itemView.item_badge.text = item.progress?.status?.cn_name?:""
helper.itemView.item_ep_box.backgroundTintList = ColorStateList.valueOf(color)
helper.itemView.backgroundTintList = ColorStateList.valueOf(color)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ class SubjectPresenter(private val context: SubjectActivity){
if(status?.id in listOf(1, 2, 3, 4)) R.drawable.ic_heart else R.drawable.ic_heart_outline, context.theme))
context.item_collect_info.text = status?.name?:context.getString(R.string.collect)

context.item_self_rating.visibility = if(body.rating == 0)View.GONE else View.VISIBLE
context.item_self_rating.rating = body.rating / 2f

context.item_collect.setOnClickListener{
if(context.formhash.isEmpty()) return@setOnClickListener
val popupMenu = PopupMenu(context, context.item_collect)
Expand Down
46 changes: 39 additions & 7 deletions app/src/main/java/soko/ekibun/bangumi/ui/subject/SubjectView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package soko.ekibun.bangumi.ui.subject

import android.animation.LayoutTransition
import android.annotation.SuppressLint
import android.graphics.Rect
import android.support.constraint.ConstraintLayout
import android.support.design.widget.AppBarLayout
import android.support.design.widget.BottomSheetDialog
Expand Down Expand Up @@ -33,6 +32,7 @@ import kotlinx.android.synthetic.main.subject_character.*
import kotlinx.android.synthetic.main.subject_detail.*
import kotlinx.android.synthetic.main.subject_episode.*
import kotlinx.android.synthetic.main.subject_episode.view.*
import kotlinx.android.synthetic.main.subject_rank.view.*
import kotlinx.android.synthetic.main.subject_topic.*
import org.jsoup.Jsoup
import soko.ekibun.bangumi.R
Expand Down Expand Up @@ -61,7 +61,7 @@ class SubjectView(private val context: SubjectActivity){

val detail: LinearLayout = context.subject_detail

var appBarOffset = 0
var appBarOffset = -1
val scroll2Top = {
if(appBarOffset != 0 || if(context.episode_detail_list.visibility == View.VISIBLE) context.episode_detail_list.canScrollVertically(-1) else context.comment_list.canScrollVertically(-1)){
context.app_bar.setExpanded(true, true)
Expand All @@ -74,7 +74,10 @@ class SubjectView(private val context: SubjectActivity){
val marginEnd = (context.item_buttons.layoutParams as CollapsingToolbarLayout.LayoutParams).marginEnd
(context.title_expand.layoutParams as ConstraintLayout.LayoutParams).marginEnd = 3 * marginEnd

context.item_self_rating.measure(0,0)
val selfRatingWidth = context.item_self_rating.measuredWidth
context.app_bar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener{ appBarLayout, verticalOffset ->
if(appBarOffset == verticalOffset) return@OnOffsetChangedListener
val ratio = Math.abs(verticalOffset.toFloat() / appBarLayout.totalScrollRange)
appBarOffset = verticalOffset
context.item_scrim.alpha = ratio
Expand All @@ -85,6 +88,12 @@ class SubjectView(private val context: SubjectActivity){
context.item_buttons.translationX = -2.2f * marginEnd * ratio
context.app_bar.elevation = Math.max(0f, 12 * (ratio - 0.95f)/ 0.05f)

context.item_self_rating.layoutParams.let {
it.width = (selfRatingWidth * (1-ratio)).toInt()
context.item_self_rating.layoutParams = it
}
context.item_self_rating.alpha = 1-ratio

context.episode_detail_list.invalidate()
})

Expand Down Expand Up @@ -196,11 +205,11 @@ class SubjectView(private val context: SubjectActivity){
context.title_expand.text = context.title_collapse.text
context.title_expand.post {
val layoutParams = (context.title_collapse.layoutParams as ConstraintLayout.LayoutParams)
layoutParams.marginEnd = 3 * (context.item_buttons.layoutParams as CollapsingToolbarLayout.LayoutParams).marginEnd + context.item_buttons.width
layoutParams.marginEnd = 3 * (context.item_buttons.layoutParams as CollapsingToolbarLayout.LayoutParams).marginEnd + context.item_buttons.width - context.item_self_rating.width
context.title_collapse.layoutParams = layoutParams
(context.item_subject.layoutParams as CollapsingToolbarLayout.LayoutParams).topMargin = context.toolbar_container.height
}
context.item_info.text = if(subject.typeString.isNullOrEmpty()) context.getString(SubjectType.getDescription(subject.type)) else subject.typeString
context.item_info.text = (if(subject.typeString.isNullOrEmpty()) context.getString(SubjectType.getDescription(subject.type)) else subject.typeString) + " · " + subject.name
context.item_subject_title.visibility = View.GONE
val saleDate = subject.infobox?.firstOrNull { it.first in arrayOf("发售日期", "发售日", "发行日期") }
val artist = subject.infobox?.firstOrNull { it.first.substringBefore(" ") in arrayOf("动画制作", "作者", "开发", "游戏制作", "艺术家") }
Expand All @@ -212,9 +221,25 @@ class SubjectView(private val context: SubjectActivity){

context.item_play.visibility = if(PlayerBridge.checkActivity(context) && subject.type in listOf(SubjectType.ANIME, SubjectType.REAL)) View.VISIBLE else View.GONE

detail.item_rank_count.text = if(subject.rank == 0) "" else "#${subject.rank}"

subject.rating?.let {
context.item_score.text = it.score.toString()
context.item_score_count.text = context.getString(R.string.rate_count, it.total)
detail.item_friend_score.text = if(it.friend_score == 0.0) "-" else it.friend_score.toString()
detail.item_score.text = if(it.score == 0.0) "-" else it.score.toString()
detail.item_rating.rating = it.score.toFloat() / 2
detail.item_score_count.text = context.getString(R.string.rate_count, it.total)
val count = it.count?:return@let
val max = count.toList().max()?:return@let
detail.rate_10.progress = if(max == 0) 0 else 100 * count.c10 / max
detail.rate_9.progress = if(max == 0) 0 else 100 * count.c9 / max
detail.rate_8.progress = if(max == 0) 0 else 100 * count.c8 / max
detail.rate_7.progress = if(max == 0) 0 else 100 * count.c7 / max
detail.rate_6.progress = if(max == 0) 0 else 100 * count.c6 / max
detail.rate_5.progress = if(max == 0) 0 else 100 * count.c5 / max
detail.rate_4.progress = if(max == 0) 0 else 100 * count.c4 / max
detail.rate_3.progress = if(max == 0) 0 else 100 * count.c3 / max
detail.rate_2.progress = if(max == 0) 0 else 100 * count.c2 / max
detail.rate_1.progress = if(max == 0) 0 else 100 * count.c1 / max
}
GlideUtil.with(context.item_cover)
?.load(subject.images?.getImage(context))
Expand Down Expand Up @@ -284,6 +309,13 @@ class SubjectView(private val context: SubjectActivity){
detail.item_detail.setOnClickListener {
showInfoBox(subject)
}
subject.collection?.let{
detail.item_collection_count.text = context.getString(R.string.phrase_collection_count, it.wish, it.collect, it.doing, it.on_hold, it.dropped)
}

detail.item_netabare.setOnClickListener {
WebActivity.launchUrl(context, "https://netaba.re/subject/${subject.id}")
}

detail.item_progress.visibility = if(subject.formhash?.isNotEmpty() == true && subject.interest?.status?.type == CollectionStatusType.DO && subject.type in listOf(SubjectType.ANIME, SubjectType.REAL, SubjectType.BOOK)) View.VISIBLE else View.GONE
detail.item_progress_info.text = context.getString(R.string.phrase_progress,
Expand All @@ -295,7 +327,7 @@ class SubjectView(private val context: SubjectActivity){
if(subject.infobox?.isNotEmpty() == true) {
val view = LayoutInflater.from(context).inflate(R.layout.dialog_infobox, detail, false)
@Suppress("DEPRECATION")
view.item_infobox_text.text = setTextLinkOpenByWebView(Html.fromHtml(subject.infobox?.map { "${it.first}: ${it.second}" }?.reduce { acc, s -> "$acc<br>$s" })){
view.item_infobox_text.text = setTextLinkOpenByWebView(Html.fromHtml("<h1>${subject.name}</h1>" + subject.infobox?.map { "${it.first}: ${it.second}" }?.reduce { acc, s -> "$acc<br>$s" })){
WebActivity.launchUrl(context, HttpUtil.getUrl(it, URI.create(Bangumi.SERVER)), "")
}
view.item_infobox_text.movementMethod = LinkMovementMethod.getInstance()
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/drawable/bg_episode_fill.xml

This file was deleted.

30 changes: 20 additions & 10 deletions app/src/main/res/drawable/bg_episode_outline.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#0000"/>
<corners android:radius="8dp" />

<stroke
android:width="1dp"
android:color="#8000"
/>
</shape>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#0000"/>
<corners android:radius="8dp" />
<stroke
android:width="1dp"
android:color="#8000"/>
</shape>
</item>
<item android:id="@android:id/mask">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#000"/>
<corners android:radius="8dp" />
</shape>
</item>
</ripple>
14 changes: 9 additions & 5 deletions app/src/main/res/drawable/bg_round_rect.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#000"/>
<corners android:radius="10000dp" />
</shape>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item>
<shape android:shape="rectangle">
<solid android:color="#000"/>
<corners android:radius="10000dp" />
</shape>
</item>
</ripple>
6 changes: 0 additions & 6 deletions app/src/main/res/drawable/bg_round_rect_checked.xml

This file was deleted.

6 changes: 0 additions & 6 deletions app/src/main/res/drawable/bg_round_rect_unchecked.xml

This file was deleted.

7 changes: 0 additions & 7 deletions app/src/main/res/drawable/bg_selectable.xml

This file was deleted.

7 changes: 7 additions & 0 deletions app/src/main/res/drawable/color_bg_checkable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 未选中-->
<item android:color="@color/colorTransGrey" android:state_checked="false" />
<!--选中-->
<item android:color="?colorAccent" android:state_checked="true" />
</selector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_navigate_next.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="18dp"
android:height="18dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="?colorAccent"
android:pathData="M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z"/>
</vector>
18 changes: 18 additions & 0 deletions app/src/main/res/drawable/rating_count_bar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="1000dp" />
<solid android:color="@color/colorTransGrey"/>
</shape>
</item>
<item android:id="@android:id/progress">
<scale android:scaleHeight="100%"
android:scaleGravity="bottom">
<shape>
<corners android:radius="1000dp" />
<solid android:color="?colorAccent"/>
</shape>
</scale>
</item>
</layer-list>
Loading

0 comments on commit 6f6969e

Please sign in to comment.