mercredi 3 août 2016

Abstracting http client succinctly in Android?

Building a simple Android application, with many activities and each oftentimes requiring many requests.

Conforming to software-engineering quality standards I was thinking to:

  • Have a NounClient.class for each noun, containing com.android.volley utilising abstractions
  • Constructor example: AuthClient(final Context context, final String api_prefix) {
  • Set request queue in the constructor, instantiate with context
  • Mock backends for testing using MockHttpClient.java with mocked test-data responses

But I've run into some questions, namely:

  • Volley always delivers parsed responses on the main thread
  • UX affects should be close to the Activity code, so in e.g.: LoginActivty I'd have: authClient.login((String res) -> mTextView.setText(response));, but then I need lambda support with something like retrolambda
  • Abstracting UX affects should also simplify testing, but is this overengineering?

Is there a reference implementation showing best-practice setup with tested abstracted clients? - Or can you tell me how best to do this?

Aucun commentaire:

Enregistrer un commentaire