Skip to content

Commit

Permalink
Merge pull request #103 from Begin-Vegan/feature/BVVER24-146-mypage-u…
Browse files Browse the repository at this point in the history
…ser-level-api

Mypage 나만의 식물 일러스트 설정
  • Loading branch information
syjeuion authored Jul 13, 2024
2 parents 5aa08d9 + 45a6fa2 commit 708449f
Show file tree
Hide file tree
Showing 23 changed files with 367 additions and 31 deletions.
Binary file modified .gradle/8.4/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/8.4/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.4/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/8.4/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/8.4/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified buildSrc/.gradle/8.4/executionHistory/executionHistory.lock
Binary file not shown.
52 changes: 52 additions & 0 deletions data/src/main/java/com/example/data/di/MypageUserInfoModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.example.data.di

import com.example.data.mapper.mypage.MypageUserInfoMapper
import com.example.data.repository.local.auth.AuthTokenDataSource
import com.example.data.repository.remote.mypage.MypageUserInfoRemoteDataSource
import com.example.data.repository.remote.mypage.MypageUserInfoRemoteDataSourceImpl
import com.example.data.repository.remote.mypage.MypageUserInfoRepositoryImpl
import com.example.data.retrofit.MypageUserInfoService
import com.example.domain.repository.mypage.MypageUserInfoRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import javax.inject.Singleton

@Module(includes = [NetworkModule::class, DataStoreModule::class])
@InstallIn(SingletonComponent::class)
class MypageUserInfoModule {
@Singleton
@Provides
fun provideMypageUserInfoService(retrofit: Retrofit): MypageUserInfoService {
return retrofit.create(MypageUserInfoService::class.java)
}

@Provides
@Singleton
fun provideMypageUserInfoDataSource(
mypageUserInfoService: MypageUserInfoService,
authTokenDataSource: AuthTokenDataSource
): MypageUserInfoRemoteDataSource {
return MypageUserInfoRemoteDataSourceImpl(mypageUserInfoService, authTokenDataSource)
}

@Provides
@Singleton
fun provideMypageUserInfoRepository(
mypageUserInfoRemoteDataSource: MypageUserInfoRemoteDataSource,
mypageUserInfoMapper: MypageUserInfoMapper
): MypageUserInfoRepository {
return MypageUserInfoRepositoryImpl(
mypageUserInfoRemoteDataSource,
mypageUserInfoMapper
)
}

@Provides
@Singleton
fun provideMypageUserInfoMapper(): MypageUserInfoMapper {
return MypageUserInfoMapper()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.data.mapper.mypage

import com.example.data.model.mypage.MypageUserInfoDto
import com.example.domain.mapper.Mapper
import com.example.domain.model.mypage.MypageUserInfo

class MypageUserInfoMapper:Mapper<MypageUserInfoDto, MypageUserInfo> {
override fun mapFromEntity(type: MypageUserInfoDto): MypageUserInfo {
return MypageUserInfo(
id = type.id,
imageUrl = type.imageUrl,
nickname = type.nickname,
userLevel = type.userLevel,
veganType = type.veganType,
point = type.point
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.data.model.mypage

import com.squareup.moshi.Json

data class MypageUserInfoResponse(
@Json(name = "check")
val check: Boolean,
@Json(name = "information")
val information: MypageUserInfoDto
)

data class MypageUserInfoDto(
@Json(name = "id") val id: Int,
@Json(name = "imageUrl") val imageUrl:String,
@Json(name = "nickname") val nickname:String,
@Json(name = "userLevel") val userLevel:String,
@Json(name = "veganType") val veganType:String,
@Json(name = "point") val point:Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.data.repository.remote.mypage

import com.example.data.model.mypage.MypageUserInfoResponse
import com.skydoves.sandwich.ApiResponse

interface MypageUserInfoRemoteDataSource {
suspend fun getMypageUserInfo(): ApiResponse<MypageUserInfoResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.data.repository.remote.mypage

import com.example.data.model.mypage.MypageUserInfoResponse
import com.example.data.repository.local.auth.AuthTokenDataSource
import com.example.data.retrofit.MypageUserInfoService
import com.skydoves.sandwich.ApiResponse
import com.skydoves.sandwich.retrofit.errorBody
import com.skydoves.sandwich.suspendOnError
import com.skydoves.sandwich.suspendOnSuccess
import kotlinx.coroutines.flow.first
import timber.log.Timber
import javax.inject.Inject

class MypageUserInfoRemoteDataSourceImpl @Inject constructor(
private val mypageUserInfoService: MypageUserInfoService,
private val authTokenDataSource: AuthTokenDataSource
):MypageUserInfoRemoteDataSource {
override suspend fun getMypageUserInfo(): ApiResponse<MypageUserInfoResponse> {
val accessToken = authTokenDataSource.accessToken.first()
val authHeader = "Bearer $accessToken"
return mypageUserInfoService.getMypageUserInfo(authHeader).suspendOnSuccess {
Timber.d("getMypageUserInfo successful")
ApiResponse.Success(this.data)
}.suspendOnError {
Timber.e("getMypageUserInfo error: ${this.errorBody}")
ApiResponse.Failure.Error(this.errorBody)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example.data.repository.remote.mypage

import com.example.data.mapper.mypage.MypageUserInfoMapper
import com.example.domain.model.mypage.MypageUserInfo
import com.example.domain.repository.mypage.MypageUserInfoRepository
import com.skydoves.sandwich.ApiResponse
import com.skydoves.sandwich.retrofit.errorBody
import timber.log.Timber
import javax.inject.Inject

class MypageUserInfoRepositoryImpl @Inject constructor(
private val mypageUserInfoRemoteDataSource: MypageUserInfoRemoteDataSource,
private val mypageUserInfoMapper: MypageUserInfoMapper
):MypageUserInfoRepository{
override suspend fun getMypageUserInfo(): Result<MypageUserInfo> {
return try {
val response = mypageUserInfoRemoteDataSource.getMypageUserInfo()
when (response) {
is ApiResponse.Success -> {
val magazineList = mypageUserInfoMapper.mapFromEntity(response.data.information)
Result.success(magazineList)
}

is ApiResponse.Failure.Error -> {
Timber.e("getMypageUserInfo error: ${response.errorBody}")
Result.failure(Exception("getMypageUserInfo failed"))
}

is ApiResponse.Failure.Exception -> {
Timber.e("getMypageUserInfo exception: ${response.message}")
Result.failure(response.throwable)
}
}
} catch (e: Exception) {
Timber.e(e, "getMypageUserInfo exception")
Result.failure(e)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.data.retrofit

import com.example.data.model.mypage.MypageUserInfoResponse
import com.skydoves.sandwich.ApiResponse
import retrofit2.http.GET
import retrofit2.http.Header

interface MypageUserInfoService {
@GET("/api/v1/users/my-page")
suspend fun getMypageUserInfo(
@Header("Authorization") token: String
): ApiResponse<MypageUserInfoResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.domain.model.mypage

data class MypageUserInfo(
val id: Int,
val imageUrl:String,
val nickname:String,
val userLevel:String,
val veganType:String,
val point:Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.domain.repository.mypage

import com.example.domain.model.mypage.MypageUserInfo

interface MypageUserInfoRepository {
suspend fun getMypageUserInfo(): Result<MypageUserInfo>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.domain.useCase.mypage

import com.example.domain.model.mypage.MypageUserInfo
import com.example.domain.repository.mypage.MypageUserInfoRepository
import javax.inject.Inject

class MypageUserInfoUseCase @Inject constructor(
private val mypageUserInfoRepository: MypageUserInfoRepository
){
suspend operator fun invoke():Result<MypageUserInfo> {
return mypageUserInfoRepository.getMypageUserInfo()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.presentation.util

import android.content.Context
import android.graphics.drawable.Drawable
import androidx.core.content.ContextCompat
import com.example.presentation.R

data class UserLevelIllusts(
val context:Context,
val userLevelIllus:List<Drawable?> = listOf(
ContextCompat.getDrawable(context, R.drawable.illus_user_level_1_seed),
ContextCompat.getDrawable(context, R.drawable.illus_user_level_2_cotyledon),
ContextCompat.getDrawable(context, R.drawable.illus_user_level_3_sprout),
ContextCompat.getDrawable(context, R.drawable.illus_user_level_4_stem),
ContextCompat.getDrawable(context, R.drawable.illus_user_level_5_leaf),
ContextCompat.getDrawable(context, R.drawable.illus_user_level_6_tree),
ContextCompat.getDrawable(context, R.drawable.illus_user_level_7_flower),
ContextCompat.getDrawable(context, R.drawable.illus_user_level_8_fruit)
),
val userLevelIcons:List<Drawable?> = listOf(
ContextCompat.getDrawable(context, R.drawable.ic_user_level_1_seed),
ContextCompat.getDrawable(context, R.drawable.ic_user_level_2_cotyledon),
ContextCompat.getDrawable(context, R.drawable.ic_user_level_3_sprout),
ContextCompat.getDrawable(context, R.drawable.ic_user_level_4_stem),
ContextCompat.getDrawable(context, R.drawable.ic_user_level_5_leaf),
ContextCompat.getDrawable(context, R.drawable.ic_user_level_6_tree),
ContextCompat.getDrawable(context, R.drawable.ic_user_level_7_flower),
ContextCompat.getDrawable(context, R.drawable.ic_user_level_8_fruit),
)
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package com.example.presentation.view.mypage.view

import android.widget.ArrayAdapter
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.example.domain.model.mypage.MypageUserInfo
import com.example.presentation.R
import com.example.presentation.base.BaseFragment
import com.example.presentation.config.navigation.main.MainNavigationHandler
import com.example.presentation.databinding.FragmentMainMypageBinding
import com.example.presentation.util.DrawerController
import com.example.presentation.util.MypageUserLevelExplainDialog
import com.example.presentation.util.UserLevelIllusts
import com.example.presentation.view.mypage.viewModel.MypageUserInfoViewModel
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber
import javax.inject.Inject
Expand Down Expand Up @@ -116,41 +127,51 @@ class MainMypageFragment : BaseFragment<FragmentMainMypageBinding>(R.layout.frag

@Inject
lateinit var drawerController: DrawerController

@Inject
lateinit var mainNavigationHandler: MainNavigationHandler
private val mypageUserInfoViewModel:MypageUserInfoViewModel by viewModels()

override fun init() {
Timber.d("mypage init")
Timber.d("findNavController().backQueue.size:${findNavController().backQueue.size}")

binding.llUserLevelExplain.setOnClickListener {
openDialogUserLevelExplain()
}
binding.lifecycleOwner = this

setOpenDrawer()
openDialogUserLevelExplain()
setProgressBar(5, 1)
setVeganTypeDropdown(getString(R.string.vegan_type_unknown))
moveFuns()

binding.llEditProfile.setOnClickListener {
mainNavigationHandler.navigateToEditProfile()
}
binding.llMyReview.setOnClickListener {
mainNavigationHandler.navigateToReview()
}
binding.llMyRestaurant.setOnClickListener {
mainNavigationHandler.navigateToMyRestaurant()
}
binding.llMyMagazine.setOnClickListener {
mainNavigationHandler.navigateToMyMagazine()
}
binding.llMyRecipe.setOnClickListener {
mainNavigationHandler.navigateToMyRecipe()
}
binding.llSetting.setOnClickListener {
mainNavigationHandler.navigateToMySetting()
getUserInfo()
}

private fun getUserInfo(){
mypageUserInfoViewModel.userInfo.observe(this){
setUserInfo(it)
}
}
private fun setUserInfo(userInfo:MypageUserInfo){
val userLevelKr = requireContext().resources.getStringArray(R.array.user_levels_kr)
val userLevelEng = requireContext().resources.getStringArray(R.array.user_levels_eng)
val levelIllusts = UserLevelIllusts(requireContext()).userLevelIllus
val levelIcons = UserLevelIllusts(requireContext()).userLevelIcons

val index = userLevelEng.indexOf(userInfo.userLevel)
Glide.with(this)
.load(levelIllusts[index])
.into(binding.ivIllusUserLevel)
binding.tvUserLevel.text = "${userLevelKr[index]} 레벨"

Glide.with(this)
.load(userInfo.imageUrl)
.transform(CircleCrop())
.into(binding.ivUserProfileImg)

Glide.with(this)
.load(levelIcons[index])
.into(binding.ivUserProfileUserLevel)

binding.tvUserName.text = userInfo.nickname

}

private fun setOpenDrawer() {
binding.includedToolbar.ibNotification.setOnClickListener {
Expand All @@ -159,8 +180,10 @@ class MainMypageFragment : BaseFragment<FragmentMainMypageBinding>(R.layout.frag
}

private fun openDialogUserLevelExplain() {
val dialog = MypageUserLevelExplainDialog(requireContext())
dialog.show()
binding.llUserLevelExplain.setOnClickListener {
val dialog = MypageUserLevelExplainDialog(requireContext())
dialog.show()
}
}

private fun setProgressBar(maxInt: Int, nowGauge: Int) {
Expand Down Expand Up @@ -192,4 +215,26 @@ class MainMypageFragment : BaseFragment<FragmentMainMypageBinding>(R.layout.frag
// binding.sSetVeganType.adapter = dropdownAdapter
}

private fun moveFuns(){

binding.llEditProfile.setOnClickListener {
mainNavigationHandler.navigateToEditProfile()
}
binding.llMyReview.setOnClickListener {
mainNavigationHandler.navigateToReview()
}
binding.llMyRestaurant.setOnClickListener {
mainNavigationHandler.navigateToMyRestaurant()
}
binding.llMyMagazine.setOnClickListener {
mainNavigationHandler.navigateToMyMagazine()
}
binding.llMyRecipe.setOnClickListener {
mainNavigationHandler.navigateToMyRecipe()
}
binding.llSetting.setOnClickListener {
mainNavigationHandler.navigateToMySetting()
}
}

}
Loading

0 comments on commit 708449f

Please sign in to comment.