From dba8e7e70ab1f2b9ca8a2ccbb02ef1402cbee6d1 Mon Sep 17 00:00:00 2001 From: LagradOst Date: Sat, 11 Dec 2021 22:23:36 +0100 Subject: [PATCH 1/2] autohide so stop fkng asking for it --- .../ui/home/HomeChildItemAdapter.kt | 8 ++-- .../cloudstream3/ui/home/HomeFragment.kt | 2 +- .../cloudstream3/ui/player/PlayerFragment.kt | 38 ++++++++++++++++++- .../cloudstream3/ui/search/SearchAdaptor.kt | 5 ++- .../cloudstream3/ui/search/SearchHelper.kt | 2 +- .../ui/search/SearchResultBuilder.kt | 16 ++++++-- app/src/main/res/layout/fragment_home.xml | 14 +------ app/src/main/res/layout/fragment_result.xml | 2 +- 8 files changed, 60 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeChildItemAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeChildItemAdapter.kt index 74abedf7..4a277a99 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeChildItemAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeChildItemAdapter.kt @@ -52,17 +52,17 @@ class HomeChildItemAdapter( ) : RecyclerView.ViewHolder(itemView) { - fun bind(card: SearchResponse, index: Int) { + fun bind(card: SearchResponse, position: Int) { // TV focus fixing - val nextFocusBehavior = when (index) { + val nextFocusBehavior = when (position) { 0 -> true itemCount - 1 -> false else -> null } - SearchResultBuilder.bind(clickCallback, card, itemView, nextFocusBehavior, nextFocusUp, nextFocusDown) - itemView.tag = index + SearchResultBuilder.bind(clickCallback, card, position, itemView, nextFocusBehavior, nextFocusUp, nextFocusDown) + itemView.tag = position //val ani = ScaleAnimation(0.9f, 1.0f, 0.9f, 1f) //ani.fillAfter = true //ani.duration = 200 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 b7521193..c87bf30a 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 @@ -437,7 +437,7 @@ class HomeFragment : Fragment() { if (itemId == 1) { handleSearchClickCallback( activity, - SearchClickCallback(SEARCH_ACTION_LOAD, callback.view, callback.card) + SearchClickCallback(SEARCH_ACTION_LOAD, callback.view, -1, callback.card) ) reloadStored() } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt index c2d885e7..edd1b049 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt @@ -409,6 +409,9 @@ class PlayerFragment : Fragment() { private fun onClickChange() { isShowing = !isShowing + if(isShowing) { + autoHide() + } activity?.hideSystemUI() updateClick() } @@ -1018,6 +1021,18 @@ class PlayerFragment : Fragment() { ) } + var currentTapIndex = 0 + + private fun autoHide() { + currentTapIndex++ + val index = currentTapIndex + player_holder?.postDelayed({ + if (isShowing && index == currentTapIndex && this::exoPlayer.isInitialized && exoPlayer.isPlaying) { + onClickChange() + } + }, 2000) + } + private var receiver: BroadcastReceiver? = null override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) { isInPIPMode = isInPictureInPictureMode @@ -1085,7 +1100,7 @@ class PlayerFragment : Fragment() { when (event.action) { KeyEvent.ACTION_DOWN -> { when (keyCode) { - KeyEvent.KEYCODE_DPAD_CENTER -> { + KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_DPAD_UP -> { if (!isShowing) { onClickChange() return true @@ -1216,6 +1231,7 @@ class PlayerFragment : Fragment() { val subsSettings = sourceDialog.findViewById(R.id.subs_settings)!! subsSettings.setOnClickListener { + autoHide() saveArguments() SubtitlesFragment.push(activity) sourceDialog.dismiss() @@ -1360,6 +1376,17 @@ class PlayerFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) updateLock() + + exo_pause?.setOnClickListener { + autoHide() + handlePlayerEvent(PlayerEventType.Pause) + } + + exo_play?.setOnClickListener { + autoHide() + handlePlayerEvent(PlayerEventType.Play) + } + context?.let { ctx -> setPreferredSubLanguage(ctx.getAutoSelectLanguageISO639_1()) } @@ -1640,6 +1667,7 @@ class PlayerFragment : Fragment() { } exo_rew?.setOnClickListener { + autoHide() rewind() } @@ -1668,6 +1696,7 @@ class PlayerFragment : Fragment() { } exo_ffwd?.setOnClickListener { + autoHide() fastForward() } @@ -1709,7 +1738,7 @@ class PlayerFragment : Fragment() { } } - player_holder.setOnTouchListener( + player_holder?.setOnTouchListener( Listener() ) @@ -1729,10 +1758,12 @@ class PlayerFragment : Fragment() { playback_speed_btt?.isVisible = playBackSpeedEnabled playback_speed_btt?.setOnClickListener { + autoHide() handlePlayerEvent(PlayerEventType.ShowSpeed) } sources_btt.setOnClickListener { + autoHide() handlePlayerEvent(PlayerEventType.ShowMirrors) } @@ -1740,6 +1771,7 @@ class PlayerFragment : Fragment() { if (playerResizeEnabled) { resize_player?.visibility = VISIBLE resize_player?.setOnClickListener { + autoHide() handlePlayerEvent(PlayerEventType.Resize) } } else { @@ -1747,10 +1779,12 @@ class PlayerFragment : Fragment() { } skip_op?.setOnClickListener { + autoHide() skipOP() } skip_episode?.setOnClickListener { + autoHide() handlePlayerEvent(PlayerEventType.NextEpisode) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchAdaptor.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchAdaptor.kt index 6936fbd1..bf36919f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchAdaptor.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchAdaptor.kt @@ -17,8 +17,9 @@ import kotlin.math.roundToInt const val SEARCH_ACTION_LOAD = 0 const val SEARCH_ACTION_SHOW_METADATA = 1 const val SEARCH_ACTION_PLAY_FILE = 2 +const val SEARCH_ACTION_FOCUSED = 4 -class SearchClickCallback(val action: Int, val view: View, val card: SearchResponse) +class SearchClickCallback(val action: Int, val view: View, val position : Int, val card: SearchResponse) class SearchAdapter( var cardList: List, @@ -69,7 +70,7 @@ class SearchAdapter( } } - SearchResultBuilder.bind(clickCallback, card, itemView) + SearchResultBuilder.bind(clickCallback, card, position, itemView) } } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchHelper.kt index e70659be..ddc70590 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchHelper.kt @@ -43,7 +43,7 @@ object SearchHelper { } else { handleSearchClickCallback( activity, - SearchClickCallback(SEARCH_ACTION_LOAD, callback.view, callback.card) + SearchClickCallback(SEARCH_ACTION_LOAD, callback.view, -1, callback.card) ) } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchResultBuilder.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchResultBuilder.kt index b5878f29..4199032a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchResultBuilder.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchResultBuilder.kt @@ -21,6 +21,7 @@ object SearchResultBuilder { fun bind( clickCallback: (SearchClickCallback) -> Unit, card: SearchResponse, + position: Int, itemView: View, nextFocusBehavior: Boolean? = null, nextFocusUp: Int? = null, @@ -54,16 +55,17 @@ object SearchResultBuilder { SearchClickCallback( if (card is DataStoreHelper.ResumeWatchingResult) SEARCH_ACTION_PLAY_FILE else SEARCH_ACTION_LOAD, it, + position, card ) ) } - if(nextFocusUp != null) { + if (nextFocusUp != null) { bg.nextFocusUpId = nextFocusUp } - - if(nextFocusDown != null) { + + if (nextFocusDown != null) { bg.nextFocusDownId = nextFocusDown } @@ -83,10 +85,16 @@ object SearchResultBuilder { } bg.setOnLongClickListener { - clickCallback.invoke(SearchClickCallback(SEARCH_ACTION_SHOW_METADATA, it, card)) + clickCallback.invoke(SearchClickCallback(SEARCH_ACTION_SHOW_METADATA, it, position, card)) return@setOnLongClickListener true } + bg.setOnFocusChangeListener { view, b -> + if (b) { + clickCallback.invoke(SearchClickCallback(SEARCH_ACTION_FOCUSED, view, position, card)) + } + } + when (card) { is DataStoreHelper.ResumeWatchingResult -> { val pos = card.watchPos?.fixVisual() diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index b524d4fc..bbdc0358 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -11,7 +11,7 @@ @@ -148,7 +148,7 @@ Date: Sat, 11 Dec 2021 22:36:35 +0100 Subject: [PATCH 2/2] autohide part 2 fuck android tv --- .../cloudstream3/ui/player/PlayerFragment.kt | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt index edd1b049..32f5f6a1 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt @@ -1073,30 +1073,6 @@ class PlayerFragment : Fragment() { private fun handleKeyEvent(event: KeyEvent): Boolean { event.keyCode.let { keyCode -> - when (keyCode) { - // don't allow dpad move when hidden - KeyEvent.KEYCODE_DPAD_LEFT, - KeyEvent.KEYCODE_DPAD_DOWN, - KeyEvent.KEYCODE_DPAD_UP, - KeyEvent.KEYCODE_DPAD_RIGHT, - KeyEvent.KEYCODE_DPAD_DOWN_LEFT, - KeyEvent.KEYCODE_DPAD_DOWN_RIGHT, - KeyEvent.KEYCODE_DPAD_UP_LEFT, - KeyEvent.KEYCODE_DPAD_UP_RIGHT -> { - if (!isShowing) { - return true - } - } - - // netflix capture back and hide ~monke - KeyEvent.KEYCODE_BACK -> { - if (isShowing) { - onClickChange() - return true - } - } - } - when (event.action) { KeyEvent.ACTION_DOWN -> { when (keyCode) { @@ -1116,6 +1092,32 @@ class PlayerFragment : Fragment() { //) } } + + when (keyCode) { + // don't allow dpad move when hidden + KeyEvent.KEYCODE_DPAD_LEFT, + KeyEvent.KEYCODE_DPAD_DOWN, + KeyEvent.KEYCODE_DPAD_UP, + KeyEvent.KEYCODE_DPAD_RIGHT, + KeyEvent.KEYCODE_DPAD_DOWN_LEFT, + KeyEvent.KEYCODE_DPAD_DOWN_RIGHT, + KeyEvent.KEYCODE_DPAD_UP_LEFT, + KeyEvent.KEYCODE_DPAD_UP_RIGHT -> { + if (!isShowing) { + return true + } else { + autoHide() + } + } + + // netflix capture back and hide ~monke + KeyEvent.KEYCODE_BACK -> { + if (isShowing) { + onClickChange() + return true + } + } + } } return false