-
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.
- Loading branch information
Showing
9 changed files
with
231 additions
and
110 deletions.
There are no files selected for viewing
5 changes: 2 additions & 3 deletions
5
app/src/main/java/com/wafflestudio/snutt2/data/notifications/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,12 +1,11 @@ | ||
package com.wafflestudio.snutt2.data.notifications | ||
|
||
import androidx.paging.PagingData | ||
import com.wafflestudio.snutt2.lib.network.dto.core.NotificationDto | ||
import com.wafflestudio.snutt2.domainmodel.Notification | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface NotificationRepository { | ||
|
||
suspend fun getNotificationResultStream(): Flow<PagingData<NotificationDto>> | ||
fun getNotificationListStream(): Flow<PagingData<Notification>> | ||
|
||
suspend fun getNotificationCount(): Long | ||
} |
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
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/wafflestudio/snutt2/domainmodel/Notification.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,39 @@ | ||
package com.wafflestudio.snutt2.domainmodel | ||
|
||
import com.wafflestudio.snutt2.lib.data.SNUTTStringUtils | ||
import com.wafflestudio.snutt2.lib.network.dto.core.NotificationDto | ||
import java.util.Date | ||
|
||
data class Notification( | ||
val title: String, | ||
val message: String, | ||
val createdAt: Date, | ||
val type: NotificationType, | ||
val deeplink: String?, | ||
) | ||
|
||
enum class NotificationType { | ||
Warning, | ||
Calendar, | ||
RefreshTime, | ||
Trash, | ||
Vacancy, | ||
Friend, | ||
Megaphone, | ||
} | ||
|
||
fun NotificationDto.domainModel() = Notification( | ||
title = title, | ||
message = message, | ||
createdAt = SNUTTStringUtils.getDateFromString(createdAt), | ||
type = when (type) { | ||
0 -> NotificationType.Warning | ||
1 -> NotificationType.Calendar | ||
2 -> NotificationType.RefreshTime | ||
3 -> NotificationType.Trash | ||
4 -> NotificationType.Vacancy | ||
5 -> NotificationType.Friend | ||
else -> NotificationType.Megaphone | ||
}, | ||
deeplink = deeplink, | ||
) |
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/wafflestudio/snutt2/lib/data/DateFormatter.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,33 @@ | ||
package com.wafflestudio.snutt2.lib.data | ||
|
||
import java.text.SimpleDateFormat | ||
import java.util.Date | ||
import java.util.Locale | ||
|
||
object DateFormatter { | ||
// Full Pattern: 서버 응답 형태로, ms 단위까지 표현되어 있는 패턴 | ||
private const val FULLPATTERN: String = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" | ||
|
||
private val threadLocalFullFormatter = object : ThreadLocal<SimpleDateFormat>() { | ||
override fun initialValue(): SimpleDateFormat { | ||
return SimpleDateFormat(FULLPATTERN, Locale.getDefault()) | ||
} | ||
} | ||
|
||
fun parseFull(dateString: String): Date { | ||
return threadLocalFullFormatter.get()?.parse(dateString) ?: Date() | ||
} | ||
|
||
// Date Pattern: UI 표현 중 하나로, 날짜만 표기되어 있는 패턴 | ||
private const val DATEPATTERN: String = "yyyy/MM/dd" | ||
|
||
private val threadLocalDateFormatter = object : ThreadLocal<SimpleDateFormat>() { | ||
override fun initialValue(): SimpleDateFormat { | ||
return SimpleDateFormat(DATEPATTERN, Locale.getDefault()) | ||
} | ||
} | ||
|
||
fun formatDate(date: Date): String { | ||
return threadLocalDateFormatter.get()?.format(date) ?: "" | ||
} | ||
} |
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
Oops, something went wrong.