Skip to content

Commit

Permalink
Merge pull request #166 from YAPP-19th/dev
Browse files Browse the repository at this point in the history
1.0.2 업데이트
  • Loading branch information
junieberry authored Jan 24, 2022
2 parents 3a36663 + 5195d2f commit ac42ba4
Show file tree
Hide file tree
Showing 27 changed files with 321 additions and 208 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
![license](https://img.shields.io/github/license/YAPP-19th/Android-Team-2-Frontend)
![app version](https://img.shields.io/badge/Version-1.0.1-orange?style=flat&logo=android)
![app version](https://img.shields.io/github/release/YAPP-19th/Android-Team-2-Frontend)
[![Google Play](https://img.shields.io/badge/Play%20Store-gray?style=flat&logo=GooglePlay)](https://play.google.com/store/apps/details?id=com.doctor.yumyum)

![yumyum doctor](https://user-images.githubusercontent.com/40855422/149953406-141cf9a1-0ca7-4506-9528-fc110443a816.png)
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android {
applicationId "com.doctor.yumyum"
minSdk 24
targetSdk 31
versionCode 3
versionName "1.0.1"
versionCode 4
versionName "1.0.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.doctor.yumyum.presentation.ui.write.LoadingDialog

abstract class BaseActivity<T : ViewDataBinding>(@LayoutRes private val layoutResId: Int) :
AppCompatActivity() {
Expand All @@ -21,7 +22,8 @@ abstract class BaseActivity<T : ViewDataBinding>(@LayoutRes private val layoutRe
}

protected fun showLoading() {
TODO()
val loadingDialog = LoadingDialog()
loadingDialog.show(supportFragmentManager,"LoadingDialog")
}

protected fun hideLoading() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import com.doctor.yumyum.presentation.ui.write.LoadingDialog

abstract class BaseFragment<T : ViewDataBinding>(@LayoutRes private val layoutResId: Int) :
Fragment() {
Expand All @@ -30,4 +31,9 @@ abstract class BaseFragment<T : ViewDataBinding>(@LayoutRes private val layoutRe
protected fun showToast(message: String) =
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()

protected fun showLoading(){
val loadingDialog = LoadingDialog()
loadingDialog.show(parentFragmentManager, "LoadingDialog")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import retrofit2.Response
import retrofit2.http.*

interface AuthService {
@POST("/api/v1/auth/creation")
@POST("/api/v1/users/creation")
suspend fun signUp(
@Body signUpModel: SignUpModel
): Response<ResponseBody>

@POST("/api/v1/auth")
@POST("/api/v1/users/auth")
suspend fun signIn(
@Body signInModel: SignInModel
): Response<ResponseBody>

@POST("/api/v1/users/auth/token")
suspend fun refreshToken(): Response<ResponseBody>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import retrofit2.Response
interface AuthDataSource {
suspend fun signUp(signUpModel: SignUpModel): Response<ResponseBody>
suspend fun signIn(signInModel: SignInModel): Response<ResponseBody>
suspend fun refreshToken(): Response<ResponseBody>
}

class AuthDataSourceImpl : AuthDataSource {
Expand All @@ -20,4 +21,7 @@ class AuthDataSourceImpl : AuthDataSource {

override suspend fun signIn(signInModel: SignInModel): Response<ResponseBody> =
RetrofitClient.getClient().create(AuthService::class.java).signIn(signInModel)

override suspend fun refreshToken(): Response<ResponseBody> =
RetrofitClient.getClient().create(AuthService::class.java).refreshToken()
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ class LoginRepositoryImpl : LoginRepository {

override suspend fun signIn(signInModel: SignInModel): Response<ResponseBody> =
authDataSource.signIn(signInModel)

override suspend fun refreshToken(): Response<ResponseBody> =
authDataSource.refreshToken()

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ interface LoginRepository {

// 회원가입
suspend fun signUp(signUpModel: SignUpModel): Response<ResponseBody>

// 로그인
suspend fun signIn(signInModel: SignInModel): Response<ResponseBody>

// 리프레스 토큰
suspend fun refreshToken(): Response<ResponseBody>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ package com.doctor.yumyum.presentation.ui.home
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.res.ResourcesCompat
import androidx.lifecycle.ViewModelProvider
import com.doctor.yumyum.R
import com.doctor.yumyum.common.base.BaseFragment
import com.doctor.yumyum.common.utils.REQUEST_CODE
import com.doctor.yumyum.databinding.FragmentHomeBinding
import com.doctor.yumyum.presentation.adapter.HomeBrandAdapter
import com.doctor.yumyum.presentation.adapter.HomeFavoriteAdapter
Expand Down Expand Up @@ -49,6 +52,16 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
Pair(R.drawable.ic_brand_ramen_home, getString(R.string.common_ramen))
)
}
private val detailLauncher: ActivityResultLauncher<Intent> =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode == REQUEST_CODE.DELETE_RECIPE) {
CoroutineScope(Dispatchers.IO).launch {
val mode = viewModel.mode.value ?: R.string.common_food
viewModel.getFavorite(requireContext().getString(mode))
viewModel.getRecommendation(requireContext().getString(mode))
}
}
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand Down Expand Up @@ -77,7 +90,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
binding.homeRvFavoriteRecipe.adapter = HomeFavoriteAdapter {
val intent = Intent(context, RecipeDetailActivity::class.java)
intent.putExtra("recipeId", it)
startActivity(intent)
detailLauncher.launch(intent)
}

// 나의 레시피 초기화
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class MyPageViewModel : BaseViewModel() {
private val userRepository = UserRepositoryImpl()
private val loginRepository = LoginRepositoryImpl()
private val localGrade = userRepository.getLocalGrade()
private val _nickname: MutableLiveData<String> = MutableLiveData("")
private val _nickname: MutableLiveData<String> = MutableLiveData()
val nickname: LiveData<String>
get() = _nickname
private val _grade: MutableLiveData<String> = MutableLiveData("")
private val _grade: MutableLiveData<String> = MutableLiveData()
val grade: LiveData<String>
get() = _grade
private val _point: MutableLiveData<Int> = MutableLiveData()
Expand All @@ -26,7 +26,7 @@ class MyPageViewModel : BaseViewModel() {
private val _errorState: MutableLiveData<Boolean> = MutableLiveData(false)
val errorState: LiveData<Boolean>
get() = _errorState
private val _gradeUp: MutableLiveData<String> = MutableLiveData("")
private val _gradeUp: MutableLiveData<String> = MutableLiveData()
val gradeUp: LiveData<String>
get() = _gradeUp

Expand All @@ -51,12 +51,8 @@ class MyPageViewModel : BaseViewModel() {
}

private fun isGradeUp(newGrade: String) {
if (localGrade != null) {
if (localGrade != newGrade) {
_gradeUp.postValue(newGrade)
userRepository.setLocalGrade(newGrade)
}
}
if ((!localGrade.isNullOrBlank()) && (localGrade != newGrade)) _gradeUp.value = newGrade
userRepository.setLocalGrade(newGrade)
}

fun logout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.lifecycle.ViewModelProvider
import com.doctor.yumyum.R
import com.doctor.yumyum.common.base.BaseActivity
import com.doctor.yumyum.databinding.ActivityNicknameBinding
import com.doctor.yumyum.presentation.ui.main.MainActivity
import com.doctor.yumyum.presentation.ui.taste.TasteActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -23,25 +22,29 @@ class NicknameActivity : BaseActivity<ActivityNicknameBinding>(R.layout.activity
ViewModelProvider.NewInstanceFactory()
)[NicknameViewModel::class.java]
}
val fromMyPage:Boolean by lazy { intent.extras?.getBoolean(getString(R.string.nickname_mode)) ?: false }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

init()
initNickname()

viewModel.nickname.observe(this) { nickname ->
binding.nicknameEtNickname.setText(nickname)
}
initNickname()
}

private fun init() {
if (fromMyPage) {
binding.nicknameTvTitle.visibility = View.GONE
}
binding.apply {
viewModel = viewModel
lifecycleOwner = this@NicknameActivity
}
binding.nicknameToolbar.appbarIbBack.setOnClickListener {
if (intent.getBooleanExtra(getString(R.string.nickname_mode), false)) {
if (fromMyPage) {
onBackPressed()
} else {
NicknameBackDialog().show(supportFragmentManager, "NicknameBackDialog")
Expand All @@ -52,9 +55,7 @@ class NicknameActivity : BaseActivity<ActivityNicknameBinding>(R.layout.activity
CoroutineScope(Dispatchers.IO).launch {
viewModel.patchNickname(binding.nicknameEtNickname.text.toString())
}

if (intent.getBooleanExtra(getString(R.string.nickname_mode), false)) {
startActivity(Intent(this@NicknameActivity, MainActivity::class.java))
if (fromMyPage) {
finish()
} else {
startActivity(Intent(this@NicknameActivity, TasteActivity::class.java))
Expand Down Expand Up @@ -84,7 +85,7 @@ class NicknameActivity : BaseActivity<ActivityNicknameBinding>(R.layout.activity
}

override fun onBackPressed() {
if (intent.getBooleanExtra(getString(R.string.nickname_mode), false)) {
if (fromMyPage) {
super.onBackPressed()
} else {
NicknameBackDialog().show(supportFragmentManager, "NicknameBackDialog")
Expand All @@ -94,7 +95,7 @@ class NicknameActivity : BaseActivity<ActivityNicknameBinding>(R.layout.activity
private fun initNickname() {
CoroutineScope(Dispatchers.IO).launch {

if (intent.getBooleanExtra(getString(R.string.nickname_mode), false)) {
if (fromMyPage) {
viewModel.getUserInfo()
} else {
viewModel.getNickname()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class RecipeDeleteDialog(private val deleteListener : () -> Unit) : BaseDialog<D
binding.writeFinishNo.setOnClickListener { dismiss() }
binding.writeFinishYes.setOnClickListener {
deleteListener()
dismiss()
}

return binding.root
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.doctor.yumyum.presentation.ui.recipedetail

import android.content.Intent
import android.os.Bundle
import android.util.DisplayMetrics
import androidx.lifecycle.ViewModelProvider
Expand All @@ -13,7 +12,6 @@ import com.doctor.yumyum.databinding.ActivityRecipeDetailBinding
import com.doctor.yumyum.presentation.adapter.RecipeDetailAdapter
import com.doctor.yumyum.presentation.adapter.TasteTagAdapter
import com.doctor.yumyum.presentation.adapter.WriteTagAdapter
import com.doctor.yumyum.presentation.ui.myrecipe.MyRecipeFragment
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
Expand Down Expand Up @@ -48,6 +46,7 @@ class RecipeDetailActivity :
binding.recipeDetailIbBack.setOnClickListener { finish() }
binding.recipeDetailIbDelete.setOnClickListener {
RecipeDeleteDialog{
showLoading()
lifecycleScope.launch {
val deleteRecipe = lifecycleScope.async {
viewModel.deleteRecipe(recipeId)
Expand Down
Loading

0 comments on commit ac42ba4

Please sign in to comment.