diff --git a/app/src/main/java/ani/dantotsu/connections/discord/Discord.kt b/app/src/main/java/ani/dantotsu/connections/discord/Discord.kt index 8470754e66..f6e791f4cc 100644 --- a/app/src/main/java/ani/dantotsu/connections/discord/Discord.kt +++ b/app/src/main/java/ani/dantotsu/connections/discord/Discord.kt @@ -72,5 +72,5 @@ object Discord { const val small_Image: String = "mp:external/9NqpMxXs4ZNQtMG42L7hqINW92GqqDxgxS9Oh0Sp880/%3Fsize%3D48%26quality%3Dlossless%26name%3DDantotsu/https/cdn.discordapp.com/emojis/1167344924874784828.gif" 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" } \ No newline at end of file diff --git a/app/src/main/java/ani/dantotsu/connections/discord/serializers/Activity.kt b/app/src/main/java/ani/dantotsu/connections/discord/serializers/Activity.kt index 2e6366ac5e..4416fe5cd6 100644 --- a/app/src/main/java/ani/dantotsu/connections/discord/serializers/Activity.kt +++ b/app/src/main/java/ani/dantotsu/connections/discord/serializers/Activity.kt @@ -40,6 +40,7 @@ data class Activity( @Serializable data class Timestamps( val start: Long? = null, + @SerialName("end") val stop: Long? = null ) } \ No newline at end of file diff --git a/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt b/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt index b0bacad592..b76cfad108 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt @@ -1114,60 +1114,6 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL ) initPlayer() 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(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() } } @@ -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(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() { checkNotch() @@ -2042,6 +2054,7 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL exoPlayer.play() if (episodeLength == 0f) { episodeLength = exoPlayer.duration.toFloat() + discordRPC() } } isBuffering = playbackState == Player.STATE_BUFFERING