From 45f9c585d17be7f0dc68caaac3d0c0b37a07026a Mon Sep 17 00:00:00 2001 From: algosketch Date: Thu, 16 Nov 2023 18:59:49 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat=20:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=84=A0=ED=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/ui/src/main/res/values/strings.xml | 1 + android/feature/upload/build.gradle.kts | 2 +- .../feature/upload/UploadFragment.kt | 21 +++++++++++++++++++ .../feature/upload/UploadViewModel.kt | 14 ++++++++++++- .../src/main/res/layout/fragment_upload.xml | 20 +++++++++++++----- .../main/res/navigation/upload_navigation.xml | 2 +- 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/android/core/ui/src/main/res/values/strings.xml b/android/core/ui/src/main/res/values/strings.xml index 3b7ce4d..728f6f0 100644 --- a/android/core/ui/src/main/res/values/strings.xml +++ b/android/core/ui/src/main/res/values/strings.xml @@ -33,6 +33,7 @@ 제목 장르 설명 + 썸네일 이미지 선택 구글계정으로 로그인 diff --git a/android/feature/upload/build.gradle.kts b/android/feature/upload/build.gradle.kts index 8abb5f4..57fd99a 100644 --- a/android/feature/upload/build.gradle.kts +++ b/android/feature/upload/build.gradle.kts @@ -27,5 +27,5 @@ android { } dependencies { - + implementation(libs.appcompat) } \ No newline at end of file diff --git a/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadFragment.kt b/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadFragment.kt index e7908f7..22f0441 100644 --- a/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadFragment.kt +++ b/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadFragment.kt @@ -2,16 +2,37 @@ package com.ohdodok.catchytape.feature.upload import android.os.Bundle import android.view.View +import androidx.activity.result.PickVisualMediaRequest +import androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia +import androidx.core.net.toFile import androidx.fragment.app.viewModels import com.ohdodok.catchytape.catchytape.upload.R import com.ohdodok.catchytape.catchytape.upload.databinding.FragmentUploadBinding import com.ohdodok.catchytape.core.ui.BaseFragment +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class UploadFragment : BaseFragment(R.layout.fragment_upload) { private val viewModel: UploadViewModel by viewModels() + private val pickMedia by lazy { + registerForActivityResult(PickVisualMedia()) { uri -> + if (uri == null) return@registerForActivityResult + + viewModel.uploadImage(uri.toFile()) + } + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.viewModel = viewModel + + setupSelectThumbnailImage() + } + + private fun setupSelectThumbnailImage() { + binding.cvUploadThumbnail.setOnClickListener { + pickMedia.launch(PickVisualMediaRequest(PickVisualMedia.ImageOnly)) + } } } \ No newline at end of file diff --git a/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt b/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt index 8bea415..a145edc 100644 --- a/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt +++ b/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt @@ -1,7 +1,19 @@ package com.ohdodok.catchytape.feature.upload import androidx.lifecycle.ViewModel +import dagger.hilt.android.lifecycle.HiltViewModel +import java.io.File +import javax.inject.Inject -class UploadViewModel : ViewModel() { +@HiltViewModel +class UploadViewModel @Inject constructor( +) : ViewModel() { + + private var uploadedImage: String? = null + + fun uploadImage(imageFile: File) { + // todo : image 파일을 업로드 한다. + // todo : 반환 값을 uploadedImage에 저장한다. + } } \ No newline at end of file diff --git a/android/feature/upload/src/main/res/layout/fragment_upload.xml b/android/feature/upload/src/main/res/layout/fragment_upload.xml index 48e734e..55f5ded 100644 --- a/android/feature/upload/src/main/res/layout/fragment_upload.xml +++ b/android/feature/upload/src/main/res/layout/fragment_upload.xml @@ -44,17 +44,27 @@ android:layout_marginTop="@dimen/extra_large" app:cardBackgroundColor="@color/on_surface_variant" app:cardCornerRadius="20dp" + app:cardElevation="0dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/tb_upload_appbar"> + app:layout_constraintTop_toBottomOf="@id/tb_upload_appbar" + android:contentDescription="@string/select_thumbnail"> - + + + android:src="@drawable/ic_camera" + android:importantForAccessibility="no"/> diff --git a/android/feature/upload/src/main/res/navigation/upload_navigation.xml b/android/feature/upload/src/main/res/navigation/upload_navigation.xml index fe8649a..c21d37d 100644 --- a/android/feature/upload/src/main/res/navigation/upload_navigation.xml +++ b/android/feature/upload/src/main/res/navigation/upload_navigation.xml @@ -2,7 +2,7 @@ Date: Thu, 16 Nov 2023 20:33:11 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat=20:=20=EC=98=A4=EB=94=94=EC=98=A4=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=84=A0=ED=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../res/navigation/catchytape_navigation.xml | 3 ++- .../catchytape/feature/upload/UploadFragment.kt | 17 +++++++++++------ .../feature/upload/UploadViewModel.kt | 4 ++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/android/app/src/main/res/navigation/catchytape_navigation.xml b/android/app/src/main/res/navigation/catchytape_navigation.xml index 342d242..38bf13a 100644 --- a/android/app/src/main/res/navigation/catchytape_navigation.xml +++ b/android/app/src/main/res/navigation/catchytape_navigation.xml @@ -2,9 +2,10 @@ + app:startDestination="@id/upload_nav_graph"> + \ No newline at end of file diff --git a/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadFragment.kt b/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadFragment.kt index 22f0441..c8dd861 100644 --- a/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadFragment.kt +++ b/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadFragment.kt @@ -2,7 +2,7 @@ package com.ohdodok.catchytape.feature.upload import android.os.Bundle import android.view.View -import androidx.activity.result.PickVisualMediaRequest +import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia import androidx.core.net.toFile import androidx.fragment.app.viewModels @@ -15,13 +15,18 @@ import dagger.hilt.android.AndroidEntryPoint class UploadFragment : BaseFragment(R.layout.fragment_upload) { private val viewModel: UploadViewModel by viewModels() - private val pickMedia by lazy { - registerForActivityResult(PickVisualMedia()) { uri -> + private val pickMedia = registerForActivityResult(PickVisualMedia()) { uri -> + if (uri == null) return@registerForActivityResult + + viewModel.uploadImage(uri.toFile()) + } + + private val filePickerLauncher = + registerForActivityResult(ActivityResultContracts.GetContent()) { uri -> if (uri == null) return@registerForActivityResult - viewModel.uploadImage(uri.toFile()) + viewModel.uploadAudio(uri.toFile()) } - } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -32,7 +37,7 @@ class UploadFragment : BaseFragment(R.layout.fragment_upl private fun setupSelectThumbnailImage() { binding.cvUploadThumbnail.setOnClickListener { - pickMedia.launch(PickVisualMediaRequest(PickVisualMedia.ImageOnly)) + filePickerLauncher.launch("audio/*") } } } \ No newline at end of file diff --git a/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt b/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt index a145edc..5e9c656 100644 --- a/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt +++ b/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt @@ -16,4 +16,8 @@ class UploadViewModel @Inject constructor( // todo : image 파일을 업로드 한다. // todo : 반환 값을 uploadedImage에 저장한다. } + + fun uploadAudio(audioFile: File) { + // todo : audio 파일을 업로드 한다. + } } \ No newline at end of file From d7e3f92231b3585c775f5815bd9a44b280558f4a Mon Sep 17 00:00:00 2001 From: algosketch Date: Thu, 16 Nov 2023 21:12:22 +0900 Subject: [PATCH 3/5] =?UTF-8?q?fix=20:=20=EC=BD=94=EB=93=9C=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=B0=98=EC=98=81(filePicker=ED=98=B8=EC=B6=9C,=20?= =?UTF-8?q?launcher=20=EC=9D=B4=EB=A6=84=20=ED=86=B5=EC=9D=BC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ohdodok/catchytape/feature/upload/UploadFragment.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadFragment.kt b/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadFragment.kt index c8dd861..a82a864 100644 --- a/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadFragment.kt +++ b/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadFragment.kt @@ -2,6 +2,7 @@ package com.ohdodok.catchytape.feature.upload import android.os.Bundle import android.view.View +import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia import androidx.core.net.toFile @@ -15,7 +16,7 @@ import dagger.hilt.android.AndroidEntryPoint class UploadFragment : BaseFragment(R.layout.fragment_upload) { private val viewModel: UploadViewModel by viewModels() - private val pickMedia = registerForActivityResult(PickVisualMedia()) { uri -> + private val imagePickerLauncher = registerForActivityResult(PickVisualMedia()) { uri -> if (uri == null) return@registerForActivityResult viewModel.uploadImage(uri.toFile()) @@ -37,7 +38,7 @@ class UploadFragment : BaseFragment(R.layout.fragment_upl private fun setupSelectThumbnailImage() { binding.cvUploadThumbnail.setOnClickListener { - filePickerLauncher.launch("audio/*") + imagePickerLauncher.launch(PickVisualMediaRequest(PickVisualMedia.ImageOnly)) } } } \ No newline at end of file From 657e7ac3453487c64fef922cf01a775d7001bcf1 Mon Sep 17 00:00:00 2001 From: algosketch Date: Thu, 16 Nov 2023 22:54:52 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor=20:=20upload=20navigation=20id=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 --- .../upload/src/main/res/navigation/upload_navigation.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/feature/upload/src/main/res/navigation/upload_navigation.xml b/android/feature/upload/src/main/res/navigation/upload_navigation.xml index cde0a67..c900214 100644 --- a/android/feature/upload/src/main/res/navigation/upload_navigation.xml +++ b/android/feature/upload/src/main/res/navigation/upload_navigation.xml @@ -2,7 +2,7 @@ Date: Thu, 16 Nov 2023 23:00:59 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor=20:=20=EC=97=85=EB=A1=9C=EB=93=9C?= =?UTF-8?q?=20=EA=B0=80=EB=8A=A5=20=EC=97=AC=EB=B6=80=20=ED=8C=90=EB=8B=A8?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EA=B0=84=EC=86=8C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/upload/UploadViewModel.kt | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt b/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt index 6c13ff9..2e703b5 100644 --- a/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt +++ b/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt @@ -6,9 +6,13 @@ import java.io.File import javax.inject.Inject import androidx.lifecycle.viewModelScope import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.stateIn @HiltViewModel class UploadViewModel @Inject constructor( @@ -17,33 +21,18 @@ class UploadViewModel @Inject constructor( private var uploadedImage: String? = null - val uploadedMusicTitle = MutableStateFlow("") + val uploadedMusicTitle = MutableStateFlow("") private val _uploadedMusicGenrePosition = MutableStateFlow(0) val uploadedMusicGenrePosition = _uploadedMusicGenrePosition.asStateFlow() - private val _isUploadEnable = MutableStateFlow(false) - val isUploadEnable = _isUploadEnable.asStateFlow() - - val onChangePosition: (Int) -> Unit = { position: Int -> _uploadedMusicGenrePosition.value = position } - - init { - observeMusicTitle() - observeGenrePosition() - } + val isUploadEnable: StateFlow = + combine(uploadedMusicTitle, uploadedMusicGenrePosition) { title, genrePosition -> + title.isNotBlank() && genrePosition != 0 + }.stateIn(viewModelScope, SharingStarted.Eagerly, false) - private fun observeMusicTitle() { - uploadedMusicTitle.onEach { - _isUploadEnable.value = uploadedMusicGenrePosition.value != 0 && it.isNotEmpty() - }.launchIn(viewModelScope) - } + val onChangePosition: (Int) -> Unit = { position: Int -> _uploadedMusicGenrePosition.value = position } - private fun observeGenrePosition() { - uploadedMusicGenrePosition.onEach { - _isUploadEnable.value = it != 0 && uploadedMusicTitle.value.isNotEmpty() - }.launchIn(viewModelScope) - } - fun uploadImage(imageFile: File) { // todo : image 파일을 업로드 한다. // todo : 반환 값을 uploadedImage에 저장한다.