-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow settings time intervals for wallpaper changer (closes #215)
- Loading branch information
Showing
10 changed files
with
195 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.bnyro.wallpaper.ext | ||
|
||
import android.text.format.DateUtils | ||
import androidx.compose.runtime.Composable | ||
|
||
@Composable | ||
fun Long.formatTime(): String { | ||
val formatted = DateUtils.formatElapsedTime(this / 1000) | ||
|
||
return formatted.substring(0, 5).trimEnd(':') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/bnyro/wallpaper/ui/components/dialogs/TimePickerDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.bnyro.wallpaper.ui.components.dialogs | ||
|
||
import androidx.compose.material3.AlertDialog | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.TimePicker | ||
import androidx.compose.material3.TimePickerLayoutType | ||
import androidx.compose.material3.rememberTimePickerState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.res.stringResource | ||
import com.bnyro.wallpaper.ui.components.DialogButton | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun TimePickerDialog( | ||
initialMillis: Long, | ||
onTimeChange: (Long) -> Unit, | ||
onDismissRequest: () -> Unit | ||
) { | ||
val timePickerState = rememberTimePickerState( | ||
initialHour = (initialMillis / 1000 / 60 / 60).toInt(), | ||
initialMinute = (initialMillis / 1000 / 60 % 60).toInt(), | ||
) | ||
|
||
AlertDialog( | ||
onDismissRequest = onDismissRequest, | ||
dismissButton = { | ||
DialogButton(stringResource(android.R.string.cancel)) { | ||
onDismissRequest() | ||
} | ||
}, | ||
confirmButton = { | ||
DialogButton(stringResource(android.R.string.ok)) { | ||
onTimeChange((timePickerState.hour * 60L + timePickerState.minute) * 60 * 1000) | ||
onDismissRequest() | ||
} | ||
}, | ||
text = { | ||
TimePicker(timePickerState, layoutType = TimePickerLayoutType.Vertical) | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.bnyro.wallpaper.util | ||
|
||
import java.util.Calendar | ||
|
||
object TimeHelper { | ||
fun isInTimeRange(currentTimeMillis: Long, startTimeMillis: Long, endTimeMillis: Long): Boolean { | ||
// start and end time are on two different days in this case | ||
if (endTimeMillis < startTimeMillis) { | ||
return currentTimeMillis <= endTimeMillis || currentTimeMillis >= startTimeMillis | ||
} | ||
|
||
return currentTimeMillis in startTimeMillis..endTimeMillis | ||
} | ||
|
||
fun timeTodayInMillis(): Long { | ||
val calendar = Calendar.getInstance() | ||
|
||
return (calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE)) * 60 * 1000L | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters