@@ -21,9 +21,12 @@ package org.schabi.newpipe.local.feed
2121
2222import android.annotation.SuppressLint
2323import android.app.Activity
24+ import android.content.Context
2425import android.content.Intent
2526import android.content.SharedPreferences
2627import android.graphics.Typeface
28+ import android.graphics.drawable.Drawable
29+ import android.graphics.drawable.LayerDrawable
2730import android.os.Bundle
2831import android.os.Parcelable
2932import android.view.LayoutInflater
@@ -33,6 +36,7 @@ import android.view.MenuItem
3336import android.view.View
3437import android.view.ViewGroup
3538import android.widget.Button
39+ import androidx.annotation.AttrRes
3640import androidx.annotation.Nullable
3741import androidx.appcompat.app.AlertDialog
3842import 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