mirror of
https://github.com/Michatec/Radio.git
synced 2026-11-16 21:36:53 +01:00
feat(cast): implement custom cast dialogs and enhance remote UI
Implemented custom UI for Google Cast device selection and session control, alongside improvements to the web remote interface and playback service. - Added `CustomCastChooserDialogFragment` and `CustomCastControllerDialogFragment` to provide a custom casting experience. - Implemented `CustomCastDialogFactory` to integrate custom dialogs into `MediaRouteButton` and `ExpandedControllerActivity`. - Added marquee scrolling for station names and metadata in the web remote interface. - Improved `PlayerService` stability with safer resource cleanup in `onDestroy` and enhanced remote playback initialization. - Updated `CollectionHelper` to include additional metadata fields for better station display during casting. - Added localized strings for custom cast dialogs across multiple languages. - Refined `CustomCastExpandedControllerStyle` and associated layouts for better UI consistency.
This commit is contained in:
1 parent
e450526692
commit
8df6b73869
27 files changed
+562
-40
No files matched your search
@@ -20,10 +20,14 @@
|
||||
<div class="current-station-info">
|
||||
<div class="current-text-info">
|
||||
<div class="current-title-row">
|
||||
<div id="currentName" class="current-name"></div>
|
||||
<div class="marquee-container">
|
||||
<div id="currentName" class="current-name marquee-content"></div>
|
||||
</div>
|
||||
<span id="currentStar" class="material-icons starred-icon hidden">star</span>
|
||||
</div>
|
||||
<div id="currentMetadata" class="current-metadata"></div>
|
||||
<div class="marquee-container">
|
||||
<div id="currentMetadata" class="current-metadata marquee-content"></div>
|
||||
</div>
|
||||
</div>
|
||||
<img id="currentImage" class="current-img" src="favicon.png" alt="Station">
|
||||
</div>
|
||||
|
||||
@@ -38,6 +38,17 @@ async function loadTranslations() {
|
||||
}
|
||||
}
|
||||
|
||||
function checkOverflow(el) {
|
||||
if (!el) return;
|
||||
el.classList.remove('animate-marquee');
|
||||
setTimeout(() => {
|
||||
const container = el.parentElement;
|
||||
if (container && el.scrollWidth > container.offsetWidth) {
|
||||
el.classList.add('animate-marquee');
|
||||
}
|
||||
}, 50);
|
||||
}
|
||||
|
||||
function updateStatusUI(data) {
|
||||
if (!data) return;
|
||||
lastStatusData = data;
|
||||
@@ -56,6 +67,7 @@ function updateStatusUI(data) {
|
||||
if (data.error) {
|
||||
statusEl.innerText = t('status_error');
|
||||
currentNameEl.innerText = data.error;
|
||||
checkOverflow(currentNameEl);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -77,8 +89,12 @@ function updateStatusUI(data) {
|
||||
const station = allStations.find(s => s.uuid === stationUuid);
|
||||
if (station) {
|
||||
currentNameEl.innerText = station.name;
|
||||
checkOverflow(currentNameEl);
|
||||
if (currentStarEl) currentStarEl.classList.toggle('hidden', !data.starred);
|
||||
if (currentMetadataEl) currentMetadataEl.innerText = data.metadata || "";
|
||||
if (currentMetadataEl) {
|
||||
currentMetadataEl.innerText = data.metadata || "";
|
||||
checkOverflow(currentMetadataEl);
|
||||
}
|
||||
if (currentImageEl) {
|
||||
let imageUrl = station.hasImage ? '/api/image/' + station.uuid : 'favicon.png';
|
||||
if (station.hasImage && authToken) {
|
||||
@@ -99,8 +115,12 @@ function updateStatusUI(data) {
|
||||
} else {
|
||||
currentNameEl.innerText = t('status_loading');
|
||||
}
|
||||
checkOverflow(currentNameEl);
|
||||
if (currentStarEl) currentStarEl.classList.add('hidden');
|
||||
if (currentMetadataEl) currentMetadataEl.innerText = "";
|
||||
if (currentMetadataEl) {
|
||||
currentMetadataEl.innerText = "";
|
||||
checkOverflow(currentMetadataEl);
|
||||
}
|
||||
if (currentImageEl) currentImageEl.src = 'favicon.png';
|
||||
}
|
||||
|
||||
@@ -338,6 +358,11 @@ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e =
|
||||
}
|
||||
});
|
||||
|
||||
window.onresize = () => {
|
||||
checkOverflow(document.getElementById('currentName'));
|
||||
checkOverflow(document.getElementById('currentMetadata'));
|
||||
};
|
||||
|
||||
const themeSelect = document.getElementById('themeSelect');
|
||||
themeSelect.onchange = () => {
|
||||
const val = themeSelect.value;
|
||||
|
||||
@@ -93,6 +93,7 @@ body.light-theme .current-station-info {
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 4px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.current-name {
|
||||
@@ -100,21 +101,40 @@ body.light-theme .current-station-info {
|
||||
font-weight: 800;
|
||||
color: var(--accent-color);
|
||||
text-shadow: var(--accent-glow);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.current-metadata {
|
||||
font-size: 0.95rem;
|
||||
font-weight: 500;
|
||||
opacity: 0.6;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
/* Marquee Styles */
|
||||
.marquee-container {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
flex: 1;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.marquee-content {
|
||||
display: inline-block;
|
||||
white-space: nowrap;
|
||||
min-width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.animate-marquee {
|
||||
animation: marquee 15s linear infinite;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes marquee {
|
||||
0% { transform: translateX(100%); }
|
||||
100% { transform: translateX(-100%); }
|
||||
}
|
||||
|
||||
.current-img {
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
|
||||
@@ -3,9 +3,12 @@ package com.michatec.radio
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.view.Menu
|
||||
import androidx.core.view.MenuItemCompat
|
||||
import androidx.mediarouter.app.MediaRouteActionProvider
|
||||
import com.google.android.gms.cast.framework.CastButtonFactory
|
||||
import com.google.android.gms.cast.framework.media.widget.ExpandedControllerActivity
|
||||
import com.michatec.radio.helpers.PreferencesHelper
|
||||
import com.michatec.radio.ui.CustomCastDialogFactory
|
||||
import java.util.Locale
|
||||
|
||||
class ExpandedControllerActivity : ExpandedControllerActivity() {
|
||||
@@ -27,6 +30,11 @@ class ExpandedControllerActivity : ExpandedControllerActivity() {
|
||||
super.onCreateOptionsMenu(menu)
|
||||
menuInflater.inflate(R.menu.expanded_controller, menu)
|
||||
CastButtonFactory.setUpMediaRouteButton(this, menu, R.id.media_route_menu_item)
|
||||
|
||||
val item = menu.findItem(R.id.media_route_menu_item)
|
||||
val actionProvider = MenuItemCompat.getActionProvider(item) as? MediaRouteActionProvider
|
||||
actionProvider?.dialogFactory = CustomCastDialogFactory()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import android.media.audiofx.AudioEffect
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.CountDownTimer
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import androidx.media3.cast.CastPlayer
|
||||
@@ -142,15 +144,23 @@ class PlayerService : MediaLibraryService(), SharedPreferences.OnSharedPreferenc
|
||||
|
||||
/* Overrides onDestroy from Service */
|
||||
override fun onDestroy() {
|
||||
// Reset playing state in preferences
|
||||
PreferencesHelper.saveIsPlaying(false)
|
||||
player.removeListener(playerListener)
|
||||
player.release()
|
||||
exoPlayer.release()
|
||||
castPlayer.release()
|
||||
mediaLibrarySession.release()
|
||||
// unregister preference change listener
|
||||
PreferencesHelper.unregisterPreferenceChangeListener(this)
|
||||
|
||||
if (this::player.isInitialized) {
|
||||
player.removeListener(playerListener)
|
||||
player.release()
|
||||
}
|
||||
if (this::exoPlayer.isInitialized) {
|
||||
exoPlayer.removeListener(playerListener)
|
||||
exoPlayer.release()
|
||||
}
|
||||
if (this::mediaLibrarySession.isInitialized) {
|
||||
mediaLibrarySession.release()
|
||||
}
|
||||
|
||||
// Reset playing state in preferences
|
||||
PreferencesHelper.saveIsPlaying(false)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
@@ -206,12 +216,6 @@ class PlayerService : MediaLibraryService(), SharedPreferences.OnSharedPreferenc
|
||||
)
|
||||
}.build()
|
||||
|
||||
if (PreferencesHelper.hasArgument("008f0747f4e27c8462baa991a538025bcc2dd143e78422f1afbdfcd9e757a20f")) {
|
||||
exoPlayer.volume = 0f
|
||||
player.volume = 0f
|
||||
castPlayer.volume = 0f
|
||||
}
|
||||
|
||||
exoPlayer.addAnalyticsListener(analyticsListener)
|
||||
exoPlayer.addListener(playerListener)
|
||||
|
||||
@@ -243,6 +247,10 @@ class PlayerService : MediaLibraryService(), SharedPreferences.OnSharedPreferenc
|
||||
}
|
||||
}
|
||||
player.addListener(playerListener)
|
||||
|
||||
if (PreferencesHelper.hasArgument("008f0747f4e27c8462baa991a538025bcc2dd143e78422f1afbdfcd9e757a20f")) {
|
||||
player.volume = 0f
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -323,6 +331,8 @@ class PlayerService : MediaLibraryService(), SharedPreferences.OnSharedPreferenc
|
||||
|
||||
/* Updates metadata */
|
||||
private fun updateMetadata(metadata: String = String()) {
|
||||
if (!this::player.isInitialized) return
|
||||
|
||||
// get metadata string
|
||||
val metadataString: String = metadata.ifEmpty {
|
||||
player.currentMediaItem?.mediaMetadata?.artist.toString()
|
||||
@@ -416,14 +426,12 @@ class PlayerService : MediaLibraryService(), SharedPreferences.OnSharedPreferenc
|
||||
applyAudioEffects()
|
||||
}
|
||||
Keys.PREF_ARGUMENTS -> {
|
||||
if (PreferencesHelper.hasArgument("008f0747f4e27c8462baa991a538025bcc2dd143e78422f1afbdfcd9e757a20f")) {
|
||||
exoPlayer.volume = 0f
|
||||
player.volume = 0f
|
||||
castPlayer.volume = 0f
|
||||
} else {
|
||||
exoPlayer.volume = 1f
|
||||
player.volume = 1f
|
||||
castPlayer.volume = 1f
|
||||
if (this::player.isInitialized) {
|
||||
if (PreferencesHelper.hasArgument("008f0747f4e27c8462baa991a538025bcc2dd143e78422f1afbdfcd9e757a20f")) {
|
||||
player.volume = 0f
|
||||
} else {
|
||||
player.volume = 1f
|
||||
}
|
||||
}
|
||||
}
|
||||
Keys.PREF_REMOTE_CONTROL_ENABLED -> {
|
||||
@@ -679,6 +687,7 @@ class PlayerService : MediaLibraryService(), SharedPreferences.OnSharedPreferenc
|
||||
|
||||
override fun onIsPlayingChanged(isPlaying: Boolean) {
|
||||
super.onIsPlayingChanged(isPlaying)
|
||||
if (!this@PlayerService::player.isInitialized) return
|
||||
// store state of playback
|
||||
val currentMediaId: String = player.currentMediaItem?.mediaId ?: String()
|
||||
PreferencesHelper.saveIsPlaying(isPlaying)
|
||||
@@ -720,6 +729,22 @@ class PlayerService : MediaLibraryService(), SharedPreferences.OnSharedPreferenc
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDeviceInfoChanged(deviceInfo: DeviceInfo) {
|
||||
super.onDeviceInfoChanged(deviceInfo)
|
||||
val isPlaying = PreferencesHelper.loadPlayerState().isPlaying
|
||||
Log.d(TAG, "onDeviceInfoChanged: playbackType=${deviceInfo.playbackType}, playWhenReady=${player.playWhenReady}, exoPlayWhenReady=${exoPlayer.playWhenReady}, prefIsPlaying=$isPlaying")
|
||||
if (deviceInfo.playbackType == DeviceInfo.PLAYBACK_TYPE_REMOTE) {
|
||||
if (exoPlayer.playWhenReady || player.playWhenReady || isPlaying) {
|
||||
Log.i(TAG, "Ensuring remote playback starts.")
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
player.playWhenReady = true
|
||||
player.prepare()
|
||||
player.play()
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPlayerError(error: PlaybackException) {
|
||||
super.onPlayerError(error)
|
||||
Log.d(TAG, "PlayerError occurred: ${error.errorCodeName}")
|
||||
@@ -735,6 +760,11 @@ class PlayerService : MediaLibraryService(), SharedPreferences.OnSharedPreferenc
|
||||
updateMetadata(AudioHelper.getMetadataString(metadata))
|
||||
}
|
||||
|
||||
override fun onMediaMetadataChanged(mediaMetadata: MediaMetadata) {
|
||||
super.onMediaMetadataChanged(mediaMetadata)
|
||||
updateMetadata()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -644,6 +644,8 @@ object CollectionHelper {
|
||||
val mediaMetadata = MediaMetadata.Builder().apply {
|
||||
setTitle(station.name)
|
||||
setArtist(station.name)
|
||||
setAlbumArtist(station.name)
|
||||
setDisplayTitle(station.name)
|
||||
|
||||
// Set artwork URI for casting (remote devices need a public URL)
|
||||
if (station.remoteImageLocation.isNotEmpty()) {
|
||||
|
||||
@@ -411,13 +411,6 @@ object PreferencesHelper {
|
||||
return sharedPreferences.getBoolean(Keys.PREF_REMOTE_CONTROL_ENABLED, false)
|
||||
}
|
||||
|
||||
/* Saves whether remote control is enabled */
|
||||
fun saveRemoteControlEnabled(enabled: Boolean) {
|
||||
sharedPreferences.edit {
|
||||
putBoolean(Keys.PREF_REMOTE_CONTROL_ENABLED, enabled)
|
||||
}
|
||||
}
|
||||
|
||||
/* Loads whether remote control authentication is enabled */
|
||||
fun loadRemoteControlAuthEnabled(): Boolean {
|
||||
return sharedPreferences.getBoolean(Keys.PREF_REMOTE_CONTROL_AUTH_ENABLED, false)
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.michatec.radio.ui
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.isVisible
|
||||
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.R
|
||||
|
||||
/**
|
||||
* A custom DialogFragment that replaces the default Google Cast device selection dialog.
|
||||
*/
|
||||
class CustomCastChooserDialogFragment : MediaRouteChooserDialogFragment() {
|
||||
|
||||
private lateinit var router: MediaRouter
|
||||
private lateinit var selector: MediaRouteSelector
|
||||
private var adapter: CastDeviceAdapter? = null
|
||||
private var recyclerView: RecyclerView? = null
|
||||
private var noDevicesText: TextView? = null
|
||||
|
||||
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()
|
||||
router = MediaRouter.getInstance(context)
|
||||
|
||||
selector = MediaRouteSelector.Builder()
|
||||
.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
|
||||
.build()
|
||||
|
||||
val view = LayoutInflater.from(context).inflate(R.layout.dialog_cast_chooser, null)
|
||||
recyclerView = view.findViewById(R.id.recyclerViewDevices)
|
||||
noDevicesText = view.findViewById(R.id.textViewNoDevices)
|
||||
|
||||
recyclerView?.layoutManager = LinearLayoutManager(context)
|
||||
adapter = CastDeviceAdapter { routeItem ->
|
||||
routeItem.originalRoute.select()
|
||||
dismiss()
|
||||
}
|
||||
recyclerView?.adapter = adapter
|
||||
|
||||
updateRouteList()
|
||||
|
||||
return MaterialAlertDialogBuilder(context)
|
||||
.setView(view)
|
||||
.create()
|
||||
}
|
||||
|
||||
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()
|
||||
recyclerView?.isVisible = hasDevices
|
||||
noDevicesText?.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 view = LayoutInflater.from(parent.context).inflate(R.layout.item_cast_device, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val item = getItem(position)
|
||||
holder.nameText.text = item.name
|
||||
|
||||
val description = item.description
|
||||
if (!description.isNullOrEmpty()) {
|
||||
holder.descriptionText.text = description
|
||||
holder.descriptionText.isVisible = true
|
||||
} else {
|
||||
holder.descriptionText.isVisible = false
|
||||
}
|
||||
|
||||
holder.itemView.setOnClickListener { onRouteSelected(item) }
|
||||
}
|
||||
|
||||
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
val nameText: TextView = view.findViewById(R.id.textViewName)
|
||||
val descriptionText: TextView = view.findViewById(R.id.textViewDescription)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.michatec.radio.ui
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.TextView
|
||||
import androidx.mediarouter.app.MediaRouteControllerDialogFragment
|
||||
import com.google.android.gms.cast.framework.CastContext
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.michatec.radio.R
|
||||
|
||||
/**
|
||||
* A custom DialogFragment that replaces the default Google Cast controller dialog.
|
||||
* It is shown when a Cast session is already active.
|
||||
*/
|
||||
class CustomCastControllerDialogFragment : MediaRouteControllerDialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val context = requireContext()
|
||||
|
||||
val view = LayoutInflater.from(context).inflate(R.layout.dialog_cast_connected, null)
|
||||
|
||||
val castContext = CastContext.getSharedInstance(context)
|
||||
val castSession = castContext.sessionManager.currentCastSession
|
||||
val deviceName = castSession?.castDevice?.friendlyName ?: context.getString(R.string.media_route_menu_title)
|
||||
|
||||
view.findViewById<TextView>(R.id.textViewDeviceName).text = deviceName
|
||||
|
||||
val dialog = MaterialAlertDialogBuilder(context)
|
||||
.setView(view)
|
||||
.create()
|
||||
|
||||
view.findViewById<MaterialButton>(R.id.buttonStopCasting).setOnClickListener {
|
||||
castContext.sessionManager.endCurrentSession(true)
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
view.findViewById<MaterialButton>(R.id.buttonCancel).setOnClickListener {
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
return dialog
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.michatec.radio.ui
|
||||
|
||||
import androidx.mediarouter.app.MediaRouteChooserDialogFragment
|
||||
import androidx.mediarouter.app.MediaRouteControllerDialogFragment
|
||||
import androidx.mediarouter.app.MediaRouteDialogFactory
|
||||
|
||||
/**
|
||||
* A custom MediaRouteDialogFactory that tells the MediaRouteButton to use
|
||||
* our custom chooser and controller dialogs.
|
||||
*/
|
||||
class CustomCastDialogFactory : MediaRouteDialogFactory() {
|
||||
|
||||
override fun onCreateChooserDialogFragment(): MediaRouteChooserDialogFragment {
|
||||
return CustomCastChooserDialogFragment()
|
||||
}
|
||||
|
||||
override fun onCreateControllerDialogFragment(): MediaRouteControllerDialogFragment {
|
||||
return CustomCastControllerDialogFragment()
|
||||
}
|
||||
}
|
||||
@@ -134,6 +134,7 @@ class LayoutHolder(binding: FragmentPlayerBinding) {
|
||||
// Set up MediaRouteButton (Google Cast)
|
||||
mediaRouteButton?.let {
|
||||
CastButtonFactory.setUpMediaRouteButton(rootView.context, it)
|
||||
it.dialogFactory = CustomCastDialogFactory()
|
||||
}
|
||||
|
||||
// Apply custom theme color
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@color/icon_default"
|
||||
android:pathData="M1,10V12A9,9 0 0,1 10,21H12C12,14.92 7.07,10 1,10M1,14V16A5,5 0 0,1 6,21H8A7,7 0 0,0 1,14M1,18V21H4A3,3 0 0,0 1,18M21,3H3C1.89,3 1,3.89 1,5V8H3V5H21V19H14V21H21A2,2 0 0,0 23,19V5C23,3.89 22.1,3 21,3Z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?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="24dp"
|
||||
android:gravity="center"
|
||||
android:textAppearance="?attr/textAppearanceBodyLarge"
|
||||
android:textColor="?attr/colorOnSurfaceVariant"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<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>
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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>
|
||||
@@ -36,6 +36,14 @@
|
||||
<string name="dialog_yes_no_positive_button_default">Ja</string>
|
||||
<string name="dialog_yes_no_positive_button_remove_station">Fjern</string>
|
||||
<string name="dialog_yes_no_positive_button_update_covers">Opdater</string>
|
||||
|
||||
<!-- Custom Cast Dialog -->
|
||||
<string name="cast_connected_to">Forbundet med</string>
|
||||
<string name="cast_stop_casting">Stop afspilning</string>
|
||||
<string name="cast_cancel">Annuller</string>
|
||||
<string name="cast_chooser_title">Cast til</string>
|
||||
<string name="cast_no_devices">Ingen enheder fundet</string>
|
||||
|
||||
<!-- Fragment -->
|
||||
<string name="fragment_settings_title">Indstillinger</string>
|
||||
<!-- Notifikation -->
|
||||
|
||||
@@ -37,6 +37,14 @@
|
||||
<string name="dialog_yes_no_positive_button_default">Ja</string>
|
||||
<string name="dialog_yes_no_positive_button_remove_station">Entfernen</string>
|
||||
<string name="dialog_yes_no_positive_button_update_covers">Aktualisieren</string>
|
||||
|
||||
<!-- Custom Cast Dialog -->
|
||||
<string name="cast_connected_to">Verbunden mit</string>
|
||||
<string name="cast_stop_casting">Streaming beenden</string>
|
||||
<string name="cast_cancel">Abbrechen</string>
|
||||
<string name="cast_chooser_title">Streamen auf</string>
|
||||
<string name="cast_no_devices">Keine Geräte gefunden</string>
|
||||
|
||||
<!-- Fragment -->
|
||||
<string name="fragment_settings_title">Einstellungen</string>
|
||||
<!-- Notification -->
|
||||
|
||||
@@ -36,6 +36,14 @@
|
||||
<string name="dialog_yes_no_positive_button_default">Ναι</string>
|
||||
<string name="dialog_yes_no_positive_button_remove_station">Αφαίρεση</string>
|
||||
<string name="dialog_yes_no_positive_button_update_covers">Ενημέρωση</string>
|
||||
|
||||
<!-- Custom Cast Dialog -->
|
||||
<string name="cast_connected_to">Συνδεδεμένο με</string>
|
||||
<string name="cast_stop_casting">Διακοπή μετάδοσης</string>
|
||||
<string name="cast_cancel">Ακύρωση</string>
|
||||
<string name="cast_chooser_title">Μετάδοση σε</string>
|
||||
<string name="cast_no_devices">Δεν βρέθηκαν συσκευές</string>
|
||||
|
||||
<!-- Fragment -->
|
||||
<string name="fragment_settings_title">Ρυθμίσεις</string>
|
||||
<!-- Notification -->
|
||||
|
||||
@@ -36,6 +36,14 @@
|
||||
<string name="dialog_yes_no_positive_button_default">Oui</string>
|
||||
<string name="dialog_yes_no_positive_button_remove_station">Supprimer</string>
|
||||
<string name="dialog_yes_no_positive_button_update_covers">Mettre à jour</string>
|
||||
|
||||
<!-- Custom Cast Dialog -->
|
||||
<string name="cast_connected_to">Connecté à</string>
|
||||
<string name="cast_stop_casting">Arrêter la diffusion</string>
|
||||
<string name="cast_cancel">Annuler</string>
|
||||
<string name="cast_chooser_title">Diffuser sur</string>
|
||||
<string name="cast_no_devices">Aucun appareil trouvé</string>
|
||||
|
||||
<!-- Fragment -->
|
||||
<string name="fragment_settings_title">Paramètres</string>
|
||||
<!-- Notification -->
|
||||
|
||||
@@ -36,6 +36,14 @@
|
||||
<string name="dialog_yes_no_positive_button_default">はい</string>
|
||||
<string name="dialog_yes_no_positive_button_remove_station">削除</string>
|
||||
<string name="dialog_yes_no_positive_button_update_covers">更新</string>
|
||||
|
||||
<!-- Custom Cast Dialog -->
|
||||
<string name="cast_connected_to">接続先:</string>
|
||||
<string name="cast_stop_casting">キャストを停止</string>
|
||||
<string name="cast_cancel">キャンセル</string>
|
||||
<string name="cast_chooser_title">キャスト先</string>
|
||||
<string name="cast_no_devices">デバイスが見つかりません</string>
|
||||
|
||||
<!-- フラグメント -->
|
||||
<string name="fragment_settings_title">設定</string>
|
||||
<!-- 通知 -->
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
</style>
|
||||
|
||||
<style name="CustomCastExpandedControllerStyle" parent="CastExpandedController">
|
||||
<style name="CustomCastExpandedControllerStyle" parent="Theme.AppCompat.NoActionBar">
|
||||
<item name="castExpandedControllerStyle">@style/CastExpandedController</item>
|
||||
<item name="android:windowBackground">#FFFFFF</item>
|
||||
<item name="castBackground">#FFFFFF</item>
|
||||
<item name="castButtonColor">#FF495D92</item>
|
||||
|
||||
@@ -36,6 +36,14 @@
|
||||
<string name="dialog_yes_no_positive_button_default">Ja</string>
|
||||
<string name="dialog_yes_no_positive_button_remove_station">Verwijder</string>
|
||||
<string name="dialog_yes_no_positive_button_update_covers">Bijwerken</string>
|
||||
|
||||
<!-- Custom Cast Dialog -->
|
||||
<string name="cast_connected_to">Verbonden met</string>
|
||||
<string name="cast_stop_casting">Stoppen met casten</string>
|
||||
<string name="cast_cancel">Annuleren</string>
|
||||
<string name="cast_chooser_title">Casten naar</string>
|
||||
<string name="cast_no_devices">Geen apparaten gevonden</string>
|
||||
|
||||
<!-- Fragment -->
|
||||
<string name="fragment_settings_title">Instellingen</string>
|
||||
<!-- Notification -->
|
||||
|
||||
@@ -36,6 +36,14 @@
|
||||
<string name="dialog_yes_no_positive_button_default">Tak</string>
|
||||
<string name="dialog_yes_no_positive_button_remove_station">Usuń</string>
|
||||
<string name="dialog_yes_no_positive_button_update_covers">Aktualizuj</string>
|
||||
|
||||
<!-- Custom Cast Dialog -->
|
||||
<string name="cast_connected_to">Połączono z</string>
|
||||
<string name="cast_stop_casting">Zatrzymaj przesyłanie</string>
|
||||
<string name="cast_cancel">Anuluj</string>
|
||||
<string name="cast_chooser_title">Prześlij do</string>
|
||||
<string name="cast_no_devices">Nie znaleziono urządzeń</string>
|
||||
|
||||
<!-- Fragment -->
|
||||
<string name="fragment_settings_title">Ustawienia</string>
|
||||
<!-- Notification -->
|
||||
|
||||
@@ -36,6 +36,14 @@
|
||||
<string name="dialog_yes_no_positive_button_default">Да</string>
|
||||
<string name="dialog_yes_no_positive_button_remove_station">Удалить</string>
|
||||
<string name="dialog_yes_no_positive_button_update_covers">Обновить</string>
|
||||
|
||||
<!-- Custom Cast Dialog -->
|
||||
<string name="cast_connected_to">Подключено к</string>
|
||||
<string name="cast_stop_casting">Остановить трансляцию</string>
|
||||
<string name="cast_cancel">Отмена</string>
|
||||
<string name="cast_chooser_title">Транслировать на</string>
|
||||
<string name="cast_no_devices">Устройства не найдены</string>
|
||||
|
||||
<!-- Fragment -->
|
||||
<string name="fragment_settings_title">Настройки</string>
|
||||
<!-- Notification -->
|
||||
|
||||
@@ -36,6 +36,14 @@
|
||||
<string name="dialog_yes_no_positive_button_default">Так</string>
|
||||
<string name="dialog_yes_no_positive_button_remove_station">Видалити</string>
|
||||
<string name="dialog_yes_no_positive_button_update_covers">Оновити</string>
|
||||
|
||||
<!-- Custom Cast Dialog -->
|
||||
<string name="cast_connected_to">Підключено до</string>
|
||||
<string name="cast_stop_casting">Зупинити трансляцію</string>
|
||||
<string name="cast_cancel">Скасувати</string>
|
||||
<string name="cast_chooser_title">Транслювати на</string>
|
||||
<string name="cast_no_devices">Пристроїв не знайдено</string>
|
||||
|
||||
<!-- Fragment -->
|
||||
<string name="fragment_settings_title">Налаштування</string>
|
||||
<!-- Notification -->
|
||||
|
||||
@@ -42,6 +42,13 @@
|
||||
<string name="dialog_yes_no_positive_button_remove_station">Remove</string>
|
||||
<string name="dialog_yes_no_positive_button_update_covers">Update</string>
|
||||
|
||||
<!-- Custom Cast Dialog -->
|
||||
<string name="cast_connected_to">Connected with</string>
|
||||
<string name="cast_stop_casting">Stop casting</string>
|
||||
<string name="cast_cancel">Cancel</string>
|
||||
<string name="cast_chooser_title">Cast to</string>
|
||||
<string name="cast_no_devices">No devices found</string>
|
||||
|
||||
<!-- Fragment -->
|
||||
<string name="fragment_settings_title">Settings</string>
|
||||
|
||||
|
||||
@@ -75,7 +75,8 @@
|
||||
<item name="cornerFamilyBottomRight">rounded</item>
|
||||
</style>
|
||||
|
||||
<style name="CustomCastExpandedControllerStyle" parent="CastExpandedController">
|
||||
<style name="CustomCastExpandedControllerStyle" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="castExpandedControllerStyle">@style/CastExpandedController</item>
|
||||
<item name="android:windowBackground">#FFFFFF</item>
|
||||
<item name="castBackground">#FFFFFF</item>
|
||||
<item name="castButtonColor">#FF495D92</item>
|
||||
|
||||
Reference in new issue
Block a user