Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

날짜 선택 체크, LaunchedEffect key 변경, 영상 텍스트 편집 수정 #179

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ dependencies {
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"
implementation "com.github.bumptech.glide:compose:$glide_compose_version"

// Coil
implementation("io.coil-kt:coil-compose:2.4.0")

// Paging
implementation "androidx.paging:paging-runtime:$pagingVersion"
implementation "androidx.paging:paging-compose:$pagingComposeVersion"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.boostcamp.dailyfilm.presentation.calendar

import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.runtime.toMutableStateList
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
Expand Down Expand Up @@ -95,7 +98,7 @@ class DateViewModel @Inject constructor(

fun reloadCalendar(itemList: List<DailyFilmItem?>) {
val tempCalendar = createCalendar(prevCalendar, day = prevMaxDay - (dayOfWeek - 2))
val dateModelList = _dateFlow.value.toMutableList()
val dateModelList = _dateFlow.value.toMutableStateList()
val prevDay = tempCalendar.day()
val prevCnt = if (dayOfWeek == 1) {
-1
Expand Down Expand Up @@ -152,14 +155,14 @@ class DateViewModel @Inject constructor(
}

fun setVideo(index: Int, dateModel: DateModel) {
val tmpList = _dateFlow.value.toMutableList()
val tmpList = _dateFlow.value.toMutableStateList()
tmpList[index] = dateModel
_dateFlow.value = tmpList
}

fun initialDateList(): List<DateModel> {
fun initialDateList(): SnapshotStateList<DateModel> {
val tempCalendar = createCalendar(prevCalendar, day = prevMaxDay - (dayOfWeek - 2))
val dateModelList = mutableListOf<DateModel>()
val dateModelList = mutableStateListOf<DateModel>()

for (i in 0 until 42) {
val year = tempCalendar.year()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.boostcamp.dailyfilm.presentation.calendar.compose

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material3.Text
Expand All @@ -15,8 +19,11 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.ColorMatrix
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Constraints
Expand All @@ -25,6 +32,10 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import coil.compose.AsyncImage
import coil.compose.AsyncImagePainter
import coil.compose.rememberAsyncImagePainter
import coil.request.ImageRequest
import com.boostcamp.dailyfilm.data.model.DailyFilmItem
import com.boostcamp.dailyfilm.presentation.calendar.DateViewModel
import com.boostcamp.dailyfilm.presentation.calendar.model.DateModel
Expand All @@ -41,6 +52,7 @@ fun CalendarView(
viewModel: DateViewModel,
resetFilm: (List<DateModel>) -> Unit,
imgClick: (Int, DateModel) -> Unit,
onMovePlayFilm: (Int, DateModel) -> Unit,
) {
val lifecycleEvent = rememberLifecycleEvent()
val itemList by viewModel.itemFlow.collectAsStateWithLifecycle(initialValue = null)
Expand All @@ -58,7 +70,8 @@ fun CalendarView(
viewModel.reloadCalendar(it)
},
resetFilm = resetFilm,
imgClick = imgClick
imgClick = imgClick,
onMovePlayFilm = onMovePlayFilm
)
}

Expand All @@ -73,6 +86,7 @@ fun CalendarView(
reloadCalendar: (List<DailyFilmItem?>) -> Unit,
resetFilm: (List<DateModel>) -> Unit,
imgClick: (Int, DateModel) -> Unit,
onMovePlayFilm: (Int, DateModel) -> Unit,
) {

val textSize = 12.sp
Expand All @@ -85,15 +99,6 @@ fun CalendarView(
Lifecycle.Event.ON_PAUSE -> {
dateState.selectedDay = null
}

Lifecycle.Event.ON_RESUME -> {
// onResume 에서 가 아닌 repeatOnLifecycle 의 RESUMED 상태로 받아도 됐었음.
// LaunchedEffect(key1 = reloadList) 가 안됨
resetFilm(
reloadList.filter { dateModel -> dateModel.videoUrl != null }
)
}

else -> {}
}
}
Expand All @@ -114,13 +119,31 @@ fun CalendarView(
currentCalendar = currentCalendar,
todayCalendar = todayCalendar,
dateState = dateState,
imgClick = imgClick
imgClick = imgClick,
onMovePlayFilm = onMovePlayFilm
)
}

@OptIn(ExperimentalGlideComposeApi::class)
@Composable
private fun DateImage(background: Color, alpha: Float, url: String?, onClick: () -> Unit) {
/*val painter = rememberAsyncImagePainter(url)
val state = painter.state

val transition by animateFloatAsState(
targetValue = if (state is AsyncImagePainter.State.Success) 1f else 0f, label = ""
)
Image(
modifier = Modifier
.fillMaxSize()
.background(background)
.alpha(transition)
.padding(2.dp)
.clip(RoundedCornerShape(5.dp))
.noRippleClickable(onClick = onClick),
painter = painter,
contentDescription = "custom transition based on painter state",
)*/

GlideImage(
modifier = Modifier
Expand All @@ -145,13 +168,13 @@ private fun CustomCalendarView(
todayCalendar: Calendar,
dateState: DateState,
imgClick: (Int, DateModel) -> Unit,
onMovePlayFilm: (Int, DateModel) -> Unit,
) {

CustomCalendarView(
textHeight = textHeight
) {
reloadList.forEachIndexed { index, dateModel ->

println("dateModel: $dateModel")
val isNotCurrentMonth = isNotCurrentMonth(
dateModel,
currentCalendar.month(),
Expand All @@ -173,13 +196,16 @@ private fun CustomCalendarView(
alpha = dateState.alpha,
url = dateModel.videoUrl
) {
println("DateImage: onCLick")
if (!isNotCurrentMonth) {
println("isNotCurrentMonth: $isNotCurrentMonth")
dateState.apply {
if (dateModel.videoUrl != null) {
selectedDay = null
imgClick(index, dateModel)
imgClick(index, dateModel)
selectedDay = if (dateModel.videoUrl != null) {
onMovePlayFilm(index, dateModel)
null
} else {
selectedDay = index
index
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ class DateComposeFragment :
activityViewModel.emitFilm(it)
},
imgClick = { idx, dateModel ->
Log.d("CalendarView", "${ArrayList(activityViewModel.filmFlow.value)}")
println("idx: $idx dateModel: $dateModel")
activityViewModel.changeSelectedItem(idx, dateModel)
},
onMovePlayFilm = { idx, dateModel ->
startForResult.launch(
Intent(requireContext(), PlayFilmActivity::class.java).apply {
putExtra(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.boostcamp.dailyfilm.presentation.selectvideo.SelectVideoActivity
import com.boostcamp.dailyfilm.presentation.selectvideo.SelectVideoActivity.Companion.DATE_VIDEO_ITEM
import com.boostcamp.dailyfilm.presentation.ui.theme.DailyFilmTheme
import com.boostcamp.dailyfilm.presentation.uploadfilm.UploadFilmActivity
import com.boostcamp.dailyfilm.presentation.uploadfilm.UploadFilmComposeActivity
import com.boostcamp.dailyfilm.presentation.uploadfilm.model.DateAndVideoModel
import com.boostcamp.dailyfilm.presentation.util.network.NetworkManager
import com.boostcamp.dailyfilm.presentation.util.network.NetworkState
Expand Down Expand Up @@ -85,15 +86,17 @@ class PlayFilmComposeFragment :
}
},
dialogEvent = { resId ->
when(resId) {
when (resId) {
R.string.delete -> {
viewModel.setDialog(true)
}

R.string.re_upload -> {
activity?.let {
it.startActivity(
Intent(
it.applicationContext, SelectVideoActivity::class.java
it.applicationContext,
SelectVideoActivity::class.java
).apply {
putExtra(
KEY_CALENDAR_INDEX,
Expand All @@ -104,7 +107,8 @@ class PlayFilmComposeFragment :
putExtra(
DATE_VIDEO_ITEM,
DateAndVideoModel(
viewModel.videoUri.value ?: return@PlayFilmUI,
viewModel.videoUri.value
?: return@PlayFilmUI,
viewModel.dateModel.getDate()
)
)
Expand All @@ -113,10 +117,17 @@ class PlayFilmComposeFragment :
it.finish()
}
}

R.string.edit_text -> {
startForResult.launch(
Intent(activity?.applicationContext, UploadFilmActivity::class.java).apply {
putExtra(KEY_CALENDAR_INDEX, activityViewModel.calendarIndex)
Intent(
activity?.applicationContext,
UploadFilmComposeActivity::class.java
).apply {
putExtra(
KEY_CALENDAR_INDEX,
activityViewModel.calendarIndex
)
putExtra(
DATE_VIDEO_ITEM,
DateAndVideoModel(
Expand Down