├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── dictionaries │ └── ennur.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── plaps │ │ └── androidcleancode │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── plaps │ │ │ └── androidcleancode │ │ │ ├── BaseApp.java │ │ │ ├── deps │ │ │ └── Deps.java │ │ │ ├── home │ │ │ ├── HomeActivity.java │ │ │ ├── HomeAdapter.java │ │ │ ├── HomePresenter.java │ │ │ └── HomeView.java │ │ │ ├── models │ │ │ ├── CityListData.java │ │ │ └── CityListResponse.java │ │ │ └── networking │ │ │ ├── NetworkError.java │ │ │ ├── NetworkModule.java │ │ │ ├── NetworkService.java │ │ │ ├── Response.java │ │ │ └── Service.java │ └── res │ │ ├── layout │ │ ├── activity_home.xml │ │ └── item_home.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── plaps │ └── androidcleancode │ ├── HomePresenterTest.java │ └── RxSchedulersOverrideRule.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.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/dictionaries/ennur.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | Android 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 51 | 52 | 53 | 54 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Clean-Android-Code 2 | 3 | Sample demo to implement MVP, Dagger 2, RxJava and Retrofit 2 4 | 5 | See the tutorial at https://medium.com/@nurrohman/a-simple-android-apps-with-mvp-dagger-rxjava-and-retrofit-4edb214a66d7#.o8fsr2904 6 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | } 8 | 9 | android { 10 | compileSdkVersion 26 11 | 12 | defaultConfig { 13 | applicationId "com.plaps.androidcleancode" 14 | minSdkVersion 14 15 | targetSdkVersion 26 16 | versionCode 1 17 | versionName "1.0" 18 | 19 | buildConfigField "int", "LIMIT", "100" 20 | buildConfigField "String", "BASEURL", "\"http://private-b8cf44-androidcleancode.apiary-mock.com/\"" 21 | buildConfigField "int", "CACHETIME", "432000" // 5days 22 | } 23 | buildTypes { 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | } 30 | 31 | dependencies { 32 | implementation fileTree(dir: 'libs', include: ['*.jar']) 33 | testImplementation 'junit:junit:4.12' 34 | implementation 'com.android.support:appcompat-v7:26.1.0' 35 | implementation 'com.android.support:design:26.1.0' 36 | implementation 'com.android.support:recyclerview-v7:26.1.0' 37 | implementation 'com.android.support:cardview-v7:26.1.0' 38 | implementation 'com.github.bumptech.glide:glide:4.3.1' 39 | implementation 'com.google.code.gson:gson:2.8.2' 40 | implementation 'com.squareup.retrofit2:retrofit:2.3.0' 41 | implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0' 42 | implementation 'com.squareup.retrofit2:converter-gson:2.3.0' 43 | implementation 'com.squareup.retrofit2:converter-scalars:2.1.0' 44 | implementation 'io.reactivex:rxandroid:1.2.1' 45 | implementation 'io.reactivex:rxjava:1.1.6' 46 | implementation 'com.google.dagger:dagger:2.5' 47 | annotationProcessor 'com.google.dagger:dagger-compiler:2.5' 48 | provided 'javax.annotation:jsr250-api:1.0' 49 | provided 'org.glassfish:javax.annotation:10.0-b28' 50 | 51 | //Mockito 52 | testImplementation 'org.mockito:mockito-core:2.15.0' 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /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/ennur/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 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/plaps/androidcleancode/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/plaps/androidcleancode/BaseApp.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | import com.plaps.androidcleancode.deps.DaggerDeps; 7 | import com.plaps.androidcleancode.deps.Deps; 8 | import com.plaps.androidcleancode.networking.NetworkModule; 9 | 10 | import java.io.File; 11 | 12 | /** 13 | * Created by ennur on 6/28/16. 14 | */ 15 | public class BaseApp extends AppCompatActivity{ 16 | Deps deps; 17 | 18 | @Override 19 | public void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | File cacheFile = new File(getCacheDir(), "responses"); 22 | deps = DaggerDeps.builder().networkModule(new NetworkModule(cacheFile)).build(); 23 | 24 | } 25 | 26 | public Deps getDeps() { 27 | return deps; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/plaps/androidcleancode/deps/Deps.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode.deps; 2 | 3 | 4 | import com.plaps.androidcleancode.home.HomeActivity; 5 | import com.plaps.androidcleancode.networking.NetworkModule; 6 | 7 | import javax.inject.Singleton; 8 | 9 | import dagger.Component; 10 | 11 | /** 12 | * Created by ennur on 6/28/16. 13 | */ 14 | @Singleton 15 | @Component(modules = {NetworkModule.class,}) 16 | public interface Deps { 17 | void inject(HomeActivity homeActivity); 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/plaps/androidcleancode/home/HomeActivity.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode.home; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.widget.LinearLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.View; 7 | import android.widget.ProgressBar; 8 | import android.widget.Toast; 9 | 10 | import com.plaps.androidcleancode.BaseApp; 11 | import com.plaps.androidcleancode.R; 12 | import com.plaps.androidcleancode.models.CityListData; 13 | import com.plaps.androidcleancode.models.CityListResponse; 14 | import com.plaps.androidcleancode.networking.Service; 15 | 16 | import javax.inject.Inject; 17 | 18 | public class HomeActivity extends BaseApp implements HomeView { 19 | 20 | private RecyclerView list; 21 | @Inject 22 | public Service service; 23 | ProgressBar progressBar; 24 | 25 | @Override 26 | public void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | getDeps().inject(this); 29 | 30 | renderView(); 31 | init(); 32 | 33 | HomePresenter presenter = new HomePresenter(service, this); 34 | presenter.getCityList(); 35 | } 36 | 37 | public void renderView(){ 38 | setContentView(R.layout.activity_home); 39 | list = findViewById(R.id.list); 40 | progressBar = findViewById(R.id.progress); 41 | } 42 | 43 | public void init(){ 44 | list.setLayoutManager(new LinearLayoutManager(this)); 45 | } 46 | 47 | @Override 48 | public void showWait() { 49 | progressBar.setVisibility(View.VISIBLE); 50 | } 51 | 52 | @Override 53 | public void removeWait() { 54 | progressBar.setVisibility(View.GONE); 55 | } 56 | 57 | @Override 58 | public void onFailure(String appErrorMessage) { 59 | 60 | } 61 | 62 | @Override 63 | public void getCityListSuccess(CityListResponse cityListResponse) { 64 | 65 | HomeAdapter adapter = new HomeAdapter(getApplicationContext(), cityListResponse.getData(), 66 | new HomeAdapter.OnItemClickListener() { 67 | @Override 68 | public void onClick(CityListData Item) { 69 | Toast.makeText(getApplicationContext(), Item.getName(), 70 | Toast.LENGTH_LONG).show(); 71 | } 72 | }); 73 | 74 | list.setAdapter(adapter); 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/com/plaps/androidcleancode/home/HomeAdapter.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode.home; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.bumptech.glide.Glide; 12 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 13 | import com.plaps.androidcleancode.R; 14 | import com.plaps.androidcleancode.models.CityListData; 15 | 16 | import java.util.List; 17 | 18 | public class HomeAdapter extends RecyclerView.Adapter { 19 | private final OnItemClickListener listener; 20 | private List data; 21 | private Context context; 22 | 23 | public HomeAdapter(Context context, List data, OnItemClickListener listener) { 24 | this.data = data; 25 | this.listener = listener; 26 | this.context = context; 27 | } 28 | 29 | 30 | @Override 31 | public HomeAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 32 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home, null); 33 | view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT)); 34 | return new ViewHolder(view); 35 | } 36 | 37 | 38 | @Override 39 | public void onBindViewHolder(HomeAdapter.ViewHolder holder, int position) { 40 | holder.click(data.get(position), listener); 41 | holder.tvCity.setText(data.get(position).getName()); 42 | holder.tvDesc.setText(data.get(position).getDescription()); 43 | 44 | String images = data.get(position).getBackground(); 45 | 46 | Glide.with(context) 47 | .load(images) 48 | .into(holder.background); 49 | 50 | } 51 | 52 | 53 | @Override 54 | public int getItemCount() { 55 | return data.size(); 56 | } 57 | 58 | 59 | public interface OnItemClickListener { 60 | void onClick(CityListData Item); 61 | } 62 | 63 | public class ViewHolder extends RecyclerView.ViewHolder { 64 | TextView tvCity, tvDesc; 65 | ImageView background; 66 | 67 | public ViewHolder(View itemView) { 68 | super(itemView); 69 | tvCity = itemView.findViewById(R.id.city); 70 | tvDesc = itemView.findViewById(R.id.hotel); 71 | background = itemView.findViewById(R.id.image); 72 | 73 | } 74 | 75 | 76 | public void click(final CityListData cityListData, final OnItemClickListener listener) { 77 | itemView.setOnClickListener(new View.OnClickListener() { 78 | @Override 79 | public void onClick(View v) { 80 | listener.onClick(cityListData); 81 | } 82 | }); 83 | } 84 | } 85 | 86 | 87 | } 88 | -------------------------------------------------------------------------------- /app/src/main/java/com/plaps/androidcleancode/home/HomePresenter.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode.home; 2 | 3 | import com.plaps.androidcleancode.models.CityListResponse; 4 | import com.plaps.androidcleancode.networking.NetworkError; 5 | import com.plaps.androidcleancode.networking.Service; 6 | 7 | import rx.Subscription; 8 | import rx.subscriptions.CompositeSubscription; 9 | 10 | /** 11 | * Created by ennur on 6/25/16. 12 | */ 13 | public class HomePresenter { 14 | private final Service service; 15 | private final HomeView view; 16 | private CompositeSubscription subscriptions; 17 | 18 | public HomePresenter(Service service, HomeView view) { 19 | this.service = service; 20 | this.view = view; 21 | this.subscriptions = new CompositeSubscription(); 22 | } 23 | 24 | public void getCityList() { 25 | view.showWait(); 26 | 27 | Subscription subscription = service.getCityList(new Service.GetCityListCallback() { 28 | @Override 29 | public void onSuccess(CityListResponse cityListResponse) { 30 | view.removeWait(); 31 | view.getCityListSuccess(cityListResponse); 32 | } 33 | 34 | @Override 35 | public void onError(NetworkError networkError) { 36 | view.removeWait(); 37 | view.onFailure(networkError.getAppErrorMessage()); 38 | } 39 | 40 | }); 41 | 42 | subscriptions.add(subscription); 43 | } 44 | public void onStop() { 45 | subscriptions.unsubscribe(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/plaps/androidcleancode/home/HomeView.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode.home; 2 | 3 | import com.plaps.androidcleancode.models.CityListResponse; 4 | 5 | /** 6 | * Created by ennur on 6/25/16. 7 | */ 8 | public interface HomeView { 9 | void showWait(); 10 | 11 | void removeWait(); 12 | 13 | void onFailure(String appErrorMessage); 14 | 15 | void getCityListSuccess(CityListResponse cityListResponse); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/plaps/androidcleancode/models/CityListData.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode.models; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | import javax.annotation.Generated; 7 | 8 | @Generated("org.jsonschema2pojo") 9 | public class CityListData { 10 | 11 | @SerializedName("id") 12 | @Expose 13 | private String id; 14 | @SerializedName("name") 15 | @Expose 16 | private String name; 17 | @SerializedName("description") 18 | @Expose 19 | private String description; 20 | @SerializedName("background") 21 | @Expose 22 | private String background; 23 | 24 | /** 25 | * 26 | * @return 27 | * The id 28 | */ 29 | public String getId() { 30 | return id; 31 | } 32 | 33 | /** 34 | * 35 | * @param id 36 | * The id 37 | */ 38 | public void setId(String id) { 39 | this.id = id; 40 | } 41 | 42 | /** 43 | * 44 | * @return 45 | * The name 46 | */ 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | /** 52 | * 53 | * @param name 54 | * The name 55 | */ 56 | public void setName(String name) { 57 | this.name = name; 58 | } 59 | 60 | /** 61 | * 62 | * @return 63 | * The description 64 | */ 65 | public String getDescription() { 66 | return description; 67 | } 68 | 69 | /** 70 | * 71 | * @param description 72 | * The description 73 | */ 74 | public void setDescription(String description) { 75 | this.description = description; 76 | } 77 | 78 | /** 79 | * 80 | * @return 81 | * The background 82 | */ 83 | public String getBackground() { 84 | return background; 85 | } 86 | 87 | /** 88 | * 89 | * @param background 90 | * The background 91 | */ 92 | public void setBackground(String background) { 93 | this.background = background; 94 | } 95 | 96 | } -------------------------------------------------------------------------------- /app/src/main/java/com/plaps/androidcleancode/models/CityListResponse.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode.models; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import javax.annotation.Generated; 10 | 11 | @Generated("org.jsonschema2pojo") 12 | public class CityListResponse { 13 | 14 | @SerializedName("data") 15 | @Expose 16 | private List data = new ArrayList(); 17 | @SerializedName("message") 18 | @Expose 19 | private String message; 20 | @SerializedName("status") 21 | @Expose 22 | private int status; 23 | 24 | /** 25 | * 26 | * @return 27 | * The data 28 | */ 29 | public List getData() { 30 | return data; 31 | } 32 | 33 | /** 34 | * 35 | * @param data 36 | * The data 37 | */ 38 | public void setData(List data) { 39 | this.data = data; 40 | } 41 | 42 | /** 43 | * 44 | * @return 45 | * The message 46 | */ 47 | public String getMessage() { 48 | return message; 49 | } 50 | 51 | /** 52 | * 53 | * @param message 54 | * The message 55 | */ 56 | public void setMessage(String message) { 57 | this.message = message; 58 | } 59 | 60 | /** 61 | * 62 | * @return 63 | * The status 64 | */ 65 | public int getStatus() { 66 | return status; 67 | } 68 | 69 | /** 70 | * 71 | * @param status 72 | * The status 73 | */ 74 | public void setStatus(int status) { 75 | this.status = status; 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /app/src/main/java/com/plaps/androidcleancode/networking/NetworkError.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode.networking; 2 | 3 | import android.text.TextUtils; 4 | 5 | import com.google.gson.Gson; 6 | 7 | import java.io.IOException; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | import retrofit2.adapter.rxjava.HttpException; 12 | 13 | import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED; 14 | 15 | public class NetworkError extends Throwable { 16 | public static final String DEFAULT_ERROR_MESSAGE = "Something went wrong! Please try again."; 17 | public static final String NETWORK_ERROR_MESSAGE = "No Internet Connection!"; 18 | private static final String ERROR_MESSAGE_HEADER = "Error-Message"; 19 | private final Throwable error; 20 | 21 | public NetworkError(Throwable e) { 22 | super(e); 23 | this.error = e; 24 | } 25 | 26 | public String getMessage() { 27 | return error.getMessage(); 28 | } 29 | 30 | public boolean isAuthFailure() { 31 | return error instanceof HttpException && 32 | ((HttpException) error).code() == HTTP_UNAUTHORIZED; 33 | } 34 | 35 | public boolean isResponseNull() { 36 | return error instanceof HttpException && ((HttpException) error).response() == null; 37 | } 38 | 39 | public String getAppErrorMessage() { 40 | if (this.error instanceof IOException) return NETWORK_ERROR_MESSAGE; 41 | if (!(this.error instanceof HttpException)) return DEFAULT_ERROR_MESSAGE; 42 | retrofit2.Response response = ((HttpException) this.error).response(); 43 | if (response != null) { 44 | String status = getJsonStringFromResponse(response); 45 | if (!TextUtils.isEmpty(status)) return status; 46 | 47 | Map> headers = response.headers().toMultimap(); 48 | if (headers.containsKey(ERROR_MESSAGE_HEADER)) 49 | return headers.get(ERROR_MESSAGE_HEADER).get(0); 50 | } 51 | 52 | return DEFAULT_ERROR_MESSAGE; 53 | } 54 | 55 | protected String getJsonStringFromResponse(final retrofit2.Response response) { 56 | try { 57 | String jsonString = response.errorBody().string(); 58 | Response errorResponse = new Gson().fromJson(jsonString, Response.class); 59 | return errorResponse.status; 60 | } catch (Exception e) { 61 | return null; 62 | } 63 | } 64 | 65 | public Throwable getError() { 66 | return error; 67 | } 68 | 69 | @Override 70 | public boolean equals(Object o) { 71 | if (this == o) return true; 72 | if (o == null || getClass() != o.getClass()) return false; 73 | 74 | NetworkError that = (NetworkError) o; 75 | 76 | return error != null ? error.equals(that.error) : that.error == null; 77 | 78 | } 79 | 80 | @Override 81 | public int hashCode() { 82 | return error != null ? error.hashCode() : 0; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/plaps/androidcleancode/networking/NetworkModule.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode.networking; 2 | 3 | import com.plaps.androidcleancode.BuildConfig; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | 8 | import javax.inject.Singleton; 9 | 10 | import dagger.Module; 11 | import dagger.Provides; 12 | import okhttp3.Cache; 13 | import okhttp3.Interceptor; 14 | import okhttp3.OkHttpClient; 15 | import okhttp3.Request; 16 | import retrofit2.Retrofit; 17 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; 18 | import retrofit2.converter.gson.GsonConverterFactory; 19 | import retrofit2.converter.scalars.ScalarsConverterFactory; 20 | 21 | /** 22 | * Created by ennur on 6/28/16. 23 | */ 24 | @Module 25 | public class NetworkModule { 26 | File cacheFile; 27 | 28 | public NetworkModule(File cacheFile) { 29 | this.cacheFile = cacheFile; 30 | } 31 | 32 | @Provides 33 | @Singleton 34 | Retrofit provideCall() { 35 | Cache cache = null; 36 | try { 37 | cache = new Cache(cacheFile, 10 * 1024 * 1024); 38 | } catch (Exception e) { 39 | e.printStackTrace(); 40 | } 41 | 42 | OkHttpClient okHttpClient = new OkHttpClient.Builder() 43 | .addInterceptor(new Interceptor() { 44 | @Override 45 | public okhttp3.Response intercept(Chain chain) throws IOException { 46 | Request original = chain.request(); 47 | 48 | // Customize the request 49 | Request request = original.newBuilder() 50 | .header("Content-Type", "application/json") 51 | .removeHeader("Pragma") 52 | .header("Cache-Control", String.format("max-age=%d", BuildConfig.CACHETIME)) 53 | .build(); 54 | 55 | okhttp3.Response response = chain.proceed(request); 56 | response.cacheResponse(); 57 | // Customize or return the response 58 | return response; 59 | } 60 | }) 61 | .cache(cache) 62 | 63 | .build(); 64 | 65 | 66 | return new Retrofit.Builder() 67 | .baseUrl(BuildConfig.BASEURL) 68 | .client(okHttpClient) 69 | .addConverterFactory(GsonConverterFactory.create()) 70 | .addConverterFactory(ScalarsConverterFactory.create()) 71 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 72 | 73 | .build(); 74 | } 75 | 76 | @Provides 77 | @Singleton 78 | @SuppressWarnings("unused") 79 | public NetworkService providesNetworkService( 80 | Retrofit retrofit) { 81 | return retrofit.create(NetworkService.class); 82 | } 83 | @Provides 84 | @Singleton 85 | @SuppressWarnings("unused") 86 | public Service providesService( 87 | NetworkService networkService) { 88 | return new Service(networkService); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /app/src/main/java/com/plaps/androidcleancode/networking/NetworkService.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode.networking; 2 | 3 | 4 | import com.plaps.androidcleancode.models.CityListResponse; 5 | 6 | import retrofit2.http.GET; 7 | import rx.Observable; 8 | 9 | /** 10 | * Created by ennur on 6/25/16. 11 | */ 12 | public interface NetworkService { 13 | 14 | @GET("v1/city") 15 | Observable getCityList(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/plaps/androidcleancode/networking/Response.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode.networking; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | public class Response { 6 | @SerializedName("status") 7 | public String status; 8 | 9 | public void setStatus(String status) { 10 | this.status = status; 11 | } 12 | 13 | public String getStatus() { 14 | return status; 15 | } 16 | 17 | @SuppressWarnings({"unused", "used by Retrofit"}) 18 | public Response() { 19 | } 20 | 21 | public Response(String status) { 22 | this.status = status; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/plaps/androidcleancode/networking/Service.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode.networking; 2 | 3 | 4 | import com.plaps.androidcleancode.models.CityListResponse; 5 | 6 | import rx.Observable; 7 | import rx.Subscriber; 8 | import rx.Subscription; 9 | import rx.android.schedulers.AndroidSchedulers; 10 | import rx.functions.Func1; 11 | import rx.schedulers.Schedulers; 12 | 13 | /** 14 | * Created by ennur on 6/25/16. 15 | */ 16 | public class Service { 17 | private final NetworkService networkService; 18 | 19 | public Service(NetworkService networkService) { 20 | this.networkService = networkService; 21 | } 22 | 23 | public Subscription getCityList(final GetCityListCallback callback) { 24 | 25 | return networkService.getCityList() 26 | .subscribeOn(Schedulers.io()) 27 | .observeOn(AndroidSchedulers.mainThread()) 28 | .onErrorResumeNext(new Func1>() { 29 | @Override 30 | public Observable call(Throwable throwable) { 31 | return Observable.error(throwable); 32 | } 33 | }) 34 | .subscribe(new Subscriber() { 35 | @Override 36 | public void onCompleted() { 37 | 38 | } 39 | 40 | @Override 41 | public void onError(Throwable e) { 42 | callback.onError(new NetworkError(e)); 43 | 44 | } 45 | 46 | @Override 47 | public void onNext(CityListResponse cityListResponse) { 48 | callback.onSuccess(cityListResponse); 49 | 50 | } 51 | }); 52 | } 53 | 54 | public interface GetCityListCallback{ 55 | void onSuccess(CityListResponse cityListResponse); 56 | 57 | void onError(NetworkError networkError); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 20 | 21 | 22 | 23 | 30 | 31 | 41 | 42 | 43 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrohmen/Clean-Android-Code/a84c9de220a1d0ce183db12573b7075053514b11/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrohmen/Clean-Android-Code/a84c9de220a1d0ce183db12573b7075053514b11/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrohmen/Clean-Android-Code/a84c9de220a1d0ce183db12573b7075053514b11/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrohmen/Clean-Android-Code/a84c9de220a1d0ce183db12573b7075053514b11/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrohmen/Clean-Android-Code/a84c9de220a1d0ce183db12573b7075053514b11/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Clean Android Code 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/plaps/androidcleancode/HomePresenterTest.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode; 2 | 3 | import com.plaps.androidcleancode.home.HomePresenter; 4 | import com.plaps.androidcleancode.home.HomeView; 5 | import com.plaps.androidcleancode.models.CityListResponse; 6 | import com.plaps.androidcleancode.networking.NetworkService; 7 | import com.plaps.androidcleancode.networking.Service; 8 | 9 | import org.junit.After; 10 | import org.junit.Before; 11 | import org.junit.Rule; 12 | import org.junit.Test; 13 | import org.junit.runner.RunWith; 14 | import org.mockito.InOrder; 15 | import org.mockito.Mock; 16 | import org.mockito.Mockito; 17 | import org.mockito.MockitoAnnotations; 18 | import org.mockito.junit.MockitoJUnitRunner; 19 | 20 | import rx.Observable; 21 | 22 | import static org.mockito.Mockito.when; 23 | 24 | @RunWith(MockitoJUnitRunner.class) 25 | public class HomePresenterTest { 26 | 27 | @Rule 28 | public final RxSchedulersOverrideRule mOverrideSchedulersRule = new RxSchedulersOverrideRule(); 29 | 30 | @Mock 31 | private NetworkService networkService; 32 | 33 | @Mock 34 | private HomeView homeView; 35 | 36 | @Mock 37 | private CityListResponse cityListResponse; 38 | 39 | private Service service; 40 | private HomePresenter homePresenter; 41 | 42 | @Before 43 | public void setUp() { 44 | MockitoAnnotations.initMocks(this); 45 | service = new Service(networkService); 46 | homePresenter = new HomePresenter(service, homeView); 47 | } 48 | 49 | @After 50 | public void teardown() { 51 | homePresenter.onStop(); 52 | } 53 | 54 | @Test 55 | public void loadCitiesFromAPIAndLoadIntoView() { 56 | 57 | Observable responseObservable = Observable.just(cityListResponse); 58 | when(networkService.getCityList()).thenReturn(responseObservable); 59 | 60 | homePresenter.getCityList(); 61 | 62 | InOrder inOrder = Mockito.inOrder(homeView); 63 | inOrder.verify(homeView).showWait(); 64 | inOrder.verify(homeView).removeWait(); 65 | inOrder.verify(homeView).getCityListSuccess(cityListResponse); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/test/java/com/plaps/androidcleancode/RxSchedulersOverrideRule.java: -------------------------------------------------------------------------------- 1 | package com.plaps.androidcleancode; 2 | 3 | 4 | import org.junit.rules.TestRule; 5 | import org.junit.runner.Description; 6 | import org.junit.runners.model.Statement; 7 | 8 | import java.lang.reflect.InvocationTargetException; 9 | import java.lang.reflect.Method; 10 | 11 | import rx.Scheduler; 12 | import rx.android.plugins.RxAndroidPlugins; 13 | import rx.android.plugins.RxAndroidSchedulersHook; 14 | import rx.plugins.RxJavaPlugins; 15 | import rx.plugins.RxJavaSchedulersHook; 16 | import rx.schedulers.Schedulers; 17 | 18 | /** 19 | * This rule registers SchedulerHooks for RxJava and RxAndroid to ensure that subscriptions 20 | * always subscribeOn and observeOn Schedulers.immediate(). 21 | * Warning, this rule will reset RxAndroidPlugins and RxJavaPlugins before and after each test so 22 | * if the application code uses RxJava plugins this may affect the behaviour of the testing method. 23 | */ 24 | public class RxSchedulersOverrideRule implements TestRule { 25 | 26 | private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() { 27 | @Override 28 | public Scheduler getIOScheduler() { 29 | return Schedulers.immediate(); 30 | } 31 | 32 | @Override 33 | public Scheduler getNewThreadScheduler() { 34 | return Schedulers.immediate(); 35 | } 36 | }; 37 | 38 | private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() { 39 | @Override 40 | public Scheduler getMainThreadScheduler() { 41 | return Schedulers.immediate(); 42 | } 43 | }; 44 | 45 | // Hack to get around RxJavaPlugins.reset() not being public 46 | // See https://github.com/ReactiveX/RxJava/issues/2297 47 | // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack. 48 | private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins) 49 | throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { 50 | Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset"); 51 | method.setAccessible(true); 52 | method.invoke(rxJavaPlugins); 53 | } 54 | 55 | @Override 56 | public Statement apply(final Statement base, Description description) { 57 | return new Statement() { 58 | @Override 59 | public void evaluate() throws Throwable { 60 | RxAndroidPlugins.getInstance().reset(); 61 | RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook); 62 | callResetViaReflectionIn(RxJavaPlugins.getInstance()); 63 | RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook); 64 | 65 | base.evaluate(); 66 | 67 | RxAndroidPlugins.getInstance().reset(); 68 | callResetViaReflectionIn(RxJavaPlugins.getInstance()); 69 | } 70 | }; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.0.1' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | google() 19 | jcenter() 20 | } 21 | } 22 | 23 | task clean(type: Delete) { 24 | delete rootProject.buildDir 25 | } 26 | -------------------------------------------------------------------------------- /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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrohmen/Clean-Android-Code/a84c9de220a1d0ce183db12573b7075053514b11/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Nov 14 13:57:51 WIB 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-4.1-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 | --------------------------------------------------------------------------------