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

DEP-197 feat: 알림 페이지 UI 구현 #61

Merged
merged 10 commits into from
Dec 10, 2022
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
implementation(project(":presentation:home"))
implementation(project(":presentation:create"))
implementation(project(":presentation:history"))
implementation(project(":presentation:notification"))

implementation(jetpackDeps)
implementation(coroutines)
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@
<activity
android:name="com.depromeet.threedays.create.update.HabitUpdateActivity"
android:exported="false"/>

<activity
android:name="com.depromeet.threedays.history.detail.DetailHistoryActivity"
android:exported="false"/>

<activity
android:name="com.depromeet.threedays.notification.NotificationActivity"
android:exported="false"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid android:color="@color/gray_600" />
<corners android:radius="10dp" />

</shape>
13 changes: 13 additions & 0 deletions core-design-system/src/main/res/drawable/ic_notibox.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="30dp"
android:height="20dp"
android:viewportWidth="30"
android:viewportHeight="20">
<path
android:pathData="M1,9H9C9,9 10,14 15,14C20,14 21,9 21,9H29M1,9V19H29V9L25,1H5L1,9Z"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#C4CAD4"
android:strokeLineCap="round"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.depromeet.threedays.data.datasource.notification

import com.depromeet.threedays.data.entity.HabitEntity
import com.depromeet.threedays.data.entity.notification.NotificationEntity

interface NotificationRemoteDataSource {
suspend fun setNotificationAsRead(notificationEntity: NotificationEntity)
suspend fun getNotifications(): List<NotificationEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.depromeet.threedays.data.datasource.notification

import com.depromeet.threedays.data.entity.notification.NotificationEntity
import javax.inject.Inject

class NotificationRemoteDataSourceImpl @Inject constructor() : NotificationRemoteDataSource {
override suspend fun setNotificationAsRead(notificationEntity: NotificationEntity) {
TODO("Not yet implemented")
}

override suspend fun getNotifications(): List<NotificationEntity> {
return emptyList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.depromeet.threedays.data.di

import com.depromeet.threedays.data.datasource.habit.HabitRemoteDataSource
import com.depromeet.threedays.data.datasource.habit.HabitRemoteDataSourceImpl
import com.depromeet.threedays.data.datasource.notification.NotificationRemoteDataSource
import com.depromeet.threedays.data.datasource.notification.NotificationRemoteDataSourceImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -17,4 +19,10 @@ internal abstract class RemoteModule {
abstract fun bindHabitRemoteDataSource(
dataSource: HabitRemoteDataSourceImpl
): HabitRemoteDataSource

@Binds
@Singleton
abstract fun bindNotificationRemoteDataSource(
dataSource: NotificationRemoteDataSourceImpl
): NotificationRemoteDataSource
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.depromeet.threedays.data.di

import com.depromeet.threedays.data.repository.HabitRepositoryImpl
import com.depromeet.threedays.data.repository.NotificationRepositoryImpl
import com.depromeet.threedays.domain.repository.HabitRepository
import com.depromeet.threedays.domain.repository.NotificationRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -17,4 +19,10 @@ abstract class RepositoryModule {
abstract fun bindsHabitRepository(
repository: HabitRepositoryImpl
): HabitRepository

@Binds
@Singleton
abstract fun bindsNotificationRepository(
repository: NotificationRepositoryImpl
): NotificationRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.depromeet.threedays.data.entity.notification

/**
* 서버 응답에 맞추기
*/
data class NotificationEntity(
val notificationId: Long,
val title: String,
val content: String,
val isRead: Boolean,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.depromeet.threedays.data.mapper

import com.depromeet.threedays.data.entity.notification.NotificationEntity
import com.depromeet.threedays.domain.entity.notification.Notification

fun NotificationEntity.toNotification() = Notification(
this.notificationId,
this.title,
this.content,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.depromeet.threedays.data.repository

import com.depromeet.threedays.domain.entity.DataState
import com.depromeet.threedays.domain.entity.notification.Notification
import com.depromeet.threedays.domain.repository.NotificationRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class NotificationRepositoryImpl @Inject constructor(): NotificationRepository {
override suspend fun getNotifications(): Flow<DataState<List<Notification>>> {
// TODO: api 한테 목록 받아와서
// mapper 한테 넘기고
// 리턴
return flow {
emit(
DataState.success(
listOf(
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
).map {
Notification(
it,
"짝심삼일 소식",
"기다리고 기다리던 짝심삼일 ver.2가 출시되었습니다. 업데이트해보세요!",
)
}
)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.depromeet.threedays.domain.entity.notification

data class Notification (
val notificationId: Int,
val notificationTime: String,
val contents: String,
val notificationId: Long,
val title: String,
val content: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.depromeet.threedays.domain.repository

import com.depromeet.threedays.domain.entity.DataState
import com.depromeet.threedays.domain.entity.notification.Notification
import kotlinx.coroutines.flow.Flow

interface NotificationRepository {
suspend fun getNotifications(): Flow<DataState<List<Notification>>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.depromeet.threedays.domain.usecase

import com.depromeet.threedays.domain.entity.DataState
import com.depromeet.threedays.domain.entity.notification.Notification
import com.depromeet.threedays.domain.repository.NotificationRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class GetNotificationsUseCase @Inject constructor(
private val notificationRepository: NotificationRepository,
) {
suspend operator fun invoke(): Flow<DataState<List<Notification>>> {
return notificationRepository.getNotifications()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.depromeet.threedays.navigator

interface NotificationNavigator : Navigator {
}
1 change: 1 addition & 0 deletions presentation/home/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies {
implementation(project(":presentation:history"))
implementation(project(":presentation:mate"))
implementation(project(":presentation:mypage"))
implementation(project(":presentation:notification"))

implementation(jetpackDeps)
implementation(coroutines)
Expand Down
2 changes: 1 addition & 1 deletion presentation/home/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.depromeet.threedays.home"/>
package="com.depromeet.threedays.home"/>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.depromeet.threedays.home.R
import com.depromeet.threedays.home.databinding.FragmentHomeBinding
import com.depromeet.threedays.navigator.GoalAddNavigator
import com.depromeet.threedays.navigator.GoalUpdateNavigator
import com.depromeet.threedays.navigator.NotificationNavigator
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import java.time.ZoneId
Expand All @@ -34,6 +35,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(R.layout.f
@Inject
lateinit var goalUpdateNavigator: GoalUpdateNavigator

@Inject
lateinit var notificationNavigator: NotificationNavigator

private val addResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->

when(result.resultCode) {
Expand All @@ -55,6 +59,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(R.layout.f
viewModel.fetchGoals()
viewModel.setObserve()
initView()
initEvent()
}

private fun onGoalClick(habitId: Int) {
Expand Down Expand Up @@ -83,6 +88,11 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(R.layout.f
dialog.show()
}

private fun onNotificationClick() {
val intent = notificationNavigator.intent(requireContext())
addResultLauncher.launch(intent)
}

private fun onDeleteConfirmClick(habitId: Int) {
// viewModel.deleteGoals(habit.goalId)
// viewModel.fetchGoals()
Expand Down Expand Up @@ -117,6 +127,12 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(R.layout.f
binding.tvDate.text = String.format("%02d월%02d일 %s요일", now.monthValue, now.dayOfMonth, dayOfWeekList[now.dayOfWeek.value - 1])
}

private fun initEvent() {
binding.ivNotification.setOnClickListener {
onNotificationClick()
}
}

private fun HomeViewModel.setObserve() {
lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
Expand Down
1 change: 1 addition & 0 deletions presentation/home/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
tools:text="10월19일 목요일" />

<ImageView
android:id="@+id/iv_notification"
android:layout_width="24dp"
android:layout_height="24dp"
app:srcCompat="@drawable/ic_noti_default"
Expand Down
1 change: 1 addition & 0 deletions presentation/notification/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
52 changes: 52 additions & 0 deletions presentation/notification/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id "kotlin-kapt"
id 'dagger.hilt.android.plugin'
}

android {
namespace 'com.depromeet.threedays.notification'
compileSdk 33

defaultConfig {
minSdk 26
targetSdk 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
dataBinding true
}
}

dependencies {
implementation(project(":core"))
implementation(project(":core-design-system"))
implementation(project(":navigator"))
implementation(project(":domain"))

implementation(jetpackDeps)
implementation(coroutines)

implementation deps.hilt.core
kapt deps.hilt.compiler

testImplementation(testDeps)
androidTestImplementation(androidTestDeps)
}
Empty file.
21 changes: 21 additions & 0 deletions presentation/notification/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
7 changes: 7 additions & 0 deletions presentation/notification/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.depromeet.threedays.notification">



</manifest>
Loading