more chromecast stuff

This commit is contained in:
LagradOst 2021-06-10 21:43:05 +02:00
parent c7d3209736
commit 47e3876e4a
10 changed files with 66 additions and 24 deletions

View file

@ -67,6 +67,9 @@ fun MainAPI.fixUrl(url: String): String {
return url
}
fun sortUrls(urls: List<ExtractorLink>): List<ExtractorLink> {
return urls.sortedBy { t -> -t.quality }
}
data class Link(
val name: String,

View file

@ -164,7 +164,8 @@ object UIHelper {
// Enables regular immersive mode.
// For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
// Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
@ -254,9 +255,10 @@ object UIHelper {
// Shows the system bars by removing all the flags
// except for the ones that make the content appear under the system bars.
fun Activity.showSystemUI() {
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
) // or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
// window.clearFlags(View.KEEP_SCREEN_ON)
}
}

View file

@ -855,7 +855,9 @@ class PlayerFragment : Fragment() {
val speedsNumbers = arrayOf(0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f)
val builder = AlertDialog.Builder(requireContext(), R.style.AlertDialogCustom)
builder.setTitle("Pick playback speed")
builder.setOnDismissListener {
activity?.hideSystemUI()
}
builder.setSingleChoiceItems(speedsText, speedsNumbers.indexOf(playbackSpeed)) { _, which ->
//val speed = speedsText[which]
@ -868,6 +870,7 @@ class PlayerFragment : Fragment() {
player_speed_text.text = "Speed (${playbackSpeed}x)".replace(".0x", "x")
dialog.dismiss()
activity?.hideSystemUI()
}
dialog = builder.create()
dialog.show()
@ -880,6 +883,9 @@ class PlayerFragment : Fragment() {
val sourcesText = sources.map { it.name }
val builder = AlertDialog.Builder(requireContext(), R.style.AlertDialogCustom)
builder.setTitle("Pick source")
builder.setOnDismissListener {
activity?.hideSystemUI()
}
builder.setSingleChoiceItems(sourcesText.toTypedArray(),
sources.indexOf(getCurrentUrl())) { _, which ->
//val speed = speedsText[which]
@ -888,6 +894,7 @@ class PlayerFragment : Fragment() {
initPlayer(getCurrentUrl())
dialog.dismiss()
activity?.hideSystemUI()
}
dialog = builder.create()
dialog.show()
@ -948,10 +955,6 @@ class PlayerFragment : Fragment() {
}
}
private fun sortUrls(urls: List<ExtractorLink>): List<ExtractorLink> {
return urls.sortedBy { t -> -t.quality }
}
private fun getEpisode(): ResultEpisode? {
return try {
episodes[playerData.episodeIndex]

View file

@ -82,7 +82,7 @@ class EpisodeAdapter(
episodeHolder.setOnClickListener {
if (activity.isCastApiAvailable()) {
val castContext = CastContext.getSharedInstance(activity)
println("SSTATE: " + castContext.castState + "<<")
if (castContext.castState == CastState.CONNECTED) {
clickCallback.invoke(EpisodeClickEvent(ACTION_CHROME_CAST_EPISODE, card))
} else {

View file

@ -33,10 +33,6 @@ import com.google.android.gms.cast.framework.CastContext
import com.google.android.gms.cast.framework.CastState
import com.google.android.gms.common.images.WebImage
import com.google.android.material.button.MaterialButton
import com.lagradost.cloudstream3.AnimeLoadResponse
import com.lagradost.cloudstream3.LoadResponse
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.ShowStatus
import com.lagradost.cloudstream3.UIHelper.fixPaddingStatusbar
import com.lagradost.cloudstream3.UIHelper.isCastApiAvailable
import com.lagradost.cloudstream3.mvvm.Resource
@ -48,6 +44,7 @@ import jp.wasabeef.glide.transformations.BlurTransformation
import kotlinx.android.synthetic.main.fragment_result.*
import org.json.JSONObject
import android.app.ProgressDialog
import com.lagradost.cloudstream3.*
const val MAX_SYNO_LENGH = 300
@ -150,20 +147,25 @@ class ResultFragment : Fragment() {
val buildInPlayer = true
when (episodeClick.action) {
ACTION_CHROME_CAST_EPISODE -> {
val dialog = ProgressDialog.show(requireContext(), "",
"Loading. Please wait...", true)
dialog.show()
/*
val builder = AlertDialog.Builder(requireContext(), R.style.AlertDialogCustom)
val customLayout = layoutInflater.inflate(R.layout.dialog_loading, null);
builder.setView(customLayout)
val dialog = builder.create()*/
//dialog.show()
Toast.makeText(activity, "Loading links", Toast.LENGTH_SHORT).show()
viewModel.loadEpisode(episodeClick.data, true) { data ->
dialog.dismiss()
// dialog.dismiss()
when (data) {
is Resource.Failure -> {
Toast.makeText(activity, "Failed to load links", Toast.LENGTH_SHORT).show()
}
is Resource.Success -> {
val epData = episodeClick.data
val links = data.value
val links = sortUrls(data.value)
val castContext = CastContext.getSharedInstance(requireContext())

View file

@ -19,6 +19,8 @@ fun ExtractorLink.getId() : Int {
return url.hashCode()
}
enum class Qualities(var value: Int) {
Unknown(0),
SD(-1), // 360p - 480p

View file

@ -2,6 +2,6 @@
<inset xmlns:android="http://schemas.android.com/apk/res/android">
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="@color/darkBackground" />
<solid android:color="?attr/bitDarkerGrayBackground" />
</shape>
</inset>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/grayBackground"/>
<solid android:color="?attr/grayBackground"/>
<corners android:topLeftRadius="16dp"
android:topRightRadius="16dp"/>

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Loading..." android:textColor="?attr/textColor" android:textSize="20sp"
android:textStyle="bold" android:layout_margin="10dp"/>
<androidx.core.widget.ContentLoadingProgressBar
android:layout_margin="10dp"
style="@android:style/Widget.Material.ProgressBar.Horizontal"
android:indeterminate="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/result_root"
@ -213,14 +213,28 @@
/>
<androidx.recyclerview.widget.RecyclerView
android:layout_marginTop="10dp"
android:paddingBottom="100dp"
tools:listitem="@layout/result_episode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/result_episodes"
/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<LinearLayout android:layout_gravity="bottom" android:layout_width="match_parent"
android:layout_height="wrap_content">
<fragment
app:castControlButtons="@array/cast_mini_controller_control_buttons"
android:id="@+id/cast_mini_controller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
class="com.google.android.gms.cast.framework.media.widget.MiniControllerFragment"
tools:ignore="FragmentTagUsage">
</fragment>
</LinearLayout>
<!--
<androidx.cardview.widget.CardView
android:layout_width="100dp"
@ -240,4 +254,4 @@
android:contentDescription="@string/search_poster_descript"/>
</androidx.cardview.widget.CardView>-->
</FrameLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>