-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from meongCare/feature/nutrition
fix: 이상증상 관련 api 통신 에러 해결
- Loading branch information
Showing
30 changed files
with
1,164 additions
and
769 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/project/meongcare/snackbar/view/CustomSnackBar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/main/java/com/project/meongcare/symptom/model/data/remote/SymptomRetrofitInstance.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.