Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce OpenSource Attribution Screen #271

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 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,7 @@ dependencies {
implementation(libs.coil.compose)
implementation(libs.coil.transformations)
implementation(libs.timber)
implementation(libs.aboutlibraries.compose)
debugImplementation(libs.androidx.compose.ui.tooling)
debugImplementation(libs.androidx.compose.ui.test.manifest)

Expand Down
36 changes: 36 additions & 0 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.viewModels
import androidx.compose.animation.core.animateFloatAsState
Expand Down Expand Up @@ -91,6 +92,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 Down Expand Up @@ -208,6 +211,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 @@ -229,6 +233,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 @@ -240,6 +248,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 @@ -275,6 +284,8 @@ private fun ZeScreen(vm: ZeBadgeViewModel, modifier: Modifier = Modifier) {
content = { paddingValues ->
if (isShowingAbout) {
ZeAbout(paddingValues, vm, LocalContext.current)
} else if (isShowingOpenSource) {
ZeOpenSource(paddingValues)
} else {
ZePages(
paddingValues = paddingValues,
Expand All @@ -297,6 +308,7 @@ private fun ZeDrawerContent(
onSaveAllClick: () -> Unit = {},
onGetStoredPages: () -> Unit = {},
onGotoReleaseClick: () -> Unit = {},
onGotoOpenSourceClick: () -> Unit = {},
onUpdateConfig: () -> Unit = {},
onCloseDrawer: () -> Unit = {},
onTitleClick: () -> Unit = {},
Expand Down Expand Up @@ -407,6 +419,14 @@ 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,
)
}
}
}
}
Expand Down Expand Up @@ -465,6 +485,22 @@ private fun ZeAbout(
}
}

@Composable
private fun ZeOpenSource(
paddingValues: PaddingValues,
) {
ZeSurface {
LibrariesContainer(
Modifier.fillMaxSize(),
contentPadding = paddingValues,
colors = libraryColors(
backgroundColor = ZeBlack,
badgeBackgroundColor = ZeWhite,
),
)
}
}

@Composable
@OptIn(ExperimentalMaterial3Api::class)
private fun ZeTopBar(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- drawable/open_source_initiative.xml --><vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:width="24dp" android:viewportWidth="24" android:viewportHeight="24"><path android:fillColor="#000000" android:pathData="M15.41,22C15.35,22 15.28,22 15.22,22C15.1,21.95 15,21.85 14.96,21.73L12.74,15.93C12.65,15.69 12.77,15.42 13,15.32C13.71,15.06 14.28,14.5 14.58,13.83C15.22,12.4 14.58,10.73 13.15,10.09C11.72,9.45 10.05,10.09 9.41,11.5C9.11,12.21 9.09,13 9.36,13.69C9.66,14.43 10.25,15 11,15.28C11.24,15.37 11.37,15.64 11.28,15.89L9,21.69C8.96,21.81 8.87,21.91 8.75,21.96C8.63,22 8.5,22 8.39,21.96C3.24,19.97 0.67,14.18 2.66,9.03C4.65,3.88 10.44,1.31 15.59,3.3C18.06,4.26 20.05,6.15 21.13,8.57C22.22,11 22.29,13.75 21.33,16.22C20.32,18.88 18.23,21 15.58,22C15.5,22 15.47,22 15.41,22M12,3.59C7.03,3.46 2.9,7.39 2.77,12.36C2.68,16.08 4.88,19.47 8.32,20.9L10.21,16C8.38,15 7.69,12.72 8.68,10.89C9.67,9.06 11.96,8.38 13.79,9.36C15.62,10.35 16.31,12.64 15.32,14.47C14.97,15.12 14.44,15.65 13.79,16L15.68,20.93C17.86,19.95 19.57,18.16 20.44,15.93C22.28,11.31 20.04,6.08 15.42,4.23C14.33,3.8 13.17,3.58 12,3.59Z" /></vector>
1 change: 1 addition & 0 deletions zeapp/android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<string name="ze_navdrawer_update_config">Update config on badge</string>
<string name="ze_navdrawer_send_random_page">Send random page to badge</string>
<string name="ze_navdrawer_open_release_page">Open release page</string>
<string name="ze_navdrawer_open_source">Open Source</string>
<string name="ze_select_content" tools:ignore="MissingTranslation">Select Content</string>
<string name="ze_not_added_yet_message" tools:ignore="MissingTranslation">Not added by you yet, please feel free to contribute this editor</string>

Expand Down
1 change: 1 addition & 0 deletions zeapp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
alias(libs.plugins.detekt.gradle) apply false
alias(libs.plugins.dagger.hilt) apply false
alias(libs.plugins.license.report.gradle) apply false
alias(libs.plugins.aboutlibraries.gradle) apply false
id("com.android.test") version "8.0.2" apply false
kotlin("multiplatform") version "1.9.10" apply false
}
Expand Down
3 changes: 3 additions & 0 deletions zeapp/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
ktlint-gradle = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint-gradle" }
license-report-gradle = { id = "com.jaredsburrows.license", version.ref = "license-report-gradle" }
aboutlibraries-gradle = { id = "com.mikepenz.aboutlibraries.plugin", version.ref = "aboutlibraries" }

[versions]

Expand Down Expand Up @@ -50,9 +51,11 @@ ktor = "2.3.9"
uiTestManifest = "1.6.4"
mockk = "1.13.11"
kotlinxCoroutinesTest = "1.7.3"
aboutlibraries = "11.2.2"

[libraries]

aboutlibraries-compose = { module = "com.mikepenz:aboutlibraries-compose-m3", version.ref = "aboutlibraries" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
androidx-benchmark-macro-junit4 = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "benchmarkMacroJunit4" }
androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "androidx-compose-bom" }
Expand Down
Loading