Skip to content

Commit

Permalink
Rei 04 - Implement module and pages navigation. (#5)
Browse files Browse the repository at this point in the history
* implement mainActivity and routing to call the views form main

* Fix appBar back action

* fix compose previews on the screens

* Fix requested changes
  • Loading branch information
NelsonChad authored Oct 10, 2024
1 parent 098eb67 commit 2305993
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 21 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ dependencies {
implementation(libs.analytics.customactivityoncrash)
implementation(platform(libs.dispatcher.dispatchBOM))
implementation(libs.dispatcher.dispatchCore)
implementation(libs.androidx.navigation.compose)
implementation(project(":rei"))

coreLibraryDesugaring(libs.desugar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.expandIn
import androidx.compose.animation.shrinkOut
import androidx.navigation.compose.rememberNavController
import androidx.compose.foundation.layout.Arrangement.Absolute.spacedBy
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -52,6 +53,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import com.saudigitus.support_module.ui.MenuScreen
import org.dhis2.R
import org.dhis2.commons.bindings.addIf
import org.dhis2.commons.date.toDateSpan
Expand Down Expand Up @@ -119,7 +121,8 @@ fun ProgramList(

ExpandableItemColumn(
modifier = Modifier
.fillMaxSize(),
.fillMaxWidth()
.height(500.dp),
itemList = programs,
) { program, verticalPadding, onSizeChanged ->

Expand All @@ -141,6 +144,7 @@ fun ProgramList(
?: run { {} },
)
}
MenuScreen(context = LocalContext.current)
} ?: run {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
ProgressIndicator(type = ProgressIndicatorType.CIRCULAR_SMALL)
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ plugins {
id("org.sonarqube").version("3.5.0.2730")
id("com.github.ben-manes.versions").version("0.46.0")
id("com.android.library") version "8.2.2" apply false
alias(libs.plugins.kotlin.android) apply false
}

sonarqube {
Expand Down
12 changes: 11 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ preference_ktx = "1.2.1"
uiautomator = "2.2.0"
maplibre = "10.2.0"
material3Android = "1.3.0"
navigationRuntimeKtx = "2.8.2"
navigationCompose = "2.8.2"
lifecycleRuntimeKtx = "2.8.6"
composeBom = "2024.04.01"
[libraries]
gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "gradle" }
kotlinPlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
Expand Down Expand Up @@ -214,9 +218,15 @@ dispatcher-dispatchBOM = { group = "com.rickbusarow.dispatch", name = "dispatch-
dispatcher-dispatchCore = { group = "com.rickbusarow.dispatch", name = "dispatch-core" }
dispatcher-dispatchEspresso = { group = "com.rickbusarow.dispatch", name = "dispatch-android-espresso", version = "1.0.0-beta10" }
deprecated-autoValueParcel = { group = "com.ryanharter.auto.value", name = "auto-value-parcel", version.ref = "autovalueparcel" }
androidx-material3-android = { group = "androidx.compose.material3", name = "material3-android", version.ref = "material3Android" } #TODO: Remove alongside AutoValue
androidx-material3-android = { group = "androidx.compose.material3", name = "material3-android", version.ref = "material3Android" }
androidx-navigation-runtime-ktx = { group = "androidx.navigation", name = "navigation-runtime-ktx", version.ref = "navigationRuntimeKtx" }
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" } #TODO: Remove alongside AutoValue
[plugins]
kotlin-compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

[bundles]
uicomponents-implementation = ["androidx-coreKtx", "androidx-material3", "google-material", "lottie-compose", "dhis2-mobile-designsystem"]
Expand Down
27 changes: 27 additions & 0 deletions support-module/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ android {

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
Expand All @@ -32,6 +35,17 @@ android {
kotlinOptions {
jvmTarget = "17"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}

dependencies {
Expand All @@ -40,8 +54,21 @@ dependencies {
implementation(libs.androidx.appcompat)
implementation(libs.google.material)
implementation(libs.androidx.material3.android)
implementation(libs.androidx.navigation.runtime.ktx)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.compose.preview)
implementation(libs.androidx.material3)
testImplementation(libs.test.junit)
androidTestImplementation(libs.test.junit.ext)
androidTestImplementation(libs.test.espresso)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.test.compose.ui.test)
coreLibraryDesugaring(libs.desugar)
debugImplementation(libs.androidx.compose.uitooling)
debugImplementation(libs.test.ui.test.manifest)
}
8 changes: 8 additions & 0 deletions support-module/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/title_activity_main"
android:theme="@style/Theme.Dhis2androidcaptureapp" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.saudigitus.support_module

import AppNavHost
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import com.saudigitus.support_module.ui.Screen
import com.saudigitus.support_module.ui.manualScreen.ManualScreen
import com.saudigitus.support_module.utils.Constants
import org.dhis2.ui.theme.Dhis2Theme

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
val screen = intent.extras?.getString(Constants.SCREENS_KEY) ?: Screen.Menu.route
val navController = rememberNavController()
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
AppNavHost(navController = navController, route = screen, activity = this)
}
}
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
Dhis2Theme {
Greeting("Android")
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.saudigitus.support_module.ui

import AppNavHost
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
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
Expand All @@ -12,40 +14,63 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.saudigitus.support_module.R
import com.saudigitus.support_module.ui.components.CustomCard

import android.content.Context
import android.content.Intent
import androidx.compose.ui.platform.LocalContext
import com.saudigitus.support_module.MainActivity
import com.saudigitus.support_module.utils.Constants

@Composable
fun MenuScreen() {
fun MenuScreen(context: Context) {
Column(
modifier = Modifier
.fillMaxWidth()
.height(170.dp)
.background(color = Color(0xFFFFFFFF))
.padding(5.dp),
.background(color = Color.White),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.Start
) {
Spacer(modifier = Modifier.height(8.dp))
Row(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
.padding(10.dp),
horizontalArrangement = Arrangement.SpaceEvenly,
verticalAlignment = Alignment.CenterVertically
) {
// First Card
CustomCard(imageResId = R.drawable.manual_icon, title = R.string.manuals.toString())
CustomCard(
imageResId = R.drawable.manual_icon,
title = stringResource(id = R.string.manuals),
onClick = {
val intent = Intent(context, MainActivity::class.java)
intent.putExtra(Constants.SCREENS_KEY, Screen.Manuals.route)
context.startActivity(intent)
}
)
// Second Card
CustomCard(imageResId = R.drawable.support, title = R.string.support.toString())
CustomCard(
imageResId = R.drawable.support,
title =stringResource(id = R.string.support),
onClick = {
val intent = Intent(context, MainActivity::class.java)
intent.putExtra(Constants.SCREENS_KEY, Screen.Support.route)
context.startActivity(intent)
}
)
}
}
}

@Preview(showBackground = true)
@Composable
fun MyScreenPreview() {
MenuScreen()
MenuScreen(context = LocalContext.current)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.saudigitus.support_module.ui

sealed class Screen(val route: String) {
object Menu : Screen("menu")
object Manuals : Screen("manuals")
object Support : Screen("support")
}


Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
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
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import com.saudigitus.support_module.R
import com.saudigitus.support_module.ui.components.SimpleCard
import timber.log.Timber

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SupportScreen(
navController: NavHostController,
onBack: () -> Unit = {} // Placeholder for back action
) {
Scaffold(
Expand All @@ -26,7 +32,7 @@ fun SupportScreen(
TopAppBar(
title = {
Text(
text = "Suporte ao utilizador",
text = stringResource(id = R.string.support_view_title),
color = Color.White,
fontSize = 20.sp
)
Expand Down Expand Up @@ -86,5 +92,5 @@ fun SupportScreen(
@Preview(showBackground = true)
@Composable
fun SupportPreview() {
SupportScreen()
SupportScreen(navController = NavHostController(LocalContext.current), onBack = {})
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.saudigitus.support_module.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand All @@ -18,18 +19,21 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp

@Composable
fun CustomCard(imageResId: Int, title: String) {
fun CustomCard(imageResId: Int, title: String, onClick: () -> Unit) {
Card(
modifier = Modifier
.size(150.dp)
.shadow(2.dp, RoundedCornerShape(16.dp))
.clip(RoundedCornerShape(16.dp)),
.clip(RoundedCornerShape(16.dp))
.clickable { onClick() },
colors = CardDefaults.cardColors(containerColor = Color.White),
elevation = CardDefaults.cardElevation(50.dp),


) {
Column(
modifier = Modifier.fillMaxSize(),
Expand All @@ -39,12 +43,13 @@ fun CustomCard(imageResId: Int, title: String) {
Image(
painter = painterResource(id = imageResId), // Substitua 'your_image' pelo nome do seu arquivo
contentDescription = null,
modifier = Modifier.size(80.dp)
modifier = Modifier.size(60.dp)
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = title,
color = Color.Black
color = Color.Black,
fontWeight = FontWeight.Bold
)
}
}
Expand Down
Loading

0 comments on commit 2305993

Please sign in to comment.