Skip to content

Commit

Permalink
Fix local provider internal storage, add Android TV banner. Disable d…
Browse files Browse the repository at this point in the history
…ownload button on local files
  • Loading branch information
CraftWorksMC committed Nov 26, 2024
1 parent 647e904 commit 86680dd
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 77 deletions.
5 changes: 1 addition & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />


<uses-feature
android:name="android.hardware.wifi"
android:required="false" />
Expand All @@ -25,7 +24,7 @@

<application
android:allowBackup="true"
android:banner="@mipmap/ic_launcher"
android:banner="@mipmap/ic_banner"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
Expand All @@ -40,11 +39,9 @@
tools:targetApi="31"
tools:ignore="UnusedAttribute">

<!-- documentation really sucks -->
<meta-data android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>


<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,80 +48,75 @@ class LocalProvider private constructor() {
}
}

//for (dir in LocalProviderManager.getAllFolders()){
applicationContext?.let { context ->
val contentResolver: ContentResolver = context.contentResolver
val uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
val projection = arrayOf(
MediaStore.Audio.Media._ID,
MediaStore.Audio.Albums.ALBUM,
MediaStore.Audio.Albums.ARTIST,
//MediaStore.Audio.Media.DATE_ADDED,
//MediaStore.Audio.Media.YEAR
)
val cursor: Cursor? = contentResolver.query(
uri,
projection,
//"${MediaStore.Audio.Media.DATA} LIKE ?",
"${MediaStore.Audio.Media.DATA} LIKE ?" +
" OR ${MediaStore.Audio.Media.DATA} LIKE ?"
.repeat(LocalProviderManager.getAllFolders().size - 1),
LocalProviderManager.getAllFolders().map {
"%$it%"
}.toTypedArray(),
sortOrder
)

when {
cursor == null -> {
// query failed, handle error.
}

!cursor.moveToFirst() -> {
// no media on the device
}

else -> {
val idColumn: Int = cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID)
val albumColumn: Int = cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM)
val artistColumn: Int = cursor.getColumnIndex(MediaStore.Audio.Albums.ARTIST)
//val dateAddedColumn: Int = cursor.getColumnIndex(MediaStore.Audio.Media.DATE_ADDED)
//val yearColumn: Int = cursor.getColumnIndex(MediaStore.Audio.Media.YEAR)

do {
val thisId = cursor.getLongOrNull(idColumn) ?: 0
val thisAlbum = cursor.getStringOrNull(albumColumn) ?: "Unknown"
val thisArtist = cursor.getStringOrNull(artistColumn) ?: "Unknown"
//val thisDateAdded = cursor.getString(dateAddedColumn)
//val thisYear = cursor.getInt(yearColumn)

val imageUri: String = try {
"content://media/external/audio/media/$thisId/albumart"
} catch (_: FileNotFoundException) {
println("No Album Art!")
}.toString()

val album = MediaData.Album(
navidromeID = "Local_$thisId",
name = thisAlbum,
album = thisAlbum,
title = thisAlbum,
artist = thisArtist,
coverArt = imageUri,
songCount = 0,
duration = 0,
artistId = "",
)
applicationContext?.let { context ->
val contentResolver: ContentResolver = context.contentResolver
val uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
val projection = arrayOf(
MediaStore.Audio.Media._ID,
MediaStore.Audio.Albums.ALBUM,
MediaStore.Audio.Albums.ARTIST,
)
val cursor: Cursor? = contentResolver.query(
uri,
projection,
"${MediaStore.Audio.Media.DATA} LIKE ?" +
" OR ${MediaStore.Audio.Media.DATA} LIKE ?"
.repeat(LocalProviderManager.getAllFolders().size - 1),
LocalProviderManager.getAllFolders().map {
"%$it%"
}.toTypedArray(),
sortOrder
)

if (!albums.contains(album))
albums.add(album)
} while (cursor.moveToNext())
}
when {
cursor == null -> {
// query failed, handle error.
}

cursor?.close()
!cursor.moveToFirst() -> {
// no media on the device
}

else -> {
val idColumn: Int = cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID)
val albumColumn: Int = cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM)
val artistColumn: Int = cursor.getColumnIndex(MediaStore.Audio.Albums.ARTIST)
//val dateAddedColumn: Int = cursor.getColumnIndex(MediaStore.Audio.Media.DATE_ADDED)
//val yearColumn: Int = cursor.getColumnIndex(MediaStore.Audio.Media.YEAR)

do {
val thisId = cursor.getLongOrNull(idColumn) ?: 0
val thisAlbum = cursor.getStringOrNull(albumColumn) ?: "Unknown"
val thisArtist = cursor.getStringOrNull(artistColumn) ?: "Unknown"
//val thisDateAdded = cursor.getString(dateAddedColumn)
//val thisYear = cursor.getInt(yearColumn)

val imageUri: String = try {
"content://media/external/audio/media/$thisId/albumart"
} catch (_: FileNotFoundException) {
println("No Album Art!")
}.toString()

val album = MediaData.Album(
navidromeID = "Local_$thisId",
name = thisAlbum,
album = thisAlbum,
title = thisAlbum,
artist = thisArtist,
coverArt = imageUri,
songCount = 0,
duration = 0,
artistId = "",
)

if (!albums.contains(album))
albums.add(album)
} while (cursor.moveToNext())
}
}
//}

cursor?.close()
}

return albums
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
Expand All @@ -56,6 +57,7 @@ import com.craftworks.music.R
import com.craftworks.music.data.MediaData
import com.craftworks.music.data.radioList
import com.craftworks.music.formatMilliseconds
import com.craftworks.music.managers.NavidromeManager
import com.craftworks.music.providers.navidrome.downloadNavidromeSong
import com.craftworks.music.ui.elements.dialogs.showAddSongToPlaylistDialog
import com.craftworks.music.ui.elements.dialogs.songToAddToPlaylist
Expand Down Expand Up @@ -149,7 +151,7 @@ fun HorizontalSongCard(song: MediaData.Song, onClick: () -> Unit) {
onClick = { onClick(); Log.d("Play", "Clicked Song: " + song.title) },
shape = RoundedCornerShape(12.dp),
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.background,
containerColor = Color.Transparent,
contentColor = MaterialTheme.colorScheme.onBackground,
disabledContainerColor = MaterialTheme.colorScheme.tertiaryContainer,
disabledContentColor = MaterialTheme.colorScheme.onTertiaryContainer
Expand Down Expand Up @@ -268,6 +270,7 @@ fun HorizontalSongCard(song: MediaData.Song, onClick: () -> Unit) {
}
)
DropdownMenuItem(
enabled = NavidromeManager.checkActiveServers(),
text = {
Text(stringResource(R.string.Action_Download))
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,9 @@ fun DownloadButton(color: Color, size: Dp) {
.bounceClick(),
contentPadding = PaddingValues(0.dp),
colors = ButtonDefaults.buttonColors(
containerColor = Color.Transparent
containerColor = Color.Transparent,
disabledContainerColor = Color.Transparent,
disabledContentColor = color.copy(alpha = 0.25f)
)
) {
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,6 @@ private fun SettingsSwitch(
overflow = TextOverflow.Ellipsis,
textAlign = TextAlign.Start
)
Switch(checked = selected, onCheckedChange = {})
Switch(checked = selected, onCheckedChange = { toggleEvent() })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.clickable
import androidx.compose.foundation.indication
import androidx.compose.foundation.interaction.Interaction
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down
42 changes: 42 additions & 0 deletions app/src/main/res/drawable/ic_banner_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="320dp"
android:height="180dp"
android:viewportWidth="320"
android:viewportHeight="180">
<group android:scaleX="0.6666667"
android:scaleY="0.6666667"
android:translateX="53.333332"
android:translateY="30">
<path
android:pathData="M0,0h320v180h-320z">
<aapt:attr name="android:fillColor">
<gradient
android:startX="160"
android:startY="0"
android:endX="0"
android:endY="180"
android:type="linear">
<item android:offset="0" android:color="#FFB4BEFE"/>
<item android:offset="1" android:color="#FF89DCEB"/>
</gradient>
</aapt:attr>
</path>
<path
android:pathData="M0,0h320v180h-320z"
android:strokeAlpha="0.5"
android:fillAlpha="0.5">
<aapt:attr name="android:fillColor">
<gradient
android:startX="157.5"
android:startY="88.5"
android:endX="320"
android:endY="-0"
android:type="linear">
<item android:offset="0" android:color="#00B4BEFE"/>
<item android:offset="1" android:color="#FF89DCEB"/>
</gradient>
</aapt:attr>
</path>
</group>
</vector>
18 changes: 18 additions & 0 deletions app/src/main/res/drawable/ic_banner_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="320dp"
android:height="180dp"
android:viewportWidth="320"
android:viewportHeight="180">
<group android:scaleX="0.6666667"
android:scaleY="0.6666667"
android:translateX="53.333332"
android:translateY="30">
<path
android:pathData="M41.47,63.67C45.59,63.44 47.11,65.3 46.04,69.24C44.77,70.38 43.39,71.38 41.92,72.25C34.43,78.79 32.31,86.77 35.57,96.18C40.33,105.7 48.01,109.75 58.62,108.32C68.65,105.45 74.07,98.81 74.87,88.39C74.77,82.47 72.66,77.43 68.53,73.25C67.15,79.08 65.89,84.94 64.74,90.84C62.94,96.85 58.89,99.63 52.61,99.19C46.54,97.78 43.53,93.96 43.59,87.72C44.36,82.42 47.37,79.19 52.61,78.04C55.77,77.64 58.59,78.42 61.07,80.37C62.14,75.87 63.14,71.34 64.07,66.79C65.23,64.82 66.9,64.11 69.08,64.68C76.57,69.2 80.83,75.84 81.89,84.6C82.99,96.98 78.28,106.37 67.75,112.77C61.23,116.12 54.4,116.93 47.26,115.22C37.13,112.21 30.56,105.64 27.56,95.51C24.85,81.6 29.49,70.99 41.47,63.67Z"
android:fillColor="#313244"
android:fillAlpha="0.967"/>
<path
android:pathData="M114.17,72.42H114.58C121.04,72.42 126.28,75.42 130.3,81.43C131.08,82.75 131.64,83.97 131.97,85.09L131.76,85.2H125.69C122.82,80.66 119.05,78.39 114.38,78.39C110.43,78.39 107.11,80.03 104.42,83.31C102.68,85.62 101.8,88.17 101.8,90.96C101.8,95.93 104.25,99.78 109.14,102.48C111,103.18 112.65,103.53 114.06,103.53H114.69C119.42,103.53 123.19,101.05 126,96.09H131.97C132.11,96.11 132.18,96.18 132.18,96.3C131,100.02 129.01,102.99 126.21,105.21C122.74,108.07 119,109.5 115,109.5H113.75C108.56,109.5 103.95,107.19 99.92,102.59C97.2,99.11 95.83,95.31 95.83,91.17V90.75C95.83,84.11 99.01,78.77 105.37,74.72C108.25,73.19 111.18,72.42 114.17,72.42ZM141.66,109.29C141.66,109.43 141.59,109.5 141.45,109.5H135.9C135.76,109.5 135.69,109.43 135.69,109.29V97.24C135.69,94.38 135.66,92.29 135.59,90.96C135.66,89.63 135.69,87.54 135.69,84.67V62.67C135.71,62.54 135.78,62.47 135.9,62.47H141.45C141.59,62.48 141.66,62.55 141.66,62.67V77.24C145.37,74.02 149.45,72.42 153.92,72.42H154.34C161.11,72.42 166.52,75.7 170.58,82.26C171.97,85.14 172.67,87.87 172.67,90.43V109.29C172.67,109.43 172.6,109.5 172.46,109.5H166.8C166.66,109.5 166.6,109.43 166.6,109.29L166.7,89.7C166.23,87.01 165.43,84.95 164.29,83.52C161.55,80.1 158.16,78.39 154.13,78.39C149.12,78.39 145.28,80.87 142.61,85.83C141.98,87.48 141.66,88.88 141.66,90.02V92.01C141.66,93.32 141.66,99.08 141.66,109.29ZM197.92,72.42H198.54C204.53,72.42 209.56,75.14 213.63,80.59C215.73,83.82 216.77,87.1 216.77,90.43V91.48C216.77,97.51 213.87,102.6 208.08,106.78C204.9,108.59 201.86,109.5 198.96,109.5H197.39C192.84,109.5 188.47,107.4 184.3,103.21C181.29,99.43 179.79,95.45 179.79,91.27V90.75C179.79,84.85 182.38,79.89 187.55,75.87C190.86,73.57 194.32,72.42 197.92,72.42ZM185.76,90.64V91.27C185.76,95.67 187.9,99.23 192.15,101.96C194.09,103 195.94,103.53 197.71,103.53H198.76C202.54,103.53 205.79,101.78 208.5,98.29C210.03,96.06 210.8,93.75 210.8,91.38V90.54C210.8,85.9 208.36,82.19 203.47,79.44C201.63,78.74 199.96,78.39 198.44,78.39H198.13C194.93,78.39 192.07,79.58 189.54,81.95C187.02,84.57 185.76,87.47 185.76,90.64ZM244.17,78.91C242.96,78.56 241.77,78.39 240.6,78.39C233.73,78.56 229.71,81.53 228.56,87.29L228.14,93.37V109.29C228.14,109.43 228.07,109.5 227.93,109.5H222.38C222.24,109.5 222.17,109.43 222.17,109.29V97.24C222.17,94.76 222.13,92.49 222.06,90.43C222.13,89.86 222.17,88.46 222.17,86.24C224.56,76.36 231.51,71.75 243.01,72.42H243.43C243.68,72.42 243.92,72.43 244.17,72.44V78.91ZM268.47,72.42H269.1C273.51,72.42 277.64,74.06 281.46,77.34V72.63C281.48,72.49 281.55,72.42 281.67,72.42H287.22C287.36,72.43 287.43,72.5 287.43,72.63V109.29C287.43,109.43 287.36,109.5 287.22,109.5H281.67C281.53,109.5 281.46,109.43 281.46,109.29V104.58C277.67,107.86 273.69,109.5 269.52,109.5H267.95C263.39,109.5 259.02,107.4 254.85,103.21C251.85,99.43 250.35,95.45 250.35,91.27V90.75C250.35,84.85 252.93,79.89 258.1,75.87C261.42,73.57 264.87,72.42 268.47,72.42ZM256.32,90.64V91.27C256.32,95.67 258.45,99.23 262.71,101.96C264.64,103 266.5,103.53 268.26,103.53H269.31C273.1,103.53 276.34,101.78 279.05,98.29C280.58,96.06 281.35,93.75 281.35,91.38V90.54C281.35,85.9 278.91,82.19 274.02,79.44C272.19,78.74 270.51,78.39 268.99,78.39H268.68C265.48,78.39 262.62,79.58 260.09,81.95C257.57,84.57 256.32,87.47 256.32,90.64Z"
android:fillColor="#313244"/>
</group>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/mipmap-anydpi-v26/ic_banner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_banner_background"/>
<foreground android:drawable="@drawable/ic_banner_foreground"/>
</adaptive-icon>

0 comments on commit 86680dd

Please sign in to comment.