From c9f1c533c7f45581ecff8e2e3d6953784f987c0c Mon Sep 17 00:00:00 2001 From: KKJ Date: Wed, 26 Jun 2024 23:58:07 +0900 Subject: [PATCH 1/8] =?UTF-8?q?fix:=20=ED=95=A8=EA=BB=98=ED=95=B4=EC=9A=94?= =?UTF-8?q?=20=EA=B1=B0=EB=9E=98=20=EC=9E=A5=EC=86=8C=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=ED=98=84=EC=9E=AC=20=EC=9C=84=EC=B9=98=EB=A1=9C=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hometown/TradeLocationActivity.kt | 5 +- .../presentation/intro/SplashActivity.kt | 2 +- .../res/layout/activity_trade_location.xml | 46 ++----------------- 3 files changed, 9 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/TradeLocationActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/TradeLocationActivity.kt index 9103616c..7acf1c83 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/TradeLocationActivity.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/TradeLocationActivity.kt @@ -1,8 +1,10 @@ package com.umc.ttoklip.presentation.hometown import android.content.Intent +import android.view.View import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts +import androidx.lifecycle.VIEW_MODEL_STORE_OWNER_KEY import androidx.recyclerview.widget.LinearLayoutManager import com.umc.ttoklip.R import com.umc.ttoklip.databinding.ActivityTradeLocationBinding @@ -27,6 +29,7 @@ class TradeLocationActivity : val address = aIntent.getStringExtra("address") val addressDetail = aIntent.getStringExtra("addressDetail") address?.let { place -> + binding.tradeLocationFrame.visibility = View.VISIBLE binding.tradeLocationTv.text = place addressDetail?.let { detail -> binding.tradeLocationDetailTv.text = detail @@ -53,7 +56,7 @@ class TradeLocationActivity : binding.recentlyUsedPlacesRv.layoutManager = LinearLayoutManager(this) adapter.submitList(places) - binding.gpsBaseSettingFrame.setOnClickListener { + binding.inputTradeLocationTv.setOnClickListener { val intent = Intent(this, PlaceActivity::class.java) activityResultLauncher.launch(intent) } diff --git a/app/src/main/java/com/umc/ttoklip/presentation/intro/SplashActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/intro/SplashActivity.kt index 5d118646..a7ebca16 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/intro/SplashActivity.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/intro/SplashActivity.kt @@ -16,7 +16,7 @@ class SplashActivity:BaseActivity(R.layout.activity_splas handler.postDelayed({ val spf=getSharedPreferences("first", MODE_PRIVATE) val firstRun=spf.getBoolean("firstRun",true) - TtoklipApplication.prefs.setBoolean("isFirstLogin", true) + TtoklipApplication.prefs.setBoolean("isFirstLogin", false) val jwt=TtoklipApplication.prefs.getString("jwt","") val isFirstLogin=TtoklipApplication.prefs.getBoolean("isFirstLogin",true) if(firstRun){ diff --git a/app/src/main/res/layout/activity_trade_location.xml b/app/src/main/res/layout/activity_trade_location.xml index 196ae5fc..0d798e95 100644 --- a/app/src/main/res/layout/activity_trade_location.xml +++ b/app/src/main/res/layout/activity_trade_location.xml @@ -37,10 +37,11 @@ android:id="@+id/trade_location_frame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="76dp" + android:layout_marginTop="20dp" android:paddingHorizontal="36dp" android:paddingVertical="15dp" - app:layout_constraintTop_toTopOf="parent"> + android:visibility="gone" + app:layout_constraintTop_toBottomOf="@id/title_tv"> - - - - - - - - - + app:layout_constraintTop_toBottomOf="@id/set_trade_location_frame"> Date: Thu, 27 Jun 2024 00:44:04 +0900 Subject: [PATCH 2/8] =?UTF-8?q?refactor:=20=ED=95=A8=EA=BB=98=ED=95=B4?= =?UTF-8?q?=EC=9A=94=20=EA=B8=80=EC=93=B0=EA=B8=B0=20=EB=82=B4=EB=B6=80=20?= =?UTF-8?q?=ED=99=94=EB=A9=B4=20activity=20intent=EC=97=90=EC=84=9C=20navi?= =?UTF-8?q?gation=EC=9C=BC=EB=A1=9C=20=EC=A0=84=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../presentation/hometown/PlaceActivity.kt | 1 + .../together/write/WriteTogetherActivity.kt | 39 ++- .../together/write/WriteTogetherFragment.kt | 288 ++++++++++++++++ .../hometown/tradelocation/PlaceFragment.kt | 17 + .../TradeLocationActivity.kt | 36 +- .../tradelocation/TradeLocationFragment.kt | 56 +++ .../tradelocation/TradeLocationViewModel.kt | 14 + .../res/layout/activity_trade_location.xml | 12 +- .../res/layout/activity_write_together.xml | 11 +- app/src/main/res/layout/fragment_place.xml | 102 ++++++ .../res/layout/fragment_trade_location.xml | 155 +++++++++ .../res/layout/fragment_write_together.xml | 319 ++++++++++++++++++ .../res/navigation/trade_location_graph.xml | 27 ++ 14 files changed, 1047 insertions(+), 32 deletions(-) create mode 100644 app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherFragment.kt create mode 100644 app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/PlaceFragment.kt rename app/src/main/java/com/umc/ttoklip/presentation/hometown/{ => tradelocation}/TradeLocationActivity.kt (60%) create mode 100644 app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationFragment.kt create mode 100644 app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationViewModel.kt create mode 100644 app/src/main/res/layout/fragment_place.xml create mode 100644 app/src/main/res/layout/fragment_trade_location.xml create mode 100644 app/src/main/res/layout/fragment_write_together.xml create mode 100644 app/src/main/res/navigation/trade_location_graph.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 85c6e9e5..39b5e898 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -130,7 +130,7 @@ android:windowSoftInputMode="adjustPan" android:exported="true" /> diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/PlaceActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/PlaceActivity.kt index 674f0240..0ed0c844 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/PlaceActivity.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/PlaceActivity.kt @@ -18,6 +18,7 @@ import com.naver.maps.map.util.FusedLocationSource import com.umc.ttoklip.R import com.umc.ttoklip.databinding.ActivityPlaceBinding import com.umc.ttoklip.presentation.base.BaseActivity +import com.umc.ttoklip.presentation.hometown.tradelocation.TradeLocationActivity import dagger.hilt.android.AndroidEntryPoint import java.util.Locale 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 a1cdb213..da1781f8 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 @@ -13,7 +13,6 @@ import android.text.TextWatcher import android.util.Log import android.view.MotionEvent import android.view.View -import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputMethodManager import android.widget.EditText import androidx.activity.result.ActivityResultLauncher @@ -23,24 +22,26 @@ import androidx.activity.viewModels import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle +import androidx.navigation.NavController +import androidx.navigation.fragment.NavHostFragment import com.umc.ttoklip.R import com.umc.ttoklip.databinding.ActivityWriteTogetherBinding import com.umc.ttoklip.presentation.base.BaseActivity -import com.umc.ttoklip.presentation.hometown.TradeLocationActivity +import com.umc.ttoklip.presentation.hometown.tradelocation.TradeLocationActivity import com.umc.ttoklip.presentation.hometown.dialog.InputMaxMemberDialogFragment import com.umc.ttoklip.presentation.hometown.dialog.TogetherDialog import com.umc.ttoklip.presentation.honeytip.adapter.Image import com.umc.ttoklip.presentation.honeytip.adapter.ImageRVA import com.umc.ttoklip.presentation.dialog.ImageDialogFragment import com.umc.ttoklip.presentation.hometown.together.read.ReadTogetherActivity -import com.umc.ttoklip.presentation.honeytip.read.ReadHoneyTipActivity import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch @AndroidEntryPoint class WriteTogetherActivity : BaseActivity(R.layout.activity_write_together) { - private val activityResultLauncher: ActivityResultLauncher = + private lateinit var navController: NavController + /*private val activityResultLauncher: ActivityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { val addressIntent = it.data addressIntent?.let { aIntent -> @@ -77,6 +78,7 @@ class WriteTogetherActivity : } } private val viewModel: WriteTogetherViewModel by viewModels() + override fun initView() { binding.vm = viewModel as WriteTogetherViewModelImpl initImageRVA() @@ -294,5 +296,34 @@ class WriteTogetherActivity : companion object { private val AMOUNT_FORMAT = DecimalFormat("#,###") + }*/ + + 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) + } + override fun initView() { + initNavigator() + } + + override fun initObserver() { + + } + + private fun initNavigator(){ + val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment + navController = navHostFragment.navController } } \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherFragment.kt new file mode 100644 index 00000000..4f0c50e3 --- /dev/null +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherFragment.kt @@ -0,0 +1,288 @@ +package com.umc.ttoklip.presentation.hometown.together.write + +import android.content.Context +import android.content.Intent +import android.graphics.PorterDuff +import android.graphics.PorterDuffColorFilter +import android.graphics.Rect +import android.icu.text.DecimalFormat +import android.net.Uri +import android.text.Editable +import android.text.TextUtils +import android.text.TextWatcher +import android.util.Log +import android.view.MotionEvent +import android.view.View +import android.view.ViewGroup +import android.view.inputmethod.InputMethodManager +import android.widget.EditText +import androidx.activity.result.PickVisualMediaRequest +import androidx.activity.result.contract.ActivityResultContracts +import androidx.activity.viewModels +import androidx.fragment.app.viewModels +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle +import androidx.navigation.fragment.findNavController +import com.umc.ttoklip.R +import com.umc.ttoklip.databinding.FragmentWriteTogetherBinding +import com.umc.ttoklip.presentation.base.BaseFragment +import com.umc.ttoklip.presentation.dialog.ImageDialogFragment +import com.umc.ttoklip.presentation.hometown.dialog.InputMaxMemberDialogFragment +import com.umc.ttoklip.presentation.hometown.dialog.TogetherDialog +import com.umc.ttoklip.presentation.hometown.together.read.ReadTogetherActivity +import com.umc.ttoklip.presentation.hometown.tradelocation.TradeLocationActivity +import com.umc.ttoklip.presentation.honeytip.adapter.Image +import com.umc.ttoklip.presentation.honeytip.adapter.ImageRVA +import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.launch + +@AndroidEntryPoint +class WriteTogetherFragment: BaseFragment(R.layout.fragment_write_together) { + + private val imageAdapter by lazy { + ImageRVA(requireContext(), 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() + + private val navigator by lazy { + findNavController() + } + override fun initView() { + binding.vm = viewModel as WriteTogetherViewModelImpl + initImageRVA() + addLink() + addImage() + + binding.backBtn.setOnClickListener { + requireActivity().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( + requireContext().getColor(R.color.black), + PorterDuff.Mode.SRC_IN + ) + } + } + binding.maxMemberTv.hint = "" + } + bottomSheet.show(childFragmentManager, bottomSheet.tag) + } + + binding.tradingPlaceTv.setOnClickListener { + navigator.navigate(R.id.action_writeTogetherFragment_to_tradeLocationFragment) + /*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(childFragmentManager, together.tag) + } + } + } + } + + launch { + repeatOnLifecycle(Lifecycle.State.STARTED){ + viewModel.postId.collect{ + if(it != 0L) { + startActivity( + ReadTogetherActivity.newIntent( + requireContext(), + it + ) + ) + requireActivity().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(childFragmentManager, 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("#,###") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/PlaceFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/PlaceFragment.kt new file mode 100644 index 00000000..36948794 --- /dev/null +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/PlaceFragment.kt @@ -0,0 +1,17 @@ +package com.umc.ttoklip.presentation.hometown.tradelocation + +import com.umc.ttoklip.R +import com.umc.ttoklip.databinding.FragmentPlaceBinding +import com.umc.ttoklip.presentation.base.BaseFragment +import dagger.hilt.android.AndroidEntryPoint + +@AndroidEntryPoint +class PlaceFragment: BaseFragment(R.layout.fragment_place) { + override fun initObserver() { + + } + + override fun initView() { + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/TradeLocationActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationActivity.kt similarity index 60% rename from app/src/main/java/com/umc/ttoklip/presentation/hometown/TradeLocationActivity.kt rename to app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationActivity.kt index 7acf1c83..cfd4ae60 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/TradeLocationActivity.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationActivity.kt @@ -1,14 +1,17 @@ -package com.umc.ttoklip.presentation.hometown +package com.umc.ttoklip.presentation.hometown.tradelocation import android.content.Intent import android.view.View import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts -import androidx.lifecycle.VIEW_MODEL_STORE_OWNER_KEY +import androidx.fragment.app.FragmentContainerView +import androidx.navigation.NavController +import androidx.navigation.fragment.NavHostFragment import androidx.recyclerview.widget.LinearLayoutManager import com.umc.ttoklip.R import com.umc.ttoklip.databinding.ActivityTradeLocationBinding import com.umc.ttoklip.presentation.base.BaseActivity +import com.umc.ttoklip.presentation.hometown.PlaceActivity import com.umc.ttoklip.presentation.hometown.adapter.OnRecentPlaceClickListener import com.umc.ttoklip.presentation.hometown.adapter.RecentPlace import com.umc.ttoklip.presentation.hometown.adapter.RecentlyUsedPlaceAdapter @@ -19,7 +22,8 @@ import dagger.hilt.android.AndroidEntryPoint class TradeLocationActivity : BaseActivity(R.layout.activity_trade_location), OnRecentPlaceClickListener { - private val adapter by lazy { + private lateinit var navController: NavController + /*private val adapter by lazy { RecentlyUsedPlaceAdapter(this) } private val activityResultLauncher: ActivityResultLauncher = @@ -37,29 +41,15 @@ class TradeLocationActivity : } } - } + }*/ override fun initView() { - binding.backBtn.setOnClickListener { - val intent = Intent(applicationContext, WriteTogetherActivity::class.java) - intent.putExtra("address", binding.tradeLocationTv.text.toString()) - intent.putExtra("addressDetail", binding.tradeLocationDetailTv.text.toString()) - setResult(1, intent) - finish() - } - val places = listOf( - RecentPlace("부산광역시 동래구 금강공원로 2", "SK HUB Olive 1203호"), - RecentPlace("부산광역시 동래구 금강공원로 2", "SK HUB Olive 1203호"), - RecentPlace("부산광역시 동래구 금강공원로 2", "SK HUB Olive 1203호") - ) - binding.recentlyUsedPlacesRv.adapter = adapter - binding.recentlyUsedPlacesRv.layoutManager = LinearLayoutManager(this) - adapter.submitList(places) + initNavigator() + } - binding.inputTradeLocationTv.setOnClickListener { - val intent = Intent(this, PlaceActivity::class.java) - activityResultLauncher.launch(intent) - } + private fun initNavigator(){ + val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment + navController = navHostFragment.navController } override fun initObserver() { diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationFragment.kt new file mode 100644 index 00000000..e3161f4c --- /dev/null +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationFragment.kt @@ -0,0 +1,56 @@ +package com.umc.ttoklip.presentation.hometown.tradelocation + +import android.content.Intent +import androidx.navigation.fragment.findNavController +import androidx.recyclerview.widget.LinearLayoutManager +import com.umc.ttoklip.R +import com.umc.ttoklip.databinding.FragmentTradeLocationBinding +import com.umc.ttoklip.presentation.base.BaseFragment +import com.umc.ttoklip.presentation.hometown.PlaceActivity +import com.umc.ttoklip.presentation.hometown.adapter.OnRecentPlaceClickListener +import com.umc.ttoklip.presentation.hometown.adapter.RecentPlace +import com.umc.ttoklip.presentation.hometown.adapter.RecentlyUsedPlaceAdapter +import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherActivity +import dagger.hilt.android.AndroidEntryPoint + +@AndroidEntryPoint +class TradeLocationFragment: BaseFragment(R.layout.fragment_trade_location), + OnRecentPlaceClickListener { + private val adapter by lazy { + RecentlyUsedPlaceAdapter(this) + } + private val navigator by lazy { + findNavController() + } + override fun initObserver() { + + } + + override fun initView() { + binding.backBtn.setOnClickListener { + val intent = Intent(requireContext(), WriteTogetherActivity::class.java) + intent.putExtra("address", binding.tradeLocationTv.text.toString()) + intent.putExtra("addressDetail", binding.tradeLocationDetailTv.text.toString()) + //setResult(1, intent) + navigator.navigateUp() + } + val places = listOf( + RecentPlace("부산광역시 동래구 금강공원로 2", "SK HUB Olive 1203호"), + RecentPlace("부산광역시 동래구 금강공원로 2", "SK HUB Olive 1203호"), + RecentPlace("부산광역시 동래구 금강공원로 2", "SK HUB Olive 1203호") + ) + binding.recentlyUsedPlacesRv.adapter = adapter + binding.recentlyUsedPlacesRv.layoutManager = LinearLayoutManager(requireContext()) + adapter.submitList(places) + + binding.inputTradeLocationTv.setOnClickListener { + navigator.navigate(R.id.action_tradeLocationFragment_to_placeFragment) + //val intent = Intent(this, PlaceActivity::class.java) + //activityResultLauncher.launch(intent) + } + } + + override fun onClick(items: RecentPlace) { + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationViewModel.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationViewModel.kt new file mode 100644 index 00000000..5be45b2f --- /dev/null +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationViewModel.kt @@ -0,0 +1,14 @@ +package com.umc.ttoklip.presentation.hometown.tradelocation + +import androidx.lifecycle.ViewModel +import com.umc.ttoklip.data.repository.naver.NaverRepository +import com.umc.ttoklip.data.repository.naver.NaverRepositoryImpl +import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject + +@HiltViewModel +class TradeLocationViewModel @Inject constructor( + private val repository: NaverRepository +) : ViewModel() { + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_trade_location.xml b/app/src/main/res/layout/activity_trade_location.xml index 0d798e95..dc88cf98 100644 --- a/app/src/main/res/layout/activity_trade_location.xml +++ b/app/src/main/res/layout/activity_trade_location.xml @@ -7,7 +7,15 @@ - + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_write_together.xml b/app/src/main/res/layout/activity_write_together.xml index ce23a922..a3f7d4c1 100644 --- a/app/src/main/res/layout/activity_write_together.xml +++ b/app/src/main/res/layout/activity_write_together.xml @@ -10,8 +10,15 @@ type="com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModelImpl" /> + - - + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_place.xml b/app/src/main/res/layout/fragment_place.xml new file mode 100644 index 00000000..3eca6a62 --- /dev/null +++ b/app/src/main/res/layout/fragment_place.xml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_trade_location.xml b/app/src/main/res/layout/fragment_trade_location.xml new file mode 100644 index 00000000..0d798e95 --- /dev/null +++ b/app/src/main/res/layout/fragment_trade_location.xml @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 new file mode 100644 index 00000000..ce23a922 --- /dev/null +++ b/app/src/main/res/layout/fragment_write_together.xml @@ -0,0 +1,319 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/trade_location_graph.xml b/app/src/main/res/navigation/trade_location_graph.xml new file mode 100644 index 00000000..83f992c0 --- /dev/null +++ b/app/src/main/res/navigation/trade_location_graph.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + \ No newline at end of file From f012d255e52607b56e0260cf89c2da05f0a0dd13 Mon Sep 17 00:00:00 2001 From: KKJ Date: Thu, 27 Jun 2024 02:15:44 +0900 Subject: [PATCH 3/8] =?UTF-8?q?refactor:=20=EA=B1=B0=EB=9E=98=20=EC=9E=A5?= =?UTF-8?q?=EC=86=8C=20=EC=84=A4=EC=A0=95=20=ED=99=94=EB=A9=B4=20=EA=B0=84?= =?UTF-8?q?=20=EC=A3=BC=EC=86=8C=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EA=B3=B5?= =?UTF-8?q?=EC=9C=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../hometown/AddressDetailActivity.kt | 3 +- .../presentation/hometown/PlaceActivity.kt | 2 +- .../together/write/WriteTogetherActivity.kt | 4 +- .../together/write/WriteTogetherFragment.kt | 29 +-- .../together/write/WriteTogetherViewModel.kt | 6 + .../write/WriteTogetherViewModelImpl.kt | 18 ++ .../tradelocation/AddressDetailFragment.kt | 44 +++++ .../write/tradelocation/PlaceFragment.kt | 182 ++++++++++++++++++ .../tradelocation/TradeLocationActivity.kt | 2 +- .../tradelocation/TradeLocationFragment.kt | 6 +- .../tradelocation/TradeLocationViewModel.kt | 2 +- .../hometown/tradelocation/PlaceFragment.kt | 17 -- app/src/main/res/layout/activity_place.xml | 4 +- .../res/layout/fragment_addres_detail.xml | 121 ++++++++++++ app/src/main/res/layout/fragment_place.xml | 17 +- .../res/navigation/trade_location_graph.xml | 14 +- 17 files changed, 412 insertions(+), 61 deletions(-) create mode 100644 app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/AddressDetailFragment.kt create mode 100644 app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt rename app/src/main/java/com/umc/ttoklip/presentation/hometown/{ => together/write}/tradelocation/TradeLocationActivity.kt (96%) rename app/src/main/java/com/umc/ttoklip/presentation/hometown/{ => together/write}/tradelocation/TradeLocationFragment.kt (85%) rename app/src/main/java/com/umc/ttoklip/presentation/hometown/{ => together/write}/tradelocation/TradeLocationViewModel.kt (83%) delete mode 100644 app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/PlaceFragment.kt create mode 100644 app/src/main/res/layout/fragment_addres_detail.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 39b5e898..23ce2add 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -130,7 +130,7 @@ android:windowSoftInputMode="adjustPan" android:exported="true" /> diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/AddressDetailActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/AddressDetailActivity.kt index 89db0c91..c61e2742 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/AddressDetailActivity.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/AddressDetailActivity.kt @@ -1,6 +1,7 @@ package com.umc.ttoklip.presentation.hometown import android.content.Intent +import androidx.navigation.findNavController import com.umc.ttoklip.R import com.umc.ttoklip.databinding.ActivityAddressDetailBinding import com.umc.ttoklip.presentation.base.BaseActivity @@ -26,7 +27,7 @@ class AddressDetailActivity : finish() } binding.gpsBaseSettingFrame.setOnClickListener { - finish() + } } diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/PlaceActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/PlaceActivity.kt index 0ed0c844..13501ca1 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/PlaceActivity.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/PlaceActivity.kt @@ -18,7 +18,7 @@ import com.naver.maps.map.util.FusedLocationSource import com.umc.ttoklip.R import com.umc.ttoklip.databinding.ActivityPlaceBinding import com.umc.ttoklip.presentation.base.BaseActivity -import com.umc.ttoklip.presentation.hometown.tradelocation.TradeLocationActivity +import com.umc.ttoklip.presentation.hometown.together.write.tradelocation.TradeLocationActivity import dagger.hilt.android.AndroidEntryPoint import java.util.Locale 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 da1781f8..946febab 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 @@ -19,6 +19,7 @@ import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels +import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle @@ -27,7 +28,7 @@ import androidx.navigation.fragment.NavHostFragment import com.umc.ttoklip.R import com.umc.ttoklip.databinding.ActivityWriteTogetherBinding import com.umc.ttoklip.presentation.base.BaseActivity -import com.umc.ttoklip.presentation.hometown.tradelocation.TradeLocationActivity +import com.umc.ttoklip.presentation.hometown.together.write.tradelocation.TradeLocationActivity import com.umc.ttoklip.presentation.hometown.dialog.InputMaxMemberDialogFragment import com.umc.ttoklip.presentation.hometown.dialog.TogetherDialog import com.umc.ttoklip.presentation.honeytip.adapter.Image @@ -41,6 +42,7 @@ import kotlinx.coroutines.launch 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 diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherFragment.kt index 4f0c50e3..1fcabe8b 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherFragment.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherFragment.kt @@ -19,6 +19,7 @@ import android.widget.EditText import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels +import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope @@ -31,7 +32,7 @@ import com.umc.ttoklip.presentation.dialog.ImageDialogFragment import com.umc.ttoklip.presentation.hometown.dialog.InputMaxMemberDialogFragment import com.umc.ttoklip.presentation.hometown.dialog.TogetherDialog import com.umc.ttoklip.presentation.hometown.together.read.ReadTogetherActivity -import com.umc.ttoklip.presentation.hometown.tradelocation.TradeLocationActivity +import com.umc.ttoklip.presentation.hometown.together.write.tradelocation.TradeLocationActivity import com.umc.ttoklip.presentation.honeytip.adapter.Image import com.umc.ttoklip.presentation.honeytip.adapter.ImageRVA import dagger.hilt.android.AndroidEntryPoint @@ -55,7 +56,7 @@ class WriteTogetherFragment: BaseFragment(R.layout Log.d("PhotoPicker", "No media selected") } } - private val viewModel: WriteTogetherViewModel by viewModels() + private val viewModel: WriteTogetherViewModel by activityViewModels() private val navigator by lazy { findNavController() @@ -117,9 +118,6 @@ class WriteTogetherFragment: BaseFragment(R.layout binding.tradingPlaceTv.setOnClickListener { navigator.navigate(R.id.action_writeTogetherFragment_to_tradeLocationFragment) - /*val intent = Intent(this, TradeLocationActivity::class.java) - activityResultLauncher.launch(intent)*/ - } } @@ -261,27 +259,6 @@ class WriteTogetherFragment: BaseFragment(R.layout 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("#,###") } 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 321a98bb..2342117e 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 @@ -17,9 +17,15 @@ interface WriteTogetherViewModel { val closePage: StateFlow val images: StateFlow> val postId: StateFlow + val address: StateFlow + val addressDetail: StateFlow fun setTotalPrice(totalPrice: Long) fun setTotalMember(totalMember: Long) + + fun setAddress(address: String) + + fun setAddressDetail(addressDetail: String) fun addImages(images: List) fun checkDone() fun doneButtonClick() 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 6c1d7d79..27c4f64a 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 @@ -14,6 +14,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import javax.inject.Inject @@ -71,6 +72,14 @@ class WriteTogetherViewModelImpl @Inject constructor( override val postId: StateFlow get() = _postId + private val _address = MutableStateFlow("") + override val address: StateFlow + get() = _address + + private val _addressDetail = MutableStateFlow("") + override val addressDetail: StateFlow + get() = _addressDetail + override fun setTotalPrice(totalPrice: Long) { _totalPrice.value = totalPrice @@ -81,6 +90,15 @@ class WriteTogetherViewModelImpl @Inject constructor( _totalMember.value = totalMember } + override fun setAddress(address: String) { + _address.value = address + Log.d("address set", this.address.value.toString()) + } + + override fun setAddressDetail(addressDetail: String) { + _addressDetail.value = addressDetail + } + override fun addImages(images: List) { val combined = _images.value + images 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 new file mode 100644 index 00000000..563cac65 --- /dev/null +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/AddressDetailFragment.kt @@ -0,0 +1,44 @@ +package com.umc.ttoklip.presentation.hometown.together.write.tradelocation + +import android.util.Log +import androidx.fragment.app.activityViewModels +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle +import androidx.navigation.fragment.findNavController +import com.umc.ttoklip.R +import com.umc.ttoklip.databinding.FragmentAddresDetailBinding +import com.umc.ttoklip.presentation.base.BaseFragment +import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModel +import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModelImpl +import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.launch + +@AndroidEntryPoint +class AddressDetailFragment: BaseFragment(R.layout.fragment_addres_detail) { + private val navigator by lazy { + findNavController() + } + 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() { + binding.viewModel = viewModel + + binding.locationNextBtn.setOnClickListener { + navigator.popBackStack(R.id.writeTogetherFragment, false) + } + binding.gpsBaseSettingFrame.setOnClickListener { + navigator.navigateUp() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt new file mode 100644 index 00000000..a50cabc5 --- /dev/null +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt @@ -0,0 +1,182 @@ +package com.umc.ttoklip.presentation.hometown.together.write.tradelocation + +import android.Manifest +import android.content.Intent +import android.content.pm.PackageManager +import android.location.Address +import android.location.Geocoder +import android.os.Build +import android.util.Log +import androidx.activity.result.ActivityResultLauncher +import androidx.activity.result.contract.ActivityResultContracts +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat +import androidx.fragment.app.activityViewModels +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle +import androidx.navigation.fragment.findNavController +import com.google.android.gms.location.FusedLocationProviderClient +import com.google.android.gms.location.LocationServices +import com.naver.maps.geometry.LatLng +import com.naver.maps.map.CameraUpdate +import com.naver.maps.map.LocationTrackingMode +import com.naver.maps.map.MapFragment +import com.naver.maps.map.NaverMap +import com.naver.maps.map.OnMapReadyCallback +import com.naver.maps.map.overlay.LocationOverlay +import com.naver.maps.map.overlay.OverlayImage +import com.naver.maps.map.util.FusedLocationSource +import com.umc.ttoklip.R +import com.umc.ttoklip.databinding.FragmentPlaceBinding +import com.umc.ttoklip.presentation.base.BaseFragment +import com.umc.ttoklip.presentation.hometown.AddressDetailActivity +import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModel +import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModelImpl +import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.launch +import java.util.Locale + +@AndroidEntryPoint +class PlaceFragment : BaseFragment(R.layout.fragment_place), + OnMapReadyCallback { + private var type = "" + private lateinit var naverMap: NaverMap + private var address: String = "" + private val LOCATION_PERMISSION_REQUEST_CODE: Int = 5000 + private val PERMISSIONS = arrayOf( + Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.ACCESS_COARSE_LOCATION + ) + private var locationok: Boolean = false + private val navigator by lazy { + findNavController() + } + private lateinit var fusedLocationClient: FusedLocationProviderClient + private val viewModel: WriteTogetherViewModel by activityViewModels() + + /*private val activityResultLauncher: ActivityResultLauncher = + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { + val addressIntent = it.data + addressIntent?.let { aIntent -> + val address = aIntent.getStringExtra("address") + val addressDetail = aIntent.getStringExtra("addressDetail") + if (address != null) { + val lIntent = Intent(this, TradeLocationActivity::class.java) + lIntent.putExtra("address", address) + lIntent.putExtra("addressDetail", addressDetail) + setResult(1, lIntent) + finish() + } + + } + }*/ + + override fun initView() { + binding.viewModel = viewModel + /*intent.getStringExtra("place")?.let { + type = it + binding.locationTitleTv.text = getString(R.string.my_hometown_address_title) + }*/ + fusedLocationClient = LocationServices.getFusedLocationProviderClient(requireActivity()) + if (!hasPermission()) { + ActivityCompat.requestPermissions(requireActivity(), PERMISSIONS, LOCATION_PERMISSION_REQUEST_CODE) + } + initMapView() + + binding.locationNextBtn.setOnClickListener { + /*val intent = Intent(requireContext(), AddressDetailActivity::class.java) + intent.putExtra("place", "town") + intent.putExtra("address", address) + activityResultLauncher.launch(intent)*/ + navigator.navigate(R.id.addressDetailFragment) + } + + binding.locationBackIb.setOnClickListener { + navigator.navigateUp() + } + } + + override fun initObserver() { + lifecycleScope.launch { + repeatOnLifecycle(Lifecycle.State.STARTED) { + viewModel.address.collect { + Log.d("address", it.toString()) + } + } + } + } + + private fun initMapView() { + val fm = childFragmentManager + val mapFragment = fm.findFragmentById(R.id.location_map) as MapFragment? + ?: MapFragment.newInstance().also { + fm.beginTransaction().add(R.id.location_map, it).commit() + } + mapFragment.getMapAsync(this) + } + + private fun getAddress(latitude: Double, longitude: Double) { + val geocoder = Geocoder(requireContext(), Locale.KOREAN) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + val addressList: List
? = geocoder.getFromLocation(latitude, longitude, 1) + if (addressList != null && addressList.isNotEmpty()) { + val address: Address = addressList[0] + val spliteAddr = address.getAddressLine(0).split(" ") + this.address = spliteAddr[1] + " " + spliteAddr[2] + " " + spliteAddr[3] + } + } else { + val addresses = geocoder.getFromLocation(latitude, longitude, 1) + if (addresses != null) { + val spliteAddr = addresses[0].getAddressLine(0).split(" ") + this.address = spliteAddr[1] + " " + spliteAddr[2] + " " + spliteAddr[3] + } + } + //binding.currentLocationTv.text = address + viewModel.setAddress(address) + } + + private fun hasPermission(): Boolean { + for (permission in PERMISSIONS) { + if (ContextCompat.checkSelfPermission(requireContext(), permission) + != PackageManager.PERMISSION_GRANTED + ) { + return false + } + } + return true + } + + override fun onMapReady(p0: NaverMap) { + this.naverMap = p0 + binding.locationNowLocation.map = naverMap + + naverMap.locationSource = FusedLocationSource(this, LOCATION_PERMISSION_REQUEST_CODE) + naverMap.locationOverlay.isVisible = true + getLastKnownLocation() + } + + private fun getLastKnownLocation() { + if (ContextCompat.checkSelfPermission( + requireContext(), + Manifest.permission.ACCESS_FINE_LOCATION + ) != PackageManager.PERMISSION_GRANTED + ) { + //ActivityCompat.requestPermissions(requireActivity(), PERMISSIONS, LOCATION_PERMISSION_REQUEST_CODE) + return + } + fusedLocationClient.lastLocation + .addOnSuccessListener { location -> + if (location != null) { + val latLng = LatLng(location.latitude, location.longitude) + naverMap.locationOverlay.position = latLng + naverMap.moveCamera(CameraUpdate.scrollTo(latLng)) + getAddress(location.latitude, location.longitude) + } else { + } + } + .addOnFailureListener { exception -> + Log.d("getLastKnownLocation", exception.message.toString()) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationActivity.kt similarity index 96% rename from app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationActivity.kt rename to app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationActivity.kt index cfd4ae60..976be665 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationActivity.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationActivity.kt @@ -1,4 +1,4 @@ -package com.umc.ttoklip.presentation.hometown.tradelocation +package com.umc.ttoklip.presentation.hometown.together.write.tradelocation import android.content.Intent import android.view.View diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationFragment.kt similarity index 85% rename from app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationFragment.kt rename to app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationFragment.kt index e3161f4c..3ccec46f 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationFragment.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationFragment.kt @@ -1,6 +1,7 @@ -package com.umc.ttoklip.presentation.hometown.tradelocation +package com.umc.ttoklip.presentation.hometown.together.write.tradelocation import android.content.Intent +import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.LinearLayoutManager import com.umc.ttoklip.R @@ -11,6 +12,8 @@ import com.umc.ttoklip.presentation.hometown.adapter.OnRecentPlaceClickListener import com.umc.ttoklip.presentation.hometown.adapter.RecentPlace import com.umc.ttoklip.presentation.hometown.adapter.RecentlyUsedPlaceAdapter import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherActivity +import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModel +import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModelImpl import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint @@ -22,6 +25,7 @@ class TradeLocationFragment: BaseFragment(R.layout private val navigator by lazy { findNavController() } + private val viewModel: WriteTogetherViewModel by activityViewModels() override fun initObserver() { } diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationViewModel.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationViewModel.kt similarity index 83% rename from app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationViewModel.kt rename to app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationViewModel.kt index 5be45b2f..a1785612 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/TradeLocationViewModel.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationViewModel.kt @@ -1,4 +1,4 @@ -package com.umc.ttoklip.presentation.hometown.tradelocation +package com.umc.ttoklip.presentation.hometown.together.write.tradelocation import androidx.lifecycle.ViewModel import com.umc.ttoklip.data.repository.naver.NaverRepository diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/PlaceFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/PlaceFragment.kt deleted file mode 100644 index 36948794..00000000 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/tradelocation/PlaceFragment.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.umc.ttoklip.presentation.hometown.tradelocation - -import com.umc.ttoklip.R -import com.umc.ttoklip.databinding.FragmentPlaceBinding -import com.umc.ttoklip.presentation.base.BaseFragment -import dagger.hilt.android.AndroidEntryPoint - -@AndroidEntryPoint -class PlaceFragment: BaseFragment(R.layout.fragment_place) { - override fun initObserver() { - - } - - override fun initView() { - - } -} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_place.xml b/app/src/main/res/layout/activity_place.xml index 3eca6a62..fb1033d5 100644 --- a/app/src/main/res/layout/activity_place.xml +++ b/app/src/main/res/layout/activity_place.xml @@ -13,8 +13,8 @@ android:name="com.naver.maps.map.MapFragment" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginTop="56dp" - android:background="@color/gray40" /> + app:navermap_locationButtonEnabled="true" + android:layout_marginTop="56dp" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_place.xml b/app/src/main/res/layout/fragment_place.xml index 3eca6a62..63f7eba3 100644 --- a/app/src/main/res/layout/fragment_place.xml +++ b/app/src/main/res/layout/fragment_place.xml @@ -2,6 +2,12 @@ + + + + @@ -34,7 +39,7 @@ android:layout_height="wrap_content" android:background="@color/white" android:text="거래희망 장소" - android:textAppearance="@style/TextAppearance.App.20sp_600" + android:textAppearance="@style/TextAppearance.App.16sp_600" app:layout_constraintBottom_toBottomOf="@id/location_back_ib" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -64,7 +69,7 @@ android:layout_height="wrap_content" android:layout_marginStart="30dp" android:layout_marginTop="30dp" - android:text="우리동네" + android:text="@{viewModel.address}" android:textAppearance="@style/TextAppearance.App.16sp_600" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/navigation/trade_location_graph.xml b/app/src/main/res/navigation/trade_location_graph.xml index 83f992c0..c5bc9a01 100644 --- a/app/src/main/res/navigation/trade_location_graph.xml +++ b/app/src/main/res/navigation/trade_location_graph.xml @@ -6,7 +6,7 @@ + android:name="com.umc.ttoklip.presentation.hometown.together.write.tradelocation.PlaceFragment" + android:label="PlaceFragment" > + + + \ No newline at end of file From 3057c29c25ab404996e13d6d89bda8c21d951201 Mon Sep 17 00:00:00 2001 From: KKJ Date: Thu, 27 Jun 2024 02:24:53 +0900 Subject: [PATCH 4/8] =?UTF-8?q?refactor:=20=EA=B1=B0=EB=9E=98=20=EC=9E=A5?= =?UTF-8?q?=EC=86=8C=20=EC=84=A4=EC=A0=95=20=EC=9D=B4=ED=9B=84=20=EA=B8=80?= =?UTF-8?q?=EC=93=B0=EA=B8=B0=20=ED=99=94=EB=A9=B4=EC=97=90=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=ED=95=9C=20=EC=A3=BC=EC=86=8C=20=ED=91=9C=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../together/write/WriteTogetherViewModelImpl.kt | 9 ++++++++- .../write/tradelocation/AddressDetailFragment.kt | 1 + .../together/write/tradelocation/PlaceFragment.kt | 4 ++-- app/src/main/res/layout/fragment_addres_detail.xml | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) 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 27c4f64a..f85ea0fc 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,12 +91,19 @@ class WriteTogetherViewModelImpl @Inject constructor( } override fun setAddress(address: String) { + if (address.isEmpty()){ + return + } _address.value = address - Log.d("address set", this.address.value.toString()) + _dealPlace.value = address } override fun setAddressDetail(addressDetail: String) { + if(addressDetail.isEmpty()){ + return + } _addressDetail.value = addressDetail + _dealPlace.value += "($addressDetail)" } 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 563cac65..253de840 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 @@ -35,6 +35,7 @@ class AddressDetailFragment: BaseFragment(R.layout. binding.viewModel = viewModel binding.locationNextBtn.setOnClickListener { + viewModel.setAddressDetail(binding.inputTradeLocationEt.text.toString()) navigator.popBackStack(R.id.writeTogetherFragment, false) } binding.gpsBaseSettingFrame.setOnClickListener { diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt index a50cabc5..ac751a86 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt @@ -162,8 +162,8 @@ class PlaceFragment : BaseFragment(R.layout.fragment_place Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED ) { - //ActivityCompat.requestPermissions(requireActivity(), PERMISSIONS, LOCATION_PERMISSION_REQUEST_CODE) - return + ActivityCompat.requestPermissions(requireActivity(), PERMISSIONS, LOCATION_PERMISSION_REQUEST_CODE) + getLastKnownLocation() } fusedLocationClient.lastLocation .addOnSuccessListener { location -> diff --git a/app/src/main/res/layout/fragment_addres_detail.xml b/app/src/main/res/layout/fragment_addres_detail.xml index 86e3e682..ccfcbbdb 100644 --- a/app/src/main/res/layout/fragment_addres_detail.xml +++ b/app/src/main/res/layout/fragment_addres_detail.xml @@ -89,7 +89,7 @@ + app:layout_constraintTop_toBottomOf="@+id/input_trade_location_et" /> \ No newline at end of file From be27677626bff7400eb22342964a599c457465de Mon Sep 17 00:00:00 2001 From: KKJ Date: Thu, 27 Jun 2024 02:49:18 +0900 Subject: [PATCH 5/8] =?UTF-8?q?feat:=20=EC=A3=BC=EC=86=8C=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=20=EC=97=AC=EB=B6=80=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=EB=90=9C=20=EC=A3=BC=EC=86=8C=20visibility?= =?UTF-8?q?=20=EC=A0=9C=EC=96=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../together/write/tradelocation/PlaceFragment.kt | 6 ++++-- .../write/tradelocation/TradeLocationFragment.kt | 1 + .../main/java/com/umc/ttoklip/util/BindAdapter.kt | 11 +++++++++++ .../main/res/layout/fragment_trade_location.xml | 14 ++++++++------ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt index ac751a86..bb33c578 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt @@ -34,6 +34,7 @@ import com.umc.ttoklip.presentation.hometown.AddressDetailActivity import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModel import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModelImpl import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.delay import kotlinx.coroutines.launch import java.util.Locale @@ -79,9 +80,9 @@ class PlaceFragment : BaseFragment(R.layout.fragment_place binding.locationTitleTv.text = getString(R.string.my_hometown_address_title) }*/ fusedLocationClient = LocationServices.getFusedLocationProviderClient(requireActivity()) - if (!hasPermission()) { + /*if (!hasPermission()) { ActivityCompat.requestPermissions(requireActivity(), PERMISSIONS, LOCATION_PERMISSION_REQUEST_CODE) - } + }*/ initMapView() binding.locationNextBtn.setOnClickListener { @@ -164,6 +165,7 @@ class PlaceFragment : BaseFragment(R.layout.fragment_place ) { ActivityCompat.requestPermissions(requireActivity(), PERMISSIONS, LOCATION_PERMISSION_REQUEST_CODE) getLastKnownLocation() + return } fusedLocationClient.lastLocation .addOnSuccessListener { location -> diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationFragment.kt index 3ccec46f..afe8e705 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationFragment.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationFragment.kt @@ -31,6 +31,7 @@ class TradeLocationFragment: BaseFragment(R.layout } override fun initView() { + binding.viewModel = viewModel binding.backBtn.setOnClickListener { val intent = Intent(requireContext(), WriteTogetherActivity::class.java) intent.putExtra("address", binding.tradeLocationTv.text.toString()) 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 70454dec..f079b239 100644 --- a/app/src/main/java/com/umc/ttoklip/util/BindAdapter.kt +++ b/app/src/main/java/com/umc/ttoklip/util/BindAdapter.kt @@ -3,10 +3,12 @@ package com.umc.ttoklip.util import android.annotation.SuppressLint import android.graphics.Typeface import android.graphics.drawable.Drawable +import android.view.View import android.widget.ImageView import android.widget.TextView import androidx.annotation.StyleRes import androidx.appcompat.widget.AppCompatTextView +import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.view.isVisible import androidx.databinding.BindingAdapter import com.bumptech.glide.Glide @@ -66,4 +68,13 @@ fun TextView.setCancelJoinBtnVisible(joinState: Boolean, isDeadLine: Boolean) { } else { !joinState } +} + +@BindingAdapter("bind:isAddressEmpty") +fun ConstraintLayout.setLayoutVisible(address: String){ + this.visibility = if (address.isEmpty()){ + View.GONE + } else { + View.VISIBLE + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_trade_location.xml b/app/src/main/res/layout/fragment_trade_location.xml index 0d798e95..b92df0b2 100644 --- a/app/src/main/res/layout/fragment_trade_location.xml +++ b/app/src/main/res/layout/fragment_trade_location.xml @@ -1,10 +1,13 @@ + xmlns:tools="http://schemas.android.com/tools" + xmlns:bind="http://schemas.android.com/apk/res-auto"> - + Date: Sat, 29 Jun 2024 18:06:26 +0900 Subject: [PATCH 6/8] =?UTF-8?q?feat:=20=EA=B1=B0=EB=9E=98=20=EC=9E=A5?= =?UTF-8?q?=EC=86=8C=20=EC=84=A4=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../data/model/naver/GeocodingResponse.kt | 2 +- .../ttoklip/presentation/home/HomeFragment.kt | 1 - .../presentation/home/HomeViewModel.kt | 2 +- .../presentation/home/HomeViewModelImpl.kt | 11 +----- .../together/write/WriteTogetherViewModel.kt | 10 ++++- .../write/WriteTogetherViewModelImpl.kt | 32 ++++++++++++++++ .../write/tradelocation/PlaceFragment.kt | 38 ++++++++++++++++++- .../java/com/umc/ttoklip/util/Extension.kt | 14 +++++++ app/src/main/res/layout/fragment_place.xml | 24 +++++++----- 10 files changed, 110 insertions(+), 26 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 23ce2add..e510cb0c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -117,7 +117,7 @@ , val errorMessage: String ) diff --git a/app/src/main/java/com/umc/ttoklip/presentation/home/HomeFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/home/HomeFragment.kt index a1c4668d..9b23b4f9 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/home/HomeFragment.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/home/HomeFragment.kt @@ -96,7 +96,6 @@ class HomeFragment : BaseFragment(R.layout.fragment_home), binding.vm = viewModel binding.tipRV.adapter = tipRVA viewModel.getMain() - viewModel.fetchGeocoding("분당구 불정로 6") Log.d("엑세스", "${TtoklipApplication.prefs.getString("jwt", "")}") CoroutineScope(Dispatchers.IO).launch { diff --git a/app/src/main/java/com/umc/ttoklip/presentation/home/HomeViewModel.kt b/app/src/main/java/com/umc/ttoklip/presentation/home/HomeViewModel.kt index a8d9528e..bc5ae7b5 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/home/HomeViewModel.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/home/HomeViewModel.kt @@ -20,7 +20,7 @@ interface HomeViewModel { fun getMain() fun patchFCM(token: String) - fun fetchGeocoding(query: String) + enum class ActivityEventBus { SEARCH, diff --git a/app/src/main/java/com/umc/ttoklip/presentation/home/HomeViewModelImpl.kt b/app/src/main/java/com/umc/ttoklip/presentation/home/HomeViewModelImpl.kt index a55b84d6..7068cb0f 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/home/HomeViewModelImpl.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/home/HomeViewModelImpl.kt @@ -28,8 +28,7 @@ import javax.inject.Inject @HiltViewModel class HomeViewModelImpl @Inject constructor( private val homeRepository: HomeRepository, - private val fcmRepository: FCMRepository, - private val naverRepository: NaverRepository + private val fcmRepository: FCMRepository ) : ViewModel(), HomeViewModel { private val _haveWork: MutableStateFlow = MutableStateFlow(true) @@ -126,12 +125,4 @@ class HomeViewModelImpl @Inject constructor( } } } - - override fun fetchGeocoding(query: String) { - viewModelScope.launch { - naverRepository.fetchGeocoding(query).onSuccess { - Log.d("naver", it.toString()) - } - } - } } \ No newline at end of file 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 2342117e..dc17cf21 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 @@ -1,7 +1,9 @@ package com.umc.ttoklip.presentation.hometown.together.write +import com.naver.maps.geometry.LatLng +import com.umc.ttoklip.data.model.naver.GeocodingResponse import com.umc.ttoklip.presentation.honeytip.adapter.Image -import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow interface WriteTogetherViewModel { @@ -19,6 +21,8 @@ interface WriteTogetherViewModel { val postId: StateFlow val address: StateFlow val addressDetail: StateFlow + val isInputComplete: StateFlow + val latLng: SharedFlow fun setTotalPrice(totalPrice: Long) fun setTotalMember(totalMember: Long) @@ -26,8 +30,12 @@ interface WriteTogetherViewModel { fun setAddress(address: String) fun setAddressDetail(addressDetail: String) + + fun setIsInputComplete() fun addImages(images: List) fun checkDone() fun doneButtonClick() fun writeTogether() + + fun fetchGeocoding(query: String) } \ No newline at end of file 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 f85ea0fc..4fa22c5c 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 @@ -4,15 +4,21 @@ import android.content.Context import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.naver.maps.geometry.LatLng +import com.umc.ttoklip.data.model.naver.GeocodingResponse import com.umc.ttoklip.data.model.town.CreateTogethersRequest +import com.umc.ttoklip.data.repository.naver.NaverRepository import com.umc.ttoklip.data.repository.town.WriteTogetherRepository import com.umc.ttoklip.module.onError +import com.umc.ttoklip.module.onException import com.umc.ttoklip.module.onSuccess import com.umc.ttoklip.presentation.honeytip.adapter.Image import com.umc.ttoklip.util.WriteHoneyTipUtil import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext +import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch @@ -21,6 +27,7 @@ import javax.inject.Inject @HiltViewModel class WriteTogetherViewModelImpl @Inject constructor( private val repository: WriteTogetherRepository, + private val naverRepository: NaverRepository, @ApplicationContext private val context: Context ) : ViewModel(), WriteTogetherViewModel { @@ -80,6 +87,13 @@ class WriteTogetherViewModelImpl @Inject constructor( override val addressDetail: StateFlow get() = _addressDetail + private val _isInputComplete = MutableStateFlow(false) + override val isInputComplete: StateFlow + get() = _isInputComplete + + private val _latLng = MutableSharedFlow() + override val latLng: SharedFlow + get() = _latLng override fun setTotalPrice(totalPrice: Long) { _totalPrice.value = totalPrice @@ -106,6 +120,10 @@ class WriteTogetherViewModelImpl @Inject constructor( _dealPlace.value += "($addressDetail)" } + override fun setIsInputComplete() { + _isInputComplete.value = _isInputComplete.value.not() + } + override fun addImages(images: List) { val combined = _images.value + images @@ -146,4 +164,18 @@ class WriteTogetherViewModelImpl @Inject constructor( } } + override fun fetchGeocoding(query: String) { + viewModelScope.launch { + naverRepository.fetchGeocoding(query).onSuccess {response -> + with(response.addresses.first()){ + val latLng = LatLng(y.toDouble(), x.toDouble()) + _latLng.emit(latLng) + setAddress(query) + } + Log.d("naver", response.toString()) + }.onException { + Log.d("error", it.toString()) + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt index bb33c578..e3d64621 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt @@ -33,6 +33,8 @@ import com.umc.ttoklip.presentation.base.BaseFragment import com.umc.ttoklip.presentation.hometown.AddressDetailActivity import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModel import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModelImpl +import com.umc.ttoklip.util.showKeyboard +import com.umc.ttoklip.util.showToast import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.delay import kotlinx.coroutines.launch @@ -55,6 +57,7 @@ class PlaceFragment : BaseFragment(R.layout.fragment_place } private lateinit var fusedLocationClient: FusedLocationProviderClient private val viewModel: WriteTogetherViewModel by activityViewModels() + private var isInputComplete = false /*private val activityResultLauncher: ActivityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { @@ -90,12 +93,26 @@ class PlaceFragment : BaseFragment(R.layout.fragment_place intent.putExtra("place", "town") intent.putExtra("address", address) activityResultLauncher.launch(intent)*/ - navigator.navigate(R.id.addressDetailFragment) + if(isInputComplete){ + showToast("먼저 위치확인을 해주세요") + } else { + navigator.navigate(R.id.addressDetailFragment) + } } binding.locationBackIb.setOnClickListener { navigator.navigateUp() } + + binding.additionalAddressBtn.setOnClickListener { + if(!isInputComplete) { + binding.currentLocationTv.showKeyboard() + binding.currentLocationTv.setSelection(binding.currentLocationTv.text.length) + } else { + viewModel.fetchGeocoding(binding.currentLocationTv.text.toString()) + } + viewModel.setIsInputComplete() + } } override fun initObserver() { @@ -106,6 +123,25 @@ class PlaceFragment : BaseFragment(R.layout.fragment_place } } } + + lifecycleScope.launch{ + repeatOnLifecycle(Lifecycle.State.STARTED){ + viewModel.isInputComplete.collect{ + isInputComplete = it + } + } + } + + lifecycleScope.launch{ + repeatOnLifecycle(Lifecycle.State.STARTED){ + viewModel.latLng.collect {latLng -> + Log.d("latLng", latLng.toString()) + naverMap.locationOverlay.position = latLng + naverMap.moveCamera(CameraUpdate.scrollTo(latLng)) + } + } + } + } private fun initMapView() { diff --git a/app/src/main/java/com/umc/ttoklip/util/Extension.kt b/app/src/main/java/com/umc/ttoklip/util/Extension.kt index 2e983546..1b581b4b 100644 --- a/app/src/main/java/com/umc/ttoklip/util/Extension.kt +++ b/app/src/main/java/com/umc/ttoklip/util/Extension.kt @@ -3,6 +3,10 @@ package com.umc.ttoklip.util import android.content.Context import android.net.Uri import android.provider.OpenableColumns +import android.view.inputmethod.InputMethodManager +import android.widget.EditText +import android.widget.Toast +import androidx.fragment.app.Fragment import java.io.File import java.io.FileOutputStream @@ -34,4 +38,14 @@ fun Context.getFileName(uri: Uri): String { } } return result ?: "unknown" +} + +fun EditText.showKeyboard(){ + this.requestFocus() + val inputMethodManager = this.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + inputMethodManager.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT) +} + +fun Fragment.showToast(text: String){ + Toast.makeText(requireContext(), text, Toast.LENGTH_SHORT).show() } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_place.xml b/app/src/main/res/layout/fragment_place.xml index 63f7eba3..bb3bbddb 100644 --- a/app/src/main/res/layout/fragment_place.xml +++ b/app/src/main/res/layout/fragment_place.xml @@ -63,36 +63,40 @@ android:paddingBottom="32dp" app:layout_constraintBottom_toBottomOf="parent"> - + android:textColor="@{viewModel.isInputComplete ? @color/black : @color/gray80}" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintBaseline_toBaselineOf="@id/current_location_tv" /> + app:layout_constraintTop_toBottomOf="@+id/current_location_tv" /> From 440309d0ac4b8419a171dd5b81fbff89c5d5e43d Mon Sep 17 00:00:00 2001 From: KKJ Date: Sat, 29 Jun 2024 18:29:58 +0900 Subject: [PATCH 7/8] =?UTF-8?q?feat:=20=EA=B1=B0=EB=9E=98=20=EC=9E=A5?= =?UTF-8?q?=EC=86=8C=20=EC=84=A4=EC=A0=95=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hometown/AddressDetailActivity.kt | 37 ---- .../presentation/hometown/PlaceActivity.kt | 134 -------------- .../together/write/WriteTogetherActivity.kt | 25 --- .../together/write/WriteTogetherFragment.kt | 10 -- .../together/write/WriteTogetherViewModel.kt | 13 +- .../write/WriteTogetherViewModelImpl.kt | 29 +++- .../write/tradelocation/PlaceFragment.kt | 69 ++------ .../tradelocation/TradeLocationActivity.kt | 62 ------- .../tradelocation/TradeLocationFragment.kt | 13 +- .../tradelocation/TradeLocationViewModel.kt | 14 -- .../res/layout/activity_trade_location.xml | 163 ------------------ 11 files changed, 57 insertions(+), 512 deletions(-) delete mode 100644 app/src/main/java/com/umc/ttoklip/presentation/hometown/AddressDetailActivity.kt delete mode 100644 app/src/main/java/com/umc/ttoklip/presentation/hometown/PlaceActivity.kt delete mode 100644 app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationActivity.kt delete mode 100644 app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationViewModel.kt delete mode 100644 app/src/main/res/layout/activity_trade_location.xml diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/AddressDetailActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/AddressDetailActivity.kt deleted file mode 100644 index c61e2742..00000000 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/AddressDetailActivity.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.umc.ttoklip.presentation.hometown - -import android.content.Intent -import androidx.navigation.findNavController -import com.umc.ttoklip.R -import com.umc.ttoklip.databinding.ActivityAddressDetailBinding -import com.umc.ttoklip.presentation.base.BaseActivity -import dagger.hilt.android.AndroidEntryPoint - -@AndroidEntryPoint -class AddressDetailActivity : - BaseActivity(R.layout.activity_address_detail) { - override fun initView() { - val type = intent.getStringExtra("place") - val address = intent.getStringExtra("address") - address?.let { - binding.dealPlaceTv.text = address - } - type?.let { - binding.titleTv.text = getString(R.string.my_hometown_address_title) - } - binding.locationNextBtn.setOnClickListener { - val intent = Intent(this, PlaceActivity::class.java) - intent.putExtra("address", address) - intent.putExtra("addressDetail", binding.inputTradeLocationTv.text.toString()) - setResult(1, intent) - finish() - } - binding.gpsBaseSettingFrame.setOnClickListener { - - } - } - - override fun initObserver() { - - } -} \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/PlaceActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/PlaceActivity.kt deleted file mode 100644 index 13501ca1..00000000 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/PlaceActivity.kt +++ /dev/null @@ -1,134 +0,0 @@ -package com.umc.ttoklip.presentation.hometown - -import android.Manifest -import android.content.Intent -import android.content.pm.PackageManager -import android.location.Address -import android.location.Geocoder -import android.os.Build -import androidx.activity.result.ActivityResultLauncher -import androidx.activity.result.contract.ActivityResultContracts -import androidx.core.app.ActivityCompat -import androidx.core.content.ContextCompat -import com.naver.maps.map.LocationTrackingMode -import com.naver.maps.map.MapFragment -import com.naver.maps.map.NaverMap -import com.naver.maps.map.OnMapReadyCallback -import com.naver.maps.map.util.FusedLocationSource -import com.umc.ttoklip.R -import com.umc.ttoklip.databinding.ActivityPlaceBinding -import com.umc.ttoklip.presentation.base.BaseActivity -import com.umc.ttoklip.presentation.hometown.together.write.tradelocation.TradeLocationActivity -import dagger.hilt.android.AndroidEntryPoint -import java.util.Locale - -@AndroidEntryPoint -class PlaceActivity : BaseActivity(R.layout.activity_place), - OnMapReadyCallback { - private var type = "" - private lateinit var naverMap: NaverMap - private var address: String = "" - private val LOCATION_PERMISSION_REQUEST_CODE: Int = 5000 - private val PERMISSIONS = arrayOf( - Manifest.permission.ACCESS_FINE_LOCATION, - Manifest.permission.ACCESS_COARSE_LOCATION - ) - private var locationok: Boolean = false - - private val activityResultLauncher: ActivityResultLauncher = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { - val addressIntent = it.data - addressIntent?.let { aIntent -> - val address = aIntent.getStringExtra("address") - val addressDetail = aIntent.getStringExtra("addressDetail") - if (address != null) { - val lIntent = Intent(this, TradeLocationActivity::class.java) - lIntent.putExtra("address", address) - lIntent.putExtra("addressDetail", addressDetail) - setResult(1, lIntent) - finish() - } - - } - } - - override fun initView() { - intent.getStringExtra("place")?.let { - type = it - binding.locationTitleTv.text = getString(R.string.my_hometown_address_title) - } - if (!hasPermission()) { - ActivityCompat.requestPermissions(this, PERMISSIONS, LOCATION_PERMISSION_REQUEST_CODE) - } - initMapView() - - binding.locationNextBtn.setOnClickListener { - val intent = Intent(this, AddressDetailActivity::class.java) - intent.putExtra("place", "town") - intent.putExtra("address", address) - activityResultLauncher.launch(intent) - } - } - - override fun initObserver() { - - } - - private fun initMapView() { - val fm = supportFragmentManager - val mapFragment = fm.findFragmentById(R.id.location_map) as MapFragment? - ?: MapFragment.newInstance().also { - fm.beginTransaction().add(R.id.location_map, it).commit() - } - mapFragment.getMapAsync(this) - } - - private fun getAddress(latitude: Double, longitude: Double) { - val geocoder = Geocoder(applicationContext, Locale.KOREAN) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - val addressList: List
? = geocoder.getFromLocation(latitude, longitude, 1) - if (addressList != null && addressList.isNotEmpty()) { - val address: Address = addressList[0] - val spliteAddr = address.getAddressLine(0).split(" ") - this.address = spliteAddr[1] + " " + spliteAddr[2] + " " + spliteAddr[3] - } - } else { - val addresses = geocoder.getFromLocation(latitude, longitude, 1) - if (addresses != null) { - val spliteAddr = addresses[0].getAddressLine(0).split(" ") - this.address = spliteAddr[1] + " " + spliteAddr[2] + " " + spliteAddr[3] - } - } - binding.currentLocationTv.text = address - } - - private fun hasPermission(): Boolean { - for (permission in PERMISSIONS) { - if (ContextCompat.checkSelfPermission(this, permission) - != PackageManager.PERMISSION_GRANTED - ) { - return false - } - } - return true - } - - override fun onMapReady(p0: NaverMap) { - this.naverMap = p0 - binding.locationNowLocation.map = naverMap - -// locationSource = - naverMap.locationSource = FusedLocationSource(this, LOCATION_PERMISSION_REQUEST_CODE) - naverMap.locationTrackingMode = LocationTrackingMode.Follow -// naverMap.locationOverlay.subIcon = -// OverlayImage.fromResource(com.naver.maps.map.R.drawable.navermap_location_overlay_icon) - - naverMap.addOnLocationChangeListener { - getAddress( - it.latitude, - it.longitude - ) - locationok = true - } - } -} \ No newline at end of file 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 946febab..5718a106 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 @@ -1,42 +1,17 @@ package com.umc.ttoklip.presentation.hometown.together.write import android.content.Context -import android.content.Intent -import android.graphics.PorterDuff -import android.graphics.PorterDuffColorFilter import android.graphics.Rect -import android.icu.text.DecimalFormat -import android.net.Uri -import android.text.Editable -import android.text.TextUtils -import android.text.TextWatcher -import android.util.Log import android.view.MotionEvent -import android.view.View import android.view.inputmethod.InputMethodManager import android.widget.EditText -import androidx.activity.result.ActivityResultLauncher -import androidx.activity.result.PickVisualMediaRequest -import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels -import androidx.fragment.app.viewModels -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.lifecycleScope -import androidx.lifecycle.repeatOnLifecycle import androidx.navigation.NavController import androidx.navigation.fragment.NavHostFragment import com.umc.ttoklip.R import com.umc.ttoklip.databinding.ActivityWriteTogetherBinding import com.umc.ttoklip.presentation.base.BaseActivity -import com.umc.ttoklip.presentation.hometown.together.write.tradelocation.TradeLocationActivity -import com.umc.ttoklip.presentation.hometown.dialog.InputMaxMemberDialogFragment -import com.umc.ttoklip.presentation.hometown.dialog.TogetherDialog -import com.umc.ttoklip.presentation.honeytip.adapter.Image -import com.umc.ttoklip.presentation.honeytip.adapter.ImageRVA -import com.umc.ttoklip.presentation.dialog.ImageDialogFragment -import com.umc.ttoklip.presentation.hometown.together.read.ReadTogetherActivity import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch @AndroidEntryPoint class WriteTogetherActivity : diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherFragment.kt index 1fcabe8b..afe99707 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherFragment.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherFragment.kt @@ -1,26 +1,17 @@ package com.umc.ttoklip.presentation.hometown.together.write -import android.content.Context -import android.content.Intent import android.graphics.PorterDuff import android.graphics.PorterDuffColorFilter -import android.graphics.Rect import android.icu.text.DecimalFormat import android.net.Uri import android.text.Editable import android.text.TextUtils import android.text.TextWatcher import android.util.Log -import android.view.MotionEvent import android.view.View -import android.view.ViewGroup -import android.view.inputmethod.InputMethodManager -import android.widget.EditText import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts -import androidx.activity.viewModels import androidx.fragment.app.activityViewModels -import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle @@ -32,7 +23,6 @@ import com.umc.ttoklip.presentation.dialog.ImageDialogFragment import com.umc.ttoklip.presentation.hometown.dialog.InputMaxMemberDialogFragment import com.umc.ttoklip.presentation.hometown.dialog.TogetherDialog import com.umc.ttoklip.presentation.hometown.together.read.ReadTogetherActivity -import com.umc.ttoklip.presentation.hometown.together.write.tradelocation.TradeLocationActivity import com.umc.ttoklip.presentation.honeytip.adapter.Image import com.umc.ttoklip.presentation.honeytip.adapter.ImageRVA import dagger.hilt.android.AndroidEntryPoint 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 dc17cf21..b3ce1812 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 @@ -1,7 +1,6 @@ package com.umc.ttoklip.presentation.hometown.together.write import com.naver.maps.geometry.LatLng -import com.umc.ttoklip.data.model.naver.GeocodingResponse import com.umc.ttoklip.presentation.honeytip.adapter.Image import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow @@ -23,6 +22,16 @@ interface WriteTogetherViewModel { val addressDetail: StateFlow val isInputComplete: StateFlow val latLng: SharedFlow + val toast: StateFlow + val tradeLocationEvent: SharedFlow + + sealed class TradeLocationEvent{ + data class InputAddressComplete(val isInputComplete: Boolean): TradeLocationEvent() + + data class CheckLocation(val latLng: LatLng): TradeLocationEvent() + + data class ToastException(val text: String): TradeLocationEvent() + } fun setTotalPrice(totalPrice: Long) fun setTotalMember(totalMember: Long) @@ -38,4 +47,6 @@ interface WriteTogetherViewModel { fun writeTogether() fun fetchGeocoding(query: String) + + fun eventTradeLocation(event: TradeLocationEvent) } \ No newline at end of file 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 4fa22c5c..484de3f9 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 @@ -95,6 +95,14 @@ class WriteTogetherViewModelImpl @Inject constructor( 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 + override fun setTotalPrice(totalPrice: Long) { _totalPrice.value = totalPrice Log.d("set price", _totalPrice.value.toString()) @@ -122,6 +130,7 @@ class WriteTogetherViewModelImpl @Inject constructor( override fun setIsInputComplete() { _isInputComplete.value = _isInputComplete.value.not() + eventTradeLocation(WriteTogetherViewModel.TradeLocationEvent.InputAddressComplete(_isInputComplete.value)) } @@ -167,10 +176,16 @@ class WriteTogetherViewModelImpl @Inject constructor( override fun fetchGeocoding(query: String) { viewModelScope.launch { naverRepository.fetchGeocoding(query).onSuccess {response -> - with(response.addresses.first()){ - val latLng = LatLng(y.toDouble(), x.toDouble()) - _latLng.emit(latLng) - setAddress(query) + val result = response.addresses.firstOrNull() + if (result == null){ + eventTradeLocation(WriteTogetherViewModel.TradeLocationEvent.ToastException("주소를 정확히 입력해주세요.")) + return@launch + } else { + with(result) { + val latLng = LatLng(y.toDouble(), x.toDouble()) + eventTradeLocation(WriteTogetherViewModel.TradeLocationEvent.CheckLocation(latLng)) + setAddress(query) + } } Log.d("naver", response.toString()) }.onException { @@ -178,4 +193,10 @@ class WriteTogetherViewModelImpl @Inject constructor( } } } + + override fun eventTradeLocation(event: WriteTogetherViewModel.TradeLocationEvent) { + viewModelScope.launch { + _tradeLocationEvent.emit(event) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt index e3d64621..dbec89ad 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt @@ -1,14 +1,11 @@ package com.umc.ttoklip.presentation.hometown.together.write.tradelocation import android.Manifest -import android.content.Intent import android.content.pm.PackageManager import android.location.Address import android.location.Geocoder import android.os.Build import android.util.Log -import androidx.activity.result.ActivityResultLauncher -import androidx.activity.result.contract.ActivityResultContracts import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.fragment.app.activityViewModels @@ -20,23 +17,18 @@ import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices import com.naver.maps.geometry.LatLng import com.naver.maps.map.CameraUpdate -import com.naver.maps.map.LocationTrackingMode import com.naver.maps.map.MapFragment import com.naver.maps.map.NaverMap import com.naver.maps.map.OnMapReadyCallback -import com.naver.maps.map.overlay.LocationOverlay -import com.naver.maps.map.overlay.OverlayImage import com.naver.maps.map.util.FusedLocationSource import com.umc.ttoklip.R import com.umc.ttoklip.databinding.FragmentPlaceBinding import com.umc.ttoklip.presentation.base.BaseFragment -import com.umc.ttoklip.presentation.hometown.AddressDetailActivity import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModel import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModelImpl import com.umc.ttoklip.util.showKeyboard import com.umc.ttoklip.util.showToast import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.delay import kotlinx.coroutines.launch import java.util.Locale @@ -59,29 +51,8 @@ class PlaceFragment : BaseFragment(R.layout.fragment_place private val viewModel: WriteTogetherViewModel by activityViewModels() private var isInputComplete = false - /*private val activityResultLauncher: ActivityResultLauncher = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { - val addressIntent = it.data - addressIntent?.let { aIntent -> - val address = aIntent.getStringExtra("address") - val addressDetail = aIntent.getStringExtra("addressDetail") - if (address != null) { - val lIntent = Intent(this, TradeLocationActivity::class.java) - lIntent.putExtra("address", address) - lIntent.putExtra("addressDetail", addressDetail) - setResult(1, lIntent) - finish() - } - - } - }*/ - override fun initView() { binding.viewModel = viewModel - /*intent.getStringExtra("place")?.let { - type = it - binding.locationTitleTv.text = getString(R.string.my_hometown_address_title) - }*/ fusedLocationClient = LocationServices.getFusedLocationProviderClient(requireActivity()) /*if (!hasPermission()) { ActivityCompat.requestPermissions(requireActivity(), PERMISSIONS, LOCATION_PERMISSION_REQUEST_CODE) @@ -89,12 +60,8 @@ class PlaceFragment : BaseFragment(R.layout.fragment_place initMapView() binding.locationNextBtn.setOnClickListener { - /*val intent = Intent(requireContext(), AddressDetailActivity::class.java) - intent.putExtra("place", "town") - intent.putExtra("address", address) - activityResultLauncher.launch(intent)*/ if(isInputComplete){ - showToast("먼저 위치확인을 해주세요") + showToast("먼저 위치확인을 해주세요.") } else { navigator.navigate(R.id.addressDetailFragment) } @@ -116,32 +83,29 @@ class PlaceFragment : BaseFragment(R.layout.fragment_place } override fun initObserver() { - lifecycleScope.launch { - repeatOnLifecycle(Lifecycle.State.STARTED) { - viewModel.address.collect { - Log.d("address", it.toString()) - } - } - } - lifecycleScope.launch{ repeatOnLifecycle(Lifecycle.State.STARTED){ - viewModel.isInputComplete.collect{ - isInputComplete = it + viewModel.tradeLocationEvent.collect{ event -> + handleTradeLocationEvent(event) } } } - lifecycleScope.launch{ - repeatOnLifecycle(Lifecycle.State.STARTED){ - viewModel.latLng.collect {latLng -> - Log.d("latLng", latLng.toString()) - naverMap.locationOverlay.position = latLng - naverMap.moveCamera(CameraUpdate.scrollTo(latLng)) - } + } + + private fun handleTradeLocationEvent(event: WriteTogetherViewModel.TradeLocationEvent){ + when(event){ + is WriteTogetherViewModel.TradeLocationEvent.CheckLocation -> { + naverMap.locationOverlay.position = event.latLng + naverMap.moveCamera(CameraUpdate.scrollTo(event.latLng)) + } + is WriteTogetherViewModel.TradeLocationEvent.InputAddressComplete -> { + isInputComplete = event.isInputComplete + } + is WriteTogetherViewModel.TradeLocationEvent.ToastException -> { + showToast(event.text) } } - } private fun initMapView() { @@ -169,7 +133,6 @@ class PlaceFragment : BaseFragment(R.layout.fragment_place this.address = spliteAddr[1] + " " + spliteAddr[2] + " " + spliteAddr[3] } } - //binding.currentLocationTv.text = address viewModel.setAddress(address) } diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationActivity.kt deleted file mode 100644 index 976be665..00000000 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationActivity.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.umc.ttoklip.presentation.hometown.together.write.tradelocation - -import android.content.Intent -import android.view.View -import androidx.activity.result.ActivityResultLauncher -import androidx.activity.result.contract.ActivityResultContracts -import androidx.fragment.app.FragmentContainerView -import androidx.navigation.NavController -import androidx.navigation.fragment.NavHostFragment -import androidx.recyclerview.widget.LinearLayoutManager -import com.umc.ttoklip.R -import com.umc.ttoklip.databinding.ActivityTradeLocationBinding -import com.umc.ttoklip.presentation.base.BaseActivity -import com.umc.ttoklip.presentation.hometown.PlaceActivity -import com.umc.ttoklip.presentation.hometown.adapter.OnRecentPlaceClickListener -import com.umc.ttoklip.presentation.hometown.adapter.RecentPlace -import com.umc.ttoklip.presentation.hometown.adapter.RecentlyUsedPlaceAdapter -import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherActivity -import dagger.hilt.android.AndroidEntryPoint - -@AndroidEntryPoint -class TradeLocationActivity : - BaseActivity(R.layout.activity_trade_location), - OnRecentPlaceClickListener { - private lateinit var navController: NavController - /*private val adapter by lazy { - RecentlyUsedPlaceAdapter(this) - } - private val activityResultLauncher: ActivityResultLauncher = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { - val addressIntent = it.data - addressIntent?.let { aIntent -> - val address = aIntent.getStringExtra("address") - val addressDetail = aIntent.getStringExtra("addressDetail") - address?.let { place -> - binding.tradeLocationFrame.visibility = View.VISIBLE - binding.tradeLocationTv.text = place - addressDetail?.let { detail -> - binding.tradeLocationDetailTv.text = detail - } - } - - } - }*/ - - override fun initView() { - initNavigator() - } - - private fun initNavigator(){ - val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment - navController = navHostFragment.navController - } - - override fun initObserver() { - - } - - override fun onClick(items: RecentPlace) { - - } -} \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationFragment.kt index afe8e705..522e86fb 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationFragment.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationFragment.kt @@ -1,17 +1,14 @@ package com.umc.ttoklip.presentation.hometown.together.write.tradelocation -import android.content.Intent import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.LinearLayoutManager import com.umc.ttoklip.R import com.umc.ttoklip.databinding.FragmentTradeLocationBinding import com.umc.ttoklip.presentation.base.BaseFragment -import com.umc.ttoklip.presentation.hometown.PlaceActivity import com.umc.ttoklip.presentation.hometown.adapter.OnRecentPlaceClickListener import com.umc.ttoklip.presentation.hometown.adapter.RecentPlace import com.umc.ttoklip.presentation.hometown.adapter.RecentlyUsedPlaceAdapter -import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherActivity import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModel import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModelImpl import dagger.hilt.android.AndroidEntryPoint @@ -33,10 +30,6 @@ class TradeLocationFragment: BaseFragment(R.layout override fun initView() { binding.viewModel = viewModel binding.backBtn.setOnClickListener { - val intent = Intent(requireContext(), WriteTogetherActivity::class.java) - intent.putExtra("address", binding.tradeLocationTv.text.toString()) - intent.putExtra("addressDetail", binding.tradeLocationDetailTv.text.toString()) - //setResult(1, intent) navigator.navigateUp() } val places = listOf( @@ -50,8 +43,10 @@ class TradeLocationFragment: BaseFragment(R.layout binding.inputTradeLocationTv.setOnClickListener { navigator.navigate(R.id.action_tradeLocationFragment_to_placeFragment) - //val intent = Intent(this, PlaceActivity::class.java) - //activityResultLauncher.launch(intent) + } + + binding.tradeLocationFrame.setOnClickListener{ + navigator.navigateUp() } } diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationViewModel.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationViewModel.kt deleted file mode 100644 index a1785612..00000000 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationViewModel.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.umc.ttoklip.presentation.hometown.together.write.tradelocation - -import androidx.lifecycle.ViewModel -import com.umc.ttoklip.data.repository.naver.NaverRepository -import com.umc.ttoklip.data.repository.naver.NaverRepositoryImpl -import dagger.hilt.android.lifecycle.HiltViewModel -import javax.inject.Inject - -@HiltViewModel -class TradeLocationViewModel @Inject constructor( - private val repository: NaverRepository -) : ViewModel() { - -} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_trade_location.xml b/app/src/main/res/layout/activity_trade_location.xml deleted file mode 100644 index dc88cf98..00000000 --- a/app/src/main/res/layout/activity_trade_location.xml +++ /dev/null @@ -1,163 +0,0 @@ - - - - - - - - - - - \ No newline at end of file From e66ac2e8595e8c3d27bb22cf1f87aa359c1ce3aa Mon Sep 17 00:00:00 2001 From: KKJ Date: Tue, 2 Jul 2024 21:27:30 +0900 Subject: [PATCH 8/8] =?UTF-8?q?feat:=20=EA=B1=B0=EB=9E=98=20=ED=9D=AC?= =?UTF-8?q?=EB=A7=9D=20=EC=9E=A5=EC=86=8C=20=EC=84=A4=EC=A0=95=20=EC=9D=B4?= =?UTF-8?q?=ED=9B=84=20=EA=B3=B5=EA=B5=AC=20=EC=B5=9C=EB=8C=80=20=EC=9D=B8?= =?UTF-8?q?=EC=9B=90=20=EA=B0=92=20=EC=9C=A0=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../together/write/WriteTogetherActivity.kt | 256 ------------------ .../together/write/WriteTogetherViewModel.kt | 2 - .../write/WriteTogetherViewModelImpl.kt | 8 - .../tradelocation/AddressDetailFragment.kt | 7 - .../java/com/umc/ttoklip/util/BindAdapter.kt | 19 ++ .../res/layout/fragment_write_together.xml | 9 +- 6 files changed, 25 insertions(+), 276 deletions(-) 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}"/>