├── README.md
├── javacode
├── .gitignore
├── .idea
│ ├── encodings.xml
│ ├── gradle.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── runConfigurations.xml
├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── androidcodehub
│ │ │ └── androidpagingsample
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── androidcodehub
│ │ │ │ └── androidpagingsample
│ │ │ │ ├── AppsExecutor.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── api
│ │ │ │ ├── ProductResponse.java
│ │ │ │ ├── Service.java
│ │ │ │ └── WalmartApi.java
│ │ │ │ ├── model
│ │ │ │ ├── DataLoadState.java
│ │ │ │ └── Product.java
│ │ │ │ └── ui
│ │ │ │ ├── ProductAdapter.java
│ │ │ │ ├── ProductDataFactory.java
│ │ │ │ ├── ProductDataSource.java
│ │ │ │ ├── ProductRepository.java
│ │ │ │ ├── ProductRepositoryImpl.java
│ │ │ │ └── ProductViewModel.java
│ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ └── ic_launcher_background.xml
│ │ │ ├── layout
│ │ │ ├── activity_main.xml
│ │ │ ├── product_content.xml
│ │ │ └── productlist.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.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
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── androidcodehub
│ │ └── androidpagingsample
│ │ └── ExampleUnitTest.java
├── build.gradle
├── device-2018-01-31-231940.mp4
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
└── versions.gradle
/README.md:
--------------------------------------------------------------------------------
1 | # android-paging-sample
2 | Android Architecture Components Paging Library Sample
3 |
4 | more info at http://androidcodehub.com/paginglibrary/
5 |
--------------------------------------------------------------------------------
/javacode/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/javacode/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/javacode/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/javacode/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | General
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/javacode/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/javacode/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/javacode/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/javacode/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion "26.0.3"
6 | defaultConfig {
7 | applicationId "com.androidcodehub.androidpagingsample"
8 | minSdkVersion 15
9 | targetSdkVersion 27
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | debug {
16 | testCoverageEnabled !project.hasProperty('android.injected.invoked.from.ide')
17 | }
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | dataBinding {
24 | enabled = true
25 | }
26 | compileOptions {
27 | sourceCompatibility JavaVersion.VERSION_1_8
28 | targetCompatibility JavaVersion.VERSION_1_8
29 | }
30 | sourceSets {
31 | androidTest.java.srcDirs += "src/test-common/java"
32 | test.java.srcDirs += "src/test-common/java"
33 | }
34 | lintOptions {
35 | lintConfig rootProject.file('lint.xml')
36 | }
37 | }
38 |
39 |
40 | dependencies {
41 | implementation deps.support.app_compat
42 | implementation deps.support.recyclerview
43 | implementation deps.support.cardview
44 | implementation deps.support.design
45 | implementation deps.room.runtime
46 | implementation deps.lifecycle.runtime
47 | implementation deps.lifecycle.extensions
48 | implementation deps.lifecycle.java8
49 | implementation deps.retrofit.runtime
50 | implementation deps.retrofit.gson
51 | implementation deps.glide
52 | implementation "android.arch.paging:runtime:1.0.0-alpha4-1"
53 | /*
54 | implementation deps.dagger.runtime
55 | implementation deps.dagger.android
56 | implementation deps.dagger.android_support*/
57 | implementation deps.constraint_layout
58 |
59 | implementation deps.timber
60 |
61 | annotationProcessor deps.dagger.android_support_compiler
62 | annotationProcessor deps.dagger.compiler
63 | annotationProcessor deps.room.compiler
64 | annotationProcessor deps.lifecycle.compiler
65 |
66 | }
67 |
68 |
69 |
--------------------------------------------------------------------------------
/javacode/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/javacode/app/src/androidTest/java/com/androidcodehub/androidpagingsample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.androidcodehub.androidpagingsample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.androidcodehub.androidpagingsample", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/javacode/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/javacode/app/src/main/java/com/androidcodehub/androidpagingsample/AppsExecutor.java:
--------------------------------------------------------------------------------
1 | package com.androidcodehub.androidpagingsample;
2 |
3 |
4 | import android.os.Handler;
5 | import android.os.Looper;
6 | import android.support.annotation.NonNull;
7 |
8 | import java.util.concurrent.Executor;
9 | import java.util.concurrent.Executors;
10 |
11 | public class AppsExecutor {
12 |
13 | private final static Executor networkIO = Executors.newFixedThreadPool(3);
14 |
15 | private final static Executor mainThread = new MainThreadExecutor();
16 |
17 | private AppsExecutor() {
18 |
19 | }
20 |
21 | public static Executor networkIO() {
22 | return networkIO;
23 | }
24 |
25 | public static Executor mainThread() {
26 | return mainThread;
27 | }
28 |
29 | private static class MainThreadExecutor implements Executor {
30 | private Handler mainThreadHandler = new Handler(Looper.getMainLooper());
31 | @Override
32 | public void execute(@NonNull Runnable command) {
33 | mainThreadHandler.post(command);
34 | }
35 | }
36 |
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/javacode/app/src/main/java/com/androidcodehub/androidpagingsample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.androidcodehub.androidpagingsample;
2 |
3 | import android.arch.lifecycle.ViewModelProviders;
4 | import android.support.annotation.NonNull;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.os.Bundle;
7 | import android.support.v7.widget.DividerItemDecoration;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.support.v7.widget.Toolbar;
10 | import android.util.Log;
11 | import android.view.View;
12 | import android.widget.ProgressBar;
13 | import android.widget.Toast;
14 |
15 | import com.androidcodehub.androidpagingsample.ui.ProductAdapter;
16 | import com.androidcodehub.androidpagingsample.ui.ProductViewModel;
17 |
18 |
19 | public class MainActivity extends AppCompatActivity {
20 |
21 | private static final String TAG = "ProductListActivity";
22 | private boolean mTwoPane;
23 | private ProductViewModel mProductsViewModel;
24 | private ProductAdapter mAdapter;
25 |
26 | private ProgressBar mLoadProgressBar;
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 |
31 | setContentView(R.layout.activity_main);
32 |
33 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
34 | setSupportActionBar(toolbar);
35 | toolbar.setTitle(getTitle());
36 |
37 | mLoadProgressBar = findViewById(R.id.progress_bar);
38 |
39 | View recyclerView = findViewById(R.id.product_list);
40 | assert recyclerView != null;
41 |
42 |
43 | setupRecyclerView((RecyclerView) recyclerView);
44 |
45 | mProductsViewModel = ViewModelProviders.of(this).get(ProductViewModel.class);
46 | mProductsViewModel.dataLoadStatus().observe(this, loadStatus -> {
47 | switch (loadStatus) {
48 | case LOADING:
49 | mLoadProgressBar.setVisibility(View.VISIBLE);
50 | break;
51 | case LOADED:
52 | mLoadProgressBar.setVisibility(View.GONE);
53 | break;
54 | case FAILED:
55 | mLoadProgressBar.setVisibility(View.GONE);
56 | Toast.makeText(this,"Failed to connect to Walmart Service",
57 | Toast.LENGTH_LONG);
58 | break;
59 | }
60 | });
61 | mProductsViewModel.getProducts().observe(this, pagedList -> {
62 | mAdapter.setList(pagedList);
63 |
64 | });
65 | }
66 |
67 | private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
68 | mAdapter = new ProductAdapter(this, mTwoPane);
69 | recyclerView.setAdapter(mAdapter);
70 | recyclerView.setHasFixedSize(true);
71 |
72 | recyclerView.addItemDecoration(new DividerItemDecoration(this,
73 | DividerItemDecoration.VERTICAL));
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/javacode/app/src/main/java/com/androidcodehub/androidpagingsample/api/ProductResponse.java:
--------------------------------------------------------------------------------
1 | package com.androidcodehub.androidpagingsample.api;
2 |
3 |
4 |
5 | import com.androidcodehub.androidpagingsample.model.Product;
6 |
7 | import java.util.List;
8 |
9 |
10 | public class ProductResponse {
11 | public List products;
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/javacode/app/src/main/java/com/androidcodehub/androidpagingsample/api/Service.java:
--------------------------------------------------------------------------------
1 | package com.androidcodehub.androidpagingsample.api;
2 |
3 | import retrofit2.Retrofit;
4 | import retrofit2.converter.gson.GsonConverterFactory;
5 |
6 |
7 |
8 | public class Service {
9 |
10 | private static final Service service = new Service();
11 | private static WalmartApi api;
12 |
13 | private static final String API_URL
14 | = "https://walmartlabs-test.appspot.com/_ah/api/walmart/v1/walmartproducts/"+
15 | "56330880-82c2-47eb-9d5d-03db3a49e3bf/";
16 |
17 | private Service() {
18 |
19 |
20 | api = new Retrofit.Builder()
21 | .baseUrl(API_URL)
22 | .addConverterFactory(GsonConverterFactory.create())
23 | //.client(client)
24 | .build()
25 | .create(WalmartApi.class);
26 | }
27 |
28 | public static WalmartApi get() {
29 | return service.api;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/javacode/app/src/main/java/com/androidcodehub/androidpagingsample/api/WalmartApi.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 com.androidcodehub.androidpagingsample.api;
18 |
19 | import retrofit2.Call;
20 | import retrofit2.http.GET;
21 | import retrofit2.http.Path;
22 |
23 | public interface WalmartApi {
24 |
25 | @GET("{page}/{size}")
26 | Call getProducts(@Path("page") int pageNumber, @Path("size") int pageSize);
27 | }
28 |
--------------------------------------------------------------------------------
/javacode/app/src/main/java/com/androidcodehub/androidpagingsample/model/DataLoadState.java:
--------------------------------------------------------------------------------
1 | package com.androidcodehub.androidpagingsample.model;
2 |
3 |
4 |
5 | public enum DataLoadState {
6 |
7 | LOADING,
8 | LOADED,
9 | FAILED
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/javacode/app/src/main/java/com/androidcodehub/androidpagingsample/model/Product.java:
--------------------------------------------------------------------------------
1 | package com.androidcodehub.androidpagingsample.model;
2 |
3 |
4 | import android.os.Parcel;
5 | import android.os.Parcelable;
6 |
7 |
8 | public class Product implements Parcelable {
9 | public String productId;
10 | public String productName;
11 | public String shortDescription;
12 | public String longDescription;
13 | public String price;
14 | public String productImage;
15 | public float reviewRating;
16 | public int reviewCount;
17 | public boolean inStock;
18 |
19 | public Product(Parcel in){
20 | this.productId = in.readString();
21 | this.productName = in.readString();
22 | this.shortDescription = in.readString();
23 | this.longDescription = in.readString();
24 | this.price = in.readString();
25 | this.productImage = in.readString();
26 | this.reviewRating = in.readFloat();
27 | this.reviewCount = in.readInt();
28 | this.inStock = in.readInt() == 1;
29 | }
30 |
31 | @Override
32 | public int describeContents() {
33 | return 0;
34 | }
35 |
36 | @Override
37 | public void writeToParcel(Parcel dest, int flags) {
38 | dest.writeString(productId);
39 | dest.writeString(productName);
40 | dest.writeString(shortDescription);
41 | dest.writeString(longDescription);
42 | dest.writeString(price);
43 | dest.writeString(productImage);
44 | dest.writeFloat(reviewRating);
45 | dest.writeInt(reviewCount);
46 | dest.writeInt(inStock ? 1 : 0);
47 |
48 | }
49 | @Override
50 | public String toString() {
51 |
52 | return "id="+productId
53 | +",\nimg="+productImage
54 | +",\ninstock="+inStock;
55 | }
56 |
57 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
58 |
59 | @Override
60 | public Product createFromParcel(Parcel source) {
61 | return new Product(source);
62 | }
63 |
64 | @Override
65 | public Product[] newArray(int size) {
66 | return new Product[size];
67 | }
68 | };
69 | }
70 |
71 |
--------------------------------------------------------------------------------
/javacode/app/src/main/java/com/androidcodehub/androidpagingsample/ui/ProductAdapter.java:
--------------------------------------------------------------------------------
1 | package com.androidcodehub.androidpagingsample.ui;
2 |
3 |
4 | import android.arch.paging.PagedListAdapter;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 | import android.support.annotation.NonNull;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.support.v7.recyclerview.extensions.DiffCallback;
12 | import android.support.v7.widget.RecyclerView;
13 | import android.view.LayoutInflater;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.widget.ImageView;
17 | import android.widget.RatingBar;
18 | import android.widget.TextView;
19 | import android.widget.Toast;
20 |
21 | import com.androidcodehub.androidpagingsample.R;
22 | import com.androidcodehub.androidpagingsample.model.Product;
23 | import com.bumptech.glide.Glide;
24 | import com.bumptech.glide.load.engine.DiskCacheStrategy;
25 |
26 | public class ProductAdapter extends PagedListAdapter {
27 |
28 | private Context mContext;
29 |
30 |
31 | public ProductAdapter(Context context, boolean twoPane) {
32 | super(DIFF_CALLBACK);
33 | mContext = context;
34 |
35 | }
36 |
37 | @Override
38 | public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
39 | View view = LayoutInflater.from(parent.getContext())
40 | .inflate(R.layout.product_content, parent, false);
41 | return new ProductViewHolder(view);
42 | }
43 |
44 | @Override
45 | public void onBindViewHolder(ProductViewHolder holder, int position) {
46 | Product product = getItem(position);
47 | if (product != null) {
48 | holder.bindTo(product);
49 | } else {
50 |
51 | holder.clear();
52 | }
53 | }
54 | public static final DiffCallback DIFF_CALLBACK = new DiffCallback() {
55 | @Override
56 | public boolean areItemsTheSame(@NonNull Product oldProduct, @NonNull Product newProduct) {
57 |
58 | return oldProduct.productId == newProduct.productId;
59 | }
60 | @Override
61 | public boolean areContentsTheSame(@NonNull Product oldProduct, @NonNull Product newProduct) {
62 |
63 | return oldProduct.equals(newProduct);
64 | }
65 | };
66 |
67 | public class ProductViewHolder extends RecyclerView.ViewHolder {
68 | private View itemView;
69 | private ImageView productImage;
70 | private TextView title;
71 | private TextView price;
72 |
73 |
74 | public ProductViewHolder(View itemView) {
75 | super(itemView);
76 | this.itemView = itemView;
77 | this.productImage = (ImageView) itemView.findViewById(R.id.product);
78 | this.title = (TextView) itemView.findViewById(R.id.title);
79 | this.price = (TextView) itemView.findViewById(R.id.price);
80 |
81 |
82 | }
83 |
84 | public void bindTo(Product product) {
85 |
86 | productImage.setImageURI(Uri.parse(product.productImage));
87 | title.setText(product.productName);
88 | price.setText(product.price);
89 |
90 |
91 | Glide.with(mContext).load(product.productImage)
92 | .thumbnail(0.5f)
93 | .crossFade()
94 | .diskCacheStrategy(DiskCacheStrategy.ALL)
95 | .into(productImage);
96 |
97 | itemView.setOnClickListener(new View.OnClickListener() {
98 | @Override
99 | public void onClick(View v) {
100 |
101 | Toast.makeText(mContext,product.productName,Toast.LENGTH_LONG).show();
102 |
103 | }
104 |
105 |
106 | });
107 | }
108 |
109 | public void clear() {
110 | //TODO
111 |
112 | productImage.setImageURI(null);
113 | title.setText(null);
114 | price.setText(null);
115 |
116 |
117 | }
118 | }
119 |
120 |
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/javacode/app/src/main/java/com/androidcodehub/androidpagingsample/ui/ProductDataFactory.java:
--------------------------------------------------------------------------------
1 | package com.androidcodehub.androidpagingsample.ui;
2 |
3 | import android.arch.lifecycle.MutableLiveData;
4 | import android.arch.paging.DataSource;
5 |
6 | import com.androidcodehub.androidpagingsample.api.Service;
7 | import com.androidcodehub.androidpagingsample.model.Product;
8 |
9 |
10 |
11 | public class ProductDataFactory implements DataSource.Factory {
12 |
13 | public MutableLiveData datasourceLiveData = new MutableLiveData<>();
14 |
15 | @Override
16 | public DataSource create() {
17 |
18 | ProductDataSource dataSource = new ProductDataSource(Service.get());
19 | datasourceLiveData.postValue(dataSource);
20 | return dataSource;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/javacode/app/src/main/java/com/androidcodehub/androidpagingsample/ui/ProductDataSource.java:
--------------------------------------------------------------------------------
1 | package com.androidcodehub.androidpagingsample.ui;
2 |
3 | import android.arch.lifecycle.MutableLiveData;
4 | import android.arch.paging.PageKeyedDataSource;
5 | import android.support.annotation.NonNull;
6 |
7 |
8 | import com.androidcodehub.androidpagingsample.api.ProductResponse;
9 | import com.androidcodehub.androidpagingsample.api.WalmartApi;
10 | import com.androidcodehub.androidpagingsample.model.DataLoadState;
11 | import com.androidcodehub.androidpagingsample.model.Product;
12 |
13 | import java.io.IOException;
14 |
15 | import retrofit2.Call;
16 | import retrofit2.Response;
17 |
18 |
19 | public class ProductDataSource extends PageKeyedDataSource {
20 |
21 | private WalmartApi walmartApi;
22 |
23 | public final MutableLiveData loadState;
24 |
25 | public ProductDataSource(WalmartApi walmartApi) {
26 |
27 | this.walmartApi = walmartApi;
28 | loadState = new MutableLiveData();
29 |
30 | }
31 |
32 | @Override
33 | public void loadInitial(@NonNull LoadInitialParams params, @NonNull LoadInitialCallback callback) {
34 |
35 | loadState.postValue(DataLoadState.LOADING);
36 |
37 | Call request = walmartApi.getProducts(1, params.requestedLoadSize);
38 |
39 | Response response = null;
40 | try{
41 | response = request.execute();
42 | if(response != null) {
43 | callback.onResult(response.body().products, 1, 2);
44 | }else {
45 | callback.onResult(null, null,2);
46 | }
47 | loadState.postValue(DataLoadState.LOADED);
48 | }catch (IOException ex) {
49 | loadState.postValue(DataLoadState.FAILED);
50 | }
51 |
52 | }
53 |
54 | @Override
55 | public void loadBefore(@NonNull LoadParams params, @NonNull LoadCallback callback) {
56 |
57 |
58 | loadState.postValue(DataLoadState.LOADING);
59 |
60 | Call request = walmartApi.getProducts(params.key, params.requestedLoadSize);
61 |
62 | Response response = null;
63 | try{
64 | response = request.execute();
65 | if(response != null) {
66 | Integer adjacentKey = (params.key > 1) ? params.key - 1 : null;
67 | callback.onResult(response.body().products, adjacentKey);
68 | }else {
69 | callback.onResult(null, params.key - 1);
70 | }
71 | loadState.postValue(DataLoadState.LOADED);
72 | }catch (IOException ex) {
73 | //networkState.postValue();
74 | }
75 | }
76 |
77 | @Override
78 | public void loadAfter(@NonNull LoadParams params, @NonNull LoadCallback callback) {
79 |
80 | loadState.postValue(DataLoadState.LOADING);
81 |
82 | Call request = walmartApi.getProducts(params.key , params.requestedLoadSize);
83 |
84 | Response response = null;
85 | try{
86 | response = request.execute();
87 | if(response != null) {
88 | callback.onResult(response.body().products, params.key + 1);
89 | }else {
90 | callback.onResult(null, params.key + 1 );
91 | }
92 | loadState.postValue(DataLoadState.LOADED);
93 | }catch (IOException ex) {
94 | //networkState.postValue();
95 | loadState.postValue(DataLoadState.FAILED);
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/javacode/app/src/main/java/com/androidcodehub/androidpagingsample/ui/ProductRepository.java:
--------------------------------------------------------------------------------
1 | package com.androidcodehub.androidpagingsample.ui;
2 |
3 | import android.arch.lifecycle.LiveData;
4 | import android.arch.paging.PagedList;
5 |
6 | import com.androidcodehub.androidpagingsample.model.DataLoadState;
7 | import com.androidcodehub.androidpagingsample.model.Product;
8 |
9 |
10 | public interface ProductRepository {
11 |
12 | public LiveData> getProducts();
13 | public LiveData getDataLoadStatus();
14 | }
15 |
--------------------------------------------------------------------------------
/javacode/app/src/main/java/com/androidcodehub/androidpagingsample/ui/ProductRepositoryImpl.java:
--------------------------------------------------------------------------------
1 | package com.androidcodehub.androidpagingsample.ui;
2 |
3 | import android.arch.lifecycle.LiveData;
4 | import android.arch.paging.LivePagedListBuilder;
5 | import android.arch.paging.PagedList;
6 | import android.arch.paging.PagedList.Config.Builder;
7 | import android.support.annotation.MainThread;
8 |
9 |
10 | import com.androidcodehub.androidpagingsample.AppsExecutor;
11 | import com.androidcodehub.androidpagingsample.model.DataLoadState;
12 | import com.androidcodehub.androidpagingsample.model.Product;
13 |
14 | import static android.arch.lifecycle.Transformations.switchMap;
15 |
16 |
17 | public class ProductRepositoryImpl implements ProductRepository{
18 |
19 | //private Executor networkExecutor;
20 | ProductDataFactory dataSourceFactory;
21 | private static final int PAGE_SIZE = 30;
22 | private LiveData> products;
23 |
24 | public ProductRepositoryImpl() {
25 | dataSourceFactory = new ProductDataFactory();
26 | //this.networkExecutor = networkExecutor;
27 | }
28 |
29 | @Override
30 | @MainThread
31 | public LiveData> getProducts() {
32 |
33 | PagedList.Config config = new Builder()
34 | .setInitialLoadSizeHint(PAGE_SIZE)
35 | .setPageSize(PAGE_SIZE)
36 | .build();
37 |
38 |
39 | products = new LivePagedListBuilder(dataSourceFactory, config)
40 | .setInitialLoadKey(1)
41 | .setBackgroundThreadExecutor(AppsExecutor.networkIO())
42 | .build();
43 |
44 | return products;
45 | }
46 |
47 | public LiveData getDataLoadStatus(){
48 | return switchMap(dataSourceFactory.datasourceLiveData,
49 | dataSource -> dataSource.loadState);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/javacode/app/src/main/java/com/androidcodehub/androidpagingsample/ui/ProductViewModel.java:
--------------------------------------------------------------------------------
1 | package com.androidcodehub.androidpagingsample.ui;
2 |
3 | import android.app.Application;
4 | import android.arch.lifecycle.AndroidViewModel;
5 | import android.arch.lifecycle.LiveData;
6 | import android.arch.paging.PagedList;
7 | import android.support.annotation.NonNull;
8 |
9 | import com.androidcodehub.androidpagingsample.model.DataLoadState;
10 | import com.androidcodehub.androidpagingsample.model.Product;
11 |
12 |
13 | public class ProductViewModel extends AndroidViewModel {
14 |
15 | private ProductRepository repository;
16 |
17 | public ProductViewModel(@NonNull Application application) {
18 | super(application);
19 | repository = new ProductRepositoryImpl();
20 | }
21 |
22 | public LiveData> getProducts() {
23 | return repository.getProducts();
24 | }
25 |
26 | public LiveData dataLoadStatus() {
27 | return repository.getDataLoadStatus();
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/javacode/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/javacode/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/javacode/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
22 |
23 |
24 |
29 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/javacode/app/src/main/res/layout/product_content.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
21 |
22 |
33 |
34 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/javacode/app/src/main/res/layout/productlist.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/javacode/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/javacode/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/javacode/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidcodehub/android-paging-sample/633e76fe4400dbae63535a682613f365e7cafe39/javacode/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/javacode/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidcodehub/android-paging-sample/633e76fe4400dbae63535a682613f365e7cafe39/javacode/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/javacode/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidcodehub/android-paging-sample/633e76fe4400dbae63535a682613f365e7cafe39/javacode/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/javacode/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidcodehub/android-paging-sample/633e76fe4400dbae63535a682613f365e7cafe39/javacode/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/javacode/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidcodehub/android-paging-sample/633e76fe4400dbae63535a682613f365e7cafe39/javacode/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/javacode/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidcodehub/android-paging-sample/633e76fe4400dbae63535a682613f365e7cafe39/javacode/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/javacode/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidcodehub/android-paging-sample/633e76fe4400dbae63535a682613f365e7cafe39/javacode/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/javacode/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidcodehub/android-paging-sample/633e76fe4400dbae63535a682613f365e7cafe39/javacode/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/javacode/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidcodehub/android-paging-sample/633e76fe4400dbae63535a682613f365e7cafe39/javacode/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/javacode/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidcodehub/android-paging-sample/633e76fe4400dbae63535a682613f365e7cafe39/javacode/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/javacode/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/javacode/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 200dp
5 | 200dp
6 | 16dp
7 |
8 |
--------------------------------------------------------------------------------
/javacode/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidPagingSample
3 |
4 |
--------------------------------------------------------------------------------
/javacode/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/javacode/app/src/test/java/com/androidcodehub/androidpagingsample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.androidcodehub.androidpagingsample;
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 | }
--------------------------------------------------------------------------------
/javacode/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | apply from: '../versions.gradle'
6 | addRepos(repositories)
7 | dependencies {
8 | classpath deps.android_gradle_plugin
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | google()
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/javacode/device-2018-01-31-231940.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidcodehub/android-paging-sample/633e76fe4400dbae63535a682613f365e7cafe39/javacode/device-2018-01-31-231940.mp4
--------------------------------------------------------------------------------
/javacode/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/javacode/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidcodehub/android-paging-sample/633e76fe4400dbae63535a682613f365e7cafe39/javacode/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/javacode/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jan 29 22:57:21 IST 2018
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 |
--------------------------------------------------------------------------------
/javacode/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 |
--------------------------------------------------------------------------------
/javacode/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 |
--------------------------------------------------------------------------------
/javacode/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/versions.gradle:
--------------------------------------------------------------------------------
1 | /**
2 | * Shared file between builds so that they can all use the same dependencies and
3 | * maven repositories.
4 | **/
5 | ext.deps = [:]
6 | def versions = [:]
7 | versions.arch = hasProperty("ARCH_VERSION") ? getProperty("ARCH_VERSION") : "1.0.0"
8 | versions.support = "26.1.0"
9 | versions.dagger = "2.11"
10 | versions.junit = "4.12"
11 | versions.espresso = "3.0.1"
12 | versions.retrofit = "2.3.0"
13 | versions.okhttp_logging_interceptor = "3.9.0"
14 | versions.mockwebserver = "3.8.1"
15 | versions.apache_commons = "2.5"
16 | versions.mockito = "2.7.19"
17 | versions.mockito_all = "1.10.19"
18 | versions.dexmaker = "2.2.0"
19 | versions.constraint_layout = "1.0.2"
20 | versions.glide = "3.8.0"
21 | versions.timber = "4.5.1"
22 | versions.android_gradle_plugin = "3.0.0"
23 | versions.rxjava2 = "2.1.3"
24 | versions.rx_android = "2.0.1"
25 | versions.atsl_runner = "1.0.1"
26 | versions.atsl_rules = "1.0.1"
27 | versions.hamcrest = "1.3"
28 | versions.kotlin = "1.1.4-2"
29 | versions.paging = "1.0.0-alpha4-1"
30 | def deps = [:]
31 |
32 | def support = [:]
33 | support.annotations = "com.android.support:support-annotations:$versions.support"
34 | support.app_compat = "com.android.support:appcompat-v7:$versions.support"
35 | support.recyclerview = "com.android.support:recyclerview-v7:$versions.support"
36 | support.cardview = "com.android.support:cardview-v7:$versions.support"
37 | support.design = "com.android.support:design:$versions.support"
38 | support.v4 = "com.android.support:support-v4:$versions.support"
39 | support.core_utils = "com.android.support:support-core-utils:$versions.support"
40 | deps.support = support
41 |
42 | def room = [:]
43 | room.runtime = "android.arch.persistence.room:runtime:$versions.arch"
44 | room.compiler = "android.arch.persistence.room:compiler:$versions.arch"
45 | room.rxjava2 = "android.arch.persistence.room:rxjava2:$versions.arch"
46 | room.testing = "android.arch.persistence.room:testing:$versions.arch"
47 | deps.room = room
48 |
49 | def lifecycle = [:]
50 | lifecycle.runtime = "android.arch.lifecycle:runtime:$versions.arch"
51 | lifecycle.extensions = "android.arch.lifecycle:extensions:$versions.arch"
52 | lifecycle.java8 = "android.arch.lifecycle:common-java8:$versions.arch"
53 | lifecycle.compiler = "android.arch.lifecycle:compiler:$versions.arch"
54 | deps.lifecycle = lifecycle
55 |
56 | def arch_core = [:]
57 | arch_core.testing = "android.arch.core:core-testing:$versions.arch"
58 | deps.arch_core = arch_core
59 |
60 | def retrofit = [:]
61 | retrofit.runtime = "com.squareup.retrofit2:retrofit:$versions.retrofit"
62 | retrofit.gson = "com.squareup.retrofit2:converter-gson:$versions.retrofit"
63 | retrofit.mock = "com.squareup.retrofit2:retrofit-mock:$versions.retrofit"
64 | deps.retrofit = retrofit
65 | deps.okhttp_logging_interceptor = "com.squareup.okhttp3:logging-interceptor:${versions.okhttp_logging_interceptor}"
66 |
67 | def dagger = [:]
68 | dagger.runtime = "com.google.dagger:dagger:$versions.dagger"
69 | dagger.android = "com.google.dagger:dagger-android:$versions.dagger"
70 | dagger.android_support = "com.google.dagger:dagger-android-support:$versions.dagger"
71 | dagger.compiler = "com.google.dagger:dagger-compiler:$versions.dagger"
72 | dagger.android_support_compiler = "com.google.dagger:dagger-android-processor:$versions.dagger"
73 |
74 | deps.dagger = dagger
75 |
76 | def espresso = [:]
77 | espresso.core = "com.android.support.test.espresso:espresso-core:$versions.espresso"
78 | espresso.contrib = "com.android.support.test.espresso:espresso-contrib:$versions.espresso"
79 | espresso.intents = "com.android.support.test.espresso:espresso-intents:$versions.espresso"
80 | deps.espresso = espresso
81 |
82 | def atsl = [:]
83 | atsl.runner = "com.android.support.test:runner:$versions.atsl_runner"
84 | atsl.rules = "com.android.support.test:rules:$versions.atsl_runner"
85 | deps.atsl = atsl
86 |
87 | def mockito = [:]
88 | mockito.core = "org.mockito:mockito-core:$versions.mockito"
89 | mockito.all = "org.mockito:mockito-all:$versions.mockito_all"
90 | deps.mockito = mockito
91 |
92 | def kotlin = [:]
93 | kotlin.stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jre7:$versions.kotlin"
94 | kotlin.test = "org.jetbrains.kotlin:kotlin-test-junit:$versions.kotlin"
95 | kotlin.plugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
96 |
97 | deps.kotlin = kotlin
98 | deps.paging = "android.arch.paging:runtime:$versions.paging"
99 | deps.glide = "com.github.bumptech.glide:glide:$versions.glide"
100 | deps.dexmaker = "com.linkedin.dexmaker:dexmaker-mockito:$versions.dexmaker"
101 | deps.constraint_layout = "com.android.support.constraint:constraint-layout:$versions.constraint_layout"
102 | deps.timber = "com.jakewharton.timber:timber:$versions.timber"
103 | deps.junit = "junit:junit:$versions.junit"
104 | deps.mock_web_server = "com.squareup.okhttp3:mockwebserver:$versions.mockwebserver"
105 | deps.rxjava2 = "io.reactivex.rxjava2:rxjava:$versions.rxjava2"
106 | deps.rx_android = "io.reactivex.rxjava2:rxandroid:$versions.rx_android"
107 | deps.hamcrest = "org.hamcrest:hamcrest-all:$versions.hamcrest"
108 | deps.android_gradle_plugin = "com.android.tools.build:gradle:$versions.android_gradle_plugin"
109 | ext.deps = deps
110 |
111 | def build_versions = [:]
112 | build_versions.min_sdk = 14
113 | build_versions.target_sdk = 26
114 | build_versions.build_tools = "26.0.2"
115 | ext.build_versions = build_versions
116 |
117 |
118 | def addRepos(RepositoryHandler handler) {
119 | handler.google()
120 | handler.jcenter()
121 | handler.maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
122 | }
123 | ext.addRepos = this.&addRepos
124 |
--------------------------------------------------------------------------------