-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…-news-news-ui
- Loading branch information
Showing
11 changed files
with
216 additions
and
7 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
feature/news/src/main/java/com/teamwable/news/NewsDetailFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>(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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
feature/news/src/main/java/com/teamwable/news/model/NewsInfoModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
26 changes: 26 additions & 0 deletions
26
feature/news/src/main/java/com/teamwable/news/notice/NewsNoticeFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>(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) | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
feature/news/src/main/java/com/teamwable/news/notice/NewsNoticeItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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.Box | ||
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) { | ||
Box(modifier = Modifier.clickable { navigateToDetail(data) }) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.background(WableTheme.colors.white) | ||
.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) | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
feature/news/src/main/java/com/teamwable/news/notice/NewsNoticeRoute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.teamwable.news.notice | ||
|
||
import android.content.Context | ||
import android.os.Build | ||
import androidx.annotation.RequiresApi | ||
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() | ||
} | ||
} | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
@Composable | ||
fun NewsNoticeScreen( | ||
context: Context, | ||
notices: List<NewsInfoModel>, | ||
navigateToDetail: (NewsInfoModel) -> Unit | ||
) { | ||
Box(modifier = Modifier.fillMaxSize()) { | ||
LazyColumn(modifier = Modifier.fillMaxSize()) { | ||
items(notices) { notice -> | ||
NewsNoticeItem(context, notice, navigateToDetail) | ||
HorizontalDivider( | ||
thickness = 1.dp, | ||
color = WableTheme.colors.gray200, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun NewsNoticeEmptyScreen() { | ||
Box(modifier = Modifier.fillMaxSize()) { | ||
Text( | ||
modifier = Modifier.align(Alignment.Center), | ||
text = stringResource(R.string.tv_news_notice_empty), | ||
color = WableTheme.colors.gray500, | ||
style = WableTheme.typography.body02 | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:id="@+id/tv_news_detail" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="detail" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters