Last active
April 28, 2019 14:00
-
-
Save mataku/8eb195131941bd138b4bda7b4ed861fe to your computer and use it in GitHub Desktop.
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 retrofit2.Response | |
class ApiErrorHandler(val context: Context?) { | |
fun handle(response: Response) { | |
// レスポンスコードとエラーレスポンスの中身をパースしてユーザにエラー内容を伝えるためのなにかをする | |
} | |
} |
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 retrofit2.Response | |
class ExampleActivity : AppCompatActivity(), ExampleView { | |
fun showError(response: Response) { | |
ApiErrorHandler(this).handle(response) | |
} | |
} |
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 retrofit2.Response | |
class ExamplePresenter(val view: ExampleView) { | |
fun fetchName() { | |
ApiClient().create(UsersService::class.java) | |
.fetchName() | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe({ response -> | |
if (response.isSuccessful) { | |
view.showName(response.name) | |
} else { | |
view.showError(response) | |
} | |
... | |
} | |
} |
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 retrofit2.Response | |
interface ExampleView { | |
fun showName(name: String) | |
fun showError(response: Response) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment