-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from boostcampwm2023/android/feature/upload-100
[업로드] 파일 선택
- Loading branch information
Showing
6 changed files
with
68 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,5 @@ android { | |
} | ||
|
||
dependencies { | ||
|
||
implementation(libs.appcompat) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 23 additions & 19 deletions
42
...oid/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String>("") | ||
) : 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<Boolean> = | ||
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 파일을 업로드 한다. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters