Skip to content

Commit

Permalink
Merge branch 'develop' into eastshine2741/more-tab-nickname
Browse files Browse the repository at this point in the history
  • Loading branch information
eastshine2741 authored Sep 6, 2023
2 parents d5479e1 + 2ac288e commit 8a8fb91
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 153 deletions.
10 changes: 0 additions & 10 deletions app/src/main/java/com/wafflestudio/snutt2/data/SNUTTStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,6 @@ class SNUTTStorage @Inject constructor(
)
)

val vacancyBannerOpenTime = PrefValue<Long>(
prefContext,
PrefValueMetaData(
domain = DOMAIN_SCOPE_LOGIN,
key = "vacancy_banner_open_time",
type = Long::class.java,
defaultValue = 0
)
)

fun clearLoginScope() {
prefContext.clear(DOMAIN_SCOPE_LOGIN)
prefContext.clear(DOMAIN_SCOPE_CURRENT_VERSION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ import kotlinx.coroutines.flow.StateFlow
interface VacancyRepository {
val firstVacancyVisit: StateFlow<Boolean>

val vacancyBannerOpenTime: StateFlow<Long>

suspend fun getVacancyLectures(): List<LectureDto>

suspend fun addVacancyLecture(lectureId: String)

suspend fun removeVacancyLecture(lectureId: String)

suspend fun setVacancyVisited()

suspend fun updateVacancyBannerOpenTime()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package com.wafflestudio.snutt2.data.vacancy_noti
import com.wafflestudio.snutt2.data.SNUTTStorage
import com.wafflestudio.snutt2.lib.network.SNUTTRestApi
import com.wafflestudio.snutt2.lib.network.dto.core.LectureDto
import kotlinx.coroutines.flow.StateFlow
import java.util.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -17,8 +15,6 @@ class VacancyRepositoryImpl @Inject constructor(

override val firstVacancyVisit = storage.firstVacancyVisit.asStateFlow()

override val vacancyBannerOpenTime: StateFlow<Long> = storage.vacancyBannerOpenTime.asStateFlow()

override suspend fun getVacancyLectures(): List<LectureDto> {
return api._getVacancyLectures().lectures
}
Expand All @@ -34,8 +30,4 @@ class VacancyRepositoryImpl @Inject constructor(
override suspend fun setVacancyVisited() {
storage.firstVacancyVisit.update(false)
}

override suspend fun updateVacancyBannerOpenTime() {
storage.vacancyBannerOpenTime.update(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1))
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.wafflestudio.snutt2.views.logged_in.bookmark

import androidx.activity.OnBackPressedCallback
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
Expand Down Expand Up @@ -74,21 +73,16 @@ fun BookmarkPage(
}

/* 뒤로가기 핸들링 */
val onBackPressedDispatcherOwner = LocalOnBackPressedDispatcherOwner.current
val onBackPressedCallback = remember {
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (bottomSheet.isVisible) {
scope.launch { bottomSheet.hide() }
} else if (navController.currentDestination?.route == NavigationDestination.Bookmark) {
navController.popBackStack()
}
}
val onBackPressed: () -> Unit = {
if (bottomSheet.isVisible) {
scope.launch { bottomSheet.hide() }
} else if (navController.currentDestination?.route == NavigationDestination.Bookmark) {
navController.popBackStack()
}
}
DisposableEffect(Unit) {
onBackPressedDispatcherOwner?.onBackPressedDispatcher?.addCallback(onBackPressedCallback)
onDispose { onBackPressedCallback.remove() }

BackHandler {
onBackPressed()
}

val selectedLecture by searchViewModel.selectedLecture.collectAsState()
Expand All @@ -113,7 +107,7 @@ fun BookmarkPage(
.background(SNUTTColors.White900)
.fillMaxWidth()
) {
SimpleTopBar(title = stringResource(R.string.bookmark_page_title), onClickNavigateBack = { onBackPressedCallback.handleOnBackPressed() })
SimpleTopBar(title = stringResource(R.string.bookmark_page_title), onClickNavigateBack = { onBackPressed() })
Box(
modifier = Modifier
.weight(1f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package com.wafflestudio.snutt2.views.logged_in.home.reviews

import android.view.ViewGroup
import android.webkit.WebView
import androidx.activity.OnBackPressedCallback
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
Expand All @@ -14,8 +13,6 @@ import androidx.compose.material.ButtonDefaults
import androidx.compose.material.LinearProgressIndicator
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -43,23 +40,17 @@ import kotlinx.coroutines.launch
fun ReviewPage() {
val webViewContainer = LocalReviewWebView.current
val homePageController = LocalHomePageController.current
val onBackPressedDispatcherOwner = LocalOnBackPressedDispatcherOwner.current

val onBackPressedCallback = remember {
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (webViewContainer.webView.canGoBack()) {
webViewContainer.webView.goBack()
} else {
homePageController.update(HomeItem.Timetable)
}
}

val onBackPressed: () -> Unit = {
if (webViewContainer.webView.canGoBack()) {
webViewContainer.webView.goBack()
} else {
homePageController.update(HomeItem.Timetable)
}
}

DisposableEffect(Unit) {
onBackPressedDispatcherOwner?.onBackPressedDispatcher?.addCallback(onBackPressedCallback)
onDispose { onBackPressedCallback.remove() }
BackHandler {
onBackPressed()
}

ReviewWebView(page = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
Expand All @@ -26,7 +25,6 @@ import com.wafflestudio.snutt2.views.*
import com.wafflestudio.snutt2.views.logged_in.home.TableListViewModel
import com.wafflestudio.snutt2.views.logged_in.home.settings.UserViewModel
import com.wafflestudio.snutt2.views.logged_in.home.showTitleChangeDialog
import com.wafflestudio.snutt2.views.logged_in.vacancy_noti.VacancyViewModel
import kotlinx.coroutines.launch

@Composable
Expand All @@ -41,11 +39,8 @@ fun TimetablePage() {
val composableStates = ComposableStatesWithScope(scope)
val tableListViewModel = hiltViewModel<TableListViewModel>()
val userViewModel = hiltViewModel<UserViewModel>()
val vacancyViewModel = hiltViewModel<VacancyViewModel>()
val newSemesterNotify by tableListViewModel.newSemesterNotify.collectAsState(false)
val firstBookmarkAlert by userViewModel.firstBookmarkAlert.collectAsState()
val vacancyBannerOpened by vacancyViewModel.vacancyBannerOpened.collectAsState()
val shouldShowVacancyBanner = remoteConfig.vacancyNotificationBannerEnabled && vacancyBannerOpened

var timetableHeight by remember { mutableStateOf(0) }
var topBarHeight by remember { mutableStateOf(0) }
Expand Down Expand Up @@ -103,7 +98,7 @@ fun TimetablePage() {
view,
context,
topBarHeight,
if (shouldShowVacancyBanner) bannerHeight else 0,
if (remoteConfig.vacancyNotificationBannerEnabled) bannerHeight else 0,
timetableHeight
)
},
Expand All @@ -121,16 +116,11 @@ fun TimetablePage() {
}
}
)
if (shouldShowVacancyBanner) {
if (remoteConfig.vacancyNotificationBannerEnabled) {
VacancyBanner(
onClick = {
navController.navigate(NavigationDestination.VacancyNotification)
},
onClose = {
scope.launch {
vacancyViewModel.closeVacancyBanner()
}
},
modifier = Modifier
.onGloballyPositioned { bannerHeight = it.size.height }
)
Expand All @@ -149,7 +139,6 @@ fun TimetablePage() {
@Composable
fun VacancyBanner(
onClick: () -> Unit,
onClose: () -> Unit,
modifier: Modifier = Modifier
) {
Row(
Expand Down Expand Up @@ -183,15 +172,6 @@ fun VacancyBanner(
)
)
}
Spacer(
modifier = Modifier.weight(1f)
)
TipCloseIcon(
modifier = Modifier
.size(11.dp)
.clicks { onClose() },
colorFilter = ColorFilter.tint(SNUTTColors.AllWhite)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package com.wafflestudio.snutt2.views.logged_in.lecture_detail

import android.content.Intent
import android.net.Uri
import androidx.activity.OnBackPressedCallback
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.animation.expandVertically
Expand Down Expand Up @@ -98,38 +97,34 @@ fun LectureDetailPage(
val bottomSheet = bottomSheet()

/* 뒤로가기 핸들링 */
val onBackPressedDispatcherOwner = LocalOnBackPressedDispatcherOwner.current
val onBackPressedCallback = remember {
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (bottomSheet.isVisible) {
scope.launch { bottomSheet.hide() }
} else when (modeType) {
ModeType.Normal -> {
if (navController.currentDestination?.route == NavigationDestination.LectureDetail) {
navController.popBackStack()
}
}
is ModeType.Editing -> {
if ((modeType as ModeType.Editing).adding) {
navController.popBackStack()
} else {
showExitEditModeDialog(composableStates, onConfirm = {
vm.abandonEditingLectureDetail()
})
}
}
ModeType.Viewing -> {
onCloseViewMode(scope)
}
val onBackPressed: () -> Unit = {
if (bottomSheet.isVisible) {
scope.launch { bottomSheet.hide() }
} else when (modeType) {
ModeType.Normal -> {
if (navController.currentDestination?.route == NavigationDestination.LectureDetail) {
navController.popBackStack()
}
}
is ModeType.Editing -> {
if ((modeType as ModeType.Editing).adding) {
navController.popBackStack()
} else {
showExitEditModeDialog(composableStates, onConfirm = {
vm.abandonEditingLectureDetail()
})
}
}
ModeType.Viewing -> {
onCloseViewMode(scope)
}
}
}
DisposableEffect(Unit) {
onBackPressedDispatcherOwner?.onBackPressedDispatcher?.addCallback(onBackPressedCallback)
onDispose { onBackPressedCallback.remove() }

BackHandler {
onBackPressed()
}

/* TODO (진행중)
* 시간 및 장소 item 추가했을 때 애니메이션 적용하기 (LazyColumn 의 기능 모방)
* 추가시 애니메이션은 되는데 삭제시는 방법을 고민중
Expand Down Expand Up @@ -176,7 +171,7 @@ fun LectureDetailPage(
modifier = Modifier
.size(30.dp)
.clicks {
onBackPressedCallback.handleOnBackPressed()
onBackPressed()
},
colorFilter = ColorFilter.tint(SNUTTColors.Black900),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class VacancyViewModel @Inject constructor(
val firstVacancyVisit
get() = vacancyRepository.firstVacancyVisit

val vacancyBannerOpened = vacancyRepository.vacancyBannerOpenTime.map { nextOpenTime ->
System.currentTimeMillis() >= nextOpenTime
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false)

@Inject
lateinit var apiOnError: ApiOnError

Expand Down Expand Up @@ -96,8 +92,4 @@ class VacancyViewModel @Inject constructor(
vacancyRepository.setVacancyVisited()
}
}

suspend fun closeVacancyBanner() {
vacancyRepository.updateVacancyBannerOpenTime()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.wafflestudio.snutt2.views.logged_out

import androidx.activity.OnBackPressedCallback
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.background
Expand Down Expand Up @@ -43,7 +42,6 @@ fun EmailVerificationPage() {
val apiOnError = LocalApiOnError.current
val context = LocalContext.current
val keyboardManager = LocalSoftwareKeyboardController.current
val onBackPressedDispatcherOwner = LocalOnBackPressedDispatcherOwner.current
val coroutineScope = rememberCoroutineScope()
val userViewModel = hiltViewModel<UserViewModel>()

Expand Down Expand Up @@ -75,24 +73,19 @@ fun EmailVerificationPage() {
}
}

val onBackPressedCallback = remember {
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
when (flowState) {
VerifyEmailState.AskContinue -> navController.navigateAsOrigin(NavigationDestination.Home)
VerifyEmailState.SendCode -> {
flowState = VerifyEmailState.AskContinue
codeField = ""
timerState.reset()
}
}
val onBackPressed: () -> Unit = {
when (flowState) {
VerifyEmailState.AskContinue -> navController.navigateAsOrigin(NavigationDestination.Home)
VerifyEmailState.SendCode -> {
flowState = VerifyEmailState.AskContinue
codeField = ""
timerState.reset()
}
}
}

DisposableEffect(Unit) {
onBackPressedDispatcherOwner?.onBackPressedDispatcher?.addCallback(onBackPressedCallback)
onDispose { onBackPressedCallback.remove() }
BackHandler {
onBackPressed()
}

Column(
Expand All @@ -102,7 +95,7 @@ fun EmailVerificationPage() {
) {
SimpleTopBar(
title = stringResource(R.string.verify_email_app_bar_title),
onClickNavigateBack = { onBackPressedCallback.handleOnBackPressed() }
onClickNavigateBack = { onBackPressed() }
)
AnimatedContent(targetState = flowState) { targetState ->
Column(modifier = Modifier.padding(horizontal = 25.dp)) {
Expand Down
Loading

0 comments on commit 8a8fb91

Please sign in to comment.