From 627dd1776b7da5fd5d9a795e778778537b3a32a3 Mon Sep 17 00:00:00 2001 From: LagradOst Date: Sat, 9 Oct 2021 23:59:37 +0200 Subject: [PATCH] better dpad support and bug fix --- .../cloudstream3/ui/AutofitRecyclerView.kt | 10 +- .../cloudstream3/ui/home/HomeFragment.kt | 2 +- .../cloudstream3/ui/home/HomeViewModel.kt | 4 +- .../cloudstream3/ui/result/ResultFragment.kt | 2 + .../ui/subtitles/SubtitlesFragment.kt | 6 +- .../lagradost/cloudstream3/utils/UIHelper.kt | 42 ++---- app/src/main/res/drawable/outline.xml | 10 ++ .../main/res/drawable/outline_drawable.xml | 5 + .../res/layout/bottom_selection_dialog.xml | 3 + .../res/layout/download_child_episode.xml | 30 ++-- .../res/layout/download_header_episode.xml | 2 +- .../res/layout/fragment_child_downloads.xml | 2 + .../main/res/layout/fragment_downloads.xml | 2 + app/src/main/res/layout/fragment_home.xml | 39 +++++- app/src/main/res/layout/fragment_result.xml | 129 +++++++++++------- app/src/main/res/layout/fragment_search.xml | 14 ++ .../res/layout/home_episodes_expanded.xml | 5 + app/src/main/res/layout/home_result_grid.xml | 2 +- app/src/main/res/layout/homepage_parent.xml | 4 + .../main/res/layout/player_custom_layout.xml | 50 ++++++- .../layout/player_select_source_and_subs.xml | 19 ++- .../main/res/layout/player_select_speed.xml | 33 ----- app/src/main/res/layout/provider_list.xml | 24 +++- app/src/main/res/layout/result_episode.xml | 18 ++- .../main/res/layout/result_episode_large.xml | 23 +++- .../main/res/layout/search_result_grid.xml | 23 ++-- app/src/main/res/values/styles.xml | 15 +- 27 files changed, 344 insertions(+), 174 deletions(-) create mode 100644 app/src/main/res/drawable/outline.xml create mode 100644 app/src/main/res/drawable/outline_drawable.xml delete mode 100644 app/src/main/res/layout/player_select_speed.xml 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 ef9332ea..26e4d07b 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/AutofitRecyclerView.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/AutofitRecyclerView.kt @@ -117,6 +117,7 @@ class GrdLayoutManager(val context: Context, val spanCoun: Int) : GridLayoutMana } } +// https://riptutorial.com/android/example/4810/gridlayoutmanager-with-dynamic-span-count class AutofitRecyclerView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : RecyclerView(context, attrs) { @@ -145,13 +146,4 @@ class AutofitRecyclerView @JvmOverloads constructor(context: Context, attrs: Att layoutManager = manager } - - - /*override fun onMeasure(widthSpec: Int, heightSpec: Int) { - super.onMeasure(widthSpec, heightSpec) - if (spanCount == 0 && columnWidth > 0) { - val count = max(1, measuredWidth / columnWidth) - spanCount = count - } - }*/ } \ No newline at end of file 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 9a347d2b..03d1498b 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 @@ -406,7 +406,7 @@ class HomeFragment : Fragment() { reloadStored() val apiName = context?.getKey(HOMEPAGE_API) - if(homeViewModel.apiName.value != apiName) { + if(homeViewModel.apiName.value != apiName || apiName == null) { println("Caught home: " + homeViewModel.apiName.value + " at " + apiName) homeViewModel.loadAndCancel(apiName) } 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 06fd6e26..ced6d6a2 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 @@ -52,7 +52,6 @@ class HomeViewModel : ViewModel() { val resumeWatching: LiveData> = _resumeWatching fun loadResumeWatching(context: Context) = viewModelScope.launch { - println("Resume::") val resumeWatching = withContext(Dispatchers.IO) { context.getAllResumeStateIds().mapNotNull { id -> context.getLastWatched(id) @@ -128,7 +127,7 @@ class HomeViewModel : ViewModel() { } var onGoingLoad: Job? = null - fun loadAndCancel(api: MainAPI?) { + private fun loadAndCancel(api: MainAPI?) { onGoingLoad?.cancel() onGoingLoad = load(api) } @@ -139,6 +138,7 @@ class HomeViewModel : ViewModel() { } else { autoloadRepo() } + _apiName.postValue(repo?.name) if (repo?.hasMainPage == true) { _page.postValue(Resource.Loading()) 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 57dc71e9..36318000 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 @@ -225,6 +225,8 @@ class ResultFragment : Fragment() { result_loading.visibility = GONE result_finish_loading.visibility = VISIBLE result_loading_error.visibility = GONE + + result_bookmark_button.requestFocus() } } } 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 c106b1a8..b47ddab7 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 @@ -54,6 +54,8 @@ data class SaveCaptionStyle( var fixedTextSize: Float?, ) +const val DEF_SUBS_ELEVATION = 20 + class SubtitlesFragment : Fragment() { companion object { val applyStyleEvent = Event() @@ -94,7 +96,7 @@ class SubtitlesFragment : Fragment() { CaptionStyleCompat.EDGE_TYPE_OUTLINE, getDefColor(1), null, - 0, + DEF_SUBS_ELEVATION, null, ) } @@ -237,7 +239,7 @@ class SubtitlesFragment : Fragment() { } subs_subtitle_elevation.setOnLongClickListener { - state.elevation = 0 + state.elevation = DEF_SUBS_ELEVATION it.context.updateState() showToast(activity, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT) return@setOnLongClickListener 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 9cfe71d5..4310cd4e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt @@ -16,7 +16,10 @@ import android.view.View import android.view.WindowManager import android.view.inputmethod.InputMethodManager import android.widget.ImageView -import androidx.annotation.* +import androidx.annotation.AttrRes +import androidx.annotation.ColorInt +import androidx.annotation.IdRes +import androidx.annotation.RequiresApi import androidx.appcompat.view.ContextThemeWrapper import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.widget.PopupMenu @@ -30,7 +33,6 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity import androidx.navigation.fragment.NavHostFragment import androidx.preference.PreferenceManager -import com.bumptech.glide.Glide import com.bumptech.glide.load.model.GlideUrl import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.mvvm.logError @@ -71,8 +73,8 @@ object UIHelper { } } - fun Activity?.navigate(@IdRes navigation : Int, arguments : Bundle? = null) { - if(this is FragmentActivity) { + fun Activity?.navigate(@IdRes navigation: Int, arguments: Bundle? = null) { + if (this is FragmentActivity) { (supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as? NavHostFragment?)?.navController?.navigate( navigation, arguments ) @@ -93,13 +95,13 @@ object UIHelper { return color } - fun ImageView?.setImage(url : String?) { - if(this == null || url.isNullOrBlank()) return + fun ImageView?.setImage(url: String?) { + if (this == null || url.isNullOrBlank()) return try { GlideApp.with(this.context) .load(GlideUrl(url)) .into(this) - } catch (e : Exception) { + } catch (e: Exception) { logError(e) } } @@ -211,6 +213,7 @@ object UIHelper { fun Context.fixPaddingStatusbar(v: View) { v.setPadding(v.paddingLeft, v.paddingTop + getStatusBarHeight(), v.paddingRight, v.paddingBottom) } + fun Context.getNavigationBarHeight(): Int { var result = 0 val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android") @@ -281,31 +284,6 @@ object UIHelper { inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0) } - - /**id, icon, stringRes */ - @SuppressLint("RestrictedApi") - fun View.popupMenu( - items: List>, - onMenuItemClick: MenuItem.() -> Unit, - ): PopupMenu { - val ctw = ContextThemeWrapper(context, R.style.PopupMenu) - val popup = PopupMenu(ctw, this, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0) - - items.forEach { (id, icon, stringRes) -> - popup.menu.add(0, id, 0, stringRes).setIcon(icon) - } - - (popup.menu as? MenuBuilder)?.setOptionalIconsVisible(true) - - popup.setOnMenuItemClickListener { - it.onMenuItemClick() - true - } - - popup.show() - return popup - } - /**id, stringRes */ @SuppressLint("RestrictedApi") fun View.popupMenuNoIcons( diff --git a/app/src/main/res/drawable/outline.xml b/app/src/main/res/drawable/outline.xml new file mode 100644 index 00000000..b437f111 --- /dev/null +++ b/app/src/main/res/drawable/outline.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/outline_drawable.xml b/app/src/main/res/drawable/outline_drawable.xml new file mode 100644 index 00000000..16eba83c --- /dev/null +++ b/app/src/main/res/drawable/outline_drawable.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/bottom_selection_dialog.xml b/app/src/main/res/layout/bottom_selection_dialog.xml index 3ec47217..7c05e8e2 100644 --- a/app/src/main/res/layout/bottom_selection_dialog.xml +++ b/app/src/main/res/layout/bottom_selection_dialog.xml @@ -22,6 +22,9 @@ android:layout_height="wrap_content"> - + + > diff --git a/app/src/main/res/layout/download_header_episode.xml b/app/src/main/res/layout/download_header_episode.xml index 06383d6b..5212562f 100644 --- a/app/src/main/res/layout/download_header_episode.xml +++ b/app/src/main/res/layout/download_header_episode.xml @@ -8,7 +8,7 @@ app:cardCornerRadius="@dimen/roundedImageRadius" app:cardBackgroundColor="@color/itemBackground" android:id="@+id/episode_holder" - android:foreground="?android:attr/selectableItemBackgroundBorderless" + android:foreground="@drawable/outline_drawable" android:layout_marginBottom="10dp" > + + android:layout_height="30dp" + tools:ignore="ContentDescription"/> + style="@style/MultiSelectButton"> + @@ -227,6 +237,11 @@ android:visibility="gone" /> @@ -389,38 +420,36 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - - + + + android:id="@+id/result_episode_select" + android:visibility="gone" + android:layout_gravity="center_vertical" + + style="@style/MultiSelectButton" + > @@ -489,6 +522,10 @@ android:contentDescription="@string/search_poster_descript"/> --> + + + @@ -520,6 +541,10 @@ android:layout_width="wrap_content" android:layout_height="match_parent"> @@ -613,6 +640,11 @@ @@ -660,6 +691,10 @@ diff --git a/app/src/main/res/layout/player_select_speed.xml b/app/src/main/res/layout/player_select_speed.xml deleted file mode 100644 index cac2c63d..00000000 --- a/app/src/main/res/layout/player_select_speed.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - diff --git a/app/src/main/res/layout/provider_list.xml b/app/src/main/res/layout/provider_list.xml index 254cb18a..60bdf80f 100644 --- a/app/src/main/res/layout/provider_list.xml +++ b/app/src/main/res/layout/provider_list.xml @@ -8,17 +8,24 @@ android:layout_height="match_parent"> + tools:text="Search" + android:layout_width="match_parent" + android:layout_height="wrap_content"> diff --git a/app/src/main/res/layout/result_episode.xml b/app/src/main/res/layout/result_episode.xml index f16ccb50..a8dc0f5b 100644 --- a/app/src/main/res/layout/result_episode.xml +++ b/app/src/main/res/layout/result_episode.xml @@ -1,15 +1,20 @@ @@ -99,6 +104,10 @@ android:visibility="visible" /> diff --git a/app/src/main/res/layout/result_episode_large.xml b/app/src/main/res/layout/result_episode_large.xml index 2e85853a..970701e8 100644 --- a/app/src/main/res/layout/result_episode_large.xml +++ b/app/src/main/res/layout/result_episode_large.xml @@ -1,14 +1,19 @@ diff --git a/app/src/main/res/layout/search_result_grid.xml b/app/src/main/res/layout/search_result_grid.xml index 1f155bab..4f74ae3a 100644 --- a/app/src/main/res/layout/search_result_grid.xml +++ b/app/src/main/res/layout/search_result_grid.xml @@ -6,12 +6,12 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" + android:foreground="@drawable/outline_drawable" android:focusable="true" android:clickable="true" android:id="@+id/search_result_root" > - + --> @drawable/rounded_dialog + 512dp @@ -153,13 +154,17 @@ 5dp 5dp 5dp - 50dp + 40dp bold false textStart 20dp 4dp 15sp + + 0dp + 0dp + @drawable/outline_drawable + + +