diff --git a/.gitignore b/.gitignore index c6cbe56..72f62ab 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ .DS_Store /build /captures +.idea \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index be001fc..27ea142 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,15 +1,15 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 24 - buildToolsVersion '24.0.2' + compileSdkVersion 27 + buildToolsVersion '27.0.3' defaultConfig { applicationId "com.aspsine.irecyclerview.demo" minSdkVersion 15 - targetSdkVersion 24 - versionCode 5 - versionName "1.5" + targetSdkVersion 27 + versionCode 6 + versionName "1.6" } buildTypes { release { @@ -20,14 +20,19 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - testCompile 'junit:junit:4.12' - compile project(':library') - // compile 'com.github.Aspsine:IRecyclerView:0.0.3' - compile 'com.android.support:appcompat-v7:24.2.0' - compile 'com.google.code.gson:gson:2.6.2' - compile 'com.squareup.okhttp3:okhttp:3.2.0' - compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1' - compile 'com.github.bumptech.glide:glide:3.7.0' - compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar' + api fileTree(include: ['*.jar'], dir: 'libs') + testImplementation 'junit:junit:4.12' + implementation project(':library') + // implementation 'com.github.Aspsine:IRecyclerView:0.0.3' + implementation ('com.android.support:appcompat-v7:27.1.1') + implementation ('com.android.support:recyclerview-v7:27.1.1') + implementation 'com.google.code.gson:gson:2.8.0' + implementation 'com.squareup.okhttp3:okhttp:3.9.0' + implementation ('com.github.JakeWharton:ViewPagerIndicator:2.4.1'){ + transitive = true + exclude group: 'com.android.support', module: 'support-v4' + exclude group: 'com.android.support', module: 'support-v7' + } + implementation 'com.github.bumptech.glide:glide:3.8.0' + implementation 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar' } diff --git a/app/src/main/java/com/aspsine/irecyclerview/demo/network/NetworkAPI.java b/app/src/main/java/com/aspsine/irecyclerview/demo/network/NetworkAPI.java index 598eb23..4d95727 100644 --- a/app/src/main/java/com/aspsine/irecyclerview/demo/network/NetworkAPI.java +++ b/app/src/main/java/com/aspsine/irecyclerview/demo/network/NetworkAPI.java @@ -18,14 +18,14 @@ public class NetworkAPI { public static void requestImages(int page, final Callback> callback) { String url = Constants.ImagesAPI(page); final Request request = new Request.Builder().get().url(url).build(); - OkHttp.getOkHttpClient().newCall(request).enqueue(new GsonCallbackWrapper>(callback, new TypeToken>() { + OkHttp.getOkHttpClient().newCall(request).enqueue(new GsonCallbackWrapper<>(callback, new TypeToken>() { })); } public static void requestBanners(final Callback> callback) { String url = Constants.BannerAPI; final Request request = new Request.Builder().get().url(url).build(); - OkHttp.getOkHttpClient().newCall(request).enqueue(new GsonCallbackWrapper>(callback, new TypeToken>() { + OkHttp.getOkHttpClient().newCall(request).enqueue(new GsonCallbackWrapper<>(callback, new TypeToken>() { })); } diff --git a/app/src/main/java/com/aspsine/irecyclerview/demo/ui/activity/MainActivity.java b/app/src/main/java/com/aspsine/irecyclerview/demo/ui/activity/MainActivity.java index 9892d68..66050f9 100644 --- a/app/src/main/java/com/aspsine/irecyclerview/demo/ui/activity/MainActivity.java +++ b/app/src/main/java/com/aspsine/irecyclerview/demo/ui/activity/MainActivity.java @@ -42,7 +42,7 @@ public class MainActivity extends AppCompatActivity implements OnItemClickListen protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - iRecyclerView = (IRecyclerView) findViewById(R.id.iRecyclerView); + iRecyclerView = findViewById(R.id.iRecyclerView); iRecyclerView.setLayoutManager(new LinearLayoutManager(this)); bannerView = (BannerView) LayoutInflater.from(this).inflate(R.layout.layout_banner_view, iRecyclerView.getHeaderContainer(), false); @@ -162,21 +162,9 @@ public void onSuccess(final List images) { if (ListUtils.isEmpty(images)) { loadMoreFooterView.setStatus(LoadMoreFooterView.Status.THE_END); } else { - -// mPage++; -// loadMoreFooterView.setStatus(LoadMoreFooterView.Status.GONE); -// mAdapter.append(images); - /** - * FIXME here we post delay to see more animation, you don't need to do this. - */ - loadMoreFooterView.postDelayed(new Runnable() { - @Override - public void run() { - mPage++; - loadMoreFooterView.setStatus(LoadMoreFooterView.Status.GONE); - mAdapter.append(images); - } - }, 2000); + mPage++; + loadMoreFooterView.setStatus(LoadMoreFooterView.Status.GONE); + mAdapter.append(images); } } diff --git a/app/src/main/java/com/aspsine/irecyclerview/demo/ui/adapter/ImageAdapter.java b/app/src/main/java/com/aspsine/irecyclerview/demo/ui/adapter/ImageAdapter.java index cad7b5a..f927863 100644 --- a/app/src/main/java/com/aspsine/irecyclerview/demo/ui/adapter/ImageAdapter.java +++ b/app/src/main/java/com/aspsine/irecyclerview/demo/ui/adapter/ImageAdapter.java @@ -52,7 +52,7 @@ public void remove(int position) { notifyItemRemoved(position); } - public void clear(){ + public void clear() { mImages.clear(); notifyDataSetChanged(); } @@ -74,9 +74,11 @@ public void onClick(View v) { * {@code IViewHolder.getIAdapterPosition()} */ final int position = holder.getIAdapterPosition(); - final Image image = mImages.get(position); - if (mOnItemClickListener != null) { - mOnItemClickListener.onItemClick(position, image, v); + if (position != RecyclerView.NO_POSITION) { + final Image image = mImages.get(position); + if (mOnItemClickListener != null) { + mOnItemClickListener.onItemClick(position, image, v); + } } } }); diff --git a/build.gradle b/build.gradle index 0a52a5e..7343418 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.0-rc1' + classpath 'com.android.tools.build:gradle:3.1.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -16,6 +17,7 @@ allprojects { repositories { jcenter() maven { url "https://jitpack.io" } + google() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d3fa8fc..59ee4fb 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Aug 11 08:45:15 CST 2016 +#Sun Jun 24 20:49:02 CST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/library/build.gradle b/library/build.gradle index 9e0be04..5014242 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,14 +1,14 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 24 - buildToolsVersion '24.0.2' + compileSdkVersion 27 + buildToolsVersion '27.0.3' defaultConfig { - minSdkVersion 11 - targetSdkVersion 24 - versionCode 5 - versionName "0.0.5" + minSdkVersion 14 + targetSdkVersion 27 + versionCode 6 + versionName "0.0.6" } buildTypes { release { @@ -19,7 +19,7 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - testCompile 'junit:junit:4.12' - compile 'com.android.support:recyclerview-v7:24.2.0' + api fileTree(include: ['*.jar'], dir: 'libs') + testImplementation 'junit:junit:4.12' + api 'com.android.support:recyclerview-v7:27.1.1' } diff --git a/library/src/main/java/com/aspsine/irecyclerview/IViewHolder.java b/library/src/main/java/com/aspsine/irecyclerview/IViewHolder.java index da273a0..6b05c08 100644 --- a/library/src/main/java/com/aspsine/irecyclerview/IViewHolder.java +++ b/library/src/main/java/com/aspsine/irecyclerview/IViewHolder.java @@ -22,6 +22,9 @@ public final int getILayoutPosition() { } public final int getIAdapterPosition() { + if (getAdapterPosition() == RecyclerView.NO_POSITION) { + return RecyclerView.NO_POSITION; + } return getAdapterPosition() - 2; } diff --git a/library/src/main/java/com/aspsine/irecyclerview/WrapperAdapter.java b/library/src/main/java/com/aspsine/irecyclerview/WrapperAdapter.java index 22880d0..d5cd179 100644 --- a/library/src/main/java/com/aspsine/irecyclerview/WrapperAdapter.java +++ b/library/src/main/java/com/aspsine/irecyclerview/WrapperAdapter.java @@ -1,5 +1,6 @@ package com.aspsine.irecyclerview; +import android.support.annotation.NonNull; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.StaggeredGridLayoutManager; @@ -74,7 +75,7 @@ public RecyclerView.Adapter getAdapter() { } @Override - public void onAttachedToRecyclerView(final RecyclerView recyclerView) { + public void onAttachedToRecyclerView(@NonNull final RecyclerView recyclerView) { RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager; @@ -95,7 +96,7 @@ public int getSpanSize(int position) { } @Override - public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) { + public void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder) { super.onViewAttachedToWindow(holder); int position = holder.getAdapterPosition(); int type = getItemViewType(position); @@ -134,8 +135,9 @@ public int getItemViewType(int position) { throw new IllegalArgumentException("Wrong type! Position = " + position); } + @NonNull @Override - public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == REFRESH_HEADER) { return new RefreshHeaderContainerViewHolder(mRefreshHeaderContainer); } else if (viewType == HEADER) { @@ -150,7 +152,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType } @Override - public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (1 < position && position < mAdapter.getItemCount() + 2) { mAdapter.onBindViewHolder(holder, position - 2); } @@ -158,28 +160,28 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { static class RefreshHeaderContainerViewHolder extends RecyclerView.ViewHolder { - public RefreshHeaderContainerViewHolder(View itemView) { + RefreshHeaderContainerViewHolder(View itemView) { super(itemView); } } static class HeaderContainerViewHolder extends RecyclerView.ViewHolder { - public HeaderContainerViewHolder(View itemView) { + HeaderContainerViewHolder(View itemView) { super(itemView); } } static class FooterContainerViewHolder extends RecyclerView.ViewHolder { - public FooterContainerViewHolder(View itemView) { + FooterContainerViewHolder(View itemView) { super(itemView); } } static class LoadMoreFooterContainerViewHolder extends RecyclerView.ViewHolder { - public LoadMoreFooterContainerViewHolder(View itemView) { + LoadMoreFooterContainerViewHolder(View itemView) { super(itemView); } }