-
Notifications
You must be signed in to change notification settings - Fork 1
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
[FEAT/#133] 알림 화면 연결 #142
Merged
Merged
[FEAT/#133] 알림 화면 연결 #142
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
dca96b8
[fix/#132] 소셜로그인 웹뷰 disable CookieManager
blueme0 a5284e4
[feat/#133] 알림 리스트 UI 구현
blueme0 7a4d63c
[feat/#133] 마이페이지 - 푸시 알림 on/off 적용
blueme0 3176f44
[feat/#133] 알림 type 별로 화면 연결
blueme0 be6876d
[feat/#133] 알림 리스트 서버 연결
blueme0 874402b
Merge remote-tracking branch 'origin/feature/#138-card-back-add-detai…
blueme0 eae9b5c
[feat/#132] 카드 후면 연결 중
blueme0 d08ead1
[fix/#132] common dialog 취소 버튼 텍스트 색상 수정
blueme0 d5fdf95
[fix/#132] 위치 권한 액티비티 -> common dialog 적용
blueme0 a1126a5
Merge remote-tracking branch 'origin/feature/#138-card-back-add-detai…
blueme0 60acb2d
Merge remote-tracking branch 'origin/main' into feature/#132-disable-…
blueme0 c2c3c42
[fix/#132] 자기소개서 카드 interest 삭제 반영되도록
blueme0 ddbf356
[fix/#132] 소셜로그인 실패 메시지 토스트로 수정
blueme0 d7ebb59
Merge branch 'main' into feature/#133-notification-list
blueme0 dd1f80d
Merge branch 'feature/#132-disable-cookie' into feature/#133-notifica…
blueme0 0405953
[fix/#133] 충돌 해결
blueme0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
108 changes: 108 additions & 0 deletions
108
app/src/main/java/com/teumteum/teumteum/presentation/notification/AlertsListActivity.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,108 @@ | ||
package com.teumteum.teumteum.presentation.notification | ||
|
||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import androidx.core.view.isVisible | ||
import androidx.lifecycle.flowWithLifecycle | ||
import androidx.lifecycle.lifecycleScope | ||
import com.teumteum.base.BindingActivity | ||
import com.teumteum.base.component.appbar.AppBarLayout | ||
import com.teumteum.base.component.appbar.AppBarMenu | ||
import com.teumteum.base.databinding.LayoutCommonAppbarBinding | ||
import com.teumteum.base.util.extension.defaultToast | ||
import com.teumteum.domain.entity.TeumAlert | ||
import com.teumteum.teumteum.R | ||
import com.teumteum.teumteum.databinding.ActivityAlertsListBinding | ||
import com.teumteum.teumteum.presentation.group.GroupListUiState | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
|
||
@AndroidEntryPoint | ||
class AlertsListActivity | ||
: BindingActivity<ActivityAlertsListBinding>(R.layout.activity_alerts_list), AppBarLayout { | ||
|
||
private lateinit var adapter: AlertsListAdapter | ||
private val viewModel by viewModels<AlertsViewModel>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
initAppBarLayout() | ||
initList() | ||
viewModel.getAlerts() | ||
observe() | ||
} | ||
|
||
override val appBarBinding: LayoutCommonAppbarBinding | ||
get() = binding.appBar | ||
|
||
override fun initAppBarLayout() { | ||
setAppBarHeight(48) | ||
|
||
addMenuToLeft( | ||
AppBarMenu.IconStyle( | ||
resourceId = R.drawable.ic_arrow_left_l, | ||
useRippleEffect = false, | ||
clickEvent = ::finish | ||
) | ||
) | ||
setAppBarTitleText(R.string.alerts_list_title) | ||
} | ||
|
||
private fun initItems() { | ||
adapter.setItems(listOf( | ||
TeumAlert("틈 채우기", "한별님이 당신을 추천했어요!", RECOMMEND_USER, "2024-01-30T16:33:00", false), | ||
TeumAlert("틈 채우기", "한별님이 당신을 추천했어요!", RECOMMEND_USER, "2024-01-31T16:33:00", false), | ||
TeumAlert("틈 채우기", "한별님이 당신을 추천했어요!", RECOMMEND_USER, "2024-02-10T16:33:00", false), | ||
TeumAlert("틈 채우기", "한별님이 당신을 추천했어요!", RECOMMEND_USER, "2024-02-11T16:33:00", false), | ||
TeumAlert("틈 채우기", "한별님이 당신을 추천했어요!", RECOMMEND_USER, "2024-02-12T09:33:00", false), | ||
TeumAlert("틈 채우기", "한별님이 당신을 추천했어요!", RECOMMEND_USER, "2024-02-12T10:33:00", false) | ||
)) | ||
} | ||
|
||
private fun observe() { | ||
viewModel.alertsData.flowWithLifecycle(lifecycle) | ||
.onEach { | ||
binding.clEmpty.isVisible = it is AlertsListUiState.Empty | ||
binding.tvNoticeEmpty.isVisible = it !is AlertsListUiState.Empty | ||
binding.rvAlertsList.isVisible = it !is AlertsListUiState.Empty | ||
when (it) { | ||
is AlertsListUiState.SetAlerts -> { | ||
adapter.setItems(it.data) | ||
} | ||
is AlertsListUiState.Failure -> { | ||
defaultToast(it.msg) | ||
} | ||
else -> {} | ||
} | ||
}.launchIn(lifecycleScope) | ||
} | ||
|
||
private fun initList() { | ||
adapter = AlertsListAdapter { | ||
when (it.type) { | ||
// 알림 리스트에서 클릭 시 이동하는 정책이 있다면 | ||
BEFORE_MEETING -> { | ||
// 틈틈으로 이동 | ||
// openActivitySlideAnimation() | ||
} | ||
END_MEETING -> { | ||
// 해당 모임 종료 화면으로 이동 | ||
// openActivitySlideAnimation() | ||
} | ||
RECOMMEND_USER -> { | ||
// 마이페이지로 이동 | ||
// openActivitySlideAnimation() | ||
} | ||
} | ||
} | ||
binding.rvAlertsList.adapter = adapter | ||
} | ||
|
||
companion object { | ||
private const val BEFORE_MEETING = "BEFORE_MEETING" | ||
private const val END_MEETING = "END_MEETING" | ||
private const val RECOMMEND_USER = "RECOMMEND_USER" | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
app/src/main/java/com/teumteum/teumteum/presentation/notification/AlertsListAdapter.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,80 @@ | ||
package com.teumteum.teumteum.presentation.notification | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.teumteum.base.R.* | ||
import com.teumteum.base.util.extension.setOnSingleClickListener | ||
import com.teumteum.domain.entity.TeumAlert | ||
import com.teumteum.teumteum.databinding.ItemAlertsListBinding | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
class AlertsListAdapter(private val itemClick: (TeumAlert) -> (Unit)) : | ||
RecyclerView.Adapter<AlertsListAdapter.AlertsListViewHolder>() { | ||
private val alertList = mutableListOf<TeumAlert>() | ||
|
||
override fun onCreateViewHolder( | ||
parent: ViewGroup, | ||
viewType: Int | ||
): AlertsListViewHolder { | ||
val binding = ItemAlertsListBinding.inflate( | ||
LayoutInflater.from(parent.context), | ||
parent, | ||
false | ||
) | ||
return AlertsListViewHolder(binding, parent.context, itemClick) | ||
} | ||
|
||
override fun onBindViewHolder(holder: AlertsListViewHolder, position: Int) { | ||
holder.onBind(alertList[position]) | ||
} | ||
|
||
override fun getItemCount(): Int = alertList.size | ||
|
||
fun setItems(newItems: List<TeumAlert>) { | ||
alertList.clear() | ||
alertList.addAll(newItems.sortedByDescending { | ||
LocalDateTime.parse(it.createdAt, DateTimeFormatter.ISO_LOCAL_DATE_TIME) | ||
}) | ||
notifyDataSetChanged() | ||
} | ||
|
||
class AlertsListViewHolder( | ||
private val binding: ItemAlertsListBinding, | ||
private val context: Context, | ||
private val itemClick: (TeumAlert) -> (Unit) | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun onBind(item: TeumAlert) { | ||
binding.tvTitle.text = item.title | ||
binding.tvContent.text = item.body | ||
binding.tvTime.text = getTimeDifference(item.createdAt) | ||
|
||
if (!item.isRead) { | ||
binding.root.setBackgroundColor(context.getColor(color.elevation_level01)) | ||
} else { | ||
binding.root.setBackgroundColor(context.getColor(color.transparent)) | ||
} | ||
binding.root.setOnSingleClickListener { | ||
itemClick(item) | ||
} | ||
} | ||
|
||
private fun getTimeDifference(inputDateTime: String): String { | ||
val currentTime = LocalDateTime.now() | ||
val formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME | ||
val inputTime = LocalDateTime.parse(inputDateTime, formatter) | ||
|
||
val diffInMinutes = java.time.Duration.between(inputTime, currentTime).toMinutes() | ||
val diffInHours = java.time.Duration.between(inputTime, currentTime).toHours() | ||
|
||
return when { | ||
diffInMinutes < 60 -> "${diffInMinutes}분 전" | ||
diffInHours < 24 -> "${diffInHours}시간 전" | ||
else -> "${inputTime.monthValue}월 ${inputTime.dayOfMonth}일" | ||
} | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/teumteum/teumteum/presentation/notification/AlertsViewModel.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,40 @@ | ||
package com.teumteum.teumteum.presentation.notification | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.teumteum.domain.entity.TeumAlert | ||
import com.teumteum.domain.repository.UserRepository | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class AlertsViewModel @Inject constructor( | ||
private val repository: UserRepository | ||
) : ViewModel() { | ||
|
||
private val _alertsData = MutableStateFlow<AlertsListUiState>(AlertsListUiState.Init) | ||
val alertsData: StateFlow<AlertsListUiState> = _alertsData | ||
|
||
fun getAlerts() { | ||
viewModelScope.launch { | ||
repository.getAlerts() | ||
.onSuccess { | ||
if (it.alerts.isEmpty()) _alertsData.value = AlertsListUiState.Empty | ||
else _alertsData.value = AlertsListUiState.SetAlerts(it.alerts) | ||
} | ||
.onFailure { | ||
_alertsData.value = AlertsListUiState.Failure("알림 가져오기 실패") | ||
} | ||
} | ||
} | ||
} | ||
|
||
sealed interface AlertsListUiState { | ||
object Init : AlertsListUiState | ||
object Empty : AlertsListUiState | ||
data class SetAlerts(val data: List<TeumAlert>) : AlertsListUiState | ||
data class Failure(val msg: String) : AlertsListUiState | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기 변동 확인했슴다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
감삼당 ~~~👍🏻👍🏻