Improved highlighting in FeedFragment

Now keeps the ``selectableItemBackground`` when highligthing an item.
pull/7050/head
litetex 2021-09-28 21:51:57 +02:00
rodzic 4eb02f584e
commit 1e0c9f46ad
1 zmienionych plików z 33 dodań i 14 usunięć

Wyświetl plik

@ -21,9 +21,12 @@ package org.schabi.newpipe.local.feed
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.graphics.Typeface import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import android.view.LayoutInflater import android.view.LayoutInflater
@ -33,6 +36,7 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Button import android.widget.Button
import androidx.annotation.AttrRes
import androidx.annotation.Nullable import androidx.annotation.Nullable
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.content.res.AppCompatResources
@ -574,12 +578,24 @@ class FeedFragment : BaseStateFragment<FeedState>() {
val item = groupAdapter.getItem(i) as StreamItem val item = groupAdapter.getItem(i) as StreamItem
var typeface = Typeface.DEFAULT var typeface = Typeface.DEFAULT
var resid = R.attr.selectableItemBackground var backgroundSupplier = { ctx: Context ->
resolveDrawable(ctx, R.attr.selectableItemBackground)
}
if (doCheck) { if (doCheck) {
// If the uploadDate is null or true we should highlight the item
if (item.streamWithState.stream.uploadDate?.isAfter(updateTime) != false) { if (item.streamWithState.stream.uploadDate?.isAfter(updateTime) != false) {
typeface = Typeface.DEFAULT_BOLD
resid = R.attr.dashed_border
highlightCount++ highlightCount++
typeface = Typeface.DEFAULT_BOLD
backgroundSupplier = { ctx: Context ->
// Merge the drawables together. Otherwise we would lose the "select" effect
LayerDrawable(
arrayOf(
resolveDrawable(ctx, R.attr.dashed_border),
resolveDrawable(ctx, R.attr.selectableItemBackground)
)
)
}
} else { } else {
// Increases execution time due to the order of the items (newest always on top) // Increases execution time due to the order of the items (newest always on top)
// Once a item is is before the updateTime we can skip all following items // Once a item is is before the updateTime we can skip all following items
@ -592,17 +608,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
// due to the fact that itemRoot is getting recycled // due to the fact that itemRoot is getting recycled
item.execBindEnd = Consumer { viewBinding -> item.execBindEnd = Consumer { viewBinding ->
val context = viewBinding.itemRoot.context val context = viewBinding.itemRoot.context
viewBinding.itemRoot.background = viewBinding.itemRoot.background = backgroundSupplier.invoke(context)
androidx.core.content.ContextCompat.getDrawable(
context,
android.util.TypedValue().apply {
context.theme.resolveAttribute(
resid,
this,
true
)
}.resourceId
)
viewBinding.itemVideoTitleView.typeface = typeface viewBinding.itemVideoTitleView.typeface = typeface
} }
} }
@ -622,6 +628,19 @@ class FeedFragment : BaseStateFragment<FeedState>() {
lastNewItemsCount = highlightCount lastNewItemsCount = highlightCount
} }
private fun resolveDrawable(context: Context, @AttrRes attrResId: Int): Drawable? {
return androidx.core.content.ContextCompat.getDrawable(
context,
android.util.TypedValue().apply {
context.theme.resolveAttribute(
attrResId,
this,
true
)
}.resourceId
)
}
private fun showNewItemsLoaded() { private fun showNewItemsLoaded() {
tryGetNewItemsLoadedButton()?.clearAnimation() tryGetNewItemsLoadedButton()?.clearAnimation()
tryGetNewItemsLoadedButton() tryGetNewItemsLoadedButton()