Skip to content

Commit

Permalink
Merge pull request #512 from 014967/feature/empty_schedule
Browse files Browse the repository at this point in the history
Feature/empty schedule
  • Loading branch information
014967 authored Jun 29, 2024
2 parents d0da4d5 + e87641d commit e7d94ab
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 141 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,7 @@ dependencies {

// Naver Map
implementation "io.github.fornewid:naver-map-compose:1.4.0"

// Date Time
implementation 'com.jakewharton.threetenabp:threetenabp:1.3.1'
}
7 changes: 7 additions & 0 deletions app/src/main/java/com/mashup/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.NavHostFragment
import com.jakewharton.threetenabp.AndroidThreeTen
import com.mashup.R
import com.mashup.base.BaseActivity
import com.mashup.constant.EXTRA_ANIMATION
Expand Down Expand Up @@ -64,6 +66,11 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidThreeTen.init(this)
}

override fun initViews() {
super.initViews()

Expand Down
61 changes: 41 additions & 20 deletions app/src/main/java/com/mashup/ui/schedule/ScheduleRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Expand All @@ -50,6 +51,7 @@ import com.mashup.ui.attendance.platform.PlatformAttendanceActivity
import com.mashup.ui.main.MainViewModel
import com.mashup.ui.schedule.component.ScheduleTabRow
import com.mashup.ui.schedule.detail.ScheduleDetailActivity
import com.mashup.ui.schedule.model.ScheduleType
import com.mashup.util.AnalyticsManager
import com.mashup.core.common.R as CR

Expand Down Expand Up @@ -86,20 +88,30 @@ fun ScheduleRoute(
LaunchedEffect(scheduleState) {
when (val state = scheduleState) {
is ScheduleState.Loading -> {}
is ScheduleState.Empty -> { isRefreshing = false }
is ScheduleState.Init -> {
isRefreshing = false
}

is ScheduleState.Success -> {
isRefreshing = false
title = context.setUiOfScheduleTitle(state.scheduleTitleState)
}
is ScheduleState.Error -> { isRefreshing = false }

is ScheduleState.Error -> {
isRefreshing = false
}
}
}

var selectedTabIndex by remember { mutableStateOf(0) }
var selectedTabIndex by remember { mutableIntStateOf(0) }
CompositionLocalProvider(
LocalOverscrollConfiguration provides null
) {
Box(modifier = modifier.pullRefresh(pullRefreshState).background(White)) {
Box(
modifier = modifier
.pullRefresh(pullRefreshState)
.background(White)
) {
LazyColumn(modifier = modifier) {
item {
ScheduleTopbar(title)
Expand All @@ -119,25 +131,17 @@ fun ScheduleRoute(
item {
when (scheduleState) {
is ScheduleState.Error -> {}
is ScheduleState.Empty -> {}
is ScheduleState.Init -> {}
else -> {
ScheduleScreen(
modifier = Modifier.fillMaxSize().background(color = Color.White),
modifier = Modifier
.fillMaxSize()
.background(color = Color.White),
scheduleState = scheduleState,
onClickScheduleInformation = { scheduleId: Int ->
AnalyticsManager.addEvent(eventName = LOG_SCHEDULE_EVENT_DETAIL)
context.startActivity(
ScheduleDetailActivity.newIntent(context, scheduleId)
)
},
onClickAttendance = { scheduleId: Int ->
AnalyticsManager.addEvent(eventName = LOG_SCHEDULE_STATUS_CONFIRM)
context.startActivity(
PlatformAttendanceActivity.newIntent(context, scheduleId)
)
},
refreshState = isRefreshing

onClickScheduleInformation = { context.moveToScheduleInformation(it) },
onClickAttendance = { context.moveToAttendance(it) },
refreshState = isRefreshing,
scheduleType = ScheduleType.values()[selectedTabIndex]
)
}
}
Expand All @@ -160,18 +164,35 @@ fun Context.setUiOfScheduleTitle(scheduleTitleState: ScheduleTitleState): String
ScheduleTitleState.Empty -> {
getString(R.string.empty_schedule)
}

is ScheduleTitleState.End -> {
getString(R.string.end_schedule, scheduleTitleState.generatedNumber)
}

is ScheduleTitleState.DateCount -> {
getString(R.string.event_list_title, scheduleTitleState.dataCount)
}

is ScheduleTitleState.SchedulePreparing -> {
getString(R.string.preparing_attendance)
}
}
}

fun Context.moveToScheduleInformation(scheduleId: Int) {
AnalyticsManager.addEvent(eventName = LOG_SCHEDULE_EVENT_DETAIL)
startActivity(
ScheduleDetailActivity.newIntent(this, scheduleId)
)
}

fun Context.moveToAttendance(scheduleId: Int) {
AnalyticsManager.addEvent(eventName = LOG_SCHEDULE_STATUS_CONFIRM)
startActivity(
PlatformAttendanceActivity.newIntent(this, scheduleId)
)
}

@Composable
fun ScheduleTopbar(title: String) {
Row(
Expand Down
114 changes: 13 additions & 101 deletions app/src/main/java/com/mashup/ui/schedule/ScheduleScreen.kt
Original file line number Diff line number Diff line change
@@ -1,119 +1,31 @@
package com.mashup.ui.schedule

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PageSize
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
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.graphicsLayer
import androidx.compose.ui.unit.dp
import com.mashup.ui.schedule.item.EmptyScheduleItem
import com.mashup.ui.schedule.item.ScheduleViewPagerInProgressItem
import com.mashup.ui.schedule.item.ScheduleViewPagerSuccessItem
import com.mashup.ui.schedule.model.ScheduleCard
import kotlin.math.abs
import kotlin.math.absoluteValue
import com.mashup.ui.schedule.component.WeeklySchedule
import com.mashup.ui.schedule.model.ScheduleType

@Composable
fun ScheduleScreen(
scheduleState: ScheduleState,
modifier: Modifier = Modifier,
scheduleType: ScheduleType = ScheduleType.WEEK,
onClickScheduleInformation: (Int) -> Unit = {},
onClickAttendance: (Int) -> Unit = {},
refreshState: Boolean = false
) {
var cacheScheduleState by remember {
mutableStateOf(scheduleState)
}

LaunchedEffect(scheduleState) {
if (scheduleState is ScheduleState.Success) {
cacheScheduleState = scheduleState
}
}

when (cacheScheduleState) {
is ScheduleState.Success -> {
val castingState = cacheScheduleState as ScheduleState.Success
val horizontalPagerState = rememberPagerState(
initialPage = if (castingState.scheduleList.size < 6) 1 else castingState.scheduleList.size - 4,
pageCount = { castingState.scheduleList.size }
)
LaunchedEffect(refreshState) {
if (refreshState.not()) { // refresh 가 끝났을 경우
horizontalPagerState.animateScrollToPage(castingState.schedulePosition)
}
}

HorizontalPager(
when (scheduleType) {
ScheduleType.WEEK -> {
WeeklySchedule(
scheduleState = scheduleState,
modifier = modifier,
state = horizontalPagerState,
pageSpacing = 12.dp,
pageSize = PageSize.Fill,
contentPadding = PaddingValues(33.dp),
verticalAlignment = Alignment.Top
) { index ->
when (val data = castingState.scheduleList[index]) {
is ScheduleCard.EmptySchedule -> {
Box(
modifier = Modifier.fillMaxSize()
) {
EmptyScheduleItem(
modifier = Modifier.fillMaxSize().graphicsLayer {
val pageOffset =
((horizontalPagerState.currentPage - index) + horizontalPagerState.currentPageOffsetFraction).absoluteValue
scaleY = 1 - 0.1f * abs(pageOffset)
}
)
}
}

is ScheduleCard.EndSchedule -> {
Box(
modifier = Modifier.fillMaxSize()
) {
ScheduleViewPagerSuccessItem(
modifier = Modifier.graphicsLayer {
val pageOffset =
((horizontalPagerState.currentPage - index) + horizontalPagerState.currentPageOffsetFraction).absoluteValue
scaleY = 1 - 0.1f * abs(pageOffset)
},
data = data,
onClickScheduleInformation = onClickScheduleInformation,
onClickAttendance = onClickAttendance
)
}
}

is ScheduleCard.InProgressSchedule -> {
Box(
modifier = Modifier.fillMaxSize()
) {
ScheduleViewPagerInProgressItem(
modifier = Modifier.graphicsLayer {
val pageOffset =
((horizontalPagerState.currentPage - index) + horizontalPagerState.currentPageOffsetFraction).absoluteValue
scaleY = 1 - 0.1f * abs(pageOffset)
},
data = data,
onClickScheduleInformation = onClickScheduleInformation,
onClickAttendance = onClickAttendance
)
}
}
}
}
onClickScheduleInformation = onClickScheduleInformation,
onClickAttendance = onClickAttendance,
refreshState = refreshState
)
}

else -> {}
ScheduleType.TOTAL -> {
}
}
}
Loading

0 comments on commit e7d94ab

Please sign in to comment.