├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── markdown-navigator.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── iammert │ │ └── com │ │ └── androidarchitecture │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── iammert │ │ │ └── com │ │ │ └── androidarchitecture │ │ │ ├── AAApp.java │ │ │ ├── data │ │ │ ├── MovieRepository.java │ │ │ ├── NetworkBoundResource.java │ │ │ ├── Resource.java │ │ │ ├── Status.java │ │ │ ├── local │ │ │ │ ├── MovieDatabase.java │ │ │ │ ├── dao │ │ │ │ │ └── MovieDao.java │ │ │ │ └── entity │ │ │ │ │ └── MovieEntity.java │ │ │ └── remote │ │ │ │ ├── ApiConstants.java │ │ │ │ ├── MovieDBService.java │ │ │ │ ├── RequestInterceptor.java │ │ │ │ └── model │ │ │ │ └── MoviesResponse.java │ │ │ ├── databinding │ │ │ ├── ImageBindingAdapter.java │ │ │ └── ListBindingAdapter.java │ │ │ ├── di │ │ │ ├── ActivityBuilderModule.java │ │ │ ├── AppComponent.java │ │ │ ├── AppModule.java │ │ │ ├── FragmentBuilderModule.java │ │ │ ├── ViewModelKey.java │ │ │ └── ViewModelModule.java │ │ │ ├── ui │ │ │ ├── BaseActivity.java │ │ │ ├── BaseAdapter.java │ │ │ ├── BaseFragment.java │ │ │ ├── detail │ │ │ │ ├── MovieDetailActivity.java │ │ │ │ └── MovieDetailViewModel.java │ │ │ └── main │ │ │ │ ├── MainActivity.java │ │ │ │ ├── MovieListAdapter.java │ │ │ │ ├── MovieListCallback.java │ │ │ │ ├── MovieListFragment.java │ │ │ │ ├── MovieListViewModel.java │ │ │ │ └── MoviesPagerAdapter.java │ │ │ └── viewmodel │ │ │ └── MovieViewModelFactory.java │ └── res │ │ ├── drawable │ │ ├── ic_language_green_24dp.xml │ │ ├── ic_stars_green_24dp.xml │ │ └── placeholder.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_movie_detail.xml │ │ ├── fragment_movie_list.xml │ │ └── item_movie_list.xml │ │ ├── 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 │ │ ├── transition │ │ └── changebounds_with_arcmotion.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── iammert │ └── com │ └── androidarchitecture │ └── ExampleUnitTest.java ├── art └── art.png ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/ 38 | .idea/workspace.xml 39 | .idea/tasks.xml 40 | .idea/gradle.xml 41 | .idea/dictionaries 42 | .idea/libraries 43 | 44 | # Keystore files 45 | *.jks 46 | 47 | # External native build folder generated in Android Studio 2.2 and later 48 | .externalNativeBuild 49 | 50 | # Google Services (e.g. APIs or Firebase) 51 | google-services.json 52 | 53 | # Freeline 54 | freeline.py 55 | freeline/ 56 | freeline_project_description.json -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 35 | 36 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Android > Lint > Correctness 39 | 40 | 41 | Android > Lint > Performance 42 | 43 | 44 | Android > Lint > Usability > Icons 45 | 46 | 47 | 48 | 49 | Android 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 61 | 62 | 63 | 64 | 65 | 1.8 66 | 67 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidArchitecture 2 | Recommended architecture by Android. This repo shows that how to use LiveData, Room Persistence, Dagger 2, Retrofit, MVVM and DataBinding. 3 | 4 | 5 | 6 | # READ ME!!! 7 | Still under development. MovieList page is completed with recommended architecture techniques and new android components. Detail page will be completed soon. PRs are welcome. 8 | Replace your [MovieDB](https://www.themoviedb.org/documentation/api?language=en) API_KEY to run this example. 9 | 10 | License 11 | -------- 12 | 13 | 14 | Copyright 2017 Mert Şimşek. 15 | 16 | Licensed under the Apache License, Version 2.0 (the "License"); 17 | you may not use this file except in compliance with the License. 18 | You may obtain a copy of the License at 19 | 20 | http://www.apache.org/licenses/LICENSE-2.0 21 | 22 | Unless required by applicable law or agreed to in writing, software 23 | distributed under the License is distributed on an "AS IS" BASIS, 24 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | See the License for the specific language governing permissions and 26 | limitations under the License. 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/ 38 | .idea/workspace.xml 39 | .idea/tasks.xml 40 | .idea/gradle.xml 41 | .idea/dictionaries 42 | .idea/libraries 43 | 44 | # Keystore files 45 | *.jks 46 | 47 | # External native build folder generated in Android Studio 2.2 and later 48 | .externalNativeBuild 49 | 50 | # Google Services (e.g. APIs or Firebase) 51 | google-services.json 52 | 53 | # Freeline 54 | freeline.py 55 | freeline/ 56 | freeline_project_description.json -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | android { 3 | compileSdkVersion 29 4 | buildToolsVersion "29.0.2" 5 | defaultConfig { 6 | applicationId "iammert.com.androidarchitecture" 7 | minSdkVersion 21 8 | targetSdkVersion 29 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | 20 | dataBinding { 21 | enabled = true 22 | } 23 | 24 | compileOptions { 25 | sourceCompatibility JavaVersion.VERSION_1_8 26 | targetCompatibility JavaVersion.VERSION_1_8 27 | } 28 | 29 | } 30 | 31 | dependencies { 32 | implementation fileTree(dir: 'libs', include: ['*.jar']) 33 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { 34 | exclude group: 'com.android.support', module: 'support-annotations' 35 | }) 36 | testImplementation 'junit:junit:4.12' 37 | 38 | 39 | 40 | implementation 'androidx.appcompat:appcompat:1.1.0' 41 | implementation 'com.google.android.material:material:1.0.0' 42 | implementation'androidx.lifecycle:lifecycle-runtime:2.1.0' 43 | implementation'androidx.lifecycle:lifecycle-extensions:2.1.0' 44 | 45 | //noinspection LifecycleAnnotationProcessorWithJava8 46 | annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.1.0' 47 | implementation'androidx.room:room-runtime:2.2.2' 48 | annotationProcessor 'androidx.room:room-compiler:2.2.2' 49 | 50 | 51 | //dagger 52 | implementation "com.google.dagger:dagger:$daggerVersion" 53 | annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion" 54 | annotationProcessor "com.google.dagger:dagger-android-processor:$daggerVersion" 55 | implementation "com.google.dagger:dagger-android-support:$daggerVersion" 56 | 57 | implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" 58 | implementation "com.squareup.retrofit2:converter-gson:$gsonConverterVersion" 59 | implementation "com.squareup.okhttp3:okhttp:$okhttpVersion" 60 | 61 | implementation "com.squareup.picasso:picasso:$picassoVersion" 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | } 72 | 73 | -------------------------------------------------------------------------------- /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 /Users/mertsimsek/Library/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/androidTest/java/iammert/com/androidarchitecture/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture; 2 | 3 | import android.content.Context; 4 | import androidx.test.platform.app.InstrumentationRegistry; 5 | import androidx.test.ext.junit.runners.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("iammert.com.androidarchitecture", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /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/iammert/com/androidarchitecture/AAApp.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture; 2 | 3 | import android.app.Activity; 4 | import android.app.Application; 5 | 6 | import javax.inject.Inject; 7 | 8 | import dagger.android.AndroidInjector; 9 | import dagger.android.DispatchingAndroidInjector; 10 | import dagger.android.HasAndroidInjector; 11 | import iammert.com.androidarchitecture.di.DaggerAppComponent; 12 | 13 | /** 14 | * Created by mertsimsek on 20/05/2017. 15 | * Updated by johnjeremih on 27/11/2019 16 | */ 17 | 18 | public class AAApp extends Application implements HasAndroidInjector { 19 | 20 | @Inject 21 | DispatchingAndroidInjector activityDispatchingInjector; 22 | 23 | @Override 24 | public void onCreate() { 25 | super.onCreate(); 26 | initializeComponent(); 27 | } 28 | 29 | private void initializeComponent() { 30 | DaggerAppComponent.builder() 31 | .application(this) 32 | .build() 33 | .inject(this); 34 | } 35 | 36 | 37 | @Override 38 | public AndroidInjector androidInjector() { 39 | return activityDispatchingInjector; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/data/MovieRepository.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.data; 2 | 3 | import androidx.lifecycle.LiveData; 4 | import androidx.annotation.NonNull; 5 | 6 | import java.util.List; 7 | 8 | import javax.inject.Inject; 9 | 10 | import iammert.com.androidarchitecture.data.local.dao.MovieDao; 11 | import iammert.com.androidarchitecture.data.local.entity.MovieEntity; 12 | import iammert.com.androidarchitecture.data.remote.MovieDBService; 13 | import iammert.com.androidarchitecture.data.remote.model.MoviesResponse; 14 | import retrofit2.Call; 15 | 16 | /** 17 | * Created by mertsimsek on 19/05/2017. 18 | */ 19 | 20 | public class MovieRepository { 21 | 22 | private final MovieDao movieDao; 23 | private final MovieDBService movieDBService; 24 | 25 | @Inject 26 | public MovieRepository(MovieDao movieDao, MovieDBService movieDBService) { 27 | this.movieDao = movieDao; 28 | this.movieDBService = movieDBService; 29 | } 30 | 31 | public LiveData>> loadPopularMovies() { 32 | return new NetworkBoundResource, MoviesResponse>() { 33 | 34 | @Override 35 | protected void saveCallResult(@NonNull MoviesResponse item) { 36 | movieDao.saveMovies(item.getResults()); 37 | } 38 | 39 | @NonNull 40 | @Override 41 | protected LiveData> loadFromDb() { 42 | return movieDao.loadMovies(); 43 | } 44 | 45 | @NonNull 46 | @Override 47 | protected Call createCall() { 48 | return movieDBService.loadMovies(); 49 | } 50 | }.getAsLiveData(); 51 | } 52 | 53 | public LiveData getMovie(int id){ 54 | return movieDao.getMovie(id); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/data/NetworkBoundResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package iammert.com.androidarchitecture.data; 17 | 18 | import androidx.lifecycle.LiveData; 19 | import androidx.lifecycle.MediatorLiveData; 20 | import android.os.AsyncTask; 21 | import androidx.annotation.MainThread; 22 | import androidx.annotation.NonNull; 23 | import androidx.annotation.Nullable; 24 | import androidx.annotation.WorkerThread; 25 | 26 | import retrofit2.Call; 27 | import retrofit2.Callback; 28 | import retrofit2.Response; 29 | 30 | public abstract class NetworkBoundResource { 31 | private final MediatorLiveData> result = new MediatorLiveData<>(); 32 | 33 | @MainThread 34 | NetworkBoundResource() { 35 | result.setValue(Resource.loading(null)); 36 | LiveData dbSource = loadFromDb(); 37 | result.addSource(dbSource, data -> { 38 | result.removeSource(dbSource); 39 | if (shouldFetch(data)) { 40 | fetchFromNetwork(dbSource); 41 | } else { 42 | result.addSource(dbSource, newData -> result.setValue(Resource.success(newData))); 43 | } 44 | }); 45 | } 46 | 47 | private void fetchFromNetwork(final LiveData dbSource) { 48 | result.addSource(dbSource, newData -> result.setValue(Resource.loading(newData))); 49 | createCall().enqueue(new Callback() { 50 | @Override 51 | public void onResponse(Call call, Response response) { 52 | result.removeSource(dbSource); 53 | saveResultAndReInit(response.body()); 54 | } 55 | 56 | @Override 57 | public void onFailure(Call call, Throwable t) { 58 | onFetchFailed(); 59 | result.removeSource(dbSource); 60 | result.addSource(dbSource, newData -> result.setValue(Resource.error(t.getMessage(), newData))); 61 | } 62 | }); 63 | } 64 | 65 | @MainThread 66 | private void saveResultAndReInit(RequestType response) { 67 | new AsyncTask() { 68 | 69 | @Override 70 | protected Void doInBackground(Void... voids) { 71 | saveCallResult(response); 72 | return null; 73 | } 74 | 75 | @Override 76 | protected void onPostExecute(Void aVoid) { 77 | result.addSource(loadFromDb(), newData -> result.setValue(Resource.success(newData))); 78 | } 79 | }.execute(); 80 | } 81 | 82 | @WorkerThread 83 | protected abstract void saveCallResult(@NonNull RequestType item); 84 | 85 | @MainThread 86 | protected boolean shouldFetch(@Nullable ResultType data) { 87 | return true; 88 | } 89 | 90 | @NonNull 91 | @MainThread 92 | protected abstract LiveData loadFromDb(); 93 | 94 | @NonNull 95 | @MainThread 96 | protected abstract Call createCall(); 97 | 98 | @MainThread 99 | protected void onFetchFailed() { 100 | } 101 | 102 | public final LiveData> getAsLiveData() { 103 | return result; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/data/Resource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package iammert.com.androidarchitecture.data; 18 | 19 | import androidx.annotation.NonNull; 20 | import androidx.annotation.Nullable; 21 | 22 | import static iammert.com.androidarchitecture.data.Status.ERROR; 23 | import static iammert.com.androidarchitecture.data.Status.LOADING; 24 | import static iammert.com.androidarchitecture.data.Status.SUCCESS; 25 | 26 | 27 | /** 28 | * A generic class that holds a value with its loading status. 29 | * @param 30 | */ 31 | public class Resource { 32 | @NonNull 33 | public final Status status; 34 | @Nullable 35 | public final T data; 36 | @Nullable public final String message; 37 | private Resource(@NonNull Status status, @Nullable T data, @Nullable String message) { 38 | this.status = status; 39 | this.data = data; 40 | this.message = message; 41 | } 42 | 43 | public static Resource success(@NonNull T data) { 44 | return new Resource<>(SUCCESS, data, null); 45 | } 46 | 47 | public static Resource error(String msg, @Nullable T data) { 48 | return new Resource<>(ERROR, data, msg); 49 | } 50 | 51 | public static Resource loading(@Nullable T data) { 52 | return new Resource<>(LOADING, data, null); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/data/Status.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package iammert.com.androidarchitecture.data; 18 | 19 | /** 20 | * Status of a resource that is provided to the UI. 21 | *

22 | * These are usually created by the Repository classes where they return 23 | * {@code LiveData>} to pass back the latest data to the UI with its fetch status. 24 | */ 25 | public enum Status { 26 | SUCCESS, 27 | ERROR, 28 | LOADING 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/data/local/MovieDatabase.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.data.local; 2 | 3 | import androidx.room.Database; 4 | import androidx.room.RoomDatabase; 5 | 6 | import iammert.com.androidarchitecture.data.local.dao.MovieDao; 7 | import iammert.com.androidarchitecture.data.local.entity.MovieEntity; 8 | 9 | /** 10 | * Created by mertsimsek on 19/05/2017. 11 | */ 12 | @Database(entities = {MovieEntity.class}, version = 2) 13 | public abstract class MovieDatabase extends RoomDatabase{ 14 | 15 | public abstract MovieDao movieDao(); 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/data/local/dao/MovieDao.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.data.local.dao; 2 | 3 | import androidx.lifecycle.LiveData; 4 | import androidx.room.Dao; 5 | import androidx.room.Insert; 6 | import androidx.room.OnConflictStrategy; 7 | import androidx.room.Query; 8 | 9 | import java.util.List; 10 | 11 | import iammert.com.androidarchitecture.data.local.entity.MovieEntity; 12 | 13 | /** 14 | * Created by mertsimsek on 19/05/2017. 15 | */ 16 | @Dao 17 | public interface MovieDao { 18 | 19 | @Query("SELECT * FROM movies") 20 | LiveData> loadMovies(); 21 | 22 | @Insert(onConflict = OnConflictStrategy.REPLACE) 23 | void saveMovies(List movieEntities); 24 | 25 | @Query("SELECT * FROM movies WHERE id=:id") 26 | LiveData getMovie(int id); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/data/local/entity/MovieEntity.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.data.local.entity; 2 | 3 | import androidx.room.Entity; 4 | import androidx.room.PrimaryKey; 5 | 6 | import com.google.gson.annotations.SerializedName; 7 | 8 | /** 9 | * Created by mertsimsek on 19/05/2017. 10 | */ 11 | @Entity(tableName = "movies") 12 | public class MovieEntity { 13 | 14 | @PrimaryKey 15 | @SerializedName("id") 16 | private int id; 17 | 18 | @SerializedName("poster_path") 19 | private String posterPath; 20 | 21 | @SerializedName("adult") 22 | private boolean adult; 23 | 24 | @SerializedName("overview") 25 | private String overview; 26 | 27 | @SerializedName("original_title") 28 | private String originalTitle; 29 | 30 | @SerializedName("title") 31 | private String title; 32 | 33 | @SerializedName("vote_count") 34 | private int voteCount; 35 | 36 | @SerializedName("vote_average") 37 | private double voteAverage; 38 | 39 | @SerializedName("backdrop_path") 40 | private String backdropPath; 41 | 42 | @SerializedName("original_language") 43 | private String originalLanguage; 44 | 45 | public int getId() { 46 | return id; 47 | } 48 | 49 | public void setId(int id) { 50 | this.id = id; 51 | } 52 | 53 | public String getPosterPath() { 54 | return posterPath; 55 | } 56 | 57 | public void setPosterPath(String posterPath) { 58 | this.posterPath = posterPath; 59 | } 60 | 61 | public boolean isAdult() { 62 | return adult; 63 | } 64 | 65 | public void setAdult(boolean adult) { 66 | this.adult = adult; 67 | } 68 | 69 | public String getOverview() { 70 | return overview; 71 | } 72 | 73 | public void setOverview(String overview) { 74 | this.overview = overview; 75 | } 76 | 77 | public String getOriginalTitle() { 78 | return originalTitle; 79 | } 80 | 81 | public void setOriginalTitle(String originalTitle) { 82 | this.originalTitle = originalTitle; 83 | } 84 | 85 | public String getTitle() { 86 | return title; 87 | } 88 | 89 | public void setTitle(String title) { 90 | this.title = title; 91 | } 92 | 93 | public int getVoteCount() { 94 | return voteCount; 95 | } 96 | 97 | public void setVoteCount(int voteCount) { 98 | this.voteCount = voteCount; 99 | } 100 | 101 | public double getVoteAverage() { 102 | return voteAverage; 103 | } 104 | 105 | public void setVoteAverage(double voteAverage) { 106 | this.voteAverage = voteAverage; 107 | } 108 | 109 | public String getBackdropPath() { 110 | return backdropPath; 111 | } 112 | 113 | public void setBackdropPath(String backdropPath) { 114 | this.backdropPath = backdropPath; 115 | } 116 | 117 | public String getOriginalLanguage() { 118 | return originalLanguage; 119 | } 120 | 121 | public void setOriginalLanguage(String originalLanguage) { 122 | this.originalLanguage = originalLanguage; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/data/remote/ApiConstants.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.data.remote; 2 | 3 | /** 4 | * Created by mertsimsek on 19/05/2017. 5 | */ 6 | 7 | public class ApiConstants { 8 | 9 | public static final String ENDPOINT = "https://api.themoviedb.org/3/"; 10 | public static final String IMAGE_ENDPOINT_PREFIX = "https://image.tmdb.org/t/p/w500/"; 11 | public static final String API_KEY = ""; 12 | public static final int TIMEOUT_IN_SEC = 15; 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/data/remote/MovieDBService.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.data.remote; 2 | 3 | import iammert.com.androidarchitecture.data.remote.model.MoviesResponse; 4 | import retrofit2.Call; 5 | import retrofit2.http.GET; 6 | 7 | /** 8 | * Created by mertsimsek on 19/05/2017. 9 | */ 10 | 11 | public interface MovieDBService { 12 | 13 | @GET("movie/popular") 14 | Call loadMovies(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/data/remote/RequestInterceptor.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.data.remote; 2 | 3 | import androidx.annotation.NonNull; 4 | 5 | import java.io.IOException; 6 | 7 | import okhttp3.HttpUrl; 8 | import okhttp3.Interceptor; 9 | import okhttp3.Request; 10 | import okhttp3.Response; 11 | 12 | /** 13 | * Created by mertsimsek on 19/05/2017. 14 | */ 15 | 16 | public class RequestInterceptor implements Interceptor { 17 | 18 | @Override 19 | public Response intercept(@NonNull Chain chain) throws IOException { 20 | Request originalRequest = chain.request(); 21 | HttpUrl originalHttpUrl = originalRequest.url(); 22 | 23 | HttpUrl url = originalHttpUrl.newBuilder() 24 | .addQueryParameter("api_key", ApiConstants.API_KEY) 25 | .build(); 26 | 27 | Request request = originalRequest.newBuilder().url(url).build(); 28 | return chain.proceed(request); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/data/remote/model/MoviesResponse.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.data.remote.model; 2 | 3 | 4 | import java.util.List; 5 | 6 | import iammert.com.androidarchitecture.data.local.entity.MovieEntity; 7 | 8 | /** 9 | * Created by mertsimsek on 19/05/2017. 10 | */ 11 | 12 | public class MoviesResponse { 13 | private List results; 14 | 15 | public List getResults() { 16 | return results; 17 | } 18 | 19 | public void setResults(List results) { 20 | this.results = results; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/databinding/ImageBindingAdapter.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.databinding; 2 | 3 | import androidx.databinding.BindingAdapter; 4 | import androidx.core.content.ContextCompat; 5 | import android.widget.ImageView; 6 | 7 | import com.squareup.picasso.Picasso; 8 | 9 | import iammert.com.androidarchitecture.R; 10 | import iammert.com.androidarchitecture.data.remote.ApiConstants; 11 | 12 | /** 13 | * Created by mertsimsek on 20/05/2017. 14 | */ 15 | 16 | public final class ImageBindingAdapter { 17 | 18 | @BindingAdapter(value = "url") 19 | public static void loadImageUrl(ImageView view, String url) { 20 | if (url != null && !url.equals("")) 21 | Picasso.get() 22 | .load(ApiConstants.IMAGE_ENDPOINT_PREFIX + url) 23 | .placeholder(R.drawable.placeholder) 24 | .into(view); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/databinding/ListBindingAdapter.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.databinding; 2 | 3 | import androidx.databinding.BindingAdapter; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | 6 | import java.util.List; 7 | 8 | import iammert.com.androidarchitecture.data.Resource; 9 | import iammert.com.androidarchitecture.ui.BaseAdapter; 10 | 11 | /** 12 | * Created by mertsimsek on 20/05/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 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/di/ActivityBuilderModule.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.di; 2 | 3 | import dagger.Module; 4 | import dagger.android.ContributesAndroidInjector; 5 | import iammert.com.androidarchitecture.ui.detail.MovieDetailActivity; 6 | import iammert.com.androidarchitecture.ui.main.MainActivity; 7 | 8 | /** 9 | * Created by mertsimsek on 30/05/2017. 10 | */ 11 | @Module 12 | public abstract class ActivityBuilderModule { 13 | 14 | @ContributesAndroidInjector(modules = FragmentBuilderModule.class) 15 | abstract MainActivity mainActivity(); 16 | 17 | @ContributesAndroidInjector 18 | abstract MovieDetailActivity movieDetailActivity(); 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/di/AppComponent.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.di; 2 | 3 | import android.app.Application; 4 | 5 | import javax.inject.Singleton; 6 | 7 | import dagger.BindsInstance; 8 | import dagger.Component; 9 | import dagger.android.AndroidInjectionModule; 10 | import iammert.com.androidarchitecture.AAApp; 11 | 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(AAApp aaApp); 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/di/AppModule.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.di; 2 | 3 | import android.app.Application; 4 | import androidx.lifecycle.ViewModelProvider; 5 | import androidx.room.Room; 6 | 7 | import java.util.concurrent.TimeUnit; 8 | 9 | import javax.inject.Singleton; 10 | 11 | import dagger.Module; 12 | import dagger.Provides; 13 | import iammert.com.androidarchitecture.data.local.MovieDatabase; 14 | import iammert.com.androidarchitecture.data.local.dao.MovieDao; 15 | import iammert.com.androidarchitecture.data.remote.ApiConstants; 16 | import iammert.com.androidarchitecture.data.remote.MovieDBService; 17 | import iammert.com.androidarchitecture.data.remote.RequestInterceptor; 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(ApiConstants.TIMEOUT_IN_SEC, TimeUnit.SECONDS); 33 | okHttpClient.readTimeout(ApiConstants.TIMEOUT_IN_SEC, TimeUnit.SECONDS); 34 | okHttpClient.addInterceptor(new RequestInterceptor()); 35 | return okHttpClient.build(); 36 | } 37 | 38 | @Provides 39 | @Singleton 40 | MovieDBService provideRetrofit(OkHttpClient okHttpClient) { 41 | Retrofit retrofit = new Retrofit.Builder() 42 | .baseUrl(ApiConstants.ENDPOINT) 43 | .addConverterFactory(GsonConverterFactory.create()) 44 | .client(okHttpClient) 45 | .build(); 46 | 47 | return retrofit.create(MovieDBService.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 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/di/FragmentBuilderModule.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.di; 2 | 3 | import dagger.Module; 4 | import dagger.android.ContributesAndroidInjector; 5 | import iammert.com.androidarchitecture.ui.main.MovieListFragment; 6 | 7 | /** 8 | * Created by mertsimsek on 30/05/2017. 9 | */ 10 | @Module 11 | public abstract class FragmentBuilderModule { 12 | 13 | @ContributesAndroidInjector 14 | abstract MovieListFragment contributeMovieListFragment(); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/di/ViewModelKey.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.di; 2 | 3 | import androidx.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 value(); 23 | } -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/di/ViewModelModule.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.di; 2 | 3 | import androidx.lifecycle.ViewModel; 4 | import androidx.lifecycle.ViewModelProvider; 5 | 6 | import dagger.Binds; 7 | import dagger.Module; 8 | import dagger.multibindings.IntoMap; 9 | import iammert.com.androidarchitecture.ui.detail.MovieDetailViewModel; 10 | import iammert.com.androidarchitecture.ui.main.MovieListViewModel; 11 | import iammert.com.androidarchitecture.viewmodel.MovieViewModelFactory; 12 | 13 | /** 14 | * Created by mertsimsek on 19/06/2017. 15 | */ 16 | 17 | @Module 18 | public abstract class ViewModelModule { 19 | 20 | @Binds 21 | @IntoMap 22 | @ViewModelKey(MovieListViewModel.class) 23 | abstract ViewModel bindsMovieListViewModel(MovieListViewModel movieListViewModel); 24 | 25 | @Binds 26 | @IntoMap 27 | @ViewModelKey(MovieDetailViewModel.class) 28 | abstract ViewModel bindsMovieDetailViewModel(MovieDetailViewModel movieDetailViewModel); 29 | 30 | @Binds 31 | abstract ViewModelProvider.Factory bindsViewModelFactory(MovieViewModelFactory movieViewModelFactory); 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/ui/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.ui; 2 | 3 | import androidx.databinding.DataBindingUtil; 4 | import androidx.databinding.ViewDataBinding; 5 | import android.os.Bundle; 6 | import androidx.annotation.LayoutRes; 7 | import androidx.annotation.Nullable; 8 | import androidx.fragment.app.Fragment; 9 | import androidx.appcompat.app.AppCompatActivity; 10 | 11 | import javax.inject.Inject; 12 | 13 | import dagger.android.AndroidInjection; 14 | import dagger.android.DispatchingAndroidInjector; 15 | import dagger.android.support.DaggerAppCompatActivity; 16 | 17 | /** 18 | * Created by mertsimsek on 15/09/2017. 19 | * Updated by johnjeremih on 26/11/2019 20 | */ 21 | 22 | public abstract class BaseActivity extends DaggerAppCompatActivity { 23 | 24 | @Inject 25 | DispatchingAndroidInjector fragmentAndroidInjector; 26 | 27 | public DB dataBinding; 28 | 29 | @LayoutRes 30 | public abstract int getLayoutRes(); 31 | 32 | @Override 33 | protected void onCreate(@Nullable Bundle savedInstanceState) { 34 | AndroidInjection.inject(this); 35 | super.onCreate(savedInstanceState); 36 | dataBinding = DataBindingUtil.setContentView(this, getLayoutRes()); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/ui/BaseAdapter.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.ui; 2 | 3 | import androidx.recyclerview.widget.RecyclerView; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created by mertsimsek on 21/05/2017. 9 | */ 10 | 11 | public abstract class BaseAdapter extends RecyclerView.Adapter{ 12 | 13 | public abstract void setData(List data); 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/ui/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.ui; 2 | 3 | import androidx.lifecycle.LifecycleRegistry; 4 | import androidx.lifecycle.LifecycleRegistryOwner; 5 | import androidx.lifecycle.ViewModel; 6 | import androidx.lifecycle.ViewModelProvider; 7 | import androidx.lifecycle.ViewModelProviders; 8 | import androidx.databinding.DataBindingUtil; 9 | import androidx.databinding.ViewDataBinding; 10 | import android.os.Bundle; 11 | import androidx.annotation.LayoutRes; 12 | import androidx.annotation.Nullable; 13 | import androidx.fragment.app.Fragment; 14 | import android.view.LayoutInflater; 15 | import android.view.View; 16 | import android.view.ViewGroup; 17 | 18 | import javax.inject.Inject; 19 | 20 | import dagger.android.support.AndroidSupportInjection; 21 | 22 | /** 23 | * Created by mertsimsek on 15/09/2017. 24 | */ 25 | 26 | public abstract class BaseFragment extends Fragment implements LifecycleRegistryOwner { 27 | 28 | private LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this); 29 | 30 | @Inject 31 | ViewModelProvider.Factory viewModelFactory; 32 | 33 | public VM viewModel; 34 | 35 | public DB dataBinding; 36 | 37 | public abstract Class getViewModel(); 38 | 39 | @LayoutRes 40 | public abstract int getLayoutRes(); 41 | 42 | @Override 43 | public void onCreate(@Nullable Bundle savedInstanceState) { 44 | AndroidSupportInjection.inject(this); 45 | super.onCreate(savedInstanceState); 46 | viewModel = ViewModelProviders.of(this, viewModelFactory).get(getViewModel()); 47 | } 48 | 49 | @Nullable 50 | @Override 51 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 52 | dataBinding = DataBindingUtil.inflate(inflater, getLayoutRes(), container, false); 53 | return dataBinding.getRoot(); 54 | } 55 | 56 | @Override 57 | public LifecycleRegistry getLifecycle() { 58 | return lifecycleRegistry; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/ui/detail/MovieDetailActivity.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.ui.detail; 2 | 3 | import androidx.lifecycle.LifecycleOwner; 4 | import androidx.lifecycle.LifecycleRegistry; 5 | import androidx.lifecycle.LifecycleRegistryOwner; 6 | import androidx.lifecycle.ViewModelProvider; 7 | import androidx.lifecycle.ViewModelProviders; 8 | import android.content.Context; 9 | import android.content.Intent; 10 | import androidx.databinding.DataBindingUtil; 11 | import android.os.Bundle; 12 | import androidx.annotation.Nullable; 13 | import androidx.core.app.ActivityCompat; 14 | import androidx.appcompat.app.AppCompatActivity; 15 | import android.view.MenuItem; 16 | 17 | import javax.inject.Inject; 18 | 19 | import dagger.android.AndroidInjection; 20 | import iammert.com.androidarchitecture.R; 21 | import iammert.com.androidarchitecture.databinding.ActivityMovieDetailBinding; 22 | 23 | /** 24 | * Created by mertsimsek on 19/05/2017. 25 | */ 26 | 27 | public class MovieDetailActivity extends AppCompatActivity implements LifecycleOwner { 28 | 29 | private static final String KEY_MOVIE_ID = "key_movie_id"; 30 | 31 | LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this); 32 | 33 | ActivityMovieDetailBinding binding; 34 | 35 | @Inject 36 | ViewModelProvider.Factory viewModelFactory; 37 | 38 | MovieDetailViewModel movieDetailViewModel; 39 | 40 | public static Intent newIntent(Context context, int movieId) { 41 | Intent intent = new Intent(context, MovieDetailActivity.class); 42 | intent.putExtra(KEY_MOVIE_ID, movieId); 43 | return intent; 44 | } 45 | 46 | @Override 47 | protected void onCreate(@Nullable Bundle savedInstanceState) { 48 | AndroidInjection.inject(this); 49 | super.onCreate(savedInstanceState); 50 | binding = DataBindingUtil.setContentView(this, R.layout.activity_movie_detail); 51 | movieDetailViewModel = ViewModelProviders.of(this, viewModelFactory).get(MovieDetailViewModel.class); 52 | 53 | setSupportActionBar(binding.toolbar); 54 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 55 | 56 | int movieId = getIntent().getIntExtra(KEY_MOVIE_ID, 0); 57 | movieDetailViewModel.getMovie(movieId) 58 | .observe(this, movieEntity -> binding.setMovie(movieEntity)); 59 | } 60 | 61 | @Override 62 | public boolean onOptionsItemSelected(MenuItem item) { 63 | switch (item.getItemId()) { 64 | case android.R.id.home: 65 | ActivityCompat.finishAfterTransition(this); 66 | break; 67 | } 68 | return super.onOptionsItemSelected(item); 69 | } 70 | 71 | @Override 72 | public LifecycleRegistry getLifecycle() { 73 | return lifecycleRegistry; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/ui/detail/MovieDetailViewModel.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.ui.detail; 2 | 3 | import androidx.lifecycle.LiveData; 4 | import androidx.lifecycle.MutableLiveData; 5 | import androidx.lifecycle.ViewModel; 6 | 7 | import javax.inject.Inject; 8 | 9 | import iammert.com.androidarchitecture.data.MovieRepository; 10 | import iammert.com.androidarchitecture.data.Resource; 11 | import iammert.com.androidarchitecture.data.local.entity.MovieEntity; 12 | 13 | /** 14 | * Created by mertsimsek on 21/05/2017. 15 | */ 16 | 17 | public class MovieDetailViewModel extends ViewModel{ 18 | private final LiveData> movieDetail = new MutableLiveData<>(); 19 | private final MovieRepository movieRepository; 20 | 21 | @Inject 22 | public MovieDetailViewModel(MovieRepository movieRepository) { 23 | this.movieRepository = movieRepository; 24 | } 25 | 26 | public LiveData getMovie(int id){ 27 | return movieRepository.getMovie(id); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/ui/main/MainActivity.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.ui.main; 2 | 3 | import android.os.Bundle; 4 | 5 | import iammert.com.androidarchitecture.R; 6 | import iammert.com.androidarchitecture.databinding.ActivityMainBinding; 7 | import iammert.com.androidarchitecture.ui.BaseActivity; 8 | 9 | public class MainActivity extends BaseActivity { 10 | 11 | @Override 12 | public int getLayoutRes() { 13 | return R.layout.activity_main; 14 | } 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | dataBinding.viewPager.setAdapter(new MoviesPagerAdapter(getSupportFragmentManager())); 20 | dataBinding.tabs.setupWithViewPager(dataBinding.viewPager); 21 | dataBinding.viewPager.setOffscreenPageLimit(3); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/ui/main/MovieListAdapter.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.ui.main; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | 6 | import android.view.LayoutInflater; 7 | import android.view.ViewGroup; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | import iammert.com.androidarchitecture.data.local.entity.MovieEntity; 13 | import iammert.com.androidarchitecture.databinding.ItemMovieListBinding; 14 | import iammert.com.androidarchitecture.ui.BaseAdapter; 15 | 16 | /** 17 | * Created by mertsimsek on 20/05/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(ItemMovieListBinding binding, MovieListCallback callback) { 62 | super(binding.getRoot()); 63 | this.binding = binding; 64 | binding.getRoot().setOnClickListener(v -> 65 | callback.onMovieClicked(binding.getMovie(), binding.imageViewCover)); 66 | } 67 | 68 | public void onBind(MovieEntity movieEntity) { 69 | binding.setMovie(movieEntity); 70 | binding.executePendingBindings(); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/ui/main/MovieListCallback.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.ui.main; 2 | 3 | import android.view.View; 4 | 5 | import iammert.com.androidarchitecture.data.local.entity.MovieEntity; 6 | 7 | /** 8 | * Created by mertsimsek on 21/05/2017. 9 | */ 10 | 11 | public interface MovieListCallback { 12 | void onMovieClicked(MovieEntity movieEntity, View sharedView); 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/ui/main/MovieListFragment.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.ui.main; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.Nullable; 5 | import androidx.core.app.ActivityOptionsCompat; 6 | import androidx.recyclerview.widget.GridLayoutManager; 7 | 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | 12 | import iammert.com.androidarchitecture.R; 13 | import iammert.com.androidarchitecture.data.local.entity.MovieEntity; 14 | import iammert.com.androidarchitecture.databinding.FragmentMovieListBinding; 15 | import iammert.com.androidarchitecture.ui.BaseFragment; 16 | import iammert.com.androidarchitecture.ui.detail.MovieDetailActivity; 17 | 18 | /** 19 | * Created by mertsimsek on 19/05/2017. 20 | */ 21 | 22 | public class MovieListFragment extends BaseFragment implements MovieListCallback { 23 | 24 | public static MovieListFragment newInstance() { 25 | Bundle args = new Bundle(); 26 | MovieListFragment fragment = new MovieListFragment(); 27 | fragment.setArguments(args); 28 | return fragment; 29 | } 30 | 31 | @Override 32 | public Class getViewModel() { 33 | return MovieListViewModel.class; 34 | } 35 | 36 | @Override 37 | public int getLayoutRes() { 38 | return R.layout.fragment_movie_list; 39 | } 40 | 41 | @Nullable 42 | @Override 43 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 44 | super.onCreateView(inflater, container, savedInstanceState); 45 | dataBinding.recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2)); 46 | dataBinding.recyclerView.setAdapter(new MovieListAdapter(this)); 47 | return dataBinding.getRoot(); 48 | } 49 | 50 | @Override 51 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 52 | super.onActivityCreated(savedInstanceState); 53 | viewModel.getPopularMovies() 54 | .observe(this, listResource -> dataBinding.setResource(listResource)); 55 | } 56 | 57 | @Override 58 | public void onMovieClicked(MovieEntity movieEntity, View sharedView) { 59 | ActivityOptionsCompat options = ActivityOptionsCompat. 60 | makeSceneTransitionAnimation(getActivity(), sharedView, getString(R.string.shared_image)); 61 | startActivity(MovieDetailActivity.newIntent(getActivity(), movieEntity.getId()), options.toBundle()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/ui/main/MovieListViewModel.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.ui.main; 2 | 3 | import androidx.lifecycle.LiveData; 4 | import androidx.lifecycle.ViewModel; 5 | 6 | import java.util.List; 7 | 8 | import javax.inject.Inject; 9 | 10 | import iammert.com.androidarchitecture.data.MovieRepository; 11 | import iammert.com.androidarchitecture.data.Resource; 12 | import iammert.com.androidarchitecture.data.local.entity.MovieEntity; 13 | 14 | /** 15 | * Created by mertsimsek on 19/05/2017. 16 | */ 17 | 18 | public class MovieListViewModel extends ViewModel { 19 | private final LiveData>> popularMovies; 20 | 21 | @Inject 22 | public MovieListViewModel(MovieRepository movieRepository) { 23 | popularMovies = movieRepository.loadPopularMovies(); 24 | } 25 | 26 | LiveData>> getPopularMovies() { 27 | return popularMovies; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/iammert/com/androidarchitecture/ui/main/MoviesPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture.ui.main; 2 | 3 | import androidx.fragment.app.Fragment; 4 | import androidx.fragment.app.FragmentManager; 5 | import androidx.fragment.app.FragmentStatePagerAdapter; 6 | 7 | /** 8 | * Created by mertsimsek on 20/05/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/iammert/com/androidarchitecture/viewmodel/MovieViewModelFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | package iammert.com.androidarchitecture.viewmodel; 19 | 20 | import androidx.lifecycle.ViewModel; 21 | import androidx.lifecycle.ViewModelProvider; 22 | 23 | import java.util.Map; 24 | 25 | import javax.inject.Inject; 26 | import javax.inject.Provider; 27 | import javax.inject.Singleton; 28 | 29 | @Singleton 30 | public class MovieViewModelFactory implements ViewModelProvider.Factory { 31 | 32 | private final Map, Provider> creators; 33 | 34 | @Inject 35 | public MovieViewModelFactory(Map, Provider> creators) { 36 | this.creators = creators; 37 | } 38 | 39 | @Override 40 | public T create(Class modelClass) { 41 | Provider creator = creators.get(modelClass); 42 | if (creator == null) { 43 | for (Map.Entry, Provider> entry : creators.entrySet()) { 44 | if (modelClass.isAssignableFrom(entry.getKey())) { 45 | creator = entry.getValue(); 46 | break; 47 | } 48 | } 49 | } 50 | if (creator == null) { 51 | throw new IllegalArgumentException("unknown model class " + modelClass); 52 | } 53 | try { 54 | return (T) creator.get(); 55 | } catch (Exception e) { 56 | throw new RuntimeException(e); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_language_green_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_stars_green_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/placeholder.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 10 | 14 | 15 | 16 | 22 | 23 | 24 | 33 | 34 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 55 | 56 | 57 | 58 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_movie_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 9 | 10 | 11 | 16 | 17 | -------------------------------------------------------------------------------- /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/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iammert/AndroidArchitecture/1cf30263a31a3cf6b46e4c3334b5f4ec9cf3a48c/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iammert/AndroidArchitecture/1cf30263a31a3cf6b46e4c3334b5f4ec9cf3a48c/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iammert/AndroidArchitecture/1cf30263a31a3cf6b46e4c3334b5f4ec9cf3a48c/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iammert/AndroidArchitecture/1cf30263a31a3cf6b46e4c3334b5f4ec9cf3a48c/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iammert/AndroidArchitecture/1cf30263a31a3cf6b46e4c3334b5f4ec9cf3a48c/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iammert/AndroidArchitecture/1cf30263a31a3cf6b46e4c3334b5f4ec9cf3a48c/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iammert/AndroidArchitecture/1cf30263a31a3cf6b46e4c3334b5f4ec9cf3a48c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iammert/AndroidArchitecture/1cf30263a31a3cf6b46e4c3334b5f4ec9cf3a48c/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iammert/AndroidArchitecture/1cf30263a31a3cf6b46e4c3334b5f4ec9cf3a48c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iammert/AndroidArchitecture/1cf30263a31a3cf6b46e4c3334b5f4ec9cf3a48c/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/transition/changebounds_with_arcmotion.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFFFFF 4 | #e2e2e2 5 | #071C24 6 | #041116 7 | #80071C24 8 | #00E175 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14sp 4 | 16sp 5 | 18sp 6 | 20sp 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ArchMovies 3 | 4 | 5 | sharedimage 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 28 | 29 | 35 | 36 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/test/java/iammert/com/androidarchitecture/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package iammert.com.androidarchitecture; 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 | } -------------------------------------------------------------------------------- /art/art.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iammert/AndroidArchitecture/1cf30263a31a3cf6b46e4c3334b5f4ec9cf3a48c/art/art.png -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | maven { url 'https://maven.google.com' } 7 | jcenter() 8 | google() 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.5.2' 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | jcenter() 21 | maven { url 'https://maven.google.com' } 22 | google() 23 | } 24 | } 25 | 26 | task clean(type: Delete) { 27 | delete rootProject.buildDir 28 | } 29 | 30 | ext { 31 | daggerVersion = '2.25.2' 32 | retrofitVersion = '2.6.2' 33 | gsonConverterVersion = '2.6.2' 34 | okhttpVersion = '4.2.2' 35 | picassoVersion = '2.71828' 36 | archVersion = '1.0.0-alpha1' 37 | roomVersion = '2.2.1' 38 | 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /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 | android.enableJetifier=true 13 | android.useAndroidX=true 14 | org.gradle.jvmargs=-Xmx1536m 15 | 16 | # When configured, Gradle will run in incubating parallel mode. 17 | # This option should only be used with decoupled projects. More details, visit 18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 19 | # org.gradle.parallel=true 20 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iammert/AndroidArchitecture/1cf30263a31a3cf6b46e4c3334b5f4ec9cf3a48c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Nov 04 12:34:50 EST 2019 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-5.6.2-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------