Java Code Examples for com.socks.jiandan.model.Picture

The following examples show how to use com.socks.jiandan.model.Picture. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: JianDan_OkHttpWithVolley   Source File: PictureAdapter.java    License: Apache License 2.0 6 votes vote down vote up
private void loadData() {

        RequestManager.addRequest(new Request4Picture(Picture.getRequestUrl(mType, page),
                new Response.Listener<ArrayList<Picture>>
                        () {
                    @Override
                    public void onResponse(ArrayList<Picture> response) {
                        getCommentCounts(response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
                mLoadFinisCallBack.loadFinish(null);
            }
        }), mActivity);
    }
 
Example 2
Source Project: JianDan_OkHttpWithVolley   Source File: PictureCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据页码获取缓存数据
 *
 * @param page
 * @return
 */
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.PictureCache> query = mPictureCacheDao.queryBuilder().where(PictureCacheDao
			.Properties.Page.eq("" + page));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<Picture>();
	}

}
 
Example 3
Source Project: JianDan_OkHttpWithVolley   Source File: Request4Picture.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Picture>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		ArrayList<Picture> pictures = (ArrayList<Picture>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
		return Response.success(pictures, HttpHeaderParser.parseCacheHeaders(response));
	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example 4
Source Project: JianDan   Source File: PictureAdapter.java    License: Apache License 2.0 6 votes vote down vote up
private void loadData() {

        RequestManager.addRequest(new Request4Picture(Picture.getRequestUrl(mType, page),
                new Response.Listener<ArrayList<Picture>>
                        () {
                    @Override
                    public void onResponse(ArrayList<Picture> response) {
                        getCommentCounts(response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
                mLoadFinisCallBack.loadFinish(null);
            }
        }), mActivity);
    }
 
Example 5
Source Project: JianDan   Source File: PictureCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据页码获取缓存数据
 *
 * @param page
 * @return
 */
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.PictureCache> query = mPictureCacheDao.queryBuilder().where(PictureCacheDao
			.Properties.Page.eq("" + page));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<Picture>();
	}

}
 
Example 6
Source Project: JianDan   Source File: Request4Picture.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Picture>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		ArrayList<Picture> pictures = (ArrayList<Picture>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
		return Response.success(pictures, HttpHeaderParser.parseCacheHeaders(response));
	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example 7
Source Project: JianDanRxJava   Source File: PictureAdapter.java    License: Apache License 2.0 6 votes vote down vote up
private void loadCache() {
    Subscription subscription = Observable.create((Observable.OnSubscribe<ArrayList<Picture>>) subscriber -> {
        subscriber.onNext(PictureCache.getInstance(mActivity).getCacheByPage(page));
        subscriber.onCompleted();
    }).compose(JDApi.applySchedulers())
            .doOnNext(pictures -> {
                if (page == 1) {
                    mPictures.clear();
                    ToastHelper.Short(ConstantString.LOAD_NO_NETWORK);
                }
            })
            .subscribe(pictures -> {
                mPictures.addAll(pictures);
                notifyDataSetChanged();
                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);
            });
    mActivity.addSubscription(subscription);
}
 
Example 8
Source Project: JianDanRxJava   Source File: PictureAdapter.java    License: Apache License 2.0 6 votes vote down vote up
private void getCommentCounts(final List<Picture> pictures) {

        StringBuilder sb = new StringBuilder();
        for (Picture joke : pictures) {
            sb.append("comment-").append(joke.getComment_ID()).append(",");
        }

        JDApi.getCommentNumber(sb.toString())
                .doOnCompleted(() -> PictureCache.getInstance(mActivity).addResultCache(GsonHelper.toString(mPictures), page))
                .subscribe(commentNumbers -> {
                    mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                    mLoadFinisCallBack.loadFinish(null);

                    for (int i = 0; i < pictures.size(); i++) {
                        pictures.get(i).setComment_counts(commentNumbers.get(i).comments + "");
                    }

                    PictureAdapter.this.mPictures.addAll(pictures);
                    notifyDataSetChanged();
                }, e -> {
                    ToastHelper.Short(ConstantString.LOAD_FAILED);
                    mLoadFinisCallBack.loadFinish(null);
                    mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET);
                });
    }
 
Example 9
Source Project: JianDanRxJava   Source File: PictureCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据页码获取缓存数据
 *
 * @param page
 * @return
 */
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.PictureCache> query = mPictureCacheDao.queryBuilder().where(PictureCacheDao
			.Properties.Page.eq("" + page));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<>();
	}

}
 
Example 10
Source Project: JianDanRxJava   Source File: PictureParser.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public ArrayList<Picture> parse(Response response) {

    if (!response.isSuccessful())
        return null;

    try {
        String jsonStr = response.body().string();
        jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

        Type type = new TypeToken<ArrayList<Picture>>() {
        }.getType();

        return new GsonHelper<ArrayList<Picture>>().fromJson(jsonStr, type);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 11
Source Project: JianDan_OkHttp   Source File: PictureParser.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public ArrayList<Picture> parse(Response response) {

    code = wrapperCode(response.code());
    if (!response.isSuccessful())
        return null;

    try {
        String jsonStr = response.body().string();
        jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();
        return (ArrayList<Picture>) JSONParser.toObject(jsonStr,
                new TypeToken<ArrayList<Picture>>() {
                }.getType());
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 12
Source Project: JianDan_OkHttp   Source File: PictureCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据页码获取缓存数据
 *
 * @param page
 * @return
 */
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.PictureCache> query = mPictureCacheDao.queryBuilder().where(PictureCacheDao
			.Properties.Page.eq("" + page));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<Picture>();
	}

}
 
Example 13
Source Project: JianDan_OkHttp   Source File: Request4Picture.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Picture>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		ArrayList<Picture> pictures = (ArrayList<Picture>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
		return Response.success(pictures, HttpHeaderParser.parseCacheHeaders(response));
	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example 14
Source Project: JianDan_OkHttpWithVolley   Source File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public PictureAdapter(Activity activity, LoadResultCallBack loadResultCallBack, LoadFinishCallBack loadFinisCallBack, Picture.PictureType type) {
    mActivity = activity;
    mType = type;
    mLoadFinisCallBack = loadFinisCallBack;
    mLoadResultCallBack = loadResultCallBack;
    pictures = new ArrayList<>();
    isWifiConnected = NetWorkUtil.isWifiConnected(mActivity);
}
 
Example 15
Source Project: JianDan_OkHttpWithVolley   Source File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void getCommentCounts(final ArrayList<Picture> pictures) {

        StringBuilder sb = new StringBuilder();
        for (Picture joke : pictures) {
            sb.append("comment-" + joke.getComment_ID() + ",");
        }

        RequestManager.addRequest(new Request4CommentCounts(CommentNumber.getCommentCountsURL(sb.toString()), new Response
                .Listener<ArrayList<CommentNumber>>() {

            @Override
            public void onResponse(ArrayList<CommentNumber> response) {

                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);

                for (int i = 0; i < pictures.size(); i++) {
                    pictures.get(i).setComment_counts(response.get(i).getComments() + "");
                }
                if (page == 1) {
                    PictureAdapter.this.pictures.clear();
                    PictureCache.getInstance(mActivity).clearAllCache();
                }
                PictureAdapter.this.pictures.addAll(pictures);
                notifyDataSetChanged();
                //加载完毕后缓存
                PictureCache.getInstance(mActivity).addResultCache(JSONParser.toString
                        (pictures), page);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                ShowToast.Short(ConstantString.LOAD_FAILED);
                mLoadFinisCallBack.loadFinish(null);
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
            }
        }
        ), mActivity);
    }
 
Example 16
Source Project: JianDan_OkHttpWithVolley   Source File: PictureFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    isFirstChange = true;
    mType = Picture.PictureType.BoringPicture;
}
 
Example 17
Source Project: JianDan_OkHttpWithVolley   Source File: SisterCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.SisterCache> query = mPictureCacheDao.queryBuilder().where(SisterCacheDao
			.Properties.Page.eq(Integer.toString(page)));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<>();
	}

}
 
Example 18
Source Project: JianDan   Source File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public PictureAdapter(Activity activity, LoadResultCallBack loadResultCallBack, LoadFinishCallBack loadFinisCallBack, Picture.PictureType type) {
    mActivity = activity;
    mType = type;
    mLoadFinisCallBack = loadFinisCallBack;
    mLoadResultCallBack = loadResultCallBack;
    pictures = new ArrayList<>();
    isWifiConnected = NetWorkUtil.isWifiConnected(mActivity);
}
 
Example 19
Source Project: JianDan   Source File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void getCommentCounts(final ArrayList<Picture> pictures) {

        StringBuilder sb = new StringBuilder();
        for (Picture joke : pictures) {
            sb.append("comment-" + joke.getComment_ID() + ",");
        }

        RequestManager.addRequest(new Request4CommentCounts(CommentNumber.getCommentCountsURL(sb.toString()), new Response
                .Listener<ArrayList<CommentNumber>>() {

            @Override
            public void onResponse(ArrayList<CommentNumber> response) {

                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);

                for (int i = 0; i < pictures.size(); i++) {
                    pictures.get(i).setComment_counts(response.get(i).getComments() + "");
                }
                if (page == 1) {
                    PictureAdapter.this.pictures.clear();
                    PictureCache.getInstance(mActivity).clearAllCache();
                }
                PictureAdapter.this.pictures.addAll(pictures);
                notifyDataSetChanged();
                //加载完毕后缓存
                PictureCache.getInstance(mActivity).addResultCache(JSONParser.toString
                        (pictures), page);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                ShowToast.Short(ConstantString.LOAD_FAILED);
                mLoadFinisCallBack.loadFinish(null);
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
            }
        }
        ), mActivity);
    }
 
Example 20
Source Project: JianDan   Source File: PictureFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    isFirstChange = true;
    mType = Picture.PictureType.BoringPicture;
}
 
Example 21
Source Project: JianDan   Source File: SisterCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.SisterCache> query = mPictureCacheDao.queryBuilder().where(SisterCacheDao
			.Properties.Page.eq(Integer.toString(page)));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<>();
	}

}
 
Example 22
Source Project: JianDanRxJava   Source File: IntentHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static void toImageDetailActivity(Context context, Picture picture){
    Intent intent = new Intent(context, ImageDetailActivity.class);

    intent.putExtra(BaseActivity.DATA_IMAGE_AUTHOR, picture.getComment_author());
    intent.putExtra(BaseActivity.DATA_IMAGE_URL, picture.getPics());
    intent.putExtra(BaseActivity.DATA_IMAGE_ID, picture.getComment_ID());
    intent.putExtra(BaseActivity.DATA_THREAD_KEY, "comment-" + picture.getComment_ID());

    if (picture.getPics()[0].endsWith(".gif")) {
        intent.putExtra(BaseActivity.DATA_IS_NEED_WEB_VIEW, true);
    }

    context.startActivity(intent);
}
 
Example 23
Source Project: JianDanRxJava   Source File: SisterCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.SisterCache> query = mPictureCacheDao.queryBuilder().where(SisterCacheDao
			.Properties.Page.eq(Integer.toString(page)));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<>();
	}

}
 
Example 24
Source Project: JianDanRxJava   Source File: JDApi.java    License: Apache License 2.0 5 votes vote down vote up
public static Observable<ArrayList<Picture>> getPictures(int type, int page) {

        return Observable.create(new Observable.OnSubscribe<ArrayList<Picture>>() {
            @Override
            public void call(Subscriber<? super ArrayList<Picture>> subscriber) {
                String url = Picture.getRequestUrl(type, page);
                try {
                    subscriber.onNext(new PictureParser().parse(OkHttpProxy.get().url(url).execute()));
                    subscriber.onCompleted();
                } catch (IOException e) {
                    subscriber.onError(e);
                }
            }
        }).compose(applySchedulers());
    }
 
Example 25
Source Project: JianDan_OkHttp   Source File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public PictureAdapter(Activity activity, LoadResultCallBack loadResultCallBack, LoadFinishCallBack loadFinisCallBack, Picture.PictureType type) {
    mActivity = activity;
    mType = type;
    mLoadFinisCallBack = loadFinisCallBack;
    mLoadResultCallBack = loadResultCallBack;
    pictures = new ArrayList<>();
    isWifiConnected = NetWorkUtil.isWifiConnected(mActivity);
}
 
Example 26
Source Project: JianDan_OkHttp   Source File: PictureFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    isFirstChange = true;
    mType = Picture.PictureType.BoringPicture;
}
 
Example 27
Source Project: JianDan_OkHttp   Source File: SisterCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.SisterCache> query = mPictureCacheDao.queryBuilder().where(SisterCacheDao
			.Properties.Page.eq(Integer.toString(page)));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<>();
	}

}
 
Example 28
Source Project: JianDan_OkHttpWithVolley   Source File: SisterFragment.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    mType = Picture.PictureType.Sister;
}
 
Example 29
Source Project: JianDan_OkHttpWithVolley   Source File: PictureFragment.java    License: Apache License 2.0 4 votes vote down vote up
public void setType(Picture.PictureType mType) {
    this.mType = mType;
}
 
Example 30
Source Project: JianDan_OkHttpWithVolley   Source File: Request4Picture.java    License: Apache License 2.0 4 votes vote down vote up
public Request4Picture(String url, Response.Listener<ArrayList<Picture>> listener,
                       Response.ErrorListener errorListener) {
	super(Method.GET, url, errorListener);
	this.listener = listener;
}