Skip to content

Commit

Permalink
feat: squiggly bar optional closes #194, centered sleep closes #191
Browse files Browse the repository at this point in the history
  • Loading branch information
Malopieds committed Jul 11, 2024
1 parent d02f783 commit ad5fad1
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 17 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ dependencies {
implementation(libs.media3)
implementation(libs.media3.session)
implementation(libs.media3.okhttp)
implementation(libs.squigglyslider)

implementation(libs.room.runtime)
annotationProcessor(libs.room.compiler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ enum class PlayerBackgroundStyle {
GRADIENT,
}

val EnableSquigglySlider = booleanPreferencesKey("enableSquigglySlider")
val TopSize = stringPreferencesKey("topSize")

val PlayerBackgroundStyleKey = stringPreferencesKey("playerBackgroundStyle")
Expand Down
75 changes: 58 additions & 17 deletions app/src/main/java/com/malopieds/innertune/ui/player/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
Expand Down Expand Up @@ -95,6 +96,7 @@ import com.malopieds.innertune.LocalDatabase
import com.malopieds.innertune.LocalDownloadUtil
import com.malopieds.innertune.LocalPlayerConnection
import com.malopieds.innertune.R
import com.malopieds.innertune.constants.EnableSquigglySlider
import com.malopieds.innertune.constants.ListThumbnailSize
import com.malopieds.innertune.constants.PlayerBackgroundStyle
import com.malopieds.innertune.constants.PlayerBackgroundStyleKey
Expand Down Expand Up @@ -124,10 +126,11 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.withContext
import me.saket.squiggles.SquigglySlider
import java.time.LocalDateTime
import kotlin.math.roundToInt

@OptIn(ExperimentalFoundationApi::class)
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
@Composable
fun BottomSheetPlayer(
state: BottomSheetState,
Expand All @@ -153,6 +156,8 @@ fun BottomSheetPlayer(
var showLyrics by rememberPreference(ShowLyricsKey, defaultValue = false)
val playerBackground by rememberEnumPreference(key = PlayerBackgroundStyleKey, defaultValue = PlayerBackgroundStyle.DEFAULT)

val enableSquigglySlider by rememberPreference(EnableSquigglySlider, defaultValue = true)

var position by rememberSaveable(playbackState) {
mutableLongStateOf(playerConnection.player.currentPosition)
}
Expand Down Expand Up @@ -703,11 +708,24 @@ fun BottomSheetPlayer(
.clickable(onClick = playerConnection.service.sleepTimer::clear),
)
} else {
IconButton(onClick = { showSleepTimerDialog = true }) {
Box(
modifier =
Modifier
.size(42.dp)
.clip(RoundedCornerShape(24.dp))
.background(MaterialTheme.colorScheme.primary)
.clickable {
showSleepTimerDialog = true
},
) {
Image(
painter = painterResource(R.drawable.bedtime),
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onPrimary),
contentDescription = null,
modifier =
Modifier
.align(Alignment.Center)
.size(24.dp),
)
}
}
Expand Down Expand Up @@ -745,21 +763,44 @@ fun BottomSheetPlayer(

Spacer(Modifier.height(6.dp))

Slider(
value = (sliderPosition ?: position).toFloat(),
valueRange = 0f..(if (duration == C.TIME_UNSET) 0f else duration.toFloat()),
onValueChange = {
sliderPosition = it.toLong()
},
onValueChangeFinished = {
sliderPosition?.let {
playerConnection.player.seekTo(it)
position = it
}
sliderPosition = null
},
modifier = Modifier.padding(horizontal = PlayerHorizontalPadding),
)
if (enableSquigglySlider) {
SquigglySlider(
value = (sliderPosition ?: position).toFloat(),
valueRange = 0f..(if (duration == C.TIME_UNSET) 0f else duration.toFloat()),
onValueChange = {
sliderPosition = it.toLong()
},
onValueChangeFinished = {
sliderPosition?.let {
playerConnection.player.seekTo(it)
position = it
}
sliderPosition = null
},
modifier = Modifier.padding(horizontal = PlayerHorizontalPadding),
squigglesSpec =
SquigglySlider.SquigglesSpec(
amplitude = if (isPlaying) (2.dp).coerceAtLeast(2.dp) else 0.dp,
strokeWidth = 3.dp,
),
)
} else {
Slider(
value = (sliderPosition ?: position).toFloat(),
valueRange = 0f..(if (duration == C.TIME_UNSET) 0f else duration.toFloat()),
onValueChange = {
sliderPosition = it.toLong()
},
onValueChangeFinished = {
sliderPosition?.let {
playerConnection.player.seekTo(it)
position = it
}
sliderPosition = null
},
modifier = Modifier.padding(horizontal = PlayerHorizontalPadding),
)
}

Row(
horizontalArrangement = Arrangement.SpaceBetween,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.malopieds.innertune.R
import com.malopieds.innertune.constants.DarkModeKey
import com.malopieds.innertune.constants.DefaultOpenTabKey
import com.malopieds.innertune.constants.DynamicThemeKey
import com.malopieds.innertune.constants.EnableSquigglySlider
import com.malopieds.innertune.constants.LyricsTextPositionKey
import com.malopieds.innertune.constants.PlayerBackgroundStyle
import com.malopieds.innertune.constants.PlayerBackgroundStyleKey
Expand Down Expand Up @@ -46,6 +47,7 @@ fun AppearanceSettings(
val (pureBlack, onPureBlackChange) = rememberPreference(PureBlackKey, defaultValue = false)
val (defaultOpenTab, onDefaultOpenTabChange) = rememberEnumPreference(DefaultOpenTabKey, defaultValue = NavigationTab.HOME)
val (lyricsPosition, onLyricsPositionChange) = rememberEnumPreference(LyricsTextPositionKey, defaultValue = LyricsPosition.CENTER)
val (squigglySlider, onSquigglySliderChange) = rememberPreference(EnableSquigglySlider, defaultValue = true)

Column(
Modifier
Expand Down Expand Up @@ -85,6 +87,13 @@ fun AppearanceSettings(
},
)

SwitchPreference(
title = { Text(stringResource(R.string.enable_squiggly_slider)) },
icon = { Icon(painterResource(R.drawable.waves), null) },
checked = squigglySlider,
onCheckedChange = onSquigglySliderChange,
)

SwitchPreference(
title = { Text(stringResource(R.string.pure_black)) },
icon = { Icon(painterResource(R.drawable.contrast), null) },
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/waves.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M17,16.99c-1.35,0 -2.2,0.42 -2.95,0.8 -0.65,0.33 -1.18,0.6 -2.05,0.6 -0.9,0 -1.4,-0.25 -2.05,-0.6 -0.75,-0.38 -1.57,-0.8 -2.95,-0.8s-2.2,0.42 -2.95,0.8c-0.65,0.33 -1.17,0.6 -2.05,0.6v1.95c1.35,0 2.2,-0.42 2.95,-0.8 0.65,-0.33 1.17,-0.6 2.05,-0.6s1.4,0.25 2.05,0.6c0.75,0.38 1.57,0.8 2.95,0.8s2.2,-0.42 2.95,-0.8c0.65,-0.33 1.18,-0.6 2.05,-0.6 0.9,0 1.4,0.25 2.05,0.6 0.75,0.38 1.58,0.8 2.95,0.8v-1.95c-0.9,0 -1.4,-0.25 -2.05,-0.6 -0.75,-0.38 -1.6,-0.8 -2.95,-0.8zM17,12.54c-1.35,0 -2.2,0.43 -2.95,0.8 -0.65,0.32 -1.18,0.6 -2.05,0.6 -0.9,0 -1.4,-0.25 -2.05,-0.6 -0.75,-0.38 -1.57,-0.8 -2.95,-0.8s-2.2,0.43 -2.95,0.8c-0.65,0.32 -1.17,0.6 -2.05,0.6v1.95c1.35,0 2.2,-0.43 2.95,-0.8 0.65,-0.35 1.15,-0.6 2.05,-0.6s1.4,0.25 2.05,0.6c0.75,0.38 1.57,0.8 2.95,0.8s2.2,-0.43 2.95,-0.8c0.65,-0.35 1.15,-0.6 2.05,-0.6s1.4,0.25 2.05,0.6c0.75,0.38 1.58,0.8 2.95,0.8v-1.95c-0.9,0 -1.4,-0.25 -2.05,-0.6 -0.75,-0.38 -1.6,-0.8 -2.95,-0.8zM19.95,4.46c-0.75,-0.38 -1.58,-0.8 -2.95,-0.8s-2.2,0.42 -2.95,0.8c-0.65,0.32 -1.18,0.6 -2.05,0.6 -0.9,0 -1.4,-0.25 -2.05,-0.6 -0.75,-0.37 -1.57,-0.8 -2.95,-0.8s-2.2,0.42 -2.95,0.8c-0.65,0.33 -1.17,0.6 -2.05,0.6v1.93c1.35,0 2.2,-0.43 2.95,-0.8 0.65,-0.33 1.17,-0.6 2.05,-0.6s1.4,0.25 2.05,0.6c0.75,0.38 1.57,0.8 2.95,0.8s2.2,-0.43 2.95,-0.8c0.65,-0.32 1.18,-0.6 2.05,-0.6 0.9,0 1.4,0.25 2.05,0.6 0.75,0.38 1.58,0.8 2.95,0.8L22,5.04c-0.9,0 -1.4,-0.25 -2.05,-0.58zM17,8.09c-1.35,0 -2.2,0.43 -2.95,0.8 -0.65,0.35 -1.15,0.6 -2.05,0.6s-1.4,-0.25 -2.05,-0.6c-0.75,-0.38 -1.57,-0.8 -2.95,-0.8s-2.2,0.43 -2.95,0.8c-0.65,0.35 -1.15,0.6 -2.05,0.6v1.95c1.35,0 2.2,-0.43 2.95,-0.8 0.65,-0.32 1.18,-0.6 2.05,-0.6s1.4,0.25 2.05,0.6c0.75,0.38 1.57,0.8 2.95,0.8s2.2,-0.43 2.95,-0.8c0.65,-0.32 1.18,-0.6 2.05,-0.6 0.9,0 1.4,0.25 2.05,0.6 0.75,0.38 1.58,0.8 2.95,0.8L22,9.49c-0.9,0 -1.4,-0.25 -2.05,-0.6 -0.75,-0.38 -1.6,-0.8 -2.95,-0.8z"/>

</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
<string name="player_background_style">Player background style</string>
<string name="follow_theme">Follow theme</string>
<string name="gradient">Gradient</string>
<string name="enable_squiggly_slider">Enable squiggly slider</string>
<string name="pure_black">Pure black</string>
<string name="default_open_tab">Default open tab</string>
<string name="customize_navigation_tabs">Customize navigation tabs</string>
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ room = "2.6.1"
hilt = "2.51.1"
ktor = "2.3.12"
ksp = "2.0.0-1.0.21"
squigglyslider = "1.0.0"

[libraries]
guava = { group = "com.google.guava", name = "guava", version = "32.1.3-android" }
Expand All @@ -31,6 +32,7 @@ compose-animation-graphics = { group = "androidx.compose.animation", name = "ani
compose-reorderable = { group = "org.burnoutcrew.composereorderable", name = "reorderable", version = "0.9.6" }


squigglyslider = { module = "me.saket.squigglyslider:squigglyslider", version.ref = "squigglyslider" }
viewmodel = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version.ref = "lifecycle" }
viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "lifecycle" }

Expand Down

0 comments on commit ad5fad1

Please sign in to comment.