Skip to content

Commit

Permalink
update ipc
Browse files Browse the repository at this point in the history
  • Loading branch information
ekibun committed Sep 28, 2019
1 parent 8a2cab8 commit 5644b77
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package soko.ekibun.bangumi.ui.crash

import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.activity_crash.*
import retrofit2.Call
Expand All @@ -13,7 +12,6 @@ import soko.ekibun.bangumi.api.ApiHelper
import soko.ekibun.bangumi.api.xxxlin.Xxxlin
import soko.ekibun.bangumi.api.xxxlin.bean.BaseResult
import soko.ekibun.bangumi.ui.splash.SplashActivity
import soko.ekibun.bangumi.util.AppUtil

class CrashActivity : AppCompatActivity() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package soko.ekibun.bangumi.ui.main.fragment.cache

import android.os.Bundle
import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.Menu
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.content_cache.*
import soko.ekibun.bangumi.R
import soko.ekibun.bangumi.model.DownloadCacheProvider
import soko.ekibun.bangumi.ui.main.MainActivity
import soko.ekibun.bangumi.ui.main.fragment.DrawerFragment
import soko.ekibun.bangumi.util.PlayerBridge
Expand All @@ -34,7 +32,7 @@ class CacheFragment: DrawerFragment(R.layout.content_cache) {
item_list?.adapter = adapter
item_list?.let{ adapter.emptyView = LayoutInflater.from(view.context).inflate(R.layout.view_empty, it, false) }
adapter.setOnItemClickListener { _, _, position ->
PlayerBridge.startActivity(view.context, adapter.data[position].subject)
PlayerBridge.startActivity(view.context, adapter.data[position].subject.toSubject())
}
item_swipe?.setOnRefreshListener {
activity.downloadCacheProvider.getCacheList({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import soko.ekibun.bangumi.api.trim21.BgmIpViewer
import soko.ekibun.bangumi.ui.web.WebActivity
import soko.ekibun.bangumi.util.HttpUtil
import soko.ekibun.bangumi.util.PlayerBridge
import soko.ekibun.videoplayer.bean.VideoSubject
import java.util.*

class SubjectPresenter(private val context: SubjectActivity) {
Expand Down Expand Up @@ -75,8 +74,8 @@ class SubjectPresenter(private val context: SubjectActivity) {
}

context.item_play.setOnClickListener {
if (PlayerBridge.checkActivity(context))
PlayerBridge.startActivity(context, VideoSubject(this.subject))
if (PlayerBridge.checkActivity(context, this.subject))
PlayerBridge.startActivity(context, this.subject)
}

subjectView.episodeAdapter.onItemLongClickListener = BaseQuickAdapter.OnItemLongClickListener { _, _, position ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class SubjectView(private val context: SubjectActivity) {
context.item_air_week.text = if (artist != null) "${artist.first}${Jsoup.parse(artist.second).body().text()}" else "更新时间:${CalendarAdapter.weekList[subject.air_weekday]}"
detail.item_detail.text = if (subject.summary.isNullOrEmpty()) subject.name else subject.summary

context.item_play.visibility = if ((PlayerBridge.checkActivity(context) || PlayerBridge.checkActivity(context)) && subject.type in listOf(Subject.TYPE_ANIME, Subject.TYPE_REAL)) View.VISIBLE else View.GONE
context.item_play.visibility = if (PlayerBridge.checkActivity(context, subject)) View.VISIBLE else View.GONE

subject.rating?.let {
context.detail_score.text = if (it.score == 0f) "-" else String.format("%.1f", it.score)
Expand Down
17 changes: 11 additions & 6 deletions app/src/main/java/soko/ekibun/bangumi/util/PlayerBridge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,30 @@ package soko.ekibun.bangumi.util
import android.content.Context
import android.content.Intent
import android.net.Uri
import soko.ekibun.bangumi.api.bangumi.bean.Subject
import soko.ekibun.videoplayer.bean.VideoSubject

object PlayerBridge {
const val EXTRA_SUBJECT = "extraSubject"
const val EXTRA_EPISODE_LIST = "extraEpisodeList"

fun checkActivity(context: Context): Boolean {
val intent = parseIntent(VideoSubject())
fun checkActivity(context: Context, subject: Subject = Subject()): Boolean {
val intent = parseIntent(subject)
return context.packageManager.queryIntentActivities(intent, 0).size != 0
}

fun startActivity(context: Context, subject: VideoSubject) {
fun startActivity(context: Context, subject: Subject) {
context.startActivity(parseIntent(subject))
}

private fun parseIntent(subject: VideoSubject): Intent {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("ekibun://player/bangumi/${subject.id}"))
private fun parseIntent(subject: Subject): Intent {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(when (subject.type) {
Subject.TYPE_MUSIC -> "ekibun://player/music/${subject.id}"
Subject.TYPE_BOOK -> "ekibun://player/book/${subject.id}"
else -> "ekibun://player/bangumi/${subject.id}"
}))
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK
intent.putExtra(EXTRA_SUBJECT, subject)
intent.putExtra(EXTRA_SUBJECT, VideoSubject(subject))
return intent
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ data class VideoSubject(

data class Token(
var formhash: String?,
var collect: Collection?
var collect: Collection?,
@Subject.SubjectType var type: String?
)

fun toSubject(): Subject{
Expand All @@ -38,6 +39,7 @@ data class VideoSubject(
id = id?.toIntOrNull()?:0,
images = Images(image ?: ""),
name = name,
type = data?.type ?: Subject.TYPE_ANY,
category = type,
air_date = air_date,
air_weekday = air_weekday,
Expand Down Expand Up @@ -73,7 +75,7 @@ data class VideoSubject(
Collection.TYPE_DROPPED -> "抛弃"
else -> null
},
JsonUtil.toJson(Token(HttpUtil.formhash, subject.collect))
JsonUtil.toJson(Token(HttpUtil.formhash, subject.collect, subject.type))
)

constructor(source: Parcel) : this(
Expand Down

0 comments on commit 5644b77

Please sign in to comment.