lifecycles) {
145 | //向Fragment的生命周期中注入一些自定义逻辑
146 | lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
147 |
148 | @Override
149 | public void onFragmentCreated(FragmentManager fm, Fragment f, Bundle savedInstanceState) {
150 | // 在配置变化的时候将这个 Fragment 保存下来,在 Activity 由于配置变化重建是重复利用已经创建的Fragment。
151 | // https://developer.android.com/reference/android/app/Fragment.html?hl=zh-cn#setRetainInstance(boolean)
152 | // 在 Activity 中绑定少量的 Fragment 建议这样做,如果需要绑定较多的 Fragment 不建议设置此参数,如 ViewPager 需要展示较多 Fragment
153 | f.setRetainInstance(true);
154 | }
155 |
156 | @Override
157 | public void onFragmentDestroyed(FragmentManager fm, Fragment f) {
158 | ((RefWatcher) ((App) f.getActivity().getApplication()).getAppComponent().extras().get(RefWatcher.class.getName())).watch(f);
159 | }
160 | });
161 | }
162 |
163 |
164 | }
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/app/GreenDaoHelper.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.app;
2 |
3 | import android.app.Application;
4 | import android.database.sqlite.SQLiteDatabase;
5 |
6 | import com.zhy.ganamrs.app.greendao.DaoMaster;
7 | import com.zhy.ganamrs.app.greendao.DaoSession;
8 |
9 | /**
10 | * Created by Administrator on 2017/3/15.
11 | */
12 |
13 | public class GreenDaoHelper {
14 |
15 | private static DaoMaster.DevOpenHelper mHelper;
16 | private static SQLiteDatabase db;
17 | private static DaoMaster mDaoMaster;
18 | private static DaoSession mDaoSession;
19 |
20 | /**
21 | * 初始化greenDao,这个操作建议在Application初始化的时候添加;
22 | * @param application
23 | */
24 | public static void initDatabase(Application application) {
25 | // 通过 DaoMaster 的内部类 DevOpenHelper,你可以得到一个便利的 SQLiteOpenHelper 对象。
26 | // 可能你已经注意到了,你并不需要去编写「CREATE TABLE」这样的 SQL 语句,因为 greenDAO 已经帮你做了。
27 | // 注意:默认的 DaoMaster.DevOpenHelper 会在数据库升级时,删除所有的表,意味着这将导致数据的丢失。
28 | // 所以,在正式的项目中,你还应该做一层封装,来实现数据库的安全升级。
29 | mHelper = new DaoMaster.DevOpenHelper(application, "ganamrs-db", null);
30 | db = mHelper.getWritableDatabase();
31 | // 注意:该数据库连接属于 DaoMaster,所以多个 Session 指的是相同的数据库连接。
32 | mDaoMaster = new DaoMaster(db);
33 | mDaoSession = mDaoMaster.newSession();
34 | }
35 | public static DaoSession getDaoSession() {
36 | return mDaoSession;
37 | }
38 | public static SQLiteDatabase getDb() {
39 | return db;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/app/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.app.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.jess.arms.base.delegate.IFragment;
10 | import com.jess.arms.mvp.IPresenter;
11 | import com.trello.rxlifecycle2.components.support.RxFragment;
12 |
13 | import javax.inject.Inject;
14 |
15 | /**
16 | * Created by Administrator on 2017/7/12.
17 | */
18 |
19 | public abstract class BaseFragment extends RxFragment implements IFragment{
20 |
21 | protected final String TAG = this.getClass().getSimpleName();
22 | @Inject
23 | protected P mPresenter;
24 |
25 | public BaseFragment() {
26 | //必须确保在Fragment实例化时setArguments()
27 | setArguments(new Bundle());
28 | }
29 |
30 |
31 | @Nullable
32 | @Override
33 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
34 | return initView(inflater, container, savedInstanceState);
35 | }
36 |
37 |
38 | @Override
39 | public void onDestroy() {
40 | super.onDestroy();
41 | initVariable();
42 | if (mPresenter != null) mPresenter.onDestroy();//释放资源
43 | this.mPresenter = null;
44 | }
45 |
46 | @Override
47 | public void onCreate(@Nullable Bundle savedInstanceState) {
48 | super.onCreate(savedInstanceState);
49 | initVariable();
50 | }
51 |
52 | // @Override
53 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
54 | //如果setUserVisibleHint()在rootView创建前调用时,那么
55 | //就等到rootView创建完后才回调onFragmentVisibleChange(true)
56 | //保证onFragmentVisibleChange()的回调发生在rootView创建完成之后,以便支持ui操作
57 | if (rootView == null) {
58 | rootView = view;
59 | }
60 | super.onViewCreated(isReuseView ? rootView : view, savedInstanceState);
61 | }
62 |
63 | @Override
64 | public void onStart() {
65 | super.onStart();
66 | if (getUserVisibleHint()) {
67 | if (isFirstVisible) {
68 | onFragmentFirstVisible();
69 | isFirstVisible = false;
70 | }
71 | onFragmentVisibleChange(true);
72 | isFragmentVisible = true;
73 | }
74 | }
75 |
76 | /**
77 | * 是否使用eventBus,默认为使用(true),
78 | *
79 | * @return
80 | */
81 | @Override
82 | public boolean useEventBus() {
83 | return true;
84 | }
85 |
86 |
87 |
88 | private boolean isFragmentVisible;
89 | private boolean isReuseView;
90 | private boolean isFirstVisible;
91 | private View rootView;
92 |
93 | private void initVariable() {
94 | isFirstVisible = true;
95 | isFragmentVisible = false;
96 | rootView = null;
97 | isReuseView = true;
98 | }
99 | //setUserVisibleHint()在Fragment创建时会先被调用一次,传入isVisibleToUser = false
100 | //如果当前Fragment可见,那么setUserVisibleHint()会再次被调用一次,传入isVisibleToUser = true
101 | //如果Fragment从可见->不可见,那么setUserVisibleHint()也会被调用,传入isVisibleToUser = false
102 | //总结:setUserVisibleHint()除了Fragment的可见状态发生变化时会被回调外,在new Fragment()时也会被回调
103 | //如果我们需要在 Fragment 可见与不可见时干点事,用这个的话就会有多余的回调了,那么就需要重新封装一个
104 | @Override
105 | public void setUserVisibleHint(boolean isVisibleToUser) {
106 | super.setUserVisibleHint(isVisibleToUser);
107 | //setUserVisibleHint()有可能在fragment的生命周期外被调用
108 | if (rootView == null) {
109 | return;
110 | }
111 | if (isFirstVisible && isVisibleToUser) {
112 | onFragmentFirstVisible();
113 | isFirstVisible = false;
114 | }
115 | if (isVisibleToUser) {
116 | onFragmentVisibleChange(true);
117 | isFragmentVisible = true;
118 | return;
119 | }
120 | if (isFragmentVisible) {
121 | isFragmentVisible = false;
122 | onFragmentVisibleChange(false);
123 | }
124 | }
125 | /**
126 | * 设置是否使用 view 的复用,默认开启
127 | * view 的复用是指,ViewPager 在销毁和重建 Fragment 时会不断调用 onCreateView() -> onDestroyView()
128 | * 之间的生命函数,这样可能会出现重复创建 view 的情况,导致界面上显示多个相同的 Fragment
129 | * view 的复用其实就是指保存第一次创建的 view,后面再 onCreateView() 时直接返回第一次创建的 view
130 | *
131 | * @param isReuse
132 | */
133 | protected void reuseView(boolean isReuse) {
134 | isReuseView = isReuse;
135 | }
136 |
137 | /**
138 | * 去除setUserVisibleHint()多余的回调场景,保证只有当fragment可见状态发生变化时才回调
139 | * 回调时机在view创建完后,所以支持ui操作,解决在setUserVisibleHint()里进行ui操作有可能报null异常的问题
140 | *
141 | * 可在该回调方法里进行一些ui显示与隐藏,比如加载框的显示和隐藏
142 | *
143 | * @param isVisible true 不可见 -> 可见
144 | * false 可见 -> 不可见
145 | */
146 | protected void onFragmentVisibleChange(boolean isVisible) {
147 |
148 | }
149 |
150 | /**
151 | * 在fragment首次可见时回调,可在这里进行加载数据,保证只在第一次打开Fragment时才会加载数据,
152 | * 这样就可以防止每次进入都重复加载数据
153 | * 该方法会在 onFragmentVisibleChange() 之前调用,所以第一次打开时,可以用一个全局变量表示数据下载状态,
154 | * 然后在该方法内将状态设置为下载状态,接着去执行下载的任务
155 | * 最后在 onFragmentVisibleChange() 里根据数据下载状态来控制下载进度ui控件的显示与隐藏
156 | */
157 | protected void onFragmentFirstVisible() {
158 |
159 | }
160 |
161 | protected boolean isFragmentVisible() {
162 | return isFragmentVisible;
163 | }
164 |
165 |
166 | }
167 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/app/greendao/DaoGankEntityDao.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.app.greendao;
2 |
3 | import android.database.Cursor;
4 | import android.database.sqlite.SQLiteStatement;
5 |
6 | import org.greenrobot.greendao.AbstractDao;
7 | import org.greenrobot.greendao.Property;
8 | import org.greenrobot.greendao.internal.DaoConfig;
9 | import org.greenrobot.greendao.database.Database;
10 | import org.greenrobot.greendao.database.DatabaseStatement;
11 |
12 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
13 |
14 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
15 | /**
16 | * DAO for table "DAO_GANK_ENTITY".
17 | */
18 | public class DaoGankEntityDao extends AbstractDao {
19 |
20 | public static final String TABLENAME = "DAO_GANK_ENTITY";
21 |
22 | /**
23 | * Properties of entity DaoGankEntity.
24 | * Can be used for QueryBuilder and for referencing column names.
25 | */
26 | public static class Properties {
27 | public final static Property _id = new Property(0, String.class, "_id", false, "_ID");
28 | public final static Property CreatedAt = new Property(1, String.class, "createdAt", false, "CREATED_AT");
29 | public final static Property Desc = new Property(2, String.class, "desc", false, "DESC");
30 | public final static Property PublishedAt = new Property(3, String.class, "publishedAt", false, "PUBLISHED_AT");
31 | public final static Property Source = new Property(4, String.class, "source", false, "SOURCE");
32 | public final static Property Type = new Property(5, String.class, "type", false, "TYPE");
33 | public final static Property Url = new Property(6, String.class, "url", false, "URL");
34 | public final static Property Used = new Property(7, boolean.class, "used", false, "USED");
35 | public final static Property Who = new Property(8, String.class, "who", false, "WHO");
36 | public final static Property Addtime = new Property(9, String.class, "addtime", false, "ADDTIME");
37 | }
38 |
39 |
40 | public DaoGankEntityDao(DaoConfig config) {
41 | super(config);
42 | }
43 |
44 | public DaoGankEntityDao(DaoConfig config, DaoSession daoSession) {
45 | super(config, daoSession);
46 | }
47 |
48 | /** Creates the underlying database table. */
49 | public static void createTable(Database db, boolean ifNotExists) {
50 | String constraint = ifNotExists? "IF NOT EXISTS ": "";
51 | db.execSQL("CREATE TABLE " + constraint + "\"DAO_GANK_ENTITY\" (" + //
52 | "\"_ID\" TEXT," + // 0: _id
53 | "\"CREATED_AT\" TEXT," + // 1: createdAt
54 | "\"DESC\" TEXT," + // 2: desc
55 | "\"PUBLISHED_AT\" TEXT," + // 3: publishedAt
56 | "\"SOURCE\" TEXT," + // 4: source
57 | "\"TYPE\" TEXT," + // 5: type
58 | "\"URL\" TEXT," + // 6: url
59 | "\"USED\" INTEGER NOT NULL ," + // 7: used
60 | "\"WHO\" TEXT," + // 8: who
61 | "\"ADDTIME\" TEXT);"); // 9: addtime
62 | }
63 |
64 | /** Drops the underlying database table. */
65 | public static void dropTable(Database db, boolean ifExists) {
66 | String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"DAO_GANK_ENTITY\"";
67 | db.execSQL(sql);
68 | }
69 |
70 | @Override
71 | protected final void bindValues(DatabaseStatement stmt, DaoGankEntity entity) {
72 | stmt.clearBindings();
73 |
74 | String _id = entity.get_id();
75 | if (_id != null) {
76 | stmt.bindString(1, _id);
77 | }
78 |
79 | String createdAt = entity.getCreatedAt();
80 | if (createdAt != null) {
81 | stmt.bindString(2, createdAt);
82 | }
83 |
84 | String desc = entity.getDesc();
85 | if (desc != null) {
86 | stmt.bindString(3, desc);
87 | }
88 |
89 | String publishedAt = entity.getPublishedAt();
90 | if (publishedAt != null) {
91 | stmt.bindString(4, publishedAt);
92 | }
93 |
94 | String source = entity.getSource();
95 | if (source != null) {
96 | stmt.bindString(5, source);
97 | }
98 |
99 | String type = entity.getType();
100 | if (type != null) {
101 | stmt.bindString(6, type);
102 | }
103 |
104 | String url = entity.getUrl();
105 | if (url != null) {
106 | stmt.bindString(7, url);
107 | }
108 | stmt.bindLong(8, entity.getUsed() ? 1L: 0L);
109 |
110 | String who = entity.getWho();
111 | if (who != null) {
112 | stmt.bindString(9, who);
113 | }
114 |
115 | String addtime = entity.getAddtime();
116 | if (addtime != null) {
117 | stmt.bindString(10, addtime);
118 | }
119 | }
120 |
121 | @Override
122 | protected final void bindValues(SQLiteStatement stmt, DaoGankEntity entity) {
123 | stmt.clearBindings();
124 |
125 | String _id = entity.get_id();
126 | if (_id != null) {
127 | stmt.bindString(1, _id);
128 | }
129 |
130 | String createdAt = entity.getCreatedAt();
131 | if (createdAt != null) {
132 | stmt.bindString(2, createdAt);
133 | }
134 |
135 | String desc = entity.getDesc();
136 | if (desc != null) {
137 | stmt.bindString(3, desc);
138 | }
139 |
140 | String publishedAt = entity.getPublishedAt();
141 | if (publishedAt != null) {
142 | stmt.bindString(4, publishedAt);
143 | }
144 |
145 | String source = entity.getSource();
146 | if (source != null) {
147 | stmt.bindString(5, source);
148 | }
149 |
150 | String type = entity.getType();
151 | if (type != null) {
152 | stmt.bindString(6, type);
153 | }
154 |
155 | String url = entity.getUrl();
156 | if (url != null) {
157 | stmt.bindString(7, url);
158 | }
159 | stmt.bindLong(8, entity.getUsed() ? 1L: 0L);
160 |
161 | String who = entity.getWho();
162 | if (who != null) {
163 | stmt.bindString(9, who);
164 | }
165 |
166 | String addtime = entity.getAddtime();
167 | if (addtime != null) {
168 | stmt.bindString(10, addtime);
169 | }
170 | }
171 |
172 | @Override
173 | public Void readKey(Cursor cursor, int offset) {
174 | return null;
175 | }
176 |
177 | @Override
178 | public DaoGankEntity readEntity(Cursor cursor, int offset) {
179 | DaoGankEntity entity = new DaoGankEntity( //
180 | cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // _id
181 | cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // createdAt
182 | cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // desc
183 | cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // publishedAt
184 | cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // source
185 | cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // type
186 | cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // url
187 | cursor.getShort(offset + 7) != 0, // used
188 | cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // who
189 | cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // addtime
190 | );
191 | return entity;
192 | }
193 |
194 | @Override
195 | public void readEntity(Cursor cursor, DaoGankEntity entity, int offset) {
196 | entity.set_id(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
197 | entity.setCreatedAt(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
198 | entity.setDesc(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
199 | entity.setPublishedAt(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
200 | entity.setSource(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
201 | entity.setType(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
202 | entity.setUrl(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
203 | entity.setUsed(cursor.getShort(offset + 7) != 0);
204 | entity.setWho(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
205 | entity.setAddtime(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
206 | }
207 |
208 | @Override
209 | protected final Void updateKeyAfterInsert(DaoGankEntity entity, long rowId) {
210 | // Unsupported or missing PK type
211 | return null;
212 | }
213 |
214 | @Override
215 | public Void getKey(DaoGankEntity entity) {
216 | return null;
217 | }
218 |
219 | @Override
220 | public boolean hasKey(DaoGankEntity entity) {
221 | // TODO
222 | return false;
223 | }
224 |
225 | @Override
226 | protected final boolean isEntityUpdateable() {
227 | return true;
228 | }
229 |
230 | }
231 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/app/greendao/DaoMaster.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.app.greendao;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.database.sqlite.SQLiteDatabase.CursorFactory;
6 | import android.util.Log;
7 |
8 | import org.greenrobot.greendao.AbstractDaoMaster;
9 | import org.greenrobot.greendao.database.StandardDatabase;
10 | import org.greenrobot.greendao.database.Database;
11 | import org.greenrobot.greendao.database.DatabaseOpenHelper;
12 | import org.greenrobot.greendao.identityscope.IdentityScopeType;
13 |
14 |
15 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
16 | /**
17 | * Master of DAO (schema version 1): knows all DAOs.
18 | */
19 | public class DaoMaster extends AbstractDaoMaster {
20 | public static final int SCHEMA_VERSION = 1;
21 |
22 | /** Creates underlying database table using DAOs. */
23 | public static void createAllTables(Database db, boolean ifNotExists) {
24 | DaoGankEntityDao.createTable(db, ifNotExists);
25 | }
26 |
27 | /** Drops underlying database table using DAOs. */
28 | public static void dropAllTables(Database db, boolean ifExists) {
29 | DaoGankEntityDao.dropTable(db, ifExists);
30 | }
31 |
32 | /**
33 | * WARNING: Drops all table on Upgrade! Use only during development.
34 | * Convenience method using a {@link DevOpenHelper}.
35 | */
36 | public static DaoSession newDevSession(Context context, String name) {
37 | Database db = new DevOpenHelper(context, name).getWritableDb();
38 | DaoMaster daoMaster = new DaoMaster(db);
39 | return daoMaster.newSession();
40 | }
41 |
42 | public DaoMaster(SQLiteDatabase db) {
43 | this(new StandardDatabase(db));
44 | }
45 |
46 | public DaoMaster(Database db) {
47 | super(db, SCHEMA_VERSION);
48 | registerDaoClass(DaoGankEntityDao.class);
49 | }
50 |
51 | public DaoSession newSession() {
52 | return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
53 | }
54 |
55 | public DaoSession newSession(IdentityScopeType type) {
56 | return new DaoSession(db, type, daoConfigMap);
57 | }
58 |
59 | /**
60 | * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} -
61 | */
62 | public static abstract class OpenHelper extends DatabaseOpenHelper {
63 | public OpenHelper(Context context, String name) {
64 | super(context, name, SCHEMA_VERSION);
65 | }
66 |
67 | public OpenHelper(Context context, String name, CursorFactory factory) {
68 | super(context, name, factory, SCHEMA_VERSION);
69 | }
70 |
71 | @Override
72 | public void onCreate(Database db) {
73 | Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
74 | createAllTables(db, false);
75 | }
76 | }
77 |
78 | /** WARNING: Drops all table on Upgrade! Use only during development. */
79 | public static class DevOpenHelper extends OpenHelper {
80 | public DevOpenHelper(Context context, String name) {
81 | super(context, name);
82 | }
83 |
84 | public DevOpenHelper(Context context, String name, CursorFactory factory) {
85 | super(context, name, factory);
86 | }
87 |
88 | @Override
89 | public void onUpgrade(Database db, int oldVersion, int newVersion) {
90 | Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
91 | dropAllTables(db, true);
92 | onCreate(db);
93 | }
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/app/greendao/DaoSession.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.app.greendao;
2 |
3 | import java.util.Map;
4 |
5 | import org.greenrobot.greendao.AbstractDao;
6 | import org.greenrobot.greendao.AbstractDaoSession;
7 | import org.greenrobot.greendao.database.Database;
8 | import org.greenrobot.greendao.identityscope.IdentityScopeType;
9 | import org.greenrobot.greendao.internal.DaoConfig;
10 |
11 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
12 |
13 | import com.zhy.ganamrs.app.greendao.DaoGankEntityDao;
14 |
15 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
16 |
17 | /**
18 | * {@inheritDoc}
19 | *
20 | * @see org.greenrobot.greendao.AbstractDaoSession
21 | */
22 | public class DaoSession extends AbstractDaoSession {
23 |
24 | private final DaoConfig daoGankEntityDaoConfig;
25 |
26 | private final DaoGankEntityDao daoGankEntityDao;
27 |
28 | public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig>
29 | daoConfigMap) {
30 | super(db);
31 |
32 | daoGankEntityDaoConfig = daoConfigMap.get(DaoGankEntityDao.class).clone();
33 | daoGankEntityDaoConfig.initIdentityScope(type);
34 |
35 | daoGankEntityDao = new DaoGankEntityDao(daoGankEntityDaoConfig, this);
36 |
37 | registerDao(DaoGankEntity.class, daoGankEntityDao);
38 | }
39 |
40 | public void clear() {
41 | daoGankEntityDaoConfig.clearIdentityScope();
42 | }
43 |
44 | public DaoGankEntityDao getDaoGankEntityDao() {
45 | return daoGankEntityDao;
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/app/service/DemoService.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.app.service;
2 |
3 | import com.jess.arms.base.BaseService;
4 |
5 | /**
6 | * Created by jess on 9/7/16 16:59
7 | * Contact with jess.yan.effort@gmail.com
8 | */
9 | public class DemoService extends BaseService {
10 | @Override
11 | public void init() {
12 |
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/app/utils/CategoryType.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.app.utils;
2 |
3 | /**
4 | * Created by Administrator on 2017/7/4.
5 | */
6 |
7 | public class CategoryType {
8 |
9 | public static final String ANDROID_STR = "Android";
10 | public static final String IOS_STR = "iOS";
11 | public static final String QIAN_STR = "前端";
12 | public static final String GIRLS_STR = "福利";
13 |
14 |
15 | public static final int ANDROID_IOS = 1;
16 | public static final int GIRLS = 2;
17 |
18 | public static String getPageTitleByPosition(int position) {
19 | if (position == 0){
20 | return ANDROID_STR;
21 | } else if (position == 1){
22 | return IOS_STR;
23 | } else if (position == 2){
24 | return QIAN_STR;
25 | } else {
26 | return "";
27 | }
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/app/utils/RxUtils.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.app.utils;
2 |
3 | import com.jess.arms.mvp.IView;
4 | import com.trello.rxlifecycle2.LifecycleTransformer;
5 | import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
6 | import com.trello.rxlifecycle2.components.support.RxFragment;
7 |
8 | import io.reactivex.Observable;
9 | import io.reactivex.ObservableTransformer;
10 | import io.reactivex.android.schedulers.AndroidSchedulers;
11 | import io.reactivex.schedulers.Schedulers;
12 |
13 |
14 | /**
15 | * Created by jess on 11/10/2016 16:39
16 | * Contact with jess.yan.effort@gmail.com
17 | */
18 |
19 | public class RxUtils {
20 |
21 | public static ObservableTransformer applySchedulers(final IView view) {
22 | return new ObservableTransformer() {
23 | @Override
24 | public Observable apply(Observable observable) {
25 | return observable.subscribeOn(Schedulers.io())
26 | .doOnSubscribe(disposable -> {
27 | //显示进度条
28 | view.showLoading();
29 | })
30 | .subscribeOn(AndroidSchedulers.mainThread())
31 | .observeOn(AndroidSchedulers.mainThread())
32 | //隐藏进度条
33 | .doAfterTerminate(view::hideLoading)
34 | .compose(RxUtils.bindToLifecycle(view));
35 | }
36 | };
37 | }
38 |
39 |
40 | public static LifecycleTransformer bindToLifecycle(IView view) {
41 | if (view instanceof RxAppCompatActivity) {
42 | return ((RxAppCompatActivity) view).bindToLifecycle();
43 | } else if (view instanceof RxFragment) {
44 | return ((RxFragment) view).bindToLifecycle();
45 | } else {
46 | throw new IllegalArgumentException("view isn't activity or fragment");
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/component/ArticleComponent.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.component;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Component;
6 |
7 | import com.jess.arms.di.component.AppComponent;
8 |
9 | import com.zhy.ganamrs.di.module.ArticleModule;
10 |
11 | import com.zhy.ganamrs.mvp.ui.fragment.ArticleFragment;
12 |
13 | @ActivityScope
14 | @Component(modules = ArticleModule.class, dependencies = AppComponent.class)
15 | public interface ArticleComponent {
16 | void inject(ArticleFragment fragment);
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/component/CategoryComponent.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.component;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Component;
6 |
7 | import com.jess.arms.di.component.AppComponent;
8 |
9 | import com.zhy.ganamrs.di.module.CategoryModule;
10 |
11 | import com.zhy.ganamrs.mvp.ui.fragment.CategoryFragment;
12 |
13 | @ActivityScope
14 | @Component(modules = CategoryModule.class, dependencies = AppComponent.class)
15 | public interface CategoryComponent {
16 | void inject(CategoryFragment fragment);
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/component/CollectComponent.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.component;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Component;
6 |
7 | import com.jess.arms.di.component.AppComponent;
8 |
9 | import com.zhy.ganamrs.di.module.CollectModule;
10 |
11 | import com.zhy.ganamrs.mvp.ui.fragment.CollectFragment;
12 |
13 | @ActivityScope
14 | @Component(modules = CollectModule.class, dependencies = AppComponent.class)
15 | public interface CollectComponent {
16 | void inject(CollectFragment fragment);
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/component/DetailComponent.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.component;
2 |
3 | import com.jess.arms.di.component.AppComponent;
4 | import com.jess.arms.di.scope.ActivityScope;
5 | import com.zhy.ganamrs.di.module.DetailModule;
6 | import com.zhy.ganamrs.mvp.ui.activity.DetailActivity;
7 |
8 | import dagger.Component;
9 |
10 | @ActivityScope
11 | @Component(modules = DetailModule.class, dependencies = AppComponent.class)
12 | public interface DetailComponent {
13 | void inject(DetailActivity activity);
14 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/component/HomeComponent.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.component;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Component;
6 |
7 | import com.jess.arms.di.component.AppComponent;
8 |
9 | import com.zhy.ganamrs.di.module.HomeModule;
10 |
11 | import com.zhy.ganamrs.mvp.ui.fragment.HomeFragment;
12 |
13 | @ActivityScope
14 | @Component(modules = HomeModule.class, dependencies = AppComponent.class)
15 | public interface HomeComponent {
16 | void inject(HomeFragment fragment);
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/component/MainComponent.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.component;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Component;
6 |
7 | import com.jess.arms.di.component.AppComponent;
8 |
9 | import com.zhy.ganamrs.di.module.MainModule;
10 |
11 | import com.zhy.ganamrs.mvp.ui.activity.MainActivity;
12 |
13 | @ActivityScope
14 | @Component(modules = MainModule.class, dependencies = AppComponent.class)
15 | public interface MainComponent {
16 | void inject(MainActivity activity);
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/component/MeiziComponent.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.component;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Component;
6 |
7 | import com.jess.arms.di.component.AppComponent;
8 |
9 | import com.zhy.ganamrs.di.module.MeiziModule;
10 |
11 | import com.zhy.ganamrs.mvp.ui.fragment.MeiziFragment;
12 |
13 | @ActivityScope
14 | @Component(modules = MeiziModule.class, dependencies = AppComponent.class)
15 | public interface MeiziComponent {
16 | void inject(MeiziFragment fragment);
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/component/WelfareComponent.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.component;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Component;
6 |
7 | import com.jess.arms.di.component.AppComponent;
8 |
9 | import com.zhy.ganamrs.di.module.WelfareModule;
10 |
11 | import com.zhy.ganamrs.mvp.ui.fragment.WelfareFragment;
12 |
13 | @ActivityScope
14 | @Component(modules = WelfareModule.class, dependencies = AppComponent.class)
15 | public interface WelfareComponent {
16 | void inject(WelfareFragment fragment);
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/module/ArticleModule.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.module;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Module;
6 | import dagger.Provides;
7 |
8 | import com.zhy.ganamrs.mvp.contract.ArticleContract;
9 | import com.zhy.ganamrs.mvp.model.ArticleModel;
10 |
11 |
12 | @Module
13 | public class ArticleModule {
14 | private ArticleContract.View view;
15 |
16 | /**
17 | * 构建ArticleModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
18 | *
19 | * @param view
20 | */
21 | public ArticleModule(ArticleContract.View view) {
22 | this.view = view;
23 | }
24 |
25 | @ActivityScope
26 | @Provides
27 | ArticleContract.View provideArticleView() {
28 | return this.view;
29 | }
30 |
31 | @ActivityScope
32 | @Provides
33 | ArticleContract.Model provideArticleModel(ArticleModel model) {
34 | return model;
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/module/CategoryModule.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.module;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Module;
6 | import dagger.Provides;
7 |
8 | import com.zhy.ganamrs.mvp.contract.CategoryContract;
9 | import com.zhy.ganamrs.mvp.model.CategoryModel;
10 |
11 |
12 | @Module
13 | public class CategoryModule {
14 | private CategoryContract.View view;
15 |
16 | /**
17 | * 构建CategoryModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
18 | *
19 | * @param view
20 | */
21 | public CategoryModule(CategoryContract.View view) {
22 | this.view = view;
23 | }
24 |
25 | @ActivityScope
26 | @Provides
27 | CategoryContract.View provideCategoryView() {
28 | return this.view;
29 | }
30 |
31 | @ActivityScope
32 | @Provides
33 | CategoryContract.Model provideCategoryModel(CategoryModel model) {
34 | return model;
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/module/CollectModule.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.module;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Module;
6 | import dagger.Provides;
7 |
8 | import com.zhy.ganamrs.mvp.contract.CollectContract;
9 | import com.zhy.ganamrs.mvp.model.CollectModel;
10 |
11 |
12 | @Module
13 | public class CollectModule {
14 | private CollectContract.View view;
15 |
16 | /**
17 | * 构建CollectModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
18 | *
19 | * @param view
20 | */
21 | public CollectModule(CollectContract.View view) {
22 | this.view = view;
23 | }
24 |
25 | @ActivityScope
26 | @Provides
27 | CollectContract.View provideCollectView() {
28 | return this.view;
29 | }
30 |
31 | @ActivityScope
32 | @Provides
33 | CollectContract.Model provideCollectModel(CollectModel model) {
34 | return model;
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/module/DetailModule.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.module;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Module;
6 | import dagger.Provides;
7 |
8 | import com.zhy.ganamrs.mvp.contract.DetailContract;
9 | import com.zhy.ganamrs.mvp.model.DetailModel;
10 |
11 |
12 | @Module
13 | public class DetailModule {
14 | private DetailContract.View view;
15 |
16 | /**
17 | * 构建DetailModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
18 | *
19 | * @param view
20 | */
21 | public DetailModule(DetailContract.View view) {
22 | this.view = view;
23 | }
24 |
25 | @ActivityScope
26 | @Provides
27 | DetailContract.View provideDetailView() {
28 | return this.view;
29 | }
30 |
31 | @ActivityScope
32 | @Provides
33 | DetailContract.Model provideDetailModel(DetailModel model) {
34 | return model;
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/module/HomeModule.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.module;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Module;
6 | import dagger.Provides;
7 |
8 | import com.zhy.ganamrs.mvp.contract.HomeContract;
9 | import com.zhy.ganamrs.mvp.model.HomeModel;
10 |
11 |
12 | @Module
13 | public class HomeModule {
14 | private HomeContract.View view;
15 |
16 | /**
17 | * 构建HomeModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
18 | *
19 | * @param view
20 | */
21 | public HomeModule(HomeContract.View view) {
22 | this.view = view;
23 | }
24 |
25 | @ActivityScope
26 | @Provides
27 | HomeContract.View provideHomeView() {
28 | return this.view;
29 | }
30 |
31 | @ActivityScope
32 | @Provides
33 | HomeContract.Model provideHomeModel(HomeModel model) {
34 | return model;
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/module/MainModule.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.module;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Module;
6 | import dagger.Provides;
7 |
8 | import com.zhy.ganamrs.mvp.contract.MainContract;
9 | import com.zhy.ganamrs.mvp.model.MainModel;
10 |
11 |
12 | @Module
13 | public class MainModule {
14 | private MainContract.View view;
15 |
16 | /**
17 | * 构建MainModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
18 | *
19 | * @param view
20 | */
21 | public MainModule(MainContract.View view) {
22 | this.view = view;
23 | }
24 |
25 | @ActivityScope
26 | @Provides
27 | MainContract.View provideMainView() {
28 | return this.view;
29 | }
30 |
31 | @ActivityScope
32 | @Provides
33 | MainContract.Model provideMainModel(MainModel model) {
34 | return model;
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/module/MeiziModule.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.module;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Module;
6 | import dagger.Provides;
7 |
8 | import com.zhy.ganamrs.mvp.contract.MeiziContract;
9 | import com.zhy.ganamrs.mvp.model.MeiziModel;
10 |
11 |
12 | @Module
13 | public class MeiziModule {
14 | private MeiziContract.View view;
15 |
16 | /**
17 | * 构建MeiziModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
18 | *
19 | * @param view
20 | */
21 | public MeiziModule(MeiziContract.View view) {
22 | this.view = view;
23 | }
24 |
25 | @ActivityScope
26 | @Provides
27 | MeiziContract.View provideMeiziView() {
28 | return this.view;
29 | }
30 |
31 | @ActivityScope
32 | @Provides
33 | MeiziContract.Model provideMeiziModel(MeiziModel model) {
34 | return model;
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/di/module/WelfareModule.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.di.module;
2 |
3 | import com.jess.arms.di.scope.ActivityScope;
4 |
5 | import dagger.Module;
6 | import dagger.Provides;
7 |
8 | import com.zhy.ganamrs.mvp.contract.WelfareContract;
9 | import com.zhy.ganamrs.mvp.model.WelfareModel;
10 |
11 |
12 | @Module
13 | public class WelfareModule {
14 | private WelfareContract.View view;
15 |
16 | /**
17 | * 构建WelfareModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
18 | *
19 | * @param view
20 | */
21 | public WelfareModule(WelfareContract.View view) {
22 | this.view = view;
23 | }
24 |
25 | @ActivityScope
26 | @Provides
27 | WelfareContract.View provideWelfareView() {
28 | return this.view;
29 | }
30 |
31 | @ActivityScope
32 | @Provides
33 | WelfareContract.Model provideWelfareModel(WelfareModel model) {
34 | return model;
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/contract/ArticleContract.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.contract;
2 |
3 | import com.jess.arms.mvp.IView;
4 | import com.jess.arms.mvp.IModel;
5 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
6 |
7 | import java.util.List;
8 |
9 |
10 | public interface ArticleContract {
11 | //对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息
12 | interface View extends IView {
13 | void startLoadMore();
14 | void endLoadMore();
15 |
16 | void setAdapter(List entity);
17 | }
18 |
19 | //Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存
20 | interface Model extends IModel {
21 | List getEntity();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/contract/CategoryContract.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.contract;
2 |
3 | import com.jess.arms.base.DefaultAdapter;
4 | import com.jess.arms.mvp.IModel;
5 | import com.jess.arms.mvp.IView;
6 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
7 |
8 | import io.reactivex.Observable;
9 |
10 |
11 | public interface CategoryContract {
12 | //对于经常使用的关于UI的方法可以定义到BaseView中,如显示隐藏进度条,和显示文字消息
13 | interface View extends IView {
14 | void startLoadMore();
15 | void endLoadMore();
16 | void setAdapter(DefaultAdapter mAdapter);
17 | }
18 |
19 | //Model层定义接口,外部只需关心model返回的数据,无需关心内部细节,及是否使用缓存
20 | interface Model extends IModel {
21 | Observable gank(String type,String page);
22 | }
23 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/contract/CollectContract.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.contract;
2 |
3 | import com.jess.arms.mvp.IView;
4 | import com.jess.arms.mvp.IModel;
5 |
6 |
7 | public interface CollectContract {
8 | //对于经常使用的关于UI的方法可以定义到BaseView中,如显示隐藏进度条,和显示文字消息
9 | interface View extends IView {
10 |
11 | }
12 |
13 | //Model层定义接口,外部只需关心model返回的数据,无需关心内部细节,及是否使用缓存
14 | interface Model extends IModel {
15 |
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/contract/DetailContract.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.contract;
2 |
3 | import com.jess.arms.mvp.IModel;
4 | import com.jess.arms.mvp.IView;
5 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
6 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
7 |
8 | import java.util.List;
9 |
10 | import io.reactivex.Observable;
11 |
12 |
13 | public interface DetailContract {
14 | //对于经常使用的关于UI的方法可以定义到BaseView中,如显示隐藏进度条,和显示文字消息
15 | interface View extends IView {
16 |
17 | void setData(String url);
18 | void onFavoriteChange(boolean isFavorite);
19 | }
20 |
21 | //Model层定义接口,外部只需关心model返回的数据,无需关心内部细节,及是否使用缓存
22 | interface Model extends IModel {
23 | Observable getRandomGirl();
24 | List queryById(String id);
25 | void removeByid(String id);
26 | void addGankEntity(DaoGankEntity entity);
27 | }
28 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/contract/HomeContract.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.contract;
2 |
3 | import com.jess.arms.mvp.IView;
4 | import com.jess.arms.mvp.IModel;
5 |
6 |
7 | public interface HomeContract {
8 | //对于经常使用的关于UI的方法可以定义到BaseView中,如显示隐藏进度条,和显示文字消息
9 | interface View extends IView {
10 |
11 | }
12 |
13 | //Model层定义接口,外部只需关心model返回的数据,无需关心内部细节,及是否使用缓存
14 | interface Model extends IModel {
15 |
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/contract/MainContract.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.contract;
2 |
3 | import com.jess.arms.mvp.IView;
4 | import com.jess.arms.mvp.IModel;
5 | import com.tbruyelle.rxpermissions2.RxPermissions;
6 |
7 |
8 | public interface MainContract {
9 | //对于经常使用的关于UI的方法可以定义到BaseView中,如显示隐藏进度条,和显示文字消息
10 | interface View extends IView {
11 | //申请权限
12 | RxPermissions getRxPermissions();
13 | }
14 |
15 | //Model层定义接口,外部只需关心model返回的数据,无需关心内部细节,及是否使用缓存
16 | interface Model extends IModel {
17 |
18 | }
19 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/contract/MeiziContract.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.contract;
2 |
3 | import com.jess.arms.mvp.IView;
4 | import com.jess.arms.mvp.IModel;
5 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
6 |
7 | import java.util.List;
8 |
9 |
10 | public interface MeiziContract {
11 | //对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息
12 | interface View extends IView {
13 | void startLoadMore();
14 | void endLoadMore();
15 |
16 | void setAdapter(List entity);
17 | }
18 |
19 | //Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存
20 | interface Model extends IModel {
21 | List getEntity();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/contract/WelfareContract.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.contract;
2 |
3 | import android.os.Message;
4 |
5 | import com.jess.arms.mvp.IModel;
6 | import com.jess.arms.mvp.IView;
7 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
8 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
9 |
10 | import java.util.List;
11 |
12 | import io.reactivex.Observable;
13 |
14 |
15 | public interface WelfareContract {
16 | //对于经常使用的关于UI的方法可以定义到BaseView中,如显示隐藏进度条,和显示文字消息
17 | interface View extends IView {
18 | void startLoadMore();
19 | void endLoadMore();
20 |
21 | void setNewData(List mData);
22 |
23 | void setAddData(List results);
24 | }
25 |
26 | //Model层定义接口,外部只需关心model返回的数据,无需关心内部细节,及是否使用缓存
27 | interface Model extends IModel {
28 | Observable getRandomGirl();
29 |
30 | Message addGankEntity(DaoGankEntity daoGankEntity);
31 | }
32 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/model/ArticleModel.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.model;
2 |
3 | import android.app.Application;
4 |
5 | import com.google.gson.Gson;
6 | import com.jess.arms.di.scope.ActivityScope;
7 | import com.jess.arms.integration.IRepositoryManager;
8 | import com.jess.arms.mvp.BaseModel;
9 | import com.zhy.ganamrs.app.GreenDaoHelper;
10 | import com.zhy.ganamrs.app.greendao.DaoGankEntityDao;
11 | import com.zhy.ganamrs.app.utils.CategoryType;
12 | import com.zhy.ganamrs.mvp.contract.ArticleContract;
13 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
14 |
15 | import java.util.List;
16 |
17 | import javax.inject.Inject;
18 |
19 |
20 | @ActivityScope
21 | public class ArticleModel extends BaseModel implements ArticleContract.Model {
22 | private Gson mGson;
23 | private Application mApplication;
24 |
25 | @Inject
26 | public ArticleModel(IRepositoryManager repositoryManager, Gson gson, Application application) {
27 | super(repositoryManager);
28 | this.mGson = gson;
29 | this.mApplication = application;
30 | }
31 |
32 | @Override
33 | public void onDestroy() {
34 | super.onDestroy();
35 | this.mGson = null;
36 | this.mApplication = null;
37 | }
38 |
39 | @Override
40 | public List getEntity() {
41 | return GreenDaoHelper.getDaoSession().getDaoGankEntityDao()
42 | .queryBuilder()
43 | .where(DaoGankEntityDao.Properties.Type.notEq(CategoryType.GIRLS_STR))
44 | .orderDesc(DaoGankEntityDao.Properties.Addtime)
45 | .list();
46 | }
47 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/model/CategoryModel.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.model;
2 |
3 | import android.app.Application;
4 |
5 | import com.google.gson.Gson;
6 | import com.jess.arms.di.scope.ActivityScope;
7 | import com.jess.arms.integration.IRepositoryManager;
8 | import com.jess.arms.mvp.BaseModel;
9 | import com.zhy.ganamrs.mvp.contract.CategoryContract;
10 | import com.zhy.ganamrs.mvp.model.api.service.CommonService;
11 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
12 |
13 | import javax.inject.Inject;
14 |
15 | import io.reactivex.Observable;
16 |
17 |
18 | @ActivityScope
19 | public class CategoryModel extends BaseModel implements CategoryContract.Model {
20 | private Gson mGson;
21 | private Application mApplication;
22 | public static final int USERS_PER_PAGESIZE = 10;
23 | @Inject
24 | public CategoryModel(IRepositoryManager repositoryManager, Gson gson, Application application) {
25 | super(repositoryManager);
26 | this.mGson = gson;
27 | this.mApplication = application;
28 | }
29 |
30 | @Override
31 | public void onDestroy() {
32 | super.onDestroy();
33 | this.mGson = null;
34 | this.mApplication = null;
35 | }
36 |
37 | @Override
38 | public Observable gank(String type, String page) {
39 | return mRepositoryManager.obtainRetrofitService(CommonService.class)
40 | .gank(type, USERS_PER_PAGESIZE, page);
41 | }
42 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/model/CollectModel.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.model;
2 |
3 | import android.app.Application;
4 |
5 | import com.google.gson.Gson;
6 | import com.jess.arms.integration.IRepositoryManager;
7 | import com.jess.arms.mvp.BaseModel;
8 |
9 | import com.jess.arms.di.scope.ActivityScope;
10 |
11 | import javax.inject.Inject;
12 |
13 | import com.zhy.ganamrs.mvp.contract.CollectContract;
14 |
15 |
16 | @ActivityScope
17 | public class CollectModel extends BaseModel implements CollectContract.Model {
18 | private Gson mGson;
19 | private Application mApplication;
20 |
21 | @Inject
22 | public CollectModel(IRepositoryManager repositoryManager, Gson gson, Application application) {
23 | super(repositoryManager);
24 | this.mGson = gson;
25 | this.mApplication = application;
26 | }
27 |
28 | @Override
29 | public void onDestroy() {
30 | super.onDestroy();
31 | this.mGson = null;
32 | this.mApplication = null;
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/model/DetailModel.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.model;
2 |
3 | import android.app.Application;
4 |
5 | import com.google.gson.Gson;
6 | import com.jess.arms.di.scope.ActivityScope;
7 | import com.jess.arms.integration.IRepositoryManager;
8 | import com.jess.arms.mvp.BaseModel;
9 | import com.zhy.ganamrs.app.GreenDaoHelper;
10 | import com.zhy.ganamrs.app.greendao.DaoGankEntityDao;
11 | import com.zhy.ganamrs.mvp.contract.DetailContract;
12 | import com.zhy.ganamrs.mvp.model.api.service.CommonService;
13 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
14 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
15 |
16 | import java.util.List;
17 |
18 | import javax.inject.Inject;
19 |
20 | import io.reactivex.Observable;
21 |
22 |
23 | @ActivityScope
24 | public class DetailModel extends BaseModel implements DetailContract.Model {
25 | private Gson mGson;
26 | private Application mApplication;
27 |
28 | @Inject
29 | public DetailModel(IRepositoryManager repositoryManager, Gson gson, Application application) {
30 | super(repositoryManager);
31 | this.mGson = gson;
32 | this.mApplication = application;
33 | }
34 |
35 | @Override
36 | public void onDestroy() {
37 | super.onDestroy();
38 | this.mGson = null;
39 | this.mApplication = null;
40 | }
41 |
42 | @Override
43 | public Observable getRandomGirl() {
44 | Observable randomGirl = mRepositoryManager.obtainRetrofitService(CommonService.class)
45 | .getRandomGirl();
46 | return randomGirl;
47 | }
48 |
49 | @Override
50 | public List queryById(String id) {
51 | return GreenDaoHelper.getDaoSession().getDaoGankEntityDao()
52 | .queryBuilder()
53 | .where(DaoGankEntityDao.Properties._id.eq(id))
54 | .list();
55 | }
56 |
57 | @Override
58 | public void removeByid(String id) {
59 | GreenDaoHelper.getDaoSession().getDaoGankEntityDao()
60 | .queryBuilder()
61 | .where(DaoGankEntityDao.Properties._id.eq(id))
62 | .buildDelete().executeDeleteWithoutDetachingEntities();
63 | }
64 |
65 | @Override
66 | public void addGankEntity(DaoGankEntity entity) {
67 | GreenDaoHelper.getDaoSession().getDaoGankEntityDao().insert(entity);
68 | }
69 |
70 |
71 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/model/HomeModel.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.model;
2 |
3 | import android.app.Application;
4 |
5 | import com.google.gson.Gson;
6 | import com.jess.arms.integration.IRepositoryManager;
7 | import com.jess.arms.mvp.BaseModel;
8 |
9 | import com.jess.arms.di.scope.ActivityScope;
10 |
11 | import javax.inject.Inject;
12 |
13 | import com.zhy.ganamrs.mvp.contract.HomeContract;
14 |
15 |
16 | @ActivityScope
17 | public class HomeModel extends BaseModel implements HomeContract.Model {
18 | private Gson mGson;
19 | private Application mApplication;
20 |
21 | @Inject
22 | public HomeModel(IRepositoryManager repositoryManager, Gson gson, Application application) {
23 | super(repositoryManager);
24 | this.mGson = gson;
25 | this.mApplication = application;
26 | }
27 |
28 | @Override
29 | public void onDestroy() {
30 | super.onDestroy();
31 | this.mGson = null;
32 | this.mApplication = null;
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/model/MainModel.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.model;
2 |
3 | import android.app.Application;
4 |
5 | import com.google.gson.Gson;
6 | import com.jess.arms.di.scope.ActivityScope;
7 | import com.jess.arms.integration.IRepositoryManager;
8 | import com.jess.arms.mvp.BaseModel;
9 | import com.zhy.ganamrs.mvp.contract.MainContract;
10 |
11 | import javax.inject.Inject;
12 |
13 |
14 | @ActivityScope
15 | public class MainModel extends BaseModel implements MainContract.Model {
16 | private Gson mGson;
17 | private Application mApplication;
18 |
19 | @Inject
20 | public MainModel(IRepositoryManager repositoryManager, Gson gson, Application application) {
21 | super(repositoryManager);
22 | this.mGson = gson;
23 | this.mApplication = application;
24 | }
25 |
26 | @Override
27 | public void onDestroy() {
28 | super.onDestroy();
29 | this.mGson = null;
30 | this.mApplication = null;
31 | }
32 |
33 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/model/MeiziModel.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.model;
2 |
3 | import android.app.Application;
4 |
5 | import com.google.gson.Gson;
6 | import com.jess.arms.di.scope.ActivityScope;
7 | import com.jess.arms.integration.IRepositoryManager;
8 | import com.jess.arms.mvp.BaseModel;
9 | import com.zhy.ganamrs.app.GreenDaoHelper;
10 | import com.zhy.ganamrs.app.greendao.DaoGankEntityDao;
11 | import com.zhy.ganamrs.app.utils.CategoryType;
12 | import com.zhy.ganamrs.mvp.contract.MeiziContract;
13 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
14 |
15 | import java.util.List;
16 |
17 | import javax.inject.Inject;
18 |
19 |
20 | @ActivityScope
21 | public class MeiziModel extends BaseModel implements MeiziContract.Model {
22 | private Gson mGson;
23 | private Application mApplication;
24 |
25 | @Inject
26 | public MeiziModel(IRepositoryManager repositoryManager, Gson gson, Application application) {
27 | super(repositoryManager);
28 | this.mGson = gson;
29 | this.mApplication = application;
30 | }
31 |
32 | @Override
33 | public void onDestroy() {
34 | super.onDestroy();
35 | this.mGson = null;
36 | this.mApplication = null;
37 | }
38 |
39 | @Override
40 | public List getEntity() {
41 | return GreenDaoHelper.getDaoSession().getDaoGankEntityDao()
42 | .queryBuilder()
43 | .where(DaoGankEntityDao.Properties.Type.eq(CategoryType.GIRLS_STR))
44 | .orderDesc(DaoGankEntityDao.Properties.Addtime)
45 | .list();
46 | }
47 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/model/WelfareModel.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.model;
2 |
3 | import android.app.Application;
4 | import android.os.Message;
5 |
6 | import com.google.gson.Gson;
7 | import com.jess.arms.di.scope.ActivityScope;
8 | import com.jess.arms.integration.IRepositoryManager;
9 | import com.jess.arms.mvp.BaseModel;
10 | import com.zhy.ganamrs.app.GreenDaoHelper;
11 | import com.zhy.ganamrs.app.greendao.DaoGankEntityDao;
12 | import com.zhy.ganamrs.mvp.contract.WelfareContract;
13 | import com.zhy.ganamrs.mvp.model.api.service.CommonService;
14 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
15 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
16 |
17 | import java.util.List;
18 |
19 | import javax.inject.Inject;
20 |
21 | import io.reactivex.Observable;
22 |
23 |
24 | @ActivityScope
25 | public class WelfareModel extends BaseModel implements WelfareContract.Model {
26 | private Gson mGson;
27 | private Application mApplication;
28 |
29 | @Inject
30 | public WelfareModel(IRepositoryManager repositoryManager, Gson gson, Application application) {
31 | super(repositoryManager);
32 | this.mGson = gson;
33 | this.mApplication = application;
34 | }
35 |
36 | @Override
37 | public void onDestroy() {
38 | super.onDestroy();
39 | this.mGson = null;
40 | this.mApplication = null;
41 | }
42 |
43 | @Override
44 | public Observable getRandomGirl() {
45 | Observable randomGirl = mRepositoryManager.obtainRetrofitService(CommonService.class)
46 | .getRandomGirl();
47 | return randomGirl;
48 | }
49 |
50 | @Override
51 | public Message addGankEntity(DaoGankEntity daoGankEntity) {
52 | Message message = new Message();
53 | List list = GreenDaoHelper.getDaoSession().getDaoGankEntityDao()
54 | .queryBuilder()
55 | .where(DaoGankEntityDao.Properties._id.eq(daoGankEntity._id))
56 | .list();
57 | if (list.size() > 0){
58 | message.what = 101;
59 | }else {
60 | long insert = GreenDaoHelper.getDaoSession().getDaoGankEntityDao().insert(daoGankEntity);
61 | if (insert > 0){
62 | message.what = 102;
63 | }else {
64 | message.what = 103;
65 | }
66 | }
67 | return message;
68 | }
69 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/model/api/Api.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.model.api;
2 |
3 | /**
4 | * Created by jess on 8/5/16 11:25
5 | * contact with jess.yan.effort@gmail.com
6 | */
7 | public interface Api {
8 | String APP_DOMAIN = "http://gank.io/";
9 | String RequestSuccess = "0";
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/model/api/cache/CommonCache.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.model.api.cache;
2 |
3 |
4 | /**
5 | * Created by jess on 8/30/16 13:53
6 | * Contact with jess.yan.effort@gmail.com
7 | */
8 | public interface CommonCache {
9 |
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/model/api/service/CommonService.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.model.api.service;
2 |
3 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
4 |
5 | import io.reactivex.Observable;
6 | import retrofit2.http.GET;
7 | import retrofit2.http.Path;
8 |
9 | /**
10 | * 存放通用的一些API
11 | * Created by jess on 8/5/16 12:05
12 | * contact with jess.yan.effort@gmail.com
13 | */
14 | public interface CommonService {
15 |
16 | @GET("api/data/{type}/{pageSize}/{page}")
17 | Observable gank(@Path("type") String type, @Path("pageSize") int pageSize, @Path("page") String page);
18 |
19 | // 随机获取一个妹子
20 | @GET("api/random/data/福利/1")
21 | Observable getRandomGirl();
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/model/entity/BaseJson.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.model.entity;
2 |
3 |
4 | import com.zhy.ganamrs.mvp.model.api.Api;
5 |
6 | import java.io.Serializable;
7 |
8 |
9 | /**
10 | * 如果你服务器返回的数据固定为这种方式(字段名可根据服务器更改)
11 | * 替换范型即可重用BaseJson
12 | * Created by jess on 26/09/2016 15:19
13 | * Contact with jess.yan.effort@gmail.com
14 | */
15 |
16 | public class BaseJson implements Serializable{
17 | private T data;
18 | private String code;
19 | private String msg;
20 |
21 | public T getData() {
22 | return data;
23 | }
24 |
25 | public String getCode() {
26 | return code;
27 | }
28 |
29 | public String getMsg() {
30 | return msg;
31 | }
32 |
33 | /**
34 | * 请求是否成功
35 | * @return
36 | */
37 | public boolean isSuccess() {
38 | if (code.equals(Api.RequestSuccess)) {
39 | return true;
40 | } else {
41 | return false;
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/model/entity/DaoGankEntity.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.model.entity;
2 |
3 | import org.greenrobot.greendao.annotation.Entity;
4 | import org.greenrobot.greendao.annotation.Transient;
5 |
6 | import java.util.List;
7 | import org.greenrobot.greendao.annotation.Generated;
8 |
9 | /**
10 | * Created by Administrator on 2017/7/4.
11 | */
12 |
13 | @Entity
14 | public class DaoGankEntity {
15 | /**
16 | * _id : 595ad074421aa90ca3bb6a90
17 | * createdAt : 2017-07-04T07:17:08.609Z
18 | * desc : Android 有两套相机 Api,使用起来很麻烦,好在 Foto 开源了他们在 Android 上的 Camera 封装 Api,力荐!
19 | * images : ["http://img.gank.io/0a15bae7-c513-4feb-bbe2-1273b8b809ce"]
20 | * publishedAt : 2017-07-04T11:50:36.484Z
21 | * source : chrome
22 | * type : Android
23 | * url : https://github.com/Fotoapparat/Fotoapparat
24 | * used : true
25 | * who : 代码家
26 | */
27 |
28 | public String _id;
29 | public String createdAt;
30 | public String desc;
31 | public String publishedAt;
32 | public String source;
33 | public String type;
34 | public String url;
35 | public boolean used;
36 | public String who;
37 | public String addtime;
38 | @Transient
39 | public List images;
40 | @Generated(hash = 1539280829)
41 | public DaoGankEntity(String _id, String createdAt, String desc, String publishedAt,
42 | String source, String type, String url, boolean used, String who,
43 | String addtime) {
44 | this._id = _id;
45 | this.createdAt = createdAt;
46 | this.desc = desc;
47 | this.publishedAt = publishedAt;
48 | this.source = source;
49 | this.type = type;
50 | this.url = url;
51 | this.used = used;
52 | this.who = who;
53 | this.addtime = addtime;
54 | }
55 | @Generated(hash = 1072603763)
56 | public DaoGankEntity() {
57 | }
58 | public String get_id() {
59 | return this._id;
60 | }
61 | public void set_id(String _id) {
62 | this._id = _id;
63 | }
64 | public String getCreatedAt() {
65 | return this.createdAt;
66 | }
67 | public void setCreatedAt(String createdAt) {
68 | this.createdAt = createdAt;
69 | }
70 | public String getDesc() {
71 | return this.desc;
72 | }
73 | public void setDesc(String desc) {
74 | this.desc = desc;
75 | }
76 | public String getPublishedAt() {
77 | return this.publishedAt;
78 | }
79 | public void setPublishedAt(String publishedAt) {
80 | this.publishedAt = publishedAt;
81 | }
82 | public String getSource() {
83 | return this.source;
84 | }
85 | public void setSource(String source) {
86 | this.source = source;
87 | }
88 | public String getType() {
89 | return this.type;
90 | }
91 | public void setType(String type) {
92 | this.type = type;
93 | }
94 | public String getUrl() {
95 | return this.url;
96 | }
97 | public void setUrl(String url) {
98 | this.url = url;
99 | }
100 | public boolean getUsed() {
101 | return this.used;
102 | }
103 | public void setUsed(boolean used) {
104 | this.used = used;
105 | }
106 | public String getWho() {
107 | return this.who;
108 | }
109 | public void setWho(String who) {
110 | this.who = who;
111 | }
112 | public String getAddtime() {
113 | return this.addtime;
114 | }
115 | public void setAddtime(String addtime) {
116 | this.addtime = addtime;
117 | }
118 |
119 | }
120 |
121 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/model/entity/GankEntity.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.model.entity;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | /**
7 | * Created by Administrator on 2017/7/4.
8 | */
9 |
10 | public class GankEntity implements Serializable {
11 | /**
12 | * error : false
13 | * results : [{"_id":"595ad074421aa90ca3bb6a90","createdAt":"2017-07-04T07:17:08.609Z","desc":"Android 有两套相机 Api,使用起来很麻烦,好在 Foto 开源了他们在 Android 上的 Camera 封装 Api,力荐!","images":["http://img.gank.io/0a15bae7-c513-4feb-bbe2-1273b8b809ce"],"publishedAt":"2017-07-04T11:50:36.484Z","source":"chrome","type":"Android","url":"https://github.com/Fotoapparat/Fotoapparat","used":true,"who":"代码家"},{"_id":"595ad096421aa90cb4724b5b","createdAt":"2017-07-04T07:17:42.635Z","desc":"MD 风格的日历组件,很精致哦。","images":["http://img.gank.io/75a6251f-ffaf-41dc-8dbc-fa58802b0d8e"],"publishedAt":"2017-07-04T11:50:36.484Z","source":"chrome","type":"Android","url":"https://github.com/Applandeo/Material-Calendar-View","used":true,"who":"代码家"},{"_id":"595ad0d4421aa90cb4724b5c","createdAt":"2017-07-04T07:18:44.154Z","desc":"非常 Fancy 的选项过滤器。","images":["http://img.gank.io/f9e1e0ef-88fc-4e02-8620-2cf1700966c5"],"publishedAt":"2017-07-04T11:50:36.484Z","source":"chrome","type":"Android","url":"https://github.com/Krupen/FabulousFilter","used":true,"who":"代码家"},{"_id":"595aec75421aa90c9203d31c","createdAt":"2017-07-04T09:16:37.902Z","desc":"Android单元测试框架Robolectric3.0(二):数据篇","publishedAt":"2017-07-04T11:50:36.484Z","source":"web","type":"Android","url":"http://url.cn/4BHx7ZG","used":true,"who":"陈宇明"},{"_id":"595b0bed421aa90ca3bb6a98","createdAt":"2017-07-04T11:30:53.793Z","desc":"前端每周清单第 20 期:React 组件解耦之道;基于Headless Chrome的自动化测试;Angular 2/4是否为时已晚?","publishedAt":"2017-07-04T11:50:36.484Z","source":"chrome","type":"Android","url":"https://zhuanlan.zhihu.com/p/27684971","used":true,"who":"王下邀月熊"},{"_id":"595b0f5a421aa90cb4724b60","createdAt":"2017-07-04T11:45:30.184Z","desc":"Android App Performance Optimization","publishedAt":"2017-07-04T11:50:36.484Z","source":"web","type":"Android","url":"https://blog.mindorks.com/android-app-performance-optimization-cdccb422e38e","used":true,"who":"AMIT SHEKHAR"},{"_id":"593f2091421aa92c769a8c6a","createdAt":"2017-06-13T07:15:29.423Z","desc":"Android之自定义View:侧滑删除","publishedAt":"2017-06-15T13:55:57.947Z","source":"web","type":"Android","url":"https://mp.weixin.qq.com/s?__biz=MzIwMzYwMTk1NA==&mid=2247484934&idx=1&sn=f2a40261efe8ebee45804e9df93c1cce&chksm=96cda74ba1ba2e5dbbac15a9e57b5329176d1fe43478e5c63f7bc502a6ca50e4dfa6c0a9041e#rd","used":true,"who":"陈宇明"},{"_id":"594109e5421aa92c769a8c84","createdAt":"2017-06-14T18:03:17.393Z","desc":"RecyclerView:利用打造悬浮效果","images":["http://img.gank.io/775b8ae5-4c21-4553-a77e-a0842248e1af"],"publishedAt":"2017-06-15T13:55:57.947Z","source":"web","type":"Android","url":"http://www.jianshu.com/p/b335b620af39","used":true,"who":null},{"_id":"5941e2ac421aa92c7be61c14","createdAt":"2017-06-15T09:28:12.702Z","desc":"《From Java To Kotlin》从Java到Kotlin·译 (双语对比)","publishedAt":"2017-06-15T13:55:57.947Z","source":"web","type":"Android","url":"http://url.cn/4AS5wCG","used":true,"who":"陈宇明"},{"_id":"5941f5f3421aa92c7be61c16","createdAt":"2017-06-15T10:50:27.317Z","desc":"仿Nice首页图片列表9图样式,并实现拖拽效果","images":["http://img.gank.io/4f54c011-e293-436a-ada1-dc03669ffb10"],"publishedAt":"2017-06-15T13:55:57.947Z","source":"web","type":"Android","url":"http://www.jianshu.com/p/0ea96b952170","used":true,"who":"兔子吃过窝边草"}]
14 | */
15 |
16 | public boolean error;
17 | public List results;
18 |
19 | public static class ResultsBean implements Serializable{
20 | /**
21 | * _id : 595ad074421aa90ca3bb6a90
22 | * createdAt : 2017-07-04T07:17:08.609Z
23 | * desc : Android 有两套相机 Api,使用起来很麻烦,好在 Foto 开源了他们在 Android 上的 Camera 封装 Api,力荐!
24 | * images : ["http://img.gank.io/0a15bae7-c513-4feb-bbe2-1273b8b809ce"]
25 | * publishedAt : 2017-07-04T11:50:36.484Z
26 | * source : chrome
27 | * type : Android
28 | * url : https://github.com/Fotoapparat/Fotoapparat
29 | * used : true
30 | * who : 代码家
31 | */
32 |
33 | public String _id;
34 | public String createdAt;
35 | public String desc;
36 | public String publishedAt;
37 | public String source;
38 | public String type;
39 | public String url;
40 | public boolean used;
41 | public String who;
42 | public List images;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/presenter/ArticlePresenter.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.presenter;
2 |
3 | import android.app.Application;
4 |
5 | import com.jess.arms.di.scope.ActivityScope;
6 | import com.jess.arms.http.imageloader.ImageLoader;
7 | import com.jess.arms.integration.AppManager;
8 | import com.jess.arms.mvp.BasePresenter;
9 | import com.zhy.ganamrs.mvp.contract.ArticleContract;
10 |
11 | import javax.inject.Inject;
12 |
13 | import me.jessyan.rxerrorhandler.core.RxErrorHandler;
14 |
15 |
16 | @ActivityScope
17 | public class ArticlePresenter extends BasePresenter {
18 | private RxErrorHandler mErrorHandler;
19 | private Application mApplication;
20 | private ImageLoader mImageLoader;
21 | private AppManager mAppManager;
22 |
23 | @Inject
24 | public ArticlePresenter(ArticleContract.Model model, ArticleContract.View rootView
25 | , RxErrorHandler handler, Application application
26 | , ImageLoader imageLoader, AppManager appManager) {
27 | super(model, rootView);
28 | this.mErrorHandler = handler;
29 | this.mApplication = application;
30 | this.mImageLoader = imageLoader;
31 | this.mAppManager = appManager;
32 | }
33 |
34 | @Override
35 | public void onDestroy() {
36 | super.onDestroy();
37 | this.mErrorHandler = null;
38 | this.mAppManager = null;
39 | this.mImageLoader = null;
40 | this.mApplication = null;
41 | }
42 |
43 | public void requestData(boolean pullToRefresh) {
44 | mRootView.setAdapter(mModel.getEntity());
45 | mRootView.endLoadMore();
46 | }
47 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/presenter/CategoryPresenter.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.presenter;
2 |
3 | import android.app.Application;
4 |
5 | import com.jess.arms.base.DefaultAdapter;
6 | import com.jess.arms.di.scope.ActivityScope;
7 | import com.jess.arms.http.imageloader.ImageLoader;
8 | import com.jess.arms.integration.AppManager;
9 | import com.jess.arms.mvp.BasePresenter;
10 | import com.zhy.ganamrs.app.utils.RxUtils;
11 | import com.zhy.ganamrs.mvp.contract.CategoryContract;
12 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
13 | import com.zhy.ganamrs.mvp.ui.adapter.CategoryAdapter;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | import javax.inject.Inject;
19 |
20 | import io.reactivex.android.schedulers.AndroidSchedulers;
21 | import io.reactivex.annotations.NonNull;
22 | import io.reactivex.schedulers.Schedulers;
23 | import me.jessyan.rxerrorhandler.core.RxErrorHandler;
24 | import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;
25 | import me.jessyan.rxerrorhandler.handler.RetryWithDelay;
26 |
27 |
28 | @ActivityScope
29 | public class CategoryPresenter extends BasePresenter {
30 | private RxErrorHandler mErrorHandler;
31 | private Application mApplication;
32 | private ImageLoader mImageLoader;
33 | private AppManager mAppManager;
34 | private int lastUserId = 1;
35 | private DefaultAdapter mAdapter;
36 | private int preEndIndex;
37 | private List mData = new ArrayList<>();
38 |
39 | @Inject
40 | public CategoryPresenter(CategoryContract.Model model, CategoryContract.View rootView
41 | , RxErrorHandler handler, Application application
42 | , ImageLoader imageLoader, AppManager appManager) {
43 | super(model, rootView);
44 | this.mErrorHandler = handler;
45 | this.mApplication = application;
46 | this.mImageLoader = imageLoader;
47 | this.mAppManager = appManager;
48 | // mAdapter = new CategoryAdapter(mData);
49 | // mRootView.setAdapter(mAdapter);//设置Adapter
50 | }
51 |
52 | @Override
53 | public void onDestroy() {
54 | super.onDestroy();
55 | this.mErrorHandler = null;
56 | this.mAppManager = null;
57 | this.mImageLoader = null;
58 | this.mApplication = null;
59 | }
60 |
61 | public void requestData(String type, boolean pullToRefresh) {
62 | if (mAdapter == null) {
63 | mAdapter = new CategoryAdapter(mData);
64 | mRootView.setAdapter(mAdapter);//设置Adapter
65 | }
66 |
67 | if (pullToRefresh){
68 | lastUserId = 1;//上拉刷新默认只请求第一页
69 | }else{
70 | lastUserId++;
71 | }
72 | mModel.gank(type,String.valueOf(lastUserId))
73 | .subscribeOn(Schedulers.io())
74 | .retryWhen(new RetryWithDelay(3, 2))
75 | .doOnSubscribe(disposable -> {
76 | if (pullToRefresh)
77 | mRootView.showLoading();//显示上拉刷新的进度条
78 | else
79 | mRootView.startLoadMore();//显示下拉加载更多的进度条
80 | })
81 | .subscribeOn(AndroidSchedulers.mainThread())
82 | .observeOn(AndroidSchedulers.mainThread())
83 | .doAfterTerminate(() -> {
84 | if (pullToRefresh)
85 | mRootView.hideLoading();//隐藏上拉刷新的进度条
86 | else
87 | mRootView.endLoadMore();//隐藏下拉加载更多的进度条
88 | })
89 | .compose(RxUtils.bindToLifecycle(mRootView))//使用Rxlifecycle,使Disposable和Activity一起销毁
90 | .subscribe(new ErrorHandleSubscriber(mErrorHandler) {
91 | @Override
92 | public void onNext(@NonNull GankEntity gankEntity) {
93 | preEndIndex = mData.size();
94 | if (pullToRefresh) mData.clear();
95 | mData.addAll(gankEntity.results);
96 | if (pullToRefresh)
97 | mAdapter.notifyDataSetChanged();
98 | else
99 | mAdapter.notifyItemRangeInserted(preEndIndex, gankEntity.results.size());
100 | }
101 | });
102 | }
103 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/presenter/CollectPresenter.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.presenter;
2 |
3 | import android.app.Application;
4 |
5 | import com.jess.arms.di.scope.ActivityScope;
6 | import com.jess.arms.http.imageloader.ImageLoader;
7 | import com.jess.arms.integration.AppManager;
8 | import com.jess.arms.mvp.BasePresenter;
9 | import com.zhy.ganamrs.mvp.contract.CollectContract;
10 |
11 | import javax.inject.Inject;
12 |
13 | import me.jessyan.rxerrorhandler.core.RxErrorHandler;
14 |
15 |
16 | @ActivityScope
17 | public class CollectPresenter extends BasePresenter {
18 | private RxErrorHandler mErrorHandler;
19 | private Application mApplication;
20 | private ImageLoader mImageLoader;
21 | private AppManager mAppManager;
22 |
23 | @Inject
24 | public CollectPresenter(CollectContract.Model model, CollectContract.View rootView
25 | , RxErrorHandler handler, Application application
26 | , ImageLoader imageLoader, AppManager appManager) {
27 | super(model, rootView);
28 | this.mErrorHandler = handler;
29 | this.mApplication = application;
30 | this.mImageLoader = imageLoader;
31 | this.mAppManager = appManager;
32 | }
33 |
34 | @Override
35 | public void onDestroy() {
36 | super.onDestroy();
37 | this.mErrorHandler = null;
38 | this.mAppManager = null;
39 | this.mImageLoader = null;
40 | this.mApplication = null;
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/presenter/DetailPresenter.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.presenter;
2 |
3 | import android.app.Application;
4 |
5 | import com.jess.arms.di.scope.ActivityScope;
6 | import com.jess.arms.http.imageloader.ImageLoader;
7 | import com.jess.arms.integration.AppManager;
8 | import com.jess.arms.mvp.BasePresenter;
9 | import com.zhy.ganamrs.app.utils.RxUtils;
10 | import com.zhy.ganamrs.mvp.contract.DetailContract;
11 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
12 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
13 |
14 | import java.text.SimpleDateFormat;
15 | import java.util.Date;
16 |
17 | import javax.inject.Inject;
18 |
19 | import io.reactivex.android.schedulers.AndroidSchedulers;
20 | import io.reactivex.annotations.NonNull;
21 | import io.reactivex.schedulers.Schedulers;
22 | import me.jessyan.rxerrorhandler.core.RxErrorHandler;
23 | import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;
24 | import me.jessyan.rxerrorhandler.handler.RetryWithDelay;
25 |
26 |
27 | @ActivityScope
28 | public class DetailPresenter extends BasePresenter {
29 | private RxErrorHandler mErrorHandler;
30 | private Application mApplication;
31 | private ImageLoader mImageLoader;
32 | private AppManager mAppManager;
33 | private DaoGankEntity daoGankEntity;
34 |
35 | @Inject
36 | public DetailPresenter(DetailContract.Model model, DetailContract.View rootView
37 | , RxErrorHandler handler, Application application
38 | , ImageLoader imageLoader, AppManager appManager) {
39 | super(model, rootView);
40 | this.mErrorHandler = handler;
41 | this.mApplication = application;
42 | this.mImageLoader = imageLoader;
43 | this.mAppManager = appManager;
44 | }
45 |
46 | @Override
47 | public void onDestroy() {
48 | super.onDestroy();
49 | this.mErrorHandler = null;
50 | this.mAppManager = null;
51 | this.mImageLoader = null;
52 | this.mApplication = null;
53 | }
54 |
55 | public void getGirl() {
56 | mModel.getRandomGirl()
57 | .subscribeOn(Schedulers.io())
58 | .retryWhen(new RetryWithDelay(3, 2))
59 | .subscribeOn(AndroidSchedulers.mainThread())
60 | .observeOn(AndroidSchedulers.mainThread())
61 | .compose(RxUtils.bindToLifecycle(mRootView))//使用Rxlifecycle,使Disposable和Activity一起销毁
62 | .subscribe(new ErrorHandleSubscriber(mErrorHandler) {
63 | @Override
64 | public void onNext(@NonNull GankEntity gankEntity) {
65 | mRootView.setData(gankEntity.results.get(0).url);
66 | }
67 | });
68 | }
69 |
70 | public void getQuery(String id){
71 | mRootView.onFavoriteChange(mModel.queryById(id).size() > 0);
72 | }
73 |
74 | public void removeByid(GankEntity.ResultsBean entity) {
75 | DaoGankEntity daoGankEntity = entityToDao(entity);
76 | mModel.removeByid(daoGankEntity._id);
77 | mRootView.onFavoriteChange(false);
78 | }
79 |
80 | public void addToFavorites(GankEntity.ResultsBean entity) {
81 | DaoGankEntity daoGankEntity = entityToDao(entity);
82 | mModel.addGankEntity(daoGankEntity);
83 | mRootView.onFavoriteChange(true);
84 | }
85 |
86 | private DaoGankEntity entityToDao(GankEntity.ResultsBean entity) {
87 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
88 | Date curDate = new Date(System.currentTimeMillis());//获取当前时间
89 | String str = formatter.format(curDate);
90 | if (daoGankEntity == null){
91 | daoGankEntity = new DaoGankEntity();
92 | }
93 | daoGankEntity._id = entity._id;
94 | daoGankEntity.createdAt = entity.createdAt;
95 | daoGankEntity.desc = entity.desc;
96 | daoGankEntity.publishedAt = entity.publishedAt;
97 | daoGankEntity.source = entity.source;
98 | daoGankEntity.type = entity.type;
99 | daoGankEntity.url = entity.url;
100 | daoGankEntity.used = entity.used;
101 | daoGankEntity.who = entity.who;
102 | daoGankEntity.addtime =str;
103 | return daoGankEntity;
104 | }
105 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/presenter/HomePresenter.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.presenter;
2 |
3 | import android.app.Application;
4 |
5 | import com.jess.arms.di.scope.ActivityScope;
6 | import com.jess.arms.http.imageloader.ImageLoader;
7 | import com.jess.arms.integration.AppManager;
8 | import com.jess.arms.mvp.BasePresenter;
9 | import com.zhy.ganamrs.mvp.contract.HomeContract;
10 |
11 | import javax.inject.Inject;
12 |
13 | import me.jessyan.rxerrorhandler.core.RxErrorHandler;
14 |
15 |
16 | @ActivityScope
17 | public class HomePresenter extends BasePresenter {
18 | private RxErrorHandler mErrorHandler;
19 | private Application mApplication;
20 | private ImageLoader mImageLoader;
21 | private AppManager mAppManager;
22 |
23 | @Inject
24 | public HomePresenter(HomeContract.Model model, HomeContract.View rootView
25 | , RxErrorHandler handler, Application application
26 | , ImageLoader imageLoader, AppManager appManager) {
27 | super(model, rootView);
28 | this.mErrorHandler = handler;
29 | this.mApplication = application;
30 | this.mImageLoader = imageLoader;
31 | this.mAppManager = appManager;
32 | }
33 |
34 | @Override
35 | public void onDestroy() {
36 | super.onDestroy();
37 | this.mErrorHandler = null;
38 | this.mAppManager = null;
39 | this.mImageLoader = null;
40 | this.mApplication = null;
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/presenter/MainPresenter.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.presenter;
2 |
3 | import android.app.Application;
4 |
5 | import com.jess.arms.di.scope.ActivityScope;
6 | import com.jess.arms.http.imageloader.ImageLoader;
7 | import com.jess.arms.integration.AppManager;
8 | import com.jess.arms.mvp.BasePresenter;
9 | import com.jess.arms.utils.PermissionUtil;
10 | import com.zhy.ganamrs.mvp.contract.MainContract;
11 |
12 | import javax.inject.Inject;
13 |
14 | import me.jessyan.rxerrorhandler.core.RxErrorHandler;
15 |
16 |
17 | @ActivityScope
18 | public class MainPresenter extends BasePresenter {
19 | private RxErrorHandler mErrorHandler;
20 | private Application mApplication;
21 | private ImageLoader mImageLoader;
22 | private AppManager mAppManager;
23 |
24 | @Inject
25 | public MainPresenter(MainContract.Model model, MainContract.View rootView
26 | , RxErrorHandler handler, Application application
27 | , ImageLoader imageLoader, AppManager appManager) {
28 | super(model, rootView);
29 | this.mErrorHandler = handler;
30 | this.mApplication = application;
31 | this.mImageLoader = imageLoader;
32 | this.mAppManager = appManager;
33 | }
34 |
35 | public void requestPermissions(){
36 | PermissionUtil.requestPermission(new PermissionUtil.RequestPermission() {
37 | @Override
38 | public void onRequestPermissionSuccess() {
39 | //request permission success, do something.
40 | }
41 |
42 | @Override
43 | public void onRequestPermissionFailure() {
44 | mRootView.showMessage("Request permissons failure");
45 | }
46 | }, mRootView.getRxPermissions(), mErrorHandler);
47 | }
48 |
49 | @Override
50 | public void onDestroy() {
51 | super.onDestroy();
52 | this.mErrorHandler = null;
53 | this.mAppManager = null;
54 | this.mImageLoader = null;
55 | this.mApplication = null;
56 | }
57 |
58 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/presenter/MeiziPresenter.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.presenter;
2 |
3 | import android.app.Application;
4 |
5 | import com.jess.arms.di.scope.ActivityScope;
6 | import com.jess.arms.http.imageloader.ImageLoader;
7 | import com.jess.arms.integration.AppManager;
8 | import com.jess.arms.mvp.BasePresenter;
9 | import com.zhy.ganamrs.mvp.contract.MeiziContract;
10 |
11 | import javax.inject.Inject;
12 |
13 | import me.jessyan.rxerrorhandler.core.RxErrorHandler;
14 |
15 |
16 | @ActivityScope
17 | public class MeiziPresenter extends BasePresenter {
18 | private RxErrorHandler mErrorHandler;
19 | private Application mApplication;
20 | private ImageLoader mImageLoader;
21 | private AppManager mAppManager;
22 |
23 | @Inject
24 | public MeiziPresenter(MeiziContract.Model model, MeiziContract.View rootView
25 | , RxErrorHandler handler, Application application
26 | , ImageLoader imageLoader, AppManager appManager) {
27 | super(model, rootView);
28 | this.mErrorHandler = handler;
29 | this.mApplication = application;
30 | this.mImageLoader = imageLoader;
31 | this.mAppManager = appManager;
32 | }
33 |
34 | @Override
35 | public void onDestroy() {
36 | super.onDestroy();
37 | this.mErrorHandler = null;
38 | this.mAppManager = null;
39 | this.mImageLoader = null;
40 | this.mApplication = null;
41 | }
42 |
43 | public void requestData(boolean b) {
44 | mRootView.setAdapter(mModel.getEntity());
45 | mRootView.endLoadMore();
46 | }
47 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/presenter/WelfarePresenter.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.presenter;
2 |
3 | import android.app.Application;
4 | import android.os.Message;
5 |
6 | import com.jess.arms.di.scope.ActivityScope;
7 | import com.jess.arms.http.imageloader.ImageLoader;
8 | import com.jess.arms.integration.AppManager;
9 | import com.jess.arms.mvp.BasePresenter;
10 | import com.zhy.ganamrs.app.utils.RxUtils;
11 | import com.zhy.ganamrs.mvp.contract.WelfareContract;
12 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
13 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
14 |
15 | import org.simple.eventbus.EventBus;
16 |
17 | import java.text.SimpleDateFormat;
18 | import java.util.Date;
19 |
20 | import javax.inject.Inject;
21 |
22 | import io.reactivex.android.schedulers.AndroidSchedulers;
23 | import io.reactivex.annotations.NonNull;
24 | import io.reactivex.schedulers.Schedulers;
25 | import me.jessyan.rxerrorhandler.core.RxErrorHandler;
26 | import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;
27 | import me.jessyan.rxerrorhandler.handler.RetryWithDelay;
28 |
29 |
30 | @ActivityScope
31 | public class WelfarePresenter extends BasePresenter {
32 | private RxErrorHandler mErrorHandler;
33 | private Application mApplication;
34 | private ImageLoader mImageLoader;
35 | private AppManager mAppManager;
36 | private DaoGankEntity daoGankEntity;
37 | @Inject
38 | public WelfarePresenter(WelfareContract.Model model, WelfareContract.View rootView
39 | , RxErrorHandler handler, Application application
40 | , ImageLoader imageLoader, AppManager appManager) {
41 | super(model, rootView);
42 | this.mErrorHandler = handler;
43 | this.mApplication = application;
44 | this.mImageLoader = imageLoader;
45 | this.mAppManager = appManager;
46 | }
47 |
48 | @Override
49 | public void onDestroy() {
50 | super.onDestroy();
51 | this.mErrorHandler = null;
52 | this.mAppManager = null;
53 | this.mImageLoader = null;
54 | this.mApplication = null;
55 | }
56 |
57 | public void requestData(boolean pullToRefresh) {
58 | mModel.getRandomGirl()
59 | .subscribeOn(Schedulers.io())
60 | .retryWhen(new RetryWithDelay(3, 2))
61 | .doOnSubscribe(disposable -> {
62 | if (pullToRefresh)
63 | mRootView.showLoading();//显示上拉刷新的进度条
64 | else
65 | mRootView.startLoadMore();//显示下拉加载更多的进度条
66 | })
67 | .subscribeOn(AndroidSchedulers.mainThread())
68 | .observeOn(AndroidSchedulers.mainThread())
69 | .doAfterTerminate(() -> {
70 | if (pullToRefresh)
71 | mRootView.hideLoading();//隐藏上拉刷新的进度条
72 | else
73 | mRootView.endLoadMore();//隐藏下拉加载更多的进度条
74 | })
75 | .compose(RxUtils.bindToLifecycle(mRootView))//使用Rxlifecycle,使Disposable和Activity一起销毁
76 | .subscribe(new ErrorHandleSubscriber(mErrorHandler) {
77 | @Override
78 | public void onNext(@NonNull GankEntity gankEntity) {
79 | if (pullToRefresh){
80 | mRootView.setNewData(gankEntity.results);
81 | } else{
82 | mRootView.setAddData(gankEntity.results);
83 | }
84 | }
85 | });
86 | }
87 |
88 | public void addToFavorites(GankEntity.ResultsBean entity) {
89 | DaoGankEntity daoGankEntity = entityToDao(entity);
90 | Message message = mModel.addGankEntity(daoGankEntity);
91 | String a = null;
92 | switch (message.what){
93 | case 101:
94 | a = "该图片已经收藏过了";
95 | break;
96 | case 102:
97 | a = "收藏成功";
98 | EventBus.getDefault().post(new Object(),"meizi");
99 | break;
100 | case 103:
101 | a = "收藏失败";
102 | break;
103 | }
104 | mRootView.showMessage(a);
105 | }
106 | private DaoGankEntity entityToDao(GankEntity.ResultsBean entity) {
107 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
108 | Date curDate = new Date(System.currentTimeMillis());//获取当前时间
109 | String str = formatter.format(curDate);
110 | if (daoGankEntity == null){
111 | daoGankEntity = new DaoGankEntity();
112 | }
113 | daoGankEntity._id = entity._id;
114 | daoGankEntity.createdAt = entity.createdAt;
115 | daoGankEntity.desc = entity.desc;
116 | daoGankEntity.publishedAt = entity.publishedAt;
117 | daoGankEntity.source = entity.source;
118 | daoGankEntity.type = entity.type;
119 | daoGankEntity.url = entity.url;
120 | daoGankEntity.used = entity.used;
121 | daoGankEntity.who = entity.who;
122 | daoGankEntity.addtime =str;
123 | return daoGankEntity;
124 | }
125 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/activity/DetailActivity.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.activity;
2 |
3 | import android.content.Intent;
4 | import android.content.res.ColorStateList;
5 | import android.os.Build;
6 | import android.os.Bundle;
7 | import android.support.annotation.NonNull;
8 | import android.support.design.widget.FloatingActionButton;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.support.v7.widget.Toolbar;
11 | import android.view.MenuItem;
12 | import android.webkit.WebResourceRequest;
13 | import android.webkit.WebSettings;
14 | import android.webkit.WebView;
15 | import android.webkit.WebViewClient;
16 | import android.widget.ImageView;
17 |
18 | import com.alibaba.android.arouter.facade.annotation.Route;
19 | import com.jess.arms.base.BaseActivity;
20 | import com.jess.arms.di.component.AppComponent;
21 | import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
22 | import com.jess.arms.utils.ArmsUtils;
23 | import com.zhy.ganamrs.R;
24 | import com.zhy.ganamrs.di.component.DaggerDetailComponent;
25 | import com.zhy.ganamrs.di.module.DetailModule;
26 | import com.zhy.ganamrs.mvp.contract.DetailContract;
27 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
28 | import com.zhy.ganamrs.mvp.presenter.DetailPresenter;
29 |
30 | import butterknife.BindView;
31 |
32 | import static com.jess.arms.utils.Preconditions.checkNotNull;
33 | import static com.zhy.ganamrs.app.ARouterPaths.MAIN_DETAIL;
34 | import static com.zhy.ganamrs.app.EventBusTags.EXTRA_DETAIL;
35 |
36 | @Route(path = MAIN_DETAIL)
37 | public class DetailActivity extends BaseActivity implements DetailContract.View {
38 |
39 |
40 | @BindView(R.id.imageView)
41 | ImageView imageView;
42 | @BindView(R.id.toolbar)
43 | Toolbar toolbar;
44 | @BindView(R.id.webview)
45 | WebView webview;
46 | @BindView(R.id.fab)
47 | FloatingActionButton fab;
48 | private GankEntity.ResultsBean entity;
49 | private boolean isFavorite;
50 |
51 | @Override
52 | public void setupActivityComponent(AppComponent appComponent) {
53 | DaggerDetailComponent //如找不到该类,请编译一下项目
54 | .builder()
55 | .appComponent(appComponent)
56 | .detailModule(new DetailModule(this))
57 | .build()
58 | .inject(this);
59 | }
60 |
61 | @Override
62 | public int initView(Bundle savedInstanceState) {
63 | return R.layout.activity_detail; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
64 | }
65 |
66 | @Override
67 | public void initData(Bundle savedInstanceState) {
68 | entity = (GankEntity.ResultsBean) getIntent()
69 | .getExtras()
70 | .getSerializable(EXTRA_DETAIL);
71 | mPresenter.getGirl();
72 | mPresenter.getQuery(entity._id);
73 | if (toolbar != null) {
74 | if (this instanceof AppCompatActivity) {
75 | setSupportActionBar(toolbar);
76 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
77 | } else {
78 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
79 | this.setActionBar((android.widget.Toolbar) this.findViewById(R.id.toolbar));
80 | this.getActionBar().setDisplayShowTitleEnabled(false);
81 | }
82 | }
83 | }
84 |
85 | // TODO: 2017/7/13 添加到收藏夹
86 | fab.setOnClickListener(v -> {
87 | if (isFavorite) {
88 | ArmsUtils.makeText(this,"已移除收藏夹");
89 | mPresenter.removeByid(entity);
90 | } else {
91 | ArmsUtils.makeText(this,"已添加到收藏夹");
92 | mPresenter.addToFavorites(entity);
93 | }
94 | });
95 |
96 | initWebView();
97 |
98 | }
99 |
100 | @Override
101 | public void onFavoriteChange(boolean isFavorite) {
102 | this.isFavorite = isFavorite;
103 | if (isFavorite){
104 | fab.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.colorAccent)));
105 | }else {
106 | fab.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.C4)));
107 | }
108 |
109 | }
110 | private void initWebView() {
111 | WebSettings settings = webview.getSettings();
112 | settings.setUseWideViewPort(true);
113 | settings.setLoadWithOverviewMode(true);
114 | settings.setSupportZoom(true);
115 | settings.setBuiltInZoomControls(true);
116 | settings.setDisplayZoomControls(false);
117 | webview.setWebViewClient(new WebViewClient(){
118 |
119 | @Override
120 | public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
121 | return true;
122 | }
123 | });
124 |
125 | webview.loadUrl(entity.url);
126 | }
127 |
128 | @Override
129 | public boolean onOptionsItemSelected(MenuItem item) {
130 | int id = item.getItemId();
131 | if (id == android.R.id.home) {
132 | finish();
133 | return true;
134 | }
135 | return super.onOptionsItemSelected(item);
136 | }
137 |
138 |
139 | @Override
140 | public void showLoading() {
141 |
142 | }
143 |
144 | @Override
145 | public void hideLoading() {
146 |
147 | }
148 |
149 | @Override
150 | public void showMessage(@NonNull String message) {
151 | checkNotNull(message);
152 | ArmsUtils.snackbarText(message);
153 | }
154 |
155 | @Override
156 | public void launchActivity(@NonNull Intent intent) {
157 | checkNotNull(intent);
158 | ArmsUtils.startActivity(intent);
159 | }
160 |
161 | @Override
162 | public void killMyself() {
163 | finish();
164 | }
165 |
166 | @Override
167 | public void onBackPressed() {
168 | if (webview.canGoBack()) {
169 | webview.goBack();
170 | } else {
171 | super.onBackPressed();
172 | }
173 | }
174 |
175 | @Override
176 | public void setData(String url) {
177 | ArmsUtils.obtainAppComponentFromContext(this).imageLoader().loadImage(this,
178 | ImageConfigImpl
179 | .builder()
180 | .url(url)
181 | .imageView(imageView)
182 | .build());
183 | }
184 |
185 |
186 | }
187 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.activity;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.IBinder;
7 | import android.support.annotation.NonNull;
8 | import android.support.v4.app.Fragment;
9 | import android.support.v4.app.FragmentManager;
10 | import android.view.View;
11 | import android.view.inputmethod.InputMethodManager;
12 | import android.widget.RelativeLayout;
13 | import android.widget.TextView;
14 |
15 | import com.jess.arms.base.BaseActivity;
16 | import com.jess.arms.di.component.AppComponent;
17 | import com.jess.arms.utils.ArmsUtils;
18 | import com.roughike.bottombar.BottomBar;
19 | import com.roughike.bottombar.OnTabSelectListener;
20 | import com.tbruyelle.rxpermissions2.RxPermissions;
21 | import com.zhy.ganamrs.R;
22 | import com.zhy.ganamrs.app.utils.FragmentUtils;
23 | import com.zhy.ganamrs.di.component.DaggerMainComponent;
24 | import com.zhy.ganamrs.di.module.MainModule;
25 | import com.zhy.ganamrs.mvp.contract.MainContract;
26 | import com.zhy.ganamrs.mvp.presenter.MainPresenter;
27 | import com.zhy.ganamrs.mvp.ui.fragment.CollectFragment;
28 | import com.zhy.ganamrs.mvp.ui.fragment.HomeFragment;
29 | import com.zhy.ganamrs.mvp.ui.fragment.WelfareFragment;
30 |
31 | import java.util.ArrayList;
32 | import java.util.List;
33 |
34 | import butterknife.BindView;
35 |
36 | import static com.jess.arms.utils.Preconditions.checkNotNull;
37 | import static com.zhy.ganamrs.app.EventBusTags.ACTIVITY_FRAGMENT_REPLACE;
38 |
39 |
40 | public class MainActivity extends BaseActivity implements MainContract.View {
41 |
42 | @BindView(R.id.toolbar_title)
43 | TextView mToolbarTitle;
44 | @BindView(R.id.bottomBar)
45 | BottomBar mBottomBar;
46 | @BindView(R.id.toolbar_back)
47 | RelativeLayout toolbarBack;
48 | private RxPermissions mRxPermissions;
49 | private List mTitles;
50 | private List mFragments;
51 | private List mNavIds;
52 | private int mReplace = 0;
53 |
54 |
55 | private OnTabSelectListener mOnTabSelectListener = tabId -> {
56 | switch (tabId) {
57 | case R.id.tab_home:
58 | mReplace = 0;
59 | break;
60 | case R.id.tab_dashboard:
61 | mReplace = 1;
62 | break;
63 | case R.id.tab_mycenter:
64 | mReplace = 2;
65 | break;
66 | }
67 | mToolbarTitle.setText(mTitles.get(mReplace));
68 | FragmentUtils.hideAllShowFragment(mFragments.get(mReplace));
69 | };
70 |
71 | @Override
72 | public void setupActivityComponent(AppComponent appComponent) {
73 | this.mRxPermissions = new RxPermissions(this);
74 | DaggerMainComponent //如找不到该类,请编译一下项目
75 | .builder()
76 | .appComponent(appComponent)
77 | .mainModule(new MainModule(this))
78 | .build()
79 | .inject(this);
80 | }
81 |
82 | @Override
83 | public int initView(Bundle savedInstanceState) {
84 | return R.layout.activity_main; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
85 | }
86 |
87 | @Override
88 | public void initData(Bundle savedInstanceState) {
89 | toolbarBack.setVisibility(View.GONE);
90 | mPresenter.requestPermissions();
91 | if (mTitles == null) {
92 | mTitles = new ArrayList<>();
93 | mTitles.add(R.string.title_home);
94 | mTitles.add(R.string.title_dashboard);
95 | mTitles.add(R.string.title_mecenter);
96 | }
97 | if (mNavIds == null) {
98 | mNavIds = new ArrayList<>();
99 | mNavIds.add(R.id.tab_home);
100 | mNavIds.add(R.id.tab_dashboard);
101 | mNavIds.add(R.id.tab_mycenter);
102 | }
103 |
104 | HomeFragment homeFragment;
105 | WelfareFragment welfareFragment;
106 | CollectFragment collectFragment;
107 | if (savedInstanceState == null) {
108 | homeFragment = HomeFragment.newInstance();
109 | welfareFragment = WelfareFragment.newInstance();
110 | collectFragment = CollectFragment.newInstance();
111 | } else {
112 | mReplace = savedInstanceState.getInt(ACTIVITY_FRAGMENT_REPLACE);
113 | FragmentManager fm = getSupportFragmentManager();
114 | homeFragment = (HomeFragment) FragmentUtils.findFragment(fm, HomeFragment.class);
115 | welfareFragment = (WelfareFragment) FragmentUtils.findFragment(fm, WelfareFragment.class);
116 | collectFragment = (CollectFragment) FragmentUtils.findFragment(fm, CollectFragment.class);
117 | }
118 | if (mFragments == null) {
119 | mFragments = new ArrayList<>();
120 | mFragments.add(homeFragment);
121 | mFragments.add(welfareFragment);
122 | mFragments.add(collectFragment);
123 | }
124 | FragmentUtils.addFragments(getSupportFragmentManager(), mFragments, R.id.main_frame, 0);
125 | mBottomBar.setOnTabSelectListener(mOnTabSelectListener);
126 | }
127 |
128 |
129 | @Override
130 | public void showLoading() {
131 |
132 | }
133 |
134 | @Override
135 | public void hideLoading() {
136 |
137 | }
138 |
139 | @Override
140 | public void showMessage(@NonNull String message) {
141 | checkNotNull(message);
142 | ArmsUtils.snackbarText(message);
143 | }
144 |
145 | @Override
146 | public void launchActivity(@NonNull Intent intent) {
147 | checkNotNull(intent);
148 | ArmsUtils.startActivity(intent);
149 | }
150 |
151 | @Override
152 | public void killMyself() {
153 | finish();
154 | }
155 |
156 |
157 | @Override
158 | public RxPermissions getRxPermissions() {
159 | return mRxPermissions;
160 | }
161 |
162 | @Override
163 | protected void onSaveInstanceState(Bundle outState) {
164 | super.onSaveInstanceState(outState);
165 | //保存当前Activity显示的Fragment索引
166 | outState.putInt(ACTIVITY_FRAGMENT_REPLACE, mReplace);
167 | }
168 |
169 | @Override
170 | protected void onDestroy() {
171 | InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
172 | try {
173 | InputMethodManager.class.getDeclaredMethod("windowDismissed", IBinder.class).invoke(imm,
174 | getWindow().getDecorView().getWindowToken());
175 | } catch (Exception e) {
176 | e.printStackTrace();
177 | }
178 | super.onDestroy();
179 | this.mRxPermissions = null;
180 | this.mTitles = null;
181 | this.mFragments = null;
182 | this.mNavIds = null;
183 | }
184 |
185 | }
186 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/adapter/ArticleAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.adapter;
2 |
3 | import android.support.annotation.Nullable;
4 | import android.widget.ImageView;
5 |
6 | import com.chad.library.adapter.base.BaseQuickAdapter;
7 | import com.chad.library.adapter.base.BaseViewHolder;
8 | import com.zhy.ganamrs.R;
9 | import com.zhy.ganamrs.app.utils.CategoryType;
10 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Created by zhy on 17-7-20.
16 | */
17 |
18 | public class ArticleAdapter extends BaseQuickAdapter {
19 |
20 | public ArticleAdapter( @Nullable List data) {
21 | super(R.layout.item_collection, data);
22 | }
23 |
24 | @Override
25 | protected void convert(BaseViewHolder helper, DaoGankEntity item) {
26 | helper.setText(R.id.tvDesc, item.desc);
27 | ImageView ivImage = helper.getView(R.id.ivImage);
28 | if (item.type.equals(CategoryType.ANDROID_STR)){
29 | ivImage.setImageResource(R.mipmap.icon_android);
30 | }else if (item.type.equals(CategoryType.IOS_STR)){
31 | ivImage.setImageResource(R.mipmap.icon_apple);
32 | }else if (item.type.equals(CategoryType.QIAN_STR)){
33 | ivImage.setImageResource(R.mipmap.html);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/adapter/CategoryAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.adapter;
2 |
3 | import android.view.View;
4 |
5 | import com.jess.arms.base.BaseHolder;
6 | import com.jess.arms.base.DefaultAdapter;
7 | import com.zhy.ganamrs.R;
8 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
9 | import com.zhy.ganamrs.mvp.ui.holder.CategoryItemHolder;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by Administrator on 2017/7/4.
15 | */
16 |
17 | public class CategoryAdapter extends DefaultAdapter {
18 |
19 | public CategoryAdapter(List infos) {
20 | super(infos);
21 | }
22 |
23 | @Override
24 | public BaseHolder getHolder(View v, int viewType) {
25 | return new CategoryItemHolder(v);
26 | }
27 |
28 | @Override
29 | public int getLayoutId(int viewType) {
30 | return R.layout.item_android;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/adapter/CollectViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.adapter;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Created by Administrator on 2017/7/4.
11 | */
12 |
13 | public class CollectViewPagerAdapter extends FragmentPagerAdapter {
14 | private List mFragments;
15 | String[] title = {"妹子","文章"};
16 | public CollectViewPagerAdapter(FragmentManager fm, List mFragments) {
17 | super(fm);
18 | this.mFragments = mFragments;
19 | }
20 |
21 | @Override
22 | public CharSequence getPageTitle(int position) {
23 | return title[position];
24 | }
25 |
26 | @Override
27 | public Fragment getItem(int position) {
28 | return mFragments.get(position);
29 | }
30 |
31 | @Override
32 | public int getCount() {
33 | return mFragments.size();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/adapter/MeiziAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.adapter;
2 |
3 | import android.support.annotation.Nullable;
4 | import android.widget.ImageView;
5 |
6 | import com.bumptech.glide.Glide;
7 | import com.chad.library.adapter.base.BaseQuickAdapter;
8 | import com.zhy.ganamrs.R;
9 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
10 | import com.zhy.ganamrs.mvp.ui.holder.WelfareHolder;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Created by zhy on 17-7-20.
16 | */
17 |
18 | public class MeiziAdapter extends BaseQuickAdapter {
19 |
20 | public MeiziAdapter(@Nullable List data) {
21 | super(R.layout.girls_item, data);
22 | }
23 |
24 | @Override
25 | protected void convert(WelfareHolder helper, DaoGankEntity item) {
26 | ImageView view = helper.getView(R.id.network_imageview);
27 | Glide.with(helper.mAppComponent.appManager().getCurrentActivity() == null
28 | ? helper.mAppComponent.application() : helper.mAppComponent.appManager().getCurrentActivity())
29 | .load(item.url)
30 | .into(view);
31 | }
32 |
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/adapter/MianViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.adapter;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 |
7 | import com.zhy.ganamrs.app.utils.CategoryType;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * Created by Administrator on 2017/7/4.
13 | */
14 |
15 | public class MianViewPagerAdapter extends FragmentPagerAdapter {
16 | private List mFragments;
17 | public MianViewPagerAdapter(FragmentManager fm,List mFragments) {
18 | super(fm);
19 | this.mFragments = mFragments;
20 | }
21 |
22 | @Override
23 | public CharSequence getPageTitle(int position) {
24 | return CategoryType.getPageTitleByPosition(position);
25 | }
26 |
27 | @Override
28 | public Fragment getItem(int position) {
29 | return mFragments.get(position);
30 | }
31 |
32 | @Override
33 | public int getCount() {
34 | return mFragments.size();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/adapter/WelfareAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.adapter;
2 |
3 | import android.support.annotation.Nullable;
4 |
5 | import com.chad.library.adapter.base.BaseQuickAdapter;
6 | import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
7 | import com.zhy.ganamrs.R;
8 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
9 | import com.zhy.ganamrs.mvp.ui.holder.WelfareHolder;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by Administrator on 2017/7/6.
15 | */
16 |
17 | public class WelfareAdapter extends BaseQuickAdapter {
18 |
19 |
20 | public WelfareAdapter( @Nullable List data) {
21 | super(R.layout.item_girls, data);
22 | }
23 |
24 | @Override
25 | protected void convert(WelfareHolder helper, GankEntity.ResultsBean item) {
26 | helper.mImageLoader.loadImage(helper.mAppComponent.appManager().getCurrentActivity() == null
27 | ? helper.mAppComponent.application() : helper.mAppComponent.appManager().getCurrentActivity(),
28 | ImageConfigImpl
29 | .builder()
30 | .url(item.url)
31 | .imageView(helper.getView(R.id.ivImage))
32 | .build());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/fragment/ArticleFragment.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.fragment;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.NonNull;
6 | import android.support.v4.widget.SwipeRefreshLayout;
7 | import android.support.v7.widget.LinearLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.Gravity;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.TextView;
14 |
15 | import com.alibaba.android.arouter.launcher.ARouter;
16 | import com.chad.library.adapter.base.BaseQuickAdapter;
17 | import com.jess.arms.di.component.AppComponent;
18 | import com.jess.arms.utils.ArmsUtils;
19 | import com.zhy.ganamrs.R;
20 | import com.zhy.ganamrs.app.base.BaseFragment;
21 | import com.zhy.ganamrs.di.component.DaggerArticleComponent;
22 | import com.zhy.ganamrs.di.module.ArticleModule;
23 | import com.zhy.ganamrs.mvp.contract.ArticleContract;
24 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
25 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
26 | import com.zhy.ganamrs.mvp.presenter.ArticlePresenter;
27 | import com.zhy.ganamrs.mvp.ui.adapter.ArticleAdapter;
28 |
29 | import java.util.List;
30 |
31 | import butterknife.BindView;
32 | import io.reactivex.Observable;
33 | import io.reactivex.android.schedulers.AndroidSchedulers;
34 |
35 | import static com.jess.arms.utils.Preconditions.checkNotNull;
36 | import static com.zhy.ganamrs.app.ARouterPaths.MAIN_DETAIL;
37 | import static com.zhy.ganamrs.app.EventBusTags.EXTRA_DETAIL;
38 |
39 |
40 | public class ArticleFragment extends BaseFragment implements ArticleContract.View , SwipeRefreshLayout.OnRefreshListener{
41 |
42 | @BindView(R.id.recyclerView)
43 | RecyclerView mRecyclerView;
44 | @BindView(R.id.refreshLayout)
45 | SwipeRefreshLayout mSwipeRefreshLayout;
46 |
47 | private ArticleAdapter mAdapter;
48 | private GankEntity.ResultsBean intentArticle;
49 |
50 | public static ArticleFragment newInstance() {
51 | ArticleFragment fragment = new ArticleFragment();
52 | return fragment;
53 | }
54 |
55 | @Override
56 | public void setupFragmentComponent(AppComponent appComponent) {
57 | DaggerArticleComponent //如找不到该类,请编译一下项目
58 | .builder()
59 | .appComponent(appComponent)
60 | .articleModule(new ArticleModule(this))
61 | .build()
62 | .inject(this);
63 | }
64 |
65 | @Override
66 | public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
67 | return inflater.inflate(R.layout.layout_refresh_list, container, false);
68 | }
69 |
70 | @Override
71 | public void initData(Bundle savedInstanceState) {
72 | mSwipeRefreshLayout.setOnRefreshListener(this);
73 | ArmsUtils.configRecycleView(mRecyclerView, new LinearLayoutManager(getActivity()));
74 |
75 | mAdapter = new ArticleAdapter(null);
76 | mAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_BOTTOM);
77 | mAdapter.setOnItemClickListener((adapter, view, position) -> {
78 | DaoGankEntity bean = (DaoGankEntity) adapter.getItem(position);
79 | if (intentArticle == null)
80 | intentArticle = new GankEntity.ResultsBean();
81 | intentArticle._id = bean._id;
82 | intentArticle.createdAt = bean.createdAt;
83 | intentArticle.desc = bean.desc;
84 | intentArticle.images = bean.images;
85 | intentArticle.publishedAt = bean.publishedAt;
86 | intentArticle.source = bean.source;
87 | intentArticle.type = bean.type;
88 | intentArticle.url = bean.url;
89 | intentArticle.used = bean.used;
90 | intentArticle.who = bean.who;
91 | ARouter.getInstance().build(MAIN_DETAIL)
92 | .withSerializable(EXTRA_DETAIL, intentArticle)
93 | .navigation();
94 | });
95 | TextView textView = new TextView(getContext());
96 | textView.setText("没有更多内容了");
97 | textView.setGravity(Gravity.CENTER);
98 | mAdapter.setEmptyView(textView);
99 | mRecyclerView.setAdapter(mAdapter);
100 | }
101 | @Override
102 | protected void onFragmentFirstVisible() {
103 | //去服务器下载数据
104 | mPresenter.requestData(true);
105 | }
106 |
107 | @Override
108 | public void startLoadMore() {
109 | Observable.just(1)
110 | .observeOn(AndroidSchedulers.mainThread())
111 | .subscribe(integer -> mSwipeRefreshLayout.setRefreshing(true));
112 | }
113 |
114 | @Override
115 | public void endLoadMore() {
116 | mSwipeRefreshLayout.setRefreshing(false);
117 | }
118 |
119 | @Override
120 | public void setAdapter(List entity) {
121 | mAdapter.setNewData(entity);
122 | }
123 |
124 | /**
125 | * 此方法是让外部调用使fragment做一些操作的,比如说外部的activity想让fragment对象执行一些方法,
126 | * 建议在有多个需要让外界调用的方法时,统一传Message,通过what字段,来区分不同的方法,在setData
127 | * 方法中就可以switch做不同的操作,这样就可以用统一的入口方法做不同的事
128 | *
129 | * 使用此方法时请注意调用时fragment的生命周期,如果调用此setData方法时onCreate还没执行
130 | * setData里却调用了presenter的方法时,是会报空的,因为dagger注入是在onCreated方法中执行的,然后才创建的presenter
131 | * 如果要做一些初始化操作,可以不必让外部调setData,在initData中初始化就可以了
132 | *
133 | * @param data
134 | */
135 |
136 |
137 |
138 | @Override
139 | public void setData(Object data) {
140 | mAdapter.notifyDataSetChanged();
141 | }
142 |
143 |
144 | @Override
145 | public void showLoading() {
146 |
147 | }
148 |
149 | @Override
150 | public void hideLoading() {
151 |
152 | }
153 |
154 | @Override
155 | public void showMessage(@NonNull String message) {
156 | checkNotNull(message);
157 | ArmsUtils.snackbarText(message);
158 | }
159 |
160 | @Override
161 | public void launchActivity(@NonNull Intent intent) {
162 | checkNotNull(intent);
163 | ArmsUtils.startActivity(intent);
164 | }
165 |
166 | @Override
167 | public void killMyself() {
168 |
169 | }
170 |
171 | @Override
172 | public void onRefresh() {
173 | mPresenter.requestData(true);
174 | }
175 |
176 |
177 | }
178 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/fragment/CategoryFragment.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.fragment;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.NonNull;
6 | import android.support.v4.widget.SwipeRefreshLayout;
7 | import android.support.v7.widget.LinearLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 |
13 | import com.alibaba.android.arouter.launcher.ARouter;
14 | import com.jess.arms.base.DefaultAdapter;
15 | import com.jess.arms.di.component.AppComponent;
16 | import com.jess.arms.utils.ArmsUtils;
17 | import com.paginate.Paginate;
18 | import com.zhy.ganamrs.R;
19 | import com.zhy.ganamrs.app.base.BaseFragment;
20 | import com.zhy.ganamrs.di.component.DaggerCategoryComponent;
21 | import com.zhy.ganamrs.di.module.CategoryModule;
22 | import com.zhy.ganamrs.mvp.contract.CategoryContract;
23 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
24 | import com.zhy.ganamrs.mvp.presenter.CategoryPresenter;
25 |
26 | import butterknife.BindView;
27 | import io.reactivex.Observable;
28 | import io.reactivex.android.schedulers.AndroidSchedulers;
29 |
30 | import static com.jess.arms.utils.Preconditions.checkNotNull;
31 | import static com.zhy.ganamrs.app.ARouterPaths.MAIN_DETAIL;
32 | import static com.zhy.ganamrs.app.EventBusTags.EXTRA_DETAIL;
33 |
34 | public class CategoryFragment extends BaseFragment implements CategoryContract.View , SwipeRefreshLayout.OnRefreshListener{
35 |
36 |
37 | @BindView(R.id.recyclerView)
38 | RecyclerView mRecyclerView;
39 | @BindView(R.id.refreshLayout)
40 | SwipeRefreshLayout mSwipeRefreshLayout;
41 |
42 | private boolean isLoadingMore;
43 | private Paginate mPaginate;
44 | private String type;
45 |
46 | public static CategoryFragment newInstance(String type) {
47 | CategoryFragment fragment = new CategoryFragment();
48 | Bundle bundle = new Bundle();
49 | bundle.putString("type", type);
50 | fragment.setArguments(bundle);
51 | return fragment;
52 | }
53 |
54 | @Override
55 | public void setupFragmentComponent(AppComponent appComponent) {
56 | DaggerCategoryComponent //如找不到该类,请编译一下项目
57 | .builder()
58 | .appComponent(appComponent)
59 | .categoryModule(new CategoryModule(this))
60 | .build()
61 | .inject(this);
62 | }
63 |
64 | @Override
65 | public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
66 | return inflater.inflate(R.layout.layout_refresh_list, container, false);
67 | }
68 |
69 | @Override
70 | public void initData(Bundle savedInstanceState) {
71 | type = getArguments().getString("type");
72 | mSwipeRefreshLayout.setOnRefreshListener(this);
73 | ArmsUtils.configRecycleView(mRecyclerView, new LinearLayoutManager(getActivity()));
74 | }
75 | @Override
76 | protected void onFragmentFirstVisible() {
77 | //去服务器下载数据
78 | mPresenter.requestData(type,true);
79 | }
80 |
81 | /**
82 | * 此方法是让外部调用使fragment做一些操作的,比如说外部的activity想让fragment对象执行一些方法,
83 | * 建议在有多个需要让外界调用的方法时,统一传Message,通过what字段,来区分不同的方法,在setData
84 | * 方法中就可以switch做不同的操作,这样就可以用统一的入口方法做不同的事
85 | *
86 | * 使用此方法时请注意调用时fragment的生命周期,如果调用此setData方法时onCreate还没执行
87 | * setData里却调用了presenter的方法时,是会报空的,因为dagger注入是在onCreated方法中执行的,然后才创建的presenter
88 | * 如果要做一些初始化操作,可以不必让外部调setData,在initData中初始化就可以了
89 | *
90 | * @param data
91 | */
92 |
93 | @Override
94 | public void setData(Object data) {
95 |
96 | }
97 |
98 |
99 | @Override
100 | public void showLoading() {
101 | Observable.just(1)
102 | .observeOn(AndroidSchedulers.mainThread())
103 | .subscribe(integer -> mSwipeRefreshLayout.setRefreshing(true));
104 | }
105 |
106 | @Override
107 | public void hideLoading() {
108 | mSwipeRefreshLayout.setRefreshing(false);
109 | }
110 |
111 | @Override
112 | public void showMessage(@NonNull String message) {
113 | checkNotNull(message);
114 | ArmsUtils.snackbarText(message);
115 | }
116 |
117 | @Override
118 | public void launchActivity(@NonNull Intent intent) {
119 | checkNotNull(intent);
120 | ArmsUtils.startActivity(intent);
121 | }
122 |
123 | @Override
124 | public void killMyself() {
125 |
126 | }
127 |
128 | @Override
129 | public void onRefresh() {
130 | mPresenter.requestData(type,true);
131 | }
132 |
133 | @Override
134 | public void startLoadMore() {
135 | isLoadingMore = true;
136 | }
137 |
138 | @Override
139 | public void endLoadMore() {
140 | isLoadingMore = false;
141 | }
142 |
143 | @Override
144 | public void setAdapter(DefaultAdapter mAdapter) {
145 | mRecyclerView.setAdapter(mAdapter);
146 | mAdapter.setOnItemClickListener((View view, int viewType, Object data, int position) -> {
147 | GankEntity.ResultsBean bean = (GankEntity.ResultsBean) data;
148 | ARouter.getInstance().build(MAIN_DETAIL)
149 | .withSerializable(EXTRA_DETAIL, bean)
150 | .navigation();
151 | });
152 | initPaginate();
153 | }
154 |
155 | private void initPaginate() {
156 | if (mPaginate == null) {
157 | Paginate.Callbacks callbacks = new Paginate.Callbacks() {
158 | @Override
159 | public void onLoadMore() {
160 | mPresenter.requestData(type,false);
161 | }
162 |
163 | @Override
164 | public boolean isLoading() {
165 | return isLoadingMore;
166 | }
167 |
168 | @Override
169 | public boolean hasLoadedAllItems() {
170 | return false;
171 | }
172 | };
173 |
174 | mPaginate = Paginate.with(mRecyclerView, callbacks)
175 | .setLoadingTriggerThreshold(0)
176 | .build();
177 | mPaginate.setHasMoreDataToLoad(false);
178 | }
179 | }
180 |
181 | @Override
182 | public void onDestroy() {
183 | super.onDestroy();
184 | DefaultAdapter.releaseAllHolder(mRecyclerView);//super.onDestroy()之后会unbind,所有view被置为null,所以必须在之前调用
185 | this.mPaginate = null;
186 | }
187 |
188 |
189 | }
190 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/fragment/CollectFragment.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.fragment;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.NonNull;
6 | import android.support.design.widget.TabLayout;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v4.view.ViewPager;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 |
13 | import com.jess.arms.base.BaseFragment;
14 | import com.jess.arms.di.component.AppComponent;
15 | import com.jess.arms.utils.ArmsUtils;
16 | import com.zhy.ganamrs.R;
17 | import com.zhy.ganamrs.di.component.DaggerCollectComponent;
18 | import com.zhy.ganamrs.di.module.CollectModule;
19 | import com.zhy.ganamrs.mvp.contract.CollectContract;
20 | import com.zhy.ganamrs.mvp.presenter.CollectPresenter;
21 | import com.zhy.ganamrs.mvp.ui.adapter.CollectViewPagerAdapter;
22 |
23 | import java.util.ArrayList;
24 | import java.util.List;
25 |
26 | import butterknife.BindView;
27 |
28 | import static com.jess.arms.utils.Preconditions.checkNotNull;
29 |
30 |
31 | public class CollectFragment extends BaseFragment implements CollectContract.View {
32 |
33 |
34 | @BindView(R.id.tabs)
35 | TabLayout tabs;
36 | @BindView(R.id.mainPager)
37 | ViewPager mainPager;
38 | private List mFragments;
39 |
40 | public static CollectFragment newInstance() {
41 | CollectFragment fragment = new CollectFragment();
42 | return fragment;
43 | }
44 |
45 | @Override
46 | public void setupFragmentComponent(AppComponent appComponent) {
47 | DaggerCollectComponent //如找不到该类,请编译一下项目
48 | .builder()
49 | .appComponent(appComponent)
50 | .collectModule(new CollectModule(this))
51 | .build()
52 | .inject(this);
53 | }
54 |
55 | @Override
56 | public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
57 | return inflater.inflate(R.layout.fragment_collect, container, false);
58 | }
59 |
60 | @Override
61 | public void initData(Bundle savedInstanceState) {
62 | if (mFragments == null) {
63 | mFragments = new ArrayList<>();
64 | mFragments.add(MeiziFragment.newInstance());
65 | mFragments.add(ArticleFragment.newInstance());
66 | }
67 | mainPager.setOffscreenPageLimit(mFragments.size());
68 | mainPager.setAdapter(new CollectViewPagerAdapter(getChildFragmentManager(),mFragments));
69 | tabs.setupWithViewPager(mainPager);
70 | }
71 | /**
72 | * 此方法是让外部调用使fragment做一些操作的,比如说外部的activity想让fragment对象执行一些方法,
73 | * 建议在有多个需要让外界调用的方法时,统一传Message,通过what字段,来区分不同的方法,在setData
74 | * 方法中就可以switch做不同的操作,这样就可以用统一的入口方法做不同的事
75 | *
76 | * 使用此方法时请注意调用时fragment的生命周期,如果调用此setData方法时onCreate还没执行
77 | * setData里却调用了presenter的方法时,是会报空的,因为dagger注入是在onCreated方法中执行的,然后才创建的presenter
78 | * 如果要做一些初始化操作,可以不必让外部调setData,在initData中初始化就可以了
79 | *
80 | * @param data
81 | */
82 |
83 | @Override
84 | public void setData(Object data) {
85 |
86 | }
87 |
88 |
89 | @Override
90 | public void showLoading() {
91 |
92 | }
93 |
94 | @Override
95 | public void hideLoading() {
96 |
97 | }
98 |
99 | @Override
100 | public void showMessage(@NonNull String message) {
101 | checkNotNull(message);
102 | ArmsUtils.snackbarText(message);
103 | }
104 |
105 | @Override
106 | public void launchActivity(@NonNull Intent intent) {
107 | checkNotNull(intent);
108 | ArmsUtils.startActivity(intent);
109 | }
110 |
111 | @Override
112 | public void killMyself() {
113 |
114 | }
115 |
116 | @Override
117 | public void onDestroy() {
118 | super.onDestroy();
119 | mainPager = null;
120 | tabs = null;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/fragment/HomeFragment.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.fragment;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.NonNull;
6 | import android.support.design.widget.TabLayout;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v4.view.ViewPager;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 |
13 | import com.jess.arms.di.component.AppComponent;
14 | import com.jess.arms.utils.ArmsUtils;
15 | import com.zhy.ganamrs.R;
16 | import com.zhy.ganamrs.app.base.BaseFragment;
17 | import com.zhy.ganamrs.app.utils.CategoryType;
18 | import com.zhy.ganamrs.di.component.DaggerHomeComponent;
19 | import com.zhy.ganamrs.di.module.HomeModule;
20 | import com.zhy.ganamrs.mvp.contract.HomeContract;
21 | import com.zhy.ganamrs.mvp.presenter.HomePresenter;
22 | import com.zhy.ganamrs.mvp.ui.adapter.MianViewPagerAdapter;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | import butterknife.BindView;
28 |
29 | import static com.jess.arms.utils.Preconditions.checkNotNull;
30 |
31 |
32 | public class HomeFragment extends BaseFragment implements HomeContract.View {
33 |
34 | @BindView(R.id.tabs)
35 | TabLayout tabs;
36 | @BindView(R.id.mainPager)
37 | ViewPager mainPager;
38 | private List mFragments;
39 | public static HomeFragment newInstance() {
40 | HomeFragment fragment = new HomeFragment();
41 | return fragment;
42 | }
43 |
44 | @Override
45 | public void setupFragmentComponent(AppComponent appComponent) {
46 | DaggerHomeComponent //如找不到该类,请编译一下项目
47 | .builder()
48 | .appComponent(appComponent)
49 | .homeModule(new HomeModule(this))
50 | .build()
51 | .inject(this);
52 | }
53 |
54 | @Override
55 | public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
56 | return inflater.inflate(R.layout.fragment_home, container, false);
57 | }
58 |
59 | @Override
60 | public void initData(Bundle savedInstanceState) {
61 | if (mFragments == null) {
62 | mFragments = new ArrayList<>();
63 | mFragments.add(CategoryFragment.newInstance(CategoryType.ANDROID_STR));
64 | mFragments.add(CategoryFragment.newInstance(CategoryType.IOS_STR));
65 | mFragments.add(CategoryFragment.newInstance(CategoryType.QIAN_STR));
66 | }
67 | mainPager.setOffscreenPageLimit(mFragments.size());
68 | mainPager.setAdapter(new MianViewPagerAdapter(getChildFragmentManager(),mFragments));
69 | tabs.setupWithViewPager(mainPager);
70 | }
71 |
72 | @Override
73 | protected void onFragmentFirstVisible() {
74 | //去服务器下载数据
75 | }
76 |
77 | /**
78 | * 此方法是让外部调用使fragment做一些操作的,比如说外部的activity想让fragment对象执行一些方法,
79 | * 建议在有多个需要让外界调用的方法时,统一传Message,通过what字段,来区分不同的方法,在setData
80 | * 方法中就可以switch做不同的操作,这样就可以用统一的入口方法做不同的事
81 | *
82 | * 使用此方法时请注意调用时fragment的生命周期,如果调用此setData方法时onCreate还没执行
83 | * setData里却调用了presenter的方法时,是会报空的,因为dagger注入是在onCreated方法中执行的,然后才创建的presenter
84 | * 如果要做一些初始化操作,可以不必让外部调setData,在initData中初始化就可以了
85 | *
86 | * @param data
87 | */
88 |
89 | @Override
90 | public void setData(Object data) {
91 |
92 | }
93 |
94 |
95 | @Override
96 | public void showLoading() {
97 |
98 | }
99 |
100 | @Override
101 | public void hideLoading() {
102 |
103 | }
104 |
105 | @Override
106 | public void showMessage(@NonNull String message) {
107 | checkNotNull(message);
108 | ArmsUtils.snackbarText(message);
109 | }
110 |
111 | @Override
112 | public void launchActivity(@NonNull Intent intent) {
113 | checkNotNull(intent);
114 | ArmsUtils.startActivity(intent);
115 | }
116 |
117 | @Override
118 | public void killMyself() {
119 |
120 | }
121 |
122 | @Override
123 | public void onDestroy() {
124 | super.onDestroy();
125 | mainPager = null;
126 | tabs = null;
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/fragment/MeiziFragment.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.fragment;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.NonNull;
6 | import android.support.v4.widget.SwipeRefreshLayout;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.StaggeredGridLayoutManager;
9 | import android.view.Gravity;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.TextView;
14 |
15 | import com.chad.library.adapter.base.BaseQuickAdapter;
16 | import com.jess.arms.di.component.AppComponent;
17 | import com.jess.arms.utils.ArmsUtils;
18 | import com.zhy.ganamrs.R;
19 | import com.zhy.ganamrs.app.base.BaseFragment;
20 | import com.zhy.ganamrs.di.component.DaggerMeiziComponent;
21 | import com.zhy.ganamrs.di.module.MeiziModule;
22 | import com.zhy.ganamrs.mvp.contract.MeiziContract;
23 | import com.zhy.ganamrs.mvp.model.entity.DaoGankEntity;
24 | import com.zhy.ganamrs.mvp.presenter.MeiziPresenter;
25 | import com.zhy.ganamrs.mvp.ui.adapter.MeiziAdapter;
26 | import com.zhy.ganamrs.mvp.ui.widget.SpacesItemDecoration;
27 |
28 | import org.simple.eventbus.Subscriber;
29 |
30 | import java.util.List;
31 |
32 | import butterknife.BindView;
33 | import io.reactivex.Observable;
34 | import io.reactivex.android.schedulers.AndroidSchedulers;
35 |
36 | import static com.jess.arms.utils.Preconditions.checkNotNull;
37 | import static com.zhy.ganamrs.R.id.recyclerView;
38 |
39 |
40 | public class MeiziFragment extends BaseFragment implements MeiziContract.View , SwipeRefreshLayout.OnRefreshListener{
41 |
42 |
43 | @BindView(recyclerView)
44 | RecyclerView mRecyclerView;
45 | @BindView(R.id.refreshLayout)
46 | SwipeRefreshLayout mSwipeRefreshLayout;
47 |
48 | private MeiziAdapter mAdapter;
49 |
50 | public static MeiziFragment newInstance() {
51 | MeiziFragment fragment = new MeiziFragment();
52 | return fragment;
53 | }
54 |
55 | @Override
56 | public void setupFragmentComponent(AppComponent appComponent) {
57 | DaggerMeiziComponent //如找不到该类,请编译一下项目
58 | .builder()
59 | .appComponent(appComponent)
60 | .meiziModule(new MeiziModule(this))
61 | .build()
62 | .inject(this);
63 | }
64 |
65 | @Override
66 | public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
67 | return inflater.inflate(R.layout.layout_refresh_list, container, false);
68 | }
69 |
70 | @Override
71 | public void initData(Bundle savedInstanceState) {
72 | mSwipeRefreshLayout.setOnRefreshListener(this);
73 | ArmsUtils.configRecycleView(mRecyclerView,new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
74 | mAdapter = new MeiziAdapter(null);
75 | mAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_BOTTOM);
76 | mAdapter.setOnItemClickListener((adapter, view, position) -> {
77 |
78 | });
79 |
80 | TextView textView = new TextView(getContext());
81 | textView.setText("没有更多内容了");
82 | textView.setGravity(Gravity.CENTER);
83 | mAdapter.setEmptyView(textView);
84 |
85 | SpacesItemDecoration decoration=new SpacesItemDecoration(16);
86 | mRecyclerView.addItemDecoration(decoration);
87 |
88 | mRecyclerView.setAdapter(mAdapter);
89 | }
90 |
91 | @Override
92 | protected void onFragmentFirstVisible() {
93 | //去服务器下载数据
94 | mPresenter.requestData(true);
95 | }
96 |
97 | @Override
98 | public void startLoadMore() {
99 | Observable.just(1)
100 | .observeOn(AndroidSchedulers.mainThread())
101 | .subscribe(integer -> mSwipeRefreshLayout.setRefreshing(true));
102 | }
103 |
104 | @Override
105 | public void endLoadMore() {
106 | mSwipeRefreshLayout.setRefreshing(false);
107 | }
108 |
109 | @Override
110 | public void setAdapter(List entity) {
111 | mAdapter.setNewData(entity);
112 | }
113 |
114 |
115 | @Subscriber(tag = "meizi")
116 | private void updateAdapter(Object o){
117 | mPresenter.requestData(true);
118 | }
119 | /**
120 | * 此方法是让外部调用使fragment做一些操作的,比如说外部的activity想让fragment对象执行一些方法,
121 | * 建议在有多个需要让外界调用的方法时,统一传Message,通过what字段,来区分不同的方法,在setData
122 | * 方法中就可以switch做不同的操作,这样就可以用统一的入口方法做不同的事
123 | *
124 | * 使用此方法时请注意调用时fragment的生命周期,如果调用此setData方法时onCreate还没执行
125 | * setData里却调用了presenter的方法时,是会报空的,因为dagger注入是在onCreated方法中执行的,然后才创建的presenter
126 | * 如果要做一些初始化操作,可以不必让外部调setData,在initData中初始化就可以了
127 | *
128 | * @param data
129 | */
130 |
131 | @Override
132 | public void setData(Object data) {
133 |
134 | }
135 |
136 |
137 | @Override
138 | public void showLoading() {
139 |
140 | }
141 |
142 | @Override
143 | public void hideLoading() {
144 |
145 | }
146 |
147 | @Override
148 | public void showMessage(@NonNull String message) {
149 | checkNotNull(message);
150 | ArmsUtils.snackbarText(message);
151 | }
152 |
153 | @Override
154 | public void launchActivity(@NonNull Intent intent) {
155 | checkNotNull(intent);
156 | ArmsUtils.startActivity(intent);
157 | }
158 |
159 | @Override
160 | public void killMyself() {
161 |
162 | }
163 |
164 | @Override
165 | public void onRefresh() {
166 | mPresenter.requestData(true);
167 | }
168 |
169 |
170 | }
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/holder/CategoryItemHolder.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.holder;
2 |
3 | import android.view.View;
4 | import android.widget.ImageView;
5 | import android.widget.TextView;
6 |
7 | import com.jess.arms.base.BaseHolder;
8 | import com.zhy.ganamrs.R;
9 | import com.zhy.ganamrs.app.utils.CategoryType;
10 | import com.zhy.ganamrs.mvp.model.entity.GankEntity;
11 |
12 | import butterknife.BindView;
13 |
14 | /**
15 | * Created by Administrator on 2017/7/5.
16 | */
17 |
18 | public class CategoryItemHolder extends BaseHolder {
19 |
20 | @BindView(R.id.ivImage)
21 | ImageView ivImage;
22 | @BindView(R.id.tvDesc)
23 | TextView tvDesc;
24 | @BindView(R.id.tvAuthor)
25 | TextView tvAuthor;
26 | @BindView(R.id.tvDate)
27 | TextView tvDate;
28 |
29 |
30 | public CategoryItemHolder(View itemView) {
31 | super(itemView);
32 | }
33 |
34 | @Override
35 | public void setData(GankEntity.ResultsBean data, int position) {
36 | tvDate.setText(data.publishedAt);
37 | tvAuthor.setText(data.who);
38 | tvDesc.setText(data.desc);
39 | if (data.type.equals(CategoryType.ANDROID_STR)){
40 | ivImage.setImageResource(R.mipmap.icon_android);
41 | }else if (data.type.equals(CategoryType.IOS_STR)){
42 | ivImage.setImageResource(R.mipmap.icon_apple);
43 | }else if (data.type.equals(CategoryType.QIAN_STR)){
44 | ivImage.setImageResource(R.mipmap.html);
45 | }
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/holder/WelfareHolder.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.holder;
2 |
3 | import android.view.View;
4 |
5 | import com.chad.library.adapter.base.BaseViewHolder;
6 | import com.jess.arms.di.component.AppComponent;
7 | import com.jess.arms.http.imageloader.ImageLoader;
8 | import com.jess.arms.utils.ArmsUtils;
9 |
10 | /**
11 | * Created by Administrator on 2017/7/6.
12 | */
13 |
14 | public class WelfareHolder extends BaseViewHolder {
15 |
16 | public AppComponent mAppComponent;
17 | public ImageLoader mImageLoader;//用于加载图片的管理类,默认使用glide,使用策略模式,可替换框架
18 | public WelfareHolder(View view) {
19 | super(view);
20 | mAppComponent = ArmsUtils.obtainAppComponentFromContext(itemView.getContext());
21 | mImageLoader = mAppComponent.imageLoader();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhy/ganamrs/mvp/ui/widget/SpacesItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs.mvp.ui.widget;
2 |
3 | import android.graphics.Rect;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 |
7 | /**
8 | * Created by clevo on 2015/7/27.
9 | */
10 | public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
11 |
12 | private int space;
13 |
14 | public SpacesItemDecoration(int space) {
15 | this.space=space;
16 | }
17 |
18 | @Override
19 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
20 | outRect.left=space;
21 | outRect.right=space;
22 | outRect.bottom=space;
23 | if(parent.getChildAdapterPosition(view)==0){
24 | outRect.top=space;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_like_circle_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_dashboard_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_heart_outline_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/drawable/ic_heart_outline_white.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_heart_red.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/drawable/ic_heart_red.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_home_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_list_item_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
25 |
26 |
33 |
34 |
40 |
41 |
42 |
43 |
44 |
45 |
49 |
50 |
54 |
55 |
56 |
66 |
67 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
16 |
17 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_category.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_collect.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
20 |
21 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_home.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
19 |
20 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/girls_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/include_title.xml:
--------------------------------------------------------------------------------
1 |
2 |
15 |
16 |
22 |
23 |
30 |
31 |
32 |
33 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_android.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 |
20 |
21 |
24 |
25 |
32 |
33 |
44 |
45 |
46 |
47 |
53 |
54 |
57 |
58 |
66 |
67 |
68 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_collection.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 |
21 |
22 |
28 |
29 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_girls.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
22 |
28 |
29 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_refresh_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_friends.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-hdpi/ic_friends.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_friends.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-mdpi/ic_friends.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_arrow_back_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-xhdpi/ic_arrow_back_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_friends.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-xhdpi/ic_friends.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_heart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-xhdpi/ic_heart.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/icon_android.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-xhdpi/icon_android.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/icon_apple.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-xhdpi/icon_apple.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/html.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-xxhdpi/html.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_arrow_back_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-xxhdpi/ic_arrow_back_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_friends.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-xxhdpi/ic_friends.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_arrow_back_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-xxxhdpi/ic_arrow_back_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_friends.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-xxxhdpi/ic_friends.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #2dbc6d
8 | #FFFEFE
9 | #e2e2e2
10 | #d1d1d1
11 | #2f3641
12 | #333333
13 | #8E8E93
14 | #FFB142
15 | #B00905
16 | #3dfc92
17 | #f2f2f2
18 | #666666
19 | #999999
20 | #cc140f
21 | #f4504c
22 | #3daba5
23 | #cccccc
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 10sp
6 | 11sp
7 | 12sp
8 | 13sp
9 | 14sp
10 | 15sp
11 | 16sp
12 | 17sp
13 | 18sp
14 | 19sp
15 | 20sp
16 | 21sp
17 | 22sp
18 | 23sp
19 | 24sp
20 | 25sp
21 |
22 |
23 | 1dp
24 | 2dp
25 | 3dp
26 | 4dp
27 | 5dp
28 | 6dp
29 | 7dp
30 | 8dp
31 | 9dp
32 | 10dp
33 | 12dp
34 | 15dp
35 | 16dp
36 | 18dp
37 | 20dp
38 |
39 |
40 | 2dp
41 | 4dp
42 | 6dp
43 | 8dp
44 | 10dp
45 |
46 |
47 | 1px
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Ganamrs
3 |
4 |
5 | 首页
6 | 福利
7 | 收藏
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/bottombar_tabs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
11 |
12 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zhy/ganamrs/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zhy.ganamrs;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | apply from: "config.gradle" //这里表示引用config.gradle文件
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | mavenCentral()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:2.3.3'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | //lambda
14 | classpath 'me.tatarka:gradle-retrolambda:3.6.0'
15 |
16 | //greendDao
17 | classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' // add plugin
18 | }
19 | }
20 |
21 | allprojects {
22 | repositories {
23 | jcenter()
24 | maven { url "https://jitpack.io" }//这里要使用rxcahche指定的仓库
25 | maven {
26 | url 'https://dl.google.com/dl/android/maven2/'
27 | // Alternative URL is 'https://dl.google.com/dl/android/maven2/'
28 | }
29 | }
30 | }
31 |
32 | task clean(type: Delete) {
33 | delete rootProject.buildDir
34 | }
35 |
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 |
3 | android = [
4 | compileSdkVersion : 26,
5 | buildToolsVersion : "26.0.1",
6 | minSdkVersion : 15,
7 | targetSdkVersion : 26,
8 | versionCode : 135,
9 | versionName : "2.2.0"
10 | ]
11 |
12 | version = [
13 | androidSupportSdkVersion: "26.0.1",
14 | retrofitSdkVersion : "2.3.0",
15 | dagger2SdkVersion : "2.11",
16 | glideSdkVersion : "4.0.0",
17 | butterknifeSdkVersion : "8.8.1",
18 | rxlifecycleSdkVersion : "1.0",
19 | rxlifecycle2SdkVersion : "2.1.0",
20 | espressoSdkVersion : "2.2.2",
21 | canarySdkVersion : "1.5.1"
22 | ]
23 |
24 | dependencies = [
25 | //support
26 | "appcompat-v7" : "com.android.support:appcompat-v7:${version["androidSupportSdkVersion"]}",
27 | "design" : "com.android.support:design:${version["androidSupportSdkVersion"]}",
28 | "support-v4" : "com.android.support:support-v4:${version["androidSupportSdkVersion"]}",
29 | "cardview-v7" : "com.android.support:cardview-v7:${version["androidSupportSdkVersion"]}",
30 | "annotations" : "com.android.support:support-annotations:${version["androidSupportSdkVersion"]}",
31 | "recyclerview-v7" : "com.android.support:recyclerview-v7:${version["androidSupportSdkVersion"]}",
32 |
33 | //network
34 | "retrofit" : "com.squareup.retrofit2:retrofit:${version["retrofitSdkVersion"]}",
35 | "retrofit-converter-gson" : "com.squareup.retrofit2:converter-gson:${version["retrofitSdkVersion"]}",
36 | "retrofit-adapter-rxjava" : "com.squareup.retrofit2:adapter-rxjava:${version["retrofitSdkVersion"]}",
37 | "retrofit-adapter-rxjava2" : "com.squareup.retrofit2:adapter-rxjava2:${version["retrofitSdkVersion"]}",
38 | "okhttp3" : "com.squareup.okhttp3:okhttp:3.8.1",
39 | "okhttp-urlconnection" : "com.squareup.okhttp:okhttp-urlconnection:2.0.0",
40 | "glide" : "com.github.bumptech.glide:glide:${version["glideSdkVersion"]}",
41 | "glide-compiler" : "com.github.bumptech.glide:compiler:${version["glideSdkVersion"]}",
42 | "glide-loader-okhttp3" : "com.github.bumptech.glide:okhttp3-integration:${version["glideSdkVersion"]}",
43 | "picasso" : "com.squareup.picasso:picasso:2.5.2",
44 |
45 | //view
46 | "autolayout" : "com.zhy:autolayout:1.4.5",
47 | "butterknife" : "com.jakewharton:butterknife:${version["butterknifeSdkVersion"]}",
48 | "butterknife-compiler" : "com.jakewharton:butterknife-compiler:${version["butterknifeSdkVersion"]}",
49 | "pickerview" : "com.contrarywind:Android-PickerView:3.2.5",
50 | "photoview" : "com.github.chrisbanes.photoview:library:1.2.3",
51 | "numberprogressbar" : "com.daimajia.numberprogressbar:library:1.2@aar",
52 | "nineoldandroids" : "com.nineoldandroids:library:2.4.0",
53 | "paginate" : "com.github.markomilos:paginate:0.5.1",
54 | "vlayout" : "com.alibaba.android:vlayout:1.1.0@aar",
55 |
56 | //rx1
57 | "rxandroid" : "io.reactivex:rxandroid:1.2.1",
58 | "rxjava" : "io.reactivex:rxjava:1.3.0",
59 | "rxlifecycle" : "com.trello:rxlifecycle:${version["rxlifecycleSdkVersion"]}",
60 | "rxlifecycle-components" : "com.trello:rxlifecycle-components:${version["rxlifecycleSdkVersion"]}",
61 | "rxcache" : "com.github.VictorAlbertos.RxCache:runtime:1.7.0-1.x",
62 | "rxcache-jolyglot-gson" : "com.github.VictorAlbertos.Jolyglot:gson:0.0.3",
63 | "rxbinding-recyclerview-v7": "com.jakewharton.rxbinding:rxbinding-recyclerview-v7:1.0.1",
64 | "rxpermissions" : "com.tbruyelle.rxpermissions:rxpermissions:0.9.4@aar",
65 | "rxerrorhandler" : "me.jessyan:rxerrorhandler:1.0.1",
66 |
67 | //rx2
68 | "rxandroid2" : "io.reactivex.rxjava2:rxandroid:2.0.1",
69 | "rxjava2" : "io.reactivex.rxjava2:rxjava:2.1.3",
70 | "rxlifecycle2" : "com.trello.rxlifecycle2:rxlifecycle:${version["rxlifecycle2SdkVersion"]}",
71 | "rxlifecycle2-android" : "com.trello.rxlifecycle2:rxlifecycle-android:${version["rxlifecycle2SdkVersion"]}",
72 | "rxlifecycle2-components" : "com.trello.rxlifecycle2:rxlifecycle-components:${version["rxlifecycle2SdkVersion"]}",
73 | "rxcache2" : "com.github.VictorAlbertos.RxCache:runtime:1.8.1-2.x",
74 | "rxpermissions2" : "com.tbruyelle.rxpermissions2:rxpermissions:0.9.4@aar",
75 | "rxerrorhandler2" : "me.jessyan:rxerrorhandler:2.0.2",
76 |
77 | //tools
78 | "dagger2" : "com.google.dagger:dagger:${version["dagger2SdkVersion"]}",
79 | "dagger2-compiler" : "com.google.dagger:dagger-compiler:${version["dagger2SdkVersion"]}",
80 | "androideventbus" : "org.simple:androideventbus:1.0.5.1",
81 | "otto" : "com.squareup:otto:1.3.8",
82 | "gson" : "com.google.code.gson:gson:2.8.1",
83 | "multidex" : "com.android.support:multidex:1.0.1",
84 | "javax.annotation" : "javax.annotation:jsr250-api:1.0",
85 | "arouter" : "com.alibaba:arouter-api:1.2.2",
86 | "arouter-compiler" : "com.alibaba:arouter-compiler:1.1.3",
87 | "progressmanager" : "me.jessyan:progressmanager:1.3.3",
88 | "retrofit-url-manager" : "me.jessyan:retrofit-url-manager:1.0.5",
89 |
90 | //test
91 | "junit" : "junit:junit:4.12",
92 | "androidJUnitRunner" : "android.support.test.runner.AndroidJUnitRunner",
93 | "runner" : "com.android.support.test:runner:0.5",
94 | "espresso-core" : "com.android.support.test.espresso:espresso-core:${version["espressoSdkVersion"]}",
95 | "espresso-contrib" : "com.android.support.test.espresso:espresso-contrib:${version["espressoSdkVersion"]}",
96 | "espresso-intents" : "com.android.support.test.espresso:espresso-intents:${version["espressoSdkVersion"]}",
97 | "mockito-core" : "org.mockito:mockito-core:1.+",
98 | "timber" : "com.jakewharton.timber:timber:4.5.1",
99 | "logger" : "com.orhanobut:logger:2.1.1",
100 | "canary-debug" : "com.squareup.leakcanary:leakcanary-android:${version["canarySdkVersion"]}",
101 | "canary-release" : "com.squareup.leakcanary:leakcanary-android-no-op:${version["canarySdkVersion"]}",
102 | "umeng-analytics" : "com.umeng.analytics:analytics:6.0.1"
103 | ]
104 |
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jul 17 22:36:43 CST 2017
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-3.3-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 |
--------------------------------------------------------------------------------
/image/image1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/image/image1.png
--------------------------------------------------------------------------------
/image/image4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/image/image4.png
--------------------------------------------------------------------------------
/image/image5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/image/image5.png
--------------------------------------------------------------------------------
/image/image6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/image/image6.png
--------------------------------------------------------------------------------
/image/image7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lianhuo/Ganamrs/4ec1b381a4183a6dddd52872df6db0d89bd07368/image/image7.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------