-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
414 additions
and
40 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
frontend/app/src/main/java/dk/scheduling/schedulingfrontend/ApiButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package dk.scheduling.schedulingfrontend | ||
|
||
import android.util.Log | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import dk.scheduling.schedulingfrontend.api.ApiClient | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
|
||
@Composable | ||
fun ApiButton() { | ||
Button(onClick = { | ||
val call = ApiClient.apiService.test() | ||
|
||
call.enqueue( | ||
object : Callback<String> { | ||
override fun onResponse( | ||
call: Call<String>, | ||
response: Response<String>, | ||
) { | ||
if (response.isSuccessful) { | ||
// val post = response.body() | ||
Log.i("testAPI", "we got a response") | ||
// Handle the retrieved post data | ||
} else { | ||
Log.w("testAPI", "we did not get a successful response") | ||
// Handle error | ||
} | ||
} | ||
|
||
override fun onFailure( | ||
call: Call<String>, | ||
t: Throwable, | ||
) { | ||
// Handle failure | ||
Log.e("testAPI", "could not get a response") | ||
} | ||
}, | ||
) | ||
}) { | ||
Text("Test API") | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
frontend/app/src/main/java/dk/scheduling/schedulingfrontend/HomePage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dk.scheduling.schedulingfrontend | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.sp | ||
|
||
@Composable | ||
fun HomePage() { | ||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { | ||
Text(text = "This is the HomePage, click the heart to reach the api button!", fontSize = 24.sp) | ||
} | ||
} |
42 changes: 2 additions & 40 deletions
42
frontend/app/src/main/java/dk/scheduling/schedulingfrontend/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
frontend/app/src/main/java/dk/scheduling/schedulingfrontend/MainLayout.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
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.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import dk.scheduling.schedulingfrontend.HomePage | ||
import dk.scheduling.schedulingfrontend.Page | ||
import dk.scheduling.schedulingfrontend.pagesInfo | ||
|
||
@Composable | ||
fun App() { | ||
var currentPage by remember { mutableStateOf(Page.HomePage) } | ||
|
||
Box(modifier = Modifier.fillMaxSize()) { | ||
// Content of the current page | ||
Column(modifier = Modifier.fillMaxSize()) { | ||
pagesInfo.find { it.page == currentPage }?.composable?.invoke() ?: HomePage() // Default to HomePage if not found | ||
Spacer(modifier = Modifier.weight(1f)) | ||
} | ||
|
||
// Bottom navigation bar | ||
BottomNavigationBar( | ||
currentPage = currentPage, | ||
onPageSelected = { page -> currentPage = page }, | ||
modifier = Modifier.align(Alignment.BottomCenter), | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
fun BottomNavigationBar( | ||
currentPage: Page, | ||
onPageSelected: (Page) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Surface(color = Color.Gray, modifier = modifier) { | ||
Row( | ||
modifier = Modifier.fillMaxWidth(), | ||
horizontalArrangement = Arrangement.SpaceEvenly, | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
pagesInfo.forEach { pageInfo -> | ||
BottomNavigationButton( | ||
icon = pageInfo.icon, | ||
isSelected = currentPage == pageInfo.page, | ||
) { onPageSelected(pageInfo.page) } | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun BottomNavigationButton( | ||
icon: ImageVector, | ||
isSelected: Boolean, | ||
onClick: () -> Unit, | ||
) { | ||
IconButton(onClick = onClick) { | ||
Icon( | ||
imageVector = icon, | ||
contentDescription = null, | ||
tint = if (isSelected) Color.White else Color.Magenta, | ||
) | ||
} | ||
} | ||
|
||
@Preview(showBackground = true, device = "spec:id=reference_phone,shape=Normal,width=411,height=891,unit=dp,dpi=420") | ||
@Composable | ||
fun PreviewApp() { | ||
App() | ||
} |
16 changes: 16 additions & 0 deletions
16
frontend/app/src/main/java/dk/scheduling/schedulingfrontend/Page3.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dk.scheduling.schedulingfrontend | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.sp | ||
|
||
@Composable | ||
fun Page3() { | ||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { | ||
Text(text = "Page 3", fontSize = 24.sp) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
frontend/app/src/main/java/dk/scheduling/schedulingfrontend/Pages.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package dk.scheduling.schedulingfrontend | ||
|
||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Favorite | ||
import androidx.compose.material.icons.filled.Home | ||
import androidx.compose.material.icons.filled.Settings | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
|
||
enum class Page { | ||
HomePage, | ||
ApiButtonPage, | ||
PAGE_3, | ||
} | ||
|
||
data class PageInfo( | ||
val page: Page, | ||
val icon: ImageVector, | ||
val composable: @Composable () -> Unit, | ||
) | ||
|
||
val pagesInfo = | ||
listOf( | ||
PageInfo(Page.HomePage, Icons.Default.Home) { HomePage() }, | ||
PageInfo(Page.ApiButtonPage, Icons.Default.Favorite) { ApiButton() }, | ||
PageInfo(Page.PAGE_3, Icons.Default.Settings) { Page3() }, | ||
) |
Oops, something went wrong.