From 06c2cf86ec076cb934afb30acfb59c9b55b8c899 Mon Sep 17 00:00:00 2001 From: Blatzar <46196380+Blatzar@users.noreply.github.com> Date: Mon, 9 Jan 2023 02:15:06 +0100 Subject: [PATCH] Various Android TV homepage fixes --- .../java/com/lagradost/cloudstream3/MainActivity.kt | 9 +++++++-- .../com/lagradost/cloudstream3/ui/APIRepository.kt | 3 ++- .../ui/home/HomeParentItemAdapterPreview.kt | 13 +++++++++++++ app/src/main/res/layout/fragment_home_head_tv.xml | 5 +++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index ee54783f..0b0b787a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -1,6 +1,7 @@ package com.lagradost.cloudstream3 import android.content.ComponentName +import android.content.DialogInterface import android.content.Intent import android.content.res.ColorStateList import android.content.res.Configuration @@ -102,6 +103,7 @@ import java.net.URI import java.net.URLDecoder import java.nio.charset.Charset import kotlin.reflect.KClass +import kotlin.system.exitProcess //https://github.com/videolan/vlc-android/blob/3706c4be2da6800b3d26344fc04fab03ffa4b860/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt#L1898 @@ -505,10 +507,13 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { val builder: AlertDialog.Builder = AlertDialog.Builder(this) builder.setTitle(R.string.confirm_exit_dialog) builder.apply { - setPositiveButton(R.string.yes) { _, _ -> super.onBackPressed() } + // Forceful exit since back button can actually go back to setup + setPositiveButton(R.string.yes) { _, _ -> exitProcess(0) } setNegativeButton(R.string.no) { _, _ -> } } - builder.show() + builder.show().also { + it.getButton(DialogInterface.BUTTON_NEGATIVE).requestFocus() + } } private fun backPressed() { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/APIRepository.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/APIRepository.kt index 645cd573..4ab2e8e2 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/APIRepository.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/APIRepository.kt @@ -81,6 +81,8 @@ class APIRepository(val api: MainAPI) { } api.load(fixedUrl)?.also { response -> + // Remove all blank tags as early as possible + response.tags = response.tags?.filter { it.isNotBlank() } val add = SavedLoadResponse(unixTime, response, lookingForHash) synchronized(cache) { @@ -122,7 +124,6 @@ class APIRepository(val api: MainAPI) { delay(delta) } - @OptIn(DelicateCoroutinesApi::class) suspend fun getMainPage(page: Int, nameIndex: Int? = null): Resource> { return safeApiCall { api.lastHomepageRequest = unixTimeMS diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt index a2e768b9..7564a9de 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapterPreview.kt @@ -268,11 +268,23 @@ class HomeParentItemAdapterPreview( ) ) } + + // This makes the hidden next buttons only available when on the info button + // Otherwise you might be able to go to the next item without being at the info button + itemView.home_preview_info_btt?.setOnFocusChangeListener { _, hasFocus -> + itemView.home_preview_hidden_next_focus?.isFocusable = hasFocus + } + itemView.home_preview_play_btt?.setOnFocusChangeListener { _, hasFocus -> + itemView.home_preview_hidden_prev_focus?.isFocusable = hasFocus + } + + itemView.home_preview_info_btt?.setOnClickListener { view -> clickCallback?.invoke( LoadClickCallback(0, view, position, this) ) } + itemView.home_preview_hidden_next_focus?.setOnFocusChangeListener { _, hasFocus -> if (hasFocus) { previewViewpager?.apply { @@ -281,6 +293,7 @@ class HomeParentItemAdapterPreview( itemView.home_preview_info_btt?.requestFocus() } } + itemView.home_preview_hidden_prev_focus?.setOnFocusChangeListener { _, hasFocus -> if (hasFocus) { previewViewpager?.apply { diff --git a/app/src/main/res/layout/fragment_home_head_tv.xml b/app/src/main/res/layout/fragment_home_head_tv.xml index c3001416..b9b4fec0 100644 --- a/app/src/main/res/layout/fragment_home_head_tv.xml +++ b/app/src/main/res/layout/fragment_home_head_tv.xml @@ -20,6 +20,7 @@ android:layout_height="wrap_content"> + android:focusable="false" /> + android:focusable="false" />