Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

70 feat 우리동네 댓글 좋아요 스크랩 구현 #75

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/src/main/java/com/umc/ttoklip/data/api/HoneyTipApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface HoneyTipApi {
@Part("title") title: RequestBody,
@Part("content") content: RequestBody,
@Part("category") category: RequestBody,
@Part images: Array<MultipartBody.Part>,
@Part images: List<MultipartBody.Part?>,
@Part("url") url: RequestBody
): Response<ResponseBody<CreateHoneyTipResponse>>

Expand Down Expand Up @@ -68,7 +68,7 @@ interface HoneyTipApi {
@Part("title") title: RequestBody,
@Part("content") content: RequestBody,
@Part("category") category: RequestBody,
@Part images: Array<MultipartBody.Part>,
@Part images: List<MultipartBody.Part?>,
@Part("url") url: RequestBody
): Response<ResponseBody<CreateHoneyTipResponse>>

Expand Down Expand Up @@ -96,7 +96,7 @@ interface HoneyTipApi {
@Part("title") title: RequestBody,
@Part("content") content: RequestBody,
@Part("category") category: RequestBody,
@Part images: Array<MultipartBody.Part>
@Part images: List<MultipartBody.Part?>
): Response<ResponseBody<CreateHoneyTipResponse>>

@GET("/api/v1/question/post/{postId}")
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/umc/ttoklip/data/api/NaverApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.umc.ttoklip.data.api

import com.umc.ttoklip.data.model.naver.GeocodingResponse
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Query

interface NaverApi {
@GET("map-geocode/v2/geocode")
suspend fun fetchGeocoding(
@Query("query") query: String
): Response<GeocodingResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.umc.ttoklip.data.model.naver

data class AddressElements(
val types: List<String>,
val longName: String,
val shortName: String,
val code: String
)
11 changes: 11 additions & 0 deletions app/src/main/java/com/umc/ttoklip/data/model/naver/Addresses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.umc.ttoklip.data.model.naver

data class Addresses(
val roadAddress: String,
val jibunAddress: String,
val englishAddress: String,
val addressElements: List<AddressElements>,
val x: String,
val y: String,
val distance: Double
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.umc.ttoklip.data.model.naver

data class GeocodingResponse(
val status: String,
val meta: Meta,
val addresses: Addresses,
val errorMessage: String
)
7 changes: 7 additions & 0 deletions app/src/main/java/com/umc/ttoklip/data/model/naver/Meta.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.umc.ttoklip.data.model.naver

data class Meta(
val totalCount: Int,
val page: Int,
val count: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface HoneyTipRepository {
title: RequestBody,
content: RequestBody,
category: RequestBody,
images: Array<MultipartBody.Part>,
images: List<MultipartBody.Part?>,
url: RequestBody
): NetworkResult<CreateHoneyTipResponse>

Expand All @@ -44,7 +44,7 @@ interface HoneyTipRepository {
title: RequestBody,
content: RequestBody,
category: RequestBody,
images: Array<MultipartBody.Part>,
images: List<MultipartBody.Part?>,
url: RequestBody
): NetworkResult<CreateHoneyTipResponse>

Expand Down Expand Up @@ -73,7 +73,7 @@ interface HoneyTipRepository {
title: RequestBody,
content: RequestBody,
category: RequestBody,
images: Array<MultipartBody.Part>
images: List<MultipartBody.Part?>
): NetworkResult<CreateHoneyTipResponse>

suspend fun inquireQuestion(questionId: Int): NetworkResult<InquireQuestionResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class HoneyTipRepositoryImpl @Inject constructor(
title: RequestBody,
content: RequestBody,
category: RequestBody,
images: Array<MultipartBody.Part>,
images: List<MultipartBody.Part?>,
uri: RequestBody
): NetworkResult<CreateHoneyTipResponse> {
return handleApi({
Expand All @@ -65,7 +65,7 @@ class HoneyTipRepositoryImpl @Inject constructor(
title: RequestBody,
content: RequestBody,
category: RequestBody,
images: Array<MultipartBody.Part>,
images: List<MultipartBody.Part?>,
url: RequestBody
): NetworkResult<CreateHoneyTipResponse> {
return handleApi({ api.patchHoneyTip(honeyTipId, title, content, category, images, url) })
Expand Down Expand Up @@ -119,7 +119,7 @@ class HoneyTipRepositoryImpl @Inject constructor(
title: RequestBody,
content: RequestBody,
category: RequestBody,
images: Array<MultipartBody.Part>
images: List<MultipartBody.Part?>
): NetworkResult<CreateHoneyTipResponse> {
return handleApi({
api.postNewQuestion(title, content, category, images)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.umc.ttoklip.data.repository.naver

import com.umc.ttoklip.data.model.naver.GeocodingResponse
import com.umc.ttoklip.module.NetworkResult

interface NaverRepository {
suspend fun fetchGeocoding(query: String): NetworkResult<GeocodingResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.umc.ttoklip.data.repository.naver

import com.umc.ttoklip.data.api.NaverApi
import com.umc.ttoklip.data.model.naver.GeocodingResponse
import com.umc.ttoklip.module.NetworkResult
import com.umc.ttoklip.module.handleApi
import javax.inject.Inject

class NaverRepositoryImpl @Inject constructor(
private val api: NaverApi
) : NaverRepository {
override suspend fun fetchGeocoding(query: String): NetworkResult<GeocodingResponse> {
return handleApi({api.fetchGeocoding(query)}) {response: GeocodingResponse -> response}
}

}
22 changes: 22 additions & 0 deletions app/src/main/java/com/umc/ttoklip/di/NetworkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.umc.ttoklip.di

import com.umc.ttoklip.R
import com.umc.ttoklip.TtoklipApplication
import com.umc.ttoklip.TtoklipApplication.Companion.getString
import com.umc.ttoklip.data.api.FCMApi
import com.umc.ttoklip.data.api.HomeApi
import com.umc.ttoklip.data.api.HoneyTipApi
Expand All @@ -14,6 +15,7 @@ import com.umc.ttoklip.data.api.MainTogethersApi
import com.umc.ttoklip.data.api.MyAccountRestrictApi
import com.umc.ttoklip.data.api.MyBlockUserApi
import com.umc.ttoklip.data.api.MyPostApi
import com.umc.ttoklip.data.api.NaverApi
import com.umc.ttoklip.data.api.NewsApi
import com.umc.ttoklip.data.api.OtherApi
import com.umc.ttoklip.data.api.ReadCommsApi
Expand Down Expand Up @@ -149,6 +151,20 @@ object NetworkModule {
.build()
}

@Provides
@Singleton
@Named("naver")
fun providesNaverRetrofit(
@Named("NaverClient") client: OkHttpClient,
): Retrofit{
return Retrofit.Builder()
.client(client)
.baseUrl(getString(R.string. naver_url))
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build()
}

@Provides
@Singleton
fun provideTestApi(retrofit: Retrofit): TestApi {
Expand Down Expand Up @@ -291,6 +307,12 @@ object NetworkModule {
return retrofit.buildService()
}

@Provides
@Singleton
fun provideNaverApi(@Named("naver") retrofit: Retrofit): NaverApi{
return retrofit.buildService()
}


private inline fun <reified T> Retrofit.buildService(): T {
return this.create(T::class.java)
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/umc/ttoklip/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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.NaverApi
import com.umc.ttoklip.data.api.NewsApi
import com.umc.ttoklip.data.api.OtherApi
import com.umc.ttoklip.data.api.ReadCommsApi
Expand All @@ -30,6 +31,8 @@ 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.repository.naver.NaverRepository
import com.umc.ttoklip.data.repository.naver.NaverRepositoryImpl
import com.umc.ttoklip.data.repository.news.NewsRepository
import com.umc.ttoklip.data.repository.news.NewsRepositoryImpl
import com.umc.ttoklip.data.repository.scrap.ScrapRepository
Expand Down Expand Up @@ -160,5 +163,8 @@ object RepositoryModule {
fun providesFCMRepository(api: FCMApi): FCMRepository =
FCMRepositoryImpl(api)


@Provides
@Singleton
fun providesNaverRepository(api: NaverApi): NaverRepository =
NaverRepositoryImpl(api)
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface HomeViewModel {
fun getMain()
fun patchFCM(token: String)

fun fetchGeocoding(query: String)

enum class ActivityEventBus {
SEARCH,
NEWS_DETAIL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.umc.ttoklip.data.model.fcm.FCMTokenRequest
import com.umc.ttoklip.data.model.home.HomeResponse
import com.umc.ttoklip.data.repository.fcm.FCMRepository
import com.umc.ttoklip.data.repository.home.HomeRepository
import com.umc.ttoklip.data.repository.naver.NaverRepository
import com.umc.ttoklip.module.NetworkResult
import com.umc.ttoklip.module.onException
import com.umc.ttoklip.module.onFail
Expand All @@ -28,6 +29,7 @@ import javax.inject.Inject
class HomeViewModelImpl @Inject constructor(
private val homeRepository: HomeRepository,
private val fcmRepository: FCMRepository,
private val naverRepository: NaverRepository
) : ViewModel(), HomeViewModel {

private val _haveWork: MutableStateFlow<Boolean> = MutableStateFlow(true)
Expand Down Expand Up @@ -124,4 +126,12 @@ class HomeViewModelImpl @Inject constructor(
}
}
}

override fun fetchGeocoding(query: String) {
viewModelScope.launch {
naverRepository.fetchGeocoding(query).onSuccess {
Log.d("naver", it.toString())
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ import com.umc.ttoklip.presentation.dialog.ImageDialogFragment
import com.umc.ttoklip.presentation.honeytip.read.ReadHoneyTipActivity
import com.umc.ttoklip.presentation.honeytip.read.ReadQuestionActivity
import com.umc.ttoklip.util.WriteHoneyTipUtil
import com.umc.ttoklip.util.uriToFile
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.ByteArrayOutputStream
import java.io.File

Expand All @@ -66,14 +70,16 @@ class WriteHoneyTipActivity :
private var isEdit = false
private var postId = 0
private var editImage = mutableListOf<Uri>()
private var selectedImageUris: List<Uri>? = null

private val pickMultipleMedia = registerForActivityResult(
ActivityResultContracts.PickMultipleVisualMedia(
100
)
) { uris ->
if (uris.isNotEmpty()) {
updateImages(uris)
selectedImageUris = uris
updateImages()
} else {
Log.d("PhotoPicker", "No media selected")
}
Expand Down Expand Up @@ -256,17 +262,31 @@ class WriteHoneyTipActivity :

private fun writeDone() {
binding.writeDoneBtn.setOnClickListener {
val beforeEditImages =
/*val beforeEditImages =
imageAdapter.currentList.filterIsInstance<Image>().map { it.url }.toList()
//convertURLtoURI(beforeEditImages)
val images = editImage + imageAdapter.currentList.filterIsInstance<Image>().map { it.uri }.filter { it != Uri.EMPTY }.toList()
Log.d("write done", images.size.toString())
val imageParts = WriteHoneyTipUtil(this).convertUriListToMultiBody(images)
val imageParts = WriteHoneyTipUtil(this).convertUriListToMultiBody(images)*/
Log.d("selectedImageUris", selectedImageUris.toString())
val imageParts = mutableListOf<MultipartBody.Part?>()
val images = imageAdapter.currentList.filterIsInstance<Image>().map { it.uri }.filter { it != Uri.EMPTY }.toList()
if(selectedImageUris == null || selectedImageUris!!.isEmpty()){
imageParts.add(null)
}
images.forEachIndexed { index, uri ->
val file = uriToFile(uri)
val requestFile = file.asRequestBody("image/*".toMediaTypeOrNull())
val body = MultipartBody.Part.createFormData("images", file.name, requestFile)
imageParts.add(body)
}
imageParts.forEach {
Log.d("용량", "${it.body.contentLength().toDouble() / (1024 * 1024)}")
if(it.body.contentLength().toDouble() / (1024 * 1024) > 10){
Toast.makeText(this, "사진 용량은 10MB로 제한되어있습니다.", Toast.LENGTH_SHORT).show()
return@setOnClickListener
if(it != null) {
Log.d("용량", "${it.body.contentLength().toDouble() / (1024 * 1024)}")
if (it.body.contentLength().toDouble() / (1024 * 1024) > 10) {
Toast.makeText(this, "사진 용량은 10MB로 제한되어있습니다.", Toast.LENGTH_SHORT).show()
return@setOnClickListener
}
}
}

Expand All @@ -278,7 +298,7 @@ class WriteHoneyTipActivity :
if(isEdit){
Log.d("it Edit", isEdit.toString())
viewModel.editHoneyTip(postId, title, content, category, imageParts, url)
Log.d("edit image imagepart", imageParts.contentToString())
Log.d("edit image imagepart", imageParts.toString())
editImage.forEach{
val delete = deleteImage(this@WriteHoneyTipActivity, it)
Log.d("delete", delete.toString())
Expand All @@ -287,7 +307,7 @@ class WriteHoneyTipActivity :
if (board == HONEY_TIPS) {
viewModel.createHoneyTip(title, content, category, imageParts, url)
} else {
viewModel.createQuestion(title, content, category, imageParts)
//viewModel.createQuestion(title, content, category, imageParts)
}
}
}
Expand Down Expand Up @@ -380,14 +400,17 @@ class WriteHoneyTipActivity :
}
}

private fun updateImages(uriList: List<Uri>) {
private fun updateImages() {
if(selectedImageUris.isNullOrEmpty()){
return
}
// uri 권한 확장
val flag = Intent.FLAG_GRANT_READ_URI_PERMISSION
uriList.forEach {
selectedImageUris!!.forEach {
applicationContext.contentResolver.takePersistableUriPermission(it, flag)
}

val images = uriList.map { Image(it, "") }
val images = selectedImageUris!!.map { Image(it, "") }
val updatedImages = imageAdapter.currentList.toMutableList().apply { addAll(images) }
imageAdapter.submitList(updatedImages)
}
Expand Down
Loading