Skip to content

Commit

Permalink
Remaining time of sleep timer changed from MM:ss to HH:mm:ss
Browse files Browse the repository at this point in the history
  • Loading branch information
jamal2362 committed Sep 27, 2023
1 parent bb56be2 commit 2bc6498
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/jamal2367/urlradio/PlayerFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ class PlayerFragment : Fragment(),
.build()

timePicker.addOnPositiveButtonClickListener {
val selectedTimeMillis = (timePicker.hour * 60 * 60 * 1000L) + (timePicker.minute * 60 * 1000L)
val selectedTimeMillis = (timePicker.hour * 60 * 60 * 1000L) + (timePicker.minute * 60 * 1000L) + 1000
// start the sleep timer with the selected time
playerState.sleepTimerRunning = true
controller?.startSleepTimer(selectedTimeMillis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ object DateTimeHelper {
}


/* Converts a milliseconds in to a readable format */
fun convertToMinutesAndSeconds(milliseconds: Long, negativeValue: Boolean = false): String {
// convert milliseconds to minutes and seconds
val minutes: Long = milliseconds / 1000 / 60
/* Converts a milliseconds into a readable format (HH:mm:ss) */
fun convertToHoursMinutesSeconds(milliseconds: Long, negativeValue: Boolean = false): String {
// convert milliseconds to hours, minutes, and seconds
val hours: Long = milliseconds / 1000 / 3600
val minutes: Long = milliseconds / 1000 % 3600 / 60
val seconds: Long = milliseconds / 1000 % 60
var timeString =
"${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}"
"${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}"
if (negativeValue) {
// add a minus sign if a negative values was requested
timeString = "-$timeString"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ data class LayoutHolder(var rootView: View) {
}
else -> {
sleepTimerRunningViews.isVisible = true
val sleepTimerTimeRemaining = DateTimeHelper.convertToMinutesAndSeconds(timeRemaining)
val sleepTimerTimeRemaining = DateTimeHelper.convertToHoursMinutesSeconds(timeRemaining)
sheetSleepTimerRemainingTimeView.text = sleepTimerTimeRemaining
sheetSleepTimerRemainingTimeView.contentDescription = "${context.getString(R.string.descr_expanded_player_sleep_timer_remaining_time)}: $sleepTimerTimeRemaining"
stationNameView.isSelected = false
Expand Down

0 comments on commit 2bc6498

Please sign in to comment.