Last active
July 5, 2019 06:39
-
-
Save humayuntanwar/12b9ac6f8b8c52587418388d4aaa1083 to your computer and use it in GitHub Desktop.
Custom Retrofit CallBack Class to handle Custom Responses.
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
import android.app.Dialog | |
import android.content.Context | |
import android.util.Log | |
import android.view.View | |
import retrofit2.Call | |
import retrofit2.Callback | |
import retrofit2.Response | |
open class RetrofitCallback(private val mContext: Context) : Callback<GeneralResponse> { | |
private lateinit var progressDialog: Dialog | |
init { | |
progressDialog = Util.ProgressDialog(mContext) | |
progressDialog.show() | |
} | |
override fun onResponse(call: Call<GeneralResponse>, response: Response<GeneralResponse>) { | |
if (response.body() == null) { | |
//response is null | |
} else { | |
if (response.body()!!.code=="3333") { | |
//session timed out } | |
else if (response.body()!!.code=="1111") { | |
//failed } | |
} | |
} | |
override fun onFailure(call: Call<GeneralResponse>, t: Throwable) { | |
hideProgress() | |
if (t.message != null) { | |
Log.e(TAG, t.message) | |
} | |
} | |
private fun hideProgress() { | |
progressDialog.dismiss() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment