Fix crash when opening description while chapter updates

This commit is contained in:
Bnyro 2023-06-08 19:15:14 +02:00
parent 93be20b2c9
commit 1fb2b2174c
5 changed files with 8 additions and 10 deletions

View File

@ -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()
}

View File

@ -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 "Libre<span style='color:$hexColor';>Tube</span>"
.parseAsHtml(HtmlCompat.FROM_HTML_MODE_COMPACT)
}

View File

@ -53,7 +53,5 @@ class ChaptersAdapter(
notifyItemChanged(newPosition)
}
override fun getItemCount(): Int {
return chapters.size
}
override fun getItemCount() = chapters.size
}

View File

@ -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)
}

View File

@ -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">
<LinearLayout
@ -13,7 +14,7 @@
android:layout_width="100dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingHorizontal="5dp">
android:padding="5dp">
<FrameLayout
android:layout_width="match_parent"