147 | *
The default implementation returns the given position. 148 | * Subclasses should override this method if the positions of items can change.
149 | * 150 | * @param position Position within this adapter 151 | * @return Unique identifier for the item at position 152 | */ 153 | public long getItemId(int position) { 154 | return position; 155 | } 156 | 157 | private static String makeFragmentName(int viewId, long id) { 158 | return "android:switcher:" + viewId + ":" + id; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /app/src/main/java/com/jiang/android/rxjavaapp/adapter/fragmentadapter/PagerAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * created by jiang, 16/2/28 3 | * Copyright (c) 2016, jyuesong@gmail.com All Rights Reserved. 4 | * * # # 5 | * # _oo0oo_ # 6 | * # o8888888o # 7 | * # 88" . "88 # 8 | * # (| -_- |) # 9 | * # 0\ = /0 # 10 | * # ___/`---'\___ # 11 | * # .' \\| |# '. # 12 | * # / \\||| : |||# \ # 13 | * # / _||||| -:- |||||- \ # 14 | * # | | \\\ - #/ | | # 15 | * # | \_| ''\---/'' |_/ | # 16 | * # \ .-\__ '-' ___/-. / # 17 | * # ___'. .' /--.--\ `. .'___ # 18 | * # ."" '< `.___\_<|>_/___.' >' "". # 19 | * # | | : `- \`.;`\ _ /`;.`/ - ` : | | # 20 | * # \ \ `_. \_ __\ /__ _/ .-` / / # 21 | * # =====`-.____`.___ \_____/___.-`___.-'===== # 22 | * # `=---=' # 23 | * # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # 24 | * # # 25 | * # 佛祖保佑 永无BUG # 26 | * # # 27 | */ 28 | 29 | package com.jiang.android.rxjavaapp.adapter.fragmentadapter; 30 | 31 | import android.database.DataSetObservable; 32 | import android.database.DataSetObserver; 33 | import android.os.Parcelable; 34 | import android.view.View; 35 | import android.view.ViewGroup; 36 | 37 | /** 38 | * Created by jiang on 16/2/28. 39 | */ 40 | public abstract class PagerAdapter { 41 | 42 | 43 | private DataSetObservable mObservable = new DataSetObservable(); 44 | 45 | public static final int POSITION_UNCHANGED = -1; 46 | public static final int POSITION_NONE = -2; 47 | 48 | /** 49 | * Return the number of views available. 50 | */ 51 | public abstract int getCount(); 52 | 53 | /** 54 | * Called when a change in the shown pages is going to start being made. 55 | * 56 | * @param container The containing View which is displaying this adapter's 57 | * page views. 58 | */ 59 | public void startUpdate(ViewGroup container) { 60 | startUpdate((View) container); 61 | } 62 | 63 | /** 64 | * Create the page for the given position. The adapter is responsible 65 | * for adding the view to the container given here, although it only 66 | * must ensure this is done by the time it returns from 67 | * {@link #finishUpdate(ViewGroup)}. 68 | * 69 | * @param container The containing View in which the page will be shown. 70 | * @param position The page position to be instantiated. 71 | * @return Returns an Object representing the new page. This does not 72 | * need to be a View, but can be some other container of the page. 73 | */ 74 | public Object instantiateItem(ViewGroup container, int position) { 75 | return instantiateItem((View) container, position); 76 | } 77 | 78 | /** 79 | * Remove a page for the given position. The adapter is responsible 80 | * for removing the view from its container, although it only must ensure 81 | * this is done by the time it returns from {@link #finishUpdate(ViewGroup)}. 82 | * 83 | * @param container The containing View from which the page will be removed. 84 | * @param position The page position to be removed. 85 | * @param object The same object that was returned by 86 | * {@link #instantiateItem(View, int)}. 87 | */ 88 | public void destroyItem(ViewGroup container, int position, Object object) { 89 | destroyItem((View) container, position, object); 90 | } 91 | 92 | /** 93 | * Called to inform the adapter of which item is currently considered to 94 | * be the "primary", that is the one show to the user as the current page. 95 | * 96 | * @param container The containing View from which the page will be removed. 97 | * @param position The page position that is now the primary. 98 | * @param object The same object that was returned by 99 | * {@link #instantiateItem(View, int)}. 100 | */ 101 | public void setPrimaryItem(ViewGroup container, int position, Object object) { 102 | setPrimaryItem((View) container, position, object); 103 | } 104 | 105 | /** 106 | * Called when the a change in the shown pages has been completed. At this 107 | * point you must ensure that all of the pages have actually been added or 108 | * removed from the container as appropriate. 109 | * 110 | * @param container The containing View which is displaying this adapter's 111 | * page views. 112 | */ 113 | public void finishUpdate(ViewGroup container) { 114 | finishUpdate((View) container); 115 | } 116 | 117 | /** 118 | * Called when a change in the shown pages is going to start being made. 119 | * 120 | * @param container The containing View which is displaying this adapter's 121 | * page views. 122 | * @deprecated Use {@link #startUpdate(ViewGroup)} 123 | */ 124 | public void startUpdate(View container) { 125 | } 126 | 127 | /** 128 | * Create the page for the given position. The adapter is responsible 129 | * for adding the view to the container given here, although it only 130 | * must ensure this is done by the time it returns from 131 | * {@link #finishUpdate(ViewGroup)}. 132 | * 133 | * @param container The containing View in which the page will be shown. 134 | * @param position The page position to be instantiated. 135 | * @return Returns an Object representing the new page. This does not 136 | * need to be a View, but can be some other container of the page. 137 | * @deprecated Use {@link #instantiateItem(ViewGroup, int)} 138 | */ 139 | public Object instantiateItem(View container, int position) { 140 | throw new UnsupportedOperationException( 141 | "Required method instantiateItem was not overridden"); 142 | } 143 | 144 | /** 145 | * Remove a page for the given position. The adapter is responsible 146 | * for removing the view from its container, although it only must ensure 147 | * this is done by the time it returns from {@link #finishUpdate(View)}. 148 | * 149 | * @param container The containing View from which the page will be removed. 150 | * @param position The page position to be removed. 151 | * @param object The same object that was returned by 152 | * {@link #instantiateItem(View, int)}. 153 | * @deprecated Use {@link #destroyItem(ViewGroup, int, Object)} 154 | */ 155 | public void destroyItem(View container, int position, Object object) { 156 | throw new UnsupportedOperationException("Required method destroyItem was not overridden"); 157 | } 158 | 159 | /** 160 | * Called to inform the adapter of which item is currently considered to 161 | * be the "primary", that is the one show to the user as the current page. 162 | * 163 | * @param container The containing View from which the page will be removed. 164 | * @param position The page position that is now the primary. 165 | * @param object The same object that was returned by 166 | * {@link #instantiateItem(View, int)}. 167 | * @deprecated Use {@link #setPrimaryItem(ViewGroup, int, Object)} 168 | */ 169 | public void setPrimaryItem(View container, int position, Object object) { 170 | } 171 | 172 | /** 173 | * Called when the a change in the shown pages has been completed. At this 174 | * point you must ensure that all of the pages have actually been added or 175 | * removed from the container as appropriate. 176 | * 177 | * @param container The containing View which is displaying this adapter's 178 | * page views. 179 | * @deprecated Use {@link #finishUpdate(ViewGroup)} 180 | */ 181 | public void finishUpdate(View container) { 182 | } 183 | 184 | /** 185 | * Determines whether a page View is associated with a specific key object 186 | * as returned by {@link #instantiateItem(ViewGroup, int)}. This method is 187 | * required for a PagerAdapter to function properly. 188 | * 189 | * @param view Page View to check for association withobject
190 | * @param object Object to check for association with view
191 | * @return true if view
is associated with the key object object
192 | */
193 | public abstract boolean isViewFromObject(View view, Object object);
194 |
195 | /**
196 | * Save any instance state associated with this adapter and its pages that should be
197 | * restored if the current UI state needs to be reconstructed.
198 | *
199 | * @return Saved state for this adapter
200 | */
201 | public Parcelable saveState() {
202 | return null;
203 | }
204 |
205 | /**
206 | * Restore any instance state associated with this adapter and its pages
207 | * that was previously saved by {@link #saveState()}.
208 | *
209 | * @param state State previously saved by a call to {@link #saveState()}
210 | * @param loader A ClassLoader that should be used to instantiate any restored objects
211 | */
212 | public void restoreState(Parcelable state, ClassLoader loader) {
213 | }
214 |
215 | /**
216 | * Called when the host view is attempting to determine if an item's position
217 | * has changed. Returns {@link #POSITION_UNCHANGED} if the position of the given
218 | * item has not changed or {@link #POSITION_NONE} if the item is no longer present
219 | * in the adapter.
220 | * 221 | *
The default implementation assumes that items will never
222 | * change position and always returns {@link #POSITION_UNCHANGED}.
223 | *
224 | * @param object Object representing an item, previously returned by a call to
225 | * {@link #instantiateItem(View, int)}.
226 | * @return object's new position index from [0, {@link #getCount()}),
227 | * {@link #POSITION_UNCHANGED} if the object's position has not changed,
228 | * or {@link #POSITION_NONE} if the item is no longer present.
229 | */
230 | public int getItemPosition(Object object) {
231 | return POSITION_UNCHANGED;
232 | }
233 |
234 | /**
235 | * This method should be called by the application if the data backing this adapter has changed
236 | * and associated views should update.
237 | */
238 | public void notifyDataSetChanged() {
239 | mObservable.notifyChanged();
240 | }
241 |
242 | /**
243 | * Register an observer to receive callbacks related to the adapter's data changing.
244 | *
245 | * @param observer The {@link DataSetObserver} which will receive callbacks.
246 | */
247 | public void registerDataSetObserver(DataSetObserver observer) {
248 | mObservable.registerObserver(observer);
249 | }
250 |
251 | /**
252 | * Unregister an observer from callbacks related to the adapter's data changing.
253 | *
254 | * @param observer The {@link DataSetObserver} which will be unregistered.
255 | */
256 | public void unregisterDataSetObserver(DataSetObserver observer) {
257 | mObservable.unregisterObserver(observer);
258 | }
259 |
260 | /**
261 | * This method may be called by the ViewPager to obtain a title string
262 | * to describe the specified page. This method may return null
263 | * indicating no title for this page. The default implementation returns
264 | * null.
265 | *
266 | * @param position The position of the title requested
267 | * @return A title for the requested page
268 | */
269 | public CharSequence getPageTitle(int position) {
270 | return null;
271 | }
272 |
273 | /**
274 | * Returns the proportional width of a given page as a percentage of the
275 | * ViewPager's measured width from (0.f-1.f]
276 | *
277 | * @param position The position of the page requested
278 | * @return Proportional width for the given page position
279 | */
280 | public float getPageWidth(int position) {
281 | return 1.f;
282 | }
283 | }
284 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jiang/android/rxjavaapp/adapter/holder/BaseViewHolder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * created by jiang, 12/3/15
3 | * Copyright (c) 2015, jyuesong@gmail.com All Rights Reserved.
4 | * * # #
5 | * # _oo0oo_ #
6 | * # o8888888o #
7 | * # 88" . "88 #
8 | * # (| -_- |) #
9 | * # 0\ = /0 #
10 | * # ___/`---'\___ #
11 | * # .' \\| |# '. #
12 | * # / \\||| : |||# \ #
13 | * # / _||||| -:- |||||- \ #
14 | * # | | \\\ - #/ | | #
15 | * # | \_| ''\---/'' |_/ | #
16 | * # \ .-\__ '-' ___/-. / #
17 | * # ___'. .' /--.--\ `. .'___ #
18 | * # ."" '< `.___\_<|>_/___.' >' "". #
19 | * # | | : `- \`.;`\ _ /`;.`/ - ` : | | #
20 | * # \ \ `_. \_ __\ /__ _/ .-` / / #
21 | * # =====`-.____`.___ \_____/___.-`___.-'===== #
22 | * # `=---=' #
23 | * # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
24 | * # #
25 | * # 佛祖保佑 永无BUG #
26 | * # #
27 | */
28 |
29 | package com.jiang.android.rxjavaapp.adapter.holder;
30 |
31 | import android.support.annotation.IdRes;
32 | import android.support.v7.widget.RecyclerView;
33 | import android.util.SparseArray;
34 | import android.view.View;
35 |
36 | /**
37 | * Created by jiang on 12/3/15.
38 | */
39 | public class BaseViewHolder extends RecyclerView.ViewHolder {
40 |
41 | protected final SparseArray
28 | * Can be used for QueryBuilder and for referencing column names.
29 | */
30 | public static class Properties {
31 | public final static Property Id = new Property(0, Long.class, "id", true, "_id");
32 | public final static Property Name = new Property(1, String.class, "name", false, "NAME");
33 | public final static Property Thread = new Property(2, String.class, "thread", false, "THREAD");
34 | public final static Property Desc = new Property(3, String.class, "desc", false, "DESC");
35 | public final static Property Img = new Property(4, String.class, "img", false, "IMG");
36 | public final static Property Url = new Property(5, String.class, "url", false, "URL");
37 | public final static Property Operators_id = new Property(6, Long.class, "operators_id", false, "OPERATORS_ID");
38 | public final static Property Outer_id = new Property(7, Long.class, "outer_id", false, "OUTER_ID");
39 | };
40 |
41 | private DaoSession daoSession;
42 |
43 | private Query
26 | * Can be used for QueryBuilder and for referencing column names.
27 | */
28 | public static class Properties {
29 | public final static Property Id = new Property(0, Long.class, "id", true, "_id");
30 | public final static Property Name = new Property(1, String.class, "name", false, "NAME");
31 | public final static Property Outer_id = new Property(2, Long.class, "outer_id", false, "OUTER_ID");
32 | };
33 |
34 | private DaoSession daoSession;
35 |
36 |
37 | public operatorsDao(DaoConfig config) {
38 | super(config);
39 | }
40 |
41 | public operatorsDao(DaoConfig config, DaoSession daoSession) {
42 | super(config, daoSession);
43 | this.daoSession = daoSession;
44 | }
45 |
46 | /** Creates the underlying database table. */
47 | public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
48 | String constraint = ifNotExists? "IF NOT EXISTS ": "";
49 | db.execSQL("CREATE TABLE " + constraint + "\"OPERATORS\" (" + //
50 | "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
51 | "\"NAME\" TEXT," + // 1: name
52 | "\"OUTER_ID\" INTEGER);"); // 2: outer_id
53 | }
54 |
55 | /** Drops the underlying database table. */
56 | public static void dropTable(SQLiteDatabase db, boolean ifExists) {
57 | String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"OPERATORS\"";
58 | db.execSQL(sql);
59 | }
60 |
61 | /** @inheritdoc */
62 | @Override
63 | protected void bindValues(SQLiteStatement stmt, operators entity) {
64 | stmt.clearBindings();
65 |
66 | Long id = entity.getId();
67 | if (id != null) {
68 | stmt.bindLong(1, id);
69 | }
70 |
71 | String name = entity.getName();
72 | if (name != null) {
73 | stmt.bindString(2, name);
74 | }
75 |
76 | Long outer_id = entity.getOuter_id();
77 | if (outer_id != null) {
78 | stmt.bindLong(3, outer_id);
79 | }
80 | }
81 |
82 | @Override
83 | protected void attachEntity(operators entity) {
84 | super.attachEntity(entity);
85 | entity.__setDaoSession(daoSession);
86 | }
87 |
88 | /** @inheritdoc */
89 | @Override
90 | public Long readKey(Cursor cursor, int offset) {
91 | return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
92 | }
93 |
94 | /** @inheritdoc */
95 | @Override
96 | public operators readEntity(Cursor cursor, int offset) {
97 | operators entity = new operators( //
98 | cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
99 | cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
100 | cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2) // outer_id
101 | );
102 | return entity;
103 | }
104 |
105 | /** @inheritdoc */
106 | @Override
107 | public void readEntity(Cursor cursor, operators entity, int offset) {
108 | entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
109 | entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
110 | entity.setOuter_id(cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2));
111 | }
112 |
113 | /** @inheritdoc */
114 | @Override
115 | protected Long updateKeyAfterInsert(operators entity, long rowId) {
116 | entity.setId(rowId);
117 | return rowId;
118 | }
119 |
120 | /** @inheritdoc */
121 | @Override
122 | public Long getKey(operators entity) {
123 | if(entity != null) {
124 | return entity.getId();
125 | } else {
126 | return null;
127 | }
128 | }
129 |
130 | /** @inheritdoc */
131 | @Override
132 | protected boolean isEntityUpdateable() {
133 | return true;
134 | }
135 |
136 | private String selectDeep;
137 |
138 | protected String getSelectDeep() {
139 | if (selectDeep == null) {
140 | StringBuilder builder = new StringBuilder("SELECT ");
141 | SqlUtils.appendColumns(builder, "T", getAllColumns());
142 | builder.append(',');
143 | SqlUtils.appendColumns(builder, "T0", daoSession.getAlloperatorsDao().getAllColumns());
144 | builder.append(" FROM OPERATORS T");
145 | builder.append(" LEFT JOIN ALLOPERATORS T0 ON T.\"OUTER_ID\"=T0.\"_id\"");
146 | builder.append(' ');
147 | selectDeep = builder.toString();
148 | }
149 | return selectDeep;
150 | }
151 |
152 | protected operators loadCurrentDeep(Cursor cursor, boolean lock) {
153 | operators entity = loadCurrent(cursor, 0, lock);
154 | int offset = getAllColumns().length;
155 |
156 | alloperators alloperators = loadCurrentOther(daoSession.getAlloperatorsDao(), cursor, offset);
157 | entity.setAlloperators(alloperators);
158 |
159 | return entity;
160 | }
161 |
162 | public operators loadDeep(Long key) {
163 | assertSinglePk();
164 | if (key == null) {
165 | return null;
166 | }
167 |
168 | StringBuilder builder = new StringBuilder(getSelectDeep());
169 | builder.append("WHERE ");
170 | SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
171 | String sql = builder.toString();
172 |
173 | String[] keyArray = new String[] { key.toString() };
174 | Cursor cursor = db.rawQuery(sql, keyArray);
175 |
176 | try {
177 | boolean available = cursor.moveToFirst();
178 | if (!available) {
179 | return null;
180 | } else if (!cursor.isLast()) {
181 | throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
182 | }
183 | return loadCurrentDeep(cursor, true);
184 | } finally {
185 | cursor.close();
186 | }
187 | }
188 |
189 | /** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */
190 | public List