Use common string separator for title/album/artist. Add range separator for Android Auto pagination.

This commit is contained in:
Robert Stone 2024-09-16 22:25:14 -07:00 committed by Duncan McNamara
parent 27bff6827a
commit 239ae771e1
11 changed files with 27 additions and 22 deletions

View File

@ -556,7 +556,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
R.string.audio_queue_progress,
if (totalTimeText.isNullOrEmpty()) progressTimeDescription else getString(R.string.talkback_out_of, progressTimeDescription, totalTimeDescription)
)
Pair("$textTrack ${TextUtils.separator} $textProgress", "$textTrackDescription. $textDescription")
Pair("$textTrack ${TextUtils.SEPARATOR} $textProgress", "$textTrackDescription. $textDescription")
}
binding.audioPlayProgress.text = text.first
binding.audioPlayProgress.contentDescription = text.second

View File

@ -85,9 +85,9 @@ object NotificationHelper {
builder.setSmallIcon(if (video) R.drawable.ic_notif_video else R.drawable.ic_notif_audio)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentTitle(title)
.setContentText(TextUtils.separatedString('-', artist, album))
.setContentText(TextUtils.separatedString(artist, album))
.setLargeIcon(cover)
.setTicker(TextUtils.separatedString('-', title, artist))
.setTicker(TextUtils.separatedString(title, artist))
.setAutoCancel(!playing)
.setOngoing(playing)
.setCategory(NotificationCompat.CATEGORY_TRANSPORT)

View File

@ -267,12 +267,12 @@ class PlayerOptionsDelegate(val activity: FragmentActivity, val service: Playbac
started = true
}
if (media.albumName.isNotBlank()) {
if (started) append(" ${TextUtils.separator} ")
if (started) append(" ${TextUtils.SEPARATOR} ")
started = true
append(media.albumName)
}
if (media.artistName.isNotBlank()) {
if (started) append(" ${TextUtils.separator} ")
if (started) append(" ${TextUtils.SEPARATOR} ")
append(media.artistName)
}
}

View File

@ -483,7 +483,7 @@ class MediaSessionBrowser {
when {
media.type == MediaWrapper.TYPE_STREAM -> media.uri.toString()
parentId.startsWith(ID_ALBUM) -> getMediaSubtitle(media)
else -> TextUtils.separatedString('-', getMediaArtist(context, media), getMediaAlbum(context, media))
else -> TextUtils.separatedString(getMediaArtist(context, media), getMediaAlbum(context, media))
}
}
MediaLibraryItem.TYPE_PLAYLIST -> res.getString(R.string.track_number, libraryItem.tracksCount)
@ -670,7 +670,7 @@ class MediaSessionBrowser {
} else if (endTitleSize > halfLabelSize) {
endTitleSize = (maxLabelSize - beginTitleSize).coerceAtMost(endTitleSize)
}
return TextUtils.separatedString(beginTitle.abbreviate(beginTitleSize).markBidi(), endTitle.abbreviate(endTitleSize).markBidi())
return TextUtils.separatedString(TextUtils.EN_DASH, beginTitle.abbreviate(beginTitleSize).markBidi(), endTitle.abbreviate(endTitleSize).markBidi())
}
private fun getPlayAllBuilder(ctx: Context, mediaId: String, @StringRes title: Int, trackCount: Int, uri: Uri? = null): MediaDescriptionCompat.Builder {

View File

@ -341,7 +341,7 @@ object MediaUtils {
val artist = getMediaArtist(ctx, media)
val isAlbumUnknown = album == getMediaString(ctx, R.string.unknown_album)
val isArtistUnknown = artist == getMediaString(ctx, R.string.unknown_artist)
return if (!isArtistUnknown && !isAlbumUnknown) TextUtils.separatedString('-', artist.markBidi(), album.markBidi()) else null
return if (!isArtistUnknown && !isAlbumUnknown) TextUtils.separatedString(artist.markBidi(), album.markBidi()) else null
}
fun getQueuePosition(mediaPosition: Int, mediaSize: Int, shortQueue: Boolean = false): String? {

View File

@ -32,24 +32,29 @@ object TextUtils {
/**
* Common string separator used in the whole app
*/
const val separator = '·'
const val SEPARATOR = '·'
/**
* Create a string separated by the common [separator]
* En-dash separator used for ranges
*/
const val EN_DASH = ''
/**
* Create a string separated by the common [SEPARATOR]
*
* @param pieces the strings to join
* @return a string containing all the [pieces] if they are not blanked, separated by the [separator]
* @return a string containing all the [pieces] if they are not blanked, separated by the [SEPARATOR]
*/
@JvmName("separatedStringArgs")
fun separatedString(vararg pieces: String?) = separatedString(this.separator, arrayOf(*pieces))
fun separatedString(vararg pieces: String?) = separatedString(this.SEPARATOR, arrayOf(*pieces))
/**
* Create a string separated by the common [separator]
* Create a string separated by the common [SEPARATOR]
*
* @param pieces the strings to join in an [Array]
* @return a string containing all the [pieces] if they are not blanked, separated by the [separator]
* @return a string containing all the [pieces] if they are not blanked, separated by the [SEPARATOR]
*/
fun separatedString(pieces: Array<String?>) = separatedString(this.separator, pieces)
fun separatedString(pieces: Array<String?>) = separatedString(this.SEPARATOR, pieces)
/**
* Create a string separated by a custom [separator]

View File

@ -471,7 +471,7 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
private fun setupTexts(context: Context, views: RemoteViews, widgetType: WidgetType, title: String?, artist: String?) {
log(-1, WidgetLogType.INFO, "setupTexts: $title /// $artist")
views.setTextViewText(R.id.songName, title)
views.setTextViewText(R.id.artist, if (!artist.isNullOrBlank()) "${if (widgetType == WidgetType.MACRO) "" else " ${TextUtils.separator} "}$artist" else artist)
views.setTextViewText(R.id.artist, if (!artist.isNullOrBlank()) "${if (widgetType == WidgetType.MACRO) "" else " ${TextUtils.SEPARATOR} "}$artist" else artist)
if (title == context.getString(R.string.widget_default_text)) {
views.setViewVisibility(R.id.app_name, View.VISIBLE)
views.setViewVisibility(R.id.songName, View.GONE)

View File

@ -1433,7 +1433,7 @@ private fun getProviderDescriptions(context: Context, scope: CoroutineScope, pro
val unparsedDescription = pair.second
val folders = unparsedDescription.getFolderNumber()
val files = unparsedDescription.getFilesNumber()
"${context.resources.getQuantityString(org.videolan.vlc.R.plurals.subfolders_quantity, folders, folders)} ${TextUtils.separator} ${context.resources.getQuantityString(org.videolan.vlc.R.plurals.mediafiles_quantity, files, files)}"
"${context.resources.getQuantityString(org.videolan.vlc.R.plurals.subfolders_quantity, folders, folders)} ${TextUtils.SEPARATOR} ${context.resources.getQuantityString(org.videolan.vlc.R.plurals.mediafiles_quantity, files, files)}"
}
if (desc.isNotEmpty()) scope.launch(Dispatchers.IO) {
RemoteAccessWebSockets.sendToAll(RemoteAccessServer.BrowserDescription(datasetEntry.uri.toString(), desc))
@ -1444,7 +1444,7 @@ private fun getProviderDescriptions(context: Context, scope: CoroutineScope, pro
val unparsedDescription = pair.second
val folders = unparsedDescription.getFolderNumber()
val files = unparsedDescription.getFilesNumber()
val desc = "${context.resources.getQuantityString(org.videolan.vlc.R.plurals.subfolders_quantity, folders, folders)} ${TextUtils.separator} ${context.resources.getQuantityString(org.videolan.vlc.R.plurals.mediafiles_quantity, files, files)}"
val desc = "${context.resources.getQuantityString(org.videolan.vlc.R.plurals.subfolders_quantity, folders, folders)} ${TextUtils.SEPARATOR} ${context.resources.getQuantityString(org.videolan.vlc.R.plurals.mediafiles_quantity, files, files)}"
if (desc.isNotEmpty()) scope.launch(Dispatchers.IO) {
RemoteAccessWebSockets.sendToAll(RemoteAccessServer.BrowserDescription(datasetEntry.uri.toString(), desc))
}
@ -1487,7 +1487,7 @@ private suspend fun getProviderContent(context:Context, provider: BrowserProvide
val folders = unparsedDescription.getFolderNumber()
val files = unparsedDescription.getFilesNumber()
if (folders > 0 && files > 0) {
"${context.resources.getQuantityString(org.videolan.vlc.R.plurals.subfolders_quantity, folders, folders)} ${TextUtils.separator} ${context.resources.getQuantityString(org.videolan.vlc.R.plurals.mediafiles_quantity, files, files)}"
"${context.resources.getQuantityString(org.videolan.vlc.R.plurals.subfolders_quantity, folders, folders)} ${TextUtils.SEPARATOR} ${context.resources.getQuantityString(org.videolan.vlc.R.plurals.mediafiles_quantity, files, files)}"
} else if (files > 0) {
context.resources.getQuantityString(org.videolan.vlc.R.plurals.mediafiles_quantity, files, files)
} else if (folders > 0) {

View File

@ -96,7 +96,7 @@ public class Tools {
final String artist = mw.getReferenceArtist(), album = mw.getAlbumName();
final StringBuilder sb = new StringBuilder();
boolean hasArtist = !TextUtils.isEmpty(artist), hasAlbum = !TextUtils.isEmpty(album);
if (hasArtist && hasAlbum) sb.append(artist).append(" - ").append(album);
if (hasArtist && hasAlbum) sb.append(artist).append(" · ").append(album);
else if (hasArtist) sb.append(artist);
else sb.append(album);
item.setDescription(sb.toString());

View File

@ -183,7 +183,7 @@ public abstract class MediaWrapper extends MediaLibraryItem implements Parcelabl
if (hasArtistMeta) {
sb.append(artist);
if (hasAlbumMeta)
sb.append(" - ");
sb.append(" · ");
}
if (hasAlbumMeta)
sb.append(album);

View File

@ -31,7 +31,7 @@ public class StubMediaWrapper extends MediaWrapper {
if (hasArtistMeta) {
sb.append(artist);
if (hasAlbumMeta)
sb.append(" - ");
sb.append(" · ");
}
if (hasAlbumMeta)
sb.append(album);