Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: simplify ThemeHelper#getThemeColor #4623

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -21,15 +20,12 @@ fun View.setWatchProgressLength(videoId: String, duration: Long) {
updateLayoutParams<ConstraintLayout.LayoutParams> {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ class SubscriptionsFragment : Fragment() {
PreferenceKeys.HIDE_WATCHED_FROM_FEED,
false
)
) return streamItems
) {
return streamItems
}

return runBlocking { DatabaseHelper.filterUnwatched(streamItems) }
}
Expand Down Expand Up @@ -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)
)
}
}

Expand Down