player support for small screen + player fixes

This commit is contained in:
LagradOst 2021-09-04 00:46:29 +02:00
parent dea167a851
commit b859508522
8 changed files with 489 additions and 401 deletions

View file

@ -200,6 +200,8 @@ class TrailersToProvider : MainAPI() {
override fun load(url: String): LoadResponse {
val response = khttp.get(url)
val document = Jsoup.parse(response.text)
var title = document?.selectFirst("h2.breadcrumbs-custom-title > a")?.text() ?: throw ErrorLoadingException("Service might be unavailable")
val metaInfo = document.select("div.post-info-meta > ul.post-info-meta-list > li")
val year = metaInfo?.get(0)?.selectFirst("> span.small-text")?.text()?.takeLast(4)?.toIntOrNull()
val rating = parseRating(metaInfo?.get(1)?.selectFirst("> span.small-text")?.text()?.replace("/ 10", ""))
@ -208,7 +210,6 @@ class TrailersToProvider : MainAPI() {
val trailer = metaInfo?.get(4)?.selectFirst("> a")?.attr("href")
val poster = document.selectFirst("div.slider-image > a > img").attr("src")
val descriptHeader = document.selectFirst("article.post-info")
var title = document.selectFirst("h2.breadcrumbs-custom-title > a").text()
title = title.substring(0, title.length - 6) // REMOVE YEAR
val descript = descriptHeader.select("> div > p").text()

View file

@ -11,6 +11,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.GridLayoutManager
@ -106,7 +107,7 @@ class HomeFragment : Fragment() {
var currentMainList: ArrayList<SearchResponse> = ArrayList()
private fun toggleMainVisibility(visible: Boolean) {
home_main_holder.visibility = if (visible) View.VISIBLE else View.GONE
home_main_holder.isVisible = visible
}
@SuppressLint("SetTextI18n")
@ -314,7 +315,7 @@ class HomeFragment : Fragment() {
}
observe(homeViewModel.bookmarks) { bookmarks ->
home_bookmarked_holder.visibility = if (bookmarks.isNotEmpty()) View.VISIBLE else View.GONE
home_bookmarked_holder.isVisible = bookmarks.isNotEmpty()
(home_bookmarked_child_recyclerview?.adapter as HomeChildItemAdapter?)?.cardList = bookmarks
home_bookmarked_child_recyclerview?.adapter?.notifyDataSetChanged()
@ -329,11 +330,11 @@ class HomeFragment : Fragment() {
}
observe(homeViewModel.resumeWatching) { resumeWatching ->
home_watch_holder.visibility = if (resumeWatching.isNotEmpty()) View.VISIBLE else View.GONE
home_watch_holder?.isVisible = resumeWatching.isNotEmpty()
(home_watch_child_recyclerview?.adapter as HomeChildItemAdapter?)?.cardList = resumeWatching
home_watch_child_recyclerview?.adapter?.notifyDataSetChanged()
home_watch_child_more_info.setOnClickListener {
home_watch_child_more_info?.setOnClickListener {
activity?.loadHomepageList(
HomePageList(
home_watch_parent_item_title?.text?.toString() ?: getString(R.string.continue_watching),

View file

@ -21,6 +21,7 @@ import android.view.MotionEvent
import android.view.View
import android.view.View.*
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.animation.AccelerateInterpolator
import android.view.animation.AlphaAnimation
import android.view.animation.Animation
@ -30,6 +31,7 @@ import android.widget.Toast.LENGTH_SHORT
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.core.net.toUri
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.preference.PreferenceManager
@ -304,11 +306,11 @@ class PlayerFragment : Fragment() {
if (event.rawX >= ctx.width / 2) {
clicksRight++
if (!ctx.isLocked && ctx.doubleTapEnabled) onDoubleClickRight(clicksRight)
if (!ctx.isShowing) onSingleClick()
//if (!ctx.isShowing) onSingleClick()
} else {
clicksLeft++
if (!ctx.isLocked && ctx.doubleTapEnabled) onDoubleClickLeft(clicksLeft)
if (!ctx.isShowing) onSingleClick()
//if (!ctx.isShowing) onSingleClick()
}
} else if (clicksLeft == 0 && clicksRight == 0 && fingerLeftScreen) {
// onSingleClick()
@ -325,8 +327,8 @@ class PlayerFragment : Fragment() {
onSingleClick()
}
}
if (ctx.isShowing && !ctx.isLocked && ctx.doubleTapEnabled) {
//ctx.isShowing &&
if (!ctx.isLocked && ctx.doubleTapEnabled) {
uiScope.launch {
delay(doubleClickQualificationSpanInMillis + 1)
check()
@ -346,7 +348,7 @@ class PlayerFragment : Fragment() {
private fun onClickChange() {
isShowing = !isShowing
click_overlay?.visibility = if (isShowing) GONE else VISIBLE
click_overlay?.isVisible = !isShowing
val titleMove = if (isShowing) 0f else -50.toPx.toFloat()
ObjectAnimator.ofFloat(video_title, "translationY", titleMove).apply {
@ -382,10 +384,24 @@ class PlayerFragment : Fragment() {
}
if (!isLocked) {
player_ffwd_holder?.alpha = 1f
player_rew_holder?.alpha = 1f
player_pause_holder?.alpha = 1f
shadow_overlay?.startAnimation(fadeAnimation)
player_ffwd_holder?.startAnimation(fadeAnimation)
player_rew_holder?.startAnimation(fadeAnimation)
player_pause_holder?.startAnimation(fadeAnimation)
} else {
//player_ffwd_holder?.alpha = 0f
//player_ffwd_holder?.alpha = 0f
//player_pause_holder?.alpha = 0f
}
video_holder?.startAnimation(fadeAnimation)
player_torrent_info?.visibility = if (isTorrent && isShowing) VISIBLE else GONE
bottom_player_bar.startAnimation(fadeAnimation)
player_top_holder.startAnimation(fadeAnimation)
// video_holder?.startAnimation(fadeAnimation)
player_torrent_info?.isVisible = (isTorrent && isShowing)
// player_torrent_info?.startAnimation(fadeAnimation)
//video_lock_holder?.startAnimation(fadeAnimation)
}
@ -614,10 +630,6 @@ class PlayerFragment : Fragment() {
}
}
private fun View.setVis(visible: Boolean) {
this.visibility = if (visible) VISIBLE else GONE
}
fun changeSkip(position: Long? = null) {
val data = localData
@ -639,17 +651,17 @@ class PlayerFragment : Fragment() {
val isAnime =
data.isAnimeBased()//(data is AnimeLoadResponse && (data.type == TvType.Anime || data.type == TvType.ONA))
skip_op?.setVis(isAnime && !nextEp)
skip_episode?.setVis((!isAnime || nextEp) && hasNext)
skip_op?.isVisible = (isAnime && !nextEp)
skip_episode?.isVisible = ((!isAnime || nextEp) && hasNext)
} else {
val isAnime = data.isAnimeBased()
if (isAnime) {
skip_op?.setVis(true)
skip_episode?.setVis(false)
skip_op?.isVisible = true
skip_episode?.isVisible = false
} else {
skip_episode?.setVis(data.isEpisodeBased())
skip_op?.setVis(false)
skip_episode?.isVisible = data.isEpisodeBased()
skip_op?.isVisible = false
}
}
}
@ -690,7 +702,7 @@ class PlayerFragment : Fragment() {
val alphaAnimation = AlphaAnimation(0f, 1f)
alphaAnimation.duration = 100
alphaAnimation.fillAfter = true
video_go_back_holder?.visibility = VISIBLE
video_go_back_holder_holder?.visibility = VISIBLE
overlay_loading_skip_button?.visibility = VISIBLE
loading_overlay?.startAnimation(alphaAnimation)
@ -798,6 +810,12 @@ class PlayerFragment : Fragment() {
resize_player.isClickable = isClick
exo_progress.isEnabled = isClick
player_media_route_button.isEnabled = isClick
if (isClick) {
player_pause_holder.alpha = 1f
player_rew_holder.alpha = 1f
player_ffwd_holder.alpha = 1f
}
//video_go_back_holder2.isEnabled = isClick
// Clickable doesn't seem to work on com.google.android.exoplayer2.ui.DefaultTimeBar
@ -973,6 +991,15 @@ class PlayerFragment : Fragment() {
navigationBarHeight = requireContext().getNavigationBarHeight()
statusBarHeight = requireContext().getStatusBarHeight()
/*player_pause_holder?.setOnClickListener {
if (this::exoPlayer.isInitialized) {
if (exoPlayer.isPlaying)
exoPlayer.pause()
else
exoPlayer.play()
}
}*/
if (activity?.isCastApiAvailable() == true && !isDownloadedFile) {
CastButtonFactory.setUpMediaRouteButton(activity, player_media_route_button)
val castContext = CastContext.getSharedInstance(requireContext())
@ -980,9 +1007,8 @@ class PlayerFragment : Fragment() {
if (castContext.castState != CastState.NO_DEVICES_AVAILABLE) player_media_route_button.visibility = VISIBLE
castContext.addCastStateListener { state ->
if (player_media_route_button != null) {
if (state == CastState.NO_DEVICES_AVAILABLE) player_media_route_button.visibility = GONE else {
if (player_media_route_button.visibility == GONE) player_media_route_button.visibility = VISIBLE
}
player_media_route_button.isVisible = state != CastState.NO_DEVICES_AVAILABLE
if (state == CastState.CONNECTED) {
if (!this::exoPlayer.isInitialized) return@addCastStateListener
val links = sortUrls(getUrls() ?: return@addCastStateListener)
@ -1071,9 +1097,7 @@ class PlayerFragment : Fragment() {
GONE else VISIBLE
else VISIBLE
player_media_route_button.visibility =
if (isDownloadedFile) GONE else VISIBLE
player_media_route_button.isVisible = !isDownloadedFile
if (savedInstanceState != null) {
currentWindow = savedInstanceState.getInt(STATE_RESUME_WINDOW)
playbackPosition = savedInstanceState.getLong(STATE_RESUME_POSITION)
@ -1155,6 +1179,8 @@ class PlayerFragment : Fragment() {
exo_rew_text.text = getString(R.string.rew_text_regular_format).format(fastForwardTime)
exo_ffwd_text.text = getString(R.string.ffw_text_regular_format).format(fastForwardTime)
fun rewind() {
player_rew_holder.alpha = 1f
val rotateLeft = AnimationUtils.loadAnimation(context, R.anim.rotate_left)
exo_rew.startAnimation(rotateLeft)
@ -1167,6 +1193,7 @@ class PlayerFragment : Fragment() {
override fun onAnimationEnd(animation: Animation?) {
exo_rew_text.post {
exo_rew_text.text = getString(R.string.rew_text_regular_format).format(fastForwardTime)
player_rew_holder.alpha = if (isShowing) 1f else 0f
}
}
})
@ -1180,6 +1207,7 @@ class PlayerFragment : Fragment() {
}
fun fastForward() {
player_ffwd_holder.alpha = 1f
val rotateRight = AnimationUtils.loadAnimation(context, R.anim.rotate_right)
exo_ffwd.startAnimation(rotateRight)
@ -1192,6 +1220,7 @@ class PlayerFragment : Fragment() {
override fun onAnimationEnd(animation: Animation?) {
exo_ffwd_text.post {
exo_ffwd_text.text = getString(R.string.ffw_text_regular_format).format(fastForwardTime)
player_ffwd_holder.alpha = if (isShowing) 1f else 0f
}
}
})
@ -1224,7 +1253,10 @@ class PlayerFragment : Fragment() {
fadeAnimation.fillAfter = true
// MENUS
centerMenu.startAnimation(fadeAnimation)
//centerMenu.startAnimation(fadeAnimation)
player_pause_holder.startAnimation(fadeAnimation)
player_ffwd_holder.startAnimation(fadeAnimation)
player_rew_holder.startAnimation(fadeAnimation)
player_media_route_button.startAnimation(fadeAnimation)
//video_bar.startAnimation(fadeAnimation)
@ -1245,13 +1277,13 @@ class PlayerFragment : Fragment() {
override fun onDoubleClickRight(clicks: Int) {
if (!isLocked) {
fastForward()
}
} else onSingleClick()
}
override fun onDoubleClickLeft(clicks: Int) {
if (!isLocked) {
rewind()
}
} else onSingleClick()
}
override fun onSingleClick() {
@ -1282,7 +1314,7 @@ class PlayerFragment : Fragment() {
activity?.popCurrentPage()
}
playback_speed_btt.visibility = if (playBackSpeedEnabled) VISIBLE else GONE
playback_speed_btt.isVisible = playBackSpeedEnabled
playback_speed_btt.setOnClickListener {
val speedsText = listOf("0.5x", "0.75x", "1x", "1.25x", "1.5x", "1.75x", "2x")
val speedsNumbers = listOf(0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f)
@ -1565,6 +1597,7 @@ class PlayerFragment : Fragment() {
}
override fun onDestroy() {
loading_overlay?.isVisible = false
savePos()
SubtitlesFragment.applyStyleEvent -= ::onSubStyleChanged
@ -1665,8 +1698,8 @@ class PlayerFragment : Fragment() {
}
// player_torrent_info?.visibility = if(isTorrent) VISIBLE else GONE
//
isShowing = false
player_torrent_info?.visibility = GONE
isShowing = true
player_torrent_info?.isVisible = false
//player_torrent_info?.alpha = 0f
println("LOADED: ${uri} or ${currentUrl}")
isCurrentlyPlaying = true
@ -1810,7 +1843,7 @@ class PlayerFragment : Fragment() {
override fun onAnimationRepeat(animation: Animation?) {}
override fun onAnimationEnd(animation: Animation?) {
loading_overlay.post { video_go_back_holder.visibility = GONE; }
loading_overlay.post { video_go_back_holder_holder.visibility = GONE; }
}
})
overlay_loading_skip_button.visibility = GONE
@ -1850,6 +1883,8 @@ class PlayerFragment : Fragment() {
}
}
player_view.performClick()
//TODO FIX
video_title?.text = hName +
if (isEpisodeBased)

View file

@ -224,6 +224,15 @@ class ResultViewModel : ViewModel() {
}
}
private fun filterName(name : String?) : String? {
if(name == null) return null
Regex("[eE]pisode [0-9]*(.*)").find(name)?.groupValues?.get(1)?.let {
if(it.isEmpty())
return null
}
return name
}
fun load(context: Context, url: String, apiName: String) = viewModelScope.launch {
_resultResponse.postValue(Resource.Loading(url))
@ -269,7 +278,7 @@ class ResultViewModel : ViewModel() {
for ((index, i) in dataList.withIndex()) {
episodes.add(
context.buildResultEpisode(
i.name,
filterName(i.name),
i.posterUrl,
index + 1, //TODO MAKE ABLE TO NOT HAVE SOME EPISODE
null, // TODO FIX SEASON
@ -291,7 +300,7 @@ class ResultViewModel : ViewModel() {
for ((index, i) in d.episodes.withIndex()) {
episodes.add(
context.buildResultEpisode(
i.name,
filterName(i.name),
i.posterUrl,
i.episode ?: (index + 1),
i.season,

View file

@ -118,6 +118,7 @@ object DataStoreHelper {
fun Context.setViewPos(id: Int?, pos: Long, dur: Long) {
if (id == null) return
if(dur < 10_000) return // too short
setKey("$currentAccount/$VIDEO_POS_DUR", id.toString(), PosDur(pos, dur))
}

View file

@ -5,6 +5,7 @@ import android.content.Context
import android.view.View
import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible
import androidx.core.view.marginLeft
import androidx.core.view.marginRight
import androidx.core.view.marginTop
@ -31,7 +32,7 @@ object SingleSelectionHelper {
val cancelButton = dialog.findViewById<TextView>(R.id.cancel_btt)!!
val applyHolder = dialog.findViewById<LinearLayout>(R.id.apply_btt_holder)!!
applyHolder.visibility = if (realShowApply) View.VISIBLE else View.GONE
applyHolder.isVisible = realShowApply
if (!realShowApply) {
val params = listView.layoutParams as LinearLayout.LayoutParams
params.setMargins(listView.marginLeft, listView.marginTop, listView.marginRight, 0)

View file

@ -3,7 +3,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:keepScreenOn="true"
app:backgroundTint="@android:color/black"
@ -71,6 +72,7 @@
</ProgressBar>
<FrameLayout
android:id="@+id/video_go_back_holder_holder"
android:layout_margin="5dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"

View file

@ -109,13 +109,19 @@
android:layout_height="match_parent"
android:id="@+id/video_holder"
>
<FrameLayout
android:id="@+id/player_top_holder"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_marginStart="80dp"
android:layout_marginEnd="80dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:gravity="center"
android:layout_marginTop="15dp"
android:layout_marginTop="35dp"
android:textStyle="bold"
android:textColor="@color/white"
android:id="@+id/video_title"
@ -123,11 +129,13 @@
>
</TextView>
<TextView
android:layout_marginStart="80dp"
android:layout_marginEnd="80dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
android:gravity="center"
android:layout_marginTop="0dp"
android:layout_marginTop="20dp"
android:textColor="@color/white"
android:id="@+id/video_title_rez"
tools:text="1920x1080"
@ -184,7 +192,7 @@
<androidx.mediarouter.app.MediaRouteButton
android:layout_margin="5dp"
android:layout_gravity="center_vertical|end"
android:layout_gravity="end"
android:id="@+id/player_media_route_button"
android:layout_width="70dp"
android:layout_height="70dp"
@ -219,8 +227,10 @@
android:background="@drawable/video_tap_button_always_white">
</ImageView>
</FrameLayout>
</FrameLayout>
<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
@ -233,9 +243,15 @@
android:id="@+id/centerMenu"
>
<FrameLayout android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content" tools:ignore="RtlSymmetry">
<FrameLayout
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="@id/player_pause_holder"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/player_rew_holder"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|start"
android:layout_height="wrap_content">
<TextView
android:id="@+id/exo_rew_text"
android:textColor="@color/white"
@ -260,37 +276,54 @@
android:src="@drawable/netflix_skip_back"
android:scaleType="fitCenter"
android:tintMode="src_in"
/>
</FrameLayout>
<!-- style="@style/ExoMediaButton.Play"
android:background="?android:selectableItemBackgroundBorderless"
-->
<FrameLayout
app:layout_constraintLeft_toLeftOf="@id/player_rew_holder"
app:layout_constraintRight_toRightOf="@id/player_ffwd_holder"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_gravity="center"
android:id="@+id/player_pause_holder"
android:layout_width="100dp"
android:layout_height="100dp">
<ImageButton
android:id="@id/exo_play"
android:scaleType="fitCenter"
android:layout_height="100dp"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_width="70dp"
android:background="@drawable/video_tap_button"
android:layout_gravity="center"
android:background="@drawable/video_tap_button_always_white"
android:foreground="@drawable/video_play"
android:src="@drawable/netflix_play"
android:clickable="true"
android:focusable="true"/>
android:focusable="true"
/>
<ImageButton
android:id="@id/exo_pause"
android:scaleType="fitCenter"
android:layout_height="100dp"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_width="70dp"
android:background="@drawable/video_tap_button"
android:layout_gravity="center"
android:background="@drawable/video_tap_button_always_white"
android:foreground="@drawable/video_pause"
android:src="@drawable/netflix_pause"
android:clickable="true"
android:focusable="true"/>
android:focusable="true"
/>
</FrameLayout>
<FrameLayout android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
<FrameLayout
app:layout_constraintLeft_toLeftOf="@id/player_pause_holder"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/player_ffwd_holder"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_height="wrap_content">
<TextView
tools:text="10"
@ -315,7 +348,7 @@
android:tintMode="src_in"
/>
</FrameLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
@ -374,8 +407,6 @@
android:orientation="horizontal"
android:id="@+id/video_bar"
>
<TextView
tools:text="15:30"
android:layout_marginStart="20dp"
@ -423,6 +454,10 @@
/>
</LinearLayout>
<HorizontalScrollView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
@ -479,8 +514,11 @@
</LinearLayout>
</androidx.cardview.widget.CardView>
<LinearLayout android:id="@+id/lock_holder" android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="match_parent">
<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"
@ -712,18 +750,21 @@
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<View android:layout_width="match_parent"
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/brightness_overlay"
android:background="@android:color/black"
android:alpha="0"
/>
<View android:layout_width="match_parent"
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/click_overlay"
android:visibility="gone"
@ -772,10 +813,7 @@
android:layout_gravity="end|center_vertical"
android:progress="100"
android:progressDrawable="@drawable/progress_drawable_vertical"
>
</ProgressBar>
/>
</RelativeLayout>
<RelativeLayout
android:layout_gravity="center_vertical"