146 lines
5.2 KiB
Kotlin
146 lines
5.2 KiB
Kotlin
package de.schanbro.weekfocus
|
|
|
|
import android.content.Context
|
|
import android.os.Bundle
|
|
import androidx.activity.ComponentActivity
|
|
import androidx.activity.compose.setContent
|
|
import androidx.activity.enableEdgeToEdge
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.filled.Home
|
|
import androidx.compose.material.icons.filled.List
|
|
import androidx.compose.material.icons.filled.Settings
|
|
import androidx.compose.material.icons.outlined.Home
|
|
import androidx.compose.material.icons.outlined.List
|
|
import androidx.compose.material.icons.outlined.Settings
|
|
import androidx.compose.material3.*
|
|
import androidx.compose.runtime.*
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
|
import androidx.compose.ui.res.stringResource
|
|
import de.schanbro.weekfocus.ui.theme.WeekFocusTheme
|
|
|
|
import de.schanbro.weekfocus.screens.WordListScreen
|
|
|
|
class MainActivity : ComponentActivity() {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
enableEdgeToEdge()
|
|
setContent {
|
|
WeekFocusTheme {
|
|
MainScreen()
|
|
}
|
|
}
|
|
}
|
|
|
|
override fun onResume() {
|
|
super.onResume()
|
|
// Falls das Widget (z.B. durch Energiesparmodus) nicht rechtzeitig aktualisiert
|
|
// wurde, wird es beim Öffnen der App nachgezogen.
|
|
updateWidget(this)
|
|
}
|
|
}
|
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
@Composable
|
|
fun MainScreen() {
|
|
var selectedTab by remember { mutableIntStateOf(0) }
|
|
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
|
|
|
|
Scaffold(
|
|
modifier = Modifier
|
|
.fillMaxSize()
|
|
.nestedScroll(scrollBehavior.nestedScrollConnection),
|
|
topBar = {
|
|
LargeTopAppBar(
|
|
title = {
|
|
Text(
|
|
when (selectedTab) {
|
|
0 -> stringResource(R.string.title_home)
|
|
1 -> stringResource(R.string.title_words)
|
|
2 -> stringResource(R.string.title_settings)
|
|
else -> stringResource(R.string.app_name)
|
|
}
|
|
)
|
|
},
|
|
scrollBehavior = scrollBehavior,
|
|
colors = TopAppBarDefaults.largeTopAppBarColors(
|
|
containerColor = MaterialTheme.colorScheme.surface,
|
|
scrolledContainerColor = MaterialTheme.colorScheme.surfaceContainer
|
|
)
|
|
)
|
|
},
|
|
bottomBar = {
|
|
NavigationBar {
|
|
NavigationBarItem(
|
|
selected = selectedTab == 0,
|
|
onClick = { selectedTab = 0 },
|
|
icon = {
|
|
Icon(
|
|
imageVector = if (selectedTab == 0) Icons.Filled.Home else Icons.Outlined.Home,
|
|
contentDescription = stringResource(R.string.title_home)
|
|
)
|
|
},
|
|
label = { Text(stringResource(R.string.title_home)) }
|
|
)
|
|
NavigationBarItem(
|
|
selected = selectedTab == 1,
|
|
onClick = { selectedTab = 1 },
|
|
icon = {
|
|
Icon(
|
|
imageVector = if (selectedTab == 1) Icons.Filled.List else Icons.Outlined.List,
|
|
contentDescription = stringResource(R.string.title_words)
|
|
)
|
|
},
|
|
label = { Text(stringResource(R.string.title_words)) }
|
|
)
|
|
NavigationBarItem(
|
|
selected = selectedTab == 2,
|
|
onClick = { selectedTab = 2 },
|
|
icon = {
|
|
Icon(
|
|
imageVector = if (selectedTab == 2) Icons.Filled.Settings else Icons.Outlined.Settings,
|
|
contentDescription = stringResource(R.string.title_settings)
|
|
)
|
|
},
|
|
label = { Text(stringResource(R.string.title_settings)) }
|
|
)
|
|
}
|
|
}
|
|
) { innerPadding ->
|
|
Surface(
|
|
modifier = Modifier
|
|
.fillMaxSize()
|
|
.padding(innerPadding),
|
|
color = MaterialTheme.colorScheme.background
|
|
) {
|
|
when (selectedTab) {
|
|
0 -> PlaceholderScreen(title = stringResource(R.string.title_weekly_focus))
|
|
1 -> WordListScreen()
|
|
2 -> PlaceholderScreen(title = stringResource(R.string.title_settings))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
fun PlaceholderScreen(title: String) {
|
|
Box(
|
|
modifier = Modifier.fillMaxSize(),
|
|
contentAlignment = Alignment.Center
|
|
) {
|
|
Text(
|
|
text = title,
|
|
style = MaterialTheme.typography.headlineMedium,
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Bleibt als Top-Level-Funktion erhalten, damit WordListScreen unverändert weiter funktioniert.
|
|
*/
|
|
fun updateWidget(context: Context) {
|
|
SimpleWidget.updateAllWidgets(context)
|
|
} |