Skip to content

Commit

Permalink
Merge pull request #123 from pknu-wap/feature/tgyuu/#116
Browse files Browse the repository at this point in the history
Feature/tgyuu/#116
  • Loading branch information
tgyuuAn authored Feb 13, 2024
2 parents 1697273 + ee12c3a commit 28a2281
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
26 changes: 8 additions & 18 deletions app/src/main/java/com/wap/wapp/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.wap.wapp

import android.content.res.Resources
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.NavGraph.Companion.findStartDestination
Expand All @@ -32,6 +32,8 @@ import com.wap.wapp.feature.management.event.navigation.eventRegistrationNavigat
import com.wap.wapp.feature.management.survey.navigation.ManagementSurveyRoute
import com.wap.wapp.feature.profile.profilesetting.navigation.profileSettingNavigationRoute
import com.wap.wapp.feature.splash.navigation.splashNavigationRoute
import com.wap.wapp.feature.survey.check.navigation.SurveyCheckRoute
import com.wap.wapp.feature.survey.check.navigation.SurveyCheckRoute.surveyCheckRoute
import com.wap.wapp.feature.survey.navigation.SurveyRoute
import com.wap.wapp.navigation.TopLevelDestination
import com.wap.wapp.navigation.WappNavHost
Expand All @@ -50,8 +52,6 @@ class MainActivity : ComponentActivity() {
setContent {
WappTheme {
val navController = rememberNavController()
val density = LocalDensity.current
val navigationBarHeight = getNavigationBarHeight(density)

Scaffold(
containerColor = WappTheme.colors.backgroundBlack,
Expand Down Expand Up @@ -82,7 +82,7 @@ class MainActivity : ComponentActivity() {
)
},
modifier = Modifier
.padding(bottom = navigationBarHeight)
.windowInsetsPadding(WindowInsets.navigationBars)
.fillMaxSize(),
) { innerPadding ->
WappNavHost(
Expand Down Expand Up @@ -115,6 +115,8 @@ private fun handleBottomBarState(
ManagementSurveyRoute.surveyFormEditRoute("{id}") -> setBottomBarState(false)
eventRegistrationNavigationRoute -> setBottomBarState(false)
SurveyRoute.answerRoute("{id}") -> setBottomBarState(false)
surveyCheckRoute -> setBottomBarState(false)
SurveyCheckRoute.surveyDetailRoute("{id}") -> setBottomBarState(false)
else -> setBottomBarState(true)
}

Expand All @@ -130,15 +132,3 @@ private fun navigateToTopLevelDestination(
restoreState = true
}
}

private fun getNavigationBarHeight(density: Density) = with(density) {
Resources.getSystem().run {
getDimensionPixelSize(
getIdentifier(
"navigation_bar_height",
"dimen",
"android",
),
).toDp()
}
}
11 changes: 7 additions & 4 deletions app/src/main/java/com/wap/wapp/navigation/WappNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.wap.wapp.feature.profile.profilesetting.navigation.profileSettingNavi
import com.wap.wapp.feature.profile.profilesetting.navigation.profileSettingScreen
import com.wap.wapp.feature.splash.navigation.splashNavigationRoute
import com.wap.wapp.feature.splash.navigation.splashScreen
import com.wap.wapp.feature.survey.check.navigation.SurveyCheckRoute.surveyCheckRoute
import com.wap.wapp.feature.survey.check.navigation.navigateToSurveyCheck
import com.wap.wapp.feature.survey.check.navigation.navigateToSurveyDetail
import com.wap.wapp.feature.survey.check.navigation.surveyCheckNavGraph
Expand Down Expand Up @@ -65,9 +66,7 @@ fun WappNavHost(
},
navigateToNotice = {
navController.navigateToNotice(
navOptions {
popUpTo(splashNavigationRoute) { inclusive = true }
},
navOptions { popUpTo(splashNavigationRoute) { inclusive = true } },
)
},
)
Expand All @@ -88,7 +87,11 @@ fun WappNavHost(
navigateToSurveyCheck = navController::navigateToSurveyCheck,
)
surveyCheckNavGraph(
navigateToSurveyCheck = navController::navigateToSurveyCheck,
navigateToSurveyCheck = {
navController.navigateToSurveyCheck(
navOptions { popUpTo(surveyCheckRoute) { inclusive = true } },
)
},
navigateToSurveyDetail = navController::navigateToSurveyDetail,
)
managementSurveyNavGraph(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.wap.wapp.core.network.constant.ATTENDANCE_COLLECTION
import com.wap.wapp.core.network.model.attendance.AttendanceRequest
import com.wap.wapp.core.network.model.attendance.AttendanceResponse
import com.wap.wapp.core.network.utils.await
import com.wap.wapp.core.network.utils.toISOLocalDateTimeString
import java.time.LocalDateTime
import javax.inject.Inject

class AttendanceDataSourceImpl @Inject constructor(
Expand Down Expand Up @@ -35,6 +37,10 @@ class AttendanceDataSourceImpl @Inject constructor(
.await()

val attendanceResponse = task.toObject<AttendanceResponse>()
checkNotNull(attendanceResponse)
attendanceResponse ?: AttendanceResponse(
eventId = eventId,
"",
LocalDateTime.MIN.toISOLocalDateTimeString(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ internal fun AttendanceRoute(
getTodayEventsAttendanceStatus()
}

is Failure -> snackBarHostState.showSnackbar(
getString(context, R.string.attendance_failure),
)
is Failure -> snackBarHostState.showSnackbar(event.message)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ class AttendanceViewModel @Inject constructor(
private suspend fun getEventListAttendance(eventList: List<Event>, userId: String) =
getEventListAttendanceUseCase(eventList.map { it.eventId })
.onSuccess { attendanceList ->
val eventAttendanceList = eventList.zip(attendanceList)
val filteredEventList = eventList.filter {
it.eventId in attendanceList.map { it.eventId }
}

val eventAttendanceList = filteredEventList.zip(attendanceList)
.map { (event, attendance) ->
EventAttendanceStatus(
eventId = event.eventId,
Expand All @@ -104,6 +108,7 @@ class AttendanceViewModel @Inject constructor(
remainAttendanceDateTime = attendance.calculateDeadline(),
)
}

getEventListAttendanceStatus(
eventAttendanceList = eventAttendanceList,
userId = userId,
Expand All @@ -129,6 +134,7 @@ class AttendanceViewModel @Inject constructor(
isAttendance = attendanceStatus.isAttendance(),
)
}

_todayEventsAttendanceStatus.value =
EventAttendanceStatusState.Success(eventAttendanceStatusList)
}.onFailure { _errorFlow.emit(it) }
Expand Down

0 comments on commit 28a2281

Please sign in to comment.