no presence when not signed in

This commit is contained in:
Finnley Somdahl 2023-12-05 00:25:37 -06:00
parent 34a3e9e5a3
commit ea83b722a6
2 changed files with 40 additions and 31 deletions

View file

@ -998,36 +998,43 @@ class ExoplayerView : AppCompatActivity(), Player.Listener {
preloading = false preloading = false
val context = this val context = this
lifecycleScope.launch { if (isOnline(context) && Discord.token != null) {
val presence = RPC.createPresence(RPC.Companion.RPCData( lifecycleScope.launch {
applicationId = Discord.application_Id, val presence = RPC.createPresence(RPC.Companion.RPCData(
type = RPC.Type.WATCHING, applicationId = Discord.application_Id,
activityName = media.userPreferredName, type = RPC.Type.WATCHING,
details = ep.title?.takeIf { it.isNotEmpty() } ?: getString( activityName = media.userPreferredName,
R.string.episode_num, details = ep.title?.takeIf { it.isNotEmpty() } ?: getString(
ep.number R.string.episode_num,
), ep.number
state = "Episode : ${ep.number}/${media.anime?.totalEpisodes ?: "??"}", ),
largeImage = media.cover?.let { RPC.Link(media.userPreferredName, it) }, state = "Episode : ${ep.number}/${media.anime?.totalEpisodes ?: "??"}",
smallImage = RPC.Link( largeImage = media.cover?.let {
"Dantotsu", RPC.Link(
Discord.small_Image media.userPreferredName,
), it
buttons = mutableListOf( )
RPC.Link(getString(R.string.view_anime), media.shareLink ?: ""), },
RPC.Link( smallImage = RPC.Link(
"Stream on Dantotsu", "Dantotsu",
"https://github.com/rebelonion/Dantotsu/" Discord.small_Image
),
buttons = mutableListOf(
RPC.Link(getString(R.string.view_anime), media.shareLink ?: ""),
RPC.Link(
"Stream on Dantotsu",
"https://github.com/rebelonion/Dantotsu/"
)
) )
) )
) )
)
val intent = Intent(context, DiscordService::class.java).apply { val intent = Intent(context, DiscordService::class.java).apply {
putExtra("presence", presence) putExtra("presence", presence)
}
DiscordServiceRunningSingleton.running = true
startService(intent)
} }
DiscordServiceRunningSingleton.running = true
startService(intent)
} }
updateProgress() updateProgress()
@ -1426,9 +1433,11 @@ class ExoplayerView : AppCompatActivity(), Player.Listener {
exoPlayer.release() exoPlayer.release()
VideoCache.release() VideoCache.release()
mediaSession?.release() mediaSession?.release()
val stopIntent = Intent(this, DiscordService::class.java) if(DiscordServiceRunningSingleton.running) {
DiscordServiceRunningSingleton.running = false val stopIntent = Intent(this, DiscordService::class.java)
stopService(stopIntent) DiscordServiceRunningSingleton.running = false
stopService(stopIntent)
}
} }

View file

@ -124,7 +124,7 @@ class MangaReaderActivity : AppCompatActivity() {
override fun onDestroy() { override fun onDestroy() {
mangaCache.clear() mangaCache.clear()
if (isOnline(baseContext)) { //TODO: if (DiscordServiceRunningSingleton.running) {
DiscordServiceRunningSingleton.running = false DiscordServiceRunningSingleton.running = false
val stopIntent = Intent(this, DiscordService::class.java) val stopIntent = Intent(this, DiscordService::class.java)
stopService(stopIntent) stopService(stopIntent)
@ -329,7 +329,7 @@ class MangaReaderActivity : AppCompatActivity() {
chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: "" chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: ""
applySettings() applySettings()
val context = this val context = this
if (isOnline(context)) { if (isOnline(context) && Discord.token != null) {
lifecycleScope.launch { lifecycleScope.launch {
val presence = RPC.createPresence( val presence = RPC.createPresence(
RPC.Companion.RPCData( RPC.Companion.RPCData(