Skip to content

Commit

Permalink
bottom nav revamp
Browse files Browse the repository at this point in the history
  • Loading branch information
wonrax committed Mar 19, 2022
1 parent 8ca69d0 commit 13d14d2
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CourseSchedule(
val tc_hp: Float? = null,
val ten_hocky: String? = null,
val ten_mh: String? = null,
val thu1: Int? = null,
val thu1: String? = null,
val tiet_bd1: Int? = null,
val tiet_kt1: Int? = null,
val tuan_hoc: String? = null
Expand Down
128 changes: 91 additions & 37 deletions app/src/main/java/com/wonrax/mybk/ui/component/BottomNavigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
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.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Surface
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import com.wonrax.mybk.ui.Screen
import com.wonrax.mybk.ui.theme.Color
import kotlinx.coroutines.delay
import java.util.Calendar
import java.util.Date

@Composable
fun BottomNavigation(navController: NavHostController) {
Expand All @@ -49,43 +52,94 @@ fun BottomNavigation(navController: NavHostController) {
}

Surface(elevation = 24.dp) {
Row(
modifier = Modifier
.padding(0.dp)
.background(Color.Light)
.fillMaxWidth()
.height(56.dp),
horizontalArrangement = Arrangement.SpaceEvenly,
verticalAlignment = Alignment.CenterVertically,
) {
items.forEach { screen ->
val selected = screen.route == backStackEntry.value?.destination?.route
Column {
StatusLine()
Divider(Color.Grey10)
Row(
modifier = Modifier
.padding(0.dp)
.background(Color.Light)
.fillMaxWidth()
.height(48.dp),
horizontalArrangement = Arrangement.SpaceEvenly,
verticalAlignment = Alignment.CenterVertically,
) {
items.forEach { screen ->
val selected = screen.route == backStackEntry.value?.destination?.route

Column(
modifier = Modifier
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = rememberRipple(bounded = false),
) { onItemClick(screen.route) }
.fillMaxHeight()
.weight(1f),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Icon(
icon = if (selected) screen.iconSelected else screen.icon,
tint = Color.Dark
)
Text(
screen.title,
fontSize = FontSize.Small,
color = Color.Dark,
textAlign = TextAlign.Center,
softWrap = false,
letterSpacing = (-0.2).sp
)
Column(
modifier = Modifier
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
) { onItemClick(screen.route) }
.fillMaxHeight()
.weight(1f),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Icon(
icon = if (selected) screen.iconSelected else screen.icon,
tint = Color.Dark
)
}
}
}
}
}
}

@Composable
fun StatusLine() {

val weekOfYear = remember { mutableStateOf(0) }
val dayOfWeek = remember { mutableStateOf(1) }

LaunchedEffect(true) {
fun updateTime() {
val calendar = Calendar.getInstance()

calendar.minimalDaysInFirstWeek = 4
calendar.firstDayOfWeek = Calendar.MONDAY

/* Set date */
calendar.time = Date()

weekOfYear.value = calendar.get(Calendar.WEEK_OF_YEAR)
dayOfWeek.value = calendar.get(Calendar.DAY_OF_WEEK)
}

// Update the time indicator every minute
while (true) {
updateTime()
delay(1000 * 60)
}
}

Box(
Modifier
.fillMaxWidth()
.padding(5.dp),
contentAlignment = Alignment.Center
) {
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(
"Tuần ${weekOfYear.value}",
fontWeight = FontWeight.Bold,
fontSize = FontSize.Small
)
if (dayOfWeek.value != 1)
Text(
"Thứ ${dayOfWeek.value}",
fontSize = FontSize.Small
)
else Text(
"Chủ nhật",
fontSize = FontSize.Small
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fun Preview() {
// tc_hp = 3f,
// ten_hocky = "Học kỳ 2 Năm học 2021 - 2022",
ten_mh = "DE CUONG LUAN VAN TOT NGHIEP KHOA HOC MAY TINH",
thu1 = 3,
thu1 = "3",
// tiet_bd1 = 2,
// tiet_kt1 = 3,
tuan_hoc = "01|02|03|--|--|06|07|08|09|--|--|--|--|14|15|16|17|18|"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/wonrax/mybk/ui/component/Text.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fun Text(
}

val fs = when (fontSize) {
FontSize.Small -> 11.sp
FontSize.Small -> 12.sp
FontSize.Body -> 14.sp
FontSize.Large -> 16.sp
FontSize.Heading -> 24.sp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fun CourseDetail(
so_tin_chi: Int?,
tc_hp: Float?,
ten_hocky: String?,
thu1: Int?,
thu1: String?,
tiet_bd1: Int?,
tiet_kt1: Int?,
tuan_hoc: String?
Expand All @@ -104,7 +104,7 @@ fun CourseDetail(
listOfNotNull(
ma_mh,
tietHoc,
thu1.toString(),
thu1,
gioHoc,
macoso,
phong1,
Expand Down
14 changes: 5 additions & 9 deletions app/src/main/java/com/wonrax/mybk/ui/screens/ExamsScreen.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.wonrax.mybk.ui.screens

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand All @@ -24,15 +23,12 @@ fun ExamsScreen(mybkViewModel: MybkViewModel) {
onRefresh = { mybkViewModel.update() }
) {
item {
Column(
Text(
"Lịch thi",
fontWeight = FontWeight.Medium,
fontSize = FontSize.Heading,
modifier = Modifier.padding(12.dp, 0.dp)
) {
Text(
"Lịch thi",
fontWeight = FontWeight.Medium,
fontSize = FontSize.Heading,
)
}
)
Spacer(modifier = Modifier.height(16.dp))
}

Expand Down
13 changes: 5 additions & 8 deletions app/src/main/java/com/wonrax/mybk/ui/screens/GradesScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ fun GradesScreen(mybkViewModel: MybkViewModel) {
onRefresh = { mybkViewModel.update() }
) {
item {
Column(
Text(
"Bảng điểm",
fontWeight = FontWeight.Medium,
fontSize = FontSize.Heading,
modifier = Modifier.padding(12.dp, 0.dp)
) {
Text(
"Bảng điểm",
fontWeight = FontWeight.Medium,
fontSize = FontSize.Heading,
)
}
)
Spacer(modifier = Modifier.height(16.dp))
}

Expand Down
47 changes: 6 additions & 41 deletions app/src/main/java/com/wonrax/mybk/ui/screens/SchedulesScreen.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
package com.wonrax.mybk.ui.screens

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.wonrax.mybk.ui.component.DropdownMenu
Expand All @@ -20,39 +13,25 @@ import com.wonrax.mybk.ui.component.LastUpdated
import com.wonrax.mybk.ui.component.MainScreenLayout
import com.wonrax.mybk.ui.component.ScheduleCard
import com.wonrax.mybk.ui.component.Text
import com.wonrax.mybk.ui.theme.Color
import com.wonrax.mybk.viewmodel.MybkViewModel
import java.util.Calendar
import java.util.Date

@Composable
fun SchedulesScreen(
mybkViewModel: MybkViewModel,
onCourseClick: (semester: String, courseId: String) -> Unit
) {
val weekOfYear by remember { mutableStateOf(getWeekOfYear()) }

MainScreenLayout(
isLoading = mybkViewModel.isLoading.value,
isRefreshing = mybkViewModel.isRefreshing.value,
onRefresh = { mybkViewModel.update() }
) {
item {
Row(
modifier = Modifier
.padding(12.dp, 0.dp)
.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
"Thời khóa biểu",
fontWeight = FontWeight.Medium,
fontSize = FontSize.Heading,
)

Text("Tuần $weekOfYear", color = Color.Grey50)
}
Text(
"Thời khóa biểu",
fontWeight = FontWeight.Medium,
fontSize = FontSize.Heading,
modifier = Modifier.padding(12.dp, 0.dp)
)
Spacer(modifier = Modifier.height(16.dp))
}

Expand Down Expand Up @@ -85,17 +64,3 @@ fun SchedulesScreen(
}
}
}

fun getWeekOfYear(): Int {
/* Build a calendar suitable to extract ISO8601 week numbers
* (see http://en.wikipedia.org/wiki/ISO_8601_week_number) */
val calendar: Calendar = Calendar.getInstance()
calendar.minimalDaysInFirstWeek = 4
calendar.firstDayOfWeek = Calendar.MONDAY

/* Set date */
calendar.time = Date()

/* Get ISO8601 week number */
return calendar.get(Calendar.WEEK_OF_YEAR)
}
14 changes: 8 additions & 6 deletions app/src/main/java/com/wonrax/mybk/viewmodel/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ fun formatDateToDisplay(
dateFormat,
Locale.ENGLISH
).parse(dateString)
if (date != null) {
displayDate = SimpleDateFormat(
"dd-MM-yyyy HH:mm",
Locale.getDefault()
).format(date)
}
if (date != null) displayDate = dateToString(date)
} catch (e: Exception) {
// Ignore
e.printStackTrace()
Expand All @@ -31,6 +26,13 @@ fun formatDateToDisplay(
return displayDate
}

fun dateToString(date: Date): String {
return SimpleDateFormat(
"dd-MM-yyyy HH:mm",
Locale.getDefault()
).format(date)
}

fun openBrowser(context: Context, url: String) {
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
context.startActivity(browserIntent)
Expand Down

0 comments on commit 13d14d2

Please sign in to comment.