-
Notifications
You must be signed in to change notification settings - Fork 0
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 #147 from boostcampwm2023/android/feature/60
Upload UI 상태
- Loading branch information
Showing
16 changed files
with
231 additions
and
38 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
android/core/data/src/main/java/com/ohdodok/catchytape/core/data/api/MusicApi.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,12 +1,20 @@ | ||
package com.ohdodok.catchytape.core.data.api | ||
|
||
import com.ohdodok.catchytape.core.data.model.MusicGenresResponse | ||
import com.ohdodok.catchytape.core.data.model.MusicRequest | ||
import retrofit2.Response | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
import retrofit2.http.POST | ||
|
||
interface MusicApi { | ||
|
||
@GET("musics/genres") | ||
suspend fun getGenres(): Response<MusicGenresResponse> | ||
|
||
@POST("musics") | ||
suspend fun postMusic( | ||
@Body music: MusicRequest | ||
): Response<Unit> | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
android/core/data/src/main/java/com/ohdodok/catchytape/core/data/api/UploadApi.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.ohdodok.catchytape.core.data.api | ||
|
||
import com.ohdodok.catchytape.core.data.model.UrlResponse | ||
import retrofit2.Response | ||
import retrofit2.http.Headers | ||
import retrofit2.http.POST | ||
|
||
interface UploadApi { | ||
|
||
@POST("upload/music") | ||
@Headers("Content-Type: audio/mpeg") | ||
suspend fun uploadMusic( | ||
): Response<UrlResponse> | ||
|
||
@POST("upload/image") | ||
@Headers("Content-Type: image/png") | ||
suspend fun uploadImage( | ||
): Response<UrlResponse> | ||
|
||
} |
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
7 changes: 7 additions & 0 deletions
7
android/core/data/src/main/java/com/ohdodok/catchytape/core/data/model/MusicRequest.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.ohdodok.catchytape.core.data.model | ||
|
||
data class MusicRequest ( | ||
val title: String, | ||
val cover: String, | ||
val file: String | ||
) |
5 changes: 5 additions & 0 deletions
5
android/core/data/src/main/java/com/ohdodok/catchytape/core/data/model/UrlResponse.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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.ohdodok.catchytape.core.data.model | ||
|
||
data class UrlResponse( | ||
val url: String | ||
) |
24 changes: 24 additions & 0 deletions
24
...core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/UploadFileUseCase.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.ohdodok.catchytape.core.domain.usecase | ||
|
||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import java.io.File | ||
import javax.inject.Inject | ||
|
||
class UploadFileUseCase @Inject constructor( | ||
|
||
) { | ||
|
||
fun getImgUrl(file: File): Flow<String> = flow { | ||
// todo : 서버 기다리는 중.. | ||
delay(1000) | ||
emit("https://kr.object.ncloudstorage.com/catchy-tape-bucket2/image/%EC%8A%A4%ED%81%AC%EB%A6%B0%EC%83%B7%202023-11-21%20180100.png") | ||
} | ||
|
||
fun getAudioUrl(file: File): Flow<String> = flow { | ||
// todo : 서버 기다리는 중.. | ||
delay(1000) | ||
emit("https://kr.object.ncloudstorage.com/catchy-tape-bucket2/music/2/%EC%9D%B4%EB%85%B8%EB%9E%98.mp3") | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ore/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/UploadMusicUseCase.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.ohdodok.catchytape.core.domain.usecase | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import javax.inject.Inject | ||
|
||
class UploadMusicUseCase @Inject constructor() { | ||
|
||
operator fun invoke(imgUrl: String, audioUrl: String, title: String, genre: String): Flow<Unit> = flow { | ||
// todo : 서버에 업로드 | ||
emit(Unit) | ||
} | ||
} |
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
10 changes: 9 additions & 1 deletion
10
android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/BindingAdapter.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,13 +1,21 @@ | ||
package com.ohdodok.catchytape.core.ui | ||
|
||
import android.widget.ImageView | ||
import androidx.databinding.BindingAdapter | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
|
||
import com.bumptech.glide.Glide | ||
|
||
@BindingAdapter("submitList") | ||
fun <T, VH : RecyclerView.ViewHolder> RecyclerView.bindItems(items: List<T>) { | ||
val adapter = this.adapter ?: return | ||
val listAdapter: ListAdapter<T, VH> = adapter as ListAdapter<T, VH> | ||
listAdapter.submitList(items) | ||
} | ||
|
||
@BindingAdapter("imgUrl") | ||
fun ImageView.bindImg(url: String) { | ||
Glide.with(this.context) | ||
.load(url) | ||
.into(this) | ||
} |
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
29 changes: 23 additions & 6 deletions
29
android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadFragment.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,45 +1,62 @@ | ||
package com.ohdodok.catchytape.feature.upload | ||
|
||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.provider.OpenableColumns | ||
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 | ||
import java.io.File | ||
|
||
@AndroidEntryPoint | ||
class UploadFragment : BaseFragment<FragmentUploadBinding>(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()) | ||
uri.path?.let { viewModel.uploadImage(File(it)) } | ||
} | ||
|
||
private val filePickerLauncher = | ||
registerForActivityResult(ActivityResultContracts.GetContent()) { uri -> | ||
if (uri == null) return@registerForActivityResult | ||
|
||
viewModel.uploadAudio(uri.toFile()) | ||
binding.btnFile.text = getFileName(uri) | ||
uri.path?.let { viewModel.uploadAudio(File(it)) } | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
binding.viewModel = viewModel | ||
|
||
setUpFileBtn() | ||
setupBackStack(binding.tbUpload) | ||
setupSelectThumbnailImage() | ||
} | ||
|
||
private fun setUpFileBtn() { | ||
binding.btnFile.setOnClickListener { | ||
filePickerLauncher.launch("audio/*") | ||
} | ||
} | ||
|
||
private fun setupSelectThumbnailImage() { | ||
binding.cvUploadThumbnail.setOnClickListener { | ||
imagePickerLauncher.launch(PickVisualMediaRequest(PickVisualMedia.ImageOnly)) | ||
} | ||
} | ||
|
||
private fun getFileName(uri: Uri): String? { | ||
val contentResolver = requireContext().contentResolver | ||
contentResolver.query(uri, null, null, null, null)?.use { cursor -> | ||
val nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME) | ||
cursor.moveToFirst() | ||
return cursor.getString(nameIndex) | ||
} | ||
return null | ||
} | ||
} |
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
Oops, something went wrong.