This commit is contained in:
LagradOst 2021-06-17 17:39:01 +02:00
parent 2fbdd058f4
commit 850be93a8b
4 changed files with 259 additions and 193 deletions

View file

@ -157,8 +157,14 @@ interface LoadResponse {
val plot: String?
}
fun LoadResponse.isEpisodeBased(): Boolean {
return this is AnimeLoadResponse || this is TvSeriesLoadResponse
fun LoadResponse?.isEpisodeBased(): Boolean {
if (this == null) return false
return (this is AnimeLoadResponse || this is TvSeriesLoadResponse) && (this.type == TvType.TvSeries || this.type == TvType.Anime)
}
fun LoadResponse?.isAnimeBased(): Boolean {
if (this == null) return false
return (this.type == TvType.Anime || this.type == TvType.ONA) // && (this is AnimeLoadResponse)
}
data class AnimeLoadResponse(
@ -198,7 +204,7 @@ data class MovieLoadResponse(
val imdbId: Int?,
) : LoadResponse
data class TvSeriesEpisode(val name: String?, val season : Int?, val episode: Int?, val data : String)
data class TvSeriesEpisode(val name: String?, val season: Int?, val episode: Int?, val data: String)
data class TvSeriesLoadResponse(
override val name: String,

View file

@ -483,6 +483,10 @@ class PlayerFragment : Fragment() {
}
}
private fun View.setVis(visible: Boolean) {
this.visibility = if (visible) VISIBLE else GONE
}
@SuppressLint("SetTextI18n")
fun changeSkip(position: Long? = null) {
val data = localData
@ -502,17 +506,20 @@ class PlayerFragment : Fragment() {
}
}
val nextEp = percentage >= OPENING_PROCENTAGE
val isAnime =
data.isAnimeBased()//(data is AnimeLoadResponse && (data.type == TvType.Anime || data.type == TvType.ONA))
skip_op_text.text = if (nextEp) "Next Episode" else "Skip OP"
val isVis =
if (nextEp) hasNext //&& !isCurrentlySkippingEp
else (data is AnimeLoadResponse && (data.type == TvType.Anime || data.type == TvType.ONA))
skip_op.visibility = if (isVis) View.VISIBLE else View.GONE
skip_op.setVis(isAnime && !nextEp)
skip_episode.setVis((!isAnime || nextEp) && hasNext)
} else {
if (data is AnimeLoadResponse) {
val isVis = ((data.type == TvType.Anime || data.type == TvType.ONA))
skip_op_text.text = "Skip OP"
skip_op.visibility = if (isVis) View.VISIBLE else View.GONE
val isAnime = data.isAnimeBased()
if (isAnime) {
skip_op.setVis(true)
skip_episode.setVis(false)
} else {
skip_episode.setVis(data.isEpisodeBased())
skip_op.setVis(false)
}
}
}
@ -530,9 +537,23 @@ class PlayerFragment : Fragment() {
private var hasUsedFirstRender = false
private fun savePositionInPlayer() {
if (this::exoPlayer.isInitialized) {
isPlayerPlaying = exoPlayer.playWhenReady
playbackPosition = exoPlayer.currentPosition
currentWindow = exoPlayer.currentWindowIndex
}
}
private fun safeReleasePlayer() {
if (this::exoPlayer.isInitialized) {
exoPlayer.release()
}
isCurrentlyPlaying = false
}
private fun releasePlayer() {
savePos()
isCurrentlyPlaying = false
val alphaAnimation = AlphaAnimation(0f, 1f)
alphaAnimation.duration = 100
alphaAnimation.fillAfter = true
@ -540,12 +561,8 @@ class PlayerFragment : Fragment() {
overlay_loading_skip_button?.visibility = VISIBLE
loading_overlay?.startAnimation(alphaAnimation)
if (this::exoPlayer.isInitialized) {
isPlayerPlaying = exoPlayer.playWhenReady
playbackPosition = exoPlayer.currentPosition
currentWindow = exoPlayer.currentWindowIndex
exoPlayer.release()
}
savePositionInPlayer()
safeReleasePlayer()
}
private class SettingsContentObserver(handler: Handler?, val activity: Activity) : ContentObserver(handler) {
@ -615,6 +632,7 @@ class PlayerFragment : Fragment() {
//next_episode_btt.isClickable = isClick
playback_speed_btt.isClickable = isClick
skip_op.isClickable = isClick
skip_episode.isClickable = isClick
resize_player.isClickable = isClick
exo_progress.isEnabled = isClick
player_media_route_button.isEnabled = isClick
@ -815,7 +833,7 @@ class PlayerFragment : Fragment() {
MediaStatus.REPEAT_MODE_REPEAT_SINGLE
)*/
// activity?.popCurrentPage(isInPlayer = true, isInExpandedView = false, isInResults = false)
releasePlayer()
safeReleasePlayer()
activity?.popCurrentPage()
}
}
@ -980,10 +998,7 @@ class PlayerFragment : Fragment() {
video_title.startAnimation(fadeAnimation)
// BOTTOM
resize_player.startAnimation(fadeAnimation)
playback_speed_btt.startAnimation(fadeAnimation)
sources_btt.startAnimation(fadeAnimation)
skip_op.startAnimation(fadeAnimation)
lock_holder.startAnimation(fadeAnimation)
video_go_back_holder2.startAnimation(fadeAnimation)
updateLock()
@ -1075,7 +1090,7 @@ class PlayerFragment : Fragment() {
sources.indexOf(getCurrentUrl())) { _, which ->
//val speed = speedsText[which]
//Toast.makeText(requireContext(), "$speed selected.", Toast.LENGTH_SHORT).show()
playbackPosition = if(this::exoPlayer.isInitialized) exoPlayer.currentPosition else 0
playbackPosition = if (this::exoPlayer.isInitialized) exoPlayer.currentPosition else 0
setMirrorId(sources[which].getId())
initPlayer(getCurrentUrl())
@ -1103,13 +1118,12 @@ class PlayerFragment : Fragment() {
}
skip_op.setOnClickListener {
if (exoPlayer.currentPosition * 100 / exoPlayer.duration >= OPENING_PROCENTAGE) {
if (hasNextEpisode()) {
// skip_op.visibility = View.GONE
skipToNextEpisode()
}
} else {
skipOP()
skipOP()
}
skip_episode.setOnClickListener {
if (hasNextEpisode()) {
skipToNextEpisode()
}
}
@ -1177,7 +1191,8 @@ class PlayerFragment : Fragment() {
private fun skipToNextEpisode() {
if (isCurrentlySkippingEp) return
releasePlayer()
savePos()
safeReleasePlayer()
isCurrentlySkippingEp = true
val copy = playerData.copy(episodeIndex = playerData.episodeIndex + 1)
playerData = copy
@ -1224,7 +1239,10 @@ class PlayerFragment : Fragment() {
super.onDestroy()
isInPlayer = false
releasePlayer()
savePos()
savePositionInPlayer()
safeReleasePlayer()
UIHelper.onAudioFocusEvent -= ::handlePauseEvent

View file

@ -146,8 +146,8 @@ class SearchFragment : Fragment() {
}
allApi.providersActive = requireActivity().getApiSettings()
searchViewModel.search("iron man")
// (activity as AppCompatActivity).loadResult("https://shiro.is/overlord-dubbed", "overlord-dubbed", "Shiro")
//searchViewModel.search("iron man")
(activity as AppCompatActivity).loadResult("https://shiro.is/overlord-dubbed", "overlord-dubbed", "Shiro")
/*
(requireActivity() as AppCompatActivity).supportFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.enter_anim,

View file

@ -417,7 +417,7 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="60dp"
android:orientation="horizontal"
android:gravity="center"
android:paddingTop="10dp"
@ -436,7 +436,7 @@
android:foreground="?attr/selectableItemBackgroundBorderless"
android:id="@+id/lock_player"
card_view:cardElevation="0dp"
tools:visibility="gone"
>
<LinearLayout
android:layout_width="wrap_content"
@ -471,197 +471,239 @@
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
card_view:cardCornerRadius="@dimen/card_corner_radius"
card_view:cardBackgroundColor="@color/transparent"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:id="@+id/resize_player"
card_view:cardElevation="0dp"
>
<LinearLayout
<LinearLayout android:id="@+id/lock_holder" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="match_parent">
<androidx.cardview.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
card_view:cardCornerRadius="@dimen/card_corner_radius"
card_view:cardBackgroundColor="@color/transparent"
android:foreground="?attr/selectableItemBackgroundBorderless"
card_view:cardElevation="0dp"
android:id="@+id/resize_player"
tools:visibility="gone"
>
<ImageView
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_baseline_aspect_ratio_24"
app:tint="@android:color/white"
android:layout_gravity="center">
</ImageView>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Resize"
android:gravity="center"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textSize="10sp"
android:textStyle="bold"
android:layout_gravity="center"
android:textColor="@android:color/white"
>
</TextView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_baseline_aspect_ratio_24"
app:tint="@android:color/white"
android:layout_gravity="center">
</LinearLayout>
</androidx.cardview.widget.CardView>
</ImageView>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Resize"
android:gravity="center"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textSize="10sp"
android:textStyle="bold"
android:layout_gravity="center"
android:textColor="@android:color/white"
>
</TextView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
app:cardCornerRadius="@dimen/card_corner_radius"
app:cardBackgroundColor="@color/transparent"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:id="@+id/playback_speed_btt"
app:cardElevation="0dp"
>
<LinearLayout
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_baseline_speed_24"
app:tint="@android:color/white"
>
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
app:cardCornerRadius="@dimen/card_corner_radius"
app:cardBackgroundColor="@color/transparent"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:id="@+id/playback_speed_btt"
app:cardElevation="0dp"
</ImageView>
<TextView
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Speed"
android:gravity="center"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:id="@+id/player_speed_text"
android:layout_gravity="center"
android:textSize="10sp"
android:textStyle="bold"
android:textColor="@android:color/white"
>
</TextView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_baseline_speed_24"
app:tint="@android:color/white"
>
</LinearLayout>
</androidx.cardview.widget.CardView>
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Speed"
android:gravity="center"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:id="@+id/player_speed_text"
android:layout_gravity="center"
android:textSize="10sp"
android:textStyle="bold"
android:textColor="@android:color/white"
>
</TextView>
<androidx.cardview.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
card_view:cardCornerRadius="@dimen/card_corner_radius"
card_view:cardBackgroundColor="@color/transparent"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:id="@+id/sources_btt"
card_view:cardElevation="0dp"
>
<LinearLayout
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
card_view:cardCornerRadius="@dimen/card_corner_radius"
card_view:cardBackgroundColor="@color/transparent"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:id="@+id/sources_btt"
card_view:cardElevation="0dp"
>
<ImageView
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_baseline_playlist_play_24"
app:tint="@android:color/white"
android:layout_gravity="center">
</ImageView>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Source"
android:gravity="center"
android:orientation="horizontal"
android:paddingStart="10dp"
android:textSize="10sp"
android:textStyle="bold"
android:paddingEnd="10dp"
android:layout_gravity="center"
android:textColor="@android:color/white"
>
</TextView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_baseline_playlist_play_24"
app:tint="@android:color/white"
android:layout_gravity="center">
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
</ImageView>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Source"
android:gravity="center"
android:paddingStart="10dp"
card_view:cardCornerRadius="@dimen/card_corner_radius"
card_view:cardBackgroundColor="@color/transparent"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:id="@+id/skip_op"
android:visibility="gone"
card_view:cardElevation="0dp"
>
<LinearLayout
android:textSize="10sp"
android:textStyle="bold"
android:paddingEnd="10dp"
android:layout_gravity="center"
android:textColor="@android:color/white"
>
</TextView>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="10dp"
>
<ImageView
android:layout_width="24dp"
android:layout_height="match_parent"
android:src="@drawable/exo_controls_fastforward"
app:tint="@android:color/white"
android:layout_gravity="center">
</ImageView>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Skip OP"
android:id="@+id/skip_op_text"
android:gravity="start|center"
android:paddingStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
card_view:cardCornerRadius="@dimen/card_corner_radius"
card_view:cardBackgroundColor="@color/transparent"
android:foreground="?attr/selectableItemBackgroundBorderless"
card_view:cardElevation="0dp"
android:textSize="10sp"
android:textStyle="bold"
android:id="@+id/skip_op"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:layout_gravity="center"
android:textColor="@android:color/white"
>
</TextView>
</LinearLayout>
</androidx.cardview.widget.CardView>
<ImageView
android:layout_width="24dp"
android:layout_height="match_parent"
android:src="@drawable/exo_controls_fastforward"
app:tint="@android:color/white"
android:layout_gravity="center">
</ImageView>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Skip OP"
android:gravity="start|center"
android:paddingStart="10dp"
android:textSize="10sp"
android:textStyle="bold"
android:paddingEnd="10dp"
android:layout_gravity="center"
android:textColor="@android:color/white"
>
</TextView>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
card_view:cardCornerRadius="@dimen/card_corner_radius"
card_view:cardBackgroundColor="@color/transparent"
android:foreground="?attr/selectableItemBackgroundBorderless"
card_view:cardElevation="0dp"
android:id="@+id/skip_episode"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="10dp"
>
<ImageView
android:layout_width="24dp"
android:layout_height="match_parent"
android:src="@drawable/ic_baseline_skip_next_24"
app:tint="@android:color/white"
android:layout_gravity="center">
</ImageView>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Next Episode"
android:gravity="start|center"
android:paddingStart="10dp"
android:textSize="10sp"
android:textStyle="bold"
android:paddingEnd="10dp"
android:layout_gravity="center"
android:textColor="@android:color/white"
>
</TextView>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</LinearLayout>