feat: message when downloader not installed
This commit is contained in:
parent
13e2e37225
commit
831b99ae40
2 changed files with 65 additions and 30 deletions
|
@ -15,6 +15,7 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.activity.result.ActivityResult
|
import androidx.activity.result.ActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
|
@ -28,6 +29,7 @@ import ani.dantotsu.addons.torrent.TorrentAddonManager
|
||||||
import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
|
import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
|
||||||
import ani.dantotsu.copyToClipboard
|
import ani.dantotsu.copyToClipboard
|
||||||
import ani.dantotsu.currActivity
|
import ani.dantotsu.currActivity
|
||||||
|
import ani.dantotsu.currContext
|
||||||
import ani.dantotsu.databinding.BottomSheetSelectorBinding
|
import ani.dantotsu.databinding.BottomSheetSelectorBinding
|
||||||
import ani.dantotsu.databinding.ItemStreamBinding
|
import ani.dantotsu.databinding.ItemStreamBinding
|
||||||
import ani.dantotsu.databinding.ItemUrlBinding
|
import ani.dantotsu.databinding.ItemUrlBinding
|
||||||
|
@ -46,12 +48,14 @@ import ani.dantotsu.parsers.Video
|
||||||
import ani.dantotsu.parsers.VideoExtractor
|
import ani.dantotsu.parsers.VideoExtractor
|
||||||
import ani.dantotsu.parsers.VideoType
|
import ani.dantotsu.parsers.VideoType
|
||||||
import ani.dantotsu.setSafeOnClickListener
|
import ani.dantotsu.setSafeOnClickListener
|
||||||
|
import ani.dantotsu.settings.SettingsAddonActivity
|
||||||
import ani.dantotsu.settings.saving.PrefManager
|
import ani.dantotsu.settings.saving.PrefManager
|
||||||
import ani.dantotsu.settings.saving.PrefName
|
import ani.dantotsu.settings.saving.PrefName
|
||||||
import ani.dantotsu.snackString
|
import ani.dantotsu.snackString
|
||||||
import ani.dantotsu.toast
|
import ani.dantotsu.toast
|
||||||
import ani.dantotsu.tryWith
|
import ani.dantotsu.tryWith
|
||||||
import ani.dantotsu.util.Logger
|
import ani.dantotsu.util.Logger
|
||||||
|
import ani.dantotsu.util.customAlertDialog
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -95,7 +99,8 @@ class SelectorDialogFragment : BottomSheetDialogFragment() {
|
||||||
_binding = BottomSheetSelectorBinding.inflate(inflater, container, false)
|
_binding = BottomSheetSelectorBinding.inflate(inflater, container, false)
|
||||||
val window = dialog?.window
|
val window = dialog?.window
|
||||||
window?.statusBarColor = Color.TRANSPARENT
|
window?.statusBarColor = Color.TRANSPARENT
|
||||||
window?.navigationBarColor = requireContext().getThemeColor(com.google.android.material.R.attr.colorSurface)
|
window?.navigationBarColor =
|
||||||
|
requireContext().getThemeColor(com.google.android.material.R.attr.colorSurface)
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,14 +445,14 @@ class SelectorDialogFragment : BottomSheetDialogFragment() {
|
||||||
val subtitleNames = subtitles.map { it.language }
|
val subtitleNames = subtitles.map { it.language }
|
||||||
var subtitleToDownload: Subtitle? = null
|
var subtitleToDownload: Subtitle? = null
|
||||||
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup)
|
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup)
|
||||||
.setTitle("Download Subtitle")
|
.setTitle(R.string.download_subtitle)
|
||||||
.setSingleChoiceItems(
|
.setSingleChoiceItems(
|
||||||
subtitleNames.toTypedArray(),
|
subtitleNames.toTypedArray(),
|
||||||
-1
|
-1
|
||||||
) { _, which ->
|
) { _, which ->
|
||||||
subtitleToDownload = subtitles[which]
|
subtitleToDownload = subtitles[which]
|
||||||
}
|
}
|
||||||
.setPositiveButton("Download") { dialog, _ ->
|
.setPositiveButton(R.string.download) { dialog, _ ->
|
||||||
scope.launch {
|
scope.launch {
|
||||||
if (subtitleToDownload != null) {
|
if (subtitleToDownload != null) {
|
||||||
SubtitleDownloader.downloadSubtitle(
|
SubtitleDownloader.downloadSubtitle(
|
||||||
|
@ -463,13 +468,13 @@ class SelectorDialogFragment : BottomSheetDialogFragment() {
|
||||||
}
|
}
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
.setNegativeButton("Cancel") { dialog, _ ->
|
.setNegativeButton(R.string.cancel) { dialog, _ ->
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
alertDialog.window?.setDimAmount(0.8f)
|
alertDialog.window?.setDimAmount(0.8f)
|
||||||
} else {
|
} else {
|
||||||
snackString("No Subtitles Available")
|
snackString(R.string.no_subtitles_available)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.urlDownload.setSafeOnClickListener {
|
binding.urlDownload.setSafeOnClickListener {
|
||||||
|
@ -486,10 +491,27 @@ class SelectorDialogFragment : BottomSheetDialogFragment() {
|
||||||
} else {
|
} else {
|
||||||
val downloadAddonManager: DownloadAddonManager = Injekt.get()
|
val downloadAddonManager: DownloadAddonManager = Injekt.get()
|
||||||
if (!downloadAddonManager.isAvailable()){
|
if (!downloadAddonManager.isAvailable()){
|
||||||
toast("Download Extension not available")
|
val context = currContext() ?: requireContext()
|
||||||
|
context.customAlertDialog().apply {
|
||||||
|
setTitle(R.string.download_addon_not_installed)
|
||||||
|
setMessage(R.string.would_you_like_to_install)
|
||||||
|
setPosButton(R.string.yes) {
|
||||||
|
ContextCompat.startActivity(
|
||||||
|
context,
|
||||||
|
Intent(context, SettingsAddonActivity::class.java),
|
||||||
|
null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
setNegButton(R.string.no) {
|
||||||
|
return@setNegButton
|
||||||
|
}
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
dismiss()
|
||||||
return@setSafeOnClickListener
|
return@setSafeOnClickListener
|
||||||
}
|
}
|
||||||
val episode = media!!.anime!!.episodes!![media!!.anime!!.selectedEpisode!!]!!
|
val episode =
|
||||||
|
media!!.anime!!.episodes!![media!!.anime!!.selectedEpisode!!]!!
|
||||||
val selectedVideo =
|
val selectedVideo =
|
||||||
if (extractor.videos.size > episode.selectedVideo) extractor.videos[episode.selectedVideo] else null
|
if (extractor.videos.size > episode.selectedVideo) extractor.videos[episode.selectedVideo] else null
|
||||||
val subtitleNames = subtitles.map { it.language }
|
val subtitleNames = subtitles.map { it.language }
|
||||||
|
@ -499,10 +521,11 @@ class SelectorDialogFragment : BottomSheetDialogFragment() {
|
||||||
if (url.startsWith("magnet:") || url.endsWith(".torrent")) {
|
if (url.startsWith("magnet:") || url.endsWith(".torrent")) {
|
||||||
val torrentExtension = Injekt.get<TorrentAddonManager>()
|
val torrentExtension = Injekt.get<TorrentAddonManager>()
|
||||||
if (!torrentExtension.isAvailable()) {
|
if (!torrentExtension.isAvailable()) {
|
||||||
toast("Torrent Extension not available")
|
toast(R.string.torrent_addon_not_available)
|
||||||
return@setSafeOnClickListener
|
return@setSafeOnClickListener
|
||||||
}
|
}
|
||||||
runBlocking {
|
runBlocking {
|
||||||
|
try {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val extension = torrentExtension.extension!!.extension
|
val extension = torrentExtension.extension!!.extension
|
||||||
torrentExtension.torrentHash?.let {
|
torrentExtension.torrentHash?.let {
|
||||||
|
@ -520,19 +543,25 @@ class SelectorDialogFragment : BottomSheetDialogFragment() {
|
||||||
extension.getLink(currentTorrent, index)
|
extension.getLink(currentTorrent, index)
|
||||||
Logger.log("Received: ${selectedVideo.file.url}")
|
Logger.log("Received: ${selectedVideo.file.url}")
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Injekt.get<CrashlyticsInterface>().logException(e)
|
||||||
|
Logger.log(e)
|
||||||
|
toast("Error starting video: ${e.message}")
|
||||||
|
return@runBlocking
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (subtitles.isNotEmpty()) {
|
if (subtitles.isNotEmpty()) {
|
||||||
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup)
|
val alertDialog = AlertDialog.Builder(context, R.style.MyPopup)
|
||||||
.setTitle("Download Subtitle")
|
.setTitle(R.string.download_subtitle)
|
||||||
.setSingleChoiceItems(
|
.setSingleChoiceItems(
|
||||||
subtitleNames.toTypedArray(),
|
subtitleNames.toTypedArray(),
|
||||||
-1
|
-1
|
||||||
) { _, which ->
|
) { _, which ->
|
||||||
subtitleToDownload = subtitles[which]
|
subtitleToDownload = subtitles[which]
|
||||||
}
|
}
|
||||||
.setPositiveButton("Download") { _, _ ->
|
.setPositiveButton(R.string.download) { _, _ ->
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
if (selectedVideo != null) {
|
if (selectedVideo != null) {
|
||||||
Helper.startAnimeDownloadService(
|
Helper.startAnimeDownloadService(
|
||||||
|
@ -546,10 +575,10 @@ class SelectorDialogFragment : BottomSheetDialogFragment() {
|
||||||
)
|
)
|
||||||
broadcastDownloadStarted(episode.number, activity)
|
broadcastDownloadStarted(episode.number, activity)
|
||||||
} else {
|
} else {
|
||||||
snackString("No Video Selected")
|
snackString(R.string.no_video_selected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.setNegativeButton("Skip") { dialog, _ ->
|
.setNegativeButton(R.string.skip) { dialog, _ ->
|
||||||
subtitleToDownload = null
|
subtitleToDownload = null
|
||||||
if (selectedVideo != null) {
|
if (selectedVideo != null) {
|
||||||
Helper.startAnimeDownloadService(
|
Helper.startAnimeDownloadService(
|
||||||
|
@ -563,11 +592,11 @@ class SelectorDialogFragment : BottomSheetDialogFragment() {
|
||||||
)
|
)
|
||||||
broadcastDownloadStarted(episode.number, activity)
|
broadcastDownloadStarted(episode.number, activity)
|
||||||
} else {
|
} else {
|
||||||
snackString("No Video Selected")
|
snackString(R.string.no_video_selected)
|
||||||
}
|
}
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
.setNeutralButton("Cancel") { dialog, _ ->
|
.setNeutralButton(R.string.cancel) { dialog, _ ->
|
||||||
subtitleToDownload = null
|
subtitleToDownload = null
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
|
@ -587,7 +616,7 @@ class SelectorDialogFragment : BottomSheetDialogFragment() {
|
||||||
)
|
)
|
||||||
broadcastDownloadStarted(episode.number, activity)
|
broadcastDownloadStarted(episode.number, activity)
|
||||||
} else {
|
} else {
|
||||||
snackString("No Video Selected")
|
snackString(R.string.no_video_selected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -975,4 +975,10 @@ Non quae tempore quo provident laudantium qui illo dolor vel quia dolor et exerc
|
||||||
<string name="hide_in_home_screen">Hide in Home Screen</string>
|
<string name="hide_in_home_screen">Hide in Home Screen</string>
|
||||||
<string name="hidden">Hidden</string>
|
<string name="hidden">Hidden</string>
|
||||||
<string name="no_hidden_items">No Hidden Items</string>
|
<string name="no_hidden_items">No Hidden Items</string>
|
||||||
|
<string name="download_addon_not_installed">Download Add-on not installed</string>
|
||||||
|
<string name="would_you_like_to_install">Would you like to install it?</string>
|
||||||
|
<string name="torrent_addon_not_available">Torrent Add-on not available</string>
|
||||||
|
<string name="download_subtitle">Download Subtitle</string>
|
||||||
|
<string name="no_video_selected">No video selected</string>
|
||||||
|
<string name="no_subtitles_available">No subtitles available</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue