Skip to content

Commit

Permalink
add subject onAir data
Browse files Browse the repository at this point in the history
  • Loading branch information
ekibun committed Nov 18, 2019
1 parent 796180b commit 3b36ed7
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ dependencies {
implementation 'com.github.siyamed:android-shape-imageview:0.9.3'
implementation 'androidx.browser:browser:1.0.0'
implementation 'com.zhy:base-adapter:3.0.3'
implementation 'com.xiaofeng.android:flowlayoutmanager:1.2.3.2'
implementation 'com.nshmura:recyclertablayout:1.5.0'
implementation 'com.github.chrisbanes:PhotoView:2.1.4'
implementation 'am.util:viewpager:25.3.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface GithubRaw{
/**
* 时间表
*/
@GET("/ekibun/bangumi_calendar/master/calendar.json")
@GET("/ekibun/bangumi_onair/master/calendar.json")
fun bangumiCalendar(): Call<List<BangumiCalendarItem>>

/**
Expand Down
44 changes: 41 additions & 3 deletions app/src/main/java/soko/ekibun/bangumi/api/github/bean/OnAirInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package soko.ekibun.bangumi.api.github.bean
data class OnAirInfo (
val id: Int,
val name: String,
val sites: List<SubjectSite>,
val eps: List<Ep>
){
/**
Expand All @@ -21,11 +22,13 @@ data class OnAirInfo (
/**
* 站点信息
*/
data class Site(
open class Site(
val site: String,
val title: String,
val url: String
private val title: String = "",
private val url: String = ""
) {
open fun title() = title
open fun url() = url
val color
get() = (0xff000000 + when (site) {
"offical" -> 0x888888
Expand Down Expand Up @@ -53,4 +56,39 @@ data class OnAirInfo (
else -> 0
}).toInt()
}

/**
* 站点信息
*/
class SubjectSite(
site: String,
val id: String,
val week: Int = 0,
val time: String? = null
) : Site(site) {
override fun title() = if (week > 0) "每周${"一二三四五六日"[week - 1]} ${time?.replace(Regex("""(\d{2})(\d{2})"""), "$1:$2")}更新" else id
override fun url() = when (site) {
"bangumi" -> "http://bangumi.tv/subject/$id"
"saraba1st" -> "https://bbs.saraba1st.com/2b/thread-$id-1-1.html"

"acfun" -> "https://www.acfun.cn/bangumi/aa$id"
"bilibili" -> "https://www.bilibili.com/bangumi/media/md$id"
"tucao" -> "http://www.tucao.tv/index.php?m=search&c=index&a=init2&q=$id"
"sohu" -> "https://tv.sohu.com/$id"
"youku" -> "https://list.youku.com/show/id_z$id.html"
"tudou" -> "https://www.tudou.com/albumcover/$id.html"
"qq" -> "https://v.qq.com/detail/$id.html"
"iqiyi" -> "http://www.iqiyi.com/$id.html"
"letv" -> "https://www.le.com/comic/$id.html"
"pptv" -> "http://v.pptv.com/page/$id.html"
"kankan" -> "http://movie.kankan.com/movie/$id"
"mgtv" -> "https://www.mgtv.com/h/$id.html"
"nicovideo" -> "http://ch.nicovideo.jp/$id"
"netflix" -> "https://www.netflix.com/title/$id"

"dmhy" -> "https://share.dmhy.org/topics/list?keyword=$id"
"nyaa" -> "https://www.nyaa.se/?page=search&term=$id"
else -> id
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class EpisodeDialog(context: Context) : Dialog(context, R.style.AppTheme_Dialog)
val dialog = EpisodeDialog(context)
dialog.eps = eps
dialog.episode = episode
dialog.onAirInfo = onAirInfo
dialog.onAirInfoChange(onAirInfo)
dialog.callback = callback
dialog.show()
return dialog
Expand Down Expand Up @@ -63,8 +63,11 @@ class EpisodeDialog(context: Context) : Dialog(context, R.style.AppTheme_Dialog)

var eps: List<Episode> = ArrayList()
var episode: Episode? = null
var onAirInfo: OnAirInfo? = null
var callback: ((eps: List<Episode>, status: String) -> Unit)? = null
val adapter = SitesAdapter()
var onAirInfoChange = { info: OnAirInfo? ->
adapter.setNewData(info?.eps?.find { it.id == episode?.id }?.sites)
}
@SuppressLint("SetTextI18n", "InflateParams")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -79,14 +82,13 @@ class EpisodeDialog(context: Context) : Dialog(context, R.style.AppTheme_Dialog)
view.item_episode_title.setOnClickListener {
WebActivity.launchUrl(context, "${Bangumi.SERVER}/m/topic/ep/${episode.id}", "")
}
val adapter = SitesAdapter(onAirInfo?.eps?.firstOrNull { it.id == episode.id }?.sites?.toMutableList())
val emptyTextView = TextView(context)
val dp4 = (context.resources.displayMetrics.density * 4 + 0.5f).toInt()
emptyTextView.setPadding(dp4, dp4, dp4, dp4)
emptyTextView.setText(R.string.hint_no_play_source)
adapter.emptyView = emptyTextView
adapter.setOnItemClickListener { _, _, position ->
WebActivity.launchUrl(context, adapter.data[position].url, "")
WebActivity.launchUrl(context, adapter.data[position].url(), "")
}
view.item_site_list.adapter = adapter
val linearLayoutManager = androidx.recyclerview.widget.LinearLayoutManager(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SitesAdapter(data: MutableList<OnAirInfo.Site>? = null) :

override fun convert(helper: BaseViewHolder, item: OnAirInfo.Site) {
helper.itemView.item_site.text = item.site
helper.itemView.item_site_id.text = item.title
helper.itemView.item_site_id.text = item.title()
helper.itemView.item_site.backgroundTintList = ColorStateList.valueOf(item.color)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class SubjectPresenter(private val context: SubjectActivity) {
subjectView.detail.item_detail.setOnClickListener {
InfoboxDialog.showDialog(context, subject)
}

subjectView.sitesAdapter.setOnItemClickListener { _, _, position ->
WebActivity.launchUrl(context, subjectView.sitesAdapter.data[position].url(), "")
}

subjectView.commentAdapter.setEnableLoadMore(true)
subjectView.commentAdapter.setLoadMoreView(BrvahLoadMoreView())
Expand Down Expand Up @@ -203,9 +205,9 @@ class SubjectPresenter(private val context: SubjectActivity) {
}
}

@SuppressLint("SetTextI18n")
private var episodeDialog: EpisodeDialog? = null
private fun openEpisode(episode: Episode, eps: List<Episode>) {
EpisodeDialog.showDialog(context, episode, eps, onAirInfo) { mEps, status ->
episodeDialog = EpisodeDialog.showDialog(context, episode, eps, onAirInfo) { mEps, status ->
updateProgress(mEps, status)
}
}
Expand Down Expand Up @@ -247,6 +249,8 @@ class SubjectPresenter(private val context: SubjectActivity) {
}
is OnAirInfo -> {
onAirInfo = it
subjectView.sitesAdapter.setNewData(it.sites)
episodeDialog?.onAirInfoChange?.invoke(it)
}
is IpView -> {
val ret = BgmIpViewer.getSeason(it, subject)
Expand Down
28 changes: 12 additions & 16 deletions app/src/main/java/soko/ekibun/bangumi/ui/subject/SubjectView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class SubjectView(private val context: SubjectActivity) {
val tagAdapter = TagAdapter()
val topicAdapter = TopicAdapter()
val blogAdapter = BlogAdapter()
val sitesAdapter = SitesAdapter()
val commentAdapter = CommentAdapter()
val seasonAdapter = SeasonAdapter()
val seasonLayoutManager = LinearLayoutManager(context)
val seasonLayoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)

val detail = context.subject_detail as LinearLayout

Expand Down Expand Up @@ -87,8 +88,7 @@ class SubjectView(private val context: SubjectActivity) {
})

context.season_list.adapter = seasonAdapter
seasonLayoutManager.orientation = RecyclerView.HORIZONTAL
context.season_list.layoutManager = seasonLayoutManager
context.season_list.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
context.season_list.isNestedScrollingEnabled = false

context.episode_list.adapter = episodeAdapter
Expand All @@ -107,6 +107,7 @@ class SubjectView(private val context: SubjectActivity) {
context.linked_list.setOnTouchListener(swipeTouchListener)
context.character_list.setOnTouchListener(swipeTouchListener)
context.tag_list.setOnTouchListener(swipeTouchListener)
context.site_list.setOnTouchListener(swipeTouchListener)

val touchListener = episodeDetailAdapter.setUpWithRecyclerView(context.episode_detail_list)
touchListener.nestScrollDistance = {
Expand All @@ -128,22 +129,15 @@ class SubjectView(private val context: SubjectActivity) {
}

context.linked_list.adapter = linkedSubjectsAdapter
val subjectLayoutManager = LinearLayoutManager(context)
subjectLayoutManager.orientation = RecyclerView.HORIZONTAL
context.linked_list.layoutManager = subjectLayoutManager
context.linked_list.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
context.linked_list.isNestedScrollingEnabled = false


context.commend_list.adapter = recommendSubjectsAdapter
val subjectLayoutManager2 = LinearLayoutManager(context)
subjectLayoutManager2.orientation = RecyclerView.HORIZONTAL
context.commend_list.layoutManager = subjectLayoutManager2
context.commend_list.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
context.commend_list.isNestedScrollingEnabled = false

context.character_list.adapter = characterAdapter
val characterLayoutManager = LinearLayoutManager(context)
characterLayoutManager.orientation = RecyclerView.HORIZONTAL
context.character_list.layoutManager = characterLayoutManager
context.character_list.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
context.character_list.isNestedScrollingEnabled = false

context.topic_list.adapter = topicAdapter
Expand All @@ -155,11 +149,13 @@ class SubjectView(private val context: SubjectActivity) {
context.blog_list.isNestedScrollingEnabled = false

context.tag_list.adapter = tagAdapter
val tagLayoutManager = LinearLayoutManager(context)
tagLayoutManager.orientation = RecyclerView.HORIZONTAL
context.tag_list.layoutManager = tagLayoutManager
context.tag_list.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
context.tag_list.isNestedScrollingEnabled = false

context.site_list.adapter = sitesAdapter
context.site_list.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
context.site_list.isNestedScrollingEnabled = false

context.comment_list.adapter = commentAdapter
context.comment_list.layoutManager = LinearLayoutManager(context)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package soko.ekibun.bangumi.util;

import android.content.Context;
import androidx.annotation.Keep;
import android.webkit.CookieManager;
import android.webkit.WebView;
import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.HttpUrl;
Expand All @@ -16,7 +13,9 @@ public class WebViewCookieHandler implements CookieJar {
private CookieManager mCookieManager = CookieManager.getInstance();

@Override
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) { }
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
/* no-op */
}

@Override
public List<Cookie> loadForRequest(HttpUrl url) {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/item_calendar_tab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@+id/item_week"
android:textSize="12sp"
android:textSize="@dimen/textSizeSmall"
android:textColor="@color/color_selectable"
android:layout_marginBottom="2dp"
tools:text="4-19"
Expand All @@ -35,6 +35,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="3dp"
android:background="@drawable/bg_calendar_selector"
android:textColor="@color/color_calendar_selector"
android:backgroundTintMode="src_in"
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/subject_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@
tools:orientation="horizontal"
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_tag"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/site_list"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="4dp"
android:clipToPadding="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:orientation="horizontal"
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_site"/>
</LinearLayout>

<LinearLayout
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down

0 comments on commit 3b36ed7

Please sign in to comment.