feat(rpc): progress bar (hope nothing breaks)
This commit is contained in:
parent
949ab7e87b
commit
7ec889a915
3 changed files with 69 additions and 55 deletions
|
@ -72,5 +72,5 @@ object Discord {
|
||||||
const val small_Image: String =
|
const val small_Image: String =
|
||||||
"mp:external/9NqpMxXs4ZNQtMG42L7hqINW92GqqDxgxS9Oh0Sp880/%3Fsize%3D48%26quality%3Dlossless%26name%3DDantotsu/https/cdn.discordapp.com/emojis/1167344924874784828.gif"
|
"mp:external/9NqpMxXs4ZNQtMG42L7hqINW92GqqDxgxS9Oh0Sp880/%3Fsize%3D48%26quality%3Dlossless%26name%3DDantotsu/https/cdn.discordapp.com/emojis/1167344924874784828.gif"
|
||||||
const val small_Image_AniList: String =
|
const val small_Image_AniList: String =
|
||||||
"mp:external/ORoccmSwMX55y1BUmiwf7OH9IlnztoO0MDpsGQnibpw/https/anilist.co/img/icons/icon.svg"
|
"https://anilist.co/img/icons/android-chrome-512x512.png"
|
||||||
}
|
}
|
|
@ -40,6 +40,7 @@ data class Activity(
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Timestamps(
|
data class Timestamps(
|
||||||
val start: Long? = null,
|
val start: Long? = null,
|
||||||
|
@SerialName("end")
|
||||||
val stop: Long? = null
|
val stop: Long? = null
|
||||||
)
|
)
|
||||||
}
|
}
|
|
@ -1114,60 +1114,6 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
|
||||||
)
|
)
|
||||||
initPlayer()
|
initPlayer()
|
||||||
preloading = false
|
preloading = false
|
||||||
val context = this
|
|
||||||
val offline: Boolean = PrefManager.getVal(PrefName.OfflineMode)
|
|
||||||
val incognito: Boolean = PrefManager.getVal(PrefName.Incognito)
|
|
||||||
if ((isOnline(context) && !offline) && Discord.token != null && !incognito) {
|
|
||||||
lifecycleScope.launch {
|
|
||||||
val discordMode = PrefManager.getCustomVal("discord_mode", "dantotsu")
|
|
||||||
val buttons = when (discordMode) {
|
|
||||||
"nothing" -> mutableListOf(
|
|
||||||
RPC.Link(getString(R.string.view_anime), media.shareLink ?: ""),
|
|
||||||
)
|
|
||||||
|
|
||||||
"dantotsu" -> mutableListOf(
|
|
||||||
RPC.Link(getString(R.string.view_anime), media.shareLink ?: ""),
|
|
||||||
RPC.Link("Watch on Dantotsu", getString(R.string.dantotsu))
|
|
||||||
)
|
|
||||||
|
|
||||||
"anilist" -> {
|
|
||||||
val userId = PrefManager.getVal<String>(PrefName.AnilistUserId)
|
|
||||||
val anilistLink = "https://anilist.co/user/$userId/"
|
|
||||||
mutableListOf(
|
|
||||||
RPC.Link(getString(R.string.view_anime), media.shareLink ?: ""),
|
|
||||||
RPC.Link("View My AniList", anilistLink)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> mutableListOf()
|
|
||||||
}
|
|
||||||
val presence = RPC.createPresence(
|
|
||||||
RPC.Companion.RPCData(
|
|
||||||
applicationId = Discord.application_Id,
|
|
||||||
type = RPC.Type.WATCHING,
|
|
||||||
activityName = media.userPreferredName,
|
|
||||||
details = ep.title?.takeIf { it.isNotEmpty() } ?: getString(
|
|
||||||
R.string.episode_num,
|
|
||||||
ep.number
|
|
||||||
),
|
|
||||||
state = "Episode : ${ep.number}/${media.anime?.totalEpisodes ?: "??"}",
|
|
||||||
largeImage = media.cover?.let {
|
|
||||||
RPC.Link(
|
|
||||||
media.userPreferredName,
|
|
||||||
it
|
|
||||||
)
|
|
||||||
},
|
|
||||||
smallImage = RPC.Link("Dantotsu", Discord.small_Image),
|
|
||||||
buttons = buttons
|
|
||||||
)
|
|
||||||
)
|
|
||||||
val intent = Intent(context, DiscordService::class.java).apply {
|
|
||||||
putExtra("presence", presence)
|
|
||||||
}
|
|
||||||
DiscordServiceRunningSingleton.running = true
|
|
||||||
startService(intent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updateProgress()
|
updateProgress()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1358,6 +1304,72 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun discordRPC(){
|
||||||
|
val context = this
|
||||||
|
val ep = episode
|
||||||
|
val offline: Boolean = PrefManager.getVal(PrefName.OfflineMode)
|
||||||
|
val incognito: Boolean = PrefManager.getVal(PrefName.Incognito)
|
||||||
|
if ((isOnline(context) && !offline) && Discord.token != null && !incognito) {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
val discordMode = PrefManager.getCustomVal("discord_mode", "dantotsu")
|
||||||
|
val buttons = when (discordMode) {
|
||||||
|
"nothing" -> mutableListOf(
|
||||||
|
RPC.Link(getString(R.string.view_anime), media.shareLink ?: ""),
|
||||||
|
)
|
||||||
|
|
||||||
|
"dantotsu" -> mutableListOf(
|
||||||
|
RPC.Link(getString(R.string.view_anime), media.shareLink ?: ""),
|
||||||
|
RPC.Link("Watch on Dantotsu", getString(R.string.dantotsu))
|
||||||
|
)
|
||||||
|
|
||||||
|
"anilist" -> {
|
||||||
|
val userId = PrefManager.getVal<String>(PrefName.AnilistUserId)
|
||||||
|
val anilistLink = "https://anilist.co/user/$userId/"
|
||||||
|
mutableListOf(
|
||||||
|
RPC.Link(getString(R.string.view_anime), media.shareLink ?: ""),
|
||||||
|
RPC.Link("View My AniList", anilistLink)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> mutableListOf()
|
||||||
|
}
|
||||||
|
val startTimestamp = Calendar.getInstance()
|
||||||
|
val durationInSeconds = if (exoPlayer.duration != C.TIME_UNSET) (exoPlayer.duration / 1000).toInt() else 1440
|
||||||
|
|
||||||
|
val endTimestamp = Calendar.getInstance().apply {
|
||||||
|
timeInMillis = startTimestamp.timeInMillis
|
||||||
|
add(Calendar.SECOND, durationInSeconds)
|
||||||
|
}
|
||||||
|
val presence = RPC.createPresence(
|
||||||
|
RPC.Companion.RPCData(
|
||||||
|
applicationId = Discord.application_Id,
|
||||||
|
type = RPC.Type.WATCHING,
|
||||||
|
activityName = media.userPreferredName,
|
||||||
|
details = ep.title?.takeIf { it.isNotEmpty() } ?: getString(
|
||||||
|
R.string.episode_num,
|
||||||
|
ep.number
|
||||||
|
),
|
||||||
|
startTimestamp = startTimestamp.timeInMillis,
|
||||||
|
stopTimestamp = endTimestamp.timeInMillis,
|
||||||
|
state = "Episode : ${ep.number}/${media.anime?.totalEpisodes ?: "??"}",
|
||||||
|
largeImage = media.cover?.let {
|
||||||
|
RPC.Link(
|
||||||
|
media.userPreferredName,
|
||||||
|
it
|
||||||
|
)
|
||||||
|
},
|
||||||
|
smallImage = RPC.Link("Dantotsu", Discord.small_Image),
|
||||||
|
buttons = buttons
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val intent = Intent(context, DiscordService::class.java).apply {
|
||||||
|
putExtra("presence", presence)
|
||||||
|
}
|
||||||
|
DiscordServiceRunningSingleton.running = true
|
||||||
|
startService(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
private fun initPlayer() {
|
private fun initPlayer() {
|
||||||
checkNotch()
|
checkNotch()
|
||||||
|
|
||||||
|
@ -2042,6 +2054,7 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
|
||||||
exoPlayer.play()
|
exoPlayer.play()
|
||||||
if (episodeLength == 0f) {
|
if (episodeLength == 0f) {
|
||||||
episodeLength = exoPlayer.duration.toFloat()
|
episodeLength = exoPlayer.duration.toFloat()
|
||||||
|
discordRPC()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isBuffering = playbackState == Player.STATE_BUFFERING
|
isBuffering = playbackState == Player.STATE_BUFFERING
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue