Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lsongdev committed Sep 5, 2024
1 parent 62f07e1 commit 074ed83
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
38 changes: 25 additions & 13 deletions app/src/main/java/org/lsong/launcher/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
Expand Down Expand Up @@ -45,7 +47,6 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import java.util.Calendar


@Composable
fun MainScreen(appListManager: AppListManager) {
val appList by appListManager.appList.collectAsState()
Expand All @@ -57,9 +58,7 @@ fun MainScreen(appListManager: AppListManager) {
Column(
modifier = Modifier
.fillMaxSize()
.background(Color.Black.copy(alpha = 0.1f))
.padding(32.dp, top = 64.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
.background(Color.Black.copy(alpha = 0.1f)),
) {
ClockDisplay()
AppList(appList)
Expand All @@ -69,27 +68,39 @@ fun MainScreen(appListManager: AppListManager) {
@Composable
fun ClockDisplay() {
var currentTime by remember { mutableStateOf("") }
var currentDate by remember { mutableStateOf("") }

LaunchedEffect(Unit) {
while (true) {
currentTime = DateFormat.format("h:mm a", Calendar.getInstance()).toString()
val calendar = Calendar.getInstance()
currentTime = DateFormat.format("h:mm a", calendar).toString()
currentDate = DateFormat.format("EEE MMM d", calendar).toString()
delay(60000) // Update every minute
}
}

Text(
text = currentTime,
color = Color.White,
style = MaterialTheme.typography.displayMedium,
)
Column(
modifier = Modifier.fillMaxWidth().padding(32.dp, top = 64.dp, bottom = 16.dp),
verticalArrangement = Arrangement.Center,
) {
Text(
text = currentTime,
color = Color.White,
style = MaterialTheme.typography.displayMedium
)
Text(
text = currentDate,
color = Color.White,
style = MaterialTheme.typography.titleMedium
)
}
}

@Composable
fun AppList(appList: List<AppInfo>) {
LazyColumn(
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(bottom = 64.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
items(appList, key = { it.packageName }) { app ->
AppItem(app = app)
Expand All @@ -104,12 +115,13 @@ fun AppItem(app: AppInfo) {
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
.clickable {
context.packageManager?.getLaunchIntentForPackage(app.packageName)?.let {
context.startActivity(it)
}
},
}
.padding(32.dp, 8.dp)
,
) {
Image(
bitmap = app.icon.toBitmap().asImageBitmap(),
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ dependencyResolutionManagement {
}
}

rootProject.name = "Fresh Launcher"
rootProject.name = "FreshLauncher"
include(":app")

0 comments on commit 074ed83

Please sign in to comment.