diff --git a/README.md b/README.md index 748f0347..2ea62fec 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/app/build.gradle b/app/build.gradle index f09cde58..8d22f509 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" } diff --git a/app/src/main/java/com/doctor/yumyum/common/base/BaseActivity.kt b/app/src/main/java/com/doctor/yumyum/common/base/BaseActivity.kt index 9566ba7f..6631585a 100644 --- a/app/src/main/java/com/doctor/yumyum/common/base/BaseActivity.kt +++ b/app/src/main/java/com/doctor/yumyum/common/base/BaseActivity.kt @@ -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(@LayoutRes private val layoutResId: Int) : AppCompatActivity() { @@ -21,7 +22,8 @@ abstract class BaseActivity(@LayoutRes private val layoutRe } protected fun showLoading() { - TODO() + val loadingDialog = LoadingDialog() + loadingDialog.show(supportFragmentManager,"LoadingDialog") } protected fun hideLoading() { diff --git a/app/src/main/java/com/doctor/yumyum/common/base/BaseFragment.kt b/app/src/main/java/com/doctor/yumyum/common/base/BaseFragment.kt index c1655ce7..62288d20 100644 --- a/app/src/main/java/com/doctor/yumyum/common/base/BaseFragment.kt +++ b/app/src/main/java/com/doctor/yumyum/common/base/BaseFragment.kt @@ -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(@LayoutRes private val layoutResId: Int) : Fragment() { @@ -30,4 +31,9 @@ abstract class BaseFragment(@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") + } + } \ No newline at end of file diff --git a/app/src/main/java/com/doctor/yumyum/data/remote/api/AuthService.kt b/app/src/main/java/com/doctor/yumyum/data/remote/api/AuthService.kt index fbef7db2..c1716c03 100644 --- a/app/src/main/java/com/doctor/yumyum/data/remote/api/AuthService.kt +++ b/app/src/main/java/com/doctor/yumyum/data/remote/api/AuthService.kt @@ -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 - @POST("/api/v1/auth") + @POST("/api/v1/users/auth") suspend fun signIn( @Body signInModel: SignInModel ): Response + + @POST("/api/v1/users/auth/token") + suspend fun refreshToken(): Response } \ No newline at end of file diff --git a/app/src/main/java/com/doctor/yumyum/data/remote/datasource/AuthDataSource.kt b/app/src/main/java/com/doctor/yumyum/data/remote/datasource/AuthDataSource.kt index d512ec0f..c75ccd84 100644 --- a/app/src/main/java/com/doctor/yumyum/data/remote/datasource/AuthDataSource.kt +++ b/app/src/main/java/com/doctor/yumyum/data/remote/datasource/AuthDataSource.kt @@ -10,6 +10,7 @@ import retrofit2.Response interface AuthDataSource { suspend fun signUp(signUpModel: SignUpModel): Response suspend fun signIn(signInModel: SignInModel): Response + suspend fun refreshToken(): Response } class AuthDataSourceImpl : AuthDataSource { @@ -20,4 +21,7 @@ class AuthDataSourceImpl : AuthDataSource { override suspend fun signIn(signInModel: SignInModel): Response = RetrofitClient.getClient().create(AuthService::class.java).signIn(signInModel) + + override suspend fun refreshToken(): Response = + RetrofitClient.getClient().create(AuthService::class.java).refreshToken() } \ No newline at end of file diff --git a/app/src/main/java/com/doctor/yumyum/data/repository/LoginRepositoryImpl.kt b/app/src/main/java/com/doctor/yumyum/data/repository/LoginRepositoryImpl.kt index 31252547..da2f9259 100644 --- a/app/src/main/java/com/doctor/yumyum/data/repository/LoginRepositoryImpl.kt +++ b/app/src/main/java/com/doctor/yumyum/data/repository/LoginRepositoryImpl.kt @@ -32,4 +32,8 @@ class LoginRepositoryImpl : LoginRepository { override suspend fun signIn(signInModel: SignInModel): Response = authDataSource.signIn(signInModel) + + override suspend fun refreshToken(): Response = + authDataSource.refreshToken() + } \ No newline at end of file diff --git a/app/src/main/java/com/doctor/yumyum/domain/repository/LoginRepository.kt b/app/src/main/java/com/doctor/yumyum/domain/repository/LoginRepository.kt index cc1c987a..f1415d7e 100644 --- a/app/src/main/java/com/doctor/yumyum/domain/repository/LoginRepository.kt +++ b/app/src/main/java/com/doctor/yumyum/domain/repository/LoginRepository.kt @@ -18,5 +18,10 @@ interface LoginRepository { // 회원가입 suspend fun signUp(signUpModel: SignUpModel): Response + + // 로그인 suspend fun signIn(signInModel: SignInModel): Response + + // 리프레스 토큰 + suspend fun refreshToken(): Response } \ No newline at end of file diff --git a/app/src/main/java/com/doctor/yumyum/presentation/ui/home/HomeFragment.kt b/app/src/main/java/com/doctor/yumyum/presentation/ui/home/HomeFragment.kt index 5eb4d1cd..233bffed 100644 --- a/app/src/main/java/com/doctor/yumyum/presentation/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/doctor/yumyum/presentation/ui/home/HomeFragment.kt @@ -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 @@ -49,6 +52,16 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) { Pair(R.drawable.ic_brand_ramen_home, getString(R.string.common_ramen)) ) } + private val detailLauncher: ActivityResultLauncher = + 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) @@ -77,7 +90,7 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) { binding.homeRvFavoriteRecipe.adapter = HomeFavoriteAdapter { val intent = Intent(context, RecipeDetailActivity::class.java) intent.putExtra("recipeId", it) - startActivity(intent) + detailLauncher.launch(intent) } // 나의 레시피 초기화 diff --git a/app/src/main/java/com/doctor/yumyum/presentation/ui/mypage/MyPageViewModel.kt b/app/src/main/java/com/doctor/yumyum/presentation/ui/mypage/MyPageViewModel.kt index 0d0bfe2c..2b28cf99 100644 --- a/app/src/main/java/com/doctor/yumyum/presentation/ui/mypage/MyPageViewModel.kt +++ b/app/src/main/java/com/doctor/yumyum/presentation/ui/mypage/MyPageViewModel.kt @@ -14,10 +14,10 @@ class MyPageViewModel : BaseViewModel() { private val userRepository = UserRepositoryImpl() private val loginRepository = LoginRepositoryImpl() private val localGrade = userRepository.getLocalGrade() - private val _nickname: MutableLiveData = MutableLiveData("") + private val _nickname: MutableLiveData = MutableLiveData() val nickname: LiveData get() = _nickname - private val _grade: MutableLiveData = MutableLiveData("") + private val _grade: MutableLiveData = MutableLiveData() val grade: LiveData get() = _grade private val _point: MutableLiveData = MutableLiveData() @@ -26,7 +26,7 @@ class MyPageViewModel : BaseViewModel() { private val _errorState: MutableLiveData = MutableLiveData(false) val errorState: LiveData get() = _errorState - private val _gradeUp: MutableLiveData = MutableLiveData("") + private val _gradeUp: MutableLiveData = MutableLiveData() val gradeUp: LiveData get() = _gradeUp @@ -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() { diff --git a/app/src/main/java/com/doctor/yumyum/presentation/ui/nickname/NicknameActivity.kt b/app/src/main/java/com/doctor/yumyum/presentation/ui/nickname/NicknameActivity.kt index b1967bd3..1a16abba 100644 --- a/app/src/main/java/com/doctor/yumyum/presentation/ui/nickname/NicknameActivity.kt +++ b/app/src/main/java/com/doctor/yumyum/presentation/ui/nickname/NicknameActivity.kt @@ -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 @@ -23,25 +22,29 @@ class NicknameActivity : BaseActivity(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") @@ -52,9 +55,7 @@ class NicknameActivity : BaseActivity(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)) @@ -84,7 +85,7 @@ class NicknameActivity : BaseActivity(R.layout.activity } override fun onBackPressed() { - if (intent.getBooleanExtra(getString(R.string.nickname_mode), false)) { + if (fromMyPage) { super.onBackPressed() } else { NicknameBackDialog().show(supportFragmentManager, "NicknameBackDialog") @@ -94,7 +95,7 @@ class NicknameActivity : BaseActivity(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() diff --git a/app/src/main/java/com/doctor/yumyum/presentation/ui/recipedetail/RecipeDeleteDialog.kt b/app/src/main/java/com/doctor/yumyum/presentation/ui/recipedetail/RecipeDeleteDialog.kt index 7689b573..4469a6df 100644 --- a/app/src/main/java/com/doctor/yumyum/presentation/ui/recipedetail/RecipeDeleteDialog.kt +++ b/app/src/main/java/com/doctor/yumyum/presentation/ui/recipedetail/RecipeDeleteDialog.kt @@ -20,6 +20,7 @@ class RecipeDeleteDialog(private val deleteListener : () -> Unit) : BaseDialog(R.layout.activity_research_list) { private lateinit var sortDialog: BottomSheetDialog private lateinit var searchDialog: BottomSheetDialog - private val viewModel by lazy { ViewModelProvider( this, ViewModelProvider.NewInstanceFactory() )[ResearchListViewModel::class.java] } - private var categoryName = "" private var sort = "id" private var order = "desc" @@ -49,9 +46,72 @@ class ResearchListActivity : private var maxPrice: Int? = null private var flavors: ArrayList = arrayListOf("") private var tags: ArrayList = arrayListOf("") - private lateinit var filterLauncher: ActivityResultLauncher - private lateinit var searchTasteLauncher: ActivityResultLauncher - private lateinit var searchHashtagLauncher: ActivityResultLauncher + private val researchListAdapter = ResearchListAdapter({ recipeId -> + val intent = Intent(this, RecipeDetailActivity::class.java) + intent.putExtra("recipeId", recipeId) + detailLauncher.launch(intent) + }, { recipe, position -> + viewModel.setBookmarkState(recipe, position) + }, {}, {}) + private val filterLauncher: ActivityResultLauncher = + // 필터 화면에서 돌아왔을 때 + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { + if (it.resultCode == RESULT_OK && it.data != null) { + minPrice = it.data?.extras?.get("minPrice") as Int? + maxPrice = it.data?.extras?.get("maxPrice") as Int? + + // 필터 아이콘 상태 변경 + if (minPrice == null && maxPrice == null) { + // 적용하지 않은 상태 + binding.researchListTvFilter.setCompoundDrawablesWithIntrinsicBounds( + getDrawable(R.drawable.ic_filter_gray), null, null, null + ) + } else { + // 적용한 상태 + binding.researchListTvFilter.setCompoundDrawablesWithIntrinsicBounds( + getDrawable(R.drawable.ic_filter_green), null, null, null + ) + } + searchRecipeList() + } + } + private val searchTasteLauncher: ActivityResultLauncher = + // 맛별로 검색할 때 + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) + { + if (it.resultCode == RESULT_OK && it.data != null) { + val tasteList = it.data?.extras?.getStringArrayList(TASTE_EXTRA_KEY) + + // 검색창 리스트 설정 + tasteList?.let { list -> + viewModel.setSearchList(list) + flavors = list + tags = arrayListOf("") + } + searchRecipeList() + } + } + private val searchHashtagLauncher: ActivityResultLauncher = + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { + if (it.resultCode == RESULT_OK && it.data != null) { + val hashtagList = it.data?.extras?.getStringArrayList(HASHTAG_EXTRA_KEY) + + // 검색창 리스트 설정 + hashtagList?.let { list -> + viewModel.setSearchList(ArrayList(list.map { it -> "#$it" })) + tags = list + flavors = arrayListOf("") + } + + searchRecipeList() + } + } + private val detailLauncher: ActivityResultLauncher = + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { + if (it.resultCode == REQUEST_CODE.DELETE_RECIPE) { + searchRecipeList() + } + } private var touchStartTime: Long = Calendar.getInstance().timeInMillis @SuppressLint("UseCompatLoadingForDrawables") @@ -82,30 +142,6 @@ class ResearchListActivity : initSortDialog() initSearchDialog() - // 필터 화면에서 돌아왔을 때 - filterLauncher = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { - if (it.resultCode == RESULT_OK && it.data != null) { - minPrice = it.data?.extras?.get("minPrice") as Int? - maxPrice = it.data?.extras?.get("maxPrice") as Int? - - // 필터 아이콘 상태 변경 - if (minPrice == null && maxPrice == null) { - // 적용하지 않은 상태 - binding.researchListTvFilter.setCompoundDrawablesWithIntrinsicBounds( - getDrawable(R.drawable.ic_filter_gray), null, null, null - ) - } else { - // 적용한 상태 - binding.researchListTvFilter.setCompoundDrawablesWithIntrinsicBounds( - getDrawable(R.drawable.ic_filter_green), null, null, null - ) - } - - searchRecipeList() - } - } - // 필터 화면으로 이동 binding.researchListTvFilter.setOnClickListener { val intent = Intent(this, FilterActivity::class.java) @@ -113,13 +149,6 @@ class ResearchListActivity : intent.putExtra("maxPrice", maxPrice) filterLauncher.launch(intent) } - val researchListAdapter = ResearchListAdapter({ recipeId -> - val intent = Intent(this, RecipeDetailActivity::class.java) - intent.putExtra("recipeId", recipeId) - startActivity(intent) - }, { recipe, position -> - viewModel.setBookmarkState(recipe, position) - }, {},{}) binding.researchListClAppbar.appbarIbBack.setOnClickListener { finish() } binding.researchListRvRecipe.adapter = researchListAdapter @@ -155,39 +184,6 @@ class ResearchListActivity : ) } - // 맛별로 검색할 때 - searchTasteLauncher = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { - if (it.resultCode == RESULT_OK && it.data != null) { - val tasteList = it.data?.extras?.getStringArrayList(TASTE_EXTRA_KEY) - - // 검색창 리스트 설정 - tasteList?.let { list -> - viewModel.setSearchList(list) - flavors = list - tags = arrayListOf("") - } - - searchRecipeList() - } - } - - searchHashtagLauncher = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { - if (it.resultCode == RESULT_OK && it.data != null) { - val hashtagList = it.data?.extras?.getStringArrayList(HASHTAG_EXTRA_KEY) - - // 검색창 리스트 설정 - hashtagList?.let { list -> - viewModel.setSearchList(ArrayList(list.map { it -> "#$it" })) - tags = list - flavors = arrayListOf("") - } - - searchRecipeList() - } - } - viewModel.searchType.observe(this) { if (it == ResearchListViewModel.SEARCH_HASHTAG) { searchHashtagLauncher.launch(Intent(this, SearchHashtagActivity::class.java)) diff --git a/app/src/main/java/com/doctor/yumyum/presentation/ui/researchrecipe/ResearchRecipeFragment.kt b/app/src/main/java/com/doctor/yumyum/presentation/ui/researchrecipe/ResearchRecipeFragment.kt index 28283798..c50f870a 100644 --- a/app/src/main/java/com/doctor/yumyum/presentation/ui/researchrecipe/ResearchRecipeFragment.kt +++ b/app/src/main/java/com/doctor/yumyum/presentation/ui/researchrecipe/ResearchRecipeFragment.kt @@ -6,10 +6,13 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +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.FragmentResearchRecipeBinding import com.doctor.yumyum.presentation.adapter.RankAdapter import com.doctor.yumyum.presentation.adapter.ResearchBrandAdapter @@ -50,6 +53,12 @@ class ResearchRecipeFragment : ) } private lateinit var brandRecyclerAdapter: ResearchBrandAdapter + private val detailLauncher: ActivityResultLauncher = + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { + if (it.resultCode == REQUEST_CODE.DELETE_RECIPE) { + getRankRecipes() + } + } @SuppressLint("NotifyDataSetChanged") override fun onCreateView( @@ -63,7 +72,7 @@ class ResearchRecipeFragment : binding.researchRecipeRecyclerviewRanking.adapter = RankAdapter { recipeId -> val intent = Intent(context, RecipeDetailActivity::class.java) intent.putExtra("recipeId", recipeId) - startActivity(intent) + detailLauncher.launch(intent) } // 브랜드 아이템 클릭시 이동 @@ -87,9 +96,7 @@ class ResearchRecipeFragment : changeBrandList(mode) // 주간 랭킹 리스트 조회 - CoroutineScope(Dispatchers.IO).launch { - viewModel.getRankRecipe(getString(mode), top = 9, rankDatePeriod = 7) - } + getRankRecipes() } viewModel.errorState.observe(viewLifecycleOwner) { resId -> @@ -100,6 +107,15 @@ class ResearchRecipeFragment : return binding.root } + // 주간 랭킹 리스트 조회 + private fun getRankRecipes() = CoroutineScope(Dispatchers.IO).launch { + viewModel.getRankRecipe( + getString(viewModel.mode.value ?: R.string.common_food), + top = 9, + rankDatePeriod = 7 + ) + } + @SuppressLint("NotifyDataSetChanged") fun changeBrandList(mode: Int) { if (mode == R.string.common_beverage) { diff --git a/app/src/main/java/com/doctor/yumyum/presentation/ui/splash/SplashViewModel.kt b/app/src/main/java/com/doctor/yumyum/presentation/ui/splash/SplashViewModel.kt index bf3d22e0..c3d39f02 100644 --- a/app/src/main/java/com/doctor/yumyum/presentation/ui/splash/SplashViewModel.kt +++ b/app/src/main/java/com/doctor/yumyum/presentation/ui/splash/SplashViewModel.kt @@ -4,12 +4,7 @@ import android.util.Log import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import com.doctor.yumyum.common.base.BaseViewModel -import com.doctor.yumyum.data.model.SignInModel import com.doctor.yumyum.data.repository.LoginRepositoryImpl -import com.kakao.sdk.auth.TokenManager -import okhttp3.ResponseBody -import retrofit2.Response -import java.lang.Exception class SplashViewModel : BaseViewModel() { private val repository: LoginRepositoryImpl = LoginRepositoryImpl() @@ -18,25 +13,14 @@ class SplashViewModel : BaseViewModel() { val isLogin: LiveData get() = _isLogin - suspend fun signIn(): Boolean { - val accessToken = TokenManager.instance.getToken()?.accessToken + suspend fun signIn() { + val accessToken = repository.getLoginToken() val oauthType = repository.getLoginMode() - if (accessToken.isNullOrEmpty()) { - _isLogin.postValue(false) - return false - } - if (oauthType.isNullOrEmpty()) { - _isLogin.postValue(false) - return false - } + if (accessToken.isNullOrEmpty() || oauthType.isNullOrEmpty()) _isLogin.postValue(false) try { - val response: Response = repository.signIn( - SignInModel( - oauthType, accessToken - ) - ) + val response = repository.refreshToken() if (response.isSuccessful) { for (h in response.headers().toList()) { if (h.first == "Authorization") { @@ -44,13 +28,12 @@ class SplashViewModel : BaseViewModel() { _isLogin.postValue(true) } } - return true + } else { + _isLogin.postValue(false) } - _isLogin.postValue(false) - return false } catch (e: Exception) { + e.printStackTrace() _isLogin.postValue(false) - return false } } } \ No newline at end of file diff --git a/app/src/main/java/com/doctor/yumyum/presentation/ui/taste/TasteActivity.kt b/app/src/main/java/com/doctor/yumyum/presentation/ui/taste/TasteActivity.kt index 28f60e35..b1589931 100644 --- a/app/src/main/java/com/doctor/yumyum/presentation/ui/taste/TasteActivity.kt +++ b/app/src/main/java/com/doctor/yumyum/presentation/ui/taste/TasteActivity.kt @@ -14,66 +14,41 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch class TasteActivity : BaseActivity(R.layout.activity_taste) { - private val viewModel by lazy { + private val tasteViewModel by lazy { ViewModelProvider( this, ViewModelProvider.NewInstanceFactory() )[TasteViewModel::class.java] } - private var fromMyPage: Boolean = false + private val fromMyPage: Boolean by lazy { + intent.extras?.getBoolean(getString(R.string.taste_mode)) ?: false + } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) init() - viewModel.mode.observe(this) { mode -> - if (mode == 0) { - if (viewModel.tasteClassState.value?.size == 0) setButtonUnavailable() - else setButtonAvailable() - setStateClass() - } else { - if (viewModel.tasteDetailState.value?.size == 0) setButtonUnavailable() - else setButtonAvailable() - setStateDetail() - } + tasteViewModel.isSelected.observe(this) { isSelected -> + if (isSelected) setButtonAvailable() + else setButtonUnavailable() } - viewModel.tasteClassState.observe(this) { tasteClassState -> - if (viewModel.mode.value == 0) { - if (tasteClassState.size == 0) setButtonUnavailable() - else setButtonAvailable() - } - } - - viewModel.tasteDetailState.observe(this) { tasteDetailState -> - if (viewModel.mode.value == 1) { - if (tasteDetailState.size == 0) setButtonUnavailable() - else setButtonAvailable() - } - } - - - viewModel.tasteClassState.observe(this) { tasteClassState -> - if (viewModel.mode.value == 0) { - if (tasteClassState.size == 0) setButtonUnavailable() - else setButtonAvailable() - } - } - - viewModel.tasteDetailState.observe(this) { tasteDetailState -> - if (viewModel.mode.value == 1) { - if (tasteDetailState.size == 0) setButtonUnavailable() - else setButtonAvailable() - } + tasteViewModel.mode.observe(this) { mode -> + if (mode == 0) setStateClass() + else setStateDetail() } } fun init() { - binding.apply { - lifecycleOwner = this@TasteActivity - viewModel = viewModel - tasteToolbar.appbarTvSub.apply { + + if (fromMyPage) { + binding.tasteToolbar.appbarTvSub.visibility = View.GONE + binding.tasteTvTitle.visibility = View.GONE + binding.tasteTvSubtitle.setTextAppearance(R.style.font_h3_bold) + } + else { + binding.tasteToolbar.appbarTvSub.apply { visibility = View.VISIBLE text = getString(R.string.common_next) setOnClickListener { @@ -82,6 +57,12 @@ class TasteActivity : BaseActivity(R.layout.activity_taste } } } + } + + binding.apply { + lifecycleOwner = this@TasteActivity + viewModel = tasteViewModel + tasteToolbar.appbarIbBack.setOnClickListener { onBackPressed() } @@ -93,11 +74,10 @@ class TasteActivity : BaseActivity(R.layout.activity_taste .navigate(R.id.action_tasteClassFragment_to_tasteDetailFragment) } } - fromMyPage = intent.extras?.getBoolean(getString(R.string.taste_mode)) ?: false } private fun setStateClass() { - if (viewModel.tasteClassState.value?.size == 0) setButtonUnavailable() + if (tasteViewModel.tasteClassState.value?.size == 0) setButtonUnavailable() binding.tasteTvSubtitle.text = getString(R.string.taste_tv_class) binding.tasteBtnNext.text = getString(R.string.common_next) binding.tasteBtnNext.setOnClickListener { @@ -107,20 +87,24 @@ class TasteActivity : BaseActivity(R.layout.activity_taste } private fun setStateDetail() { - if (viewModel.tasteDetailState.value?.size == 0) setButtonUnavailable() + if (tasteViewModel.tasteDetailState.value?.size == 0) setButtonUnavailable() binding.tasteTvSubtitle.text = getString(R.string.taste_tv_detail) binding.tasteBtnNext.text = getString(R.string.common_complete) binding.tasteBtnNext.setOnClickListener { CoroutineScope(Dispatchers.IO).launch { - viewModel.postFlavor() + tasteViewModel.postFlavor() + } + if (fromMyPage) { + finish() + } else { + startActivity( + Intent( + this, + MainActivity::class.java + ).apply { + flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + }) } - startActivity( - Intent( - this, - MainActivity::class.java - ).apply { - flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK - }) } } diff --git a/app/src/main/java/com/doctor/yumyum/presentation/ui/taste/TasteViewModel.kt b/app/src/main/java/com/doctor/yumyum/presentation/ui/taste/TasteViewModel.kt index b2cbc83b..d790b5e2 100644 --- a/app/src/main/java/com/doctor/yumyum/presentation/ui/taste/TasteViewModel.kt +++ b/app/src/main/java/com/doctor/yumyum/presentation/ui/taste/TasteViewModel.kt @@ -3,6 +3,7 @@ package com.doctor.yumyum.presentation.ui.taste import android.view.View import android.widget.Button import androidx.lifecycle.LiveData +import androidx.lifecycle.MediatorLiveData import androidx.lifecycle.MutableLiveData import com.doctor.yumyum.common.base.BaseViewModel import com.doctor.yumyum.data.model.UserFlavor @@ -26,6 +27,17 @@ class TasteViewModel : BaseViewModel() { private val _mode: MutableLiveData = MutableLiveData(MODE_CLASS) val mode: LiveData = _mode + val isSelected: MediatorLiveData = MediatorLiveData().apply { + addSource(mode) { value = isStateSelected() } + addSource(tasteClassState) { value = isStateSelected() } + addSource(tasteDetailState) { value = isStateSelected() } + } + + fun isStateSelected(): Boolean { + if (mode.value == MODE_CLASS) return !tasteClassState.value.isNullOrEmpty() + else if (mode.value == MODE_DETAIL) return !tasteDetailState.value.isNullOrEmpty() + return false + } fun tasteClassChange(taste: String) { diff --git a/app/src/main/java/com/doctor/yumyum/presentation/ui/write/LoadingDialog.kt b/app/src/main/java/com/doctor/yumyum/presentation/ui/write/LoadingDialog.kt new file mode 100644 index 00000000..21ac1156 --- /dev/null +++ b/app/src/main/java/com/doctor/yumyum/presentation/ui/write/LoadingDialog.kt @@ -0,0 +1,21 @@ +package com.doctor.yumyum.presentation.ui.write + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.doctor.yumyum.R +import com.doctor.yumyum.common.base.BaseDialog +import com.doctor.yumyum.databinding.DialogLoadingBinding + +class LoadingDialog : BaseDialog(R.layout.dialog_loading) { + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + super.onCreateView(inflater, container, savedInstanceState) + isCancelable = false + return binding.root + } +} \ No newline at end of file diff --git a/app/src/main/java/com/doctor/yumyum/presentation/ui/write/WriteDialog.kt b/app/src/main/java/com/doctor/yumyum/presentation/ui/write/WriteDialog.kt index 73b76aed..186ab928 100644 --- a/app/src/main/java/com/doctor/yumyum/presentation/ui/write/WriteDialog.kt +++ b/app/src/main/java/com/doctor/yumyum/presentation/ui/write/WriteDialog.kt @@ -1,6 +1,5 @@ package com.doctor.yumyum.presentation.ui.write -import android.content.Intent import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -8,11 +7,6 @@ import android.view.ViewGroup import com.doctor.yumyum.R import com.doctor.yumyum.common.base.BaseDialog import com.doctor.yumyum.databinding.DialogWriteBinding -import com.doctor.yumyum.presentation.ui.main.MainActivity -import com.doctor.yumyum.presentation.ui.write.viewmodel.WriteViewModel -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch class WriteDialog(private val finishListener : () -> Unit) : BaseDialog(R.layout.dialog_write) { override fun onCreateView( @@ -24,6 +18,7 @@ class WriteDialog(private val finishListener : () -> Unit) : BaseDialog(R.layout.fragment WriteViewModel() as T } } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -61,30 +62,32 @@ class WriteFragment5 : BaseFragment(R.layout.fragment binding.writeBtnFinish.setOnClickListener { WriteDialog { - lifecycleScope.launch { - val postRecipe = lifecycleScope.async { + showLoading() + lifecycleScope.launch { + val postRecipe = lifecycleScope.async { writeViewModel.postRecipe() } - postRecipe.await() - activity?.finish() - } + postRecipe.await() + activity?.finish() + } + }.show(parentFragmentManager, "WriteDialog") } - writeViewModel.fifthOnFinish.observe(viewLifecycleOwner){ - if(it){ + writeViewModel.fifthOnFinish.observe(viewLifecycleOwner) { + if (it) { binding.writeBtnFinish.isEnabled = true binding.writeBtnFinish.background = resources.getDrawable(R.drawable.bg_btn_main) - }else{ + } else { binding.writeBtnFinish.isEnabled = false binding.writeBtnFinish.background = resources.getDrawable(R.drawable.bg_btn_sub) } } - writeViewModel.privateMode.observe(viewLifecycleOwner){ - if(it){ + writeViewModel.privateMode.observe(viewLifecycleOwner) { + if (it) { binding.writeFifthSwRecipePrivate.setTrackResource(R.drawable.recipe_private_sw_seleted_track) - }else{ + } else { binding.writeFifthSwRecipePrivate.setTrackResource(R.drawable.recipe_private_sw_track) } } @@ -137,10 +140,10 @@ class WriteFragment5 : BaseFragment(R.layout.fragment images.add(Pair(uri, path)) if (images.size == 3) break } - }?: intentResult?.data?.let { - images.add(Pair(it,uriToPath(requireContext(),it))) + } ?: intentResult?.data?.let { + images.add(Pair(it, uriToPath(requireContext(), it))) } - Log.d("img",images.toString()) + Log.d("img", images.toString()) writeViewModel.setReviewImageList(images) } } diff --git a/app/src/main/java/com/doctor/yumyum/presentation/ui/write/viewmodel/WriteViewModel.kt b/app/src/main/java/com/doctor/yumyum/presentation/ui/write/viewmodel/WriteViewModel.kt index 7863a322..b8e36b82 100644 --- a/app/src/main/java/com/doctor/yumyum/presentation/ui/write/viewmodel/WriteViewModel.kt +++ b/app/src/main/java/com/doctor/yumyum/presentation/ui/write/viewmodel/WriteViewModel.kt @@ -3,22 +3,17 @@ package com.doctor.yumyum.presentation.ui.write.viewmodel import android.net.Uri import android.util.Log import android.view.View -import android.widget.EditText import android.widget.TextView import androidx.lifecycle.LiveData import androidx.lifecycle.MediatorLiveData import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.viewModelScope import com.doctor.yumyum.R import com.doctor.yumyum.common.base.BaseViewModel import com.doctor.yumyum.common.utils.StatusType import com.doctor.yumyum.common.utils.TagType -import com.doctor.yumyum.data.model.FoodImage import com.doctor.yumyum.data.model.TagItem import com.doctor.yumyum.data.model.WriteRecipe import com.doctor.yumyum.data.repository.WriteRepositoryImpl -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MultipartBody import okhttp3.RequestBody.Companion.asRequestBody @@ -236,7 +231,8 @@ class WriteViewModel : BaseViewModel() { name = "images", filename = file.name, body = body - )) + ) + ) } writeRepository.postRecipeImage(recipeId = recipeId, imgList = images) } catch (e: Exception) { diff --git a/app/src/main/res/drawable/ic_loading_logo.xml b/app/src/main/res/drawable/ic_loading_logo.xml new file mode 100644 index 00000000..758b9776 --- /dev/null +++ b/app/src/main/res/drawable/ic_loading_logo.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_nickname.xml b/app/src/main/res/layout/activity_nickname.xml index a2c9f5eb..96c23267 100644 --- a/app/src/main/res/layout/activity_nickname.xml +++ b/app/src/main/res/layout/activity_nickname.xml @@ -51,7 +51,8 @@ android:textColor="@color/gray" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/nickname_tv_title" /> + app:layout_constraintTop_toBottomOf="@id/nickname_tv_title" + app:layout_goneMarginTop="26dp" /> + app:layout_constraintTop_toBottomOf="@id/taste_tv_title" + app:layout_goneMarginTop="28dp" /> + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a1ace15b..c9da66a2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -110,6 +110,7 @@ 사진을 첨부하기 위해서는 이미지 접근 권한이 필요합니다.기능 사용을 원하실 경우 휴대폰설정 > 애플리케이션 관리자에서 해당 앱의 권한을 허용해주세요. 설정 닫기 + 잠시만 기다려주세요. 재료 입력 @@ -299,7 +300,7 @@ 내정보 닉네임 수정 회원탈퇴 - + 회원탈퇴 탈퇴 사유를 선택해주세요