diff --git a/feature/news/src/main/java/com/teamwable/news/NewsDetailFragment.kt b/feature/news/src/main/java/com/teamwable/news/NewsDetailFragment.kt new file mode 100644 index 00000000..21d7b9c8 --- /dev/null +++ b/feature/news/src/main/java/com/teamwable/news/NewsDetailFragment.kt @@ -0,0 +1,19 @@ +package com.teamwable.news + +import androidx.navigation.fragment.navArgs +import com.teamwable.news.databinding.FragmentNewsDetailBinding +import com.teamwable.news.model.NewsInfoModel +import com.teamwable.ui.base.BindingFragment + +class NewsDetailFragment : BindingFragment(FragmentNewsDetailBinding::inflate) { + private val args: NewsDetailFragmentArgs by navArgs() + private val notice: NewsInfoModel by lazy { args.newsInfoModel } + + override fun initView() { + receiveResultFromNotice() + } + + private fun receiveResultFromNotice() { + binding.tvNewsDetail.text = notice.newsText + } +} diff --git a/feature/news/src/main/java/com/teamwable/news/NewsViewModel.kt b/feature/news/src/main/java/com/teamwable/news/NewsViewModel.kt index f408e9a2..33cf97bf 100644 --- a/feature/news/src/main/java/com/teamwable/news/NewsViewModel.kt +++ b/feature/news/src/main/java/com/teamwable/news/NewsViewModel.kt @@ -6,6 +6,7 @@ import com.teamwable.common.uistate.UiState import com.teamwable.data.repository.NewsRepository import com.teamwable.model.news.NewsMatchModel import com.teamwable.model.news.NewsRankModel +import com.teamwable.news.model.NewsInfoModel import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow @@ -24,6 +25,17 @@ class NewsViewModel private val _rankUiState = MutableStateFlow>>(UiState.Loading) val rankUiState = _rankUiState.asStateFlow() + val dummyNotice = listOf( + NewsInfoModel(1, "와블 커뮤니티 업데이트 안내", "본문입니다 본문입니다 본문입니다 본문입니다 본문입니다 본문입니다 본문입니다 본문입니다 본문입니다", "www.11", "2024-01-10 11:47:18"), + NewsInfoModel(2, "제목2", "내용2", null, "2024-06-12 20:00:37"), + NewsInfoModel(3, "제목3", "내용3", "www.33", "2024-11-22 04:50:26"), + NewsInfoModel(4, "제목4", "내용4", "www.33", "2024-11-22 04:50:26"), + NewsInfoModel(5, "제목5", "내용5", "www.33", "2024-11-22 04:50:26"), + NewsInfoModel(6, "제목6", "내용6", "www.33", "2024-11-22 04:50:26"), + NewsInfoModel(7, "제목7", "내용7", "www.33", "2024-11-22 04:50:26"), + NewsInfoModel(8, "제목8", "내용8", "www.33", "2024-11-22 04:50:26"), + ) + init { getGameType() } diff --git a/feature/news/src/main/java/com/teamwable/news/model/NewsInfoModel.kt b/feature/news/src/main/java/com/teamwable/news/model/NewsInfoModel.kt index 797f2bc3..e80e659d 100644 --- a/feature/news/src/main/java/com/teamwable/news/model/NewsInfoModel.kt +++ b/feature/news/src/main/java/com/teamwable/news/model/NewsInfoModel.kt @@ -1,9 +1,13 @@ package com.teamwable.news.model +import android.os.Parcelable +import kotlinx.parcelize.Parcelize + +@Parcelize data class NewsInfoModel( val newsId: Int, val newsTitle: String, val newsText: String, - val newsImage: String, + val newsImage: String?, val time: String, -) +) : Parcelable diff --git a/feature/news/src/main/java/com/teamwable/news/notice/NewsNoticeFragment.kt b/feature/news/src/main/java/com/teamwable/news/notice/NewsNoticeFragment.kt index 57420594..e1ab6b24 100644 --- a/feature/news/src/main/java/com/teamwable/news/notice/NewsNoticeFragment.kt +++ b/feature/news/src/main/java/com/teamwable/news/notice/NewsNoticeFragment.kt @@ -1,12 +1,38 @@ package com.teamwable.news.notice +import android.os.Build +import androidx.annotation.RequiresApi +import androidx.compose.ui.platform.ViewCompositionStrategy +import androidx.navigation.fragment.findNavController +import com.teamwable.designsystem.theme.WableTheme +import com.teamwable.news.NewsFragmentDirections import com.teamwable.news.databinding.FragmentNewsNoticeBinding +import com.teamwable.news.model.NewsInfoModel import com.teamwable.ui.base.BindingFragment import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class NewsNoticeFragment : BindingFragment(FragmentNewsNoticeBinding::inflate) { + @RequiresApi(Build.VERSION_CODES.O) override fun initView() { + initComposeView() + } + + @RequiresApi(Build.VERSION_CODES.O) + private fun initComposeView() { + binding.composeNewsNotice.apply { + setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) + setContent { + WableTheme { + NewsNoticeRoute(navigateToDetail = { notice -> navigateToDetail(notice) }) + } + } + } + } + private fun navigateToDetail(notice: NewsInfoModel) { + val parentNavController = requireParentFragment().findNavController() + val action = NewsFragmentDirections.actionNavigationNewsToNavigationNewsDetail(notice) + parentNavController.navigate(action) } } diff --git a/feature/news/src/main/java/com/teamwable/news/notice/NewsNoticeItem.kt b/feature/news/src/main/java/com/teamwable/news/notice/NewsNoticeItem.kt new file mode 100644 index 00000000..3f135d0a --- /dev/null +++ b/feature/news/src/main/java/com/teamwable/news/notice/NewsNoticeItem.kt @@ -0,0 +1,44 @@ +package com.teamwable.news.notice + +import android.content.Context +import android.os.Build +import androidx.annotation.RequiresApi +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.teamwable.designsystem.theme.WableTheme +import com.teamwable.news.model.NewsInfoModel +import com.teamwable.ui.util.CalculateTime + +@RequiresApi(Build.VERSION_CODES.O) +@Composable +fun NewsNoticeItem( + context: Context, + data: NewsInfoModel, + navigateToDetail: (NewsInfoModel) -> Unit +) { + Column( + modifier = Modifier + .fillMaxWidth() + .background(WableTheme.colors.white) + .clickable { navigateToDetail(data) } + .padding(vertical = 12.dp, horizontal = 20.dp) + ) { + Row { + Text(text = data.newsTitle, style = WableTheme.typography.body01) + Spacer(modifier = Modifier.weight(1f)) + Text(text = CalculateTime().getCalculateTime(context, data.time), color = WableTheme.colors.gray500, style = WableTheme.typography.caption04) + } + Spacer(modifier = Modifier.height(2.dp)) + Text(text = data.newsText, color = WableTheme.colors.gray600, maxLines = 2, style = WableTheme.typography.body04) + } +} diff --git a/feature/news/src/main/java/com/teamwable/news/notice/NewsNoticeRoute.kt b/feature/news/src/main/java/com/teamwable/news/notice/NewsNoticeRoute.kt new file mode 100644 index 00000000..db16479e --- /dev/null +++ b/feature/news/src/main/java/com/teamwable/news/notice/NewsNoticeRoute.kt @@ -0,0 +1,70 @@ +package com.teamwable.news.notice + +import android.content.Context +import android.os.Build +import androidx.annotation.RequiresApi +import androidx.annotation.StringRes +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel +import com.teamwable.designsystem.theme.WableTheme +import com.teamwable.news.NewsViewModel +import com.teamwable.news.R +import com.teamwable.news.model.NewsInfoModel + +@RequiresApi(Build.VERSION_CODES.O) +@Composable +internal fun NewsNoticeRoute( + viewModel: NewsViewModel = hiltViewModel(), + navigateToDetail: (NewsInfoModel) -> Unit +) { + val context = LocalContext.current + + viewModel.dummyNotice.apply { + if (this.isNotEmpty()) { + NewsNoticeScreen(context = context, notices = this, navigateToDetail = navigateToDetail) + } else { + NewsNoticeEmptyScreen(R.string.tv_news_notice_empty) + } + } +} + +@RequiresApi(Build.VERSION_CODES.O) +@Composable +fun NewsNoticeScreen( + context: Context, + notices: List, + navigateToDetail: (NewsInfoModel) -> Unit +) { + LazyColumn(modifier = Modifier.fillMaxSize()) { + items(items = notices, key = { item -> item.newsId }) { notice -> + NewsNoticeItem(context, notice, navigateToDetail) + HorizontalDivider( + thickness = 1.dp, + color = WableTheme.colors.gray200, + ) + } + } +} + +@Composable +fun NewsNoticeEmptyScreen(@StringRes emptyTxt: Int) { + Box(modifier = Modifier.fillMaxSize()) { + Text( + modifier = Modifier.align(Alignment.Center), + text = stringResource(emptyTxt), + color = WableTheme.colors.gray500, + style = WableTheme.typography.body02 + ) + } +} diff --git a/feature/news/src/main/res/layout/fragment_news.xml b/feature/news/src/main/res/layout/fragment_news.xml index 2b2a665c..ba66ebe1 100644 --- a/feature/news/src/main/res/layout/fragment_news.xml +++ b/feature/news/src/main/res/layout/fragment_news.xml @@ -39,6 +39,7 @@ android:id="@+id/lottie_news_tab" android:layout_width="0dp" android:layout_height="wrap_content" + android:background="@color/black" android:scaleType="fitXY" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/feature/news/src/main/res/layout/fragment_news_detail.xml b/feature/news/src/main/res/layout/fragment_news_detail.xml new file mode 100644 index 00000000..f5527339 --- /dev/null +++ b/feature/news/src/main/res/layout/fragment_news_detail.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/feature/news/src/main/res/layout/fragment_news_notice.xml b/feature/news/src/main/res/layout/fragment_news_notice.xml index 8b4a14db..614c6ae0 100644 --- a/feature/news/src/main/res/layout/fragment_news_notice.xml +++ b/feature/news/src/main/res/layout/fragment_news_notice.xml @@ -4,10 +4,10 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + tools:layout="@layout/fragment_news"> + + + + + + diff --git a/feature/news/src/main/res/values/strings.xml b/feature/news/src/main/res/values/strings.xml index b8b86c6e..6d7ba6e8 100644 --- a/feature/news/src/main/res/values/strings.xml +++ b/feature/news/src/main/res/values/strings.xml @@ -35,4 +35,7 @@ 공지사항 + + 아직 작성된 공지사항이 없어요. +