Skip to content

Commit

Permalink
feat: 거래 희망 장소 설정 이후 공구 최대 인원 값 유지
Browse files Browse the repository at this point in the history
  • Loading branch information
kyujin0911 committed Jul 2, 2024
1 parent 440309d commit e66ac2e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,262 +18,6 @@ class WriteTogetherActivity :
BaseActivity<ActivityWriteTogetherBinding>(R.layout.activity_write_together) {
private lateinit var navController: NavController
private val viewModel: WriteTogetherViewModel by viewModels<WriteTogetherViewModelImpl>()
/*private val activityResultLauncher: ActivityResultLauncher<Intent> =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
val addressIntent = it.data
addressIntent?.let { aIntent ->
val address = aIntent.getStringExtra("address")
val addressDetail = aIntent.getStringExtra("addressDetail")
binding.tradingPlaceTv.setTextColor(getColor(R.color.black))
binding.tradingPlaceTv.compoundDrawables.forEach { drawable ->
if (drawable != null) {
drawable.colorFilter =
PorterDuffColorFilter(getColor(R.color.black), PorterDuff.Mode.SRC_IN)
}
}
binding.tradingPlaceTv.text = if (!addressDetail.isNullOrBlank()) {
StringBuilder().append(address).append(" (").append(addressDetail).append(")")
.toString()
} else {
StringBuilder().append(address).toString()
}
}
}
private val imageAdapter by lazy {
ImageRVA(this, null)
}
private val pickMultipleMedia = registerForActivityResult(
ActivityResultContracts.PickMultipleVisualMedia(
100
)
) { uris ->
if (uris.isNotEmpty()) {
updateImages(uris)
} else {
Log.d("PhotoPicker", "No media selected")
}
}
private val viewModel: WriteTogetherViewModel by viewModels<WriteTogetherViewModelImpl>()
override fun initView() {
binding.vm = viewModel as WriteTogetherViewModelImpl
initImageRVA()
addLink()
addImage()
binding.backBtn.setOnClickListener {
finish()
}
var result = ""
binding.totalPriceTv.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) =
Unit
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
if(!TextUtils.isEmpty(s.toString()) && s.toString() != result){
result = s.toString().replace(",","")
viewModel.setTotalPrice(result.toLong())
result = AMOUNT_FORMAT.format(result.toDouble())
binding.totalPriceTv.setText(result)
binding.totalPriceTv.setSelection(result.length)
}
s?.let {
if (it.isBlank()) {
viewModel.setTotalPrice(0)
viewModel.checkDone()
result = ""
}
}
}
override fun afterTextChanged(s: Editable?) = Unit
})
binding.maxMemberTv.setOnClickListener {
val bottomSheet = InputMaxMemberDialogFragment { member ->
viewModel.setTotalMember(member.toLong())
binding.maxMemberTv.text = getString(R.string.max_member_format, member)
binding.maxMemberTv.compoundDrawables.forEach { drawable ->
if (drawable != null) {
drawable.colorFilter =
PorterDuffColorFilter(
getColor(R.color.black),
PorterDuff.Mode.SRC_IN
)
}
}
binding.maxMemberTv.hint = ""
}
bottomSheet.show(supportFragmentManager, bottomSheet.tag)
}
binding.tradingPlaceTv.setOnClickListener {
val intent = Intent(this, TradeLocationActivity::class.java)
activityResultLauncher.launch(intent)
}
}
override fun initObserver() {
with(lifecycleScope) {
launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.doneButtonActivated.collect {
Log.d("enable", it.toString())
binding.writeDoneBtn.isEnabled = it
}
}
}
launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.title.collect {
Log.d("text", it)
viewModel.checkDone()
}
}
}
launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.content.collect {
Log.d("content", it)
viewModel.checkDone()
}
}
}
launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.totalPrice.collect {
Log.d("price", it.toString())
viewModel.checkDone()
}
}
}
launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.totalMember.collect {
Log.d("member", it.toString())
viewModel.checkDone()
}
}
}
launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.dealPlace.collect {
viewModel.checkDone()
}
}
}
launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.openLink.collect {
viewModel.checkDone()
}
}
}
launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.content.collect {
viewModel.checkDone()
}
}
}
launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.images.collect {
Log.d("uri image", it.toString())
imageAdapter.submitList(it.toList())
}
}
}
launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.doneWriteTogether.collect {
if (it) {
val together = TogetherDialog()
together.setDialogClickListener(object :
TogetherDialog.TogetherDialogClickListener {
override fun onClick() {
viewModel.writeTogether()
}
})
together.show(supportFragmentManager, together.tag)
}
}
}
}
launch {
repeatOnLifecycle(Lifecycle.State.STARTED){
viewModel.postId.collect{
if(it != 0L) {
startActivity(
ReadTogetherActivity.newIntent(
this@WriteTogetherActivity,
it
)
)
finish()
}
}
}
}
}
}
private fun addLink() {
binding.addLinkBtn.setOnClickListener {
binding.addLinkBtn.visibility = View.GONE
binding.inputUrlBtn.visibility = View.VISIBLE
}
}
private fun initImageRVA() {
binding.imageRv.adapter = imageAdapter
}
private fun addImage() {
binding.addImageBtn.setOnClickListener {
val imageDialog = ImageDialogFragment()
imageDialog.setDialogClickListener(object : ImageDialogFragment.DialogClickListener {
override fun onClick() {
binding.imageRv.visibility = View.VISIBLE
pickMultipleMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
}
})
imageDialog.show(supportFragmentManager, imageDialog.tag)
}
}
private fun updateImages(uriList: List<Uri>) {
Log.d("uri", uriList.toString())
val images = uriList.map { Image(it, "") }
viewModel.addImages(images)
}
override fun dispatchTouchEvent(event: MotionEvent?): Boolean {
if (event?.action == MotionEvent.ACTION_DOWN) {
val v = currentFocus
if (v is EditText) {
val outRect = Rect()
v.getGlobalVisibleRect(outRect)
if (!outRect.contains(event.rawX.toInt(), event.rawY.toInt())) {
v.clearFocus()
val imm: InputMethodManager =
getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(v.getWindowToken(), 0)
}
}
}
return super.dispatchTouchEvent(event)
}
companion object {
private val AMOUNT_FORMAT = DecimalFormat("#,###")
}*/

override fun dispatchTouchEvent(event: MotionEvent?): Boolean {
if (event?.action == MotionEvent.ACTION_DOWN) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ interface WriteTogetherViewModel {
val address: StateFlow<String>
val addressDetail: StateFlow<String>
val isInputComplete: StateFlow<Boolean>
val latLng: SharedFlow<LatLng>
val toast: StateFlow<String>
val tradeLocationEvent: SharedFlow<TradeLocationEvent>

sealed class TradeLocationEvent{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ class WriteTogetherViewModelImpl @Inject constructor(
override val isInputComplete: StateFlow<Boolean>
get() = _isInputComplete

private val _latLng = MutableSharedFlow<LatLng>()
override val latLng: SharedFlow<LatLng>
get() = _latLng

private val _toast = MutableStateFlow("")
override val toast: StateFlow<String>
get() = _toast

private val _tradeLocationEvent = MutableSharedFlow<WriteTogetherViewModel.TradeLocationEvent>()
override val tradeLocationEvent: SharedFlow<WriteTogetherViewModel.TradeLocationEvent>
get() = _tradeLocationEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ class AddressDetailFragment: BaseFragment<FragmentAddresDetailBinding>(R.layout.
}
private val viewModel: WriteTogetherViewModel by activityViewModels<WriteTogetherViewModelImpl>()
override fun initObserver() {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED){
viewModel.address.collect{
Log.d("address", it.toString())
}
}
}
}

override fun initView() {
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/umc/ttoklip/util/BindAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.umc.ttoklip.util

import android.annotation.SuppressLint
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.view.View
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.StyleRes
Expand All @@ -12,6 +15,7 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.umc.ttoklip.R


@BindingAdapter("bindTextViewStyle")
Expand Down Expand Up @@ -77,4 +81,19 @@ fun ConstraintLayout.setLayoutVisible(address: String){
} else {
View.VISIBLE
}
}

@BindingAdapter("bind:totalMember")
fun TextView.setCompoundDrawableColorFilter(totalMember: Long){
if(totalMember != 0L) {
this.compoundDrawables.forEach { drawable ->
if (drawable != null) {
drawable.colorFilter =
PorterDuffColorFilter(
this.context.getColor(R.color.black),
PorterDuff.Mode.SRC_IN
)
}
}
}
}
9 changes: 6 additions & 3 deletions app/src/main/res/layout/fragment_write_together.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools"
xmlns:bind="http://schemas.android.com/apk/res-auto">

<data>

Expand Down Expand Up @@ -110,15 +111,17 @@
android:layout_marginStart="8dp"
android:background="@drawable/rectangle_corner_10_strok_1"
android:drawablePadding="6dp"
android:hint="공구 최대 인원"
android:text='@{vm.totalMember.equals(0L) ? null : String.valueOf(vm.totalMember) + "명"}'
android:hint='@{vm.totalMember.equals(0L) ? "공구 최대 인원" : null}'
android:paddingHorizontal="15dp"
android:paddingVertical="7dp"
android:textAppearance="@style/TextAppearance.App.12sp_500"
android:textColor="@color/black"
android:textColorHint="@color/gray80"
app:drawableStartCompat="@drawable/ic_face_off_18"
app:layout_constraintStart_toEndOf="@id/total_price_tv"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
bind:totalMember="@{vm.totalMember}"/>

<TextView
android:id="@+id/trading_place_tv"
Expand Down

0 comments on commit e66ac2e

Please sign in to comment.