fixed provider, fixed toast stacking, updated quality API for better sorting

This commit is contained in:
LagradOst 2021-08-25 00:19:15 +02:00
parent 0967fe7600
commit efa95ddbe6
17 changed files with 165 additions and 143 deletions

View file

@ -51,16 +51,12 @@
<receiver <receiver
android:name=".receivers.VideoDownloadRestartReceiver" android:name=".receivers.VideoDownloadRestartReceiver"
android:enabled="true" android:enabled="false"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="restart_service" /> <action android:name="restart_service" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<service
android:name=".services.VideoDownloadKeepAliveService"
android:enabled="false" >
</service>
<service <service
android:name=".services.VideoDownloadService" android:name=".services.VideoDownloadService"
android:enabled="true" android:enabled="true"

View file

@ -1,13 +1,18 @@
package com.lagradost.cloudstream3 package com.lagradost.cloudstream3
import android.app.Activity
import android.app.PictureInPictureParams import android.app.PictureInPictureParams
import android.content.ComponentName import android.content.ComponentName
import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.WindowManager import android.view.*
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavOptions import androidx.navigation.NavOptions
import androidx.navigation.findNavController import androidx.navigation.findNavController
@ -15,11 +20,6 @@ import androidx.navigation.fragment.NavHostFragment
import com.google.android.gms.cast.framework.CastButtonFactory import com.google.android.gms.cast.framework.CastButtonFactory
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
import com.lagradost.cloudstream3.APIHolder.apis import com.lagradost.cloudstream3.APIHolder.apis
import com.lagradost.cloudstream3.utils.UIHelper.checkWrite
import com.lagradost.cloudstream3.utils.UIHelper.getResourceColor
import com.lagradost.cloudstream3.utils.UIHelper.hasPIPPermission
import com.lagradost.cloudstream3.utils.UIHelper.requestRW
import com.lagradost.cloudstream3.utils.UIHelper.shouldShowPIPMode
import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO
import com.lagradost.cloudstream3.ui.download.DownloadChildFragment import com.lagradost.cloudstream3.ui.download.DownloadChildFragment
@ -33,10 +33,17 @@ import com.lagradost.cloudstream3.utils.DataStore.removeKey
import com.lagradost.cloudstream3.utils.DataStoreHelper.setViewPos import com.lagradost.cloudstream3.utils.DataStoreHelper.setViewPos
import com.lagradost.cloudstream3.utils.Event import com.lagradost.cloudstream3.utils.Event
import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate
import com.lagradost.cloudstream3.utils.UIHelper.checkWrite
import com.lagradost.cloudstream3.utils.UIHelper.getResourceColor
import com.lagradost.cloudstream3.utils.UIHelper.hasPIPPermission
import com.lagradost.cloudstream3.utils.UIHelper.requestRW
import com.lagradost.cloudstream3.utils.UIHelper.shouldShowPIPMode
import com.lagradost.cloudstream3.utils.UIHelper.toPx
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_result.* import kotlinx.android.synthetic.main.fragment_result.*
import kotlin.concurrent.thread import kotlin.concurrent.thread
const val VLC_PACKAGE = "org.videolan.vlc" const val VLC_PACKAGE = "org.videolan.vlc"
const val VLC_INTENT_ACTION_RESULT = "org.videolan.vlc.player.result" const val VLC_INTENT_ACTION_RESULT = "org.videolan.vlc.player.result"
val VLC_COMPONENT: ComponentName = val VLC_COMPONENT: ComponentName =
@ -67,6 +74,41 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
val onColorSelectedEvent = Event<Pair<Int, Int>>() val onColorSelectedEvent = Event<Pair<Int, Int>>()
val onDialogDismissedEvent = Event<Int>() val onDialogDismissedEvent = Event<Int>()
lateinit var navOptions: NavOptions lateinit var navOptions: NavOptions
var currentToast: Toast? = null
fun showToast(act: Activity?, @StringRes message: Int, duration: Int) {
if (act == null) return
showToast(act, act.getString(message), duration)
}
fun showToast(act: Activity?, message: String, duration: Int) {
if (act == null) return
try {
currentToast?.cancel()
} catch (e: Exception) {
e.printStackTrace()
}
try {
val inflater = act.getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater
val layout: View = inflater.inflate(
R.layout.toast,
act.findViewById<View>(R.id.toast_layout_root) as ViewGroup?
)
val text = layout.findViewById(R.id.text) as TextView
text.text = message.trim()
val toast = Toast(act)
toast.setGravity(Gravity.CENTER_HORIZONTAL or Gravity.BOTTOM, 0, 5.toPx)
toast.duration = duration
toast.view = layout
toast.show()
currentToast = toast
} catch (e: Exception) {
}
}
} }
private fun enterPIPMode() { private fun enterPIPMode() {

View file

@ -2,7 +2,8 @@ package com.lagradost.cloudstream3.animeproviders
import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.getQualityFromName import com.lagradost.cloudstream3.utils.Qualities
import com.lagradost.cloudstream3.utils.extractorApis
import org.jsoup.Jsoup import org.jsoup.Jsoup
import java.util.* import java.util.*
@ -65,14 +66,15 @@ class AnimeFlickProvider : MainAPI() {
val title = doc.selectFirst("h2.title").text() val title = doc.selectFirst("h2.title").text()
val yearText = doc.selectFirst(".trending-year")?.text() val yearText = doc.selectFirst(".trending-year")?.text()
val year = if(yearText != null) Regex("""(\d{4})""").find(yearText)?.destructured?.component1()?.toIntOrNull() else null val year = if (yearText != null) Regex("""(\d{4})""").find(yearText)?.destructured?.component1()
?.toIntOrNull() else null
val description = doc.selectFirst("p").text() val description = doc.selectFirst("p").text()
val genres = doc.select("a[href*=\"genre-\"]").map { it.text() } val genres = doc.select("a[href*=\"genre-\"]").map { it.text() }
val episodes = doc.select("#collapseOne .block-space > .row > div:nth-child(2)").map { val episodes = doc.select("#collapseOne .block-space > .row > div:nth-child(2)").map {
val name = it.selectFirst("a").text() val name = it.selectFirst("a").text()
val link = mainUrl + it.selectFirst("a").attr("href") val link = mainUrl + it.selectFirst("a").attr("href")
AnimeEpisode(link, name) AnimeEpisode(link, name)
}.reversed() }.reversed()
@ -102,19 +104,33 @@ class AnimeFlickProvider : MainAPI() {
val html = khttp.get(data).text val html = khttp.get(data).text
val episodeRegex = Regex("""(https://.*?\.mp4)""") val episodeRegex = Regex("""(https://.*?\.mp4)""")
episodeRegex.findAll(html).map { val links = episodeRegex.findAll(html).map {
it.value it.value
}.toList().forEach { }.toList()
callback( for (link in links) {
ExtractorLink( var alreadyAdded = false
"Animeflick", for (extractor in extractorApis) {
"Animeflick - Auto", if (link.startsWith(extractor.mainUrl)) {
it, extractor.getSafeUrl(link, data)?.forEach {
"", callback(it)
getQualityFromName("1080") }
alreadyAdded = true
break
}
}
if (!alreadyAdded) {
callback(
ExtractorLink(
this.name,
"${this.name} - Auto",
link,
"",
Qualities.P1080.value
)
) )
) }
} }
return true return true
} }
} }

View file

@ -5,9 +5,6 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import android.util.Log import android.util.Log
import com.lagradost.cloudstream3.services.RESTART_ALL_DOWNLOADS_AND_QUEUE
import com.lagradost.cloudstream3.services.START_VALUE_KEY
import com.lagradost.cloudstream3.services.VideoDownloadKeepAliveService
class VideoDownloadRestartReceiver : BroadcastReceiver() { class VideoDownloadRestartReceiver : BroadcastReceiver() {

View file

@ -1,54 +0,0 @@
package com.lagradost.cloudstream3.services
import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.util.Log
import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver
import com.lagradost.cloudstream3.utils.DataStore.getKey
import com.lagradost.cloudstream3.utils.DataStore.getKeys
import com.lagradost.cloudstream3.utils.VideoDownloadManager
const val RESTART_ALL_DOWNLOADS_AND_QUEUE = 1
const val RESTART_NONE = 0
const val START_VALUE_KEY = "start_value"
class VideoDownloadKeepAliveService : Service() {
override fun onBind(p0: Intent?): IBinder? {
return null
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val startValue = intent?.getIntExtra(START_VALUE_KEY, RESTART_NONE) ?: RESTART_NONE
Log.i("Service", "Restarted with start value of $startValue")
if (startValue == RESTART_ALL_DOWNLOADS_AND_QUEUE) {
val keys = this.getKeys(VideoDownloadManager.KEY_RESUME_PACKAGES)
val resumePkg = keys.mapNotNull { k -> this.getKey<VideoDownloadManager.DownloadResumePackage>(k) }
for (pkg in resumePkg) { // ADD ALL CURRENT DOWNLOADS
VideoDownloadManager.downloadFromResume(this, pkg)
}
// ADD QUEUE
val resumeQueue =
this.getKey<List<VideoDownloadManager.DownloadQueueResumePackage>>(VideoDownloadManager.KEY_RESUME_QUEUE_PACKAGES)
if (resumeQueue != null && resumeQueue.isNotEmpty()) {
val sorted = resumeQueue.sortedBy { item -> item.index }
for (queueItem in sorted) {
VideoDownloadManager.downloadFromResume(this, queueItem.pkg)
}
}
}
return START_STICKY//super.onStartCommand(intent, flags, startId)
}
override fun onDestroy() {
val broadcastIntent = Intent()
broadcastIntent.action = "restart_service"
broadcastIntent.setClass(this, VideoDownloadRestartReceiver::class.java)
this.sendBroadcast(broadcastIntent)
super.onDestroy()
}
}

View file

@ -57,6 +57,7 @@ import com.google.android.material.button.MaterialButton
import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.MainActivity.Companion.canEnterPipMode import com.lagradost.cloudstream3.MainActivity.Companion.canEnterPipMode
import com.lagradost.cloudstream3.MainActivity.Companion.isInPIPMode import com.lagradost.cloudstream3.MainActivity.Companion.isInPIPMode
import com.lagradost.cloudstream3.MainActivity.Companion.showToast
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.mvvm.Resource import com.lagradost.cloudstream3.mvvm.Resource
import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.mvvm.observe
@ -1242,7 +1243,8 @@ class PlayerFragment : Fragment() {
} }
} }
val startIndexFromMap = currentSubtitles.map { it.removeSuffix(" ") }.indexOf(preferredSubtitles.removeSuffix(" ")) + 1 val startIndexFromMap =
currentSubtitles.map { it.removeSuffix(" ") }.indexOf(preferredSubtitles.removeSuffix(" ")) + 1
var subtitleIndex = startIndexFromMap var subtitleIndex = startIndexFromMap
if (currentSubtitles.isEmpty()) { if (currentSubtitles.isEmpty()) {
@ -1805,33 +1807,30 @@ class PlayerFragment : Fragment() {
when (error.type) { when (error.type) {
ExoPlaybackException.TYPE_SOURCE -> { ExoPlaybackException.TYPE_SOURCE -> {
if (currentUrl?.url != "") { if (currentUrl?.url != "") {
Toast.makeText( showToast(
activity, activity,
"Source error\n" + error.sourceException.message, "Source error\n" + error.sourceException.message,
LENGTH_SHORT LENGTH_SHORT
) )
.show()
tryNextMirror() tryNextMirror()
} }
} }
ExoPlaybackException.TYPE_REMOTE -> { ExoPlaybackException.TYPE_REMOTE -> {
Toast.makeText(activity, "Remote error", LENGTH_SHORT) showToast(activity, "Remote error", LENGTH_SHORT)
.show()
} }
ExoPlaybackException.TYPE_RENDERER -> { ExoPlaybackException.TYPE_RENDERER -> {
Toast.makeText( showToast(
activity, activity,
"Renderer error\n" + error.rendererException.message, "Renderer error\n" + error.rendererException.message,
LENGTH_SHORT LENGTH_SHORT
) )
.show()
} }
ExoPlaybackException.TYPE_UNEXPECTED -> { ExoPlaybackException.TYPE_UNEXPECTED -> {
Toast.makeText( showToast(
activity, activity,
"Unexpected player error\n" + error.unexpectedException.message, "Unexpected player error\n" + error.unexpectedException.message,
LENGTH_SHORT LENGTH_SHORT
).show() )
} }
} }
} }
@ -1840,8 +1839,8 @@ class PlayerFragment : Fragment() {
println("Warning: Illegal state exception in PlayerFragment") println("Warning: Illegal state exception in PlayerFragment")
} finally { } finally {
setPreferredSubLanguage( setPreferredSubLanguage(
if(isDownloadedFile) { if (isDownloadedFile) {
if(activeSubtitles.isNotEmpty()) { if (activeSubtitles.isNotEmpty()) {
activeSubtitles.first() activeSubtitles.first()
} else null } else null
} else { } else {
@ -1877,9 +1876,7 @@ class PlayerFragment : Fragment() {
initPlayer(getCurrentUrl()) initPlayer(getCurrentUrl())
} }
} else { } else {
context?.let { ctx -> showToast(activity, "No Links Found", LENGTH_SHORT)
Toast.makeText(ctx, "No Links Found", LENGTH_SHORT).show()
}
} }
} }
} }

View file

@ -39,6 +39,7 @@ const val ACTION_COPY_LINK = 9
const val ACTION_SHOW_OPTIONS = 10 const val ACTION_SHOW_OPTIONS = 10
const val ACTION_CLICK_DEFAULT = 11 const val ACTION_CLICK_DEFAULT = 11
const val ACTION_SHOW_TOAST = 12
data class EpisodeClickEvent(val action: Int, val data: ResultEpisode) data class EpisodeClickEvent(val action: Int, val data: ResultEpisode)
@ -173,7 +174,7 @@ class EpisodeAdapter(
} }
episodePoster?.setOnLongClickListener { episodePoster?.setOnLongClickListener {
Toast.makeText(it.context, R.string.play_episode_toast, Toast.LENGTH_SHORT).show() clickCallback.invoke(EpisodeClickEvent(ACTION_SHOW_TOAST, card))
return@setOnLongClickListener true return@setOnLongClickListener true
} }

View file

@ -31,25 +31,16 @@ import com.google.android.material.button.MaterialButton
import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.APIHolder.getApiFromName import com.lagradost.cloudstream3.APIHolder.getApiFromName
import com.lagradost.cloudstream3.APIHolder.getId import com.lagradost.cloudstream3.APIHolder.getId
import com.lagradost.cloudstream3.utils.UIHelper.checkWrite import com.lagradost.cloudstream3.MainActivity.Companion.showToast
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
import com.lagradost.cloudstream3.utils.UIHelper.getStatusBarHeight
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
import com.lagradost.cloudstream3.utils.UIHelper.popCurrentPage
import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIcons
import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIconsAndNoStringRes
import com.lagradost.cloudstream3.utils.UIHelper.requestRW
import com.lagradost.cloudstream3.mvvm.Resource import com.lagradost.cloudstream3.mvvm.Resource
import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.mvvm.observe
import com.lagradost.cloudstream3.ui.WatchType import com.lagradost.cloudstream3.ui.WatchType
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO
import com.lagradost.cloudstream3.ui.download.EasyDownloadButton
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
import com.lagradost.cloudstream3.ui.download.EasyDownloadButton
import com.lagradost.cloudstream3.ui.player.PlayerData import com.lagradost.cloudstream3.ui.player.PlayerData
import com.lagradost.cloudstream3.ui.player.PlayerFragment import com.lagradost.cloudstream3.ui.player.PlayerFragment
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.getDownloadSubsLanguageISO639_1 import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.getDownloadSubsLanguageISO639_1
import com.lagradost.cloudstream3.utils.* import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.utils.AppUtils.isAppInstalled import com.lagradost.cloudstream3.utils.AppUtils.isAppInstalled
@ -60,16 +51,22 @@ import com.lagradost.cloudstream3.utils.Coroutines.main
import com.lagradost.cloudstream3.utils.DataStore.getFolderName import com.lagradost.cloudstream3.utils.DataStore.getFolderName
import com.lagradost.cloudstream3.utils.DataStore.setKey import com.lagradost.cloudstream3.utils.DataStore.setKey
import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
import com.lagradost.cloudstream3.utils.UIHelper.checkWrite
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
import com.lagradost.cloudstream3.utils.UIHelper.getStatusBarHeight
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
import com.lagradost.cloudstream3.utils.UIHelper.popCurrentPage
import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIcons
import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIconsAndNoStringRes
import com.lagradost.cloudstream3.utils.UIHelper.requestRW
import com.lagradost.cloudstream3.utils.UIHelper.setImage import com.lagradost.cloudstream3.utils.UIHelper.setImage
import com.lagradost.cloudstream3.utils.VideoDownloadManager.sanitizeFilename import com.lagradost.cloudstream3.utils.VideoDownloadManager.sanitizeFilename
import kotlinx.android.synthetic.main.fragment_result.* import kotlinx.android.synthetic.main.fragment_result.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.io.File import java.io.File
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
const val MAX_SYNO_LENGH = 300 const val MAX_SYNO_LENGH = 300
@ -278,7 +275,7 @@ class ResultFragment : Fragment() {
media_route_button?.alpha = if (chromecastSupport) 1f else 0.3f media_route_button?.alpha = if (chromecastSupport) 1f else 0.3f
if (!chromecastSupport) { if (!chromecastSupport) {
media_route_button.setOnClickListener { media_route_button.setOnClickListener {
Toast.makeText(it.context, "This provider has no chromecast support", Toast.LENGTH_LONG).show() showToast(activity, "This provider has no chromecast support", Toast.LENGTH_LONG)
} }
} }
@ -369,7 +366,11 @@ class ResultFragment : Fragment() {
return true return true
} }
is Resource.Failure -> { is Resource.Failure -> {
Toast.makeText(requireContext(), R.string.error_loading_links, Toast.LENGTH_SHORT).show() showToast(
activity,
R.string.error_loading_links,
Toast.LENGTH_SHORT
)
} }
else -> { else -> {
@ -476,7 +477,7 @@ class ResultFragment : Fragment() {
// DOWNLOAD VIDEO // DOWNLOAD VIDEO
VideoDownloadManager.downloadEpisode( VideoDownloadManager.downloadEpisode(
ctx, activity,
src,//url ?: return, src,//url ?: return,
folder, folder,
meta, meta,
@ -525,6 +526,10 @@ class ResultFragment : Fragment() {
if (!isLoaded) return@main // CANT LOAD if (!isLoaded) return@main // CANT LOAD
when (episodeClick.action) { when (episodeClick.action) {
ACTION_SHOW_TOAST -> {
showToast(activity, R.string.play_episode_toast, Toast.LENGTH_SHORT)
}
ACTION_CLICK_DEFAULT -> { ACTION_CLICK_DEFAULT -> {
context?.let { ctx -> context?.let { ctx ->
if (ctx.isConnectedToChromecast()) { if (ctx.isConnectedToChromecast()) {
@ -584,7 +589,7 @@ class ResultFragment : Fragment() {
?: return@acquireSingeExtractorLink ?: return@acquireSingeExtractorLink
val clip = ClipData.newPlainText(link.name, link.url) val clip = ClipData.newPlainText(link.name, link.url)
serviceClipboard.setPrimaryClip(clip) serviceClipboard.setPrimaryClip(clip)
Toast.makeText(requireContext(), "Text Copied", Toast.LENGTH_SHORT).show() showToast(activity, "Link copied to clipboard", Toast.LENGTH_SHORT)
} }
} }
@ -1012,7 +1017,7 @@ class ResultFragment : Fragment() {
} }
} }
is Resource.Failure -> { is Resource.Failure -> {
result_error_text.text = data.errorString result_error_text.text = url?.plus("\n") + data.errorString
updateVisStatus(1) updateVisStatus(1)
} }
is Resource.Loading -> { is Resource.Loading -> {

View file

@ -2,6 +2,7 @@ package com.lagradost.cloudstream3.ui.search
import android.app.Activity import android.app.Activity
import android.widget.Toast import android.widget.Toast
import com.lagradost.cloudstream3.MainActivity.Companion.showToast
import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult
object SearchHelper { object SearchHelper {
@ -12,9 +13,7 @@ object SearchHelper {
activity.loadSearchResult(card) activity.loadSearchResult(card)
} }
SEARCH_ACTION_SHOW_METADATA -> { SEARCH_ACTION_SHOW_METADATA -> {
activity?.let { act -> showToast(activity, callback.card.name, Toast.LENGTH_SHORT)
Toast.makeText(act, callback.card.name, Toast.LENGTH_SHORT).show()
}
} }
} }
} }

View file

@ -4,6 +4,7 @@ import android.os.Bundle
import android.widget.Toast import android.widget.Toast
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import com.lagradost.cloudstream3.MainActivity.Companion.showToast
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment
import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate
@ -19,7 +20,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
thread { thread {
if (!requireActivity().runAutoUpdate(false)) { if (!requireActivity().runAutoUpdate(false)) {
activity?.runOnUiThread { activity?.runOnUiThread {
Toast.makeText(this.context, "No Update Found", Toast.LENGTH_SHORT).show() showToast(activity, "No Update Found", Toast.LENGTH_SHORT)
} }
} }
} }

View file

@ -21,6 +21,7 @@ import com.google.android.exoplayer2.text.Cue
import com.google.android.exoplayer2.ui.CaptionStyleCompat import com.google.android.exoplayer2.ui.CaptionStyleCompat
import com.jaredrummler.android.colorpicker.ColorPickerDialog import com.jaredrummler.android.colorpicker.ColorPickerDialog
import com.lagradost.cloudstream3.MainActivity import com.lagradost.cloudstream3.MainActivity
import com.lagradost.cloudstream3.MainActivity.Companion.showToast
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.getKey
import com.lagradost.cloudstream3.utils.DataStore.setKey import com.lagradost.cloudstream3.utils.DataStore.setKey
@ -207,7 +208,7 @@ class SubtitlesFragment : Fragment() {
this.setOnLongClickListener { this.setOnLongClickListener {
it.context.setColor(id, null) it.context.setColor(id, null)
Toast.makeText(it.context, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT).show() showToast(activity, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT)
return@setOnLongClickListener true return@setOnLongClickListener true
} }
} }
@ -248,7 +249,7 @@ class SubtitlesFragment : Fragment() {
subs_subtitle_elevation.setOnLongClickListener { subs_subtitle_elevation.setOnLongClickListener {
state.elevation = 0 state.elevation = 0
it.context.updateState() it.context.updateState()
Toast.makeText(it.context, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT).show() showToast(activity, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT)
return@setOnLongClickListener true return@setOnLongClickListener true
} }
@ -276,7 +277,7 @@ class SubtitlesFragment : Fragment() {
subs_edge_type.setOnLongClickListener { subs_edge_type.setOnLongClickListener {
state.edgeType = CaptionStyleCompat.EDGE_TYPE_OUTLINE state.edgeType = CaptionStyleCompat.EDGE_TYPE_OUTLINE
it.context.updateState() it.context.updateState()
Toast.makeText(it.context, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT).show() showToast(activity, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT)
return@setOnLongClickListener true return@setOnLongClickListener true
} }
@ -312,7 +313,7 @@ class SubtitlesFragment : Fragment() {
subs_font.setOnLongClickListener { textView -> subs_font.setOnLongClickListener { textView ->
state.typeface = null state.typeface = null
textView.context.updateState() textView.context.updateState()
Toast.makeText(textView.context, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT).show() showToast(activity, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT)
return@setOnLongClickListener true return@setOnLongClickListener true
} }
@ -336,7 +337,7 @@ class SubtitlesFragment : Fragment() {
subs_auto_select_language.setOnLongClickListener { textView -> subs_auto_select_language.setOnLongClickListener { textView ->
textView.context.setKey(SUBTITLE_AUTO_SELECT_KEY, "en") textView.context.setKey(SUBTITLE_AUTO_SELECT_KEY, "en")
Toast.makeText(textView.context, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT).show() showToast(activity, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT)
return@setOnLongClickListener true return@setOnLongClickListener true
} }
@ -359,7 +360,7 @@ class SubtitlesFragment : Fragment() {
subs_download_languages.setOnLongClickListener { textView -> subs_download_languages.setOnLongClickListener { textView ->
textView.context.setKey(SUBTITLE_DOWNLOAD_KEY, listOf("en")) textView.context.setKey(SUBTITLE_DOWNLOAD_KEY, listOf("en"))
Toast.makeText(textView.context, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT).show() showToast(activity, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT)
return@setOnLongClickListener true return@setOnLongClickListener true
} }

View file

@ -15,8 +15,8 @@ import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.readValue import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.BuildConfig import com.lagradost.cloudstream3.BuildConfig
import com.lagradost.cloudstream3.MainActivity.Companion.showToast
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate
import java.io.* import java.io.*
import java.net.URL import java.net.URL
import java.net.URLConnection import java.net.URLConnection
@ -178,7 +178,7 @@ class InAppUpdater {
} catch (e: Exception) { } catch (e: Exception) {
println(e) println(e)
runOnUiThread { runOnUiThread {
Toast.makeText(this, "Permission error", Toast.LENGTH_SHORT).show() showToast(this, "Permission error", Toast.LENGTH_SHORT)
} }
return false return false
} }
@ -291,14 +291,14 @@ class InAppUpdater {
val context = this val context = this
builder.apply { builder.apply {
setPositiveButton("Update") { _, _ -> setPositiveButton("Update") { _, _ ->
Toast.makeText(context, "Download started", Toast.LENGTH_LONG).show() showToast(context, "Download started", Toast.LENGTH_LONG)
thread { thread {
val downloadStatus = context.downloadUpdate(update.updateURL) val downloadStatus = context.downloadUpdate(update.updateURL)
if (!downloadStatus) { if (!downloadStatus) {
runOnUiThread { runOnUiThread {
Toast.makeText(context, showToast(context,
"Download Failed", "Download Failed",
Toast.LENGTH_LONG).show() Toast.LENGTH_LONG)
} }
} /*else { } /*else {
activity.runOnUiThread { activity.runOnUiThread {

View file

@ -1,9 +1,6 @@
package com.lagradost.cloudstream3.utils package com.lagradost.cloudstream3.utils
import android.app.ActivityManager import android.app.*
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.* import android.content.*
import android.graphics.Bitmap import android.graphics.Bitmap
import android.net.Uri import android.net.Uri
@ -19,6 +16,7 @@ import androidx.core.app.NotificationManagerCompat
import androidx.core.net.toUri import androidx.core.net.toUri
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.lagradost.cloudstream3.MainActivity import com.lagradost.cloudstream3.MainActivity
import com.lagradost.cloudstream3.MainActivity.Companion.showToast
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
@ -908,15 +906,15 @@ object VideoDownloadManager {
return context.getKey(KEY_RESUME_PACKAGES, id.toString()) return context.getKey(KEY_RESUME_PACKAGES, id.toString())
} }
fun downloadFromResume(context: Context, pkg: DownloadResumePackage, setKey: Boolean = true) { fun downloadFromResume(context: Activity, pkg: DownloadResumePackage, setKey: Boolean = true) {
if (!currentDownloads.any { it == pkg.item.ep.id }) { if (!currentDownloads.any { it == pkg.item.ep.id }) {
if (currentDownloads.size == maxConcurrentDownloads) { if (currentDownloads.size == maxConcurrentDownloads) {
main { main {
Toast.makeText( showToast( // can be replaced with regular Toast
context, context,
"${pkg.item.ep.mainName}${pkg.item.ep.episode?.let { " Episode $it " } ?: " "}queued", "${pkg.item.ep.mainName}${pkg.item.ep.episode?.let { " Episode $it " } ?: " "}queued",
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() )
} }
} }
downloadQueue.addLast(pkg) downloadQueue.addLast(pkg)
@ -947,12 +945,13 @@ object VideoDownloadManager {
} }
fun downloadEpisode( fun downloadEpisode(
context: Context, context: Activity?,
source: String?, source: String?,
folder: String?, folder: String?,
ep: DownloadEpisodeMetadata, ep: DownloadEpisodeMetadata,
links: List<ExtractorLink> links: List<ExtractorLink>
) { ) {
if(context == null) return
val validLinks = links.filter { !it.isM3u8 } val validLinks = links.filter { !it.isM3u8 }
if (validLinks.isNotEmpty()) { if (validLinks.isNotEmpty()) {
downloadFromResume(context, DownloadResumePackage(DownloadItem(source, folder, ep, validLinks), null)) downloadFromResume(context, DownloadResumePackage(DownloadItem(source, folder, ep, validLinks), null))

View file

@ -49,7 +49,6 @@
android:id="@+id/overlay_loading_skip_button" android:id="@+id/overlay_loading_skip_button"
android:text="@string/skip_loading" android:text="@string/skip_loading"
app:rippleColor="?attr/colorPrimary" app:rippleColor="?attr/colorPrimary"
android:textColor="?attr/textColor" android:textColor="?attr/textColor"
app:iconTint="?attr/textColor" app:iconTint="?attr/textColor"

View file

@ -389,10 +389,13 @@
</TextView> </TextView>
</LinearLayout> </LinearLayout>
<LinearLayout android:orientation="horizontal" android:gravity="center_vertical" <LinearLayout
android:layout_width="match_parent" android:layout_height="wrap_content"> android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:visibility="visible" android:visibility="gone"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:id="@+id/result_season_button" android:id="@+id/result_season_button"
tools:text="Season 1" tools:text="Season 1"
@ -409,7 +412,7 @@
android:layout_height="50dp"> android:layout_height="50dp">
</com.google.android.material.button.MaterialButton> </com.google.android.material.button.MaterialButton>
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:visibility="visible" android:visibility="gone"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:id="@+id/result_episode_select" android:id="@+id/result_episode_select"
tools:text="50-100" tools:text="50-100"

View file

@ -0,0 +1,19 @@
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toast_layout_root"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
app:cardCornerRadius="10dp"
android:background="?attr/bitDarkerGrayBackground">
<TextView
android:padding="20dp"
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="?attr/textColor"/>
</androidx.cardview.widget.CardView>

View file

@ -7,6 +7,7 @@
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@drawable/splash_background</item> <item name="android:windowBackground">@drawable/splash_background</item>
<item name="android:navigationBarColor">?attr/bitDarkerGrayBackground</item> <item name="android:navigationBarColor">?attr/bitDarkerGrayBackground</item>
<item name="android:colorEdgeEffect">?attr/textColor</item>
<!--<item name="android:navigationBarColor">@color/darkBackground</item>--> <!--<item name="android:navigationBarColor">@color/darkBackground</item>-->
<item name="android:statusBarColor">@color/grayBackground</item> <item name="android:statusBarColor">@color/grayBackground</item>