├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── array.png
│ │ │ │ ├── back.png
│ │ │ │ ├── star.png
│ │ │ │ ├── collect.png
│ │ │ │ ├── header.png
│ │ │ │ ├── publish.png
│ │ │ │ ├── setting.png
│ │ │ │ ├── ic_test_0.png
│ │ │ │ ├── ic_test_1.jpg
│ │ │ │ ├── home_selected.png
│ │ │ │ ├── arena_selected.png
│ │ │ │ ├── home_unselected.png
│ │ │ │ ├── page_indicator.png
│ │ │ │ ├── arena_unselected.png
│ │ │ │ ├── attention_selected.png
│ │ │ │ ├── discovery_selected.png
│ │ │ │ ├── rating_small_empty.png
│ │ │ │ ├── rating_small_full.png
│ │ │ │ ├── rating_small_half.png
│ │ │ │ ├── toolbar_navigation.png
│ │ │ │ ├── attention_unselected.png
│ │ │ │ ├── discovery_unselected.png
│ │ │ │ ├── fragment_home_discount.png
│ │ │ │ ├── page_indicator_focused.png
│ │ │ │ ├── item_attention_textbackgroud.png
│ │ │ │ ├── item_discovery_bottom_look.png
│ │ │ │ ├── fragment_discovery_flip_effect.jpg
│ │ │ │ ├── tab_item_arena.xml
│ │ │ │ ├── tab_item_home.xml
│ │ │ │ ├── tab_item_attention.xml
│ │ │ │ ├── tab_item_discovery.xml
│ │ │ │ └── room_rating_bar.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
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── colors.xml
│ │ │ ├── menu
│ │ │ │ ├── menu_edit.xml
│ │ │ │ └── menu_drawer.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── item_fragment_discovery_hot_column.xml
│ │ │ │ ├── drawer_header.xml
│ │ │ │ ├── toolbar.xml
│ │ │ │ ├── fragment_attention.xml
│ │ │ │ ├── fragment_discovery.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── fragment_ability1.xml
│ │ │ │ ├── item_fragment_attention_recyclerview.xml
│ │ │ │ ├── item_fragment_ability_recyclerview.xml
│ │ │ │ └── fragment_arena.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── fuzhucheng
│ │ │ │ └── rxjavartrofitrecyclerview
│ │ │ │ ├── utils
│ │ │ │ ├── ReUtil.java
│ │ │ │ ├── ToastUtils.java
│ │ │ │ ├── ScreenUtil.java
│ │ │ │ ├── NetUtil.java
│ │ │ │ ├── RetrofitUtil.java
│ │ │ │ └── SPUtil.java
│ │ │ │ ├── requests
│ │ │ │ └── MovieRequest.java
│ │ │ │ ├── widget
│ │ │ │ ├── ScollTextView.java
│ │ │ │ ├── NoScrollViewPager.java
│ │ │ │ ├── MyNestedScrollView.java
│ │ │ │ └── FullyLinearLayoutManager.java
│ │ │ │ ├── bean
│ │ │ │ ├── HotColumnBean.java
│ │ │ │ ├── AttentionBean.java
│ │ │ │ ├── AbilityItem.java
│ │ │ │ ├── DiscountColumnBean.java
│ │ │ │ └── AbilityBean.java
│ │ │ │ ├── App.java
│ │ │ │ ├── adapter
│ │ │ │ ├── ViewPagerAdapter.java
│ │ │ │ └── HomeViewPagerAdapter.java
│ │ │ │ ├── activity
│ │ │ │ ├── base
│ │ │ │ │ ├── ToolbarActivity.java
│ │ │ │ │ ├── BaseActivity.java
│ │ │ │ │ └── DrawerActivity.java
│ │ │ │ └── MainActivity.java
│ │ │ │ └── fragment
│ │ │ │ ├── ArenaFragment.java
│ │ │ │ ├── base
│ │ │ │ ├── BaseFragment.java
│ │ │ │ ├── RecyclerViewFragment.java
│ │ │ │ └── BannerFragment.java
│ │ │ │ ├── AttentionFragment.java
│ │ │ │ ├── DiscoveryFragment.java
│ │ │ │ └── AbilityFragment.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── fuzhucheng
│ │ │ └── rxjavartrofitrecyclerview
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── fuzhucheng
│ │ └── rxjavartrofitrecyclerview
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/array.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/array.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/back.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/star.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/collect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/collect.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/header.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/publish.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/publish.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/setting.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/setting.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_test_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/ic_test_0.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_test_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/ic_test_1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/home_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/home_selected.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/arena_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/arena_selected.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/home_unselected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/home_unselected.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/page_indicator.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/page_indicator.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/arena_unselected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/arena_unselected.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/attention_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/attention_selected.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/discovery_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/discovery_selected.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/rating_small_empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/rating_small_empty.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/rating_small_full.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/rating_small_full.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/rating_small_half.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/rating_small_half.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/toolbar_navigation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/toolbar_navigation.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/attention_unselected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/attention_unselected.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/discovery_unselected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/discovery_unselected.png
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/fragment_home_discount.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/fragment_home_discount.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/page_indicator_focused.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/page_indicator_focused.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/item_attention_textbackgroud.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/item_attention_textbackgroud.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/item_discovery_bottom_look.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/item_discovery_bottom_look.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/fragment_discovery_flip_effect.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FuZhucheng/RxjavaRtrofitRecyclerview/HEAD/app/src/main/res/drawable/fragment_discovery_flip_effect.jpg
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_item_arena.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_item_home.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_item_attention.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_item_discovery.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_edit.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/room_rating_bar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_fragment_discovery_hot_column.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/fuzhucheng/rxjavartrofitrecyclerview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview;
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 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/utils/ReUtil.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.utils;
2 |
3 | import java.util.regex.Matcher;
4 | import java.util.regex.Pattern;
5 |
6 | /**
7 | * Created by 符柱成 on 2017/1/12.
8 | */
9 |
10 | public class ReUtil {
11 | public static boolean isPhone(String phone) {
12 | Pattern pattern = Pattern.compile("^1(3[0-9]|4[57]|5[0-35-9]|7[0135678]|8[0-9])\\d{8}$");
13 | Matcher matcher = pattern.matcher(phone);
14 | return matcher.matches();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/requests/MovieRequest.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.requests;
2 |
3 | import com.fuzhucheng.rxjavartrofitrecyclerview.bean.AbilityBean;
4 |
5 | import retrofit2.http.GET;
6 | import retrofit2.http.Query;
7 | import rx.Observable;
8 |
9 | /**
10 | * Created by ${符柱成} on 2017/1/21.
11 | */
12 |
13 | public interface MovieRequest {
14 | // //请求参数
15 | @GET("/v2/movie/top250")
16 | Observable getMovies(@Query("start") int start, @Query("count") int count);
17 | }
18 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/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 E:\Android\AndroidStudioSDK/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/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/widget/ScollTextView.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.widget;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 |
6 | import java.util.List;
7 |
8 | import lester.scolltextview.scolltextview.BaseScollTextView;
9 |
10 | public class ScollTextView extends BaseScollTextView {
11 |
12 | public ScollTextView(Context context) {
13 | super(context);
14 | }
15 |
16 | public ScollTextView(Context context, AttributeSet attrs) {
17 | super(context, attrs);
18 | }
19 |
20 | @Override
21 | public String getItemText(List data, int postion) {
22 | return data.get(postion);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/bean/HotColumnBean.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.bean;
2 |
3 | /**
4 | * Created by ${符柱成} on 2016/12/9.
5 | */
6 |
7 | public class HotColumnBean {
8 | private String image;
9 | private boolean isComMeg;
10 |
11 |
12 | public HotColumnBean(String image) {
13 | this.image = image;
14 | }
15 |
16 | public String getImage() {
17 | return image;
18 | }
19 |
20 | public void setImage(String image) {
21 | this.image = image;
22 | }
23 |
24 | public boolean isComMeg() {
25 | return isComMeg;
26 | }
27 |
28 | public void setComMeg(boolean comMeg) {
29 | isComMeg = comMeg;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/App.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import android.support.multidex.MultiDex;
6 |
7 | /**
8 | * Created by 符柱成 on 2016/12/2.
9 | */
10 | public class App extends Application {
11 |
12 | private static App app;
13 |
14 | @Override
15 | protected void attachBaseContext(Context base) {
16 | super.attachBaseContext(base);
17 | }
18 |
19 | @Override
20 | public void onCreate() {
21 | super.onCreate();
22 | MultiDex.install(this);
23 |
24 | app = this;
25 | }
26 |
27 | public static App getInstance() {
28 | return app;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/bean/AttentionBean.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.bean;
2 |
3 | /**
4 | * Created by ${符柱成} on 2016/12/10.
5 | */
6 | public class AttentionBean {
7 |
8 | private String icon;
9 | private String title;
10 |
11 |
12 | public AttentionBean(String icon, String title) {
13 | this.icon = icon;
14 | this.title = title;
15 | }
16 |
17 | public String getIcon() {
18 | return icon;
19 | }
20 |
21 | public void setIcon(String icon) {
22 | this.icon = icon;
23 | }
24 |
25 | public String getTitle() {
26 | return title;
27 | }
28 |
29 | public void setTitle(String title) {
30 | this.title = title;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RxjavaRtrofitRecyclerview
3 |
4 | 登录
5 | 购物车
6 | 经历
7 | 参加
8 | 收藏
9 | 设置
10 |
11 | 确定
12 |
13 | 打开
14 | 关闭
15 |
16 | 获取成功
17 | 获取失败
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
17 |
18 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Android-多列表的项目(Rxjava+Rtrofit+Recyclerview+Glide+Adapter封装)
2 | ***
3 | #### 简介:本系列将会把我最近那个安卓项目的一些好东西抽出来分享给大家。并附带一系列的博客解析。
4 | ### (一)[Android-多列表的项目(Rxjava+Rtrofit+Recyclerview+Glide+Adapter封装)之(一)项目架构](http://blog.csdn.net/jack__frost/article/details/55853599)
5 | ### (二)[Android-多列表的项目(Rxjava+Rtrofit+Recyclerview+Glide+Adapter封装)之(二)网络层的封装](http://blog.csdn.net/Jack__Frost/article/details/56012531)
6 | ### (三)[Android-ButterKnife不能注解RatingBar(含ButterKnife部分原理以及View传递机制)](http://blog.csdn.net/Jack__Frost/article/details/59490388)
7 | ### (四)[Android--焦点问题以及讨论事件传递机制问题(结合部分相关源码)](http://blog.csdn.net/jack__frost/article/details/59578796)
8 | ***
9 | ### 喜欢给个star吧。
10 | ### 更多内容,可以访问[JackFrost的博客](http://blog.csdn.net/jack__frost?viewmode=contents)
11 | ***
12 | ### 联系方式:
13 | #### 邮箱:jackfrost@fuzhufuzhu.com
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/drawer_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/utils/ToastUtils.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.utils;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 |
6 | public class ToastUtils {
7 |
8 | private static Toast toast = null;
9 |
10 | public static void showToast(Context mContext, String text) {
11 | if (toast == null) {
12 | toast = Toast.makeText(mContext, text, Toast.LENGTH_SHORT);
13 | } else {
14 | toast.setText(text);
15 | }
16 | toast.show();
17 | }
18 |
19 | public static void showToast(Context mContext, int id) {
20 | if (toast == null) {
21 | toast = Toast.makeText(mContext, id, Toast.LENGTH_SHORT);
22 | } else {
23 | toast.setText(id);
24 | }
25 | toast.show();
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/adapter/ViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.adapter;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentStatePagerAdapter;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Created by 符柱成 on 2016/12/3.
11 | */
12 | public class ViewPagerAdapter extends FragmentStatePagerAdapter {
13 |
14 | private List fragments;
15 |
16 | public ViewPagerAdapter(FragmentManager fm, List fragments) {
17 | super(fm);
18 | this.fragments = fragments;
19 | }
20 |
21 | @Override
22 | public Fragment getItem(int position) {
23 | return fragments.get(position);
24 | }
25 |
26 | @Override
27 | public int getCount() {
28 | return fragments.size();
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/utils/ScreenUtil.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.utils;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by 符柱成 on 2016/12/3.
7 | */
8 | public class ScreenUtil {
9 |
10 | /**
11 | * 获得状态栏的高度
12 | *
13 | * @param context
14 | * @return px
15 | */
16 | public static int getStatusHeight(Context context) {
17 |
18 | int statusHeight = -1;
19 | try {
20 | Class> clazz = Class.forName("com.android.internal.R$dimen");
21 | Object object = clazz.newInstance();
22 | int height = Integer.parseInt(clazz.getField("status_bar_height").get(object).toString());
23 | statusHeight = context.getResources().getDimensionPixelSize(height);
24 | } catch (Exception e) {
25 | e.printStackTrace();
26 | }
27 | return statusHeight;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/fuzhucheng/rxjavartrofitrecyclerview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview;
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 | * Instrumentation 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.fuzhucheng.rxjavartrofitrecyclerview", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_attention.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
14 |
15 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/bean/AbilityItem.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.bean;
2 |
3 | /**
4 | * Created by ${符柱成} on 2017/2/19.
5 | */
6 |
7 | public class AbilityItem {
8 | private String image;
9 | private String title;
10 | private String content;
11 |
12 | public String getImage() {
13 | return image;
14 | }
15 |
16 | public void setImage(String image) {
17 | this.image = image;
18 | }
19 |
20 | public String getTitle() {
21 | return title;
22 | }
23 |
24 | public void setTitle(String title) {
25 | this.title = title;
26 | }
27 |
28 | public String getContent() {
29 | return content;
30 | }
31 |
32 | public void setContent(String content) {
33 | this.content = content;
34 | }
35 |
36 | public AbilityItem(String image, String title, String content) {
37 | this.image = image;
38 | this.title = title;
39 | this.content = content;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/bean/DiscountColumnBean.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.bean;
2 |
3 | /**
4 | * Created by ${符柱成} on 2016/12/8.
5 | */
6 | public class DiscountColumnBean {
7 |
8 | private int icon;
9 | private String name;
10 | private String content;
11 |
12 | public DiscountColumnBean(int icon, String name, String content) {
13 | this.icon = icon;
14 | this.name = name;
15 | this.content = content;
16 | }
17 |
18 | public int getIcon() {
19 | return icon;
20 | }
21 |
22 | public void setIcon(int icon) {
23 | this.icon = icon;
24 | }
25 |
26 | public String getName() {
27 | return name;
28 | }
29 |
30 | public void setName(String name) {
31 | this.name = name;
32 | }
33 |
34 | public String getContent() {
35 | return content;
36 | }
37 |
38 | public void setContent(String content) {
39 | this.content = content;
40 | }
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
16 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/adapter/HomeViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.adapter;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Created by 符柱成 on 2016/12/4.
11 | */
12 | public class HomeViewPagerAdapter extends FragmentPagerAdapter {
13 |
14 | private List title;
15 | private List views;
16 |
17 | public HomeViewPagerAdapter(FragmentManager fm, List fragments, List titles ) {
18 | super(fm);
19 | this.title = titles;
20 | this.views = fragments;
21 | }
22 |
23 | @Override
24 | public Fragment getItem(int position) {
25 | return views.get(position);
26 | }
27 |
28 | @Override
29 | public int getCount() {
30 | return views.size();
31 | }
32 |
33 |
34 | //配置标题的方法
35 | @Override
36 | public CharSequence getPageTitle(int position) {
37 | return title.get(position);
38 | }
39 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #1574e7
4 | #1574e7
5 | #1574e7
6 |
7 |
8 | #1574e7
9 | #e2e2e2
10 |
11 | #999999
12 | #24C789
13 | #ecf0f3
14 |
15 | #ecf0f3
16 | #404040
17 | #BDBCBC
18 | #545069
19 | #24C789
20 |
21 | #404040
22 | #24C789
23 |
24 | #24C789
25 | #404040
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/widget/NoScrollViewPager.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.widget;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.ViewPager;
5 | import android.util.AttributeSet;
6 | import android.view.MotionEvent;
7 |
8 | /**
9 | * Created by 符柱成 on 2016/12/4.
10 | */
11 | public class NoScrollViewPager extends ViewPager {
12 |
13 | public NoScrollViewPager(Context context, AttributeSet attrs) {
14 | super(context, attrs);
15 | }
16 |
17 | public NoScrollViewPager(Context context) {
18 | super(context);
19 | }
20 |
21 |
22 | @Override
23 | public void scrollTo(int x, int y) {
24 | super.scrollTo(x, y);
25 | }
26 |
27 | @Override
28 | public boolean onTouchEvent(MotionEvent arg0) {
29 | return false;
30 | }
31 |
32 | @Override
33 | public boolean onInterceptTouchEvent(MotionEvent arg0) {
34 | return false;
35 | }
36 |
37 | @Override
38 | public void setCurrentItem(int item, boolean smoothScroll) {
39 | super.setCurrentItem(item, smoothScroll);
40 | }
41 |
42 | @Override
43 | public void setCurrentItem(int item) {
44 | super.setCurrentItem(item);
45 | }
46 |
47 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/activity/base/ToolbarActivity.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.activity.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.widget.Toolbar;
6 | import android.view.View;
7 | import android.widget.TextView;
8 |
9 | import com.fuzhucheng.rxjavartrofitrecyclerview.R;
10 |
11 | import butterknife.BindView;
12 |
13 | /**
14 | * Created by 符柱成 on 2016/12/2.
15 | */
16 | public abstract class ToolbarActivity extends BaseActivity {
17 |
18 | @BindView(R.id.toolbar)
19 | Toolbar toolbar;
20 | @BindView(R.id.title)
21 | public TextView title;
22 |
23 |
24 |
25 | @Override
26 | protected void onCreate(@Nullable Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 |
29 | toolbar.setTitle("");
30 | setSupportActionBar(toolbar);
31 | if (getSupportActionBar() != null) {
32 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
33 | }
34 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
35 | @Override
36 | public void onClick(View v) {
37 | finish();
38 | }
39 | });
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_discovery.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
18 |
19 |
20 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/fragment/ArenaFragment.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.fragment;
2 |
3 | import android.view.View;
4 | import android.widget.LinearLayout;
5 |
6 | import com.fuzhucheng.rxjavartrofitrecyclerview.R;
7 | import com.fuzhucheng.rxjavartrofitrecyclerview.fragment.base.BaseFragment;
8 |
9 | import butterknife.BindView;
10 | import butterknife.OnClick;
11 |
12 | /**
13 | * Created by 符柱成 on 2016/12/3.
14 | */
15 | public class ArenaFragment extends BaseFragment {
16 |
17 | @BindView(R.id.get_on_list)
18 | LinearLayout getOnList;
19 | @BindView(R.id.lang_ya)
20 | LinearLayout langYa;
21 | @BindView(R.id.choose)
22 | LinearLayout choose;
23 |
24 | @Override
25 | protected void initEvent() {
26 |
27 | }
28 |
29 | @Override
30 | protected void loadData() {
31 |
32 | }
33 |
34 | @Override
35 | protected void initView() {
36 |
37 | }
38 |
39 | @Override
40 | protected int getLayoutId() {
41 | return R.layout.fragment_arena;
42 | }
43 |
44 |
45 |
46 | @OnClick({R.id.get_on_list, R.id.lang_ya, R.id.choose})
47 | public void onClick(View view) {
48 | switch (view.getId()) {
49 | case R.id.get_on_list:
50 | // startActivity(new Intent(getActivity(), GetOnListActivity.class));
51 | break;
52 |
53 | case R.id.lang_ya:
54 | // startActivity(new Intent(getActivity(), LangYaActivity.class));
55 | break;
56 |
57 | case R.id.choose:
58 | // startActivity(new Intent(getActivity(), ChooseActivity.class));
59 | break;
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/widget/MyNestedScrollView.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.widget;
2 |
3 | import android.content.Context;
4 | import android.support.v4.widget.NestedScrollView;
5 | import android.util.AttributeSet;
6 | import android.view.MotionEvent;
7 | import android.view.ViewConfiguration;
8 |
9 | /**
10 | * Created by 符柱成 on 2016/12/24.
11 | */
12 | public class MyNestedScrollView extends NestedScrollView {
13 | private int downX;
14 | private int downY;
15 | private int mTouchSlop;
16 |
17 | public MyNestedScrollView(Context context) {
18 | super(context);
19 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
20 | }
21 |
22 | public MyNestedScrollView(Context context, AttributeSet attrs) {
23 | super(context, attrs);
24 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
25 | }
26 |
27 | public MyNestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
28 | super(context, attrs, defStyleAttr);
29 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
30 | }
31 |
32 | @Override
33 | public boolean onInterceptTouchEvent(MotionEvent e) {
34 | int action = e.getAction();
35 | switch (action) {
36 | case MotionEvent.ACTION_DOWN:
37 | downX = (int) e.getRawX();
38 | downY = (int) e.getRawY();
39 | break;
40 | case MotionEvent.ACTION_MOVE:
41 | int moveY = (int) e.getRawY();
42 | if (Math.abs(moveY - downY) > mTouchSlop) {
43 | return true;
44 | }
45 | }
46 | return super.onInterceptTouchEvent(e);
47 | }
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/fragment/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.fragment.base;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import butterknife.ButterKnife;
12 |
13 | /**
14 | * Created by 符柱成 on 2016/12/2.
15 | */
16 | public abstract class BaseFragment extends Fragment {
17 | private Handler handler = new Handler();
18 | private Runnable loadDataTask = new Runnable() {
19 | @Override
20 | public void run() {
21 | loadData();
22 | }
23 | };
24 | @Nullable
25 | @Override
26 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
27 | View view = inflater.inflate(getLayoutId(), container, false);
28 | ButterKnife.bind(this, view);
29 | return view;
30 | }
31 |
32 | @Override
33 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
34 | initView();
35 | initEvent();
36 | // 延迟加载数据,减少卡顿
37 | handler.postDelayed(loadDataTask, 500);
38 | }
39 | @Override
40 | public void setUserVisibleHint(boolean isVisibleToUser) {
41 | super.setUserVisibleHint(isVisibleToUser);
42 | if (!isVisibleToUser) {
43 | handler.removeCallbacks(loadDataTask);
44 | }
45 | }
46 |
47 | protected abstract void initView();
48 |
49 | protected abstract void initEvent();
50 |
51 | protected abstract void loadData();
52 |
53 | protected abstract int getLayoutId();
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
15 |
16 |
21 |
22 |
26 |
27 |
35 |
36 |
37 |
38 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_ability1.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
19 |
20 |
26 |
27 |
32 |
33 |
34 |
35 |
36 |
37 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_fragment_attention_recyclerview.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
21 |
22 |
28 |
29 |
33 |
34 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_fragment_ability_recyclerview.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
21 |
22 |
27 |
28 |
34 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/utils/NetUtil.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.utils;
2 |
3 | import android.app.Activity;
4 | import android.content.ComponentName;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.net.ConnectivityManager;
8 | import android.net.NetworkInfo;
9 |
10 | /**
11 | * Created by 符柱成 on 2017/1/10.
12 | */
13 |
14 | public class NetUtil {
15 | private NetUtil()
16 | {
17 | /* cannot be instantiated */
18 | throw new UnsupportedOperationException("cannot be instantiated");
19 | }
20 |
21 | /**
22 | * 判断网络是否连接
23 | *
24 | * @param context
25 | * @return
26 | */
27 | public static boolean isConnected(Context context)
28 | {
29 |
30 | ConnectivityManager connectivity = (ConnectivityManager) context
31 | .getSystemService(Context.CONNECTIVITY_SERVICE);
32 |
33 | if (null != connectivity)
34 | {
35 |
36 | NetworkInfo info = connectivity.getActiveNetworkInfo();
37 | if (null != info && info.isConnected())
38 | {
39 | if (info.getState() == NetworkInfo.State.CONNECTED)
40 | {
41 | return true;
42 | }
43 | }
44 | }
45 | return false;
46 | }
47 |
48 | /**
49 | * 判断是否是wifi连接
50 | */
51 | public static boolean isWifi(Context context)
52 | {
53 | ConnectivityManager cm = (ConnectivityManager) context
54 | .getSystemService(Context.CONNECTIVITY_SERVICE);
55 |
56 | if (cm == null)
57 | return false;
58 | return cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI;
59 |
60 | }
61 |
62 | /**
63 | * 打开网络设置界面
64 | */
65 | public static void openSetting(Activity activity)
66 | {
67 | Intent intent = new Intent("/");
68 | ComponentName cm = new ComponentName("com.android.settings",
69 | "com.android.settings.WirelessSettings");
70 | intent.setComponent(cm);
71 | intent.setAction("android.intent.action.VIEW");
72 | activity.startActivityForResult(intent, 0);
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/activity/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.activity.base;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 |
8 | import com.orhanobut.logger.Logger;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | import butterknife.ButterKnife;
14 |
15 | /**
16 | * Created by 符柱成 on 2016/12/2.
17 | */
18 | public abstract class BaseActivity extends AppCompatActivity {
19 |
20 | private static List activities = new ArrayList<>();
21 |
22 | @Override
23 | protected void onCreate(@Nullable Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | Logger.i("Activity--->" + getClass().getSimpleName());
26 | addActivity(this);
27 |
28 | if (getLayoutId() != 0) {
29 | setContentView(getLayoutId());
30 | } else {
31 | throw new IllegalArgumentException("返回一个正确的ContentView");
32 | }
33 | ButterKnife.bind(this);
34 |
35 | initView();
36 | initEvent();
37 | loadData();
38 | }
39 |
40 | protected abstract int getLayoutId();
41 |
42 | protected abstract void initView();
43 |
44 | protected abstract void initEvent();
45 |
46 | protected abstract void loadData();
47 |
48 | @Override
49 | protected void onPause() {
50 | super.onPause();
51 | removeActivity(this);
52 | }
53 |
54 |
55 | // 添加Activity到容器中
56 | private void addActivity(Activity activity) {
57 | if (activity != null && !activities.contains(activity)) {
58 | activities.add(activity);
59 | }
60 | }
61 |
62 | private void removeActivity(Activity activity) {
63 | if (activity != null && activities.contains(activity)) {
64 | activities.remove(activity);
65 | }
66 | }
67 |
68 | // 退出整个APP
69 | public static void exit() {
70 | if (activities != null && activities.size() > 0) {
71 | for (Activity activity : activities) {
72 | activity.finish();
73 | }
74 | }
75 | System.exit(0);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/.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 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/fragment/base/RecyclerViewFragment.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.fragment.base;
2 |
3 | import android.os.Handler;
4 | import android.os.Message;
5 | import android.support.v4.widget.SwipeRefreshLayout;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.widget.LinearLayout;
8 |
9 | import com.fuzhucheng.rxjavartrofitrecyclerview.R;
10 | import com.fuzhucheng.rxjavartrofitrecyclerview.widget.FullyLinearLayoutManager;
11 |
12 | import butterknife.BindView;
13 |
14 | /**
15 | * Created by ${符柱成} on 2017/1/12.
16 | */
17 |
18 | public abstract class RecyclerViewFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener {
19 |
20 | protected static final int REFRESH = 0x101;
21 | @BindView(R.id.recycler_view)
22 | RecyclerView recyclerView;
23 | @BindView(R.id.swipeRefreshLayout)
24 | SwipeRefreshLayout swipeRefreshLayout;
25 | protected RecyclerView.Adapter adapter;
26 |
27 | private Handler handler = new Handler() {
28 | @Override
29 | public void handleMessage(Message msg) {
30 | switch (msg.what) {
31 | case REFRESH:
32 | swipeRefreshLayout.setRefreshing(false);
33 | break;
34 | }
35 | }
36 | };
37 |
38 |
39 | @Override
40 | protected void initView() {
41 | FullyLinearLayoutManager layoutManager = new FullyLinearLayoutManager(getActivity(), LinearLayout.VERTICAL, false);
42 | layoutManager.setSmoothScrollbarEnabled(true);
43 | recyclerView.setLayoutManager(layoutManager);
44 | recyclerView.setNestedScrollingEnabled(false);
45 |
46 |
47 | swipeRefreshLayout.setSize(SwipeRefreshLayout.LARGE);
48 | swipeRefreshLayout.setColorSchemeResources(R.color.colorArenaGreen, R.color.colorAccent, R.color.colorMainDividerLine);
49 |
50 | }
51 | @Override
52 | protected void initEvent() {
53 | swipeRefreshLayout.setOnRefreshListener(this);
54 | }
55 |
56 | @Override
57 | protected void loadData(){
58 | adapterBuilder();
59 | recyclerView.setAdapter(adapter);
60 | }
61 | //子activity设置适配器
62 | protected abstract void adapterBuilder();
63 | @Override
64 | public void onRefresh() {
65 | //todo 网络请求任务
66 | handler.sendEmptyMessageDelayed(REFRESH, 3000);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_arena.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
20 |
21 |
22 |
23 |
29 |
30 |
31 |
40 |
41 |
42 |
48 |
49 |
50 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 | defaultConfig {
7 | applicationId "com.fuzhucheng.rxjavartrofitrecyclerview"
8 | minSdkVersion 15
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | testCompile 'junit:junit:4.12'
28 | compile 'com.android.support:appcompat-v7:23.4.0'
29 | compile 'com.android.support:support-v4:23.4.0'
30 | //material design
31 | compile 'com.android.support:design:23.4.0'
32 | // 多dex
33 | compile 'com.android.support:multidex:1.0.1'
34 | // https://github.com/orhanobut/logger
35 | compile 'com.orhanobut:logger:1.15'
36 | // https://github.com/ReactiveX/RxAndroid rx异步
37 | compile 'io.reactivex:rxandroid:1.2.1'
38 | compile 'io.reactivex:rxjava:1.1.6'
39 | // https://github.com/square/retrofit 网络请求
40 | compile 'com.squareup.retrofit2:retrofit:2.1.0'
41 | compile 'com.squareup.retrofit2:converter-gson:2.1.0'
42 | compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
43 | //https://github.com/franmontiel/PersistentCookieJar Okhttp的Cookie缓存
44 | compile 'com.github.franmontiel:PersistentCookieJar:v1.0.0'
45 | // https://github.com/hongyangAndroid/baseAdapter 通用adapter
46 | compile 'com.zhy:base-rvadapter:3.0.3'
47 | // https://github.com/JakeWharton/butterknife
48 | compile 'com.jakewharton:butterknife:8.4.0'
49 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
50 | // https://github.com/hdodenhof/CircleImageView 圆形头像
51 | compile 'de.hdodenhof:circleimageview:2.1.0'
52 | // https://github.com/saiwu-bigkoo/Android-ConvenientBanner 轮播图
53 | compile 'com.bigkoo:convenientbanner:2.0.5'
54 | //图片框架
55 | compile 'com.github.bumptech.glide:glide:3.7.0'
56 | // https://github.com/Lester-lin/AutoScrollTextView
57 | compile 'com.lester:scolltextview:1.0.0'
58 | //cardView
59 | compile 'com.android.support:cardview-v7:23.4.0'
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/fragment/base/BannerFragment.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.fragment.base;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.widget.ImageView;
6 |
7 | import com.bigkoo.convenientbanner.ConvenientBanner;
8 | import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
9 | import com.bigkoo.convenientbanner.holder.Holder;
10 | import com.bigkoo.convenientbanner.listener.OnItemClickListener;
11 | import com.bumptech.glide.Glide;
12 | import com.fuzhucheng.rxjavartrofitrecyclerview.R;
13 |
14 | import java.util.List;
15 |
16 | import butterknife.BindView;
17 |
18 | /**
19 | * Created by 符柱成 on 2016/12/2.
20 | */
21 | public abstract class BannerFragment extends RecyclerViewFragment implements OnItemClickListener {
22 |
23 | private static final long LOOP_TIME = 5000;
24 |
25 | @BindView(R.id.banner)
26 | ConvenientBanner convenientBanner;
27 |
28 | protected abstract List getBitmapList();
29 | protected void loadConvenientBanner() {
30 | convenientBanner.setPages(new CBViewHolderCreator() {
31 | @Override
32 | public LocalImageHolderView createHolder() {
33 | return new LocalImageHolderView();
34 | }
35 | }, getBitmapList())
36 | .setPageIndicator(new int[]{R.drawable.page_indicator, R.drawable.page_indicator_focused})
37 | .setOnItemClickListener(this);
38 | convenientBanner.startTurning(LOOP_TIME);
39 | }
40 |
41 | @Override
42 | protected void initView() {
43 | super.initView();
44 | convenientBanner.setPages(new CBViewHolderCreator() {
45 | @Override
46 | public LocalImageHolderView createHolder() {
47 | return new LocalImageHolderView();
48 | }
49 | }, getBitmapList())
50 | .setPageIndicator(new int[]{R.drawable.page_indicator, R.drawable.page_indicator_focused})
51 | .setOnItemClickListener(this);
52 | convenientBanner.startTurning(LOOP_TIME);
53 | }
54 |
55 | @Override
56 | protected void loadData(){
57 | super.loadData();
58 | }
59 | public class LocalImageHolderView implements Holder {
60 | private ImageView imageView;
61 |
62 | @Override
63 | public View createView(Context context) {
64 | imageView = new ImageView(context);
65 | imageView.setScaleType(ImageView.ScaleType.FIT_XY);
66 | return imageView;
67 | }
68 |
69 | @Override
70 | public void UpdateUI(Context context, final int position, String data) {
71 | Glide.with(context).load(data).into(imageView);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/bean/AbilityBean.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.bean;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by 符柱成 on 2016/12/14.
7 | */
8 | public class AbilityBean {
9 |
10 | public int image;
11 | public String place;
12 | public int like;
13 | public int price;
14 |
15 |
16 | public int count;
17 | public int start;
18 | public int total;
19 | public String title;
20 | public List subjects;
21 |
22 | public AbilityBean(int image, String place, int like, int price) {
23 | this.image = image;
24 | this.place = place;
25 | this.like = like;
26 | this.price = price;
27 | }
28 |
29 |
30 | public static class SubjectsEntity {
31 |
32 | public RatingEntity rating;
33 | public String title;
34 | public int collect_count;
35 | public String original_title;
36 | public String subtype;
37 | public String year;
38 | public RatingEntity.ImagesEntity images;
39 | public String alt;
40 | public String id;
41 | public List genres;
42 | public List casts;
43 | public List directors;
44 |
45 |
46 | public static class RatingEntity {
47 |
48 |
49 | public int max;
50 | public double average;
51 | public String stars;
52 | public int min;
53 |
54 |
55 | public static class ImagesEntity {
56 |
57 | public String small;
58 | public String large;
59 | public String medium;
60 |
61 |
62 | }
63 |
64 | public static class CastsEntity {
65 |
66 |
67 | public String alt;
68 | public AvatarsEntity avatars;
69 | public String name;
70 | public String id;
71 |
72 |
73 | public static class AvatarsEntity {
74 |
75 |
76 | public String small;
77 | public String large;
78 | public String medium;
79 |
80 |
81 | }
82 | }
83 |
84 | public static class DirectorsEntity {
85 |
86 |
87 | public String alt;
88 | public AvatarsEntityX avatars;
89 | public String name;
90 | public String id;
91 |
92 |
93 | public static class AvatarsEntityX {
94 |
95 |
96 | public String small;
97 | public String large;
98 | public String medium;
99 |
100 |
101 | }
102 | }
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/activity/base/DrawerActivity.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.activity.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.design.widget.NavigationView;
6 | import android.support.v4.widget.DrawerLayout;
7 | import android.support.v7.app.ActionBarDrawerToggle;
8 | import android.view.Gravity;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 |
12 | import com.fuzhucheng.rxjavartrofitrecyclerview.R;
13 |
14 | import butterknife.BindView;
15 |
16 | /**
17 | * Created by 符柱成 on 2016/12/2.
18 | */
19 | public abstract class DrawerActivity extends ToolbarActivity implements NavigationView.OnNavigationItemSelectedListener {
20 |
21 | @BindView(R.id.navigation_view)
22 | NavigationView navigationView;
23 | @BindView(R.id.drawer_layout)
24 | DrawerLayout drawerLayout;
25 |
26 | @Override
27 | protected void onCreate(@Nullable Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 |
30 | ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close);
31 | drawerToggle.syncState();
32 | drawerLayout.setDrawerListener(drawerToggle);
33 |
34 | drawerToggle.setDrawerIndicatorEnabled(false);
35 | toolbar.setNavigationIcon(R.drawable.toolbar_navigation);
36 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
37 | @Override
38 | public void onClick(View v) {
39 | drawerLayout.openDrawer(Gravity.LEFT);
40 | }
41 | });
42 | navigationView.setNavigationItemSelectedListener(this);
43 |
44 |
45 | }
46 | @Override
47 | public boolean onNavigationItemSelected(MenuItem item) {
48 | switch (item.getItemId()) {
49 |
50 | case R.id.publish:
51 | // startActivity(new Intent(this, PublishActivity.class));
52 | drawerLayout.closeDrawers();
53 | return true;
54 |
55 | case R.id.published:
56 | // startActivity(new Intent(this, PublishedActivity.class));
57 | drawerLayout.closeDrawers();
58 | return true;
59 |
60 | case R.id.growth:
61 | // startActivity(new Intent(this, GrowthActivity.class));
62 | drawerLayout.closeDrawers();
63 | break;
64 |
65 | case R.id.collect:
66 | // startActivity(new Intent(this, CollectionActivity.class));
67 | drawerLayout.closeDrawers();
68 | return true;
69 |
70 | // 设置
71 | case R.id.setting:
72 | // startActivity(new Intent(this, SettingActivity.class));
73 | drawerLayout.closeDrawers();
74 | return true;
75 | }
76 | return super.onContextItemSelected(item);
77 | }
78 |
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.activity;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.drawable.Drawable;
6 | import android.net.Uri;
7 | import android.os.Build;
8 | import android.os.PowerManager;
9 | import android.support.design.widget.TabLayout;
10 | import android.support.v4.app.Fragment;
11 | import android.support.v4.content.ContextCompat;
12 |
13 | import com.fuzhucheng.rxjavartrofitrecyclerview.R;
14 | import com.fuzhucheng.rxjavartrofitrecyclerview.activity.base.DrawerActivity;
15 | import com.fuzhucheng.rxjavartrofitrecyclerview.adapter.ViewPagerAdapter;
16 | import com.fuzhucheng.rxjavartrofitrecyclerview.fragment.AbilityFragment;
17 | import com.fuzhucheng.rxjavartrofitrecyclerview.fragment.ArenaFragment;
18 | import com.fuzhucheng.rxjavartrofitrecyclerview.fragment.AttentionFragment;
19 | import com.fuzhucheng.rxjavartrofitrecyclerview.fragment.DiscoveryFragment;
20 | import com.fuzhucheng.rxjavartrofitrecyclerview.widget.NoScrollViewPager;
21 |
22 | import java.util.ArrayList;
23 | import java.util.List;
24 |
25 | import butterknife.BindView;
26 |
27 | public class MainActivity extends DrawerActivity {
28 | private static final int PAGE_LIMIT = 4;
29 | @BindView(R.id.tab_layout)
30 | TabLayout tabLayout;
31 | @BindView(R.id.viewpager)
32 | NoScrollViewPager viewPager;
33 |
34 |
35 | @Override
36 | protected int getLayoutId() {
37 | return R.layout.activity_main;
38 | }
39 |
40 | @Override
41 | protected void initView() {
42 |
43 | }
44 |
45 | @Override
46 | protected void initEvent() {
47 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
48 | String packageName = getPackageName();
49 | PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
50 | if (!pm.isIgnoringBatteryOptimizations(packageName)) {
51 | Intent intent = new Intent();
52 | intent.setAction(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
53 | intent.setData(Uri.parse("package:" + packageName));
54 | startActivity(intent);
55 | }
56 | }
57 | }
58 |
59 | @Override
60 | protected void loadData() {
61 | List fragments = new ArrayList<>();
62 | fragments.add(new AbilityFragment());
63 | fragments.add(new AttentionFragment());
64 | fragments.add(new DiscoveryFragment());
65 | fragments.add(new ArenaFragment());
66 | ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager(), fragments);
67 | viewPager.setAdapter(adapter);
68 | viewPager.setOffscreenPageLimit(PAGE_LIMIT);
69 | tabLayout.setupWithViewPager(viewPager);
70 | for (int i = 0; i < tabLayout.getTabCount(); i++) {
71 | TabLayout.Tab tab = tabLayout.getTabAt(i);
72 | Drawable drawable = null;
73 | switch (i) {
74 | case 0:
75 | drawable = ContextCompat.getDrawable(this, R.drawable.tab_item_home);
76 | break;
77 | case 1:
78 | drawable = ContextCompat.getDrawable(this, R.drawable.tab_item_attention);
79 | break;
80 | case 2:
81 | drawable = ContextCompat.getDrawable(this, R.drawable.tab_item_discovery);
82 | break;
83 | case 3:
84 | drawable = ContextCompat.getDrawable(this, R.drawable.tab_item_arena);
85 | break;
86 | }
87 | if (tab != null) {
88 | tab.setIcon(drawable);
89 | }
90 | }
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/widget/FullyLinearLayoutManager.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.widget;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.LinearLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | /**
11 | * Created by 符柱成 on 2016/12/24.
12 | */
13 | public class FullyLinearLayoutManager extends LinearLayoutManager {
14 |
15 | private static final String TAG = FullyLinearLayoutManager.class.getSimpleName();
16 |
17 | public FullyLinearLayoutManager(Context context) {
18 | super(context);
19 | }
20 |
21 | public FullyLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
22 | super(context, orientation, reverseLayout);
23 | }
24 |
25 | private int[] mMeasuredDimension = new int[2];
26 |
27 | @Override
28 | public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state,
29 | int widthSpec, int heightSpec) {
30 |
31 | final int widthMode = View.MeasureSpec.getMode(widthSpec);
32 | final int heightMode = View.MeasureSpec.getMode(heightSpec);
33 | final int widthSize = View.MeasureSpec.getSize(widthSpec);
34 | final int heightSize = View.MeasureSpec.getSize(heightSpec);
35 |
36 | Log.i(TAG, "onMeasure called. \nwidthMode " + widthMode
37 | + " \nheightMode " + heightSpec
38 | + " \nwidthSize " + widthSize
39 | + " \nheightSize " + heightSize
40 | + " \ngetItemCount() " + getItemCount());
41 |
42 | int width = 0;
43 | int height = 0;
44 | for (int i = 0; i < getItemCount(); i++) {
45 | measureScrapChild(recycler, i,
46 | View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
47 | View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
48 | mMeasuredDimension);
49 |
50 | if (getOrientation() == HORIZONTAL) {
51 | width = width + mMeasuredDimension[0];
52 | if (i == 0) {
53 | height = mMeasuredDimension[1];
54 | }
55 | } else {
56 | height = height + mMeasuredDimension[1];
57 | if (i == 0) {
58 | width = mMeasuredDimension[0];
59 | }
60 | }
61 | }
62 | switch (widthMode) {
63 | case View.MeasureSpec.EXACTLY:
64 | width = widthSize;
65 | case View.MeasureSpec.AT_MOST:
66 | case View.MeasureSpec.UNSPECIFIED:
67 | }
68 |
69 | switch (heightMode) {
70 | case View.MeasureSpec.EXACTLY:
71 | height = heightSize;
72 | case View.MeasureSpec.AT_MOST:
73 | case View.MeasureSpec.UNSPECIFIED:
74 | }
75 |
76 | setMeasuredDimension(width, height);
77 | }
78 |
79 | private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
80 | int heightSpec, int[] measuredDimension) {
81 | try {
82 | View view = recycler.getViewForPosition(0);//fix 动态添加时报IndexOutOfBoundsException
83 |
84 | if (view != null) {
85 | RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();
86 |
87 | int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec,
88 | getPaddingLeft() + getPaddingRight(), p.width);
89 |
90 | int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec,
91 | getPaddingTop() + getPaddingBottom(), p.height);
92 |
93 | view.measure(childWidthSpec, childHeightSpec);
94 | measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
95 | measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;
96 | recycler.recycleView(view);
97 | }
98 | } catch (Exception e) {
99 | e.printStackTrace();
100 | } finally {
101 | }
102 | }
103 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/fragment/AttentionFragment.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.fragment;
2 |
3 | import android.support.v4.widget.SwipeRefreshLayout;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.widget.ImageView;
6 |
7 | import com.bumptech.glide.Glide;
8 | import com.fuzhucheng.rxjavartrofitrecyclerview.R;
9 | import com.fuzhucheng.rxjavartrofitrecyclerview.bean.AbilityBean;
10 | import com.fuzhucheng.rxjavartrofitrecyclerview.bean.AttentionBean;
11 | import com.fuzhucheng.rxjavartrofitrecyclerview.fragment.base.RecyclerViewFragment;
12 | import com.fuzhucheng.rxjavartrofitrecyclerview.requests.MovieRequest;
13 | import com.fuzhucheng.rxjavartrofitrecyclerview.utils.RetrofitUtil;
14 | import com.fuzhucheng.rxjavartrofitrecyclerview.utils.ToastUtils;
15 | import com.zhy.adapter.recyclerview.CommonAdapter;
16 | import com.zhy.adapter.recyclerview.base.ViewHolder;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | import butterknife.BindView;
22 | import rx.Subscriber;
23 | import rx.android.schedulers.AndroidSchedulers;
24 | import rx.schedulers.Schedulers;
25 |
26 | /**
27 | * Created by 符柱成 on 2016/12/3.
28 | */
29 | public class AttentionFragment extends RecyclerViewFragment {
30 | @BindView(R.id.recycler_view)
31 | RecyclerView recyclerView;
32 | @BindView(R.id.swipeRefreshLayout)
33 | SwipeRefreshLayout swipeRefreshLayout;
34 |
35 | private CommonAdapter adapter;
36 | private MovieRequest movieRequest;
37 |
38 | private List datas = new ArrayList<>();
39 |
40 | @Override
41 | protected void initView() {
42 | super.initView();
43 | }
44 |
45 | @Override
46 | protected void initEvent() {
47 | super.initEvent();
48 | }
49 |
50 | @Override
51 | protected void loadData() {
52 | getMovie();
53 | }
54 | private void getMovie() {
55 | movieRequest = RetrofitUtil.getInstance().create(MovieRequest.class);
56 | movieRequest.getMovies(0, 10)
57 | .subscribeOn(Schedulers.io())
58 | .unsubscribeOn(Schedulers.io())
59 | .observeOn(AndroidSchedulers.mainThread())
60 | .subscribe(new Subscriber() {
61 | @Override
62 | public void onCompleted() {
63 |
64 | }
65 |
66 | @Override
67 | public void onError(Throwable e) {
68 | ToastUtils.showToast(getActivity(), getString(R.string.request_error));
69 | }
70 |
71 | @Override
72 | public void onNext(AbilityBean abilityBean) {
73 | swipeRefreshLayout.setRefreshing(false);
74 | datas.clear();
75 | ToastUtils.showToast(getActivity(), getString(R.string.request_success));
76 | for (int i = 0; i < abilityBean.subjects.size(); i++) {
77 | datas.add(new AttentionBean(abilityBean.subjects.get(i).images.small, abilityBean.subjects.get(i).original_title));
78 | }
79 |
80 | adapter = new CommonAdapter(getActivity(), R.layout.item_fragment_attention_recyclerview, datas) {
81 | @Override
82 | protected void convert(ViewHolder holder, final AttentionBean attentionBean, final int position) {
83 |
84 | holder.setText(R.id.tx_attention_title, attentionBean.getTitle());
85 | ImageView circleImageView = holder.getView(R.id.img_attention);
86 | Glide.with(getActivity()).load(attentionBean.getIcon()).into(circleImageView);
87 | }
88 | };
89 | recyclerView.setAdapter(adapter);
90 | }
91 | });
92 | }
93 | @Override
94 | protected void adapterBuilder() {
95 |
96 | }
97 | @Override
98 | public void onRefresh() {
99 | super.onRefresh();
100 | getMovie();
101 | }
102 | @Override
103 | protected int getLayoutId() {
104 | return R.layout.fragment_attention;
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/fragment/DiscoveryFragment.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.fragment;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.widget.ImageView;
5 | import android.widget.LinearLayout;
6 |
7 | import com.bumptech.glide.Glide;
8 | import com.fuzhucheng.rxjavartrofitrecyclerview.R;
9 | import com.fuzhucheng.rxjavartrofitrecyclerview.bean.AbilityBean;
10 | import com.fuzhucheng.rxjavartrofitrecyclerview.bean.HotColumnBean;
11 | import com.fuzhucheng.rxjavartrofitrecyclerview.fragment.base.BaseFragment;
12 | import com.fuzhucheng.rxjavartrofitrecyclerview.requests.MovieRequest;
13 | import com.fuzhucheng.rxjavartrofitrecyclerview.utils.RetrofitUtil;
14 | import com.fuzhucheng.rxjavartrofitrecyclerview.utils.ToastUtils;
15 | import com.fuzhucheng.rxjavartrofitrecyclerview.widget.FullyLinearLayoutManager;
16 | import com.zhy.adapter.recyclerview.CommonAdapter;
17 | import com.zhy.adapter.recyclerview.base.ViewHolder;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import butterknife.BindView;
23 | import rx.Subscriber;
24 | import rx.android.schedulers.AndroidSchedulers;
25 | import rx.schedulers.Schedulers;
26 |
27 | /**
28 | * Created by 符柱成 on 2016/12/3.
29 | */
30 | public class DiscoveryFragment extends BaseFragment {
31 |
32 | @BindView(R.id.hot_column_recycler_view)
33 | RecyclerView hotColumnRecyclerView;
34 |
35 | private List hotColumnDatas = new ArrayList<>();
36 | private CommonAdapter hotColumnAdapter;
37 | private MovieRequest movieRequest;
38 |
39 | @Override
40 | protected void initView() {
41 | FullyLinearLayoutManager layoutManager = new FullyLinearLayoutManager(getActivity(), LinearLayout.HORIZONTAL, false);
42 | layoutManager.setSmoothScrollbarEnabled(true);
43 |
44 | hotColumnRecyclerView.setLayoutManager(layoutManager);
45 | hotColumnRecyclerView.setNestedScrollingEnabled(false);
46 |
47 | }
48 |
49 | @Override
50 | protected void initEvent() {
51 |
52 | }
53 |
54 | @Override
55 | protected void loadData() {
56 | getMovie();
57 | // TODO 网络加载优惠栏目图片
58 |
59 |
60 | }
61 | private void getMovie() {
62 | movieRequest = RetrofitUtil.getInstance().create(MovieRequest.class);
63 | movieRequest.getMovies(0, 10)
64 | .subscribeOn(Schedulers.io())
65 | .unsubscribeOn(Schedulers.io())
66 | .observeOn(AndroidSchedulers.mainThread())
67 | .subscribe(new Subscriber() {
68 | @Override
69 | public void onCompleted() {
70 |
71 | }
72 |
73 | @Override
74 | public void onError(Throwable e) {
75 | ToastUtils.showToast(getActivity(), getString(R.string.request_error));
76 | }
77 |
78 | @Override
79 | public void onNext(AbilityBean abilityBean) {
80 | hotColumnDatas.clear();
81 | ToastUtils.showToast(getActivity(), getString(R.string.request_success));
82 | for (int i = 0; i < abilityBean.subjects.size(); i++) {
83 | hotColumnDatas.add(new HotColumnBean(abilityBean.subjects.get(i).casts.get(1).avatars.medium));
84 | }
85 |
86 | hotColumnAdapter = new CommonAdapter(getActivity(), R.layout.item_fragment_discovery_hot_column, hotColumnDatas) {
87 | @Override
88 | protected void convert(ViewHolder holder, final HotColumnBean hotColumnBean, final int position) {
89 |
90 | ImageView circleImageView = holder.getView(R.id.fragment_discovery_gallery_Image);
91 | Glide.with(getActivity()).load(hotColumnBean.getImage()).into(circleImageView);
92 | }
93 | };
94 | hotColumnRecyclerView.setAdapter(hotColumnAdapter);
95 | }
96 | });
97 | }
98 |
99 |
100 | @Override
101 | protected int getLayoutId() {
102 | return R.layout.fragment_discovery;
103 | }
104 |
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/utils/RetrofitUtil.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.utils;
2 |
3 | import com.franmontiel.persistentcookiejar.ClearableCookieJar;
4 | import com.franmontiel.persistentcookiejar.PersistentCookieJar;
5 | import com.franmontiel.persistentcookiejar.cache.SetCookieCache;
6 | import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor;
7 | import com.fuzhucheng.rxjavartrofitrecyclerview.App;
8 | import com.orhanobut.logger.Logger;
9 |
10 | import java.io.File;
11 | import java.io.IOException;
12 | import java.util.concurrent.TimeUnit;
13 |
14 | import okhttp3.Cache;
15 | import okhttp3.CacheControl;
16 | import okhttp3.Interceptor;
17 | import okhttp3.OkHttpClient;
18 | import okhttp3.Request;
19 | import okhttp3.Response;
20 | import retrofit2.Retrofit;
21 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
22 | import retrofit2.converter.gson.GsonConverterFactory;
23 |
24 | /**
25 | * Created by 符柱成 on 2017/1/8.
26 | */
27 |
28 | public class RetrofitUtil {
29 | private static final String TAG = "retrofit";
30 | //TODO:修改主机地址
31 | private static final String BASE_URL = "https://api.douban.com";
32 | private static final int DEFAULT_TIMEOUT = 5;
33 | private static Retrofit retrofit;
34 |
35 | //实例化私有
36 | private RetrofitUtil(){
37 |
38 | }
39 |
40 | public static Retrofit getInstance(){
41 | if(retrofit==null) {
42 | ClearableCookieJar cookieJar =
43 | new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(App.getInstance()));
44 | OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); //okhttp创建,写入缓存机制,还有addInterceptor
45 | httpClientBuilder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
46 | File cacheFile = new File(App.getInstance().getCacheDir(), "superman");
47 | Cache cache = new Cache(cacheFile, 1024 * 1024 * 100); //100Mb
48 | httpClientBuilder.cache(cache);
49 | httpClientBuilder.cookieJar(cookieJar);
50 | httpClientBuilder.addInterceptor(LoggingInterceptor);
51 | httpClientBuilder.addInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR);
52 | httpClientBuilder.addNetworkInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR);
53 |
54 | return new Retrofit.Builder() //retrofit的创建。
55 | .client(httpClientBuilder.build()) //传入okhttp
56 | .addConverterFactory(GsonConverterFactory.create()) //传入gson解析手段
57 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) //传入异步手段
58 | .baseUrl(BASE_URL) //传入服务器地址
59 | .build();
60 | }else{
61 | return retrofit;
62 | }
63 | }
64 | private static final Interceptor LoggingInterceptor = new Interceptor() {
65 | @Override
66 | public Response intercept(Chain chain) throws IOException {
67 | Request request = chain.request();
68 | long t1 = System.nanoTime();
69 | Logger.t(TAG).i(String.format("Sending request %s on %s%n%s", request.url(), chain.connection(), request.headers()));
70 | Response response = chain.proceed(request);
71 | long t2 = System.nanoTime();
72 | Logger.t(TAG).i(String.format("Received response for %s in %.1fms%n%s", response.request().url(), (t2 - t1) / 1e6d, response.headers()));
73 | return response;
74 | }
75 | };
76 | private static final Interceptor REWRITE_CACHE_CONTROL_INTERCEPTOR = new Interceptor() {
77 | @Override
78 | public Response intercept(Chain chain) throws IOException {
79 | Request request = chain.request();
80 | if(!NetUtil.isConnected(App.getInstance())){
81 | request = request.newBuilder()
82 | .cacheControl(CacheControl.FORCE_CACHE)
83 | .build();
84 | Logger.t(TAG).w("no network");
85 | }
86 | Response originalResponse = chain.proceed(request);
87 | if(NetUtil.isConnected(App.getInstance())){
88 | //有网的时候读接口上的@Headers里的配置,你可以在这里进行统一的设置
89 | String cacheControl = request.cacheControl().toString();
90 | return originalResponse.newBuilder()
91 | .header("Cache-Control", cacheControl)
92 | .removeHeader("Pragma")
93 | .build();
94 | }else{
95 | return originalResponse.newBuilder()
96 | .header("Cache-Control", "public, only-if-cached, max-stale=2419200")
97 | .removeHeader("Pragma")
98 | .build();
99 | }
100 | }
101 | };
102 | }
103 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/utils/SPUtil.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.utils;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | import com.fuzhucheng.rxjavartrofitrecyclerview.App;
7 |
8 | import java.lang.reflect.InvocationTargetException;
9 | import java.lang.reflect.Method;
10 | import java.util.Map;
11 |
12 | /**
13 | * Created by 符柱成 on 2017/1/11.
14 | */
15 |
16 | public class SPUtil {
17 | /**
18 | * 保存在手机里面的文件名
19 | */
20 | public static final String FILE_NAME = "share_data";
21 |
22 | /**
23 | * 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法
24 | *
25 | * @param key
26 | * @param object
27 | */
28 | public static void put(Context context,String key, Object object) {
29 |
30 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
31 | Context.MODE_PRIVATE);
32 | SharedPreferences.Editor editor = sp.edit();
33 |
34 | if (object instanceof String) {
35 | editor.putString(key, (String) object);
36 | } else if (object instanceof Integer) {
37 | editor.putInt(key, (Integer) object);
38 | } else if (object instanceof Boolean) {
39 | editor.putBoolean(key, (Boolean) object);
40 | } else if (object instanceof Float) {
41 | editor.putFloat(key, (Float) object);
42 | } else if (object instanceof Long) {
43 | editor.putLong(key, (Long) object);
44 | } else {
45 | editor.putString(key, object.toString());
46 | }
47 |
48 | SharedPreferencesCompat.apply(editor);
49 | }
50 |
51 | /**
52 | * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值
53 | *
54 | * @param key
55 | * @param defaultObject
56 | * @return
57 | */
58 | public static Object get(Context context,String key, Object defaultObject) {
59 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
60 | Context.MODE_PRIVATE);
61 |
62 | if (defaultObject instanceof String) {
63 | return sp.getString(key, (String) defaultObject);
64 | } else if (defaultObject instanceof Integer) {
65 | return sp.getInt(key, (Integer) defaultObject);
66 | } else if (defaultObject instanceof Boolean) {
67 | return sp.getBoolean(key, (Boolean) defaultObject);
68 | } else if (defaultObject instanceof Float) {
69 | return sp.getFloat(key, (Float) defaultObject);
70 | } else if (defaultObject instanceof Long) {
71 | return sp.getLong(key, (Long) defaultObject);
72 | }
73 |
74 | return null;
75 | }
76 |
77 | /**
78 | * 移除某个key值已经对应的值
79 | *
80 | * @param key
81 | */
82 | public static void remove(String key) {
83 | SharedPreferences sp = App.getInstance().getSharedPreferences(FILE_NAME,
84 | Context.MODE_PRIVATE);
85 | SharedPreferences.Editor editor = sp.edit();
86 | editor.remove(key);
87 | SharedPreferencesCompat.apply(editor);
88 | }
89 |
90 | /**
91 | * 清除所有数据
92 | *
93 | */
94 | public static void clear() {
95 | SharedPreferences sp = App.getInstance().getSharedPreferences(FILE_NAME,
96 | Context.MODE_PRIVATE);
97 | SharedPreferences.Editor editor = sp.edit();
98 | editor.clear();
99 | SharedPreferencesCompat.apply(editor);
100 | }
101 |
102 | /**
103 | * 查询某个key是否已经存在
104 | *
105 | * @param key
106 | * @return
107 | */
108 | public static boolean contains(String key) {
109 | SharedPreferences sp = App.getInstance().getSharedPreferences(FILE_NAME,
110 | Context.MODE_PRIVATE);
111 | return sp.contains(key);
112 | }
113 |
114 | /**
115 | * 返回所有的键值对
116 | *
117 | * @return
118 | */
119 | public static Map getAll() {
120 | SharedPreferences sp = App.getInstance().getSharedPreferences(FILE_NAME,
121 | Context.MODE_PRIVATE);
122 | return sp.getAll();
123 | }
124 |
125 | /**
126 | * 创建一个解决SharedPreferencesCompat.apply方法的一个兼容类
127 | *
128 | * @author zhy
129 | */
130 | private static class SharedPreferencesCompat {
131 | private static final Method sApplyMethod = findApplyMethod();
132 |
133 | /**
134 | * 反射查找apply的方法
135 | *
136 | * @return
137 | */
138 | @SuppressWarnings({"unchecked", "rawtypes"})
139 | private static Method findApplyMethod() {
140 | try {
141 | Class clz = SharedPreferences.Editor.class;
142 | return clz.getMethod("apply");
143 | } catch (NoSuchMethodException e) {
144 | }
145 |
146 | return null;
147 | }
148 |
149 | /**
150 | * 如果找到则使用apply执行,否则使用commit
151 | *
152 | * @param editor
153 | */
154 | public static void apply(SharedPreferences.Editor editor) {
155 | try {
156 | if (sApplyMethod != null) {
157 | sApplyMethod.invoke(editor);
158 | return;
159 | }
160 | } catch (IllegalArgumentException e) {
161 | } catch (IllegalAccessException e) {
162 | } catch (InvocationTargetException e) {
163 | }
164 | editor.commit();
165 | }
166 | }
167 |
168 | }
169 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fuzhucheng/rxjavartrofitrecyclerview/fragment/AbilityFragment.java:
--------------------------------------------------------------------------------
1 | package com.fuzhucheng.rxjavartrofitrecyclerview.fragment;
2 |
3 | import android.support.v4.widget.SwipeRefreshLayout;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.widget.ImageView;
8 | import android.widget.RatingBar;
9 |
10 | import com.bumptech.glide.Glide;
11 | import com.fuzhucheng.rxjavartrofitrecyclerview.bean.AbilityItem;
12 | import com.fuzhucheng.rxjavartrofitrecyclerview.R;
13 | import com.fuzhucheng.rxjavartrofitrecyclerview.bean.AbilityBean;
14 | import com.fuzhucheng.rxjavartrofitrecyclerview.fragment.base.BannerFragment;
15 | import com.fuzhucheng.rxjavartrofitrecyclerview.requests.MovieRequest;
16 | import com.fuzhucheng.rxjavartrofitrecyclerview.utils.RetrofitUtil;
17 | import com.fuzhucheng.rxjavartrofitrecyclerview.utils.ToastUtils;
18 | import com.zhy.adapter.recyclerview.CommonAdapter;
19 | import com.zhy.adapter.recyclerview.base.ViewHolder;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | import butterknife.BindView;
25 | import rx.Subscriber;
26 | import rx.android.schedulers.AndroidSchedulers;
27 | import rx.schedulers.Schedulers;
28 |
29 | /**
30 | * Created by 符柱成 on 2016/12/2.
31 | */
32 | public class AbilityFragment extends BannerFragment implements View.OnClickListener {
33 |
34 |
35 | @BindView(R.id.recycler_view)
36 | RecyclerView recyclerView;
37 | @BindView(R.id.swipeRefreshLayout)
38 | SwipeRefreshLayout swipeRefreshLayout;
39 |
40 | private List datas = new ArrayList<>();
41 | private CommonAdapter adapter;
42 | private MovieRequest movieRequest;
43 |
44 | private RatingBar ratingBar;
45 |
46 |
47 | private List bitmapList = new ArrayList<>();
48 |
49 |
50 | @Override
51 | protected List getBitmapList() {
52 | return bitmapList;
53 | }
54 |
55 | @Override
56 | protected void initView() {
57 | LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
58 | View view = layoutInflater.inflate(R.layout.fragment_ability1, null);
59 | ratingBar = (RatingBar) view.findViewById(R.id.ratingBar);
60 | super.initView();
61 |
62 | }
63 |
64 |
65 | @Override
66 | protected void initEvent() {
67 | super.initEvent();
68 | }
69 |
70 | @Override
71 | protected void loadData() {
72 | getMovie();
73 | }
74 |
75 |
76 | private void getMovie() {
77 | movieRequest = RetrofitUtil.getInstance().create(MovieRequest.class);
78 | movieRequest.getMovies(0, 10)
79 | .subscribeOn(Schedulers.io())
80 | .unsubscribeOn(Schedulers.io())
81 | .observeOn(AndroidSchedulers.mainThread())
82 | .subscribe(new Subscriber() {
83 | @Override
84 | public void onCompleted() {
85 |
86 | }
87 |
88 | @Override
89 | public void onError(Throwable e) {
90 | ToastUtils.showToast(getActivity(), getString(R.string.request_error));
91 | }
92 |
93 | @Override
94 | public void onNext(AbilityBean abilityBean) {
95 | swipeRefreshLayout.setRefreshing(false);
96 | datas.clear();
97 | ToastUtils.showToast(getActivity(), getString(R.string.request_success));
98 | for (int i = 0; i < abilityBean.subjects.size(); i++) {
99 | datas.add(new AbilityItem(abilityBean.subjects.get(i).images.medium, abilityBean.subjects.get(i).title, abilityBean.subjects.get(i).year));
100 | bitmapList.add(abilityBean.subjects.get(i).images.large);
101 | }
102 | loadConvenientBanner();
103 |
104 | adapter = new CommonAdapter(getActivity(), R.layout.item_fragment_ability_recyclerview, datas) {
105 | @Override
106 | protected void convert(ViewHolder holder, final AbilityItem abilityItem, final int position) {
107 |
108 | holder.setText(R.id.place, abilityItem.getTitle());
109 | holder.setText(R.id.price, abilityItem.getContent());
110 | holder.setRating(R.id.ratingBar,2);
111 | ImageView circleImageView = holder.getView(R.id.image);
112 | Glide.with(getActivity()).load(abilityItem.getImage()).into(circleImageView);
113 | }
114 | };
115 | recyclerView.setAdapter(adapter);
116 | }
117 | });
118 | }
119 |
120 |
121 | @Override
122 | protected void adapterBuilder() {
123 |
124 | }
125 |
126 |
127 | @Override
128 | protected int getLayoutId() {
129 | return R.layout.fragment_ability1;
130 | }
131 |
132 |
133 | @Override
134 | public void onRefresh() {
135 | super.onRefresh();
136 | getMovie();
137 | }
138 |
139 |
140 | @Override
141 | public void onClick(View v) {
142 | switch (v.getId()) {
143 | case R.id.root_view:
144 | // startActivity(new Intent(getActivity(), IntroduceActivity.class));
145 | break;
146 | }
147 | }
148 |
149 | @Override
150 | public void onItemClick(int position) {
151 |
152 | }
153 | }
--------------------------------------------------------------------------------