Skip to content

Commit

Permalink
Added ability to change starting time
Browse files Browse the repository at this point in the history
Added settings item for notification permission access
Fixed UI elements being out of frame in certain languages
  • Loading branch information
Anthonyy232 committed Oct 9, 2024
1 parent 18ca628 commit 618e896
Show file tree
Hide file tree
Showing 19 changed files with 552 additions and 171 deletions.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM"/>
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ object SettingsConstants {
const val GRAYSCALE = "grayscale"
const val HOME_GRAYSCALE_PERCENTAGE = "home_grayscale_percentage"
const val LOCK_GRAYSCALE_PERCENTAGE = "lock_grayscale_percentage"
const val CHANGE_START_TIME = "change_start_time"
const val START_HOUR = "start_hour"
const val START_MINUTE = "start_minute"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -61,6 +62,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun PaperizeApp(
firstLaunch: Boolean,
Expand Down Expand Up @@ -230,6 +232,8 @@ fun PaperizeApp(
grayscale = settingsState.value.grayscale,
homeGrayscalePercentage = settingsState.value.homeGrayscalePercentage,
lockGrayscalePercentage = settingsState.value.lockGrayscalePercentage,
changeStartTime = settingsState.value.changeStartTime,
startingTime = settingsState.value.startTime,
onSettingsClick = { navController.navigate(Settings) },
navigateToAddWallpaperScreen = {
navController.navigate(AddEdit(it))
Expand All @@ -248,13 +252,16 @@ fun PaperizeApp(
lockInterval = settingsState.value.lockInterval,
scheduleSeparately = settingsState.value.scheduleSeparately,
setHome = settingsState.value.setHomeWallpaper,
setLock = settingsState.value.setLockWallpaper
setLock = settingsState.value.setLockWallpaper,
changeStartTime = settingsState.value.changeStartTime,
startTime = settingsState.value.startTime
)
alarmItem.let{scheduler.scheduleWallpaperAlarm(
wallpaperAlarmItem = it,
origin = null,
changeImmediate = true,
cancelImmediate = true
cancelImmediate = true,
firstLaunch = true
) }
scheduler.scheduleRefresh()
}
Expand All @@ -271,13 +278,14 @@ fun PaperizeApp(
lockInterval = settingsState.value.lockInterval,
scheduleSeparately = settingsState.value.scheduleSeparately,
setHome = settingsState.value.setHomeWallpaper,
setLock = settingsState.value.setLockWallpaper
setLock = settingsState.value.setLockWallpaper,
changeStartTime = settingsState.value.changeStartTime,
startTime = settingsState.value.startTime
)
alarmItem.let{scheduler.updateWallpaperAlarm(it)}
scheduler.scheduleRefresh()
}
}

},
onLockTimeChange = { timeInMinutes ->
settingsViewModel.onEvent(SettingsEvent.SetLockWallpaperInterval(timeInMinutes))
Expand All @@ -290,7 +298,9 @@ fun PaperizeApp(
lockInterval = timeInMinutes,
scheduleSeparately = settingsState.value.scheduleSeparately,
setHome = settingsState.value.setHomeWallpaper,
setLock = settingsState.value.setLockWallpaper
setLock = settingsState.value.setLockWallpaper,
changeStartTime = settingsState.value.changeStartTime,
startTime = settingsState.value.startTime
)
alarmItem.let{scheduler.updateWallpaperAlarm(it)}
scheduler.scheduleRefresh()
Expand Down Expand Up @@ -330,13 +340,16 @@ fun PaperizeApp(
lockInterval = settingsState.value.lockInterval,
scheduleSeparately = settingsState.value.scheduleSeparately,
setHome = settingsState.value.setHomeWallpaper,
setLock = settingsState.value.setLockWallpaper
setLock = settingsState.value.setLockWallpaper,
changeStartTime = settingsState.value.changeStartTime,
startTime = settingsState.value.startTime
)
alarmItem.let{scheduler.scheduleWallpaperAlarm(
wallpaperAlarmItem = it,
origin = null,
changeImmediate = true,
cancelImmediate = true
cancelImmediate = true,
firstLaunch = true
) }
scheduler.scheduleRefresh()
}
Expand Down Expand Up @@ -458,14 +471,17 @@ fun PaperizeApp(
lockInterval = settingsState.value.lockInterval,
scheduleSeparately = settingsState.value.scheduleSeparately,
setHome = settingsState.value.setHomeWallpaper,
setLock = settingsState.value.setLockWallpaper
setLock = settingsState.value.setLockWallpaper,
changeStartTime = settingsState.value.changeStartTime,
startTime = settingsState.value.startTime
)
alarmItem.let {
scheduler.scheduleWallpaperAlarm(
wallpaperAlarmItem = it,
origin = null,
changeImmediate = true,
cancelImmediate = true
cancelImmediate = true,
firstLaunch = true
)
}
scheduler.scheduleRefresh()
Expand Down Expand Up @@ -508,7 +524,6 @@ fun PaperizeApp(
onHomeCheckedChange = { setHome -> settingsViewModel.onEvent(SettingsEvent.SetHome(setHome))
if (!selectedState.value.selectedAlbum.isNullOrEmpty() && !setHome && !settingsState.value.setLockWallpaper) {
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper("", ""))
selectedState.value.selectedAlbum?.let { wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset()) }
scheduler.cancelWallpaperAlarm()
}
Expand Down Expand Up @@ -536,13 +551,16 @@ fun PaperizeApp(
lockInterval = settingsState.value.lockInterval,
scheduleSeparately = false,
setHome = setHome,
setLock = settingsState.value.setLockWallpaper
setLock = settingsState.value.setLockWallpaper,
changeStartTime = settingsState.value.changeStartTime,
startTime = settingsState.value.startTime
)
alarmItem.let{scheduler.scheduleWallpaperAlarm(
wallpaperAlarmItem = it,
origin = null,
changeImmediate = false,
cancelImmediate = true,
firstLaunch = true
) }
scheduler.scheduleRefresh()
}
Expand All @@ -567,7 +585,6 @@ fun PaperizeApp(
onLockCheckedChange = { setLock -> settingsViewModel.onEvent(SettingsEvent.SetLock(setLock))
if (selectedState.value.selectedAlbum!= null && !setLock && !settingsState.value.setHomeWallpaper) {
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper("", ""))
selectedState.value.selectedAlbum?.let {
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset())
}
Expand All @@ -584,13 +601,16 @@ fun PaperizeApp(
lockInterval = settingsState.value.lockInterval,
scheduleSeparately = false,
setHome = settingsState.value.setHomeWallpaper,
setLock = setLock
setLock = setLock,
changeStartTime = settingsState.value.changeStartTime,
startTime = settingsState.value.startTime
)
alarmItem.let{scheduler.scheduleWallpaperAlarm(
alarmItem.let{ scheduler.scheduleWallpaperAlarm(
wallpaperAlarmItem = it,
origin = null,
changeImmediate = false,
cancelImmediate = true
cancelImmediate = true,
firstLaunch = true
) }
scheduler.scheduleRefresh()
}
Expand Down Expand Up @@ -659,14 +679,17 @@ fun PaperizeApp(
lockInterval = settingsState.value.lockInterval,
scheduleSeparately = changeSeparately,
setHome = settingsState.value.setHomeWallpaper,
setLock = settingsState.value.setLockWallpaper
setLock = settingsState.value.setLockWallpaper,
changeStartTime = settingsState.value.changeStartTime,
startTime = settingsState.value.startTime
)
alarmItem.let{scheduler.scheduleWallpaperAlarm(
wallpaperAlarmItem = it,
origin = null,
changeImmediate = true,
cancelImmediate = true)
}
cancelImmediate = true,
firstLaunch = true
) }
scheduler.scheduleRefresh()
}
}
Expand Down Expand Up @@ -731,6 +754,46 @@ fun PaperizeApp(
}
}
},
onStartTimeChange = { time ->
settingsViewModel.onEvent(SettingsEvent.SetStartTime(time.hour, time.minute))
if (settingsState.value.enableChanger) {
job?.cancel()
job = scope.launch {
delay(1000)
val alarmItem = WallpaperAlarmItem(
homeInterval = settingsState.value.homeInterval,
lockInterval = settingsState.value.lockInterval,
scheduleSeparately = settingsState.value.scheduleSeparately,
setHome = settingsState.value.setHomeWallpaper,
setLock = settingsState.value.setLockWallpaper,
changeStartTime = true,
startTime = Pair(time.hour, time.minute)
)
alarmItem.let{scheduler.updateWallpaperAlarm(it, true)}
scheduler.scheduleRefresh()
}
}
},
onChangeStartTimeToggle = { changeStartTime ->
settingsViewModel.onEvent(SettingsEvent.SetChangeStartTime(changeStartTime))
if (settingsState.value.enableChanger) {
job?.cancel()
job = scope.launch {
delay(1000)
val alarmItem = WallpaperAlarmItem(
homeInterval = settingsState.value.homeInterval,
lockInterval = settingsState.value.lockInterval,
scheduleSeparately = settingsState.value.scheduleSeparately,
setHome = settingsState.value.setHomeWallpaper,
setLock = settingsState.value.setLockWallpaper,
changeStartTime = changeStartTime,
startTime = settingsState.value.startTime
)
alarmItem.let{scheduler.updateWallpaperAlarm(it, true)}
scheduler.scheduleRefresh()
}
}
},
)
}
// Navigate to the add album screen to create a new album and add wallpapers to it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.TabRowDefaults
import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
import androidx.compose.material3.Text
import androidx.compose.material3.TimePickerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand All @@ -30,6 +32,7 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.compone
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.LibraryScreen
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreen

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeScreen(
albums: List<AlbumWithWallpaperAndFolder>,
Expand Down Expand Up @@ -79,7 +82,11 @@ fun HomeScreen(
lockGrayscalePercentage: Int,
onGrayscalePercentageChange: (Int, Int) -> Unit,
onGrayscaleChange: (Boolean) -> Unit,
grayscale: Boolean
grayscale: Boolean,
changeStartTime: Boolean,
onChangeStartTimeToggle: (Boolean) -> Unit,
onStartTimeChange: (TimePickerState) -> Unit,
startingTime: Pair<Int, Int>
) {
val tabItems = getTabItems()
val pagerState = rememberPagerState(0) { tabItems.size }
Expand Down Expand Up @@ -188,7 +195,11 @@ fun HomeScreen(
lockGrayscalePercentage = lockGrayscalePercentage,
onGrayscalePercentageChange = onGrayscalePercentageChange,
onGrayscaleChange = onGrayscaleChange,
grayscale = grayscale
grayscale = grayscale,
changeStartTime = changeStartTime,
onChangeStartTimeToggle = onChangeStartTimeToggle,
onStartTimeChange = onStartTimeChange,
startingTime = startingTime
)
else -> LibraryScreen(
albums = albums,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ sealed class SettingsEvent {
data class SetGrayscale(val grayscale: Boolean): SettingsEvent()
data class SetLock(val lock: Boolean): SettingsEvent()
data class SetHome(val home: Boolean): SettingsEvent()
data class SetChangeStartTime(val changeStartTime: Boolean): SettingsEvent()
data class SetCurrentHomeWallpaper(val currentHomeWallpaper: String?): SettingsEvent()
data class SetCurrentLockWallpaper(val currentLockWallpaper: String?): SettingsEvent()
data class SetCurrentWallpaper(val currentHomeWallpaper: String?, val currentLockWallpaper: String?): SettingsEvent()
Expand All @@ -36,5 +37,6 @@ sealed class SettingsEvent {
data class SetNextHomeWallpaper(val nextHomeWallpaper: String?): SettingsEvent()
data class SetNextLockWallpaper(val nextLockWallpaper: String?): SettingsEvent()
data class SetNextWallpaper(val nextHomeWallpaper: String?, val nextLockWallpaper: String?): SettingsEvent()
data class SetStartTime(val hour: Int, val minute: Int): SettingsEvent()
data object RefreshNextWallpaper: SettingsEvent()
}
Loading

0 comments on commit 618e896

Please sign in to comment.