├── .gitattributes
├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── example
│ │ └── jdk
│ │ └── restapp
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── iconfont.ttf
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── jdk
│ │ │ └── restapp
│ │ │ ├── Activity
│ │ │ ├── BaseActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── ShowBigBitmapActivity.java
│ │ │ └── ShowWebViewActivity.java
│ │ │ ├── Adapter
│ │ │ ├── RecyclerViewBaseAdapter.java
│ │ │ ├── RecyclerViewDataAdapter.java
│ │ │ └── UniversalViewolder.java
│ │ │ ├── CustomizedWidget
│ │ │ ├── CustomClearAndSearechEdittext.java
│ │ │ ├── CustomizedTextView.java
│ │ │ └── LoadMoreRecyclerView.java
│ │ │ ├── DataBase
│ │ │ ├── MySQLiteBase.java
│ │ │ ├── MySQLiteDAL.java
│ │ │ ├── MySQLiteOpenHelper.java
│ │ │ └── MySQLiteWebViewTextBussiness.java
│ │ │ ├── Fragment
│ │ │ ├── AboutAuthorFragment.java
│ │ │ ├── AboutProjectFragment.java
│ │ │ ├── AndroidFragment.java
│ │ │ ├── BaseFragment.java
│ │ │ ├── CollectionFragment.java
│ │ │ ├── FrontFragment.java
│ │ │ ├── MeiziFragment.java
│ │ │ ├── ShakeAndroidFragment.java
│ │ │ ├── ShakeFragment.java
│ │ │ ├── ShakeFrontFragment.java
│ │ │ ├── ShakeMeiziFragment.java
│ │ │ ├── WatchAndShakeFragment.java
│ │ │ └── WatchFragment.java
│ │ │ ├── HttpUtils
│ │ │ ├── RequestData.java
│ │ │ ├── ReturnRetrofit.java
│ │ │ └── gankAPI.java
│ │ │ ├── ModelData
│ │ │ ├── BaseData.java
│ │ │ ├── Constant.java
│ │ │ ├── FrontData.java
│ │ │ ├── MeiziData.java
│ │ │ ├── MyAndroidData.java
│ │ │ ├── RestVideoData.java
│ │ │ └── entity
│ │ │ │ ├── Base.java
│ │ │ │ ├── Front.java
│ │ │ │ ├── Gank.java
│ │ │ │ ├── Meizi.java
│ │ │ │ ├── MyAndroid.java
│ │ │ │ ├── URLTableData.java
│ │ │ │ └── Video.java
│ │ │ └── Utils
│ │ │ ├── BackHandlerHelper.java
│ │ │ ├── ChangeTimeFormat.java
│ │ │ ├── FileUtils.java
│ │ │ ├── FragmentBackHandler.java
│ │ │ ├── MyDecoration.java
│ │ │ ├── SPDataUtil.java
│ │ │ ├── ShakeUtils.java
│ │ │ ├── ShareUtils.java
│ │ │ ├── SnackBarUtils.java
│ │ │ └── SplitUtils.java
│ └── res
│ │ ├── drawable
│ │ ├── bg_card.xml
│ │ ├── bottom_btnback.xml
│ │ ├── custom_progressbar.xml
│ │ ├── divider.xml
│ │ ├── ic__about_author_24dp.xml
│ │ ├── ic_about_project_24dp.xml
│ │ ├── ic_back_24dp.xml
│ │ ├── ic_back_28dp.xml
│ │ ├── ic_collection_24dp.xml
│ │ ├── ic_github_36dp.xml
│ │ ├── ic_navigation_30dp.xml
│ │ ├── ic_save_24dp.xml
│ │ ├── ic_share_24dp.xml
│ │ ├── ic_sort_24dp.xml
│ │ ├── ic_star_36dp.xml
│ │ ├── ic_toolbar_share_24dp.xml
│ │ ├── selector_tabtext.xml
│ │ └── selector_tabtext_first.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_show_big_bitmap.xml
│ │ ├── android_item.xml
│ │ ├── collection_item.xml
│ │ ├── content_about.xml
│ │ ├── fragment_about_author.xml
│ │ ├── fragment_about_project.xml
│ │ ├── fragment_collection.xml
│ │ ├── fragment_my_collection.xml
│ │ ├── fragment_shake_android.xml
│ │ ├── fragment_shake_front.xml
│ │ ├── fragment_shake_meizi.xml
│ │ ├── fragment_user.xml
│ │ ├── fragment_watch_android.xml
│ │ ├── fragment_watch_front.xml
│ │ ├── fragment_watch_meizi.xml
│ │ ├── fragment_watch_shake.xml
│ │ ├── front_item.xml
│ │ ├── meizi_item.xml
│ │ ├── meizi_none_item.xml
│ │ ├── navigation_header.xml
│ │ ├── navigationview_layout.xml
│ │ ├── other_toolbar.xml
│ │ ├── paf_fragment_layout.xml
│ │ ├── show_webview.xml
│ │ ├── show_webview_title.xml
│ │ ├── swiperefreshlayout_layout.xml
│ │ └── watch_shake_toolbar.xml
│ │ ├── menu
│ │ ├── big_picture_toolbar_menu.xml
│ │ ├── navigation_menu_item.xml
│ │ └── webview_toolbar_menu.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── navigationview_head.jpg
│ │ ├── mipmap-mdpi
│ │ ├── back.png
│ │ ├── back_right.png
│ │ ├── collected.png
│ │ ├── error.png
│ │ ├── ic_launcher.png
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ └── uncollected.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_thumb_up.png
│ │ ├── mipmap-xxhdpi
│ │ ├── about_author.jpg
│ │ ├── ic_launcher.png
│ │ └── logo.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── about_project.PNG
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── material_designer_color.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── example
│ └── jdk
│ └── restapp
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | RestAPP
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | **gank.io Material Design, RxJava & Retrofit & MVVM**
4 |
5 | 这是2.0版本,如果想看1.0版本,请在分支处选择1.0,从1.0版本到2.0版本是一个大更新,所有界面都更改了,因为
6 | 我比较喜欢网易云音乐的界面,所以2.0版本是仿网易云音乐界面,并且增加了很多功能,比如,**摇一摇**,**搜索**等,
7 | 整个项目看起来焕然一新!
8 | 然后,我又重新**封装**了一下项目,并且将原来的摇一摇**加载图片的bug**给消除了,同时增加了**保存和分享**的功能,这里是原来的[2.0版本](https://github.com/sakurajiang/OriginalRestAPP),我之所以另开一个仓库来存储原来的版本,而没有直接将新代码提交到这个的仓库中,是因为这样可以直接在网页上看出两次封装的不同,可以更好的理解我为什么这么封装。特别是对于Adapter的重新封装。
9 | 相关文章:https://sakurajiang.github.io/ 进去之后点击右边的Tags,然后选择#RestApp,就能找到关于这个项目的文章了。
10 |
11 | 直接下载:https://fir.im/sakurajiangAPP
12 |
13 |
14 | 界面预览:
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | ### about me
25 | I am a junior student ( now a senior student) , I learn Android almost a year , Compared with a year ago, I made great progress in programming , and feel a sense of achievement, if you have any questions or love programming , please send an email to wssakurajiang@gmail.com or 546759734@qq.com
26 |
27 | In addition, my blog: https://sakurajiang.github.io/
28 |
29 | If you like this open source projects, please star: https://github.com/sakurajiang/RestAPP
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.android.databinding'
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 | dataBinding {
7 | enabled true
8 | }
9 | defaultConfig {
10 | applicationId "com.example.jdk.restapp"
11 | minSdkVersion 19
12 | targetSdkVersion 23
13 | versionCode 2
14 | versionName "2.0"
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | testCompile 'junit:junit:4.12'
27 | compile 'com.android.support:appcompat-v7:23.3.0'
28 | compile ('com.android.support:support-v4:23.3.0'){
29 | force = true;
30 | }
31 | compile 'io.reactivex:rxjava:1.1.0'
32 | compile 'io.reactivex:rxandroid:1.1.0'
33 | compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
34 | compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
35 | compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4'
36 | compile 'com.google.code.gson:gson:2.6.2'
37 | compile 'com.jakewharton:butterknife:7.0.1'
38 | compile 'com.squareup.picasso:picasso:2.5.2'
39 | compile 'com.android.support:recyclerview-v7:23.3.0'
40 | compile 'com.android.support:cardview-v7:23.3.0'
41 | compile 'com.android.support:percent:23.3.0'
42 | compile 'com.android.support:design:23.3.0'
43 | compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
44 | compile 'com.github.chrisbanes:PhotoView:1.3.0'
45 | }
46 |
--------------------------------------------------------------------------------
/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-stdio\Android_Stdio1.5\SDK/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/androidTest/java/com/example/jdk/restapp/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/assets/iconfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sakurajiang/RestAPP/f87ffbcbd73e4e2588c437058601b1b6b7d35aba/app/src/main/assets/iconfont.ttf
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Activity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Activity;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentTransaction;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.util.DisplayMetrics;
8 |
9 | import android.view.Window;
10 | import android.view.WindowManager;
11 | import android.widget.LinearLayout;
12 | import android.widget.TextView;
13 |
14 |
15 | import com.example.jdk.restapp.R;
16 |
17 | /**
18 | * Created by JDK on 2016/8/8.
19 | */
20 | public class BaseActivity extends AppCompatActivity{
21 | public void setFullScreen(){
22 | requestWindowFeature(Window.FEATURE_NO_TITLE);
23 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
24 | ,WindowManager.LayoutParams.FLAG_FULLSCREEN);
25 | }
26 | public void setWebViewAdaptScreen(int layout_id,int id){
27 | setContentView(layout_id);
28 | LinearLayout linearLayout= (LinearLayout) findViewById(R.id.webview_linearlayout);
29 | DisplayMetrics metric = new DisplayMetrics();
30 | getWindowManager().getDefaultDisplay().getMetrics(metric);
31 | int width = metric.widthPixels; // 屏幕宽度(像素)
32 | int height = metric.heightPixels; // 屏幕高度(像素)
33 | float density = metric.density; // 屏幕密度(0.75 / 1.0 / 1.5)
34 | int densityDpi = metric.densityDpi; // 屏幕密度DPI(120 / 160 / 240)
35 | LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(width,height-260);
36 | linearLayout.setLayoutParams(params);
37 | }
38 |
39 | public FragmentTransaction getFragmentTransaction(){
40 | FragmentManager fragmentManager=getSupportFragmentManager();
41 | FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
42 | return fragmentTransaction;
43 | }
44 | public void addFragment(int id,Fragment fragment){
45 | getFragmentTransaction().add(id, fragment).commit();
46 | }
47 | public void addFragmentWithTag(int id,Fragment fragment,String TAG){
48 | getFragmentTransaction().add(id, fragment,TAG).commit();
49 | }
50 | public void replaceFragment(int id,Fragment fragment){
51 | getFragmentTransaction().replace(id, fragment).addToBackStack(null).commit();
52 | }
53 | public void replaceFragmentWithTag(int id,Fragment fragment,String TAG){
54 | getFragmentTransaction().replace(id,fragment,TAG).addToBackStack(null).commit();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Adapter/RecyclerViewBaseAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Adapter;
2 |
3 | import android.content.Context;
4 | import android.databinding.ViewDataBinding;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.SparseArray;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.AdapterView;
11 |
12 | import com.example.jdk.restapp.ModelData.entity.MyAndroid;
13 | import com.example.jdk.restapp.R;
14 |
15 | import java.util.List;
16 |
17 | /**
18 | * Created by JDK on 2016/9/29.
19 | */
20 | public abstract class RecyclerViewBaseAdapter extends RecyclerView.Adapter {
21 | List mDataList;
22 | int mLayoutId;
23 | int mVariableId;
24 | Context mContext;
25 | int [] mLayoutIdArray;
26 | private SparseArray mOnItemClickListeners;
27 |
28 | /**
29 | *
30 | * @param context 传入一个context
31 | * @param dataList 传入数据源
32 | * @param layoutIdArray 传入显示数据源的layout数组
33 | * @param variableId 传入layout中的variable,形式如BR.XXX
34 | */
35 | public RecyclerViewBaseAdapter(Context context,List dataList,int [] layoutIdArray,int variableId){
36 | this.mContext=context;
37 | mDataList=dataList;
38 | mLayoutIdArray=layoutIdArray;
39 | mOnItemClickListeners=new SparseArray<>();
40 | mVariableId=variableId;
41 | }
42 |
43 | @Override
44 | public UniversalViewolder onCreateViewHolder(ViewGroup parent, int viewType) {
45 | if(mLayoutIdArray.length==1){
46 | mLayoutId=mLayoutIdArray[0];
47 | }else {
48 | mLayoutId = getLayoutId(viewType);
49 | }
50 | return UniversalViewolder.getViewHolder(parent,mLayoutId);
51 | }
52 | @Override
53 | public void onBindViewHolder( UniversalViewolder holder, final int position) {
54 | ViewDataBinding viewDataBinding= holder.getViewDataBinding();
55 | final T itemModel=mDataList.get(position);
56 | viewDataBinding.setVariable(mVariableId, mDataList.get(position));
57 | viewDataBinding.executePendingBindings();
58 | getViewDataBinding(holder, position);
59 | for(int i=0;i void onItemClick(View v, T t,int position);
95 | }
96 | /**
97 | * 为View设置监听器
98 | * @param ViewId 是指设置监听器控件的Id,传入0代表整个item
99 | * @param mOnItemClickListener 是onItemClickListener接口.
100 | */
101 | public void setOnItemClickListener(int ViewId,onItemClickListener mOnItemClickListener){
102 | onItemClickListener onItemClickListener_=mOnItemClickListeners.get(ViewId);
103 | if(onItemClickListener_==null){
104 | mOnItemClickListeners.put(ViewId,mOnItemClickListener);
105 | }
106 | }
107 | public abstract void getViewDataBinding(UniversalViewolder viewolder,final int position);
108 |
109 | /**
110 | * 如果需要设置多种type的布局,就需要定义这个个方法,默认的是一个type。
111 | * @param viewType
112 | * @return
113 | */
114 | public abstract int getLayoutId(int viewType);
115 | }
116 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Adapter/RecyclerViewDataAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Adapter;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.example.jdk.restapp.ModelData.entity.Front;
7 | import com.example.jdk.restapp.ModelData.entity.MyAndroid;
8 | import com.example.jdk.restapp.ModelData.entity.URLTableData;
9 | import com.example.jdk.restapp.ModelData.entity.Video;
10 | import com.example.jdk.restapp.R;
11 | import java.util.Date;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by JDK on 2016/9/30.
16 | */
17 | public class RecyclerViewDataAdapter extends RecyclerViewBaseAdapter {
18 | private recyclerViewDataBindingItemOnClickListener myRecyclerViewDataBindingItemOnClick;
19 | public RecyclerViewDataAdapter(Context context, List dataList, int[] layoutIdArray,int variableId) {
20 | super(context, dataList,layoutIdArray, variableId);
21 | }
22 | @Override
23 | public void getViewDataBinding(UniversalViewolder viewolder, final int position) {
24 | if (myRecyclerViewDataBindingItemOnClick != null) {
25 | super.setOnItemClickListener(0, new onItemClickListener() {
26 | @Override
27 | public void onItemClick(View v, T b, int position) {
28 | if (b instanceof MyAndroid)
29 | myRecyclerViewDataBindingItemOnClick.recyclerViewDataBindingItemOnClick(((MyAndroid) b).url, ((MyAndroid) b).desc, ((MyAndroid) b).who, ((MyAndroid) b).publishedAt, ((MyAndroid) b).type, position,0);
30 | if(b instanceof Front)
31 | myRecyclerViewDataBindingItemOnClick.recyclerViewDataBindingItemOnClick(((Front) b).url, ((Front) b).desc, ((Front) b).who, ((Front) b).publishedAt, ((Front) b).type, position,0);
32 | if(b instanceof Video)
33 | myRecyclerViewDataBindingItemOnClick.recyclerViewDataBindingItemOnClick(((Video) b).url, ((Video) b).desc, ((Video) b).who, ((Video) b).publishedAt, ((Video) b).type, position,0);
34 | if(b instanceof URLTableData)
35 | myRecyclerViewDataBindingItemOnClick.recyclerViewDataBindingItemOnClick(((URLTableData) b).url, ((URLTableData) b).desc, ((URLTableData) b).who, ((URLTableData) b).publishedAt, ((URLTableData) b).type, position,0);
36 | }
37 |
38 | });
39 | super.setOnItemClickListener(R.id.meizi_imageView, new onItemClickListener() {
40 | @Override
41 | public void onItemClick(View v, T t, int position) {
42 | if(t instanceof Video)
43 | myRecyclerViewDataBindingItemOnClick.recyclerViewDataBindingItemOnClick(((Video) t).url, ((Video) t).desc, ((Video) t).who, ((Video) t).publishedAt, ((Video) t).type, position,R.id.meizi_imageView);
44 | }
45 | });
46 | }
47 |
48 | }
49 |
50 | @Override
51 | public int getLayoutId(int viewType) {
52 | return 0;
53 | }
54 |
55 |
56 | public interface recyclerViewDataBindingItemOnClickListener{
57 | public void recyclerViewDataBindingItemOnClick(String url,String desc,String who,Date CreateAt,String type,int position,int clickPosition);
58 | }
59 | public void setRecyclerViewItemOnClickListener(recyclerViewDataBindingItemOnClickListener myRecyclerViewDataBindingItemOnClick){
60 | this.myRecyclerViewDataBindingItemOnClick=myRecyclerViewDataBindingItemOnClick;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Adapter/UniversalViewolder.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Adapter;
2 |
3 | import android.databinding.DataBindingUtil;
4 | import android.databinding.ViewDataBinding;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.SparseArray;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | /**
12 | * Created by JDK on 2016/9/30.
13 | */
14 | public class UniversalViewolder extends RecyclerView.ViewHolder{
15 | private SparseArray mChildViews;
16 | private View mItemView;
17 | private ViewDataBinding viewDataBinding;
18 | public UniversalViewolder(View itemView) {
19 | super(itemView);
20 | mItemView=itemView;
21 | mChildViews=new SparseArray<>();
22 | viewDataBinding= DataBindingUtil.bind(itemView);
23 | }
24 | public ViewDataBinding getViewDataBinding() {
25 | return viewDataBinding;
26 | }
27 | public void setViewDataBinding(ViewDataBinding viewDataBinding) {
28 | this.viewDataBinding = viewDataBinding;
29 | }
30 | public static UniversalViewolder getViewHolder(ViewGroup parent,int LayoutId){
31 | View v=LayoutInflater.from(parent.getContext()).inflate(LayoutId, parent, false);
32 | return new UniversalViewolder(v);
33 | }
34 | public View getChildView(int ChildId){
35 | View childView=mChildViews.get(ChildId);
36 | if(childView==null){
37 | childView=mItemView.findViewById(ChildId);
38 | mChildViews.put(ChildId,childView);
39 | }
40 | return childView;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/CustomizedWidget/CustomClearAndSearechEdittext.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.CustomizedWidget;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.Drawable;
5 | import android.support.v4.content.ContextCompat;
6 | import android.text.Editable;
7 | import android.text.TextWatcher;
8 | import android.util.AttributeSet;
9 | import android.view.MotionEvent;
10 | import android.view.View;
11 | import android.view.inputmethod.InputMethodManager;
12 | import android.widget.EditText;
13 |
14 | import com.example.jdk.restapp.R;
15 |
16 | /**
17 | * Created by JDK on 2016/9/15.
18 | */
19 | public class CustomClearAndSearechEdittext extends EditText implements View.OnFocusChangeListener,TextWatcher{
20 | private Drawable mClearDrawable;
21 | /**
22 | * 控件是否有焦点
23 | */
24 | private boolean hasFoucs;
25 | public OnClickSearchListener mOnClickSearchListener;
26 | private InputMethodManager inputManager;
27 | public interface OnClickSearchListener{
28 | public void onClickSearch();
29 | }
30 | public void setOnClickSearchListener(OnClickSearchListener onClickSearchListener){
31 | this.mOnClickSearchListener=onClickSearchListener;
32 | }
33 | public CustomClearAndSearechEdittext(Context context) {
34 | this(context, null);
35 | }
36 |
37 | public CustomClearAndSearechEdittext(Context context, AttributeSet attrs) {
38 | super(context, attrs);
39 | init(context);
40 |
41 | }
42 |
43 | public CustomClearAndSearechEdittext(Context context, AttributeSet attrs, int defStyleAttr) {
44 | super(context, attrs, defStyleAttr);
45 | init(context);
46 | }
47 | private void init(final Context context) {
48 | //获取EditText的DrawableRight,假如没有设置我们就使用默认的图片
49 | final Drawable drawable = ContextCompat.getDrawable(context, R.drawable.abc_ic_clear_mtrl_alpha);
50 | setTextColor(getCurrentHintTextColor());
51 | mClearDrawable=drawable;
52 | mClearDrawable.setBounds(0, 0, mClearDrawable.getIntrinsicWidth()+10, mClearDrawable.getIntrinsicHeight()+10);
53 | //默认设置隐藏图标
54 | setClearIconVisible(false);
55 | //设置焦点改变的监听
56 | setOnFocusChangeListener(this);
57 | //设置输入框里面内容发生改变的监听
58 | addTextChangedListener(this);
59 | inputManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
60 | }
61 |
62 |
63 |
64 | /**
65 | * 当手指抬起的位置在clean的图标的区域
66 | * 我们将此视为进行清除操作
67 | * getWidth():得到控件的宽度
68 | * event.getX():抬起时的坐标(该坐标是相对于控件本身而言的)
69 | * getTotalPaddingRight():clean的图标左边缘至控件右边缘的距离
70 | * getPaddingRight():clean的图标右边缘至控件右边缘的距离
71 | * 于是:
72 | * getWidth() - getTotalPaddingRight()表示:
73 | * 控件左边到clean的图标左边缘的区域
74 | * getWidth() - getPaddingRight()表示:
75 | * 控件左边到clean的图标右边缘的区域
76 | * 所以这两者之间的区域刚好是clean的图标的区域
77 | */
78 | @Override
79 | public boolean onTouchEvent(MotionEvent event) {
80 | if(event.getAction()==MotionEvent.ACTION_DOWN) {
81 | return true;
82 | }
83 | if(event.getAction()==MotionEvent.ACTION_MOVE) {
84 | return false;
85 | }
86 | if (event.getAction() == MotionEvent.ACTION_UP) {
87 | if (getCompoundDrawables()[2] != null) {
88 | boolean searchable=event.getX()>((getWidth()-getPaddingRight()+80));
89 | boolean touchable = event.getX() > (getWidth() - getTotalPaddingRight())
90 | && (event.getX() < ((getWidth() - getPaddingRight())));
91 | if (touchable) {
92 | this.setText("");
93 | }
94 | if(searchable&&mOnClickSearchListener!=null){
95 | mOnClickSearchListener.onClickSearch();
96 | }
97 | }
98 | return true;
99 | }
100 | return true;
101 | }
102 |
103 | /**
104 | * 当ClearEditText焦点发生变化的时候,判断里面字符串长度设置清除图标的显示与隐藏
105 | */
106 | @Override
107 | public void onFocusChange(View v, boolean hasFocus) {
108 | this.hasFoucs = hasFocus;
109 | if (hasFocus) {
110 | setClearIconVisible(getText().length() > 0);
111 | //当获得焦点时,弹出输入法
112 | inputManager.showSoftInput(v, 0);
113 | } else {
114 | //失去焦点时,关闭输入法
115 | setClearIconVisible(false);
116 | //为什么在这里设置隐藏键盘没有用?
117 | // inputManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
118 | // inputManager.hideSoftInputFromInputMethod(getWindowToken(), 0);
119 |
120 |
121 |
122 | }
123 | }
124 |
125 |
126 | /**
127 | * 设置清除图标的显示与隐藏,调用setCompoundDrawables为EditText绘制上去
128 | * @param visible
129 | */
130 | protected void setClearIconVisible(boolean visible) {
131 | Drawable right = visible ? mClearDrawable : null;
132 | setCompoundDrawables(getCompoundDrawables()[0],
133 | getCompoundDrawables()[1] ,right, getCompoundDrawables()[3]);
134 |
135 | }
136 |
137 |
138 | /**
139 | * 当输入框里面内容发生变化的时候回调的方法
140 | */
141 | @Override
142 | public void onTextChanged(CharSequence s, int start, int count,
143 | int after) {
144 | if(hasFoucs){
145 | setClearIconVisible(s.length() > 0);
146 | }
147 | }
148 |
149 | @Override
150 | public void beforeTextChanged(CharSequence s, int start, int count,
151 | int after) {
152 |
153 | }
154 |
155 | @Override
156 | public void afterTextChanged(Editable s) {
157 |
158 | }
159 |
160 | }
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/CustomizedWidget/CustomizedTextView.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.CustomizedWidget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Rect;
5 | import android.util.AttributeSet;
6 | import android.widget.TextView;
7 |
8 | /**
9 | * Created by JDK on 2016/8/22.
10 | */
11 | public class CustomizedTextView extends TextView{
12 | public CustomizedTextView(Context context, AttributeSet attrs) {
13 | super(context, attrs);
14 | }
15 | @Override
16 | protected void onFocusChanged(boolean focused, int direction,
17 | Rect previouslyFocusedRect) {
18 | if (focused)
19 | super.onFocusChanged(focused, direction, previouslyFocusedRect);
20 | }
21 |
22 | @Override
23 | public void onWindowFocusChanged(boolean focused) {
24 | if (focused)
25 | super.onWindowFocusChanged(focused);
26 | }
27 | @Override
28 | public boolean isFocused() {
29 | return true;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/CustomizedWidget/LoadMoreRecyclerView.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.CustomizedWidget;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.LinearLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.AttributeSet;
7 |
8 | /**
9 | * Created by JDK on 2016/10/31.
10 | */
11 | public class LoadMoreRecyclerView extends RecyclerView{
12 | private LoadMoreListener mLoadMoreListener;
13 | private boolean isBottom=true;
14 | public LoadMoreRecyclerView(Context context, AttributeSet attrs) {
15 | super(context, attrs);
16 | }
17 | public interface LoadMoreListener{
18 | public void loadMore();
19 | }
20 | public void setLoadMoreListener(LoadMoreListener loadMoreListener){
21 | this.mLoadMoreListener=loadMoreListener;
22 | }
23 |
24 | @Override
25 | public void onScrolled(int dx, int dy) {
26 | isBottom=dy>0;
27 | }
28 |
29 | @Override
30 | public void onScrollStateChanged(int state) {
31 | if (computeVerticalScrollExtent() + computeVerticalScrollOffset()
32 | >= computeVerticalScrollRange()) {
33 | if (mLoadMoreListener != null&&isBottom)
34 | mLoadMoreListener.loadMore();
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/DataBase/MySQLiteBase.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.DataBase;
2 |
3 | import android.content.Context;
4 | import android.database.Cursor;
5 | import android.database.sqlite.SQLiteDatabase;
6 |
7 | import com.example.jdk.restapp.R;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | /**
13 | * Created by JDK on 2016/8/12.
14 | */
15 | public abstract class MySQLiteBase implements MySQLiteOpenHelper.callBackOnCreateTable{
16 | private SQLiteDatabase mySqLiteDatabase;
17 | private Context mContext;
18 | public MySQLiteBase(Context context){
19 | this.mContext=context;
20 | }
21 | public SQLiteDatabase getMySqLiteDatabase(){
22 | if(mySqLiteDatabase==null){
23 | mySqLiteDatabase=MySQLiteOpenHelper.getInstance(mContext).getReadableDatabase();
24 | }
25 | return mySqLiteDatabase;
26 | }
27 | public void beginTransaction()
28 | {
29 | mySqLiteDatabase.beginTransaction();
30 | }
31 |
32 | public void setTransactionSuccessful()
33 | {
34 | mySqLiteDatabase.setTransactionSuccessful();
35 | }
36 |
37 | public void endTransaction()
38 | {
39 | mySqLiteDatabase.endTransaction();
40 | }
41 | public List getTables(){
42 | List stringList=new ArrayList<>();
43 | String [] collection=mContext.getResources().getStringArray(R.array.table_name);
44 | for (int i=0;i 0;
56 | }
57 | public URLTableData queryFromURLTable(int _id){
58 | String sql="select * from "+getTable()+" where 1=1 And _id= "+_id;
59 | Cursor c=getMySqLiteDatabase().rawQuery(sql, null);
60 | return (URLTableData) FindModel(c);
61 |
62 | }
63 | public Boolean deleteFromURLTable(int _id){
64 | return deleteFromURLTableInBase(getTable(), _id);
65 | }
66 | public int getCountInDAL(){
67 | String sql="select * from "+getTable();
68 | return getList(sql).size();
69 | }
70 | public List queryAllFromURLTableInDAL(){
71 | String sql="select * from "+getTable();
72 | return getList(sql);
73 | }
74 | public URLTableData setUrlTableData(URLTableData urlTableData){
75 | if(urlTableData.getUrl()==null){
76 | urlTableData.setUrl("该链接不存在");
77 | }
78 | if(urlTableData.getWho()==null){
79 | urlTableData.setWho("佚名");
80 | }
81 | if(urlTableData.getDesc()==null){
82 | urlTableData.setDesc("不存在");
83 | }
84 | if(urlTableData.publishedAt==null){
85 | urlTableData.publishedAt=new Date();
86 | }
87 | return urlTableData;
88 | }
89 | public ContentValues CreatParms(URLTableData urlTableData) {
90 | setUrlTableData(urlTableData);
91 | ContentValues _ContentValues = new ContentValues();
92 | _ContentValues.put("URLValue",urlTableData.getUrl());
93 | Log.e("log",""+urlTableData.publishedAt);
94 | _ContentValues.put("URLPublishedAt",ChangeTimeFormat.changeToYearMonthDay(urlTableData.publishedAt));
95 | _ContentValues.put("URLWho",urlTableData.getWho());
96 | _ContentValues.put("URLDesc",urlTableData.getDesc());
97 | return _ContentValues;
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/DataBase/MySQLiteOpenHelper.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.DataBase;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.database.sqlite.SQLiteOpenHelper;
6 |
7 | import com.example.jdk.restapp.ModelData.Constant;
8 |
9 | /**
10 | * Created by JDK on 2016/8/11.
11 | */
12 | public class MySQLiteOpenHelper extends SQLiteOpenHelper{
13 | private static Context mContext;
14 | private callBackOnCreateTable myCallBackOnCreateTable;
15 | private static MySQLiteOpenHelper mySQLiteOpenHelper;
16 | private MySQLiteOpenHelper(Context mContext) {
17 | super(mContext, Constant.MYDATABASE_NAME, null, Constant.MYDATABASE_VERSION);
18 | this.mContext=mContext;
19 | }
20 | public static MySQLiteOpenHelper getInstance(Context context){
21 | if(mySQLiteOpenHelper==null){
22 | synchronized (MySQLiteOpenHelper.class){
23 | mySQLiteOpenHelper=new MySQLiteOpenHelper(context);
24 | }
25 | }
26 | return mySQLiteOpenHelper;
27 | }
28 | public interface callBackOnCreateTable{
29 | public void myOnCreateTable(SQLiteDatabase sqLiteDatabase);
30 | }
31 | public void setCallBackOnCreateTable(callBackOnCreateTable myCallBackOnCreateTable){
32 | this.myCallBackOnCreateTable=myCallBackOnCreateTable;
33 | }
34 | @Override
35 | public void onCreate(SQLiteDatabase db) {
36 | if(myCallBackOnCreateTable!=null) {
37 | myCallBackOnCreateTable.myOnCreateTable(db);
38 | }
39 | }
40 |
41 | @Override
42 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
43 |
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/DataBase/MySQLiteWebViewTextBussiness.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.DataBase;
2 |
3 | import android.content.Context;
4 |
5 | import com.example.jdk.restapp.ModelData.entity.URLTableData;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Created by JDK on 2016/8/12.
11 | */
12 | public class MySQLiteWebViewTextBussiness extends MySQLiteDAL{
13 | private MySQLiteDAL mySQLiteDAL;
14 | public MySQLiteWebViewTextBussiness(Context context) {
15 | super(context);
16 | mySQLiteDAL=new MySQLiteDAL(context);
17 | }
18 | public Boolean insertToWebViewURLTable(URLTableData urlTableData){
19 | mySQLiteDAL.beginTransaction();
20 | try {
21 | Boolean _Result = mySQLiteDAL.insertToURLTable(urlTableData);
22 | if (_Result ) {
23 | mySQLiteDAL.setTransactionSuccessful();
24 | return true;
25 | } else {
26 | return false;
27 | }
28 | } catch (Exception e) {
29 | return false;
30 | } finally {
31 | mySQLiteDAL.endTransaction();
32 | }
33 | }
34 | public Boolean deleteFromWebViewTable(int _id){
35 | mySQLiteDAL.beginTransaction();
36 | try {
37 | Boolean _Result = mySQLiteDAL.deleteFromURLTable(_id);
38 | if (_Result ) {
39 | mySQLiteDAL.setTransactionSuccessful();
40 | return true;
41 | } else {
42 | return false;
43 | }
44 | } catch (Exception e) {
45 | return false;
46 | } finally {
47 | mySQLiteDAL.endTransaction();
48 | }
49 | }
50 | public URLTableData queryFromTable(int _id){
51 | return mySQLiteDAL.queryFromURLTable(_id);
52 | }
53 | public List queryAllFromTable(){
54 | return mySQLiteDAL.queryAllFromURLTableInDAL();
55 | }
56 | public int getCount(){
57 | return mySQLiteDAL.getCountInDAL();
58 | }
59 |
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Fragment/AboutAuthorFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Fragment;
2 |
3 | import android.content.Intent;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.design.widget.AppBarLayout;
8 | import android.support.design.widget.FloatingActionButton;
9 | import android.support.v4.app.Fragment;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.support.v7.widget.Toolbar;
12 | import android.text.Html;
13 | import android.text.method.LinkMovementMethod;
14 | import android.view.LayoutInflater;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.view.animation.AlphaAnimation;
18 | import android.widget.TextView;
19 |
20 | import com.example.jdk.restapp.R;
21 |
22 | import butterknife.Bind;
23 | import butterknife.ButterKnife;
24 |
25 |
26 | /**
27 | * Created by JDK on 2016/9/9.
28 | */
29 | public class AboutAuthorFragment extends Fragment implements View.OnClickListener,AppBarLayout.OnOffsetChangedListener{
30 | @Bind(R.id.app_bar)
31 | AppBarLayout appBarLayout;
32 | @Bind(R.id.tool_bar)
33 | Toolbar toolbar;
34 | @Bind(R.id.music_link_tv)
35 | TextView music_link_tv;
36 | @Bind(R.id.fab)
37 | FloatingActionButton floatingActionButton;
38 | private static final float PERCENTAGE_TO_SHOW_TITLE_AT_TOOLBAR = 0.9f;
39 | private static final int ALPHA_ANIMATIONS_DURATION = 200;
40 | private boolean mIsTheTitleVisible = false;
41 | private AppCompatActivity appCompatActivity;
42 | private static AboutAuthorFragment aboutAuthorFragment;
43 | private View v;
44 |
45 | public interface aboutAuthorDrawerIconListener{
46 | public void aboutAuthorDrawerIcon();
47 | }
48 | public static AboutAuthorFragment newInstance(){
49 | if( aboutAuthorFragment ==null){
50 | aboutAuthorFragment =new AboutAuthorFragment();
51 | }
52 | return aboutAuthorFragment;
53 | }
54 | @Override
55 | public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
56 | int maxScroll = appBarLayout.getTotalScrollRange();
57 | float percentage = (float) Math.abs(verticalOffset) / (float) maxScroll;
58 | if (percentage >= 0.5f) {
59 | toolbar.setNavigationIcon(R.drawable.ic_navigation_30dp);
60 | }
61 | handleToolbarTitleVisibility(percentage);
62 | }
63 | @Nullable
64 | @Override
65 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
66 | if(v!=null){
67 | ButterKnife.bind(this,v);
68 | return v;
69 | }
70 | v=inflater.inflate(R.layout.fragment_about_author, container, false);
71 | ButterKnife.bind(this,v);
72 | appBarLayout.addOnOffsetChangedListener(this);
73 | initFabListener();
74 | initWidget();
75 | appCompatActivity=((AppCompatActivity) getActivity());
76 | appCompatActivity.setSupportActionBar(toolbar);
77 | toolbar.setNavigationOnClickListener(this);
78 | return v;
79 | }
80 | // 设置渐变的动画
81 | public static void startAlphaAnimation(View v, long duration, int visibility) {
82 | AlphaAnimation alphaAnimation = (visibility == View.VISIBLE)
83 | ? new AlphaAnimation(0f, 1f)
84 | : new AlphaAnimation(1f, 0f);
85 |
86 | alphaAnimation.setDuration(duration);
87 | alphaAnimation.setFillAfter(true);
88 | v.startAnimation(alphaAnimation);
89 | }
90 | // 处理ToolBar的显示
91 | private void handleToolbarTitleVisibility(float percentage) {
92 | if (percentage >= PERCENTAGE_TO_SHOW_TITLE_AT_TOOLBAR) {
93 | if (!mIsTheTitleVisible) {
94 | startAlphaAnimation(toolbar, ALPHA_ANIMATIONS_DURATION, View.VISIBLE);
95 | mIsTheTitleVisible = true;
96 | }
97 | } else {
98 | if (mIsTheTitleVisible) {
99 | startAlphaAnimation(toolbar, ALPHA_ANIMATIONS_DURATION, View.INVISIBLE);
100 | mIsTheTitleVisible = false;
101 | }
102 | }
103 | }
104 | @Override
105 | public void onClick(View v) {
106 | if(getActivity() instanceof aboutAuthorDrawerIconListener){
107 | ((aboutAuthorDrawerIconListener) getActivity()).aboutAuthorDrawerIcon();
108 | }
109 | }
110 | public void initFabListener(){
111 | floatingActionButton.setOnClickListener(new View.OnClickListener() {
112 | @Override
113 | public void onClick(View v) {
114 | Uri uri=Uri.parse("https://github.com/sakurajiang");
115 | Intent intent=new Intent(Intent.ACTION_VIEW,uri);
116 | startActivity(intent);
117 | }
118 |
119 | });
120 | }
121 | public void initWidget(){
122 | String html=getResources().getString(R.string.plus_a_litter_content);
123 | music_link_tv.setText(Html.fromHtml(html));
124 | // music_link_tv.setText(getText(R.string.plus_a_litter_content));
125 | music_link_tv.setMovementMethod(LinkMovementMethod.getInstance());
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Fragment/AboutProjectFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Fragment;
2 |
3 | import android.content.Intent;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.design.widget.AppBarLayout;
8 | import android.support.design.widget.FloatingActionButton;
9 | import android.support.v4.app.Fragment;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.support.v7.widget.Toolbar;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.view.animation.AlphaAnimation;
16 | import android.widget.TextView;
17 |
18 | import com.example.jdk.restapp.BuildConfig;
19 | import com.example.jdk.restapp.R;
20 |
21 | import butterknife.Bind;
22 | import butterknife.ButterKnife;
23 |
24 | /**
25 | * Created by JDK on 2016/9/9.
26 | */
27 | public class AboutProjectFragment extends Fragment implements View.OnClickListener,AppBarLayout.OnOffsetChangedListener{
28 | @Bind(R.id.app_bar)
29 | AppBarLayout appBarLayout;
30 | @Bind(R.id.tool_bar)
31 | Toolbar toolbar;
32 | @Bind(R.id.tv_app_version)
33 | TextView version_tv;
34 | @Bind(R.id.fab)
35 | FloatingActionButton floatingActionButton;
36 | private static final float PERCENTAGE_TO_SHOW_TITLE_AT_TOOLBAR = 0.9f;
37 | private static final int ALPHA_ANIMATIONS_DURATION = 200;
38 | private boolean mIsTheTitleVisible = false;
39 | private static AboutProjectFragment aboutProjectFragment;
40 | private AppCompatActivity appCompatActivity;
41 | private View v;
42 | @Override
43 | public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
44 | int maxScroll = appBarLayout.getTotalScrollRange();
45 | float percentage = (float) Math.abs(verticalOffset) / (float) maxScroll;
46 | if (percentage >= 0.5f) {
47 | toolbar.setNavigationIcon(R.drawable.ic_navigation_30dp);
48 | }
49 | handleToolbarTitleVisibility(percentage);
50 | }
51 |
52 |
53 | public interface aboutProjectDrawerIconListener{
54 | public void aboutProjectDrawerIcon();
55 | }
56 | public static AboutProjectFragment newInstance(){
57 | if( aboutProjectFragment ==null){
58 | aboutProjectFragment =new AboutProjectFragment();
59 | }
60 | return aboutProjectFragment;
61 | }
62 | @Nullable
63 | @Override
64 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
65 | if(v!=null){
66 | ButterKnife.bind(this,v);
67 | return v;
68 | }
69 | v=inflater.inflate(R.layout.fragment_about_project,container,false);
70 | ButterKnife.bind(this, v);
71 | version_tv.setText(getResources().getString(R.string.app_version) + " " + BuildConfig.VERSION_NAME);
72 | appBarLayout.addOnOffsetChangedListener(this);
73 | initFabListener();
74 | appCompatActivity=((AppCompatActivity) getActivity());
75 | appCompatActivity.setSupportActionBar(toolbar);
76 | toolbar.setNavigationOnClickListener(this);
77 | return v;
78 | }
79 | // 设置渐变的动画
80 | public static void startAlphaAnimation(View v, long duration, int visibility) {
81 | AlphaAnimation alphaAnimation = (visibility == View.VISIBLE)
82 | ? new AlphaAnimation(0f, 1f)
83 | : new AlphaAnimation(1f, 0f);
84 |
85 | alphaAnimation.setDuration(duration);
86 | alphaAnimation.setFillAfter(true);
87 | v.startAnimation(alphaAnimation);
88 | }
89 | // 处理ToolBar的显示
90 | private void handleToolbarTitleVisibility(float percentage) {
91 | if (percentage >= PERCENTAGE_TO_SHOW_TITLE_AT_TOOLBAR) {
92 | if (!mIsTheTitleVisible) {
93 | startAlphaAnimation(toolbar, ALPHA_ANIMATIONS_DURATION, View.VISIBLE);
94 | mIsTheTitleVisible = true;
95 | }
96 | } else {
97 | if (mIsTheTitleVisible) {
98 | startAlphaAnimation(toolbar, ALPHA_ANIMATIONS_DURATION, View.INVISIBLE);
99 | mIsTheTitleVisible = false;
100 | }
101 | }
102 | }
103 | @Override
104 | public void onClick(View v) {
105 | if (getActivity() instanceof aboutProjectDrawerIconListener) {
106 | ((aboutProjectDrawerIconListener) getActivity()).aboutProjectDrawerIcon();
107 | }
108 | }
109 | public void initFabListener(){
110 | floatingActionButton.setOnClickListener(new View.OnClickListener() {
111 | @Override
112 | public void onClick(View v) {
113 | Uri uri = Uri.parse("https://github.com/sakurajiang/RestAPP");
114 | Intent intent = new Intent(Intent.ACTION_VIEW,uri);
115 | startActivity(intent);
116 | }
117 | });
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Fragment/AndroidFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Fragment;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.example.jdk.restapp.HttpUtils.RequestData;
12 | import com.example.jdk.restapp.HttpUtils.ReturnRetrofit;
13 | import com.example.jdk.restapp.ModelData.entity.Base;
14 | import com.example.jdk.restapp.R;
15 | import com.example.jdk.restapp.Utils.MyDecoration;
16 | import com.example.jdk.restapp.Utils.SPDataUtil;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | import rx.Observable;
22 |
23 | /**
24 | * Created by JDK on 2016/8/4.
25 | */
26 | public class AndroidFragment extends BaseFragment {
27 | private List androidList;
28 | static Context mContext;
29 | private boolean isCache=false;
30 |
31 | public AndroidFragment() {
32 | super(R.layout.fragment_watch_android);
33 | }
34 | public static AndroidFragment newInstance(Context context){
35 | AndroidFragment androidFragment=new AndroidFragment();
36 | mContext = context;
37 | return androidFragment;
38 | }
39 | @Override
40 | public void onAttach(Context context) {
41 | super.onAttach(context);
42 | }
43 |
44 | @Override
45 | public void onDetach() {
46 | super.onDetach();
47 | }
48 |
49 | @Override
50 | public void onPause() {
51 | super.onPause();
52 | }
53 |
54 | @Override
55 | public void onDestroy() {
56 | super.onDestroy();
57 | }
58 |
59 |
60 |
61 | @Override
62 | public void onStart() {
63 | super.onStart();
64 | }
65 |
66 | @Override
67 | public void onStop() {
68 | super.onStop();
69 | }
70 | @Override
71 | public void onCreate(@Nullable Bundle savedInstanceState) {
72 | super.onCreate(savedInstanceState);
73 | androidList=SPDataUtil.getFirstPageGirls(getString(R.string.sharedPreferences_android),mContext);
74 | if(androidList!=null&&androidList.size()!=0){
75 | isCache=true;
76 | }else {
77 | androidList = new ArrayList<>();
78 | }
79 |
80 | }
81 |
82 | @Nullable
83 | @Override
84 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
85 | return super.onCreateView(inflater, container, savedInstanceState);
86 | }
87 |
88 | @Override
89 | public void getData(int page) {
90 | setSubscriber(page,false);
91 | }
92 | @Override
93 | public void setSubscriber(int page,boolean isRefresh){
94 | if(isRefresh) {
95 | SPDataUtil.saveFirstPageGirls(mContext,androidList);
96 | androidList.clear();
97 | }
98 | RequestData.getInstance(mContext).requestAndroidData(ReturnRetrofit.getInstance().getMyGankApiRetrofit().getWatchAndroidData(page),getMyRecyclerView(),page,androidList,isFirst(),false,isCache);
99 | isCache=false;
100 | }
101 | @Override
102 | public void onResume() {
103 | super.onResume();
104 | }
105 |
106 | @Override
107 | public void onDestroyView() {
108 | super.onDestroyView();
109 | }
110 |
111 | @Override
112 | public void setUserVisibleHint(boolean isVisibleToUser) {
113 | super.setUserVisibleHint(isVisibleToUser);
114 | if(isVisibleToUser) {
115 | RequestData.getInstance(mContext).setSHProgressinterface(this);
116 | }
117 |
118 | }
119 |
120 | @Override
121 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
122 | super.onActivityCreated(savedInstanceState);
123 | getMyRecyclerView().setLayoutManager(new LinearLayoutManager(mContext));
124 | getMyRecyclerView().addItemDecoration(new MyDecoration(getActivity(), MyDecoration.VERTICAL_LIST));
125 | getData(1);
126 | InitListener();
127 | }
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Fragment/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Fragment;
2 |
3 |
4 |
5 |
6 | import android.content.Context;
7 | import android.os.Bundle;
8 | import android.support.annotation.Nullable;
9 | import android.support.v4.app.Fragment;
10 | import android.support.v4.widget.SwipeRefreshLayout;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 |
15 | import com.example.jdk.restapp.CustomizedWidget.LoadMoreRecyclerView;
16 | import com.example.jdk.restapp.HttpUtils.RequestData;
17 | import com.example.jdk.restapp.R;
18 |
19 | import butterknife.Bind;
20 | import butterknife.ButterKnife;
21 | import rx.Observable;
22 | import rx.Subscriber;
23 | import rx.android.schedulers.AndroidSchedulers;
24 | import rx.functions.Action1;
25 | import rx.schedulers.Schedulers;
26 |
27 |
28 | /**
29 | * Created by JDK on 2016/8/4.
30 | */
31 | //这个BaseFragment主要实现了下拉刷新和上拉加载
32 | public abstract class BaseFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener,LoadMoreRecyclerView.LoadMoreListener,RequestData.shProgressinterface {
33 | @Bind(R.id.swipe_refresh_layout)
34 | SwipeRefreshLayout swipeRefreshLayout;
35 | @Bind(R.id.LM_RecyclerView)
36 | LoadMoreRecyclerView mLMRecyclerView;
37 | //判断是第一次加载数据还是后面的更新数据
38 | private boolean isFirst=true;
39 | private int mLayout_Id;
40 | private int t=1;
41 | private View v;
42 |
43 | public BaseFragment(int layout_Id){
44 | this.mLayout_Id=layout_Id;
45 | }
46 |
47 | public boolean isFirst() {
48 | return isFirst;
49 | }
50 |
51 | public void setIsFirst(boolean isFirst) {
52 | this.isFirst = isFirst;
53 | }
54 |
55 | public LoadMoreRecyclerView getMyRecyclerView() {
56 | return mLMRecyclerView;
57 | }
58 |
59 | public void setLoadMoreRecyclerView(LoadMoreRecyclerView LMRecyclerView) {
60 | this.mLMRecyclerView = LMRecyclerView;
61 | }
62 |
63 | @Override
64 | public void setUserVisibleHint(boolean isVisibleToUser) {
65 | super.setUserVisibleHint(isVisibleToUser);
66 | }
67 |
68 | @Override
69 | public void onAttach(Context context) {
70 | super.onAttach(context);
71 | }
72 |
73 | @Override
74 | public void onCreate(@Nullable Bundle savedInstanceState) {
75 | super.onCreate(savedInstanceState);
76 | }
77 |
78 | @Override
79 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
80 | super.onActivityCreated(savedInstanceState);
81 | }
82 |
83 | @Override
84 | public void onDestroyView() {
85 | super.onDestroyView();
86 |
87 | }
88 |
89 | @Override
90 | public void onDetach() {
91 | super.onDetach();
92 | }
93 |
94 | @Override
95 | public void onPause() {
96 | super.onPause();
97 | }
98 |
99 | @Override
100 | public void onDestroy() {
101 | super.onDestroy();
102 | }
103 |
104 | @Override
105 | public void onResume() {
106 | super.onResume();
107 | }
108 |
109 | @Override
110 | public void onStart() {
111 | super.onStart();
112 | }
113 |
114 | @Override
115 | public void onStop() {
116 | super.onStop();
117 | }
118 |
119 | @Nullable
120 | @Override
121 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
122 | if(v!=null){
123 | ButterKnife.bind(this,v);
124 | return v;
125 | }
126 | v = inflater.inflate(mLayout_Id, container, false);
127 | ButterKnife.bind(this, v);
128 | setLoadMoreRecyclerView(mLMRecyclerView);
129 | return v;
130 | }
131 | public abstract void getData(int page);
132 | public abstract void setSubscriber(int page,boolean isRefersh);
133 | public void InitListener(){
134 | mLMRecyclerView.setLoadMoreListener(this);
135 | swipeRefreshLayout.setColorSchemeResources(R.color.red, R.color.green, R.color.blue);
136 | swipeRefreshLayout.setOnRefreshListener(this);
137 | }
138 | @Override
139 | public void onRefresh() {
140 | setIsFirst(false);
141 | setSubscriber(1,true);
142 | }
143 |
144 | @Override
145 | public void loadMore() {
146 | setIsFirst(false);
147 | t++;
148 | setSubscriber(t,false);
149 | }
150 |
151 | @Override
152 | public void hideProgress() {
153 | if (swipeRefreshLayout.isRefreshing())
154 | swipeRefreshLayout.setRefreshing(false);
155 | }
156 | @Override
157 | public void showProgress() {
158 | if (!swipeRefreshLayout.isRefreshing())
159 | swipeRefreshLayout.setRefreshing(true);
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Fragment/CollectionFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Fragment;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.Typeface;
6 | import android.os.Bundle;
7 | import android.support.annotation.Nullable;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.TextView;
13 |
14 | import com.example.jdk.restapp.Activity.ShowWebViewActivity;
15 | import com.example.jdk.restapp.Adapter.RecyclerViewDataAdapter;
16 |
17 | import com.example.jdk.restapp.BR;
18 | import com.example.jdk.restapp.DataBase.MySQLiteWebViewTextBussiness;
19 | import com.example.jdk.restapp.ModelData.entity.Base;
20 | import com.example.jdk.restapp.ModelData.entity.URLTableData;
21 | import com.example.jdk.restapp.R;
22 | import com.example.jdk.restapp.Utils.MyDecoration;
23 | import com.example.jdk.restapp.Utils.SnackBarUtils;
24 |
25 | import java.util.ArrayList;
26 | import java.util.Date;
27 | import java.util.List;
28 |
29 | import butterknife.Bind;
30 | import butterknife.ButterKnife;
31 |
32 | /**
33 | * Created by JDK on 2016/8/13.
34 | */
35 | public class CollectionFragment extends BaseFragment implements View.OnClickListener{
36 | @Bind(R.id.drawerIcon)
37 | TextView drawerIcon_tv;
38 | private static Context mContext;
39 | private List myList;
40 | private MySQLiteWebViewTextBussiness mySQLiteWebViewTextBussiness;
41 | private View v;
42 | private RecyclerViewDataAdapter recyclerViewDataAdapter;
43 | private final int collectionLayoutIdArray[]={R.layout.collection_item};
44 | public interface collectionDrawerIconListener{
45 | public void collectionDrawerIcon();
46 | }
47 | public CollectionFragment() {
48 | super(R.layout.fragment_my_collection);
49 | }
50 |
51 | @Nullable
52 | @Override
53 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
54 | if(v!=null){
55 | ButterKnife.bind(this,v);
56 | return v;
57 | }
58 | v=super.onCreateView(inflater, container, savedInstanceState);
59 | ButterKnife.bind(this,v);
60 | Typeface typeface = Typeface.createFromAsset(getActivity().getAssets(), "iconfont.ttf");
61 | drawerIcon_tv.setTypeface(typeface);
62 | return v;
63 | }
64 |
65 | public static CollectionFragment newInstance(Context context){
66 | CollectionFragment collectionFragment=new CollectionFragment();
67 | mContext=context;
68 | return collectionFragment;
69 | }
70 | @Override
71 | public void onCreate(@Nullable Bundle savedInstanceState) {
72 | super.onCreate(savedInstanceState);
73 | mySQLiteWebViewTextBussiness=new MySQLiteWebViewTextBussiness(getActivity());
74 | }
75 |
76 | @Override
77 | public void onResume() {
78 | super.onResume();
79 | getData(1);
80 | drawerIcon_tv.setOnClickListener(this);
81 | }
82 |
83 | @Override
84 | public void getData(int page) {
85 | List urlTableDataList=mySQLiteWebViewTextBussiness.queryAllFromTable();
86 | myList=new ArrayList<>();
87 | for(int i=0;i1) {
124 | SnackBarUtils.makeShort(getActivity().getWindow().getDecorView(), getResources().getString(R.string.collection_loadmore_footer)).danger();
125 | }else{
126 | SnackBarUtils.makeShort(getActivity().getWindow().getDecorView(), getResources().getString(R.string.collection_refresh_header)).danger();
127 | swipeRefreshLayout.setRefreshing(false);
128 | }
129 | }
130 |
131 | @Override
132 | public void setUserVisibleHint(boolean isVisibleToUser) {
133 | super.setUserVisibleHint(isVisibleToUser);
134 |
135 | }
136 |
137 | @Override
138 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
139 | super.onActivityCreated(savedInstanceState);
140 | getMyRecyclerView().setLayoutManager(new LinearLayoutManager(mContext));
141 | getMyRecyclerView().addItemDecoration(new MyDecoration(getActivity(), MyDecoration.VERTICAL_LIST));
142 | InitListener();
143 | }
144 |
145 | @Override
146 | public void onClick(View v) {
147 | if(getActivity() instanceof collectionDrawerIconListener){
148 | ((collectionDrawerIconListener) getActivity()).collectionDrawerIcon();
149 | }
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Fragment/FrontFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Fragment;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.example.jdk.restapp.HttpUtils.RequestData;
12 | import com.example.jdk.restapp.HttpUtils.ReturnRetrofit;
13 | import com.example.jdk.restapp.ModelData.entity.Base;
14 | import com.example.jdk.restapp.ModelData.entity.Front;
15 | import com.example.jdk.restapp.R;
16 | import com.example.jdk.restapp.Utils.MyDecoration;
17 | import com.example.jdk.restapp.Utils.SPDataUtil;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | /**
23 | * Created by JDK on 2016/8/10.
24 | */
25 | public class FrontFragment extends BaseFragment {
26 | private List frontList;
27 | private static Context mContext;
28 | private boolean isCache=false;
29 | public FrontFragment() {
30 | super(R.layout.fragment_watch_front);
31 | }
32 | public static FrontFragment newInstance(Context context){
33 | FrontFragment frontFragment=new FrontFragment();
34 | mContext=context;
35 | return frontFragment;
36 | }
37 |
38 | @Override
39 | public void onAttach(Context context) {
40 | super.onAttach(context);
41 | }
42 | @Override
43 | public void onDetach() {
44 | super.onDetach();
45 | }
46 |
47 | @Override
48 | public void onPause() {
49 | super.onPause();
50 | }
51 |
52 | @Override
53 | public void onDestroy() {
54 | super.onDestroy();
55 | }
56 |
57 | @Override
58 | public void onResume() {
59 | super.onResume();
60 | }
61 |
62 | @Override
63 | public void onStart() {
64 | super.onStart();
65 | }
66 |
67 | @Override
68 | public void onStop() {
69 | super.onStop();
70 | }
71 | @Override
72 | public void setUserVisibleHint(boolean isVisibleToUser) {
73 | super.setUserVisibleHint(isVisibleToUser);
74 | if(isVisibleToUser){
75 | RequestData.getInstance(mContext).setSHProgressinterface(this);
76 | }
77 |
78 | }@Override
79 | public void onCreate(@Nullable Bundle savedInstanceState) {
80 | super.onCreate(savedInstanceState);
81 | frontList =SPDataUtil.getFirstPageGirls(getString(R.string.sharedPreferences_front),mContext);
82 | if(frontList !=null&& frontList.size()!=0){
83 | isCache=true;
84 | }else {
85 | frontList = new ArrayList<>();
86 | }
87 | }
88 | @Override
89 | public void onDestroyView() {
90 | super.onDestroyView();
91 | }
92 | @Nullable
93 | @Override
94 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
95 | return super.onCreateView(inflater, container, savedInstanceState);
96 | }
97 |
98 | @Override
99 | public void getData(int page) {
100 | setSubscriber(page,false);
101 | }
102 | public void setSubscriber(int page,boolean isRefresh){
103 | if(isRefresh) {
104 | SPDataUtil.saveFirstPageGirls(mContext, frontList);
105 | frontList.clear();
106 | }
107 | RequestData.getInstance(mContext).requestFrontData(ReturnRetrofit.getInstance().getMyGankApiRetrofit().getWatchFrontData(page), getMyRecyclerView(), page, frontList,isFirst(),false,isCache);
108 | isCache=false;
109 |
110 | }
111 | @Override
112 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
113 | super.onActivityCreated(savedInstanceState);
114 | getMyRecyclerView().setLayoutManager(new LinearLayoutManager(mContext));
115 | getMyRecyclerView().addItemDecoration(new MyDecoration(getActivity(), MyDecoration.VERTICAL_LIST));
116 | getData(1);
117 | InitListener();
118 | }
119 |
120 |
121 |
122 | }
123 |
124 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Fragment/MeiziFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Fragment;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.StaggeredGridLayoutManager;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 |
12 | import com.example.jdk.restapp.HttpUtils.RequestData;
13 | import com.example.jdk.restapp.HttpUtils.ReturnRetrofit;
14 | import com.example.jdk.restapp.ModelData.entity.Base;
15 | import com.example.jdk.restapp.R;
16 | import com.example.jdk.restapp.Utils.SPDataUtil;
17 |
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | /**
23 | * Created by JDK on 2016/8/4.
24 | */
25 | public class MeiziFragment extends BaseFragment {
26 | private static Context mContext;
27 | private List meiziList;
28 | private boolean isCache=false;
29 | public MeiziFragment() {
30 | super(R.layout.fragment_watch_meizi);
31 | }
32 | public static MeiziFragment newInstance(Context context){
33 | MeiziFragment meiziFragment=new MeiziFragment();
34 | mContext=context;
35 | return meiziFragment;
36 | }
37 |
38 | @Override
39 | public void onAttach(Context context) {
40 | super.onAttach(context);
41 | }
42 |
43 | @Override
44 | public void onCreate(Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | meiziList=SPDataUtil.getFirstPageGirls(getString(R.string.sharedPreferences_picture),mContext);
47 | if(meiziList!=null&&meiziList.size()!=0) {
48 | isCache=true;
49 | }else{
50 | meiziList = new ArrayList<>();
51 | }
52 |
53 | }
54 | @Nullable
55 | @Override
56 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
57 | return super.onCreateView(inflater, container, savedInstanceState);
58 | }
59 | @Override
60 | public void onDestroyView() {
61 | super.onDestroyView();
62 |
63 | }
64 |
65 | @Override
66 | public void onDetach() {
67 | super.onDetach();
68 | }
69 |
70 | @Override
71 | public void onPause() {
72 | super.onPause();
73 | }
74 |
75 | @Override
76 | public void onDestroy() {
77 | super.onDestroy();
78 | }
79 |
80 | @Override
81 | public void onResume() {
82 | super.onResume();
83 | }
84 |
85 | @Override
86 | public void onStart() {
87 | super.onStart();
88 | }
89 |
90 | @Override
91 | public void onStop() {
92 | super.onStop();
93 | }
94 |
95 | @Override
96 | public void getData(final int page) {
97 | setSubscriber(page,false);
98 | }
99 | public void setSubscriber(final int page,boolean isRefresh){
100 | if(isRefresh) {
101 | SPDataUtil.saveFirstPageGirls(mContext, meiziList);
102 | meiziList.clear();
103 | }
104 | RequestData.getInstance(mContext).requestMeiziData(ReturnRetrofit.getInstance().getMyGankApiRetrofit().getWatchMeiziData(page),
105 | ReturnRetrofit.getInstance().getMyGankApiRetrofit().getWatchRestVideoData(page), getMyRecyclerView(), page, meiziList, isFirst(), false,isCache);
106 | isCache=false;
107 | }
108 | @Override
109 | public void setUserVisibleHint(boolean isVisibleToUser) {
110 | super.setUserVisibleHint(isVisibleToUser);
111 | if(isVisibleToUser) {
112 | RequestData.getInstance(mContext).setSHProgressinterface(this);
113 | }
114 |
115 | }
116 | @Override
117 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
118 | super.onActivityCreated(savedInstanceState);
119 | StaggeredGridLayoutManager staggeredGridLayoutManager=new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
120 | staggeredGridLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
121 | getMyRecyclerView().setLayoutManager(new LinearLayoutManager(getActivity()));
122 | InitListener();
123 | swipeRefreshLayout.post(new Runnable() {
124 | @Override
125 | public void run() {
126 | swipeRefreshLayout.setRefreshing(true);
127 | setSubscriber(1, false);
128 | }
129 | });
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Fragment/ShakeAndroidFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Fragment;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.example.jdk.restapp.HttpUtils.RequestData;
12 | import com.example.jdk.restapp.HttpUtils.ReturnRetrofit;
13 | import com.example.jdk.restapp.R;
14 | import com.example.jdk.restapp.Utils.MyDecoration;
15 | import com.example.jdk.restapp.Utils.SnackBarUtils;
16 |
17 | /**
18 | * Created by JDK on 2016/8/4.
19 | */
20 | public class ShakeAndroidFragment extends BaseFragment{
21 | static Context mContext;
22 | public ShakeAndroidFragment() {
23 | super(R.layout.fragment_shake_android);
24 | }
25 | public static ShakeAndroidFragment newInstance(Context context){
26 | ShakeAndroidFragment androidFragment=new ShakeAndroidFragment();
27 | mContext = context;
28 | return androidFragment;
29 | }
30 |
31 | @Override
32 | public void onCreate(@Nullable Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 |
35 | }
36 |
37 | @Nullable
38 | @Override
39 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
40 | return super.onCreateView(inflater, container, savedInstanceState);
41 | }
42 |
43 | @Override
44 | public void getData(int page) {
45 | setSubscriber(page,false);
46 | }
47 | public void setSubscriber(int page,boolean isRefresh){
48 | if(isRefresh)
49 | swipeRefreshLayout.setRefreshing(false);
50 | if(page>1) {
51 | SnackBarUtils.makeLong(getActivity().getWindow().getDecorView(), getResources().getString(R.string.shake_loadmore_footer)).danger();
52 | return;
53 | }else if(page==1){
54 | SnackBarUtils.makeLong(getActivity().getWindow().getDecorView(), getResources().getString(R.string.shake_refresh_header)).danger();
55 | return;
56 | }
57 | RequestData.getInstance(mContext).requestAndroidData(ReturnRetrofit.getInstance().getMyGankApiRetrofit().getShakeAndroidData(), getMyRecyclerView(), page, null, isFirst(), true,false);
58 |
59 | }
60 |
61 | @Override
62 | public void onResume() {
63 | super.onResume();
64 | }
65 |
66 | @Override
67 | public void onDestroyView() {
68 | super.onDestroyView();
69 | }
70 | @Override
71 | public void setUserVisibleHint(boolean isVisibleToUser) {
72 | super.setUserVisibleHint(isVisibleToUser);
73 | }
74 | @Override
75 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
76 | super.onActivityCreated(savedInstanceState);
77 | getMyRecyclerView().setLayoutManager(new LinearLayoutManager(mContext));
78 | getMyRecyclerView().addItemDecoration(new MyDecoration(getActivity(),MyDecoration.VERTICAL_LIST));
79 | getData(0);
80 | InitListener();
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Fragment/ShakeFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Fragment;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.design.widget.TabLayout;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v4.app.FragmentManager;
9 | import android.support.v4.app.FragmentPagerAdapter;
10 | import android.support.v4.view.ViewPager;
11 | import android.util.Log;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.Toast;
16 |
17 | import com.example.jdk.restapp.R;
18 | import com.example.jdk.restapp.Utils.ShakeUtils;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | import butterknife.Bind;
24 | import butterknife.ButterKnife;
25 |
26 | public class ShakeFragment extends Fragment implements ShakeUtils.onMySensorChangedListener{
27 | @Bind(R.id.myViewPager)
28 | ViewPager myViewPager;
29 | @Bind(R.id.watch_tl)
30 | TabLayout myTabLayout;
31 | Fragment shakeMeiziFragment;
32 | Fragment shakeAndroidFragment;
33 | Fragment shakeFrontFragment;
34 | List fragmentList=new ArrayList(3);;
35 | private List mTitleList = new ArrayList<>(3);
36 | private final int page=0;
37 | private static Context mContext;
38 | private ShakeUtils shakeUtils;
39 | private boolean isCreateView;
40 | private View v;
41 | static ShakeFragment shakeFragment;
42 | int t;
43 | public static ShakeFragment getInstance(Context context){
44 | if( shakeFragment==null){
45 | shakeFragment=new ShakeFragment();
46 | }
47 | mContext=context;
48 | return shakeFragment;
49 | }
50 | @Nullable
51 | @Override
52 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
53 | if(v!=null){
54 | ButterKnife.bind(this,v);
55 | return v;
56 | }
57 | v=inflater.inflate(R.layout.paf_fragment_layout,container,false);
58 | ButterKnife.bind(this,v);
59 | isCreateView=true;
60 | return v;
61 | }
62 |
63 | @Override
64 | public void setUserVisibleHint(boolean isVisibleToUser) {
65 | if(getActivity()!=null) {
66 | if (isVisibleToUser) {
67 | shakeUtils = new ShakeUtils(getActivity());
68 | shakeUtils.setOnMySensorChangedListener(this);
69 | shakeUtils.registerSensor();
70 | } else {
71 | if(shakeUtils!=null) {
72 | shakeUtils.unRegisterSensor();
73 | }
74 | }
75 | }
76 | if(isVisibleToUser&&isCreateView){
77 | InitVariable();
78 | MyAdapter myAdapter = new MyAdapter(getChildFragmentManager());
79 | myAdapter.notifyDataSetChanged();
80 | myViewPager.setOffscreenPageLimit(2);
81 | myViewPager.setCurrentItem(0);
82 | myViewPager.setAdapter(myAdapter);
83 | myTabLayout.setTabMode(TabLayout.MODE_FIXED);
84 | myTabLayout.setupWithViewPager(myViewPager);
85 | isCreateView=false;
86 | }
87 | super.setUserVisibleHint(isVisibleToUser);
88 |
89 | }
90 | @Override
91 | public void onPause() {
92 | super.onPause();
93 | }
94 | public void InitVariable(){
95 | mTitleList.add("Picture");
96 | mTitleList.add("Android");
97 | mTitleList.add("Front");
98 | shakeMeiziFragment=ShakeMeiziFragment.newInstance(getActivity());
99 | shakeAndroidFragment=ShakeAndroidFragment.newInstance(getActivity());
100 | shakeFrontFragment=ShakeFrontFragment.newInstance(getActivity());
101 | fragmentList.add(shakeMeiziFragment);
102 | fragmentList.add(shakeAndroidFragment);
103 | fragmentList.add(shakeFrontFragment);
104 | }
105 | @Override
106 | public void onMySensorChanged() {
107 | Toast.makeText(mContext,getString(R.string.shake_and_shake),Toast.LENGTH_SHORT).show();
108 | if(shakeMeiziFragment.getUserVisibleHint()){
109 | ((ShakeMeiziFragment) shakeMeiziFragment).setSubscriber(page,false);
110 | }
111 | if(shakeAndroidFragment.getUserVisibleHint()){
112 | ((ShakeAndroidFragment)shakeAndroidFragment).setSubscriber(page,false);
113 | }
114 | if(shakeFrontFragment.getUserVisibleHint()){
115 | ((ShakeFrontFragment)shakeFrontFragment).setSubscriber(page,false);
116 | }
117 | }
118 |
119 | class MyAdapter extends FragmentPagerAdapter {
120 |
121 | public MyAdapter(FragmentManager fm) {
122 | super(fm);
123 | }
124 |
125 | @Override
126 | public Fragment getItem(int position) {
127 | return fragmentList.get(position);
128 | }
129 |
130 | @Override
131 | public int getCount() {
132 | return fragmentList.size();
133 | }
134 |
135 |
136 | @Override
137 | public CharSequence getPageTitle(int position) {
138 | return mTitleList.get(position);
139 | }
140 |
141 | @Override
142 | public void destroyItem(ViewGroup container, int position, Object object) {
143 | super.destroyItem(container, position, object);
144 | }
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Fragment/ShakeFrontFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Fragment;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.example.jdk.restapp.HttpUtils.RequestData;
12 | import com.example.jdk.restapp.HttpUtils.ReturnRetrofit;
13 | import com.example.jdk.restapp.ModelData.entity.Base;
14 | import com.example.jdk.restapp.R;
15 | import com.example.jdk.restapp.Utils.MyDecoration;
16 | import com.example.jdk.restapp.Utils.SnackBarUtils;
17 |
18 | import java.util.List;
19 |
20 | /**
21 | * Created by JDK on 2016/8/10.
22 | */
23 | public class ShakeFrontFragment extends BaseFragment {
24 | private List myList;
25 | private static Context mContext;
26 | public ShakeFrontFragment() {
27 | super(R.layout.fragment_shake_front);
28 | }
29 | public static ShakeFrontFragment newInstance(Context context){
30 | ShakeFrontFragment frontFragment=new ShakeFrontFragment();
31 | mContext=context;
32 | return frontFragment;
33 | }
34 | @Override
35 | public void onCreate(@Nullable Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | }
38 | @Override
39 | public void onDestroyView() {
40 | super.onDestroyView();
41 | }
42 | @Nullable
43 | @Override
44 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
45 | return super.onCreateView(inflater, container, savedInstanceState);
46 | }
47 |
48 | @Override
49 | public void getData(int page) {
50 | setSubscriber(page,false);
51 | }
52 | public void setSubscriber(int page,boolean isRefresh){
53 | // if(isRefresh)
54 | swipeRefreshLayout.setRefreshing(false);
55 | if(page>1) {
56 | SnackBarUtils.makeLong(getActivity().getWindow().getDecorView(), getResources().getString(R.string.shake_loadmore_footer)).danger();
57 | return;
58 | }else if(page==1){
59 | SnackBarUtils.makeLong(getActivity().getWindow().getDecorView(), getResources().getString(R.string.shake_refresh_header)).danger();
60 | return;
61 | }
62 | RequestData.getInstance(mContext).requestFrontData( ReturnRetrofit.getInstance().getMyGankApiRetrofit().getShakeFrontData(),getMyRecyclerView(),page,null,isFirst(),true,false);
63 | }
64 | @Override
65 | public void setUserVisibleHint(boolean isVisibleToUser) {
66 | super.setUserVisibleHint(isVisibleToUser);
67 | }
68 | @Override
69 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
70 | super.onActivityCreated(savedInstanceState);
71 | getMyRecyclerView().setLayoutManager(new LinearLayoutManager(mContext));
72 | getMyRecyclerView().addItemDecoration(new MyDecoration(getActivity(), MyDecoration.VERTICAL_LIST));
73 | getData(0);
74 | InitListener();
75 | }
76 |
77 |
78 |
79 | }
80 |
81 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Fragment/ShakeMeiziFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Fragment;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.StaggeredGridLayoutManager;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 |
12 | import com.example.jdk.restapp.HttpUtils.RequestData;
13 | import com.example.jdk.restapp.HttpUtils.ReturnRetrofit;
14 | import com.example.jdk.restapp.R;
15 | import com.example.jdk.restapp.Utils.SnackBarUtils;
16 |
17 | /**
18 | * Created by JDK on 2016/8/4.
19 | */
20 | public class ShakeMeiziFragment extends BaseFragment implements RequestData.shProgressinterfaceofShake{
21 | private static Context mContext;
22 | public ShakeMeiziFragment() {
23 | super(R.layout.fragment_shake_meizi);
24 | }
25 | public static ShakeMeiziFragment newInstance(Context context){
26 | ShakeMeiziFragment meiziFragment=new ShakeMeiziFragment();
27 | mContext=context;
28 | return meiziFragment;
29 | }
30 | @Override
31 | public void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 |
34 | }
35 | @Nullable
36 | @Override
37 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
38 | return super.onCreateView(inflater, container, savedInstanceState);
39 | }
40 | @Override
41 | public void onDestroyView() {
42 | super.onDestroyView();
43 |
44 | }
45 |
46 | @Override
47 | public void onPause() {
48 | super.onPause();
49 | }
50 |
51 | @Override
52 | public void getData(final int page) {
53 | setSubscriber(page,false);
54 | }
55 |
56 | /**
57 | * 这里的page的作用是用来判断snackbar的显示与否
58 | * @param page
59 | */
60 | public void setSubscriber(final int page,boolean isRefresh){
61 | if(isRefresh)
62 | swipeRefreshLayout.setRefreshing(false);
63 | //这里设置return是因为当在摇一摇界面的时候刷新的话直接跳出,不请求数据,节省流量。
64 | if(page>1) {
65 | SnackBarUtils.makeLong(getActivity().getWindow().getDecorView(), getResources().getString(R.string.shake_loadmore_footer)).danger();
66 | return;
67 | }else if(page==1){
68 | SnackBarUtils.makeLong(getActivity().getWindow().getDecorView(), getResources().getString(R.string.shake_refresh_header)).danger();
69 | return;
70 | }
71 | RequestData.getInstance(mContext).requestMeiziData(ReturnRetrofit.getInstance().getMyGankApiRetrofit().getShakeMeiziData(),
72 | ReturnRetrofit.getInstance().getMyGankApiRetrofit().getShakeRestVideoData(),getMyRecyclerView(),page,null,isFirst(),true,false);
73 |
74 | }
75 |
76 | @Override
77 | public void setUserVisibleHint(boolean isVisibleToUser) {
78 | super.setUserVisibleHint(isVisibleToUser);
79 | if(isVisibleToUser)
80 | RequestData.getInstance(mContext).setSHProgressinterfaceofShake(this);
81 | }
82 | @Override
83 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
84 | super.onActivityCreated(savedInstanceState);
85 | StaggeredGridLayoutManager staggeredGridLayoutManager=new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
86 | staggeredGridLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
87 | getMyRecyclerView().setLayoutManager(new LinearLayoutManager(getActivity()));
88 | InitListener();
89 | swipeRefreshLayout.post(new Runnable() {
90 | @Override
91 | public void run() {
92 | swipeRefreshLayout.setRefreshing(true);
93 | setSubscriber(0, false);
94 | }
95 | });
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/Fragment/WatchFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.Fragment;
2 |
3 | import android.support.annotation.Nullable;
4 | import android.support.design.widget.TabLayout;
5 | import android.support.v4.app.Fragment;
6 |
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.app.FragmentPagerAdapter;
9 | import android.support.v4.app.FragmentStatePagerAdapter;
10 | import android.support.v4.view.ViewPager;
11 | import android.os.Bundle;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 |
16 | import com.example.jdk.restapp.HttpUtils.RequestData;
17 | import com.example.jdk.restapp.R;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import butterknife.Bind;
23 | import butterknife.ButterKnife;
24 |
25 | public class WatchFragment extends Fragment{
26 | @Bind(R.id.myViewPager)
27 | ViewPager myViewPager;
28 | @Bind(R.id.watch_tl)
29 | TabLayout tabLayout;
30 | Fragment meiziFragment;
31 | Fragment androidFragment;
32 | Fragment frontFragment;
33 | List fragmentList;
34 | private List mTitleList = new ArrayList<>(3);
35 | View v;
36 | static WatchFragment watchFragment;
37 | public static WatchFragment getInstance(){
38 | if( watchFragment ==null){
39 | watchFragment =new WatchFragment();
40 | }
41 | return watchFragment;
42 | }
43 | @Nullable
44 | @Override
45 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
46 | if(v!=null){
47 | ButterKnife.bind(this,v);
48 | return v;
49 | }
50 | v=inflater.inflate(R.layout.paf_fragment_layout,container,false);
51 | ButterKnife.bind(this, v);
52 | InitVariable();
53 | MyAdapter myAdapter = new MyAdapter(getChildFragmentManager());
54 | myViewPager.setAdapter(myAdapter);
55 | myViewPager.setOffscreenPageLimit(2);
56 | tabLayout.setTabMode(TabLayout.MODE_FIXED);
57 | tabLayout.setupWithViewPager(myViewPager);
58 | return v;
59 | }
60 |
61 | public void InitVariable(){
62 | mTitleList.add("Picture");
63 | mTitleList.add("Android");
64 | mTitleList.add("Front");
65 | meiziFragment=MeiziFragment.newInstance(getActivity());
66 | androidFragment=AndroidFragment.newInstance(getActivity());
67 | frontFragment=FrontFragment.newInstance(getActivity());
68 | fragmentList=new ArrayList();
69 | fragmentList.add(meiziFragment);
70 | fragmentList.add(androidFragment);
71 | fragmentList.add(frontFragment);
72 | }
73 | @Override
74 | public void setUserVisibleHint(boolean isVisibleToUser) {
75 | super.setUserVisibleHint(isVisibleToUser);
76 | }
77 |
78 | class MyAdapter extends FragmentPagerAdapter {
79 |
80 | public MyAdapter(FragmentManager fm) {
81 | super(fm);
82 | }
83 |
84 | @Override
85 | public Fragment getItem(int position) {
86 | return fragmentList.get(position);
87 | }
88 |
89 | @Override
90 | public int getCount() {
91 | return fragmentList.size();
92 | }
93 |
94 |
95 | @Override
96 | public CharSequence getPageTitle(int position) {
97 | return mTitleList.get(position);
98 | }
99 |
100 | @Override
101 | public void destroyItem(ViewGroup container, int position, Object object) {
102 | super.destroyItem(container, position, object);
103 | }
104 | }
105 |
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/HttpUtils/ReturnRetrofit.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.HttpUtils;
2 |
3 | import com.example.jdk.restapp.ModelData.Constant;
4 | import com.google.gson.Gson;
5 | import com.google.gson.GsonBuilder;
6 |
7 | import retrofit2.Retrofit;
8 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
9 | import retrofit2.converter.gson.GsonConverterFactory;
10 |
11 | /**
12 | * Created by JDK on 2016/8/2.
13 | */
14 | public class ReturnRetrofit {
15 | gankAPI myGankApi;
16 | Retrofit retrofit;
17 | static final ReturnRetrofit returnRetrofit=new ReturnRetrofit();
18 | static Gson gson = new GsonBuilder()
19 | .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
20 | .create();
21 | private ReturnRetrofit(){};
22 | private void createRetrofit(){
23 | retrofit=new Retrofit.Builder()
24 | .baseUrl(Constant.BASE_URL)
25 | .addConverterFactory(GsonConverterFactory.create(gson))
26 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
27 | .build();
28 | }
29 | public static ReturnRetrofit getInstance(){
30 | return returnRetrofit;
31 | }
32 | public gankAPI getMyGankApiRetrofit(){
33 | returnRetrofit.createRetrofit();
34 | myGankApi=retrofit.create(gankAPI.class);
35 | return myGankApi;
36 | }
37 |
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/HttpUtils/gankAPI.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.HttpUtils;
2 |
3 | import com.example.jdk.restapp.ModelData.Constant;
4 | import com.example.jdk.restapp.ModelData.FrontData;
5 | import com.example.jdk.restapp.ModelData.MeiziData;
6 | import com.example.jdk.restapp.ModelData.MyAndroidData;
7 | import com.example.jdk.restapp.ModelData.RestVideoData;
8 |
9 | import retrofit2.http.GET;
10 | import retrofit2.http.Path;
11 | import rx.Observable;
12 |
13 | /**
14 | * Created by JDK on 2016/8/2.
15 | */
16 | public interface gankAPI {
17 | @GET("data/福利/" + Constant.WATCH_MEIZI_SIZE + "/{page}")
18 | Observable getWatchMeiziData(@Path("page") int page);
19 | @GET("data/Android/" +Constant.WATCH_ANDROID_SIZE+ "/{page}")
20 | Observable getWatchAndroidData(@Path("page") int page);
21 | @GET("data/前端/" +Constant.WATCH_FRONT_SIZE+ "/{page}")
22 | Observable getWatchFrontData(@Path("page") int page);
23 | @GET("data/休息视频/"+Constant.WATCH_GANK_SIZE+"/{page}")
24 | Observable getWatchRestVideoData(@Path("page") int page);
25 | @GET("random/data/福利/" + Constant.SHAKE_MEIZI_SIZE )
26 | Observable getShakeMeiziData();
27 | @GET("random/data/Android/" +Constant.SHAKE_ANDROID_SIZE)
28 | Observable getShakeAndroidData( );
29 | @GET("random/data/前端/" +Constant.SHAKE_FRONT_SIZE)
30 | Observable getShakeFrontData( );
31 | @GET("random/data/休息视频/"+Constant.SHAKE_GANK_SIZE)
32 | Observable getShakeRestVideoData();
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/ModelData/BaseData.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.ModelData;
2 |
3 | /**
4 | * Created by JDK on 2016/8/2.
5 | */
6 | public class BaseData {
7 | public boolean error;
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/ModelData/Constant.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.ModelData;
2 |
3 | /**
4 | * Created by JDK on 2016/8/2.
5 | */
6 | public class Constant {
7 | public static final int WATCH_MEIZI_SIZE=10;
8 | public static final int WATCH_ANDROID_SIZE=20;
9 | public static final int WATCH_FRONT_SIZE=20;
10 | public static final int WATCH_GANK_SIZE=10;
11 | public static final int SHAKE_MEIZI_SIZE=2;
12 | public static final int SHAKE_ANDROID_SIZE=8;
13 | public static final int SHAKE_FRONT_SIZE=8;
14 | public static final int SHAKE_GANK_SIZE=2;
15 | public static final int MYDATABASE_VERSION=1;
16 | public static final String BASE_URL="http://gank.io/api/";
17 | public static final String MYDATABASE_NAME="RestAPPDataBase";
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/ModelData/FrontData.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.ModelData;
2 |
3 | import com.example.jdk.restapp.ModelData.entity.Front;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by JDK on 2016/8/10.
9 | */
10 | public class FrontData extends BaseData{
11 | public List results;
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/ModelData/MeiziData.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.ModelData;
2 |
3 | import com.example.jdk.restapp.ModelData.entity.Meizi;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by JDK on 2016/8/2.
9 | */
10 | public class MeiziData extends BaseData{
11 | public List results;
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/ModelData/MyAndroidData.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.ModelData;
2 |
3 | import com.example.jdk.restapp.ModelData.entity.MyAndroid;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by JDK on 2016/8/7.
9 | */
10 | public class MyAndroidData extends BaseData{
11 | public List results;
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/jdk/restapp/ModelData/RestVideoData.java:
--------------------------------------------------------------------------------
1 | package com.example.jdk.restapp.ModelData;
2 |
3 | import com.example.jdk.restapp.ModelData.entity.Video;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by JDK on 2016/8/2.
9 | */
10 | public class RestVideoData extends BaseData{
11 | public List