├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── ic_stars_green_50_24dp.png
│ │ │ │ └── ic_language_green_50_24dp.png
│ │ │ ├── drawable-mdpi
│ │ │ │ ├── ic_stars_green_50_24dp.png
│ │ │ │ └── ic_language_green_50_24dp.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── ic_stars_green_50_24dp.png
│ │ │ │ ├── ic_language_green_50_24dp.png
│ │ │ │ └── placeholder.xml
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── ic_stars_green_50_24dp.png
│ │ │ │ └── ic_language_green_50_24dp.png
│ │ │ ├── drawable-xxxhdpi
│ │ │ │ ├── ic_stars_green_50_24dp.png
│ │ │ │ └── ic_language_green_50_24dp.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimen.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── transition
│ │ │ │ └── changebounds_with_arcmotion.xml
│ │ │ └── layout
│ │ │ │ ├── fragment_movie_list.xml
│ │ │ │ ├── item_movie_list.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── activity_movie_detail.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── sunil
│ │ │ │ └── androidarchitecturesample
│ │ │ │ ├── api
│ │ │ │ ├── Status.java
│ │ │ │ ├── ApiServices.java
│ │ │ │ ├── MoviesResponse.java
│ │ │ │ ├── RequestInterceptor.java
│ │ │ │ ├── Resource.java
│ │ │ │ ├── APIClient.java
│ │ │ │ └── NetworkBoundResource.java
│ │ │ │ ├── ui
│ │ │ │ ├── list
│ │ │ │ │ ├── MovieListCallback.java
│ │ │ │ │ ├── MovieListViewModel.java
│ │ │ │ │ ├── MoviesPagerAdapter.java
│ │ │ │ │ ├── MovieListAdapter.java
│ │ │ │ │ └── MovieListFragment.java
│ │ │ │ └── detail
│ │ │ │ │ ├── MovieDetailViewModel.java
│ │ │ │ │ └── MovieDetailActivity.java
│ │ │ │ ├── base
│ │ │ │ └── BaseAdapter.java
│ │ │ │ ├── util
│ │ │ │ └── Constant.java
│ │ │ │ ├── di
│ │ │ │ ├── FragmentBuilderModule.java
│ │ │ │ ├── ViewModelKey.java
│ │ │ │ ├── ActivityBuilderModule.java
│ │ │ │ ├── AppComponent.java
│ │ │ │ ├── ViewModelModule.java
│ │ │ │ └── AppModule.java
│ │ │ │ ├── db
│ │ │ │ ├── database
│ │ │ │ │ └── MovieDatabase.java
│ │ │ │ ├── dao
│ │ │ │ │ └── MovieDao.java
│ │ │ │ └── entity
│ │ │ │ │ └── MovieEntity.java
│ │ │ │ ├── databinding
│ │ │ │ ├── ImageBindingAdapter.java
│ │ │ │ └── ListBindingAdapter.java
│ │ │ │ ├── MainApplication.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── viewmodel
│ │ │ │ └── MovieViewModelFactory.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── sunil
│ │ │ └── androidarchitecturesample
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── sunil
│ │ └── androidarchitecturesample
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── inspectionProfiles
│ ├── profiles_settings.xml
│ └── Project_Default.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── Screenshot_20170917-143557.png
├── Screenshot_20170917-143609.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Screenshot_20170917-143557.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/Screenshot_20170917-143557.png
--------------------------------------------------------------------------------
/Screenshot_20170917-143609.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/Screenshot_20170917-143609.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_stars_green_50_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/drawable-hdpi/ic_stars_green_50_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_stars_green_50_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/drawable-mdpi/ic_stars_green_50_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_stars_green_50_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/drawable-xhdpi/ic_stars_green_50_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_stars_green_50_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/drawable-xxhdpi/ic_stars_green_50_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_language_green_50_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/drawable-hdpi/ic_language_green_50_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_language_green_50_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/drawable-mdpi/ic_language_green_50_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_language_green_50_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/drawable-xhdpi/ic_language_green_50_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_stars_green_50_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/drawable-xxxhdpi/ic_stars_green_50_24dp.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_language_green_50_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/drawable-xxhdpi/ic_language_green_50_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_language_green_50_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunil676/AndroidArchitectureSample/HEAD/app/src/main/res/drawable-xxxhdpi/ic_language_green_50_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidArchitectureSample
3 |
4 | sharedimage
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/placeholder.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/api/Status.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.api;
2 |
3 | /**
4 | * Created by sunil on 16-09-2017.
5 | */
6 |
7 | public enum Status {
8 | SUCCESS,
9 | ERROR,
10 | LOADING
11 | }
12 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Sep 16 13:15:43 IST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 14sp
4 | 16sp
5 | 18sp
6 | 20sp
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/api/ApiServices.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.api;
2 |
3 | import retrofit2.Call;
4 | import retrofit2.http.GET;
5 |
6 | /**
7 | * Created by sunil on 16-09-2017.
8 | */
9 |
10 | public interface ApiServices {
11 |
12 | @GET("movie/popular")
13 | Call loadMovies();
14 | }
15 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/ui/list/MovieListCallback.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.ui.list;
2 |
3 | import android.view.View;
4 |
5 | import com.sunil.androidarchitecturesample.db.entity.MovieEntity;
6 |
7 | /**
8 | * Created by sunil on 16-09-2017.
9 | */
10 |
11 | public interface MovieListCallback {
12 | void onMovieClicked(MovieEntity movieEntity, View sharedView);
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/base/BaseAdapter.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.base;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by sunil on 16-09-2017.
9 | */
10 |
11 | public abstract class BaseAdapter extends RecyclerView.Adapter{
12 |
13 | public abstract void setData(List data);
14 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #071C24
7 | #041116
8 | #80071C24
9 | #fff
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/util/Constant.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.util;
2 |
3 | /**
4 | * Created by sunil on 16-09-2017.
5 | */
6 |
7 | public class Constant {
8 | public static final String ENDPOINT = "https://api.themoviedb.org/3/";
9 | public static final String IMAGE_ENDPOINT_PREFIX = "https://image.tmdb.org/t/p/w500/";
10 | public static final String API_KEY = "";
11 | public static final int TIMEOUT_IN_SEC = 15;
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/di/FragmentBuilderModule.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.di;
2 |
3 | import com.sunil.androidarchitecturesample.ui.list.MovieListFragment;
4 |
5 | import dagger.Module;
6 | import dagger.android.ContributesAndroidInjector;
7 |
8 | /**
9 | * Created by mertsimsek on 30/05/2017.
10 | */
11 | @Module
12 | public abstract class FragmentBuilderModule {
13 |
14 | @ContributesAndroidInjector
15 | abstract MovieListFragment contributeMovieListFragment();
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/test/java/com/sunil/androidarchitecturesample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/api/MoviesResponse.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.api;
2 |
3 | import com.sunil.androidarchitecturesample.db.entity.MovieEntity;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by sunil on 16-09-2017.
9 | */
10 |
11 | public class MoviesResponse {
12 | private List results;
13 |
14 | public List getResults() {
15 | return results;
16 | }
17 |
18 | public void setResults(List results) {
19 | this.results = results;
20 | }
21 | }
--------------------------------------------------------------------------------
/app/src/main/res/transition/changebounds_with_arcmotion.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_movie_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
9 |
10 |
11 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/db/database/MovieDatabase.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.db.database;
2 |
3 | import android.arch.persistence.room.Database;
4 | import android.arch.persistence.room.RoomDatabase;
5 |
6 | import com.sunil.androidarchitecturesample.db.dao.MovieDao;
7 | import com.sunil.androidarchitecturesample.db.entity.MovieEntity;
8 |
9 | /**
10 | * Created by sunil on 16-09-2017.
11 | */
12 |
13 | @Database(entities = {MovieEntity.class}, version = 2)
14 | public abstract class MovieDatabase extends RoomDatabase {
15 |
16 | public abstract MovieDao movieDao();
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/di/ViewModelKey.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.di;
2 |
3 | import android.arch.lifecycle.ViewModel;
4 |
5 | import java.lang.annotation.Documented;
6 | import java.lang.annotation.ElementType;
7 | import java.lang.annotation.Retention;
8 | import java.lang.annotation.RetentionPolicy;
9 | import java.lang.annotation.Target;
10 |
11 | import dagger.MapKey;
12 |
13 | /**
14 | * Created by mertsimsek on 19/06/2017.
15 | */
16 |
17 | @Documented
18 | @Target({ElementType.METHOD})
19 | @Retention(RetentionPolicy.RUNTIME)
20 | @MapKey
21 | @interface ViewModelKey {
22 | Class extends ViewModel> value();
23 | }
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/di/ActivityBuilderModule.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.di;
2 |
3 | import com.sunil.androidarchitecturesample.MainActivity;
4 | import com.sunil.androidarchitecturesample.ui.detail.MovieDetailActivity;
5 |
6 | import dagger.Module;
7 | import dagger.android.ContributesAndroidInjector;
8 |
9 | /**
10 | * Created by mertsimsek on 30/05/2017.
11 | */
12 | @Module
13 | public abstract class ActivityBuilderModule {
14 |
15 | @ContributesAndroidInjector(modules = FragmentBuilderModule.class)
16 | abstract MainActivity mainActivity();
17 |
18 | @ContributesAndroidInjector
19 | abstract MovieDetailActivity movieDetailActivity();
20 | }
21 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/databinding/ImageBindingAdapter.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.databinding;
2 |
3 | import android.databinding.BindingAdapter;
4 | import android.widget.ImageView;
5 |
6 | import com.squareup.picasso.Picasso;
7 | import com.sunil.androidarchitecturesample.R;
8 | import com.sunil.androidarchitecturesample.util.Constant;
9 |
10 | /**
11 | * Created by sunil on 16-09-2017.
12 | */
13 |
14 | public final class ImageBindingAdapter {
15 |
16 | @BindingAdapter(value = "url")
17 | public static void loadImageUrl(ImageView view, String url) {
18 | if (url != null && !url.equals(""))
19 | Picasso.with(view.getContext())
20 | .load(Constant.IMAGE_ENDPOINT_PREFIX + url)
21 | .placeholder(R.drawable.placeholder)
22 | .into(view);
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/di/AppComponent.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.di;
2 |
3 | import android.app.Application;
4 |
5 | import com.sunil.androidarchitecturesample.MainApplication;
6 |
7 | import javax.inject.Singleton;
8 |
9 | import dagger.BindsInstance;
10 | import dagger.Component;
11 | import dagger.android.AndroidInjectionModule;
12 | /**
13 | * Created by mertsimsek on 20/05/2017.
14 | */
15 | @Singleton
16 | @Component(modules = {
17 | AppModule.class,
18 | AndroidInjectionModule.class,
19 | ActivityBuilderModule.class})
20 | public interface AppComponent {
21 |
22 | @Component.Builder
23 | interface Builder {
24 | @BindsInstance
25 | Builder application(Application application);
26 |
27 | AppComponent build();
28 | }
29 |
30 | void inject(MainApplication aaApp);
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/db/dao/MovieDao.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.db.dao;
2 |
3 | import android.arch.lifecycle.LiveData;
4 | import android.arch.persistence.room.Dao;
5 | import android.arch.persistence.room.Insert;
6 | import android.arch.persistence.room.OnConflictStrategy;
7 | import android.arch.persistence.room.Query;
8 |
9 | import com.sunil.androidarchitecturesample.db.entity.MovieEntity;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by sunil on 16-09-2017.
15 | */
16 |
17 | @Dao
18 | public interface MovieDao {
19 |
20 | @Query("SELECT * FROM movies")
21 | LiveData> loadMovies();
22 |
23 | @Insert(onConflict = OnConflictStrategy.REPLACE)
24 | void saveMovies(List movieEntities);
25 |
26 | @Query("SELECT * FROM movies WHERE id=:id")
27 | LiveData getMovie(int id);
28 |
29 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/sunil/androidarchitecturesample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.sunil.androidarchitecturesample", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/ui/list/MovieListViewModel.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.ui.list;
2 |
3 | import android.arch.lifecycle.LiveData;
4 | import android.arch.lifecycle.ViewModel;
5 |
6 | import com.sunil.androidarchitecturesample.api.APIClient;
7 | import com.sunil.androidarchitecturesample.api.Resource;
8 | import com.sunil.androidarchitecturesample.db.entity.MovieEntity;
9 |
10 | import java.util.List;
11 |
12 | import javax.inject.Inject;
13 |
14 | /**
15 | * Created by sunil on 16-09-2017.
16 | */
17 |
18 | public class MovieListViewModel extends ViewModel{
19 | private final LiveData>> popularMovies;
20 |
21 | @Inject
22 | public MovieListViewModel(APIClient movieRepository) {
23 | popularMovies = movieRepository.loadPopularMovies();
24 | }
25 |
26 | LiveData>> getPopularMovies() {
27 | return popularMovies;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/ui/list/MoviesPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.ui.list;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentStatePagerAdapter;
6 |
7 | /**
8 | * Created by sunil on 16-09-2017.
9 | */
10 |
11 | public class MoviesPagerAdapter extends FragmentStatePagerAdapter {
12 |
13 | private static final String[] titles = new String[]{"Popular", "Science", "Comedy"};
14 |
15 | public MoviesPagerAdapter(FragmentManager fm) {
16 | super(fm);
17 | }
18 |
19 | @Override
20 | public Fragment getItem(int i) {
21 | return MovieListFragment.newInstance();
22 | }
23 |
24 | @Override
25 | public int getCount() {
26 | return 3;
27 | }
28 |
29 | @Override
30 | public CharSequence getPageTitle(int position) {
31 | return titles[position];
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/databinding/ListBindingAdapter.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.databinding;
2 |
3 | import android.databinding.BindingAdapter;
4 | import android.support.v7.widget.RecyclerView;
5 |
6 | import com.sunil.androidarchitecturesample.api.Resource;
7 | import com.sunil.androidarchitecturesample.base.BaseAdapter;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * Created by sunil on 16-09-2017.
13 | */
14 |
15 | public final class ListBindingAdapter{
16 | @BindingAdapter(value = "resource")
17 | public static void setResource(RecyclerView recyclerView, Resource resource){
18 | RecyclerView.Adapter adapter = recyclerView.getAdapter();
19 | if(adapter == null)
20 | return;
21 |
22 | if(resource == null || resource.data == null)
23 | return;
24 |
25 | if(adapter instanceof BaseAdapter){
26 | ((BaseAdapter)adapter).setData((List) resource.data);
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_movie_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
10 |
11 |
12 |
18 |
19 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\sunil\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/ui/detail/MovieDetailViewModel.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.ui.detail;
2 |
3 | import android.arch.lifecycle.LiveData;
4 | import android.arch.lifecycle.MutableLiveData;
5 | import android.arch.lifecycle.ViewModel;
6 |
7 | import com.sunil.androidarchitecturesample.api.APIClient;
8 | import com.sunil.androidarchitecturesample.api.Resource;
9 | import com.sunil.androidarchitecturesample.db.entity.MovieEntity;
10 |
11 | import javax.inject.Inject;
12 |
13 | /**
14 | * Created by sunil on 16-09-2017.
15 | */
16 |
17 | public class MovieDetailViewModel extends ViewModel {
18 | private final LiveData> movieDetail = new MutableLiveData<>();
19 | private final APIClient movieRepository;
20 |
21 | @Inject
22 | public MovieDetailViewModel(APIClient movieRepository) {
23 | this.movieRepository = movieRepository;
24 | }
25 |
26 | public LiveData getMovie(int id){
27 | return movieRepository.getMovie(id);
28 | }
29 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/api/RequestInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.api;
2 |
3 | import android.provider.SyncStateContract;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.sunil.androidarchitecturesample.util.Constant;
7 |
8 | import java.io.IOException;
9 |
10 | import okhttp3.HttpUrl;
11 | import okhttp3.Interceptor;
12 | import okhttp3.Request;
13 | import okhttp3.Response;
14 |
15 | /**
16 | * Created by sunil on 16-09-2017.
17 | */
18 |
19 | public class RequestInterceptor implements Interceptor {
20 |
21 | @Override
22 | public Response intercept(@NonNull Chain chain) throws IOException {
23 | Request originalRequest = chain.request();
24 | HttpUrl originalHttpUrl = originalRequest.url();
25 |
26 | HttpUrl url = originalHttpUrl.newBuilder()
27 | .addQueryParameter("api_key", Constant.API_KEY)
28 | .build();
29 |
30 | Request request = originalRequest.newBuilder().url(url).build();
31 | return chain.proceed(request);
32 | }
33 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/api/Resource.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.api;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.annotation.Nullable;
5 |
6 | /**
7 | * Created by sunil on 16-09-2017.
8 | */
9 |
10 | public class Resource {
11 | @NonNull
12 | public final Status status;
13 | @Nullable
14 | public final T data;
15 | @Nullable public final String message;
16 | private Resource(@NonNull Status status, @Nullable T data, @Nullable String message) {
17 | this.status = status;
18 | this.data = data;
19 | this.message = message;
20 | }
21 |
22 | public static Resource success(@NonNull T data) {
23 | return new Resource<>(Status.SUCCESS, data, null);
24 | }
25 |
26 | public static Resource error(String msg, @Nullable T data) {
27 | return new Resource<>(Status.ERROR, data, msg);
28 | }
29 |
30 | public static Resource loading(@Nullable T data) {
31 | return new Resource<>(Status.LOADING, data, null);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/di/ViewModelModule.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.di;
2 |
3 | import android.arch.lifecycle.ViewModel;
4 | import android.arch.lifecycle.ViewModelProvider;
5 |
6 | import com.sunil.androidarchitecturesample.ui.detail.MovieDetailViewModel;
7 | import com.sunil.androidarchitecturesample.ui.list.MovieListViewModel;
8 | import com.sunil.androidarchitecturesample.viewmodel.MovieViewModelFactory;
9 |
10 | import dagger.Binds;
11 | import dagger.Module;
12 | import dagger.multibindings.IntoMap;
13 |
14 | /**
15 | * Created by mertsimsek on 19/06/2017.
16 | */
17 |
18 | @Module
19 | public abstract class ViewModelModule {
20 |
21 | @Binds
22 | @IntoMap
23 | @ViewModelKey(MovieListViewModel.class)
24 | abstract ViewModel bindsMovieListViewModel(MovieListViewModel movieListViewModel);
25 |
26 | @Binds
27 | @IntoMap
28 | @ViewModelKey(MovieDetailViewModel.class)
29 | abstract ViewModel bindsMovieDetailViewModel(MovieDetailViewModel movieDetailViewModel);
30 |
31 | @Binds
32 | abstract ViewModelProvider.Factory bindsViewModelFactory(MovieViewModelFactory movieViewModelFactory);
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/MainApplication.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 |
6 | import com.sunil.androidarchitecturesample.di.DaggerAppComponent;
7 |
8 | import javax.inject.Inject;
9 |
10 | import dagger.android.AndroidInjector;
11 | import dagger.android.DispatchingAndroidInjector;
12 | import dagger.android.HasActivityInjector;
13 |
14 | /**
15 | * Created by sunil on 16-09-2017.
16 | */
17 |
18 | public class MainApplication extends Application implements HasActivityInjector{
19 |
20 | @Inject
21 | DispatchingAndroidInjector activityDispatchingAndroidInjector;
22 |
23 | @Override
24 | public void onCreate() {
25 | super.onCreate();
26 | initializeComponent();
27 | }
28 |
29 | @Override
30 | public AndroidInjector activityInjector() {
31 | return activityDispatchingAndroidInjector;
32 | }
33 |
34 | private void initializeComponent() {
35 | DaggerAppComponent.builder()
36 | .application(this)
37 | .build()
38 | .inject(this);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample;
2 |
3 | import android.databinding.DataBindingUtil;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.os.Bundle;
7 |
8 | import com.sunil.androidarchitecturesample.databinding.ActivityMainBinding;
9 | import com.sunil.androidarchitecturesample.ui.list.MoviesPagerAdapter;
10 |
11 | import javax.inject.Inject;
12 |
13 | import dagger.android.AndroidInjection;
14 | import dagger.android.AndroidInjector;
15 | import dagger.android.DispatchingAndroidInjector;
16 | import dagger.android.support.HasSupportFragmentInjector;
17 |
18 | public class MainActivity extends AppCompatActivity implements HasSupportFragmentInjector{
19 |
20 | @Inject
21 | DispatchingAndroidInjector fragmentDispatchingAndroidInjector;
22 | ActivityMainBinding binding;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | AndroidInjection.inject(this);
27 | super.onCreate(savedInstanceState);
28 | binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
29 | binding.viewPager.setAdapter(new MoviesPagerAdapter(getSupportFragmentManager()));
30 | binding.tabs.setupWithViewPager(binding.viewPager);
31 | binding.viewPager.setOffscreenPageLimit(3);
32 | }
33 |
34 | @Override
35 | public AndroidInjector supportFragmentInjector() {
36 | return fragmentDispatchingAndroidInjector;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/viewmodel/MovieViewModelFactory.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.viewmodel;
2 |
3 | import android.arch.lifecycle.ViewModel;
4 | import android.arch.lifecycle.ViewModelProvider;
5 |
6 | import java.util.Map;
7 |
8 | import javax.inject.Inject;
9 | import javax.inject.Provider;
10 |
11 | /**
12 | * Created by sunil on 16-09-2017.
13 | */
14 |
15 | public class MovieViewModelFactory implements ViewModelProvider.Factory {
16 |
17 | private final Map, Provider extends ViewModel>> creators;
18 |
19 | @Inject
20 | public MovieViewModelFactory(Map, Provider extends ViewModel>> creators) {
21 | this.creators = creators;
22 | }
23 |
24 | @Override
25 | public T create(Class modelClass) {
26 | Provider extends ViewModel> creator = creators.get(modelClass);
27 | if (creator == null) {
28 | for (Map.Entry, Provider extends ViewModel>> entry : creators.entrySet()) {
29 | if (modelClass.isAssignableFrom(entry.getKey())) {
30 | creator = entry.getValue();
31 | break;
32 | }
33 | }
34 | }
35 | if (creator == null) {
36 | throw new IllegalArgumentException("unknown model class " + modelClass);
37 | }
38 | try {
39 | return (T) creator.get();
40 | } catch (Exception e) {
41 | throw new RuntimeException(e);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AndroidArchitectureSample
2 | Android Architecture component sample, to run this project add your api key in Constant file.
3 | ## Using library
4 |
5 | - [LiveData](https://developer.android.com/topic/libraries/architecture/livedata.html)
6 | LiveData is a data holder class that keeps a value and allows this value to be observed. Unlike a regular observable, LiveData respects the lifecycle of app components, such that the Observer can specify a Lifecycle in which it should observe..
7 | - [Lifecycle](https://developer.android.com/topic/libraries/architecture/lifecycle.html#lc)
8 | Lifecycle is a class that holds the information about the lifecycle state of a component (like an activity or a fragment) and allows other objects to observe this state..
9 | - [Retrofit2](https://github.com/square/retrofit)
10 | A library for networking operation and provide Reactive Nature.
11 | - [Dagger2](https://github.com/google/dagger)
12 | Dependency Injection for injecting the instance of object easy.
13 | - [Room](https://developer.android.com/topic/libraries/architecture/room.html)
14 | Room provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite..
15 | - DataBinding
16 | Bind the view easy.
17 | - [Material Design](https://material.io/)
18 | It provides the material deisgn for UI.
19 |
20 | 
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/api/APIClient.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.api;
2 |
3 | import android.arch.lifecycle.LiveData;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.sunil.androidarchitecturesample.db.dao.MovieDao;
7 | import com.sunil.androidarchitecturesample.db.entity.MovieEntity;
8 |
9 | import java.util.List;
10 |
11 | import javax.inject.Inject;
12 |
13 | import retrofit2.Call;
14 |
15 | /**
16 | * Created by sunil on 16-09-2017.
17 | */
18 |
19 | public class APIClient {
20 |
21 | private final MovieDao movieDao;
22 | private final ApiServices apiServices;
23 |
24 | @Inject
25 | public APIClient(MovieDao movieDao, ApiServices apiServices) {
26 | this.movieDao = movieDao;
27 | this.apiServices = apiServices;
28 | }
29 |
30 | public LiveData>> loadPopularMovies() {
31 | return new NetworkBoundResource, MoviesResponse>() {
32 |
33 | @Override
34 | protected void saveCallResult(@NonNull MoviesResponse item) {
35 | movieDao.saveMovies(item.getResults());
36 | }
37 |
38 | @NonNull
39 | @Override
40 | protected LiveData> loadFromDb() {
41 | return movieDao.loadMovies();
42 | }
43 |
44 | @NonNull
45 | @Override
46 | protected Call createCall() {
47 | return apiServices.loadMovies();
48 | }
49 | }.getAsLiveData();
50 | }
51 |
52 | public LiveData getMovie(int id){
53 | return movieDao.getMovie(id);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
26 |
27 |
33 |
34 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.1"
6 | defaultConfig {
7 | applicationId "com.sunil.androidarchitecturesample"
8 | minSdkVersion 15
9 | targetSdkVersion 26
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | dataBinding {
21 | enabled = true
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | exclude module: 'jsr305'
30 | })
31 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
32 | testCompile 'junit:junit:4.12'
33 |
34 | //support lib
35 | compile rootProject.ext.supportLibAppCompat
36 | compile rootProject.ext.supportLibDesign
37 |
38 | compile rootProject.ext.archRuntime
39 | compile rootProject.ext.archExtension
40 | annotationProcessor rootProject.ext.archCompiler
41 |
42 | compile rootProject.ext.roomRuntime
43 | annotationProcessor rootProject.ext.roomCompiler
44 |
45 | compile rootProject.ext.okhttp
46 | compile rootProject.ext.retrofit
47 | compile rootProject.ext.gsonConverter
48 |
49 | //dagger
50 | annotationProcessor rootProject.ext.daggerCompiler
51 | compile rootProject.ext.dagger
52 | compile rootProject.ext.daggerAndroid
53 | compile rootProject.ext.daggerAndroidSupport
54 | annotationProcessor rootProject.ext.daggerAndroidProcessor
55 |
56 | //ui
57 | compile rootProject.ext.picasso
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/di/AppModule.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.di;
2 |
3 | import android.app.Application;
4 | import android.arch.persistence.room.Room;
5 |
6 | import com.sunil.androidarchitecturesample.api.ApiServices;
7 | import com.sunil.androidarchitecturesample.api.RequestInterceptor;
8 | import com.sunil.androidarchitecturesample.db.dao.MovieDao;
9 | import com.sunil.androidarchitecturesample.db.database.MovieDatabase;
10 | import com.sunil.androidarchitecturesample.util.Constant;
11 |
12 | import java.util.concurrent.TimeUnit;
13 |
14 | import javax.inject.Singleton;
15 |
16 | import dagger.Module;
17 | import dagger.Provides;
18 | import okhttp3.OkHttpClient;
19 | import retrofit2.Retrofit;
20 | import retrofit2.converter.gson.GsonConverterFactory;
21 |
22 | /**
23 | * Created by mertsimsek on 20/05/2017.
24 | */
25 | @Module(includes = ViewModelModule.class)
26 | public class AppModule {
27 |
28 | @Provides
29 | @Singleton
30 | OkHttpClient provideOkHttpClient() {
31 | OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder();
32 | okHttpClient.connectTimeout(Constant.TIMEOUT_IN_SEC, TimeUnit.SECONDS);
33 | okHttpClient.readTimeout(Constant.TIMEOUT_IN_SEC, TimeUnit.SECONDS);
34 | okHttpClient.addInterceptor(new RequestInterceptor());
35 | return okHttpClient.build();
36 | }
37 |
38 | @Provides
39 | @Singleton
40 | ApiServices provideRetrofit(OkHttpClient okHttpClient) {
41 | Retrofit retrofit = new Retrofit.Builder()
42 | .baseUrl(Constant.ENDPOINT)
43 | .addConverterFactory(GsonConverterFactory.create())
44 | .client(okHttpClient)
45 | .build();
46 |
47 | return retrofit.create(ApiServices.class);
48 | }
49 |
50 | @Provides
51 | @Singleton
52 | MovieDatabase provideMovieDatabase(Application application) {
53 | return Room.databaseBuilder(application, MovieDatabase.class, "aa.db").build();
54 | }
55 |
56 | @Provides
57 | @Singleton
58 | MovieDao provideMovieDao(MovieDatabase movieDatabase) {
59 | return movieDatabase.movieDao();
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/ui/list/MovieListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.ui.list;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.sunil.androidarchitecturesample.base.BaseAdapter;
10 | import com.sunil.androidarchitecturesample.databinding.ItemMovieListBinding;
11 | import com.sunil.androidarchitecturesample.db.entity.MovieEntity;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | /**
17 | * Created by sunil on 16-09-2017.
18 | */
19 |
20 | public class MovieListAdapter extends BaseAdapter {
21 |
22 | private List movieEntities;
23 |
24 | private final MovieListCallback movieListCallback;
25 |
26 | public MovieListAdapter(@NonNull MovieListCallback movieListCallback) {
27 | movieEntities = new ArrayList<>();
28 | this.movieListCallback = movieListCallback;
29 | }
30 |
31 | @Override
32 | public void setData(List movieEntities) {
33 | this.movieEntities = movieEntities;
34 | notifyDataSetChanged();
35 | }
36 |
37 | @Override
38 | public MovieViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
39 | return MovieViewHolder.create(LayoutInflater.from(viewGroup.getContext()), viewGroup, movieListCallback);
40 | }
41 |
42 | @Override
43 | public void onBindViewHolder(MovieViewHolder viewHolder, int i) {
44 | viewHolder.onBind(movieEntities.get(i));
45 | }
46 |
47 | @Override
48 | public int getItemCount() {
49 | return movieEntities.size();
50 | }
51 |
52 | static class MovieViewHolder extends RecyclerView.ViewHolder {
53 |
54 | public static MovieViewHolder create(LayoutInflater inflater, ViewGroup parent, MovieListCallback callback) {
55 | ItemMovieListBinding itemMovieListBinding = ItemMovieListBinding.inflate(inflater, parent, false);
56 | return new MovieViewHolder(itemMovieListBinding, callback);
57 | }
58 |
59 | ItemMovieListBinding binding;
60 |
61 | public MovieViewHolder(final ItemMovieListBinding binding,final MovieListCallback callback) {
62 | super(binding.getRoot());
63 | this.binding = binding;
64 | binding.getRoot().setOnClickListener(new View.OnClickListener() {
65 | @Override
66 | public void onClick(View view) {
67 | callback.onMovieClicked(binding.getMovie(), binding.imageViewCover);
68 | }
69 | });
70 | }
71 |
72 | public void onBind(MovieEntity movieEntity) {
73 | binding.setMovie(movieEntity);
74 | binding.executePendingBindings();
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/ui/detail/MovieDetailActivity.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.ui.detail;
2 |
3 | import android.arch.lifecycle.LifecycleRegistry;
4 | import android.arch.lifecycle.LifecycleRegistryOwner;
5 | import android.arch.lifecycle.Observer;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.databinding.DataBindingUtil;
9 | import android.os.Bundle;
10 | import android.support.annotation.Nullable;
11 | import android.support.v4.app.ActivityCompat;
12 | import android.support.v7.app.AppCompatActivity;
13 | import android.view.MenuItem;
14 |
15 | import com.sunil.androidarchitecturesample.R;
16 | import com.sunil.androidarchitecturesample.databinding.ActivityMovieDetailBinding;
17 | import com.sunil.androidarchitecturesample.db.entity.MovieEntity;
18 |
19 | import javax.inject.Inject;
20 |
21 | import dagger.android.AndroidInjection;
22 | import dagger.android.HasActivityInjector;
23 |
24 | /**
25 | * Created by sunil on 16-09-2017.
26 | */
27 |
28 | public class MovieDetailActivity extends AppCompatActivity implements LifecycleRegistryOwner {
29 |
30 | private static final String KEY_MOVIE_ID = "key_movie_id";
31 |
32 | LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this);
33 |
34 | ActivityMovieDetailBinding binding;
35 |
36 | @Inject
37 | MovieDetailViewModel movieDetailViewModel;
38 |
39 | public static Intent newIntent(Context context, int movieId) {
40 | Intent intent = new Intent(context, MovieDetailActivity.class);
41 | intent.putExtra(KEY_MOVIE_ID, movieId);
42 | return intent;
43 | }
44 |
45 | @Override
46 | protected void onCreate(@Nullable Bundle savedInstanceState) {
47 | AndroidInjection.inject(this);
48 | super.onCreate(savedInstanceState);
49 | binding = DataBindingUtil.setContentView(this, R.layout.activity_movie_detail);
50 |
51 | setSupportActionBar(binding.toolbar);
52 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
53 |
54 | int movieId = getIntent().getIntExtra(KEY_MOVIE_ID, 0);
55 | movieDetailViewModel.getMovie(movieId)
56 | .observe(this, new Observer() {
57 | @Override
58 | public void onChanged(@Nullable MovieEntity movieEntity) {
59 | binding.setMovie(movieEntity);
60 | }
61 | });
62 | }
63 |
64 | @Override
65 | public boolean onOptionsItemSelected(MenuItem item) {
66 | switch (item.getItemId()) {
67 | case android.R.id.home:
68 | ActivityCompat.finishAfterTransition(this);
69 | break;
70 | }
71 | return super.onOptionsItemSelected(item);
72 | }
73 |
74 | @Override
75 | public LifecycleRegistry getLifecycle() {
76 | return lifecycleRegistry;
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
10 |
11 |
17 |
18 |
19 |
25 |
26 |
27 |
36 |
37 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
58 |
59 |
60 |
61 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/ui/list/MovieListFragment.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.ui.list;
2 |
3 | import android.arch.lifecycle.LifecycleFragment;
4 | import android.arch.lifecycle.Observer;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.ActivityOptionsCompat;
8 | import android.support.v7.widget.GridLayoutManager;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 |
13 | import com.sunil.androidarchitecturesample.R;
14 | import com.sunil.androidarchitecturesample.api.Resource;
15 | import com.sunil.androidarchitecturesample.databinding.FragmentMovieListBinding;
16 | import com.sunil.androidarchitecturesample.db.entity.MovieEntity;
17 | import com.sunil.androidarchitecturesample.ui.detail.MovieDetailActivity;
18 |
19 | import java.util.List;
20 |
21 | import javax.inject.Inject;
22 |
23 | import dagger.android.support.AndroidSupportInjection;
24 |
25 | /**
26 | * Created by sunil on 16-09-2017.
27 | */
28 |
29 | public class MovieListFragment extends LifecycleFragment implements MovieListCallback{
30 |
31 | @Inject
32 | MovieListViewModel movieListViewModel;
33 |
34 | FragmentMovieListBinding binding;
35 |
36 | public static MovieListFragment newInstance() {
37 | Bundle args = new Bundle();
38 | MovieListFragment fragment = new MovieListFragment();
39 | fragment.setArguments(args);
40 | return fragment;
41 | }
42 |
43 | @Override
44 | public void onCreate(@Nullable Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | AndroidSupportInjection.inject(this);
47 | }
48 |
49 | @Nullable
50 | @Override
51 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
52 | binding = FragmentMovieListBinding.inflate(inflater, container, false);
53 | binding.recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
54 | binding.recyclerView.setAdapter(new MovieListAdapter(this));
55 | return binding.getRoot();
56 | }
57 |
58 | @Override
59 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
60 | super.onActivityCreated(savedInstanceState);
61 | movieListViewModel
62 | .getPopularMovies()
63 | .observe(this, new Observer>>() {
64 | @Override
65 | public void onChanged(@Nullable Resource> listResource) {
66 | binding.setResource(listResource);
67 | }
68 | });
69 | }
70 |
71 |
72 | @Override
73 | public void onMovieClicked(MovieEntity movieEntity, View sharedView) {
74 | ActivityOptionsCompat options = ActivityOptionsCompat.
75 | makeSceneTransitionAnimation(getActivity(), sharedView, getString(R.string.shared_image));
76 | startActivity(MovieDetailActivity.newIntent(getActivity(), movieEntity.getId()), options.toBundle());
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/db/entity/MovieEntity.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.db.entity;
2 |
3 | import android.arch.persistence.room.Entity;
4 | import android.arch.persistence.room.PrimaryKey;
5 |
6 | import com.google.gson.annotations.SerializedName;
7 |
8 | /**
9 | * Created by sunil on 16-09-2017.
10 | */
11 |
12 | @Entity(tableName = "movies")
13 | public class MovieEntity {
14 |
15 | @PrimaryKey
16 | @SerializedName("id")
17 | private int id;
18 |
19 | @SerializedName("poster_path")
20 | private String posterPath;
21 |
22 | @SerializedName("adult")
23 | private boolean adult;
24 |
25 | @SerializedName("overview")
26 | private String overview;
27 |
28 | @SerializedName("original_title")
29 | private String originalTitle;
30 |
31 | @SerializedName("title")
32 | private String title;
33 |
34 | @SerializedName("vote_count")
35 | private int voteCount;
36 |
37 | @SerializedName("vote_average")
38 | private double voteAverage;
39 |
40 | @SerializedName("backdrop_path")
41 | private String backdropPath;
42 |
43 | @SerializedName("original_language")
44 | private String originalLanguage;
45 |
46 | public int getId() {
47 | return id;
48 | }
49 |
50 | public void setId(int id) {
51 | this.id = id;
52 | }
53 |
54 | public String getPosterPath() {
55 | return posterPath;
56 | }
57 |
58 | public void setPosterPath(String posterPath) {
59 | this.posterPath = posterPath;
60 | }
61 |
62 | public boolean isAdult() {
63 | return adult;
64 | }
65 |
66 | public void setAdult(boolean adult) {
67 | this.adult = adult;
68 | }
69 |
70 | public String getOverview() {
71 | return overview;
72 | }
73 |
74 | public void setOverview(String overview) {
75 | this.overview = overview;
76 | }
77 |
78 | public String getOriginalTitle() {
79 | return originalTitle;
80 | }
81 |
82 | public void setOriginalTitle(String originalTitle) {
83 | this.originalTitle = originalTitle;
84 | }
85 |
86 | public String getTitle() {
87 | return title;
88 | }
89 |
90 | public void setTitle(String title) {
91 | this.title = title;
92 | }
93 |
94 | public int getVoteCount() {
95 | return voteCount;
96 | }
97 |
98 | public void setVoteCount(int voteCount) {
99 | this.voteCount = voteCount;
100 | }
101 |
102 | public double getVoteAverage() {
103 | return voteAverage;
104 | }
105 |
106 | public void setVoteAverage(double voteAverage) {
107 | this.voteAverage = voteAverage;
108 | }
109 |
110 | public String getBackdropPath() {
111 | return backdropPath;
112 | }
113 |
114 | public void setBackdropPath(String backdropPath) {
115 | this.backdropPath = backdropPath;
116 | }
117 |
118 | public String getOriginalLanguage() {
119 | return originalLanguage;
120 | }
121 |
122 | public void setOriginalLanguage(String originalLanguage) {
123 | this.originalLanguage = originalLanguage;
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sunil/androidarchitecturesample/api/NetworkBoundResource.java:
--------------------------------------------------------------------------------
1 | package com.sunil.androidarchitecturesample.api;
2 |
3 | import android.arch.lifecycle.LiveData;
4 | import android.arch.lifecycle.MediatorLiveData;
5 | import android.arch.lifecycle.Observer;
6 | import android.os.AsyncTask;
7 | import android.support.annotation.MainThread;
8 | import android.support.annotation.NonNull;
9 | import android.support.annotation.Nullable;
10 | import android.support.annotation.WorkerThread;
11 |
12 | import retrofit2.Call;
13 | import retrofit2.Callback;
14 | import retrofit2.Response;
15 |
16 | /**
17 | * Created by sunil on 16-09-2017.
18 | */
19 |
20 | public abstract class NetworkBoundResource {
21 | private final MediatorLiveData> result = new MediatorLiveData<>();
22 |
23 | @MainThread
24 | NetworkBoundResource() {
25 | //result.setValue(Resource.loading(null));
26 | final LiveData dbSource = loadFromDb();
27 | result.addSource(dbSource, new Observer() {
28 | @Override
29 | public void onChanged(@Nullable ResultType resultType) {
30 | result.removeSource(dbSource);
31 | if (shouldFetch(resultType)) {
32 | fetchFromNetwork(dbSource);
33 | } else {
34 | result.addSource(dbSource, new Observer() {
35 | @Override
36 | public void onChanged(@Nullable ResultType resultType) {
37 | result.setValue(Resource.success(resultType));
38 | }
39 | });
40 | }
41 | }
42 | });
43 | }
44 |
45 | private void fetchFromNetwork(final LiveData dbSource) {
46 | result.addSource(dbSource, new Observer() {
47 | @Override
48 | public void onChanged(@Nullable ResultType resultType) {
49 | result.setValue(Resource.loading(resultType));
50 | }
51 | });
52 | createCall().enqueue(new Callback() {
53 | @Override
54 | public void onResponse(Call call, Response response) {
55 | result.removeSource(dbSource);
56 | saveResultAndReInit(response.body());
57 | }
58 |
59 | @Override
60 | public void onFailure(Call call, final Throwable t) {
61 | onFetchFailed();
62 | result.removeSource(dbSource);
63 | result.addSource(dbSource, new Observer() {
64 | @Override
65 | public void onChanged(@Nullable ResultType resultType) {
66 | result.setValue(Resource.error(t.getMessage(), resultType));
67 | }
68 | });
69 | }
70 | });
71 | }
72 |
73 | @MainThread
74 | private void saveResultAndReInit(final RequestType response) {
75 | new AsyncTask() {
76 |
77 | @Override
78 | protected Void doInBackground(Void... voids) {
79 | saveCallResult(response);
80 | return null;
81 | }
82 |
83 | @Override
84 | protected void onPostExecute(Void aVoid) {
85 | result.addSource(loadFromDb(), new Observer() {
86 | @Override
87 | public void onChanged(@Nullable ResultType resultType) {
88 | result.setValue(Resource.success(resultType));
89 | }
90 | });
91 | }
92 | }.execute();
93 | }
94 |
95 | @WorkerThread
96 | protected abstract void saveCallResult(@NonNull RequestType item);
97 |
98 | @MainThread
99 | protected boolean shouldFetch(@Nullable ResultType data) {
100 | return true;
101 | }
102 |
103 | @NonNull
104 | @MainThread
105 | protected abstract LiveData loadFromDb();
106 |
107 | @NonNull
108 | @MainThread
109 | protected abstract Call createCall();
110 |
111 | @MainThread
112 | protected void onFetchFailed() {
113 | }
114 |
115 | public final LiveData> getAsLiveData() {
116 | return result;
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_movie_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
10 |
11 |
12 |
13 |
18 |
19 |
23 |
24 |
28 |
29 |
30 |
39 |
40 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
58 |
59 |
66 |
67 |
73 |
74 |
79 |
80 |
84 |
85 |
93 |
94 |
95 |
96 |
101 |
102 |
106 |
107 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
131 |
132 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
--------------------------------------------------------------------------------