├── .gitattributes
├── .gitignore
├── README.md
├── app
├── .gitignore
├── app.iml
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── mvp
│ │ └── mobile
│ │ ├── IBaseView
│ │ ├── IBaseView.java
│ │ └── navigation
│ │ │ ├── IMeizhiNavigationCommand.java
│ │ │ └── INavigationCommand.java
│ │ ├── app
│ │ ├── MobileApplication.java
│ │ ├── able
│ │ │ ├── EntryComparable.java
│ │ │ └── SelectionListener.java
│ │ ├── discover
│ │ │ └── DiscoverFragment.java
│ │ ├── lessons
│ │ │ ├── ILessonsPresenter.java
│ │ │ ├── ILessonsView.java
│ │ │ ├── IMeizhiModel.java
│ │ │ ├── LessonsFragment.java
│ │ │ ├── LessonsPresenterImpl.java
│ │ │ └── MeizhiModelImpl.java
│ │ ├── me
│ │ │ └── MeFragment.java
│ │ ├── scheduled
│ │ │ └── ScheduledFragment.java
│ │ └── utils
│ │ │ └── ImageUtils.java
│ │ ├── data
│ │ ├── Entry.java
│ │ ├── EntryList.java
│ │ ├── ListEntry.java
│ │ ├── MeizhiData.java
│ │ └── inject
│ │ │ ├── InjectData.java
│ │ │ └── Injector.java
│ │ ├── model
│ │ ├── base
│ │ │ ├── BaseModel.java
│ │ │ ├── INetModel.java
│ │ │ ├── NetModelImpl.java
│ │ │ └── OnNetModelListener.java
│ │ ├── common
│ │ │ └── IntentAction.java
│ │ ├── net
│ │ │ ├── MobileApi.java
│ │ │ └── WaitCancelListener.java
│ │ └── retrofit
│ │ │ └── RetGankMeizhi.java
│ │ ├── presenter
│ │ ├── BasePresenter.java
│ │ └── BasePresenterImpl.java
│ │ └── ui
│ │ ├── activity
│ │ └── MainActivity.java
│ │ ├── adapter
│ │ └── MeizhiListAdapter.java
│ │ ├── base
│ │ ├── BaseActivity.java
│ │ ├── SwipeRefreshActivity.java
│ │ └── SwipeRefreshFragment.java
│ │ ├── fragment
│ │ └── BaseFragment.java
│ │ └── widget
│ │ └── MultiSwipeRefreshLayout.java
│ └── res
│ ├── drawable-xxxhdpi
│ ├── bb_menu_discover.png
│ ├── bb_menu_lessons.png
│ ├── bb_menu_me.png
│ └── bb_menu_scheduled.png
│ ├── layout
│ ├── activity_main.xml
│ ├── fr_discover.xml
│ ├── fr_lessons.xml
│ ├── fr_me.xml
│ ├── fr_scheduled.xml
│ ├── item_meizhi.xml
│ └── view_home_header.xml
│ ├── menu
│ └── bottombar_menu.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── attrs.xml
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── local.properties
└── 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 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # Windows shortcuts
18 | *.lnk
19 |
20 | # =========================
21 | # Operating System Files
22 | # =========================
23 |
24 | # OSX
25 | # =========================
26 |
27 | .DS_Store
28 | .AppleDouble
29 | .LSOverride
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear in the root of a volume
35 | .DocumentRevisions-V100
36 | .fseventsd
37 | .Spotlight-V100
38 | .TemporaryItems
39 | .Trashes
40 | .VolumeIcon.icns
41 |
42 | # Directories potentially created on remote AFP share
43 | .AppleDB
44 | .AppleDesktop
45 | Network Trash Folder
46 | Temporary Items
47 | .apdisk
48 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Demo-Retrofit-MVP
2 | retrofit2.0.1(okhttp3) + mvp + bottom navigation (material design) + gank.io(api) + fragments
3 |
4 | 更新
5 | 2016.04.27
6 | 抽离P层某些过重的方法,使其更合理,MVP三端代码量再次降低(各端各做自己的事)
7 |
8 | 其他实现:recyclerview + fresco (带下拉刷新和自动加载更多)
9 |
10 | 说明:现学了一些新库和当前流行的 MVP 设计模式做了一个大杂烩,引用了 gank.io 的api 和 bottom navigation 来实现的伪 “tabhost” 项目
11 |
12 | 特色:
13 |
14 | 1.fragment和activity销毁的同时,自动终止该UI上的网络交互。
15 |
16 | 2.M V P三端代码都只需要很少即可实现相关功能。
17 |
18 | 3.其他一些好用的基类请到项目中查看。
19 |
20 | 4.作者认为这个挺好的(殴。
21 |
22 | 欢迎提意见指出改进方法啊!!!意见宝贵感谢感谢>_<
23 |
24 | ==================大家好,我叫分割线=========================
25 |
26 | 以下为借鉴的项目(次序不分先后):
27 |
28 | bottom navigation (material design)
29 | 开源库:https://github.com/roughike/BottomBar
30 |
31 | 晓峰的Meizhi
32 | https://github.com/drakeet/Meizhi
33 |
34 | Witype的lite另一种姿势
35 | https://github.com/Witype/LiteHttpDemo
36 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | generateDebugSources
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 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "24.0.0 rc2"
6 |
7 | defaultConfig {
8 | applicationId "com.example.kituri.demomvp"
9 | minSdkVersion 22
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.3.0'
26 | compile 'com.android.support:recyclerview-v7:23.2.0'
27 | compile 'com.android.support:design:23.2.0'
28 | compile 'com.squareup.retrofit2:retrofit:2.0.1'
29 | compile 'com.google.code.gson:gson:2.6.2'
30 | compile 'com.squareup.retrofit2:converter-gson:2.0.1'
31 | compile 'com.roughike:bottom-bar:1.3.3'
32 | compile 'me.henrytao:smooth-app-bar-layout:0.2.1'
33 | compile 'com.facebook.fresco:fresco:0.9.0'
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/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-sdk-windows/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/IBaseView/IBaseView.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.IBaseView;
2 |
3 | import android.content.Context;
4 |
5 |
6 | public interface IBaseView {
7 |
8 | Context getActivity();
9 |
10 | void onSuccess();
11 |
12 | void onNetWorkError();
13 |
14 |
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/IBaseView/navigation/IMeizhiNavigationCommand.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.IBaseView.navigation;
2 |
3 | import com.mvp.mobile.data.MeizhiData;
4 |
5 | /**
6 | * Created by kirijin on 2016/4/25.
7 | */
8 | public interface IMeizhiNavigationCommand extends INavigationCommand{
9 | //带参跳转请按照以上继承
10 | void setMeizhi(MeizhiData.Results meizhi);
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/IBaseView/navigation/INavigationCommand.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.IBaseView.navigation;
2 |
3 | /**
4 | * Created by kirijin on 2016/4/25.
5 | */
6 | public interface INavigationCommand {
7 | //跳转请使用该接口
8 | void navigate();
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/app/MobileApplication.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.app;
2 |
3 | import android.app.Application;
4 |
5 | import com.facebook.drawee.backends.pipeline.Fresco;
6 |
7 |
8 | /**
9 | * Created by kirijin on 2016/4/20.
10 | */
11 | public class MobileApplication extends Application {
12 |
13 | protected static final Object object = new Object();
14 |
15 | static private MobileApplication app = null;
16 |
17 | public static MobileApplication getInstance() {
18 | synchronized (object) {
19 | return app;
20 | }
21 | }
22 |
23 | @Override
24 | public void onCreate() {
25 | super.onCreate();
26 | Fresco.initialize(this);
27 | app = this;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/app/able/EntryComparable.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.app.able;
2 |
3 | public interface EntryComparable {
4 |
5 | public long entryCompare();
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/app/able/SelectionListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.mvp.mobile.app.able;
5 |
6 | /**
7 | * @author Kituri
8 | *
9 | */
10 | public interface SelectionListener {
11 |
12 | public void onSelectionChanged(E item, boolean selected);
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/app/discover/DiscoverFragment.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.app.discover;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import com.mvp.mobile.R;
9 | import com.mvp.mobile.ui.fragment.BaseFragment;
10 |
11 |
12 | public class DiscoverFragment extends BaseFragment {
13 |
14 | private View fragmentLayout;
15 |
16 | static public final String TAG = "DiscoverFragment";
17 |
18 | @Override
19 | public void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | if (presenter != null) presenter.onCreate();
22 | }
23 |
24 | @Override
25 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
26 | Bundle savedInstanceState) {
27 | fragmentLayout = inflater.inflate(R.layout.fr_discover, container, false);
28 | return fragmentLayout;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/app/lessons/ILessonsPresenter.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.app.lessons;
2 |
3 | import com.mvp.mobile.presenter.BasePresenter;
4 |
5 | public interface ILessonsPresenter extends BasePresenter {
6 |
7 | void loadDataList(final boolean clear);
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/app/lessons/ILessonsView.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.app.lessons;
2 |
3 |
4 | import com.mvp.mobile.IBaseView.IBaseView;
5 | import com.mvp.mobile.data.ListEntry;
6 |
7 | public interface ILessonsView extends IBaseView {
8 |
9 | void onLoadDataList(ListEntry meizhiData);
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/app/lessons/IMeizhiModel.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.app.lessons;
2 |
3 | import com.mvp.mobile.data.ListEntry;
4 | import com.mvp.mobile.model.base.INetModel;
5 | import com.mvp.mobile.model.base.OnNetModelListener;
6 |
7 | /**
8 | * Created by kirijin on 2016/4/25.
9 | */
10 | public interface IMeizhiModel extends INetModel{
11 |
12 | void getMeizhiList(final boolean clear, final OnNetModelListener onNetModelListener);
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/app/lessons/LessonsFragment.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.app.lessons;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.widget.LinearLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Toast;
10 |
11 | import com.mvp.mobile.IBaseView.navigation.IMeizhiNavigationCommand;
12 | import com.mvp.mobile.R;
13 | import com.mvp.mobile.app.MobileApplication;
14 | import com.mvp.mobile.data.Entry;
15 | import com.mvp.mobile.data.ListEntry;
16 | import com.mvp.mobile.data.MeizhiData;
17 | import com.mvp.mobile.ui.adapter.MeizhiListAdapter;
18 | import com.mvp.mobile.ui.base.SwipeRefreshFragment;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 |
24 | public class LessonsFragment extends SwipeRefreshFragment implements ILessonsView, IMeizhiNavigationCommand {
25 |
26 | private View fragmentLayout;
27 |
28 | private RecyclerView rv_list;
29 | private MeizhiListAdapter mMeizhiListAdapter;
30 | private List mMeizhiList = new ArrayList<>();
31 |
32 | ILessonsPresenter mPresenter = getPresenter();
33 |
34 | static public final String TAG = "LessonsFragment";
35 | private boolean mIsFirstTimeTouchBottom = true;
36 | private MeizhiData.Results meizhi;
37 |
38 | @Override
39 | public void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | if (presenter != null) presenter.onCreate();
42 | }
43 |
44 | @Override
45 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
46 | Bundle savedInstanceState) {
47 | fragmentLayout = inflater.inflate(R.layout.fr_lessons, container, false);
48 | rv_list = (RecyclerView) fragmentLayout.findViewById(R.id.rv_list);
49 | setupRecyclerView();
50 | requestDataRefresh();
51 | return fragmentLayout;
52 | }
53 |
54 | public LessonsPresenterImpl getPresenter() {
55 | return new LessonsPresenterImpl(this);
56 | }
57 |
58 | @Override
59 | public void onLoadDataList(ListEntry meizhiData) {
60 | mMeizhiList.clear();
61 | for (Entry entry : meizhiData.getEntries()){
62 | mMeizhiList.add((MeizhiData.Results) entry);
63 | }
64 | mMeizhiListAdapter.notifyDataSetChanged();
65 | setRefreshing(false);
66 | }
67 |
68 | private void setupRecyclerView() {
69 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
70 | rv_list.setLayoutManager(linearLayoutManager);
71 | mMeizhiListAdapter = new MeizhiListAdapter(mMeizhiList);
72 | mMeizhiListAdapter.setOnNavigationCommand(this);
73 | rv_list.setAdapter(mMeizhiListAdapter);
74 | rv_list.addOnScrollListener(getOnBottomListener(linearLayoutManager));
75 | }
76 |
77 | RecyclerView.OnScrollListener getOnBottomListener(final LinearLayoutManager layoutManager){
78 | return new RecyclerView.OnScrollListener() {
79 | @Override
80 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
81 | super.onScrolled(recyclerView, dx, dy);
82 | int lastVisibleItem = layoutManager.findLastVisibleItemPosition();
83 | int totalItemCount = layoutManager.getItemCount();
84 | if (lastVisibleItem >= totalItemCount - 1 && dy > 0 && !mSwipeRefreshLayout.isRefreshing()) {
85 | if (!mIsFirstTimeTouchBottom) {
86 | mSwipeRefreshLayout.setRefreshing(true);
87 | mPresenter.loadDataList(false);
88 | }else{
89 | mIsFirstTimeTouchBottom = false;
90 | }
91 | }
92 | }
93 | };
94 | }
95 |
96 | @Override public void requestDataRefresh() {
97 | super.requestDataRefresh();
98 | mPresenter.loadDataList(true);
99 | }
100 |
101 | @Override
102 | public void setMeizhi(MeizhiData.Results meizhi) {
103 | this.meizhi = meizhi;
104 | }
105 |
106 | @Override
107 | public void navigate() {
108 | if(meizhi != null){
109 | Toast.makeText(MobileApplication.getInstance(), meizhi.getDesc(), Toast.LENGTH_SHORT).show();
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/app/lessons/LessonsPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.app.lessons;
2 |
3 | import com.mvp.mobile.data.ListEntry;
4 | import com.mvp.mobile.model.base.OnNetModelListener;
5 | import com.mvp.mobile.presenter.BasePresenterImpl;
6 |
7 |
8 | public class LessonsPresenterImpl extends BasePresenterImpl implements ILessonsPresenter, OnNetModelListener {
9 |
10 | private ILessonsView mILessonsView;
11 | private IMeizhiModel mIMeizhiModel;
12 |
13 | public LessonsPresenterImpl(ILessonsView mIBaseView) {
14 | super(mIBaseView);
15 | this.mILessonsView = mIBaseView;
16 | this.mIMeizhiModel = new MeizhiModelImpl();
17 | super.addNetModel(mIMeizhiModel);
18 | }
19 |
20 | @Override
21 | public void loadDataList(final boolean clear) {
22 | mIMeizhiModel.getMeizhiList(clear, this);
23 | }
24 |
25 | @Override
26 | public void onNetModelSuccess(ListEntry entry) {
27 | super.onSuccess(entry);
28 | mILessonsView.onLoadDataList(entry);
29 | }
30 |
31 | //重写的情况需要自行处理,必须执行super
32 | // @Override
33 | // public void onNetModelNetWorkError() {
34 | // super.onNetWorkError();
35 | // }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/app/lessons/MeizhiModelImpl.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.app.lessons;
2 |
3 | import com.mvp.mobile.data.ListEntry;
4 | import com.mvp.mobile.data.MeizhiData;
5 | import com.mvp.mobile.model.base.NetModelImpl;
6 | import com.mvp.mobile.model.base.OnNetModelListener;
7 | import com.mvp.mobile.model.net.MobileApi;
8 | import com.mvp.mobile.model.retrofit.RetGankMeizhi;
9 |
10 | import retrofit2.Call;
11 | import retrofit2.Callback;
12 | import retrofit2.Response;
13 |
14 | /**
15 | * Created by kirijin on 2016/4/25.
16 | */
17 | public class MeizhiModelImpl extends NetModelImpl implements IMeizhiModel {
18 |
19 | private int mPage = 1;
20 | private ListEntry mMeizhiList = new ListEntry();
21 |
22 | @Override
23 | public void getMeizhiList(final boolean clear, final OnNetModelListener onNetModelListener) {
24 | if(clear){
25 | mPage = 1;
26 | }else{
27 | mPage += 1;
28 | }
29 | enqueue(MobileApi.getInstance().getService(RetGankMeizhi.class).getMeizhiList(mPage), new Callback() {
30 | @Override
31 | public void onResponse(Call call, Response response) {
32 | if(response.isSuccessful() && onNetModelListener != null){
33 | if(clear){
34 | mMeizhiList.clear();
35 | }
36 | mMeizhiList.addAll(response.body().getResults());
37 | onNetModelListener.onNetModelSuccess(mMeizhiList);
38 | }
39 | }
40 |
41 | @Override
42 | public void onFailure(Call call, Throwable t) {
43 | if(onNetModelListener != null){
44 | onNetModelListener.onNetModelNetWorkError();
45 | }
46 | }
47 | });
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/app/me/MeFragment.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.app.me;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import com.mvp.mobile.R;
9 | import com.mvp.mobile.ui.fragment.BaseFragment;
10 |
11 |
12 | public class MeFragment extends BaseFragment {
13 |
14 | private View fragmentLayout;
15 |
16 | static public final String TAG = "MeFragment";
17 |
18 | @Override
19 | public void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | if (presenter != null) presenter.onCreate();
22 | }
23 |
24 | @Override
25 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
26 | Bundle savedInstanceState) {
27 | fragmentLayout = inflater.inflate(R.layout.fr_me, container, false);
28 | return fragmentLayout;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/app/scheduled/ScheduledFragment.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.app.scheduled;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import com.mvp.mobile.R;
9 | import com.mvp.mobile.ui.fragment.BaseFragment;
10 |
11 |
12 | public class ScheduledFragment extends BaseFragment {
13 |
14 | private View fragmentLayout;
15 |
16 | static public final String TAG = "ScheduledFragment";
17 |
18 | @Override
19 | public void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | if (presenter != null) presenter.onCreate();
22 | }
23 |
24 | @Override
25 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
26 | Bundle savedInstanceState) {
27 | fragmentLayout = inflater.inflate(R.layout.fr_scheduled, container, false);
28 | return fragmentLayout;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/app/utils/ImageUtils.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.app.utils;
2 |
3 | import android.net.Uri;
4 | import android.text.TextUtils;
5 | import android.widget.ImageView;
6 |
7 | import com.facebook.drawee.view.SimpleDraweeView;
8 |
9 | /**
10 | * Created by kirijin on 2016/4/20.
11 | */
12 | public class ImageUtils {
13 |
14 | //ImageLoader简单封装
15 | static public void loadImageView(ImageView imageView, String url){
16 | if(TextUtils.isEmpty(url)){ return; }
17 | if(imageView instanceof SimpleDraweeView){
18 | SimpleDraweeView draweeView = (SimpleDraweeView) imageView;
19 | draweeView.setImageURI(Uri.parse(url));
20 | }
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/data/Entry.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.data;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created by kirijin on 2016/4/12.
7 | */
8 | public class Entry implements Serializable{
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/data/EntryList.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.mvp.mobile.data;
5 |
6 |
7 | import java.io.Serializable;
8 | import java.util.ArrayList;
9 |
10 | /**
11 | * @author kituri
12 | * 继承用,一般不用
13 | */
14 | public class EntryList extends ArrayList implements Serializable{
15 |
16 | private static final long serialVersionUID = -1797215192050958113L;
17 |
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/data/ListEntry.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.mvp.mobile.data;
5 |
6 |
7 |
8 | import java.util.Collection;
9 | import java.util.Collections;
10 | import java.util.List;
11 |
12 | /**
13 | * @author kituri
14 | * List用这个
15 | */
16 | public class ListEntry extends Entry{
17 |
18 | private static final long serialVersionUID = 8369729682149235659L;
19 |
20 | private List mEntries = Collections.synchronizedList(new EntryList());
21 |
22 | private Object lock = new Object();
23 |
24 | public void add(Entry entry) {
25 | synchronized (lock){
26 | mEntries.add(entry);
27 | }
28 | }
29 |
30 | public void add(Entry entry,int index){
31 | synchronized (lock){
32 | mEntries.add(0, entry);
33 | }
34 | }
35 |
36 | public void inSet(int index, Entry entry) {
37 | synchronized (lock){
38 | mEntries.add(index, entry);
39 | }
40 | }
41 |
42 | public void remove(Entry entry) {
43 | synchronized (lock){
44 | mEntries.remove(entry);
45 | }
46 | }
47 |
48 | public void clear() {
49 | synchronized (lock){
50 | mEntries.clear();
51 | }
52 | }
53 |
54 | public void addAll(Collection extends Entry> collection){
55 | synchronized (lock){
56 | mEntries.addAll(collection);
57 | }
58 | }
59 |
60 | public List getEntries() {
61 | return mEntries;
62 | }
63 |
64 | // public void print(){
65 | // for(Entry entry:mEntries){
66 | // entry.print();
67 | // }
68 | // }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/data/MeizhiData.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.data;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by kirijin on 2016/4/12.
7 | */
8 | public class MeizhiData extends Entry {
9 |
10 | private boolean error;
11 |
12 | private List results;
13 |
14 | public void setError(boolean error) {
15 | this.error = error;
16 | }
17 |
18 | public boolean getError() {
19 | return this.error;
20 | }
21 |
22 | public void setResults(List results) {
23 | this.results = results;
24 | }
25 |
26 | public List getResults() {
27 | return this.results;
28 | }
29 |
30 | public class Results extends Entry{
31 | private String _id;
32 |
33 | private String createdAt;
34 |
35 | private String desc;
36 |
37 | private String publishedAt;
38 |
39 | private String source;
40 |
41 | private String type;
42 |
43 | private String url;
44 |
45 | private boolean used;
46 |
47 | private String who;
48 |
49 | public void set_id(String _id) {
50 | this._id = _id;
51 | }
52 |
53 | public String get_id() {
54 | return this._id;
55 | }
56 |
57 | public void setCreatedAt(String createdAt) {
58 | this.createdAt = createdAt;
59 | }
60 |
61 | public String getCreatedAt() {
62 | return this.createdAt;
63 | }
64 |
65 | public void setDesc(String desc) {
66 | this.desc = desc;
67 | }
68 |
69 | public String getDesc() {
70 | return this.desc;
71 | }
72 |
73 | public void setPublishedAt(String publishedAt) {
74 | this.publishedAt = publishedAt;
75 | }
76 |
77 | public String getPublishedAt() {
78 | return this.publishedAt;
79 | }
80 |
81 | public void setSource(String source) {
82 | this.source = source;
83 | }
84 |
85 | public String getSource() {
86 | return this.source;
87 | }
88 |
89 | public void setType(String type) {
90 | this.type = type;
91 | }
92 |
93 | public String getType() {
94 | return this.type;
95 | }
96 |
97 | public void setUrl(String url) {
98 | this.url = url;
99 | }
100 |
101 | public String getUrl() {
102 | return this.url;
103 | }
104 |
105 | public void setUsed(boolean used) {
106 | this.used = used;
107 | }
108 |
109 | public boolean getUsed() {
110 | return this.used;
111 | }
112 |
113 | public void setWho(String who) {
114 | this.who = who;
115 | }
116 |
117 | public String getWho() {
118 | return this.who;
119 | }
120 |
121 | }
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/data/inject/InjectData.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.data.inject;
2 |
3 | import java.lang.annotation.Retention;
4 |
5 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
6 |
7 | @Retention(RUNTIME)
8 | public @interface InjectData {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/data/inject/Injector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.mvp.mobile.data.inject;
18 |
19 | import android.os.Bundle;
20 | import android.os.Parcelable;
21 |
22 | import java.io.Serializable;
23 | import java.lang.reflect.Field;
24 | import java.util.ArrayList;
25 |
26 | public final class Injector {
27 |
28 | static final String TAG = "Injector";
29 |
30 | @SuppressWarnings("unchecked")
31 | private static final void onSave(Field[] fields, Object obj, Bundle outsave) {
32 | if (fields == null || fields.length == 0)
33 | return;
34 | try {
35 | for (Field field : fields) {
36 | if (field.isAnnotationPresent(InjectData.class)) {
37 | field.setAccessible(true);
38 | Object value = field.get(obj);
39 | if (value instanceof String) {
40 | outsave.putString(field.getName(), (String) value);
41 | } else if (value instanceof Integer) {
42 | outsave.putInt(field.getName(), (Integer) value);
43 | } else if (value instanceof Parcelable) {
44 | outsave.putParcelable(field.getName(), (Parcelable) value);
45 | } else if (value instanceof Serializable) {
46 | outsave.putSerializable(field.getName(), (Serializable)value);
47 | } else if (value instanceof Float) {
48 | outsave.putFloat(field.getName(), (Float) value);
49 | } else if (value instanceof Double) {
50 | outsave.putDouble(field.getName(), (Double) value);
51 | } else if (value instanceof String[]) {
52 | outsave.putStringArray(field.getName(), (String[]) value);
53 | } else if (value instanceof Boolean) {
54 | outsave.putBoolean(field.getName(), (Boolean)value);
55 | } else if (value instanceof ArrayList>) {
56 | ArrayList> data = (ArrayList>) value;
57 | if (!data.isEmpty()) {
58 | Object temp = data.get(0);
59 | if (temp instanceof String) {
60 | outsave.putStringArrayList(field.getName(), (ArrayList) value);
61 | } else if (temp instanceof Parcelable) {
62 | outsave.putParcelableArrayList(field.getName(), (ArrayList) value);
63 | }
64 | }
65 | }
66 | field.setAccessible(false);
67 | }
68 | }
69 | } catch (Exception e) {
70 | e.printStackTrace();
71 | }
72 | }
73 |
74 | public static final void save(Object obj, Bundle outsave) {
75 | onSave(obj.getClass().getDeclaredFields(), obj, outsave);
76 | Class extends Object> _supperclass = obj.getClass().getSuperclass();
77 | while (_supperclass != null) {
78 | onSave(_supperclass.getDeclaredFields(), obj, outsave);
79 | _supperclass = _supperclass.getSuperclass();
80 | }
81 | }
82 |
83 | private static final void onRestore(Field[] fields, Object obj, Bundle savedInstanceState) {
84 | if (fields == null || fields.length == 0)
85 | return;
86 | try {
87 | for (Field field : fields) {
88 | if (field.isAnnotationPresent(InjectData.class)) {
89 | Object value = savedInstanceState.get(field.getName());
90 | field.setAccessible(true);
91 | field.set(obj, value);
92 | field.setAccessible(false);
93 | }
94 | }
95 | } catch (Exception e) {
96 | e.printStackTrace();
97 | }
98 | }
99 |
100 | public static final void onRestore(Object obj, Bundle savedInstanceState) {
101 | onRestore(obj.getClass().getDeclaredFields(), obj, savedInstanceState);
102 | Class extends Object> _supperclass = obj.getClass().getSuperclass();
103 | while (_supperclass != null) {
104 | onRestore(_supperclass.getDeclaredFields(), obj, savedInstanceState);
105 | _supperclass = _supperclass.getSuperclass();
106 | }
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/model/base/BaseModel.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.model.base;
2 |
3 | /**
4 | * Created by kirijin on 2016/4/26.
5 | * 该类备用
6 | */
7 | public class BaseModel {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/model/base/INetModel.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.model.base;
2 |
3 | import com.mvp.mobile.data.Entry;
4 |
5 | import retrofit2.Call;
6 | import retrofit2.Callback;
7 |
8 | /**
9 | * Created by kirijin on 2016/4/25.
10 | * 网络基础model接口
11 | */
12 | public interface INetModel {
13 | public void onDestroy();
14 | public void enqueue(Call call, Callback callback);
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/model/base/NetModelImpl.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.model.base;
2 |
3 | import com.mvp.mobile.data.Entry;
4 |
5 | import java.util.ArrayList;
6 |
7 | import retrofit2.Call;
8 | import retrofit2.Callback;
9 |
10 | /**
11 | * Created by kirijin on 2016/4/25.
12 | */
13 | public class NetModelImpl extends BaseModel implements INetModel{
14 |
15 | private ArrayList mTask = new ArrayList<>();
16 |
17 | @Override
18 | public void onDestroy() {
19 | if (mTask == null) return;
20 | for (Call item : mTask) {
21 | item.cancel();
22 | }
23 | mTask.clear();
24 | }
25 |
26 | public void enqueue(Call call, Callback callback){
27 | // mTask.add(callback);
28 | mTask.add(call);
29 | call.enqueue(callback);
30 | }
31 |
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/model/base/OnNetModelListener.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.model.base;
2 |
3 | import com.mvp.mobile.data.Entry;
4 |
5 | /**
6 | * Created by kirijin on 2016/4/26.
7 | */
8 | public interface OnNetModelListener {
9 | /**
10 | * 当请求成功时候调用
11 | */
12 | void onNetModelSuccess(T entry);
13 |
14 | void onNetModelNetWorkError();
15 | // /**
16 | // * 当Presenter onDestory时调用
17 | // */
18 | // void onNetModeDestroy();
19 | //
20 | // void onNetModeCreate();
21 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/model/common/IntentAction.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.model.common;
2 |
3 | /**
4 | * Created by kirijin on 2016/4/25.
5 | * Activity跳转和传递
6 | */
7 | public class IntentAction {
8 |
9 | public static final String ACTION_DETAIL_PICS = "com.mvp.mobile.model.intent.action.detail.pics";
10 |
11 | public static final String EXTRA_MEIZHI = "com.mvp.mobile.model.intent.extra.meizhi";
12 | public static final String EXTRA_PHOTOS_RECT = "com.mvp.mobile.model.intent.photos.rect";
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/model/net/MobileApi.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.model.net;
2 |
3 | import retrofit2.Retrofit;
4 | import retrofit2.converter.gson.GsonConverterFactory;
5 |
6 | /**
7 | * Created by kirijin on 2016/4/12.
8 | */
9 | public class MobileApi {
10 |
11 | protected static final Object object = new Object();
12 | static MobileApi sMobileApi = null;
13 | private Retrofit retrofit;
14 | //final RetGankMeizhi mIGankMeizhi;
15 | MobileApi(){
16 | if (retrofit == null) {
17 | retrofit = new Retrofit.Builder()
18 | .baseUrl("http://gank.io/api/")
19 | .addConverterFactory(GsonConverterFactory.create())
20 | .build();
21 | }
22 | }
23 |
24 | public T getService(Class cls) {
25 | return retrofit.create(cls);
26 | }
27 |
28 | public static MobileApi getInstance() {
29 | synchronized (object) {
30 | if (sMobileApi == null) {
31 | sMobileApi = new MobileApi();
32 | }
33 | return sMobileApi;
34 | }
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/model/net/WaitCancelListener.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.model.net;
2 |
3 | public interface WaitCancelListener {
4 |
5 | void onDialogCancel();
6 | }
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/model/retrofit/RetGankMeizhi.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.model.retrofit;
2 |
3 | import com.mvp.mobile.data.MeizhiData;
4 |
5 | import retrofit2.Call;
6 | import retrofit2.http.GET;
7 | import retrofit2.http.Path;
8 |
9 | /**
10 | * Created by kirijin on 2016/4/12.
11 | */
12 | //http://gank.io/api/data/福利/10/1
13 | public interface RetGankMeizhi {
14 | @GET("data/福利/10/{page}")
15 | Call getMeizhiList(@Path("page") int page);
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/presenter/BasePresenter.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.presenter;
2 |
3 |
4 | import com.mvp.mobile.data.Entry;
5 | import com.mvp.mobile.model.net.WaitCancelListener;
6 |
7 |
8 | public interface BasePresenter {
9 |
10 | /**
11 | * 当Activity onCreate时调用
12 | */
13 | void onCreate();
14 |
15 | /**
16 | * 当Activity onDestory时调用
17 | */
18 | void onDestroy();
19 |
20 | /**
21 | * 当前Activity是否destroy
22 | */
23 | boolean isDestroy();
24 |
25 | void showWaitDialog(String message, WaitCancelListener listener);
26 |
27 | void dismiss();
28 |
29 | void showToast(String msg);
30 |
31 | /**
32 | * 当请求成功时候调用
33 | */
34 | void onSuccess(Entry response);
35 |
36 | void onNetWorkError();
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/presenter/BasePresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.presenter;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.DialogInterface;
5 | import android.widget.Toast;
6 |
7 | import com.mvp.mobile.IBaseView.IBaseView;
8 | import com.mvp.mobile.data.Entry;
9 | import com.mvp.mobile.model.base.INetModel;
10 | import com.mvp.mobile.model.net.WaitCancelListener;
11 |
12 | import java.util.ArrayList;
13 |
14 |
15 | public class BasePresenterImpl implements BasePresenter {
16 |
17 | private IBaseView mIBaseView;
18 |
19 | private ProgressDialog mDialog;
20 |
21 | private boolean isOnCreate;
22 |
23 | private ArrayList mNetModels = new ArrayList<>();
24 |
25 | public BasePresenterImpl(IBaseView mIBaseView) {
26 | this.mIBaseView = mIBaseView;
27 | }
28 |
29 | @Override
30 | public void onCreate() {
31 | this.isOnCreate = true;
32 | }
33 |
34 | @Override
35 | public void onDestroy() {
36 | this.isOnCreate = false;
37 | if (mNetModels == null) return;
38 | for (INetModel item : mNetModels) {
39 | item.onDestroy();
40 | }
41 | mNetModels.clear();
42 | }
43 |
44 | @Override
45 | public boolean isDestroy() {
46 | return isOnCreate;
47 | }
48 |
49 | @Override
50 | public void showWaitDialog(String message, final WaitCancelListener listener) {
51 | if (mIBaseView == null) return;
52 | if (mDialog == null) {
53 | mDialog = new ProgressDialog(mIBaseView.getActivity());
54 | }
55 | if (mDialog.isShowing()){
56 | mDialog.setTitle(message);
57 | } else {
58 | mDialog.setTitle(message);
59 | mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
60 | @Override
61 | public void onCancel(DialogInterface dialog) {
62 | if (listener != null) listener.onDialogCancel();
63 | }
64 | });
65 | mDialog.setCancelable(true);
66 | mDialog.setCanceledOnTouchOutside(true);
67 | mDialog.show();
68 | }
69 | }
70 |
71 | @Override
72 | public void dismiss() {
73 | if (mDialog != null) mDialog.dismiss();
74 | }
75 |
76 | @Override
77 | public void showToast(String msg) {
78 | Toast.makeText(mIBaseView.getActivity(), msg,Toast.LENGTH_SHORT).show();
79 | }
80 |
81 | @Override
82 | public void onSuccess(Entry response) {
83 | if (mIBaseView != null) {
84 | mIBaseView.onSuccess();
85 | }
86 | }
87 |
88 |
89 | @Override
90 | public void onNetWorkError() {
91 | if (mIBaseView != null) {
92 | mIBaseView.onNetWorkError();
93 | }
94 | }
95 |
96 | public void addNetModel(INetModel... netModels){
97 | if(netModels == null || netModels.length == 0){
98 | return;
99 | }
100 | for (INetModel model : netModels){
101 | mNetModels.add(model);
102 | }
103 | }
104 |
105 | public void onNetModelNetWorkError() {
106 | onNetWorkError();
107 | }
108 |
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/ui/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.ui.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.IdRes;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.app.FragmentTransaction;
7 | import android.support.v4.content.ContextCompat;
8 | import android.widget.Button;
9 | import android.widget.TextView;
10 |
11 | import com.roughike.bottombar.BottomBar;
12 | import com.roughike.bottombar.OnMenuTabClickListener;
13 | import com.mvp.mobile.R;
14 | import com.mvp.mobile.ui.base.BaseActivity;
15 | import com.mvp.mobile.app.discover.DiscoverFragment;
16 | import com.mvp.mobile.app.lessons.LessonsFragment;
17 | import com.mvp.mobile.app.me.MeFragment;
18 | import com.mvp.mobile.app.scheduled.ScheduledFragment;
19 |
20 | public class MainActivity extends BaseActivity {
21 |
22 | private BottomBar mBottomBar;
23 | private TextView tv_submit;
24 | private Button btn_submit;
25 | private Fragment mContent;
26 |
27 | private LessonsFragment mLessonsFragment;
28 | private ScheduledFragment mScheduledFragment;
29 | private DiscoverFragment mDiscoverFragment;
30 | private MeFragment mMeFragment;
31 |
32 | static final String tags[] = {LessonsFragment.TAG, ScheduledFragment.TAG, DiscoverFragment.TAG, MeFragment.TAG};
33 |
34 | static final String TAG = "MainActivity";
35 |
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_main);
41 | intiFragment();
42 | stateCheck(savedInstanceState);
43 | initBottomBar(savedInstanceState);
44 | }
45 |
46 | private void initBottomBar(Bundle savedInstanceState) {
47 | mBottomBar = BottomBar.attach(this, savedInstanceState);
48 | mBottomBar.setItemsFromMenu(R.menu.bottombar_menu, new OnMenuTabClickListener() {
49 | @Override
50 | public void onMenuTabSelected(@IdRes int menuItemId) {
51 | switch (menuItemId){
52 | case R.id.bb_menu_lessons:
53 | switchContent(mContent, mLessonsFragment, 0);
54 | break;
55 | case R.id.bb_menu_schedule:
56 | switchContent(mContent, mScheduledFragment, 1);
57 | break;
58 | case R.id.bb_menu_discover:
59 | switchContent(mContent, mDiscoverFragment, 2);
60 | break;
61 | case R.id.bb_menu_me:
62 | switchContent(mContent, mMeFragment, 3);
63 | break;
64 |
65 | default:
66 | switchContent(mContent, mLessonsFragment, 0);
67 | }
68 | }
69 |
70 | @Override
71 | public void onMenuTabReSelected(@IdRes int menuItemId) {
72 |
73 | }
74 | });
75 |
76 | // Setting colors for different tabs when there's more than three of them.
77 | // You can set colors for tabs in three different ways as shown below.
78 | mBottomBar.mapColorForTab(0, ContextCompat.getColor(this, R.color.colorPrimary));
79 | mBottomBar.mapColorForTab(1, ContextCompat.getColor(this, R.color.colorPrimary));
80 | mBottomBar.mapColorForTab(2, ContextCompat.getColor(this, R.color.colorPrimary));
81 | mBottomBar.mapColorForTab(3, ContextCompat.getColor(this, R.color.colorPrimary));
82 | //mBottomBar.noTopOffset();
83 | // mBottomBar.setFragmentItems(getSupportFragmentManager(), R.id.content_frame,
84 | // new BottomBarFragment(mLessonsFragment, R.drawable.bb_menu_lessons, getString(R.string.cap_bb_menu_lessons)),
85 | // new BottomBarFragment(mScheduledFragment, R.drawable.bb_menu_scheduled, getString(R.string.cap_bb_menu_scheduled)),
86 | // new BottomBarFragment(mDiscoverFragment, R.drawable.bb_menu_discover, getString(R.string.cap_bb_menu_discover)),
87 | // new BottomBarFragment(mMeFragment, R.drawable.bb_menu_me, getString(R.string.cap_bb_menu_me))
88 | // );
89 | }
90 |
91 | @Override
92 | protected void onSaveInstanceState(Bundle outState) {
93 | super.onSaveInstanceState(outState);
94 |
95 | // Necessary to restore the BottomBar's state, otherwise we would
96 | // lose the current tab on orientation change.
97 | //stateCheck(outState);
98 | if(mBottomBar != null){
99 | mBottomBar.onSaveInstanceState(outState);
100 | }
101 | }
102 |
103 | @Override
104 | public void onDestroy(){
105 | super.onDestroy();
106 | mContent = null;
107 | mLessonsFragment = null;
108 | mScheduledFragment = null;
109 | mDiscoverFragment = null;
110 | mMeFragment = null;
111 | }
112 |
113 | /**
114 | * fragment 切换
115 | *
116 | * @param from
117 | * @param to
118 | */
119 | public void switchContent(Fragment from, Fragment to, int position) {
120 | if (mContent != to) {
121 | mContent = to;
122 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
123 | if (!to.isAdded()) { // 先判断是否被add过
124 | transaction.hide(from)
125 | .add(R.id.content_frame, to, tags[position]).commit(); // 隐藏当前的fragment,add下一个到Activity中
126 | } else {
127 | transaction.hide(from).show(to).commit(); // 隐藏当前的fragment,显示下一个
128 | }
129 | }
130 | }
131 |
132 |
133 | private void intiFragment() {
134 | mLessonsFragment = new LessonsFragment();
135 | mScheduledFragment = new ScheduledFragment();
136 | mDiscoverFragment = new DiscoverFragment();
137 | mMeFragment = new MeFragment();
138 | }
139 |
140 | /**
141 | * 状态检测 用于内存不足的时候保证fragment不会重叠
142 | *
143 | * @param savedInstanceState
144 | */
145 | private void stateCheck(Bundle savedInstanceState) {
146 | if (savedInstanceState == null) {
147 | FragmentTransaction fts = getSupportFragmentManager().beginTransaction();
148 | LessonsFragment af = new LessonsFragment();
149 | mContent = af;
150 | fts.add(R.id.content_frame, af);
151 | fts.commit();
152 | } else {
153 | LessonsFragment lf = (LessonsFragment) getSupportFragmentManager()
154 | .findFragmentByTag(tags[0]);
155 | ScheduledFragment sf = (ScheduledFragment) getSupportFragmentManager()
156 | .findFragmentByTag(tags[1]);
157 | DiscoverFragment df = (DiscoverFragment) getSupportFragmentManager()
158 | .findFragmentByTag(tags[2]);
159 | MeFragment mf = (MeFragment) getSupportFragmentManager()
160 | .findFragmentByTag(tags[3]);
161 | getSupportFragmentManager().beginTransaction().show(lf).hide(sf).hide(df)
162 | .hide(mf).commit();
163 | }
164 | }
165 |
166 | }
167 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/ui/adapter/MeizhiListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.ui.adapter;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.ImageView;
8 | import android.widget.TextView;
9 |
10 | import com.mvp.mobile.IBaseView.navigation.IMeizhiNavigationCommand;
11 | import com.mvp.mobile.R;
12 | import com.mvp.mobile.app.able.SelectionListener;
13 | import com.mvp.mobile.app.utils.ImageUtils;
14 | import com.mvp.mobile.data.Entry;
15 | import com.mvp.mobile.data.MeizhiData;
16 |
17 | import java.util.List;
18 |
19 | public class MeizhiListAdapter extends RecyclerView.Adapter implements SelectionListener {
20 |
21 | public static final String TAG = "MeizhiListAdapter";
22 |
23 | private List mList;
24 | private IMeizhiNavigationCommand mNavigationCommand;
25 |
26 |
27 | public MeizhiListAdapter(List meizhiList) {
28 | mList = meizhiList;
29 | }
30 |
31 | public void setOnNavigationCommand(IMeizhiNavigationCommand navigationCommand){
32 | this.mNavigationCommand = navigationCommand;
33 | }
34 |
35 | @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int i) {
36 | View v = LayoutInflater.from(parent.getContext())
37 | .inflate(R.layout.item_meizhi, parent, false);
38 | ViewHolder vh = new ViewHolder(v);
39 | vh.setOnSelectionListener(this);
40 | return vh;
41 | }
42 |
43 | @Override
44 | public void onSelectionChanged(Entry item, boolean selected) {
45 | if(mNavigationCommand != null){
46 | mNavigationCommand.setMeizhi((MeizhiData.Results)item);
47 | mNavigationCommand.navigate();
48 | }
49 | }
50 |
51 | @Override
52 | public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
53 | MeizhiData.Results meizhi = mList.get(position);
54 | int limit = 48;
55 | String text = meizhi.getDesc().length() > limit ? meizhi.getDesc().substring(0, limit) +
56 | "..." : meizhi.getDesc();
57 | viewHolder.meizhi = meizhi;
58 | viewHolder.tv_title.setText(text);
59 | viewHolder.card.setTag(meizhi.getDesc());
60 |
61 | ImageUtils.loadImageView(viewHolder.iv_meizhi, meizhi.getUrl());
62 | }
63 |
64 |
65 | @Override public void onViewRecycled(ViewHolder holder) {
66 | super.onViewRecycled(holder);
67 | }
68 |
69 |
70 | @Override public int getItemCount() {
71 | return mList.size();
72 | }
73 |
74 |
75 | static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
76 |
77 | ImageView iv_meizhi;
78 | TextView tv_title;
79 | View card;
80 | MeizhiData.Results meizhi;
81 | private SelectionListener mSelectionListener;
82 |
83 | public ViewHolder(View itemView) {
84 | super(itemView);
85 | card = itemView;
86 | iv_meizhi = (ImageView) card.findViewById(R.id.iv_meizhi);
87 | tv_title = (TextView) card.findViewById(R.id.tv_title);
88 | card.setOnClickListener(this);
89 | }
90 |
91 | public void setOnSelectionListener(SelectionListener selectionListener){
92 | this.mSelectionListener = selectionListener;
93 | }
94 |
95 | @Override
96 | public void onClick(View v) {
97 | if(mSelectionListener != null){
98 | mSelectionListener.onSelectionChanged(meizhi, true);
99 | }
100 | }
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/ui/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.ui.base;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.os.PersistableBundle;
6 | import android.support.v4.app.FragmentActivity;
7 |
8 | import com.mvp.mobile.IBaseView.IBaseView;
9 | import com.mvp.mobile.data.inject.Injector;
10 | import com.mvp.mobile.presenter.BasePresenter;
11 | import com.mvp.mobile.presenter.BasePresenterImpl;
12 |
13 |
14 | public class BaseActivity extends FragmentActivity implements IBaseView {
15 |
16 | public BasePresenter presenter = getPresenter();
17 |
18 | @Override
19 | public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
20 | super.onCreate(savedInstanceState, persistentState);
21 | if (presenter != null) presenter.onCreate();
22 | if (savedInstanceState != null) Injector.onRestore(this, savedInstanceState);
23 | }
24 |
25 | @Override
26 | protected void onDestroy() {
27 | super.onDestroy();
28 | if (presenter != null) presenter.onDestroy();
29 | }
30 |
31 | @Override
32 | public Context getActivity() {
33 | return this;
34 | }
35 |
36 | @Override
37 | public void onSuccess() {
38 |
39 | }
40 |
41 | @Override
42 | public void onNetWorkError() {
43 |
44 | }
45 |
46 | public BasePresenterImpl getPresenter() {
47 | return new BasePresenterImpl(this);
48 | }
49 |
50 | @Override
51 | protected void onSaveInstanceState(Bundle outState) {
52 | super.onSaveInstanceState(outState);
53 | Injector.save(this, outState);
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/ui/base/SwipeRefreshActivity.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.ui.base;
2 |
3 | import android.os.Bundle;
4 | import android.os.PersistableBundle;
5 | import android.support.v4.widget.SwipeRefreshLayout;
6 |
7 | import com.mvp.mobile.R;
8 | import com.mvp.mobile.ui.widget.MultiSwipeRefreshLayout;
9 |
10 |
11 | public abstract class SwipeRefreshActivity extends BaseActivity {
12 |
13 | public MultiSwipeRefreshLayout mSwipeRefreshLayout;
14 | private boolean mIsRequestDataRefresh = false;
15 |
16 |
17 | @Override
18 | public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
19 | super.onCreate(savedInstanceState, persistentState);
20 | mSwipeRefreshLayout = (MultiSwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
21 | }
22 |
23 |
24 | @Override protected void onPostCreate(Bundle savedInstanceState) {
25 | super.onPostCreate(savedInstanceState);
26 | trySetupSwipeRefresh();
27 | }
28 |
29 |
30 | void trySetupSwipeRefresh() {
31 | if (mSwipeRefreshLayout != null) {
32 | mSwipeRefreshLayout.setColorSchemeResources(R.color.refresh_progress_3,
33 | R.color.refresh_progress_2, R.color.refresh_progress_1);
34 | mSwipeRefreshLayout.setOnRefreshListener(
35 | new SwipeRefreshLayout.OnRefreshListener() {
36 | @Override public void onRefresh() {
37 | requestDataRefresh();
38 | }
39 | });
40 | }
41 | }
42 |
43 |
44 | public void requestDataRefresh() {
45 | mIsRequestDataRefresh = true;
46 | }
47 |
48 |
49 | public void setRequestDataRefresh(boolean requestDataRefresh) {
50 | if (mSwipeRefreshLayout == null) {
51 | return;
52 | }
53 | if (!requestDataRefresh) {
54 | mIsRequestDataRefresh = false;
55 | // 防止刷新消失太快
56 | mSwipeRefreshLayout.postDelayed(new Runnable() {
57 | @Override public void run() {
58 | if (mSwipeRefreshLayout != null) {
59 | mSwipeRefreshLayout.setRefreshing(false);
60 | }
61 | }
62 | }, 1000);
63 | }
64 | else {
65 | mSwipeRefreshLayout.setRefreshing(true);
66 | }
67 | }
68 |
69 |
70 | public void setProgressViewOffset(boolean scale, int start, int end) {
71 | mSwipeRefreshLayout.setProgressViewOffset(scale, start, end);
72 | }
73 |
74 |
75 | public void setSwipeableChildren(MultiSwipeRefreshLayout.CanChildScrollUpCallback canChildScrollUpCallback) {
76 | mSwipeRefreshLayout.setCanChildScrollUpCallback(canChildScrollUpCallback);
77 | }
78 |
79 |
80 | public boolean isRequestDataRefresh() {
81 | return mIsRequestDataRefresh;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/ui/base/SwipeRefreshFragment.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.ui.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.widget.SwipeRefreshLayout;
5 | import android.view.View;
6 |
7 | import com.mvp.mobile.R;
8 | import com.mvp.mobile.ui.fragment.BaseFragment;
9 | import com.mvp.mobile.ui.widget.MultiSwipeRefreshLayout;
10 |
11 |
12 |
13 | public class SwipeRefreshFragment extends BaseFragment {
14 |
15 | public MultiSwipeRefreshLayout mSwipeRefreshLayout;
16 | private int mPage = 1;
17 |
18 | @Override public void onViewCreated(View view, Bundle savedInstanceState) {
19 | super.onViewCreated(view, savedInstanceState);
20 | trySetupSwipeRefresh(view);
21 | }
22 |
23 |
24 | void trySetupSwipeRefresh(View root) {
25 | mSwipeRefreshLayout = (MultiSwipeRefreshLayout) root.findViewById(
26 | R.id.swipe_refresh_layout);
27 | if (mSwipeRefreshLayout != null) {
28 | mSwipeRefreshLayout.setColorSchemeResources(R.color.refresh_progress_3,
29 | R.color.refresh_progress_2, R.color.refresh_progress_1);
30 | mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
31 | @Override
32 | public void onRefresh() {
33 | requestDataRefresh();
34 | }
35 | });
36 | }
37 | }
38 |
39 |
40 | public void requestDataRefresh() {
41 |
42 | }
43 |
44 |
45 | public void setRefreshing(boolean refreshing) {
46 | if (mSwipeRefreshLayout == null) {
47 | return;
48 | }
49 | if (!refreshing) {
50 | // 防止刷新消失太快
51 | mSwipeRefreshLayout.postDelayed(new Runnable() {
52 | @Override
53 | public void run() {
54 | mSwipeRefreshLayout.setRefreshing(false);
55 | }
56 | }, 1000);
57 | }
58 | else {
59 | mSwipeRefreshLayout.setRefreshing(true);
60 | }
61 | }
62 |
63 |
64 | public void setProgressViewOffset(boolean scale, int start, int end) {
65 | mSwipeRefreshLayout.setProgressViewOffset(scale, start, end);
66 | }
67 |
68 |
69 | public void setSwipeableChildren(MultiSwipeRefreshLayout.CanChildScrollUpCallback canChildScrollUpCallback) {
70 | mSwipeRefreshLayout.setCanChildScrollUpCallback(canChildScrollUpCallback);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/ui/fragment/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.ui.fragment;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 |
7 | import com.mvp.mobile.IBaseView.IBaseView;
8 | import com.mvp.mobile.presenter.BasePresenter;
9 | import com.mvp.mobile.presenter.BasePresenterImpl;
10 | import com.mvp.mobile.ui.base.BaseActivity;
11 |
12 |
13 | public class BaseFragment extends Fragment implements IBaseView {
14 |
15 | public BasePresenter presenter = getPresenter();
16 |
17 | protected BaseActivity baseActivity;
18 |
19 | @Override
20 | public void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | if (presenter != null) presenter.onCreate();
23 | }
24 |
25 | @Override
26 | public void onDestroy() {
27 | super.onDestroy();
28 | if (presenter != null) presenter.onDestroy();
29 | }
30 |
31 | @Override
32 | public void onSuccess() {
33 |
34 | }
35 |
36 | @Override
37 | public void onNetWorkError() {
38 |
39 | }
40 |
41 | public BasePresenterImpl getPresenter() {
42 | return new BasePresenterImpl(this);
43 | }
44 |
45 | public BaseActivity getBaseActivity(){
46 | Activity act = getActivity();
47 | if(act instanceof BaseActivity){
48 | return (BaseActivity)act;
49 | }
50 | return null;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mvp/mobile/ui/widget/MultiSwipeRefreshLayout.java:
--------------------------------------------------------------------------------
1 | package com.mvp.mobile.ui.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.drawable.Drawable;
6 | import android.support.v4.widget.SwipeRefreshLayout;
7 | import android.util.AttributeSet;
8 |
9 | import com.mvp.mobile.R;
10 |
11 | public class MultiSwipeRefreshLayout extends SwipeRefreshLayout {
12 |
13 | private CanChildScrollUpCallback mCanChildScrollUpCallback;
14 | private Drawable mForegroundDrawable;
15 |
16 |
17 | public MultiSwipeRefreshLayout(Context context) {
18 | this(context, null);
19 | }
20 |
21 |
22 | public MultiSwipeRefreshLayout(Context context, AttributeSet attrs) {
23 | super(context, attrs);
24 | final TypedArray a = context.obtainStyledAttributes(attrs,
25 | R.styleable.MultiSwipeRefreshLayout, 0, 0);
26 |
27 | mForegroundDrawable = a.getDrawable(
28 | R.styleable.MultiSwipeRefreshLayout_foreground);
29 | if (mForegroundDrawable != null) {
30 | mForegroundDrawable.setCallback(this);
31 | setWillNotDraw(false);
32 | }
33 | a.recycle();
34 | }
35 |
36 | @Override
37 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
38 | super.onSizeChanged(w, h, oldw, oldh);
39 | if (mForegroundDrawable != null) {
40 | mForegroundDrawable.setBounds(0, 0, w, h);
41 | }
42 | }
43 |
44 |
45 | public void setCanChildScrollUpCallback(CanChildScrollUpCallback canChildScrollUpCallback) {
46 | mCanChildScrollUpCallback = canChildScrollUpCallback;
47 | }
48 |
49 |
50 | public interface CanChildScrollUpCallback {
51 | boolean canSwipeRefreshChildScrollUp();
52 | }
53 |
54 | @Override
55 | public boolean canChildScrollUp() {
56 | if (mCanChildScrollUpCallback != null) {
57 | return mCanChildScrollUpCallback.canSwipeRefreshChildScrollUp();
58 | }
59 | return super.canChildScrollUp();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/bb_menu_discover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kituri/Demo-Retrofit-MVP/d2ac95c9d272769236ee530af79322472275c147/app/src/main/res/drawable-xxxhdpi/bb_menu_discover.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/bb_menu_lessons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kituri/Demo-Retrofit-MVP/d2ac95c9d272769236ee530af79322472275c147/app/src/main/res/drawable-xxxhdpi/bb_menu_lessons.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/bb_menu_me.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kituri/Demo-Retrofit-MVP/d2ac95c9d272769236ee530af79322472275c147/app/src/main/res/drawable-xxxhdpi/bb_menu_me.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/bb_menu_scheduled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kituri/Demo-Retrofit-MVP/d2ac95c9d272769236ee530af79322472275c147/app/src/main/res/drawable-xxxhdpi/bb_menu_scheduled.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fr_discover.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fr_lessons.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fr_me.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fr_scheduled.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_meizhi.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
20 |
21 |
30 |
31 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_home_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/bottombar_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kituri/Demo-Retrofit-MVP/d2ac95c9d272769236ee530af79322472275c147/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kituri/Demo-Retrofit-MVP/d2ac95c9d272769236ee530af79322472275c147/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kituri/Demo-Retrofit-MVP/d2ac95c9d272769236ee530af79322472275c147/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kituri/Demo-Retrofit-MVP/d2ac95c9d272769236ee530af79322472275c147/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kituri/Demo-Retrofit-MVP/d2ac95c9d272769236ee530af79322472275c147/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #FFF2EC
7 | #00000000
8 | #e91e63
9 | #00b0ff
10 | @color/colorPrimary
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 201dp
6 | 36dp
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 | Demo-Retrofit
12 |
13 |
14 | 我的课程
15 | 订课
16 | 发现
17 | 个人
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kituri/Demo-Retrofit-MVP/d2ac95c9d272769236ee530af79322472275c147/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | ## This file is automatically generated by Android Studio.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 | #
7 | # Location of the SDK. This is only used by Gradle.
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | #Wed Apr 27 13:58:25 CST 2016
11 | ndk.dir=E\:\\android-sdk-windows\\ndk-bundle
12 | sdk.dir=E\:\\android-sdk-windows
13 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------