Skip to content
Open
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: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ android {

dependencies {

def nav_version = "2.6.0"

implementation "androidx.navigation:navigation-compose:$nav_version"
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation 'androidx.activity:activity-compose:1.7.1'
Expand Down
59 changes: 52 additions & 7 deletions app/src/main/java/com/ics342/labs/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package com.ics342.labs
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.clickable
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.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
Expand All @@ -20,6 +22,12 @@ import androidx.compose.ui.text.font.FontWeight.Companion.Bold
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.ics342.labs.data.DataItem
import com.ics342.labs.ui.theme.LabsTheme

Expand Down Expand Up @@ -52,15 +60,44 @@ class MainActivity : ComponentActivity() {
setContent {
LabsTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
// Greeting("Android")
DataItemList(dataItems = dataItems)
// Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
// DataItemList(dataItems = dataItems)
val navController = rememberNavController()
NavHost(navController = navController, startDestination = "Start") {
composable(route = "Start") {
DataItemList(dataItems = dataItems, navController = navController)
}
composable(route = "DetailsScreen/{id}", arguments = listOf(navArgument("id") {
type = NavType.IntType
defaultValue = 0
})) {
entry -> DetailsScreenView(dataItem = dataItems[entry.arguments!!.getInt("id") -1])
}

}
}
}
}
}

//display id, title, and description
@Composable
fun DetailsScreenView(dataItem:DataItem) {
Column(modifier = Modifier.fillMaxSize()) {
Row(modifier = Modifier.fillMaxWidth()) {
Text(text = dataItem.id.toString(),
style = MaterialTheme.typography.bodyMedium)
Spacer(modifier = Modifier.size(8.dp))
Text(text = dataItem.name,
style = MaterialTheme.typography.bodyMedium)
Spacer(modifier = Modifier.size(8.dp))
Text(text = dataItem.description,
style = MaterialTheme.typography.bodyMedium)
Spacer(modifier = Modifier.size(8.dp))
}
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
Expand All @@ -70,10 +107,16 @@ fun Greeting(name: String, modifier: Modifier = Modifier) {
}

@Composable
fun DataItemView(dataItem: DataItem) {
fun DataItemView(dataItem: DataItem, navController : NavController) {
/* Create the view for the data item her. */
Row (
Modifier.padding(bottom = 8.dp)){
Modifier.padding(bottom = 8.dp)
.clickable(onClick = {
navController.navigate(route = buildString {
append("DetailsScreen/")
append(dataItem.id)
})
})){
Text(text = dataItem.id.toString())
Spacer(modifier = Modifier.size(8.dp))

Expand All @@ -85,16 +128,18 @@ fun DataItemView(dataItem: DataItem) {

}


@Composable
fun DataItemList(dataItems: List<DataItem>) {
fun DataItemList(dataItems: List<DataItem>, navController : NavController) {
/* Create the list here. This function will call DataItemView() */
LazyColumn {
for(data in dataItems){
item{DataItemView(data)}
item{DataItemView(data, navController = navController)}
}
}
}


@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
Expand Down