From 3ac462ae9625f8a546e0c95f947da00c6283eba3 Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Sat, 12 Aug 2023 21:20:51 +0200 Subject: [PATCH] changed UI a bit for flashbang + fixed crash inf loading bug --- app/build.gradle.kts | 2 +- .../lagradost/cloudstream3/MainActivity.kt | 30 ++-- .../cloudstream3/ui/home/HomeFragment.kt | 23 ++- .../ui/home/HomeParentItemAdapterPreview.kt | 55 +++---- .../cloudstream3/ui/home/HomeViewModel.kt | 3 +- .../ui/settings/SettingsUpdates.kt | 4 +- .../lagradost/cloudstream3/utils/UIHelper.kt | 7 +- .../res/color/player_on_button_tv_attr.xml | 5 + app/src/main/res/color/white_attr_20.xml | 4 + .../res/drawable/player_button_tv_attr.xml | 15 ++ .../drawable/player_button_tv_attr_no_bg.xml | 9 ++ app/src/main/res/layout/fragment_home.xml | 47 ++++-- .../main/res/layout/fragment_home_head.xml | 24 ++-- .../main/res/layout/fragment_home_head_tv.xml | 135 +++++++++++------- app/src/main/res/layout/fragment_home_tv.xml | 52 ++++--- app/src/main/res/values/attrs.xml | 1 + app/src/main/res/values/colors.xml | 1 - app/src/main/res/values/strings.xml | 1 - app/src/main/res/values/styles.xml | 19 ++- 19 files changed, 252 insertions(+), 185 deletions(-) create mode 100644 app/src/main/res/color/player_on_button_tv_attr.xml create mode 100644 app/src/main/res/color/white_attr_20.xml create mode 100644 app/src/main/res/drawable/player_button_tv_attr.xml create mode 100644 app/src/main/res/drawable/player_button_tv_attr_no_bg.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9300775c..cfe89c05 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -51,7 +51,7 @@ android { targetSdk = 33 versionCode = 59 - versionName = "4.1.2" + versionName = "4.1.3" resValue("string", "app_version", "${defaultConfig.versionName}${versionNameSuffix ?: ""}") diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index d6e275ed..a8160d33 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -278,7 +278,7 @@ var app = Requests(responseParser = object : ResponseParser { class MainActivity : AppCompatActivity(), ColorPickerDialogListener { companion object { const val TAG = "MAINACT" - + var lastError: String? = null /** * Setting this will automatically enter the query in the search * next time the search fragment is opened. @@ -599,22 +599,9 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { } override fun dispatchKeyEvent(event: KeyEvent?): Boolean { - val start = System.currentTimeMillis() - try { - val response = CommonActivity.dispatchKeyEvent(this, event) - - if (response != null) - return response - } finally { - debugAssert({ - val end = System.currentTimeMillis() - val delta = end - start - delta > 100 - }) { - "Took over 100ms to navigate, smth is VERY wrong" - } - } - + val response = CommonActivity.dispatchKeyEvent(this, event) + if (response != null) + return response return super.dispatchKeyEvent(event) } @@ -1054,10 +1041,11 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) val errorFile = filesDir.resolve("last_error") - var lastError: String? = null if (errorFile.exists() && errorFile.isFile) { lastError = errorFile.readText(Charset.defaultCharset()) errorFile.delete() + } else { + lastError = null } val settingsForProvider = SettingsJson() @@ -1167,16 +1155,16 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { } //Automatically download not existing plugins, using mode specified. - val auto_download_plugin = AutoDownloadMode.getEnum( + val autoDownloadPlugin = AutoDownloadMode.getEnum( settingsManager.getInt( getString(R.string.auto_download_plugins_key), 0 ) ) ?: AutoDownloadMode.Disable - if (auto_download_plugin != AutoDownloadMode.Disable) { + if (autoDownloadPlugin != AutoDownloadMode.Disable) { PluginManager.downloadNotExistingPluginsAndLoad( this@MainActivity, - auto_download_plugin + autoDownloadPlugin ) } } 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 6f9a1654..fa0b6dfb 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 @@ -513,9 +513,13 @@ class HomeFragment : Fragment() { fixGrid() binding?.apply { - homeChangeApiLoading.setOnClickListener(apiChangeClickListener) + //homeChangeApiLoading.setOnClickListener(apiChangeClickListener) //homeChangeApiLoading.setOnClickListener(apiChangeClickListener) homeApiFab.setOnClickListener(apiChangeClickListener) + homeChangeApi.setOnClickListener(apiChangeClickListener) + homeSwitchAccount.setOnClickListener { v -> + DataStoreHelper.showWhoIsWatching(v?.context ?: return@setOnClickListener) + } homeRandom.setOnClickListener { if (listHomepageItems.isNotEmpty()) { activity.loadSearchResult(listHomepageItems.random()) @@ -527,21 +531,9 @@ class HomeFragment : Fragment() { mutableListOf(), homeViewModel ) - fixPaddingStatusbar(homeLoadingStatusbar) + //fixPaddingStatusbar(homeLoadingStatusbar) - if (isTvSettings()) { - homeApiFab.isVisible = false - if (isTrueTvSettings()) { - homeChangeApiLoading.isVisible = true - homeChangeApiLoading.isFocusable = true - homeChangeApiLoading.isFocusableInTouchMode = true - } - // home_bookmark_select?.isFocusable = true - // home_bookmark_select?.isFocusableInTouchMode = true - } else { - homeApiFab.isVisible = true - homeChangeApiLoading.isVisible = false - } + homeApiFab.isVisible = !isTvSettings() homeMasterRecycler.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { @@ -574,6 +566,7 @@ class HomeFragment : Fragment() { observe(homeViewModel.apiName) { apiName -> currentApiName = apiName binding?.homeApiFab?.text = apiName + binding?.homeChangeApi?.text = apiName } observe(homeViewModel.page) { data -> 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 1684dfe5..943f784a 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 @@ -3,7 +3,6 @@ package com.lagradost.cloudstream3.ui.home import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.FrameLayout import androidx.appcompat.widget.SearchView import androidx.core.content.ContextCompat import androidx.core.view.isGone @@ -13,7 +12,6 @@ import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding import androidx.viewpager2.widget.ViewPager2 import com.google.android.material.chip.Chip -import com.google.android.material.chip.ChipDrawable import com.google.android.material.chip.ChipGroup import com.lagradost.cloudstream3.APIHolder.getId import com.lagradost.cloudstream3.AcraApplication.Companion.getActivity @@ -41,10 +39,9 @@ import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSet import com.lagradost.cloudstream3.utils.DataStoreHelper import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showOptionSelectStringRes -import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbarMargin import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbarView -import com.lagradost.cloudstream3.utils.UIHelper.setImage +import com.lagradost.cloudstream3.utils.UIHelper.populateChips class HomeParentItemAdapterPreview( items: MutableList, @@ -245,7 +242,11 @@ class HomeParentItemAdapterPreview( private val previewViewpager: ViewPager2 = itemView.findViewById(R.id.home_preview_viewpager) - private val previewHeader: FrameLayout = itemView.findViewById(R.id.home_preview) + + private val previewViewpagerText: ViewGroup = + itemView.findViewById(R.id.home_preview_viewpager_text) + + // private val previewHeader: FrameLayout = itemView.findViewById(R.id.home_preview) private var resumeHolder: View = itemView.findViewById(R.id.home_watch_holder) private var resumeRecyclerView: RecyclerView = itemView.findViewById(R.id.home_watch_child_recyclerview) @@ -254,7 +255,7 @@ class HomeParentItemAdapterPreview( itemView.findViewById(R.id.home_bookmarked_child_recyclerview) private var homeAccount: View? = - itemView.findViewById(R.id.home_switch_account) + itemView.findViewById(R.id.home_preview_switch_account) private var topPadding : View? = itemView.findViewById(R.id.home_padding) @@ -282,26 +283,8 @@ class HomeParentItemAdapterPreview( item.plot ?: "" homePreviewText.text = item.name - homePreviewTags.apply { - removeAllViews() - item.tags?.forEach { tag -> - val chip = Chip(context) - val chipDrawable = - ChipDrawable.createFromAttributes( - context, - null, - 0, - R.style.ChipFilledSemiTransparent - ) - chip.setChipDrawable(chipDrawable) - chip.text = tag - chip.isChecked = false - chip.isCheckable = false - chip.isFocusable = false - chip.isClickable = false - addView(chip) - } - } + populateChips(homePreviewTags,item.tags ?: emptyList(), R.style.ChipFilledSemiTransparent) + homePreviewTags.isGone = item.tags.isNullOrEmpty() @@ -324,7 +307,7 @@ class HomeParentItemAdapterPreview( } (binding as? FragmentHomeHeadBinding)?.apply { - homePreviewImage.setImage(item.posterUrl, item.posterHeaders) + //homePreviewImage.setImage(item.posterUrl, item.posterHeaders) homePreviewPlay.setOnClickListener { view -> viewModel.click( @@ -402,7 +385,6 @@ class HomeParentItemAdapterPreview( if (binding is FragmentHomeHeadTvBinding) { observe(viewModel.apiName) { name -> binding.homePreviewChangeApi.text = name - binding.homePreviewChangeApi2.text = name } } observe(viewModel.resumeWatching) { @@ -468,11 +450,6 @@ class HomeParentItemAdapterPreview( viewModel.loadAndCancel(api, forceReload = true, fromUI = true) } } - homePreviewChangeApi2.setOnClickListener { view -> - view.context.selectHomepage(viewModel.repo?.name) { api -> - viewModel.loadAndCancel(api, forceReload = true, fromUI = true) - } - } // 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 @@ -517,10 +494,6 @@ class HomeParentItemAdapterPreview( } private fun updatePreview(preview: Resource>>) { - if (binding is FragmentHomeHeadTvBinding) { - binding.homePreviewChangeApi2.isGone = preview is Resource.Success - } - if (preview is Resource.Success) { homeNonePadding.apply { val params = layoutParams @@ -545,14 +518,18 @@ class HomeParentItemAdapterPreview( previewViewpager.fakeDragBy(1f) previewViewpager.endFakeDrag() previewCallback.onPageSelected(0) - previewHeader.isVisible = true + previewViewpager.isVisible = true + previewViewpagerText.isVisible = true + //previewHeader.isVisible = true } } else -> { previewAdapter.setItems(listOf(), false) previewViewpager.setCurrentItem(0, false) - previewHeader.isVisible = false + previewViewpager.isVisible = false + previewViewpagerText.isVisible = false + //previewHeader.isVisible = false } } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt index a2dc9821..b1ced59e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt @@ -18,6 +18,7 @@ import com.lagradost.cloudstream3.HomePageList import com.lagradost.cloudstream3.LoadResponse import com.lagradost.cloudstream3.MainAPI import com.lagradost.cloudstream3.MainActivity +import com.lagradost.cloudstream3.MainActivity.Companion.lastError import com.lagradost.cloudstream3.SearchResponse import com.lagradost.cloudstream3.amap import com.lagradost.cloudstream3.mvvm.Resource @@ -484,7 +485,7 @@ class HomeViewModel : ViewModel() { } else if (api == null) { // API is not found aka not loaded or removed, post the loading // progress if waiting for plugins, otherwise nothing - if(PluginManager.loadedLocalPlugins) { + if(PluginManager.loadedLocalPlugins || PluginManager.checkSafeModeFile() || lastError != null) { loadAndCancel(noneApi) } else { _page.postValue(Resource.Loading()) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt index 9227409d..c304629a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt @@ -177,7 +177,7 @@ class SettingsUpdates : PreferenceFragmentCompat() { val prefNames = resources.getStringArray(R.array.auto_download_plugin) val prefValues = enumValues().sortedBy { x -> x.value }.map { x -> x.value } - val current = settingsManager.getInt(getString(R.string.auto_download_plugins_pref), 0) + val current = settingsManager.getInt(getString(R.string.auto_download_plugins_key), 0) activity?.showBottomDialog( prefNames.toList(), @@ -185,7 +185,7 @@ class SettingsUpdates : PreferenceFragmentCompat() { getString(R.string.automatic_plugin_download_mode_title), true, {}) { - settingsManager.edit().putInt(getString(R.string.auto_download_plugins_pref), prefValues[it]).apply() + settingsManager.edit().putInt(getString(R.string.auto_download_plugins_key), prefValues[it]).apply() (context ?: AcraApplication.context)?.let { ctx -> app.initClient(ctx) } } return@setOnPreferenceClickListener true 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 5a393ed5..038a2f11 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt @@ -24,6 +24,7 @@ import androidx.annotation.AttrRes import androidx.annotation.ColorInt import androidx.annotation.DrawableRes import androidx.annotation.IdRes +import androidx.annotation.StyleRes import androidx.appcompat.view.ContextThemeWrapper import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.widget.PopupMenu @@ -81,7 +82,7 @@ object UIHelper { || Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) } - fun populateChips(view: ChipGroup?, tags: List) { + fun populateChips(view: ChipGroup?, tags: List, @StyleRes style : Int = R.style.ChipFilled) { if (view == null) return view.removeAllViews() val context = view.context ?: return @@ -92,7 +93,7 @@ object UIHelper { context, null, 0, - R.style.ChipFilled + style ) chip.setChipDrawable(chipDrawable) chip.text = tag @@ -100,7 +101,7 @@ object UIHelper { chip.isCheckable = false chip.isFocusable = false chip.isClickable = false - chip.setTextColor(context.colorFromAttribute(R.attr.textColor)) + chip.setTextColor(context.colorFromAttribute(R.attr.white)) view.addView(chip) } } diff --git a/app/src/main/res/color/player_on_button_tv_attr.xml b/app/src/main/res/color/player_on_button_tv_attr.xml new file mode 100644 index 00000000..feb1eeb0 --- /dev/null +++ b/app/src/main/res/color/player_on_button_tv_attr.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/color/white_attr_20.xml b/app/src/main/res/color/white_attr_20.xml new file mode 100644 index 00000000..e0237df0 --- /dev/null +++ b/app/src/main/res/color/white_attr_20.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/player_button_tv_attr.xml b/app/src/main/res/drawable/player_button_tv_attr.xml new file mode 100644 index 00000000..4c90a64e --- /dev/null +++ b/app/src/main/res/drawable/player_button_tv_attr.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/player_button_tv_attr_no_bg.xml b/app/src/main/res/drawable/player_button_tv_attr_no_bg.xml new file mode 100644 index 00000000..b9b927da --- /dev/null +++ b/app/src/main/res/drawable/player_button_tv_attr_no_bg.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index eb38e262..672a6d21 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -13,7 +13,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" - tools:visibility="gone"> + tools:visibility="visible"> - + + + - + android:contentDescription="@string/account" + android:nextFocusLeft="@id/home_search" + android:padding="10dp" + android:src="@drawable/ic_outline_account_circle_24" /> + + tools:listitem="@layout/homepage_parent" + tools:visibility="gone" /> @@ -26,15 +26,6 @@ - - @@ -150,6 +141,7 @@ app:tint="?attr/white" /> + 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 d2c20bc4..03766d79 100644 --- a/app/src/main/res/layout/fragment_home_head_tv.xml +++ b/app/src/main/res/layout/fragment_home_head_tv.xml @@ -15,7 +15,6 @@ android:layout_height="0dp" /> @@ -28,7 +27,44 @@ - + + + + + + + + + - - - + + + tools:visibility="visible"> - + + + + - + android:padding="10dp" + android:src="@drawable/ic_outline_account_circle_24" + android:tag="@string/tv_no_focus_tag" + app:tint="@color/player_on_button_tv_attr" /> + - + tools:listitem="@layout/homepage_parent_tv" + tools:visibility="gone" /> + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 7dd4c989..d9258c40 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -13,7 +13,6 @@ #161616 #e9eaee - #1AFFFFFF #9ba0a4 #DCDCDC diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 74515fbf..c80e0e76 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -7,7 +7,6 @@ auto_update auto_update_plugins auto_download_plugins_key - auto_download_plugins_pref skip_update_key prerelease_update manual_check_update diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 3ef56c22..e2f11221 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -62,7 +62,8 @@ @color/iconGrayBackground @color/boxItemBackground @color/iconColor - #FFF + @color/white + @color/black @style/CustomPreferenceThemeOverlay @@ -99,7 +100,7 @@ @@ -117,6 +118,7 @@ @color/textColor @color/grayTextColor @color/white + @color/black @color/whiteText @@ -158,7 +160,9 @@ @color/lightItemBackground @color/lightTextColor @color/lightGrayTextColor - #000 + @color/black + @color/white + @color/blackText @@ -170,6 +174,7 @@ @color/material_dynamic_neutral90 @color/material_dynamic_neutral60 @color/material_dynamic_neutral90 + @color/material_dynamic_neutral10 @color/material_on_primary_emphasis_medium @@ -747,13 +752,13 @@ @null @color/transparent @null - @drawable/player_button_tv + @drawable/player_button_tv_attr @color/white @color/transparent - @color/player_on_button_tv - @color/player_on_button_tv - @color/player_on_button_tv + @color/player_on_button_tv_attr + @color/player_on_button_tv_attr + @color/player_on_button_tv_attr wrap_content 40dp 16dp