From 1fb2b2174c6b2895cb4e1ed86629217d7cd2c39f Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 8 Jun 2023 19:15:14 +0200 Subject: [PATCH] Fix crash when opening description while chapter updates --- .../java/com/github/libretube/extensions/FormatShort.kt | 2 +- .../main/java/com/github/libretube/helpers/ThemeHelper.kt | 2 +- .../com/github/libretube/ui/adapters/ChaptersAdapter.kt | 4 +--- .../com/github/libretube/ui/fragments/PlayerFragment.kt | 7 +++---- app/src/main/res/layout/chapter_column.xml | 3 ++- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/github/libretube/extensions/FormatShort.kt b/app/src/main/java/com/github/libretube/extensions/FormatShort.kt index 621b1339c..a0eed0043 100644 --- a/app/src/main/java/com/github/libretube/extensions/FormatShort.kt +++ b/app/src/main/java/com/github/libretube/extensions/FormatShort.kt @@ -16,7 +16,7 @@ fun Long?.formatShort(): String { val units = arrayOf("", "K", "M", "B", "T") for (i in units.size downTo 1) { val step = 1000.0.pow(i.toDouble()) - if (value > step) return String.format("%3.0f%s", value / step, units[i]).trim() + if (value > step) return "%3.0f%s".format(value / step, units[i]).trim() } value.toString() } diff --git a/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt b/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt index 9bcc52b82..56e984038 100644 --- a/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt @@ -133,7 +133,7 @@ object ThemeHelper { */ fun getStyledAppName(context: Context): Spanned { val colorPrimary = getThemeColor(context, androidx.appcompat.R.attr.colorPrimaryDark) - val hexColor = String.format("#%06X", (0xFFFFFF and colorPrimary)) + val hexColor = "#%06X".format(0xFFFFFF and colorPrimary) return "LibreTube" .parseAsHtml(HtmlCompat.FROM_HTML_MODE_COMPACT) } diff --git a/app/src/main/java/com/github/libretube/ui/adapters/ChaptersAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/ChaptersAdapter.kt index d302cdc0c..a5d863391 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/ChaptersAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/ChaptersAdapter.kt @@ -53,7 +53,5 @@ class ChaptersAdapter( notifyItemChanged(newPosition) } - override fun getItemCount(): Int { - return chapters.size - } + override fun getItemCount() = chapters.size } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index c27101c4d..9406a7e79 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -563,7 +563,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { streams.views.formatShort() } else { // show exact view count - String.format("%,d", streams.views) + "%,d".format(streams.views) } val viewInfo = getString(R.string.normal_views, views, localizeDate(streams)) if (binding.descLinLayout.isVisible) { @@ -586,9 +586,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { if (this::chapters.isInitialized && chapters.isNotEmpty()) { val chapterIndex = getCurrentChapterIndex() ?: return // scroll to the current chapter in the chapterRecView in the description - val layoutManager = binding.chaptersRecView.layoutManager as LinearLayoutManager - layoutManager.scrollToPositionWithOffset(chapterIndex, 0) - // set selected + binding.chaptersRecView.scrollToPosition(chapterIndex) + // set selected item, that should be highlighted val chaptersAdapter = binding.chaptersRecView.adapter as ChaptersAdapter chaptersAdapter.updateSelectedPosition(chapterIndex) } diff --git a/app/src/main/res/layout/chapter_column.xml b/app/src/main/res/layout/chapter_column.xml index 220f7990e..add81cb16 100644 --- a/app/src/main/res/layout/chapter_column.xml +++ b/app/src/main/res/layout/chapter_column.xml @@ -6,6 +6,7 @@ android:layout_height="match_parent" android:background="?attr/selectableItemBackground" android:backgroundTint="@android:color/transparent" + android:layout_marginHorizontal="1dp" app:strokeWidth="0dp"> + android:padding="5dp">