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 768dc61305..602a11d2be 100644 --- a/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt @@ -5,8 +5,8 @@ import android.content.ComponentName import android.content.Context import android.content.pm.PackageManager import android.content.res.Configuration +import android.graphics.Color import android.text.Spanned -import android.util.TypedValue import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate import androidx.core.text.HtmlCompat @@ -15,6 +15,7 @@ import com.github.libretube.R import com.github.libretube.constants.PreferenceKeys import com.github.libretube.ui.adapters.IconsSheetAdapter import com.google.android.material.color.DynamicColors +import com.google.android.material.color.MaterialColors object ThemeHelper { @@ -114,13 +115,12 @@ object ThemeHelper { } /** - * Get a color by a resource code + * Get a color by a color resource attr */ - fun getThemeColor(context: Context, colorCode: Int): Int { - val value = TypedValue() - context.theme.resolveAttribute(colorCode, value, true) - return value.data - } + fun getThemeColor( + context: Context, + colorCode: Int + ) = MaterialColors.getColor(context, colorCode, Color.TRANSPARENT) /** * Get the styled app name diff --git a/app/src/main/java/com/github/libretube/services/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt index 2355e9f3b2..d47c5c7731 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -47,7 +47,6 @@ import java.net.URL import java.nio.file.Path import java.nio.file.StandardOpenOption import java.util.concurrent.Executors -import kotlin.io.path.absolute import kotlin.io.path.createFile import kotlin.io.path.deleteIfExists import kotlin.io.path.div diff --git a/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt b/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt index 5db1a5fba5..b396279fff 100644 --- a/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt +++ b/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt @@ -9,7 +9,6 @@ import androidx.core.view.isVisible import androidx.core.view.updateLayoutParams import com.github.libretube.db.DatabaseHolder.Database import com.github.libretube.helpers.ThemeHelper -import com.google.android.material.color.MaterialColors import kotlinx.coroutines.runBlocking /** @@ -21,15 +20,12 @@ fun View.setWatchProgressLength(videoId: String, duration: Long) { updateLayoutParams { matchConstraintPercentWidth = 0f } - var backgroundColor = MaterialColors.getColor( - this, + var backgroundColor = ThemeHelper.getThemeColor( + context, com.google.android.material.R.attr.colorPrimaryDark ) // increase the brightness for better contrast in light mode - if (!ThemeHelper.isDarkMode( - context - ) - ) { + if (!ThemeHelper.isDarkMode(context)) { backgroundColor = ColorUtils.blendARGB(backgroundColor, Color.WHITE, 0.4f) } setBackgroundColor(backgroundColor) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt index 89e66fd2ed..9739c1cb7f 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt @@ -284,7 +284,10 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions { if (DataSaverMode.isEnabled(requireContext())) { binding.progress.isVisible = false binding.thumbnail.setImageResource(R.drawable.ic_launcher_monochrome) - val primaryColor = ThemeHelper.getThemeColor(requireContext(), androidx.appcompat.R.attr.colorPrimary) + val primaryColor = ThemeHelper.getThemeColor( + requireContext(), + androidx.appcompat.R.attr.colorPrimary + ) binding.thumbnail.setColorFilter(primaryColor) return } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt index a6c74f7c59..3f6b2e2650 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt @@ -265,7 +265,9 @@ class SubscriptionsFragment : Fragment() { PreferenceKeys.HIDE_WATCHED_FROM_FEED, false ) - ) return streamItems + ) { + return streamItems + } return runBlocking { DatabaseHelper.filterUnwatched(streamItems) } } @@ -299,7 +301,10 @@ class SubscriptionsFragment : Fragment() { (it.uploaded ?: 0L) / 1000 < lastCheckedFeedTime } if (caughtUpIndex > 0) { - sortedFeed.add(caughtUpIndex, StreamItem(type = VideosAdapter.CAUGHT_UP_STREAM_TYPE)) + sortedFeed.add( + caughtUpIndex, + StreamItem(type = VideosAdapter.CAUGHT_UP_STREAM_TYPE) + ) } }