diff --git a/android/core/ui/src/main/res/values/strings.xml b/android/core/ui/src/main/res/values/strings.xml index f1d1bcb..f03fc8d 100644 --- a/android/core/ui/src/main/res/values/strings.xml +++ b/android/core/ui/src/main/res/values/strings.xml @@ -29,4 +29,5 @@ 제목 장르 설명 + 썸네일 이미지 선택 \ No newline at end of file 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 b7ebb34..75ae687 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,17 +2,44 @@ 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 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 imagePickerLauncher = 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.uploadAudio(uri.toFile()) + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.viewModel = viewModel + setupBackStack(binding.tbUploadAppbar) + setupSelectThumbnailImage() + } + + private fun setupSelectThumbnailImage() { + binding.cvUploadThumbnail.setOnClickListener { + imagePickerLauncher.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 a361345..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 @@ -1,40 +1,44 @@ package com.ohdodok.catchytape.feature.upload import androidx.lifecycle.ViewModel +import dagger.hilt.android.lifecycle.HiltViewModel +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 -class UploadViewModel : ViewModel() { +@HiltViewModel +class UploadViewModel @Inject constructor( - val uploadedMusicTitle = MutableStateFlow("") +) : ViewModel() { + + private var uploadedImage: String? = null + + val uploadedMusicTitle = MutableStateFlow("") private val _uploadedMusicGenrePosition = MutableStateFlow(0) val uploadedMusicGenrePosition = _uploadedMusicGenrePosition.asStateFlow() - private val _isUploadEnable = MutableStateFlow(false) - val isUploadEnable = _isUploadEnable.asStateFlow() - - init { - observeMusicTitle() - observeGenrePosition() - } + val isUploadEnable: StateFlow = + combine(uploadedMusicTitle, uploadedMusicGenrePosition) { title, genrePosition -> + title.isNotBlank() && genrePosition != 0 + }.stateIn(viewModelScope, SharingStarted.Eagerly, false) val onChangePosition: (Int) -> Unit = { position: Int -> _uploadedMusicGenrePosition.value = position } - - private fun observeMusicTitle() { - uploadedMusicTitle.onEach { - _isUploadEnable.value = uploadedMusicGenrePosition.value != 0 && it.isNotEmpty() - }.launchIn(viewModelScope) + fun uploadImage(imageFile: File) { + // todo : image 파일을 업로드 한다. + // todo : 반환 값을 uploadedImage에 저장한다. } - - private fun observeGenrePosition() { - uploadedMusicGenrePosition.onEach { - _isUploadEnable.value = it != 0 && uploadedMusicTitle.value.isNotEmpty() - }.launchIn(viewModelScope) + fun uploadAudio(audioFile: File) { + // todo : audio 파일을 업로드 한다. } } \ 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 6ff4e67..93b4ae6 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 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 @@