diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 85c6e9e5..e510cb0c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -117,7 +117,7 @@ diff --git a/app/src/main/java/com/umc/ttoklip/data/model/naver/GeocodingResponse.kt b/app/src/main/java/com/umc/ttoklip/data/model/naver/GeocodingResponse.kt index 63eb28cf..1eb1ec42 100644 --- a/app/src/main/java/com/umc/ttoklip/data/model/naver/GeocodingResponse.kt +++ b/app/src/main/java/com/umc/ttoklip/data/model/naver/GeocodingResponse.kt @@ -3,6 +3,6 @@ package com.umc.ttoklip.data.model.naver data class GeocodingResponse( val status: String, val meta: Meta, - val addresses: Addresses, + val addresses: List, 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 f436b8b2..6a13d93d 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/AddressDetailActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/AddressDetailActivity.kt deleted file mode 100644 index 89db0c91..00000000 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/AddressDetailActivity.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.umc.ttoklip.presentation.hometown - -import android.content.Intent -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 { - finish() - } - } - - 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 674f0240..00000000 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/PlaceActivity.kt +++ /dev/null @@ -1,133 +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 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/TradeLocationActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/TradeLocationActivity.kt deleted file mode 100644 index 9103616c..00000000 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/TradeLocationActivity.kt +++ /dev/null @@ -1,69 +0,0 @@ -package com.umc.ttoklip.presentation.hometown - -import android.content.Intent -import androidx.activity.result.ActivityResultLauncher -import androidx.activity.result.contract.ActivityResultContracts -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.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 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.tradeLocationTv.text = place - addressDetail?.let { detail -> - binding.tradeLocationDetailTv.text = detail - } - } - - } - } - - 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) - - binding.gpsBaseSettingFrame.setOnClickListener { - val intent = Intent(this, PlaceActivity::class.java) - activityResultLauncher.launch(intent) - } - } - - 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/WriteTogetherActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherActivity.kt index a1cdb213..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 @@ -1,279 +1,23 @@ 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.EditorInfo 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.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.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 = - 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 lateinit var navController: NavController 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) { @@ -291,8 +35,16 @@ class WriteTogetherActivity : } return super.dispatchTouchEvent(event) } + override fun initView() { + initNavigator() + } + + override fun initObserver() { + + } - companion object { - private val AMOUNT_FORMAT = DecimalFormat("#,###") + 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..afe99707 --- /dev/null +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherFragment.kt @@ -0,0 +1,255 @@ +package com.umc.ttoklip.presentation.hometown.together.write + +import android.graphics.PorterDuff +import android.graphics.PorterDuffColorFilter +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.View +import androidx.activity.result.PickVisualMediaRequest +import androidx.activity.result.contract.ActivityResultContracts +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.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.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 activityViewModels() + + 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) + } + } + + 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) + } + + 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/together/write/WriteTogetherViewModel.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/WriteTogetherViewModel.kt index 321a98bb..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 @@ -1,7 +1,8 @@ package com.umc.ttoklip.presentation.hometown.together.write +import com.naver.maps.geometry.LatLng 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 { @@ -17,11 +18,33 @@ interface WriteTogetherViewModel { val closePage: StateFlow val images: StateFlow> val postId: StateFlow + val address: StateFlow + val addressDetail: StateFlow + val isInputComplete: 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) + + fun setAddress(address: String) + + fun setAddressDetail(addressDetail: String) + + fun setIsInputComplete() fun addImages(images: List) fun checkDone() fun doneButtonClick() 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 6c1d7d79..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 @@ -4,22 +4,30 @@ 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 import javax.inject.Inject @HiltViewModel class WriteTogetherViewModelImpl @Inject constructor( private val repository: WriteTogetherRepository, + private val naverRepository: NaverRepository, @ApplicationContext private val context: Context ) : ViewModel(), WriteTogetherViewModel { @@ -71,6 +79,21 @@ 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 + + private val _isInputComplete = MutableStateFlow(false) + override val isInputComplete: StateFlow + get() = _isInputComplete + + private val _tradeLocationEvent = MutableSharedFlow() + override val tradeLocationEvent: SharedFlow + get() = _tradeLocationEvent override fun setTotalPrice(totalPrice: Long) { _totalPrice.value = totalPrice @@ -81,6 +104,27 @@ class WriteTogetherViewModelImpl @Inject constructor( _totalMember.value = totalMember } + override fun setAddress(address: String) { + if (address.isEmpty()){ + return + } + _address.value = address + _dealPlace.value = address + } + + override fun setAddressDetail(addressDetail: String) { + if(addressDetail.isEmpty()){ + return + } + _addressDetail.value = addressDetail + _dealPlace.value += "($addressDetail)" + } + + override fun setIsInputComplete() { + _isInputComplete.value = _isInputComplete.value.not() + eventTradeLocation(WriteTogetherViewModel.TradeLocationEvent.InputAddressComplete(_isInputComplete.value)) + } + override fun addImages(images: List) { val combined = _images.value + images @@ -121,4 +165,30 @@ class WriteTogetherViewModelImpl @Inject constructor( } } + override fun fetchGeocoding(query: String) { + viewModelScope.launch { + naverRepository.fetchGeocoding(query).onSuccess {response -> + 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 { + Log.d("error", it.toString()) + } + } + } + + 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/AddressDetailFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/AddressDetailFragment.kt new file mode 100644 index 00000000..9f8126ab --- /dev/null +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/AddressDetailFragment.kt @@ -0,0 +1,38 @@ +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() { + } + + override fun initView() { + binding.viewModel = viewModel + + binding.locationNextBtn.setOnClickListener { + viewModel.setAddressDetail(binding.inputTradeLocationEt.text.toString()) + 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..dbec89ad --- /dev/null +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/PlaceFragment.kt @@ -0,0 +1,183 @@ +package com.umc.ttoklip.presentation.hometown.together.write.tradelocation + +import android.Manifest +import android.content.pm.PackageManager +import android.location.Address +import android.location.Geocoder +import android.os.Build +import android.util.Log +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.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.FragmentPlaceBinding +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 com.umc.ttoklip.util.showKeyboard +import com.umc.ttoklip.util.showToast +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 var isInputComplete = false + + override fun initView() { + binding.viewModel = viewModel + fusedLocationClient = LocationServices.getFusedLocationProviderClient(requireActivity()) + /*if (!hasPermission()) { + ActivityCompat.requestPermissions(requireActivity(), PERMISSIONS, LOCATION_PERMISSION_REQUEST_CODE) + }*/ + initMapView() + + binding.locationNextBtn.setOnClickListener { + 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() { + lifecycleScope.launch{ + repeatOnLifecycle(Lifecycle.State.STARTED){ + viewModel.tradeLocationEvent.collect{ event -> + handleTradeLocationEvent(event) + } + } + } + + } + + 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() { + 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] + } + } + 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) + getLastKnownLocation() + 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/together/write/tradelocation/TradeLocationFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationFragment.kt new file mode 100644 index 00000000..522e86fb --- /dev/null +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/together/write/tradelocation/TradeLocationFragment.kt @@ -0,0 +1,56 @@ +package com.umc.ttoklip.presentation.hometown.together.write.tradelocation + +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.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.WriteTogetherViewModel +import com.umc.ttoklip.presentation.hometown.together.write.WriteTogetherViewModelImpl +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() + } + private val viewModel: WriteTogetherViewModel by activityViewModels() + override fun initObserver() { + + } + + override fun initView() { + binding.viewModel = viewModel + binding.backBtn.setOnClickListener { + 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) + } + + binding.tradeLocationFrame.setOnClickListener{ + navigator.navigateUp() + } + } + + override fun onClick(items: RecentPlace) { + + } +} \ No newline at end of file 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/java/com/umc/ttoklip/util/BindAdapter.kt b/app/src/main/java/com/umc/ttoklip/util/BindAdapter.kt index 70454dec..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,15 +1,21 @@ 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 import androidx.appcompat.widget.AppCompatTextView +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") @@ -66,4 +72,28 @@ 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 + } +} + +@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/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/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_addres_detail.xml b/app/src/main/res/layout/fragment_addres_detail.xml new file mode 100644 index 00000000..ccfcbbdb --- /dev/null +++ b/app/src/main/res/layout/fragment_addres_detail.xml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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..bb3bbddb --- /dev/null +++ b/app/src/main/res/layout/fragment_place.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_trade_location.xml b/app/src/main/res/layout/fragment_trade_location.xml similarity index 76% rename from app/src/main/res/layout/activity_trade_location.xml rename to app/src/main/res/layout/fragment_trade_location.xml index 196ae5fc..b92df0b2 100644 --- a/app/src/main/res/layout/activity_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"> - + + bind:isAddressEmpty="@{viewModel.address}" + app:layout_constraintTop_toBottomOf="@id/title_tv"> - - - - - - - - - + app:layout_constraintTop_toBottomOf="@id/set_trade_location_frame"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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..c5bc9a01 --- /dev/null +++ b/app/src/main/res/navigation/trade_location_graph.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + \ No newline at end of file