Skip to content

Commit

Permalink
added navigation. need to fix weird bug where it won't switch properl…
Browse files Browse the repository at this point in the history
…y the second time.
  • Loading branch information
m-GDEV committed Jan 22, 2024
1 parent aa8c37d commit 29c5b98
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .idea/gradle.xml

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

6 changes: 6 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,10 @@ dependencies {
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")

// Custom added by musa
// https://developer.android.com/jetpack/compose/navigation#kts
val nav_version = "2.7.6"
implementation("androidx.navigation:navigation-compose:$nav_version")

}
75 changes: 75 additions & 0 deletions app/src/main/java/com/redline/android/AppScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.redline.android

import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.DateRange
import androidx.compose.material.icons.filled.Home
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.redline.android.ui.AssignmentsScreen

@Composable
fun RedlineApp(
navController: NavHostController = rememberNavController()
) {
Scaffold(topBar = {
// Talha, change this when you write the top app bar
}) { innerPadding ->
Surface(
modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background
) {
NavHost(
navController = navController,
startDestination = AppScreen.Assignments.name,
modifier = Modifier.padding(innerPadding)
) {
// Assignments screen composable
composable(route = AppScreen.Assignments.name) {
AssignmentsScreen(modifier = Modifier
.fillMaxSize()
.padding(10.dp),
onScreenChange = { screen ->
Log.d("NAVIGATIOM", "$screen")
navController.navigate(screen.name)
})
}

// Schedule Screen composable
composable(route = AppScreen.Schedule.name) {
ScheduleScreen(modifier = Modifier
.fillMaxSize()
.padding(10.dp),
onScreenChange = {
navController.navigate(AppScreen.Assignments.name)
})
}
}
}
}
}

enum class AppScreen() {
Assignments, Schedule
}
16 changes: 1 addition & 15 deletions app/src/main/java/com/redline/android/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,10 @@ class MainActivity : ComponentActivity() {
setContent {
RedlineTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Main()
}
RedlineApp()
}
}
}
}

@Composable
fun Main(modifier: Modifier = Modifier) {
Column(
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
HomeTabs()
}
}

21 changes: 21 additions & 0 deletions app/src/main/java/com/redline/android/ScheduleScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.redline.android

import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.redline.android.ui.HomeTabs

@Composable
fun ScheduleScreen(
modifier: Modifier = Modifier,
onScreenChange: (screen: AppScreen) -> Unit
) {
Column {
HomeTabs(onScreenChange = onScreenChange)
Text(
text = "Schedule"
)
}

}
21 changes: 21 additions & 0 deletions app/src/main/java/com/redline/android/ui/AssignmentsScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.redline.android.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.redline.android.AppScreen

@Composable
fun AssignmentsScreen(
modifier: Modifier = Modifier, onScreenChange: (screen: AppScreen) -> Unit
) {
Column {
HomeTabs(onScreenChange = onScreenChange)
Text(
text = "Assignments",
)
}

}
24 changes: 20 additions & 4 deletions app/src/main/java/com/redline/android/ui/CommonUI.kt
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
package com.redline.android.ui

import android.util.Log
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.redline.android.AppScreen
import com.redline.android.R


@Composable
fun HomeTabs(modifier: Modifier = Modifier) {
fun HomeTabs(modifier: Modifier = Modifier, onScreenChange: (screen: AppScreen) -> Unit) {
Row(
modifier = Modifier.fillMaxWidth(),
modifier = Modifier
.fillMaxWidth()
.padding(top = 15.dp),
horizontalArrangement = Arrangement.SpaceEvenly,
verticalAlignment = Alignment.CenterVertically
) {
Button(onClick = { /*TODO*/ }) {
Button(
onClick = {
Log.d("NAVIGATIOM_", "Navigating to assignments from button")
onScreenChange(AppScreen.Assignments)
}
) {
Text(
text = stringResource(R.string.assignments_tab)
)
}
Button(onClick = { /*TODO*/ }) {
Button(
onClick = {
Log.d("NAVIGATIOM_", "Navigating to schedule from button")
onScreenChange(AppScreen.Schedule)
}
) {
Text(
text = stringResource(R.string.schedule_tab)
)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.2.0" apply false
id("com.android.application") version "8.2.1" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
}

0 comments on commit 29c5b98

Please sign in to comment.