콘텐츠 업로드 - 미리 듣기 시간 설정 기능 추가
This commit is contained in:
parent
b7a986c33c
commit
302e7d9a45
|
@ -258,6 +258,32 @@ class AudioContentUploadActivity : BaseActivity<ActivityAudioContentUploadBindin
|
|||
}
|
||||
)
|
||||
|
||||
compositeDisposable.add(
|
||||
binding.etPreviewStartTime.textChanges().skip(1)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe {
|
||||
if (it.isNotBlank()) {
|
||||
viewModel.previewStartTime = it.toString()
|
||||
} else {
|
||||
viewModel.previewStartTime = null
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
compositeDisposable.add(
|
||||
binding.etPreviewEndTime.textChanges().skip(1)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe {
|
||||
if (it.isNotBlank()) {
|
||||
viewModel.previewEndTime = it.toString()
|
||||
} else {
|
||||
viewModel.previewEndTime = null
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
viewModel.toastLiveData.observe(this) {
|
||||
it?.let { Toast.makeText(applicationContext, it, Toast.LENGTH_LONG).show() }
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ import okhttp3.RequestBody
|
|||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import okio.BufferedSink
|
||||
import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
|
||||
class AudioContentUploadViewModel(
|
||||
private val repository: AudioContentRepository
|
||||
|
@ -52,6 +54,8 @@ class AudioContentUploadViewModel(
|
|||
var theme: GetAudioContentThemeResponse? = null
|
||||
var coverImageUri: Uri? = null
|
||||
var contentUri: Uri? = null
|
||||
var previewStartTime: String? = null
|
||||
var previewEndTime: String? = null
|
||||
|
||||
fun setAdult(isAdult: Boolean) {
|
||||
_isAdultLiveData.postValue(isAdult)
|
||||
|
@ -76,7 +80,9 @@ class AudioContentUploadViewModel(
|
|||
price = price,
|
||||
themeId = theme!!.id,
|
||||
isAdult = _isAdultLiveData.value!!,
|
||||
isCommentAvailable = _isAvailableCommentLiveData.value!!
|
||||
isCommentAvailable = _isAvailableCommentLiveData.value!!,
|
||||
previewStartTime = previewStartTime,
|
||||
previewEndTime = previewEndTime
|
||||
)
|
||||
|
||||
val requestJson = Gson().toJson(request)
|
||||
|
@ -206,6 +212,52 @@ class AudioContentUploadViewModel(
|
|||
return false
|
||||
}
|
||||
|
||||
if (previewStartTime != null && previewEndTime != null) {
|
||||
val startTimeArray = previewStartTime!!.split(":")
|
||||
if (startTimeArray.size != 3) {
|
||||
_toastLiveData.postValue("미리 듣기 시간 형식은 00:30:00 과 같아야 합니다")
|
||||
return false
|
||||
}
|
||||
|
||||
for (time in startTimeArray) {
|
||||
if (time.length != 2) {
|
||||
_toastLiveData.postValue("미리 듣기 시간 형식은 00:30:00 과 같아야 합니다")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
val endTimeArray = previewEndTime!!.split(":")
|
||||
if (endTimeArray.size != 3) {
|
||||
_toastLiveData.postValue("미리 듣기 시간 형식은 00:30:00 과 같아야 합니다")
|
||||
return false
|
||||
}
|
||||
|
||||
for (time in endTimeArray) {
|
||||
if (time.length != 2) {
|
||||
_toastLiveData.postValue("미리 듣기 시간 형식은 00:30:00 과 같아야 합니다")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
val timeDifference = timeDifference(previewStartTime!!, previewEndTime!!)
|
||||
|
||||
if (timeDifference < 30000) {
|
||||
_toastLiveData.postValue(
|
||||
"미리 듣기의 최소 시간은 30초 입니다."
|
||||
)
|
||||
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
if (previewStartTime != null || previewEndTime != null) {
|
||||
_toastLiveData.postValue(
|
||||
"미리 듣기 시작 시간과 종료 시간 둘 다 입력을 하거나 둘 다 입력 하지 않아야 합니다."
|
||||
)
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if (contentUri == null) {
|
||||
_toastLiveData.postValue("오디오 콘텐츠를 선택해 주세요.")
|
||||
return false
|
||||
|
@ -218,4 +270,28 @@ class AudioContentUploadViewModel(
|
|||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun timeDifference(startTime: String, endTime: String): Long {
|
||||
try {
|
||||
// Define a date format for parsing the times
|
||||
val dateFormat = SimpleDateFormat("HH:mm:ss", Locale.KOREAN)
|
||||
|
||||
// Parse the input times into Date objects
|
||||
val date1 = dateFormat.parse(startTime)
|
||||
val date2 = dateFormat.parse(endTime)
|
||||
|
||||
// Check if either date is null
|
||||
if (date1 == null || date2 == null) {
|
||||
return 0
|
||||
}
|
||||
|
||||
// Calculate the absolute time difference in milliseconds
|
||||
|
||||
// Check if the time difference is greater than 30 seconds (30000 milliseconds)
|
||||
return date2.time - date1.time
|
||||
} catch (e: Exception) {
|
||||
// Handle invalid time formats or parsing errors
|
||||
return 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,4 +10,6 @@ data class CreateAudioContentRequest(
|
|||
@SerializedName("themeId") val themeId: Long,
|
||||
@SerializedName("isAdult") val isAdult: Boolean,
|
||||
@SerializedName("isCommentAvailable") val isCommentAvailable: Boolean,
|
||||
@SerializedName("previewStartTime") val previewStartTime: String? = null,
|
||||
@SerializedName("previewEndTime") val previewEndTime: String? = null
|
||||
)
|
||||
|
|
|
@ -628,6 +628,101 @@
|
|||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="13.3dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/gmarket_sans_bold"
|
||||
android:lineSpacingExtra="5sp"
|
||||
android:text="미리듣기 시간 설정"
|
||||
android:textColor="@color/color_eeeeee"
|
||||
android:textSize="16.7sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="13.3dp"
|
||||
android:baselineAligned="false">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/gmarket_sans_medium"
|
||||
android:text="시작 시간"
|
||||
android:textColor="@color/color_eeeeee"
|
||||
android:textSize="13.3sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_preview_start_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5.3dp"
|
||||
android:background="@drawable/bg_round_corner_6_7_222222"
|
||||
android:fontFamily="@font/gmarket_sans_bold"
|
||||
android:gravity="center"
|
||||
android:hint="00:00:00"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textWebEditText"
|
||||
android:paddingHorizontal="13.3dp"
|
||||
android:paddingVertical="17dp"
|
||||
android:textColor="@color/color_eeeeee"
|
||||
android:textColorHint="@color/color_777777"
|
||||
android:textCursorDrawable="@drawable/edit_text_cursor"
|
||||
android:textSize="14.7sp"
|
||||
android:theme="@style/EditTextStyle"
|
||||
tools:ignore="LabelFor" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="13.3dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/gmarket_sans_medium"
|
||||
android:text="종료 시간"
|
||||
android:textColor="@color/color_eeeeee"
|
||||
android:textSize="13.3sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_preview_end_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5.3dp"
|
||||
android:background="@drawable/bg_round_corner_6_7_222222"
|
||||
android:fontFamily="@font/gmarket_sans_bold"
|
||||
android:gravity="center"
|
||||
android:hint="00:30:00"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textWebEditText"
|
||||
android:paddingHorizontal="13.3dp"
|
||||
android:paddingVertical="17dp"
|
||||
android:textColor="@color/color_eeeeee"
|
||||
android:textColorHint="@color/color_777777"
|
||||
android:textCursorDrawable="@drawable/edit_text_cursor"
|
||||
android:textSize="14.7sp"
|
||||
android:theme="@style/EditTextStyle"
|
||||
tools:ignore="LabelFor" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
Loading…
Reference in New Issue