Skip to content

hammmmy/PopularMovies

Repository files navigation

Travis-ci

Popular Movies

Popular Movies app for Android Nanodegree

To compile this project, insert your own TMDB key in strings.xml

The following concepts were used

Model View Presenter (MVP):

This project uses Model View Presenter Architecture. Reference : Android Architecture Samples, Android Testing Codelab The features are seperated by packages i.e. movie and detail. The View, Model, and Presenter are seperated . The interfaces between movie View and movie Presenter is MoviesContract and interface between detail View and detail Presenter is MovieDetailContract. Interface between Presenters and Repository is RepositoryContact.

RxJava2 with Retrofit2

TheMovieDbApiHelper class defines interfaces for both Retrofit2 only movie info retrieval and RxJava with Retrofit2 movie info retrieval. RxJava2 implementation is in MoviesServiceApiImpl and Retrofit2 only implementation is in MoviesServiceApiImplWithoutRx class. To use Retrofit2 only include the following dependencies in build.gradle:

compile "com.squareup.retrofit2:retrofit:${retrofitVersion}"
compile "com.squareup.retrofit2:converter-gson:${retrofitVersion}"

Using camel case with gson converter can save lives when using results from pojo :)

    Gson camelCaseGson = new GsonBuilder()
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .create();
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create(camelCaseGson))
            .build();

To use RxJava2 include the following:

a. Enable Java 8 I used Jack for Java8 support, which is depreciated. When I wrote this code, Java 8 language features were not built into the default toolchain. Jack compilation takes forever so including incremental builds can be a life saver.

defaultConfig {

    jackOptions {
        enabled true
        additionalParameters('jack.incremental': 'true')
    }
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

b. add RxJava2 support and RetroFit2 adapter for rxJava2

compile "com.squareup.retrofit2:adapter-rxjava2:${retrofitVersion}"
compile "io.reactivex.rxjava2:rxandroid:${rxAndroid}"
compile "io.reactivex.rxjava2:rxjava:${rxJava}"

Android Data Binding

I used to use ButterKnife but Android Data Binding library is pretty stable now. I would recommend using the data binding library. To add data binding support use the following in the build.gradle. I used it in movie_list_item and movie_detail_view by just adding layout tag in them.

<layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"></layout>

and then accessed them in MovieAdapter and MovieDetailFragment

Injection

Didn't use Dagger2. Just referred to Android Testing Codelab's injection method for testability. Unit and Instrument tests are not added yet though.

AutoFitGridLayout

I referred to this blog post to create AutoFitGridRecyclerView util class in my project.

Loading Images

I used Picasso in build.gradle, you guys may prefer Glide or any other relevant library.

 compile "com.squareup.picasso:picasso:${picassoVersion}"

    Picasso.with(mContext).load(movie.getPosterPath())
            .error(android.R.drawable.ic_menu_report_image)
            .into(viewHolder.mMovieViewBinding.posterThumbnail);

Material Design and Color Palette

I used Palette to get background and text colors in movie detail layout. I also tried to use a bit of material design in the project.

ContentProvider

I used ContentProvider for loading favorites as required by the course.

Tablet Layout

To distinguish between Tablet and Phone Layouts I added movie_item_detail_container in res/layout-w900dp/movie_list.xml which was not present in phone layout. The tablet layout loaded the detail fragment in movie_item_detail_container and the phone layout loads the detail fragment in MovieDetailActivity. You can refer to the implementation in MovieListActivity. Loader and ContentObserver is required for Tablet layouts where favorites can be added or removed right from the detail layout.

Disclaimer

The images in the projects are downloaded either from material.io or unsplash.com

Screenshots:

Preview

Preview

Preview

Preview

Preview

License

Copyright 2017 Hamid Mukhtar

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.