diff --git a/app/src/main/java/com/lagradost/cloudstream3/plugins/RepositoryManager.kt b/app/src/main/java/com/lagradost/cloudstream3/plugins/RepositoryManager.kt index 910d847353e..675ecf03433 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/plugins/RepositoryManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/plugins/RepositoryManager.kt @@ -131,6 +131,13 @@ object RepositoryManager { suspend fun parseRepoUrl(url: String): String? { val fixedUrl = url.trim() + val githubRepoRegex = Regex("""^https?://github\.com/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/?.*$""", RegexOption.IGNORE_CASE) + val ghMatch = githubRepoRegex.find(fixedUrl) + if (ghMatch != null && !fixedUrl.endsWith(".json")) { + val (user, repoName) = ghMatch.destructured + return "https://raw.githubusercontent.com/$user/$repoName/builds/repo.json" + } + return if (fixedUrl.contains("^https?://".toRegex())) { fixedUrl } else if (fixedUrl.contains("^(cloudstreamrepo://)|(https://cs\\.repo/\\??)".toRegex())) { @@ -239,8 +246,18 @@ object RepositoryManager { } } + val LIVE_HUB_REPO = RepositoryData( + iconUrl = "https://raw.githubusercontent.com/sika200581/cloudstream-live-hub/builds/icon.png", + name = "CloudStream Live Hub (Kick/Twitch/YouTube)", + url = "https://raw.githubusercontent.com/sika200581/cloudstream-live-hub/builds/repo.json" + ) + fun getRepositories(): Array { - return getKey>(REPOSITORIES_KEY) ?: emptyArray() + val repos = getKey>(REPOSITORIES_KEY) ?: emptyArray() + if (repos.isEmpty()) { + return arrayOf(LIVE_HUB_REPO) + } + return repos } // Don't want to read before we write in another thread diff --git a/app/src/main/java/com/lagradost/cloudstream3/services/DownloadQueueService.kt b/app/src/main/java/com/lagradost/cloudstream3/services/DownloadQueueService.kt index e07747a860c..c38ee59c2a1 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/services/DownloadQueueService.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/services/DownloadQueueService.kt @@ -272,8 +272,14 @@ class DownloadQueueService : Service() { override fun onBind(intent: Intent?): IBinder? = null override fun onTimeout(reason: Int) { - stopSelf() Log.e(TAG, "Service stopped due to timeout: $reason") + isRunning = false + _downloadInstances.value.forEach { instance -> + safe { + instance.cancelDownload() + } + } + stopSelf() } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/WebviewFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/WebviewFragment.kt index 0d951bf6a7a..f5027e21041 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/WebviewFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/WebviewFragment.kt @@ -30,13 +30,27 @@ class WebviewFragment : BaseFragment( view: WebView?, request: WebResourceRequest? ): Boolean { - val requestUrl = request?.url.toString() + val requestUrl = request?.url?.toString() ?: return false val performedAction = MainActivity.handleAppIntentUrl(activity, requestUrl, true) if (performedAction) { findNavController().popBackStack() return true } + if (!requestUrl.startsWith("http://") && !requestUrl.startsWith("https://") && + !requestUrl.startsWith("about:") && !requestUrl.startsWith("javascript:")) { + return try { + val intent = android.content.Intent.parseUri(requestUrl, android.content.Intent.URI_INTENT_SCHEME) + if (activity != null && intent.resolveActivity(activity!!.packageManager) != null) { + activity?.startActivity(intent) + } + true + } catch (e: Throwable) { + com.lagradost.cloudstream3.mvvm.logError(e) + true + } + } + return super.shouldOverrideUrlLoading(view, request) } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt index a0fb3a2fe0e..236261b5c74 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt @@ -329,12 +329,16 @@ class DownloadFragment : BaseFragment( if (!preventAutoSwitching) activateSwitchOnHls(text?.toString(), binding) } - (activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager)?.primaryClip?.getItemAt( - 0 - )?.text?.toString()?.let { copy -> - val fixedText = copy.trim() - binding.streamUrl.setText(fixedText) - activateSwitchOnHls(fixedText, binding) + safe { + val clipboard = activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager + val primaryClip = clipboard?.primaryClip + if (primaryClip != null && primaryClip.itemCount > 0) { + primaryClip.getItemAt(0)?.text?.toString()?.let { copy -> + val fixedText = copy.trim() + binding.streamUrl.setText(fixedText) + activateSwitchOnHls(fixedText, binding) + } + } } binding.applyBtt.setOnClickListener { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt index 04f8b0b26ff..39993726c5b 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt @@ -285,6 +285,7 @@ class HomeFragment : BaseFragment( docs: Chip?, movies: Chip?, asian: Chip?, + shortDrama: Chip?, livestream: Chip?, torrent: Chip?, nsfw: Chip?, @@ -296,6 +297,7 @@ class HomeFragment : BaseFragment( Pair(tvs, listOf(TvType.TvSeries)), Pair(anime, listOf(TvType.Anime, TvType.OVA, TvType.AnimeMovie)), Pair(asian, listOf(TvType.AsianDrama)), + Pair(shortDrama, listOf(TvType.ShortDrama, TvType.AsianDrama)), Pair(cartoons, listOf(TvType.Cartoon)), Pair(docs, listOf(TvType.Documentary)), Pair(livestream, listOf(TvType.Live)), @@ -312,6 +314,7 @@ class HomeFragment : BaseFragment( header.homeSelectDocumentaries, header.homeSelectMovies, header.homeSelectAsian, + header.homeSelectShortDrama, header.homeSelectLivestreams, header.homeSelectTorrents, header.homeSelectNsfw, diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt index 1f721ee2062..e3468203a8f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt @@ -16,6 +16,7 @@ import com.lagradost.cloudstream3.ui.BaseAdapter import com.lagradost.cloudstream3.ui.BaseDiffCallback import com.lagradost.cloudstream3.ui.ViewHolderState import com.lagradost.cloudstream3.ui.newSharedPool +import com.lagradost.cloudstream3.ui.player.MultiPlayerManager import com.lagradost.cloudstream3.ui.result.FOCUS_SELF import com.lagradost.cloudstream3.ui.result.setLinearListLayout import com.lagradost.cloudstream3.ui.search.SearchClickCallback @@ -95,13 +96,17 @@ open class ParentItemAdapter( val binding = holder.view if (binding !is HomepageParentBinding) return val info = item.list + val sectionClickCallback: (SearchClickCallback) -> Unit = { click -> + MultiPlayerManager.setCurrentHomeSection(info.name, info.list) + clickCallback(click) + } binding.apply { val currentAdapter = homeChildRecyclerview.adapter as? HomeChildItemAdapter if (currentAdapter == null) { homeChildRecyclerview.setRecycledViewPool(HomeChildItemAdapter.sharedPool) homeChildRecyclerview.adapter = HomeChildItemAdapter( id = id + position + 100, - clickCallback = clickCallback, + clickCallback = sectionClickCallback, nextFocusUp = homeChildRecyclerview.nextFocusUpId, nextFocusDown = homeChildRecyclerview.nextFocusDownId, ).apply { @@ -113,7 +118,7 @@ open class ParentItemAdapter( currentAdapter.apply { isHorizontal = info.isHorizontalImages hasNext = item.hasNext - this.clickCallback = this@ParentItemAdapter.clickCallback + this.clickCallback = sectionClickCallback nextFocusUp = homeChildRecyclerview.nextFocusUpId nextFocusDown = homeChildRecyclerview.nextFocusDownId submitIncomparableList(item.list.list) @@ -190,4 +195,4 @@ open class ParentItemAdapter( @Suppress("DEPRECATION") inline fun Bundle.getSafeParcelable(key: String): T? = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) getParcelable(key) - else getParcelable(key, T::class.java) \ No newline at end of file + else getParcelable(key, T::class.java) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt index 730e688a2c7..1a6fe2ea40c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt @@ -209,6 +209,14 @@ class CS3IPlayer : IPlayer { override fun getPosition(): Long? = exoPlayer?.currentPosition override fun getIsPlaying(): Boolean = isPlaying override fun getPlaybackSpeed(): Float = playBackSpeed + override fun getCurrentLink(): ExtractorLink? = currentLink + override fun getExoPlayer(): ExoPlayer? = exoPlayer + override var volume: Float + get() = exoPlayer?.volume ?: 1.0f + set(value) { + val clamped = value.coerceIn(0f, 1f) + exoPlayer?.volume = clamped + } /** * Tracks reported to be used by exoplayer, since sometimes it has a mind of it's own when selecting subs. diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt index d337d53a6c9..fa2cd55fc88 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt @@ -241,6 +241,23 @@ open class FullScreenPlayer : AbstractPlayerFragment( throw NotImplementedError() } + open fun openMultiView() { + val act = activity as? androidx.appcompat.app.AppCompatActivity ?: return + val activeLink = player.getCurrentLink() + val activeTitle = playerBinding?.playerVideoTitle?.text?.toString()?.takeIf { it.isNotBlank() } ?: activeLink?.name ?: "Main Stream" + + if (activeLink != null) { + MultiPlayerManager.setMainStream(activeLink, activeTitle) + } + + player.handleEvent(CSPlayerEvent.Pause) + + act.supportFragmentManager.beginTransaction() + .replace(android.R.id.content, MultiViewPlayerFragment()) + .addToBackStack("MultiViewPlayer") + .commit() + } + open fun showTracksDialogue() { throw NotImplementedError() } @@ -1549,6 +1566,10 @@ open class FullScreenPlayer : AbstractPlayerFragment( showMirrorsDialogue() } + view?.findViewById(R.id.player_multiview_btn)?.setOnClickListener { + openMultiView() + } + playerTracksBtt.setOnClickListener { showTracksDialogue() } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index 49422f3f1e3..7c7ee50dbc1 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -1009,6 +1009,27 @@ class GeneratorPlayer : FullScreenPlayer() { } + override fun openMultiView() { + val sources = viewModel.state.links.mapNotNull { it.first } + val episodes = allMeta ?: emptyList() + MultiPlayerManager.setAvailableSourcesAndEpisodes(sources, episodes) + + // The last home row clicked is global state. Only keep it when it belongs to + // the extension that provided the item currently playing. + val currentProvider = (currentMeta as? ResultEpisode)?.apiName + ?: player.getCurrentLink()?.source + val matchingHomeStreams = currentProvider?.let { provider -> + MultiPlayerManager.currentHomeSectionStreams.filter { + it.apiName.equals(provider, ignoreCase = true) + } + }.orEmpty() + MultiPlayerManager.setCurrentHomeSection( + if (matchingHomeStreams.isEmpty()) "" else MultiPlayerManager.currentHomeSectionName.orEmpty(), + matchingHomeStreams + ) + super.openMultiView() + } + override fun showMirrorsDialogue() { try { currentSelectedSubtitles = player.getCurrentPreferredSubtitle() diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/IPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/IPlayer.kt index 0342372667f..bbe041f9a5d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/IPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/IPlayer.kt @@ -211,6 +211,9 @@ interface IPlayer { fun setPlaybackSpeed(speed: Float) fun getIsPlaying(): Boolean + var volume: Float + fun getCurrentLink(): ExtractorLink? = null + fun getExoPlayer(): androidx.media3.exoplayer.ExoPlayer? = null /** Current player duration in milliseconds */ fun getDuration(): Long? /** Current player position in milliseconds */ diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/MultiPlayerManager.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/MultiPlayerManager.kt new file mode 100644 index 00000000000..b1d610b262f --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/MultiPlayerManager.kt @@ -0,0 +1,239 @@ +package com.lagradost.cloudstream3.ui.player + +import android.content.Context +import androidx.media3.exoplayer.ExoPlayer +import androidx.media3.ui.PlayerView +import com.lagradost.cloudstream3.SearchResponse +import com.lagradost.cloudstream3.ui.result.ResultEpisode +import com.lagradost.cloudstream3.utils.ExtractorLink + +data class MultiStreamSlot( + val slotIndex: Int, + var title: String? = null, + var url: String? = null, + var isMuted: Boolean = true, + var isOffline: Boolean = false, + var isFocused: Boolean = false, + var initialLink: ExtractorLink? = null, + var player: CS3IPlayer? = null, + var playerView: PlayerView? = null, + val attemptedSourceUrls: MutableSet = mutableSetOf(), +) + +object MultiPlayerManager { + const val MAX_SLOTS = 9 + + var availableSources: List = emptyList() + var availableEpisodes: List = emptyList() + var currentHomeSectionName: String? = null + var currentHomeSectionStreams: List = emptyList() + + var currentMaxHeight: Int = 720 // Default 720p cap for multi-stream to eliminate lag + + fun setGlobalQualityCap(height: Int) { + currentMaxHeight = height + for (i in 0 until MAX_SLOTS) { + val slot = slots[i] + if (height != Int.MAX_VALUE) { + slot.player?.setMaxVideoSize(height * 16 / 9, height) + } else { + slot.player?.setMaxVideoSize(Int.MAX_VALUE, Int.MAX_VALUE) + } + } + } + + fun setAvailableSourcesAndEpisodes(sources: List, episodes: List) { + availableSources = sources + availableEpisodes = episodes + } + + fun setCurrentHomeSection(name: String, streams: List) { + currentHomeSectionName = name + currentHomeSectionStreams = streams.toList() + } + + val slots = Array(MAX_SLOTS) { slotIndex -> + MultiStreamSlot(slotIndex = slotIndex) + } + + var activeFocusSlotIndex: Int = 0 + + fun setMainStream(link: ExtractorLink, title: String) { + if (slots[0].url != link.url || slots[0].player != null) closeSlot(0) + activeFocusSlotIndex = 0 + val slot0 = slots[0] + slot0.title = title + slot0.url = link.url + slot0.isOffline = false + slot0.isMuted = false + slot0.isFocused = true + slot0.initialLink = link + slot0.attemptedSourceUrls.clear() + slot0.attemptedSourceUrls.add(link.url) + } + + fun getSlot(index: Int): MultiStreamSlot? { + if (index !in 0 until MAX_SLOTS) return null + return slots[index] + } + + private fun handleSlotStreamError(slotIndex: Int, context: Context) { + val slot = getSlot(slotIndex) ?: return + val alternativeSource = availableSources.firstOrNull { + it.url != slot.url && it.url !in slot.attemptedSourceUrls + } + if (alternativeSource != null && slot.playerView != null) { + android.util.Log.d("MultiPlayerManager", "Slot $slotIndex stream failed. Auto-switching to live extension feed: ${alternativeSource.name}") + loadStream(context, slotIndex, alternativeSource.name, alternativeSource, slot.playerView!!) + } else { + setSlotOffline(slotIndex) + } + } + + fun loadStream( + context: Context, + slotIndex: Int, + title: String, + link: ExtractorLink, + playerView: PlayerView, + autoPlay: Boolean = true + ) { + if (slotIndex !in 0 until MAX_SLOTS) return + + val slot = slots[slotIndex] + if (slot.url != link.url) slot.attemptedSourceUrls.clear() + slot.attemptedSourceUrls.add(link.url) + slot.title = title + slot.url = link.url + slot.initialLink = link + slot.isOffline = false + slot.playerView = playerView + + val player = slot.player ?: CS3IPlayer().also { slot.player = it } + player.initCallbacks( + eventHandler = { event -> + if (slot.player !== player || slot.url != link.url) return@initCallbacks + if (event is PlayerAttachedEvent) { + playerView.player = event.player as? ExoPlayer ?: player.getExoPlayer() + player.volume = if (slot.isMuted) 0f else 1f + } else if (event is ErrorEvent) { + android.util.Log.w("MultiPlayerManager", "Slot $slotIndex playback error: ${event.error}. Attempting extension feed fallback...") + handleSlotStreamError(slotIndex, context) + } else if (event is VideoEndedEvent) { + setSlotOffline(slotIndex) + } + } + ) + + playerView.player = player.getExoPlayer() + + // Only active focused slot plays audio initially + val isMuted = slotIndex != activeFocusSlotIndex + slot.isMuted = isMuted + + // Apply resolution cap to prevent lag + if (currentMaxHeight != Int.MAX_VALUE) { + player.setMaxVideoSize(currentMaxHeight * 16 / 9, currentMaxHeight) + } + + player.loadPlayer( + context = context, + sameEpisode = false, + link = link, + data = null, + startPosition = null, + subtitles = emptySet(), + subtitle = null, + autoPlay = autoPlay, + preview = false + ) + + player.volume = if (isMuted) 0f else 1f + } + + fun toggleMute(slotIndex: Int): Boolean { + val slot = getSlot(slotIndex) ?: return false + val player = slot.player ?: return false + player.handleEvent(CSPlayerEvent.ToggleMute) + slot.isMuted = !slot.isMuted + return slot.isMuted + } + + fun setVolume(slotIndex: Int, volume: Float) { + val slot = getSlot(slotIndex) ?: return + val player = slot.player ?: return + val clamped = volume.coerceIn(0f, 1f) + player.volume = clamped + slot.isMuted = clamped <= 0f + } + + fun getVolume(slotIndex: Int): Float { + val slot = getSlot(slotIndex) ?: return 0f + return slot.player?.volume ?: if (slot.isMuted) 0f else 1f + } + + fun setMuted(slotIndex: Int, mute: Boolean) { + val slot = getSlot(slotIndex) ?: return + val player = slot.player ?: return + if (slot.isMuted != mute) { + player.handleEvent(CSPlayerEvent.ToggleMute) + slot.isMuted = mute + } + } + + fun setFocusedSlot(slotIndex: Int) { + if (slotIndex !in 0 until MAX_SLOTS) return + if (slots[slotIndex].url == null || slots[slotIndex].isOffline) return + activeFocusSlotIndex = slotIndex + for (i in 0 until MAX_SLOTS) { + val slot = slots[i] + slot.isFocused = i == slotIndex + // Unmute focused stream, mute non-focused streams + setMuted(i, i != slotIndex) + } + } + + fun setSlotOffline(slotIndex: Int) { + val slot = getSlot(slotIndex) ?: return + slot.isOffline = true + slot.player?.release() + slot.playerView?.player = null + slot.player = null + if (activeFocusSlotIndex == slotIndex) { + val nextFocus = slots.firstOrNull { it.url != null && !it.isOffline } + activeFocusSlotIndex = nextFocus?.slotIndex ?: 0 + slots.forEach { it.isFocused = it.slotIndex == activeFocusSlotIndex } + slots.forEach { setMuted(it.slotIndex, it.slotIndex != activeFocusSlotIndex) } + } + } + + fun closeSlot(slotIndex: Int) { + val slot = getSlot(slotIndex) ?: return + android.util.Log.d("MultiPlayerManager", "Closing slot $slotIndex (${slot.title})") + slot.player?.release() + slot.player = null + slot.playerView?.player = null + slot.playerView = null + slot.title = null + slot.url = null + slot.isOffline = false + slot.isMuted = true + slot.isFocused = false + slot.initialLink = null + slot.attemptedSourceUrls.clear() + if (activeFocusSlotIndex == slotIndex) { + val nextFocus = slots.firstOrNull { it.slotIndex != slotIndex && it.url != null && !it.isOffline } + activeFocusSlotIndex = nextFocus?.slotIndex ?: 0 + slots.forEach { it.isFocused = it.slotIndex == activeFocusSlotIndex } + slots.forEach { setMuted(it.slotIndex, it.slotIndex != activeFocusSlotIndex) } + } + } + + fun releaseAll() { + android.util.Log.d("MultiPlayerManager", "Releasing all $MAX_SLOTS multi-stream slots") + for (i in 0 until MAX_SLOTS) { + closeSlot(i) + } + activeFocusSlotIndex = 0 + } +} diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/MultiViewPlayerFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/MultiViewPlayerFragment.kt new file mode 100644 index 00000000000..14e3ddc5dff --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/MultiViewPlayerFragment.kt @@ -0,0 +1,513 @@ +package com.lagradost.cloudstream3.ui.player + +import android.view.View +import android.widget.SeekBar +import androidx.appcompat.app.AlertDialog +import androidx.constraintlayout.widget.ConstraintSet +import androidx.core.view.isVisible +import androidx.navigation.findNavController +import com.lagradost.cloudstream3.R +import com.lagradost.cloudstream3.databinding.FragmentMultiviewPlayerBinding +import com.lagradost.cloudstream3.databinding.MultiviewStreamItemBinding +import com.lagradost.cloudstream3.ui.BaseFragment +import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setSystemBarsPadding +import com.lagradost.cloudstream3.utils.AppContextUtils.setDefaultFocus +import com.lagradost.cloudstream3.utils.UIHelper.popCurrentPage + +enum class MultiViewMode { + SPLIT_1X2, + FOCUS_1PLUS2, + GRID_2X2, + GRID_3X3 +} + +class MultiViewPlayerFragment : BaseFragment( + BaseFragment.BindingCreator.Inflate(FragmentMultiviewPlayerBinding::inflate) +) { + private var currentMode = MultiViewMode.GRID_2X2 + private var activeFocusSlotIndex = 0 + + override fun fixLayout(view: View) { + setSystemBarsPadding() + } + + override fun onBindingCreated(binding: FragmentMultiviewPlayerBinding) { + setupBottomBar(binding) + updateAllSlots(binding) + applyLayoutMode(binding) + } + + private fun setupBottomBar(binding: FragmentMultiviewPlayerBinding) { + binding.btnAddStream.setOnClickListener { + openStreamPickerForEmptySlot() + } + + binding.btnMode1x2.setOnClickListener { + currentMode = MultiViewMode.SPLIT_1X2 + updateAllSlots(binding) + applyLayoutMode(binding) + } + + binding.btnMode1plus2.setOnClickListener { + currentMode = MultiViewMode.FOCUS_1PLUS2 + updateAllSlots(binding) + applyLayoutMode(binding) + } + + binding.btnModeGrid.setOnClickListener { + currentMode = MultiViewMode.GRID_2X2 + updateAllSlots(binding) + applyLayoutMode(binding) + } + + binding.btnModeGrid3x3.setOnClickListener { + currentMode = MultiViewMode.GRID_3X3 + updateAllSlots(binding) + applyLayoutMode(binding) + } + + binding.btnModeQuality.setOnClickListener { view -> + val popup = androidx.appcompat.widget.PopupMenu(view.context, view) + popup.menu.add(0, Int.MAX_VALUE, 0, "Auto (Full Quality)") + popup.menu.add(0, 720, 1, "720p HD") + popup.menu.add(0, 480, 2, "480p SD") + popup.menu.add(0, 360, 3, "360p Low") + + popup.setOnMenuItemClickListener { menuItem -> + val height = menuItem.itemId + MultiPlayerManager.setGlobalQualityCap(height) + val label = when (height) { + 720 -> "Quality: 720p" + 480 -> "Quality: 480p" + 360 -> "Quality: 360p" + else -> "Quality: Auto" + } + binding.btnModeQuality.text = label + true + } + popup.show() + } + + binding.btnExitMultiview.setOnClickListener { + returnToSinglePlayer() + } + + binding.btnCloseAllMultiview.setOnClickListener { + android.util.Log.d("MultiViewPlayer", "Close All clicked - releasing all players and returning home") + MultiPlayerManager.releaseAll() + activity?.let { act -> + act.supportFragmentManager.popBackStack("MultiViewPlayer", androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE) + act.popCurrentPage("MultiViewPlayer") + } ?: dispatchBackPressed() + } + } + + private fun getSlotIncludeView(slotIndex: Int, binding: FragmentMultiviewPlayerBinding): View { + return when (slotIndex) { + 0 -> binding.multiviewSlot0.root + 1 -> binding.multiviewSlot1.root + 2 -> binding.multiviewSlot2.root + 3 -> binding.multiviewSlot3.root + 4 -> binding.multiviewSlot4.root + 5 -> binding.multiviewSlot5.root + 6 -> binding.multiviewSlot6.root + 7 -> binding.multiviewSlot7.root + 8 -> binding.multiviewSlot8.root + else -> binding.multiviewSlot0.root + } + } + + private fun getSlotBinding(slotIndex: Int, binding: FragmentMultiviewPlayerBinding): MultiviewStreamItemBinding { + return MultiviewStreamItemBinding.bind(getSlotIncludeView(slotIndex, binding)) + } + + private fun updateAllSlots(binding: FragmentMultiviewPlayerBinding) { + val maxVisibleSlots = when (currentMode) { + MultiViewMode.SPLIT_1X2 -> 2 + MultiViewMode.FOCUS_1PLUS2 -> 3 + MultiViewMode.GRID_2X2 -> 4 + MultiViewMode.GRID_3X3 -> 9 + } + + for (i in 0 until MultiPlayerManager.MAX_SLOTS) { + val includeView = getSlotIncludeView(i, binding) + if (i < maxVisibleSlots) { + includeView.isVisible = true + val slotBinding = getSlotBinding(i, binding) + bindSlot(i, slotBinding, binding) + } else { + includeView.isVisible = false + } + } + } + + private fun bindSlot( + slotIndex: Int, + slotBinding: MultiviewStreamItemBinding, + fragmentBinding: FragmentMultiviewPlayerBinding + ) { + val slot = MultiPlayerManager.getSlot(slotIndex) ?: return + if (slot.url != null) { + bindActiveSlot(slotIndex, slot, slotBinding, fragmentBinding) + } else { + bindEmptySlot(slotBinding) + } + } + + private fun bindActiveSlot( + slotIndex: Int, + slot: MultiStreamSlot, + slotBinding: MultiviewStreamItemBinding, + fragmentBinding: FragmentMultiviewPlayerBinding + ) { + slotBinding.apply { + if (slot.player == null && slot.initialLink != null && !slot.isOffline) { + context?.let { ctx -> + MultiPlayerManager.loadStream( + ctx, + slotIndex, + slot.title ?: "Stream ${slotIndex + 1}", + slot.initialLink!!, + multiviewPlayerView + ) + } + } + + multiviewPlayerView.isVisible = true + multiviewHeaderOverlay.isVisible = true + multiviewMuteBtn.isVisible = true + multiviewEmptySlotContainer.isVisible = false + + multiviewStreamTitle.text = slot.title ?: "Stream ${slotIndex + 1}" + + multiviewOfflineCard.isVisible = slot.isOffline + if (slot.isOffline) { + multiviewOfflineText.text = "${slot.title ?: "Stream"} is offline" + } + + setupVolumeControls(slotIndex, slotBinding) + + val onCloseClick = { + val countBefore = MultiPlayerManager.slots.count { it.url != null && !it.isOffline } + MultiPlayerManager.closeSlot(slotIndex) + updateAllSlots(fragmentBinding) + val countAfter = MultiPlayerManager.slots.count { it.url != null && !it.isOffline } + if (countBefore > 1 && countAfter == 1) { + promptSingleStreamSwitch() + } + } + multiviewCloseBtn.setOnClickListener { onCloseClick() } + multiviewOfflineCloseBtn.setOnClickListener { onCloseClick() } + + multiviewItemRoot.setOnClickListener { + activeFocusSlotIndex = slotIndex + MultiPlayerManager.setFocusedSlot(slotIndex) + updateAllSlots(fragmentBinding) + if (currentMode == MultiViewMode.FOCUS_1PLUS2) { + applyLayoutMode(fragmentBinding) + } + } + } + } + + private fun setupVolumeControls(slotIndex: Int, slotBinding: MultiviewStreamItemBinding) { + slotBinding.apply { + val currentVol = MultiPlayerManager.getVolume(slotIndex) + multiviewVolumeSlider.progress = (currentVol * 100).toInt() + + val muteIcon = when { + currentVol <= 0f -> R.drawable.ic_baseline_volume_mute_24 + currentVol < 0.5f -> R.drawable.ic_baseline_volume_down_24 + else -> R.drawable.ic_baseline_volume_up_24 + } + multiviewMuteBtn.setImageResource(muteIcon) + + multiviewVolumeContainer.setOnHoverListener { _, event -> + when (event.action) { + android.view.MotionEvent.ACTION_HOVER_ENTER, android.view.MotionEvent.ACTION_HOVER_MOVE -> { + multiviewVolumeSlider.isVisible = true + } + android.view.MotionEvent.ACTION_HOVER_EXIT -> { + if (!multiviewVolumeSlider.isPressed) { + multiviewVolumeSlider.isVisible = false + } + } + } + false + } + + multiviewMuteBtn.setOnClickListener { + multiviewVolumeSlider.isVisible = !multiviewVolumeSlider.isVisible + } + + multiviewVolumeSlider.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + if (fromUser) { + val vol = progress / 100f + MultiPlayerManager.setVolume(slotIndex, vol) + val icon = when { + vol <= 0f -> R.drawable.ic_baseline_volume_mute_24 + vol < 0.5f -> R.drawable.ic_baseline_volume_down_24 + else -> R.drawable.ic_baseline_volume_up_24 + } + multiviewMuteBtn.setImageResource(icon) + } + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) {} + override fun onStopTrackingTouch(seekBar: SeekBar?) {} + }) + } + } + + private fun bindEmptySlot(slotBinding: MultiviewStreamItemBinding) { + slotBinding.apply { + multiviewPlayerView.isVisible = false + multiviewHeaderOverlay.isVisible = false + multiviewMuteBtn.isVisible = false + multiviewOfflineCard.isVisible = false + multiviewEmptySlotContainer.isVisible = true + + multiviewSlotAddBtn.setOnClickListener { + openStreamPickerForSlot() + } + } + } + + private fun returnToSinglePlayer() { + val activeSlot = MultiPlayerManager.getSlot(MultiPlayerManager.activeFocusSlotIndex) + ?.takeIf { it.url != null && !it.isOffline } + ?: MultiPlayerManager.slots.firstOrNull { it.url != null && !it.isOffline } + val activeLink = activeSlot?.initialLink + MultiPlayerManager.releaseAll() + + activity?.let { act -> + act.supportFragmentManager.popBackStack("MultiViewPlayer", androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE) + if (activeLink != null) { + val intentData = GeneratorPlayer.newInstance( + ExtractorLinkGenerator(listOf(activeLink), emptyList()), 0 + ) + try { + act.findNavController(R.id.nav_host_fragment)?.navigate( + R.id.global_to_navigation_player, + intentData + ) + } catch (_: Throwable) { + act.popCurrentPage("MultiViewPlayer") + } + } else { + act.popCurrentPage("MultiViewPlayer") + } + } ?: dispatchBackPressed() + } + + private fun promptSingleStreamSwitch() { + android.util.Log.d("MultiViewPlayer", "Active streams dropped to 1. Prompting user.") + context?.let { ctx -> + AlertDialog.Builder(ctx, R.style.AlertDialogCustom) + .setTitle("Switch to Single Stream?") + .setMessage("Only 1 stream is active. Would you like to return to full-screen player mode?") + .setPositiveButton(R.string.yes) { _, _ -> + android.util.Log.d("MultiViewPlayer", "User clicked YES - returning to single player") + returnToSinglePlayer() + } + .setNegativeButton(R.string.no) { dialog, _ -> + android.util.Log.d("MultiViewPlayer", "User clicked NO - staying in Multi-View") + dialog.dismiss() + } + .show() + .setDefaultFocus() + } + } + + private fun openStreamPickerForEmptySlot() { + openStreamPickerForSlot() + } + + private fun openStreamPickerForSlot() { + val maxSlots = when (currentMode) { + MultiViewMode.SPLIT_1X2 -> 2 + MultiViewMode.FOCUS_1PLUS2 -> 3 + MultiViewMode.GRID_2X2 -> 4 + MultiViewMode.GRID_3X3 -> 9 + } + val emptySlots = (0 until maxSlots).filter { + MultiPlayerManager.getSlot(it)?.url == null + } + if (emptySlots.isEmpty()) return + val dialog = MultiViewStreamPickerDialog(maxCapacity = emptySlots.size) { selectedStreams -> + val binding = binding ?: return@MultiViewStreamPickerDialog + context?.let { ctx -> + val availableSlotIndices = (0 until maxSlots).filter { + MultiPlayerManager.getSlot(it)?.url == null + } + selectedStreams.zip(availableSlotIndices).forEach { (stream, emptySlotIndex) -> + val (link, title) = stream + val slotBinding = getSlotBinding(emptySlotIndex, binding) + MultiPlayerManager.loadStream(ctx, emptySlotIndex, title, link, slotBinding.multiviewPlayerView) + } + updateAllSlots(binding) + } + } + activity?.let { dialog.show(it.supportFragmentManager, "MultiViewStreamPicker") } + } + + private fun applyLayoutMode(binding: FragmentMultiviewPlayerBinding) { + when (currentMode) { + MultiViewMode.SPLIT_1X2 -> apply1x2SplitConstraints(binding) + MultiViewMode.FOCUS_1PLUS2 -> apply1Plus2Constraints(binding, activeFocusSlotIndex) + MultiViewMode.GRID_2X2 -> apply2x2GridConstraints(binding) + MultiViewMode.GRID_3X3 -> apply3x3GridConstraints(binding) + } + } + + private fun apply1x2SplitConstraints(binding: FragmentMultiviewPlayerBinding) { + val constraintSet = ConstraintSet() + constraintSet.clone(binding.multiviewViewport) + + val id0 = R.id.multiview_slot_0 + val id1 = R.id.multiview_slot_1 + + constraintSet.clear(id0) + constraintSet.clear(id1) + + // Slot 0 (Left 50%) + constraintSet.connect(id0, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP) + constraintSet.connect(id0, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM) + constraintSet.connect(id0, ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START) + constraintSet.connect(id0, ConstraintSet.END, id1, ConstraintSet.START) + + // Slot 1 (Right 50%) + constraintSet.connect(id1, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP) + constraintSet.connect(id1, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM) + constraintSet.connect(id1, ConstraintSet.START, id0, ConstraintSet.END) + constraintSet.connect(id1, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END) + + constraintSet.applyTo(binding.multiviewViewport) + } + + private fun apply1Plus2Constraints(binding: FragmentMultiviewPlayerBinding, focusSlotIndex: Int) { + val constraintSet = ConstraintSet() + constraintSet.clone(binding.multiviewViewport) + + val slots = intArrayOf( + R.id.multiview_slot_0, + R.id.multiview_slot_1, + R.id.multiview_slot_2 + ) + + val focusId = slots[focusSlotIndex.coerceIn(0, 2)] + val sideIds = slots.filterIndexed { index, _ -> index != focusSlotIndex.coerceIn(0, 2) } + + // Primary Focused Slot takes ~67% width on Left + constraintSet.clear(focusId) + constraintSet.connect(focusId, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP) + constraintSet.connect(focusId, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM) + constraintSet.connect(focusId, ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START) + constraintSet.connect(focusId, ConstraintSet.END, sideIds[0], ConstraintSet.START) + + // Top Right Small Slot + constraintSet.clear(sideIds[0]) + constraintSet.connect(sideIds[0], ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP) + constraintSet.connect(sideIds[0], ConstraintSet.BOTTOM, sideIds[1], ConstraintSet.TOP) + constraintSet.connect(sideIds[0], ConstraintSet.START, focusId, ConstraintSet.END) + constraintSet.connect(sideIds[0], ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END) + + // Bottom Right Small Slot + constraintSet.clear(sideIds[1]) + constraintSet.connect(sideIds[1], ConstraintSet.TOP, sideIds[0], ConstraintSet.BOTTOM) + constraintSet.connect(sideIds[1], ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM) + constraintSet.connect(sideIds[1], ConstraintSet.START, focusId, ConstraintSet.END) + constraintSet.connect(sideIds[1], ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END) + + constraintSet.applyTo(binding.multiviewViewport) + } + + private fun apply2x2GridConstraints(binding: FragmentMultiviewPlayerBinding) { + val constraintSet = ConstraintSet() + constraintSet.clone(binding.multiviewViewport) + + val slots = intArrayOf( + R.id.multiview_slot_0, + R.id.multiview_slot_1, + R.id.multiview_slot_2, + R.id.multiview_slot_3 + ) + + // Slot 0 (Top Left) + constraintSet.connect(slots[0], ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP) + constraintSet.connect(slots[0], ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START) + constraintSet.connect(slots[0], ConstraintSet.END, slots[1], ConstraintSet.START) + constraintSet.connect(slots[0], ConstraintSet.BOTTOM, slots[2], ConstraintSet.TOP) + + // Slot 1 (Top Right) + constraintSet.connect(slots[1], ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP) + constraintSet.connect(slots[1], ConstraintSet.START, slots[0], ConstraintSet.END) + constraintSet.connect(slots[1], ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END) + constraintSet.connect(slots[1], ConstraintSet.BOTTOM, slots[3], ConstraintSet.TOP) + + // Slot 2 (Bottom Left) + constraintSet.connect(slots[2], ConstraintSet.TOP, slots[0], ConstraintSet.BOTTOM) + constraintSet.connect(slots[2], ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START) + constraintSet.connect(slots[2], ConstraintSet.END, slots[3], ConstraintSet.START) + constraintSet.connect(slots[2], ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM) + + // Slot 3 (Bottom Right) + constraintSet.connect(slots[3], ConstraintSet.TOP, slots[1], ConstraintSet.BOTTOM) + constraintSet.connect(slots[3], ConstraintSet.START, slots[2], ConstraintSet.END) + constraintSet.connect(slots[3], ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END) + constraintSet.connect(slots[3], ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM) + + constraintSet.applyTo(binding.multiviewViewport) + } + + private fun apply3x3GridConstraints(binding: FragmentMultiviewPlayerBinding) { + val constraintSet = ConstraintSet() + constraintSet.clone(binding.multiviewViewport) + + val slots = intArrayOf( + R.id.multiview_slot_0, R.id.multiview_slot_1, R.id.multiview_slot_2, + R.id.multiview_slot_3, R.id.multiview_slot_4, R.id.multiview_slot_5, + R.id.multiview_slot_6, R.id.multiview_slot_7, R.id.multiview_slot_8 + ) + + for (r in 0..2) { + for (c in 0..2) { + val index = r * 3 + c + val id = slots[index] + constraintSet.clear(id) + + if (r == 0) { + constraintSet.connect(id, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP) + } else { + constraintSet.connect(id, ConstraintSet.TOP, slots[(r - 1) * 3 + c], ConstraintSet.BOTTOM) + } + + if (r == 2) { + constraintSet.connect(id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM) + } else { + constraintSet.connect(id, ConstraintSet.BOTTOM, slots[(r + 1) * 3 + c], ConstraintSet.TOP) + } + + if (c == 0) { + constraintSet.connect(id, ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START) + } else { + constraintSet.connect(id, ConstraintSet.START, slots[r * 3 + (c - 1)], ConstraintSet.END) + } + + if (c == 2) { + constraintSet.connect(id, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END) + } else { + constraintSet.connect(id, ConstraintSet.END, slots[r * 3 + (c + 1)], ConstraintSet.START) + } + } + } + + constraintSet.applyTo(binding.multiviewViewport) + } + + override fun onDestroyView() { + MultiPlayerManager.releaseAll() + super.onDestroyView() + } +} diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/MultiViewStreamPickerDialog.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/MultiViewStreamPickerDialog.kt new file mode 100644 index 00000000000..1abf2f1b5b9 --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/MultiViewStreamPickerDialog.kt @@ -0,0 +1,472 @@ +package com.lagradost.cloudstream3.ui.player + +import android.content.Context +import android.net.Uri +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.EditText +import android.widget.ImageView +import android.widget.TextView +import android.widget.Toast +import com.google.android.material.bottomsheet.BottomSheetBehavior +import androidx.core.view.isVisible +import androidx.core.widget.doOnTextChanged +import androidx.recyclerview.widget.GridLayoutManager +import androidx.recyclerview.widget.RecyclerView +import java.util.concurrent.atomic.AtomicInteger +import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import com.lagradost.cloudstream3.APIHolder +import com.lagradost.cloudstream3.MainAPI +import com.lagradost.cloudstream3.R +import com.lagradost.cloudstream3.SearchResponse +import com.lagradost.cloudstream3.amap +import com.lagradost.cloudstream3.ui.APIRepository +import com.lagradost.cloudstream3.utils.Coroutines.ioSafe +import com.lagradost.cloudstream3.utils.Coroutines.main +import com.lagradost.cloudstream3.utils.DataStoreHelper +import com.lagradost.cloudstream3.utils.ExtractorLink +import com.lagradost.cloudstream3.utils.ExtractorLinkType +import com.lagradost.cloudstream3.utils.ImageLoader.loadImage +import com.lagradost.cloudstream3.utils.Qualities +import com.lagradost.cloudstream3.utils.loadExtractor + +class MultiViewStreamPickerDialog( + val maxCapacity: Int = 4, + val onStreamsBatchSelected: (List>) -> Unit +) : BottomSheetDialogFragment() { + + private val selectedItems = mutableSetOf() + private var allStreams = mutableListOf() + private var filteredStreams = mutableListOf() + private val searchRequestId = AtomicInteger(0) + + // View references promoted to fields so helper methods can access them + private var slotCounter: TextView? = null + private var confirmBtn: TextView? = null + private var gridRecycler: RecyclerView? = null + private var searchInput: EditText? = null + private var chipGroup: com.google.android.material.chip.ChipGroup? = null + + private val categoryMap = mutableMapOf>() + private var currentCategoryFilter: String? = null + + override fun onStart() { + super.onStart() + dialog?.window?.setLayout( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + ) + dialog?.findViewById(com.google.android.material.R.id.design_bottom_sheet)?.let { sheet -> + sheet.layoutParams = sheet.layoutParams.apply { + height = ViewGroup.LayoutParams.MATCH_PARENT + } + BottomSheetBehavior.from(sheet).apply { + skipCollapsed = true + state = BottomSheetBehavior.STATE_EXPANDED + } + } + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val dialogView = inflater.inflate(R.layout.dialog_kick_multiview_picker, container, false) + + val closeBtn = dialogView.findViewById(R.id.kick_picker_close_btn) + val cancelBtn = dialogView.findViewById(R.id.kick_cancel_btn) + slotCounter = dialogView.findViewById(R.id.kick_slot_counter) + confirmBtn = dialogView.findViewById(R.id.kick_confirm_btn) + gridRecycler = dialogView.findViewById(R.id.kick_streams_grid) + searchInput = dialogView.findViewById(R.id.kick_search_input) + chipGroup = dialogView.findViewById(R.id.picker_category_chip_group) + + updateCounter() + closeBtn?.setOnClickListener { dismiss() } + cancelBtn?.setOnClickListener { dismiss() } + + val adapter = setupAdapter() + populateLocalStreams() + loadRemoteStreamsAsync() + setupSearchInput() + setupConfirmButton() + + return dialogView + } + + private fun updateCounter() { + val count = selectedItems.size + slotCounter?.text = "$count/$maxCapacity" + confirmBtn?.text = if (count > 0) "Confirm ($count)" else "Confirm" + } + + private fun applyFilter() { + val query = searchInput?.text?.toString()?.trim()?.lowercase() ?: "" + filteredStreams.clear() + + val categoryFiltered = if (currentCategoryFilter.isNullOrBlank() || currentCategoryFilter == "All") { + allStreams + } else { + categoryMap[currentCategoryFilter] + ?: allStreams.filter { it.apiName.equals(currentCategoryFilter, ignoreCase = true) } + } + + if (query.isBlank()) { + filteredStreams.addAll(categoryFiltered.distinctBy { it.url }) + } else { + filteredStreams.addAll(categoryFiltered.distinctBy { it.url }.filter { + it.name.lowercase().contains(query) || it.apiName.lowercase().contains(query) + }) + } + gridRecycler?.adapter?.notifyDataSetChanged() + } + + private fun updateCategoryChips() { + chipGroup?.removeAllViews() + val providerNames = APIHolder.apis.map { it.name } + val categories = mutableListOf("All") + providerNames + categoryMap.keys.toList() + categories.distinct().forEach { catName -> + val chip = com.google.android.material.chip.Chip(context).apply { + text = catName + isCheckable = true + isChecked = catName == (currentCategoryFilter ?: "All") + setOnClickListener { + currentCategoryFilter = catName + applyFilter() + } + } + chipGroup?.addView(chip) + } + } + + private fun setupAdapter(): KickStreamsAdapter { + gridRecycler?.layoutManager = GridLayoutManager(context, 3) + val adapter = KickStreamsAdapter(filteredStreams, selectedItems) { streamItem -> + if (selectedItems.contains(streamItem)) { + selectedItems.remove(streamItem) + } else { + if (selectedItems.size >= maxCapacity) { + Toast.makeText(context, "Maximum $maxCapacity streams selected", Toast.LENGTH_SHORT).show() + return@KickStreamsAdapter + } + selectedItems.add(streamItem) + } + updateCounter() + gridRecycler?.adapter?.notifyDataSetChanged() + } + gridRecycler?.adapter = adapter + return adapter + } + + // STEP 1: INSTANT LOCAL POPULATION (0ms Delay on Main Thread) + private fun populateLocalStreams() { + val localStreams = mutableListOf() + + // 1. In-memory matches from current provider (MultiPlayerManager.availableEpisodes) + MultiPlayerManager.availableEpisodes.forEach { ep -> + val title = ep.name ?: ep.headerName + @Suppress("DEPRECATION_ERROR") + val searchItem = com.lagradost.cloudstream3.LiveSearchResponse( + name = title, + url = ep.data, + apiName = ep.apiName, + type = ep.tvType, + posterUrl = ep.poster, + id = ep.id + ) + localStreams.add(searchItem) + val category = ep.headerName.takeIf { it.isNotBlank() } ?: ep.apiName + categoryMap.getOrPut(category) { mutableListOf() }.add(searchItem) + categoryMap.getOrPut(ep.apiName) { mutableListOf() }.add(searchItem) + } + + // Keep the exact list from the home section the user opened available at the top. + MultiPlayerManager.currentHomeSectionStreams.forEach { searchItem -> + localStreams.add(searchItem) + val sectionName = MultiPlayerManager.currentHomeSectionName + if (!sectionName.isNullOrBlank()) { + categoryMap.getOrPut(sectionName) { mutableListOf() }.add(searchItem) + } + } + + // 2. Alternative mirror sources + MultiPlayerManager.availableSources.forEach { sourceLink -> + @Suppress("DEPRECATION_ERROR") + val searchItem = com.lagradost.cloudstream3.LiveSearchResponse( + name = "${sourceLink.name} (${sourceLink.source})", + url = sourceLink.url, + apiName = sourceLink.source, + type = com.lagradost.cloudstream3.TvType.Live, + posterUrl = null, + id = sourceLink.url.hashCode() + ) + localStreams.add(searchItem) + categoryMap.getOrPut("Sources") { mutableListOf() }.add(searchItem) + } + + // 3. Bookmarks & Favorites + val bookmarks = DataStoreHelper.getAllBookmarkedData() + localStreams.addAll(bookmarks) + if (bookmarks.isNotEmpty()) { + categoryMap.getOrPut("Bookmarks") { mutableListOf() }.addAll(bookmarks) + } + + DataStoreHelper.getAllFavorites().forEach { fav -> + @Suppress("DEPRECATION_ERROR") + val searchItem = com.lagradost.cloudstream3.LiveSearchResponse( + name = fav.name, + url = fav.url, + apiName = fav.apiName, + type = fav.type, + posterUrl = fav.posterUrl, + id = fav.id + ) + localStreams.add(searchItem) + categoryMap.getOrPut("Favorites") { mutableListOf() }.add(searchItem) + } + + // Instantly display local streams with 0ms delay! + allStreams.clear() + allStreams.addAll(localStreams.distinctBy { it.url }) + filteredStreams.clear() + filteredStreams.addAll(allStreams) + updateCategoryChips() + gridRecycler?.adapter?.notifyDataSetChanged() + } + + // STEP 2 & 3: ASYNCHRONOUS BACKGROUND MULTI-PAGE SCRAPING & AUTO LIVE SEARCH + private fun loadRemoteStreamsAsync() { + ioSafe { + val remoteStreams = mutableListOf() + + // A. Fetch Page 1 and Page 2 for active extensions + APIHolder.apis.forEach { api -> + for (page in 1..2) { + try { + val repo = APIRepository(api) + val mainPageRes = repo.getMainPage(page) + if (mainPageRes is com.lagradost.cloudstream3.mvvm.Resource.Success) { + mainPageRes.value.filterNotNull().flatMap { it.items }.forEach { homePageList -> + val catName = homePageList.name + val list = categoryMap.getOrPut(catName) { mutableListOf() } + list.addAll(homePageList.list) + categoryMap.getOrPut(api.name) { mutableListOf() }.addAll(homePageList.list) + remoteStreams.addAll(homePageList.list) + } + } + } catch (_: Throwable) {} + } + } + + // B. Auto Live Query Execution ("live" & "vs") across all extensions + listOf("live", "vs").forEach { query -> + try { + val searchResults = APIHolder.apis.amap { api -> + val repo = APIRepository(api) + val searchRes = try { repo.search(query, 1) } catch (_: Throwable) { null } + when (searchRes) { + is com.lagradost.cloudstream3.mvvm.Resource.Success -> searchRes.value.items + else -> emptyList() + } + }.flatten() + remoteStreams.addAll(searchResults) + } catch (_: Throwable) {} + } + + if (remoteStreams.isNotEmpty()) { + main { + if (!isAdded || view == null) return@main + allStreams.addAll(remoteStreams) + allStreams = allStreams.distinctBy { it.url }.toMutableList() + updateCategoryChips() + applyFilter() + } + } + } + } + + private fun setupSearchInput() { + searchInput?.doOnTextChanged { text, _, _, _ -> + val query = text?.toString()?.trim() ?: "" + applyFilter() + + if (query.length >= 2) { + val requestId = searchRequestId.incrementAndGet() + ioSafe { + val searchResults = APIHolder.apis.amap { api -> + val repo = APIRepository(api) + val searchRes = try { repo.search(query, 1) } catch (_: Throwable) { null } + when (searchRes) { + is com.lagradost.cloudstream3.mvvm.Resource.Success -> searchRes.value.items + else -> emptyList() + } + }.flatten() + + if (searchRequestId.get() == requestId && searchResults.isNotEmpty()) { + main { + if (searchRequestId.get() != requestId) return@main + allStreams.addAll(searchResults) + allStreams = allStreams.distinctBy { it.url }.toMutableList() + applyFilter() + } + } + } + } else { + searchRequestId.incrementAndGet() + } + } + } + + // Batch Confirm Selection + private fun setupConfirmButton() { + confirmBtn?.setOnClickListener { + if (selectedItems.isEmpty()) { + dismiss() + return@setOnClickListener + } + + confirmBtn?.isEnabled = false + confirmBtn?.text = "Loading..." + val itemsToLoad = selectedItems.toList() + + ioSafe { + val batchResult = resolveSelectedItems(itemsToLoad) + main { + if (!isAdded) return@main + onStreamsBatchSelected(batchResult) + dismiss() + } + } + } + } + + private suspend fun resolveSelectedItems( + items: List + ): List> { + val batchResult = mutableListOf>() + + items.forEach { item -> + val channelName = item.name + val channelUrl = item.url + val api = APIHolder.getApiFromNameNull(item.apiName) + val extractedLinks = mutableListOf() + + if (api != null) { + try { + val repo = APIRepository(api) + repo.loadLinks(channelUrl, isCasting = false, subtitleCallback = {}, callback = { extractedLink -> + extractedLinks.add(extractedLink) + }) + } catch (t: Throwable) { + android.util.Log.e("MultiViewPicker", "Error loadLinks for ${item.name}: $t") + } + } + + if (extractedLinks.isEmpty()) { + val (resolvedUrl, _) = resolveLiveStreamUrlAndHeaders(channelUrl) + try { + loadExtractor(resolvedUrl, subtitleCallback = {}, callback = { extractedLinks.add(it) }) + } catch (_: Throwable) {} + } + + val (resolvedUrl, headers) = resolveLiveStreamUrlAndHeaders(channelUrl) + val isM3u8 = resolvedUrl.contains(".m3u8") || resolvedUrl.contains("m3u8") || + resolvedUrl.contains("playback.kick.com") || resolvedUrl.contains("twitch") + val linkType = if (isM3u8) ExtractorLinkType.M3U8 else ExtractorLinkType.VIDEO + + val selectedLink = extractedLinks.firstOrNull() ?: @Suppress("DEPRECATION_ERROR") ExtractorLink( + source = item.apiName, + name = channelName, + url = resolvedUrl, + referer = headers["Referer"] ?: "", + quality = Qualities.Unknown.value, + type = linkType, + headers = headers + ) + batchResult.add(selectedLink to channelName) + } + + return batchResult + } + + override fun onDestroyView() { + searchRequestId.incrementAndGet() + super.onDestroyView() + } + + private fun resolveLiveStreamUrlAndHeaders(url: String): Pair> { + val cleanUrl = url.trim() + + val kickRegex = Regex("""(?:https?://)?(?:www\.)?kick\.com/([a-zA-Z0-9_-]+)""", RegexOption.IGNORE_CASE) + val kickMatch = kickRegex.find(cleanUrl) + if (kickMatch != null) { + val channel = kickMatch.groupValues[1].lowercase() + if (channel != "api" && channel != "categories" && channel != "video") { + val streamUrl = "https://playback.kick.com/livestream/$channel/index.m3u8" + val headers = mapOf( + "User-Agent" to "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", + "Referer" to "https://kick.com/", + "Origin" to "https://kick.com" + ) + return streamUrl to headers + } + } + + val twitchRegex = Regex("""(?:https?://)?(?:www\.)?twitch\.tv/([a-zA-Z0-9_-]+)""", RegexOption.IGNORE_CASE) + val twitchMatch = twitchRegex.find(cleanUrl) + if (twitchMatch != null) { + val channel = twitchMatch.groupValues[1].lowercase() + val streamUrl = "https://pstream.m3u8.workers.dev/twitch/$channel" + val headers = mapOf( + "User-Agent" to "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", + "Referer" to "https://twitch.tv/", + "Origin" to "https://twitch.tv" + ) + return streamUrl to headers + } + + val defaultHeaders = mapOf( + "User-Agent" to "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" + ) + return cleanUrl to defaultHeaders + } + + private class KickStreamsAdapter( + val items: List, + val selectedSet: Set, + val onItemClick: (SearchResponse) -> Unit + ) : RecyclerView.Adapter() { + + class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + val thumbnail: ImageView = view.findViewById(R.id.kick_stream_thumbnail) + val liveBadge: TextView = view.findViewById(R.id.kick_live_badge) + val checkmark: ImageView = view.findViewById(R.id.kick_checkmark_badge) + val avatar: ImageView = view.findViewById(R.id.kick_avatar) + val streamerName: TextView = view.findViewById(R.id.kick_streamer_name) + val streamTitle: TextView = view.findViewById(R.id.kick_stream_title) + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val view = LayoutInflater.from(parent.context).inflate(R.layout.kick_stream_card_item, parent, false) + return ViewHolder(view) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val item = items[position] + val isSelected = selectedSet.contains(item) + + holder.streamerName.text = item.name + holder.streamTitle.text = item.apiName + holder.thumbnail.loadImage(item.posterUrl) + holder.avatar.loadImage(item.posterUrl) + holder.checkmark.isVisible = isSelected + + holder.itemView.setOnClickListener { onItemClick(item) } + } + + override fun getItemCount(): Int = items.size + } +} diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerView.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerView.kt index c363a29b3aa..09a6ce5d747 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerView.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerView.kt @@ -172,6 +172,7 @@ class PlayerView @JvmOverloads constructor( var currentPlayerStatus: CSPlayerLoading = CSPlayerLoading.IsBuffering var mMediaSession: MediaSession? = null private var pipReceiver: BroadcastReceiver? = null + private var pipActivity: Activity? = null /** Auto-hide */ private var autoHideToken = 0 @@ -489,9 +490,19 @@ class PlayerView @JvmOverloads constructor( gestureHelper.release() autoHideHandler.removeCallbacksAndMessages(null) + unregisterPipReceiver() + keepScreenOn(false) } + private fun unregisterPipReceiver() { + val receiver = pipReceiver ?: return + val act = pipActivity + safe { act?.unregisterReceiver(receiver) } + pipReceiver = null + pipActivity = null + } + fun onPictureInPictureModeChanged( isInPictureInPictureMode: Boolean, activity: Activity? @@ -501,6 +512,7 @@ class PlayerView @JvmOverloads constructor( if (isInPictureInPictureMode) { // Hide the full-screen UI (controls, etc.) while in picture-in-picture mode. piphide?.isVisible = false + unregisterPipReceiver() pipReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { if (ACTION_MEDIA_CONTROL != intent.action) return @@ -510,6 +522,7 @@ class PlayerView @JvmOverloads constructor( ) } } + pipActivity = activity val filter = IntentFilter().apply { addAction(ACTION_MEDIA_CONTROL) } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { activity?.registerReceiver(pipReceiver, filter, Context.RECEIVER_EXPORTED) @@ -524,10 +537,7 @@ class PlayerView @JvmOverloads constructor( // Restore the full-screen UI. piphide?.isVisible = true callbacks?.exitedPipMode() - pipReceiver?.let { - // Prevents java.lang.IllegalArgumentException: Receiver not registered - safe { activity?.unregisterReceiver(it) } - } + unregisterPipReceiver() activity?.hideSystemUI() hideKeyboard(this) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt index 5e550416477..44d248ff1a5 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt @@ -270,6 +270,7 @@ class EpisodeAdapter( episodeDescript.apply { text = item.description.html() isGone = text.isNullOrBlank() + maxLines = 4 var isExpanded = false setOnClickListener { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt index 17a698de2df..6bbd86c6b2b 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt @@ -316,6 +316,7 @@ fun LoadResponse.toResultData(repo: APIRepository): ResultData { TvType.Movie -> R.string.movies_singular TvType.Torrent -> R.string.torrent_singular TvType.AsianDrama -> R.string.asian_drama_singular + TvType.ShortDrama -> R.string.short_drama_singular TvType.Live -> R.string.live_singular TvType.Others -> R.string.other_singular TvType.NSFW -> R.string.nsfw_singular diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/search/NotificationAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/search/NotificationAdapter.kt new file mode 100644 index 00000000000..ab6d32bfbfb --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/search/NotificationAdapter.kt @@ -0,0 +1,73 @@ +package com.lagradost.cloudstream3.ui.search + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.core.view.isVisible +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.ListAdapter +import androidx.recyclerview.widget.RecyclerView +import com.lagradost.cloudstream3.R +import com.lagradost.cloudstream3.databinding.NotificationItemBinding +import com.lagradost.cloudstream3.utils.DataStoreHelper.SubscribedData +import com.lagradost.cloudstream3.utils.ImageLoader.loadImage +import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute + +class NotificationAdapter( + private val onItemClick: (SubscribedData) -> Unit, + private val onDeleteClick: (SubscribedData) -> Unit, +) : ListAdapter(SubscribedDiffCallback()) { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NotificationViewHolder { + val binding = NotificationItemBinding.inflate( + LayoutInflater.from(parent.context), + parent, + false + ) + return NotificationViewHolder(binding) + } + + override fun onBindViewHolder(holder: NotificationViewHolder, position: Int) { + holder.bind(getItem(position)) + } + + inner class NotificationViewHolder( + private val binding: NotificationItemBinding + ) : RecyclerView.ViewHolder(binding.root) { + + fun bind(item: SubscribedData) { + binding.itemPoster.loadImage(item.posterUrl, item.posterHeaders) + binding.itemTitle.text = item.name + + val context = binding.root.context + val maxEp = item.lastSeenEpisodeCount.values.filterNotNull().maxOrNull() + + if (maxEp != null && maxEp > 0) { + binding.itemBadge.isVisible = true + binding.itemSubtitle.text = "${context.getString(R.string.subscription_episode_released, maxEp)} • ${item.apiName}" + binding.itemSubtitle.setTextColor(context.colorFromAttribute(R.attr.colorPrimary)) + } else { + binding.itemBadge.isVisible = false + binding.itemSubtitle.text = "${context.getString(R.string.subscription_list_name)} • ${item.apiName}" + binding.itemSubtitle.setTextColor(context.colorFromAttribute(R.attr.grayTextColor)) + } + + binding.root.setOnClickListener { + onItemClick(item) + } + + binding.itemDelete.setOnClickListener { + onDeleteClick(item) + } + } + } + + private class SubscribedDiffCallback : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: SubscribedData, newItem: SubscribedData): Boolean { + return oldItem.id == newItem.id + } + + override fun areContentsTheSame(oldItem: SubscribedData, newItem: SubscribedData): Boolean { + return oldItem == newItem + } + } +} diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt index dd5b9771194..fa58f782123 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt @@ -24,6 +24,7 @@ import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.activity.result.contract.ActivityResultContracts import androidx.core.view.doOnLayout +import android.content.Context import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.button.MaterialButton @@ -40,6 +41,7 @@ import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.SearchResponse import com.lagradost.cloudstream3.TvType +import com.lagradost.cloudstream3.databinding.DialogNotificationsBinding import com.lagradost.cloudstream3.databinding.FragmentSearchBinding import com.lagradost.cloudstream3.databinding.HomeSelectMainpageBinding import com.lagradost.cloudstream3.mvvm.Resource @@ -67,6 +69,8 @@ import com.lagradost.cloudstream3.utils.AppContextUtils.filterProviderByPreferre import com.lagradost.cloudstream3.utils.AppContextUtils.filterSearchResultByFilmQuality import com.lagradost.cloudstream3.utils.AppContextUtils.getApiProviderLangSettings import com.lagradost.cloudstream3.utils.AppContextUtils.getApiSettings +import com.lagradost.cloudstream3.utils.AppContextUtils.loadSearchResult +import com.lagradost.cloudstream3.utils.UIHelper.navigate import com.lagradost.cloudstream3.utils.AppContextUtils.ownHide import com.lagradost.cloudstream3.utils.AppContextUtils.ownShow import com.lagradost.cloudstream3.utils.AppContextUtils.setDefaultFocus @@ -407,6 +411,12 @@ class SearchFragment : BaseFragment( } } + binding.searchNotification.setOnClickListener { searchView -> + searchView?.context?.let { ctx -> + showNotificationsDialog(ctx) + } + } + val settingsManager = context?.let { PreferenceManager.getDefaultSharedPreferences(it) } val isAdvancedSearch = settingsManager?.getBoolean("advanced_search", true) ?: true val isSearchSuggestionsEnabled = settingsManager?.getBoolean("search_suggestions_enabled", true) ?: true @@ -416,6 +426,8 @@ class SearchFragment : BaseFragment( if (!isLayout(PHONE)) { binding.searchFilter.isFocusable = true binding.searchFilter.isFocusableInTouchMode = true + binding.searchNotification.isFocusable = true + binding.searchNotification.isFocusableInTouchMode = true } // Hide suggestions when search view loses focus (phone only) @@ -701,4 +713,56 @@ class SearchFragment : BaseFragment( searchViewModel.updateHistory() } + + private fun showNotificationsDialog(ctx: Context) { + val builder = BottomSheetDialog(ctx) + builder.behavior.state = BottomSheetBehavior.STATE_EXPANDED + + val dialogBinding = DialogNotificationsBinding.inflate( + builder.layoutInflater, + null, + false + ) + builder.setContentView(dialogBinding.root) + + val subscriptions = DataStoreHelper.getAllSubscriptions().toMutableList() + + fun updateVisibility() { + val isEmpty = subscriptions.isEmpty() + dialogBinding.notificationEmptyState.isVisible = isEmpty + dialogBinding.notificationRecyclerView.isVisible = !isEmpty + } + + var adapter: NotificationAdapter? = null + adapter = NotificationAdapter( + onItemClick = { item -> + builder.dismissSafe() + activity?.loadSearchResult(item) + }, + onDeleteClick = { item -> + DataStoreHelper.removeSubscribedData(item.id) + subscriptions.remove(item) + adapter?.submitList(subscriptions.toList()) + updateVisibility() + showToast(ctx.getString(R.string.subscription_deleted, item.name)) + } + ) + + dialogBinding.notificationRecyclerView.layoutManager = LinearLayoutManager(ctx) + dialogBinding.notificationRecyclerView.adapter = adapter + adapter.submitList(subscriptions.toList()) + + updateVisibility() + + dialogBinding.notificationClose.setOnClickListener { + builder.dismissSafe() + } + + dialogBinding.notificationViewLibraryBtt.setOnClickListener { + builder.dismissSafe() + activity?.navigate(R.id.navigation_library) + } + + builder.show() + } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchViewModel.kt index f60588e35cd..d26df414a46 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchViewModel.kt @@ -26,6 +26,9 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import java.util.concurrent.ConcurrentHashMap + + data class ExpandableSearchList( var list: List, var currentPage: Int, var hasNext: Boolean, ) @@ -52,9 +55,12 @@ class SearchViewModel : ViewModel() { private var repos = apis.withLock { apis.map { APIRepository(it) } } fun clearSearch() { + synchronized(expandableSearches) { + currentSearchIndex++ + expandableSearches.clear() + } _searchResponse.postValue(Resource.Success(ExpandableSearchList(emptyList(), 0, false))) _currentSearch.postValue(emptyMap()) - expandableSearches.clear() } var lastQuery: String? = null @@ -62,7 +68,7 @@ class SearchViewModel : ViewModel() { /** Save which providers can searched again and which search result page they are on. * Maps provider name to search list. * @see [HomeViewModel.expandable] */ - private val expandableSearches: MutableMap = mutableMapOf() + private val expandableSearches: MutableMap = ConcurrentHashMap() private var currentSearchIndex = 0 private var onGoingSearch: Job? = null @@ -77,7 +83,9 @@ class SearchViewModel : ViewModel() { ignoreSettings: Boolean = false, isQuickSearch: Boolean = false, ) { - currentSearchIndex++ + synchronized(expandableSearches) { + currentSearchIndex++ + } onGoingSearch?.cancel() onGoingSearch = search(query, providersActive, ignoreSettings, isQuickSearch) } @@ -125,10 +133,12 @@ class SearchViewModel : ViewModel() { if (lock.contains(name)) return null val query = lastQuery ?: return null val repo = repos.find { it.name == name } ?: return null + val currentIndex = currentSearchIndex lock += name - expandableSearches[name]?.let { current -> + val current = synchronized(expandableSearches) { expandableSearches[name] } + if (current != null) { debugAssert({ !current.hasNext }) { "Expand called when not needed" } @@ -137,39 +147,48 @@ class SearchViewModel : ViewModel() { val next = repo.search(query, nextPage) if (next is Resource.Success) { val nextValue = next.value - expandableSearches[name]?.apply { - this.hasNext = nextValue.hasNext - this.currentPage = nextPage - - debugWarning({ nextValue.items.any { outer -> this.list.any { it.url == outer.url } } }) { - "Expanded search contained an item that was previously already in the list.\nQuery = $query, ${nextValue.items} = ${this.list}" + val snapshot = synchronized(expandableSearches) { + if (currentSearchIndex != currentIndex || lastQuery != query) { + return@synchronized null + } + val existing = expandableSearches[name] ?: return@synchronized null + val newList = (existing.list + nextValue.items).distinctBy { it.url } + expandableSearches[name] = ExpandableSearchList(newList, nextPage, nextValue.hasNext) + expandableSearches.mapValues { entry -> + entry.value.copy(list = entry.value.list.toList()) } + } - // just to be sure we are not adding the same shit for some reason - // Avoids weird behavior in the recyclerview by recreating the list - this.list = (this.list + nextValue.items).distinctBy { it.url } - } ?: debugWarning { - "Expanded an item not in search load named $name, current list is ${expandableSearches.keys}" + if (snapshot != null) { + synchronized(expandableSearches) { + if (currentSearchIndex == currentIndex && lastQuery == query) { + _searchResponse.postValue(Resource.Success(bundleSearch(snapshot))) + _currentSearch.postValue(snapshot) + } + } } } else { - current.hasNext = false + synchronized(expandableSearches) { + if (currentSearchIndex == currentIndex && lastQuery == query) { + expandableSearches[name]?.hasNext = false + } + } } - - _searchResponse.postValue(Resource.Success(bundleSearch(expandableSearches))) - _currentSearch.postValue(expandableSearches) } lock -= name - val item = expandableSearches[name] ?: return null + val item = synchronized(expandableSearches) { + expandableSearches[name]?.let { it.copy(list = it.list.toList()) } + } ?: return null return HomeViewModel.ExpandableHomepageList( - HomePageList(name, item.list), + HomePageList(name, item.list.toList()), item.currentPage, item.hasNext ) } - private fun bundleSearch(lists: MutableMap): ExpandableSearchList { + private fun bundleSearch(lists: Map): ExpandableSearchList { if (lists.size == 1) { return lists.values.first() } @@ -208,47 +227,81 @@ class SearchViewModel : ViewModel() { return@launchSafe } - if (!isQuickSearch) { - val key = query.hashCode().toString() - setKey( - "$currentAccount/$SEARCH_HISTORY_KEY", - key, - SearchHistoryItem( - searchedAt = System.currentTimeMillis(), - searchText = query, - type = emptyList(), // TODO implement tv type - key = key, - ) - ) - } - - _searchResponse.postValue(Resource.Loading()) - _currentSearch.postValue(emptyMap()) - expandableSearches.clear() + if (!isQuickSearch) saveSearchHistory(query) + resetSearchState() lastQuery = query withContext(Dispatchers.IO) { // This interrupts UI otherwise - repos.filter { a -> - (ignoreSettings || (providersActive.isEmpty() || providersActive.contains(a.name))) && (!isQuickSearch || a.hasQuickSearch) - }.amap { a -> // Parallel - val search = if (isQuickSearch) a.quickSearch(query) else a.search(query, 1) - if (currentSearchIndex != currentIndex) return@amap - if (search is Resource.Success) { - val searchValue = search.value - expandableSearches[a.name] = - ExpandableSearchList(searchValue.items, 1, searchValue.hasNext) - } + executeParallelSearch(query, providersActive, ignoreSettings, isQuickSearch, currentIndex) + postFinalSearchResult(currentIndex) + } + } - _currentSearch.postValue(expandableSearches) - } + private fun saveSearchHistory(query: String) { + val key = query.hashCode().toString() + setKey( + "$currentAccount/$SEARCH_HISTORY_KEY", + key, + SearchHistoryItem( + searchedAt = System.currentTimeMillis(), + searchText = query, + type = emptyList(), // TODO implement tv type + key = key, + ) + ) + } - if (currentSearchIndex != currentIndex) return@withContext // this should prevent rewrite of existing data bug + private fun resetSearchState() { + _searchResponse.postValue(Resource.Loading()) + _currentSearch.postValue(emptyMap()) + synchronized(expandableSearches) { expandableSearches.clear() } + } - _currentSearch.postValue(expandableSearches) - val list = bundleSearch(expandableSearches) + private suspend fun executeParallelSearch( + query: String, + providersActive: Set, + ignoreSettings: Boolean, + isQuickSearch: Boolean, + currentIndex: Int, + ) { + repos.filter { a -> + (ignoreSettings || providersActive.isEmpty() || providersActive.contains(a.name)) && + (!isQuickSearch || a.hasQuickSearch) + }.amap { a -> // Parallel + val search = if (isQuickSearch) a.quickSearch(query) else a.search(query, 1) + if (search is Resource.Success) { + val searchValue = search.value + val snapshot = synchronized(expandableSearches) { + if (currentSearchIndex != currentIndex) return@amap + expandableSearches[a.name] = + ExpandableSearchList(searchValue.items.toList(), 1, searchValue.hasNext) + expandableSearches.mapValues { entry -> + entry.value.copy(list = entry.value.list.toList()) + } + } + synchronized(expandableSearches) { + if (currentSearchIndex == currentIndex) { + _currentSearch.postValue(snapshot) + } + } + } + } + } + private fun postFinalSearchResult(currentIndex: Int) { + val finalSnapshot = synchronized(expandableSearches) { + if (currentSearchIndex != currentIndex) return + expandableSearches.mapValues { entry -> + entry.value.copy(list = entry.value.list.toList()) + } + } + synchronized(expandableSearches) { + if (currentSearchIndex == currentIndex) { + _currentSearch.postValue(finalSnapshot) + val list = bundleSearch(finalSnapshot) _searchResponse.postValue(Resource.Success(list)) } } -} + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsProvidersScreen.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsProvidersScreen.kt index 4186994c780..978a7a1083c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsProvidersScreen.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsProvidersScreen.kt @@ -32,6 +32,7 @@ object SettingsProvidersScreen : SearchableSettings { TvType.Movie -> R.string.movies_singular TvType.Torrent -> R.string.torrent_singular TvType.AsianDrama -> R.string.asian_drama_singular + TvType.ShortDrama -> R.string.short_drama_singular TvType.Live -> R.string.live_singular TvType.Others -> R.string.other_singular TvType.NSFW -> R.string.nsfw_singular diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginAdapter.kt index 2ff06cd6acb..8d2d765f4c3 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginAdapter.kt @@ -6,11 +6,15 @@ import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.viewbinding.ViewBinding import com.lagradost.cloudstream3.CloudStreamApp.Companion.getActivity +import com.lagradost.cloudstream3.PROVIDER_STATUS_BETA_ONLY import com.lagradost.cloudstream3.PROVIDER_STATUS_DOWN +import com.lagradost.cloudstream3.PROVIDER_STATUS_OK +import com.lagradost.cloudstream3.PROVIDER_STATUS_SLOW import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.TvType import com.lagradost.cloudstream3.databinding.RepositoryItemBinding @@ -24,6 +28,7 @@ import com.lagradost.cloudstream3.ui.settings.Globals.TV import com.lagradost.cloudstream3.ui.settings.Globals.isLayout import com.lagradost.cloudstream3.utils.AppContextUtils.html import com.lagradost.cloudstream3.utils.ImageLoader.loadImage +import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute import com.lagradost.cloudstream3.utils.SubtitleHelper.getNameNextToFlagEmoji import com.lagradost.cloudstream3.utils.UIHelper.toPx import com.lagradost.cloudstream3.utils.getImageFromDrawable @@ -171,23 +176,23 @@ class PluginAdapter( //val oldRecycleCount = (holder as? RepositoryViewHolderState)?.recycleCount - binding.extVotes.isVisible = false - - // Disable this for now as the vote api is down, this will also significantly improve the lag - // from doing all these network requests - /*if (!isLocal) { - ioSafe { - metadata.getVotes().main { votes -> - val currentRecycleCount = (holder as? RepositoryViewHolderState)?.recycleCount - - // Only set the text if the view is correctly rendered - if (currentRecycleCount == oldRecycleCount) { - binding.extVotes.setText(txt(R.string.extension_rating, prettyCount(votes))) - binding.extVotes.isVisible = true - } - } + val statusArray = itemView.context.resources.getStringArray(R.array.extension_statuses) + val statusInt = metadata.status + if (statusInt in statusArray.indices) { + val statusName = statusArray[statusInt] + binding.extVotes.isVisible = true + binding.extVotes.text = "• $statusName" + val statusColor = when (statusInt) { + PROVIDER_STATUS_OK -> itemView.context.colorFromAttribute(R.attr.colorPrimary) + PROVIDER_STATUS_SLOW -> ContextCompat.getColor(itemView.context, R.color.adultColor) + PROVIDER_STATUS_BETA_ONLY -> itemView.context.colorFromAttribute(R.attr.grayTextColor) + PROVIDER_STATUS_DOWN -> ContextCompat.getColor(itemView.context, R.color.adultColor) + else -> itemView.context.colorFromAttribute(R.attr.grayTextColor) } - }*/ + binding.extVotes.setTextColor(statusColor) + } else { + binding.extVotes.isVisible = false + } if (metadata.fileSize != null) { binding.extFilesize.isVisible = true diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsViewModel.kt index 09c202d43ba..f336918f134 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsViewModel.kt @@ -10,7 +10,10 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.preference.PreferenceManager import com.lagradost.cloudstream3.CommonActivity.showToast +import com.lagradost.cloudstream3.PROVIDER_STATUS_BETA_ONLY import com.lagradost.cloudstream3.PROVIDER_STATUS_DOWN +import com.lagradost.cloudstream3.PROVIDER_STATUS_OK +import com.lagradost.cloudstream3.PROVIDER_STATUS_SLOW import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.TvType import com.lagradost.cloudstream3.amap @@ -243,25 +246,61 @@ class PluginsViewModel : ViewModel() { } private fun List.sortByQuery(query: String?): List { + val selectedLangsLower = selectedLanguages.map { it.lowercase() } + + fun getHealthRankScore(item: PluginViewData): Int { + val status = item.pluginWrapper.plugin.status + var score = 0 + + // 1. Downloaded plugins get priority as user installed them + if (item.isDownloaded) { + score += 1000 + } + + // 2. Health status rank (OK > SLOW > BETA > DOWN) + score += when (status) { + PROVIDER_STATUS_OK -> 400 + PROVIDER_STATUS_SLOW -> 200 + PROVIDER_STATUS_BETA_ONLY -> 100 + PROVIDER_STATUS_DOWN -> -500 // Disabled/Down providers pushed to bottom + else -> 0 + } + + // 3. Preferred language bonus + val lang = item.pluginWrapper.plugin.language?.lowercase() + if (lang != null && selectedLangsLower.contains(lang)) { + score += 50 + } + + return score + } + return if (query.isNullOrBlank()) { - // Return list to base state if no query - this.sortedBy { it.pluginWrapper.plugin.name } + this.sortedWith( + compareByDescending { getHealthRankScore(it) } + .thenBy { it.pluginWrapper.plugin.name.lowercase() } + ) } else { - this.mapNotNull { + this.mapNotNull { item -> // Try matching name - val score = Levenshtein.partialRatio( - it.pluginWrapper.plugin.name.lowercase(), + val nameScore = Levenshtein.partialRatio( + item.pluginWrapper.plugin.name.lowercase(), query.lowercase() - ).takeIf { score -> score > 80 } ?: - // Fallback to description, but limit characters to reduce lag - it.pluginWrapper.plugin.description?.lowercase()?.take(64) - ?.let { description -> - Levenshtein.partialRatio( - description, - query.lowercase() - ) - }?.takeIf { score -> score > 80 } ?: return@mapNotNull null - it to score + ).takeIf { score -> score > 80 } + + val descScore = if (nameScore == null) { + item.pluginWrapper.plugin.description?.lowercase()?.take(64) + ?.let { description -> + Levenshtein.partialRatio( + description, + query.lowercase() + ) + }?.takeIf { score -> score > 80 } + } else null + + val searchScore = nameScore ?: descScore ?: return@mapNotNull null + val totalScore = searchScore + (getHealthRankScore(item) / 10) + item to totalScore }.sortedBy { -it.second }.map { it.first } diff --git a/app/src/main/res/drawable/multiview_cancel_button_background.xml b/app/src/main/res/drawable/multiview_cancel_button_background.xml new file mode 100644 index 00000000000..76e72f3b2e1 --- /dev/null +++ b/app/src/main/res/drawable/multiview_cancel_button_background.xml @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/app/src/main/res/drawable/multiview_confirm_button_background.xml b/app/src/main/res/drawable/multiview_confirm_button_background.xml new file mode 100644 index 00000000000..10201362e4b --- /dev/null +++ b/app/src/main/res/drawable/multiview_confirm_button_background.xml @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/app/src/main/res/layout/dialog_kick_multiview_picker.xml b/app/src/main/res/layout/dialog_kick_multiview_picker.xml new file mode 100644 index 00000000000..37c0a2a4346 --- /dev/null +++ b/app/src/main/res/layout/dialog_kick_multiview_picker.xml @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/dialog_multiview_stream_picker.xml b/app/src/main/res/layout/dialog_multiview_stream_picker.xml new file mode 100644 index 00000000000..5e971a9ba21 --- /dev/null +++ b/app/src/main/res/layout/dialog_multiview_stream_picker.xml @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/dialog_notifications.xml b/app/src/main/res/layout/dialog_notifications.xml new file mode 100644 index 00000000000..df6ba2379dc --- /dev/null +++ b/app/src/main/res/layout/dialog_notifications.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_multiview_player.xml b/app/src/main/res/layout/fragment_multiview_player.xml new file mode 100644 index 00000000000..f26d291028f --- /dev/null +++ b/app/src/main/res/layout/fragment_multiview_player.xml @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml index 408460d41d3..64973a31470 100644 --- a/app/src/main/res/layout/fragment_search.xml +++ b/app/src/main/res/layout/fragment_search.xml @@ -49,7 +49,7 @@ android:layout_width="match_parent" android:layout_height="30dp" android:layout_gravity="center_vertical" - android:layout_marginEnd="30dp"> + android:layout_marginEnd="75dp"> - - android:layout_margin="10dp" - android:background="?selectableItemBackgroundBorderless" - android:contentDescription="@string/change_providers_img_des" - android:nextFocusLeft="@id/main_search" - android:nextFocusRight="@id/main_search" - android:nextFocusUp="@id/nav_rail_view" - android:nextFocusDown="@id/search_autofit_results" - android:src="@drawable/ic_baseline_tune_24" - app:tint="?attr/textColor" /> + + + + diff --git a/app/src/main/res/layout/fragment_search_tv.xml b/app/src/main/res/layout/fragment_search_tv.xml index ed2f3b63991..887d5ea3fdb 100644 --- a/app/src/main/res/layout/fragment_search_tv.xml +++ b/app/src/main/res/layout/fragment_search_tv.xml @@ -50,7 +50,7 @@ android:layout_width="match_parent" android:layout_height="30dp" android:layout_gravity="center_vertical" - android:layout_marginEnd="30dp"> + android:layout_marginEnd="75dp"> - - android:layout_margin="10dp" - android:background="?selectableItemBackgroundBorderless" - android:contentDescription="@string/change_providers_img_des" - android:nextFocusLeft="@id/main_search" - android:nextFocusRight="@id/main_search" - android:nextFocusUp="@id/navigation_search" - android:nextFocusDown="@id/tvtypes_chips_scroll" - android:tag = "@string/tv_no_focus_tag" - android:src="@drawable/ic_baseline_tune_24" - app:tint="?attr/textColor" /> + + + + diff --git a/app/src/main/res/layout/kick_stream_card_item.xml b/app/src/main/res/layout/kick_stream_card_item.xml new file mode 100644 index 00000000000..5ac8a4dcbf5 --- /dev/null +++ b/app/src/main/res/layout/kick_stream_card_item.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/multiview_stream_item.xml b/app/src/main/res/layout/multiview_stream_item.xml new file mode 100644 index 00000000000..50310bccdca --- /dev/null +++ b/app/src/main/res/layout/multiview_stream_item.xml @@ -0,0 +1,173 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/notification_item.xml b/app/src/main/res/layout/notification_item.xml new file mode 100644 index 00000000000..e0ee605220e --- /dev/null +++ b/app/src/main/res/layout/notification_item.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/player_custom_layout.xml b/app/src/main/res/layout/player_custom_layout.xml index 9a79e6590fc..955ab4811ec 100644 --- a/app/src/main/res/layout/player_custom_layout.xml +++ b/app/src/main/res/layout/player_custom_layout.xml @@ -916,10 +916,20 @@ android:layout_height="40dp" android:nextFocusLeft="@id/player_subtitle_offset_btt" - android:nextFocusRight="@id/player_tracks_btt" + android:nextFocusRight="@id/player_multiview_btn" android:text="@string/video_source" app:icon="@drawable/ic_baseline_playlist_play_24" /> + + + Subscribed to %s Unsubscribed from %s Episode %d released! + Notifications + No notifications yet + Subscribe to shows to receive updates on new episodes. + NEW + Short Drama + Short Drama Subscribe Unsubscribe Profile %d diff --git a/gradle/gradle-daemon-jvm.properties b/gradle/gradle-daemon-jvm.properties new file mode 100644 index 00000000000..fa4ed510e60 --- /dev/null +++ b/gradle/gradle-daemon-jvm.properties @@ -0,0 +1,12 @@ +#This file is generated by updateDaemonJvm +toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect +toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect +toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect +toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect +toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c2dd35c9d0aaf0ba6ad0791320f99dfc/redirect +toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/e5810bd7fd1f8a586644409d395a7e55/redirect +toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect +toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect +toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/7b3c4877c0749019e6805bb61e421497/redirect +toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/d76df094a9cbbabd3b08251f9e61444a/redirect +toolchainVersion=25 diff --git a/library/api/jvm/library.api b/library/api/jvm/library.api index 389c8e83f32..3db90a1d4b9 100644 --- a/library/api/jvm/library.api +++ b/library/api/jvm/library.api @@ -946,6 +946,8 @@ public final class com/lagradost/cloudstream3/MainAPIKt { public static final fun newTvSeriesSearchResponse (Lcom/lagradost/cloudstream3/MainAPI;Ljava/lang/String;Ljava/lang/String;Lcom/lagradost/cloudstream3/TvType;ZLkotlin/jvm/functions/Function1;)Lcom/lagradost/cloudstream3/TvSeriesSearchResponse; public static synthetic fun newTvSeriesSearchResponse$default (Lcom/lagradost/cloudstream3/MainAPI;Ljava/lang/String;Ljava/lang/String;Lcom/lagradost/cloudstream3/TvType;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/lagradost/cloudstream3/TvSeriesSearchResponse; public static final fun sortUrls (Ljava/util/Set;)Ljava/util/List; + public static final fun splitUrlParameters (Lio/ktor/http/Url;)Ljava/util/Map; + public static final fun splitUrlParameters (Ljava/lang/String;)Ljava/util/Map; public static final fun toNewSearchResponseList (Ljava/util/List;Ljava/lang/Boolean;)Lcom/lagradost/cloudstream3/SearchResponseList; public static synthetic fun toNewSearchResponseList$default (Ljava/util/List;Ljava/lang/Boolean;ILjava/lang/Object;)Lcom/lagradost/cloudstream3/SearchResponseList; public static final fun toRatingInt (Ljava/lang/String;)Ljava/lang/Integer; @@ -1706,6 +1708,7 @@ public final class com/lagradost/cloudstream3/TvType : java/lang/Enum { public static final field OVA Lcom/lagradost/cloudstream3/TvType; public static final field Others Lcom/lagradost/cloudstream3/TvType; public static final field Podcast Lcom/lagradost/cloudstream3/TvType; + public static final field ShortDrama Lcom/lagradost/cloudstream3/TvType; public static final field Torrent Lcom/lagradost/cloudstream3/TvType; public static final field TvSeries Lcom/lagradost/cloudstream3/TvType; public static final field Video Lcom/lagradost/cloudstream3/TvType; @@ -1781,6 +1784,11 @@ public final class com/lagradost/cloudstream3/extractors/Aico : com/lagradost/cl public fun getName ()Ljava/lang/String; } +public final class com/lagradost/cloudstream3/extractors/Antarcticadocs : com/lagradost/cloudstream3/extractors/Vidara { + public fun ()V + public fun getMainUrl ()Ljava/lang/String; +} + public final class com/lagradost/cloudstream3/extractors/Asnwish : com/lagradost/cloudstream3/extractors/StreamWishExtractor { public fun ()V public fun getMainUrl ()Ljava/lang/String; @@ -2506,6 +2514,11 @@ public class com/lagradost/cloudstream3/extractors/Firestream : com/lagradost/cl public fun getUrl (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } +public final class com/lagradost/cloudstream3/extractors/FirestreamSite : com/lagradost/cloudstream3/extractors/Firestream { + public fun ()V + public fun getMainUrl ()Ljava/lang/String; +} + public final class com/lagradost/cloudstream3/extractors/FlaswishCom : com/lagradost/cloudstream3/extractors/StreamWishExtractor { public fun ()V public fun getMainUrl ()Ljava/lang/String; @@ -2961,12 +2974,25 @@ public final class com/lagradost/cloudstream3/extractors/Habetar : com/lagradost public fun getName ()Ljava/lang/String; } +public final class com/lagradost/cloudstream3/extractors/Handfacesnap : com/lagradost/cloudstream3/extractors/Vidara { + public fun ()V + public fun getMainUrl ()Ljava/lang/String; +} + public final class com/lagradost/cloudstream3/extractors/Haxloppd : com/lagradost/cloudstream3/extractors/VidHidePro { public fun ()V public fun getMainUrl ()Ljava/lang/String; public fun getName ()Ljava/lang/String; } +public final class com/lagradost/cloudstream3/extractors/Hexload : com/lagradost/cloudstream3/utils/ExtractorApi { + public fun ()V + public fun getMainUrl ()Ljava/lang/String; + public fun getName ()Ljava/lang/String; + public fun getRequiresReferer ()Z + public fun getUrl (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + public final class com/lagradost/cloudstream3/extractors/Hgcloudto : com/lagradost/cloudstream3/extractors/StreamWishExtractor { public fun ()V public fun getMainUrl ()Ljava/lang/String; @@ -3007,6 +3033,14 @@ public final class com/lagradost/cloudstream3/extractors/HubCloud : com/lagrados public fun getUrl (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } +public class com/lagradost/cloudstream3/extractors/HubuCloud : com/lagradost/cloudstream3/utils/ExtractorApi { + public fun ()V + public fun getMainUrl ()Ljava/lang/String; + public fun getName ()Ljava/lang/String; + public fun getRequiresReferer ()Z + public fun getUrl (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + public class com/lagradost/cloudstream3/extractors/Hxfile : com/lagradost/cloudstream3/utils/ExtractorApi { public fun ()V public fun getMainUrl ()Ljava/lang/String; @@ -3531,6 +3565,16 @@ public final class com/lagradost/cloudstream3/extractors/MyVidPlay : com/lagrado public fun setMainUrl (Ljava/lang/String;)V } +public final class com/lagradost/cloudstream3/extractors/Namefacesnap : com/lagradost/cloudstream3/extractors/Vidara { + public fun ()V + public fun getMainUrl ()Ljava/lang/String; +} + +public final class com/lagradost/cloudstream3/extractors/Nameitweb : com/lagradost/cloudstream3/extractors/Vidara { + public fun ()V + public fun getMainUrl ()Ljava/lang/String; +} + public final class com/lagradost/cloudstream3/extractors/NathanFromSubject : com/lagradost/cloudstream3/extractors/Voe { public fun ()V public fun getMainUrl ()Ljava/lang/String; @@ -3605,6 +3649,11 @@ public final class com/lagradost/cloudstream3/extractors/Odnoklassniki$OkRuVideo public final fun serializer ()Lkotlinx/serialization/KSerializer; } +public final class com/lagradost/cloudstream3/extractors/Odysseusa : com/lagradost/cloudstream3/extractors/Vidara { + public fun ()V + public fun getMainUrl ()Ljava/lang/String; +} + public class com/lagradost/cloudstream3/extractors/OkRuHTTP : com/lagradost/cloudstream3/extractors/Odnoklassniki { public fun ()V public fun getMainUrl ()Ljava/lang/String; @@ -3982,6 +4031,14 @@ public final class com/lagradost/cloudstream3/extractors/Playerwish : com/lagrad public fun getName ()Ljava/lang/String; } +public final class com/lagradost/cloudstream3/extractors/Playmate : com/lagradost/cloudstream3/utils/ExtractorApi { + public fun ()V + public fun getMainUrl ()Ljava/lang/String; + public fun getName ()Ljava/lang/String; + public fun getRequiresReferer ()Z + public fun getUrl (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + public final class com/lagradost/cloudstream3/extractors/Playmogo : com/lagradost/cloudstream3/extractors/DoodLaExtractor { public fun ()V public fun getMainUrl ()Ljava/lang/String; @@ -4982,6 +5039,11 @@ public final class com/lagradost/cloudstream3/extractors/Techinmind : com/lagrad public fun getRequiresReferer ()Z } +public final class com/lagradost/cloudstream3/extractors/Thebesthostertv : com/lagradost/cloudstream3/extractors/Vidara { + public fun ()V + public fun getMainUrl ()Ljava/lang/String; +} + public final class com/lagradost/cloudstream3/extractors/Tubeless : com/lagradost/cloudstream3/extractors/Voe { public fun ()V public fun getMainUrl ()Ljava/lang/String; @@ -5139,6 +5201,11 @@ public class com/lagradost/cloudstream3/extractors/Vicloud : com/lagradost/cloud public fun getUrl (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } +public final class com/lagradost/cloudstream3/extractors/VidChampions : com/lagradost/cloudstream3/extractors/Vidara { + public fun ()V + public fun getMainUrl ()Ljava/lang/String; +} + public final class com/lagradost/cloudstream3/extractors/VidHideHub : com/lagradost/cloudstream3/extractors/VidHidePro { public fun ()V public fun getMainUrl ()Ljava/lang/String; @@ -5408,6 +5475,11 @@ public class com/lagradost/cloudstream3/extractors/VidhideExtractor : com/lagrad public fun setName (Ljava/lang/String;)V } +public final class com/lagradost/cloudstream3/extractors/Vidmatrixa : com/lagradost/cloudstream3/extractors/Vidara { + public fun ()V + public fun getMainUrl ()Ljava/lang/String; +} + public class com/lagradost/cloudstream3/extractors/Vidmoly : com/lagradost/cloudstream3/utils/ExtractorApi { public fun ()V public fun getMainUrl ()Ljava/lang/String; @@ -5457,6 +5529,15 @@ public class com/lagradost/cloudstream3/extractors/Vids : com/lagradost/cloudstr public fun getUrl (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } +public class com/lagradost/cloudstream3/extractors/Vidsonic : com/lagradost/cloudstream3/utils/ExtractorApi { + public fun ()V + public fun extractEncodedVideoUrl (Lcom/lagradost/nicehttp/NiceResponse;)Ljava/lang/String; + public fun getMainUrl ()Ljava/lang/String; + public fun getName ()Ljava/lang/String; + public fun getRequiresReferer ()Z + public fun getUrl (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + public final class com/lagradost/cloudstream3/extractors/VinovoSi : com/lagradost/cloudstream3/extractors/VinovoTo { public fun ()V public fun getMainUrl ()Ljava/lang/String; @@ -5473,6 +5554,7 @@ public class com/lagradost/cloudstream3/extractors/VinovoTo : com/lagradost/clou public class com/lagradost/cloudstream3/extractors/Vixeo : com/lagradost/cloudstream3/extractors/Vidsonic { public fun ()V + public fun extractEncodedVideoUrl (Lcom/lagradost/nicehttp/NiceResponse;)Ljava/lang/String; public fun getMainUrl ()Ljava/lang/String; public fun getName ()Ljava/lang/String; } @@ -8072,6 +8154,8 @@ public class com/lagradost/cloudstream3/utils/AtomicList : java/util/List, kotli public fun add (Ljava/lang/Object;)Z public fun addAll (ILjava/util/Collection;)Z public fun addAll (Ljava/util/Collection;)Z + public fun addFirst (Ljava/lang/Object;)V + public fun addLast (Ljava/lang/Object;)V public fun clear ()V public fun contains (Ljava/lang/Object;)Z public fun containsAll (Ljava/util/Collection;)Z @@ -8090,6 +8174,8 @@ public class com/lagradost/cloudstream3/utils/AtomicList : java/util/List, kotli public fun remove (I)Ljava/lang/Object; public fun remove (Ljava/lang/Object;)Z public fun removeAll (Ljava/util/Collection;)Z + public fun removeFirst ()Ljava/lang/Object; + public fun removeLast ()Ljava/lang/Object; public fun replaceAll (Ljava/util/function/UnaryOperator;)V public fun retainAll (Ljava/util/Collection;)Z public fun set (ILjava/lang/Object;)Ljava/lang/Object; @@ -8197,22 +8283,27 @@ public abstract class com/lagradost/cloudstream3/utils/ExtractorApi { public final class com/lagradost/cloudstream3/utils/ExtractorApiKt { public static final fun fixUrl (Lcom/lagradost/cloudstream3/utils/ExtractorApi;Ljava/lang/String;)Ljava/lang/String; public static final fun getAndUnpack (Ljava/lang/String;)Ljava/lang/String; + public static final fun getCLEARKEY_DRM_UUID ()Lkotlin/uuid/Uuid; public static final fun getCLEARKEY_UUID ()Ljava/util/UUID; public static final fun getExtractorApiFromName (Ljava/lang/String;)Lcom/lagradost/cloudstream3/utils/ExtractorApi; public static final fun getExtractorApis ()Lcom/lagradost/cloudstream3/utils/AtomicMutableList; public static final fun getINFER_TYPE ()Lcom/lagradost/cloudstream3/utils/ExtractorLinkType; + public static final fun getPLAYREADY_DRM_UUID ()Lkotlin/uuid/Uuid; public static final fun getPLAYREADY_UUID ()Ljava/util/UUID; public static final fun getPacked (Ljava/lang/String;)Ljava/lang/String; public static final fun getPostForm (Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun getQualityFromName (Ljava/lang/String;)I public static final fun getSchemaStripRegex ()Lkotlin/text/Regex; + public static final fun getWIDEVINE_DRM_UUID ()Lkotlin/uuid/Uuid; public static final fun getWIDEVINE_UUID ()Ljava/util/UUID; public static final fun httpsify (Ljava/lang/String;)Ljava/lang/String; public static final fun loadExtractor (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun loadExtractor (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun loadExtractor$default (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public static final fun newDrmExtractorLink (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/lagradost/cloudstream3/utils/ExtractorLinkType;Ljava/util/UUID;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun newDrmExtractorLink (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/lagradost/cloudstream3/utils/ExtractorLinkType;Lkotlin/uuid/Uuid;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun newDrmExtractorLink$default (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/lagradost/cloudstream3/utils/ExtractorLinkType;Ljava/util/UUID;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun newDrmExtractorLink$default (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/lagradost/cloudstream3/utils/ExtractorLinkType;Lkotlin/uuid/Uuid;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public static final fun newExtractorLink (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/lagradost/cloudstream3/utils/ExtractorLinkType;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun newExtractorLink$default (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/lagradost/cloudstream3/utils/ExtractorLinkType;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public static final fun requireReferer (Ljava/lang/String;)Z @@ -8968,11 +9059,44 @@ public final class com/lagradost/cloudstream3/utils/SubtitleHelperPlatform_jvmKt public static final fun localizedLanguageName (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; } +public final class com/lagradost/cloudstream3/utils/serializers/FloatAsIntSerializer : kotlinx/serialization/KSerializer { + public static final field INSTANCE Lcom/lagradost/cloudstream3/utils/serializers/FloatAsIntSerializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Integer; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;I)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V +} + +public final class com/lagradost/cloudstream3/utils/serializers/FloatAsLongSerializer : kotlinx/serialization/KSerializer { + public static final field INSTANCE Lcom/lagradost/cloudstream3/utils/serializers/FloatAsLongSerializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Long; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;J)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V +} + +public abstract class com/lagradost/cloudstream3/utils/serializers/JsonTransformSerializer : kotlinx/serialization/json/JsonTransformingSerializer { + public fun (Lkotlinx/serialization/KSerializer;Ljava/util/Set;Ljava/util/Set;Ljava/util/Set;)V + public synthetic fun (Lkotlinx/serialization/KSerializer;Ljava/util/Set;Ljava/util/Set;Ljava/util/Set;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + protected fun transformDeserialize (Lkotlinx/serialization/json/JsonElement;)Lkotlinx/serialization/json/JsonElement; +} + public abstract class com/lagradost/cloudstream3/utils/serializers/NonEmptySerializer : kotlinx/serialization/json/JsonTransformingSerializer { public fun (Lkotlinx/serialization/KSerializer;)V protected fun transformSerialize (Lkotlinx/serialization/json/JsonElement;)Lkotlinx/serialization/json/JsonElement; } +public final class com/lagradost/cloudstream3/utils/serializers/NullableStringSerializer : kotlinx/serialization/KSerializer { + public static final field INSTANCE Lcom/lagradost/cloudstream3/utils/serializers/NullableStringSerializer; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/String; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/String;)V +} + public abstract class com/lagradost/cloudstream3/utils/serializers/WriteOnlySerializer : kotlinx/serialization/json/JsonTransformingSerializer { public fun (Lkotlinx/serialization/KSerializer;Ljava/util/Set;)V protected fun transformSerialize (Lkotlinx/serialization/json/JsonElement;)Lkotlinx/serialization/json/JsonElement; diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/MainAPI.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/MainAPI.kt index c5935b766c8..b8314311f21 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/MainAPI.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/MainAPI.kt @@ -1137,6 +1137,7 @@ enum class TvType(value: Int?) { Audio(16), Podcast(17), Video(18), + ShortDrama(19), } enum class AutoDownloadMode(val value: Int) { @@ -2165,7 +2166,8 @@ fun TvType?.isEpisodeBased(): Boolean { TvType.Anime, TvType.AsianDrama, TvType.Cartoon, - TvType.TvSeries -> true + TvType.TvSeries, + TvType.ShortDrama -> true else -> false } @@ -2202,6 +2204,7 @@ fun TvType.getFolderPrefix(): String { TvType.Torrent -> "Torrents" TvType.TvSeries -> "TVSeries" TvType.Video -> "Videos" + TvType.ShortDrama -> "ShortDramas" } } diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 6bca3488e24..35b9d81e7f6 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -45,9 +45,10 @@ kotlin { implementation(libs.ktor.client.android) } - appleMain.dependencies { - implementation(libs.ktor.client.darwin) - } + // appleMain is unused as there are currently no Apple targets configured in shared or library + // appleMain.dependencies { + // implementation(libs.ktor.client.darwin) + // } jvmMain.dependencies { implementation(libs.ktor.client.java)