Skip to content

Commit

Permalink
pin episode header
Browse files Browse the repository at this point in the history
  • Loading branch information
ekibun committed Feb 21, 2019
1 parent 228e830 commit a9e55c9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 38 deletions.
20 changes: 18 additions & 2 deletions app/src/main/java/soko/ekibun/bangumi/ui/subject/EpisodeAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ package soko.ekibun.bangumi.ui.subject
import android.content.res.ColorStateList
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.TextView
import com.chad.library.adapter.base.BaseSectionQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.chad.library.adapter.base.entity.SectionEntity
import com.oushangfeng.pinnedsectionitemdecoration.PinnedHeaderItemDecoration
import kotlinx.android.synthetic.main.item_episode.view.*
import soko.ekibun.bangumi.R
import soko.ekibun.bangumi.api.bangumi.bean.Episode
import soko.ekibun.bangumi.util.ResourceUtil
import soko.ekibun.bangumi.api.bangumi.bean.SubjectProgress
import soko.ekibun.bangumi.ui.view.DragSelectTouchListener
import com.oushangfeng.pinnedsectionitemdecoration.utils.FullSpanUtil



class EpisodeAdapter(data: MutableList<SelectableSectionEntity<Episode>>? = null) :
BaseSectionQuickAdapter<EpisodeAdapter.SelectableSectionEntity<Episode>, BaseViewHolder>
Expand All @@ -23,7 +26,7 @@ class EpisodeAdapter(data: MutableList<SelectableSectionEntity<Episode>>? = null
constructor(t: T): super(t)
}
override fun convertHead(helper: BaseViewHolder, item: SelectableSectionEntity<Episode>) {
helper.getView<TextView>(R.id.item_header).visibility = if(data.indexOf(item) == 0) View.GONE else View.VISIBLE
//helper.getView<TextView>(R.id.item_header).visibility = if(data.indexOf(item) == 0) View.GONE else View.VISIBLE
helper.setText(R.id.item_header, item.header)
}

Expand Down Expand Up @@ -59,6 +62,9 @@ class EpisodeAdapter(data: MutableList<SelectableSectionEntity<Episode>>? = null

fun setUpWithRecyclerView(recyclerView: RecyclerView): DragSelectTouchListener{
recyclerView.adapter = this

recyclerView.addItemDecoration(PinnedHeaderItemDecoration.Builder(SECTION_HEADER_VIEW).create())

val touchListener = DragSelectTouchListener()
recyclerView.addOnItemTouchListener(touchListener)
longClickListener = {position ->
Expand Down Expand Up @@ -87,4 +93,14 @@ class EpisodeAdapter(data: MutableList<SelectableSectionEntity<Episode>>? = null
}
updateSelection()
}

override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
super.onAttachedToRecyclerView(recyclerView)
FullSpanUtil.onAttachedToRecyclerView(recyclerView, this, SECTION_HEADER_VIEW)
}

override fun onViewAttachedToWindow(holder: BaseViewHolder) {
super.onViewAttachedToWindow(holder)
FullSpanUtil.onViewAttachedToWindow(holder, this, SECTION_HEADER_VIEW)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class SubjectPresenter(private val context: SubjectActivity){
subjectView.episodeDetailAdapter.updateSelection = {
val eps = subjectView.episodeDetailAdapter.data.filter { it.isSelected }
context.item_edit_ep.visibility = if(eps.isEmpty()) View.GONE else View.VISIBLE
context.item_ep_title.visibility = context.item_edit_ep.visibility
context.item_ep_title.text = "${context.getText(R.string.episodes)}${if(eps.isEmpty()) "" else "(${eps.size})"}"
}

Expand Down Expand Up @@ -225,7 +226,7 @@ class SubjectPresenter(private val context: SubjectActivity){
showDialog(view)
}

fun updateProgress(subject: Subject, eps: List<Episode>, newStatus: String){
private fun updateProgress(subject: Subject, eps: List<Episode>, newStatus: String){
if(newStatus == WATCH_TO){
val epIds = eps.map{ it.id.toString()}.reduce { acc, s -> "$acc,$s" }
Bangumi.updateProgress(eps.last().id, SubjectProgress.EpisodeProgress.EpisodeStatus.WATCH, context.formhash, context.ua, epIds).enqueue(
Expand Down Expand Up @@ -332,7 +333,7 @@ class SubjectPresenter(private val context: SubjectActivity){
subjectView.commentAdapter.loadMoreFail()}))
}

var onAirInfo: OnAirInfo? = null;
private var onAirInfo: OnAirInfo? = null
private fun refreshLines(subject: Subject){
val dateList = subject.air_date?.split("-") ?: return
val year = dateList.getOrNull(0)?.toIntOrNull()?:0
Expand Down
71 changes: 40 additions & 31 deletions app/src/main/res/layout/activity_subject.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@
android:layout_height="match_parent"
android:fillViewport="true"
android:background="?android:colorBackground"
android:layout_marginTop="44dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
Expand All @@ -254,45 +253,55 @@
android:layout_width="match_parent"
android:layout_height="44dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="?android:colorBackground"
android:clickable="true"
android:focusable="true"
android:visibility="invisible">
<ImageView android:layout_width="26dp"
android:layout_height="26dp"
android:padding="4dp"
android:layout_margin="8dp"
android:id="@+id/item_close"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:src="@drawable/ic_clear"
android:clickable="true"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:focusable="true"
android:contentDescription="@string/episodes"/>
<ImageView android:visibility="gone"
android:layout_width="26dp"
android:layout_height="26dp"
android:padding="4dp"
android:layout_margin="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/item_edit_ep"
app:layout_constraintEnd_toStartOf="@+id/item_close"
android:src="@drawable/ic_edit"
android:clickable="true"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:focusable="true"
android:contentDescription="@string/episodes"/>
<RelativeLayout
android:id="@+id/item_eps_button_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:background="?android:colorBackground"
app:layout_constraintEnd_toEndOf="parent">
<ImageView android:layout_width="26dp"
android:layout_height="26dp"
android:padding="4dp"
android:layout_margin="8dp"
android:id="@+id/item_close"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:src="@drawable/ic_clear"
android:clickable="true"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:focusable="true"
android:contentDescription="@string/episodes"/>
<ImageView android:visibility="gone"
android:layout_width="26dp"
android:layout_height="26dp"
android:padding="4dp"
android:layout_margin="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/item_edit_ep"
app:layout_constraintEnd_toStartOf="@+id/item_close"
android:src="@drawable/ic_edit"
android:clickable="true"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:focusable="true"
android:contentDescription="@string/episodes"/>
</RelativeLayout>
<TextView android:layout_width="0dp"
android:layout_height="match_parent"
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
android:padding="12dp"
android:text="@string/episodes"
android:id="@+id/item_ep_title"
app:layout_constraintEnd_toStartOf="@+id/item_edit_ep"
app:layout_constraintStart_toStartOf="parent"/>
app:layout_constraintEnd_toStartOf="@+id/item_eps_button_box"
app:layout_constraintStart_toStartOf="parent"
android:visibility="invisible"
android:background="?android:colorBackground"/>
</android.support.constraint.ConstraintLayout>

</android.support.design.widget.CoordinatorLayout>
8 changes: 5 additions & 3 deletions app/src/main/res/layout/header_episode.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="44dp">
<TextView android:id="@+id/item_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:padding="8dp"
android:textAppearance="@android:style/TextAppearance.Material.Subhead"/>
android:gravity="center_vertical"
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
android:background="?android:colorBackground"/>
</android.support.constraint.ConstraintLayout>

0 comments on commit a9e55c9

Please sign in to comment.