Skip to content

Commit

Permalink
Change animated bg color handling, small ui changes, local provider n…
Browse files Browse the repository at this point in the history
…ow scans local files
  • Loading branch information
CraftWorksMC committed Nov 27, 2024
1 parent 86680dd commit ed074b3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.content.ContentResolver
import android.content.ContentUris
import android.content.Context
import android.database.Cursor
import android.media.MediaScannerConnection
import android.net.Uri
import android.os.Environment
import android.provider.MediaStore
import android.util.Log
import androidx.core.database.getIntOrNull
Expand All @@ -31,6 +33,14 @@ class LocalProvider private constructor() {

fun init(context: Context) {
applicationContext = context.applicationContext

scanLocalFiles()
}

fun scanLocalFiles() {
MediaScannerConnection.scanFile(
applicationContext, arrayOf(Environment.getExternalStorageDirectory().path), null
) { _, _ -> Log.i("Scan For Files", "Media Scan Completed") }
}

//region Albums
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.os.Environment
import android.util.Log
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.OptIn
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
Expand All @@ -17,14 +15,13 @@ import androidx.media3.common.util.UnstableApi
import com.craftworks.music.R
import com.craftworks.music.data.MediaData
import com.craftworks.music.managers.NavidromeManager.getCurrentServer
import com.craftworks.music.player.SongHelper
import com.craftworks.music.providers.local.LocalProvider
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.net.URL
import kotlin.io.path.exists

@OptIn(UnstableApi::class)
suspend fun downloadNavidromeSong(
Expand Down Expand Up @@ -119,11 +116,14 @@ suspend fun downloadNavidromeSong(
song.title + " " + context.getString(R.string.Notification_Download_Success),
Toast.LENGTH_SHORT
).show()

LocalProvider.getInstance().scanLocalFiles();
}

} catch (e: Exception) {
e.printStackTrace()


// Show failure notification
notificationBuilder
.setContentText(context.getString(R.string.Notification_Download_Failure) + " " + song.title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ fun HorizontalSongCard(song: MediaData.Song, onClick: () -> Unit) {
}
)
DropdownMenuItem(
enabled = NavidromeManager.checkActiveServers(),
enabled = !song.navidromeID.startsWith("Local_"),
text = {
Text(stringResource(R.string.Action_Download))
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import com.craftworks.music.R
import com.craftworks.music.data.BottomNavItem
import com.craftworks.music.managers.SettingsManager
import com.craftworks.music.ui.elements.bounceClick
import com.craftworks.music.ui.viewmodels.GlobalViewModels
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import sh.calvin.reorderable.ReorderableItem
Expand Down Expand Up @@ -235,6 +236,28 @@ fun ThemeDialog(setShowDialog: (Boolean) -> Unit) {
onClick = {
runBlocking {
SettingsManager(context).setAppTheme(option)
val uiModeManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager

when (option) {
SettingsManager.Companion.AppTheme.DARK -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
uiModeManager.setApplicationNightMode(UiModeManager.MODE_NIGHT_YES)
else
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}
SettingsManager.Companion.AppTheme.LIGHT -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
uiModeManager.setApplicationNightMode(UiModeManager.MODE_NIGHT_NO)
else
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
SettingsManager.Companion.AppTheme.SYSTEM -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
uiModeManager.setApplicationNightMode(UiModeManager.MODE_NIGHT_AUTO)
else
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
}
}
}
setShowDialog(false)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ private fun StaticBlurBG(
}

Canvas(modifier = Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background)) {
// Draw all gradients in a single pass
drawRect(
Brush.radialGradient(
colors = listOf(animatedColors[0], Color.Transparent),
Expand Down Expand Up @@ -161,50 +160,35 @@ fun AnimatedGradientBG(
uniform float iTime;
uniform float3 color1;
uniform float3 color2;
// ACES Filmic Tone Mapping Function
float3 ACESFilm(float3 x) {
float a = 2.51;
float b = 0.03;
float c = 2.43;
float d = 0.59;
float e = 0.14;
return saturate((x * (a * x + b)) / (x * (c * x + d) + e));
}
float3 reinhardToneMapping(float3 color) {
float luminance = dot(color, float3(0.2126, 0.7152, 0.0722));
return color / (color + 1.0);
}
uniform float3 color3;
half4 main(vec2 fragCoord) {
float mr = min(iResolution.x, iResolution.y);
vec2 uv = (fragCoord * 0.5 - iResolution.xy) / mr;
vec2 uv = (fragCoord * 2 - iResolution.xy) / mr;
float d = -iTime * 0.5;
float a = 0.0;
for (float i = 0.0; i < 8.0; ++i) {
for (float i = 0.0; i < 4; ++i) {
a += cos(i - d - a * uv.x);
d += sin(uv.y * i + a);
}
d += iTime * 0.5;
float mixFactor = (cos(uv.x * d) + sin(uv.y * a)) * 0.5 + 0.5;
float3 col = mix(color1, color2, mixFactor);
col = reinhardToneMapping(col);
//float mixFactor = (cos(uv.x * d) + sin(uv.y * a)) * 0.5 + 0.5;
//float3 col = mix(color1, color2, mixFactor);
vec3 col = vec3(cos(uv * vec2(d, a)).x * 0.6 + 0.4, cos(a + d) * 0.5 + 0.5, 0.0);
float blendValue = (col.x + col.y) * 0.5;
//col = ACESFilm(col);
col = mix(color1, color2, blendValue);
col = mix(col, color3, smoothstep(0.0, 1.0, sin(d) * 0.5 + 0.5));
return half4(col, 1.0);
}
"""

var time by remember { mutableFloatStateOf(0f) }

// val currentColor1 by rememberUpdatedState(color1)
// val currentColor2 by rememberUpdatedState(color2)

val currentColor1 by animateColorAsState(
targetValue = color1,
animationSpec = tween(durationMillis = 1000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ fun DownloadButton(color: Color, size: Dp) {
downloadNavidromeSong(context, SongHelper.currentSong)
}
},
enabled = NavidromeManager.checkActiveServers(),
enabled = !SongHelper.currentSong.navidromeID.startsWith("Local_"),
shape = CircleShape,
modifier = Modifier
.height(size)
Expand All @@ -389,12 +389,12 @@ fun DownloadButton(color: Color, size: Dp) {
colors = ButtonDefaults.buttonColors(
containerColor = Color.Transparent,
disabledContainerColor = Color.Transparent,
disabledContentColor = color.copy(alpha = 0.25f)
disabledContentColor = Color.Transparent
)
) {
Icon(
imageVector = ImageVector.vectorResource(R.drawable.rounded_download_24),
tint = color.copy(alpha = 0.5f),
tint = if (SongHelper.currentSong.navidromeID.startsWith("Local_")) color.copy(alpha = 0.25f) else color.copy(alpha = 0.5f),
contentDescription = "Download Song",
modifier = Modifier
.height(size)
Expand Down

0 comments on commit ed074b3

Please sign in to comment.