-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[업로드] 파일 선택 #105
[업로드] 파일 선택 #105
Changes from all commits
45f9c58
592987b
140f87d
d7e3f92
33b0d39
657e7ac
dbe7cd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,5 @@ android { | |
} | ||
|
||
dependencies { | ||
|
||
implementation(libs.appcompat) | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아직 개발이 덜 되어서, 놔두신것 같은데, nullable 한 string으로 하신 이유가 궁금합니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네이밍은 uploadedImageUrl이 더 적절할 수도 있겠네... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 썸네일이 없는 경우는 Blank("") 로 하는 건 어떠신가요??? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 변수명은 말씀하신것 처럼 'uploadedImageUrl' 이 더 적절해 보입니다~ |
||
|
||
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 파일을 업로드 한다. | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GOOD@!~! |
||
|
||
<ImageButton | ||
android:id="@+id/btn_select_thumbnail" | ||
<ImageView | ||
android:id="@+id/iv_thumbnail_image" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_gravity="center" | ||
android:background="@color/white" | ||
android:importantForAccessibility="no" /> | ||
|
||
<ImageView | ||
android:id="@+id/iv_camera_icon" | ||
android:layout_width="48dp" | ||
android:layout_height="48dp" | ||
android:layout_gravity="center" | ||
android:background="@drawable/ic_camera" | ||
android:backgroundTint="@color/surface" /> | ||
android:src="@drawable/ic_camera" | ||
android:importantForAccessibility="no"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. importantForAccessibility 이거 처음봐서 어떤건지 궁금하네요1!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no를 지정하면 스크린 리더가 해당 View를 읽지 않는다는데, 이 아이콘은 장식용 아이콘이라 읽지 않아도 된다고 판단했어. |
||
|
||
</androidx.cardview.widget.CardView> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요건 언제 쓰신 건가여?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
registerForActivityResult의 파라미터 넣어줄 때 사용하는 PickVisualMedia랑 ActivityResultContracts가 액티비티를 필요로 해요