Skip to content

Commit

Permalink
feat/#109: 내가 쓴 글 서버 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
jinukeu committed Jan 21, 2024
1 parent 50f0473 commit e283121
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 119 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.suwiki.feature.timetable.timetablelist.component
package com.suwiki.core.designsystem.component.container

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -26,13 +25,13 @@ import com.suwiki.core.designsystem.theme.Black
import com.suwiki.core.designsystem.theme.GrayF6
import com.suwiki.core.designsystem.theme.SuwikiTheme
import com.suwiki.core.designsystem.theme.White
import com.suwiki.core.model.timetable.Timetable
import com.suwiki.core.ui.extension.suwikiClickable

@Composable
fun TimetableEditContainer(
fun SuwikiEditContainer(
modifier: Modifier = Modifier,
timetable: Timetable = Timetable(),
name: String,
semester: String,
onClickEditButton: () -> Unit = {},
onClickDeleteButton: () -> Unit = {},
onClick: () -> Unit = {},
Expand Down Expand Up @@ -67,12 +66,12 @@ fun TimetableEditContainer(
modifier = Modifier.weight(1f, false),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
text = timetable.name,
text = name,
style = SuwikiTheme.typography.header6,
color = Black,
)

SuwikiBadge(color = BadgeColor.Gray, text = "${timetable.year}-${timetable.semester}")
SuwikiBadge(color = BadgeColor.Gray, text = semester)
}

Row(
Expand All @@ -95,14 +94,9 @@ fun TimetableEditContainer(
fun TimetableEditContainerPreview() {
SuwikiTheme {
Column {
TimetableEditContainer(
timetable = Timetable(
createTime = 0,
year = "2024",
semester = "1",
name = "시간표시간표시간표시간표시간표시간표시간표시간표",
cellList = listOf(),
),
SuwikiEditContainer(
name = "시간표시간표시간표시간표시간표시간표시간표시간표",
semester = "1",
)
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class AuthenticationInterceptor @Inject constructor(
Timber.tag(RETROFIT_TAG)
.d(
"AuthenticationInterceptor - intercept() called / request header: %s",
request.headers,
accessToken,
)
return@runBlocking chain.proceed(request)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshotFlow
import kotlinx.coroutines.flow.collectLatest

// https://manavtamboli.medium.com/infinite-list-paged-list-in-jetpack-compose-b10fc7e74768
@Composable
Expand All @@ -26,9 +27,9 @@ fun LazyListState.OnBottomReached(
lastVisibleItem.index >= layoutInfo.totalItemsCount - 1 - buffer
}
}
LaunchedEffect(shouldLoadMore.value) {
LaunchedEffect(shouldLoadMore) {
snapshotFlow { shouldLoadMore.value }
.collect {
.collectLatest {
if (it) {
onLoadMore()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.pager.HorizontalPager
Expand All @@ -26,7 +27,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.suwiki.core.designsystem.component.appbar.SuwikiAppBarWithTitle
import com.suwiki.core.designsystem.component.container.SuwikiReviewEditContainer
import com.suwiki.core.designsystem.component.container.SuwikiEditContainer
import com.suwiki.core.designsystem.component.loading.LoadingScreen
import com.suwiki.core.designsystem.component.tabbar.SuwikiTabBar
import com.suwiki.core.designsystem.component.tabbar.TabTitle
Expand All @@ -44,13 +45,13 @@ import kotlinx.collections.immutable.PersistentList
import kotlinx.serialization.json.Json
import org.orbitmvi.orbit.compose.collectAsState
import org.orbitmvi.orbit.compose.collectSideEffect
import timber.log.Timber

private val MY_EVALUATION_PAGE_COUNT = MyEvaluationTab.entries.size

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun MyEvaluationRoute(
padding: PaddingValues,
viewModel: MyEvaluationViewModel = hiltViewModel(),
popBackStack: () -> Unit = {},
navigateMyLectureEvaluation: (String) -> Unit = {},
Expand Down Expand Up @@ -92,9 +93,10 @@ fun MyEvaluationRoute(
}

MyEvaluationScreen(
padding = padding,
uiState = uiState,
pagerState = pagerState,
lectureEvaluationListState = lectureEvaluationListState,
examEvaluationListState = examEvaluationListState,
onClickTab = viewModel::syncPager,
onClickBack = viewModel::popBackStack,
onClickLectureEvaluationEditButton = viewModel::navigateMyLectureEvaluation,
Expand All @@ -103,20 +105,19 @@ fun MyEvaluationRoute(
}

@OptIn(ExperimentalFoundationApi::class)
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@Composable
fun MyEvaluationScreen(
padding: PaddingValues,
uiState: MyEvaluationState,
pagerState: PagerState = rememberPagerState(pageCount = { MY_EVALUATION_PAGE_COUNT }),
lectureEvaluationListState: LazyListState = rememberLazyListState(),
examEvaluationListState: LazyListState = rememberLazyListState(),
onClickTab: (Int) -> Unit = {},
onClickBack: () -> Unit = {},
onClickLectureEvaluationEditButton: (String) -> Unit = {},
onClickExamEvaluationEditButton: (String) -> Unit = {},
) {
Column(
modifier = Modifier
.padding(padding)
.background(White)
.fillMaxSize(),
) {
Expand Down Expand Up @@ -147,15 +148,16 @@ fun MyEvaluationScreen(
when (MyEvaluationTab.entries[page]) {
MyEvaluationTab.LECTURE_EVALUATION -> {
MyEvaluationLazyColumn(
// itemList = uiState.myLectureEvaluationList,
itemList = MyLectureEvaluationsSample,
itemList = uiState.myLectureEvaluationList,
listState = lectureEvaluationListState,
onClickLectureEditButton = onClickLectureEvaluationEditButton,
)
}

MyEvaluationTab.EXAM_INFO -> {
MyEvaluationLazyColumn(
// itemList = uiState.myExamEvaluationList,
itemList = MyExamEvaluationsSample,
itemList = uiState.myExamEvaluationList,
listState = examEvaluationListState,
onClickExamEditButton = onClickExamEvaluationEditButton,
)
}
Expand All @@ -171,28 +173,33 @@ fun MyEvaluationScreen(
fun MyEvaluationLazyColumn(
modifier: Modifier = Modifier,
itemList: PersistentList<Any>,
listState: LazyListState,
onClickLectureEditButton: (String) -> Unit = {},
onClickExamEditButton: (String) -> Unit = {},
) {
LazyColumn(
modifier = modifier.fillMaxSize(),
state = listState,
) {
items(items = itemList) { item ->
when (item) {
is MyLectureEvaluation -> {
SuwikiReviewEditContainer(
semesterText = item.selectedSemester,
classNameText = item.lectureInfo.lectureName,
SuwikiEditContainer(
semester = item.selectedSemester,
name = item.lectureInfo.lectureName,
onClickEditButton = { onClickLectureEditButton(Json.encodeToUri(item)) },
onClickDeleteButton = {},
)
}

is MyExamEvaluation -> {
val (examSemester, examName) = item.selectedSemester to item.lectureName

SuwikiReviewEditContainer(
semesterText = examSemester ?: stringResource(R.string.word_semester),
classNameText = examName ?: stringResource(R.string.word_lecture_name),
SuwikiEditContainer(
semester = examSemester ?: "",
name = examName ?: "",
onClickEditButton = { onClickExamEditButton(Json.encodeToUri(item)) },
onClickDeleteButton = {},
)
}
}
Expand All @@ -207,7 +214,6 @@ fun MyEvaluationPreview() {
var currentPage by remember { mutableIntStateOf(0) }
SuwikiTheme {
MyEvaluationScreen(
padding = PaddingValues(0.dp),
uiState = MyEvaluationState(
currentTabPage = currentPage,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,50 @@ class MyEvaluationViewModel @Inject constructor(
) : ContainerHost<MyEvaluationState, MyEvaluationSideEffect>, ViewModel() {
override val container: Container<MyEvaluationState, MyEvaluationSideEffect> = container(MyEvaluationState())

private var currentLectureEvaluationPage = 1
private var currentExamEvaluationPage = 1
private var isFirstVisit = true
private var lectureEvaluationPage = 1
private var isLastLectureEvaluation = false
private var examEvaluationPage = 1
private var isLastExamEvaluation = false

fun getMyLectureEvaluations() = intent {
showLoadingScreen()
getMyLectureEvaluationListUseCase(currentLectureEvaluationPage)
if (isLastLectureEvaluation) return@intent

getMyLectureEvaluationListUseCase(lectureEvaluationPage)
.onSuccess {
reduce { state.copy(myLectureEvaluationList = state.myLectureEvaluationList.addAll(it.toPersistentList())) }
currentLectureEvaluationPage++
reduce {
lectureEvaluationPage++
isLastLectureEvaluation = it.isEmpty()
state.copy(myLectureEvaluationList = state.myLectureEvaluationList.addAll(it.toPersistentList()))
}
}
.onFailure {
postSideEffect(MyEvaluationSideEffect.HandleException(it))
}
hideLoadingScreen()
}

fun getMyExamEvaluations() = intent {
showLoadingScreen()
getMyExamEvaluationListUseCase(currentExamEvaluationPage)
if (isLastExamEvaluation) return@intent

getMyExamEvaluationListUseCase(examEvaluationPage)
.onSuccess {
reduce { state.copy(myExamEvaluationList = state.myExamEvaluationList.addAll(it.toPersistentList())) }
currentExamEvaluationPage++
reduce {
examEvaluationPage++
isLastExamEvaluation = it.isEmpty()
state.copy(myExamEvaluationList = state.myExamEvaluationList.addAll(it.toPersistentList()))
}
}
.onFailure {
postSideEffect(MyEvaluationSideEffect.HandleException(it))
}
hideLoadingScreen()
}

fun initData() = intent {
if (isFirstVisit.not()) return@intent
showLoadingScreen()
joinAll(getMyLectureEvaluations(), getMyExamEvaluations())
hideLoadingScreen()
isFirstVisit = false
}

fun syncPager(currentPage: Int) = intent { reduce { state.copy(currentTabPage = currentPage) } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ fun NavController.navigateMyEvaluation() {
}

fun NavGraphBuilder.myEvaluationNavGraph(
padding: PaddingValues,
popBackStack: () -> Unit = {},
navigateMyLectureEvaluationEdit: (String) -> Unit = {},
navigateMyExamEvaluationEdit: (String) -> Unit = {},
handleException: (Throwable) -> Unit,
) {
composable(route = MyEvaluationRoute.route) {
MyEvaluationRoute(
padding = padding,
popBackStack = popBackStack,
navigateMyLectureEvaluation = navigateMyLectureEvaluationEdit,
navigateMyExamEvaluation = navigateMyExamEvaluationEdit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ internal fun MainScreen(
)

myEvaluationNavGraph(
padding = innerPadding,
popBackStack = navigator::popBackStackIfNotHome,
navigateMyLectureEvaluationEdit = navigator::navigateMyLectureEvaluationEdit,
navigateMyExamEvaluationEdit = navigator::navigateMyExamEvaluationEdit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.suwiki.core.designsystem.theme.White
import com.suwiki.core.model.timetable.Timetable
import com.suwiki.feature.timetable.R
import com.suwiki.feature.timetable.navigation.argument.TimetableEditorArgument
import com.suwiki.feature.timetable.timetablelist.component.TimetableEditContainer
import com.suwiki.core.designsystem.component.container.SuwikiEditContainer
import org.orbitmvi.orbit.compose.collectAsState
import org.orbitmvi.orbit.compose.collectSideEffect

Expand Down Expand Up @@ -98,8 +98,9 @@ fun TimetableListScreen(

LazyColumn {
items(items = uiState.timetableList, key = { it.createTime }) { timetable ->
TimetableEditContainer(
timetable = timetable,
SuwikiEditContainer(
name = timetable.name,
semester = "${timetable.year}-${timetable.semester}",
onClickEditButton = { onClickTimetableEditButton(timetable) },
onClickDeleteButton = { onClickTimetableDeleteButton(timetable) },
onClick = { onClickTimetableContainer(timetable.createTime) },
Expand Down
Loading

0 comments on commit e283121

Please sign in to comment.