Skip to content

Commit

Permalink
Merge pull request #106 from meongCare/feature/nutrition
Browse files Browse the repository at this point in the history
fix: 이상증상 관련 api 통신 에러 해결
  • Loading branch information
hxeyexn authored Jan 13, 2024
2 parents 332e718 + 09f22f5 commit c5d5025
Show file tree
Hide file tree
Showing 30 changed files with 1,164 additions and 769 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.project.meongcare.snackbar.view

import android.view.LayoutInflater
import android.view.View
import androidx.core.content.ContextCompat
import com.google.android.material.snackbar.Snackbar
import com.project.meongcare.databinding.LayoutSnackbarBinding

class CustomSnackBar(view: View, private val drawable: Int, private val message: String) {
companion object {
fun make(
view: View,
drawable: Int,
message: String,
) = CustomSnackBar(view, drawable, message)
}

private val context = view.context
private val snackbar = Snackbar.make(view, "", 1000)
private val snackbarLayout = snackbar.view as Snackbar.SnackbarLayout

private val inflater = LayoutInflater.from(context)
private val snackbarBinding: LayoutSnackbarBinding =
LayoutSnackbarBinding.inflate(inflater, null, false)

init {
initView()
initData()
}

private fun initView() {
with(snackbarLayout) {
removeAllViews()
setPadding(0, 0, 0, 0)
setBackgroundColor(ContextCompat.getColor(context, android.R.color.transparent))
addView(snackbarBinding.root, 0)
}
}

private fun initData() {
snackbarBinding.textViewLayoutSnackbar.text = message
snackbarBinding.imageViewLayoutSnackbar.setImageResource(drawable)
}

fun show() {
snackbar.show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.lang.reflect.Type

object RetrofitInstance {
object SupplementRetrofitInstance {
val BASE_URL = MainActivity.BASE_URL

val nullOnEmptyConverterFactory =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.project.meongcare.supplement.model.data.repository

import com.project.meongcare.MainActivity
import com.project.meongcare.supplement.model.data.remote.RetrofitInstance
import com.project.meongcare.supplement.model.data.remote.SupplementRetrofitInstance
import com.project.meongcare.supplement.model.data.remote.SupplementAPI
import com.project.meongcare.supplement.model.entities.DetailSupplement
import com.project.meongcare.supplement.model.entities.DogSupplement
Expand All @@ -12,7 +12,7 @@ import okhttp3.ResponseBody
class SupplementRepository {
companion object {
private val supplementAPI: SupplementAPI =
RetrofitInstance.getInstance().create(SupplementAPI::class.java)
SupplementRetrofitInstance.getInstance().create(SupplementAPI::class.java)
}

suspend fun getSupplements(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.project.meongcare.symptom.model.data.remote

import com.project.meongcare.symptom.model.entities.ResponseSymptom
import com.project.meongcare.symptom.model.entities.ResultSymptom
import com.project.meongcare.symptom.model.entities.ToAddSymptom
import com.project.meongcare.symptom.model.entities.ToEditSymptom
import retrofit2.Call
import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
Expand All @@ -16,28 +16,28 @@ import retrofit2.http.Query

interface SymptomAPI {
@GET("/symptom/{dogId}")
fun getResultSymptom(
suspend fun getSymptomList(
@Header("AccessToken") accessToken: String,
@Path("dogId") dogId: Int,
@Query("dateTime") dateTime: String,
): Call<ResultSymptom>
): Response<ResultSymptom>

@POST("/symptom")
fun addSymptom(
suspend fun addSymptom(
@Header("AccessToken") accessToken: String,
@Body requestBody: ToAddSymptom,
): Call<ResponseSymptom>
): Response<ResponseBody>

@DELETE("/symptom")
fun deleteSymptom(
suspend fun deleteSymptom(
@Header("AccessToken") accessToken: String,
@Query("symptomIds") symtomIds: IntArray,
): Call<ResponseSymptom>
): Response<ResponseBody>

@PATCH("/symptom")
fun editSymptom(
suspend fun patchSymptom(
@Header("AccessToken") accessToken: String,
@Body requestBody: ToEditSymptom,
): Call<ResponseSymptom>
): Response<ResponseBody>
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.project.meongcare.symptom.model.data.remote

import com.project.meongcare.MainActivity
import okhttp3.ResponseBody
import retrofit2.Converter
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.lang.reflect.Type

object SymptomRetrofitInstance {
val BASE_URL = MainActivity.BASE_URL

val nullOnEmptyConverterFactory =
object : Converter.Factory() {
fun converterFactory() = this

override fun responseBodyConverter(
type: Type,
annotations: Array<out Annotation>,
retrofit: Retrofit,
) = object : Converter<ResponseBody, Any?> {
val nextResponseBodyConverter =
retrofit.nextResponseBodyConverter<Any?>(
converterFactory(),
type,
annotations,
)

override fun convert(value: ResponseBody) =
if (value.contentLength() != 0L) nextResponseBodyConverter.convert(value) else null
}
}

val client =
Retrofit
.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(nullOnEmptyConverterFactory)
.addConverterFactory(GsonConverterFactory.create())
.build()

fun getInstance(): Retrofit {
return client
}
}
Loading

0 comments on commit c5d5025

Please sign in to comment.