mirror of
https://github.com/Michatec/Radio.git
synced 2026-11-16 12:41:38 +01:00
feat(ui): migrate cast dialogs to Compose and refactor app theme logic
- Migrate `CustomCastChooserDialogFragment` and `CustomCastControllerDialogFragment` from View-based to Jetpack Compose. - Create `CastComposables.kt` containing new Compose UI for Cast device selection and volume control. - Remove legacy XML layouts `dialog_cast_chooser.xml`, `dialog_cast_connected.xml`, and `item_cast_device.xml`. - Refactor `AppTheme.kt` to simplify color scheme logic and wrap content in a `Surface`. - Add `ic_shader_24dp.xml` and update the shader effect preference icon in `SettingsFragment`. - Adjust `windowLightStatusBar` and `windowLightNavigationBar` in night theme styles.
This commit is contained in:
1 parent
7345c3e52f
commit
45dafe486d
11 files changed
+322
-365
No files matched your search
@@ -417,7 +417,7 @@ class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedP
|
||||
// set up "Shader Effect" preference
|
||||
val preferenceShaderEffect = MarqueeSwitchPreference(context)
|
||||
preferenceShaderEffect.title = getString(R.string.pref_shader_effect_title)
|
||||
preferenceShaderEffect.setIcon(R.drawable.ic_brush_24dp)
|
||||
preferenceShaderEffect.setIcon(R.drawable.ic_shader_24dp)
|
||||
preferenceShaderEffect.key = Keys.PREF_SHADER_EFFECT
|
||||
preferenceShaderEffect.summary = getString(R.string.pref_shader_effect_summary)
|
||||
preferenceShaderEffect.setDefaultValue(true)
|
||||
|
||||
@@ -2,20 +2,19 @@ package com.michatec.radio.ui
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.mediarouter.app.MediaRouteChooserDialogFragment
|
||||
import androidx.mediarouter.media.MediaControlIntent
|
||||
import androidx.mediarouter.media.MediaRouteSelector
|
||||
import androidx.mediarouter.media.MediaRouter
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.michatec.radio.databinding.DialogCastChooserBinding
|
||||
import com.michatec.radio.databinding.ItemCastDeviceBinding
|
||||
import com.michatec.radio.ui.screens.CastChooserContent
|
||||
import com.michatec.radio.ui.theme.RadioTheme
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
|
||||
/**
|
||||
* A custom DialogFragment that replaces the default Google Cast device selection dialog.
|
||||
@@ -24,35 +23,6 @@ class CustomCastChooserDialogFragment : MediaRouteChooserDialogFragment() {
|
||||
|
||||
private lateinit var router: MediaRouter
|
||||
private lateinit var selector: MediaRouteSelector
|
||||
private var adapter: CastDeviceAdapter? = null
|
||||
private var _binding: DialogCastChooserBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private val callback = object : MediaRouter.Callback() {
|
||||
override fun onRouteAdded(router: MediaRouter, route: MediaRouter.RouteInfo) {
|
||||
updateRouteList()
|
||||
}
|
||||
|
||||
override fun onRouteRemoved(router: MediaRouter, route: MediaRouter.RouteInfo) {
|
||||
updateRouteList()
|
||||
}
|
||||
|
||||
override fun onRouteChanged(router: MediaRouter, route: MediaRouter.RouteInfo) {
|
||||
updateRouteList()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data class to hold route information safely for background diffing.
|
||||
* MediaRouter.RouteInfo must only be accessed on the main thread.
|
||||
*/
|
||||
private data class RouteItem(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val description: String?,
|
||||
val isSelected: Boolean,
|
||||
val originalRoute: MediaRouter.RouteInfo
|
||||
)
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val context = requireContext()
|
||||
@@ -62,95 +32,50 @@ class CustomCastChooserDialogFragment : MediaRouteChooserDialogFragment() {
|
||||
.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
|
||||
.build()
|
||||
|
||||
_binding = DialogCastChooserBinding.inflate(LayoutInflater.from(context))
|
||||
val composeView = ComposeView(context).apply {
|
||||
setContent {
|
||||
RadioTheme {
|
||||
val routes by produceState(initialValue = emptyList<MediaRouter.RouteInfo>()) {
|
||||
val flow = callbackFlow {
|
||||
val updateList = {
|
||||
val currentRoutes = router.routes.filter {
|
||||
it.matchesSelector(selector) && !it.isDefault
|
||||
}
|
||||
trySend(currentRoutes)
|
||||
}
|
||||
|
||||
binding.recyclerViewDevices.layoutManager = LinearLayoutManager(context)
|
||||
adapter = CastDeviceAdapter { routeItem ->
|
||||
routeItem.originalRoute.select()
|
||||
dismiss()
|
||||
val callback = object : MediaRouter.Callback() {
|
||||
override fun onRouteAdded(router: MediaRouter, route: MediaRouter.RouteInfo) { updateList() }
|
||||
override fun onRouteRemoved(router: MediaRouter, route: MediaRouter.RouteInfo) { updateList() }
|
||||
override fun onRouteChanged(router: MediaRouter, route: MediaRouter.RouteInfo) { updateList() }
|
||||
}
|
||||
|
||||
router.addCallback(selector, callback, MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY)
|
||||
updateList()
|
||||
|
||||
awaitClose {
|
||||
router.removeCallback(callback)
|
||||
}
|
||||
}
|
||||
|
||||
flow.collectLatest {
|
||||
value = it
|
||||
}
|
||||
}
|
||||
|
||||
CastChooserContent(
|
||||
routes = routes,
|
||||
onRouteSelected = { route ->
|
||||
route.select()
|
||||
dismiss()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
binding.recyclerViewDevices.adapter = adapter
|
||||
|
||||
updateRouteList()
|
||||
|
||||
return MaterialAlertDialogBuilder(context)
|
||||
.setView(binding.root)
|
||||
.setView(composeView)
|
||||
.create()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
router.addCallback(selector, callback, MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
router.removeCallback(callback)
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
private fun updateRouteList() {
|
||||
val routes = router.routes
|
||||
.filter { it.matchesSelector(selector) && !it.isDefault }
|
||||
.map { route ->
|
||||
RouteItem(
|
||||
id = route.id,
|
||||
name = route.name,
|
||||
description = route.description,
|
||||
isSelected = route.isSelected,
|
||||
originalRoute = route
|
||||
)
|
||||
}
|
||||
|
||||
adapter?.submitList(routes)
|
||||
|
||||
val hasDevices = routes.isNotEmpty()
|
||||
binding.recyclerViewDevices.isVisible = hasDevices
|
||||
binding.textViewNoDevices.isVisible = !hasDevices
|
||||
}
|
||||
|
||||
/**
|
||||
* Inner adapter for the Cast device list
|
||||
*/
|
||||
private class CastDeviceAdapter(private val onRouteSelected: (RouteItem) -> Unit) :
|
||||
ListAdapter<RouteItem, CastDeviceAdapter.ViewHolder>(RouteDiffCallback()) {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val binding = ItemCastDeviceBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return ViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val item = getItem(position)
|
||||
holder.binding.textViewName.text = item.name
|
||||
|
||||
val description = item.description
|
||||
if (!description.isNullOrEmpty()) {
|
||||
holder.binding.textViewDescription.text = description
|
||||
holder.binding.textViewDescription.isVisible = true
|
||||
} else {
|
||||
holder.binding.textViewDescription.isVisible = false
|
||||
}
|
||||
|
||||
holder.itemView.setOnClickListener { onRouteSelected(item) }
|
||||
}
|
||||
|
||||
class ViewHolder(val binding: ItemCastDeviceBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
||||
private class RouteDiffCallback : DiffUtil.ItemCallback<RouteItem>() {
|
||||
override fun areItemsTheSame(oldItem: RouteItem, newItem: RouteItem): Boolean {
|
||||
return oldItem.id == newItem.id
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: RouteItem, newItem: RouteItem): Boolean {
|
||||
return oldItem.name == newItem.name &&
|
||||
oldItem.description == newItem.description &&
|
||||
oldItem.isSelected == newItem.isSelected
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,15 @@ package com.michatec.radio.ui
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.SeekBar
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.mediarouter.app.MediaRouteControllerDialogFragment
|
||||
import com.google.android.gms.cast.Cast
|
||||
import com.google.android.gms.cast.framework.CastContext
|
||||
import com.google.android.gms.cast.framework.CastSession
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.michatec.radio.R
|
||||
import com.michatec.radio.databinding.DialogCastConnectedBinding
|
||||
import com.michatec.radio.ui.screens.CastControllerContent
|
||||
import com.michatec.radio.ui.theme.RadioTheme
|
||||
|
||||
/**
|
||||
* A custom DialogFragment that replaces the default Google Cast controller dialog.
|
||||
@@ -18,74 +18,53 @@ import com.michatec.radio.databinding.DialogCastConnectedBinding
|
||||
*/
|
||||
class CustomCastControllerDialogFragment : MediaRouteControllerDialogFragment() {
|
||||
|
||||
private var _binding: DialogCastConnectedBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
private var castSession: CastSession? = null
|
||||
|
||||
private val castListener = object : Cast.Listener() {
|
||||
override fun onVolumeChanged() {
|
||||
updateVolumeSeekBar()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val context = requireContext()
|
||||
|
||||
_binding = DialogCastConnectedBinding.inflate(LayoutInflater.from(context))
|
||||
|
||||
val castContext = CastContext.getSharedInstance(context)
|
||||
castSession = castContext.sessionManager.currentCastSession
|
||||
val deviceName = castSession?.castDevice?.friendlyName ?: context.getString(R.string.media_route_menu_title)
|
||||
|
||||
binding.textViewDeviceName.text = deviceName
|
||||
val composeView = ComposeView(context).apply {
|
||||
setContent {
|
||||
RadioTheme {
|
||||
val castSession = remember { castContext.sessionManager.currentCastSession }
|
||||
var volume by remember { mutableFloatStateOf(castSession?.volume?.toFloat() ?: 0f) }
|
||||
var isMute by remember { mutableStateOf(castSession?.isMute ?: false) }
|
||||
val deviceName = remember { castSession?.castDevice?.friendlyName ?: context.getString(R.string.media_route_menu_title) }
|
||||
|
||||
updateVolumeSeekBar()
|
||||
binding.seekBarVolume.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||
if (fromUser) {
|
||||
castSession?.volume = progress / 100.0
|
||||
DisposableEffect(castSession) {
|
||||
val listener = object : Cast.Listener() {
|
||||
override fun onVolumeChanged() {
|
||||
volume = castSession?.volume?.toFloat() ?: 0f
|
||||
isMute = castSession?.isMute ?: false
|
||||
}
|
||||
}
|
||||
castSession?.addCastListener(listener)
|
||||
onDispose {
|
||||
castSession?.removeCastListener(listener)
|
||||
}
|
||||
}
|
||||
|
||||
CastControllerContent(
|
||||
deviceName = deviceName,
|
||||
volume = volume,
|
||||
isMute = isMute,
|
||||
onVolumeChanged = { newVolume ->
|
||||
castSession?.volume = newVolume.toDouble()
|
||||
volume = newVolume
|
||||
},
|
||||
onStopCasting = {
|
||||
castContext.sessionManager.endCurrentSession(true)
|
||||
dismiss()
|
||||
},
|
||||
onCancel = {
|
||||
dismiss()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
||||
})
|
||||
|
||||
val dialog = MaterialAlertDialogBuilder(context)
|
||||
.setView(binding.root)
|
||||
return MaterialAlertDialogBuilder(context)
|
||||
.setView(composeView)
|
||||
.create()
|
||||
|
||||
binding.buttonStopCasting.setOnClickListener {
|
||||
castContext.sessionManager.endCurrentSession(true)
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
binding.buttonCancel.setOnClickListener {
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
return dialog
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
castSession?.addCastListener(castListener)
|
||||
updateVolumeSeekBar()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
castSession?.removeCastListener(castListener)
|
||||
}
|
||||
|
||||
private fun updateVolumeSeekBar() {
|
||||
val volume = castSession?.volume ?: 0.0
|
||||
binding.seekBarVolume.progress = (volume * 100).toInt()
|
||||
binding.seekBarVolume.isEnabled = castSession?.isMute == false
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
package com.michatec.radio.ui.screens
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.mediarouter.media.MediaRouter
|
||||
import com.michatec.radio.R
|
||||
|
||||
@Composable
|
||||
fun CastChooserContent(
|
||||
routes: List<MediaRouter.RouteInfo>,
|
||||
onRouteSelected: (MediaRouter.RouteInfo) -> Unit
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 10.dp)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.cast_chooser_title),
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
modifier = Modifier.padding(horizontal = 24.dp, vertical = 16.dp)
|
||||
)
|
||||
|
||||
if (routes.isEmpty()) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(32.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.cast_no_devices),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
}
|
||||
} else {
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(min = 100.dp, max = 400.dp)
|
||||
) {
|
||||
items(routes) { route ->
|
||||
CastDeviceItem(route = route, onClick = { onRouteSelected(route) })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CastDeviceItem(
|
||||
route: MediaRouter.RouteInfo,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable(onClick = onClick)
|
||||
.padding(14.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.ic_cast_24dp),
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Column {
|
||||
Text(
|
||||
text = route.name,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
route.description?.let { description ->
|
||||
if (description.isNotEmpty()) {
|
||||
Text(
|
||||
text = description,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CastControllerContent(
|
||||
deviceName: String,
|
||||
volume: Float,
|
||||
isMute: Boolean,
|
||||
onVolumeChanged: (Float) -> Unit,
|
||||
onStopCasting: () -> Unit,
|
||||
onCancel: () -> Unit
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(24.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.ic_cast_24dp),
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier
|
||||
.size(48.dp)
|
||||
.padding(bottom = 16.dp)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = stringResource(id = R.string.cast_connected_to),
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
|
||||
Text(
|
||||
text = deviceName,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(top = 8.dp, bottom = 16.dp)
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 24.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.ic_volume_down_24dp),
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
Slider(
|
||||
value = volume,
|
||||
onValueChange = onVolumeChanged,
|
||||
enabled = !isMute,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(horizontal = 8.dp)
|
||||
)
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.ic_volume_up_24dp),
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onStopCasting,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 8.dp),
|
||||
shape = MaterialTheme.shapes.medium
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.cast_stop_casting))
|
||||
}
|
||||
|
||||
TextButton(
|
||||
onClick = onCancel,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
shape = MaterialTheme.shapes.medium
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.cast_cancel))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.michatec.radio.ui.theme
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -17,10 +18,8 @@ fun RadioTheme(
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val customThemeEnabled = PreferencesHelper.loadCustomThemeEnabled()
|
||||
val isDark: Boolean
|
||||
val backgroundColor: Color
|
||||
|
||||
if (customThemeEnabled) {
|
||||
val colorScheme = if (customThemeEnabled) {
|
||||
var colorInt = PreferencesHelper.loadCustomThemeColor(context)
|
||||
val index = PreferencesHelper.loadCustomThemeIndex()
|
||||
if (index != -1) {
|
||||
@@ -29,27 +28,32 @@ fun RadioTheme(
|
||||
colorInt = colors[index]
|
||||
}
|
||||
}
|
||||
backgroundColor = Color(colorInt)
|
||||
isDark = backgroundColor.luminance() < 0.5f
|
||||
val backgroundColor = Color(colorInt)
|
||||
val isDark = backgroundColor.luminance() < 0.5f
|
||||
if (isDark) {
|
||||
darkColorScheme(
|
||||
background = backgroundColor,
|
||||
surface = backgroundColor
|
||||
)
|
||||
} else {
|
||||
lightColorScheme(
|
||||
background = backgroundColor,
|
||||
surface = backgroundColor
|
||||
)
|
||||
}
|
||||
} else {
|
||||
isDark = isSystemInDarkTheme()
|
||||
backgroundColor = if (isDark) Color(0xFF1C1B1F) else Color(0xFFFFFBFE)
|
||||
}
|
||||
|
||||
val colorScheme = if (isDark) {
|
||||
darkColorScheme(
|
||||
background = backgroundColor,
|
||||
surface = backgroundColor
|
||||
)
|
||||
} else {
|
||||
lightColorScheme(
|
||||
background = backgroundColor,
|
||||
surface = backgroundColor
|
||||
)
|
||||
val isDark = isSystemInDarkTheme()
|
||||
if (isDark) {
|
||||
darkColorScheme()
|
||||
} else {
|
||||
lightColorScheme()
|
||||
}
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colorScheme = colorScheme,
|
||||
content = content
|
||||
content = {
|
||||
Surface(content = content)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="960"
|
||||
android:viewportWidth="960"
|
||||
android:width="24dp">
|
||||
<path
|
||||
android:fillColor="@color/icon_default"
|
||||
android:pathData="M440,440L440,160L880,160L880,440L440,440ZM80,800L80,520L480,520L480,800L80,800ZM80,440L80,160L360,160L360,440L80,440ZM520,360L800,360L800,240L520,240L520,360ZM160,720L400,720L400,600L160,600L160,720ZM160,360L280,360L280,240L160,240L160,360ZM520,360L520,360L520,360L520,360ZM400,600L400,600L400,600L400,600ZM280,360L280,360L280,360L280,360ZM680,880L668,820Q656,815 645.5,809.5Q635,804 624,796L566,814L526,746L572,706Q570,693 570,680Q570,667 572,654L526,614L566,546L624,564Q635,556 645.5,550.5Q656,545 668,540L680,480L760,480L772,540Q784,545 794.5,550.5Q805,556 816,564L874,546L914,614L868,654Q870,667 870,680Q870,693 868,706L914,746L874,814L816,796Q805,804 794.5,809.5Q784,815 772,820L760,880L680,880ZM776.5,736.5Q800,713 800,680Q800,647 776.5,623.5Q753,600 720,600Q687,600 663.5,623.5Q640,647 640,680Q640,713 663.5,736.5Q687,760 720,760Q753,760 776.5,736.5Z"/>
|
||||
</vector>
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="24dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:text="@string/cast_chooser_title"
|
||||
android:textAppearance="?attr/textAppearanceTitleLarge" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerViewDevices"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="100dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewNoDevices"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:padding="32dp"
|
||||
android:text="@string/cast_no_devices"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
@@ -1,85 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="24dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:contentDescription="@string/cast_ad_label"
|
||||
android:src="@drawable/cast_ic_notification_on"
|
||||
app:tint="?attr/colorPrimary" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/cast_connected_to"
|
||||
android:textAppearance="?attr/textAppearanceTitleLarge"
|
||||
android:textColor="?attr/colorOnSurface" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewDeviceName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:gravity="center"
|
||||
android:textAppearance="?attr/textAppearanceBodyLarge"
|
||||
android:textColor="?attr/colorOnSurfaceVariant"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/ic_volume_down_24dp"
|
||||
app:tint="?attr/colorOnSurfaceVariant" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBarVolume"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:max="100" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/ic_volume_up_24dp"
|
||||
app:tint="?attr/colorOnSurfaceVariant" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/buttonStopCasting"
|
||||
style="@style/Widget.Material3.Button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="@string/cast_stop_casting"
|
||||
app:cornerRadius="12dp" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/buttonCancel"
|
||||
style="@style/Widget.Material3.Button.TextButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/cast_cancel"
|
||||
app:cornerRadius="12dp" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,42 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="16dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/ic_cast_24dp"
|
||||
app:tint="?attr/colorOnSurfaceVariant"
|
||||
android:contentDescription="@null" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?attr/textAppearanceBodyLarge"
|
||||
android:textColor="?attr/colorOnSurface" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewDescription"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?attr/textAppearanceBodySmall"
|
||||
android:textColor="?attr/colorOnSurfaceVariant"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
@@ -29,6 +29,8 @@
|
||||
<item name="materialTimePickerTheme">@style/ThemeOverlay.App.TimePicker</item>
|
||||
|
||||
<!-- Don't show light status bar -->
|
||||
<item name="android:windowLightStatusBar">false</item>
|
||||
<item name="android:windowLightNavigationBar">false</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
|
||||
<!-- Set splash screen icon background color -->
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<item name="materialTimePickerTheme">@style/ThemeOverlay.App.TimePicker</item>
|
||||
|
||||
<!-- Don't show light status bar -->
|
||||
<item name="android:windowLightStatusBar">false</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
</style>
|
||||
|
||||
|
||||
Reference in new issue
Block a user