Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用layout和id来限制HeaderView和FooterView不是很方便,建议使用SwipeViewFactory接口 #132

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ SwipeToLoadLayout is a reusable pull-to-refresh and pull-to-load-more widget.
## Supported View
Theoretically support all kinds of views.

## Update
1、add [SwipeViewFactory](https://github.com/liyzay/SwipeToLoadLayout/blob/master/library/src/main/java/com/aspsine/swipetoloadlayout/SwipeViewFactory.java) to generate HeaderView and FooterView

2、add default Google Style HeaderView FooterView(use [GoogleStyleSwipeViewFactory](https://github.com/liyzay/SwipeToLoadLayout/blob/master/library/src/main/java/com/aspsine/swipetoloadlayout/GoogleStyleSwipeViewFactory.java) by default)

## Demo
[Download](https://raw.githubusercontent.com/Aspsine/SwipeToLoadLayout/master/art/demo.apk)

Expand Down
5 changes: 5 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ SwipeToLoadLayout是一个可以帮助你实现下拉刷新和加载更多的Lay
## 支持的View
理论上支持所有的View

## 修改
1、添加[SwipeViewFactory](https://github.com/liyzay/SwipeToLoadLayout/blob/master/library/src/main/java/com/aspsine/swipetoloadlayout/SwipeViewFactory.java)接口,用于生成HeaderView和FooterView

2、添加内置的Google Style的HeaderView和FooterView(默认使用[GoogleStyleSwipeViewFactory](https://github.com/liyzay/SwipeToLoadLayout/blob/master/library/src/main/java/com/aspsine/swipetoloadlayout/GoogleStyleSwipeViewFactory.java))

## Demo
[Download](https://raw.githubusercontent.com/Aspsine/SwipeToLoadLayout/master/art/demo.apk)

Expand Down
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
compileSdkVersion rootProject.ext.sdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
applicationId "com.aspsine.swipetoloadlayout"
minSdkVersion 10
targetSdkVersion 25
targetSdkVersion rootProject.ext.sdkVersion
versionCode 4
versionName "1.0.4"
}
Expand All @@ -27,9 +27,9 @@ dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile project(':library')
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile "com.android.support:appcompat-v7:$supportLibVersion"
compile "com.android.support:recyclerview-v7:$supportLibVersion"
compile "com.android.support:design:$supportLibVersion"
compile 'com.google.code.gson:gson:2.4'
compile 'com.mcxiaoke.volley:library-aar:1.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.aspsine.swipetoloadlayout.demo.R;
import com.aspsine.swipetoloadlayout.demo.adapter.RecyclerCharactersAdapter;
import com.aspsine.swipetoloadlayout.demo.model.SectionCharacters;
import com.aspsine.swipetoloadlayout.demo.viewfactory.GoogleRingSwipeViewFactory;

/**
* Created by Aspsine on 2015/9/10.
Expand Down Expand Up @@ -67,6 +68,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
swipeToLoadLayout = (SwipeToLoadLayout) view.findViewById(R.id.swipeToLoadLayout);
if(mType!=0){
swipeToLoadLayout.setSwipeViewFactory(new GoogleRingSwipeViewFactory(getContext()));
}
recyclerView = (RecyclerView) view.findViewById(R.id.swipe_target);
recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
recyclerView.setAdapter(mAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.aspsine.swipetoloadlayout.OnRefreshListener;
import com.aspsine.swipetoloadlayout.SwipeToLoadLayout;
import com.aspsine.swipetoloadlayout.demo.R;
import com.aspsine.swipetoloadlayout.demo.viewfactory.JDSwipeViewFactory;

/**
* A simple {@link Fragment} subclass.
Expand Down Expand Up @@ -49,6 +50,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
swipeToLoadLayout = (SwipeToLoadLayout) view.findViewById(R.id.swipeToLoadLayout);
swipeToLoadLayout.setSwipeViewFactory(new JDSwipeViewFactory(getContext()));
swipeToLoadLayout.setOnRefreshListener(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.aspsine.swipetoloadlayout.SwipeToLoadLayout;
import com.aspsine.swipetoloadlayout.demo.R;
import com.aspsine.swipetoloadlayout.demo.adapter.BaseArrayAdapter;
import com.aspsine.swipetoloadlayout.demo.viewfactory.YalantisSwipeViewFactory;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -86,6 +87,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setTitle("Yalantis Style");
swipeToLoadLayout = (SwipeToLoadLayout) view.findViewById(R.id.swipeToLoadLayout);
swipeToLoadLayout.setSwipeViewFactory(new YalantisSwipeViewFactory(getContext()));
swipeToLoadLayout.setOnRefreshListener(this);
ListView listView = (ListView) view.findViewById(R.id.swipe_target);
BaseArrayAdapter adapter = new SampleAdapter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.aspsine.swipetoloadlayout.demo.R;
import com.aspsine.swipetoloadlayout.demo.adapter.CharacterAdapter;
import com.aspsine.swipetoloadlayout.demo.model.SectionCharacters;
import com.aspsine.swipetoloadlayout.demo.viewfactory.TwitterRefreshSwipeViewFactory;

/**
* A simple {@link Fragment} subclass.
Expand Down Expand Up @@ -60,6 +61,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
swipeToLoadLayout = (SwipeToLoadLayout) view.findViewById(R.id.swipeToLoadLayout);
swipeToLoadLayout.setSwipeViewFactory(new TwitterRefreshSwipeViewFactory(getContext()));
gridView = (GridView) view.findViewById(R.id.swipe_target);

swipeToLoadLayout.setOnRefreshListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.aspsine.swipetoloadlayout.demo.adapter.SectionAdapter;
import com.aspsine.swipetoloadlayout.demo.model.Character;
import com.aspsine.swipetoloadlayout.demo.model.SectionCharacters;
import com.aspsine.swipetoloadlayout.demo.viewfactory.TwitterRefreshSwipeViewFactory;

/**
* A simple {@link Fragment} subclass.
Expand Down Expand Up @@ -72,6 +73,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
View pagerView = LayoutInflater.from(view.getContext()).inflate(R.layout.layout_viewpager, listView, false);
swipeToLoadLayout = (SwipeToLoadLayout) view.findViewById(R.id.swipeToLoadLayout);
swipeToLoadLayout.setSwipeViewFactory(new TwitterRefreshSwipeViewFactory(getContext()));
listView = (ListView) view.findViewById(R.id.swipe_target);
viewPager = (ViewPager) pagerView.findViewById(R.id.viewPager);
indicators = (ViewGroup) pagerView.findViewById(R.id.indicators);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.aspsine.swipetoloadlayout.OnRefreshListener;
import com.aspsine.swipetoloadlayout.SwipeToLoadLayout;
import com.aspsine.swipetoloadlayout.demo.R;
import com.aspsine.swipetoloadlayout.demo.viewfactory.TwitterRefreshSwipeViewFactory;
import com.squareup.picasso.Picasso;

/**
Expand Down Expand Up @@ -65,6 +66,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
swipeToLoadLayout = (SwipeToLoadLayout) view.findViewById(R.id.swipeToLoadLayout);
swipeToLoadLayout.setSwipeViewFactory(new TwitterRefreshSwipeViewFactory(getContext()));
tvTitle = (TextView) view.findViewById(R.id.tvTitle);
View targetView = view.findViewById(R.id.swipe_target);
swipeToLoadLayout.setOnRefreshListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
import android.widget.Toast;

import com.android.volley.Response;
Expand All @@ -27,9 +26,9 @@
import com.aspsine.swipetoloadlayout.demo.adapter.OnChildItemClickListener;
import com.aspsine.swipetoloadlayout.demo.adapter.OnChildItemLongClickListener;
import com.aspsine.swipetoloadlayout.demo.adapter.RecyclerCharactersAdapter;
import com.aspsine.swipetoloadlayout.demo.adapter.SectionAdapter;
import com.aspsine.swipetoloadlayout.demo.model.Character;
import com.aspsine.swipetoloadlayout.demo.model.SectionCharacters;
import com.aspsine.swipetoloadlayout.demo.viewfactory.TwitterRefreshSwipeViewFactory;

/**
* A simple {@link Fragment} subclass.
Expand Down Expand Up @@ -85,6 +84,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
swipeToLoadLayout = (SwipeToLoadLayout) view.findViewById(R.id.swipeToLoadLayout);
swipeToLoadLayout.setSwipeViewFactory(new TwitterRefreshSwipeViewFactory(getContext()));
recyclerView = (RecyclerView) view.findViewById(R.id.swipe_target);
RecyclerView.LayoutManager layoutManager = null;
if (mType == TYPE_LINEAR) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -24,6 +23,7 @@
import com.aspsine.swipetoloadlayout.demo.R;
import com.aspsine.swipetoloadlayout.demo.model.Character;
import com.aspsine.swipetoloadlayout.demo.model.SectionCharacters;
import com.aspsine.swipetoloadlayout.demo.viewfactory.TwitterRefreshSwipeViewFactory;
import com.squareup.picasso.Picasso;

import java.util.List;
Expand Down Expand Up @@ -58,6 +58,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
swipeToLoadLayout = (SwipeToLoadLayout) view.findViewById(R.id.swipeToLoadLayout);
swipeToLoadLayout.setSwipeViewFactory(new TwitterRefreshSwipeViewFactory(getContext()));
scrollView = (ScrollView) view.findViewById(R.id.swipe_target);
tvTitle = (TextView) view.findViewById(R.id.tvTitle);
ViewGroup viewGroup = (ViewGroup) view.findViewById(R.id.group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.aspsine.swipetoloadlayout.OnRefreshListener;
import com.aspsine.swipetoloadlayout.SwipeToLoadLayout;
import com.aspsine.swipetoloadlayout.demo.R;
import com.aspsine.swipetoloadlayout.demo.viewfactory.TwitterRefreshSwipeViewFactory;

/**
* A simple {@link Fragment} subclass.
Expand All @@ -41,6 +42,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
swipeToLoadLayout = (SwipeToLoadLayout) view.findViewById(R.id.swipeToLoadLayout);
swipeToLoadLayout.setSwipeViewFactory(new TwitterRefreshSwipeViewFactory(getContext()));
webView = (WebView) view.findViewById(R.id.swipe_target);
swipeToLoadLayout.setOnRefreshListener(this);
swipeToLoadLayout.setOnLoadMoreListener(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.aspsine.swipetoloadlayout.demo.viewfactory;

import android.content.Context;
import android.view.LayoutInflater;

import com.aspsine.swipetoloadlayout.SwipeToLoadLayout;
import com.aspsine.swipetoloadlayout.SwipeViewFactory;
import com.aspsine.swipetoloadlayout.demo.R;
import com.aspsine.swipetoloadlayout.demo.view.footer.GoogleLoadMoreFooterView;
import com.aspsine.swipetoloadlayout.demo.view.header.GoogleRefreshHeaderView;

/**
* Created by Alex on 2017/9/14.
*/

public class GoogleRingSwipeViewFactory implements SwipeViewFactory<GoogleRefreshHeaderView,GoogleLoadMoreFooterView>{
private Context mContext;

public GoogleRingSwipeViewFactory(Context context) {
mContext = context;
}

@Override
public GoogleRefreshHeaderView createHeaderView(SwipeToLoadLayout parent) {
return (GoogleRefreshHeaderView) LayoutInflater.from(mContext).inflate(R.layout.layout_google_header,parent,false);
}

@Override
public GoogleLoadMoreFooterView createFooterView(SwipeToLoadLayout parent) {
return (GoogleLoadMoreFooterView) LayoutInflater.from(mContext).inflate(R.layout.layout_google_footer,parent,false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.aspsine.swipetoloadlayout.demo.viewfactory;

import android.content.Context;
import android.view.LayoutInflater;

import com.aspsine.swipetoloadlayout.SwipeLoadMoreFooterLayout;
import com.aspsine.swipetoloadlayout.SwipeToLoadLayout;
import com.aspsine.swipetoloadlayout.SwipeViewFactory;
import com.aspsine.swipetoloadlayout.demo.R;
import com.aspsine.swipetoloadlayout.demo.view.header.JdRefreshHeaderView;

/**
* Created by Alex on 2017/9/14.
*/

public class JDSwipeViewFactory implements SwipeViewFactory<JdRefreshHeaderView,SwipeLoadMoreFooterLayout>{
private Context mContext;

public JDSwipeViewFactory(Context context) {
mContext = context;
}

@Override
public JdRefreshHeaderView createHeaderView(SwipeToLoadLayout parent) {
return (JdRefreshHeaderView) LayoutInflater.from(mContext).inflate(R.layout.layout_jd_header,parent,false);
}

@Override
public SwipeLoadMoreFooterLayout createFooterView(SwipeToLoadLayout parent) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.aspsine.swipetoloadlayout.demo.viewfactory;

import android.content.Context;
import android.view.LayoutInflater;

import com.aspsine.swipetoloadlayout.SwipeToLoadLayout;
import com.aspsine.swipetoloadlayout.SwipeViewFactory;
import com.aspsine.swipetoloadlayout.demo.R;
import com.aspsine.swipetoloadlayout.demo.view.footer.ClassicLoadMoreFooterView;
import com.aspsine.swipetoloadlayout.demo.view.header.TwitterRefreshHeaderView;

/**
* Created by Alex on 2017/9/14.
*/

public class TwitterRefreshSwipeViewFactory implements SwipeViewFactory<TwitterRefreshHeaderView,ClassicLoadMoreFooterView>{
private Context mContext;

public TwitterRefreshSwipeViewFactory(Context context) {
mContext = context;
}

@Override
public TwitterRefreshHeaderView createHeaderView(SwipeToLoadLayout parent) {
return (TwitterRefreshHeaderView) LayoutInflater.from(mContext).inflate(R.layout.layout_twitter_header,parent,false);
}

@Override
public ClassicLoadMoreFooterView createFooterView(SwipeToLoadLayout parent) {
return (ClassicLoadMoreFooterView) LayoutInflater.from(mContext).inflate(R.layout.layout_classic_footer,parent,false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.aspsine.swipetoloadlayout.demo.viewfactory;

import android.content.Context;
import android.view.LayoutInflater;

import com.aspsine.swipetoloadlayout.SwipeLoadMoreFooterLayout;
import com.aspsine.swipetoloadlayout.SwipeToLoadLayout;
import com.aspsine.swipetoloadlayout.SwipeViewFactory;
import com.aspsine.swipetoloadlayout.demo.R;
import com.aspsine.swipetoloadlayout.demo.view.header.YalantisPhoenixRefreshHeaderView;

/**
* Created by Alex on 2017/9/14.
*/

public class YalantisSwipeViewFactory implements SwipeViewFactory<YalantisPhoenixRefreshHeaderView,SwipeLoadMoreFooterLayout>{
private Context mContext;

public YalantisSwipeViewFactory(Context context) {
mContext = context;
}

@Override
public YalantisPhoenixRefreshHeaderView createHeaderView(SwipeToLoadLayout parent) {
return (YalantisPhoenixRefreshHeaderView) LayoutInflater.from(mContext).inflate(R.layout.layout_yalantis_header,parent,false);
}

@Override
public SwipeLoadMoreFooterLayout createFooterView(SwipeToLoadLayout parent) {
return null;
}
}
8 changes: 0 additions & 8 deletions app/src/main/res/layout/fragment_google_style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,10 @@
app:load_more_complete_delay_duration="0"
app:swipe_style="above">

<include
android:id="@id/swipe_refresh_header"
layout="@layout/layout_google_hook_header" />

<android.support.v7.widget.RecyclerView
android:id="@id/swipe_target"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false" />

<include
android:id="@id/swipe_load_more_footer"
layout="@layout/layout_google_hook_footer" />

</com.aspsine.swipetoloadlayout.SwipeToLoadLayout>
8 changes: 0 additions & 8 deletions app/src/main/res/layout/fragment_google_style_custom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,10 @@
app:refresh_trigger_offset="@dimen/refresh_trigger_offset_google"
app:swipe_style="above">

<include
android:id="@id/swipe_refresh_header"
layout="@layout/layout_google_header" />

<android.support.v7.widget.RecyclerView
android:id="@id/swipe_target"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false" />

<include
android:id="@id/swipe_load_more_footer"
layout="@layout/layout_google_footer" />

</com.aspsine.swipetoloadlayout.SwipeToLoadLayout>
Loading