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

내 계정 화면 내에 세부 화면 구성 #100

Merged
merged 13 commits into from
Sep 15, 2023
Merged
Prev Previous commit
Next Next commit
공지사항 화면 구성 및 네비게이션 플로우 구현
notice 와 notice card 를 분리
easyhooon committed Sep 11, 2023
commit 84889976f1dcd4adbadb66e594ab02e85178821d
Original file line number Diff line number Diff line change
@@ -16,20 +16,13 @@ import us.wedemy.eggeum.android.main.ui.item.NoticeItem

class NoticeAdapter(
private var noticeList: List<NoticeItem> = emptyList(),
private val clickListener: (Int) -> Unit,
) : RecyclerView.Adapter<NoticeViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
NoticeViewHolder(ItemNoticeBinding.inflate(parent.context.layoutInflater, parent, false))

override fun onBindViewHolder(holder: NoticeViewHolder, position: Int) {
val notice = noticeList[position]
with(holder) {
bind(notice)
binding.root.setOnClickListener {
clickListener(bindingAdapterPosition)
}
}
holder.bind(notice)
}

override fun getItemCount() = noticeList.size
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Designed and developed by Wedemy 2023.
*
* Licensed under the MIT.
* Please see full license: https://github.com/Wedemy/eggeum-android/blob/main/LICENSE
*/

package us.wedemy.eggeum.android.main.ui.adapter

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import us.wedemy.eggeum.android.common.extension.layoutInflater
import us.wedemy.eggeum.android.main.databinding.ItemNoticeCardBinding
import us.wedemy.eggeum.android.main.ui.adapter.viewholder.NoticeCardViewHolder
import us.wedemy.eggeum.android.main.ui.item.NoticeCardItem

class NoticeCardAdapter(
private var noticeList: List<NoticeCardItem> = emptyList(),
private val clickListener: (Int) -> Unit,
) : RecyclerView.Adapter<NoticeCardViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
NoticeCardViewHolder(ItemNoticeCardBinding.inflate(parent.context.layoutInflater, parent, false))

override fun onBindViewHolder(holder: NoticeCardViewHolder, position: Int) {
val notice = noticeList[position]
with(holder) {
bind(notice)
binding.root.setOnClickListener {
clickListener(bindingAdapterPosition)
}
}
}

override fun getItemCount() = noticeList.size
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Designed and developed by Wedemy 2023.
*
* Licensed under the MIT.
* Please see full license: https://github.com/Wedemy/eggeum-android/blob/main/LICENSE
*/

package us.wedemy.eggeum.android.main.ui.adapter.viewholder

import androidx.recyclerview.widget.RecyclerView
import us.wedemy.eggeum.android.main.databinding.ItemNoticeCardBinding
import us.wedemy.eggeum.android.main.ui.item.NoticeCardItem

class NoticeCardViewHolder(val binding: ItemNoticeCardBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(notice: NoticeCardItem) {
binding.tvHomeNoticeTitle.text = notice.title
binding.tvNotificationDate.text = notice.date
}
}
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import us.wedemy.eggeum.android.main.ui.item.NoticeItem

class NoticeViewHolder(val binding: ItemNoticeBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(notice: NoticeItem) {
binding.tvHomeNoticeTitle.text = notice.title
binding.tvNotificationDate.text = notice.date
"[공지] ${notice.title}".also { binding.tvNoticeTitle.text = it }
// binding.tvNoticeContent.text = notice.content
}
}
Original file line number Diff line number Diff line change
@@ -15,16 +15,16 @@ import us.wedemy.eggeum.android.common.ui.BaseFragment
import us.wedemy.eggeum.android.common.extension.addDivider
import us.wedemy.eggeum.android.main.databinding.FragmentHomeBinding
import us.wedemy.eggeum.android.main.ui.adapter.NewCafeAdapter
import us.wedemy.eggeum.android.main.ui.adapter.NoticeAdapter
import us.wedemy.eggeum.android.main.ui.adapter.NoticeCardAdapter
import us.wedemy.eggeum.android.main.ui.item.NewCafeItem
import us.wedemy.eggeum.android.main.ui.item.NoticeItem
import us.wedemy.eggeum.android.main.ui.item.NoticeCardItem

@AndroidEntryPoint
class HomeFragment : BaseFragment<FragmentHomeBinding>() {
override fun getViewBinding() = FragmentHomeBinding.inflate(layoutInflater)

private lateinit var newCafeAdapter: NewCafeAdapter
private lateinit var noticeAdapter: NoticeAdapter
private lateinit var noticeAdapter: NoticeCardAdapter

private val newCafes = listOf(
NewCafeItem("스타벅스 강남역신분당역사점", "서울특별시 강남구 강남대로 396"),
@@ -43,12 +43,12 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
)

private val notices = listOf(
NoticeItem("공부하기 좋은 카페 찾는 법", "23.03.01"),
NoticeItem("카페 평가하는 법", "23.03.01"),
NoticeItem("일이삼사오육칠팔구십일이삼사오육", "23.03.01"),
NoticeItem("공부하기 좋은 카페 찾는 법", "23.03.01"),
NoticeItem("카페 평가하는 법", "23.03.01"),
NoticeItem("일이삼사오육칠팔구십일이삼사오육", "23.03.01"),
NoticeCardItem("공부하기 좋은 카페 찾는 법", "23.03.01"),
NoticeCardItem("카페 평가하는 법", "23.03.01"),
NoticeCardItem("일이삼사오육칠팔구십일이삼사오육", "23.03.01"),
NoticeCardItem("공부하기 좋은 카페 찾는 법", "23.03.01"),
NoticeCardItem("카페 평가하는 법", "23.03.01"),
NoticeCardItem("일이삼사오육칠팔구십일이삼사오육", "23.03.01"),
)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@@ -60,10 +60,10 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {

private fun initView() {
newCafeAdapter = NewCafeAdapter(newCafes) { _ -> run {} }
noticeAdapter = NoticeAdapter(notices) { _ -> run {} }
noticeAdapter = NoticeCardAdapter(notices) { _ -> run {} }
with(binding) {
newCafeAdapter = NewCafeAdapter(newCafes) { _ -> run {} }
noticeAdapter = NoticeAdapter(notices) { _ -> run {} }
noticeAdapter = NoticeCardAdapter(notices) { _ -> run {} }

rvHomeNewCafe.apply {
setHasFixedSize(true)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Designed and developed by Wedemy 2023.
*
* Licensed under the MIT.
* Please see full license: https://github.com/Wedemy/eggeum-android/blob/main/LICENSE
*/

package us.wedemy.eggeum.android.main.ui.item

data class NoticeCardItem(
val title: String,
val date: String,
)
Original file line number Diff line number Diff line change
@@ -9,5 +9,5 @@ package us.wedemy.eggeum.android.main.ui.item

data class NoticeItem(
val title: String,
val date: String,
val content: String,
)
Original file line number Diff line number Diff line change
@@ -36,6 +36,11 @@ class MyAccountFragment : BaseFragment<FragmentMyAccountBinding>() {
val action = MyAccountFragmentDirections.actionFragmentMyAccountToFragmentInquiry()
findNavController().safeNavigate(action)
}

clMyAccountNotice.setOnClickListener {
val action = MyAccountFragmentDirections.actionFragmentMyAccountToFragmentNotice()
findNavController().safeNavigate(action)
}
}
}

Original file line number Diff line number Diff line change
@@ -7,11 +7,80 @@

package us.wedemy.eggeum.android.main.ui.myaccount

import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import us.wedemy.eggeum.android.common.extension.addDivider
import us.wedemy.eggeum.android.common.extension.repeatOnStarted
import us.wedemy.eggeum.android.common.extension.textChangesAsFlow
import us.wedemy.eggeum.android.common.ui.BaseFragment
import us.wedemy.eggeum.android.main.databinding.FragmentNoticeBinding
import us.wedemy.eggeum.android.main.ui.adapter.NoticeAdapter
import us.wedemy.eggeum.android.main.ui.item.NoticeItem
import us.wedemy.eggeum.android.main.viewmodel.NoticeViewModel

@AndroidEntryPoint
class NoticeFragment : BaseFragment<FragmentNoticeBinding>() {
override fun getViewBinding() = FragmentNoticeBinding.inflate(layoutInflater)

private val viewModel by viewModels<NoticeViewModel>()

private lateinit var noticeAdapter: NoticeAdapter

private val notices = listOf(
NoticeItem("공부하기 좋은 카페 찾는 법", "공지 내용"),
NoticeItem("카페 평가하는 법", "공지 내용"),
NoticeItem("일이삼사오육칠팔구십일이삼사오육", "공지 내용"),
NoticeItem("공부하기 좋은 카페 찾는 법", "공지 내용"),
NoticeItem("카페 평가하는 법", "공지 내용"),
NoticeItem("일이삼사오육칠팔구십일이삼사오육", "공지 내용"),
)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initView()
initListener()
initObserver()
}

private fun initView() {
noticeAdapter = NoticeAdapter(notices)

binding.rvNotice.apply {
setHasFixedSize(true)
adapter = noticeAdapter
addDivider(us.wedemy.eggeum.android.design.R.color.gray_300)
}
}

private fun initListener() {
with(binding) {
tbNotice.setNavigationOnClickListener {
if (!findNavController().navigateUp()) {
requireActivity().finish()
}
}
}
}

private fun initObserver() {
repeatOnStarted {
launch {
val searchKeywordEditTextFlow = binding.tietNotice.textChangesAsFlow()
searchKeywordEditTextFlow.collect { text ->
val searchKeyword = text.toString().trim()
viewModel.setSearchKeyword(searchKeyword)
}
}

launch {
viewModel.searchKeyword.collect {
// TODO searchKeyword 를 통한 공지사항 리스트 필터링 구현
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Designed and developed by Wedemy 2023.
*
* Licensed under the MIT.
* Please see full license: https://github.com/Wedemy/eggeum-android/blob/main/LICENSE
*/

package us.wedemy.eggeum.android.main.viewmodel

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import us.wedemy.eggeum.android.common.util.getMutableStateFlow

@HiltViewModel
class NoticeViewModel @Inject constructor(savedStateHandle: SavedStateHandle) : ViewModel() {
private val _searchKeyword = savedStateHandle.getMutableStateFlow(KEY_SEARCH_KEYWORD, "")
val searchKeyword = _searchKeyword.asStateFlow()

init {
getNoticeList()
}

private fun getNoticeList() {
// TODO 공지사항 리스트 조회 구현
}

fun setSearchKeyword(searchKeyword: String) {
_searchKeyword.value = searchKeyword
}

private companion object {
private const val KEY_SEARCH_KEYWORD = "search_keyword"
}
}
2 changes: 1 addition & 1 deletion main/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
@@ -111,7 +111,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_home_notice_title"
tools:listitem="@layout/item_notice" />
tools:listitem="@layout/item_notice_card" />

<View
android:layout_width="0dp"
4 changes: 2 additions & 2 deletions main/src/main/res/layout/fragment_my_account.xml
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@
app:layout_constraintTop_toBottomOf="@id/tv_my_account_email">

<ImageView
android:id="@+id/iv_my_account_notice_icon"
android:id="@+id/iv_notice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
@@ -143,7 +143,7 @@
android:textColor="@color/gray_700"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_my_account_notice_icon" />
app:layout_constraintTop_toBottomOf="@id/iv_notice" />

</androidx.constraintlayout.widget.ConstraintLayout>

67 changes: 67 additions & 0 deletions main/src/main/res/layout/fragment_notice.xml
Original file line number Diff line number Diff line change
@@ -6,7 +6,74 @@
-->

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/tb_notice"
style="@style/Widget.Eggeum.Toolbar.WithArrow"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:elevation="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

</com.google.android.material.appbar.MaterialToolbar>

<TextView
android:id="@+id/tv_notice_title"
style="@style/H5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="@string/notice"
android:textColor="@color/gray_900"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tb_notice" />

<androidx.cardview.widget.CardView
android:id="@+id/cv_notice"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp"
android:elevation="8dp"
app:cardCornerRadius="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_notice_title">

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_notice"
style="@style/Widget.Eggeum.TextInputLayout.SearchBox"
app:boxStrokeColor="@drawable/selector_box_stroke_color_white"
app:startIconDrawable="@drawable/ic_left_arrow_outlined_16">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tiet_notice"
style="@style/Widget.Eggeum.TextInputEditText.OutlinedBox"
android:ellipsize="end"
android:hint="@string/search_keyword"
android:inputType="text"
android:maxLines="1" />

</com.google.android.material.textfield.TextInputLayout>

</androidx.cardview.widget.CardView>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_notice"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cv_notice"
tools:listitem="@layout/item_notice" />

</androidx.constraintlayout.widget.ConstraintLayout>
Loading