Skip to content

Commit

Permalink
[kiosksetup] Split UI code into several files.
Browse files Browse the repository at this point in the history
  • Loading branch information
msimonides committed Feb 11, 2024
1 parent db223db commit 29c403c
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,15 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.studio4plus.homerplayer2.base.ui.theme.HomerPlayer2Theme
import com.studio4plus.homerplayer2.kiosk.deviceadmin.DeviceAdminStatus
import com.studio4plus.homerplayer2.kiosk.ui.KioskSetupUi
import org.koin.android.ext.android.inject

class MainActivity : ComponentActivity() {

private val deviceAdminStatus: DeviceAdminStatus by inject()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val isDeviceOwner = deviceAdminStatus.isDeviceOwner.collectAsStateWithLifecycle().value
val isDeviceOwnerString = if (isDeviceOwner) "yes" else "no"
HomerPlayer2Theme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize().padding(16.dp),
color = MaterialTheme.colorScheme.background
) {
Column {
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 = { deviceAdminStatus.dropDeviceOwner() },
enabled = isDeviceOwner
) {

Text("Drop device owner privilege")
}
}
}
}
KioskSetupUi()
}
}
}
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()
}
}
}
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")
}
}
}
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()
}

0 comments on commit 29c403c

Please sign in to comment.