parent
6fac6ecd4d
commit
5d42e2b16e
|
@ -4,6 +4,7 @@ import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
data class CreateCommunityPostRequest(
|
data class CreateCommunityPostRequest(
|
||||||
@SerializedName("content") val content: String,
|
@SerializedName("content") val content: String,
|
||||||
|
@SerializedName("price") val price: Int,
|
||||||
@SerializedName("isAdult") val isAdult: Boolean,
|
@SerializedName("isAdult") val isAdult: Boolean,
|
||||||
@SerializedName("isCommentAvailable") val isCommentAvailable: Boolean
|
@SerializedName("isCommentAvailable") val isCommentAvailable: Boolean
|
||||||
)
|
)
|
||||||
|
|
|
@ -101,6 +101,8 @@ class CreatorCommunityWriteActivity : BaseActivity<ActivityCreatorCommunityWrite
|
||||||
|
|
||||||
binding.llCommentNo.setOnClickListener { viewModel.setAvailableComment(false) }
|
binding.llCommentNo.setOnClickListener { viewModel.setAvailableComment(false) }
|
||||||
binding.llCommentYes.setOnClickListener { viewModel.setAvailableComment(true) }
|
binding.llCommentYes.setOnClickListener { viewModel.setAvailableComment(true) }
|
||||||
|
binding.llPricePaid.setOnClickListener { viewModel.setPriceFree(false) }
|
||||||
|
binding.llPriceFree.setOnClickListener { viewModel.setPriceFree(true) }
|
||||||
binding.tvCancel.setOnClickListener { finish() }
|
binding.tvCancel.setOnClickListener { finish() }
|
||||||
binding.tvUpload.setOnClickListener {
|
binding.tvUpload.setOnClickListener {
|
||||||
viewModel.createCommunityPost { finish() }
|
viewModel.createCommunityPost { finish() }
|
||||||
|
@ -140,6 +142,24 @@ class CreatorCommunityWriteActivity : BaseActivity<ActivityCreatorCommunityWrite
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
compositeDisposable.add(
|
||||||
|
binding.etPrice.textChanges().skip(1)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe {
|
||||||
|
val price = it.toString().toIntOrNull()
|
||||||
|
if (price != null) {
|
||||||
|
viewModel.price = price.toInt()
|
||||||
|
} else {
|
||||||
|
viewModel.price = 0
|
||||||
|
if (it.isNotBlank()) {
|
||||||
|
binding.etPrice.setText(it.substring(0, it.length - 1))
|
||||||
|
binding.etPrice.setSelection(it.length - 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
viewModel.toastLiveData.observe(this) {
|
viewModel.toastLiveData.observe(this) {
|
||||||
it?.let { Toast.makeText(applicationContext, it, Toast.LENGTH_LONG).show() }
|
it?.let { Toast.makeText(applicationContext, it, Toast.LENGTH_LONG).show() }
|
||||||
}
|
}
|
||||||
|
@ -195,6 +215,14 @@ class CreatorCommunityWriteActivity : BaseActivity<ActivityCreatorCommunityWrite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewModel.isPriceFreeLiveData.observe(this) {
|
||||||
|
if (it) {
|
||||||
|
checkPriceFree()
|
||||||
|
} else {
|
||||||
|
checkPricePaid()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (SharedPreferenceManager.isAuth) {
|
if (SharedPreferenceManager.isAuth) {
|
||||||
binding.llAgeAll.setOnClickListener {
|
binding.llAgeAll.setOnClickListener {
|
||||||
viewModel.setAdult(false)
|
viewModel.setAdult(false)
|
||||||
|
@ -245,4 +273,54 @@ class CreatorCommunityWriteActivity : BaseActivity<ActivityCreatorCommunityWrite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkPriceFree() {
|
||||||
|
viewModel.price = 0
|
||||||
|
binding.etPrice.setText("0")
|
||||||
|
binding.rlPrice.visibility = View.GONE
|
||||||
|
|
||||||
|
binding.ivPriceFree.visibility = View.VISIBLE
|
||||||
|
binding.tvPriceFree.setTextColor(
|
||||||
|
ContextCompat.getColor(
|
||||||
|
applicationContext,
|
||||||
|
R.color.color_eeeeee
|
||||||
|
)
|
||||||
|
)
|
||||||
|
binding.llPriceFree.setBackgroundResource(R.drawable.bg_round_corner_6_7_3bb9f1)
|
||||||
|
|
||||||
|
binding.ivPricePaid.visibility = View.GONE
|
||||||
|
binding.tvPricePaid.setTextColor(
|
||||||
|
ContextCompat.getColor(
|
||||||
|
applicationContext,
|
||||||
|
R.color.color_3bb9f1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
binding.llPricePaid.setBackgroundResource(
|
||||||
|
R.drawable.bg_round_corner_6_7_13181b
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun checkPricePaid() {
|
||||||
|
binding.rlPrice.visibility = View.VISIBLE
|
||||||
|
|
||||||
|
binding.ivPricePaid.visibility = View.VISIBLE
|
||||||
|
binding.tvPricePaid.setTextColor(
|
||||||
|
ContextCompat.getColor(
|
||||||
|
applicationContext,
|
||||||
|
R.color.color_eeeeee
|
||||||
|
)
|
||||||
|
)
|
||||||
|
binding.llPricePaid.setBackgroundResource(R.drawable.bg_round_corner_6_7_3bb9f1)
|
||||||
|
|
||||||
|
binding.ivPriceFree.visibility = View.GONE
|
||||||
|
binding.tvPriceFree.setTextColor(
|
||||||
|
ContextCompat.getColor(
|
||||||
|
applicationContext,
|
||||||
|
R.color.color_3bb9f1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
binding.llPriceFree.setBackgroundResource(
|
||||||
|
R.drawable.bg_round_corner_6_7_13181b
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,8 @@ import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
import okio.BufferedSink
|
import okio.BufferedSink
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class CreatorCommunityWriteViewModel(private val repository: CreatorCommunityRepository
|
class CreatorCommunityWriteViewModel(
|
||||||
|
private val repository: CreatorCommunityRepository
|
||||||
) : BaseViewModel() {
|
) : BaseViewModel() {
|
||||||
private val _toastLiveData = MutableLiveData<String?>()
|
private val _toastLiveData = MutableLiveData<String?>()
|
||||||
val toastLiveData: LiveData<String?>
|
val toastLiveData: LiveData<String?>
|
||||||
|
@ -36,8 +37,13 @@ class CreatorCommunityWriteViewModel(private val repository: CreatorCommunityRep
|
||||||
val isAvailableCommentLiveData: LiveData<Boolean>
|
val isAvailableCommentLiveData: LiveData<Boolean>
|
||||||
get() = _isAvailableCommentLiveData
|
get() = _isAvailableCommentLiveData
|
||||||
|
|
||||||
|
private val _isPriceFreeLiveData = MutableLiveData(true)
|
||||||
|
val isPriceFreeLiveData: LiveData<Boolean>
|
||||||
|
get() = _isPriceFreeLiveData
|
||||||
|
|
||||||
lateinit var getRealPathFromURI: (Uri) -> String?
|
lateinit var getRealPathFromURI: (Uri) -> String?
|
||||||
|
|
||||||
|
var price = 0
|
||||||
var content = ""
|
var content = ""
|
||||||
var imageUri: Uri? = null
|
var imageUri: Uri? = null
|
||||||
|
|
||||||
|
@ -49,12 +55,17 @@ class CreatorCommunityWriteViewModel(private val repository: CreatorCommunityRep
|
||||||
_isAvailableCommentLiveData.postValue(isAvailableComment)
|
_isAvailableCommentLiveData.postValue(isAvailableComment)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setPriceFree(isPriceFree: Boolean) {
|
||||||
|
_isPriceFreeLiveData.postValue(isPriceFree)
|
||||||
|
}
|
||||||
|
|
||||||
fun createCommunityPost(onSuccess: () -> Unit) {
|
fun createCommunityPost(onSuccess: () -> Unit) {
|
||||||
if (!_isLoading.value!! && validateData()) {
|
if (!_isLoading.value!! && validateData()) {
|
||||||
_isLoading.postValue(true)
|
_isLoading.postValue(true)
|
||||||
|
|
||||||
val request = CreateCommunityPostRequest(
|
val request = CreateCommunityPostRequest(
|
||||||
content = content,
|
content = content,
|
||||||
|
price = price,
|
||||||
isAdult = _isAdultLiveData.value!!,
|
isAdult = _isAdultLiveData.value!!,
|
||||||
isCommentAvailable = _isAvailableCommentLiveData.value!!
|
isCommentAvailable = _isAvailableCommentLiveData.value!!
|
||||||
)
|
)
|
||||||
|
@ -131,6 +142,16 @@ class CreatorCommunityWriteViewModel(private val repository: CreatorCommunityRep
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!isPriceFreeLiveData.value!! && price < 5) {
|
||||||
|
_toastLiveData.postValue("최소금액은 5캔 입니다.")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
_toastLiveData.postValue("가격은 숫자만 입력 가능 합니다.")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,6 +323,129 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/ll_price"
|
||||||
|
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:id="@+id/ll_config_price"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="13.3dp"
|
||||||
|
android:baselineAligned="false">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/ll_price_free"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/bg_round_corner_6_7_13181b"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingVertical="14.3dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/iv_price_free"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="6.7dp"
|
||||||
|
android:contentDescription="@null"
|
||||||
|
android:src="@drawable/ic_select_check"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_price_free"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:fontFamily="@font/gmarket_sans_bold"
|
||||||
|
android:text="무료"
|
||||||
|
android:textColor="@color/color_3bb9f1"
|
||||||
|
android:textSize="14.7sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/ll_price_paid"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="13.3dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/bg_round_corner_6_7_13181b"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingVertical="14.3dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/iv_price_paid"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="6.7dp"
|
||||||
|
android:contentDescription="@null"
|
||||||
|
android:src="@drawable/ic_select_check"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_price_paid"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:fontFamily="@font/gmarket_sans_bold"
|
||||||
|
android:text="유료"
|
||||||
|
android:textColor="@color/color_3bb9f1"
|
||||||
|
android:textSize="14.7sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/rl_price"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="13.3dp"
|
||||||
|
android:background="@drawable/bg_live_room_price_select"
|
||||||
|
android:baselineAligned="false"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/et_price"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="13.3dp"
|
||||||
|
android:layout_toStartOf="@+id/tv_can"
|
||||||
|
android:background="@null"
|
||||||
|
android:fontFamily="@font/gmarket_sans_bold"
|
||||||
|
android:gravity="center"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:inputType="numberDecimal"
|
||||||
|
android:maxLength="5"
|
||||||
|
android:paddingVertical="16.7dp"
|
||||||
|
android:text="0"
|
||||||
|
android:textColor="@color/color_3bb9f1"
|
||||||
|
android:textCursorDrawable="@drawable/edit_text_cursor"
|
||||||
|
android:textSize="13.3sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_can"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginEnd="13.3dp"
|
||||||
|
android:fontFamily="@font/gmarket_sans_medium"
|
||||||
|
android:text="캔"
|
||||||
|
android:textColor="@color/color_3bb9f1"
|
||||||
|
android:textSize="13.3sp" />
|
||||||
|
</RelativeLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
Loading…
Reference in New Issue