Skip to content

Commit

Permalink
Merge pull request #537 from 07jasjeet/refactor-plus-fix
Browse files Browse the repository at this point in the history
Minor UI improvements + perf fix
  • Loading branch information
07jasjeet authored Jan 26, 2025
2 parents ba19e95 + afb9013 commit 74c5347
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Slider
import androidx.compose.material.SliderDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.res.colorResource
Expand All @@ -20,6 +24,7 @@ import androidx.compose.ui.semantics.progressBarRangeInfo
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import org.listenbrainz.android.R
import org.listenbrainz.android.ui.theme.ListenBrainzTheme

@Composable
fun SeekBar(
Expand Down Expand Up @@ -47,7 +52,9 @@ fun CustomSeekBar(
@FloatRange(from = 0.0, to = 1.0)
progress: Float,
onValueChange: (Float) -> Unit,
remainingProgressColor: Color = Color.Transparent
shape: Shape = RectangleShape,
progressColor: Color = ListenBrainzTheme.colorScheme.lbSignature,
remainingProgressColor: Color = ListenBrainzTheme.colorScheme.hint
) {
val range = 0f..1f

Expand Down Expand Up @@ -82,17 +89,17 @@ fun CustomSeekBar(
Box(
modifier = Modifier
.fillMaxWidth()
.height(4.dp)
.height(5.dp)
.graphicsLayer {
alpha = 0.2f
}
.background(remainingProgressColor)
.background(remainingProgressColor, shape)
)
Box(
modifier = Modifier
.fillMaxWidth(progress)
.height(4.dp)
.background(colorResource(id = R.color.bp_color_primary))
.height(5.dp)
.background(progressColor, shape)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.BackdropScaffold
import androidx.compose.material.BackdropScaffoldState
Expand Down Expand Up @@ -56,6 +57,7 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
Expand All @@ -69,7 +71,6 @@ import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
Expand Down Expand Up @@ -98,6 +99,7 @@ import org.listenbrainz.android.util.BrainzPlayerExtensions.toSong
import org.listenbrainz.android.util.SongViewPager
import org.listenbrainz.android.viewmodel.BrainzPlayerViewModel
import org.listenbrainz.android.viewmodel.PlaylistViewModel
import java.util.Locale
import kotlin.math.absoluteValue
import kotlin.math.max

Expand Down Expand Up @@ -293,11 +295,11 @@ fun PlayerScreen(
.fillMaxWidth(0.98F)
.padding(horizontal = 20.dp),
progress = progress,
shape = CircleShape,
onValueChange = { newProgress ->
brainzPlayerViewModel.onSeek(newProgress)
brainzPlayerViewModel.onSeeked()
},
remainingProgressColor = colorResource(id = R.color.bp_color_primary)
}
)
}
Row(
Expand All @@ -308,32 +310,44 @@ fun PlayerScreen(
.padding(start = 22.dp, top = 10.dp, end = 22.dp)
) {
val songCurrentPosition by brainzPlayerViewModel.songCurrentPosition.collectAsState()
val duration: String
val currentPosition: String
if (currentlyPlayingSong.duration / (1000 * 60 * 60) > 0 && songCurrentPosition / (1000 * 60 * 60) > 0) {
duration = String.format(
"%02d:%02d:%02d",
currentlyPlayingSong.duration / (1000 * 60 * 60),
currentlyPlayingSong.duration / (1000 * 60) % 60,
currentlyPlayingSong.duration / 1000 % 60
)
currentPosition = String.format(
"%02d:%02d:%02d",
songCurrentPosition / (1000 * 60 * 60),
songCurrentPosition / (1000 * 60) % 60,
songCurrentPosition / 1000 % 60
)
} else {
duration = String.format(
"%02d:%02d",
currentlyPlayingSong.duration / (1000 * 60) % 60,
currentlyPlayingSong.duration / 1000 % 60
)
currentPosition = String.format(
"%02d:%02d",
songCurrentPosition / (1000 * 60) % 60,
songCurrentPosition / 1000 % 60
)

val (duration, currentPosition) = remember(
currentlyPlayingSong.duration,
songCurrentPosition
) {
val duration: String
val currentPosition: String
if (currentlyPlayingSong.duration / (1000 * 60 * 60) > 0 && songCurrentPosition / (1000 * 60 * 60) > 0) {
duration = String.format(
Locale.getDefault(),
"%02d:%02d:%02d",
currentlyPlayingSong.duration / (1000 * 60 * 60),
currentlyPlayingSong.duration / (1000 * 60) % 60,
currentlyPlayingSong.duration / 1000 % 60
)
currentPosition = String.format(
Locale.getDefault(),
"%02d:%02d:%02d",
songCurrentPosition / (1000 * 60 * 60),
songCurrentPosition / (1000 * 60) % 60,
songCurrentPosition / 1000 % 60
)
} else {
duration = String.format(
Locale.getDefault(),
"%02d:%02d",
currentlyPlayingSong.duration / (1000 * 60) % 60,
currentlyPlayingSong.duration / 1000 % 60
)
currentPosition = String.format(
Locale.getDefault(),
"%02d:%02d",
songCurrentPosition / (1000 * 60) % 60,
songCurrentPosition / 1000 % 60
)
}

return@remember duration to currentPosition
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ fun SongViewPager(
onValueChange = { newProgress ->
viewModel.onSeek(newProgress)
viewModel.onSeeked()
}
},
remainingProgressColor = ListenBrainzTheme.colorScheme.hint
)
}
Spacer(modifier = Modifier.height(4.dp))
Expand Down

0 comments on commit 74c5347

Please sign in to comment.