This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
๐ก FCM ํ์คํ ๋ฆฌ ์กฐํ ๊ธฐ๋ฅ (#108)
* [feat] ์๋ฆผ ํ์ด์ง view * [feat] ์๋ฆผ ํ์ด์ง api ์์
- Loading branch information
1 parent
404a8b4
commit 1a3b434
Showing
19 changed files
with
348 additions
and
12 deletions.
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
6 changes: 6 additions & 0 deletions
6
Nabi/data/src/main/java/com/nabi/data/model/notification/NotificationResponseDTO.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,6 @@ | ||
package com.nabi.data.model.notification | ||
|
||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
class NotificationResponseDTO : ArrayList<NotificationResponseDTOItem>() |
13 changes: 13 additions & 0 deletions
13
Nabi/data/src/main/java/com/nabi/data/model/notification/NotificationResponseDTOItem.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,13 @@ | ||
package com.nabi.data.model.notification | ||
|
||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class NotificationResponseDTOItem( | ||
@SerializedName("body") | ||
val body: String, | ||
@SerializedName("createdAt") | ||
val createdAt: String, | ||
@SerializedName("title") | ||
val title: String | ||
) |
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
5 changes: 5 additions & 0 deletions
5
Nabi/domain/src/main/java/com/nabi/domain/model/notification/NotificationInfo.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,5 @@ | ||
package com.nabi.domain.model.notification | ||
|
||
data class NotificationInfo( | ||
val contents: String | ||
) |
3 changes: 3 additions & 0 deletions
3
Nabi/domain/src/main/java/com/nabi/domain/repository/NotificationRepository.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,5 +1,8 @@ | ||
package com.nabi.domain.repository | ||
|
||
interface NotificationRepository { | ||
|
||
suspend fun getNotification(accessToken: String): Result<List<String>> | ||
|
||
suspend fun registerFcmToken(accessToken: String, fcmToken: String): Result<String> | ||
} |
9 changes: 9 additions & 0 deletions
9
Nabi/domain/src/main/java/com/nabi/domain/usecase/notification/GetNotificationUseCase.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,9 @@ | ||
package com.nabi.domain.usecase.notification | ||
|
||
import com.nabi.domain.repository.NotificationRepository | ||
|
||
class GetNotificationUseCase(private val repository: NotificationRepository) { | ||
suspend operator fun invoke(accessToken: String): Result<List<String>> { | ||
return repository.getNotification("Bearer $accessToken") | ||
} | ||
} |
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
12 changes: 0 additions & 12 deletions
12
Nabi/presentation/src/main/java/com/nabi/nabi/views/home/NotifyFragment.kt
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
Nabi/presentation/src/main/java/com/nabi/nabi/views/notification/NotificationAdapter.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.nabi.nabi.views.notification | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.nabi.nabi.databinding.ItemFcmNotifyBinding | ||
|
||
class NotificationAdapter : RecyclerView.Adapter<NotificationAdapter.ActivityViewHolder>() { | ||
private var notifyList: List<String> = mutableListOf() | ||
|
||
inner class ActivityViewHolder(val binding: ItemFcmNotifyBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun bind(content: String) { | ||
binding.tvFcmContent.text = content | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder( | ||
parent: ViewGroup, | ||
viewType: Int | ||
): ActivityViewHolder { | ||
val binding = | ||
ItemFcmNotifyBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
return ActivityViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ActivityViewHolder, position: Int) { | ||
holder.bind(notifyList[position]) | ||
} | ||
|
||
override fun getItemCount(): Int = notifyList.size | ||
|
||
@SuppressLint("NotifyDataSetChanged") | ||
fun setData(newList: List<String>) { | ||
notifyList = newList | ||
notifyDataSetChanged() | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
Nabi/presentation/src/main/java/com/nabi/nabi/views/notification/NotificationViewModel.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.nabi.nabi.views.notification | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.nabi.domain.usecase.datastore.GetAccessTokenUseCase | ||
import com.nabi.domain.usecase.notification.GetNotificationUseCase | ||
import com.nabi.nabi.utils.UiState | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class NotificationViewModel @Inject constructor( | ||
private val getNotificationUseCase: GetNotificationUseCase, | ||
private val getAccessTokenUseCase: GetAccessTokenUseCase | ||
) : ViewModel() { | ||
|
||
private val _notifyState = MutableLiveData<UiState<List<String>>>(UiState.Loading) | ||
val notifyState: LiveData<UiState<List<String>>> get() = _notifyState | ||
|
||
fun fetchData() { | ||
_notifyState.value = UiState.Loading | ||
|
||
viewModelScope.launch { | ||
val accessTokenResult = getAccessTokenUseCase.invoke() | ||
|
||
if (accessTokenResult.isSuccess) { | ||
val accessToken = accessTokenResult.getOrNull().orEmpty() | ||
|
||
getNotificationUseCase(accessToken).onSuccess { | ||
_notifyState.value = UiState.Success(it) | ||
}.onFailure { e -> | ||
_notifyState.value = UiState.Failure(message = e.message.toString()) | ||
} | ||
} else { | ||
_notifyState.value = UiState.Failure(message = "Failed to get Notification List") | ||
} | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
Nabi/presentation/src/main/java/com/nabi/nabi/views/notification/NotifyFragment.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,60 @@ | ||
package com.nabi.nabi.views.notification | ||
|
||
import androidx.core.content.ContextCompat | ||
import androidx.fragment.app.viewModels | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.nabi.nabi.R | ||
import com.nabi.nabi.base.BaseFragment | ||
import com.nabi.nabi.custom.CustomDecoration | ||
import com.nabi.nabi.databinding.FragmentNotifyBinding | ||
import com.nabi.nabi.utils.LoggerUtils | ||
import com.nabi.nabi.utils.UiState | ||
import com.nabi.nabi.views.MainActivity | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class NotifyFragment : BaseFragment<FragmentNotifyBinding>(R.layout.fragment_notify) { | ||
private lateinit var notificationAdapter: NotificationAdapter | ||
private val viewModel: NotificationViewModel by viewModels() | ||
|
||
override fun initView() { | ||
(requireActivity() as MainActivity).setStatusBarColor(R.color.white, false) | ||
|
||
viewModel.fetchData() | ||
setNotificationRv() | ||
} | ||
|
||
private fun setNotificationRv() { | ||
notificationAdapter = NotificationAdapter() | ||
|
||
binding.rvFcmNotify.apply { | ||
adapter = notificationAdapter | ||
layoutManager = | ||
LinearLayoutManager(requireContext()) | ||
addItemDecoration( | ||
CustomDecoration( | ||
0.5f, | ||
ContextCompat.getColor(requireContext(), R.color.gray2) | ||
) | ||
) | ||
} | ||
} | ||
|
||
override fun setObserver() { | ||
super.setObserver() | ||
|
||
viewModel.notifyState.observe(this) { | ||
when (it) { | ||
is UiState.Loading -> {} | ||
is UiState.Failure -> { | ||
showToast(it.message) | ||
LoggerUtils.e("์๋ฆผ ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐ ์คํจ: ${it.message}") | ||
} | ||
|
||
is UiState.Success -> { | ||
notificationAdapter.setData(it.data) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.