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-198 마이페이지 ui 적용 #73

Merged
merged 14 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies {
implementation(project(":presentation:create"))
implementation(project(":presentation:history"))
implementation(project(":presentation:notification"))
implementation(project(":presentation:mypage"))

implementation(jetpackDeps)
implementation(coroutines)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<activity
android:name="com.depromeet.threedays.notification.NotificationActivity"
android:exported="false"/>

<activity
android:name="com.depromeet.threedays.mypage.archived_habit.ArchivedHabitActivity"
android:exported="false"/>
</application>

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

<solid android:color="@color/white" />
<corners android:radius="10dp" />
<stroke
android:width="1dp"
android:color="@color/gray_450" />

</shape>
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/white" />
<corners android:radius="20dp" />

</shape>
13 changes: 13 additions & 0 deletions core-design-system/src/main/res/drawable/ic_close_white.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="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M18,6L6,18M6,6L18,18"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#FFFFFF"
android:strokeLineCap="round"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shape_switch_track_off" android:state_checked="false" />
<item android:drawable="@drawable/shape_switch_track_on" android:state_checked="true" />
</selector>
15 changes: 15 additions & 0 deletions core-design-system/src/main/res/drawable/shape_switch_thumb.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp">
<shape android:shape="oval">
<size
android:width="24dp"
android:height="24dp" />
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:height="28dp"
android:width="46dp" />
<solid android:color="@color/gray_500" />
<corners android:radius="20dp" />
</shape>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:height="28dp"
android:width="46dp"/>
<solid android:color="#33C95A" />
<corners android:radius="30dp" />
</shape>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ interface HabitService {

): List<HabitEntity>

@GET("/api/v1/habits?status=ARCHIVED")
suspend fun getArchivedHabits(): List<HabitEntity>

// @GET("/api/v1/habits/{habitId}")
// suspend fun getHabit(
// @Body request: PostProductsRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.depromeet.threedays.data.entity.HabitEntity
interface HabitRemoteDataSource {
suspend fun postHabit(habitEntity: HabitEntity)
suspend fun getHabits(): List<HabitEntity>
suspend fun getArchivedHabits(): List<HabitEntity>
//fun getHabit(habitId: Long): HabitEntity
suspend fun updateHabit(habitId: Long)
suspend fun deleteHabit(habitId: Long)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package com.depromeet.threedays.data.datasource.habit

import com.depromeet.threedays.data.api.HabitService
import com.depromeet.threedays.data.entity.HabitEntity
import java.time.DayOfWeek
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.concurrent.ThreadLocalRandom
import javax.inject.Inject

class HabitRemoteDataSourceImpl @Inject constructor(
Expand All @@ -15,6 +19,40 @@ class HabitRemoteDataSourceImpl @Inject constructor(
return habitService.getHabits()
}

override suspend fun getArchivedHabits(): List<HabitEntity> {
return listOf(
HabitEntity(
1,
memberId = 1,
title = "물 마시기",
imojiPath = "",
dayOfWeeks = listOf(
"MONDAY","TUESDAY","WEDNESDAY"
),
reward = ThreadLocalRandom.current().nextInt(10),
color = "pink",
mate = null,
todayHabitAchievementId = null,
sequence = 1,
createAt = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME),
),
HabitEntity(
2,
memberId = 1,
title = "영어 공부 1시간 하기",
imojiPath = "",
dayOfWeeks = DayOfWeek.values().map { it.name }.toList(),
reward = ThreadLocalRandom.current().nextInt(10),
color = "blue",
mate = null,
todayHabitAchievementId = null,
sequence = 1,
createAt = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME),
),
)
// return habitService.getArchivedHabits()
}

// override fun getHabit(habitId: Long): HabitEntity {
//
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class HabitEntity (
val memberId: Int,
val title: String,
val imojiPath: String,
val dayOfWeeks: ArrayList<String>,
val dayOfWeeks: List<String>,
val reward: Int,
val color: String,
val mate: Mate,
val mate: Mate?,
val todayHabitAchievementId: Int?, // null이면 오늘 체크를 하지 않은 것
val sequence: Int,
val createAt: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ class HabitRepositoryImpl @Inject constructor(
}
}

override suspend fun getArchivedHabits(): Flow<DataState<List<Habit>>> {
return flow {
emit(DataState.loading())
val response = habitRemoteDataSource.getArchivedHabits()

if(response.isNotEmpty()) {
emit(DataState.success(data = response.map { it.toHabit() }))
} else {
emit(DataState.error(msg = "response has error"))
}.runCatching {
emit(DataState.fail("response is fail"))
}
}
}

// override suspend fun getHabit(habitId: Long): Habit {
//
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ data class Habit(
val memberId: Int,
val title: String,
val imojiPath: String,
val dayOfWeeks: ArrayList<String>,
val dayOfWeeks: List<String>,
val reward: Int,
val color: Color,
val mate: Mate,
val mate: Mate?,
val todayHabitAchievementId: Int?, // null이면 오늘 체크를 하지 않은 것
val sequence: Int,
val createAt: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.coroutines.flow.Flow
interface HabitRepository {
suspend fun createHabit(habit: Habit)
suspend fun getHabits(): Flow<DataState<List<Habit>>>
suspend fun getArchivedHabits(): Flow<DataState<List<Habit>>>
//suspend fun getHabit(habitId: Long): Habit
suspend fun updateHabit(habitId: Long)
suspend fun deleteHabit(habitId: Long)
Expand Down
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.habit.Habit
import com.depromeet.threedays.domain.repository.HabitRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class GetArchivedHabitsUseCase @Inject constructor(
private val habitRepository: HabitRepository,
) {
suspend operator fun invoke(): Flow<DataState<List<Habit>>> {
return habitRepository.getArchivedHabits()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.depromeet.threedays.navigator

interface ArchivedHabitNavigator : Navigator
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class HabitViewHolder(private val view: ItemHabitBinding) : RecyclerView.ViewHol
}
}

private fun convertDayListToString(dayOfWeeks: ArrayList<String>): String {
private fun convertDayListToString(dayOfWeeks: List<String>): String {
return if (dayOfWeeks.size == 7) {
"매일"
} else if (dayOfWeeks.size == 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class HabitUI(
val habitId: Int,
val title: String,
val imojiPath: String,
val dayOfWeeks: ArrayList<String>,
val dayOfWeeks: List<String>,
val reward: Int,
val todayHabitAchievementId: Int?, // null이면 오늘 체크를 하지 않은 것
val createAt: String,
Expand All @@ -31,17 +31,17 @@ fun Habit.toHabitUI(): HabitUI {
createAt = this.createAt,
todayIndex = this.sequence % 3,
isTodayChecked = this.todayHabitAchievementId != null,
checkedBackgroundResId = when(this.color) {
checkedBackgroundResId = when (this.color) {
Color.GREEN -> R.drawable.selector_check_green
Color.BLUE -> R.drawable.selector_check_blue
Color.PINK -> R.drawable.selector_check_pink
},
checkableBackgroundResId = when(this.color) {
checkableBackgroundResId = when (this.color) {
Color.GREEN -> R.drawable.selector_check_light_green
Color.BLUE -> R.drawable.selector_check_light_blue
Color.PINK -> R.drawable.selector_check_light_pink
},
checkableTextColor = when(this.color) {
checkableTextColor = when (this.color) {
Color.GREEN -> core_color.color.green_50
Color.BLUE -> core_color.color.blue_50
Color.PINK -> core_color.color.pink_50
Expand Down
4 changes: 1 addition & 3 deletions presentation/mypage/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.depromeet.threedays.mypage">

</manifest>
package="com.depromeet.threedays.mypage" />
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,63 @@ import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import com.depromeet.threedays.core.BaseFragment
import com.depromeet.threedays.core.util.ThreeDaysToast
import com.depromeet.threedays.mypage.databinding.FragmentMyPageBinding
import com.depromeet.threedays.mypage.nickname.EditNicknameDialog
import com.depromeet.threedays.mypage.nickname.EditNicknameDialogFragment
import com.depromeet.threedays.navigator.ArchivedHabitNavigator
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class MyPageFragment: BaseFragment<FragmentMyPageBinding, MyPageViewModel>(R.layout.fragment_my_page) {
override val viewModel by viewModels<MyPageViewModel>()

@Inject
lateinit var archivedHabitNavigator: ArchivedHabitNavigator

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initEvent()
}

/**
* 이벤트 관련 작업 초기화
*/
private fun initEvent() {
binding.ivHabitArchived.setOnClickListener {
onHabitArchivedButtonClicked()
}
binding.ivEdit.setOnClickListener {
onEditButtonClicked()
}
}

private fun onHabitArchivedButtonClicked() {
val intent = archivedHabitNavigator.intent(requireContext())
startActivity(intent)
}

private fun onEditButtonClicked() {
val nickname = binding.tvNickname.text.toString()
val dialog = EditNicknameDialog(requireContext(), nickname)
dialog.show()
EditNicknameDialogFragment(
nickname = nickname,
onComplete = { ThreeDaysToast().show(requireContext(), "닉네임이 변경됐어요.") } ,
).show(
requireActivity().supportFragmentManager,
EditNicknameDialogFragment.TAG,
)
}

private fun onVersionButtonClicked() {
TODO("버전 정보")
}

private fun onServicePolicyButtonClicked() {
TODO("이용 약관")
}

private fun onPrivacyPolicyButtonClicked() {
TODO("개인정보처리방침")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.depromeet.threedays.mypage

import com.depromeet.threedays.mypage.archived_habit.ArchivedHabitNavigatorImpl
import com.depromeet.threedays.navigator.ArchivedHabitNavigator
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
internal abstract class MyPageModule {
@Binds
abstract fun bindArchivedHabitNavigator(navigator: ArchivedHabitNavigatorImpl): ArchivedHabitNavigator
}
Loading