/ThumbnailApp

A simple code challenge

Primary LanguageJava

ThumbnailApp

#About A simple code challenge that requires getting a user list from a webservice and showing it in a grid. Also if we click in some of the thumbnails a request is sent to another webservice, the response is plain text that is shown in a Snackbar.

#Overall architecture I used a simplified version of Fernando Cejas Clean Architecture. I got rid of a couple of layers and the project isn't split in data, domain and presentation. Mainly I just kept the UseCases, the Repository pattern (although isn't 100% a repository pattern, lazy guilt there) and the MVP architecture.

#Technologies that I used

  • Picasso: To load the images fron the web through a simple API.
  • Dagger: To make the dependency injection.
  • Android SDK components: Just a RecyclerView with a GridLayoutManager.
  • Retrofit + OkHttpClient: To perform the HTTP requests.
  • Soundcloud's Lightcycle: To avoid hooking up the Presenter in each of the Fragment lifecycle methods. The Lightcycle library does this for us.
  • Butterknife: To avoid all the findViewById boilerplate code.
  • RxJava: To perform asynchronously the request and using the Subscribers as callbacks.

#Package organization

  • datasource: In this package I put the Repository concrete implementation.
  • di: All Dagger Modules are here.
  • model: The model classes are here, I didn't use entity mapper classes, so basically the model classes and the entity mapper classes are the same.
  • net: All the network layer related classes are here.
    • rest: The RESTful API interface is in this package and the concrete implementation that uses the Retrofit service class.
    • services: The Retrofit classes. The Retrofit service interface and the Retrofit factory class.
    • subscribers: Default subscribers implementations.
    • usecases: The UseCases implementations are in this package. Notice that I didn't inject the threads to avoid creating extra Modules, since the project is really small I think that doing so would be a waste.
  • repository: The repository interfaces. Since there's only one Repository implementation, and there's no memory layer Repositories or database Repositories I didn't inject this dependencies neither.
  • ui: All User Interface related classes are here, Activities, Fragments, Custom Views, etc.
    • main: Main screen classes. It only contains the MainActivity class.
    • challenge: Challenge screen classes. The challenge screen is the screen that shows the grid with the Player's thumbnails.
    • widgets: Custom view classes. It contains a custom TextView, the ThumbnailAppTextView and the TriangleShapeView which is a custom view that draws a right triangle fill with color, used as separator in the thumbnails.

#Notes

  • As you can see I got rid of a couple of layers from the Clean Architecture, because this app isn't complex enough to require those layers I avoided some dependency injections, for example: I didn't inject the Executor in the UseCase class. I didn't inject the OkHttpClient or the Retrofit instance in the ServiceFactory. I didn't inject the Repositories in the use cases.
  • Checked against Lollipop and Marshmellow (there's no special single permissons that can be taken off, so there's no need to perform any type of single permission validation).
  • I'll add some Robolectric Fragment unit testing using a mocked Presenter if I've time left this weekend :BAlready done! Check the ChallengeFragmentTest class. I've use Mockito + Robolectric.
  • I'm cancelling the image requests that're outside the Grid, this way if you scroll really fast through the grid, we'll avoid stacking up several request. Check the ViewHolder class, the cancelLoading method.
  • The MainActivity is being use only as a shell container for the Fragment. I like keeping all the logic in the Fragment/Presenters so Its easier to manage.

#Some screencaps alt tag

#APK Click here to download the apk debug deploy to your device.

#References