diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherActivity.kt index 5718a106..33c8e4be 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherActivity.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherActivity.kt @@ -18,262 +18,6 @@ class WriteTogetherActivity : BaseActivity(R.layout.activity_write_together) { private lateinit var navController: NavController private val viewModel: WriteTogetherViewModel by viewModels() - /*private val activityResultLauncher: ActivityResultLauncher = - 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() - - 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) { - 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) { diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherViewModel.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherViewModel.kt index b3ce1812..8153f5ee 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherViewModel.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherViewModel.kt @@ -21,8 +21,6 @@ interface WriteTogetherViewModel { val address: StateFlow val addressDetail: StateFlow val isInputComplete: StateFlow - val latLng: SharedFlow - val toast: StateFlow val tradeLocationEvent: SharedFlow sealed class TradeLocationEvent{ diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherViewModelImpl.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherViewModelImpl.kt index 484de3f9..3d29755b 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherViewModelImpl.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherViewModelImpl.kt @@ -91,14 +91,6 @@ class WriteTogetherViewModelImpl @Inject constructor( override val isInputComplete: StateFlow get() = _isInputComplete - private val _latLng = MutableSharedFlow() - override val latLng: SharedFlow - get() = _latLng - - private val _toast = MutableStateFlow("") - override val toast: StateFlow - get() = _toast - private val _tradeLocationEvent = MutableSharedFlow() override val tradeLocationEvent: SharedFlow get() = _tradeLocationEvent diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/AddressDetailFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/AddressDetailFragment.kt index 253de840..9f8126ab 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/AddressDetailFragment.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/AddressDetailFragment.kt @@ -22,13 +22,6 @@ class AddressDetailFragment: BaseFragment(R.layout. } private val viewModel: WriteTogetherViewModel by activityViewModels() override fun initObserver() { - lifecycleScope.launch { - repeatOnLifecycle(Lifecycle.State.STARTED){ - viewModel.address.collect{ - Log.d("address", it.toString()) - } - } - } } override fun initView() { diff --git a/app/src/main/java/com/umc/ttoklip/util/BindAdapter.kt b/app/src/main/java/com/umc/ttoklip/util/BindAdapter.kt index f079b239..1caf2877 100644 --- a/app/src/main/java/com/umc/ttoklip/util/BindAdapter.kt +++ b/app/src/main/java/com/umc/ttoklip/util/BindAdapter.kt @@ -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 @@ -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") @@ -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 + ) + } + } + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_write_together.xml b/app/src/main/res/layout/fragment_write_together.xml index ce23a922..5807ba3d 100644 --- a/app/src/main/res/layout/fragment_write_together.xml +++ b/app/src/main/res/layout/fragment_write_together.xml @@ -1,7 +1,8 @@ + xmlns:tools="http://schemas.android.com/tools" + xmlns:bind="http://schemas.android.com/apk/res-auto"> @@ -110,7 +111,8 @@ 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" @@ -118,7 +120,8 @@ 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}"/>