Skip to content

Commit

Permalink
Merge pull request #2 from veghtomi/add-new-shimmer-implementation
Browse files Browse the repository at this point in the history
Add new shimmer implementation
  • Loading branch information
ethanhua committed Aug 31, 2017
2 parents e89120c + 26fde3f commit 310b517
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 1,195 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
.idea
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# skeleton
# Skeleton

a library provide a easy way to show skeleton loading view like facebook and alipay
The library provides an easy way to show skeleton loading view like Facebook and Alipay. It now uses a memory optimised version of shimmer animation so it is even faster and you can animate bigger layouts as well.

# Preview

Expand All @@ -18,8 +18,10 @@ you can scan the qrcode for download demo apk

# Feature
- Light
- Noninvasive,You don't need to make changes to existing code.
- Wide applicability,It is available for all views
- Different colors can be set for the shimmer effect
- Noninvasive, you don't need to make changes to existing code.
- Wide applicability,it is available for all views
- Memory optimised

# Getting started

Expand All @@ -31,17 +33,19 @@ In your build.gradle:


# Usage
for recyclerview:
For RecyclerView:

skeletonScreen = Skeleton.bind(recyclerView)
.adapter(adapter)
.load(R.layout.item_skeleton_news)
.count(10)
.color(R.color.shimmer_color)
.show();
 for view
 For View

skeletonScreen = Skeleton.bind(rootView)
.load(R.layout.layout_img_skeleton)
.color(R.color.shimmer_color)
.show();
when data return you can call the method to hide skeleton loading view
Expand All @@ -50,10 +54,10 @@ In your build.gradle:
# Thanks

https://github.com/team-supercharge/ShimmerLayout

https://github.com/sharish/ShimmerRecyclerView

https://github.com/facebook/shimmer-android


# License

Copyright 2017, ethanhua
Expand Down
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
})
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'io.supercharge:shimmerlayout:1.0.2'
testCompile 'junit:junit:4.12'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ethanhua.skeleton;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;

/**
Expand All @@ -8,23 +10,18 @@

public class RecyclerViewSkeletonScreen implements SkeletonScreen {


private RecyclerView mRecyclerView;
private RecyclerView.Adapter mActualAdapter;
private ShimmerAdapter mSkeletonAdapter;

private RecyclerViewSkeletonScreen(Builder builder) {
this.mRecyclerView = builder.mRecyclerView;
this.mActualAdapter = builder.mActualAdapter;

private RecyclerViewSkeletonScreen(RecyclerView recyclerView,
RecyclerView.Adapter adapter,
int itemResID,
int itemCount) {
this.mRecyclerView = recyclerView;
mActualAdapter = adapter;
int mItemResID = itemResID;
int mItemCount = itemCount;
mSkeletonAdapter = new ShimmerAdapter();
mSkeletonAdapter.setItemCount(mItemCount);
mSkeletonAdapter.setLayoutReference(mItemResID);
this.mSkeletonAdapter = new ShimmerAdapter();
this.mSkeletonAdapter.setItemCount(builder.mItemCount);
this.mSkeletonAdapter.setLayoutReference(builder.mItemResID);
this.mSkeletonAdapter.setColor(builder.mColor);
}

@Override
Expand All @@ -43,15 +40,19 @@ public void hide() {
}
}


public static class Builder {
private RecyclerView.Adapter mActualAdapter;
private RecyclerView mRecyclerView;
private int mItemCount = 10;
private int mItemResID = R.layout.layout_default_item_skeleton;
private int mColor;
private Context mContext;

public Builder(RecyclerView recyclerView) {
public Builder(RecyclerView recyclerView, Context context) {
this.mRecyclerView = recyclerView;
this.mContext = context;

this.mColor = ContextCompat.getColor(context, R.color.shimmer_color);
}

public Builder adapter(RecyclerView.Adapter adapter) {
Expand All @@ -64,14 +65,20 @@ public Builder count(int itemCount) {
return this;
}

public Builder color(int color) {
this.mColor = ContextCompat.getColor(mContext, color);
return this;
}

public Builder load(int skeletonLayoutResID) {
this.mItemResID = skeletonLayoutResID;
return this;
}

public RecyclerViewSkeletonScreen show() {
RecyclerViewSkeletonScreen recyclerViewSkeleton = new RecyclerViewSkeletonScreen(mRecyclerView, mActualAdapter, mItemResID, mItemCount);
RecyclerViewSkeletonScreen recyclerViewSkeleton = new RecyclerViewSkeletonScreen(this);
recyclerViewSkeleton.show();

return recyclerViewSkeleton;
}
}
Expand Down
18 changes: 12 additions & 6 deletions library/src/main/java/com/ethanhua/skeleton/ShimmerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.view.LayoutInflater;
import android.view.ViewGroup;

import io.supercharge.shimmerlayout.ShimmerLayout;

/**
* Created by ethanhua on 2017/7/29.
*/
Expand All @@ -12,11 +14,7 @@ public class ShimmerAdapter extends RecyclerView.Adapter<ShimmerViewHolder> {

private int mItemCount;
private int mLayoutReference;


public void setItemCount(int itemCount) {
mItemCount = itemCount;
}
private int mColor;

@Override
public ShimmerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Expand All @@ -26,7 +24,9 @@ public ShimmerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

@Override
public void onBindViewHolder(ShimmerViewHolder holder, int position) {
ShimmerFrameLayout layout = (ShimmerFrameLayout) holder.itemView;
ShimmerLayout layout = (ShimmerLayout) holder.itemView;

layout.setShimmerColor(mColor);
layout.startShimmerAnimation();
}

Expand All @@ -39,5 +39,11 @@ public void setLayoutReference(int layoutReference) {
this.mLayoutReference = layoutReference;
}

public void setItemCount(int itemCount) {
this.mItemCount = itemCount;
}

public void setColor(int color) {
this.mColor = color;
}
}
Loading

0 comments on commit 310b517

Please sign in to comment.