From 89c5cb8a46499cacf29659f085ae7d51037c64be Mon Sep 17 00:00:00 2001 From: Blatzar <46196380+Blatzar@users.noreply.github.com> Date: Fri, 20 Jan 2023 01:16:05 +0100 Subject: [PATCH] Added better focus on dialogs on TV & fixed stream button on emulator layout --- .../com/lagradost/cloudstream3/MainActivity.kt | 7 +++---- .../ui/download/DownloadButtonSetup.kt | 3 ++- .../cloudstream3/ui/download/DownloadFragment.kt | 5 ++++- .../cloudstream3/ui/home/HomeFragment.kt | 3 ++- .../cloudstream3/ui/search/SearchFragment.kt | 3 ++- .../ui/settings/extensions/ExtensionsFragment.kt | 3 ++- .../com/lagradost/cloudstream3/utils/AppUtils.kt | 16 ++++++++++++++-- .../lagradost/cloudstream3/utils/InAppUpdater.kt | 3 ++- 8 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index a5f3ff48..4907411f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -79,6 +79,7 @@ import com.lagradost.cloudstream3.utils.AppUtils.loadCache import com.lagradost.cloudstream3.utils.AppUtils.loadRepository import com.lagradost.cloudstream3.utils.AppUtils.loadResult import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult +import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus import com.lagradost.cloudstream3.utils.BackupUtils.setUpBackup import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.DataStore.getKey @@ -511,9 +512,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { setPositiveButton(R.string.yes) { _, _ -> exitProcess(0) } setNegativeButton(R.string.no) { _, _ -> } } - builder.show().also { - it.getButton(DialogInterface.BUTTON_NEGATIVE).requestFocus() - } + builder.show().setDefaultFocus() } private fun backPressed() { @@ -706,7 +705,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { setNegativeButton("Ok") { _, _ -> } } - builder.show() + builder.show().setDefaultFocus() } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt index 0069be3a..add36f1a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt @@ -11,6 +11,7 @@ import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.ui.player.DownloadFileGenerator import com.lagradost.cloudstream3.ui.player.GeneratorPlayer import com.lagradost.cloudstream3.utils.AppUtils.getNameFull +import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus import com.lagradost.cloudstream3.utils.DOWNLOAD_HEADER_CACHE import com.lagradost.cloudstream3.utils.ExtractorUri import com.lagradost.cloudstream3.utils.UIHelper.navigate @@ -49,7 +50,7 @@ object DownloadButtonSetup { ) .setPositiveButton(R.string.delete, dialogClickListener) .setNegativeButton(R.string.cancel, dialogClickListener) - .show() + .show().setDefaultFocus() } catch (e: Exception) { logError(e) // ye you somehow fucked up formatting did you? diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt index b2286c99..f0340845 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt @@ -40,6 +40,7 @@ import kotlinx.android.synthetic.main.stream_input.* import android.text.format.Formatter.formatShortFileSize import androidx.core.widget.doOnTextChanged import com.lagradost.cloudstream3.mvvm.normalSafeApiCall +import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings import java.net.URI @@ -178,7 +179,9 @@ class DownloadFragment : Fragment() { download_list?.adapter = adapter download_list?.layoutManager = GridLayoutManager(context, 1) - download_stream_button?.isGone = isTvSettings() + + // Should be visible in emulator layout + download_stream_button?.isGone = isTrueTvSettings() download_stream_button?.setOnClickListener { val dialog = Dialog(it.context ?: return@setOnClickListener, R.style.AlertDialogCustom) 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 3e9f6810..bb183f12 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 @@ -51,6 +51,7 @@ import com.lagradost.cloudstream3.utils.AppUtils.loadResult import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult import com.lagradost.cloudstream3.utils.AppUtils.ownHide import com.lagradost.cloudstream3.utils.AppUtils.ownShow +import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.setKey @@ -182,7 +183,7 @@ class HomeFragment : Fragment() { ) .setPositiveButton(R.string.delete, dialogClickListener) .setNegativeButton(R.string.cancel, dialogClickListener) - .show() + .show().setDefaultFocus() } catch (e: Exception) { logError(e) // ye you somehow fucked up formatting did you? diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt index 5c101246..1da30691 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt @@ -46,6 +46,7 @@ import com.lagradost.cloudstream3.ui.home.ParentItemAdapter import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings import com.lagradost.cloudstream3.utils.AppUtils.ownShow +import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.setKey @@ -395,7 +396,7 @@ class SearchFragment : Fragment() { ) .setPositiveButton(R.string.sort_clear, dialogClickListener) .setNegativeButton(R.string.cancel, dialogClickListener) - .show() + .show().setDefaultFocus() } catch (e: Exception) { logError(e) // ye you somehow fucked up formatting did you? diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/ExtensionsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/ExtensionsFragment.kt index fbf10499..7e60910d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/ExtensionsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/ExtensionsFragment.kt @@ -26,6 +26,7 @@ import com.lagradost.cloudstream3.ui.result.setText import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar import com.lagradost.cloudstream3.utils.AppUtils.downloadAllPluginsDialog +import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe @@ -107,7 +108,7 @@ class ExtensionsFragment : Fragment() { ) .setPositiveButton(R.string.delete, dialogClickListener) .setNegativeButton(R.string.cancel, dialogClickListener) - .show() + .show().setDefaultFocus() } }) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt index a3eb7362..d563bffa 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt @@ -49,6 +49,7 @@ import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStri import com.lagradost.cloudstream3.ui.WebviewFragment import com.lagradost.cloudstream3.ui.result.ResultFragment import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings +import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings import com.lagradost.cloudstream3.ui.settings.extensions.PluginsViewModel.Companion.downloadAll import com.lagradost.cloudstream3.ui.settings.extensions.RepositoryData import com.lagradost.cloudstream3.utils.Coroutines.ioSafe @@ -88,7 +89,7 @@ object AppUtils { this?.show() Handler(Looper.getMainLooper()).postDelayed({ this?.window?.setWindowAnimations(R.style.Animation_Design_BottomSheetDialog) - },200) + }, 200) } //fun Context.deleteFavorite(data: SearchResponse) { @@ -345,7 +346,7 @@ object AppUtils { setNegativeButton(R.string.no) { _, _ -> } } - builder.show() + builder.show().setDefaultFocus() } } @@ -568,6 +569,17 @@ object AppUtils { return false } + /** + * Sets the focus to the negative button when in TV and Emulator layout. + **/ + fun AlertDialog.setDefaultFocus(buttonFocus: Int = DialogInterface.BUTTON_NEGATIVE) { + if (!isTvSettings()) return + this.getButton(buttonFocus).run { + isFocusableInTouchMode = true + requestFocus() + } + } + // Copied from https://github.com/videolan/vlc-android/blob/master/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt @SuppressLint("Range") fun Context.getUri(data: Uri?): Uri? { diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt index 3acfb9a1..8b516e8c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt @@ -23,6 +23,7 @@ import okio.buffer import okio.sink import java.io.File import android.text.TextUtils +import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus import java.io.BufferedReader import java.io.IOException import java.io.InputStreamReader @@ -355,7 +356,7 @@ class InAppUpdater { } } } - builder.show() + builder.show().setDefaultFocus() } catch (e: Exception) { logError(e) }