-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[kiosksetup] Split UI code into several files.
- Loading branch information
1 parent
db223db
commit 29c403c
Showing
4 changed files
with
153 additions
and
24 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
42 changes: 42 additions & 0 deletions
42
kiosksetup/src/main/java/com/studio4plus/homerplayer2/kiosk/ui/KioskSetupUi.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,42 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Marcin Simonides | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.studio4plus.homerplayer2.kiosk.ui | ||
|
||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.Composable | ||
import com.studio4plus.homerplayer2.base.ui.theme.HomerPlayer2Theme | ||
|
||
@Composable | ||
fun KioskSetupUi() { | ||
HomerPlayer2Theme { | ||
// A surface container using the 'background' color from the theme | ||
Surface( | ||
color = MaterialTheme.colorScheme.background | ||
) { | ||
MainScreenRoute() | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
kiosksetup/src/main/java/com/studio4plus/homerplayer2/kiosk/ui/MainScreen.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,70 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Marcin Simonides | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.studio4plus.homerplayer2.kiosk.ui | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import com.studio4plus.homerplayer2.base.ui.theme.HomerTheme | ||
import org.koin.androidx.compose.koinViewModel | ||
|
||
@Composable | ||
fun MainScreenRoute( | ||
viewModel: MainScreenViewModel = koinViewModel() | ||
) { | ||
val isDeviceOwner by viewModel.isDeviceOwner.collectAsStateWithLifecycle() | ||
MainScreen( | ||
isDeviceOwner = isDeviceOwner, | ||
dropDeviceOwnerPrivilege = viewModel::dropDeviceOwnerPrivilege, | ||
) | ||
} | ||
|
||
@Composable | ||
fun MainScreen( | ||
isDeviceOwner: Boolean, | ||
dropDeviceOwnerPrivilege: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Column( | ||
modifier = modifier.padding(HomerTheme.dimensions.screenContentPadding) | ||
) { | ||
val isDeviceOwnerString = if (isDeviceOwner) "yes" else "no" | ||
Text("Is device owner: $isDeviceOwnerString") | ||
// TODO: inform the user it's better to do a factory reset. | ||
// TODO: ask user for confirmation when dropping device owner. | ||
Button( | ||
onClick = dropDeviceOwnerPrivilege, | ||
enabled = isDeviceOwner | ||
) { | ||
|
||
Text("Drop device owner privilege") | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
kiosksetup/src/main/java/com/studio4plus/homerplayer2/kiosk/ui/MainScreenViewModel.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,39 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Marcin Simonides | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.studio4plus.homerplayer2.kiosk.ui | ||
|
||
import androidx.lifecycle.ViewModel | ||
import com.studio4plus.homerplayer2.kiosk.deviceadmin.DeviceAdminStatus | ||
import org.koin.android.annotation.KoinViewModel | ||
|
||
@KoinViewModel | ||
class MainScreenViewModel( | ||
private val deviceAdminStatus: DeviceAdminStatus | ||
): ViewModel() { | ||
|
||
val isDeviceOwner = deviceAdminStatus.isDeviceOwner | ||
|
||
fun dropDeviceOwnerPrivilege() = deviceAdminStatus.dropDeviceOwner() | ||
} |