From d169cbac2f59cc570816dfd63e1cd90e99d6dd8f Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sun, 24 Mar 2024 22:13:41 +0900 Subject: [PATCH 001/119] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=EB=A5=BC=20=EC=9C=84=ED=95=9C=20AWS?= =?UTF-8?q?S3Api=20=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aws/model/data/remote/AWSS3Api.kt | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3Api.kt diff --git a/app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3Api.kt b/app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3Api.kt new file mode 100644 index 00000000..51eac751 --- /dev/null +++ b/app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3Api.kt @@ -0,0 +1,27 @@ +package com.project.meongcare.aws.model.data.remote + +import com.project.meongcare.aws.model.entities.AWSS3Response +import okhttp3.MultipartBody +import retrofit2.Response +import retrofit2.http.GET +import retrofit2.http.Header +import retrofit2.http.Multipart +import retrofit2.http.PUT +import retrofit2.http.Part +import retrofit2.http.Query +import retrofit2.http.Url + +interface AWSS3Api { + @GET("aws/s3") + suspend fun getPreSignedUrl( + @Header("AccessToken") accessToken: String, + @Query("fileName") fileName: String, + ): Response + + @Multipart + @PUT + suspend fun uploadImageToS3( + @Url preSignedUrl: String, + @Part file: MultipartBody.Part, + ): Response +} From c54656cff0b294ff0cae5a0fad306571a5d45c7b Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sun, 24 Mar 2024 22:14:28 +0900 Subject: [PATCH 002/119] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=EB=A5=BC=20=EC=9C=84=ED=95=9C=20Ret?= =?UTF-8?q?rofit=20Client=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/data/remote/AWSS3RetrofitClient.kt | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3RetrofitClient.kt diff --git a/app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3RetrofitClient.kt b/app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3RetrofitClient.kt new file mode 100644 index 00000000..ce33749b --- /dev/null +++ b/app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3RetrofitClient.kt @@ -0,0 +1,43 @@ +package com.project.meongcare.aws.model.data.remote + +import com.project.meongcare.BuildConfig +import okhttp3.ResponseBody +import retrofit2.Converter +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory +import java.lang.reflect.Type +import javax.inject.Inject + +class AWSS3RetrofitClient + @Inject + constructor() { + val awsS3Api: AWSS3Api by lazy { + Retrofit.Builder() + .baseUrl(BuildConfig.SEMOBAN_DEV_DOMAIN) + .addConverterFactory(nullOnEmptyConverterFactory) + .addConverterFactory(GsonConverterFactory.create()) + .build() + .create(AWSS3Api::class.java) + } + + private val nullOnEmptyConverterFactory = + object : Converter.Factory() { + fun converterFactory() = this + + override fun responseBodyConverter( + type: Type, + annotations: Array, + retrofit: Retrofit, + ) = object : Converter { + val nextResponseBodyConverter = + retrofit.nextResponseBodyConverter( + converterFactory(), + type, + annotations, + ) + + override fun convert(value: ResponseBody) = + if (value.contentLength() != 0L) nextResponseBodyConverter.convert(value) else null + } + } + } From e67e41cc95184fb0b8545fdb28f7d15857bd60bc Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sun, 24 Mar 2024 22:14:56 +0900 Subject: [PATCH 003/119] =?UTF-8?q?feat:=20AWSS3=20Repository=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aws/model/data/repository/AWSS3Repository.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3Repository.kt diff --git a/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3Repository.kt b/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3Repository.kt new file mode 100644 index 00000000..b12d9e6a --- /dev/null +++ b/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3Repository.kt @@ -0,0 +1,16 @@ +package com.project.meongcare.aws.model.data.repository + +import com.project.meongcare.aws.model.entities.AWSS3Response +import okhttp3.MultipartBody + +interface AWSS3Repository { + suspend fun getPreSignedUrl( + accessToken: String, + fileName: String, + ): AWSS3Response? + + suspend fun uploadImageToS3( + preSignedUrl: String, + file: MultipartBody.Part, + ): Int? +} From b370b23b402d68ad799e9b3d9d2c1c401eab4435 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sun, 24 Mar 2024 22:15:22 +0900 Subject: [PATCH 004/119] =?UTF-8?q?feat:=20AWSS3=20Repository=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=EC=B2=B4=EC=99=80=20=EB=AA=A8=EB=93=88=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aws/model/data/repository/AWSS3Module.kt | 15 ++++++ .../data/repository/AWSS3RepositoryImpl.kt | 53 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3Module.kt create mode 100644 app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3RepositoryImpl.kt diff --git a/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3Module.kt b/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3Module.kt new file mode 100644 index 00000000..e28bba00 --- /dev/null +++ b/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3Module.kt @@ -0,0 +1,15 @@ +package com.project.meongcare.aws.model.data.repository + +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent + +@Module +@InstallIn(SingletonComponent::class) +object AWSS3Module { + @Provides + fun provideAWSS3Repository(awsS3RepositoryImpl: AWSS3RepositoryImpl): AWSS3Repository { + return awsS3RepositoryImpl + } +} diff --git a/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3RepositoryImpl.kt b/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3RepositoryImpl.kt new file mode 100644 index 00000000..ecc4c051 --- /dev/null +++ b/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3RepositoryImpl.kt @@ -0,0 +1,53 @@ +package com.project.meongcare.aws.model.data.repository + +import android.util.Log +import com.project.meongcare.aws.model.data.remote.AWSS3RetrofitClient +import com.project.meongcare.aws.model.entities.AWSS3Response +import okhttp3.MultipartBody +import org.json.JSONObject +import java.lang.Exception +import javax.inject.Inject + +class AWSS3RepositoryImpl + @Inject + constructor(private val awsS3RetrofitClient: AWSS3RetrofitClient) : AWSS3Repository { + override suspend fun getPreSignedUrl( + accessToken: String, + fileName: String, + ): AWSS3Response? { + return try { + val response = awsS3RetrofitClient.awsS3Api.getPreSignedUrl(accessToken, fileName) + if (response.isSuccessful) { + Log.d("AWSS3Repo-getPreUrl", "통신 성공 ${response.code()}") + response.body() + } else { + val stringToJson = JSONObject(response.errorBody()?.string()!!) + Log.e("AWSS3Repo-getPreUrl", "통신 실패 ${response.code()}\n$stringToJson") + null + } + } catch (e: Exception) { + e.printStackTrace() + null + } + } + + override suspend fun uploadImageToS3( + preSignedUrl: String, + file: MultipartBody.Part, + ): Int? { + return try { + val response = awsS3RetrofitClient.awsS3Api.uploadImageToS3(preSignedUrl, file) + if (response.isSuccessful) { + Log.d("AWSS3Repo-upload", "통신 성공 ${response.code()}") + response.code() + } else { + val stringToJson = JSONObject(response.errorBody()?.string()!!) + Log.e("AWSS3Repo-upload", "통신 실패 ${response.code()}\n$stringToJson") + response.code() + } + } catch (e: Exception) { + e.printStackTrace() + null + } + } + } From 1708ba12e8ff1a4fec17ca8425b8f4f5c4f701cf Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sun, 24 Mar 2024 22:16:56 +0900 Subject: [PATCH 005/119] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=EB=A5=BC=20=EC=9C=84=ED=95=B4=20AWS?= =?UTF-8?q?S3Response=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/meongcare/aws/model/entities/AWSS3Response.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 app/src/main/java/com/project/meongcare/aws/model/entities/AWSS3Response.kt diff --git a/app/src/main/java/com/project/meongcare/aws/model/entities/AWSS3Response.kt b/app/src/main/java/com/project/meongcare/aws/model/entities/AWSS3Response.kt new file mode 100644 index 00000000..cfa204c5 --- /dev/null +++ b/app/src/main/java/com/project/meongcare/aws/model/entities/AWSS3Response.kt @@ -0,0 +1,5 @@ +package com.project.meongcare.aws.model.entities + +data class AWSS3Response( + val preSignedUrl: String, +) From 285c1536db0157177effd8758fc6c43603b93653 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sun, 24 Mar 2024 22:17:41 +0900 Subject: [PATCH 006/119] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=EB=A5=BC=20=EC=9C=84=ED=95=9C=20Vie?= =?UTF-8?q?wModel=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/aws/viewmodel/AWSS3ViewModel.kt | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 app/src/main/java/com/project/meongcare/aws/viewmodel/AWSS3ViewModel.kt diff --git a/app/src/main/java/com/project/meongcare/aws/viewmodel/AWSS3ViewModel.kt b/app/src/main/java/com/project/meongcare/aws/viewmodel/AWSS3ViewModel.kt new file mode 100644 index 00000000..c11ea4b9 --- /dev/null +++ b/app/src/main/java/com/project/meongcare/aws/viewmodel/AWSS3ViewModel.kt @@ -0,0 +1,43 @@ +package com.project.meongcare.aws.viewmodel + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.project.meongcare.aws.model.data.repository.AWSS3Repository +import com.project.meongcare.aws.model.entities.AWSS3Response +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch +import okhttp3.MultipartBody +import javax.inject.Inject + +@HiltViewModel +class AWSS3ViewModel + @Inject + constructor(private val awsS3Repository: AWSS3Repository) : ViewModel() { + private val _preSignedUrl = MutableLiveData() + val preSignedUrl: LiveData + get() = _preSignedUrl + + private val _uploadImageResponse = MutableLiveData() + val uploadImageResponse: LiveData + get() = _uploadImageResponse + + fun getPreSignedUrl( + accessToken: String, + fileName: String, + ) { + viewModelScope.launch { + _preSignedUrl.value = awsS3Repository.getPreSignedUrl(accessToken, fileName) + } + } + + fun uploadImageToS3( + preSignedUrl: String, + file: MultipartBody.Part, + ) { + viewModelScope.launch { + _uploadImageResponse.value = awsS3Repository.uploadImageToS3(preSignedUrl, file) + } + } + } From 5f4e1afd584a0828e72969d47194df302567a8b0 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sun, 24 Mar 2024 22:19:40 +0900 Subject: [PATCH 007/119] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20u?= =?UTF-8?q?ri=EC=9D=98=20Multipart=20=EB=B3=80=ED=99=98=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4=20Util=20=EA=B0=9D=EC=B2=B4=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/info/util/ProfileImageUtils.kt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 app/src/main/java/com/project/meongcare/info/util/ProfileImageUtils.kt diff --git a/app/src/main/java/com/project/meongcare/info/util/ProfileImageUtils.kt b/app/src/main/java/com/project/meongcare/info/util/ProfileImageUtils.kt new file mode 100644 index 00000000..05011e60 --- /dev/null +++ b/app/src/main/java/com/project/meongcare/info/util/ProfileImageUtils.kt @@ -0,0 +1,36 @@ +package com.project.meongcare.info.util + +import android.content.Context +import android.net.Uri +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.MultipartBody +import okhttp3.RequestBody.Companion.asRequestBody +import okhttp3.RequestBody.Companion.toRequestBody +import java.io.File +import java.util.UUID + +object ProfileImageUtils { + private fun createUUID(): String { + return UUID.randomUUID().toString() + } + + fun createMultipartFromUri( + context: Context, + uri: Uri?, + ): MultipartBody.Part { + if (uri != null) { + val inputStream = context.contentResolver.openInputStream(uri) + val file = File(context.cacheDir, createUUID()) + inputStream.use { input -> + file.outputStream().use { output -> + input?.copyTo(output) + } + } + val requestFile = file.asRequestBody("multipart/form-data".toMediaTypeOrNull()) + + return MultipartBody.Part.createFormData("file", file.name, requestFile) + } + val emptyBody = "".toRequestBody("multipart/form-data".toMediaTypeOrNull()) + return MultipartBody.Part.createFormData("file", "", emptyBody) + } +} From 83ea4a5b9b7e668c21a9d8b9239f5280615705ed Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sun, 24 Mar 2024 22:24:03 +0900 Subject: [PATCH 008/119] =?UTF-8?q?feat:=20aws=20=ED=81=B4=EB=9D=BC?= =?UTF-8?q?=EC=9A=B0=EB=93=9C=EC=97=90=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=20=EC=8B=9C=20=EC=82=AC=EC=9A=A9=ED=95=A0=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=20=EA=B2=BD=EB=A1=9C=EB=A5=BC=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20Constants=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/meongcare/aws/util/AWSS3Constants.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/src/main/java/com/project/meongcare/aws/util/AWSS3Constants.kt diff --git a/app/src/main/java/com/project/meongcare/aws/util/AWSS3Constants.kt b/app/src/main/java/com/project/meongcare/aws/util/AWSS3Constants.kt new file mode 100644 index 00000000..ab49ff04 --- /dev/null +++ b/app/src/main/java/com/project/meongcare/aws/util/AWSS3Constants.kt @@ -0,0 +1,12 @@ +package com.project.meongcare.aws.util + +// Parent Folder +const val PARENT_FOLDER_PATH = "meongcare/" + +// Sub Folder +const val DOG_FOLDER_PATH = "dog/" +const val EXCRETA_FOLDER_PATH = "excreta/" +const val FEED_FOLDER_PATH = "feed/" +const val MEDICAL_RECORD_FOLDER_PATH = "medical-record/" +const val MEMBER_FOLDER_PATH = "member/" +const val SUPPLEMENTS_FOLDER_PATH = "supplements/" From 5fb26926171a00564fe833fb60c02ca9c82061cb Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sun, 24 Mar 2024 22:37:14 +0900 Subject: [PATCH 009/119] =?UTF-8?q?refactor:=20ProfileFragment=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ViewModel을 사용해 Access Token 관리 - 각종 View 초기화하는 코드 함수화 --- .../meongcare/info/view/ProfileFragment.kt | 119 +++++++++--------- 1 file changed, 63 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt index aa752915..4a19308a 100644 --- a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt @@ -19,7 +19,6 @@ import com.google.android.gms.auth.api.signin.GoogleSignInOptions import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.kakao.sdk.user.UserApiClient import com.navercorp.nid.NaverIdLoginSDK -import com.project.meongcare.MainActivity import com.project.meongcare.R import com.project.meongcare.databinding.FragmentProfileBinding import com.project.meongcare.databinding.LayoutLogoutDialogBinding @@ -27,24 +26,24 @@ import com.project.meongcare.databinding.LayoutMedicalRecordDialogBinding import com.project.meongcare.info.viewmodel.ProfileViewModel import com.project.meongcare.login.model.data.local.UserPreferences import com.project.meongcare.login.model.data.repository.LoginRepository +import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener import com.project.meongcare.onboarding.view.createMultipartBody import com.project.meongcare.snackbar.view.CustomSnackBar import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import javax.inject.Inject @AndroidEntryPoint class ProfileFragment : Fragment(), PhotoMenuListener { private lateinit var binding: FragmentProfileBinding - private lateinit var mainActivity: MainActivity private val profileViewModel: ProfileViewModel by viewModels() + private val userViewModel: UserViewModel by viewModels() private val logoutCoroutineJob = Job() private lateinit var profileUri: Uri - private lateinit var currentAccessToken: String + private var currentAccessToken = "" @Inject lateinit var loginRepository: LoginRepository @@ -52,22 +51,25 @@ class ProfileFragment : Fragment(), PhotoMenuListener { @Inject lateinit var userPreferences: UserPreferences - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - getAccessToken() - } - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, ): View { binding = FragmentProfileBinding.inflate(inflater) - mainActivity = activity as MainActivity + return binding.root + } - profileViewModel.getUserProfile(currentAccessToken) - profileViewModel.getDogList(currentAccessToken) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + userViewModel.accessTokenPreferencesLiveData.observe(viewLifecycleOwner) { accessToken -> + if (accessToken != null) { + currentAccessToken = accessToken + profileViewModel.getUserProfile(currentAccessToken) + profileViewModel.getDogList(currentAccessToken) + } + } profileViewModel.userProfile.observe(viewLifecycleOwner) { profileResponse -> if (profileResponse != null) { @@ -184,11 +186,7 @@ class ProfileFragment : Fragment(), PhotoMenuListener { profileViewModel.patchProfileResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { - binding.run { - Glide.with(this@ProfileFragment) - .load(profileUri) - .into(imageviewProfileImage) - } + profileViewModel.getUserProfile(currentAccessToken) CustomSnackBar.make( requireView(), R.drawable.snackbar_success_16dp, @@ -208,39 +206,17 @@ class ProfileFragment : Fragment(), PhotoMenuListener { } } - binding.run { - imagebuttonProfileBack.setOnClickListener { - findNavController().popBackStack() - } - - imageviewProfileImage.setOnClickListener { - val modalBottomSheet = UserProfileSelectBottomSheetFragment() - modalBottomSheet.setPhotoMenuListener(this@ProfileFragment) - modalBottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.RoundCornerPhotoDialogTheme) - modalBottomSheet.show(mainActivity.supportFragmentManager, modalBottomSheet.tag) } - recyclerviewProfilePetList.run { - adapter = ProfileDogAdapter(layoutInflater, context) - layoutManager = LinearLayoutManager(mainActivity, LinearLayoutManager.HORIZONTAL, false) - } - - buttonProfileShare.setOnClickListener { - showUpdateDialog() - } - - buttonProfileSetting.setOnClickListener { - val bundle = Bundle() - bundle.putBoolean("pushAgreement", profileViewModel.userProfile.value?.body()?.pushAgreement!!) - findNavController().navigate(R.id.action_profileFragment_to_settingFragment, bundle) - } - - buttonProfileLogout.setOnClickListener { - showLogoutDialog() } } - return binding.root + initPetListRecyclerView() + initProfileImageView() + initBackButton() + initShareButton() + initSettingButton() + initLogoutButton() } override fun onDestroyView() { @@ -252,6 +228,47 @@ class ProfileFragment : Fragment(), PhotoMenuListener { profileUri = uri val multipartBody = createMultipartBody(requireContext(), uri) profileViewModel.patchProfileImage(currentAccessToken, multipartBody) + + private fun initPetListRecyclerView() { + binding.recyclerviewProfilePetList.run { + adapter = ProfileDogAdapter(layoutInflater, context) + layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) + } + } + + private fun initProfileImageView() { + binding.imageviewProfileImage.setOnClickListener { + val modalBottomSheet = UserProfileSelectBottomSheetFragment() + modalBottomSheet.setPhotoMenuListener(this@ProfileFragment) + modalBottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.RoundCornerPhotoDialogTheme) + modalBottomSheet.show(requireActivity().supportFragmentManager, modalBottomSheet.tag) + } + } + + private fun initBackButton() { + binding.imagebuttonProfileBack.setOnClickListener { + findNavController().popBackStack() + } + } + + private fun initShareButton() { + binding.buttonProfileShare.setOnClickListener { + showUpdateDialog() + } + } + + private fun initSettingButton() { + binding.buttonProfileSetting.setOnClickListener { + val bundle = Bundle() + bundle.putBoolean("pushAgreement", profileViewModel.userProfile.value?.body()?.pushAgreement!!) + findNavController().navigate(R.id.action_profileFragment_to_settingFragment, bundle) + } + } + + private fun initLogoutButton() { + binding.buttonProfileLogout.setOnClickListener { + showLogoutDialog() + } } private fun showLogoutDialog() { @@ -296,16 +313,6 @@ class ProfileFragment : Fragment(), PhotoMenuListener { dialog.show() } - private fun getAccessToken() { - lifecycleScope.launch { - userPreferences.accessToken.collectLatest { accessToken -> - if (accessToken != null) { - currentAccessToken = accessToken - } - } - } - } - private fun kakaoLogout() { UserApiClient.instance.logout { error -> if (error != null) { From 7394066f48d7647163d82c7dea113562262ac40a Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sun, 24 Mar 2024 22:46:16 +0900 Subject: [PATCH 010/119] =?UTF-8?q?feat:=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=88=98=EC=A0=95=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4=20preSigned=20URL=20=EB=B0=9B=EC=95=84?= =?UTF-8?q?=EC=98=A4=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/info/view/ProfileFragment.kt | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt index 4a19308a..13de3cfc 100644 --- a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt @@ -20,19 +20,23 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.kakao.sdk.user.UserApiClient import com.navercorp.nid.NaverIdLoginSDK import com.project.meongcare.R +import com.project.meongcare.aws.util.MEMBER_FOLDER_PATH +import com.project.meongcare.aws.util.PARENT_FOLDER_PATH +import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentProfileBinding import com.project.meongcare.databinding.LayoutLogoutDialogBinding import com.project.meongcare.databinding.LayoutMedicalRecordDialogBinding +import com.project.meongcare.info.util.ProfileImageUtils.createMultipartFromUri import com.project.meongcare.info.viewmodel.ProfileViewModel import com.project.meongcare.login.model.data.local.UserPreferences import com.project.meongcare.login.model.data.repository.LoginRepository import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener -import com.project.meongcare.onboarding.view.createMultipartBody import com.project.meongcare.snackbar.view.CustomSnackBar import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.Job import kotlinx.coroutines.launch +import okhttp3.MultipartBody import javax.inject.Inject @AndroidEntryPoint @@ -40,9 +44,11 @@ class ProfileFragment : Fragment(), PhotoMenuListener { private lateinit var binding: FragmentProfileBinding private val profileViewModel: ProfileViewModel by viewModels() + private val awsS3ViewModel: AWSS3ViewModel by viewModels() private val userViewModel: UserViewModel by viewModels() + + private lateinit var multipartImage: MultipartBody.Part private val logoutCoroutineJob = Job() - private lateinit var profileUri: Uri private var currentAccessToken = "" @Inject @@ -206,6 +212,8 @@ class ProfileFragment : Fragment(), PhotoMenuListener { } } + awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> + if (response != null) { } } @@ -225,9 +233,13 @@ class ProfileFragment : Fragment(), PhotoMenuListener { } override fun onUriPassed(uri: Uri) { - profileUri = uri - val multipartBody = createMultipartBody(requireContext(), uri) - profileViewModel.patchProfileImage(currentAccessToken, multipartBody) + multipartImage = createMultipartFromUri(requireContext(), uri) + val disposition = multipartImage.headers?.get("Content-Disposition") + val filename = disposition?.substringAfterLast("filename=")?.removeSurrounding("\"") ?: "tempFile" + + val filePath = "$PARENT_FOLDER_PATH$MEMBER_FOLDER_PATH$filename" + awsS3ViewModel.getPreSignedUrl(currentAccessToken, filePath) + } private fun initPetListRecyclerView() { binding.recyclerviewProfilePetList.run { From c8c63ced429ddec40e94fab73ee90b4a58cd3996 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sun, 24 Mar 2024 22:47:44 +0900 Subject: [PATCH 011/119] =?UTF-8?q?feat:=20preSigned=20URL=EC=9D=84=20?= =?UTF-8?q?=EC=9D=B4=EC=9A=A9=ED=95=B4=20=ED=81=B4=EB=9D=BC=EC=9A=B0?= =?UTF-8?q?=EB=93=9C=EC=97=90=20=ED=94=84=EB=A1=9C=ED=95=84=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/info/view/ProfileFragment.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt index 13de3cfc..0a26534e 100644 --- a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt @@ -214,8 +214,14 @@ class ProfileFragment : Fragment(), PhotoMenuListener { awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> if (response != null) { + awsS3ViewModel.uploadImageToS3(response.preSignedUrl, multipartImage) } + } + awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> + if (response == 200) { + // 저장된 이미지 경로를 데이터와 함께 서버로 전달 + // profileViewModel.patchProfileImage(currentAccessToken, multipartBody) } } From b1b6d33fafd086b08f6a1649109449ea54e059f2 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sun, 24 Mar 2024 23:57:04 +0900 Subject: [PATCH 012/119] =?UTF-8?q?fix:=20UserPreferences=EC=9D=98=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=A0=91=EA=B7=BC=EC=A0=9C=ED=95=9C?= =?UTF-8?q?=EC=9E=90=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../login/model/data/local/UserPreferences.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/login/model/data/local/UserPreferences.kt b/app/src/main/java/com/project/meongcare/login/model/data/local/UserPreferences.kt index 237f6487..1635576f 100644 --- a/app/src/main/java/com/project/meongcare/login/model/data/local/UserPreferences.kt +++ b/app/src/main/java/com/project/meongcare/login/model/data/local/UserPreferences.kt @@ -27,7 +27,7 @@ class UserPreferences private val preferenceKeyIsFirstLogin = booleanPreferencesKey("isFirstLogin") // 값 저장(수정) - private suspend fun editProvider(provider: String?) { + suspend fun editProvider(provider: String?) { context.userDataStore.edit { preferences -> if (provider == null) { preferences.remove(preferenceKeyProvider) @@ -37,7 +37,7 @@ class UserPreferences } } - private suspend fun editEmail(email: String?) { + suspend fun editEmail(email: String?) { context.userDataStore.edit { preferences -> if (email == null) { preferences.remove(preferenceKeyEmail) @@ -47,7 +47,7 @@ class UserPreferences } } - private suspend fun editAccessToken(accessToken: String?) { + suspend fun editAccessToken(accessToken: String?) { context.userDataStore.edit { preferences -> if (accessToken == null) { preferences.remove(preferenceKeyAccessToken) @@ -57,7 +57,7 @@ class UserPreferences } } - private suspend fun editRefreshToken(refreshToken: String?) { + suspend fun editRefreshToken(refreshToken: String?) { context.userDataStore.edit { preferences -> if (refreshToken == null) { preferences.remove(preferenceKeyRefreshToken) @@ -67,7 +67,7 @@ class UserPreferences } } - private suspend fun editIsFirstLogin(isFirstLogin: Boolean?) { + suspend fun editIsFirstLogin(isFirstLogin: Boolean?) { context.userDataStore.edit { preferences -> if (isFirstLogin == null) { preferences.remove(preferenceKeyIsFirstLogin) From b2a4898b282c791fd003a79afa5044f4368c8358 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Mon, 25 Mar 2024 00:03:10 +0900 Subject: [PATCH 013/119] =?UTF-8?q?feat:=20UserViewModel=EC=97=90=20UserPr?= =?UTF-8?q?eferences=20=EA=B4=80=EB=A0=A8=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AccessToken 재발급 로직 추가 - AccessToken과 Provider 값 수정하는 로직 추가 - RefreshToken, Provider, Email flow 객체를 LiveData로 변환 --- .../medicalrecord/viewmodel/UserViewModel.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/src/main/java/com/project/meongcare/medicalrecord/viewmodel/UserViewModel.kt b/app/src/main/java/com/project/meongcare/medicalrecord/viewmodel/UserViewModel.kt index 9c2a52d2..fd06c16d 100644 --- a/app/src/main/java/com/project/meongcare/medicalrecord/viewmodel/UserViewModel.kt +++ b/app/src/main/java/com/project/meongcare/medicalrecord/viewmodel/UserViewModel.kt @@ -1,9 +1,16 @@ package com.project.meongcare.medicalrecord.viewmodel +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.asLiveData +import androidx.lifecycle.viewModelScope import com.project.meongcare.login.model.data.local.UserPreferences +import com.project.meongcare.login.model.data.repository.LoginRepository +import com.project.meongcare.login.model.entities.ReissueResponse import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch +import retrofit2.Response import javax.inject.Inject @HiltViewModel @@ -11,6 +18,32 @@ class UserViewModel @Inject constructor( private val userPreferences: UserPreferences, + private val loginRepository: LoginRepository, ) : ViewModel() { val accessTokenPreferencesLiveData = userPreferences.accessToken.asLiveData() + val refreshTokenPreferencesLiveData = userPreferences.refreshToken.asLiveData() + val providerPreferencesLiveData = userPreferences.provider.asLiveData() + val emailPreferencesLiveData = userPreferences.email.asLiveData() + + private val _reissueResponse = MutableLiveData>() + val reissueResponse: LiveData> + get() = _reissueResponse + + fun getNewAccessToken(refreshToken: String) { + viewModelScope.launch { + _reissueResponse.value = loginRepository.getNewAccessToken(refreshToken) + } + } + + fun setAccessToken(accessToken: String?) { + viewModelScope.launch { + userPreferences.editAccessToken(accessToken) + } + } + + fun setProvider(provider: String?) { + viewModelScope.launch { + userPreferences.editProvider(provider) + } + } } From 28a3ea6b9f46e598e5440b6db1d06e3c1b646106 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Mon, 25 Mar 2024 00:05:21 +0900 Subject: [PATCH 014/119] =?UTF-8?q?fix:=20View=EC=97=90=EC=84=9C=20LoginRe?= =?UTF-8?q?pository=EC=99=80=20UserPreferences=EB=A5=BC=20=EC=A7=81?= =?UTF-8?q?=EC=A0=91=20=EC=A3=BC=EC=9E=85=EB=B0=9B=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ViewModel을 이용해 LoginRepository의 함수 호출, UserPreferences의 값 접근 --- .../meongcare/info/view/ProfileFragment.kt | 160 +++++++++--------- 1 file changed, 76 insertions(+), 84 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt index 0a26534e..692f66b6 100644 --- a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt @@ -28,13 +28,10 @@ import com.project.meongcare.databinding.LayoutLogoutDialogBinding import com.project.meongcare.databinding.LayoutMedicalRecordDialogBinding import com.project.meongcare.info.util.ProfileImageUtils.createMultipartFromUri import com.project.meongcare.info.viewmodel.ProfileViewModel -import com.project.meongcare.login.model.data.local.UserPreferences -import com.project.meongcare.login.model.data.repository.LoginRepository import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener import com.project.meongcare.snackbar.view.CustomSnackBar import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.Job import kotlinx.coroutines.launch import okhttp3.MultipartBody import javax.inject.Inject @@ -42,20 +39,15 @@ import javax.inject.Inject @AndroidEntryPoint class ProfileFragment : Fragment(), PhotoMenuListener { private lateinit var binding: FragmentProfileBinding + private lateinit var multipartImage: MultipartBody.Part private val profileViewModel: ProfileViewModel by viewModels() private val awsS3ViewModel: AWSS3ViewModel by viewModels() private val userViewModel: UserViewModel by viewModels() - private lateinit var multipartImage: MultipartBody.Part - private val logoutCoroutineJob = Job() private var currentAccessToken = "" - - @Inject - lateinit var loginRepository: LoginRepository - - @Inject - lateinit var userPreferences: UserPreferences + private var currentRefreshToken = "" + private var currentProvider = "" override fun onCreateView( inflater: LayoutInflater, @@ -69,13 +61,9 @@ class ProfileFragment : Fragment(), PhotoMenuListener { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - userViewModel.accessTokenPreferencesLiveData.observe(viewLifecycleOwner) { accessToken -> - if (accessToken != null) { - currentAccessToken = accessToken - profileViewModel.getUserProfile(currentAccessToken) - profileViewModel.getDogList(currentAccessToken) - } - } + getAccessToken() + getProvider() + getEmail() profileViewModel.userProfile.observe(viewLifecycleOwner) { profileResponse -> if (profileResponse != null) { @@ -86,29 +74,13 @@ class ProfileFragment : Fragment(), PhotoMenuListener { .load(profileResponse.body()?.imageUrl) .error(R.drawable.profile_default_image) .into(imageviewProfileImage) - textviewProfileEmail.text = profileResponse.body()?.email } } 401 -> { lifecycleScope.launch { - val refreshToken = userPreferences.getRefreshToken() + val refreshToken = currentRefreshToken if (refreshToken.isNotEmpty()) { - val response = loginRepository.getNewAccessToken(refreshToken) - if (response != null) { - when (response.code()) { - 200 -> { - userPreferences.setAccessToken(response.body()?.accessToken!!) - } - 401 -> { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_refresh_expire), - ).show() - findNavController().navigate(R.id.action_profileFragment_to_loginFragment) - } - } - } + reissueAccessToken() } } } @@ -134,24 +106,9 @@ class ProfileFragment : Fragment(), PhotoMenuListener { } 401 -> { lifecycleScope.launch { - val refreshToken = userPreferences.getRefreshToken() + val refreshToken = currentRefreshToken if (refreshToken.isNotEmpty()) { - val response = loginRepository.getNewAccessToken(refreshToken) - if (response != null) { - when (response.code()) { - 200 -> { - userPreferences.setAccessToken(response.body()?.accessToken!!) - } - 401 -> { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_refresh_expire), - ).show() - findNavController().navigate(R.id.action_profileFragment_to_loginFragment) - } - } - } + reissueAccessToken() } } } @@ -172,14 +129,10 @@ class ProfileFragment : Fragment(), PhotoMenuListener { profileViewModel.logoutResponse.observe(viewLifecycleOwner) { response -> if (response != null) { - lifecycleScope.launch(logoutCoroutineJob) { - userPreferences.provider.collect { provider -> - when (provider) { - "kakao" -> kakaoLogout() - "naver" -> naverLogout() - "google" -> googleLogout() - } - } + when (currentProvider) { + "kakao" -> kakaoLogout() + "naver" -> naverLogout() + "google" -> googleLogout() } } else { CustomSnackBar.make( @@ -199,11 +152,6 @@ class ProfileFragment : Fragment(), PhotoMenuListener { getString(R.string.snack_bar_profile_update_complete), ).show() } else { - binding.run { - Glide.with(this@ProfileFragment) - .load(R.drawable.profile_default_image) - .into(imageviewProfileImage) - } CustomSnackBar.make( requireView(), R.drawable.snackbar_error_16dp, @@ -233,11 +181,6 @@ class ProfileFragment : Fragment(), PhotoMenuListener { initLogoutButton() } - override fun onDestroyView() { - super.onDestroyView() - logoutCoroutineJob.cancel() - } - override fun onUriPassed(uri: Uri) { multipartImage = createMultipartFromUri(requireContext(), uri) val disposition = multipartImage.headers?.get("Content-Disposition") @@ -247,6 +190,60 @@ class ProfileFragment : Fragment(), PhotoMenuListener { awsS3ViewModel.getPreSignedUrl(currentAccessToken, filePath) } + private fun reissueAccessToken() { + userViewModel.getNewAccessToken(currentRefreshToken) + userViewModel.reissueResponse.observe(viewLifecycleOwner) { response -> + if (response != null) { + when (response.code()) { + 200 -> { + userViewModel.setAccessToken(response.body()?.accessToken) + } + 401 -> { + CustomSnackBar.make( + requireView(), + R.drawable.snackbar_error_16dp, + getString(R.string.snack_bar_refresh_expire), + ).show() + findNavController().navigate(R.id.action_profileFragment_to_loginFragment) + } + } + } + } + } + + private fun getAccessToken() { + userViewModel.accessTokenPreferencesLiveData.observe(viewLifecycleOwner) { accessToken -> + if (accessToken != null) { + currentAccessToken = accessToken + getRefreshToken() + } + } + } + + private fun getRefreshToken() { + userViewModel.refreshTokenPreferencesLiveData.observe(viewLifecycleOwner) { refreshToken -> + if (refreshToken != null) { + currentRefreshToken = refreshToken + profileViewModel.getUserProfile(currentAccessToken) + profileViewModel.getDogList(currentAccessToken) + } + } + } + + private fun getProvider() { + userViewModel.providerPreferencesLiveData.observe(viewLifecycleOwner) { provider -> + if (provider != null) { + currentProvider = provider + } + } + } + + private fun getEmail() { + userViewModel.emailPreferencesLiveData.observe(viewLifecycleOwner) { email -> + binding.textviewProfileEmail.text = email ?: "" + } + } + private fun initPetListRecyclerView() { binding.recyclerviewProfilePetList.run { adapter = ProfileDogAdapter(layoutInflater, context) @@ -299,13 +296,8 @@ class ProfileFragment : Fragment(), PhotoMenuListener { dialogBinding.run { buttonLogoutDialogLogout.setOnClickListener { - lifecycleScope.launch(logoutCoroutineJob) { - val refreshToken = userPreferences.getRefreshToken() - if (refreshToken != null) { - dialog.dismiss() - profileViewModel.logoutUser(refreshToken) - } - } + dialog.dismiss() + profileViewModel.logoutUser(currentRefreshToken) } buttonLogoutDialogCancel.setOnClickListener { @@ -337,8 +329,8 @@ class ProfileFragment : Fragment(), PhotoMenuListener { Log.e("Logout-kakao", "로그아웃 실패, SDK에서 토큰 삭제됨\n $error") } else { Log.i("Logout-kakao", "로그아웃 성공, SDK에서 토큰 삭제됨") - userPreferences.setProvider(null) - userPreferences.setAccessToken(null) + userViewModel.setProvider(null) + userViewModel.setAccessToken(null) findNavController().navigate(R.id.action_profileFragment_to_loginFragment) } } @@ -346,8 +338,8 @@ class ProfileFragment : Fragment(), PhotoMenuListener { private fun naverLogout() { NaverIdLoginSDK.logout() - userPreferences.setProvider(null) - userPreferences.setAccessToken(null) + userViewModel.setProvider(null) + userViewModel.setAccessToken(null) findNavController().navigate(R.id.action_profileFragment_to_loginFragment) } @@ -365,8 +357,8 @@ class ProfileFragment : Fragment(), PhotoMenuListener { .addOnCompleteListener { task -> if (task.isSuccessful) { Log.d("Logout-google", "로그아웃 성공") - userPreferences.setProvider(null) - userPreferences.setAccessToken(null) + userViewModel.setProvider(null) + userViewModel.setAccessToken(null) findNavController().navigate(R.id.action_profileFragment_to_loginFragment) } else { Log.e("Logout-google", "로그아웃 실패") From 12a961e2420651326bad0131f464a2c8401a2831 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Mon, 25 Mar 2024 00:06:48 +0900 Subject: [PATCH 015/119] =?UTF-8?q?fix:=20AWS=20S3=20Retrofit=20Client?= =?UTF-8?q?=EC=9D=98=20Builder=20baseUrl=EC=9D=84=20=EC=9A=B4=EC=98=81=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=20=EB=8F=84=EB=A9=94=EC=9D=B8=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/aws/model/data/remote/AWSS3RetrofitClient.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3RetrofitClient.kt b/app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3RetrofitClient.kt index ce33749b..aca6bc66 100644 --- a/app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3RetrofitClient.kt +++ b/app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3RetrofitClient.kt @@ -13,7 +13,7 @@ class AWSS3RetrofitClient constructor() { val awsS3Api: AWSS3Api by lazy { Retrofit.Builder() - .baseUrl(BuildConfig.SEMOBAN_DEV_DOMAIN) + .baseUrl(BuildConfig.SEMOBAN_DOMAIN) .addConverterFactory(nullOnEmptyConverterFactory) .addConverterFactory(GsonConverterFactory.create()) .build() From 0054b6de5e5288b2f22d397e6e679eaf15f32a83 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 27 Mar 2024 15:15:15 +0900 Subject: [PATCH 016/119] =?UTF-8?q?rename:=20ProfileImageUtils=20->=20AWSS?= =?UTF-8?q?3ImageUtils=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 패키지도 info.util에서 aws.util로 변경 --- .../util/ProfileImageUtils.kt => aws/util/AWSS3ImageUtils.kt} | 2 +- .../java/com/project/meongcare/info/view/ProfileFragment.kt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) rename app/src/main/java/com/project/meongcare/{info/util/ProfileImageUtils.kt => aws/util/AWSS3ImageUtils.kt} (96%) diff --git a/app/src/main/java/com/project/meongcare/info/util/ProfileImageUtils.kt b/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt similarity index 96% rename from app/src/main/java/com/project/meongcare/info/util/ProfileImageUtils.kt rename to app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt index 05011e60..c3aaf9f2 100644 --- a/app/src/main/java/com/project/meongcare/info/util/ProfileImageUtils.kt +++ b/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt @@ -1,4 +1,4 @@ -package com.project.meongcare.info.util +package com.project.meongcare.aws.util import android.content.Context import android.net.Uri diff --git a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt index 692f66b6..32f40f18 100644 --- a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt @@ -26,7 +26,7 @@ import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentProfileBinding import com.project.meongcare.databinding.LayoutLogoutDialogBinding import com.project.meongcare.databinding.LayoutMedicalRecordDialogBinding -import com.project.meongcare.info.util.ProfileImageUtils.createMultipartFromUri +import com.project.meongcare.aws.util.ProfileImageUtils.createMultipartFromUri import com.project.meongcare.info.viewmodel.ProfileViewModel import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener @@ -34,7 +34,6 @@ import com.project.meongcare.snackbar.view.CustomSnackBar import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch import okhttp3.MultipartBody -import javax.inject.Inject @AndroidEntryPoint class ProfileFragment : Fragment(), PhotoMenuListener { From b053ad56da0f6848ea6b7da112e971cd49827952 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 27 Mar 2024 17:21:29 +0900 Subject: [PATCH 017/119] =?UTF-8?q?feat:=20UserViewModel=EC=97=90=20Refres?= =?UTF-8?q?hToken,=20IsFirstLogin,=20Email=20=EA=B0=92=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../medicalrecord/viewmodel/UserViewModel.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/main/java/com/project/meongcare/medicalrecord/viewmodel/UserViewModel.kt b/app/src/main/java/com/project/meongcare/medicalrecord/viewmodel/UserViewModel.kt index fd06c16d..c98aadc6 100644 --- a/app/src/main/java/com/project/meongcare/medicalrecord/viewmodel/UserViewModel.kt +++ b/app/src/main/java/com/project/meongcare/medicalrecord/viewmodel/UserViewModel.kt @@ -46,4 +46,22 @@ class UserViewModel userPreferences.editProvider(provider) } } + + fun setRefreshToken(refreshToken: String?) { + viewModelScope.launch { + userPreferences.editRefreshToken(refreshToken) + } + } + + fun setIsFirstLogin(isFirstLogin: Boolean?) { + viewModelScope.launch { + userPreferences.editIsFirstLogin(isFirstLogin) + } + } + + fun setEmail(email: String?) { + viewModelScope.launch { + userPreferences.editEmail(email) + } + } } From d7902af9e7dc744f4b9e8132cfc6ec957dfcc1f2 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 27 Mar 2024 17:22:45 +0900 Subject: [PATCH 018/119] =?UTF-8?q?feat:=20AWSS3ImageUtil=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=EC=97=90=20Multipart=20=ED=8C=8C=EC=9D=BC=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=B6=94=EC=B6=9C=ED=95=98=EB=8A=94=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt b/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt index c3aaf9f2..0652fcb6 100644 --- a/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt +++ b/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt @@ -33,4 +33,9 @@ object ProfileImageUtils { val emptyBody = "".toRequestBody("multipart/form-data".toMediaTypeOrNull()) return MultipartBody.Part.createFormData("file", "", emptyBody) } + + fun getMultipartFileName(file: MultipartBody.Part): String { + val disposition = file.headers?.get("Content-Disposition") + return disposition?.substringAfterLast("filename=")?.removeSurrounding("\"") ?: "tempFile" + } } From ccef1f63fbfcfb0c602d9a1354a775692c42d749 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 27 Mar 2024 17:24:44 +0900 Subject: [PATCH 019/119] =?UTF-8?q?fix:=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=ED=99=94=EB=A9=B4=EC=97=90=EC=84=9C=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EC=B6=94=EC=B6=9C=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20getMultipartFileName=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=EB=A1=9C=20=EB=8C=80=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/meongcare/info/view/ProfileFragment.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt index 32f40f18..3fbee991 100644 --- a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt @@ -27,6 +27,7 @@ import com.project.meongcare.databinding.FragmentProfileBinding import com.project.meongcare.databinding.LayoutLogoutDialogBinding import com.project.meongcare.databinding.LayoutMedicalRecordDialogBinding import com.project.meongcare.aws.util.ProfileImageUtils.createMultipartFromUri +import com.project.meongcare.aws.util.ProfileImageUtils.getMultipartFileName import com.project.meongcare.info.viewmodel.ProfileViewModel import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener @@ -39,6 +40,7 @@ import okhttp3.MultipartBody class ProfileFragment : Fragment(), PhotoMenuListener { private lateinit var binding: FragmentProfileBinding private lateinit var multipartImage: MultipartBody.Part + private lateinit var fileName: String private val profileViewModel: ProfileViewModel by viewModels() private val awsS3ViewModel: AWSS3ViewModel by viewModels() @@ -182,10 +184,9 @@ class ProfileFragment : Fragment(), PhotoMenuListener { override fun onUriPassed(uri: Uri) { multipartImage = createMultipartFromUri(requireContext(), uri) - val disposition = multipartImage.headers?.get("Content-Disposition") - val filename = disposition?.substringAfterLast("filename=")?.removeSurrounding("\"") ?: "tempFile" + fileName = getMultipartFileName(multipartImage) - val filePath = "$PARENT_FOLDER_PATH$MEMBER_FOLDER_PATH$filename" + val filePath = "$PARENT_FOLDER_PATH$MEMBER_FOLDER_PATH$fileName" awsS3ViewModel.getPreSignedUrl(currentAccessToken, filePath) } From 8c73927d7c398fb2ef88db352d437b211c5d94d0 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 27 Mar 2024 17:29:52 +0900 Subject: [PATCH 020/119] =?UTF-8?q?fix:=20binding=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - fragmentLoginBinding -> binding --- .../meongcare/login/view/LoginFragment.kt | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt b/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt index c177436f..3951b4f2 100644 --- a/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt +++ b/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt @@ -41,8 +41,8 @@ import javax.inject.Inject @AndroidEntryPoint class LoginFragment : Fragment() { - lateinit var fragmentLoginBinding: FragmentLoginBinding lateinit var mainActivity: MainActivity + private lateinit var binding: FragmentLoginBinding private val googleSignInClient: GoogleSignInClient by lazy { getGoogleClient() } val googleAuthLauncher = @@ -61,8 +61,10 @@ class LoginFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle?, ): View? { - fragmentLoginBinding = FragmentLoginBinding.inflate(inflater) mainActivity = activity as MainActivity + binding = FragmentLoginBinding.inflate(inflater) + return binding.root + } loginViewModel.loginResponse.observe(viewLifecycleOwner) { loginResponse -> if (loginResponse != null) { @@ -113,19 +115,19 @@ class LoginFragment : Fragment() { } } - fragmentLoginBinding.run { - buttonKakaoLogin.setOnClickListener { - kakaoLogin() - } - buttonNaverLogin.setOnClickListener { - naverLogin() - } - buttonGoogleLogin.setOnClickListener { - googleLogin() } } + binding.buttonKakaoLogin.setOnClickListener { + kakaoLogin() + } - return fragmentLoginBinding.root + binding.buttonNaverLogin.setOnClickListener { + naverLogin() + } + + binding.buttonGoogleLogin.setOnClickListener { + googleLogin() + } } private fun kakaoLogin() { From 84f1741a911c611a49dc620c310163cb4a1dd76c Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 27 Mar 2024 17:32:06 +0900 Subject: [PATCH 021/119] =?UTF-8?q?fix:=20Login=20Fragment=EC=97=90?= =?UTF-8?q?=EC=84=9C=20mainActivity=20=EA=B0=9D=EC=B2=B4=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - context 인자는 requireContext(), activity 인자는 requireActivity()로 대체 --- .../project/meongcare/login/view/LoginFragment.kt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt b/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt index 3951b4f2..ec7005e7 100644 --- a/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt +++ b/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt @@ -26,7 +26,6 @@ import com.navercorp.nid.oauth.OAuthLoginCallback import com.navercorp.nid.profile.NidProfileCallback import com.navercorp.nid.profile.data.NidProfileResponse import com.project.meongcare.BuildConfig -import com.project.meongcare.MainActivity import com.project.meongcare.R import com.project.meongcare.databinding.FragmentLoginBinding import com.project.meongcare.login.model.data.local.UserPreferences @@ -41,7 +40,6 @@ import javax.inject.Inject @AndroidEntryPoint class LoginFragment : Fragment() { - lateinit var mainActivity: MainActivity private lateinit var binding: FragmentLoginBinding private val googleSignInClient: GoogleSignInClient by lazy { getGoogleClient() } @@ -61,7 +59,6 @@ class LoginFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle?, ): View? { - mainActivity = activity as MainActivity binding = FragmentLoginBinding.inflate(inflater) return binding.root } @@ -143,8 +140,8 @@ class LoginFragment : Fragment() { } // 카카오톡이 설치되어 있으면 카카오톡으로 로그인, 아니면 카카오계정으로 로그인 - if (UserApiClient.instance.isKakaoTalkLoginAvailable(mainActivity)) { - UserApiClient.instance.loginWithKakaoTalk(mainActivity) { token, error -> + if (UserApiClient.instance.isKakaoTalkLoginAvailable(requireContext())) { + UserApiClient.instance.loginWithKakaoTalk(requireContext()) { token, error -> if (error != null) { Log.e("Login-kakao", "카카오톡으로 로그인 실패", error) @@ -155,14 +152,14 @@ class LoginFragment : Fragment() { } // 카카오톡에 연결된 카카오계정이 없는 경우, 카카오계정으로 로그인 시도 - UserApiClient.instance.loginWithKakaoAccount(mainActivity, callback = callback) + UserApiClient.instance.loginWithKakaoAccount(requireContext(), callback = callback) } else if (token != null) { Log.i("Login-kakao", "카카오톡으로 로그인 성공") getKakaoLoginInfo() } } } else { - UserApiClient.instance.loginWithKakaoAccount(mainActivity, callback = callback) + UserApiClient.instance.loginWithKakaoAccount(requireContext(), callback = callback) } } @@ -258,7 +255,7 @@ class LoginFragment : Fragment() { NidOAuthLogin().callProfileApi(nidProfileCallback) } } - NaverIdLoginSDK.authenticate(mainActivity, oauthLoginCallback) + NaverIdLoginSDK.authenticate(requireContext(), oauthLoginCallback) } private fun googleLogin() { @@ -275,7 +272,7 @@ class LoginFragment : Fragment() { .requestServerAuthCode(BuildConfig.GOOGLE_CLIENT_ID) .build() - return GoogleSignIn.getClient(mainActivity, googleSignInOptions) + return GoogleSignIn.getClient(requireActivity(), googleSignInOptions) } private fun getGoogleResult(task: Task) { From f65021938bc9ae9f937d33a977e3d5a1652d8def Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 27 Mar 2024 17:34:47 +0900 Subject: [PATCH 022/119] =?UTF-8?q?fix:=20Login=20Fragment=EC=97=90?= =?UTF-8?q?=EC=84=9C=20UserPreferences=20=EC=A7=81=EC=A0=91=20=EC=A3=BC?= =?UTF-8?q?=EC=9E=85=EB=B0=9B=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - UserViewModel을 통해 DataStore 객체에 접근 - provider 값 받아오는 함수 정의 --- .../meongcare/login/view/LoginFragment.kt | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt b/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt index ec7005e7..dbea8539 100644 --- a/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt +++ b/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt @@ -8,7 +8,6 @@ import android.view.ViewGroup import androidx.activity.result.contract.ActivityResultContracts import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels -import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignInAccount @@ -28,19 +27,18 @@ import com.navercorp.nid.profile.data.NidProfileResponse import com.project.meongcare.BuildConfig import com.project.meongcare.R import com.project.meongcare.databinding.FragmentLoginBinding -import com.project.meongcare.login.model.data.local.UserPreferences import com.project.meongcare.login.model.data.repository.FirebaseCloudMessagingService import com.project.meongcare.login.model.entities.LoginRequest import com.project.meongcare.login.viewmodel.LoginViewModel +import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.snackbar.view.CustomSnackBar import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking -import javax.inject.Inject @AndroidEntryPoint class LoginFragment : Fragment() { private lateinit var binding: FragmentLoginBinding + private lateinit var provider: String private val googleSignInClient: GoogleSignInClient by lazy { getGoogleClient() } val googleAuthLauncher = @@ -49,11 +47,9 @@ class LoginFragment : Fragment() { getGoogleResult(task) } private val loginViewModel: LoginViewModel by viewModels() + private val userViewModel: UserViewModel by viewModels() private val myFirebaseMessagingService = FirebaseCloudMessagingService() - @Inject - lateinit var userPreferences: UserPreferences - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -70,9 +66,9 @@ class LoginFragment : Fragment() { // 로그인 성공 if (loginResponse.body() != null) { Log.e("isFirstLogin", loginResponse.body()?.isFirstLogin.toString()) - userPreferences.setAccessToken(loginResponse.body()?.accessToken) - userPreferences.setRefreshToken(loginResponse.body()?.refreshToken) - userPreferences.setIsFirstLogin(loginResponse.body()?.isFirstLogin) + userViewModel.setAccessToken(loginResponse.body()?.accessToken) + userViewModel.setRefreshToken(loginResponse.body()?.refreshToken) + userViewModel.setIsFirstLogin(loginResponse.body()?.isFirstLogin) when (loginResponse.body()?.isFirstLogin) { true -> { val bundle = Bundle() @@ -91,13 +87,10 @@ class LoginFragment : Fragment() { R.drawable.snackbar_error_16dp, getString(R.string.snack_bar_login_failure_deleted), ) - lifecycleScope.launch { - val provider = userPreferences.getProvider() - when (provider) { - "kakao" -> deleteKakaoAccount() - "naver" -> deleteNaverAccount() - "google" -> deleteGoogleAccount() - } + when (provider) { + "kakao" -> deleteKakaoAccount() + "naver" -> deleteNaverAccount() + "google" -> deleteGoogleAccount() } } else -> { @@ -106,14 +99,19 @@ class LoginFragment : Fragment() { R.drawable.snackbar_error_16dp, getString(R.string.snack_bar_login_failure), ) - Log.d("Login", "통신 실패") } } } } + } + private fun getProvider() { + userViewModel.providerPreferencesLiveData.observe(viewLifecycleOwner) { provider -> + if (provider != null) { + this.provider = provider } } + } binding.buttonKakaoLogin.setOnClickListener { kakaoLogin() } @@ -173,8 +171,8 @@ class LoginFragment : Fragment() { val deviceToken = getDeviceToken() // data store에 저장 - userPreferences.setEmail(user.kakaoAccount?.email!!) - userPreferences.setProvider("kakao") + userViewModel.setEmail(user.kakaoAccount?.email!!) + userViewModel.setProvider("kakao") val loginRequest = LoginRequest( @@ -215,8 +213,8 @@ class LoginFragment : Fragment() { val deviceToken = getDeviceToken() // data store에 저장 - userPreferences.setEmail(result.profile?.email!!) - userPreferences.setProvider("naver") + userViewModel.setEmail(result.profile?.email!!) + userViewModel.setProvider("naver") // 서버에 로그인 정보 전송 val loginRequest = @@ -281,8 +279,8 @@ class LoginFragment : Fragment() { val deviceToken = getDeviceToken() // data store에 저장 - userPreferences.setEmail(account.email!!) - userPreferences.setProvider("google") + userViewModel.setEmail(account.email!!) + userViewModel.setProvider("google") val loginRequest = LoginRequest( From 276ffb24f5e21491514ce694d1205f58914ffc07 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 27 Mar 2024 17:37:00 +0900 Subject: [PATCH 023/119] =?UTF-8?q?refactor:=20Login=20Fragment=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - addListeners() 함수에 버튼 클릭 리스너 정의 - 뷰 초기화 및 LiveData Observe를 수행하는 콜백함수 onCreateView -> onViewCreated 변경 --- .../com/project/meongcare/login/view/LoginFragment.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt b/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt index dbea8539..3f4abaa6 100644 --- a/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt +++ b/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt @@ -59,6 +59,15 @@ class LoginFragment : Fragment() { return binding.root } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + getProvider() + addListeners() + loginResponseProcess() + } + + private fun loginResponseProcess() { loginViewModel.loginResponse.observe(viewLifecycleOwner) { loginResponse -> if (loginResponse != null) { when (loginResponse.code()) { @@ -112,6 +121,8 @@ class LoginFragment : Fragment() { } } } + + private fun addListeners() { binding.buttonKakaoLogin.setOnClickListener { kakaoLogin() } From a1b6ef85c241622993bc5ea2f54dd851623cf894 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 28 Mar 2024 16:06:39 +0900 Subject: [PATCH 024/119] =?UTF-8?q?fix:=20=EC=98=A8=EB=B3=B4=EB=94=A9=20Fr?= =?UTF-8?q?agment=EC=97=90=EC=84=9C=20mainActivity=20=EA=B0=9D=EC=B2=B4=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - context 인자는 requireContext(), activity 인자는 requireActivity()로 대체 --- .../onboarding/view/DogAddOnBoardingFragment.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt index 7b97783c..3cbbf743 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt @@ -16,7 +16,6 @@ import com.bumptech.glide.Glide import com.google.android.material.chip.Chip import com.google.gson.Gson import com.project.meongcare.BirthdayBottomSheetFragment -import com.project.meongcare.MainActivity import com.project.meongcare.R import com.project.meongcare.databinding.FragmentDogAddOnBoardingBinding import com.project.meongcare.login.model.data.local.UserPreferences @@ -43,7 +42,6 @@ import javax.inject.Inject @AndroidEntryPoint class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListener { lateinit var fragmentDogAddOnBoardingBinding: FragmentDogAddOnBoardingBinding - lateinit var mainActivity: MainActivity private val dogAddViewModel: DogAddViewModel by viewModels() private val dogTypeSharedViewModel: DogTypeSharedViewModel by activityViewModels() @@ -70,7 +68,6 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen savedInstanceState: Bundle?, ): View? { fragmentDogAddOnBoardingBinding = FragmentDogAddOnBoardingBinding.inflate(inflater) - mainActivity = activity as MainActivity dogAddViewModel.dogProfileImage.observe(viewLifecycleOwner) { uri -> if (uri != null) { @@ -157,7 +154,7 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen modalBottomSheet.setPhotoMenuListener(this@DogAddOnBoardingFragment) // 둥근 모서리 지정 modalBottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.RoundCornerPhotoDialogTheme) - modalBottomSheet.show(mainActivity.supportFragmentManager, modalBottomSheet.tag) + modalBottomSheet.show(requireActivity().supportFragmentManager, modalBottomSheet.tag) } // 품종 등록 @@ -174,7 +171,7 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen ) birthdayBottomSheet.setDateSubmitListener(this@DogAddOnBoardingFragment) birthdayBottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.RoundCornerBirthdayDialogTheme) - birthdayBottomSheet.show(mainActivity.supportFragmentManager, birthdayBottomSheet.tag) + birthdayBottomSheet.show(requireActivity().supportFragmentManager, birthdayBottomSheet.tag) } checkboxPetaddNeuterStatus.setOnCheckedChangeListener { buttonView, isChecked -> @@ -251,7 +248,7 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen ) val json = Gson().toJson(dog) val requestBody: RequestBody = json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) - val filePart = createMultipartBody(mainActivity, dogAddViewModel.dogProfileImage.value) + val filePart = createMultipartBody(requireContext(), dogAddViewModel.dogProfileImage.value) lifecycleScope.launch(postDogCoroutineJob) { userPreferences.accessToken.collectLatest { accessToken -> From c4e916ad52b9f27e31d3325457e20e9ba39489df Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 28 Mar 2024 16:08:11 +0900 Subject: [PATCH 025/119] =?UTF-8?q?fix:=20binding=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - fragmentDogAddOnBoardingBinding -> binding --- .../view/DogAddOnBoardingFragment.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt index 3cbbf743..46b5beee 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt @@ -41,7 +41,7 @@ import javax.inject.Inject @AndroidEntryPoint class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListener { - lateinit var fragmentDogAddOnBoardingBinding: FragmentDogAddOnBoardingBinding + lateinit var binding: FragmentDogAddOnBoardingBinding private val dogAddViewModel: DogAddViewModel by viewModels() private val dogTypeSharedViewModel: DogTypeSharedViewModel by activityViewModels() @@ -67,11 +67,11 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen container: ViewGroup?, savedInstanceState: Bundle?, ): View? { - fragmentDogAddOnBoardingBinding = FragmentDogAddOnBoardingBinding.inflate(inflater) + binding = FragmentDogAddOnBoardingBinding.inflate(inflater) dogAddViewModel.dogProfileImage.observe(viewLifecycleOwner) { uri -> if (uri != null) { - fragmentDogAddOnBoardingBinding.run { + binding.run { Glide.with(this@DogAddOnBoardingFragment) .load(uri) .into(imageviewPetaddImage) @@ -83,8 +83,8 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen dogAddViewModel.dogBirthDate.observe(viewLifecycleOwner) { date -> if (date != null) { - fragmentDogAddOnBoardingBinding.textviewPetaddSelectBirthday.run { - fragmentDogAddOnBoardingBinding.edittextPetaddSelectBirthdayError.visibility = View.INVISIBLE + binding.textviewPetaddSelectBirthday.run { + binding.edittextPetaddSelectBirthdayError.visibility = View.INVISIBLE text = dateFormat(date) setTextAppearance(R.style.Typography_Body1_Medium) } @@ -93,8 +93,8 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen dogTypeSharedViewModel.selectedDogType.observe(viewLifecycleOwner) { dogType -> if (dogType != null) { - fragmentDogAddOnBoardingBinding.edittextPetaddSelectType.run { - fragmentDogAddOnBoardingBinding.edittextPetaddSelectTypeError.visibility = View.GONE + binding.edittextPetaddSelectType.run { + binding.edittextPetaddSelectTypeError.visibility = View.GONE text = dogType setTextAppearance(R.style.Typography_Body1_Medium) } @@ -142,7 +142,7 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen } } - fragmentDogAddOnBoardingBinding.run { + binding.run { when (isFirstRegister) { true -> buttonCancel.visibility = View.GONE false, null -> buttonCancel.visibility = View.VISIBLE @@ -166,7 +166,7 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen textviewPetaddSelectBirthday.setOnClickListener { val birthdayBottomSheet = BirthdayBottomSheetFragment( - fragmentDogAddOnBoardingBinding.root, + binding.root, dogAddViewModel.dogBirthDate.value, ) birthdayBottomSheet.setDateSubmitListener(this@DogAddOnBoardingFragment) @@ -228,7 +228,7 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen val dogName = edittextPetaddName.text.toString() val dogType = edittextPetaddSelectType.text.toString() - val dogGender = getCheckedGender(fragmentDogAddOnBoardingBinding.root, chipgroupPetaddGroupGender.checkedChipId) + val dogGender = getCheckedGender(binding.root, chipgroupPetaddGroupGender.checkedChipId) val dogBirth = dogAddViewModel.dogBirthDate.value!! val dogWeight: Double = edittextPetaddWeight.text.toString().toDouble() val dogBack: Double? = bodySizeCheck(edittextPetaddBackLength.text.toString()) @@ -264,7 +264,7 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen } } - return fragmentDogAddOnBoardingBinding.root + return binding.root } override fun onDestroy() { From c48b782bfaf91776b293e2e2f4060f4775b258cf Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 28 Mar 2024 16:28:29 +0900 Subject: [PATCH 026/119] =?UTF-8?q?fix:=20=EC=98=A8=EB=B3=B4=EB=94=A9=20Fr?= =?UTF-8?q?agment=EC=97=90=EC=84=9C=20UserPreferences=20=EC=A7=81=EC=A0=91?= =?UTF-8?q?=20=EC=A3=BC=EC=9E=85=EB=B0=9B=EC=A7=80=20=EC=95=8A=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - UserViewModel을 통해 DataStore 객체에 접근 --- .../view/DogAddOnBoardingFragment.kt | 95 +++++++++++-------- 1 file changed, 54 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt index 46b5beee..785ee83d 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt @@ -20,6 +20,7 @@ import com.project.meongcare.R import com.project.meongcare.databinding.FragmentDogAddOnBoardingBinding import com.project.meongcare.login.model.data.local.UserPreferences import com.project.meongcare.login.model.data.repository.LoginRepository +import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.DateSubmitListener import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener import com.project.meongcare.onboarding.model.entities.Dog @@ -44,18 +45,16 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen lateinit var binding: FragmentDogAddOnBoardingBinding private val dogAddViewModel: DogAddViewModel by viewModels() + private val userViewModel: UserViewModel by viewModels() private val dogTypeSharedViewModel: DogTypeSharedViewModel by activityViewModels() - private val postDogCoroutineJob = Job() - private val dogAddCoroutineJob = Job() - - @Inject - lateinit var userPreferences: UserPreferences @Inject lateinit var loginRepository: LoginRepository private var isCbxChecked = false private var isFirstRegister: Boolean? = null + private lateinit var accessToken: String + private lateinit var refreshToken: String override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -102,36 +101,17 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen } dogAddViewModel.dogAddResponse.observe(viewLifecycleOwner) { response -> - postDogCoroutineJob.cancel() if (response == 200) { CustomSnackBar.make( requireView(), R.drawable.snackbar_success_16dp, getString(R.string.snack_bar_dog_create_complete), ).show() - userPreferences.setIsFirstLogin(false) + userViewModel.setIsFirstLogin(false) findNavController().navigate(R.id.action_dogAddOnBoardingFragment_to_completeOnBoardingFragment) } else if (response == 401) { - lifecycleScope.launch(dogAddCoroutineJob) { - val refreshToken = userPreferences.getRefreshToken() - if (refreshToken.isNotEmpty()) { - val reissueResponse = loginRepository.getNewAccessToken(refreshToken) - if (reissueResponse != null && reissueResponse.code() == 200) { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_info_add_failure), - ).show() - userPreferences.setAccessToken(reissueResponse.body()?.accessToken!!) - } else if (reissueResponse != null && reissueResponse.code() == 401) { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_refresh_expire), - ).show() - findNavController().navigate(R.id.action_dogAddOnBoardingFragment_to_loginFragment) - } - } + if (refreshToken.isNotEmpty()) { + reissueAccessToken() } } else { CustomSnackBar.make( @@ -250,26 +230,59 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen val requestBody: RequestBody = json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) val filePart = createMultipartBody(requireContext(), dogAddViewModel.dogProfileImage.value) - lifecycleScope.launch(postDogCoroutineJob) { - userPreferences.accessToken.collectLatest { accessToken -> - if (accessToken != null) { - dogAddViewModel.postDogInfo( - accessToken, - filePart, - requestBody, - ) - } - } + if (accessToken.isNotEmpty()) { + dogAddViewModel.postDogInfo( + accessToken, + filePart, + requestBody, + ) } } } - return binding.root } - override fun onDestroy() { - super.onDestroy() - dogAddCoroutineJob.cancel() + private fun getAccessToken() { + userViewModel.accessTokenPreferencesLiveData.observe(viewLifecycleOwner) { accessToken -> + if (accessToken != null) { + this.accessToken = accessToken + getRefreshToken() + } + } + } + + private fun getRefreshToken() { + userViewModel.refreshTokenPreferencesLiveData.observe(viewLifecycleOwner) { refreshToken -> + if (refreshToken != null) { + this.refreshToken = refreshToken + } + } + } + + private fun reissueAccessToken() { + userViewModel.getNewAccessToken(refreshToken) + userViewModel.reissueResponse.observe(viewLifecycleOwner) { response -> + if (response != null) { + when (response.code()) { + 200 -> { + CustomSnackBar.make( + requireView(), + R.drawable.snackbar_error_16dp, + getString(R.string.snack_bar_info_add_failure), + ).show() + userViewModel.setAccessToken(response.body()?.accessToken) + } + 401 -> { + CustomSnackBar.make( + requireView(), + R.drawable.snackbar_error_16dp, + getString(R.string.snack_bar_refresh_expire), + ).show() + findNavController().navigate(R.id.action_dogAddOnBoardingFragment_to_loginFragment) + } + } + } + } } override fun onUriPassed(uri: Uri) { From 0d18156e9bc6bcc76102b79a78953bb41b820d20 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 28 Mar 2024 16:40:37 +0900 Subject: [PATCH 027/119] =?UTF-8?q?fix:=20=EC=98=A8=EB=B3=B4=EB=94=A9=20Fr?= =?UTF-8?q?agment=EC=9D=98=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20import?= =?UTF-8?q?=20=EB=AC=B8=20=EB=B0=8F=20=EB=AF=B8=EC=B0=B8=EC=A1=B0=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onboarding/view/DogAddOnBoardingFragment.kt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt index 785ee83d..ef3812a2 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt @@ -10,7 +10,6 @@ import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels -import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import com.bumptech.glide.Glide import com.google.android.material.chip.Chip @@ -18,8 +17,6 @@ import com.google.gson.Gson import com.project.meongcare.BirthdayBottomSheetFragment import com.project.meongcare.R import com.project.meongcare.databinding.FragmentDogAddOnBoardingBinding -import com.project.meongcare.login.model.data.local.UserPreferences -import com.project.meongcare.login.model.data.repository.LoginRepository import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.DateSubmitListener import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener @@ -28,9 +25,6 @@ import com.project.meongcare.onboarding.viewmodel.DogAddViewModel import com.project.meongcare.onboarding.viewmodel.DogTypeSharedViewModel import com.project.meongcare.snackbar.view.CustomSnackBar import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.collectLatest -import kotlinx.coroutines.launch import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MultipartBody import okhttp3.RequestBody @@ -38,7 +32,6 @@ import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.toRequestBody import java.io.File import java.text.SimpleDateFormat -import javax.inject.Inject @AndroidEntryPoint class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListener { @@ -48,9 +41,6 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen private val userViewModel: UserViewModel by viewModels() private val dogTypeSharedViewModel: DogTypeSharedViewModel by activityViewModels() - @Inject - lateinit var loginRepository: LoginRepository - private var isCbxChecked = false private var isFirstRegister: Boolean? = null private lateinit var accessToken: String From 50c5262ddd66745c231f991542e42d4652b227f4 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 28 Mar 2024 16:45:24 +0900 Subject: [PATCH 028/119] =?UTF-8?q?fix:=20=EC=98=A8=EB=B3=B4=EB=94=A9=20Fr?= =?UTF-8?q?agment=20=EB=82=B4=20Gender=20enum=20class=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/meongcare/onboarding/model/entities/Gender.kt | 6 ++++++ .../meongcare/onboarding/view/DogAddOnBoardingFragment.kt | 6 +----- 2 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/com/project/meongcare/onboarding/model/entities/Gender.kt diff --git a/app/src/main/java/com/project/meongcare/onboarding/model/entities/Gender.kt b/app/src/main/java/com/project/meongcare/onboarding/model/entities/Gender.kt new file mode 100644 index 00000000..f0ce1672 --- /dev/null +++ b/app/src/main/java/com/project/meongcare/onboarding/model/entities/Gender.kt @@ -0,0 +1,6 @@ +package com.project.meongcare.onboarding.model.entities + +enum class Gender(val korean: String, val english: String) { + MALE("남성", "male"), + FEMALE("여성", "female"), +} diff --git a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt index ef3812a2..daf4c76e 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt @@ -21,6 +21,7 @@ import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.DateSubmitListener import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener import com.project.meongcare.onboarding.model.entities.Dog +import com.project.meongcare.onboarding.model.entities.Gender import com.project.meongcare.onboarding.viewmodel.DogAddViewModel import com.project.meongcare.onboarding.viewmodel.DogTypeSharedViewModel import com.project.meongcare.snackbar.view.CustomSnackBar @@ -284,11 +285,6 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen } } -enum class Gender(val korean: String, val english: String) { - MALE("남성", "male"), - FEMALE("여성", "female"), -} - fun dateFormat(str: String): String { val inputDateFormat = SimpleDateFormat("yyyy-MM-dd") val outputDateFormat = SimpleDateFormat("yyyy년 MM월 dd일") From 261c1f7a251a1c6fd981689a8cb68969dd4ef323 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 28 Mar 2024 16:50:48 +0900 Subject: [PATCH 029/119] =?UTF-8?q?fix:=20=EC=98=A8=EB=B3=B4=EB=94=A9=20Fr?= =?UTF-8?q?agment=20=EB=82=B4=20=EB=82=A0=EC=A7=9C=20=ED=8F=AC=EB=A7=B7=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20Util=20=EA=B0=9D=EC=B2=B4=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EA=B4=80=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onboarding/util/DogAddOnBoardingDateUtils.kt | 13 +++++++++++++ .../onboarding/view/DogAddOnBoardingFragment.kt | 10 +--------- 2 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/com/project/meongcare/onboarding/util/DogAddOnBoardingDateUtils.kt diff --git a/app/src/main/java/com/project/meongcare/onboarding/util/DogAddOnBoardingDateUtils.kt b/app/src/main/java/com/project/meongcare/onboarding/util/DogAddOnBoardingDateUtils.kt new file mode 100644 index 00000000..52c42084 --- /dev/null +++ b/app/src/main/java/com/project/meongcare/onboarding/util/DogAddOnBoardingDateUtils.kt @@ -0,0 +1,13 @@ +package com.project.meongcare.onboarding.util + +import java.text.SimpleDateFormat + +object DogAddOnBoardingDateUtils { + fun dateFormat(str: String): String { + val inputDateFormat = SimpleDateFormat("yyyy-MM-dd") + val outputDateFormat = SimpleDateFormat("yyyy년 MM월 dd일") + + val parsedDate = inputDateFormat.parse(str) + return outputDateFormat.format(parsedDate) + } +} diff --git a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt index daf4c76e..32245abc 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt @@ -22,6 +22,7 @@ import com.project.meongcare.onboarding.model.data.local.DateSubmitListener import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener import com.project.meongcare.onboarding.model.entities.Dog import com.project.meongcare.onboarding.model.entities.Gender +import com.project.meongcare.onboarding.util.DogAddOnBoardingDateUtils.dateFormat import com.project.meongcare.onboarding.viewmodel.DogAddViewModel import com.project.meongcare.onboarding.viewmodel.DogTypeSharedViewModel import com.project.meongcare.snackbar.view.CustomSnackBar @@ -32,7 +33,6 @@ import okhttp3.RequestBody import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.toRequestBody import java.io.File -import java.text.SimpleDateFormat @AndroidEntryPoint class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListener { @@ -285,14 +285,6 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen } } -fun dateFormat(str: String): String { - val inputDateFormat = SimpleDateFormat("yyyy-MM-dd") - val outputDateFormat = SimpleDateFormat("yyyy년 MM월 dd일") - - val parsedDate = inputDateFormat.parse(str) - return outputDateFormat.format(parsedDate) -} - fun createMultipartBody( context: Context, uri: Uri?, From b1ea9a580e22999b11fa083deeaa81de058dba6e Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 28 Mar 2024 16:56:10 +0900 Subject: [PATCH 030/119] =?UTF-8?q?fix:=20=EC=98=A8=EB=B3=B4=EB=94=A9=20Fr?= =?UTF-8?q?agment=20=EB=82=B4=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=ED=95=A8=EC=88=98=20Util=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EA=B4=80=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/DogAddOnBoardingInfoUtils.kt | 19 +++++++++++++++++++ .../view/DogAddOnBoardingFragment.kt | 16 ++-------------- 2 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/com/project/meongcare/onboarding/util/DogAddOnBoardingInfoUtils.kt diff --git a/app/src/main/java/com/project/meongcare/onboarding/util/DogAddOnBoardingInfoUtils.kt b/app/src/main/java/com/project/meongcare/onboarding/util/DogAddOnBoardingInfoUtils.kt new file mode 100644 index 00000000..ae2cf857 --- /dev/null +++ b/app/src/main/java/com/project/meongcare/onboarding/util/DogAddOnBoardingInfoUtils.kt @@ -0,0 +1,19 @@ +package com.project.meongcare.onboarding.util + +import android.view.View +import com.google.android.material.chip.Chip +import com.project.meongcare.onboarding.model.entities.Gender + +object DogAddOnBoardingInfoUtils { + fun getCheckedGender( + view: View, + checkedChipId: Int, + ): String { + val checkedChip = view.findViewById(checkedChipId) + return if (checkedChip.text.toString() == Gender.FEMALE.korean) Gender.FEMALE.english else Gender.MALE.english + } + + fun bodySizeCheck(str: String): Double? { + return if (str.isEmpty()) null else str.toDouble() + } +} diff --git a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt index 32245abc..f78bec94 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt @@ -12,7 +12,6 @@ import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import com.bumptech.glide.Glide -import com.google.android.material.chip.Chip import com.google.gson.Gson import com.project.meongcare.BirthdayBottomSheetFragment import com.project.meongcare.R @@ -21,8 +20,9 @@ import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.DateSubmitListener import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener import com.project.meongcare.onboarding.model.entities.Dog -import com.project.meongcare.onboarding.model.entities.Gender import com.project.meongcare.onboarding.util.DogAddOnBoardingDateUtils.dateFormat +import com.project.meongcare.onboarding.util.DogAddOnBoardingInfoUtils.bodySizeCheck +import com.project.meongcare.onboarding.util.DogAddOnBoardingInfoUtils.getCheckedGender import com.project.meongcare.onboarding.viewmodel.DogAddViewModel import com.project.meongcare.onboarding.viewmodel.DogTypeSharedViewModel import com.project.meongcare.snackbar.view.CustomSnackBar @@ -304,15 +304,3 @@ fun createMultipartBody( val emptyBody = "".toRequestBody("multipart/form-data".toMediaTypeOrNull()) return MultipartBody.Part.createFormData("file", "", emptyBody) } - -fun getCheckedGender( - view: View, - checkedChipId: Int, -): String { - val checkedChip = view.findViewById(checkedChipId) - return if (checkedChip.text.toString() == Gender.FEMALE.korean) Gender.FEMALE.english else Gender.MALE.english -} - -fun bodySizeCheck(str: String): Double? { - return if (str.isEmpty()) null else str.toDouble() -} From 8d799fba16a0bf32158268fb96db9012350b02e4 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Fri, 29 Mar 2024 23:44:31 +0900 Subject: [PATCH 031/119] =?UTF-8?q?refactor:=20=EA=B0=95=EC=95=84=EC=A7=80?= =?UTF-8?q?=20=EB=93=B1=EB=A1=9D=20Fragment=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - initView() 함수에 뷰 초기화 로직 작성 - initObserves() 함수에 LiveData Observe 로직 작성 - 뷰 초기화 및 LiveData Observe를 수행하는 콜백함수 onCreateView -> onViewCreated 변경 --- .../view/DogAddOnBoardingFragment.kt | 329 +++++++++--------- 1 file changed, 173 insertions(+), 156 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt index f78bec94..8bf1e878 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt @@ -58,7 +58,126 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen savedInstanceState: Bundle?, ): View? { binding = FragmentDogAddOnBoardingBinding.inflate(inflater) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + getAccessToken() + initObserves() + initViews() + } + + private fun getAccessToken() { + userViewModel.accessTokenPreferencesLiveData.observe(viewLifecycleOwner) { accessToken -> + if (accessToken != null) { + this.accessToken = accessToken + getRefreshToken() + } + } + } + + private fun getRefreshToken() { + userViewModel.refreshTokenPreferencesLiveData.observe(viewLifecycleOwner) { refreshToken -> + if (refreshToken != null) { + this.refreshToken = refreshToken + } + } + } + private fun reissueAccessToken() { + userViewModel.getNewAccessToken(refreshToken) + userViewModel.reissueResponse.observe(viewLifecycleOwner) { response -> + if (response != null) { + when (response.code()) { + 200 -> { + CustomSnackBar.make( + requireView(), + R.drawable.snackbar_error_16dp, + getString(R.string.snack_bar_info_add_failure), + ).show() + userViewModel.setAccessToken(response.body()?.accessToken) + } + 401 -> { + CustomSnackBar.make( + requireView(), + R.drawable.snackbar_error_16dp, + getString(R.string.snack_bar_refresh_expire), + ).show() + findNavController().navigate(R.id.action_dogAddOnBoardingFragment_to_loginFragment) + } + } + } + } + } + + override fun onUriPassed(uri: Uri) { + dogAddViewModel.getDogProfileImage(uri) + } + + override fun onDateSubmit(str: String) { + dogAddViewModel.getDogBirthDate(str) + } + + private fun initViews() { + // 사진 등록 + binding.cardviewPetaddImage.setOnClickListener { + val modalBottomSheet = PhotoSelectBottomSheetFragment() + modalBottomSheet.setPhotoMenuListener(this@DogAddOnBoardingFragment) + modalBottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.RoundCornerPhotoDialogTheme) + modalBottomSheet.show(requireActivity().supportFragmentManager, modalBottomSheet.tag) + } + + // 품종 등록 + binding.viewPetaddType.setOnClickListener { + findNavController().navigate(R.id.action_dogAddOnBoardingFragment_to_dogVarietySearchFragment) + } + + // 날짜 등록 + binding.textviewPetaddSelectBirthday.setOnClickListener { + val birthdayBottomSheet = + BirthdayBottomSheetFragment( + binding.root, + dogAddViewModel.dogBirthDate.value, + ) + birthdayBottomSheet.setDateSubmitListener(this@DogAddOnBoardingFragment) + birthdayBottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.RoundCornerBirthdayDialogTheme) + birthdayBottomSheet.show(requireActivity().supportFragmentManager, birthdayBottomSheet.tag) + } + + binding.checkboxPetaddNeuterStatus.setOnCheckedChangeListener { buttonView, isChecked -> + isCbxChecked = isChecked + } + + // 중성화 여부 텍스트 클릭 시 체크박스 반전 + binding.textviewPetaddNeuterStatus.setOnClickListener { + binding.checkboxPetaddNeuterStatus.isChecked = !isCbxChecked + } + + binding.edittextPetaddNameError.setOnClickListener { + it.visibility = View.INVISIBLE + binding.edittextPetaddName.requestFocus() + } + + binding.edittextPetaddWeightError.setOnClickListener { + it.visibility = View.INVISIBLE + binding.edittextPetaddWeight.requestFocus() + } + + binding.edittextPetaddSelectTypeError.setOnClickListener { + findNavController().navigate(R.id.action_dogAddOnBoardingFragment_to_dogVarietySearchFragment) + } + + binding.buttonCancel.setOnClickListener { + findNavController().popBackStack() + } + + initCancelButtonVisibility() + initCompleteButton() + } + + private fun initObserves() { dogAddViewModel.dogProfileImage.observe(viewLifecycleOwner) { uri -> if (uri != null) { binding.run { @@ -112,177 +231,75 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen ).show() } } + } - binding.run { - when (isFirstRegister) { - true -> buttonCancel.visibility = View.GONE - false, null -> buttonCancel.visibility = View.VISIBLE - } - - // 사진 등록 - cardviewPetaddImage.setOnClickListener { - val modalBottomSheet = PhotoSelectBottomSheetFragment() - modalBottomSheet.setPhotoMenuListener(this@DogAddOnBoardingFragment) - // 둥근 모서리 지정 - modalBottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.RoundCornerPhotoDialogTheme) - modalBottomSheet.show(requireActivity().supportFragmentManager, modalBottomSheet.tag) - } - - // 품종 등록 - viewPetaddType.setOnClickListener { - findNavController().navigate(R.id.action_dogAddOnBoardingFragment_to_dogVarietySearchFragment) - } - - // 날짜 등록 - textviewPetaddSelectBirthday.setOnClickListener { - val birthdayBottomSheet = - BirthdayBottomSheetFragment( - binding.root, - dogAddViewModel.dogBirthDate.value, - ) - birthdayBottomSheet.setDateSubmitListener(this@DogAddOnBoardingFragment) - birthdayBottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.RoundCornerBirthdayDialogTheme) - birthdayBottomSheet.show(requireActivity().supportFragmentManager, birthdayBottomSheet.tag) - } + private fun initCancelButtonVisibility() { + when (isFirstRegister) { + true -> binding.buttonCancel.visibility = View.GONE + false, null -> binding.buttonCancel.visibility = View.VISIBLE + } + } - checkboxPetaddNeuterStatus.setOnCheckedChangeListener { buttonView, isChecked -> - isCbxChecked = isChecked + private fun initCompleteButton() { + binding.buttonComplete.setOnClickListener { + // 입력 검사 + if (binding.edittextPetaddName.text.isEmpty()) { + binding.edittextPetaddNameError.visibility = View.VISIBLE + return@setOnClickListener } - // 중성화 여부 텍스트 클릭 시 체크박스 반전 - textviewPetaddNeuterStatus.setOnClickListener { - checkboxPetaddNeuterStatus.isChecked = !isCbxChecked + if (binding.edittextPetaddSelectType.text.isEmpty()) { + binding.edittextPetaddSelectTypeError.visibility = View.VISIBLE + return@setOnClickListener } - edittextPetaddNameError.setOnClickListener { - it.visibility = View.INVISIBLE - edittextPetaddName.requestFocus() - } - edittextPetaddWeightError.setOnClickListener { - it.visibility = View.INVISIBLE - edittextPetaddWeight.requestFocus() - } - edittextPetaddSelectTypeError.setOnClickListener { - findNavController().navigate(R.id.action_dogAddOnBoardingFragment_to_dogVarietySearchFragment) + if (binding.chipgroupPetaddGroupGender.checkedChipId == View.NO_ID) { + return@setOnClickListener } - buttonCancel.setOnClickListener { - findNavController().popBackStack() + if (binding.textviewPetaddSelectBirthday.text.isEmpty()) { + binding.edittextPetaddSelectBirthdayError.visibility = View.VISIBLE + return@setOnClickListener } - // 완료 - buttonComplete.setOnClickListener { - // 입력 검사 - if (edittextPetaddName.text.isEmpty()) { - edittextPetaddNameError.visibility = View.VISIBLE - return@setOnClickListener - } - - if (edittextPetaddSelectType.text.isEmpty()) { - edittextPetaddSelectTypeError.visibility = View.VISIBLE - return@setOnClickListener - } - - if (chipgroupPetaddGroupGender.checkedChipId == View.NO_ID) { - return@setOnClickListener - } - - if (textviewPetaddSelectBirthday.text.isEmpty()) { - edittextPetaddSelectBirthdayError.visibility = View.VISIBLE - return@setOnClickListener - } - - if (edittextPetaddWeight.text.isEmpty()) { - edittextPetaddWeightError.visibility = View.VISIBLE - return@setOnClickListener - } - - val dogName = edittextPetaddName.text.toString() - val dogType = edittextPetaddSelectType.text.toString() - val dogGender = getCheckedGender(binding.root, chipgroupPetaddGroupGender.checkedChipId) - val dogBirth = dogAddViewModel.dogBirthDate.value!! - val dogWeight: Double = edittextPetaddWeight.text.toString().toDouble() - val dogBack: Double? = bodySizeCheck(edittextPetaddBackLength.text.toString()) - val dogNeck: Double? = bodySizeCheck(edittextPetaddNeckCircumference.text.toString()) - val dogChest: Double? = bodySizeCheck(edittextPetaddChestCircumference.text.toString()) - val dog = - Dog( - dogName, - dogType, - dogGender, - dogBirth, - isCbxChecked, - dogWeight, - dogBack, - dogNeck, - dogChest, - ) - val json = Gson().toJson(dog) - val requestBody: RequestBody = json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) - val filePart = createMultipartBody(requireContext(), dogAddViewModel.dogProfileImage.value) - - if (accessToken.isNotEmpty()) { - dogAddViewModel.postDogInfo( - accessToken, - filePart, - requestBody, - ) - } - } - } - return binding.root - } - - private fun getAccessToken() { - userViewModel.accessTokenPreferencesLiveData.observe(viewLifecycleOwner) { accessToken -> - if (accessToken != null) { - this.accessToken = accessToken - getRefreshToken() - } - } - } - - private fun getRefreshToken() { - userViewModel.refreshTokenPreferencesLiveData.observe(viewLifecycleOwner) { refreshToken -> - if (refreshToken != null) { - this.refreshToken = refreshToken + if (binding.edittextPetaddWeight.text.isEmpty()) { + binding.edittextPetaddWeightError.visibility = View.VISIBLE + return@setOnClickListener } - } - } - private fun reissueAccessToken() { - userViewModel.getNewAccessToken(refreshToken) - userViewModel.reissueResponse.observe(viewLifecycleOwner) { response -> - if (response != null) { - when (response.code()) { - 200 -> { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_info_add_failure), - ).show() - userViewModel.setAccessToken(response.body()?.accessToken) - } - 401 -> { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_refresh_expire), - ).show() - findNavController().navigate(R.id.action_dogAddOnBoardingFragment_to_loginFragment) - } - } + val dogName = binding.edittextPetaddName.text.toString() + val dogType = binding.edittextPetaddSelectType.text.toString() + val dogGender = getCheckedGender(binding.root, binding.chipgroupPetaddGroupGender.checkedChipId) + val dogBirth = dogAddViewModel.dogBirthDate.value!! + val dogWeight: Double = binding.edittextPetaddWeight.text.toString().toDouble() + val dogBack: Double? = bodySizeCheck(binding.edittextPetaddBackLength.text.toString()) + val dogNeck: Double? = bodySizeCheck(binding.edittextPetaddNeckCircumference.text.toString()) + val dogChest: Double? = bodySizeCheck(binding.edittextPetaddChestCircumference.text.toString()) + val dog = + Dog( + dogName, + dogType, + dogGender, + dogBirth, + isCbxChecked, + dogWeight, + dogBack, + dogNeck, + dogChest, + ) + val json = Gson().toJson(dog) + val requestBody: RequestBody = json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) + val filePart = createMultipartBody(requireContext(), dogAddViewModel.dogProfileImage.value) + + if (accessToken.isNotEmpty()) { + dogAddViewModel.postDogInfo( + accessToken, + filePart, + requestBody, + ) } } } - - override fun onUriPassed(uri: Uri) { - dogAddViewModel.getDogProfileImage(uri) - } - - override fun onDateSubmit(str: String) { - dogAddViewModel.getDogBirthDate(str) - } } fun createMultipartBody( From 28395928e7a0b1d75fd0afd42528c0bc8c0451d5 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 00:24:28 +0900 Subject: [PATCH 032/119] =?UTF-8?q?fix:=20=EA=B0=95=EC=95=84=EC=A7=80=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20Fragment=20=EB=82=B4=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/DogAddOnBoardingFragment.kt | 92 +++++++++++-------- 1 file changed, 56 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt index 8bf1e878..a9c08945 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt @@ -12,24 +12,24 @@ import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import com.bumptech.glide.Glide -import com.google.gson.Gson import com.project.meongcare.BirthdayBottomSheetFragment import com.project.meongcare.R +import com.project.meongcare.aws.util.DOG_FOLDER_PATH +import com.project.meongcare.aws.util.PARENT_FOLDER_PATH +import com.project.meongcare.aws.util.ProfileImageUtils.createMultipartFromUri +import com.project.meongcare.aws.util.ProfileImageUtils.getMultipartFileName +import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentDogAddOnBoardingBinding import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.DateSubmitListener import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener -import com.project.meongcare.onboarding.model.entities.Dog import com.project.meongcare.onboarding.util.DogAddOnBoardingDateUtils.dateFormat -import com.project.meongcare.onboarding.util.DogAddOnBoardingInfoUtils.bodySizeCheck -import com.project.meongcare.onboarding.util.DogAddOnBoardingInfoUtils.getCheckedGender import com.project.meongcare.onboarding.viewmodel.DogAddViewModel import com.project.meongcare.onboarding.viewmodel.DogTypeSharedViewModel import com.project.meongcare.snackbar.view.CustomSnackBar import dagger.hilt.android.AndroidEntryPoint import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MultipartBody -import okhttp3.RequestBody import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.toRequestBody import java.io.File @@ -40,12 +40,16 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen private val dogAddViewModel: DogAddViewModel by viewModels() private val userViewModel: UserViewModel by viewModels() + private val awsS3ViewModel: AWSS3ViewModel by viewModels() private val dogTypeSharedViewModel: DogTypeSharedViewModel by activityViewModels() private var isCbxChecked = false private var isFirstRegister: Boolean? = null + private lateinit var accessToken: String private lateinit var refreshToken: String + private lateinit var multipartImage: MultipartBody.Part + private lateinit var fileName: String override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -114,6 +118,8 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen override fun onUriPassed(uri: Uri) { dogAddViewModel.getDogProfileImage(uri) + multipartImage = createMultipartFromUri(requireContext(), uri) + fileName = getMultipartFileName(multipartImage) } override fun onDateSubmit(str: String) { @@ -231,6 +237,49 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen ).show() } } + + awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> + if (response != null) { + awsS3ViewModel.uploadImageToS3(response.preSignedUrl, multipartImage) + } + } + + awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> + if (response == 200) { + // 저장된 이미지 경로를 데이터와 함께 서버로 전달 +// val dogName = binding.edittextPetaddName.text.toString() +// val dogType = binding.edittextPetaddSelectType.text.toString() +// val dogGender = getCheckedGender(binding.root, binding.chipgroupPetaddGroupGender.checkedChipId) +// val dogBirth = dogAddViewModel.dogBirthDate.value!! +// val dogWeight: Double = binding.edittextPetaddWeight.text.toString().toDouble() +// val dogBack: Double? = bodySizeCheck(binding.edittextPetaddBackLength.text.toString()) +// val dogNeck: Double? = bodySizeCheck(binding.edittextPetaddNeckCircumference.text.toString()) +// val dogChest: Double? = bodySizeCheck(binding.edittextPetaddChestCircumference.text.toString()) +// val dog = +// Dog( +// dogName, +// dogType, +// dogGender, +// dogBirth, +// isCbxChecked, +// dogWeight, +// dogBack, +// dogNeck, +// dogChest, +// ) +// val json = Gson().toJson(dog) +// val requestBody: RequestBody = json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) +// val filePart = createMultipartBody(requireContext(), dogAddViewModel.dogProfileImage.value) +// +// if (accessToken.isNotEmpty()) { +// dogAddViewModel.postDogInfo( +// accessToken, +// filePart, +// requestBody, +// ) +// } + } + } } private fun initCancelButtonVisibility() { @@ -267,37 +316,8 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen return@setOnClickListener } - val dogName = binding.edittextPetaddName.text.toString() - val dogType = binding.edittextPetaddSelectType.text.toString() - val dogGender = getCheckedGender(binding.root, binding.chipgroupPetaddGroupGender.checkedChipId) - val dogBirth = dogAddViewModel.dogBirthDate.value!! - val dogWeight: Double = binding.edittextPetaddWeight.text.toString().toDouble() - val dogBack: Double? = bodySizeCheck(binding.edittextPetaddBackLength.text.toString()) - val dogNeck: Double? = bodySizeCheck(binding.edittextPetaddNeckCircumference.text.toString()) - val dogChest: Double? = bodySizeCheck(binding.edittextPetaddChestCircumference.text.toString()) - val dog = - Dog( - dogName, - dogType, - dogGender, - dogBirth, - isCbxChecked, - dogWeight, - dogBack, - dogNeck, - dogChest, - ) - val json = Gson().toJson(dog) - val requestBody: RequestBody = json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) - val filePart = createMultipartBody(requireContext(), dogAddViewModel.dogProfileImage.value) - - if (accessToken.isNotEmpty()) { - dogAddViewModel.postDogInfo( - accessToken, - filePart, - requestBody, - ) - } + val filePath = "$PARENT_FOLDER_PATH$DOG_FOLDER_PATH$fileName" + awsS3ViewModel.getPreSignedUrl(accessToken, filePath) } } } From a9e0e8155b776f9bb56f8d0482d857936cdd3af9 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 00:31:27 +0900 Subject: [PATCH 033/119] =?UTF-8?q?fix:=20=EA=B0=95=EC=95=84=EC=A7=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=88=98=EC=A0=95=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=97=90=EC=84=9C=20MainActivity=20=EA=B0=9D=EC=B2=B4=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/meongcare/info/view/PetEditFragment.kt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt index 40affd28..2ce481b0 100644 --- a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt @@ -18,7 +18,6 @@ import androidx.navigation.fragment.findNavController import com.bumptech.glide.Glide import com.google.gson.Gson import com.project.meongcare.BirthdayBottomSheetFragment -import com.project.meongcare.MainActivity import com.project.meongcare.R import com.project.meongcare.databinding.FragmentPetEditBinding import com.project.meongcare.home.view.getCurrentDate @@ -55,7 +54,6 @@ import javax.inject.Inject @AndroidEntryPoint class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { private lateinit var binding: FragmentPetEditBinding - private lateinit var mainActivity: MainActivity private lateinit var dogInfo: GetDogInfoResponse private lateinit var currentAccessToken: String @@ -84,7 +82,6 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { savedInstanceState: Bundle?, ): View? { binding = FragmentPetEditBinding.inflate(inflater) - mainActivity = activity as MainActivity if (!isInitialized) { initDogInfo(dogInfo) @@ -288,7 +285,7 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { val modalBottomSheet = PhotoSelectBottomSheetFragment() modalBottomSheet.setPhotoMenuListener(this@PetEditFragment) modalBottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.RoundCornerPhotoDialogTheme) - modalBottomSheet.show(mainActivity.supportFragmentManager, modalBottomSheet.tag) + modalBottomSheet.show(requireActivity().supportFragmentManager, modalBottomSheet.tag) } edittextPeteditType.setOnClickListener { @@ -357,7 +354,7 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { val requestBody: RequestBody = json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) if (isImageUpdated) { // 새 이미지 등록된 경우 - val filePart: MultipartBody.Part = createMultipartBody(mainActivity, petEditViewModel.dogProfile.value) + val filePart: MultipartBody.Part = createMultipartBody(requireContext(), petEditViewModel.dogProfile.value) petEditViewModel.putDogInfo(dogInfo.dogId, currentAccessToken, filePart, requestBody) } else { // 기존 이미지인 경우 From dd7d1ec2bf832b4f18f6a739489eaccb8def2673 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 00:37:41 +0900 Subject: [PATCH 034/119] =?UTF-8?q?fix:=20=EA=B0=95=EC=95=84=EC=A7=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=88=98=EC=A0=95=20=ED=99=94=EB=A9=B4=20?= =?UTF-8?q?=EB=B7=B0=20=EC=B4=88=EA=B8=B0=ED=99=94=20=EB=B0=8F=20livedata?= =?UTF-8?q?=20=EC=98=B5=EC=A0=80=EB=B2=84=20onViewCreated()=20=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=88=98=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/meongcare/info/view/PetEditFragment.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt index 2ce481b0..b253ef72 100644 --- a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt @@ -82,6 +82,11 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { savedInstanceState: Bundle?, ): View? { binding = FragmentPetEditBinding.inflate(inflater) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) if (!isInitialized) { initDogInfo(dogInfo) @@ -365,8 +370,6 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { } } } - - return binding.root } private fun getAccessToken() { From 3f5c32ee5e6019bf5e633e95be78cc33b908a219 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 00:46:40 +0900 Subject: [PATCH 035/119] =?UTF-8?q?fix:=20=EC=98=A8=EB=B3=B4=EB=94=A9=20Fr?= =?UTF-8?q?agment=EC=97=90=EC=84=9C=20UserPreferences=20=EB=B0=8F=20LoginR?= =?UTF-8?q?epository=EA=B0=9D=EC=B2=B4=20=EC=B0=B8=EC=A1=B0=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - UserViewModel을 통해 DataStore 객체에 접근 --- .../meongcare/info/view/PetEditFragment.kt | 156 +++++++----------- 1 file changed, 57 insertions(+), 99 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt index b253ef72..6c332b62 100644 --- a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt @@ -23,17 +23,16 @@ import com.project.meongcare.databinding.FragmentPetEditBinding import com.project.meongcare.home.view.getCurrentDate import com.project.meongcare.info.model.entities.GetDogInfoResponse import com.project.meongcare.info.viewmodel.ProfileViewModel -import com.project.meongcare.login.model.data.local.UserPreferences -import com.project.meongcare.login.model.data.repository.LoginRepository +import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.DateSubmitListener import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener import com.project.meongcare.onboarding.model.entities.Dog -import com.project.meongcare.onboarding.view.Gender +import com.project.meongcare.onboarding.model.entities.Gender +import com.project.meongcare.onboarding.util.DogAddOnBoardingDateUtils.dateFormat +import com.project.meongcare.onboarding.util.DogAddOnBoardingInfoUtils.bodySizeCheck +import com.project.meongcare.onboarding.util.DogAddOnBoardingInfoUtils.getCheckedGender import com.project.meongcare.onboarding.view.PhotoSelectBottomSheetFragment -import com.project.meongcare.onboarding.view.bodySizeCheck import com.project.meongcare.onboarding.view.createMultipartBody -import com.project.meongcare.onboarding.view.dateFormat -import com.project.meongcare.onboarding.view.getCheckedGender import com.project.meongcare.onboarding.viewmodel.DogTypeSharedViewModel import com.project.meongcare.snackbar.view.CustomSnackBar import com.project.meongcare.weight.model.entities.WeightPostRequest @@ -49,14 +48,15 @@ import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.toRequestBody import java.io.File import java.net.URL -import javax.inject.Inject @AndroidEntryPoint class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { private lateinit var binding: FragmentPetEditBinding private lateinit var dogInfo: GetDogInfoResponse - private lateinit var currentAccessToken: String + private lateinit var accessToken: String + private lateinit var refreshToken: String + private val userViewModel: UserViewModel by viewModels() private val petEditViewModel: ProfileViewModel by viewModels() private val dogTypeSharedViewModel: DogTypeSharedViewModel by activityViewModels() @@ -64,16 +64,9 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { private var isInitialized = false private var isImageUpdated = false - @Inject - lateinit var userPreferences: UserPreferences - - @Inject - lateinit var loginRepository: LoginRepository - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) dogInfo = getDogInfo() - getAccessToken() } override fun onCreateView( @@ -93,6 +86,8 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { isInitialized = true } + getAccessToken() + petEditViewModel.dogProfile.observe(viewLifecycleOwner) { uri -> if (uri != null) { Glide.with(this@PetEditFragment) @@ -118,34 +113,11 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { getCurrentDate(), null, ) - petEditViewModel.postDogWeight(currentAccessToken, dogPostRequest) + petEditViewModel.postDogWeight(accessToken, dogPostRequest) } 401 -> { - lifecycleScope.launch { - val refreshToken = userPreferences.getRefreshToken() - if (refreshToken.isNotEmpty()) { - val response = loginRepository.getNewAccessToken(refreshToken) - if (response != null) { - when (response.code()) { - 200 -> { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_info_edit_failure), - ).show() - userPreferences.setAccessToken(response.body()?.accessToken!!) - } - 401 -> { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_refresh_expire), - ).show() - findNavController().navigate(R.id.action_petEditFragment_to_loginFragment) - } - } - } - } + if (refreshToken.isNotEmpty()) { + reissueAccessToken() } } else -> { @@ -168,36 +140,12 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { dogInfo.dogId, binding.edittextPeteditWeight.text.toString().toDouble(), getCurrentDate(), - currentAccessToken, + accessToken, ) } 401 -> { - // refresh reissue 호출 - lifecycleScope.launch { - val refreshToken = userPreferences.getRefreshToken() - if (refreshToken.isNotEmpty()) { - val response = loginRepository.getNewAccessToken(refreshToken) - if (response != null) { - when (response.code()) { - 200 -> { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_info_edit_failure), - ).show() - userPreferences.setAccessToken(response.body()?.accessToken!!) - } - 401 -> { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_refresh_expire), - ).show() - findNavController().navigate(R.id.action_petEditFragment_to_loginFragment) - } - } - } - } + if (refreshToken.isNotEmpty()) { + reissueAccessToken() } } else -> { @@ -230,31 +178,8 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { findNavController().popBackStack() } 401 -> { - lifecycleScope.launch { - val refreshToken = userPreferences.getRefreshToken() - if (refreshToken.isNotEmpty()) { - val response = loginRepository.getNewAccessToken(refreshToken) - if (response != null) { - when (response.code()) { - 200 -> { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_info_edit_failure), - ).show() - userPreferences.setAccessToken(response.body()?.accessToken!!) - } - 401 -> { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_refresh_expire), - ).show() - findNavController().navigate(R.id.action_petEditFragment_to_loginFragment) - } - } - } - } + if (refreshToken.isNotEmpty()) { + reissueAccessToken() } } else -> { @@ -360,12 +285,12 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { if (isImageUpdated) { // 새 이미지 등록된 경우 val filePart: MultipartBody.Part = createMultipartBody(requireContext(), petEditViewModel.dogProfile.value) - petEditViewModel.putDogInfo(dogInfo.dogId, currentAccessToken, filePart, requestBody) + petEditViewModel.putDogInfo(dogInfo.dogId, accessToken, filePart, requestBody) } else { // 기존 이미지인 경우 lifecycleScope.launch { val filePart: MultipartBody.Part = createMultipartFromUrl(dogInfo.imageUrl) - petEditViewModel.putDogInfo(dogInfo.dogId, currentAccessToken, filePart, requestBody) + petEditViewModel.putDogInfo(dogInfo.dogId, accessToken, filePart, requestBody) } } } @@ -373,10 +298,43 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { } private fun getAccessToken() { - lifecycleScope.launch { - userPreferences.accessToken.collectLatest { accessToken -> - if (accessToken != null) { - currentAccessToken = accessToken + userViewModel.accessTokenPreferencesLiveData.observe(viewLifecycleOwner) { accessToken -> + if (accessToken != null) { + this.accessToken = accessToken + getRefreshToken() + } + } + } + + private fun getRefreshToken() { + userViewModel.refreshTokenPreferencesLiveData.observe(viewLifecycleOwner) { refreshToken -> + if (refreshToken != null) { + this.refreshToken = refreshToken + } + } + } + + private fun reissueAccessToken() { + userViewModel.getNewAccessToken(refreshToken) + userViewModel.reissueResponse.observe(viewLifecycleOwner) { response -> + if (response != null) { + when (response.code()) { + 200 -> { + CustomSnackBar.make( + requireView(), + R.drawable.snackbar_error_16dp, + getString(R.string.snack_bar_info_edit_failure), + ).show() + userViewModel.setAccessToken(response.body()?.accessToken) + } + 401 -> { + CustomSnackBar.make( + requireView(), + R.drawable.snackbar_error_16dp, + getString(R.string.snack_bar_refresh_expire), + ).show() + findNavController().navigate(R.id.action_petEditFragment_to_loginFragment) + } } } } From c65bd4ef4c019f6214dfddd4e1b32be263746d67 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 01:23:41 +0900 Subject: [PATCH 036/119] =?UTF-8?q?fix:=20=EA=B0=95=EC=95=84=EC=A7=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EC=88=98=EC=A0=95=20=ED=94=84=EB=9E=98?= =?UTF-8?q?=EA=B7=B8=EB=A8=BC=ED=8A=B8=20LiveData=20Observe=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20initObserves()=20=ED=95=A8=EC=88=98=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=88=98=ED=96=89=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/info/view/PetEditFragment.kt | 237 +++++++++--------- 1 file changed, 120 insertions(+), 117 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt index 6c332b62..06ccbb93 100644 --- a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt @@ -87,123 +87,7 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { } getAccessToken() - - petEditViewModel.dogProfile.observe(viewLifecycleOwner) { uri -> - if (uri != null) { - Glide.with(this@PetEditFragment) - .load(uri) - .error(R.drawable.dog_profile_default) - .into(binding.imageviewPeteditImage) - } - } - - petEditViewModel.dogBirth.observe(viewLifecycleOwner) { birth -> - if (birth != null) { - binding.edittextPeteditSelectBirthday.setText(dateFormat(birth)) - } - } - - petEditViewModel.dogPutResponse.observe(viewLifecycleOwner) { response -> - if (response != null) { - when (response) { - 200 -> { - val dogPostRequest = - WeightPostRequest( - dogInfo.dogId, - getCurrentDate(), - null, - ) - petEditViewModel.postDogWeight(accessToken, dogPostRequest) - } - 401 -> { - if (refreshToken.isNotEmpty()) { - reissueAccessToken() - } - } - else -> { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_failure), - ).show() - } - } - } - } - - petEditViewModel.postDogWeightResponse.observe(viewLifecycleOwner) { postResponse -> - if (postResponse != null) { - when (postResponse) { - 200 -> { - // post 성공, patch 호출 - petEditViewModel.patchDogWeight( - dogInfo.dogId, - binding.edittextPeteditWeight.text.toString().toDouble(), - getCurrentDate(), - accessToken, - ) - } - 401 -> { - if (refreshToken.isNotEmpty()) { - reissueAccessToken() - } - } - else -> { - // 강아지 정보 수정 실패 - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_dog_weight_failure), - ).show() - } - } - } else { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_failure), - ).show() - } - } - - petEditViewModel.patchDogWeightResponse.observe(viewLifecycleOwner) { patchResponse -> - if (patchResponse != null) { - when (patchResponse) { - 200 -> { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_success_16dp, - getString(R.string.snack_bar_dog_edit_complete), - ).show() - findNavController().popBackStack() - } - 401 -> { - if (refreshToken.isNotEmpty()) { - reissueAccessToken() - } - } - else -> { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_dog_weight_failure), - ).show() - } - } - } else { - CustomSnackBar.make( - requireView(), - R.drawable.snackbar_error_16dp, - getString(R.string.snack_bar_failure), - ).show() - } - } - - dogTypeSharedViewModel.selectedDogType.observe(viewLifecycleOwner) { dogType -> - if (dogType != null) { - binding.edittextPeteditType.setText(dogType) - } - } + initObserves() binding.run { editTextWatcher(edittextPeteditName, edittextPeteditName, "이름을 입력해주세요") @@ -340,6 +224,125 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { } } + private fun initObserves() { + petEditViewModel.dogProfile.observe(viewLifecycleOwner) { uri -> + if (uri != null) { + Glide.with(this@PetEditFragment) + .load(uri) + .error(R.drawable.dog_profile_default) + .into(binding.imageviewPeteditImage) + } + } + + petEditViewModel.dogBirth.observe(viewLifecycleOwner) { birth -> + if (birth != null) { + binding.edittextPeteditSelectBirthday.setText(dateFormat(birth)) + } + } + + petEditViewModel.dogPutResponse.observe(viewLifecycleOwner) { response -> + if (response != null) { + when (response) { + 200 -> { + val dogPostRequest = + WeightPostRequest( + dogInfo.dogId, + getCurrentDate(), + null, + ) + petEditViewModel.postDogWeight(accessToken, dogPostRequest) + } + 401 -> { + if (refreshToken.isNotEmpty()) { + reissueAccessToken() + } + } + else -> { + CustomSnackBar.make( + requireView(), + R.drawable.snackbar_error_16dp, + getString(R.string.snack_bar_failure), + ).show() + } + } + } + } + + petEditViewModel.postDogWeightResponse.observe(viewLifecycleOwner) { postResponse -> + if (postResponse != null) { + when (postResponse) { + 200 -> { + // post 성공, patch 호출 + petEditViewModel.patchDogWeight( + dogInfo.dogId, + binding.edittextPeteditWeight.text.toString().toDouble(), + getCurrentDate(), + accessToken, + ) + } + 401 -> { + if (refreshToken.isNotEmpty()) { + reissueAccessToken() + } + } + else -> { + // 강아지 정보 수정 실패 + CustomSnackBar.make( + requireView(), + R.drawable.snackbar_error_16dp, + getString(R.string.snack_bar_dog_weight_failure), + ).show() + } + } + } else { + CustomSnackBar.make( + requireView(), + R.drawable.snackbar_error_16dp, + getString(R.string.snack_bar_failure), + ).show() + } + } + + petEditViewModel.patchDogWeightResponse.observe(viewLifecycleOwner) { patchResponse -> + if (patchResponse != null) { + when (patchResponse) { + 200 -> { + CustomSnackBar.make( + requireView(), + R.drawable.snackbar_success_16dp, + getString(R.string.snack_bar_dog_edit_complete), + ).show() + findNavController().popBackStack() + } + 401 -> { + if (refreshToken.isNotEmpty()) { + reissueAccessToken() + } + } + else -> { + CustomSnackBar.make( + requireView(), + R.drawable.snackbar_error_16dp, + getString(R.string.snack_bar_dog_weight_failure), + ).show() + } + } + } else { + CustomSnackBar.make( + requireView(), + R.drawable.snackbar_error_16dp, + getString(R.string.snack_bar_failure), + ).show() + } + } + + dogTypeSharedViewModel.selectedDogType.observe(viewLifecycleOwner) { dogType -> + if (dogType != null) { + binding.edittextPeteditType.setText(dogType) + } + } + } + private fun editTextWatcher( editText: EditText, targetView: View, From 876b97ecf2b1d5f2a4ae74e240cc11c114bb7f83 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 01:36:53 +0900 Subject: [PATCH 037/119] =?UTF-8?q?fix:=20=EA=B0=95=EC=95=84=EC=A7=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EC=88=98=EC=A0=95=20=ED=94=84=EB=9E=98?= =?UTF-8?q?=EA=B7=B8=EB=A8=BC=ED=8A=B8=20=EB=B7=B0=20=EC=B4=88=EA=B8=B0?= =?UTF-8?q?=ED=99=94=20=EB=A1=9C=EC=A7=81=20initViews()=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=EC=97=90=EC=84=9C=20=EC=88=98=ED=96=89=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/info/view/PetEditFragment.kt | 183 +++++++++--------- 1 file changed, 92 insertions(+), 91 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt index 06ccbb93..39f5133e 100644 --- a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt @@ -88,97 +88,7 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { getAccessToken() initObserves() - - binding.run { - editTextWatcher(edittextPeteditName, edittextPeteditName, "이름을 입력해주세요") - editTextWatcher(edittextPeteditType, edittextPeteditType, "품종을 입력해주세요") - editTextWatcher(edittextPeteditSelectBirthday, edittextPeteditSelectBirthday, "날짜를 선택해주세요") - editTextWatcher(edittextPeteditWeight, viewPeteditWeight, "") - - cardviewPeteditImage.setOnClickListener { - val modalBottomSheet = PhotoSelectBottomSheetFragment() - modalBottomSheet.setPhotoMenuListener(this@PetEditFragment) - modalBottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.RoundCornerPhotoDialogTheme) - modalBottomSheet.show(requireActivity().supportFragmentManager, modalBottomSheet.tag) - } - - edittextPeteditType.setOnClickListener { - findNavController().navigate(R.id.action_petEditFragment_to_dogVarietySearchFragment) - } - - checkboxPeteditNeuterStatus.setOnCheckedChangeListener { buttonView, isChecked -> - isCbxChecked = isChecked - } - - textviewPeteditNeuterStatus.setOnClickListener { - checkboxPeteditNeuterStatus.isChecked = !isCbxChecked - } - - edittextPeteditSelectBirthday.setOnClickListener { - val birthdayBottomSheet = - BirthdayBottomSheetFragment( - binding.root, - petEditViewModel.dogBirth.value, - ) - birthdayBottomSheet.setDateSubmitListener(this@PetEditFragment) - birthdayBottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.RoundCornerBirthdayDialogTheme) - birthdayBottomSheet.show(requireActivity().supportFragmentManager, birthdayBottomSheet.tag) - } - - buttonPeteditCancel.setOnClickListener { - findNavController().popBackStack() - } - - buttonPeteditSubmit.setOnClickListener { - if (edittextPeteditName.text.isEmpty()) { - return@setOnClickListener - } - if (edittextPeteditType.text.isEmpty()) { - return@setOnClickListener - } - if (edittextPeteditSelectBirthday.text.isEmpty()) { - return@setOnClickListener - } - if (edittextPeteditWeight.text.isEmpty()) { - return@setOnClickListener - } - - val dogName = edittextPeteditName.text.toString() - val dogType = edittextPeteditType.text.toString() - val dogGender = getCheckedGender(binding.root, chipgroupPeteditGroupGender.checkedChipId) - val dogBirth = petEditViewModel.dogBirth.value!! - val dogWeight = edittextPeteditWeight.text.toString().toDouble() - val dogBack = bodySizeCheck(edittextPeteditBackLength.text.toString()) - val dogNeck = bodySizeCheck(edittextPeteditNeckCircumference.text.toString()) - val dogChest = bodySizeCheck(edittextPeteditChestCircumference.text.toString()) - val dog = - Dog( - dogName, - dogType, - dogGender, - dogBirth, - isCbxChecked, - dogWeight, - dogBack, - dogNeck, - dogChest, - ) - - val json = Gson().toJson(dog) - val requestBody: RequestBody = json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) - if (isImageUpdated) { - // 새 이미지 등록된 경우 - val filePart: MultipartBody.Part = createMultipartBody(requireContext(), petEditViewModel.dogProfile.value) - petEditViewModel.putDogInfo(dogInfo.dogId, accessToken, filePart, requestBody) - } else { - // 기존 이미지인 경우 - lifecycleScope.launch { - val filePart: MultipartBody.Part = createMultipartFromUrl(dogInfo.imageUrl) - petEditViewModel.putDogInfo(dogInfo.dogId, accessToken, filePart, requestBody) - } - } - } - } + initViews() } private fun getAccessToken() { @@ -343,6 +253,97 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { } } + private fun initViews() { + editTextWatcher(binding.edittextPeteditName, binding.edittextPeteditName, "이름을 입력해주세요") + editTextWatcher(binding.edittextPeteditType, binding.edittextPeteditType, "품종을 입력해주세요") + editTextWatcher(binding.edittextPeteditSelectBirthday, binding.edittextPeteditSelectBirthday, "날짜를 선택해주세요") + editTextWatcher(binding.edittextPeteditWeight, binding.viewPeteditWeight, "") + + binding.cardviewPeteditImage.setOnClickListener { + val modalBottomSheet = PhotoSelectBottomSheetFragment() + modalBottomSheet.setPhotoMenuListener(this@PetEditFragment) + modalBottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.RoundCornerPhotoDialogTheme) + modalBottomSheet.show(requireActivity().supportFragmentManager, modalBottomSheet.tag) + } + + binding.edittextPeteditType.setOnClickListener { + findNavController().navigate(R.id.action_petEditFragment_to_dogVarietySearchFragment) + } + + binding.checkboxPeteditNeuterStatus.setOnCheckedChangeListener { buttonView, isChecked -> + isCbxChecked = isChecked + } + + binding.textviewPeteditNeuterStatus.setOnClickListener { + binding.checkboxPeteditNeuterStatus.isChecked = !isCbxChecked + } + + binding.edittextPeteditSelectBirthday.setOnClickListener { + val birthdayBottomSheet = + BirthdayBottomSheetFragment( + binding.root, + petEditViewModel.dogBirth.value, + ) + birthdayBottomSheet.setDateSubmitListener(this@PetEditFragment) + birthdayBottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.RoundCornerBirthdayDialogTheme) + birthdayBottomSheet.show(requireActivity().supportFragmentManager, birthdayBottomSheet.tag) + } + + binding.buttonPeteditCancel.setOnClickListener { + findNavController().popBackStack() + } + + binding.buttonPeteditSubmit.setOnClickListener { + if (binding.edittextPeteditName.text.isEmpty()) { + return@setOnClickListener + } + if (binding.edittextPeteditType.text.isEmpty()) { + return@setOnClickListener + } + if (binding.edittextPeteditSelectBirthday.text.isEmpty()) { + return@setOnClickListener + } + if (binding.edittextPeteditWeight.text.isEmpty()) { + return@setOnClickListener + } + + val dogName = binding.edittextPeteditName.text.toString() + val dogType = binding.edittextPeteditType.text.toString() + val dogGender = getCheckedGender(binding.root, binding.chipgroupPeteditGroupGender.checkedChipId) + val dogBirth = petEditViewModel.dogBirth.value!! + val dogWeight = binding.edittextPeteditWeight.text.toString().toDouble() + val dogBack = bodySizeCheck(binding.edittextPeteditBackLength.text.toString()) + val dogNeck = bodySizeCheck(binding.edittextPeteditNeckCircumference.text.toString()) + val dogChest = bodySizeCheck(binding.edittextPeteditChestCircumference.text.toString()) + val dog = + Dog( + dogName, + dogType, + dogGender, + dogBirth, + isCbxChecked, + dogWeight, + dogBack, + dogNeck, + dogChest, + ) + + val json = Gson().toJson(dog) + val requestBody: RequestBody = json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) + if (isImageUpdated) { + // 새 이미지 등록된 경우 + val filePart: MultipartBody.Part = createMultipartBody(requireContext(), petEditViewModel.dogProfile.value) + petEditViewModel.putDogInfo(dogInfo.dogId, accessToken, filePart, requestBody) + } else { + // 기존 이미지인 경우 + lifecycleScope.launch { + val filePart: MultipartBody.Part = createMultipartFromUrl(dogInfo.imageUrl) + petEditViewModel.putDogInfo(dogInfo.dogId, accessToken, filePart, requestBody) + } + } + } + } + private fun editTextWatcher( editText: EditText, targetView: View, From 6c284bb9ec4a143e975c1d0091a2ba72900ba0cd Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 14:32:12 +0900 Subject: [PATCH 038/119] =?UTF-8?q?fix:=20=EA=B0=95=EC=95=84=EC=A7=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=88=98=EC=A0=95=20Fragment=20=EB=82=B4?= =?UTF-8?q?=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 추후 이미시 수신 로직 변경 시 이미지 새로 선택하지 않은 경우 업로드 로직 수정 필요 --- .../meongcare/info/view/PetEditFragment.kt | 126 +++++++++--------- 1 file changed, 64 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt index 39f5133e..b65de9d6 100644 --- a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt @@ -16,9 +16,14 @@ import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import com.bumptech.glide.Glide -import com.google.gson.Gson import com.project.meongcare.BirthdayBottomSheetFragment import com.project.meongcare.R +import com.project.meongcare.aws.util.DOG_FOLDER_PATH +import com.project.meongcare.aws.util.PARENT_FOLDER_PATH +import com.project.meongcare.aws.util.ProfileImageUtils.createMultipartFromUri +import com.project.meongcare.aws.util.ProfileImageUtils.createMultipartFromUrl +import com.project.meongcare.aws.util.ProfileImageUtils.getMultipartFileName +import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentPetEditBinding import com.project.meongcare.home.view.getCurrentDate import com.project.meongcare.info.model.entities.GetDogInfoResponse @@ -26,28 +31,15 @@ import com.project.meongcare.info.viewmodel.ProfileViewModel import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.DateSubmitListener import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener -import com.project.meongcare.onboarding.model.entities.Dog import com.project.meongcare.onboarding.model.entities.Gender import com.project.meongcare.onboarding.util.DogAddOnBoardingDateUtils.dateFormat -import com.project.meongcare.onboarding.util.DogAddOnBoardingInfoUtils.bodySizeCheck -import com.project.meongcare.onboarding.util.DogAddOnBoardingInfoUtils.getCheckedGender import com.project.meongcare.onboarding.view.PhotoSelectBottomSheetFragment -import com.project.meongcare.onboarding.view.createMultipartBody import com.project.meongcare.onboarding.viewmodel.DogTypeSharedViewModel import com.project.meongcare.snackbar.view.CustomSnackBar import com.project.meongcare.weight.model.entities.WeightPostRequest import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MultipartBody -import okhttp3.RequestBody -import okhttp3.RequestBody.Companion.asRequestBody -import okhttp3.RequestBody.Companion.toRequestBody -import java.io.File -import java.net.URL @AndroidEntryPoint class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { @@ -55,7 +47,10 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { private lateinit var dogInfo: GetDogInfoResponse private lateinit var accessToken: String private lateinit var refreshToken: String + private lateinit var fileName: String + private lateinit var multipartImage: MultipartBody.Part + private val awsS3ViewModel: AWSS3ViewModel by viewModels() private val userViewModel: UserViewModel by viewModels() private val petEditViewModel: ProfileViewModel by viewModels() private val dogTypeSharedViewModel: DogTypeSharedViewModel by activityViewModels() @@ -251,6 +246,51 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { binding.edittextPeteditType.setText(dogType) } } + + awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> + if (response != null) { + awsS3ViewModel.uploadImageToS3(response.preSignedUrl, multipartImage) + } + } + + awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> + if (response == 200) { +// val dogName = binding.edittextPeteditName.text.toString() +// val dogType = binding.edittextPeteditType.text.toString() +// val dogGender = getCheckedGender(binding.root, binding.chipgroupPeteditGroupGender.checkedChipId) +// val dogBirth = petEditViewModel.dogBirth.value!! +// val dogWeight = binding.edittextPeteditWeight.text.toString().toDouble() +// val dogBack = bodySizeCheck(binding.edittextPeteditBackLength.text.toString()) +// val dogNeck = bodySizeCheck(binding.edittextPeteditNeckCircumference.text.toString()) +// val dogChest = bodySizeCheck(binding.edittextPeteditChestCircumference.text.toString()) +// val dog = +// Dog( +// dogName, +// dogType, +// dogGender, +// dogBirth, +// isCbxChecked, +// dogWeight, +// dogBack, +// dogNeck, +// dogChest, +// ) +// +// val json = Gson().toJson(dog) +// val requestBody: RequestBody = json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) +// if (isImageUpdated) { +// // 새 이미지 등록된 경우 +// val filePart: MultipartBody.Part = createMultipartBody(requireContext(), petEditViewModel.dogProfile.value) +// petEditViewModel.putDogInfo(dogInfo.dogId, accessToken, filePart, requestBody) +// } else { +// // 기존 이미지인 경우 +// lifecycleScope.launch { +// val filePart: MultipartBody.Part = createMultipartFromUrl(dogInfo.imageUrl) +// petEditViewModel.putDogInfo(dogInfo.dogId, accessToken, filePart, requestBody) +// } +// } + } + } } private fun initViews() { @@ -307,38 +347,19 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { return@setOnClickListener } - val dogName = binding.edittextPeteditName.text.toString() - val dogType = binding.edittextPeteditType.text.toString() - val dogGender = getCheckedGender(binding.root, binding.chipgroupPeteditGroupGender.checkedChipId) - val dogBirth = petEditViewModel.dogBirth.value!! - val dogWeight = binding.edittextPeteditWeight.text.toString().toDouble() - val dogBack = bodySizeCheck(binding.edittextPeteditBackLength.text.toString()) - val dogNeck = bodySizeCheck(binding.edittextPeteditNeckCircumference.text.toString()) - val dogChest = bodySizeCheck(binding.edittextPeteditChestCircumference.text.toString()) - val dog = - Dog( - dogName, - dogType, - dogGender, - dogBirth, - isCbxChecked, - dogWeight, - dogBack, - dogNeck, - dogChest, - ) - - val json = Gson().toJson(dog) - val requestBody: RequestBody = json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) if (isImageUpdated) { // 새 이미지 등록된 경우 - val filePart: MultipartBody.Part = createMultipartBody(requireContext(), petEditViewModel.dogProfile.value) - petEditViewModel.putDogInfo(dogInfo.dogId, accessToken, filePart, requestBody) + multipartImage = createMultipartFromUri(requireContext(), petEditViewModel.dogProfile.value) + fileName = "$PARENT_FOLDER_PATH$DOG_FOLDER_PATH${getMultipartFileName(multipartImage)}" + awsS3ViewModel.getPreSignedUrl(accessToken, fileName) } else { - // 기존 이미지인 경우 lifecycleScope.launch { - val filePart: MultipartBody.Part = createMultipartFromUrl(dogInfo.imageUrl) - petEditViewModel.putDogInfo(dogInfo.dogId, accessToken, filePart, requestBody) + // 기존 이미지인 경우 + // 일단 받아온 이미지 형태가 url이기 때문에 새로운 multipart를 만들어서 이미지 전송하도록 했지만 + // 추후에 이미지 수신 형태가 파일 경로 형태이면 이미지 전송 없이 기존 파일 경로 포함해서 정보만 전송하도록 변경 + multipartImage = createMultipartFromUrl(requireContext(), dogInfo.imageUrl) + fileName = "$PARENT_FOLDER_PATH$DOG_FOLDER_PATH${getMultipartFileName(multipartImage)}" + awsS3ViewModel.getPreSignedUrl(accessToken, fileName) } } } @@ -350,7 +371,7 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { hint: String, ) { editText.addTextChangedListener { - editText.doAfterTextChanged { editable -> + editText.doAfterTextChanged { updateEditTextStyle(editText, targetView, hint) } } @@ -407,25 +428,6 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { } } - private suspend fun createMultipartFromUrl(url: String?): MultipartBody.Part { - return withContext(Dispatchers.IO) { - if (url.isNullOrEmpty()) { - val emptyBody = "".toRequestBody("multipart/form-data".toMediaTypeOrNull()) - MultipartBody.Part.createFormData("file", "", emptyBody) - } else { - val inputStream = URL(url).openStream() - val file = File(requireContext().cacheDir, "url_image.jpg") - inputStream.use { input -> - file.outputStream().use { output -> - input.copyTo(output) - } - } - val requestFile = file.asRequestBody("multipart/form-data".toMediaTypeOrNull()) - MultipartBody.Part.createFormData("file", file.name, requestFile) - } - } - } - override fun onUriPassed(uri: Uri) { petEditViewModel.setDogProfile(uri) isImageUpdated = true From 911ee3ce00223d273cdd10f64b0aea60c41d19ea Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 14:54:17 +0900 Subject: [PATCH 039/119] =?UTF-8?q?fix:=20=EA=B0=95=EC=95=84=EC=A7=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=88=98=EC=A0=95=20Fragment=20=EB=82=B4?= =?UTF-8?q?=20createMultipartFromUrl=20=ED=95=A8=EC=88=98=20AWSS3ImageUtil?= =?UTF-8?q?s=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/aws/util/AWSS3ImageUtils.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt b/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt index 0652fcb6..7329350f 100644 --- a/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt +++ b/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt @@ -2,11 +2,14 @@ package com.project.meongcare.aws.util import android.content.Context import android.net.Uri +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MultipartBody import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.toRequestBody import java.io.File +import java.net.URL import java.util.UUID object ProfileImageUtils { @@ -34,6 +37,28 @@ object ProfileImageUtils { return MultipartBody.Part.createFormData("file", "", emptyBody) } + suspend fun createMultipartFromUrl( + context: Context, + url: String? + ): MultipartBody.Part { + return withContext(Dispatchers.IO) { + if (url.isNullOrEmpty()) { + val emptyBody = "".toRequestBody("multipart/form-data".toMediaTypeOrNull()) + MultipartBody.Part.createFormData("file", "", emptyBody) + } else { + val inputStream = URL(url).openStream() + val file = File(context.cacheDir, createUUID()) + inputStream.use { input -> + file.outputStream().use { output -> + input.copyTo(output) + } + } + val requestFile = file.asRequestBody("multipart/form-data".toMediaTypeOrNull()) + MultipartBody.Part.createFormData("file", file.name, requestFile) + } + } + } + fun getMultipartFileName(file: MultipartBody.Part): String { val disposition = file.headers?.get("Content-Disposition") return disposition?.substringAfterLast("filename=")?.removeSurrounding("\"") ?: "tempFile" From d4f0ce45d89e41b8d6b292e1495bfc60f1572e19 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 16:35:41 +0900 Subject: [PATCH 040/119] =?UTF-8?q?fix:=20=EC=82=AC=EB=A3=8C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EC=8B=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/feed/view/FeedAddFragment.kt | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt b/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt index caa6feba..5e982eb8 100644 --- a/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt +++ b/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt @@ -19,6 +19,11 @@ import com.archit.calendardaterangepicker.customviews.CalendarListener import com.archit.calendardaterangepicker.customviews.DateRangeCalendarView import com.bumptech.glide.Glide import com.project.meongcare.R +import com.project.meongcare.aws.util.FEED_FOLDER_PATH +import com.project.meongcare.aws.util.PARENT_FOLDER_PATH +import com.project.meongcare.aws.util.ProfileImageUtils.createMultipartFromUri +import com.project.meongcare.aws.util.ProfileImageUtils.getMultipartFileName +import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentFeedAddEditBinding import com.project.meongcare.excreta.utils.SUCCESS import com.project.meongcare.feed.model.data.local.FeedPhotoListener @@ -45,6 +50,7 @@ import com.project.meongcare.feed.viewmodel.DogViewModel import com.project.meongcare.feed.viewmodel.FeedPostViewModel import com.project.meongcare.feed.viewmodel.UserViewModel import dagger.hilt.android.AndroidEntryPoint +import okhttp3.MultipartBody import java.text.SimpleDateFormat import java.util.Calendar import java.util.Locale @@ -56,9 +62,13 @@ class FeedAddFragment : Fragment(), FeedPhotoListener { val binding get() = _binding!! private lateinit var inputMethodManager: InputMethodManager + private lateinit var multipartImage: MultipartBody.Part + private lateinit var fileName: String + private val feedPostViewModel: FeedPostViewModel by viewModels() private val dogViewModel: DogViewModel by viewModels() private val userViewModel: UserViewModel by viewModels() + private val awsS3ViewModel: AWSS3ViewModel by viewModels() private var recommendIntake = 0.0 var selectedStartDate = "" @@ -103,6 +113,12 @@ class FeedAddFragment : Fragment(), FeedPhotoListener { dogViewModel.dogWeight.observe(viewLifecycleOwner) { response -> weight = response } + awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> + if (response == 200) { + // 이미지 업로드 성공 시 데이터 전송 처리 + // postFeedInfo() -> 함수 내 이미지 전송 로직 제거 필요 + } + } initInputMethodManager() initToolbar() initPhotoAttachModalBottomSheet() @@ -457,14 +473,13 @@ class FeedAddFragment : Fragment(), FeedPhotoListener { } if (isValid) { - postFeedInfo() + getPreSignedUrl() } } } } private fun postFeedInfo() { - createFeedInfo() val dto = convertFeedPostDto(feedInfo) val file = convertFeedFile( @@ -493,6 +508,18 @@ class FeedAddFragment : Fragment(), FeedPhotoListener { } } + private fun getPreSignedUrl() { + createFeedInfo() + multipartImage = createMultipartFromUri(requireContext(), imageUri) + fileName = "$PARENT_FOLDER_PATH$FEED_FOLDER_PATH${getMultipartFileName(multipartImage)}" + awsS3ViewModel.getPreSignedUrl(accessToken, fileName) + awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> + if (response != null) { + awsS3ViewModel.uploadImageToS3(response.preSignedUrl, multipartImage) + } + } + } + private fun initInputMethodManager() { thread { SystemClock.sleep(300) From b8c2c1c5e4b3005657ac8e3f2ab20a44fc7fb0d8 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 17:03:37 +0900 Subject: [PATCH 041/119] =?UTF-8?q?fix:=20=EB=8C=80=EC=86=8C=EB=B3=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EB=93=B1=EB=A1=9D=20=EC=8B=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excreta/view/ExcretaAddFragment.kt | 102 ++++++++++++------ 1 file changed, 68 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt index 1f8b03ab..a97231f0 100644 --- a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt +++ b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt @@ -11,6 +11,11 @@ import androidx.navigation.fragment.findNavController import com.bumptech.glide.Glide import com.project.meongcare.CalendarBottomSheetFragment import com.project.meongcare.R +import com.project.meongcare.aws.util.EXCRETA_FOLDER_PATH +import com.project.meongcare.aws.util.PARENT_FOLDER_PATH +import com.project.meongcare.aws.util.ProfileImageUtils.createMultipartFromUri +import com.project.meongcare.aws.util.ProfileImageUtils.getMultipartFileName +import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentExcretaAddEditBinding import com.project.meongcare.excreta.model.data.local.PhotoListener import com.project.meongcare.excreta.model.entities.Excreta @@ -28,6 +33,7 @@ import com.project.meongcare.feed.viewmodel.DogViewModel import com.project.meongcare.feed.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.DateSubmitListener import dagger.hilt.android.AndroidEntryPoint +import okhttp3.MultipartBody @AndroidEntryPoint class ExcretaAddFragment : Fragment(), DateSubmitListener, PhotoListener { @@ -37,12 +43,16 @@ class ExcretaAddFragment : Fragment(), DateSubmitListener, PhotoListener { private val excretaAddViewModel: ExcretaAddViewModel by viewModels() private val userViewModel: UserViewModel by viewModels() private val dogViewModel: DogViewModel by viewModels() + private val awsS3ViewModel: AWSS3ViewModel by viewModels() private val calendarModalBottomSheet = CalendarBottomSheetFragment() private var excretaDate = "" private var accessToken = "" private var dogId = 0L + private lateinit var multipartImage: MultipartBody.Part + private lateinit var fileName: String + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -154,45 +164,69 @@ class ExcretaAddFragment : Fragment(), DateSubmitListener, PhotoListener { } if (isValid) { - val excretaType = - if (checkboxExcretaaddUrine.isChecked) { - Excreta.URINE.toString() - } else { - Excreta.FECES.toString() - } - - val excretaTime = convertTimeFormat(timepikerExcretaaddTime) - val excretaDateTime = "${excretaDate}T$excretaTime" - - val currentImageUri = excretaAddViewModel.excretaImage.value - - excretaAddViewModel.postExcreta( - dogId, - accessToken, - excretaType, - excretaDateTime, - requireContext(), - currentImageUri ?: Uri.EMPTY, - ) - excretaAddViewModel.excretaPosted.observe(viewLifecycleOwner) { response -> - if (response == SUCCESS) { - showSuccessSnackBar( - requireView(), - EXCRETA_POST_SUCCESS, - ) - findNavController().popBackStack() - } else { - showFailureSnackBar( - requireView(), - EXCRETA_POST_FAILURE, - ) - } - } + getPreSignedUrl() } } } } + private fun getPreSignedUrl() { + multipartImage = createMultipartFromUri(requireContext(), excretaAddViewModel.excretaImage.value) + fileName = "$PARENT_FOLDER_PATH$EXCRETA_FOLDER_PATH${getMultipartFileName(multipartImage)}" + awsS3ViewModel.getPreSignedUrl(accessToken, fileName) + awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> + if (response != null) { + uploadImage(response.preSignedUrl, multipartImage) + } + } + } + + private fun uploadImage(preSignedUrl: String, image: MultipartBody.Part) { + awsS3ViewModel.uploadImageToS3(preSignedUrl, image) + awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> + if (response == 200) { +// postExcreta() + } + } + } + + private fun postExcreta() { + val excretaType = + if (binding.checkboxExcretaaddUrine.isChecked) { + Excreta.URINE.toString() + } else { + Excreta.FECES.toString() + } + + val excretaTime = convertTimeFormat(binding.timepikerExcretaaddTime) + val excretaDateTime = "${excretaDate}T$excretaTime" + + val currentImageUri = excretaAddViewModel.excretaImage.value + + excretaAddViewModel.postExcreta( + dogId, + accessToken, + excretaType, + excretaDateTime, + requireContext(), + currentImageUri ?: Uri.EMPTY, + ) + excretaAddViewModel.excretaPosted.observe(viewLifecycleOwner) { response -> + if (response == SUCCESS) { + showSuccessSnackBar( + requireView(), + EXCRETA_POST_SUCCESS, + ) + findNavController().popBackStack() + } else { + showFailureSnackBar( + requireView(), + EXCRETA_POST_FAILURE, + ) + } + } + } + override fun onDestroyView() { super.onDestroyView() _binding = null From 9dadbb3261fcb4847e74d7dd12faf24ea7597a96 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 17:34:50 +0900 Subject: [PATCH 042/119] =?UTF-8?q?rename:=20ProfileImageUtils=20->=20AWSS?= =?UTF-8?q?3ImageUtils=EB=A1=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt | 2 +- .../project/meongcare/excreta/view/ExcretaAddFragment.kt | 4 ++-- .../java/com/project/meongcare/feed/view/FeedAddFragment.kt | 4 ++-- .../java/com/project/meongcare/info/view/PetEditFragment.kt | 6 +++--- .../java/com/project/meongcare/info/view/ProfileFragment.kt | 4 ++-- .../meongcare/onboarding/view/DogAddOnBoardingFragment.kt | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt b/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt index 7329350f..a6b65a27 100644 --- a/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt +++ b/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt @@ -12,7 +12,7 @@ import java.io.File import java.net.URL import java.util.UUID -object ProfileImageUtils { +object AWSS3ImageUtils { private fun createUUID(): String { return UUID.randomUUID().toString() } diff --git a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt index a97231f0..210ecf3f 100644 --- a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt +++ b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt @@ -13,8 +13,8 @@ import com.project.meongcare.CalendarBottomSheetFragment import com.project.meongcare.R import com.project.meongcare.aws.util.EXCRETA_FOLDER_PATH import com.project.meongcare.aws.util.PARENT_FOLDER_PATH -import com.project.meongcare.aws.util.ProfileImageUtils.createMultipartFromUri -import com.project.meongcare.aws.util.ProfileImageUtils.getMultipartFileName +import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri +import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentExcretaAddEditBinding import com.project.meongcare.excreta.model.data.local.PhotoListener diff --git a/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt b/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt index 5e982eb8..0a06fb2f 100644 --- a/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt +++ b/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt @@ -21,8 +21,8 @@ import com.bumptech.glide.Glide import com.project.meongcare.R import com.project.meongcare.aws.util.FEED_FOLDER_PATH import com.project.meongcare.aws.util.PARENT_FOLDER_PATH -import com.project.meongcare.aws.util.ProfileImageUtils.createMultipartFromUri -import com.project.meongcare.aws.util.ProfileImageUtils.getMultipartFileName +import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri +import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentFeedAddEditBinding import com.project.meongcare.excreta.utils.SUCCESS diff --git a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt index b65de9d6..8bd7c1e6 100644 --- a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt @@ -20,9 +20,9 @@ import com.project.meongcare.BirthdayBottomSheetFragment import com.project.meongcare.R import com.project.meongcare.aws.util.DOG_FOLDER_PATH import com.project.meongcare.aws.util.PARENT_FOLDER_PATH -import com.project.meongcare.aws.util.ProfileImageUtils.createMultipartFromUri -import com.project.meongcare.aws.util.ProfileImageUtils.createMultipartFromUrl -import com.project.meongcare.aws.util.ProfileImageUtils.getMultipartFileName +import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri +import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUrl +import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentPetEditBinding import com.project.meongcare.home.view.getCurrentDate diff --git a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt index 3fbee991..ef8df4b5 100644 --- a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt @@ -26,8 +26,8 @@ import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentProfileBinding import com.project.meongcare.databinding.LayoutLogoutDialogBinding import com.project.meongcare.databinding.LayoutMedicalRecordDialogBinding -import com.project.meongcare.aws.util.ProfileImageUtils.createMultipartFromUri -import com.project.meongcare.aws.util.ProfileImageUtils.getMultipartFileName +import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri +import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName import com.project.meongcare.info.viewmodel.ProfileViewModel import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener diff --git a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt index a9c08945..ce1b7215 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt @@ -16,8 +16,8 @@ import com.project.meongcare.BirthdayBottomSheetFragment import com.project.meongcare.R import com.project.meongcare.aws.util.DOG_FOLDER_PATH import com.project.meongcare.aws.util.PARENT_FOLDER_PATH -import com.project.meongcare.aws.util.ProfileImageUtils.createMultipartFromUri -import com.project.meongcare.aws.util.ProfileImageUtils.getMultipartFileName +import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri +import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentDogAddOnBoardingBinding import com.project.meongcare.medicalrecord.viewmodel.UserViewModel From d86439c0417032d7e705896e3bae880e00afa25c Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 17:38:18 +0900 Subject: [PATCH 043/119] =?UTF-8?q?fix:=20=EA=B0=95=EC=95=84=EC=A7=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=ED=99=94=EB=A9=B4=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EB=8D=98=20=EC=97=94=ED=84=B0?= =?UTF-8?q?=ED=8B=B0=EC=99=80=20=ED=95=A8=EC=88=98=EC=9D=98=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20import=20=EB=AC=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/info/view/PetInfoFragment.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/PetInfoFragment.kt b/app/src/main/java/com/project/meongcare/info/view/PetInfoFragment.kt index 89c4e64a..a980fdf6 100644 --- a/app/src/main/java/com/project/meongcare/info/view/PetInfoFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/PetInfoFragment.kt @@ -15,8 +15,8 @@ import com.project.meongcare.info.model.entities.GetDogInfoResponse import com.project.meongcare.info.viewmodel.ProfileViewModel import com.project.meongcare.login.model.data.local.UserPreferences import com.project.meongcare.login.model.data.repository.LoginRepository -import com.project.meongcare.onboarding.view.Gender -import com.project.meongcare.onboarding.view.dateFormat +import com.project.meongcare.onboarding.model.entities.Gender +import com.project.meongcare.onboarding.util.DogAddOnBoardingDateUtils.dateFormat import com.project.meongcare.snackbar.view.CustomSnackBar import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.collectLatest From ef14a16c171632c0d4a118788dcaecb59895e2c0 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 17:39:13 +0900 Subject: [PATCH 044/119] =?UTF-8?q?fix:=20=ED=94=84=EB=A1=9C=ED=95=84=20Fr?= =?UTF-8?q?agment=EC=97=90=EC=84=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C?= =?UTF-8?q?=20=EC=BD=94=EB=A3=A8=ED=8B=B4=20=EC=82=AC=EC=9A=A9=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/info/view/ProfileFragment.kt | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt index ef8df4b5..f37549da 100644 --- a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt @@ -10,7 +10,6 @@ import androidx.core.content.ContextCompat import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels -import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.LinearLayoutManager import com.bumptech.glide.Glide @@ -33,7 +32,6 @@ import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener import com.project.meongcare.snackbar.view.CustomSnackBar import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch import okhttp3.MultipartBody @AndroidEntryPoint @@ -78,11 +76,8 @@ class ProfileFragment : Fragment(), PhotoMenuListener { } } 401 -> { - lifecycleScope.launch { - val refreshToken = currentRefreshToken - if (refreshToken.isNotEmpty()) { - reissueAccessToken() - } + if (currentRefreshToken.isNotEmpty()) { + reissueAccessToken() } } else -> { @@ -106,11 +101,8 @@ class ProfileFragment : Fragment(), PhotoMenuListener { adapter.updateDogList(dogListResponse.body()?.dogs!!) } 401 -> { - lifecycleScope.launch { - val refreshToken = currentRefreshToken - if (refreshToken.isNotEmpty()) { - reissueAccessToken() - } + if (currentRefreshToken.isNotEmpty()) { + reissueAccessToken() } } else -> { From 3add7946c676b86fd35c819c069aa76c84026168 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 17:41:16 +0900 Subject: [PATCH 045/119] =?UTF-8?q?fix:=20=EC=98=81=EC=96=91=EC=A0=9C=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EB=93=B1=EB=A1=9D=20=EC=8B=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supplement/view/SupplementAddFragment.kt | 70 ++++++++++++++++--- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt b/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt index 943f5af5..2e859585 100644 --- a/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt +++ b/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt @@ -13,6 +13,7 @@ import android.widget.ImageView import android.widget.TextView import androidx.core.content.ContextCompat.getColor import androidx.fragment.app.Fragment +import androidx.fragment.app.viewModels import androidx.lifecycle.ViewModelProvider import androidx.navigation.NavController import androidx.navigation.fragment.findNavController @@ -21,8 +22,14 @@ import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide import com.project.meongcare.MainActivity import com.project.meongcare.R +import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri +import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName +import com.project.meongcare.aws.util.PARENT_FOLDER_PATH +import com.project.meongcare.aws.util.SUPPLEMENTS_FOLDER_PATH +import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentSupplementAddBinding import com.project.meongcare.databinding.ItemSupplementAddTimeBinding +import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.snackbar.view.CustomSnackBar import com.project.meongcare.supplement.model.data.local.OnPictureChangedListener import com.project.meongcare.supplement.model.data.repository.SupplementRepository @@ -34,13 +41,24 @@ import com.project.meongcare.supplement.utils.SupplementUtils.Companion.showTime import com.project.meongcare.supplement.view.bottomSheet.SupplementPictureBottomSheetDialogFragment import com.project.meongcare.supplement.viewmodel.SupplementViewModel import com.project.meongcare.supplement.viewmodel.SupplementViewModelFactory +import dagger.hilt.android.AndroidEntryPoint +import okhttp3.MultipartBody +@AndroidEntryPoint class SupplementAddFragment : Fragment(), OnPictureChangedListener { lateinit var fragmentSupplementAddBinding: FragmentSupplementAddBinding lateinit var mainActivity: MainActivity lateinit var supplementViewModel: SupplementViewModel lateinit var navController: NavController + private val awsS3ViewModel: AWSS3ViewModel by viewModels() + private val userViewModel: UserViewModel by viewModels() + + private lateinit var multipartImage: MultipartBody.Part + private lateinit var fileName: String + + private var accessToken = "" + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -49,6 +67,7 @@ class SupplementAddFragment : Fragment(), OnPictureChangedListener { fragmentSupplementAddBinding = FragmentSupplementAddBinding.inflate(layoutInflater) mainActivity = activity as MainActivity navController = findNavController() + getAccessToken() val factory = SupplementViewModelFactory(SupplementRepository()) supplementViewModel = ViewModelProvider(this, factory)[SupplementViewModel::class.java] @@ -184,15 +203,7 @@ class SupplementAddFragment : Fragment(), OnPictureChangedListener { buttonSupplementAddComplete.setOnClickListener { checkInput() if (checkInput()) { - val brandName = editTextSupplementAddBrandName.text.toString() - val name = editTextSupplementAddName.text.toString() - val imgUri = supplementViewModel.supplementAddImg.value - - supplementViewModel.addSupplement( - brandName, - name, - imgUri ?: Uri.EMPTY, - ) + getPreSignedUrl() } } } @@ -341,6 +352,47 @@ class SupplementAddFragment : Fragment(), OnPictureChangedListener { } } + private fun getAccessToken() { + userViewModel.accessTokenPreferencesLiveData.observe(viewLifecycleOwner) { accessToken -> + if (accessToken != null) { + this.accessToken = accessToken + } + } + } + + private fun getPreSignedUrl() { + multipartImage = createMultipartFromUri(requireContext(), supplementViewModel.supplementAddImg.value) + fileName = "$PARENT_FOLDER_PATH$SUPPLEMENTS_FOLDER_PATH${getMultipartFileName(multipartImage)}" + awsS3ViewModel.getPreSignedUrl(accessToken, fileName) + awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> + if (response != null) { + uploadImage(response.preSignedUrl) + Log.d("uploadedImage", response.preSignedUrl) + } + } + } + + private fun uploadImage(preSignedUrl: String) { + awsS3ViewModel.uploadImageToS3(preSignedUrl, multipartImage) + awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> + if (response == 200) { +// postSupplement() + } + } + } + + private fun postSupplement() { + val brandName = fragmentSupplementAddBinding.editTextSupplementAddBrandName.text.toString() + val name = fragmentSupplementAddBinding.editTextSupplementAddName.text.toString() + val imgUri = supplementViewModel.supplementAddImg.value + + supplementViewModel.addSupplement( + brandName, + name, + imgUri ?: Uri.EMPTY, + ) + } + private fun showPictureBottomSheet() { val bottomSheetFragment = SupplementPictureBottomSheetDialogFragment() From 060921add1c1be82970cc79ddc1bfba0771f884c Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 18:20:02 +0900 Subject: [PATCH 046/119] =?UTF-8?q?fix:=20=EC=82=AC=EB=A3=8C=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=88=98=EC=A0=95=20=EC=8B=9C=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/feed/view/FeedEditFragment.kt | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt b/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt index 59c0b5e1..0b6b731b 100644 --- a/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt @@ -22,6 +22,11 @@ import com.archit.calendardaterangepicker.customviews.CalendarListener import com.archit.calendardaterangepicker.customviews.DateRangeCalendarView import com.bumptech.glide.Glide import com.project.meongcare.R +import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri +import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName +import com.project.meongcare.aws.util.FEED_FOLDER_PATH +import com.project.meongcare.aws.util.PARENT_FOLDER_PATH +import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentFeedAddEditBinding import com.project.meongcare.excreta.utils.SUCCESS import com.project.meongcare.feed.model.data.local.FeedPhotoListener @@ -67,10 +72,13 @@ class FeedEditFragment : Fragment(), FeedPhotoListener { private var feedRecordId = 0L private lateinit var feedInfo: FeedDetailGetResponse private lateinit var feedPutInfo: FeedPutInfo + private lateinit var multipartImage: MultipartBody.Part + private lateinit var fileName: String private var recommendIntake = 0.0 private var selectedStartDate = "" private var selectedEndDate: String? = null + private val awsS3ViewModel: AWSS3ViewModel by viewModels() private val feedPutViewModel: FeedPutViewModel by viewModels() private val dogViewModel: DogViewModel by viewModels() private val userViewModel: UserViewModel by viewModels() @@ -491,12 +499,43 @@ class FeedEditFragment : Fragment(), FeedPhotoListener { } if (isValid) { - editFeedInfo() +// editFeedInfo() + getPreSignedUrl() } } } } + private fun getPreSignedUrl() { + awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> + if (response != null) { + uploadImage(response.preSignedUrl) + } + } + val imageUri = feedPutViewModel.feedImage.value + + if (imageUri == null) { + lifecycleScope.launch { + multipartImage = convertFeedImageUrl(requireContext(), feedInfo.imageURL) + fileName = "$PARENT_FOLDER_PATH$FEED_FOLDER_PATH${getMultipartFileName(multipartImage)}" + awsS3ViewModel.getPreSignedUrl(accessToken, fileName) + } + } else { + multipartImage = createMultipartFromUri(requireContext(), imageUri) + fileName = "$PARENT_FOLDER_PATH$FEED_FOLDER_PATH${getMultipartFileName(multipartImage)}" + awsS3ViewModel.getPreSignedUrl(accessToken, fileName) + } + } + + private fun uploadImage(preSignedUrl: String) { + awsS3ViewModel.uploadImageToS3(preSignedUrl, multipartImage) + awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> + if (response == 200) { +// editFeedInfo() + } + } + } + private fun editFeedInfo() { binding.apply { createFeedInfo() From 1d8115e1145686d6b1af72bda67df449fdaa3369 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Sat, 30 Mar 2024 19:45:22 +0900 Subject: [PATCH 047/119] =?UTF-8?q?fix:=20=EB=8C=80=EC=86=8C=EB=B3=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20Fragment=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excreta/view/ExcretaEditFragment.kt | 110 ++++++++++++------ 1 file changed, 77 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaEditFragment.kt b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaEditFragment.kt index 94cb281b..5a4835cc 100644 --- a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaEditFragment.kt @@ -8,10 +8,15 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels +import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import com.bumptech.glide.Glide import com.project.meongcare.CalendarBottomSheetFragment import com.project.meongcare.R +import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri +import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUrl +import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName +import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentExcretaAddEditBinding import com.project.meongcare.excreta.model.data.local.PhotoListener import com.project.meongcare.excreta.model.entities.Excreta @@ -34,17 +39,22 @@ import com.project.meongcare.excreta.viewmodel.ExcretaPatchViewModel import com.project.meongcare.feed.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.DateSubmitListener import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.launch +import okhttp3.MultipartBody @AndroidEntryPoint class ExcretaEditFragment : Fragment(), DateSubmitListener, PhotoListener { private var _binding: FragmentExcretaAddEditBinding? = null val binding get() = _binding!! + private val awsS3ViewModel: AWSS3ViewModel by viewModels() private val excretaPatchViewModel: ExcretaPatchViewModel by viewModels() private val userViewModel: UserViewModel by viewModels() private val calendarModalBottomSheet = CalendarBottomSheetFragment() private lateinit var excretaInfo: ExcretaDetailGetResponse + private lateinit var multipartImage: MultipartBody.Part + private lateinit var fileName: String private var excretaDate = "" private var accessToken = "" @@ -187,41 +197,75 @@ class ExcretaEditFragment : Fragment(), DateSubmitListener, PhotoListener { } if (isValid) { - val excretaType = - if (checkboxExcretaaddUrine.isChecked) { - Excreta.URINE.toString() - } else { - Excreta.FECES.toString() - } + getPreSignedUrl() + } + } + } + } - val excretaTime = - ExcretaDateTimeUtils.convertTimeFormat(timepikerExcretaaddTime) - val excretaDateTime = "${excretaDate}T$excretaTime" + private fun getPreSignedUrl() { + awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> + if (response != null) { + uploadImage(response.preSignedUrl) + } + } + val imageUri = excretaPatchViewModel.excretaImage.value - val currentImageUri = excretaPatchViewModel.excretaImage.value - excretaPatchViewModel.patchExcreta( - accessToken, - getExcretaId(), - excretaType, - excretaDateTime, - requireContext(), - currentImageUri ?: Uri.EMPTY, - ) - excretaPatchViewModel.excretaPatched.observe(viewLifecycleOwner) { response -> - if (response == SUCCESS) { - showSuccessSnackBar( - requireView(), - EXCRETA_PATCH_SUCCESS, - ) - findNavController().popBackStack() - } else { - showFailureSnackBar( - requireView(), - EXCRETA_PATCH_FAILURE, - ) - } - } - } + if (imageUri == null) { + lifecycleScope.launch { + multipartImage = createMultipartFromUrl(requireContext(), excretaInfo.excretaImageURL) + fileName = getMultipartFileName(multipartImage) + awsS3ViewModel.getPreSignedUrl(accessToken, fileName) + } + } else { + multipartImage = createMultipartFromUri(requireContext(), imageUri) + fileName = getMultipartFileName(multipartImage) + awsS3ViewModel.getPreSignedUrl(accessToken, fileName) + } + } + + private fun uploadImage(preSignedUrl: String) { + awsS3ViewModel.uploadImageToS3(preSignedUrl, multipartImage) + awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> + if (response == 200) { +// patchExcreta() + } + } + } + + private fun patchExcreta() { + val excretaType = + if (binding.checkboxExcretaaddUrine.isChecked) { + Excreta.URINE.toString() + } else { + Excreta.FECES.toString() + } + + val excretaTime = + ExcretaDateTimeUtils.convertTimeFormat(binding.timepikerExcretaaddTime) + val excretaDateTime = "${excretaDate}T$excretaTime" + + val currentImageUri = excretaPatchViewModel.excretaImage.value + excretaPatchViewModel.patchExcreta( + accessToken, + getExcretaId(), + excretaType, + excretaDateTime, + requireContext(), + currentImageUri ?: Uri.EMPTY, + ) + excretaPatchViewModel.excretaPatched.observe(viewLifecycleOwner) { response -> + if (response == SUCCESS) { + showSuccessSnackBar( + requireView(), + EXCRETA_PATCH_SUCCESS, + ) + findNavController().popBackStack() + } else { + showFailureSnackBar( + requireView(), + EXCRETA_PATCH_FAILURE, + ) } } } From f090bf1b4e3438245bf88b3c77abf044995bf6f7 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Mon, 1 Apr 2024 17:48:58 +0900 Subject: [PATCH 048/119] =?UTF-8?q?rename:=20Dog=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=AA=85=EC=9D=84=20DogPostRequest=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onboarding/model/entities/{Dog.kt => DogPostRequest.kt} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename app/src/main/java/com/project/meongcare/onboarding/model/entities/{Dog.kt => DogPostRequest.kt} (91%) diff --git a/app/src/main/java/com/project/meongcare/onboarding/model/entities/Dog.kt b/app/src/main/java/com/project/meongcare/onboarding/model/entities/DogPostRequest.kt similarity index 91% rename from app/src/main/java/com/project/meongcare/onboarding/model/entities/Dog.kt rename to app/src/main/java/com/project/meongcare/onboarding/model/entities/DogPostRequest.kt index c9453783..87477297 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/model/entities/Dog.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/model/entities/DogPostRequest.kt @@ -1,6 +1,6 @@ package com.project.meongcare.onboarding.model.entities -data class Dog( +data class DogPostRequest( val name: String, val type: String, val sex: String, From 8140d601089ade28ed55eb664e8163065f88754a Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Mon, 1 Apr 2024 17:52:19 +0900 Subject: [PATCH 049/119] =?UTF-8?q?fix:=20API=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EA=B0=95=EC=95=84=EC=A7=80=20?= =?UTF-8?q?Post=20=EC=8B=9C=20Request=20Body=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Multipart 어노테이션 삭제 --- .../onboarding/model/data/remote/DogAddApi.kt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/model/data/remote/DogAddApi.kt b/app/src/main/java/com/project/meongcare/onboarding/model/data/remote/DogAddApi.kt index 6464f12d..06ec6aa7 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/model/data/remote/DogAddApi.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/model/data/remote/DogAddApi.kt @@ -1,19 +1,15 @@ package com.project.meongcare.onboarding.model.data.remote -import okhttp3.MultipartBody -import okhttp3.RequestBody +import com.project.meongcare.onboarding.model.entities.DogPostRequest import retrofit2.Response +import retrofit2.http.Body import retrofit2.http.Header -import retrofit2.http.Multipart import retrofit2.http.POST -import retrofit2.http.Part interface DogAddApi { - @Multipart @POST("dog") suspend fun postDogInfo( @Header("AccessToken") accessToken: String, - @Part file: MultipartBody.Part, - @Part("dto") dto: RequestBody, + @Body dogPostRequest: DogPostRequest, ): Response } From 0109486899bd0f61085f62daa8dc8ad8513f046f Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Mon, 1 Apr 2024 17:59:09 +0900 Subject: [PATCH 050/119] =?UTF-8?q?fix:=20DogPostRequest=EC=97=90=20imageU?= =?UTF-8?q?RL=20=ED=94=84=EB=A1=9C=ED=8D=BC=ED=8B=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/onboarding/model/entities/DogPostRequest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/project/meongcare/onboarding/model/entities/DogPostRequest.kt b/app/src/main/java/com/project/meongcare/onboarding/model/entities/DogPostRequest.kt index 87477297..49e77ca5 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/model/entities/DogPostRequest.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/model/entities/DogPostRequest.kt @@ -10,4 +10,5 @@ data class DogPostRequest( val backRound: Double?, val neckRound: Double?, val chestRound: Double?, + val imageURL: String, ) From 9802bf6d6eceaedcfd8e6d3e2af79c9dad664cbf Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Mon, 1 Apr 2024 18:03:41 +0900 Subject: [PATCH 051/119] =?UTF-8?q?fix:=20=EA=B0=95=EC=95=84=EC=A7=80=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=A0=88=ED=8F=AC=EC=A7=80=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=EC=99=80=20=EA=B5=AC=ED=98=84=EC=B2=B4=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onboarding/model/data/repository/DogAddRepository.kt | 6 ++---- .../model/data/repository/DogAddRepositoryImpl.kt | 8 +++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/model/data/repository/DogAddRepository.kt b/app/src/main/java/com/project/meongcare/onboarding/model/data/repository/DogAddRepository.kt index 61c3a97d..b6506560 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/model/data/repository/DogAddRepository.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/model/data/repository/DogAddRepository.kt @@ -1,12 +1,10 @@ package com.project.meongcare.onboarding.model.data.repository -import okhttp3.MultipartBody -import okhttp3.RequestBody +import com.project.meongcare.onboarding.model.entities.DogPostRequest interface DogAddRepository { suspend fun postDogInfo( accessToken: String, - file: MultipartBody.Part, - dto: RequestBody, + dogPostRequest: DogPostRequest, ): Int } diff --git a/app/src/main/java/com/project/meongcare/onboarding/model/data/repository/DogAddRepositoryImpl.kt b/app/src/main/java/com/project/meongcare/onboarding/model/data/repository/DogAddRepositoryImpl.kt index 301eb524..7894b0e0 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/model/data/repository/DogAddRepositoryImpl.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/model/data/repository/DogAddRepositoryImpl.kt @@ -2,8 +2,7 @@ package com.project.meongcare.onboarding.model.data.repository import android.util.Log import com.project.meongcare.onboarding.model.data.remote.DogAddRetrofitClient -import okhttp3.MultipartBody -import okhttp3.RequestBody +import com.project.meongcare.onboarding.model.entities.DogPostRequest import javax.inject.Inject class DogAddRepositoryImpl @@ -11,11 +10,10 @@ class DogAddRepositoryImpl constructor(private val dogAddRetrofitClient: DogAddRetrofitClient) : DogAddRepository { override suspend fun postDogInfo( accessToken: String, - file: MultipartBody.Part, - dto: RequestBody, + dogPostRequest: DogPostRequest, ): Int { try { - val response = dogAddRetrofitClient.dogAddApi.postDogInfo(accessToken, file, dto) + val response = dogAddRetrofitClient.dogAddApi.postDogInfo(accessToken, dogPostRequest) if (response.isSuccessful) { Log.d("DogAddRepository", "통신 성공(code-${response.code()})") return response.code() From 21f0842d7dbef65472e7805d3506f57d41f3b5d3 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Mon, 1 Apr 2024 18:04:23 +0900 Subject: [PATCH 052/119] =?UTF-8?q?fix:=20DogAddViewModel=EC=9D=98=20postD?= =?UTF-8?q?ogInfo=20=ED=95=A8=EC=88=98=20=EB=A7=A4=EA=B0=9C=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/onboarding/viewmodel/DogAddViewModel.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/viewmodel/DogAddViewModel.kt b/app/src/main/java/com/project/meongcare/onboarding/viewmodel/DogAddViewModel.kt index 9718f62f..62d6b81a 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/viewmodel/DogAddViewModel.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/viewmodel/DogAddViewModel.kt @@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.project.meongcare.onboarding.model.data.repository.DogAddRepository +import com.project.meongcare.onboarding.model.entities.DogPostRequest import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import okhttp3.MultipartBody @@ -40,11 +41,10 @@ class DogAddViewModel fun postDogInfo( accessToken: String, - file: MultipartBody.Part, - dto: RequestBody, + dogPostRequest: DogPostRequest, ) { viewModelScope.launch { - _dogAddResponse.value = dogAddRepository.postDogInfo(accessToken, file, dto) + _dogAddResponse.value = dogAddRepository.postDogInfo(accessToken, dogPostRequest) } } } From ed0ce47224fe5dc7c92ef48c514adb316603e0ec Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Mon, 1 Apr 2024 18:09:49 +0900 Subject: [PATCH 053/119] =?UTF-8?q?feat:=20=EA=B0=95=EC=95=84=EC=A7=80=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=ED=99=94=EB=A9=B4=EC=97=90=EC=84=9C=20AWS?= =?UTF-8?q?=EC=97=90=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5=20=EC=8B=9C=20=EA=B0=95=EC=95=84=EC=A7=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20POST=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/DogAddOnBoardingFragment.kt | 73 ++++++++++--------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt index ce1b7215..47482e76 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt @@ -23,7 +23,10 @@ import com.project.meongcare.databinding.FragmentDogAddOnBoardingBinding import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.DateSubmitListener import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener +import com.project.meongcare.onboarding.model.entities.DogPostRequest import com.project.meongcare.onboarding.util.DogAddOnBoardingDateUtils.dateFormat +import com.project.meongcare.onboarding.util.DogAddOnBoardingInfoUtils.bodySizeCheck +import com.project.meongcare.onboarding.util.DogAddOnBoardingInfoUtils.getCheckedGender import com.project.meongcare.onboarding.viewmodel.DogAddViewModel import com.project.meongcare.onboarding.viewmodel.DogTypeSharedViewModel import com.project.meongcare.snackbar.view.CustomSnackBar @@ -49,7 +52,7 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen private lateinit var accessToken: String private lateinit var refreshToken: String private lateinit var multipartImage: MultipartBody.Part - private lateinit var fileName: String + private lateinit var filePath: String override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -118,8 +121,6 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen override fun onUriPassed(uri: Uri) { dogAddViewModel.getDogProfileImage(uri) - multipartImage = createMultipartFromUri(requireContext(), uri) - fileName = getMultipartFileName(multipartImage) } override fun onDateSubmit(str: String) { @@ -246,38 +247,36 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { - // 저장된 이미지 경로를 데이터와 함께 서버로 전달 -// val dogName = binding.edittextPetaddName.text.toString() -// val dogType = binding.edittextPetaddSelectType.text.toString() -// val dogGender = getCheckedGender(binding.root, binding.chipgroupPetaddGroupGender.checkedChipId) -// val dogBirth = dogAddViewModel.dogBirthDate.value!! -// val dogWeight: Double = binding.edittextPetaddWeight.text.toString().toDouble() -// val dogBack: Double? = bodySizeCheck(binding.edittextPetaddBackLength.text.toString()) -// val dogNeck: Double? = bodySizeCheck(binding.edittextPetaddNeckCircumference.text.toString()) -// val dogChest: Double? = bodySizeCheck(binding.edittextPetaddChestCircumference.text.toString()) -// val dog = -// Dog( -// dogName, -// dogType, -// dogGender, -// dogBirth, -// isCbxChecked, -// dogWeight, -// dogBack, -// dogNeck, -// dogChest, -// ) -// val json = Gson().toJson(dog) -// val requestBody: RequestBody = json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) -// val filePart = createMultipartBody(requireContext(), dogAddViewModel.dogProfileImage.value) -// -// if (accessToken.isNotEmpty()) { -// dogAddViewModel.postDogInfo( -// accessToken, -// filePart, -// requestBody, -// ) -// } + val name = binding.edittextPetaddName.text.toString() + val type = binding.edittextPetaddSelectType.text.toString() + val sex = getCheckedGender(binding.root, binding.chipgroupPetaddGroupGender.checkedChipId) + val birthDate = dogAddViewModel.dogBirthDate.value!! + val castrate = binding.checkboxPetaddNeuterStatus.isChecked + val weight: Double = binding.edittextPetaddWeight.text.toString().toDouble() + val backRound: Double? = bodySizeCheck(binding.edittextPetaddBackLength.text.toString()) + val neckRound: Double? = bodySizeCheck(binding.edittextPetaddNeckCircumference.text.toString()) + val chestRound: Double? = bodySizeCheck(binding.edittextPetaddChestCircumference.text.toString()) + + val dogPostRequest = + DogPostRequest( + name, + type, + sex, + birthDate, + castrate, + weight, + backRound, + neckRound, + chestRound, + filePath, + ) + + if (accessToken.isNotEmpty()) { + dogAddViewModel.postDogInfo( + accessToken, + dogPostRequest, + ) + } } } } @@ -316,7 +315,9 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen return@setOnClickListener } - val filePath = "$PARENT_FOLDER_PATH$DOG_FOLDER_PATH$fileName" + multipartImage = createMultipartFromUri(requireContext(), dogAddViewModel.dogProfileImage.value) + val fileName = getMultipartFileName(multipartImage) + filePath = "$PARENT_FOLDER_PATH$DOG_FOLDER_PATH$fileName" awsS3ViewModel.getPreSignedUrl(accessToken, filePath) } } From 98fb5c8f26b1fa163e22b1dee9252c3d33ee78e7 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 15:25:21 +0900 Subject: [PATCH 054/119] =?UTF-8?q?chore:=20=EC=95=B1=EC=88=98=EC=A4=80=20?= =?UTF-8?q?gradle=EC=97=90=20aws=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20base=20ur?= =?UTF-8?q?l=EC=9D=84=20BuildConfigField=EB=A1=9C=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/app/build.gradle b/app/build.gradle index 8e93865b..fe1671de 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,6 +30,7 @@ android { buildConfigField "String", "NAVER_OAUTH_CLIENT_SECRET", properties['naver_oauth_client_secret'] buildConfigField "String", "NAVER_OAUTH_CLIENT_NAME", properties['naver_oauth_client_name'] buildConfigField "String", "GOOGLE_CLIENT_ID", properties['google_client_id'] + buildConfigField "String", "AWS_S3_BASE_URL", properties['aws_s3_base_url'] manifestPlaceholders["kakaoNativeAppKeyManifest"] = properties["kakao_native_app_key_manifest"] as String } From 15462f8b189fb4fed88c3af776fa043bc70ca7a2 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 15:29:36 +0900 Subject: [PATCH 055/119] =?UTF-8?q?fix:=20AWS=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=ED=95=98?= =?UTF-8?q?=EB=8A=94=20api=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 이미지를 MultipartBody.Part 형식이 아닌 RequestBody 형식으로 보내도록 수정 --- .../project/meongcare/aws/model/data/remote/AWSS3Api.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3Api.kt b/app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3Api.kt index 51eac751..637d6391 100644 --- a/app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3Api.kt +++ b/app/src/main/java/com/project/meongcare/aws/model/data/remote/AWSS3Api.kt @@ -1,13 +1,12 @@ package com.project.meongcare.aws.model.data.remote import com.project.meongcare.aws.model.entities.AWSS3Response -import okhttp3.MultipartBody +import okhttp3.RequestBody import retrofit2.Response +import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.Header -import retrofit2.http.Multipart import retrofit2.http.PUT -import retrofit2.http.Part import retrofit2.http.Query import retrofit2.http.Url @@ -18,10 +17,9 @@ interface AWSS3Api { @Query("fileName") fileName: String, ): Response - @Multipart @PUT suspend fun uploadImageToS3( @Url preSignedUrl: String, - @Part file: MultipartBody.Part, + @Body image: RequestBody, ): Response } From 39ac5d4bb2e5329a693f492e69cde3217c8feccc Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 15:36:55 +0900 Subject: [PATCH 056/119] =?UTF-8?q?fix:=20AWS=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20Repository,=20Impleme?= =?UTF-8?q?nt,=20ViewModel=EC=9D=98=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=9D=B8=EC=9E=90=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/aws/model/data/repository/AWSS3Repository.kt | 4 ++-- .../aws/model/data/repository/AWSS3RepositoryImpl.kt | 6 +++--- .../com/project/meongcare/aws/viewmodel/AWSS3ViewModel.kt | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3Repository.kt b/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3Repository.kt index b12d9e6a..3f94d1da 100644 --- a/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3Repository.kt +++ b/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3Repository.kt @@ -1,7 +1,7 @@ package com.project.meongcare.aws.model.data.repository import com.project.meongcare.aws.model.entities.AWSS3Response -import okhttp3.MultipartBody +import okhttp3.RequestBody interface AWSS3Repository { suspend fun getPreSignedUrl( @@ -11,6 +11,6 @@ interface AWSS3Repository { suspend fun uploadImageToS3( preSignedUrl: String, - file: MultipartBody.Part, + image: RequestBody, ): Int? } diff --git a/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3RepositoryImpl.kt b/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3RepositoryImpl.kt index ecc4c051..bc3b803e 100644 --- a/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3RepositoryImpl.kt +++ b/app/src/main/java/com/project/meongcare/aws/model/data/repository/AWSS3RepositoryImpl.kt @@ -3,7 +3,7 @@ package com.project.meongcare.aws.model.data.repository import android.util.Log import com.project.meongcare.aws.model.data.remote.AWSS3RetrofitClient import com.project.meongcare.aws.model.entities.AWSS3Response -import okhttp3.MultipartBody +import okhttp3.RequestBody import org.json.JSONObject import java.lang.Exception import javax.inject.Inject @@ -33,10 +33,10 @@ class AWSS3RepositoryImpl override suspend fun uploadImageToS3( preSignedUrl: String, - file: MultipartBody.Part, + image: RequestBody, ): Int? { return try { - val response = awsS3RetrofitClient.awsS3Api.uploadImageToS3(preSignedUrl, file) + val response = awsS3RetrofitClient.awsS3Api.uploadImageToS3(preSignedUrl, image) if (response.isSuccessful) { Log.d("AWSS3Repo-upload", "통신 성공 ${response.code()}") response.code() diff --git a/app/src/main/java/com/project/meongcare/aws/viewmodel/AWSS3ViewModel.kt b/app/src/main/java/com/project/meongcare/aws/viewmodel/AWSS3ViewModel.kt index c11ea4b9..fb96db0a 100644 --- a/app/src/main/java/com/project/meongcare/aws/viewmodel/AWSS3ViewModel.kt +++ b/app/src/main/java/com/project/meongcare/aws/viewmodel/AWSS3ViewModel.kt @@ -8,7 +8,7 @@ import com.project.meongcare.aws.model.data.repository.AWSS3Repository import com.project.meongcare.aws.model.entities.AWSS3Response import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch -import okhttp3.MultipartBody +import okhttp3.RequestBody import javax.inject.Inject @HiltViewModel @@ -34,10 +34,10 @@ class AWSS3ViewModel fun uploadImageToS3( preSignedUrl: String, - file: MultipartBody.Part, + image: RequestBody, ) { viewModelScope.launch { - _uploadImageResponse.value = awsS3Repository.uploadImageToS3(preSignedUrl, file) + _uploadImageResponse.value = awsS3Repository.uploadImageToS3(preSignedUrl, image) } } } From 1dc326bcb5d69e4972184ae386185d04ada68545 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 15:43:53 +0900 Subject: [PATCH 057/119] =?UTF-8?q?fix:=20DogPostRequest=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EC=9D=98=20imageURL=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=8D=BC=ED=8B=B0=20nullable=20=EC=84=A0=EC=96=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/onboarding/model/entities/DogPostRequest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/model/entities/DogPostRequest.kt b/app/src/main/java/com/project/meongcare/onboarding/model/entities/DogPostRequest.kt index 49e77ca5..dec0e7ad 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/model/entities/DogPostRequest.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/model/entities/DogPostRequest.kt @@ -10,5 +10,5 @@ data class DogPostRequest( val backRound: Double?, val neckRound: Double?, val chestRound: Double?, - val imageURL: String, + val imageURL: String?, ) From 90497c140a40448511ab71038614c06a90bbf81e Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 15:45:23 +0900 Subject: [PATCH 058/119] =?UTF-8?q?feat:=20uri=EB=A5=BC=20file=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=ED=99=98=ED=95=98=EB=8A=94=20converUriToFile=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=84=A0=EC=96=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/aws/util/AWSS3ImageUtils.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt b/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt index a6b65a27..fa24ac69 100644 --- a/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt +++ b/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt @@ -9,6 +9,7 @@ import okhttp3.MultipartBody import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.toRequestBody import java.io.File +import java.io.FileOutputStream import java.net.URL import java.util.UUID @@ -37,6 +38,23 @@ object AWSS3ImageUtils { return MultipartBody.Part.createFormData("file", "", emptyBody) } + fun convertUriToFile( + context: Context, + uri: Uri, + ): File { + val contentResolver = context.contentResolver + val file = File(context.cacheDir, createUUID()) + file.deleteOnExit() + + contentResolver.openInputStream(uri).use { inputStream -> + FileOutputStream(file).use { outputStream -> + inputStream?.copyTo(outputStream) + } + } + + return file + } + suspend fun createMultipartFromUrl( context: Context, url: String? From 8bf22a57d14a99eda3b7860896a1ea3290444a58 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 15:49:30 +0900 Subject: [PATCH 059/119] =?UTF-8?q?refactor:=20postDogInfo=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=EC=97=90=20=EB=B0=98=EB=A0=A4=EB=8F=99=EB=AC=BC=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20POST=ED=95=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=82=BD=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/DogAddOnBoardingFragment.kt | 63 ++++++++++--------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt index 47482e76..dff10e3c 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt @@ -247,40 +247,43 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { - val name = binding.edittextPetaddName.text.toString() - val type = binding.edittextPetaddSelectType.text.toString() - val sex = getCheckedGender(binding.root, binding.chipgroupPetaddGroupGender.checkedChipId) - val birthDate = dogAddViewModel.dogBirthDate.value!! - val castrate = binding.checkboxPetaddNeuterStatus.isChecked - val weight: Double = binding.edittextPetaddWeight.text.toString().toDouble() - val backRound: Double? = bodySizeCheck(binding.edittextPetaddBackLength.text.toString()) - val neckRound: Double? = bodySizeCheck(binding.edittextPetaddNeckCircumference.text.toString()) - val chestRound: Double? = bodySizeCheck(binding.edittextPetaddChestCircumference.text.toString()) - - val dogPostRequest = - DogPostRequest( - name, - type, - sex, - birthDate, - castrate, - weight, - backRound, - neckRound, - chestRound, - filePath, - ) - - if (accessToken.isNotEmpty()) { - dogAddViewModel.postDogInfo( - accessToken, - dogPostRequest, - ) - } } } } + private fun postDogInfo(imageURL: String?) { + val name = binding.edittextPetaddName.text.toString() + val type = binding.edittextPetaddSelectType.text.toString() + val sex = getCheckedGender(binding.root, binding.chipgroupPetaddGroupGender.checkedChipId) + val birthDate = dogAddViewModel.dogBirthDate.value!! + val castrate = binding.checkboxPetaddNeuterStatus.isChecked + val weight: Double = binding.edittextPetaddWeight.text.toString().toDouble() + val backRound: Double? = bodySizeCheck(binding.edittextPetaddBackLength.text.toString()) + val neckRound: Double? = bodySizeCheck(binding.edittextPetaddNeckCircumference.text.toString()) + val chestRound: Double? = bodySizeCheck(binding.edittextPetaddChestCircumference.text.toString()) + + val dogPostRequest = + DogPostRequest( + name, + type, + sex, + birthDate, + castrate, + weight, + backRound, + neckRound, + chestRound, + imageURL, + ) + + if (accessToken.isNotEmpty()) { + dogAddViewModel.postDogInfo( + accessToken, + dogPostRequest, + ) + } + } + private fun initCancelButtonVisibility() { when (isFirstRegister) { true -> binding.buttonCancel.visibility = View.GONE From bf86a2860f6614865d299e8463e8933b1f142a85 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 15:54:24 +0900 Subject: [PATCH 060/119] =?UTF-8?q?fix:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 이미지 미등록 시 DogPostRequest 객체 imageURL값 null 처리 - 이미지 업로드 시 파일 생성 로직 변경 (기존 createMultipartFromUri 메서드 -> convertUriToFile 메서드 사용) --- .../view/DogAddOnBoardingFragment.kt | 43 ++++++------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt index dff10e3c..eca33877 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt @@ -1,6 +1,5 @@ package com.project.meongcare.onboarding.view -import android.content.Context import android.net.Uri import android.os.Bundle import android.view.LayoutInflater @@ -13,11 +12,11 @@ import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import com.bumptech.glide.Glide import com.project.meongcare.BirthdayBottomSheetFragment +import com.project.meongcare.BuildConfig import com.project.meongcare.R +import com.project.meongcare.aws.util.AWSS3ImageUtils.convertUriToFile import com.project.meongcare.aws.util.DOG_FOLDER_PATH import com.project.meongcare.aws.util.PARENT_FOLDER_PATH -import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri -import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentDogAddOnBoardingBinding import com.project.meongcare.medicalrecord.viewmodel.UserViewModel @@ -32,9 +31,7 @@ import com.project.meongcare.onboarding.viewmodel.DogTypeSharedViewModel import com.project.meongcare.snackbar.view.CustomSnackBar import dagger.hilt.android.AndroidEntryPoint import okhttp3.MediaType.Companion.toMediaTypeOrNull -import okhttp3.MultipartBody import okhttp3.RequestBody.Companion.asRequestBody -import okhttp3.RequestBody.Companion.toRequestBody import java.io.File @AndroidEntryPoint @@ -51,7 +48,7 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen private lateinit var accessToken: String private lateinit var refreshToken: String - private lateinit var multipartImage: MultipartBody.Part + private lateinit var imageFile: File private lateinit var filePath: String override fun onCreate(savedInstanceState: Bundle?) { @@ -241,12 +238,15 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> if (response != null) { - awsS3ViewModel.uploadImageToS3(response.preSignedUrl, multipartImage) + val requestBody = imageFile.asRequestBody("image/*".toMediaTypeOrNull()) + awsS3ViewModel.uploadImageToS3(response.preSignedUrl, requestBody) } } awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { + val imageURL = BuildConfig.AWS_S3_BASE_URL + filePath + postDogInfo(imageURL) } } } @@ -318,30 +318,13 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen return@setOnClickListener } - multipartImage = createMultipartFromUri(requireContext(), dogAddViewModel.dogProfileImage.value) - val fileName = getMultipartFileName(multipartImage) - filePath = "$PARENT_FOLDER_PATH$DOG_FOLDER_PATH$fileName" - awsS3ViewModel.getPreSignedUrl(accessToken, filePath) - } - } -} - -fun createMultipartBody( - context: Context, - uri: Uri?, -): MultipartBody.Part { - if (uri != null) { - val inputStream = context.contentResolver.openInputStream(uri) - val file = File(context.cacheDir, "tempFile") - inputStream.use { input -> - file.outputStream().use { output -> - input?.copyTo(output) + if (dogAddViewModel.dogProfileImage.value == null) { + postDogInfo(null) + } else { + imageFile = convertUriToFile(requireContext(), dogAddViewModel.dogProfileImage.value!!) + filePath = "$PARENT_FOLDER_PATH$DOG_FOLDER_PATH${imageFile.name}" + awsS3ViewModel.getPreSignedUrl(accessToken, filePath) } } - val requestFile = file.asRequestBody("multipart/form-data".toMediaTypeOrNull()) - - return MultipartBody.Part.createFormData("file", file.name, requestFile) } - val emptyBody = "".toRequestBody("multipart/form-data".toMediaTypeOrNull()) - return MultipartBody.Part.createFormData("file", "", emptyBody) } From 4628cd10abce236ec4fd089f31cc739edeb0c317 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 16:34:26 +0900 Subject: [PATCH 061/119] =?UTF-8?q?fix:=20ExcretaInfo=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 클래스명 ExcretaInfo -> ExcretaPostRequest로 변경 - imageURL 프로퍼티 추가 --- .../model/entities/{ExcretaInfo.kt => ExcretaPostRequest.kt} | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename app/src/main/java/com/project/meongcare/excreta/model/entities/{ExcretaInfo.kt => ExcretaPostRequest.kt} (68%) diff --git a/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaInfo.kt b/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaPostRequest.kt similarity index 68% rename from app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaInfo.kt rename to app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaPostRequest.kt index b1c67e08..28f4c755 100644 --- a/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaInfo.kt +++ b/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaPostRequest.kt @@ -1,7 +1,8 @@ package com.project.meongcare.excreta.model.entities -data class ExcretaInfo( +data class ExcretaPostRequest( val dogId: Long, val excreta: String, val dateTime: String, + val imageURL: String?, ) From 2d68dcc513b6c48991a671e9de3bde794d6242bd Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 16:37:41 +0900 Subject: [PATCH 062/119] =?UTF-8?q?fix:=20=EB=B0=B1=EC=97=94=EB=93=9C=20Ex?= =?UTF-8?q?creta=20Post=20API=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20Excreta=20Post=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/remote/ExcretaRemoteDataSource.kt | 6 ++--- .../model/data/remote/ExcretaService.kt | 6 ++--- .../data/repository/ExcretaRepository.kt | 3 ++- .../data/repository/ExcretaRepositoryImpl.kt | 5 ++-- .../excreta/viewmodel/ExcretaAddViewModel.kt | 24 +++++-------------- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaRemoteDataSource.kt b/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaRemoteDataSource.kt index 4727e77a..28861fb9 100644 --- a/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaRemoteDataSource.kt +++ b/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaRemoteDataSource.kt @@ -2,6 +2,7 @@ package com.project.meongcare.excreta.model.data.remote import android.util.Log import com.project.meongcare.excreta.model.entities.ExcretaDetailGetResponse +import com.project.meongcare.excreta.model.entities.ExcretaPostRequest import com.project.meongcare.excreta.model.entities.ExcretaRecordGetRequest import com.project.meongcare.excreta.model.entities.ExcretaRecordGetResponse import com.project.meongcare.excreta.model.entities.ExcretaUploadRequest @@ -16,14 +17,13 @@ class ExcretaRemoteDataSource suspend fun postExcreta( accessToken: String, - excretaPostRequest: ExcretaUploadRequest, + excretaPostRequest: ExcretaPostRequest, ): Int? { try { val postResponse = excretaApiService.postExcreta( accessToken, - excretaPostRequest.dto, - excretaPostRequest.file, + excretaPostRequest, ) if (postResponse.code() != SUCCESS) { diff --git a/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaService.kt b/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaService.kt index dc243e34..e7877a62 100644 --- a/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaService.kt +++ b/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaService.kt @@ -1,10 +1,12 @@ package com.project.meongcare.excreta.model.data.remote import com.project.meongcare.excreta.model.entities.ExcretaDetailGetResponse +import com.project.meongcare.excreta.model.entities.ExcretaPostRequest import com.project.meongcare.excreta.model.entities.ExcretaRecordGetResponse import okhttp3.MultipartBody import okhttp3.RequestBody import retrofit2.Response +import retrofit2.http.Body import retrofit2.http.DELETE import retrofit2.http.GET import retrofit2.http.Header @@ -16,12 +18,10 @@ import retrofit2.http.Path import retrofit2.http.Query interface ExcretaService { - @Multipart @POST("excreta") suspend fun postExcreta( @Header("AccessToken") accessToken: String, - @Part("dto") dto: RequestBody, - @Part file: MultipartBody.Part, + @Body excretaPostRequest: ExcretaPostRequest, ): Response @GET("excreta/{dogId}") diff --git a/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepository.kt b/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepository.kt index 15a17b1e..92813f8a 100644 --- a/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepository.kt +++ b/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepository.kt @@ -1,6 +1,7 @@ package com.project.meongcare.excreta.model.data.repository import com.project.meongcare.excreta.model.entities.ExcretaDetailGetResponse +import com.project.meongcare.excreta.model.entities.ExcretaPostRequest import com.project.meongcare.excreta.model.entities.ExcretaRecordGetRequest import com.project.meongcare.excreta.model.entities.ExcretaRecordGetResponse import com.project.meongcare.excreta.model.entities.ExcretaUploadRequest @@ -8,7 +9,7 @@ import com.project.meongcare.excreta.model.entities.ExcretaUploadRequest interface ExcretaRepository { suspend fun postExcreta( accessToken: String, - excretaUploadRequest: ExcretaUploadRequest, + excretaPostRequest: ExcretaPostRequest, ): Int? suspend fun getExcretaRecord( diff --git a/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepositoryImpl.kt b/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepositoryImpl.kt index c1dca8ee..2a4768f8 100644 --- a/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepositoryImpl.kt +++ b/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepositoryImpl.kt @@ -1,6 +1,7 @@ package com.project.meongcare.excreta.model.data.repository import com.project.meongcare.excreta.model.data.remote.ExcretaRemoteDataSource +import com.project.meongcare.excreta.model.entities.ExcretaPostRequest import com.project.meongcare.excreta.model.entities.ExcretaRecordGetRequest import com.project.meongcare.excreta.model.entities.ExcretaUploadRequest import javax.inject.Inject @@ -12,8 +13,8 @@ class ExcretaRepositoryImpl ) : ExcretaRepository { override suspend fun postExcreta( accessToken: String, - excretaUploadRequest: ExcretaUploadRequest, - ) = excretaRemoteDataSource.postExcreta(accessToken, excretaUploadRequest) + excretaPostRequest: ExcretaPostRequest + ): Int? = excretaRemoteDataSource.postExcreta(accessToken, excretaPostRequest) override suspend fun getExcretaRecord( accessToken: String, diff --git a/app/src/main/java/com/project/meongcare/excreta/viewmodel/ExcretaAddViewModel.kt b/app/src/main/java/com/project/meongcare/excreta/viewmodel/ExcretaAddViewModel.kt index eb1188df..afb7667e 100644 --- a/app/src/main/java/com/project/meongcare/excreta/viewmodel/ExcretaAddViewModel.kt +++ b/app/src/main/java/com/project/meongcare/excreta/viewmodel/ExcretaAddViewModel.kt @@ -1,15 +1,11 @@ package com.project.meongcare.excreta.viewmodel -import android.content.Context import android.net.Uri import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.project.meongcare.excreta.model.data.repository.ExcretaRepositoryImpl -import com.project.meongcare.excreta.model.entities.ExcretaInfo -import com.project.meongcare.excreta.model.entities.ExcretaUploadRequest -import com.project.meongcare.excreta.utils.ExcretaInfoUtils.convertExcretaFile -import com.project.meongcare.excreta.utils.ExcretaInfoUtils.convertExcretaPostDto +import com.project.meongcare.excreta.model.entities.ExcretaPostRequest import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import javax.inject.Inject @@ -41,27 +37,19 @@ class ExcretaAddViewModel } fun postExcreta( - dogId: Long, accessToken: String, + dogId: Long, excretaType: String, dateTime: String, - context: Context, - uri: Uri, + imageURL: String?, ) { viewModelScope.launch { - val excretaInfo = - ExcretaInfo( + val excretaPostRequest = + ExcretaPostRequest( dogId, excretaType, dateTime, - ) - val dto = convertExcretaPostDto(excretaInfo) - val file = convertExcretaFile(context, uri) - - val excretaPostRequest = - ExcretaUploadRequest( - dto, - file, + imageURL, ) _excretaPosted.value = excretaRepositoryImpl.postExcreta(accessToken, excretaPostRequest) From 85bc87b6e7a020cccf06ce836f47ad88215462af Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 16:43:31 +0900 Subject: [PATCH 063/119] =?UTF-8?q?fix:=20ExcretaAddFragment=EC=9D=98=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excreta/view/ExcretaAddFragment.kt | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt index 210ecf3f..b9453713 100644 --- a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt +++ b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt @@ -9,12 +9,12 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import com.bumptech.glide.Glide +import com.project.meongcare.BuildConfig import com.project.meongcare.CalendarBottomSheetFragment import com.project.meongcare.R +import com.project.meongcare.aws.util.AWSS3ImageUtils.convertUriToFile import com.project.meongcare.aws.util.EXCRETA_FOLDER_PATH import com.project.meongcare.aws.util.PARENT_FOLDER_PATH -import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri -import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentExcretaAddEditBinding import com.project.meongcare.excreta.model.data.local.PhotoListener @@ -33,7 +33,10 @@ import com.project.meongcare.feed.viewmodel.DogViewModel import com.project.meongcare.feed.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.DateSubmitListener import dagger.hilt.android.AndroidEntryPoint -import okhttp3.MultipartBody +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.asRequestBody +import java.io.File @AndroidEntryPoint class ExcretaAddFragment : Fragment(), DateSubmitListener, PhotoListener { @@ -50,8 +53,8 @@ class ExcretaAddFragment : Fragment(), DateSubmitListener, PhotoListener { private var accessToken = "" private var dogId = 0L - private lateinit var multipartImage: MultipartBody.Part - private lateinit var fileName: String + private lateinit var imageFile: File + private lateinit var filePath: String override fun onCreateView( inflater: LayoutInflater, @@ -164,33 +167,40 @@ class ExcretaAddFragment : Fragment(), DateSubmitListener, PhotoListener { } if (isValid) { - getPreSignedUrl() + val uri = excretaAddViewModel.excretaImage.value + if (uri == null) { + postExcreta(null) + } else { + imageFile = convertUriToFile(requireContext(), uri) + filePath = "$PARENT_FOLDER_PATH$EXCRETA_FOLDER_PATH${imageFile.name}" + getPreSignedUrl() + } } } } } private fun getPreSignedUrl() { - multipartImage = createMultipartFromUri(requireContext(), excretaAddViewModel.excretaImage.value) - fileName = "$PARENT_FOLDER_PATH$EXCRETA_FOLDER_PATH${getMultipartFileName(multipartImage)}" - awsS3ViewModel.getPreSignedUrl(accessToken, fileName) + awsS3ViewModel.getPreSignedUrl(accessToken, filePath) awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> if (response != null) { - uploadImage(response.preSignedUrl, multipartImage) + val requestBody = imageFile.asRequestBody("image/*".toMediaTypeOrNull()) + uploadImage(response.preSignedUrl, requestBody) } } } - private fun uploadImage(preSignedUrl: String, image: MultipartBody.Part) { - awsS3ViewModel.uploadImageToS3(preSignedUrl, image) + private fun uploadImage(preSignedUrl: String, requestBody: RequestBody) { + awsS3ViewModel.uploadImageToS3(preSignedUrl, requestBody) awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { -// postExcreta() + val imageURL = BuildConfig.AWS_S3_BASE_URL + filePath + postExcreta(imageURL) } } } - private fun postExcreta() { + private fun postExcreta(imageURL: String?) { val excretaType = if (binding.checkboxExcretaaddUrine.isChecked) { Excreta.URINE.toString() @@ -201,15 +211,12 @@ class ExcretaAddFragment : Fragment(), DateSubmitListener, PhotoListener { val excretaTime = convertTimeFormat(binding.timepikerExcretaaddTime) val excretaDateTime = "${excretaDate}T$excretaTime" - val currentImageUri = excretaAddViewModel.excretaImage.value - excretaAddViewModel.postExcreta( - dogId, accessToken, + dogId, excretaType, excretaDateTime, - requireContext(), - currentImageUri ?: Uri.EMPTY, + imageURL, ) excretaAddViewModel.excretaPosted.observe(viewLifecycleOwner) { response -> if (response == SUCCESS) { From 90de1153388a111294bf31e814526854ee30a662 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 16:45:05 +0900 Subject: [PATCH 064/119] =?UTF-8?q?remove:=20ExcretaInfoUtils=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20import=20?= =?UTF-8?q?=EB=B0=8F=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/meongcare/excreta/utils/ExcretaInfoUtils.kt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/excreta/utils/ExcretaInfoUtils.kt b/app/src/main/java/com/project/meongcare/excreta/utils/ExcretaInfoUtils.kt index 5bc28bfd..fa9e4583 100644 --- a/app/src/main/java/com/project/meongcare/excreta/utils/ExcretaInfoUtils.kt +++ b/app/src/main/java/com/project/meongcare/excreta/utils/ExcretaInfoUtils.kt @@ -5,7 +5,6 @@ import android.net.Uri import android.view.View import com.google.gson.Gson import com.project.meongcare.R -import com.project.meongcare.excreta.model.entities.ExcretaInfo import com.project.meongcare.excreta.model.entities.ExcretaInfoPatch import com.project.meongcare.snackbar.view.CustomSnackBar import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -16,11 +15,6 @@ import okhttp3.RequestBody.Companion.toRequestBody import java.io.File object ExcretaInfoUtils { - fun convertExcretaPostDto(excretaInfo: ExcretaInfo): RequestBody { - val json = Gson().toJson(excretaInfo) - return json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) - } - fun convertExcretaPatchDto(excretaInfoPatch: ExcretaInfoPatch): RequestBody { val json = Gson().toJson(excretaInfoPatch) return json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) From a7af7c2d1f0457852d71fd055a3edc4dbfbf4aa4 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 17:11:58 +0900 Subject: [PATCH 065/119] =?UTF-8?q?fix:=20FeedInfo=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 클래스명 FeedInfo -> FeedPostRequest로 변경 - imageURL 프로퍼티 추가 --- .../feed/model/entities/{FeedInfo.kt => FeedPostRequest.kt} | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename app/src/main/java/com/project/meongcare/feed/model/entities/{FeedInfo.kt => FeedPostRequest.kt} (86%) diff --git a/app/src/main/java/com/project/meongcare/feed/model/entities/FeedInfo.kt b/app/src/main/java/com/project/meongcare/feed/model/entities/FeedPostRequest.kt similarity index 86% rename from app/src/main/java/com/project/meongcare/feed/model/entities/FeedInfo.kt rename to app/src/main/java/com/project/meongcare/feed/model/entities/FeedPostRequest.kt index 4151cc5c..5d82ff88 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/entities/FeedInfo.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/entities/FeedPostRequest.kt @@ -1,6 +1,6 @@ package com.project.meongcare.feed.model.entities -data class FeedInfo( +data class FeedPostRequest( val dogId: Long, val brand: String, val feedName: String, @@ -13,4 +13,5 @@ data class FeedInfo( val recommendIntake: Int, val startDate: String, val endDate: String? = null, + val imageURL: String?, ) From 774414f2adb75b8291f874e077d994f9e90eb331 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 17:13:01 +0900 Subject: [PATCH 066/119] =?UTF-8?q?fix:=20=EB=B0=B1=EC=97=94=EB=93=9C=20Fe?= =?UTF-8?q?ed=20Post=20API=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20Feed=20Post=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feed/model/data/remote/FeedRemoteDataSource.kt | 6 +++--- .../project/meongcare/feed/model/data/remote/FeedService.kt | 5 ++--- .../meongcare/feed/model/data/repository/FeedRepository.kt | 3 ++- .../feed/model/data/repository/FeedRepositoryImpl.kt | 5 +++-- .../project/meongcare/feed/viewmodel/FeedPostViewModel.kt | 5 +++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedRemoteDataSource.kt b/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedRemoteDataSource.kt index f8e7891d..af2a9b5a 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedRemoteDataSource.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedRemoteDataSource.kt @@ -6,6 +6,7 @@ import com.project.meongcare.feed.model.entities.FeedDetailGetResponse import com.project.meongcare.feed.model.entities.FeedGetResponse import com.project.meongcare.feed.model.entities.FeedPartRecords import com.project.meongcare.feed.model.entities.FeedPatchRequest +import com.project.meongcare.feed.model.entities.FeedPostRequest import com.project.meongcare.feed.model.entities.FeedRecords import com.project.meongcare.feed.model.entities.FeedUploadRequest import com.project.meongcare.feed.model.entities.Feeds @@ -19,14 +20,13 @@ class FeedRemoteDataSource suspend fun postFeed( accessToken: String, - feedUploadRequest: FeedUploadRequest, + feedPostRequest: FeedPostRequest, ): Int? { try { val postFeedResponse = feedApiService.postFeed( accessToken, - feedUploadRequest.dto, - feedUploadRequest.file, + feedPostRequest, ) if (postFeedResponse.code() != SUCCESS) { diff --git a/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedService.kt b/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedService.kt index a75b56d8..cdaf1b7c 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedService.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedService.kt @@ -4,6 +4,7 @@ import com.project.meongcare.feed.model.entities.FeedDetailGetResponse import com.project.meongcare.feed.model.entities.FeedGetResponse import com.project.meongcare.feed.model.entities.FeedPartRecords import com.project.meongcare.feed.model.entities.FeedPatchRequest +import com.project.meongcare.feed.model.entities.FeedPostRequest import com.project.meongcare.feed.model.entities.FeedRecords import com.project.meongcare.feed.model.entities.Feeds import okhttp3.MultipartBody @@ -22,12 +23,10 @@ import retrofit2.http.Path import retrofit2.http.Query interface FeedService { - @Multipart @POST("feed") suspend fun postFeed( @Header("AccessToken") accessToken: String, - @Part("dto") dto: RequestBody, - @Part file: MultipartBody.Part, + @Body feedPostRequest: FeedPostRequest, ): Response @GET("feed/{dogId}") diff --git a/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepository.kt b/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepository.kt index 260e82af..01c91b82 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepository.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepository.kt @@ -4,6 +4,7 @@ import com.project.meongcare.feed.model.entities.FeedDetailGetResponse import com.project.meongcare.feed.model.entities.FeedGetResponse import com.project.meongcare.feed.model.entities.FeedPartRecords import com.project.meongcare.feed.model.entities.FeedPatchRequest +import com.project.meongcare.feed.model.entities.FeedPostRequest import com.project.meongcare.feed.model.entities.FeedRecords import com.project.meongcare.feed.model.entities.FeedUploadRequest import com.project.meongcare.feed.model.entities.Feeds @@ -16,7 +17,7 @@ interface FeedRepository { suspend fun postFeed( accessToken: String, - feedUploadRequest: FeedUploadRequest, + feedPostRequest: FeedPostRequest, ): Int? suspend fun getFeedPart( diff --git a/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepositoryImpl.kt b/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepositoryImpl.kt index 15dfdbba..d184b93f 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepositoryImpl.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepositoryImpl.kt @@ -2,6 +2,7 @@ package com.project.meongcare.feed.model.data.repository import com.project.meongcare.feed.model.data.remote.FeedRemoteDataSource import com.project.meongcare.feed.model.entities.FeedPatchRequest +import com.project.meongcare.feed.model.entities.FeedPostRequest import com.project.meongcare.feed.model.entities.FeedUploadRequest import javax.inject.Inject @@ -17,8 +18,8 @@ class FeedRepositoryImpl override suspend fun postFeed( accessToken: String, - feedUploadRequest: FeedUploadRequest, - ) = feedRemoteDataSource.postFeed(accessToken, feedUploadRequest) + feedPostRequest: FeedPostRequest, + ) = feedRemoteDataSource.postFeed(accessToken, feedPostRequest) override suspend fun getFeedPart( accessToken: String, diff --git a/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPostViewModel.kt b/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPostViewModel.kt index 4729f121..030df9f9 100644 --- a/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPostViewModel.kt +++ b/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPostViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.project.meongcare.feed.model.data.repository.FeedRepositoryImpl +import com.project.meongcare.feed.model.entities.FeedPostRequest import com.project.meongcare.feed.model.entities.FeedUploadRequest import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch @@ -30,11 +31,11 @@ class FeedPostViewModel fun postFeed( accessToken: String, - feedUploadRequest: FeedUploadRequest, + feedPostRequest: FeedPostRequest, ) { viewModelScope.launch { _feedPosted.value = - feedRepositoryImpl.postFeed(accessToken, feedUploadRequest) + feedRepositoryImpl.postFeed(accessToken, feedPostRequest) } } } From e2500397cd7ce80c8ee5d317422000a2e6cfa58e Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 17:14:29 +0900 Subject: [PATCH 067/119] =?UTF-8?q?fix:=20FeedAddFragment=EC=9D=98=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/feed/view/FeedAddFragment.kt | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt b/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt index 0a06fb2f..93b66cd2 100644 --- a/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt +++ b/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt @@ -18,16 +18,16 @@ import androidx.navigation.fragment.findNavController import com.archit.calendardaterangepicker.customviews.CalendarListener import com.archit.calendardaterangepicker.customviews.DateRangeCalendarView import com.bumptech.glide.Glide +import com.project.meongcare.BuildConfig import com.project.meongcare.R +import com.project.meongcare.aws.util.AWSS3ImageUtils.convertUriToFile import com.project.meongcare.aws.util.FEED_FOLDER_PATH import com.project.meongcare.aws.util.PARENT_FOLDER_PATH -import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri -import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentFeedAddEditBinding import com.project.meongcare.excreta.utils.SUCCESS import com.project.meongcare.feed.model.data.local.FeedPhotoListener -import com.project.meongcare.feed.model.entities.FeedInfo +import com.project.meongcare.feed.model.entities.FeedPostRequest import com.project.meongcare.feed.model.entities.FeedUploadRequest import com.project.meongcare.feed.model.utils.END_DATE import com.project.meongcare.feed.model.utils.FEED_POST_FAILURE @@ -50,7 +50,10 @@ import com.project.meongcare.feed.viewmodel.DogViewModel import com.project.meongcare.feed.viewmodel.FeedPostViewModel import com.project.meongcare.feed.viewmodel.UserViewModel import dagger.hilt.android.AndroidEntryPoint +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MultipartBody +import okhttp3.RequestBody.Companion.asRequestBody +import java.io.File import java.text.SimpleDateFormat import java.util.Calendar import java.util.Locale @@ -62,8 +65,8 @@ class FeedAddFragment : Fragment(), FeedPhotoListener { val binding get() = _binding!! private lateinit var inputMethodManager: InputMethodManager - private lateinit var multipartImage: MultipartBody.Part - private lateinit var fileName: String + private lateinit var imageFile: File + private lateinit var filePath: String private val feedPostViewModel: FeedPostViewModel by viewModels() private val dogViewModel: DogViewModel by viewModels() @@ -73,7 +76,6 @@ class FeedAddFragment : Fragment(), FeedPhotoListener { private var recommendIntake = 0.0 var selectedStartDate = "" private var selectedEndDate: String? = null - private lateinit var feedInfo: FeedInfo private var imageUri: Uri? = null private var proteinValue = 0.0 @@ -115,8 +117,8 @@ class FeedAddFragment : Fragment(), FeedPhotoListener { } awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { - // 이미지 업로드 성공 시 데이터 전송 처리 - // postFeedInfo() -> 함수 내 이미지 전송 로직 제거 필요 + val imageURL = BuildConfig.AWS_S3_BASE_URL + filePath + postFeedInfo(imageURL) } } initInputMethodManager() @@ -321,12 +323,12 @@ class FeedAddFragment : Fragment(), FeedPhotoListener { } } - private fun createFeedInfo() { + private fun createFeedInfo(imageURL: String?): FeedPostRequest { binding.apply { val brand = edittextFeedaddeditBrand.text.toString() val feedName = edittextFeedaddeditName.text.toString() - feedInfo = - FeedInfo( + val feedPostRequest = + FeedPostRequest( dogId, brand, feedName, @@ -339,8 +341,9 @@ class FeedAddFragment : Fragment(), FeedPhotoListener { recommendIntake.toInt(), selectedStartDate, selectedEndDate, + imageURL, ) - imageUri = feedPostViewModel.feedImage.value + return feedPostRequest } } @@ -473,24 +476,21 @@ class FeedAddFragment : Fragment(), FeedPhotoListener { } if (isValid) { - getPreSignedUrl() + val uri = feedPostViewModel.feedImage.value + if (uri == null) { + + } else { + getPreSignedUrl(uri) + } } } } } - private fun postFeedInfo() { - val dto = convertFeedPostDto(feedInfo) - val file = - convertFeedFile( - requireContext(), - imageUri ?: Uri.EMPTY, - ) - val uploadRequest = FeedUploadRequest(dto, file) - + private fun postFeedInfo(imageURL: String?) { feedPostViewModel.postFeed( accessToken, - uploadRequest, + createFeedInfo(imageURL), ) feedPostViewModel.feedPosted.observe(viewLifecycleOwner) { response -> if (response == SUCCESS) { @@ -508,14 +508,14 @@ class FeedAddFragment : Fragment(), FeedPhotoListener { } } - private fun getPreSignedUrl() { - createFeedInfo() - multipartImage = createMultipartFromUri(requireContext(), imageUri) - fileName = "$PARENT_FOLDER_PATH$FEED_FOLDER_PATH${getMultipartFileName(multipartImage)}" - awsS3ViewModel.getPreSignedUrl(accessToken, fileName) + private fun getPreSignedUrl(uri: Uri) { + imageFile = convertUriToFile(requireContext(), uri) + filePath = "$PARENT_FOLDER_PATH$FEED_FOLDER_PATH${imageFile.name}" + awsS3ViewModel.getPreSignedUrl(accessToken, filePath) awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> if (response != null) { - awsS3ViewModel.uploadImageToS3(response.preSignedUrl, multipartImage) + val requestBody = imageFile.asRequestBody("image/*".toMediaTypeOrNull()) + awsS3ViewModel.uploadImageToS3(response.preSignedUrl, requestBody) } } } From 5d8e70e72e38c21f05b2be44d5ecaf961bdf97c0 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 17:16:50 +0900 Subject: [PATCH 068/119] =?UTF-8?q?remove:=20FeedInfoUtils=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20import=20?= =?UTF-8?q?=EB=B0=8F=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/meongcare/feed/model/utils/FeedInfoUtils.kt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/feed/model/utils/FeedInfoUtils.kt b/app/src/main/java/com/project/meongcare/feed/model/utils/FeedInfoUtils.kt index 7a03300c..e7150765 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/utils/FeedInfoUtils.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/utils/FeedInfoUtils.kt @@ -7,7 +7,6 @@ import android.view.View import android.widget.TextView import com.google.gson.Gson import com.project.meongcare.R -import com.project.meongcare.feed.model.entities.FeedInfo import com.project.meongcare.feed.model.entities.FeedPutInfo import com.project.meongcare.snackbar.view.CustomSnackBar import kotlinx.coroutines.Dispatchers @@ -22,11 +21,6 @@ import java.io.File import java.net.URL object FeedInfoUtils { - fun convertFeedPostDto(feedInfo: FeedInfo): RequestBody { - val json = Gson().toJson(feedInfo) - return json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) - } - fun convertFeedPutDto(feedPutInfo: FeedPutInfo): RequestBody { val json = Gson().toJson(feedPutInfo) return json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) From 499dd4c31889ce3ad485d229e8bdb2baaeee656d Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 21:30:34 +0900 Subject: [PATCH 069/119] =?UTF-8?q?fix:=20SupplementDto=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 클래스명 SupplementDto -> SupplementPostRequest로 변경 - imageURL 프로퍼티 추가 --- .../meongcare/supplement/model/entities/SupplementData.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/supplement/model/entities/SupplementData.kt b/app/src/main/java/com/project/meongcare/supplement/model/entities/SupplementData.kt index 56114b47..d393c88a 100644 --- a/app/src/main/java/com/project/meongcare/supplement/model/entities/SupplementData.kt +++ b/app/src/main/java/com/project/meongcare/supplement/model/entities/SupplementData.kt @@ -37,12 +37,13 @@ data class DetailSupplement( val intakeInfos: List, ) -data class SupplementDto( +data class SupplementPostRequest( val dogId: Long, val brand: String, val name: String, val intakeCycle: Int, val intakeUnit: String, + val imageURL: String?, val intakeInfos: List, ) From abf7e22dea9ec582962dd0b48935c2e96680d116 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 21:31:58 +0900 Subject: [PATCH 070/119] =?UTF-8?q?fix:=20=EB=B0=B1=EC=97=94=EB=93=9C=20Su?= =?UTF-8?q?pplement=20Post=20API=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20Supplement=20Post=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/data/remote/SupplementAPI.kt | 10 ++---- .../data/repository/SupplementRepository.kt | 7 ++-- .../viewmodel/SupplementViewModel.kt | 32 +++---------------- 3 files changed, 10 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/supplement/model/data/remote/SupplementAPI.kt b/app/src/main/java/com/project/meongcare/supplement/model/data/remote/SupplementAPI.kt index 16115b72..d22cb927 100644 --- a/app/src/main/java/com/project/meongcare/supplement/model/data/remote/SupplementAPI.kt +++ b/app/src/main/java/com/project/meongcare/supplement/model/data/remote/SupplementAPI.kt @@ -3,17 +3,15 @@ package com.project.meongcare.supplement.model.data.remote import com.project.meongcare.supplement.model.entities.DetailSupplement import com.project.meongcare.supplement.model.entities.DogSupplement import com.project.meongcare.supplement.model.entities.ResultSupplement -import okhttp3.MultipartBody -import okhttp3.RequestBody +import com.project.meongcare.supplement.model.entities.SupplementPostRequest import okhttp3.ResponseBody import retrofit2.Response +import retrofit2.http.Body import retrofit2.http.DELETE import retrofit2.http.GET import retrofit2.http.Header -import retrofit2.http.Multipart import retrofit2.http.PATCH import retrofit2.http.POST -import retrofit2.http.Part import retrofit2.http.Path import retrofit2.http.Query @@ -37,12 +35,10 @@ interface SupplementAPI { @Path("dogId") dogId: Long?, ): Response - @Multipart @POST("supplements") suspend fun addSupplement( @Header("AccessToken") accessToken: String?, - @Part filePart: MultipartBody.Part, - @Part("dto") supplementDto: RequestBody, + @Body supplementPostRequest: SupplementPostRequest, ): Response @PATCH("supplements/check") diff --git a/app/src/main/java/com/project/meongcare/supplement/model/data/repository/SupplementRepository.kt b/app/src/main/java/com/project/meongcare/supplement/model/data/repository/SupplementRepository.kt index 68933a7b..7f3b0b55 100644 --- a/app/src/main/java/com/project/meongcare/supplement/model/data/repository/SupplementRepository.kt +++ b/app/src/main/java/com/project/meongcare/supplement/model/data/repository/SupplementRepository.kt @@ -4,8 +4,8 @@ import com.project.meongcare.supplement.model.data.remote.SupplementAPI import com.project.meongcare.supplement.model.data.remote.SupplementRetrofitInstance import com.project.meongcare.supplement.model.entities.DetailSupplement import com.project.meongcare.supplement.model.entities.DogSupplement -import com.project.meongcare.supplement.model.entities.RequestSupplement import com.project.meongcare.supplement.model.entities.ResultSupplement +import com.project.meongcare.supplement.model.entities.SupplementPostRequest import okhttp3.ResponseBody import javax.inject.Inject @@ -162,13 +162,12 @@ class SupplementRepository suspend fun addSupplement( accessToken: String?, - requestSupplement: RequestSupplement, + supplementsPostRequest: SupplementPostRequest, ): Int { val response = supplementAPI.addSupplement( accessToken, - requestSupplement.file, - requestSupplement.dto, + supplementsPostRequest, ) return response.code() } diff --git a/app/src/main/java/com/project/meongcare/supplement/viewmodel/SupplementViewModel.kt b/app/src/main/java/com/project/meongcare/supplement/viewmodel/SupplementViewModel.kt index c48694ff..87517f6b 100644 --- a/app/src/main/java/com/project/meongcare/supplement/viewmodel/SupplementViewModel.kt +++ b/app/src/main/java/com/project/meongcare/supplement/viewmodel/SupplementViewModel.kt @@ -1,30 +1,22 @@ package com.project.meongcare.supplement.viewmodel -import android.app.Activity -import android.content.Context import android.net.Uri import android.util.Log import android.widget.ImageView import android.widget.ProgressBar import android.widget.TextView -import androidx.core.content.ContextCompat import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import androidx.navigation.NavController -import com.project.meongcare.R import com.project.meongcare.home.model.data.local.DogPreferences import com.project.meongcare.login.model.data.local.UserPreferences import com.project.meongcare.login.view.GlobalApplication import com.project.meongcare.supplement.model.data.repository.SupplementRepository import com.project.meongcare.supplement.model.entities.DetailSupplement import com.project.meongcare.supplement.model.entities.IntakeInfo -import com.project.meongcare.supplement.model.entities.RequestSupplement import com.project.meongcare.supplement.model.entities.Supplement import com.project.meongcare.supplement.model.entities.SupplementDog -import com.project.meongcare.supplement.model.entities.SupplementDto -import com.project.meongcare.supplement.utils.SupplementUtils.Companion.convertPictureToFile -import com.project.meongcare.supplement.utils.SupplementUtils.Companion.convertSupplementDto +import com.project.meongcare.supplement.model.entities.SupplementPostRequest import com.project.meongcare.supplement.utils.SupplementUtils.Companion.convertToDateToDate import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers.Main @@ -146,27 +138,11 @@ class SupplementViewModel } fun addSupplement( - brandName: String, - name: String, - uri: Uri, + accessToken: String, + supplementPostRequest: SupplementPostRequest, ) { viewModelScope.launch { - val accessToken: String? = - UserPreferences(GlobalApplication.applicationContext()).accessToken.first() - val dogId: Long? = DogPreferences(GlobalApplication.applicationContext()).dogId.first() - - val supplementDto = - SupplementDto(dogId!!, brandName, name, supplementCycle.value!!, intakeTimeUnit.value!!, intakeTimeList.value!!) - val dto = convertSupplementDto(supplementDto) - val file = convertPictureToFile(GlobalApplication.applicationContext(), uri) - - val requestSupplement = - RequestSupplement( - dto, - file, - ) - Log.d("영양제 추가 확인", supplementDto.toString()) - supplementCode.value = repository.addSupplement(accessToken, requestSupplement) + supplementCode.value = repository.addSupplement(accessToken, supplementPostRequest) Log.d("영양제 추가 확인2", supplementCode.value.toString()) } } From 738624f55725c750bab44433fb0277eb5ebe1028 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 21:34:23 +0900 Subject: [PATCH 071/119] =?UTF-8?q?fix:=20SupplementAddFragment=EC=9D=98?= =?UTF-8?q?=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supplement/view/SupplementAddFragment.kt | 73 +++++++++++++------ 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt b/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt index 2e859585..f038853f 100644 --- a/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt +++ b/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt @@ -20,20 +20,21 @@ import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide +import com.project.meongcare.BuildConfig import com.project.meongcare.MainActivity import com.project.meongcare.R -import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri -import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName +import com.project.meongcare.aws.util.AWSS3ImageUtils.convertUriToFile import com.project.meongcare.aws.util.PARENT_FOLDER_PATH import com.project.meongcare.aws.util.SUPPLEMENTS_FOLDER_PATH import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentSupplementAddBinding import com.project.meongcare.databinding.ItemSupplementAddTimeBinding +import com.project.meongcare.medicalrecord.viewmodel.DogViewModel import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.snackbar.view.CustomSnackBar import com.project.meongcare.supplement.model.data.local.OnPictureChangedListener import com.project.meongcare.supplement.model.data.repository.SupplementRepository -import com.project.meongcare.supplement.model.entities.SupplementDto +import com.project.meongcare.supplement.model.entities.SupplementPostRequest import com.project.meongcare.supplement.utils.SupplementUtils.Companion.convertDateToTime import com.project.meongcare.supplement.utils.SupplementUtils.Companion.hideKeyboard import com.project.meongcare.supplement.utils.SupplementUtils.Companion.showCycleBottomSheet @@ -42,7 +43,10 @@ import com.project.meongcare.supplement.view.bottomSheet.SupplementPictureBottom import com.project.meongcare.supplement.viewmodel.SupplementViewModel import com.project.meongcare.supplement.viewmodel.SupplementViewModelFactory import dagger.hilt.android.AndroidEntryPoint -import okhttp3.MultipartBody +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.asRequestBody +import java.io.File @AndroidEntryPoint class SupplementAddFragment : Fragment(), OnPictureChangedListener { @@ -53,11 +57,13 @@ class SupplementAddFragment : Fragment(), OnPictureChangedListener { private val awsS3ViewModel: AWSS3ViewModel by viewModels() private val userViewModel: UserViewModel by viewModels() + private val dogViewModel: DogViewModel by viewModels() - private lateinit var multipartImage: MultipartBody.Part - private lateinit var fileName: String + private lateinit var imageFile: File + private lateinit var filePath: String private var accessToken = "" + private var dogId = 0L override fun onCreateView( inflater: LayoutInflater, @@ -203,7 +209,12 @@ class SupplementAddFragment : Fragment(), OnPictureChangedListener { buttonSupplementAddComplete.setOnClickListener { checkInput() if (checkInput()) { - getPreSignedUrl() + val uri = supplementViewModel.supplementAddImg.value + if (uri == null) { + postSupplement(null) + } else { + getPreSignedUrl(uri) + } } } } @@ -356,43 +367,57 @@ class SupplementAddFragment : Fragment(), OnPictureChangedListener { userViewModel.accessTokenPreferencesLiveData.observe(viewLifecycleOwner) { accessToken -> if (accessToken != null) { this.accessToken = accessToken + getDogId() } } } - private fun getPreSignedUrl() { - multipartImage = createMultipartFromUri(requireContext(), supplementViewModel.supplementAddImg.value) - fileName = "$PARENT_FOLDER_PATH$SUPPLEMENTS_FOLDER_PATH${getMultipartFileName(multipartImage)}" - awsS3ViewModel.getPreSignedUrl(accessToken, fileName) + private fun getDogId() { + dogViewModel.dogIdPreferencesLiveData.observe(viewLifecycleOwner) { dogId -> + if (dogId != null) { + this.dogId = dogId + } + } + } + + private fun getPreSignedUrl(uri: Uri) { + imageFile = convertUriToFile(requireContext(), uri) + filePath = "$PARENT_FOLDER_PATH$SUPPLEMENTS_FOLDER_PATH${imageFile.name}" + awsS3ViewModel.getPreSignedUrl(accessToken, filePath) awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> if (response != null) { - uploadImage(response.preSignedUrl) - Log.d("uploadedImage", response.preSignedUrl) + val requestBody = imageFile.asRequestBody("image/*".toMediaTypeOrNull()) + uploadImage(response.preSignedUrl, requestBody) } } } - private fun uploadImage(preSignedUrl: String) { - awsS3ViewModel.uploadImageToS3(preSignedUrl, multipartImage) + private fun uploadImage(preSignedUrl: String, requestBody: RequestBody) { + awsS3ViewModel.uploadImageToS3(preSignedUrl, requestBody) awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { -// postSupplement() + val imageURL = BuildConfig.AWS_S3_BASE_URL + filePath + postSupplement(imageURL) } } } - private fun postSupplement() { - val brandName = fragmentSupplementAddBinding.editTextSupplementAddBrandName.text.toString() - val name = fragmentSupplementAddBinding.editTextSupplementAddName.text.toString() - val imgUri = supplementViewModel.supplementAddImg.value - + private fun postSupplement(imageURL: String?) { supplementViewModel.addSupplement( - brandName, - name, - imgUri ?: Uri.EMPTY, + accessToken, + createSupplementInfo(imageURL) ) } + private fun createSupplementInfo(imageURL: String?): SupplementPostRequest { + val brandName = fragmentSupplementAddBinding.editTextSupplementAddBrandName.text.toString() + val name = fragmentSupplementAddBinding.editTextSupplementAddName.text.toString() + val intakeCycle = supplementViewModel.supplementCycle.value!! + val intakeUnit = supplementViewModel.intakeTimeUnit.value!! + val intakeInfos = supplementViewModel.intakeTimeList.value!! + return SupplementPostRequest(dogId, brandName, name, intakeCycle, intakeUnit, imageURL, intakeInfos) + } + private fun showPictureBottomSheet() { val bottomSheetFragment = SupplementPictureBottomSheetDialogFragment() From 18bf49ac318b02a6aa1a31703179615d71b1936a Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 21:35:16 +0900 Subject: [PATCH 072/119] =?UTF-8?q?remove:=20SupplementData=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EC=97=90=EC=84=9C=20=EB=AF=B8=EC=B0=B8?= =?UTF-8?q?=EC=A1=B0=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/supplement/model/entities/SupplementData.kt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/supplement/model/entities/SupplementData.kt b/app/src/main/java/com/project/meongcare/supplement/model/entities/SupplementData.kt index d393c88a..818fc254 100644 --- a/app/src/main/java/com/project/meongcare/supplement/model/entities/SupplementData.kt +++ b/app/src/main/java/com/project/meongcare/supplement/model/entities/SupplementData.kt @@ -1,17 +1,9 @@ package com.project.meongcare.supplement.model.entities -import okhttp3.MultipartBody -import okhttp3.RequestBody - data class ResultSupplement( val routines: List, ) -data class RequestSupplement( - val dto: RequestBody, - val file: MultipartBody.Part, -) - data class DogSupplement( val supplementsInfos: List, ) From 4a8e5916da79a893d7c43977d1aaa076e67e88e6 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 21:35:51 +0900 Subject: [PATCH 073/119] =?UTF-8?q?remove:=20SupplementUtils=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20import=20?= =?UTF-8?q?=EB=B0=8F=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supplement/utils/SupplementUtils.kt | 35 ------------------- 1 file changed, 35 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/supplement/utils/SupplementUtils.kt b/app/src/main/java/com/project/meongcare/supplement/utils/SupplementUtils.kt index 37066285..69193e1f 100644 --- a/app/src/main/java/com/project/meongcare/supplement/utils/SupplementUtils.kt +++ b/app/src/main/java/com/project/meongcare/supplement/utils/SupplementUtils.kt @@ -1,22 +1,13 @@ package com.project.meongcare.supplement.utils import android.content.Context -import android.net.Uri import android.view.View import android.view.inputmethod.InputMethodManager import androidx.fragment.app.FragmentManager -import com.google.gson.Gson import com.project.meongcare.supplement.model.entities.IntakeInfo -import com.project.meongcare.supplement.model.entities.SupplementDto import com.project.meongcare.supplement.view.bottomSheet.SupplementCycleBottomSheetDialogFragment import com.project.meongcare.supplement.view.bottomSheet.SupplementTimeBottomSheetDialogFragment import com.project.meongcare.supplement.viewmodel.SupplementViewModel -import okhttp3.MediaType.Companion.toMediaTypeOrNull -import okhttp3.MultipartBody -import okhttp3.RequestBody -import okhttp3.RequestBody.Companion.asRequestBody -import okhttp3.RequestBody.Companion.toRequestBody -import java.io.File import java.time.Instant import java.time.LocalTime import java.time.ZoneId @@ -50,32 +41,6 @@ class SupplementUtils { return localDateTime.format(formatter) } - fun convertSupplementDto(supplementDto: SupplementDto): RequestBody { - val json = Gson().toJson(supplementDto) - return json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) - } - - fun convertPictureToFile( - context: Context, - uri: Uri, - ): MultipartBody.Part { - if (uri.toString().isEmpty()) { - val emptyFile = "".toRequestBody("multipart/form-data".toMediaTypeOrNull()) - return MultipartBody.Part.createFormData("file", "", emptyFile) - } - - val inputStream = context.contentResolver.openInputStream(uri) - val file = File(context.cacheDir, "tempFile") - inputStream.use { input -> - file.outputStream().use { output -> - input?.copyTo(output) - } - } - val requestFile = file.asRequestBody("multipart/form-data".toMediaTypeOrNull()) - - return MultipartBody.Part.createFormData("file", file.name, requestFile) - } - fun showCycleBottomSheet( parentFragmentManager: FragmentManager, supplementViewModel: SupplementViewModel, From e451f2e0e3d3ab57c38996b7fb17de277043ce84 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 21:37:58 +0900 Subject: [PATCH 074/119] =?UTF-8?q?remove:=20FeedAddFragment=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20import=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/feed/view/FeedAddFragment.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt b/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt index 93b66cd2..b39de917 100644 --- a/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt +++ b/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt @@ -28,14 +28,11 @@ import com.project.meongcare.databinding.FragmentFeedAddEditBinding import com.project.meongcare.excreta.utils.SUCCESS import com.project.meongcare.feed.model.data.local.FeedPhotoListener import com.project.meongcare.feed.model.entities.FeedPostRequest -import com.project.meongcare.feed.model.entities.FeedUploadRequest import com.project.meongcare.feed.model.utils.END_DATE import com.project.meongcare.feed.model.utils.FEED_POST_FAILURE import com.project.meongcare.feed.model.utils.FEED_POST_SUCCESS import com.project.meongcare.feed.model.utils.FeedDateUtils.convertDateFormat import com.project.meongcare.feed.model.utils.FeedInfoUtils.calculateRecommendDailyIntake -import com.project.meongcare.feed.model.utils.FeedInfoUtils.convertFeedFile -import com.project.meongcare.feed.model.utils.FeedInfoUtils.convertFeedPostDto import com.project.meongcare.feed.model.utils.FeedInfoUtils.initRecommendDailyIntake import com.project.meongcare.feed.model.utils.FeedInfoUtils.showFailureSnackBar import com.project.meongcare.feed.model.utils.FeedInfoUtils.showSuccessSnackBar @@ -51,7 +48,6 @@ import com.project.meongcare.feed.viewmodel.FeedPostViewModel import com.project.meongcare.feed.viewmodel.UserViewModel import dagger.hilt.android.AndroidEntryPoint import okhttp3.MediaType.Companion.toMediaTypeOrNull -import okhttp3.MultipartBody import okhttp3.RequestBody.Companion.asRequestBody import java.io.File import java.text.SimpleDateFormat From 929297cde4b7975cf1bc254a4fa6d0685b1068f2 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 23:04:25 +0900 Subject: [PATCH 075/119] =?UTF-8?q?fix:=20ExcretaInfoPatch=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 클래스명 ExcretaInfoPatch -> ExcretaPatchRequest로 변경 - imageURL 프로퍼티 추가 --- .../entities/{ExcretaInfoPatch.kt => ExcretaPatchRequest.kt} | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename app/src/main/java/com/project/meongcare/excreta/model/entities/{ExcretaInfoPatch.kt => ExcretaPatchRequest.kt} (70%) diff --git a/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaInfoPatch.kt b/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaPatchRequest.kt similarity index 70% rename from app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaInfoPatch.kt rename to app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaPatchRequest.kt index a62a81ea..099a92bc 100644 --- a/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaInfoPatch.kt +++ b/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaPatchRequest.kt @@ -1,7 +1,8 @@ package com.project.meongcare.excreta.model.entities -data class ExcretaInfoPatch( +data class ExcretaPatchRequest( val excretaId: Long, val excretaString: String, val dateTime: String, + val imageURL: String?, ) From a70def900f3b6119ae83538b6731e8eed5807716 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 23:05:44 +0900 Subject: [PATCH 076/119] =?UTF-8?q?fix:=20Excreta=20Patch=20API=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20Excreta=20Pa?= =?UTF-8?q?tch=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/remote/ExcretaRemoteDataSource.kt | 7 +++--- .../model/data/remote/ExcretaService.kt | 9 ++------ .../data/repository/ExcretaRepository.kt | 4 ++-- .../data/repository/ExcretaRepositoryImpl.kt | 6 ++--- .../viewmodel/ExcretaPatchViewModel.kt | 23 ++++--------------- 5 files changed, 15 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaRemoteDataSource.kt b/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaRemoteDataSource.kt index 28861fb9..34bc8754 100644 --- a/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaRemoteDataSource.kt +++ b/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaRemoteDataSource.kt @@ -2,10 +2,10 @@ package com.project.meongcare.excreta.model.data.remote import android.util.Log import com.project.meongcare.excreta.model.entities.ExcretaDetailGetResponse +import com.project.meongcare.excreta.model.entities.ExcretaPatchRequest import com.project.meongcare.excreta.model.entities.ExcretaPostRequest import com.project.meongcare.excreta.model.entities.ExcretaRecordGetRequest import com.project.meongcare.excreta.model.entities.ExcretaRecordGetResponse -import com.project.meongcare.excreta.model.entities.ExcretaUploadRequest import com.project.meongcare.excreta.utils.SUCCESS import org.json.JSONObject import javax.inject.Inject @@ -120,14 +120,13 @@ class ExcretaRemoteDataSource suspend fun patchExcreta( accessToken: String, - excretaUploadRequest: ExcretaUploadRequest, + excretaPatchRequest: ExcretaPatchRequest, ): Int? { try { val patchResponse = excretaApiService.patchExcreta( accessToken, - excretaUploadRequest.dto, - excretaUploadRequest.file, + excretaPatchRequest, ) if (patchResponse.code() != SUCCESS) { diff --git a/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaService.kt b/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaService.kt index e7877a62..fd042df1 100644 --- a/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaService.kt +++ b/app/src/main/java/com/project/meongcare/excreta/model/data/remote/ExcretaService.kt @@ -1,19 +1,16 @@ package com.project.meongcare.excreta.model.data.remote import com.project.meongcare.excreta.model.entities.ExcretaDetailGetResponse +import com.project.meongcare.excreta.model.entities.ExcretaPatchRequest import com.project.meongcare.excreta.model.entities.ExcretaPostRequest import com.project.meongcare.excreta.model.entities.ExcretaRecordGetResponse -import okhttp3.MultipartBody -import okhttp3.RequestBody import retrofit2.Response import retrofit2.http.Body import retrofit2.http.DELETE import retrofit2.http.GET import retrofit2.http.Header -import retrofit2.http.Multipart import retrofit2.http.PATCH import retrofit2.http.POST -import retrofit2.http.Part import retrofit2.http.Path import retrofit2.http.Query @@ -43,11 +40,9 @@ interface ExcretaService { @Query("excretaIds") excretaIds: IntArray, ): Response - @Multipart @PATCH("excreta") suspend fun patchExcreta( @Header("AccessToken") accessToken: String, - @Part("dto") dto: RequestBody, - @Part file: MultipartBody.Part, + @Body excretaPatchRequest: ExcretaPatchRequest, ): Response } diff --git a/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepository.kt b/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepository.kt index 92813f8a..1bd46108 100644 --- a/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepository.kt +++ b/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepository.kt @@ -1,10 +1,10 @@ package com.project.meongcare.excreta.model.data.repository import com.project.meongcare.excreta.model.entities.ExcretaDetailGetResponse +import com.project.meongcare.excreta.model.entities.ExcretaPatchRequest import com.project.meongcare.excreta.model.entities.ExcretaPostRequest import com.project.meongcare.excreta.model.entities.ExcretaRecordGetRequest import com.project.meongcare.excreta.model.entities.ExcretaRecordGetResponse -import com.project.meongcare.excreta.model.entities.ExcretaUploadRequest interface ExcretaRepository { suspend fun postExcreta( @@ -29,6 +29,6 @@ interface ExcretaRepository { suspend fun patchExcreta( accessToken: String, - excretaUploadRequest: ExcretaUploadRequest, + excretaPatchRequest: ExcretaPatchRequest, ): Int? } diff --git a/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepositoryImpl.kt b/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepositoryImpl.kt index 2a4768f8..5fab8af0 100644 --- a/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepositoryImpl.kt +++ b/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepositoryImpl.kt @@ -1,9 +1,9 @@ package com.project.meongcare.excreta.model.data.repository import com.project.meongcare.excreta.model.data.remote.ExcretaRemoteDataSource +import com.project.meongcare.excreta.model.entities.ExcretaPatchRequest import com.project.meongcare.excreta.model.entities.ExcretaPostRequest import com.project.meongcare.excreta.model.entities.ExcretaRecordGetRequest -import com.project.meongcare.excreta.model.entities.ExcretaUploadRequest import javax.inject.Inject class ExcretaRepositoryImpl @@ -33,6 +33,6 @@ class ExcretaRepositoryImpl override suspend fun patchExcreta( accessToken: String, - excretaUploadRequest: ExcretaUploadRequest, - ) = excretaRemoteDataSource.patchExcreta(accessToken, excretaUploadRequest) + excretaPatchRequest: ExcretaPatchRequest + ): Int? = excretaRemoteDataSource.patchExcreta(accessToken, excretaPatchRequest) } diff --git a/app/src/main/java/com/project/meongcare/excreta/viewmodel/ExcretaPatchViewModel.kt b/app/src/main/java/com/project/meongcare/excreta/viewmodel/ExcretaPatchViewModel.kt index f8976671..b05a92d4 100644 --- a/app/src/main/java/com/project/meongcare/excreta/viewmodel/ExcretaPatchViewModel.kt +++ b/app/src/main/java/com/project/meongcare/excreta/viewmodel/ExcretaPatchViewModel.kt @@ -1,15 +1,11 @@ package com.project.meongcare.excreta.viewmodel -import android.content.Context import android.net.Uri import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.project.meongcare.excreta.model.data.repository.ExcretaRepositoryImpl -import com.project.meongcare.excreta.model.entities.ExcretaInfoPatch -import com.project.meongcare.excreta.model.entities.ExcretaUploadRequest -import com.project.meongcare.excreta.utils.ExcretaInfoUtils.convertExcretaFile -import com.project.meongcare.excreta.utils.ExcretaInfoUtils.convertExcretaPatchDto +import com.project.meongcare.excreta.model.entities.ExcretaPatchRequest import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import javax.inject.Inject @@ -45,25 +41,16 @@ class ExcretaPatchViewModel excretaId: Long, excretaType: String, excretaDateTime: String, - context: Context, - uri: Uri, + imageURL: String?, ) { viewModelScope.launch { - val excretaInfoPatch = - ExcretaInfoPatch( + val excretaPatchRequest = + ExcretaPatchRequest( excretaId, excretaType, excretaDateTime, + imageURL, ) - val dto = convertExcretaPatchDto(excretaInfoPatch) - val file = convertExcretaFile(context, uri) - - val excretaPatchRequest = - ExcretaUploadRequest( - dto, - file, - ) - _excretaPatched.value = excretaRepositoryImpl.patchExcreta(accessToken, excretaPatchRequest) } } From ce1cb1a881b11b23f78b9ad85aee94c5bf254eae Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 23:07:09 +0900 Subject: [PATCH 077/119] =?UTF-8?q?fix:=20ExcretaDetailGetResponse?= =?UTF-8?q?=EC=9D=98=20excretaImageURL=20=ED=94=84=EB=A1=9C=ED=8D=BC?= =?UTF-8?q?=ED=8B=B0=20nullable=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excreta/model/entities/ExcretaDetailGetResponse.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaDetailGetResponse.kt b/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaDetailGetResponse.kt index 8f8ccd20..179f76f6 100644 --- a/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaDetailGetResponse.kt +++ b/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaDetailGetResponse.kt @@ -5,7 +5,7 @@ import kotlinx.parcelize.Parcelize @Parcelize data class ExcretaDetailGetResponse( - val excretaImageURL: String, + val excretaImageURL: String?, val dateTime: String, val excretaType: String, ) : Parcelable From b45c78ff78047e1f11be93c09421753a97f355ff Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 23:08:36 +0900 Subject: [PATCH 078/119] =?UTF-8?q?fix:=20=EB=8C=80=EC=86=8C=EB=B3=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=ED=99=94=EB=A9=B4=20excretaImageURL=20nul?= =?UTF-8?q?l=20=EB=8C=80=EC=9D=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/excreta/view/ExcretaInfoFragment.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaInfoFragment.kt b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaInfoFragment.kt index 4d4bc11d..4bde06cc 100644 --- a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaInfoFragment.kt +++ b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaInfoFragment.kt @@ -35,7 +35,7 @@ class ExcretaInfoFragment : Fragment() { private val userViewModel: UserViewModel by viewModels() private lateinit var excretaInfo: ExcretaDetailGetResponse - private var excretaImageURL = "" + private var excretaImageURL: String? = "" private var excretaDateTime = "" private var excretaType = "" private var accessToken = "" @@ -125,9 +125,9 @@ class ExcretaInfoFragment : Fragment() { } } - private fun initExcretaImage(excretaImageURL: String) { + private fun initExcretaImage(excretaImageURL: String?) { binding.apply { - if (excretaImageURL.isNotEmpty()) { + if (!excretaImageURL.isNullOrEmpty()) { cardviewExcretaInfoVisibilityOff.visibility = View.VISIBLE imageviewExcretainfoFecesIllustration.visibility = View.INVISIBLE Glide.with(this@ExcretaInfoFragment) @@ -139,6 +139,9 @@ class ExcretaInfoFragment : Fragment() { imageviewExcretainfoPicture.setOnClickListener { cardviewExcretaInfoVisibilityOff.visibility = View.VISIBLE } + } else { + cardviewExcretaInfoVisibilityOff.visibility = View.GONE + imageviewExcretainfoFecesIllustration.visibility = View.VISIBLE } } } From 49595f37b6b57f5865d320593b647defb86c799e Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 23:09:20 +0900 Subject: [PATCH 079/119] =?UTF-8?q?fix:=20ExcretaEditFragment=EC=9D=98=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excreta/view/ExcretaEditFragment.kt | 66 ++++++++++--------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaEditFragment.kt b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaEditFragment.kt index 5a4835cc..99154f54 100644 --- a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaEditFragment.kt @@ -8,14 +8,14 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels -import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import com.bumptech.glide.Glide +import com.project.meongcare.BuildConfig import com.project.meongcare.CalendarBottomSheetFragment import com.project.meongcare.R -import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri -import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUrl -import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName +import com.project.meongcare.aws.util.AWSS3ImageUtils.convertUriToFile +import com.project.meongcare.aws.util.EXCRETA_FOLDER_PATH +import com.project.meongcare.aws.util.PARENT_FOLDER_PATH import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentExcretaAddEditBinding import com.project.meongcare.excreta.model.data.local.PhotoListener @@ -39,8 +39,10 @@ import com.project.meongcare.excreta.viewmodel.ExcretaPatchViewModel import com.project.meongcare.feed.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.DateSubmitListener import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch -import okhttp3.MultipartBody +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.asRequestBody +import java.io.File @AndroidEntryPoint class ExcretaEditFragment : Fragment(), DateSubmitListener, PhotoListener { @@ -53,8 +55,8 @@ class ExcretaEditFragment : Fragment(), DateSubmitListener, PhotoListener { private val calendarModalBottomSheet = CalendarBottomSheetFragment() private lateinit var excretaInfo: ExcretaDetailGetResponse - private lateinit var multipartImage: MultipartBody.Part - private lateinit var fileName: String + private lateinit var imageFile: File + private lateinit var filePath: String private var excretaDate = "" private var accessToken = "" @@ -107,7 +109,7 @@ class ExcretaEditFragment : Fragment(), DateSubmitListener, PhotoListener { private fun initExcretaImage() { val excretaImageURL = excretaInfo.excretaImageURL binding.apply { - if (excretaImageURL.isNotEmpty()) { + if (!excretaImageURL.isNullOrEmpty()) { Glide.with(this@ExcretaEditFragment) .load(excretaImageURL) .into(imageviewExcretaaddPicture) @@ -197,43 +199,44 @@ class ExcretaEditFragment : Fragment(), DateSubmitListener, PhotoListener { } if (isValid) { - getPreSignedUrl() + val uri = excretaPatchViewModel.excretaImage.value + if (uri == null) { // 새로 등록된 이미지가 없을 때 + if (excretaInfo.excretaImageURL == null) { // 기존 이미지 null + patchExcreta(null) + } else { + patchExcreta(excretaInfo.excretaImageURL) + } + } else { + getPreSignedUrl(uri) + } } } } } - private fun getPreSignedUrl() { + private fun getPreSignedUrl(uri: Uri) { + imageFile = convertUriToFile(requireContext(), uri) + filePath = "$PARENT_FOLDER_PATH$EXCRETA_FOLDER_PATH${imageFile.name}" + awsS3ViewModel.getPreSignedUrl(accessToken, filePath) awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> if (response != null) { - uploadImage(response.preSignedUrl) - } - } - val imageUri = excretaPatchViewModel.excretaImage.value - - if (imageUri == null) { - lifecycleScope.launch { - multipartImage = createMultipartFromUrl(requireContext(), excretaInfo.excretaImageURL) - fileName = getMultipartFileName(multipartImage) - awsS3ViewModel.getPreSignedUrl(accessToken, fileName) + val requestBody = imageFile.asRequestBody("image/*".toMediaTypeOrNull()) + uploadImage(response.preSignedUrl, requestBody) } - } else { - multipartImage = createMultipartFromUri(requireContext(), imageUri) - fileName = getMultipartFileName(multipartImage) - awsS3ViewModel.getPreSignedUrl(accessToken, fileName) } } - private fun uploadImage(preSignedUrl: String) { - awsS3ViewModel.uploadImageToS3(preSignedUrl, multipartImage) + private fun uploadImage(preSignedUrl: String, requestBody: RequestBody) { + awsS3ViewModel.uploadImageToS3(preSignedUrl, requestBody) awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { -// patchExcreta() + val imageURL = BuildConfig.AWS_S3_BASE_URL + filePath + patchExcreta(imageURL) } } } - private fun patchExcreta() { + private fun patchExcreta(imageURL: String?) { val excretaType = if (binding.checkboxExcretaaddUrine.isChecked) { Excreta.URINE.toString() @@ -245,15 +248,14 @@ class ExcretaEditFragment : Fragment(), DateSubmitListener, PhotoListener { ExcretaDateTimeUtils.convertTimeFormat(binding.timepikerExcretaaddTime) val excretaDateTime = "${excretaDate}T$excretaTime" - val currentImageUri = excretaPatchViewModel.excretaImage.value excretaPatchViewModel.patchExcreta( accessToken, getExcretaId(), excretaType, excretaDateTime, - requireContext(), - currentImageUri ?: Uri.EMPTY, + imageURL, ) + excretaPatchViewModel.excretaPatched.observe(viewLifecycleOwner) { response -> if (response == SUCCESS) { showSuccessSnackBar( From 3828fa88caffcac5eb284f7ce41fcb680c67a140 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 23:09:49 +0900 Subject: [PATCH 080/119] =?UTF-8?q?remove:=20ExcretaInfoUtils=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20import=20?= =?UTF-8?q?=EB=B0=8F=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/meongcare/excreta/utils/ExcretaInfoUtils.kt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/excreta/utils/ExcretaInfoUtils.kt b/app/src/main/java/com/project/meongcare/excreta/utils/ExcretaInfoUtils.kt index fa9e4583..9eb7cb3a 100644 --- a/app/src/main/java/com/project/meongcare/excreta/utils/ExcretaInfoUtils.kt +++ b/app/src/main/java/com/project/meongcare/excreta/utils/ExcretaInfoUtils.kt @@ -5,7 +5,6 @@ import android.net.Uri import android.view.View import com.google.gson.Gson import com.project.meongcare.R -import com.project.meongcare.excreta.model.entities.ExcretaInfoPatch import com.project.meongcare.snackbar.view.CustomSnackBar import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MultipartBody @@ -15,11 +14,6 @@ import okhttp3.RequestBody.Companion.toRequestBody import java.io.File object ExcretaInfoUtils { - fun convertExcretaPatchDto(excretaInfoPatch: ExcretaInfoPatch): RequestBody { - val json = Gson().toJson(excretaInfoPatch) - return json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) - } - fun convertExcretaFile( context: Context, uri: Uri, From 693af97edb831cb2a44672ff3cf49b6c5239189a Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 3 Apr 2024 23:11:29 +0900 Subject: [PATCH 081/119] =?UTF-8?q?fix:=20=EC=82=AC=EB=A3=8C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=ED=99=94=EB=A9=B4=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EB=AF=B8=EB=93=B1=EB=A1=9D=20=EC=8B=9C=20Post=20api=20?= =?UTF-8?q?=ED=98=B8=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/feed/view/FeedAddFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt b/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt index b39de917..649fc090 100644 --- a/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt +++ b/app/src/main/java/com/project/meongcare/feed/view/FeedAddFragment.kt @@ -474,7 +474,7 @@ class FeedAddFragment : Fragment(), FeedPhotoListener { if (isValid) { val uri = feedPostViewModel.feedImage.value if (uri == null) { - + postFeedInfo(null) } else { getPreSignedUrl(uri) } From 8a74222d6b5be98b2751f9f580c539733d033f58 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 4 Apr 2024 01:14:44 +0900 Subject: [PATCH 082/119] =?UTF-8?q?fix:=20FeedPutInfo=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 클래스명 FeedPutInfo -> FeedPutRequest로 변경 - imageURL 프로퍼티 추가 --- .../feed/model/entities/{FeedPutInfo.kt => FeedPutRequest.kt} | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename app/src/main/java/com/project/meongcare/feed/model/entities/{FeedPutInfo.kt => FeedPutRequest.kt} (87%) diff --git a/app/src/main/java/com/project/meongcare/feed/model/entities/FeedPutInfo.kt b/app/src/main/java/com/project/meongcare/feed/model/entities/FeedPutRequest.kt similarity index 87% rename from app/src/main/java/com/project/meongcare/feed/model/entities/FeedPutInfo.kt rename to app/src/main/java/com/project/meongcare/feed/model/entities/FeedPutRequest.kt index 35297b86..c5ce1c92 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/entities/FeedPutInfo.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/entities/FeedPutRequest.kt @@ -1,6 +1,6 @@ package com.project.meongcare.feed.model.entities -data class FeedPutInfo( +data class FeedPutRequest( val feedId: Long, val brand: String, val feedName: String, @@ -14,4 +14,5 @@ data class FeedPutInfo( val startDate: String, val endDate: String? = null, val feedRecordId: Long, + val imageURL: String?, ) From 2e30ebe1578c467a2959611159e98166d15590d9 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 4 Apr 2024 01:15:33 +0900 Subject: [PATCH 083/119] =?UTF-8?q?fix:=20Feed=20Put=20API=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20Feed=20Put=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feed/model/data/remote/FeedRemoteDataSource.kt | 7 +++---- .../meongcare/feed/model/data/remote/FeedService.kt | 9 ++------- .../feed/model/data/repository/FeedRepository.kt | 4 ++-- .../feed/model/data/repository/FeedRepositoryImpl.kt | 6 +++--- .../project/meongcare/feed/viewmodel/FeedPutViewModel.kt | 5 +++-- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedRemoteDataSource.kt b/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedRemoteDataSource.kt index af2a9b5a..d0f6394d 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedRemoteDataSource.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedRemoteDataSource.kt @@ -7,8 +7,8 @@ import com.project.meongcare.feed.model.entities.FeedGetResponse import com.project.meongcare.feed.model.entities.FeedPartRecords import com.project.meongcare.feed.model.entities.FeedPatchRequest import com.project.meongcare.feed.model.entities.FeedPostRequest +import com.project.meongcare.feed.model.entities.FeedPutRequest import com.project.meongcare.feed.model.entities.FeedRecords -import com.project.meongcare.feed.model.entities.FeedUploadRequest import com.project.meongcare.feed.model.entities.Feeds import org.json.JSONObject import javax.inject.Inject @@ -231,14 +231,13 @@ class FeedRemoteDataSource suspend fun putFeed( accessToken: String, - feedUploadRequest: FeedUploadRequest, + feedPutRequest: FeedPutRequest, ): Int? { try { val putFeedResponse = feedApiService.putFeed( accessToken, - feedUploadRequest.dto, - feedUploadRequest.file, + feedPutRequest, ) if (putFeedResponse.code() != SUCCESS) { diff --git a/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedService.kt b/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedService.kt index cdaf1b7c..7d9bf3df 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedService.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/data/remote/FeedService.kt @@ -5,20 +5,17 @@ import com.project.meongcare.feed.model.entities.FeedGetResponse import com.project.meongcare.feed.model.entities.FeedPartRecords import com.project.meongcare.feed.model.entities.FeedPatchRequest import com.project.meongcare.feed.model.entities.FeedPostRequest +import com.project.meongcare.feed.model.entities.FeedPutRequest import com.project.meongcare.feed.model.entities.FeedRecords import com.project.meongcare.feed.model.entities.Feeds -import okhttp3.MultipartBody -import okhttp3.RequestBody import retrofit2.Response import retrofit2.http.Body import retrofit2.http.DELETE import retrofit2.http.GET import retrofit2.http.Header -import retrofit2.http.Multipart import retrofit2.http.PATCH import retrofit2.http.POST import retrofit2.http.PUT -import retrofit2.http.Part import retrofit2.http.Path import retrofit2.http.Query @@ -74,12 +71,10 @@ interface FeedService { @Path("feedRecordId") feedRecordId: Long, ): Response - @Multipart @PUT("feed") suspend fun putFeed( @Header("AccessToken") accessToken: String, - @Part("dto") dto: RequestBody, - @Part file: MultipartBody.Part, + @Body feedPutRequest: FeedPutRequest, ): Response @DELETE("feed/{feedRecordId}") diff --git a/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepository.kt b/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepository.kt index 01c91b82..51f2be18 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepository.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepository.kt @@ -5,8 +5,8 @@ import com.project.meongcare.feed.model.entities.FeedGetResponse import com.project.meongcare.feed.model.entities.FeedPartRecords import com.project.meongcare.feed.model.entities.FeedPatchRequest import com.project.meongcare.feed.model.entities.FeedPostRequest +import com.project.meongcare.feed.model.entities.FeedPutRequest import com.project.meongcare.feed.model.entities.FeedRecords -import com.project.meongcare.feed.model.entities.FeedUploadRequest import com.project.meongcare.feed.model.entities.Feeds interface FeedRepository { @@ -55,7 +55,7 @@ interface FeedRepository { suspend fun putFeed( accessToken: String, - feedUploadRequest: FeedUploadRequest, + feedPutRequest: FeedPutRequest, ): Int? suspend fun deleteFeed( diff --git a/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepositoryImpl.kt b/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepositoryImpl.kt index d184b93f..617f98a0 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepositoryImpl.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/data/repository/FeedRepositoryImpl.kt @@ -3,7 +3,7 @@ package com.project.meongcare.feed.model.data.repository import com.project.meongcare.feed.model.data.remote.FeedRemoteDataSource import com.project.meongcare.feed.model.entities.FeedPatchRequest import com.project.meongcare.feed.model.entities.FeedPostRequest -import com.project.meongcare.feed.model.entities.FeedUploadRequest +import com.project.meongcare.feed.model.entities.FeedPutRequest import javax.inject.Inject class FeedRepositoryImpl @@ -56,8 +56,8 @@ class FeedRepositoryImpl override suspend fun putFeed( accessToken: String, - feedUploadRequest: FeedUploadRequest, - ) = feedRemoteDataSource.putFeed(accessToken, feedUploadRequest) + feedPutRequest: FeedPutRequest, + ): Int? = feedRemoteDataSource.putFeed(accessToken, feedPutRequest) override suspend fun deleteFeed( accessToken: String, diff --git a/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPutViewModel.kt b/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPutViewModel.kt index fd7b2de7..19719da5 100644 --- a/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPutViewModel.kt +++ b/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPutViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.project.meongcare.feed.model.data.repository.FeedRepositoryImpl +import com.project.meongcare.feed.model.entities.FeedPutRequest import com.project.meongcare.feed.model.entities.FeedUploadRequest import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch @@ -30,11 +31,11 @@ class FeedPutViewModel fun putFeed( accessToken: String, - feedUploadRequest: FeedUploadRequest, + feedPutRequest: FeedPutRequest, ) { viewModelScope.launch { _feedPut.value = - feedRepositoryImpl.putFeed(accessToken, feedUploadRequest) + feedRepositoryImpl.putFeed(accessToken, feedPutRequest) } } } From 679b3d426eede890d97ede28a2c5515783408b01 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 4 Apr 2024 01:16:41 +0900 Subject: [PATCH 084/119] =?UTF-8?q?fix:=20FeedEditFragment=EC=9D=98=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/feed/view/FeedEditFragment.kt | 103 +++++++----------- 1 file changed, 39 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt b/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt index 0b6b731b..584218b4 100644 --- a/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt @@ -21,9 +21,9 @@ import androidx.navigation.fragment.findNavController import com.archit.calendardaterangepicker.customviews.CalendarListener import com.archit.calendardaterangepicker.customviews.DateRangeCalendarView import com.bumptech.glide.Glide +import com.project.meongcare.BuildConfig import com.project.meongcare.R -import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri -import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName +import com.project.meongcare.aws.util.AWSS3ImageUtils.convertUriToFile import com.project.meongcare.aws.util.FEED_FOLDER_PATH import com.project.meongcare.aws.util.PARENT_FOLDER_PATH import com.project.meongcare.aws.viewmodel.AWSS3ViewModel @@ -31,7 +31,7 @@ import com.project.meongcare.databinding.FragmentFeedAddEditBinding import com.project.meongcare.excreta.utils.SUCCESS import com.project.meongcare.feed.model.data.local.FeedPhotoListener import com.project.meongcare.feed.model.entities.FeedDetailGetResponse -import com.project.meongcare.feed.model.entities.FeedPutInfo +import com.project.meongcare.feed.model.entities.FeedPutRequest import com.project.meongcare.feed.model.entities.FeedUploadRequest import com.project.meongcare.feed.model.utils.END_DATE import com.project.meongcare.feed.model.utils.FEED_PUT_FAILURE @@ -56,7 +56,11 @@ import com.project.meongcare.feed.viewmodel.FeedPutViewModel import com.project.meongcare.feed.viewmodel.UserViewModel import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MultipartBody +import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.asRequestBody +import java.io.File import java.text.SimpleDateFormat import java.util.Calendar import java.util.Locale @@ -71,9 +75,9 @@ class FeedEditFragment : Fragment(), FeedPhotoListener { private var feedId = 0L private var feedRecordId = 0L private lateinit var feedInfo: FeedDetailGetResponse - private lateinit var feedPutInfo: FeedPutInfo - private lateinit var multipartImage: MultipartBody.Part - private lateinit var fileName: String + private lateinit var feedPutInfo: FeedPutRequest + private lateinit var imageFile: File + private lateinit var filePath: String private var recommendIntake = 0.0 private var selectedStartDate = "" private var selectedEndDate: String? = null @@ -132,7 +136,7 @@ class FeedEditFragment : Fragment(), FeedPhotoListener { private fun fetchFeedInfo() { binding.apply { recommendIntake = feedInfo.recommendIntake.toDouble() - if (feedInfo.imageURL.isNotEmpty()) { + if (!feedInfo.imageURL.isNullOrEmpty()) { Glide.with(this@FeedEditFragment) .load(feedInfo.imageURL) .into(imageviewFeedaddeditPicture) @@ -347,12 +351,12 @@ class FeedEditFragment : Fragment(), FeedPhotoListener { } } - private fun createFeedInfo() { + private fun createFeedInfo(imageURL: String?) { binding.apply { val brand = edittextFeedaddeditBrand.text.toString() val feedName = edittextFeedaddeditName.text.toString() feedPutInfo = - FeedPutInfo( + FeedPutRequest( feedId, brand, feedName, @@ -366,6 +370,7 @@ class FeedEditFragment : Fragment(), FeedPhotoListener { selectedStartDate, selectedEndDate, feedRecordId, + imageURL, ) } } @@ -499,80 +504,50 @@ class FeedEditFragment : Fragment(), FeedPhotoListener { } if (isValid) { -// editFeedInfo() - getPreSignedUrl() + val uri = feedPutViewModel.feedImage.value + if (uri == null) { // 기존 이미지 + if (feedInfo.imageURL == null) { + createFeedInfo(null) + putFeed() + } else { + createFeedInfo(feedInfo.imageURL) + putFeed() + } + } else { // 새 이미지 + getPreSignedUrl(uri) + } } } } } - private fun getPreSignedUrl() { + private fun getPreSignedUrl(uri: Uri) { + imageFile = convertUriToFile(requireContext(), uri) + filePath = "$PARENT_FOLDER_PATH$FEED_FOLDER_PATH${imageFile.name}" + awsS3ViewModel.getPreSignedUrl(accessToken, filePath) awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> if (response != null) { - uploadImage(response.preSignedUrl) + val requestBody = imageFile.asRequestBody("image/*".toMediaTypeOrNull()) + uploadImage(response.preSignedUrl, requestBody) } } - val imageUri = feedPutViewModel.feedImage.value - - if (imageUri == null) { - lifecycleScope.launch { - multipartImage = convertFeedImageUrl(requireContext(), feedInfo.imageURL) - fileName = "$PARENT_FOLDER_PATH$FEED_FOLDER_PATH${getMultipartFileName(multipartImage)}" - awsS3ViewModel.getPreSignedUrl(accessToken, fileName) - } - } else { - multipartImage = createMultipartFromUri(requireContext(), imageUri) - fileName = "$PARENT_FOLDER_PATH$FEED_FOLDER_PATH${getMultipartFileName(multipartImage)}" - awsS3ViewModel.getPreSignedUrl(accessToken, fileName) - } } - private fun uploadImage(preSignedUrl: String) { - awsS3ViewModel.uploadImageToS3(preSignedUrl, multipartImage) + private fun uploadImage(preSignedUrl: String, requestBody: RequestBody) { + awsS3ViewModel.uploadImageToS3(preSignedUrl, requestBody) awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { -// editFeedInfo() - } - } - } - - private fun editFeedInfo() { - binding.apply { - createFeedInfo() - val imageUri = feedPutViewModel.feedImage.value - - if (imageUri == null) { - lifecycleScope.launch { - val file = - convertFeedImageUrl( - requireContext(), - feedInfo.imageURL, - ) - val feedUploadRequest = createFeedPutRequest(file) - putFeed(feedUploadRequest) - } - } else { - val file = - convertFeedFile( - requireContext(), - imageUri, - ) - val feedUploadRequest = createFeedPutRequest(file) - putFeed(feedUploadRequest) + val imageURL = BuildConfig.AWS_S3_BASE_URL + filePath + createFeedInfo(imageURL) + putFeed() } } } - private fun createFeedPutRequest(file: MultipartBody.Part): FeedUploadRequest { - val dto = convertFeedPutDto(feedPutInfo) - - return FeedUploadRequest(dto, file) - } - - private fun putFeed(feedUploadRequest: FeedUploadRequest) { + private fun putFeed() { feedPutViewModel.putFeed( accessToken, - feedUploadRequest, + feedPutInfo, ) feedPutViewModel.feedPut.observe(viewLifecycleOwner) { response -> if (response == SUCCESS) { From db7f6777cc6a4d6fb67f5ca49157120b05072394 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 4 Apr 2024 01:18:43 +0900 Subject: [PATCH 085/119] =?UTF-8?q?fix:=20Feed=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EC=9D=98=20imageURL=20=ED=94=84=EB=A1=9C=ED=8D=BC?= =?UTF-8?q?=ED=8B=B0=20nullable=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FeedsAdapter 클래스에서 imageURL null 대응 --- .../main/java/com/project/meongcare/feed/model/entities/Feed.kt | 2 +- .../main/java/com/project/meongcare/feed/view/FeedsAdapter.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/feed/model/entities/Feed.kt b/app/src/main/java/com/project/meongcare/feed/model/entities/Feed.kt index 8b18ae0d..a2a3fa61 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/entities/Feed.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/entities/Feed.kt @@ -4,5 +4,5 @@ data class Feed( val feedId: Long, val brandName: String, val feedName: String, - val imageURL: String, + val imageURL: String?, ) diff --git a/app/src/main/java/com/project/meongcare/feed/view/FeedsAdapter.kt b/app/src/main/java/com/project/meongcare/feed/view/FeedsAdapter.kt index a7ff1901..bc80c0a6 100644 --- a/app/src/main/java/com/project/meongcare/feed/view/FeedsAdapter.kt +++ b/app/src/main/java/com/project/meongcare/feed/view/FeedsAdapter.kt @@ -18,7 +18,7 @@ class FeedsAdapter( RecyclerView.ViewHolder(binding.root) { fun bind(item: Feed) { binding.run { - if (item.imageURL.isNotEmpty()) { + if (!item.imageURL.isNullOrEmpty()) { Glide.with(itemView) .load(item.imageURL) .into(imageviewOldfeed) From 59359b93e993ca23b3428234caa86106bb8be28b Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 4 Apr 2024 01:20:07 +0900 Subject: [PATCH 086/119] =?UTF-8?q?fix:=20FeedDetailGetResponse=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EC=9D=98=20imageURL=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=8D=BC=ED=8B=B0=20nullable=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/feed/model/entities/FeedDetailGetResponse.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/feed/model/entities/FeedDetailGetResponse.kt b/app/src/main/java/com/project/meongcare/feed/model/entities/FeedDetailGetResponse.kt index 4a1c773f..ba468b6d 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/entities/FeedDetailGetResponse.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/entities/FeedDetailGetResponse.kt @@ -14,7 +14,7 @@ data class FeedDetailGetResponse( val etc: Double, val kcal: Double, val recommendIntake: Long, - val imageURL: String, + val imageURL: String?, val startDate: String, val endDate: String?, ) : Parcelable From fa294b8aa59d1a12b780ab89431120d00739ff46 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 4 Apr 2024 01:21:13 +0900 Subject: [PATCH 087/119] =?UTF-8?q?fix:=20FeedPartRecord=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EC=9D=98=20feedImageURL=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=8D=BC=ED=8B=B0=20nullable=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FeedPartAdapter 클래스에서 feedImageURL 값 null 대응 --- .../com/project/meongcare/feed/model/entities/FeedPartRecord.kt | 2 +- .../java/com/project/meongcare/feed/view/FeedPartAdapter.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/feed/model/entities/FeedPartRecord.kt b/app/src/main/java/com/project/meongcare/feed/model/entities/FeedPartRecord.kt index 6992ea3e..6098d803 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/entities/FeedPartRecord.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/entities/FeedPartRecord.kt @@ -5,6 +5,6 @@ data class FeedPartRecord( val feedName: String, val startDate: String, val endDate: String, - val feedImageURL: String, + val feedImageURL: String?, val feedRecordId: Long, ) diff --git a/app/src/main/java/com/project/meongcare/feed/view/FeedPartAdapter.kt b/app/src/main/java/com/project/meongcare/feed/view/FeedPartAdapter.kt index 981605af..50407587 100644 --- a/app/src/main/java/com/project/meongcare/feed/view/FeedPartAdapter.kt +++ b/app/src/main/java/com/project/meongcare/feed/view/FeedPartAdapter.kt @@ -14,7 +14,7 @@ class FeedPartAdapter : ListAdapter Date: Thu, 4 Apr 2024 01:22:11 +0900 Subject: [PATCH 088/119] =?UTF-8?q?fix:=20FeedRecord=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EC=9D=98=20imageURL=20=ED=94=84=EB=A1=9C=ED=8D=BC?= =?UTF-8?q?=ED=8B=B0=20nullable=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PreviousFeedAdapter 클래스에서 imageURL 값 null 대응 --- .../com/project/meongcare/feed/model/entities/FeedRecord.kt | 2 +- .../java/com/project/meongcare/feed/view/PreviousFeedAdapter.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/feed/model/entities/FeedRecord.kt b/app/src/main/java/com/project/meongcare/feed/model/entities/FeedRecord.kt index aa5a1db1..1f152784 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/entities/FeedRecord.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/entities/FeedRecord.kt @@ -6,6 +6,6 @@ data class FeedRecord( val startDate: String, val endDate: String, val feedRecordId: Long, - val imageURL: String, + val imageURL: String?, val feedId: Long, ) diff --git a/app/src/main/java/com/project/meongcare/feed/view/PreviousFeedAdapter.kt b/app/src/main/java/com/project/meongcare/feed/view/PreviousFeedAdapter.kt index 211d70d9..98ad0732 100644 --- a/app/src/main/java/com/project/meongcare/feed/view/PreviousFeedAdapter.kt +++ b/app/src/main/java/com/project/meongcare/feed/view/PreviousFeedAdapter.kt @@ -17,7 +17,7 @@ class PreviousFeedAdapter : ListAdapter Date: Thu, 4 Apr 2024 01:23:20 +0900 Subject: [PATCH 089/119] =?UTF-8?q?fix:=20FeedInfoFragment=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EC=97=90=EC=84=9C=20imageURL=20null=20?= =?UTF-8?q?=EB=8C=80=EC=9D=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/feed/view/FeedInfoFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/feed/view/FeedInfoFragment.kt b/app/src/main/java/com/project/meongcare/feed/view/FeedInfoFragment.kt index 3745578a..21ea36c6 100644 --- a/app/src/main/java/com/project/meongcare/feed/view/FeedInfoFragment.kt +++ b/app/src/main/java/com/project/meongcare/feed/view/FeedInfoFragment.kt @@ -84,7 +84,7 @@ class FeedInfoFragment : Fragment() { response.startDate, response.endDate, ) - if (response.imageURL.isNotEmpty()) { + if (!response.imageURL.isNullOrEmpty()) { Glide.with(this@FeedInfoFragment) .load(response.imageURL) .into(imageviewFeedinfo) From 0f8e80f1c15fa97aaaddaadb9a64b0823e103099 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 4 Apr 2024 01:25:41 +0900 Subject: [PATCH 090/119] =?UTF-8?q?remove:=20FeedInfoUtils=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20import?= =?UTF-8?q?=EB=AC=B8=20=EB=B0=8F=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feed/model/utils/FeedInfoUtils.kt | 69 ------------------- 1 file changed, 69 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/feed/model/utils/FeedInfoUtils.kt b/app/src/main/java/com/project/meongcare/feed/model/utils/FeedInfoUtils.kt index e7150765..bf56bc42 100644 --- a/app/src/main/java/com/project/meongcare/feed/model/utils/FeedInfoUtils.kt +++ b/app/src/main/java/com/project/meongcare/feed/model/utils/FeedInfoUtils.kt @@ -1,80 +1,11 @@ package com.project.meongcare.feed.model.utils -import android.content.Context -import android.net.Uri -import android.util.Log import android.view.View import android.widget.TextView -import com.google.gson.Gson import com.project.meongcare.R -import com.project.meongcare.feed.model.entities.FeedPutInfo import com.project.meongcare.snackbar.view.CustomSnackBar -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext -import okhttp3.MediaType.Companion.toMediaTypeOrNull -import okhttp3.MultipartBody -import okhttp3.RequestBody -import okhttp3.RequestBody.Companion.asRequestBody -import okhttp3.RequestBody.Companion.toRequestBody -import java.io.BufferedInputStream -import java.io.File -import java.net.URL object FeedInfoUtils { - fun convertFeedPutDto(feedPutInfo: FeedPutInfo): RequestBody { - val json = Gson().toJson(feedPutInfo) - return json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) - } - - fun convertFeedFile( - context: Context, - uri: Uri, - ): MultipartBody.Part { - if (uri.toString().isEmpty()) { - val emptyFile = "".toRequestBody("multipart/form-data".toMediaTypeOrNull()) - return MultipartBody.Part.createFormData("file", "", emptyFile) - } - - // Uri로부터 InputStream을 얻고, 임시 파일로 복사 - val inputStream = context.contentResolver.openInputStream(uri) - val file = File(context.cacheDir, "tempFile") - inputStream.use { input -> - file.outputStream().use { output -> - input?.copyTo(output) - } - } - val requestFile = file.asRequestBody("multipart/form-data".toMediaTypeOrNull()) - - return MultipartBody.Part.createFormData("file", file.name, requestFile) - } - - suspend fun convertFeedImageUrl( - context: Context, - urlString: String, - ): MultipartBody.Part { - return withContext(Dispatchers.IO) { - try { - val url = URL(urlString) - val connection = url.openConnection() - val inputStream = BufferedInputStream(connection.getInputStream()) - val file = File(context.cacheDir, "downloadedFile") - inputStream.use { input -> - file.outputStream().use { output -> - input.copyTo(output) - } - } - - val requestFile = file.asRequestBody("multipart/form-data".toMediaTypeOrNull()) - MultipartBody.Part.createFormData("file", file.name, requestFile) - } catch (e: Exception) { - Log.d("사료 이미지 URL 변환 실패", e.message.toString()) - - val emptyFile = "".toRequestBody("multipart/form-data".toMediaTypeOrNull()) - MultipartBody.Part.createFormData("file", "", emptyFile) - } - } - } - fun calculateRecommendDailyIntake( weight: Double, feedKcal: Double, From 351024993509a6dc5e0963c9450fe2622221f3ee Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 4 Apr 2024 01:55:09 +0900 Subject: [PATCH 091/119] =?UTF-8?q?remove:=20FeedEditFragment=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20import?= =?UTF-8?q?=EB=AC=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/meongcare/feed/view/FeedEditFragment.kt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt b/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt index 584218b4..c8a6ce8f 100644 --- a/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt @@ -15,7 +15,6 @@ import android.widget.TextView import androidx.core.widget.doAfterTextChanged import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels -import androidx.lifecycle.lifecycleScope import androidx.navigation.findNavController import androidx.navigation.fragment.findNavController import com.archit.calendardaterangepicker.customviews.CalendarListener @@ -32,15 +31,11 @@ import com.project.meongcare.excreta.utils.SUCCESS import com.project.meongcare.feed.model.data.local.FeedPhotoListener import com.project.meongcare.feed.model.entities.FeedDetailGetResponse import com.project.meongcare.feed.model.entities.FeedPutRequest -import com.project.meongcare.feed.model.entities.FeedUploadRequest import com.project.meongcare.feed.model.utils.END_DATE import com.project.meongcare.feed.model.utils.FEED_PUT_FAILURE import com.project.meongcare.feed.model.utils.FEED_PUT_SUCCESS import com.project.meongcare.feed.model.utils.FeedDateUtils.convertDateFormat import com.project.meongcare.feed.model.utils.FeedInfoUtils.calculateRecommendDailyIntake -import com.project.meongcare.feed.model.utils.FeedInfoUtils.convertFeedFile -import com.project.meongcare.feed.model.utils.FeedInfoUtils.convertFeedImageUrl -import com.project.meongcare.feed.model.utils.FeedInfoUtils.convertFeedPutDto import com.project.meongcare.feed.model.utils.FeedInfoUtils.initRecommendDailyIntake import com.project.meongcare.feed.model.utils.FeedInfoUtils.showFailureSnackBar import com.project.meongcare.feed.model.utils.FeedInfoUtils.showSuccessSnackBar @@ -55,9 +50,7 @@ import com.project.meongcare.feed.viewmodel.DogViewModel import com.project.meongcare.feed.viewmodel.FeedPutViewModel import com.project.meongcare.feed.viewmodel.UserViewModel import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch import okhttp3.MediaType.Companion.toMediaTypeOrNull -import okhttp3.MultipartBody import okhttp3.RequestBody import okhttp3.RequestBody.Companion.asRequestBody import java.io.File From 300affa4494b1f81f0f71622186a24998a248af4 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 4 Apr 2024 01:56:21 +0900 Subject: [PATCH 092/119] =?UTF-8?q?feat:=20=EA=B0=95=EC=95=84=EC=A7=80=20P?= =?UTF-8?q?ut=20api=20=ED=98=B8=EC=B6=9C=20=EC=8B=9C=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20DogPutRequest=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/info/model/entities/DogPutRequest.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 app/src/main/java/com/project/meongcare/info/model/entities/DogPutRequest.kt diff --git a/app/src/main/java/com/project/meongcare/info/model/entities/DogPutRequest.kt b/app/src/main/java/com/project/meongcare/info/model/entities/DogPutRequest.kt new file mode 100644 index 00000000..34a27f79 --- /dev/null +++ b/app/src/main/java/com/project/meongcare/info/model/entities/DogPutRequest.kt @@ -0,0 +1,14 @@ +package com.project.meongcare.info.model.entities + +data class DogPutRequest( + val name: String, + val type: String, + val sex: String, + val birthDate: String, + val castrate: Boolean, + val weight: Double, + val backRound: Double?, + val neckRound: Double?, + val chestRound: Double?, + val imageURL: String?, +) From 35bd12055816046b8b878654b5646c4955b78a35 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 4 Apr 2024 01:58:04 +0900 Subject: [PATCH 093/119] =?UTF-8?q?fix:=20Dog=20Put=20API=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20Dog=20Put=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/meongcare/info/model/data/remote/ProfileApi.kt | 6 ++---- .../info/model/data/repository/ProfileRepository.kt | 4 ++-- .../info/model/data/repository/ProfileRepositoryImpl.kt | 6 +++--- .../project/meongcare/info/viewmodel/ProfileViewModel.kt | 6 +++--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/model/data/remote/ProfileApi.kt b/app/src/main/java/com/project/meongcare/info/model/data/remote/ProfileApi.kt index 42942c49..62c0c9fa 100644 --- a/app/src/main/java/com/project/meongcare/info/model/data/remote/ProfileApi.kt +++ b/app/src/main/java/com/project/meongcare/info/model/data/remote/ProfileApi.kt @@ -3,9 +3,9 @@ package com.project.meongcare.info.model.data.remote import com.project.meongcare.home.model.entities.GetDogListResponse import com.project.meongcare.home.model.entities.GetUserProfileResponse import com.project.meongcare.info.model.entities.GetDogInfoResponse +import com.project.meongcare.info.model.entities.DogPutRequest import com.project.meongcare.weight.model.entities.WeightPostRequest import okhttp3.MultipartBody -import okhttp3.RequestBody import retrofit2.Response import retrofit2.http.Body import retrofit2.http.DELETE @@ -42,13 +42,11 @@ interface ProfileApi { @Header("AccessToken") accessToken: String, ): Response - @Multipart @PUT("dog/{dogId}") suspend fun putDogInfo( @Path("dogId") dogId: Long, @Header("AccessToken") accessToken: String, - @Part file: MultipartBody.Part, - @Part("dto") dto: RequestBody, + @Body dogPutRequest: DogPutRequest, ): Response @POST("weight") diff --git a/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepository.kt b/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepository.kt index 4a8df6b2..690c1acc 100644 --- a/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepository.kt +++ b/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepository.kt @@ -3,6 +3,7 @@ package com.project.meongcare.info.model.data.repository import com.project.meongcare.home.model.entities.DogProfile import com.project.meongcare.home.model.entities.GetDogListResponse import com.project.meongcare.home.model.entities.GetUserProfileResponse +import com.project.meongcare.info.model.entities.DogPutRequest import com.project.meongcare.info.model.entities.GetDogInfoResponse import com.project.meongcare.weight.model.entities.WeightPostRequest import okhttp3.MultipartBody @@ -27,8 +28,7 @@ interface ProfileRepository { suspend fun putDogInfo( dogId: Long, accessToken: String, - file: MultipartBody.Part, - dto: RequestBody, + dogPutRequest: DogPutRequest, ): Int? suspend fun postDogWeight( diff --git a/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepositoryImpl.kt b/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepositoryImpl.kt index 1e9d13af..cfee1391 100644 --- a/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepositoryImpl.kt +++ b/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepositoryImpl.kt @@ -5,6 +5,7 @@ import com.project.meongcare.home.model.entities.DogProfile import com.project.meongcare.home.model.entities.GetDogListResponse import com.project.meongcare.home.model.entities.GetUserProfileResponse import com.project.meongcare.info.model.data.remote.ProfileRetrofitClient +import com.project.meongcare.info.model.entities.DogPutRequest import com.project.meongcare.info.model.entities.GetDogInfoResponse import com.project.meongcare.weight.model.entities.WeightPostRequest import okhttp3.MultipartBody @@ -88,11 +89,10 @@ class ProfileRepositoryImpl override suspend fun putDogInfo( dogId: Long, accessToken: String, - file: MultipartBody.Part, - dto: RequestBody, + dogPutRequest: DogPutRequest, ): Int? { return try { - val response = profileRetrofitClient.profileApi.putDogInfo(dogId, accessToken, file, dto) + val response = profileRetrofitClient.profileApi.putDogInfo(dogId, accessToken, dogPutRequest) if (response.code() == 200) { Log.d("ProfileRepo-PutDog", "통신 성공 : ${response.code()}") response.code() diff --git a/app/src/main/java/com/project/meongcare/info/viewmodel/ProfileViewModel.kt b/app/src/main/java/com/project/meongcare/info/viewmodel/ProfileViewModel.kt index 98dbf9e5..f1196056 100644 --- a/app/src/main/java/com/project/meongcare/info/viewmodel/ProfileViewModel.kt +++ b/app/src/main/java/com/project/meongcare/info/viewmodel/ProfileViewModel.kt @@ -8,6 +8,7 @@ import androidx.lifecycle.viewModelScope import com.project.meongcare.home.model.entities.GetDogListResponse import com.project.meongcare.home.model.entities.GetUserProfileResponse import com.project.meongcare.info.model.data.repository.ProfileRepository +import com.project.meongcare.info.model.entities.DogPutRequest import com.project.meongcare.info.model.entities.GetDogInfoResponse import com.project.meongcare.weight.model.entities.WeightPostRequest import dagger.hilt.android.lifecycle.HiltViewModel @@ -114,11 +115,10 @@ class ProfileViewModel fun putDogInfo( dogId: Long, accessToken: String, - file: MultipartBody.Part, - dto: RequestBody, + dogPutRequest: DogPutRequest, ) { viewModelScope.launch { - _dogPutResponse.value = profileRepository.putDogInfo(dogId, accessToken, file, dto) + _dogPutResponse.value = profileRepository.putDogInfo(dogId, accessToken, dogPutRequest) } } From f61db6ecb0155aee22df865196abeea48d3ef558 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Thu, 4 Apr 2024 01:58:28 +0900 Subject: [PATCH 094/119] =?UTF-8?q?fix:=20PetEditFragment=EC=9D=98=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/info/view/PetEditFragment.kt | 131 +++++++++--------- 1 file changed, 64 insertions(+), 67 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt index 8bd7c1e6..6f592daf 100644 --- a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt @@ -13,19 +13,18 @@ import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels -import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import com.bumptech.glide.Glide import com.project.meongcare.BirthdayBottomSheetFragment +import com.project.meongcare.BuildConfig import com.project.meongcare.R +import com.project.meongcare.aws.util.AWSS3ImageUtils.convertUriToFile import com.project.meongcare.aws.util.DOG_FOLDER_PATH import com.project.meongcare.aws.util.PARENT_FOLDER_PATH -import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri -import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUrl -import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentPetEditBinding import com.project.meongcare.home.view.getCurrentDate +import com.project.meongcare.info.model.entities.DogPutRequest import com.project.meongcare.info.model.entities.GetDogInfoResponse import com.project.meongcare.info.viewmodel.ProfileViewModel import com.project.meongcare.medicalrecord.viewmodel.UserViewModel @@ -33,13 +32,17 @@ import com.project.meongcare.onboarding.model.data.local.DateSubmitListener import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener import com.project.meongcare.onboarding.model.entities.Gender import com.project.meongcare.onboarding.util.DogAddOnBoardingDateUtils.dateFormat +import com.project.meongcare.onboarding.util.DogAddOnBoardingInfoUtils.bodySizeCheck +import com.project.meongcare.onboarding.util.DogAddOnBoardingInfoUtils.getCheckedGender import com.project.meongcare.onboarding.view.PhotoSelectBottomSheetFragment import com.project.meongcare.onboarding.viewmodel.DogTypeSharedViewModel import com.project.meongcare.snackbar.view.CustomSnackBar import com.project.meongcare.weight.model.entities.WeightPostRequest import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch -import okhttp3.MultipartBody +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.asRequestBody +import java.io.File @AndroidEntryPoint class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { @@ -47,8 +50,8 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { private lateinit var dogInfo: GetDogInfoResponse private lateinit var accessToken: String private lateinit var refreshToken: String - private lateinit var fileName: String - private lateinit var multipartImage: MultipartBody.Part + private lateinit var filePath: String + private lateinit var imageFile: File private val awsS3ViewModel: AWSS3ViewModel by viewModels() private val userViewModel: UserViewModel by viewModels() @@ -246,51 +249,6 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { binding.edittextPeteditType.setText(dogType) } } - - awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> - if (response != null) { - awsS3ViewModel.uploadImageToS3(response.preSignedUrl, multipartImage) - } - } - - awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> - if (response == 200) { -// val dogName = binding.edittextPeteditName.text.toString() -// val dogType = binding.edittextPeteditType.text.toString() -// val dogGender = getCheckedGender(binding.root, binding.chipgroupPeteditGroupGender.checkedChipId) -// val dogBirth = petEditViewModel.dogBirth.value!! -// val dogWeight = binding.edittextPeteditWeight.text.toString().toDouble() -// val dogBack = bodySizeCheck(binding.edittextPeteditBackLength.text.toString()) -// val dogNeck = bodySizeCheck(binding.edittextPeteditNeckCircumference.text.toString()) -// val dogChest = bodySizeCheck(binding.edittextPeteditChestCircumference.text.toString()) -// val dog = -// Dog( -// dogName, -// dogType, -// dogGender, -// dogBirth, -// isCbxChecked, -// dogWeight, -// dogBack, -// dogNeck, -// dogChest, -// ) -// -// val json = Gson().toJson(dog) -// val requestBody: RequestBody = json.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()) -// if (isImageUpdated) { -// // 새 이미지 등록된 경우 -// val filePart: MultipartBody.Part = createMultipartBody(requireContext(), petEditViewModel.dogProfile.value) -// petEditViewModel.putDogInfo(dogInfo.dogId, accessToken, filePart, requestBody) -// } else { -// // 기존 이미지인 경우 -// lifecycleScope.launch { -// val filePart: MultipartBody.Part = createMultipartFromUrl(dogInfo.imageUrl) -// petEditViewModel.putDogInfo(dogInfo.dogId, accessToken, filePart, requestBody) -// } -// } - } - } } private fun initViews() { @@ -347,24 +305,63 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { return@setOnClickListener } - if (isImageUpdated) { - // 새 이미지 등록된 경우 - multipartImage = createMultipartFromUri(requireContext(), petEditViewModel.dogProfile.value) - fileName = "$PARENT_FOLDER_PATH$DOG_FOLDER_PATH${getMultipartFileName(multipartImage)}" - awsS3ViewModel.getPreSignedUrl(accessToken, fileName) - } else { - lifecycleScope.launch { - // 기존 이미지인 경우 - // 일단 받아온 이미지 형태가 url이기 때문에 새로운 multipart를 만들어서 이미지 전송하도록 했지만 - // 추후에 이미지 수신 형태가 파일 경로 형태이면 이미지 전송 없이 기존 파일 경로 포함해서 정보만 전송하도록 변경 - multipartImage = createMultipartFromUrl(requireContext(), dogInfo.imageUrl) - fileName = "$PARENT_FOLDER_PATH$DOG_FOLDER_PATH${getMultipartFileName(multipartImage)}" - awsS3ViewModel.getPreSignedUrl(accessToken, fileName) - } + if (isImageUpdated) {// 새 이미지 등록 + getPreSignedURL(petEditViewModel.dogProfile.value!!) + } else { // 기존 이미지 + putDogInfo(dogInfo.imageUrl) + } + } + } + + private fun getPreSignedURL(uri: Uri) { + imageFile = convertUriToFile(requireContext(), uri) + filePath = "$PARENT_FOLDER_PATH$DOG_FOLDER_PATH${imageFile.name}" + awsS3ViewModel.getPreSignedUrl(accessToken, filePath) + awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> + if (response != null) { + val requestBody = imageFile.asRequestBody("image/*".toMediaTypeOrNull()) + uploadImage(response.preSignedUrl, requestBody) } } } + private fun uploadImage(preSignedURL: String, requestBody: RequestBody) { + awsS3ViewModel.uploadImageToS3(preSignedURL, requestBody) + awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> + if (response == 200) { + val imageURL = BuildConfig.AWS_S3_BASE_URL + filePath + putDogInfo(imageURL) + } + } + } + + private fun putDogInfo(imageURL: String?) { + val dogName = binding.edittextPeteditName.text.toString() + val dogType = binding.edittextPeteditType.text.toString() + val dogGender = getCheckedGender(binding.root, binding.chipgroupPeteditGroupGender.checkedChipId) + val dogBirth = petEditViewModel.dogBirth.value!! + val dogCastrate = binding.checkboxPeteditNeuterStatus.isChecked + val dogWeight = binding.edittextPeteditWeight.text.toString().toDouble() + val dogBack = bodySizeCheck(binding.edittextPeteditBackLength.text.toString()) + val dogNeck = bodySizeCheck(binding.edittextPeteditNeckCircumference.text.toString()) + val dogChest = bodySizeCheck(binding.edittextPeteditChestCircumference.text.toString()) + val dogPutRequest = + DogPutRequest( + dogName, + dogType, + dogGender, + dogBirth, + dogCastrate, + dogWeight, + dogBack, + dogNeck, + dogChest, + imageURL, + ) + + petEditViewModel.putDogInfo(dogInfo.dogId, accessToken, dogPutRequest) + } + private fun editTextWatcher( editText: EditText, targetView: View, From 275290d0a8bda13f8e31d34590b30b06730d3836 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 01:24:21 +0900 Subject: [PATCH 095/119] =?UTF-8?q?feat:=20=ED=94=84=EB=A1=9C=ED=95=84=20P?= =?UTF-8?q?atch=20api=20=ED=98=B8=EC=B6=9C=20=EC=8B=9C=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20ProfilePatchRequest=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/info/model/entities/ProfilePatchRequest.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 app/src/main/java/com/project/meongcare/info/model/entities/ProfilePatchRequest.kt diff --git a/app/src/main/java/com/project/meongcare/info/model/entities/ProfilePatchRequest.kt b/app/src/main/java/com/project/meongcare/info/model/entities/ProfilePatchRequest.kt new file mode 100644 index 00000000..7fd4f176 --- /dev/null +++ b/app/src/main/java/com/project/meongcare/info/model/entities/ProfilePatchRequest.kt @@ -0,0 +1,5 @@ +package com.project.meongcare.info.model.entities + +data class ProfilePatchRequest( + val imageURL: String?, +) \ No newline at end of file From f45a94f4a8f8267bf908f26fc5a251e5667d42e9 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 01:27:15 +0900 Subject: [PATCH 096/119] =?UTF-8?q?fix:=20=ED=94=84=EB=A1=9C=ED=95=84=20Pa?= =?UTF-8?q?tch=20API=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Retrofit Interface 함수 인자 수정 - patchProfileImage 함수 호출을 위해 Repository, Impl, ViewModel에서 전달하는 인자 수정 --- .../meongcare/info/model/data/remote/ProfileApi.kt | 7 ++----- .../info/model/data/repository/ProfileRepository.kt | 6 ++---- .../info/model/data/repository/ProfileRepositoryImpl.kt | 8 +++----- .../project/meongcare/info/viewmodel/ProfileViewModel.kt | 7 +++---- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/model/data/remote/ProfileApi.kt b/app/src/main/java/com/project/meongcare/info/model/data/remote/ProfileApi.kt index 62c0c9fa..38121278 100644 --- a/app/src/main/java/com/project/meongcare/info/model/data/remote/ProfileApi.kt +++ b/app/src/main/java/com/project/meongcare/info/model/data/remote/ProfileApi.kt @@ -4,18 +4,16 @@ import com.project.meongcare.home.model.entities.GetDogListResponse import com.project.meongcare.home.model.entities.GetUserProfileResponse import com.project.meongcare.info.model.entities.GetDogInfoResponse import com.project.meongcare.info.model.entities.DogPutRequest +import com.project.meongcare.info.model.entities.ProfilePatchRequest import com.project.meongcare.weight.model.entities.WeightPostRequest -import okhttp3.MultipartBody import retrofit2.Response import retrofit2.http.Body import retrofit2.http.DELETE import retrofit2.http.GET import retrofit2.http.Header -import retrofit2.http.Multipart import retrofit2.http.PATCH import retrofit2.http.POST import retrofit2.http.PUT -import retrofit2.http.Part import retrofit2.http.Path import retrofit2.http.Query @@ -79,10 +77,9 @@ interface ProfileApi { @Header("AccessToken") accessToken: String, ): Response - @Multipart @PATCH("member/profile") suspend fun patchProfileImage( @Header("AccessToken") accessToken: String, - @Part file: MultipartBody.Part, + @Body profilePatchRequest: ProfilePatchRequest, ): Response } diff --git a/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepository.kt b/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepository.kt index 690c1acc..c8f97e67 100644 --- a/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepository.kt +++ b/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepository.kt @@ -1,13 +1,11 @@ package com.project.meongcare.info.model.data.repository -import com.project.meongcare.home.model.entities.DogProfile import com.project.meongcare.home.model.entities.GetDogListResponse import com.project.meongcare.home.model.entities.GetUserProfileResponse import com.project.meongcare.info.model.entities.DogPutRequest import com.project.meongcare.info.model.entities.GetDogInfoResponse +import com.project.meongcare.info.model.entities.ProfilePatchRequest import com.project.meongcare.weight.model.entities.WeightPostRequest -import okhttp3.MultipartBody -import okhttp3.RequestBody import retrofit2.Response interface ProfileRepository { @@ -54,6 +52,6 @@ interface ProfileRepository { suspend fun patchProfileImage( accessToken: String, - file: MultipartBody.Part, + profilePatchRequest: ProfilePatchRequest, ): Int? } diff --git a/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepositoryImpl.kt b/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepositoryImpl.kt index cfee1391..9842faa7 100644 --- a/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepositoryImpl.kt +++ b/app/src/main/java/com/project/meongcare/info/model/data/repository/ProfileRepositoryImpl.kt @@ -1,15 +1,13 @@ package com.project.meongcare.info.model.data.repository import android.util.Log -import com.project.meongcare.home.model.entities.DogProfile import com.project.meongcare.home.model.entities.GetDogListResponse import com.project.meongcare.home.model.entities.GetUserProfileResponse import com.project.meongcare.info.model.data.remote.ProfileRetrofitClient import com.project.meongcare.info.model.entities.DogPutRequest import com.project.meongcare.info.model.entities.GetDogInfoResponse +import com.project.meongcare.info.model.entities.ProfilePatchRequest import com.project.meongcare.weight.model.entities.WeightPostRequest -import okhttp3.MultipartBody -import okhttp3.RequestBody import retrofit2.Response import javax.inject.Inject @@ -199,10 +197,10 @@ class ProfileRepositoryImpl override suspend fun patchProfileImage( accessToken: String, - file: MultipartBody.Part, + profilePatchRequest: ProfilePatchRequest, ): Int? { return try { - val response = profileRetrofitClient.profileApi.patchProfileImage(accessToken, file) + val response = profileRetrofitClient.profileApi.patchProfileImage(accessToken, profilePatchRequest) if (response.code() == 200) { Log.d("ProfileRepo-PatchProfile", "통신 성공") response.code() diff --git a/app/src/main/java/com/project/meongcare/info/viewmodel/ProfileViewModel.kt b/app/src/main/java/com/project/meongcare/info/viewmodel/ProfileViewModel.kt index f1196056..13206595 100644 --- a/app/src/main/java/com/project/meongcare/info/viewmodel/ProfileViewModel.kt +++ b/app/src/main/java/com/project/meongcare/info/viewmodel/ProfileViewModel.kt @@ -10,11 +10,10 @@ import com.project.meongcare.home.model.entities.GetUserProfileResponse import com.project.meongcare.info.model.data.repository.ProfileRepository import com.project.meongcare.info.model.entities.DogPutRequest import com.project.meongcare.info.model.entities.GetDogInfoResponse +import com.project.meongcare.info.model.entities.ProfilePatchRequest import com.project.meongcare.weight.model.entities.WeightPostRequest import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch -import okhttp3.MultipartBody -import okhttp3.RequestBody import retrofit2.Response import javax.inject.Inject @@ -165,10 +164,10 @@ class ProfileViewModel fun patchProfileImage( accessToken: String, - file: MultipartBody.Part, + profilePatchRequest: ProfilePatchRequest, ) { viewModelScope.launch { - _patchProfileResponse.value = profileRepository.patchProfileImage(accessToken, file) + _patchProfileResponse.value = profileRepository.patchProfileImage(accessToken, profilePatchRequest) } } } From 626c55dd99abdc534682118a57743f2c0d9c2b50 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 01:28:37 +0900 Subject: [PATCH 097/119] =?UTF-8?q?fix:=20ProfileFragment=EC=9D=98=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=ED=95=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20Pat?= =?UTF-8?q?ch=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/info/view/ProfileFragment.kt | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt index f37549da..8a6d04d2 100644 --- a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt @@ -18,27 +18,31 @@ import com.google.android.gms.auth.api.signin.GoogleSignInOptions import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.kakao.sdk.user.UserApiClient import com.navercorp.nid.NaverIdLoginSDK +import com.project.meongcare.BuildConfig import com.project.meongcare.R +import com.project.meongcare.aws.util.AWSS3ImageUtils.convertUriToFile import com.project.meongcare.aws.util.MEMBER_FOLDER_PATH import com.project.meongcare.aws.util.PARENT_FOLDER_PATH import com.project.meongcare.aws.viewmodel.AWSS3ViewModel import com.project.meongcare.databinding.FragmentProfileBinding import com.project.meongcare.databinding.LayoutLogoutDialogBinding import com.project.meongcare.databinding.LayoutMedicalRecordDialogBinding -import com.project.meongcare.aws.util.AWSS3ImageUtils.createMultipartFromUri -import com.project.meongcare.aws.util.AWSS3ImageUtils.getMultipartFileName +import com.project.meongcare.info.model.entities.ProfilePatchRequest import com.project.meongcare.info.viewmodel.ProfileViewModel import com.project.meongcare.medicalrecord.viewmodel.UserViewModel import com.project.meongcare.onboarding.model.data.local.PhotoMenuListener import com.project.meongcare.snackbar.view.CustomSnackBar import dagger.hilt.android.AndroidEntryPoint -import okhttp3.MultipartBody +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.asRequestBody +import java.io.File @AndroidEntryPoint class ProfileFragment : Fragment(), PhotoMenuListener { private lateinit var binding: FragmentProfileBinding - private lateinit var multipartImage: MultipartBody.Part - private lateinit var fileName: String + private lateinit var imageFile: File + private lateinit var filePath: String private val profileViewModel: ProfileViewModel by viewModels() private val awsS3ViewModel: AWSS3ViewModel by viewModels() @@ -153,19 +157,6 @@ class ProfileFragment : Fragment(), PhotoMenuListener { } } - awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> - if (response != null) { - awsS3ViewModel.uploadImageToS3(response.preSignedUrl, multipartImage) - } - } - - awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> - if (response == 200) { - // 저장된 이미지 경로를 데이터와 함께 서버로 전달 - // profileViewModel.patchProfileImage(currentAccessToken, multipartBody) - } - } - initPetListRecyclerView() initProfileImageView() initBackButton() @@ -175,11 +166,29 @@ class ProfileFragment : Fragment(), PhotoMenuListener { } override fun onUriPassed(uri: Uri) { - multipartImage = createMultipartFromUri(requireContext(), uri) - fileName = getMultipartFileName(multipartImage) + imageFile = convertUriToFile(requireContext(), uri) + filePath = "$PARENT_FOLDER_PATH$MEMBER_FOLDER_PATH${imageFile.name}" + getPreSignedURL() + } - val filePath = "$PARENT_FOLDER_PATH$MEMBER_FOLDER_PATH$fileName" + private fun getPreSignedURL() { awsS3ViewModel.getPreSignedUrl(currentAccessToken, filePath) + awsS3ViewModel.preSignedUrl.observe(viewLifecycleOwner) { response -> + if (response != null) { + val requestBody = imageFile.asRequestBody("image/*".toMediaTypeOrNull()) + uploadImage(response.preSignedUrl, requestBody) + } + } + } + + private fun uploadImage(preSignedURL: String, requestBody: RequestBody) { + awsS3ViewModel.uploadImageToS3(preSignedURL, requestBody) + awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> + if (response == 200) { + val profilePatchRequest = ProfilePatchRequest(BuildConfig.AWS_S3_BASE_URL + filePath) + profileViewModel.patchProfileImage(currentAccessToken, profilePatchRequest) + } + } } private fun reissueAccessToken() { From e1269fc8fae987a16dec5c481cd392571750ef8d Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 01:29:41 +0900 Subject: [PATCH 098/119] =?UTF-8?q?remove:=20AWSS3ImageUtils=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20import=EB=AC=B8=20?= =?UTF-8?q?=EB=B0=8F=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/aws/util/AWSS3ImageUtils.kt | 54 ------------------- 1 file changed, 54 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt b/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt index fa24ac69..a94229a3 100644 --- a/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt +++ b/app/src/main/java/com/project/meongcare/aws/util/AWSS3ImageUtils.kt @@ -2,15 +2,8 @@ package com.project.meongcare.aws.util import android.content.Context import android.net.Uri -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext -import okhttp3.MediaType.Companion.toMediaTypeOrNull -import okhttp3.MultipartBody -import okhttp3.RequestBody.Companion.asRequestBody -import okhttp3.RequestBody.Companion.toRequestBody import java.io.File import java.io.FileOutputStream -import java.net.URL import java.util.UUID object AWSS3ImageUtils { @@ -18,26 +11,6 @@ object AWSS3ImageUtils { return UUID.randomUUID().toString() } - fun createMultipartFromUri( - context: Context, - uri: Uri?, - ): MultipartBody.Part { - if (uri != null) { - val inputStream = context.contentResolver.openInputStream(uri) - val file = File(context.cacheDir, createUUID()) - inputStream.use { input -> - file.outputStream().use { output -> - input?.copyTo(output) - } - } - val requestFile = file.asRequestBody("multipart/form-data".toMediaTypeOrNull()) - - return MultipartBody.Part.createFormData("file", file.name, requestFile) - } - val emptyBody = "".toRequestBody("multipart/form-data".toMediaTypeOrNull()) - return MultipartBody.Part.createFormData("file", "", emptyBody) - } - fun convertUriToFile( context: Context, uri: Uri, @@ -54,31 +27,4 @@ object AWSS3ImageUtils { return file } - - suspend fun createMultipartFromUrl( - context: Context, - url: String? - ): MultipartBody.Part { - return withContext(Dispatchers.IO) { - if (url.isNullOrEmpty()) { - val emptyBody = "".toRequestBody("multipart/form-data".toMediaTypeOrNull()) - MultipartBody.Part.createFormData("file", "", emptyBody) - } else { - val inputStream = URL(url).openStream() - val file = File(context.cacheDir, createUUID()) - inputStream.use { input -> - file.outputStream().use { output -> - input.copyTo(output) - } - } - val requestFile = file.asRequestBody("multipart/form-data".toMediaTypeOrNull()) - MultipartBody.Part.createFormData("file", file.name, requestFile) - } - } - } - - fun getMultipartFileName(file: MultipartBody.Part): String { - val disposition = file.headers?.get("Content-Disposition") - return disposition?.substringAfterLast("filename=")?.removeSurrounding("\"") ?: "tempFile" - } } From f9261e3c2c4407b1f84c26654f489040d7de1f05 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 01:30:01 +0900 Subject: [PATCH 099/119] =?UTF-8?q?remove:=20ExcretaInfoUtils=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20import=EB=AC=B8=20?= =?UTF-8?q?=EB=B0=8F=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excreta/utils/ExcretaInfoUtils.kt | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/excreta/utils/ExcretaInfoUtils.kt b/app/src/main/java/com/project/meongcare/excreta/utils/ExcretaInfoUtils.kt index 9eb7cb3a..51f646af 100644 --- a/app/src/main/java/com/project/meongcare/excreta/utils/ExcretaInfoUtils.kt +++ b/app/src/main/java/com/project/meongcare/excreta/utils/ExcretaInfoUtils.kt @@ -1,41 +1,10 @@ package com.project.meongcare.excreta.utils -import android.content.Context -import android.net.Uri import android.view.View -import com.google.gson.Gson import com.project.meongcare.R import com.project.meongcare.snackbar.view.CustomSnackBar -import okhttp3.MediaType.Companion.toMediaTypeOrNull -import okhttp3.MultipartBody -import okhttp3.RequestBody -import okhttp3.RequestBody.Companion.asRequestBody -import okhttp3.RequestBody.Companion.toRequestBody -import java.io.File object ExcretaInfoUtils { - fun convertExcretaFile( - context: Context, - uri: Uri, - ): MultipartBody.Part { - if (uri.toString().isEmpty()) { - val emptyFile = "".toRequestBody("multipart/form-data".toMediaTypeOrNull()) - return MultipartBody.Part.createFormData("file", "", emptyFile) - } - - // Uri로부터 InputStream을 얻고, 임시 파일로 복사 - val inputStream = context.contentResolver.openInputStream(uri) - val file = File(context.cacheDir, "tempFile") - inputStream.use { input -> - file.outputStream().use { output -> - input?.copyTo(output) - } - } - val requestFile = file.asRequestBody("multipart/form-data".toMediaTypeOrNull()) - - return MultipartBody.Part.createFormData("file", file.name, requestFile) - } - fun showSuccessSnackBar( view: View, message: String, From 53717a14224cfd964ffb624c91a8eb07b728bae9 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 01:30:23 +0900 Subject: [PATCH 100/119] =?UTF-8?q?remove:=20FeedPostViewModel=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20import=EB=AC=B8=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/meongcare/feed/viewmodel/FeedPostViewModel.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPostViewModel.kt b/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPostViewModel.kt index 030df9f9..31af1b01 100644 --- a/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPostViewModel.kt +++ b/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPostViewModel.kt @@ -6,7 +6,6 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.project.meongcare.feed.model.data.repository.FeedRepositoryImpl import com.project.meongcare.feed.model.entities.FeedPostRequest -import com.project.meongcare.feed.model.entities.FeedUploadRequest import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import javax.inject.Inject From 20547fc043f95a687d16635eec2c396fc1829c78 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 01:30:38 +0900 Subject: [PATCH 101/119] =?UTF-8?q?remove:=20FeedPutViewModel=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20import=EB=AC=B8=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/meongcare/feed/viewmodel/FeedPutViewModel.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPutViewModel.kt b/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPutViewModel.kt index 19719da5..bd2ca1b2 100644 --- a/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPutViewModel.kt +++ b/app/src/main/java/com/project/meongcare/feed/viewmodel/FeedPutViewModel.kt @@ -6,7 +6,6 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.project.meongcare.feed.model.data.repository.FeedRepositoryImpl import com.project.meongcare.feed.model.entities.FeedPutRequest -import com.project.meongcare.feed.model.entities.FeedUploadRequest import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import javax.inject.Inject From b5ed291a074a51ec758eb3da33138b9c3f565a12 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 01:30:56 +0900 Subject: [PATCH 102/119] =?UTF-8?q?remove:=20SettingFragment=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20import=EB=AC=B8=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/info/view/SettingFragment.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/SettingFragment.kt b/app/src/main/java/com/project/meongcare/info/view/SettingFragment.kt index 79b52a1c..320097d5 100644 --- a/app/src/main/java/com/project/meongcare/info/view/SettingFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/SettingFragment.kt @@ -1,15 +1,10 @@ package com.project.meongcare.info.view -import android.content.Context import android.os.Bundle import android.util.Log -import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.ImageView -import android.widget.LinearLayout -import android.widget.TextView import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels From 6ceab0bd06e9ae09b832c8519e4e4b1b234385a8 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 01:31:17 +0900 Subject: [PATCH 103/119] =?UTF-8?q?remove:=20DogAddViewModel=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20import=EB=AC=B8=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/meongcare/onboarding/viewmodel/DogAddViewModel.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/viewmodel/DogAddViewModel.kt b/app/src/main/java/com/project/meongcare/onboarding/viewmodel/DogAddViewModel.kt index 62d6b81a..83f6f6d3 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/viewmodel/DogAddViewModel.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/viewmodel/DogAddViewModel.kt @@ -9,8 +9,6 @@ import com.project.meongcare.onboarding.model.data.repository.DogAddRepository import com.project.meongcare.onboarding.model.entities.DogPostRequest import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch -import okhttp3.MultipartBody -import okhttp3.RequestBody import javax.inject.Inject @HiltViewModel From 3d5f69406e1339b2ad38cdccab9401fa0e8ffca6 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 01:31:56 +0900 Subject: [PATCH 104/119] =?UTF-8?q?remove:=20ExcretaUploadRequest=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excreta/model/entities/ExcretaUploadRequest.kt | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaUploadRequest.kt diff --git a/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaUploadRequest.kt b/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaUploadRequest.kt deleted file mode 100644 index cb3b0dda..00000000 --- a/app/src/main/java/com/project/meongcare/excreta/model/entities/ExcretaUploadRequest.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.project.meongcare.excreta.model.entities - -import okhttp3.MultipartBody -import okhttp3.RequestBody - -data class ExcretaUploadRequest( - val dto: RequestBody, - val file: MultipartBody.Part, -) From d67cf1b66a145d2368f58a5a4a7c96fb68031b19 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 01:32:09 +0900 Subject: [PATCH 105/119] =?UTF-8?q?remove:=20FeedUploadRequest=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/feed/model/entities/FeedUploadRequest.kt | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 app/src/main/java/com/project/meongcare/feed/model/entities/FeedUploadRequest.kt diff --git a/app/src/main/java/com/project/meongcare/feed/model/entities/FeedUploadRequest.kt b/app/src/main/java/com/project/meongcare/feed/model/entities/FeedUploadRequest.kt deleted file mode 100644 index 37baaca1..00000000 --- a/app/src/main/java/com/project/meongcare/feed/model/entities/FeedUploadRequest.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.project.meongcare.feed.model.entities - -import okhttp3.MultipartBody -import okhttp3.RequestBody - -data class FeedUploadRequest( - val dto: RequestBody, - val file: MultipartBody.Part, -) From 9089d6517389edae7a1beb6cc2f36bae56fa19aa Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 02:56:04 +0900 Subject: [PATCH 106/119] =?UTF-8?q?refactor:=20ExcretaRepositoryImpl=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=ED=95=A8=EC=88=98=20=EC=9D=B8?= =?UTF-8?q?=EC=9E=90=20=EB=81=9D=20=EC=BD=A4=EB=A7=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excreta/model/data/repository/ExcretaRepositoryImpl.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepositoryImpl.kt b/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepositoryImpl.kt index 5fab8af0..c85c0d72 100644 --- a/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepositoryImpl.kt +++ b/app/src/main/java/com/project/meongcare/excreta/model/data/repository/ExcretaRepositoryImpl.kt @@ -13,7 +13,7 @@ class ExcretaRepositoryImpl ) : ExcretaRepository { override suspend fun postExcreta( accessToken: String, - excretaPostRequest: ExcretaPostRequest + excretaPostRequest: ExcretaPostRequest, ): Int? = excretaRemoteDataSource.postExcreta(accessToken, excretaPostRequest) override suspend fun getExcretaRecord( @@ -33,6 +33,6 @@ class ExcretaRepositoryImpl override suspend fun patchExcreta( accessToken: String, - excretaPatchRequest: ExcretaPatchRequest + excretaPatchRequest: ExcretaPatchRequest, ): Int? = excretaRemoteDataSource.patchExcreta(accessToken, excretaPatchRequest) } From a37bc1c6046b3c1e9c9bdbaf538cf39aedfb4200 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 02:56:44 +0900 Subject: [PATCH 107/119] =?UTF-8?q?refactor:=20ExcretaAddFragment=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20uploadImage=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B8=EC=9E=90=20=EA=B0=9C=ED=96=89=20=EB=B0=8F?= =?UTF-8?q?=20=EC=BD=A4=EB=A7=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/meongcare/excreta/view/ExcretaAddFragment.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt index b9453713..600b1394 100644 --- a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt +++ b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaAddFragment.kt @@ -190,7 +190,10 @@ class ExcretaAddFragment : Fragment(), DateSubmitListener, PhotoListener { } } - private fun uploadImage(preSignedUrl: String, requestBody: RequestBody) { + private fun uploadImage( + preSignedUrl: String, + requestBody: RequestBody, + ) { awsS3ViewModel.uploadImageToS3(preSignedUrl, requestBody) awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { From 83bc2624979a3e1c9f1da0075841ca43dd4d15ea Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 02:57:03 +0900 Subject: [PATCH 108/119] =?UTF-8?q?refactor:=20ExcretaEditFragment=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20uploadImage=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B8=EC=9E=90=20=EA=B0=9C=ED=96=89=20=EB=B0=8F?= =?UTF-8?q?=20=EC=BD=A4=EB=A7=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/meongcare/excreta/view/ExcretaEditFragment.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaEditFragment.kt b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaEditFragment.kt index 99154f54..e6578c19 100644 --- a/app/src/main/java/com/project/meongcare/excreta/view/ExcretaEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/excreta/view/ExcretaEditFragment.kt @@ -226,7 +226,10 @@ class ExcretaEditFragment : Fragment(), DateSubmitListener, PhotoListener { } } - private fun uploadImage(preSignedUrl: String, requestBody: RequestBody) { + private fun uploadImage( + preSignedUrl: String, + requestBody: RequestBody, + ) { awsS3ViewModel.uploadImageToS3(preSignedUrl, requestBody) awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { From ba6d90da301d93ebc9305269d536218da6b387ca Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 02:57:19 +0900 Subject: [PATCH 109/119] =?UTF-8?q?refactor:=20FeedEditFragment=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20uploadImage=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B8=EC=9E=90=20=EA=B0=9C=ED=96=89=20=EB=B0=8F?= =?UTF-8?q?=20=EC=BD=A4=EB=A7=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/feed/view/FeedEditFragment.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt b/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt index c8a6ce8f..060f23a8 100644 --- a/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/feed/view/FeedEditFragment.kt @@ -526,7 +526,10 @@ class FeedEditFragment : Fragment(), FeedPhotoListener { } } - private fun uploadImage(preSignedUrl: String, requestBody: RequestBody) { + private fun uploadImage( + preSignedUrl: String, + requestBody: RequestBody, + ) { awsS3ViewModel.uploadImageToS3(preSignedUrl, requestBody) awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { From c38a5cacd9ce57f3b1df49cb4f1792a4d6806926 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 02:57:46 +0900 Subject: [PATCH 110/119] =?UTF-8?q?refactor:=20ProfilePatchRequest=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=A7=88=EC=A7=80=EB=A7=89=20?= =?UTF-8?q?=EC=A4=84=20=EA=B0=9C=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/info/model/entities/ProfilePatchRequest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/info/model/entities/ProfilePatchRequest.kt b/app/src/main/java/com/project/meongcare/info/model/entities/ProfilePatchRequest.kt index 7fd4f176..eecdfa90 100644 --- a/app/src/main/java/com/project/meongcare/info/model/entities/ProfilePatchRequest.kt +++ b/app/src/main/java/com/project/meongcare/info/model/entities/ProfilePatchRequest.kt @@ -2,4 +2,4 @@ package com.project.meongcare.info.model.entities data class ProfilePatchRequest( val imageURL: String?, -) \ No newline at end of file +) From ecfcc27d25accc1fb6633aa7a45492fc67112929 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 02:58:19 +0900 Subject: [PATCH 111/119] =?UTF-8?q?refactor:=20PetEditFragment=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20uploadImage=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EC=9D=B8=EC=9E=90=20=EA=B0=9C=ED=96=89=20=EB=B0=8F=20?= =?UTF-8?q?=EC=BD=A4=EB=A7=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/info/view/PetEditFragment.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt index d06ac2ac..4a013baa 100644 --- a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt @@ -325,7 +325,10 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { } } - private fun uploadImage(preSignedURL: String, requestBody: RequestBody) { + private fun uploadImage( + preSignedURL: String, + requestBody: RequestBody, + ) { awsS3ViewModel.uploadImageToS3(preSignedURL, requestBody) awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { From a8bb53138f6fc03d58692f6bfc0488c980d5f24c Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 02:59:05 +0900 Subject: [PATCH 112/119] =?UTF-8?q?refactor:=20PetEditFragment=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=A3=BC=EC=84=9D=20=EC=95=9E=20=EA=B3=B5?= =?UTF-8?q?=EB=B0=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/info/view/PetEditFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt index 4a013baa..9ca460a1 100644 --- a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt @@ -305,7 +305,7 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { return@setOnClickListener } - if (isImageUpdated) {// 새 이미지 등록 + if (isImageUpdated) { // 새 이미지 등록 getPreSignedURL(petEditViewModel.dogProfile.value!!) } else { // 기존 이미지 putDogInfo(dogInfo.imageUrl) From 916e7340f8f6b6df8e1087b097c7fd0c06312bd6 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 02:59:30 +0900 Subject: [PATCH 113/119] =?UTF-8?q?refactor:=20PetEditFragment=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20onViewCreated=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B8=EC=9E=90=20=EA=B0=9C=ED=96=89=20=EB=B0=8F?= =?UTF-8?q?=20=EC=BD=A4=EB=A7=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/info/view/PetEditFragment.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt index 9ca460a1..aa7f41f7 100644 --- a/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/PetEditFragment.kt @@ -76,7 +76,10 @@ class PetEditFragment : Fragment(), PhotoMenuListener, DateSubmitListener { return binding.root } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + override fun onViewCreated( + view: View, + savedInstanceState: Bundle?, + ) { super.onViewCreated(view, savedInstanceState) if (!isInitialized) { From 2fb6b19f8d1596a663a21cd57379f72de9566b8f Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 02:59:46 +0900 Subject: [PATCH 114/119] =?UTF-8?q?refactor:=20ProfileFragment=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20uploadImage=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EC=9D=B8=EC=9E=90=20=EA=B0=9C=ED=96=89=20=EB=B0=8F=20?= =?UTF-8?q?=EC=BD=A4=EB=A7=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/info/view/ProfileFragment.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt index 995bc5c3..f76bd156 100644 --- a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt @@ -181,7 +181,10 @@ class ProfileFragment : Fragment(), PhotoMenuListener { } } - private fun uploadImage(preSignedURL: String, requestBody: RequestBody) { + private fun uploadImage( + preSignedURL: String, + requestBody: RequestBody, + ) { awsS3ViewModel.uploadImageToS3(preSignedURL, requestBody) awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { From f9eeef3da4e00a7f47040aae0d0fe17021206fd6 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 03:00:06 +0900 Subject: [PATCH 115/119] =?UTF-8?q?refactor:=20ProfileFragment=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20onViewCreated=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B8=EC=9E=90=20=EA=B0=9C=ED=96=89=20=EB=B0=8F?= =?UTF-8?q?=20=EC=BD=A4=EB=A7=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/info/view/ProfileFragment.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt index f76bd156..210fe88e 100644 --- a/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt +++ b/app/src/main/java/com/project/meongcare/info/view/ProfileFragment.kt @@ -61,7 +61,10 @@ class ProfileFragment : Fragment(), PhotoMenuListener { return binding.root } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + override fun onViewCreated( + view: View, + savedInstanceState: Bundle?, + ) { super.onViewCreated(view, savedInstanceState) getAccessToken() From 6b06d4a6c1643e11aa5a1c3aa0817ef9935e9706 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 03:00:22 +0900 Subject: [PATCH 116/119] =?UTF-8?q?refactor:=20LoginFragment=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20onViewCreated=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B8=EC=9E=90=20=EA=B0=9C=ED=96=89=20=EB=B0=8F?= =?UTF-8?q?=20=EC=BD=A4=EB=A7=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/project/meongcare/login/view/LoginFragment.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt b/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt index 4ef3a1ae..8d68a1a9 100644 --- a/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt +++ b/app/src/main/java/com/project/meongcare/login/view/LoginFragment.kt @@ -59,7 +59,10 @@ class LoginFragment : Fragment() { return binding.root } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + override fun onViewCreated( + view: View, + savedInstanceState: Bundle?, + ) { super.onViewCreated(view, savedInstanceState) getProvider() From 5bd9084798a8eb1145d243e5ee19dce94a31ed2a Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 03:00:40 +0900 Subject: [PATCH 117/119] =?UTF-8?q?refactor:=20DogAddOnBoardingFragment=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20onViewCreated=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=9D=B8=EC=9E=90=20=EA=B0=9C=ED=96=89=20?= =?UTF-8?q?=EB=B0=8F=20=EC=BD=A4=EB=A7=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/onboarding/view/DogAddOnBoardingFragment.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt index af34f74a..891d293c 100644 --- a/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt +++ b/app/src/main/java/com/project/meongcare/onboarding/view/DogAddOnBoardingFragment.kt @@ -65,7 +65,10 @@ class DogAddOnBoardingFragment : Fragment(), PhotoMenuListener, DateSubmitListen return binding.root } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + override fun onViewCreated( + view: View, + savedInstanceState: Bundle?, + ) { super.onViewCreated(view, savedInstanceState) getAccessToken() From 4a8bee8a2d414fb4ba24ea0d6ceef0d7c3d2db01 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 03:00:58 +0900 Subject: [PATCH 118/119] =?UTF-8?q?refactor:=20SupplementAddFragment=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20uploadImage=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B8=EC=9E=90=20=EA=B0=9C=ED=96=89=20=EB=B0=8F?= =?UTF-8?q?=20=EC=BD=A4=EB=A7=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meongcare/supplement/view/SupplementAddFragment.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt b/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt index 74a4716d..829fb94c 100644 --- a/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt +++ b/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt @@ -392,7 +392,10 @@ class SupplementAddFragment : Fragment(), OnPictureChangedListener { } } - private fun uploadImage(preSignedUrl: String, requestBody: RequestBody) { + private fun uploadImage( + preSignedUrl: String, + requestBody: RequestBody, + ) { awsS3ViewModel.uploadImageToS3(preSignedUrl, requestBody) awsS3ViewModel.uploadImageResponse.observe(viewLifecycleOwner) { response -> if (response == 200) { From 72b40c4c27c311b53a164fa08cc700208bf9aeb6 Mon Sep 17 00:00:00 2001 From: "lge6716@gmail.com" Date: Wed, 10 Apr 2024 03:01:56 +0900 Subject: [PATCH 119/119] =?UTF-8?q?refactor:=20SupplementAddFragment=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20addSupplement=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=ED=98=B8=EC=B6=9C=20=EA=B5=AC=EB=AC=B8=20?= =?UTF-8?q?=EB=A7=A4=EA=B0=9C=EB=B3=80=EC=88=98=20=EB=81=9D=20=EC=BD=A4?= =?UTF-8?q?=EB=A7=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/meongcare/supplement/view/SupplementAddFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt b/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt index 829fb94c..6f52da78 100644 --- a/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt +++ b/app/src/main/java/com/project/meongcare/supplement/view/SupplementAddFragment.kt @@ -408,7 +408,7 @@ class SupplementAddFragment : Fragment(), OnPictureChangedListener { private fun postSupplement(imageURL: String?) { supplementViewModel.addSupplement( accessToken, - createSupplementInfo(imageURL) + createSupplementInfo(imageURL), ) }