From 59e318a74228d7a2337f5d2da5e7ef4e47ac7f9a Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Fri, 18 Feb 2022 20:54:55 +0100 Subject: [PATCH] emulator layout statusbar fix + fixed #674 --- .../lagradost/cloudstream3/MainActivity.kt | 4 ++ .../cloudstream3/ui/AutofitRecyclerView.kt | 2 - .../ui/search/SearchResultBuilder.kt | 61 +++++++++++++++---- .../ui/settings/SettingsFragment.kt | 4 ++ .../lagradost/cloudstream3/utils/UIHelper.kt | 11 ++-- 5 files changed, 63 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 42ff34c4..f81f9965 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -34,6 +34,7 @@ import com.lagradost.cloudstream3.syncproviders.OAuth2API.Companion.appString import com.lagradost.cloudstream3.ui.APIRepository import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO import com.lagradost.cloudstream3.ui.result.ResultFragment +import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isEmulatorSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings import com.lagradost.cloudstream3.utils.AppUtils.isCastApiAvailable import com.lagradost.cloudstream3.utils.AppUtils.loadCache @@ -42,6 +43,7 @@ import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.removeKey import com.lagradost.cloudstream3.utils.DataStoreHelper.setViewPos import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate +import com.lagradost.cloudstream3.utils.UIHelper.changeStatusBarState import com.lagradost.cloudstream3.utils.UIHelper.checkWrite import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute import com.lagradost.cloudstream3.utils.UIHelper.getResourceColor @@ -293,6 +295,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { setContentView(R.layout.activity_main) } + changeStatusBarState(isEmulatorSettings()) + // val navView: BottomNavigationView = findViewById(R.id.nav_view) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/AutofitRecyclerView.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/AutofitRecyclerView.kt index 7aa920b6..48f82022 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/AutofitRecyclerView.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/AutofitRecyclerView.kt @@ -62,8 +62,6 @@ class GrdLayoutManager(val context: Context, private val spanCoun: Int) : GridLa } private fun calcOffsetToNextView(direction: Int): Int { - println("calc") - val spanCount = this.spanCoun val orientation = this.orientation 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 10d94ed8..67b6aacd 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 @@ -53,17 +53,49 @@ object SearchResultBuilder { cardView.setImageResource(R.drawable.default_cover) } - bg.setOnClickListener { + fun click(view: View?) { clickCallback.invoke( SearchClickCallback( if (card is DataStoreHelper.ResumeWatchingResult) SEARCH_ACTION_PLAY_FILE else SEARCH_ACTION_LOAD, - it, + view ?: return, position, card ) ) } + fun longClick(view: View?) { + clickCallback.invoke( + SearchClickCallback( + SEARCH_ACTION_SHOW_METADATA, + view ?: return, + position, + card + ) + ) + } + + fun focus(view: View?, focus: Boolean) { + if (focus) { + clickCallback.invoke( + SearchClickCallback( + SEARCH_ACTION_FOCUSED, + view ?: return, + position, + card + ) + ) + } + } + + bg.setOnClickListener { + click(it) + } + + itemView.setOnClickListener { + click(it) + } + if (nextFocusUp != null) { bg.nextFocusUpId = nextFocusUp } @@ -90,23 +122,23 @@ object SearchResultBuilder { } bg.setOnLongClickListener { - clickCallback.invoke(SearchClickCallback(SEARCH_ACTION_SHOW_METADATA, it, position, card)) + longClick(it) return@setOnLongClickListener true } + itemView.setOnLongClickListener { - clickCallback.invoke(SearchClickCallback(SEARCH_ACTION_SHOW_METADATA, it, position, card)) + longClick(it) return@setOnLongClickListener true } + bg.setOnFocusChangeListener { view, b -> - if (b) { - clickCallback.invoke(SearchClickCallback(SEARCH_ACTION_FOCUSED, view, position, card)) - } + focus(view, b) } + itemView.setOnFocusChangeListener { view, b -> - if (b) { - clickCallback.invoke(SearchClickCallback(SEARCH_ACTION_FOCUSED, view, position, card)) - } + focus(view, b) } + when (card) { is DataStoreHelper.ResumeWatchingResult -> { val pos = card.watchPos?.fixVisual() @@ -119,7 +151,8 @@ object SearchResultBuilder { playImg?.visibility = View.VISIBLE if (!card.type.isMovieType()) { - cardText?.text = cardText?.context?.getNameFull(card.name, card.episode, card.season) + cardText?.text = + cardText?.context?.getNameFull(card.name, card.episode, card.season) } } is AnimeSearchResponse -> { @@ -135,7 +168,8 @@ object SearchResultBuilder { textIsDub?.apply { val dubText = context.getString(R.string.app_dubbed_text) text = if (card.dubEpisodes != null && card.dubEpisodes > 0) { - context.getString(R.string.app_dub_sub_episode_text_format).format(dubText, card.dubEpisodes) + context.getString(R.string.app_dub_sub_episode_text_format) + .format(dubText, card.dubEpisodes) } else { dubText } @@ -144,7 +178,8 @@ object SearchResultBuilder { textIsSub?.apply { val subText = context.getString(R.string.app_subbed_text) text = if (card.subEpisodes != null && card.subEpisodes > 0) { - context.getString(R.string.app_dub_sub_episode_text_format).format(subText, card.subEpisodes) + context.getString(R.string.app_dub_sub_episode_text_format) + .format(subText, card.subEpisodes) } else { subText } 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 812afb20..606e1464 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 @@ -74,6 +74,10 @@ class SettingsFragment : PreferenceFragmentCompat() { return getLayoutInt() == 1 } + fun Context.isEmulatorSettings() : Boolean { + return getLayoutInt() == 2 + } + private fun Context.isAutoTv(): Boolean { val uiModeManager = getSystemService(Context.UI_MODE_SERVICE) as UiModeManager? return uiModeManager?.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt index 7ad29aed..aedbe2e8 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt @@ -39,6 +39,7 @@ import com.bumptech.glide.load.model.GlideUrl import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.mvvm.logError +import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isEmulatorSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings import com.lagradost.cloudstream3.utils.GlideOptions.bitmapTransform import jp.wasabeef.glide.transformations.BlurTransformation @@ -313,10 +314,12 @@ object UIHelper { // Shows the system bars by removing all the flags // except for the ones that make the content appear under the system bars. fun Activity.showSystemUI() { - window.decorView.systemUiVisibility = ( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE - or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - ) // or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + window.decorView.systemUiVisibility = + + (View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) + + changeStatusBarState(isEmulatorSettings()) + // window.clearFlags(View.KEEP_SCREEN_ON) }