Skip to content

Commit

Permalink
Merge pull request #113 from ultimagz/feat/about-app-oss-licenses
Browse files Browse the repository at this point in the history
Feat/About App menu Open Source Licenses
  • Loading branch information
akexorcist authored Dec 27, 2024
2 parents 417ec0d + a647e35 commit afd9c04
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 22 deletions.
9 changes: 9 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ plugins {
alias(libs.plugins.jetbrainsKotlinAndroid)
alias(libs.plugins.devToolsKsp)
alias(libs.plugins.roborazzi)
alias(libs.plugins.aboutLibraries)
}

aboutLibraries {
registerAndroidTasks = true
includePlatform = false
offlineMode = true
outputFileName = "aboutlibraries.json"
}

android {
Expand Down Expand Up @@ -91,6 +99,7 @@ dependencies {
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.koin.androidx.compose)
implementation(libs.koin.androidx.compose.navigation)
implementation(libs.bundles.aboutLibraries.all)
implementation(platform(libs.androidx.compose.bom))
implementation(platform(libs.koin.bom))

Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/com/akexorcist/ruammij/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.akexorcist.ruammij.ui.RuamMijApp
import androidx.navigation.compose.NavHost
import com.akexorcist.ruammij.ui.RUAM_MIJ_APP_ROUTE
import com.akexorcist.ruammij.ui.osslicense.openSourceLicenseScreen
import com.akexorcist.ruammij.ui.rememberAppState
import com.akexorcist.ruammij.ui.ruamMijApp
import com.akexorcist.ruammij.ui.theme.RuamMijTheme
import com.akexorcist.ruammij.utility.getOwnerPackageName
import org.koin.androidx.viewmodel.ext.android.viewModel
Expand All @@ -26,7 +29,14 @@ class MainActivity : AppCompatActivity() {
setContent {
RuamMijTheme {
val appState = rememberAppState()
RuamMijApp(appState = appState)

NavHost(
navController = appState.mainNavController,
startDestination = RUAM_MIJ_APP_ROUTE,
) {
ruamMijApp(appState = appState)
openSourceLicenseScreen(navController = appState.mainNavController)
}
}
}
displayManager.registerDisplayListener(displayListener, null)
Expand Down
19 changes: 10 additions & 9 deletions app/src/main/java/com/akexorcist/ruammij/ui/RuamMijApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -45,7 +44,7 @@ import com.akexorcist.ruammij.ui.theme.RuamMijTheme
fun RuamMijApp(
appState: AppState,
) {
val navController = appState.navController
val navController = appState.bottomBarNavController

Scaffold(
bottomBar = {
Expand All @@ -66,13 +65,13 @@ fun RuamMijApp(
modifier = Modifier
.fillMaxSize()
.padding(padding),
navController = appState.navController,
navController = appState.bottomBarNavController,
startDestination = OVERVIEW_ROUTE,
) {
overviewScreen(navController = navController)
accessibilityScreen()
installedAppScreen()
aboutAppScreen()
aboutAppScreen(appState = appState)
}
},
)
Expand Down Expand Up @@ -109,18 +108,20 @@ private fun DownloadButton(onClick: () -> Unit) {

@Stable
class AppState(
val navController: NavHostController,
val mainNavController: NavHostController,
val bottomBarNavController: NavHostController,
) {
val currentDestination: NavDestination?
@Composable get() = navController.currentBackStackEntryAsState().value?.destination
@Composable get() = bottomBarNavController.currentBackStackEntryAsState().value?.destination
}

@Composable
fun rememberAppState(
navController: NavHostController = rememberNavController(),
mainNavController: NavHostController = rememberNavController(),
bottomBarNavController: NavHostController = rememberNavController(),
): AppState {
return remember(navController) {
AppState(navController)
return remember(mainNavController, bottomBarNavController) {
AppState(mainNavController, bottomBarNavController)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.akexorcist.ruammij.ui

import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable

const val RUAM_MIJ_APP_ROUTE = "ruam_mij_app_route"

fun NavGraphBuilder.ruamMijApp(
appState: AppState,
) {
composable(route = RUAM_MIJ_APP_ROUTE) {
RuamMijApp(
appState = appState,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.akexorcist.ruammij.ui.aboutapp
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.akexorcist.ruammij.ui.AppState

const val ABOUT_APP_ROUTE = "about_app_route"

Expand All @@ -11,8 +12,12 @@ fun NavController.navigateToAboutApp() = navigate(ABOUT_APP_ROUTE) {
launchSingleTop = true
}

fun NavGraphBuilder.aboutAppScreen() {
fun NavGraphBuilder.aboutAppScreen(
appState: AppState,
) {
composable(route = ABOUT_APP_ROUTE) {
AboutAppRoute()
AboutAppRoute(
appState = appState,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@ import androidx.compose.ui.unit.dp
import com.akexorcist.ruammij.BuildConfig
import com.akexorcist.ruammij.R
import com.akexorcist.ruammij.common.Contributors
import com.akexorcist.ruammij.ui.AppState
import com.akexorcist.ruammij.ui.component.BodyText
import com.akexorcist.ruammij.ui.component.BoldBodyText
import com.akexorcist.ruammij.ui.component.DescriptionText
import com.akexorcist.ruammij.ui.component.HeadlineText
import com.akexorcist.ruammij.ui.osslicense.navigateToOpenSourceLicense
import com.akexorcist.ruammij.ui.theme.Buttons
import com.akexorcist.ruammij.ui.theme.RuamMijTheme

@Composable
fun AboutAppRoute() {
fun AboutAppRoute(
appState: AppState,
) {
val activity = LocalContext.current as Activity
var showPrivacyPolicy by remember { mutableStateOf(false) }
var showContributor by remember { mutableStateOf(false) }
Expand All @@ -81,7 +85,7 @@ fun AboutAppRoute() {
showContributor = true
},
onOpenSourceLicenseClick = {
// TODO navigate to open source license screen
appState.mainNavController.navigateToOpenSourceLicense()
},
onSourceCodeClick = {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/akexorcist/ruam-mij-android"))
Expand Down Expand Up @@ -133,13 +137,12 @@ private fun AboutAppScreen(
onClick = onContributorClick,
)
Spacer(modifier = Modifier.height(16.dp))
// TODO Add Open Source License section
// MenuItem(
// label = stringResource(R.string.about_app_menu_open_source_licenses),
// icon = painterResource(R.drawable.ic_about_app_source_code),
// onClick = onOpenSourceLicenseClick,
// )
// Spacer(modifier = Modifier.height(16.dp))
MenuItem(
label = stringResource(R.string.about_app_menu_open_source_licenses),
icon = painterResource(R.drawable.ic_about_app_source_code),
onClick = onOpenSourceLicenseClick,
)
Spacer(modifier = Modifier.height(16.dp))
MenuItem(
label = stringResource(R.string.about_app_menu_source_code),
icon = painterResource(R.drawable.ic_about_app_source_code),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.akexorcist.ruammij.ui.osslicense

import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.core.tween
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable

const val OPEN_SOURCE_LICENSES_ROUTE = "open_source_licenses_route"

fun NavController.navigateToOpenSourceLicense() = navigate(route = OPEN_SOURCE_LICENSES_ROUTE) {
popUpTo(graph.startDestinationId)
launchSingleTop = true
}

fun NavGraphBuilder.openSourceLicenseScreen(
navController: NavController,
) {
composable(
route = OPEN_SOURCE_LICENSES_ROUTE,
enterTransition = {
slideIntoContainer(AnimatedContentTransitionScope.SlideDirection.Start, tween(350))
},
exitTransition = {
slideOutOfContainer(AnimatedContentTransitionScope.SlideDirection.End, tween(350))
},
) {
OpenSourceLicenseRoute(
navController = navController,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.akexorcist.ruammij.ui.osslicense

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavController
import com.akexorcist.ruammij.R
import com.mikepenz.aboutlibraries.Libs
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
import com.mikepenz.aboutlibraries.util.withJson

@Composable
fun OpenSourceLicenseRoute(
navController: NavController,
) {
OpenSourceLicenseScreen(navController = navController)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun OpenSourceLicenseScreen(
navController: NavController,
) {
Scaffold(
topBar = {
TopAppBar(
title = {
Text(
text = stringResource(R.string.about_app_menu_open_source_licenses),
)
},
navigationIcon = {
IconButton(onClick = { navController.popBackStack() }) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = "Back"
)
}
},
)
}
) { paddingValues ->
LibrariesContainer(
modifier = Modifier.fillMaxSize(),
contentPadding = paddingValues,
librariesBlock = { ctx ->
Libs.Builder()
.withJson(ctx, R.raw.aboutlibraries)
.build()
},
)
}
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
alias(libs.plugins.devToolsKsp) apply false
alias(libs.plugins.aboutLibraries) apply false
}
7 changes: 7 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ksp = "1.9.22-1.0.18"
oss = "17.0.1"
robolectric = "4.11.1"
roborazzi = "1.11.0"
aboutLibraries = "11.2.3"

[libraries]
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" }
Expand Down Expand Up @@ -51,9 +52,15 @@ robolectric = { group = "org.robolectric", name = "robolectric", version.ref = "
roborazzi = { group = "io.github.takahirom.roborazzi", name = "roborazzi", version.ref = "roborazzi" }
roborazzi-compose = { group = "io.github.takahirom.roborazzi", name = "roborazzi-compose", version.ref = "roborazzi" }
roborazzi-rule = { group = "io.github.takahirom.roborazzi", name = "roborazzi-junit-rule", version.ref = "roborazzi" }
aboutLibraries-core = { group = "com.mikepenz", name = "aboutlibraries-core", version.ref = "aboutLibraries" }
aboutLibraries-composeM3 = { group = "com.mikepenz", name = "aboutlibraries-compose-m3", version.ref = "aboutLibraries" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
devToolsKsp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
roborazzi = { id = "io.github.takahirom.roborazzi", version.ref = "roborazzi" }
aboutLibraries = { id = "com.mikepenz.aboutlibraries.plugin", version.ref = "aboutLibraries" }

[bundles]
aboutLibraries-all = ["aboutLibraries-core", "aboutLibraries-composeM3"]

0 comments on commit afd9c04

Please sign in to comment.