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 259cfb89..df031443 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt @@ -1083,35 +1083,45 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL val incognito: Boolean = PrefManager.getVal(PrefName.Incognito) if ((isOnline(context) && !offline) && Discord.token != null && !incognito) { lifecycleScope.launch { - 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 = mutableListOf( + val discordMode = PrefManager.getCustomVal("discord_mode", "dantotsu") + val buttons = when (discordMode) { + "dantotsu" -> mutableListOf( RPC.Link(getString(R.string.view_anime), media.shareLink ?: ""), - RPC.Link( - "Stream on Dantotsu", - getString(R.string.github) + 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) ) + } + "custom" -> { + val customButtonText = PrefManager.getCustomVal("custom_button_text", "") + val customButtonLink = PrefManager.getCustomVal("custom_button_link", "") + mutableListOf( + RPC.Link(getString(R.string.view_anime), media.shareLink ?: ""), + RPC.Link(customButtonText, customButtonLink) + ) + } + 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) } @@ -1119,7 +1129,6 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL startService(intent) } } - updateProgress() } } diff --git a/app/src/main/java/ani/dantotsu/media/manga/mangareader/MangaReaderActivity.kt b/app/src/main/java/ani/dantotsu/media/manga/mangareader/MangaReaderActivity.kt index 6f00adb4..3664819b 100644 --- a/app/src/main/java/ani/dantotsu/media/manga/mangareader/MangaReaderActivity.kt +++ b/app/src/main/java/ani/dantotsu/media/manga/mangareader/MangaReaderActivity.kt @@ -362,15 +362,11 @@ class MangaReaderActivity : AppCompatActivity() { currentChapterIndex = chaptersArr.indexOf(chap.number) binding.mangaReaderChapterSelect.setSelection(currentChapterIndex) if (defaultSettings.direction == RIGHT_TO_LEFT || defaultSettings.direction == BOTTOM_TO_TOP) { - binding.mangaReaderNextChap.text = - chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: "" - binding.mangaReaderPrevChap.text = - chaptersTitleArr.getOrNull(currentChapterIndex + 1) ?: "" + binding.mangaReaderNextChap.text = chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: "" + binding.mangaReaderPrevChap.text = chaptersTitleArr.getOrNull(currentChapterIndex + 1) ?: "" } else { - binding.mangaReaderNextChap.text = - chaptersTitleArr.getOrNull(currentChapterIndex + 1) ?: "" - binding.mangaReaderPrevChap.text = - chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: "" + binding.mangaReaderNextChap.text = chaptersTitleArr.getOrNull(currentChapterIndex + 1) ?: "" + binding.mangaReaderPrevChap.text = chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: "" } applySettings() val context = this @@ -378,6 +374,30 @@ class MangaReaderActivity : AppCompatActivity() { 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) { + "dantotsu" -> mutableListOf( + RPC.Link(getString(R.string.view_manga), media.shareLink ?: ""), + RPC.Link("Read 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_manga), media.shareLink ?: ""), + RPC.Link("View My AniList", anilistLink) + ) + } + "custom" -> { + val customButtonText = PrefManager.getCustomVal("custom_button_text", "") + val customButtonLink = PrefManager.getCustomVal("custom_button_link", "") + mutableListOf( + RPC.Link(getString(R.string.view_manga), media.shareLink ?: ""), + RPC.Link(customButtonText, customButtonLink) + ) + } + else -> mutableListOf() + } val presence = RPC.createPresence( RPC.Companion.RPCData( applicationId = Discord.application_Id, @@ -386,20 +406,9 @@ class MangaReaderActivity : AppCompatActivity() { details = chap.title?.takeIf { it.isNotEmpty() } ?: getString(R.string.chapter_num, chap.number), state = "${chap.number}/${media.manga?.totalChapters ?: "??"}", - largeImage = media.cover?.let { cover -> - RPC.Link(media.userPreferredName, cover) - }, - smallImage = RPC.Link( - "Dantotsu", - Discord.small_Image - ), - buttons = mutableListOf( - RPC.Link(getString(R.string.view_manga), media.shareLink ?: ""), - RPC.Link( - "Stream on Dantotsu", - getString(R.string.github) - ) - ) + largeImage = media.cover?.let { cover -> RPC.Link(media.userPreferredName, cover) }, + smallImage = RPC.Link("Dantotsu", Discord.small_Image), + buttons = buttons ) ) val intent = Intent(context, DiscordService::class.java).apply { diff --git a/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt b/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt index 8733da53..ff8278f5 100644 --- a/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt +++ b/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt @@ -13,12 +13,18 @@ import android.os.Build.VERSION.CODENAME import android.os.Build.VERSION.RELEASE import android.os.Build.VERSION.SDK_INT import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.animation.AnimationUtils import android.view.inputmethod.EditorInfo import android.widget.ArrayAdapter +import android.widget.Button +import android.widget.EditText +import android.widget.RadioButton +import android.widget.RadioGroup import android.widget.TextView import androidx.activity.OnBackPressedCallback import androidx.activity.result.contract.ActivityResultContracts @@ -26,6 +32,7 @@ import androidx.annotation.OptIn import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.core.view.updateLayoutParams +import androidx.core.widget.doAfterTextChanged import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.lifecycleScope import androidx.media3.common.util.UnstableApi @@ -79,6 +86,7 @@ import ani.dantotsu.statusBarHeight import ani.dantotsu.themes.ThemeManager import ani.dantotsu.toast import ani.dantotsu.util.Logger +import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.textfield.TextInputEditText import eltos.simpledialogfragment.SimpleDialog import eltos.simpledialogfragment.SimpleDialog.OnDialogResultListener.BUTTON_POSITIVE @@ -295,6 +303,74 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene imageSwitcher.setImageResource(initialStatus) imageSwitcher.startAnimation(zoomInAnimation) } + imageSwitcher.setOnLongClickListener { + val dialogView = LayoutInflater.from(this@SettingsActivity).inflate(R.layout.discord_rpc_layout, null) + val radioGroup = dialogView.findViewById(R.id.radio_group) + val radioDantotsu = dialogView.findViewById(R.id.radio_dantotsu) + val radioAnilist = dialogView.findViewById(R.id.radio_anilist) + val radioCustom = dialogView.findViewById(R.id.radio_custom) + val anilistLinkPreview = dialogView.findViewById(R.id.anilistLinkPreview) + val customButtonPreview = dialogView.findViewById(R.id.customButtonPreview) + val customLinkPreview = dialogView.findViewById(R.id.customLinkPreview) + val buttonEditText = dialogView.findViewById(R.id.buttonEditText) + val linkEditText = dialogView.findViewById(R.id.linkEditText) + + buttonEditText.addTextChangedListener(object : TextWatcher { + override fun afterTextChanged(s: Editable?) {} + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { + PrefManager.setCustomVal("custom_button_text", s.toString()) + customButtonPreview.text = s.toString().ifEmpty { "Sample" } + } + }) + + linkEditText.addTextChangedListener(object : TextWatcher { + override fun afterTextChanged(s: Editable?) {} + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { + PrefManager.setCustomVal("custom_button_link", s.toString()) + customLinkPreview.text = s.toString().ifEmpty { "https://example.com/" } + } + }) + + val userId = PrefManager.getVal(PrefName.AnilistUserName) + val currentMode = PrefManager.getCustomVal("discord_mode", "dantotsu") + val customButtonText = PrefManager.getCustomVal("custom_button_text", "") + val customButtonLink = PrefManager.getCustomVal("custom_button_link", "") + + when (currentMode) { + "dantotsu" -> radioDantotsu.isChecked = true + "anilist" -> radioAnilist.isChecked = true + "custom" -> radioCustom.isChecked = true + } + + anilistLinkPreview.text = getString(R.string.anilist_link, userId) + customButtonPreview.text = customButtonText.ifEmpty { "Sample" } + customLinkPreview.text = customButtonLink.ifEmpty { "https://example.com/" } + buttonEditText.setText(customButtonText) + linkEditText.setText(customButtonLink) + + val bottomSheetDialog = BottomSheetDialog(this@SettingsActivity) + bottomSheetDialog.setContentView(dialogView) + + radioGroup.setOnCheckedChangeListener { _, checkedId -> + when (checkedId) { + R.id.radio_dantotsu -> { + PrefManager.setCustomVal("discord_mode", "dantotsu") + } + R.id.radio_anilist -> { + PrefManager.setCustomVal("discord_mode", "anilist") + } + R.id.radio_custom -> { + PrefManager.setCustomVal("discord_mode", "custom") + PrefManager.setCustomVal("custom_button_text", buttonEditText.text.toString()) + PrefManager.setCustomVal("custom_button_link", linkEditText.text.toString()) + } + } + } + bottomSheetDialog.show() + true + } } else { imageSwitcher.visibility = View.GONE settingsDiscordAvatar.setImageResource(R.drawable.ic_round_person_24) diff --git a/app/src/main/res/layout/bottom_sheet_search_filter.xml b/app/src/main/res/layout/bottom_sheet_search_filter.xml index 8ca02366..916a2e72 100644 --- a/app/src/main/res/layout/bottom_sheet_search_filter.xml +++ b/app/src/main/res/layout/bottom_sheet_search_filter.xml @@ -2,9 +2,9 @@ + android:layout_height="wrap_content" + android:background="@drawable/bottom_sheet_background"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6dbabbdd..230a227a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -11,8 +11,11 @@ https://discord.gg/4HPZ5nAWwM https://github.com/rebelonion/Dantotsu + https://dantotsu.app/ https://t.me/+gzBCQExtLQo1YTNh https://www.buymeacoffee.com/rebelonion + https://anilist.co/user/%1$s/ + Home Anime @@ -652,6 +655,9 @@ Try logging-in again Error loading Discord User Data + Display dantotsu in the second button + Display your AniList profile + Set up your own custom button Warning View Anime View Manga @@ -810,4 +816,10 @@ Non quae tempore quo provident laudantium qui illo dolor vel quia dolor et exerc donate :) Do it! Password + Discord Rich Presence + Stream on Dantotsu + View My AniList + Button Text + Button Link + Sample