diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 42df43a..5b7b425 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -47,7 +47,7 @@ android { minSdk = 26 targetSdk = 34 versionCode = 11011 - versionName = "1.1.1" + versionName = "1.1.2" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c076d67..e6b9efa 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -61,6 +61,17 @@ + + + + + + + + + + + >() { - lateinit var pagingSource: GetCommentsPageSource + private lateinit var pagingSource: GetCommentsPageSource override fun fetch(arguments: Arguments): Flow> { return Pager( config = PagingConfig( @@ -36,11 +36,15 @@ class GetCommentsRepository @Inject constructor( }.flow } - override fun closeResources() { - super.closeResources() + fun invalidateSource() { if (::pagingSource.isInitialized) pagingSource.invalidate() } + + override fun closeResources() { + super.closeResources() + this.invalidateSource() + } } class GetCommentsPageSource @Inject constructor( diff --git a/app/src/main/java/com/no5ing/bbibbi/data/repository/post/GetFeedsRepository.kt b/app/src/main/java/com/no5ing/bbibbi/data/repository/post/GetFeedsRepository.kt index 4383fca..ae7058d 100644 --- a/app/src/main/java/com/no5ing/bbibbi/data/repository/post/GetFeedsRepository.kt +++ b/app/src/main/java/com/no5ing/bbibbi/data/repository/post/GetFeedsRepository.kt @@ -23,7 +23,7 @@ import javax.inject.Singleton class GetFeedsRepository @Inject constructor( private val memberCacheProvider: MemberCacheProvider, ) : BaseRepository>() { - lateinit var pagingSource: GetFeedPageSource + private lateinit var pagingSource: GetFeedPageSource override fun fetch(arguments: Arguments): Flow> { return Pager( config = PagingConfig( @@ -37,11 +37,15 @@ class GetFeedsRepository @Inject constructor( }.flow } - override fun closeResources() { - super.closeResources() + fun invalidateSource() { if (::pagingSource.isInitialized) pagingSource.invalidate() } + + override fun closeResources() { + super.closeResources() + this.invalidateSource() + } } class GetFeedPageSource @Inject constructor( diff --git a/app/src/main/java/com/no5ing/bbibbi/di/NetworkModule.kt b/app/src/main/java/com/no5ing/bbibbi/di/NetworkModule.kt index b6f70bb..e92339f 100644 --- a/app/src/main/java/com/no5ing/bbibbi/di/NetworkModule.kt +++ b/app/src/main/java/com/no5ing/bbibbi/di/NetworkModule.kt @@ -32,9 +32,9 @@ import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) object NetworkModule { - private const val timeout_read = 10L - private const val timeout_connect = 10L - private const val timeout_write = 10L + private const val timeout_read = 20L + private const val timeout_connect = 20L + private const val timeout_write = 20L val requireUpdateState = MutableStateFlow(false) val requireTokenInvalidRestart = MutableStateFlow(false) @@ -144,7 +144,6 @@ object NetworkModule { // HttpLoggingInterceptor { message -> Timber.d("%s", message) } // httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BODY return client - // .addInterceptor(httpLoggingInterceptor) .connectTimeout(timeout_connect, TimeUnit.SECONDS) .readTimeout(timeout_read, TimeUnit.SECONDS) .writeTimeout(timeout_write, TimeUnit.SECONDS) diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/uistate/family/MainFeedStoryElementUiState.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/uistate/family/MainFeedStoryElementUiState.kt new file mode 100644 index 0000000..cfd2b53 --- /dev/null +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/uistate/family/MainFeedStoryElementUiState.kt @@ -0,0 +1,9 @@ +package com.no5ing.bbibbi.presentation.feature.uistate.family + +import com.no5ing.bbibbi.data.model.BaseModel +import com.no5ing.bbibbi.data.model.member.Member + +data class MainFeedStoryElementUiState( + val member: Member, + val isUploadedToday: Boolean, +) : BaseModel() diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/common/CustomAlertDialog.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/common/CustomAlertDialog.kt index 0296d43..bf9c200 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/common/CustomAlertDialog.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/common/CustomAlertDialog.kt @@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.AlertDialog import androidx.compose.material3.AlertDialogDefaults +import androidx.compose.material3.BasicAlertDialog import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.ExperimentalMaterial3Api @@ -60,7 +61,7 @@ fun CustomAlertDialog( hasCancel: Boolean = true, ) { if (enabledState.value) { - AlertDialog( + BasicAlertDialog( onDismissRequest = cancelRequest, modifier = Modifier, properties = DialogProperties() diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/common/PostCommentDialog.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/common/PostCommentDialog.kt index b2f5a97..f38c232 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/common/PostCommentDialog.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/common/PostCommentDialog.kt @@ -25,8 +25,8 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions -import androidx.compose.material3.Divider import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text @@ -217,7 +217,10 @@ fun PostCommentDialog( style = MaterialTheme.bbibbiTypo.bodyOneBold, ) Spacer(modifier = Modifier.height(16.dp)) - Divider(thickness = 1.dp, color = MaterialTheme.bbibbiScheme.gray600) + HorizontalDivider( + thickness = 1.dp, + color = MaterialTheme.bbibbiScheme.gray600 + ) } } ) { diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/landing/join_family_with_link/JoinFamilyWithLinkPage.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/landing/join_family_with_link/JoinFamilyWithLinkPage.kt index 005ca99..6689a51 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/landing/join_family_with_link/JoinFamilyWithLinkPage.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/landing/join_family_with_link/JoinFamilyWithLinkPage.kt @@ -238,6 +238,6 @@ fun JoinFamilyWithLinkPage( } private fun isValidUrl(input: String): Boolean { - val linkPrefix = "https://no5ing.kr/o/" - return input.startsWith(linkPrefix) + return input.startsWith("https://no5ing.kr/o/") + || input.startsWith("https://bibbi.app/o/") } \ No newline at end of file diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/family/FamilyPage.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/family/FamilyPage.kt index b3c2b7c..4e079ed 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/family/FamilyPage.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/family/FamilyPage.kt @@ -4,7 +4,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Divider +import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -77,7 +77,10 @@ fun FamilyPage( onTapShare = onTapShare, uiState = inviteLinkState, ) - Divider(thickness = 1.dp, color = MaterialTheme.bbibbiScheme.backgroundSecondary) + HorizontalDivider( + thickness = 1.dp, + color = MaterialTheme.bbibbiScheme.backgroundSecondary + ) FamilyPageMemberList( meId = meId, meState = meState, @@ -110,7 +113,10 @@ fun FamilyPagePreview() { mutableStateOf(APIResponse.success(DeepLink.mock())) }, ) - Divider(thickness = 1.dp, color = MaterialTheme.bbibbiScheme.backgroundSecondary) + HorizontalDivider( + thickness = 1.dp, + color = MaterialTheme.bbibbiScheme.backgroundSecondary + ) FamilyPageMemberList( meId = Member.unknown().memberId, meState = remember { mutableStateOf(APIResponse.success(Member.unknown())) }, diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/HomePage.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/HomePage.kt index 2e3444c..b713cc5 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/HomePage.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/HomePage.kt @@ -28,7 +28,6 @@ import com.no5ing.bbibbi.presentation.component.BBiBBiSurface import com.no5ing.bbibbi.presentation.component.BackToExitHandler import com.no5ing.bbibbi.presentation.feature.view.common.CustomAlertDialog import com.no5ing.bbibbi.presentation.feature.view_model.auth.RetrieveMeViewModel -import com.no5ing.bbibbi.presentation.feature.view_model.members.FamilyMembersViewModel import com.no5ing.bbibbi.presentation.feature.view_model.post.DailyFamilyTopViewModel import com.no5ing.bbibbi.presentation.feature.view_model.post.IsMeUploadedTodayViewModel import com.no5ing.bbibbi.presentation.feature.view_model.post.MainPostFeedViewModel @@ -43,7 +42,6 @@ fun HomePage( retrieveMeViewModel: RetrieveMeViewModel = hiltViewModel(), isMeUploadedTodayViewModel: IsMeUploadedTodayViewModel = hiltViewModel(), familyPostsViewModel: MainPostFeedViewModel = hiltViewModel(), - familyMembersViewModel: FamilyMembersViewModel = hiltViewModel(), familyPostTopViewModel: DailyFamilyTopViewModel = hiltViewModel(), onTapLeft: () -> Unit = {}, onTapRight: () -> Unit = {}, @@ -81,7 +79,7 @@ fun HomePage( } if (familyPostsViewModel.isInitialize()) { - familyMembersViewModel.invoke(Arguments()) + // familyMembersViewModel.invoke(Arguments()) retrieveMeViewModel.invoke(Arguments()) familyPostTopViewModel.invoke(Arguments())// TODO familyPostsViewModel.invoke( @@ -114,7 +112,6 @@ fun HomePage( ) HomePageContent( contentState = familyPostsViewModel.uiState, - familyListState = familyMembersViewModel.uiState, postTopState = familyPostTopViewModel.uiState, meState = retrieveMeViewModel.uiState, onTapContent = onTapContent, @@ -152,8 +149,7 @@ fun HomePagePreview() { HomePageTopBar() HomePageContent( contentState = MutableStateFlow(PagingData.empty()), - familyListState = MutableStateFlow(PagingData.empty()), - postTopState = MutableStateFlow(emptyMap()), + postTopState = MutableStateFlow(APIResponse.idle()), meState = MutableStateFlow(APIResponse.success(Member.unknown())) ) } diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/HomePageContent.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/HomePageContent.kt index 326a0ae..643d50b 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/HomePageContent.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/HomePageContent.kt @@ -10,7 +10,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.lazy.grid.GridItemSpan -import androidx.compose.material3.Divider +import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -30,6 +30,7 @@ import com.no5ing.bbibbi.R import com.no5ing.bbibbi.data.model.APIResponse import com.no5ing.bbibbi.data.model.member.Member import com.no5ing.bbibbi.data.model.post.Post +import com.no5ing.bbibbi.presentation.feature.uistate.family.MainFeedStoryElementUiState import com.no5ing.bbibbi.presentation.feature.uistate.family.MainFeedUiState import com.no5ing.bbibbi.presentation.theme.bbibbiScheme import com.no5ing.bbibbi.util.gapBetweenNow @@ -39,8 +40,8 @@ import kotlinx.coroutines.flow.StateFlow @Composable fun HomePageContent( contentState: StateFlow>, - familyListState: StateFlow>, - postTopState: StateFlow>, + //familyListState: StateFlow>, + postTopState: StateFlow>>, meState: StateFlow>, onTapContent: (Post) -> Unit = {}, onTapProfile: (Member) -> Unit = {}, @@ -48,12 +49,11 @@ fun HomePageContent( onRefresh: () -> Unit = {}, ) { val postItems = contentState.collectAsLazyPagingItems() - val memberItems = familyListState.collectAsLazyPagingItems() + // val memberItems = familyListState.collectAsLazyPagingItems() var isRefreshing by remember { mutableStateOf(false) } - LaunchedEffect(postItems.loadState.refresh, memberItems.loadState.refresh) { + LaunchedEffect(postItems.loadState.refresh) { if (isRefreshing && - postItems.loadState.refresh is LoadState.NotLoading && - memberItems.loadState.refresh is LoadState.NotLoading + postItems.loadState.refresh is LoadState.NotLoading ) { isRefreshing = false } @@ -64,7 +64,6 @@ fun HomePageContent( onRefresh = { if (isRefreshing) return@HomePageFeedGrid isRefreshing = true - memberItems.refresh() postItems.refresh() onRefresh() } @@ -76,12 +75,11 @@ fun HomePageContent( HomePageStoryBar( postTopStateFlow = postTopState, meStateFlow = meState, - familyListStateFlow = familyListState, onTapProfile = onTapProfile, onTapInvite = onTapInvite, ) Spacer(modifier = Modifier.height(24.dp)) - Divider( + HorizontalDivider( thickness = 1.dp, color = MaterialTheme.bbibbiScheme.backgroundSecondary ) diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/HomePageStoryBar.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/HomePageStoryBar.kt index bb5236f..7f14ff7 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/HomePageStoryBar.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/HomePageStoryBar.kt @@ -29,12 +29,11 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp -import androidx.paging.PagingData -import androidx.paging.compose.collectAsLazyPagingItems import com.no5ing.bbibbi.R import com.no5ing.bbibbi.data.model.APIResponse import com.no5ing.bbibbi.data.model.member.Member import com.no5ing.bbibbi.presentation.component.CircleProfileImage +import com.no5ing.bbibbi.presentation.feature.uistate.family.MainFeedStoryElementUiState import com.no5ing.bbibbi.presentation.theme.bbibbiScheme import com.no5ing.bbibbi.presentation.theme.bbibbiTypo import com.no5ing.bbibbi.util.LocalSessionState @@ -42,18 +41,17 @@ import kotlinx.coroutines.flow.StateFlow @Composable fun HomePageStoryBar( - postTopStateFlow: StateFlow>, + postTopStateFlow: StateFlow>>, meStateFlow: StateFlow>, - familyListStateFlow: StateFlow>, onTapProfile: (Member) -> Unit = {}, onTapInvite: () -> Unit = {}, ) { val meId = LocalSessionState.current.memberId val postTopState by postTopStateFlow.collectAsState() val meState by meStateFlow.collectAsState() - val items = familyListStateFlow.collectAsLazyPagingItems() + //val items = familyListStateFlow.collectAsLazyPagingItems() - if (items.itemCount == 1) { + if (postTopState.isReady() && postTopState.data.size == 1) { HomePageNoFamilyBar( modifier = Modifier .fillMaxWidth() @@ -61,7 +59,7 @@ fun HomePageStoryBar( .padding(horizontal = 16.dp), onTap = onTapInvite, ) - } else { + } else if (postTopState.isReady()) { LazyRow( modifier = Modifier .fillMaxWidth() @@ -71,8 +69,9 @@ fun HomePageStoryBar( Spacer(modifier = Modifier.width(20.dp)) } - if (meState.isReady()) { + if (meState.isReady() && postTopState.isReady()) { val item = meState.data + val meData = postTopState.data.indexOfFirst { it.member.memberId == meId } item { StoryBarIcon( member = item, @@ -80,28 +79,28 @@ fun HomePageStoryBar( onTapProfile(item) }, isMe = true, - isUploaded = postTopState.containsKey(item.memberId), - rank = postTopState[item.memberId] ?: -1, + isUploaded = postTopState.data[meData].isUploadedToday, + rank = meData, ) } } items( - count = items.itemCount, - key = { items[it]!!.memberId } + count = postTopState.data.size, + key = { postTopState.data[it].member.memberId } ) { index -> - val item = items[index] ?: throw RuntimeException() - if (item.memberId != meId) { + val item = postTopState.data[index] + if (item.member.memberId != meId) { Row { Spacer(modifier = Modifier.width(12.dp)) StoryBarIcon( - member = item, + member = item.member, onTap = { - onTapProfile(item) + onTapProfile(item.member) }, - isUploaded = postTopState.containsKey(item.memberId), - rank = postTopState[item.memberId] ?: -1, + isUploaded = item.isUploadedToday, + rank = index, ) } } @@ -132,8 +131,8 @@ fun StoryBarIcon( horizontalAlignment = Alignment.CenterHorizontally ) { Box { - val rankColor = getRankColor(rank = rank) - val rankBadge = getRankBadge(rank = rank) + val rankColor = if (isUploaded) getRankColor(rank = rank) else null + val rankBadge = if (isUploaded) getRankBadge(rank = rank) else null if (rankColor != null) { Box( modifier = Modifier diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/TryWidgetPopup.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/TryWidgetPopup.kt index 52663a6..e9b8bab 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/TryWidgetPopup.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/home/TryWidgetPopup.kt @@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.AlertDialog import androidx.compose.material3.AlertDialogDefaults +import androidx.compose.material3.BasicAlertDialog import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.ExperimentalMaterial3Api @@ -38,7 +39,7 @@ import com.no5ing.bbibbi.presentation.theme.bbibbiTypo fun TryWidgetPopup() { val enabledState = remember { mutableStateOf(true) } if (enabledState.value) { - AlertDialog( + BasicAlertDialog( onDismissRequest = { enabledState.value = false }, diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/post_view/PostViewPage.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/post_view/PostViewPage.kt index 065f0ed..2b596cf 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/post_view/PostViewPage.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/post_view/PostViewPage.kt @@ -82,7 +82,7 @@ fun PostViewPage( var isPagerReady by remember { mutableStateOf(false) } val postState by postViewPageState.uiState.collectAsState() val siblingPostState by familyPostsViewModel.uiState.collectAsState() - val pagerState = key(siblingPostState.isReady()) { + val pagerState = key(siblingPostState) { rememberPagerState( initialPage = if (siblingPostState.isReady()) siblingPostState.data .indexOfFirst { it.post.postId == postId } else 0, @@ -123,7 +123,8 @@ fun PostViewPage( LaunchedEffect(postState, pagerState.currentPage) { if (postState.isReady()) { val currentPost = - if (siblingPostState.isReady()) siblingPostState.data[pagerState.currentPage] else postState.data + (if (siblingPostState.isReady()) siblingPostState.data.getOrNull(pagerState.currentPage) else postState.data) + ?: return@LaunchedEffect familyPostReactionBarViewModel.invoke( Arguments( arguments = mapOf( @@ -145,7 +146,13 @@ fun PostViewPage( modifier = Modifier.fillMaxSize() ) { AsyncImage( - model = asyncImagePainter(source = postState.data.post.imageUrl), + model = asyncImagePainter( + source = + if (postState.isReady()) + if (siblingPostState.isReady()) siblingPostState.data[pagerState.currentPage].post.imageUrl + else postState.data.post.imageUrl + else null + ), contentDescription = null, modifier = Modifier .fillMaxSize() diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/profile/ProfilePageMemberBar.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/profile/ProfilePageMemberBar.kt index 0fb54c0..391bdf0 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/profile/ProfilePageMemberBar.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/profile/ProfilePageMemberBar.kt @@ -11,7 +11,7 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width -import androidx.compose.material3.Divider +import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text @@ -126,7 +126,10 @@ fun ProfilePageMemberBar( ) } Spacer(modifier = Modifier.height(24.dp)) - Divider(thickness = 1.dp, color = MaterialTheme.bbibbiScheme.backgroundSecondary) + HorizontalDivider( + thickness = 1.dp, + color = MaterialTheme.bbibbiScheme.backgroundSecondary + ) Spacer(modifier = Modifier.height(24.dp)) } } diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/CreatePostViewModel.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/CreatePostViewModel.kt index 394bb60..d858dd1 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/CreatePostViewModel.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/CreatePostViewModel.kt @@ -59,7 +59,7 @@ class CreatePostViewModel @Inject constructor( data.url ) if (imageUploadResult == null) { - //TODO: SOME KIND + setState(APIResponse.unknownError()) return@suspendOnSuccess } val postResult = restAPI.getPostApi().createPost( diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/DailyFamilyTopViewModel.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/DailyFamilyTopViewModel.kt index 893be95..40e5573 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/DailyFamilyTopViewModel.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/DailyFamilyTopViewModel.kt @@ -1,25 +1,38 @@ package com.no5ing.bbibbi.presentation.feature.view_model.post import com.no5ing.bbibbi.data.datasource.network.RestAPI +import com.no5ing.bbibbi.data.model.APIResponse import com.no5ing.bbibbi.data.repository.Arguments +import com.no5ing.bbibbi.presentation.feature.uistate.family.MainFeedStoryElementUiState import com.no5ing.bbibbi.presentation.feature.view_model.BaseViewModel import com.no5ing.bbibbi.util.todayAsString +import com.skydoves.sandwich.getOrNull +import com.skydoves.sandwich.isSuccess +import com.skydoves.sandwich.suspendOnFailure import com.skydoves.sandwich.suspendOnSuccess import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async import javax.inject.Inject @HiltViewModel class DailyFamilyTopViewModel @Inject constructor( private val restAPI: RestAPI, -) : BaseViewModel>() { - override fun initState(): Map { - return emptyMap() +) : BaseViewModel>>() { + override fun initState(): APIResponse> { + return APIResponse.idle() } override fun invoke(arguments: Arguments) { withMutexScope(Dispatchers.IO) { - val newMap = HashMap() + val newList = ArrayList() + val members = async { + restAPI.getMemberApi() + .getMembers( + page = 1, + size = 100 + ) + } restAPI .getPostApi() .getPosts( @@ -29,10 +42,25 @@ class DailyFamilyTopViewModel @Inject constructor( date = todayAsString(), sort = "ASC" ).suspendOnSuccess { - data.results.forEachIndexed { index, post -> - newMap[post.authorId] = index + val response = members.await() + if (response.isSuccess) { + val memberMap = (response.getOrNull()?.results?.associateBy { it.memberId } + ?: emptyMap()) + .toMutableMap() + data.results.forEachIndexed { index, post -> + val currentMember = + memberMap.remove(post.authorId) ?: return@forEachIndexed + newList.add(MainFeedStoryElementUiState(currentMember, true)) + } + memberMap.forEach { + newList.add(MainFeedStoryElementUiState(it.value, false)) + } + setState(APIResponse.success(newList)) + } else { + setState(APIResponse.unknownError()) } - setState(newMap) + }.suspendOnFailure { + setState(APIResponse.unknownError()) } } } diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/MainPostFeedViewModel.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/MainPostFeedViewModel.kt index ff0789a..3378556 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/MainPostFeedViewModel.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/MainPostFeedViewModel.kt @@ -37,9 +37,7 @@ class MainPostFeedViewModel @Inject constructor( } } - fun refresh() { - getPostsRepository.pagingSource.invalidate() - } + fun refresh() = getPostsRepository.invalidateSource() override fun release() { super.release() diff --git a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/PostCommentViewModel.kt b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/PostCommentViewModel.kt index 8b91d34..64c63cd 100644 --- a/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/PostCommentViewModel.kt +++ b/app/src/main/java/com/no5ing/bbibbi/presentation/feature/view_model/post/PostCommentViewModel.kt @@ -22,9 +22,7 @@ class PostCommentViewModel @Inject constructor( return PagingData.empty() } - fun refresh() { - getCommentsRepository.pagingSource.invalidate() - } + fun refresh() = getCommentsRepository.invalidateSource() override fun invoke(arguments: Arguments) { withMutexScope(Dispatchers.IO) { diff --git a/app/src/main/java/com/no5ing/bbibbi/util/ImageUploader.kt b/app/src/main/java/com/no5ing/bbibbi/util/ImageUploader.kt index 6a5779b..05f40f8 100644 --- a/app/src/main/java/com/no5ing/bbibbi/util/ImageUploader.kt +++ b/app/src/main/java/com/no5ing/bbibbi/util/ImageUploader.kt @@ -3,7 +3,6 @@ package com.no5ing.bbibbi.util import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient import okhttp3.Request -import okhttp3.RequestBody import okhttp3.RequestBody.Companion.asRequestBody import java.io.File @@ -16,25 +15,8 @@ fun OkHttpClient.uploadImage( .url(targetUrl) .put(targetFile.asRequestBody("image/jpeg".toMediaType())) .build() - val response = newCall(request).execute() - return if (response.isSuccessful) { - destinationUrl - } else { - null - } -} - -fun OkHttpClient.upload( - body: RequestBody, - targetUrl: String -): String? { - val destinationUrl = removeQueryParams(targetUrl) - val request = Request.Builder() - .url(targetUrl) - .put(body) - .build() - val response = newCall(request).execute() - return if (response.isSuccessful) { + val response = runCatching { newCall(request).execute() }.getOrNull() + return if (response?.isSuccessful == true) { destinationUrl } else { null diff --git a/fastlane/metadata/android/ko-KR/title.txt b/fastlane/metadata/android/ko-KR/title.txt index a608909..7349f1b 100644 --- a/fastlane/metadata/android/ko-KR/title.txt +++ b/fastlane/metadata/android/ko-KR/title.txt @@ -1 +1 @@ -삐삐 - 가족 일상 위젯 \ No newline at end of file +삐삐 - 하루 한 번, 가족에게 보내는 생존신고 \ No newline at end of file