Skip to content

Commit 1e0c9f4

Browse files
committed
Improved highlighting in FeedFragment
Now keeps the ``selectableItemBackground`` when highligthing an item.
1 parent 4eb02f5 commit 1e0c9f4

1 file changed

Lines changed: 33 additions & 14 deletions

File tree

app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ package org.schabi.newpipe.local.feed
2121

2222
import android.annotation.SuppressLint
2323
import android.app.Activity
24+
import android.content.Context
2425
import android.content.Intent
2526
import android.content.SharedPreferences
2627
import android.graphics.Typeface
28+
import android.graphics.drawable.Drawable
29+
import android.graphics.drawable.LayerDrawable
2730
import android.os.Bundle
2831
import android.os.Parcelable
2932
import android.view.LayoutInflater
@@ -33,6 +36,7 @@ import android.view.MenuItem
3336
import android.view.View
3437
import android.view.ViewGroup
3538
import android.widget.Button
39+
import androidx.annotation.AttrRes
3640
import androidx.annotation.Nullable
3741
import androidx.appcompat.app.AlertDialog
3842
import androidx.appcompat.content.res.AppCompatResources
@@ -574,12 +578,24 @@ class FeedFragment : BaseStateFragment<FeedState>() {
574578
val item = groupAdapter.getItem(i) as StreamItem
575579

576580
var typeface = Typeface.DEFAULT
577-
var resid = R.attr.selectableItemBackground
581+
var backgroundSupplier = { ctx: Context ->
582+
resolveDrawable(ctx, R.attr.selectableItemBackground)
583+
}
578584
if (doCheck) {
585+
// If the uploadDate is null or true we should highlight the item
579586
if (item.streamWithState.stream.uploadDate?.isAfter(updateTime) != false) {
580-
typeface = Typeface.DEFAULT_BOLD
581-
resid = R.attr.dashed_border
582587
highlightCount++
588+
589+
typeface = Typeface.DEFAULT_BOLD
590+
backgroundSupplier = { ctx: Context ->
591+
// Merge the drawables together. Otherwise we would lose the "select" effect
592+
LayerDrawable(
593+
arrayOf(
594+
resolveDrawable(ctx, R.attr.dashed_border),
595+
resolveDrawable(ctx, R.attr.selectableItemBackground)
596+
)
597+
)
598+
}
583599
} else {
584600
// Increases execution time due to the order of the items (newest always on top)
585601
// Once a item is is before the updateTime we can skip all following items
@@ -592,17 +608,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
592608
// due to the fact that itemRoot is getting recycled
593609
item.execBindEnd = Consumer { viewBinding ->
594610
val context = viewBinding.itemRoot.context
595-
viewBinding.itemRoot.background =
596-
androidx.core.content.ContextCompat.getDrawable(
597-
context,
598-
android.util.TypedValue().apply {
599-
context.theme.resolveAttribute(
600-
resid,
601-
this,
602-
true
603-
)
604-
}.resourceId
605-
)
611+
viewBinding.itemRoot.background = backgroundSupplier.invoke(context)
606612
viewBinding.itemVideoTitleView.typeface = typeface
607613
}
608614
}
@@ -622,6 +628,19 @@ class FeedFragment : BaseStateFragment<FeedState>() {
622628
lastNewItemsCount = highlightCount
623629
}
624630

631+
private fun resolveDrawable(context: Context, @AttrRes attrResId: Int): Drawable? {
632+
return androidx.core.content.ContextCompat.getDrawable(
633+
context,
634+
android.util.TypedValue().apply {
635+
context.theme.resolveAttribute(
636+
attrResId,
637+
this,
638+
true
639+
)
640+
}.resourceId
641+
)
642+
}
643+
625644
private fun showNewItemsLoaded() {
626645
tryGetNewItemsLoadedButton()?.clearAnimation()
627646
tryGetNewItemsLoadedButton()

0 commit comments

Comments
 (0)