From cd119822f21045d7db6cf1838ffb44f305bb384b Mon Sep 17 00:00:00 2001 From: reduplicated <110570621+reduplicated@users.noreply.github.com> Date: Mon, 29 Aug 2022 01:52:15 +0200 Subject: [PATCH] tv UI fixes --- .../lagradost/cloudstream3/CommonActivity.kt | 5 +- .../com/lagradost/cloudstream3/MainAPI.kt | 2 +- .../ui/download/DownloadFragment.kt | 2 +- .../cloudstream3/ui/home/HomeFragment.kt | 64 +++--- .../ui/home/HomeParentItemAdapter.kt | 2 +- .../cloudstream3/ui/player/GeneratorPlayer.kt | 2 +- .../ui/player/PlayerEpisodeAdapter.kt | 2 +- .../cloudstream3/ui/result/EpisodeAdapter.kt | 2 +- .../cloudstream3/ui/result/ImageAdapter.kt | 2 +- .../cloudstream3/ui/result/ResultFragment.kt | 10 +- .../cloudstream3/ui/result/SelectAdaptor.kt | 2 +- .../cloudstream3/ui/search/SearchFragment.kt | 2 +- .../ui/search/SearchResultBuilder.kt | 2 +- .../ui/settings/SettingsAccount.kt | 2 +- .../ui/settings/SettingsFragment.kt | 24 +- .../cloudstream3/ui/settings/SettingsUI.kt | 8 +- .../settings/extensions/ExtensionsFragment.kt | 24 +- .../ui/settings/extensions/PluginAdapter.kt | 5 +- .../ui/settings/extensions/PluginsFragment.kt | 2 +- .../ui/settings/extensions/RepoAdapter.kt | 4 +- .../ui/setup/SetupFragmentExtensions.kt | 6 +- .../subtitles/ChromecastSubtitlesFragment.kt | 2 +- .../ui/subtitles/SubtitlesFragment.kt | 2 +- .../lagradost/cloudstream3/utils/AppUtils.kt | 8 +- .../utils/SingleSelectionHelper.kt | 2 +- .../widget/LinearRecycleViewLayoutManager.kt | 30 +++ app/src/main/res/layout/add_repo_input.xml | 4 + .../main/res/layout/fragment_extensions.xml | 216 ++++++++++-------- .../main/res/layout/repository_item_tv.xml | 122 ++++++++++ 29 files changed, 393 insertions(+), 167 deletions(-) create mode 100644 app/src/main/java/com/lagradost/cloudstream3/widget/LinearRecycleViewLayoutManager.kt create mode 100644 app/src/main/res/layout/repository_item_tv.xml diff --git a/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt index 0f54770f..e56b3bd9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt @@ -6,7 +6,6 @@ import android.content.Context import android.content.pm.PackageManager import android.content.res.Resources import android.os.Build -import android.os.Looper import android.util.Log import android.view.* import android.widget.TextView @@ -20,12 +19,12 @@ import com.google.android.gms.cast.framework.CastSession import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.ui.player.PlayerEventType import com.lagradost.cloudstream3.ui.result.UiText +import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.updateTv import com.lagradost.cloudstream3.utils.Event import com.lagradost.cloudstream3.utils.UIHelper import com.lagradost.cloudstream3.utils.UIHelper.hasPIPPermission import com.lagradost.cloudstream3.utils.UIHelper.shouldShowPIPMode import com.lagradost.cloudstream3.utils.UIHelper.toPx -import kotlinx.coroutines.currentCoroutineContext import org.schabi.newpipe.extractor.NewPipe import java.util.* @@ -128,7 +127,7 @@ object CommonActivity { act.hasPIPPermission() // CHECK IF FEATURE IS ENABLED IN SETTINGS act.updateLocale() - + act.updateTv() NewPipe.init(DownloaderTestImpl.getInstance()) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index 67a3051c..dc6cc454 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -226,7 +226,7 @@ object APIHolder { } private fun Context.getHasTrailers(): Boolean { - if (this.isTvSettings()) return false + if (isTvSettings()) return false val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) return settingsManager.getBoolean(this.getString(R.string.show_trailers_key), true) } 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 7ea360a8..3335e023 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 @@ -175,7 +175,7 @@ class DownloadFragment : Fragment() { download_list?.adapter = adapter download_list?.layoutManager = GridLayoutManager(context, 1) - download_stream_button?.isGone = context?.isTvSettings() == true + download_stream_button?.isGone = isTvSettings() 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 539ce843..0071ab49 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 @@ -400,7 +400,7 @@ class HomeFragment : Fragment() { //homeViewModel = // ViewModelProvider(this).get(HomeViewModel::class.java) val layout = - if (context?.isTvSettings() == true) R.layout.fragment_home_tv else R.layout.fragment_home + if (isTvSettings()) R.layout.fragment_home_tv else R.layout.fragment_home return inflater.inflate(layout, container, false) } @@ -568,7 +568,7 @@ class HomeFragment : Fragment() { val randomSize = items.size tempAdapter?.updateList(items) - if (context?.isTvSettings() == false) { + if (!isTvSettings()) { home_main_poster_recyclerview?.post { (home_main_poster_recyclerview?.layoutManager as CenterZoomLayoutManager?)?.let { manager -> manager.updateSize(forceUpdate = true) @@ -939,7 +939,7 @@ class HomeFragment : Fragment() { } } // GridLayoutManager(context, 1).also { it.supportsPredictiveItemAnimations() } - if (context?.isTvSettings() == false) { + if (!isTvSettings()) { LinearSnapHelper().attachToRecyclerView(home_main_poster_recyclerview) // snap val centerLayoutManager = CenterZoomLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) @@ -975,7 +975,7 @@ class HomeFragment : Fragment() { home_api_fab?.shrink() // hide home_random?.shrink() } else if (dy < -5) { - if (v.context?.isTvSettings() == false) { + if (!isTvSettings()) { home_api_fab?.extend() // show home_random?.extend() } @@ -984,37 +984,35 @@ class HomeFragment : Fragment() { // nice profile pic on homepage home_profile_picture_holder?.isVisible = false - context?.let { ctx -> - // just in case - if (ctx.isTvSettings()) { - home_api_fab?.isVisible = false - home_change_api?.isVisible = true - if (ctx.isTrueTvSettings()) { - home_change_api_loading?.isVisible = true - home_change_api_loading?.isFocusable = true - home_change_api_loading?.isFocusableInTouchMode = true - home_change_api?.isFocusable = true - home_change_api?.isFocusableInTouchMode = true - } - // home_bookmark_select?.isFocusable = true - // home_bookmark_select?.isFocusableInTouchMode = true - } else { - home_api_fab?.isVisible = true - home_change_api?.isVisible = false - home_change_api_loading?.isVisible = false + // just in case + if (isTvSettings()) { + home_api_fab?.isVisible = false + home_change_api?.isVisible = true + if (isTrueTvSettings()) { + home_change_api_loading?.isVisible = true + home_change_api_loading?.isFocusable = true + home_change_api_loading?.isFocusableInTouchMode = true + home_change_api?.isFocusable = true + home_change_api?.isFocusableInTouchMode = true } + // home_bookmark_select?.isFocusable = true + // home_bookmark_select?.isFocusableInTouchMode = true + } else { + home_api_fab?.isVisible = true + home_change_api?.isVisible = false + home_change_api_loading?.isVisible = false + } - for (syncApi in OAuth2Apis) { - val login = syncApi.loginInfo() - val pic = login?.profilePicture - if (home_profile_picture?.setImage( - pic, - errorImageDrawable = errorProfilePic - ) == true - ) { - home_profile_picture_holder?.isVisible = true - break - } + for (syncApi in OAuth2Apis) { + val login = syncApi.loginInfo() + val pic = login?.profilePicture + if (home_profile_picture?.setImage( + pic, + errorImageDrawable = errorProfilePic + ) == true + ) { + home_profile_picture_holder?.isVisible = true + break } } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt index 3fc1da24..23ab81ce 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeParentItemAdapter.kt @@ -29,7 +29,7 @@ class ParentItemAdapter( override fun onCreateViewHolder(parent: ViewGroup, i: Int): ParentViewHolder { //println("onCreateViewHolder $i") val layout = - if (parent.context.isTvSettings()) R.layout.homepage_parent_tv else R.layout.homepage_parent + if (isTvSettings()) R.layout.homepage_parent_tv else R.layout.homepage_parent return ParentViewHolder( LayoutInflater.from(parent.context).inflate(layout, parent, false), clickCallback, diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index 3e6e24cb..8f908465 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -993,7 +993,7 @@ class GeneratorPlayer : FullScreenPlayer() { savedInstanceState: Bundle? ): View? { // this is used instead of layout-television to follow the settings and some TV devices are not classified as TV for some reason - isTv = context?.isTvSettings() == true + isTv = isTvSettings() layout = if (isTv) R.layout.fragment_player_tv else R.layout.fragment_player diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerEpisodeAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerEpisodeAdapter.kt index 2ba47978..cfe27a30 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerEpisodeAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerEpisodeAdapter.kt @@ -124,7 +124,7 @@ class PlayerEpisodeAdapter( clickCallback.invoke(PlayerEpisodeClickEvent(0, card)) } - if (parentView.context.isTrueTvSettings()) { + if (isTrueTvSettings()) { parentView.isFocusable = true parentView.isFocusableInTouchMode = true parentView.touchscreenBlocksFocus = false diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt index 075e6cf5..a89e8279 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt @@ -166,7 +166,7 @@ class EpisodeAdapter( fun bind(card: ResultEpisode) { localCard = card - val isTrueTv = itemView.context?.isTrueTvSettings() == true + val isTrueTv = isTrueTvSettings() val (parentView, otherView) = if (card.poster == null) { itemView.episode_holder to itemView.episode_holder_large diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ImageAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ImageAdapter.kt index 35e372d6..ebd6a658 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ImageAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ImageAdapter.kt @@ -83,7 +83,7 @@ class ImageAdapter( this.nextFocusUpId = nextFocusUp } if (clickCallback != null) { - if (context.isTrueTvSettings()) { + if (isTrueTvSettings()) { isClickable = true isLongClickable = true isFocusable = true diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt index d47ebb4c..5fc61146 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt @@ -293,7 +293,7 @@ open class ResultFragment : ResultTrailerPlayer() { result_reload_connection_open_in_browser?.isVisible = true } 2 -> { - result_bookmark_fab?.isGone = result_bookmark_fab?.context?.isTvSettings() == true + result_bookmark_fab?.isGone = isTvSettings() result_bookmark_fab?.extend() //if (result_bookmark_button?.context?.isTrueTvSettings() == true) { // when { @@ -551,7 +551,7 @@ open class ResultFragment : ResultTrailerPlayer() { } // This is to band-aid FireTV navigation - val isTv = context?.isTvSettings() == true + val isTv = isTvSettings() result_season_button?.isFocusableInTouchMode = isTv result_episode_select?.isFocusableInTouchMode = isTv result_dub_select?.isFocusableInTouchMode = isTv @@ -794,7 +794,7 @@ open class ResultFragment : ResultTrailerPlayer() { result_next_airing_time.setText(d.nextAiringDate) result_poster.setImage(d.posterImage) - if (d.posterImage != null && context?.isTrueTvSettings() == false) + if (d.posterImage != null && !isTrueTvSettings()) result_poster_holder?.setOnClickListener { try { context?.let { ctx -> @@ -883,7 +883,7 @@ open class ResultFragment : ResultTrailerPlayer() { result_tag_holder?.isVisible = tags.isNotEmpty() if (tags.isNotEmpty()) { //result_tag_holder?.visibility = VISIBLE - val isOnTv = context?.isTrueTvSettings() == true + val isOnTv = isTrueTvSettings() for ((index, tag) in tags.withIndex()) { val viewBtt = layoutInflater.inflate(R.layout.result_tag, null) val btt = viewBtt.findViewById(R.id.result_tag_card) @@ -941,7 +941,7 @@ open class ResultFragment : ResultTrailerPlayer() { } // bloats the navigation on tv - if (context?.isTrueTvSettings() == false) { + if (!isTrueTvSettings()) { result_meta_site?.setOnClickListener { it.context?.openBrowser(storedData.url) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/SelectAdaptor.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/SelectAdaptor.kt index 74647ada..2e7ec529 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/SelectAdaptor.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/SelectAdaptor.kt @@ -85,7 +85,7 @@ class SelectAdaptor(val callback: (Any) -> Unit) : RecyclerView.Adapter Unit ) { - val isTrueTv = itemView.context?.isTrueTvSettings() == true + val isTrueTv = isTrueTvSettings() if (isTrueTv) { item.isFocusable = true item.isFocusableInTouchMode = true 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 74d81627..69f8a274 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 @@ -386,7 +386,7 @@ class SearchFragment : Fragment() { } } - if (context?.isTrueTvSettings() == true) { + if (isTrueTvSettings()) { search_filter.isFocusable = true search_filter.isFocusableInTouchMode = true } 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 bcabb268..3afbb8c0 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 @@ -164,7 +164,7 @@ object SearchResultBuilder { } } - if (bg.context.isTrueTvSettings()) { + if (isTrueTvSettings()) { bg.isFocusable = true bg.isFocusableInTouchMode = true bg.touchscreenBlocksFocus = false diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsAccount.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsAccount.kt index 971e630e..2554d6ee 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsAccount.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsAccount.kt @@ -117,7 +117,7 @@ class SettingsAccount : PreferenceFragmentCompat() { dialog.login_username_input to api.requiresUsername ) - if (activity.isTvSettings()) { + if (isTvSettings()) { visibilityMap.forEach { (input, isVisible) -> input.isVisible = isVisible diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt index 4c532e4c..7e26afb5 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt @@ -30,6 +30,9 @@ class SettingsFragment : Fragment() { companion object { var beneneCount = 0 + private var isTv : Boolean = false + private var isTrueTv : Boolean = false + fun PreferenceFragmentCompat?.getPref(id: Int): Preference? { if (this == null) return null @@ -45,7 +48,7 @@ class SettingsFragment : Fragment() { * On TV you cannot properly scroll to the bottom of settings, this fixes that. * */ fun PreferenceFragmentCompat.setPaddingBottom() { - if (this.context?.isTvSettings() == true) { + if (isTvSettings()) { listView?.setPadding(0, 0, 0, 100.toPx) } } @@ -93,7 +96,7 @@ class SettingsFragment : Fragment() { return settingsManager.getInt(this.getString(R.string.app_layout_key), -1) } - fun Context.isTvSettings(): Boolean { + private fun Context.isTvSettings(): Boolean { var value = getLayoutInt() if (value == -1) { value = if (isAutoTv()) 1 else 0 @@ -101,7 +104,7 @@ class SettingsFragment : Fragment() { return value == 1 || value == 2 } - fun Context.isTrueTvSettings(): Boolean { + private fun Context.isTrueTvSettings(): Boolean { var value = getLayoutInt() if (value == -1) { value = if (isAutoTv()) 1 else 0 @@ -109,6 +112,19 @@ class SettingsFragment : Fragment() { return value == 1 } + fun Context.updateTv() { + isTrueTv = isTrueTvSettings() + isTv = isTvSettings() + } + + fun isTrueTvSettings(): Boolean { + return isTrueTv + } + + fun isTvSettings(): Boolean { + return isTv + } + fun Context.isEmulatorSettings(): Boolean { return getLayoutInt() == 2 } @@ -136,7 +152,7 @@ class SettingsFragment : Fragment() { activity?.navigate(id, Bundle()) } - val isTrueTv = context?.isTrueTvSettings() == true + val isTrueTv = isTrueTvSettings() for (syncApi in accountManagers) { val login = syncApi.loginInfo() diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUI.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUI.kt index 9e85ab94..9ad3ee8f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUI.kt @@ -11,6 +11,7 @@ import com.lagradost.cloudstream3.ui.search.SearchResultBuilder import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar +import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.updateTv import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog @@ -22,6 +23,7 @@ class SettingsUI : PreferenceFragmentCompat() { setUpToolbar(R.string.category_ui) setPaddingBottom() } + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { hideKeyboard() setPreferencesFromResource(R.xml.settins_ui, rootKey) @@ -71,6 +73,7 @@ class SettingsUI : PreferenceFragmentCompat() { settingsManager.edit() .putInt(getString(R.string.app_layout_key), prefValues[it]) .apply() + context?.updateTv() activity?.recreate() } catch (e: Exception) { logError(e) @@ -130,7 +133,10 @@ class SettingsUI : PreferenceFragmentCompat() { getPref(R.string.pref_filter_search_quality_key)?.setOnPreferenceClickListener { val names = enumValues().sorted().map { it.name } - val currentList = settingsManager.getStringSet(getString(R.string.pref_filter_search_quality_key), setOf())?.map { + val currentList = settingsManager.getStringSet( + getString(R.string.pref_filter_search_quality_key), + setOf() + )?.map { it.toInt() } ?: listOf() 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 143794d1..267dda60 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 @@ -11,6 +11,7 @@ import android.view.ViewGroup import android.widget.LinearLayout import android.widget.Toast import androidx.appcompat.app.AlertDialog +import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels @@ -23,12 +24,14 @@ import com.lagradost.cloudstream3.mvvm.Some import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.plugins.RepositoryManager import com.lagradost.cloudstream3.ui.result.setText +import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar import com.lagradost.cloudstream3.utils.AppUtils.downloadAllPluginsDialog import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe +import com.lagradost.cloudstream3.widget.LinearRecycleViewLayoutManager import kotlinx.android.synthetic.main.add_repo_input.* import kotlinx.android.synthetic.main.fragment_extensions.* import kotlinx.android.synthetic.main.fragment_extensions.list_repositories @@ -119,9 +122,15 @@ class ExtensionsFragment : Fragment() { (repo_recycler_view?.adapter as? RepoAdapter)?.updateList(it) } + repo_recycler_view?.apply { + context?.let { ctx -> + layoutManager = LinearRecycleViewLayoutManager(ctx, nextFocusUpId, nextFocusDownId) + } + } + list_repositories?.setOnClickListener { // Open webview on tv if browser fails - val isTv = it.context.isTvSettings() + val isTv = isTvSettings() openBrowser(PUBLIC_REPOSITORIES_LIST, isTv, this) // Set clipboard on TV because the browser might not exist or work properly @@ -170,9 +179,9 @@ class ExtensionsFragment : Fragment() { ) } - add_repo_button?.setOnClickListener { + val addRepositoryClick = View.OnClickListener { val builder = - AlertDialog.Builder(context ?: return@setOnClickListener, R.style.AlertDialogCustom) + AlertDialog.Builder(context ?: return@OnClickListener, R.style.AlertDialogCustom) .setView(R.layout.add_repo_input) val dialog = builder.create() @@ -193,8 +202,7 @@ class ExtensionsFragment : Fragment() { dialog.list_repositories?.setOnClickListener { // Open webview on tv if browser fails - val isTv = it.context.isTvSettings() - openBrowser(PUBLIC_REPOSITORIES_LIST, isTv, this) + openBrowser(PUBLIC_REPOSITORIES_LIST, isTvSettings(), this) } // dialog.text2?.text = provider.name @@ -223,6 +231,12 @@ class ExtensionsFragment : Fragment() { } } + val isTv = isTrueTvSettings() + add_repo_button?.isGone = isTv + add_repo_button_imageview_holder?.isVisible = isTv + add_repo_button?.setOnClickListener(addRepositoryClick) + add_repo_button_imageview?.setOnClickListener(addRepositoryClick) + reloadRepositories() } } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginAdapter.kt index e46c1508..75e7023e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginAdapter.kt @@ -14,6 +14,7 @@ import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.plugins.PluginManager import com.lagradost.cloudstream3.ui.result.setText import com.lagradost.cloudstream3.ui.result.txt +import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings import com.lagradost.cloudstream3.utils.AppUtils.html import com.lagradost.cloudstream3.utils.GlideApp import com.lagradost.cloudstream3.utils.SubtitleHelper.fromTwoLettersToLanguage @@ -36,8 +37,9 @@ class PluginAdapter( private val plugins: MutableList = mutableListOf() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + val layout = if(isTrueTvSettings()) R.layout.repository_item_tv else R.layout.repository_item return PluginViewHolder( - LayoutInflater.from(parent.context).inflate(R.layout.repository_item, parent, false) + LayoutInflater.from(parent.context).inflate(layout, parent, false) ) } @@ -123,7 +125,6 @@ class PluginAdapter( itemView.action_button?.setOnClickListener { iconClickCallback.invoke(data.plugin) } - testFindClosestBase2() //if (itemView.context?.isTrueTvSettings() == false) { // val siteUrl = metadata.repositoryUrl // if (siteUrl != null && siteUrl.isNotBlank() && siteUrl != "NONE") { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsFragment.kt index 0ee0615a..7b944f62 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginsFragment.kt @@ -128,7 +128,7 @@ class PluginsFragment : Fragment() { pluginViewModel.handlePluginAction(activity, url, it, isLocal) } - if (context?.isTvSettings() == true) { + if (isTvSettings()) { // Scrolling down does not reveal the whole RecyclerView on TV, add to bypass that. plugin_recycler_view?.setPadding(0, 0, 0, 200.toPx) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/RepoAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/RepoAdapter.kt index 15c54687..2dc302ee 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/RepoAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/RepoAdapter.kt @@ -7,6 +7,7 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.plugins.RepositoryManager.PREBUILT_REPOSITORIES +import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings import kotlinx.android.synthetic.main.repository_item.view.* class RepoAdapter( @@ -19,8 +20,9 @@ class RepoAdapter( private val repositories: MutableList = mutableListOf() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + val layout = if(isTrueTvSettings()) R.layout.repository_item_tv else R.layout.repository_item return RepoViewHolder( - LayoutInflater.from(parent.context).inflate(R.layout.repository_item, parent, false) + LayoutInflater.from(parent.context).inflate(layout, parent, false) ) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/setup/SetupFragmentExtensions.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/setup/SetupFragmentExtensions.kt index a3ea9b2a..43037038 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/setup/SetupFragmentExtensions.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/setup/SetupFragmentExtensions.kt @@ -73,8 +73,7 @@ class SetupFragmentExtensions : Fragment() { } else { list_repositories?.setOnClickListener { // Open webview on tv if browser fails - val isTv = it.context.isTvSettings() - openBrowser(PUBLIC_REPOSITORIES_LIST, isTv, this) + openBrowser(PUBLIC_REPOSITORIES_LIST, isTvSettings(), this) } } } @@ -86,8 +85,7 @@ class SetupFragmentExtensions : Fragment() { val isSetup = arguments?.getBoolean(SETUP_EXTENSION_BUNDLE_IS_SETUP) ?: false view_public_repositories_button?.setOnClickListener { - val isTv = it.context.isTvSettings() - openBrowser(PUBLIC_REPOSITORIES_LIST, isTv, this) + openBrowser(PUBLIC_REPOSITORIES_LIST, isTvSettings(), this) } with(context) { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/ChromecastSubtitlesFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/ChromecastSubtitlesFragment.kt index 957b1d9b..83d134cb 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/ChromecastSubtitlesFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/ChromecastSubtitlesFragment.kt @@ -164,7 +164,7 @@ class ChromecastSubtitlesFragment : Fragment() { state = getCurrentSavedStyle() context?.updateState() - val isTvSettings = context?.isTvSettings() == true + val isTvSettings = isTvSettings() fun View.setFocusableInTv() { this.isFocusableInTouchMode = isTvSettings diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt index 8095b007..b1d82b76 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt @@ -243,7 +243,7 @@ class SubtitlesFragment : Fragment() { state = getCurrentSavedStyle() context?.updateState() - val isTvTrueSettings = context?.isTrueTvSettings() == true + val isTvTrueSettings = isTrueTvSettings() fun View.setFocusableInTv() { this.isFocusableInTouchMode = isTvTrueSettings 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 fa39e374..1c7bb214 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/AppUtils.kt @@ -407,8 +407,8 @@ object AppUtils { //private val viewModel: ResultViewModel by activityViewModels() - private fun getResultsId(context: Context): Int { - return if (context.isTrueTvSettings()) { + private fun getResultsId(): Int { + return if (isTrueTvSettings()) { R.id.global_to_navigation_results_tv } else { R.id.global_to_navigation_results_phone @@ -424,7 +424,7 @@ object AppUtils { this.runOnUiThread { // viewModelStore.clear() this.navigate( - getResultsId(this.applicationContext ?: return@runOnUiThread), + getResultsId(), ResultFragment.newInstance(url, apiName, startAction, startValue) ) } @@ -438,7 +438,7 @@ object AppUtils { this?.runOnUiThread { // viewModelStore.clear() this.navigate( - getResultsId(this), + getResultsId(), ResultFragment.newInstance(card, startAction, startValue) ) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/SingleSelectionHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/SingleSelectionHelper.kt index b228fe77..b3bce446 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/SingleSelectionHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/SingleSelectionHelper.kt @@ -44,7 +44,7 @@ object SingleSelectionHelper { ) { if (this == null) return - if (this.isTvSettings()) { + if (isTvSettings()) { val builder = AlertDialog.Builder(this, R.style.AlertDialogCustom) .setView(R.layout.options_popup_tv) diff --git a/app/src/main/java/com/lagradost/cloudstream3/widget/LinearRecycleViewLayoutManager.kt b/app/src/main/java/com/lagradost/cloudstream3/widget/LinearRecycleViewLayoutManager.kt new file mode 100644 index 00000000..4df8e086 --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/widget/LinearRecycleViewLayoutManager.kt @@ -0,0 +1,30 @@ +package com.lagradost.cloudstream3.widget + +import android.content.Context +import android.view.View +import androidx.recyclerview.widget.LinearLayoutManager + +class LinearRecycleViewLayoutManager( + val context: Context, + val nextFocusUp: Int, + val nextFocusDown: Int +) : LinearLayoutManager(context) { + override fun onInterceptFocusSearch(focused: View, direction: Int): View? { + return try { + val position = getPosition(focused) + val count = itemCount + //println("onInterceptFocusSearch position=$position count=$count focused=$focused direction=$direction") + + (if (position == count - 1 && direction == View.FOCUS_DOWN) { + focused.rootView.findViewById(nextFocusDown) + } else if (position == 0 && direction == View.FOCUS_UP) { + focused.rootView.findViewById(nextFocusUp) + } else { + super.onInterceptFocusSearch(focused, direction) + }) ?: super.onInterceptFocusSearch(focused, direction) + } catch (t : Throwable) { + super.onInterceptFocusSearch(focused, direction) + } + } +} + diff --git a/app/src/main/res/layout/add_repo_input.xml b/app/src/main/res/layout/add_repo_input.xml index 0e8b72aa..445e71ec 100644 --- a/app/src/main/res/layout/add_repo_input.xml +++ b/app/src/main/res/layout/add_repo_input.xml @@ -29,7 +29,10 @@ android:textStyle="bold" /> + android:orientation="vertical" + tools:visibility="gone"> - - + android:orientation="horizontal"> - - - - - - - - - - + + + android:text="@string/extensions" + android:textColor="?attr/textColor" /> - + + + + + + + + + + android:orientation="horizontal"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file