Skip to content

Commit

Permalink
Merge pull request #173 from hellokitty-coding-club/feat/indicate-new…
Browse files Browse the repository at this point in the history
…-noti

[FEAT] Home 화면 안읽은 알림 있을 시 초록색 점 표시 (#172)
  • Loading branch information
KxxHyoRim authored Nov 7, 2023
2 parents 5be7dce + 46ff1f5 commit 6e8535c
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lgtm.android.data.datasource

import com.lgtm.android.data.model.response.BaseDTO
import com.lgtm.android.data.model.response.HasNotificationDTO
import com.lgtm.android.data.model.response.NotificationDTO
import com.lgtm.android.data.service.NotificationService
import javax.inject.Inject
Expand All @@ -11,4 +12,8 @@ class NotificationDatasource @Inject constructor(
suspend fun getNotificationList(): BaseDTO<List<NotificationDTO>> {
return checkResponse(notificationService.getNotificationList())
}

suspend fun hasNewNotification(): BaseDTO<HasNotificationDTO> {
return checkResponse(notificationService.hasNewNotification())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lgtm.android.data.model.response

data class HasNotificationDTO(
val hasNewNotification: Boolean?
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ class NotificationRepositoryImpl @Inject constructor(
Result.failure(e)
}
}

override suspend fun hasNewNotification(): Result<Boolean> {
return try {
val response = notificationDatasource.hasNewNotification()
Result.success(response.data.hasNewNotification ?: false)
} catch (e: Exception) {
Result.failure(e)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lgtm.android.data.service

import com.lgtm.android.data.model.response.BaseDTO
import com.lgtm.android.data.model.response.HasNotificationDTO
import com.lgtm.android.data.model.response.NotificationDTO
import retrofit2.Response
import retrofit2.http.GET
Expand All @@ -9,4 +10,7 @@ interface NotificationService {

@GET("v1/notification")
suspend fun getNotificationList(): Response<BaseDTO<List<NotificationDTO>>>

@GET("v1/notification/new")
suspend fun hasNewNotification(): Response<BaseDTO<HasNotificationDTO>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import com.lgtm.domain.entity.response.NotificationVO

interface NotificationRepository {
suspend fun getNotificationList(): Result<List<NotificationVO>>
suspend fun hasNewNotification(): Result<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,33 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
setUpNotificationClickListener()
onClickNewMissionButton()
onClickServiceGuideButton()
observeNewNotification()
}

override fun onResume() {
super.onResume()
getHomeInfo()
checkNewNotification()
}

private fun getHomeInfo() {
homeViewModel.getHomeInfo()
}

private fun checkNewNotification() {
homeViewModel.hasNewNotification()
}

private fun observeNewNotification() {
homeViewModel.hasNewNotification.observe(viewLifecycleOwner) {
if (it == true) {
binding.ivNewNotification.visibility = View.VISIBLE
} else {
binding.ivNewNotification.visibility = View.GONE
}
}
}

private fun setupViewModel() {
binding.viewModel = homeViewModel
}
Expand All @@ -59,7 +75,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
lgtmNavigator.navigateToMissionDetail(requireContext(), missionId)
}

private fun moveToNotificationCenter(){
private fun moveToNotificationCenter() {
lgtmNavigator.navigateToNotificationCenter(requireContext())
}

Expand All @@ -76,10 +92,10 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
}
}

private fun onClickServiceGuideButton(){
private fun onClickServiceGuideButton() {
val role = homeViewModel.getUserRole()
binding.ivServiceGuide.setOnThrottleClickListener {
val url =when(role){
val url = when (role) {
Role.REVIEWER -> "https://www.notion.so/team-hkcc/c1933575315e4b50aedbdd6b39069d3e?pvs=4"
Role.REVIEWEE -> "https://www.notion.so/team-hkcc/5abf8b03763a4f0d90cb2d463f6d46b4?pvs=4"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.lgtm.domain.entity.response.SduiItemVO
import com.lgtm.domain.logging.HomeScreenClickScheme
import com.lgtm.domain.logging.HomeScreenExposureScheme
import com.lgtm.domain.repository.AuthRepository
import com.lgtm.domain.repository.NotificationRepository
import com.lgtm.domain.usecase.MissionUseCase
import com.swm.logging.android.SWMLogging
import com.swm.logging.android.logging_scheme.ClickScheme
Expand All @@ -22,7 +23,8 @@ import javax.inject.Inject
@HiltViewModel
class HomeViewModel @Inject constructor(
private val useCase: MissionUseCase,
authRepository: AuthRepository
private val notificationRepository: NotificationRepository,
authRepository: AuthRepository,
) : BaseViewModel() {

private val role = authRepository.getMemberType()
Expand All @@ -43,6 +45,21 @@ class HomeViewModel @Inject constructor(
}


private val _hasNewNotification = MutableLiveData<Boolean>()
val hasNewNotification: LiveData<Boolean> = _hasNewNotification

fun hasNewNotification() {
viewModelScope.launch(lgtmErrorHandler) {
notificationRepository.hasNewNotification()
.onSuccess {
_hasNewNotification.postValue(it)
}.onFailure {
Log.e(TAG, "hasNewNotification: ${it.message}")
}
}
}


fun shotHomeExposureLogging() {
val scheme = getHomeExposureLoggingScheme()
SWMLogging.logEvent(scheme)
Expand Down
12 changes: 12 additions & 0 deletions feature/main/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_new_notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:src="@drawable/oval_diameter_9_green"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="@id/iv_notification"
app:layout_constraintTop_toTopOf="@id/iv_notification"
tools:visibility="visible" />


<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_service_guide"
Expand Down

0 comments on commit 6e8535c

Please sign in to comment.