Skip to content

Commit

Permalink
Merge branch 'main' into droidcon/aditya
Browse files Browse the repository at this point in the history
  • Loading branch information
alisen authored Jul 3, 2024
2 parents 40cbb46 + ac46a6f commit 8d9f9e1
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 78 deletions.
3 changes: 3 additions & 0 deletions zeapp/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
alias(libs.plugins.kotlin.kapt)
alias(libs.plugins.license.report.gradle)
alias(libs.plugins.baselineprofile)
alias(libs.plugins.aboutlibraries.gradle)
}

val isCi = System.getenv("CI") == "true"
Expand Down Expand Up @@ -183,6 +184,8 @@ dependencies {
implementation(libs.coil.compose)
implementation(libs.coil.transformations)
implementation(libs.timber)
implementation(libs.aboutlibraries.compose)
implementation(libs.androidx.compose.hilt.navigation)
debugImplementation(libs.androidx.compose.ui.tooling)
debugImplementation(libs.androidx.compose.ui.test.manifest)

Expand Down
99 changes: 41 additions & 58 deletions zeapp/android/src/main/java/de/berlindroid/zeapp/ZeMainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
Expand Down Expand Up @@ -94,6 +95,8 @@ import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.DialogProperties
import androidx.compose.ui.zIndex
import com.ban.autosizetextfield.AutoSizeTextField
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
import com.mikepenz.aboutlibraries.ui.compose.m3.LibraryDefaults.libraryColors
import dagger.hilt.android.AndroidEntryPoint
import de.berlindroid.zeapp.zemodels.ZeConfiguration
import de.berlindroid.zeapp.zemodels.ZeEditor
Expand All @@ -111,6 +114,7 @@ import de.berlindroid.zeapp.zeui.WeatherEditorDialog
import de.berlindroid.zeapp.zeui.ZeCameraEditor
import de.berlindroid.zeapp.zeui.ZeImageDrawEditorDialog
import de.berlindroid.zeapp.zeui.ZeNavigationPad
import de.berlindroid.zeapp.zeui.zeabout.ZeAbout
import de.berlindroid.zeapp.zeui.zetheme.ZeBadgeAppTheme
import de.berlindroid.zeapp.zeui.zetheme.ZeBlack
import de.berlindroid.zeapp.zeui.zetheme.ZeWhite
Expand Down Expand Up @@ -212,6 +216,7 @@ class ZeMainActivity : ComponentActivity() {
private fun ZeScreen(vm: ZeBadgeViewModel, modifier: Modifier = Modifier) {
val lazyListState = rememberLazyListState()
var isShowingAbout by remember { mutableStateOf(false) }
var isShowingOpenSource by remember { mutableStateOf(false) }
val context = LocalContext.current
val goToReleases: () -> Unit = remember {
{
Expand All @@ -233,6 +238,10 @@ private fun ZeScreen(vm: ZeBadgeViewModel, modifier: Modifier = Modifier) {
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
val scope = rememberCoroutineScope()

BackHandler(isShowingOpenSource || isShowingAbout) {
isShowingOpenSource = false
isShowingAbout = false
}

ZeBadgeAppTheme(
content = {
Expand All @@ -244,6 +253,7 @@ private fun ZeScreen(vm: ZeBadgeViewModel, modifier: Modifier = Modifier) {
onGetStoredPages = vm::getStoredPages,
onSaveAllClick = vm::saveAll,
onGotoReleaseClick = goToReleases,
onGotoOpenSourceClick = { isShowingOpenSource = !isShowingOpenSource },
onUpdateConfig = vm::listConfiguration,
onCloseDrawer = {
scope.launch {
Expand Down Expand Up @@ -278,7 +288,9 @@ private fun ZeScreen(vm: ZeBadgeViewModel, modifier: Modifier = Modifier) {
},
content = { paddingValues ->
if (isShowingAbout) {
ZeAbout(paddingValues, vm, LocalContext.current)
ZeAbout(paddingValues)
} else if (isShowingOpenSource) {
ZeOpenSource(paddingValues)
} else {
ZePages(
paddingValues = paddingValues,
Expand All @@ -301,6 +313,7 @@ private fun ZeDrawerContent(
onSaveAllClick: () -> Unit = {},
onGetStoredPages: () -> Unit = {},
onGotoReleaseClick: () -> Unit = {},
onGotoOpenSourceClick: () -> Unit = {},
onUpdateConfig: () -> Unit = {},
onCloseDrawer: () -> Unit = {},
onTitleClick: () -> Unit = {},
Expand Down Expand Up @@ -411,61 +424,31 @@ private fun ZeDrawerContent(
onClick = onGotoReleaseClick,
)
}

item {
NavDrawerItem(
text = stringResource(id = R.string.ze_navdrawer_open_source),
painter = painterResource(id = R.drawable.ic_open_source_initiative),
onClick = onGotoOpenSourceClick,
)
}
}
}
}

@Composable
private fun ZeAbout(
private fun ZeOpenSource(
paddingValues: PaddingValues,
vm: ZeBadgeViewModel,
context: Context,
) {
val lines by vm.lines.collectAsState()

ZeSurface(
modifier = ZeModifier
.fillMaxSize()
.padding(paddingValues)
.padding(ZeDimen.Half),
) {
Column {
ZeText(
text = "${lines.count()} contributors",
modifier = Modifier.padding(8.dp),
style = MaterialTheme.typography.bodyMedium,
fontSize = 24.sp,
)
ZeText(
text = "Running on '${getPlatform()}'.",
)
ZeLazyColumn {
items(lines) { line ->
ZeRow(
verticalAlignment = Alignment.CenterVertically,
) {
val email = line.substring(line.indexOf('<').plus(1), line.lastIndexOf('>')).trim()
ZeText(
text = line.substring(0, line.indexOf('<')).trim(),
color = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.padding(8.dp),
style = MaterialTheme.typography.bodyMedium,
fontSize = 18.sp,
)
ZeIcon(
painter = painterResource(id = R.drawable.email),
contentDescription = "Send random page to badge",
Modifier
.size(20.dp, 20.dp)
.clickable {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("mailto:$email"))
context.startActivity(intent)
},
)
}
}
}
}
ZeSurface {
LibrariesContainer(
Modifier.fillMaxSize(),
contentPadding = paddingValues,
colors = libraryColors(
backgroundColor = ZeBlack,
badgeBackgroundColor = ZeWhite,
),
)
}
}

Expand Down Expand Up @@ -632,7 +615,7 @@ private fun ZePages(
@Composable
@Preview
private fun InfoBar(
message: String = "Very Important",
message: String = stringResource(id = R.string.ze_very_important),
progress: Float = 0.5f,
copyMoreToClipboard: (() -> Unit) = {},
) {
Expand Down Expand Up @@ -684,9 +667,9 @@ private fun InfoBar(
@Preview
private fun BadgeConfigEditor(
config: Map<String, Any?> = mapOf(
"sample configuration" to "sample value",
"sample int" to 23,
"another configuration" to true,
stringResource(id = R.string.ze_sample_configuration_key) to stringResource(id = R.string.ze_sample_configuration_value),
stringResource(id = R.string.ze_sample_int_key) to 23,
stringResource(id = R.string.ze_sample_another_configuration_key) to true,
),
onDismissRequest: () -> Unit = {},
onConfirmed: (updateConfig: Map<String, Any?>) -> Unit = {},
Expand Down Expand Up @@ -805,7 +788,7 @@ private fun SelectedEditor(
)

is ZeConfiguration.Schedule -> {
vm.showMessage(message = "Not added by you yet, please feel free to contribute this editor")
vm.showMessage(message = stringResource(id = R.string.ze_not_added_yet_message))
vm.slotConfigured(null, null)
}

Expand Down Expand Up @@ -878,7 +861,7 @@ private fun TemplateChooserDialog(
title = {
ZeText(
color = ZeBlack,
text = "Select Content",
text = stringResource(id = R.string.ze_select_content),
)
},
text = {
Expand Down Expand Up @@ -949,7 +932,7 @@ private fun PagePreview(
item {
ZeToolButton(
imageVector = Icons.AutoMirrored.Filled.Send,
text = "Send",
text = stringResource(id = R.string.send),
onClick = sendToDevice,
)
}
Expand All @@ -958,7 +941,7 @@ private fun PagePreview(
item {
ZeToolButton(
imageVector = Icons.Filled.Refresh,
text = "Reset",
text = stringResource(id = R.string.reset),
onClick = resetThisPage,
)
}
Expand All @@ -967,7 +950,7 @@ private fun PagePreview(
item {
ZeToolButton(
imageVector = Icons.Filled.Edit,
text = "Edit",
text = stringResource(id = R.string.ze_edit),
onClick = customizeThisPage,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Clear
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -87,13 +88,19 @@ fun NameEditorDialog(
Text(text = stringResource(id = android.R.string.cancel))
}
},
title = { Text(
color = ZeBlack,
text = stringResource(R.string.add_your_contact_details)
) },
title = {
Text(
color = ZeBlack,
text = stringResource(R.string.add_your_contact_details),
)
},
properties = DialogProperties(decorFitsSystemWindows = false),
text = {
Column {
Column(
modifier = Modifier
.fillMaxWidth()
.verticalScroll(rememberScrollState()),
) {
BinaryImageEditor(
bitmap = image,
bitmapUpdated = { image = it },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package de.berlindroid.zeapp.zeui.zeabout

import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import de.berlindroid.zeapp.R
import de.berlindroid.zeapp.ZeDimen
import de.berlindroid.zekompanion.getPlatform

@Composable
fun ZeAbout(
paddingValues: PaddingValues,
vm: ZeAboutViewModel = hiltViewModel(),
) {
val lines by vm.lines.collectAsState()

val context = LocalContext.current
Surface(
modifier = Modifier
.fillMaxSize()
.padding(paddingValues)
.padding(ZeDimen.Half),
) {
Column {
Text(
text = "${lines.count()} contributors",
modifier = Modifier.padding(8.dp),
style = MaterialTheme.typography.bodyMedium,
fontSize = 24.sp,
)
Text(
text = "Running on '${getPlatform()}'.",
)
LazyColumn {
items(lines) { line ->
Row(
verticalAlignment = Alignment.CenterVertically,
) {
val email = line.substring(line.indexOf('<').plus(1), line.lastIndexOf('>')).trim()
Text(
text = line.substring(0, line.indexOf('<')).trim(),
color = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.padding(8.dp),
style = MaterialTheme.typography.bodyMedium,
fontSize = 18.sp,
)
Icon(
painter = painterResource(id = R.drawable.email),
contentDescription = "Send random page to badge",
Modifier
.size(20.dp, 20.dp)
.clickable {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("mailto:$email"))
context.startActivity(intent)
},
)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.berlindroid.zeapp.zeui.zeabout

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import de.berlindroid.zeapp.zeservices.ZeContributorsService
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject

@HiltViewModel
class ZeAboutViewModel @Inject constructor(
contributorsService: ZeContributorsService,
):ViewModel(){

val lines: StateFlow<List<String>> = contributorsService.contributors()
.stateIn(viewModelScope, SharingStarted.Lazily, initialValue = emptyList())
}
Loading

0 comments on commit 8d9f9e1

Please sign in to comment.