From 753861ceae72975764190b871200263dd1cdbe81 Mon Sep 17 00:00:00 2001 From: posite Date: Mon, 19 Feb 2024 21:15:00 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=EC=9A=B0=EB=A6=AC=EB=8F=99?= =?UTF-8?q?=EB=84=A4=20=EB=A9=94=EC=9D=B8=EC=9D=98=20=EC=A3=BC=EC=86=8C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=A1=9C=EC=A7=81=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 | 4 ++ .../hometown/MyHometownFragment.kt | 15 +++++++- .../presentation/hometown/PlaceActivity.kt | 6 +++ .../mypage/MyHometownAddressActivity.kt | 38 +++++++++++++++++++ .../layout/activity_my_homtown_address.xml | 1 + .../layout/fragment_bottom_dialog_search.xml | 33 +++++++++++++++- 6 files changed, 93 insertions(+), 4 deletions(-) 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 8727403d..89db0c91 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 @@ -10,10 +10,14 @@ import dagger.hilt.android.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) diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/MyHometownFragment.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/MyHometownFragment.kt index 24b9bcac..166f1b8c 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/MyHometownFragment.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/MyHometownFragment.kt @@ -2,6 +2,8 @@ package com.umc.ttoklip.presentation.hometown import android.content.Intent import android.util.Log +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.TtoklipApplication @@ -18,6 +20,16 @@ import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class MyHometownFragment : BaseFragment(R.layout.fragment_my_hometown), OnTogetherClickListener { + private val activityResultLauncher: ActivityResultLauncher = + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { + val addressIntent = it.data + addressIntent?.let { aIntent -> + val address = aIntent.getStringExtra("address") + address?.let { place -> + binding.myHometownFilterTv.text = address + } + } + } private val togetherAdapter by lazy { TogetherAdapter( this, @@ -54,8 +66,7 @@ class MyHometownFragment : BaseFragment(R.layout.frag } binding.myHometownFilterTv.setOnClickListener { val intent = Intent(requireContext(), MyHometownAddressActivity::class.java) - startActivity(intent) - true + activityResultLauncher.launch(intent) } binding.writeTogetherBtn.setOnClickListener { val intent = Intent(requireContext(), WriteTogetherActivity::class.java) 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 37615b51..674f0240 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 @@ -24,6 +24,7 @@ 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 @@ -51,6 +52,10 @@ class PlaceActivity : BaseActivity(R.layout.activity_place } 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) } @@ -58,6 +63,7 @@ class PlaceActivity : BaseActivity(R.layout.activity_place binding.locationNextBtn.setOnClickListener { val intent = Intent(this, AddressDetailActivity::class.java) + intent.putExtra("place", "town") intent.putExtra("address", address) activityResultLauncher.launch(intent) } diff --git a/app/src/main/java/com/umc/ttoklip/presentation/mypage/MyHometownAddressActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/mypage/MyHometownAddressActivity.kt index 315ef536..d8dbbc52 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/mypage/MyHometownAddressActivity.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/mypage/MyHometownAddressActivity.kt @@ -1,23 +1,61 @@ package com.umc.ttoklip.presentation.mypage +import android.content.Intent import android.widget.SeekBar +import androidx.activity.result.ActivityResultLauncher +import androidx.activity.result.contract.ActivityResultContracts import com.umc.ttoklip.R import com.umc.ttoklip.databinding.ActivityMyHomtownAddressBinding import com.umc.ttoklip.presentation.base.BaseActivity +import com.umc.ttoklip.presentation.hometown.MyHometownFragment +import com.umc.ttoklip.presentation.hometown.PlaceActivity import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class MyHometownAddressActivity : BaseActivity(R.layout.activity_my_homtown_address) { private lateinit var range: String + 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.currentPlaceTv.text = if (!addressDetail.isNullOrBlank()) { + StringBuilder().append(address).append(" (").append(addressDetail) + .append(")") + .toString() + } else { + StringBuilder().append(address).toString() + } + } + } + } + override fun initView() { range = getString(R.string.range_500m) + binding.gpsBaseSettingFrame.setOnClickListener { + val intent = Intent(this, PlaceActivity::class.java) + intent.putExtra("place", "town") + activityResultLauncher.launch(intent) + } binding.rangeSettingExplainTv.text = getString(R.string.range_setting_format, range) + binding.myHometownAddressBackBtn.setOnClickListener { + val intent = Intent(this, MyHometownFragment::class.java) + intent.putExtra("address", binding.currentPlaceTv.text.toString()) + setResult(1, intent) finish() } + binding.finishAddressBtn.setOnClickListener { + val intent = Intent(this, MyHometownFragment::class.java) + intent.putExtra("address", binding.currentPlaceTv.text.toString()) + setResult(1, intent) + finish() + } binding.range500mTv.setOnClickListener { setRange500m() } diff --git a/app/src/main/res/layout/activity_my_homtown_address.xml b/app/src/main/res/layout/activity_my_homtown_address.xml index 6fa24da1..335eed86 100644 --- a/app/src/main/res/layout/activity_my_homtown_address.xml +++ b/app/src/main/res/layout/activity_my_homtown_address.xml @@ -228,6 +228,7 @@ + + + @@ -283,9 +312,9 @@ + app:constraint_referenced_ids="categoryT, categoryChipG" /> \ No newline at end of file From 57290990d7a6e7fced1690d6008810fa498c6cac Mon Sep 17 00:00:00 2001 From: posite Date: Mon, 19 Feb 2024 22:26:13 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=EC=86=8C=ED=86=B5=ED=95=B4?= =?UTF-8?q?=EC=9A=94=20=EA=B8=80=EB=AA=A9=EB=A1=9D=20API=20=EC=97=B0?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/{TogethersApi.kt => MainCommsApi.kt} | 7 +- .../api/{CommsApi.kt => MainTogethersApi.kt} | 3 +- .../ttoklip/data/model/town/CommsResponse.kt | 2 +- .../model/town/{Comms.kt => Communities.kt} | 5 +- .../umc/ttoklip/data/model/town/ImageUrl.kt | 3 +- .../repository/town/MainCommsRepository.kt | 8 ++ .../town/MainCommsRepositoryImpl.kt | 15 +++ .../town/MainTogethersRepository.kt | 4 + .../town/MainTogethersRepositoryImpl.kt | 9 ++ .../java/com/umc/ttoklip/di/NetworkModule.kt | 16 ++- .../com/umc/ttoklip/di/RepositoryModule.kt | 22 +++- .../hometown/CommunicationActivity.kt | 113 +++++------------- .../hometown/CommunicationViewModel.kt | 6 + .../hometown/CommunicationViewModelImpl.kt | 26 +++- .../hometown/ReadCommunicationActivity.kt | 6 +- .../ReadCommunicationViewModelImpl.kt | 19 ++- .../hometown/ReadTogetherActivity.kt | 2 +- .../hometown/TogetherViewModelImpl.kt | 5 +- .../hometown/adapter/CommunicationAdapter.kt | 21 ++-- .../res/layout/activity_communication.xml | 31 +++-- .../layout/activity_read_communication.xml | 4 +- 21 files changed, 193 insertions(+), 134 deletions(-) rename app/src/main/java/com/umc/ttoklip/data/api/{TogethersApi.kt => MainCommsApi.kt} (58%) rename app/src/main/java/com/umc/ttoklip/data/api/{CommsApi.kt => MainTogethersApi.kt} (53%) rename app/src/main/java/com/umc/ttoklip/data/model/town/{Comms.kt => Communities.kt} (68%) create mode 100644 app/src/main/java/com/umc/ttoklip/data/repository/town/MainCommsRepository.kt create mode 100644 app/src/main/java/com/umc/ttoklip/data/repository/town/MainCommsRepositoryImpl.kt create mode 100644 app/src/main/java/com/umc/ttoklip/data/repository/town/MainTogethersRepository.kt create mode 100644 app/src/main/java/com/umc/ttoklip/data/repository/town/MainTogethersRepositoryImpl.kt diff --git a/app/src/main/java/com/umc/ttoklip/data/api/TogethersApi.kt b/app/src/main/java/com/umc/ttoklip/data/api/MainCommsApi.kt similarity index 58% rename from app/src/main/java/com/umc/ttoklip/data/api/TogethersApi.kt rename to app/src/main/java/com/umc/ttoklip/data/api/MainCommsApi.kt index bc9c01e6..eb95d58c 100644 --- a/app/src/main/java/com/umc/ttoklip/data/api/TogethersApi.kt +++ b/app/src/main/java/com/umc/ttoklip/data/api/MainCommsApi.kt @@ -4,11 +4,8 @@ import com.umc.ttoklip.data.model.ResponseBody import com.umc.ttoklip.data.model.town.CommsResponse import retrofit2.Response import retrofit2.http.GET -import retrofit2.http.Path -interface TogethersApi { +interface MainCommsApi { @GET("/api/v1/town/main/community") - suspend fun commsList( - @Path("postId") postId: Long - ): Response> + suspend fun commsList(): Response> } \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/data/api/CommsApi.kt b/app/src/main/java/com/umc/ttoklip/data/api/MainTogethersApi.kt similarity index 53% rename from app/src/main/java/com/umc/ttoklip/data/api/CommsApi.kt rename to app/src/main/java/com/umc/ttoklip/data/api/MainTogethersApi.kt index cc0eda69..0c41029e 100644 --- a/app/src/main/java/com/umc/ttoklip/data/api/CommsApi.kt +++ b/app/src/main/java/com/umc/ttoklip/data/api/MainTogethersApi.kt @@ -1,4 +1,5 @@ package com.umc.ttoklip.data.api -interface CommsApi { +interface MainTogethersApi { + } \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/data/model/town/CommsResponse.kt b/app/src/main/java/com/umc/ttoklip/data/model/town/CommsResponse.kt index 83cb3e30..bc2ec335 100644 --- a/app/src/main/java/com/umc/ttoklip/data/model/town/CommsResponse.kt +++ b/app/src/main/java/com/umc/ttoklip/data/model/town/CommsResponse.kt @@ -1,5 +1,5 @@ package com.umc.ttoklip.data.model.town data class CommsResponse( - val communities: List + val communities: List ) diff --git a/app/src/main/java/com/umc/ttoklip/data/model/town/Comms.kt b/app/src/main/java/com/umc/ttoklip/data/model/town/Communities.kt similarity index 68% rename from app/src/main/java/com/umc/ttoklip/data/model/town/Comms.kt rename to app/src/main/java/com/umc/ttoklip/data/model/town/Communities.kt index a774f75e..fdf2f742 100644 --- a/app/src/main/java/com/umc/ttoklip/data/model/town/Comms.kt +++ b/app/src/main/java/com/umc/ttoklip/data/model/town/Communities.kt @@ -1,10 +1,11 @@ package com.umc.ttoklip.data.model.town -data class Comms( +data class Communities( val id: Long, val title: String, val content: String, val commentCount: Long, val likeCount: Long, - val scrapCount: Long + val scrapCount: Long, + val writer: String ) \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/data/model/town/ImageUrl.kt b/app/src/main/java/com/umc/ttoklip/data/model/town/ImageUrl.kt index 220c3ea5..4594e694 100644 --- a/app/src/main/java/com/umc/ttoklip/data/model/town/ImageUrl.kt +++ b/app/src/main/java/com/umc/ttoklip/data/model/town/ImageUrl.kt @@ -1,6 +1,5 @@ package com.umc.ttoklip.data.model.town data class ImageUrl( - val imageId: Long, - val postImageUrl: String + val imageUrl: String ) \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/data/repository/town/MainCommsRepository.kt b/app/src/main/java/com/umc/ttoklip/data/repository/town/MainCommsRepository.kt new file mode 100644 index 00000000..d51fc9a6 --- /dev/null +++ b/app/src/main/java/com/umc/ttoklip/data/repository/town/MainCommsRepository.kt @@ -0,0 +1,8 @@ +package com.umc.ttoklip.data.repository.town + +import com.umc.ttoklip.data.model.town.CommsResponse +import com.umc.ttoklip.module.NetworkResult + +interface MainCommsRepository { + suspend fun getComms(): NetworkResult +} \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/data/repository/town/MainCommsRepositoryImpl.kt b/app/src/main/java/com/umc/ttoklip/data/repository/town/MainCommsRepositoryImpl.kt new file mode 100644 index 00000000..792c02f0 --- /dev/null +++ b/app/src/main/java/com/umc/ttoklip/data/repository/town/MainCommsRepositoryImpl.kt @@ -0,0 +1,15 @@ +package com.umc.ttoklip.data.repository.town + +import com.umc.ttoklip.data.api.MainCommsApi +import com.umc.ttoklip.data.model.ResponseBody +import com.umc.ttoklip.data.model.town.CommsResponse +import com.umc.ttoklip.module.NetworkResult +import com.umc.ttoklip.module.handleApi +import javax.inject.Inject + +class MainCommsRepositoryImpl @Inject constructor(private val api: MainCommsApi) : + MainCommsRepository { + override suspend fun getComms(): NetworkResult { + return handleApi({ api.commsList() }) { response: ResponseBody -> response.result } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/data/repository/town/MainTogethersRepository.kt b/app/src/main/java/com/umc/ttoklip/data/repository/town/MainTogethersRepository.kt new file mode 100644 index 00000000..158beda7 --- /dev/null +++ b/app/src/main/java/com/umc/ttoklip/data/repository/town/MainTogethersRepository.kt @@ -0,0 +1,4 @@ +package com.umc.ttoklip.data.repository.town + +interface MainTogethersRepository { +} \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/data/repository/town/MainTogethersRepositoryImpl.kt b/app/src/main/java/com/umc/ttoklip/data/repository/town/MainTogethersRepositoryImpl.kt new file mode 100644 index 00000000..7274771a --- /dev/null +++ b/app/src/main/java/com/umc/ttoklip/data/repository/town/MainTogethersRepositoryImpl.kt @@ -0,0 +1,9 @@ +package com.umc.ttoklip.data.repository.town + +import com.umc.ttoklip.data.api.MainTogethersApi +import javax.inject.Inject + +class MainTogethersRepositoryImpl @Inject constructor(private val api: MainTogethersApi) : + MainTogethersRepository { + +} \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/di/NetworkModule.kt b/app/src/main/java/com/umc/ttoklip/di/NetworkModule.kt index 4791b6cd..2f017606 100644 --- a/app/src/main/java/com/umc/ttoklip/di/NetworkModule.kt +++ b/app/src/main/java/com/umc/ttoklip/di/NetworkModule.kt @@ -4,6 +4,8 @@ import com.umc.ttoklip.R import com.umc.ttoklip.TtoklipApplication import com.umc.ttoklip.data.api.HoneyTipApi import com.umc.ttoklip.data.api.LoginApi +import com.umc.ttoklip.data.api.MainCommsApi +import com.umc.ttoklip.data.api.MainTogethersApi import com.umc.ttoklip.data.api.NewsApi import com.umc.ttoklip.data.api.ReadCommsApi import com.umc.ttoklip.data.api.ReadTogetherApi @@ -107,7 +109,7 @@ object NetworkModule { @Provides @Singleton - fun provideLoginApi(retrofit: Retrofit): LoginApi{ + fun provideLoginApi(retrofit: Retrofit): LoginApi { return retrofit.buildService() } @@ -141,6 +143,18 @@ object NetworkModule { return retrofit.buildService() } + @Provides + @Singleton + fun provideMainCommsApi(retrofit: Retrofit): MainCommsApi { + return retrofit.buildService() + } + + @Provides + @Singleton + fun provideMainTogethersApi(retrofit: Retrofit): MainTogethersApi { + return retrofit.buildService() + } + private inline fun Retrofit.buildService(): T { return this.create(T::class.java) diff --git a/app/src/main/java/com/umc/ttoklip/di/RepositoryModule.kt b/app/src/main/java/com/umc/ttoklip/di/RepositoryModule.kt index 48acd391..c23fc7e0 100644 --- a/app/src/main/java/com/umc/ttoklip/di/RepositoryModule.kt +++ b/app/src/main/java/com/umc/ttoklip/di/RepositoryModule.kt @@ -1,10 +1,12 @@ package com.umc.ttoklip.di +import com.umc.ttoklip.data.api.MainCommsApi +import com.umc.ttoklip.data.api.MainTogethersApi import com.umc.ttoklip.data.api.NewsApi -import com.umc.ttoklip.data.api.Search2Api -import com.umc.ttoklip.data.api.SearchApi import com.umc.ttoklip.data.api.ReadCommsApi import com.umc.ttoklip.data.api.ReadTogetherApi +import com.umc.ttoklip.data.api.Search2Api +import com.umc.ttoklip.data.api.SearchApi import com.umc.ttoklip.data.api.WriteCommsApi import com.umc.ttoklip.data.api.WriteTogetherApi import com.umc.ttoklip.data.repository.news.NewsRepository @@ -13,6 +15,10 @@ import com.umc.ttoklip.data.repository.search.Search2Repository import com.umc.ttoklip.data.repository.search.Search2RepositoryImpl import com.umc.ttoklip.data.repository.search.SearchRepository import com.umc.ttoklip.data.repository.search.SearchRepositoryImpl +import com.umc.ttoklip.data.repository.town.MainCommsRepository +import com.umc.ttoklip.data.repository.town.MainCommsRepositoryImpl +import com.umc.ttoklip.data.repository.town.MainTogethersRepository +import com.umc.ttoklip.data.repository.town.MainTogethersRepositoryImpl import com.umc.ttoklip.data.repository.town.ReadCommsRepository import com.umc.ttoklip.data.repository.town.ReadCommsRepositoryImpl import com.umc.ttoklip.data.repository.town.ReadTogetherRepository @@ -70,4 +76,16 @@ object RepositoryModule { Search2RepositoryImpl(api) + @Provides + @Singleton + fun providesMainCommsRepository(api: MainCommsApi): MainCommsRepository = + MainCommsRepositoryImpl(api) + + + @Provides + @Singleton + fun providesMainTogethersRepository(api: MainTogethersApi): MainTogethersRepository = + MainTogethersRepositoryImpl(api) + + } \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationActivity.kt index 4cdfef40..7fd20846 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationActivity.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationActivity.kt @@ -2,20 +2,28 @@ package com.umc.ttoklip.presentation.hometown import android.content.Intent import androidx.activity.viewModels +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle import androidx.recyclerview.widget.LinearLayoutManager import com.umc.ttoklip.R +import com.umc.ttoklip.data.model.town.Communities import com.umc.ttoklip.databinding.ActivityCommunicationBinding +import com.umc.ttoklip.presentation.alarm.AlarmActivity import com.umc.ttoklip.presentation.base.BaseActivity -import com.umc.ttoklip.presentation.hometown.adapter.Communication import com.umc.ttoklip.presentation.hometown.adapter.CommunicationAdapter import com.umc.ttoklip.presentation.hometown.adapter.OnItemClickListener import com.umc.ttoklip.presentation.mypage.SortSpinnerAdapter import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.launch @AndroidEntryPoint class CommunicationActivity : BaseActivity(R.layout.activity_communication), OnItemClickListener { + private val adapter by lazy { + CommunicationAdapter(this) + } private val viewModel: CommunicationViewModel by viewModels() override fun initView() { binding.vm = viewModel as CommunicationViewModelImpl @@ -29,105 +37,40 @@ class CommunicationActivity : getString(R.string.sort_most_comments), getString(R.string.sort_most_scrap) ) + binding.bellBtn.setOnClickListener { + startActivity(AlarmActivity.newIntent(this)) + } binding.honeyTipFilterSpinner.adapter = SortSpinnerAdapter(this, sortFilters) binding.honeyTipFilterSpinner.setSelection(0) - val honeyTipList = listOf( - Communication( - "똑똑이", - "음식물 쓰레기 냄새 방지!!", - "집에 가끔씩이지만 나타나는 바퀴벌레, 잘못 처리하면 알깐다고도...", - "1일전", - 0 - ), - Communication( - "똑똑이", - "음식물 쓰레기 냄새 방지!!", - "집에 가끔씩이지만 나타나는 바퀴벌레, 잘못 처리하면 알깐다고도...", - "1일전", - 0 - ), - Communication( - "똑똑이", - "음식물 쓰레기 냄새 방지!!", - "집에 가끔씩이지만 나타나는 바퀴벌레, 잘못 처리하면 알깐다고도...", - "1일전", - 0 - ), - Communication( - "똑똑이", - "음식물 쓰레기 냄새 방지!!", - "집에 가끔씩이지만 나타나는 바퀴벌레, 잘못 처리하면 알깐다고도...", - "1일전", - 0 - ), - Communication( - "똑똑이", - "음식물 쓰레기 냄새 방지!!", - "집에 가끔씩이지만 나타나는 바퀴벌레, 잘못 처리하면 알깐다고도...", - "1일전", - 0 - ), - Communication( - "똑똑이", - "음식물 쓰레기 냄새 방지!!", - "집에 가끔씩이지만 나타나는 바퀴벌레, 잘못 처리하면 알깐다고도...", - "1일전", - 0 - ), - Communication( - "똑똑이", - "음식물 쓰레기 냄새 방지!!", - "집에 가끔씩이지만 나타나는 바퀴벌레, 잘못 처리하면 알깐다고도...", - "1일전", - 0 - ), - Communication( - "똑똑이", - "음식물 쓰레기 냄새 방지!!", - "집에 가끔씩이지만 나타나는 바퀴벌레, 잘못 처리하면 알깐다고도...", - "1일전", - 0 - ), - Communication( - "똑똑이", - "음식물 쓰레기 냄새 방지!!", - "집에 가끔씩이지만 나타나는 바퀴벌레, 잘못 처리하면 알깐다고도...", - "1일전", - 0 - ), - Communication( - "똑똑이", - "음식물 쓰레기 냄새 방지!!", - "집에 가끔씩이지만 나타나는 바퀴벌레, 잘못 처리하면 알깐다고도...", - "1일전", - 0 - ), - Communication( - "똑똑이", - "음식물 쓰레기 냄새 방지!!", - "집에 가끔씩이지만 나타나는 바퀴벌레, 잘못 처리하면 알깐다고도...", - "1일전", - 0 - ), - ) - val adapter = CommunicationAdapter(this) + + binding.communicationRv.layoutManager = LinearLayoutManager(this) binding.communicationRv.adapter = adapter - adapter.submitList(honeyTipList) binding.backBtn.setOnClickListener { finish() } + viewModel.getCommunities() } override fun initObserver() { - + with(lifecycleScope) { + launch { + repeatOnLifecycle(Lifecycle.State.STARTED) { + viewModel.communities.collect { + adapter.submitList(it) + } + } + } + } } - override fun onClick(communication: Communication) { - + override fun onClick(communication: Communities) { + val intent = Intent(this, ReadCommunicationActivity::class.java) + intent.putExtra("postId", communication.id) + startActivity(intent) } } \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationViewModel.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationViewModel.kt index 8d7e3109..25e7be7e 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationViewModel.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationViewModel.kt @@ -1,4 +1,10 @@ package com.umc.ttoklip.presentation.hometown +import com.umc.ttoklip.data.model.town.Communities +import kotlinx.coroutines.flow.StateFlow + interface CommunicationViewModel { + val communities: StateFlow> + + fun getCommunities() } \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationViewModelImpl.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationViewModelImpl.kt index 05896440..2d57d406 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationViewModelImpl.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationViewModelImpl.kt @@ -1,11 +1,33 @@ package com.umc.ttoklip.presentation.hometown import androidx.lifecycle.ViewModel -import com.umc.ttoklip.data.repository.town.ReadCommsRepository +import androidx.lifecycle.viewModelScope +import com.umc.ttoklip.data.model.town.Communities +import com.umc.ttoklip.data.repository.town.MainCommsRepository +import com.umc.ttoklip.module.onError +import com.umc.ttoklip.module.onSuccess import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel -class CommunicationViewModelImpl @Inject constructor(private val repository: ReadCommsRepository) : +class CommunicationViewModelImpl @Inject constructor(private val repository: MainCommsRepository) : ViewModel(), CommunicationViewModel { + private val _communities = MutableStateFlow>(emptyList()) + override val communities: StateFlow> + get() = _communities + + override fun getCommunities() { + viewModelScope.launch { + repository.getComms().onSuccess { + _communities.value = it.communities + }.onError { + + } + } + } + + } \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationActivity.kt index 2ce093e1..4c6aec59 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationActivity.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationActivity.kt @@ -2,6 +2,7 @@ package com.umc.ttoklip.presentation.hometown import android.content.Context import android.graphics.Rect +import android.util.Log import android.view.MotionEvent import android.view.inputmethod.InputMethodManager import android.widget.EditText @@ -104,10 +105,9 @@ class ReadCommunicationActivity : writerTv.text = response.writer titleTv.text = response.title contentT.text = response.content + Log.d("image", response.imageUrls.toString()) imageAdapter.submitList(response.imageUrls.map { url -> - ImageUrl( - imageUrl = url.postImageUrl - ) + ImageUrl(url.imageUrl) }) if (response.likedByCurrentUser) { likeImg.setImageDrawable(getDrawable(R.drawable.ic_heart_on_20)) diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationViewModelImpl.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationViewModelImpl.kt index c854e928..f2c18242 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationViewModelImpl.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationViewModelImpl.kt @@ -1,5 +1,6 @@ package com.umc.ttoklip.presentation.hometown +import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.umc.ttoklip.data.model.town.CommentResponse @@ -61,6 +62,8 @@ class ReadCommunicationViewModelImpl @Inject constructor( viewModelScope.launch { repository.viewComms(postId).onSuccess { _postContent.value = it + _like.value = it.likedByCurrentUser + _scrap.value = it.scrapedByCurrentUser }.onError { } @@ -71,9 +74,13 @@ class ReadCommunicationViewModelImpl @Inject constructor( _like.value = _like.value.not() viewModelScope.launch { if (_like.value) { - repository.addCommsLike(postId.value) + repository.addCommsLike(postId.value).onSuccess { + Log.d("change", "스크랩") + } } else { - repository.cancelCommsLike(postId.value) + repository.cancelCommsLike(postId.value).onSuccess { + Log.d("change", "스크랩") + } } } } @@ -82,9 +89,13 @@ class ReadCommunicationViewModelImpl @Inject constructor( _scrap.value = _scrap.value.not() viewModelScope.launch { if (_scrap.value) { - repository.addCommsScrap(postId.value) + repository.addCommsScrap(postId.value).onSuccess { + Log.d("change", "좋아요") + } } else { - repository.cancelCommsScrap(postId.value) + repository.cancelCommsScrap(postId.value).onSuccess { + Log.d("change", "좋아요") + } } } } diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadTogetherActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadTogetherActivity.kt index 5dfeab32..54b9b2af 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadTogetherActivity.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadTogetherActivity.kt @@ -134,7 +134,7 @@ class ReadTogetherActivity : contentT.text = response.content imageAdapter.submitList(response.imageUrls.map { url -> ImageUrl( - imageUrl = url.postImageUrl + imageUrl = url.imageUrl ) }) commentRVA.submitList(response.commentResponse) diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/TogetherViewModelImpl.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/TogetherViewModelImpl.kt index 2e97a382..ff494a1a 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/TogetherViewModelImpl.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/TogetherViewModelImpl.kt @@ -2,18 +2,17 @@ package com.umc.ttoklip.presentation.hometown import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.umc.ttoklip.data.repository.town.ReadTogetherRepository +import com.umc.ttoklip.data.repository.town.MainTogethersRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharedFlow - import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel -class TogetherViewModelImpl @Inject constructor(private val repository: ReadTogetherRepository) : +class TogetherViewModelImpl @Inject constructor(private val repository: MainTogethersRepository) : ViewModel(), TogetherViewModel { private val _filterRequiredAmount = MutableStateFlow(0L) override val filterRequiredAmount: StateFlow diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/adapter/CommunicationAdapter.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/adapter/CommunicationAdapter.kt index e4d260b3..8652b2b3 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/adapter/CommunicationAdapter.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/adapter/CommunicationAdapter.kt @@ -6,31 +6,34 @@ import androidx.core.view.isGone import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView +import com.umc.ttoklip.data.model.town.Communities import com.umc.ttoklip.databinding.ItemCommunicationBinding class CommunicationAdapter(private var listener: OnItemClickListener) : - ListAdapter(object : - DiffUtil.ItemCallback() { - override fun areItemsTheSame(oldItem: Communication, newItem: Communication): Boolean { + ListAdapter(object : + DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: Communities, newItem: Communities): Boolean { return oldItem.writer == newItem.writer && oldItem.title == newItem.title } - override fun areContentsTheSame(oldItem: Communication, newItem: Communication): Boolean { + override fun areContentsTheSame(oldItem: Communities, newItem: Communities): Boolean { return oldItem == newItem } }) { inner class CommunicationViewHolder(private val binding: ItemCommunicationBinding) : RecyclerView.ViewHolder(binding.root) { - fun bind(honeyTips: Communication, pos: Int) { + fun bind(honeyTips: Communities, pos: Int) { if (pos == itemCount - 1) { binding.itemSeparator.isGone = true } binding.titleTv.text = honeyTips.title binding.writerTv.text = honeyTips.writer - binding.dateTv.text = honeyTips.date - binding.bodyTv.text = honeyTips.body - binding.commentCountTv.text = honeyTips.chatCnt.toString() + binding.dateTv.isGone = true + binding.bodyTv.text = honeyTips.content + binding.starCountTv.text = honeyTips.scrapCount.toString() + binding.likeCountTv.text = honeyTips.likeCount.toString() + binding.commentCountTv.text = honeyTips.commentCount.toString() binding.root.setOnClickListener { listener.onClick(honeyTips) @@ -52,5 +55,5 @@ class CommunicationAdapter(private var listener: OnItemClickListener) : } interface OnItemClickListener { - fun onClick(communication: Communication) + fun onClick(communication: Communities) } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_communication.xml b/app/src/main/res/layout/activity_communication.xml index eadafbcd..c1ca9a64 100644 --- a/app/src/main/res/layout/activity_communication.xml +++ b/app/src/main/res/layout/activity_communication.xml @@ -40,6 +40,15 @@ android:src="@drawable/ic_arrow_back_24" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintEnd_toEndOf="parent" + app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlayExtended" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_read_communication.xml b/app/src/main/res/layout/activity_read_communication.xml index ed21b303..6417bb12 100644 --- a/app/src/main/res/layout/activity_read_communication.xml +++ b/app/src/main/res/layout/activity_read_communication.xml @@ -210,7 +210,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="12dp" - android:src="@drawable/ic_bookmark_off_20" + android:src="@{vm.scrap ? @drawable/ic_bookmark_on_20 : @drawable/ic_bookmark_off_20}" app:layout_constraintStart_toStartOf="@id/contentT" app:layout_constraintTop_toBottomOf="@id/image_rv" /> @@ -232,7 +232,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="6dp" - android:src="@drawable/ic_heart_off_20" + android:src="@{vm.like ? @drawable/ic_heart_on_20 : @drawable/ic_heart_off_20}" app:layout_constraintBottom_toBottomOf="@id/bookmarkImg" app:layout_constraintStart_toEndOf="@id/bookmarkT" app:layout_constraintTop_toTopOf="@id/bookmarkImg" /> From de78393ebb1ce3134cceb63949a117ee2fc52eab Mon Sep 17 00:00:00 2001 From: posite Date: Mon, 19 Feb 2024 23:37:36 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=EC=86=8C=ED=86=B5=ED=95=B4?= =?UTF-8?q?=EC=9A=94=20=EA=B8=80=20=EC=9D=BD=EA=B8=B0=20=EC=A2=8B=EC=95=84?= =?UTF-8?q?=EC=9A=94,=20=EC=8A=A4=ED=81=AC=EB=9E=A9,=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20API=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/model/town/CommentResponse.kt | 2 +- .../data/model/town/CreateCommentRequest.kt | 2 +- .../model/town/ViewCommunicationResponse.kt | 2 +- .../com/umc/ttoklip/di/RepositoryModule.kt | 6 +-- .../hometown/CommunicationActivity.kt | 1 + .../hometown/ReadCommunicationActivity.kt | 37 +++++++++++++++++-- ...Model.kt => ReadCommunicationViewModel.kt} | 2 +- .../ReadCommunicationViewModelImpl.kt | 22 +++++------ .../layout/activity_read_communication.xml | 2 - 9 files changed, 52 insertions(+), 24 deletions(-) rename app/src/main/java/com/umc/ttoklip/presentation/hometown/{ReadCommunicationVIewModel.kt => ReadCommunicationViewModel.kt} (95%) diff --git a/app/src/main/java/com/umc/ttoklip/data/model/town/CommentResponse.kt b/app/src/main/java/com/umc/ttoklip/data/model/town/CommentResponse.kt index e81d7bfd..8a640ce8 100644 --- a/app/src/main/java/com/umc/ttoklip/data/model/town/CommentResponse.kt +++ b/app/src/main/java/com/umc/ttoklip/data/model/town/CommentResponse.kt @@ -2,7 +2,7 @@ package com.umc.ttoklip.data.model.town data class CommentResponse( val commentId: Long, - val commentContent: String, + val commentContent: String?, val parentId: Long?, val writer: String, val writtenTime: String diff --git a/app/src/main/java/com/umc/ttoklip/data/model/town/CreateCommentRequest.kt b/app/src/main/java/com/umc/ttoklip/data/model/town/CreateCommentRequest.kt index 4cc6e887..890cde61 100644 --- a/app/src/main/java/com/umc/ttoklip/data/model/town/CreateCommentRequest.kt +++ b/app/src/main/java/com/umc/ttoklip/data/model/town/CreateCommentRequest.kt @@ -1,6 +1,6 @@ package com.umc.ttoklip.data.model.town data class CreateCommentRequest( - val content: String, + val comment: String, val parentCommentId: Long ) diff --git a/app/src/main/java/com/umc/ttoklip/data/model/town/ViewCommunicationResponse.kt b/app/src/main/java/com/umc/ttoklip/data/model/town/ViewCommunicationResponse.kt index a05dc8dc..e1dfb2ea 100644 --- a/app/src/main/java/com/umc/ttoklip/data/model/town/ViewCommunicationResponse.kt +++ b/app/src/main/java/com/umc/ttoklip/data/model/town/ViewCommunicationResponse.kt @@ -10,7 +10,7 @@ data class ViewCommunicationResponse( val scrapCount: Long, val likeCount: Long, val commentCount: Int, - val commentResponse: List, + val commentResponses: List, val likedByCurrentUser: Boolean, val scrapedByCurrentUser: Boolean ) \ No newline at end of file diff --git a/app/src/main/java/com/umc/ttoklip/di/RepositoryModule.kt b/app/src/main/java/com/umc/ttoklip/di/RepositoryModule.kt index fc98dde1..804a1654 100644 --- a/app/src/main/java/com/umc/ttoklip/di/RepositoryModule.kt +++ b/app/src/main/java/com/umc/ttoklip/di/RepositoryModule.kt @@ -10,16 +10,14 @@ import com.umc.ttoklip.data.api.ReadCommsApi import com.umc.ttoklip.data.api.ReadTogetherApi import com.umc.ttoklip.data.api.Search2Api import com.umc.ttoklip.data.api.SearchApi +import com.umc.ttoklip.data.api.WriteCommsApi +import com.umc.ttoklip.data.api.WriteTogetherApi import com.umc.ttoklip.data.repository.mypage.MyAccountRestrictRepository import com.umc.ttoklip.data.repository.mypage.MyAccountRestrictRepositoryImpl import com.umc.ttoklip.data.repository.mypage.MyBlockUserRepository import com.umc.ttoklip.data.repository.mypage.MyBlockUserRepositoryImpl import com.umc.ttoklip.data.repository.mypage.MyPostRepository import com.umc.ttoklip.data.repository.mypage.MyPostRepositoryImpl -import com.umc.ttoklip.data.api.ReadCommsApi -import com.umc.ttoklip.data.api.ReadTogetherApi -import com.umc.ttoklip.data.api.WriteCommsApi -import com.umc.ttoklip.data.api.WriteTogetherApi import com.umc.ttoklip.data.repository.news.NewsRepository import com.umc.ttoklip.data.repository.news.NewsRepositoryImpl import com.umc.ttoklip.data.repository.search.Search2Repository diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationActivity.kt index 7fd20846..9963796f 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationActivity.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/CommunicationActivity.kt @@ -55,6 +55,7 @@ class CommunicationActivity : viewModel.getCommunities() } + override fun initObserver() { with(lifecycleScope) { launch { diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationActivity.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationActivity.kt index 4c6aec59..9055820c 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationActivity.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationActivity.kt @@ -23,6 +23,9 @@ import com.umc.ttoklip.presentation.honeytip.adapter.ReadImageRVA import com.umc.ttoklip.presentation.honeytip.dialog.DeleteDialogFragment import com.umc.ttoklip.presentation.honeytip.dialog.ReportDialogFragment import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay import kotlinx.coroutines.launch @AndroidEntryPoint @@ -41,7 +44,7 @@ class ReadCommunicationActivity : private val imageAdapter: ReadImageRVA by lazy { ReadImageRVA(this, this@ReadCommunicationActivity) } - private val viewModel: ReadCommunicationVIewModel by viewModels() + private val viewModel: ReadCommunicationViewModel by viewModels() private var postId = 0L override fun initView() { @@ -82,7 +85,31 @@ class ReadCommunicationActivity : binding.cardView.setOnClickListener { if (binding.commentEt.text.toString().isNotBlank()) { - viewModel.createComment(CreateCommentRequest(binding.commentEt.text.toString(), 0L)) + CoroutineScope(Dispatchers.IO).launch { + viewModel.createComment( + CreateCommentRequest( + binding.commentEt.text.toString(), + 0L + ) + ) + delay(500) + viewModel.readCommunication(postId) + } + } + } + + binding.scrapBtn.setOnClickListener { + CoroutineScope(Dispatchers.IO).launch { + viewModel.changeScrap() + delay(500) + viewModel.readCommunication(postId) + } + } + binding.likeBtn.setOnClickListener { + CoroutineScope(Dispatchers.IO).launch { + viewModel.changeLike() + delay(500) + viewModel.readCommunication(postId) } } } @@ -109,6 +136,9 @@ class ReadCommunicationActivity : imageAdapter.submitList(response.imageUrls.map { url -> ImageUrl(url.imageUrl) }) + likeT.text = response.likeCount.toString() + bookmarkT.text = response.scrapCount.toString() + commitT.text = response.commentCount.toString() if (response.likedByCurrentUser) { likeImg.setImageDrawable(getDrawable(R.drawable.ic_heart_on_20)) } else { @@ -119,7 +149,8 @@ class ReadCommunicationActivity : } else { bookmarkImg.setImageDrawable(getDrawable(R.drawable.ic_bookmark_off_20)) } - commentRVA.submitList(response.commentResponse) +// Log.d("comment", response.commentResponse.toString()) + commentRVA.submitList(response.commentResponses) } } } diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationVIewModel.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationViewModel.kt similarity index 95% rename from app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationVIewModel.kt rename to app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationViewModel.kt index a2c29c2d..c1c577db 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationVIewModel.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationViewModel.kt @@ -5,7 +5,7 @@ import com.umc.ttoklip.data.model.town.ReportRequest import com.umc.ttoklip.data.model.town.ViewCommunicationResponse import kotlinx.coroutines.flow.StateFlow -interface ReadCommunicationVIewModel { +interface ReadCommunicationViewModel { val postId: StateFlow val postContent: StateFlow val like: StateFlow diff --git a/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationViewModelImpl.kt b/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationViewModelImpl.kt index f2c18242..a0005481 100644 --- a/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationViewModelImpl.kt +++ b/app/src/main/java/com/umc/ttoklip/presentation/hometown/ReadCommunicationViewModelImpl.kt @@ -20,7 +20,7 @@ import javax.inject.Inject class ReadCommunicationViewModelImpl @Inject constructor( private val repository: ReadCommsRepository ) : ViewModel(), - ReadCommunicationVIewModel { + ReadCommunicationViewModel { private val _postContent: MutableStateFlow = MutableStateFlow( ViewCommunicationResponse( @@ -71,14 +71,14 @@ class ReadCommunicationViewModelImpl @Inject constructor( } override fun changeScrap() { - _like.value = _like.value.not() + Log.d("change", "스크랩") + _scrap.value = _scrap.value.not() viewModelScope.launch { - if (_like.value) { - repository.addCommsLike(postId.value).onSuccess { - Log.d("change", "스크랩") + if (_scrap.value) { + repository.addCommsScrap(postId.value).onSuccess { } } else { - repository.cancelCommsLike(postId.value).onSuccess { + repository.cancelCommsScrap(postId.value).onSuccess { Log.d("change", "스크랩") } } @@ -86,14 +86,14 @@ class ReadCommunicationViewModelImpl @Inject constructor( } override fun changeLike() { - _scrap.value = _scrap.value.not() + Log.d("change", "좋아요") + _like.value = _like.value.not() viewModelScope.launch { - if (_scrap.value) { - repository.addCommsScrap(postId.value).onSuccess { - Log.d("change", "좋아요") + if (_like.value) { + repository.addCommsLike(postId.value).onSuccess { } } else { - repository.cancelCommsScrap(postId.value).onSuccess { + repository.cancelCommsLike(postId.value).onSuccess { Log.d("change", "좋아요") } } diff --git a/app/src/main/res/layout/activity_read_communication.xml b/app/src/main/res/layout/activity_read_communication.xml index 6417bb12..8599bbc0 100644 --- a/app/src/main/res/layout/activity_read_communication.xml +++ b/app/src/main/res/layout/activity_read_communication.xml @@ -278,7 +278,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="12dp" - android:onClick="@{()->vm.changeScrap()}" android:background="@drawable/rectangle_corner_4" android:backgroundTint="@color/gray20" app:layout_constraintStart_toStartOf="@id/bookmarkImg" @@ -316,7 +315,6 @@ android:layout_height="wrap_content" android:layout_marginStart="12dp" android:layout_marginTop="12dp" - android:onClick="@{()->vm.changeLike()}" android:background="@drawable/rectangle_corner_4" android:backgroundTint="@color/gray20" app:layout_constraintStart_toEndOf="@id/scrapBtn" From c77782e8fda3921fcdcdab02edeec1491bd6f8ce Mon Sep 17 00:00:00 2001 From: posite Date: Mon, 19 Feb 2024 23:53:23 +0900 Subject: [PATCH 4/4] =?UTF-8?q?chore:=20=EB=88=84=EB=9D=BD=EB=90=9C=20merg?= =?UTF-8?q?e=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/umc/ttoklip/di/RepositoryModule.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/umc/ttoklip/di/RepositoryModule.kt b/app/src/main/java/com/umc/ttoklip/di/RepositoryModule.kt index 7936fe81..fdb54890 100644 --- a/app/src/main/java/com/umc/ttoklip/di/RepositoryModule.kt +++ b/app/src/main/java/com/umc/ttoklip/di/RepositoryModule.kt @@ -1,14 +1,12 @@ package com.umc.ttoklip.di +import com.umc.ttoklip.data.api.HomeApi import com.umc.ttoklip.data.api.MainCommsApi import com.umc.ttoklip.data.api.MainTogethersApi -import com.umc.ttoklip.data.api.HomeApi -import com.umc.ttoklip.data.api.MyPage2Api -import com.umc.ttoklip.data.api.MyPageApi -import com.umc.ttoklip.data.repository.mypage.MyPageRepository2 -import com.umc.ttoklip.data.repository.mypage.MyPageRepository2Impl import com.umc.ttoklip.data.api.MyAccountRestrictApi import com.umc.ttoklip.data.api.MyBlockUserApi +import com.umc.ttoklip.data.api.MyPage2Api +import com.umc.ttoklip.data.api.MyPageApi import com.umc.ttoklip.data.api.MyPostApi import com.umc.ttoklip.data.api.NewsApi import com.umc.ttoklip.data.api.ReadCommsApi @@ -17,16 +15,16 @@ import com.umc.ttoklip.data.api.Search2Api import com.umc.ttoklip.data.api.SearchApi import com.umc.ttoklip.data.api.WriteCommsApi import com.umc.ttoklip.data.api.WriteTogetherApi +import com.umc.ttoklip.data.repository.home.HomeRepository +import com.umc.ttoklip.data.repository.home.HomeRepositoryImpl import com.umc.ttoklip.data.repository.mypage.MyAccountRestrictRepository import com.umc.ttoklip.data.repository.mypage.MyAccountRestrictRepositoryImpl import com.umc.ttoklip.data.repository.mypage.MyBlockUserRepository import com.umc.ttoklip.data.repository.mypage.MyBlockUserRepositoryImpl +import com.umc.ttoklip.data.repository.mypage.MyPageRepository2 +import com.umc.ttoklip.data.repository.mypage.MyPageRepository2Impl import com.umc.ttoklip.data.repository.mypage.MyPostRepository import com.umc.ttoklip.data.repository.mypage.MyPostRepositoryImpl -import com.umc.ttoklip.data.api.ReadCommsApi -import com.umc.ttoklip.data.api.ReadTogetherApi -import com.umc.ttoklip.data.api.WriteCommsApi -import com.umc.ttoklip.data.api.WriteTogetherApi import com.umc.ttoklip.data.repository.news.NewsRepository import com.umc.ttoklip.data.repository.news.NewsRepositoryImpl import com.umc.ttoklip.data.repository.scrap.ScrapRepository