com.socks.jiandan.model.Picture Java Examples

The following examples show how to use com.socks.jiandan.model.Picture. 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 File: PictureAdapter.java    From JianDan_OkHttpWithVolley with 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 File: Request4Picture.java    From JianDan_OkHttp with 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 #3
Source File: PictureCache.java    From JianDan_OkHttp with 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 #4
Source File: PictureParser.java    From JianDan_OkHttp with 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 #5
Source File: PictureParser.java    From JianDanRxJava with 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 #6
Source File: PictureCache.java    From JianDanRxJava with 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 #7
Source File: PictureAdapter.java    From JianDanRxJava with 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 #8
Source File: PictureAdapter.java    From JianDanRxJava with 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 #9
Source File: Request4Picture.java    From JianDan with 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 #10
Source File: PictureCache.java    From JianDan with 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 #11
Source File: PictureAdapter.java    From JianDan with 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 #12
Source File: PictureCache.java    From JianDan_OkHttpWithVolley with 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 File: Request4Picture.java    From JianDan_OkHttpWithVolley with 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 File: PictureAdapter.java    From JianDan_OkHttpWithVolley with 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 #15
Source File: SisterCache.java    From JianDanRxJava with 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 #16
Source File: PictureAdapter.java    From JianDan with 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 #17
Source File: SisterCache.java    From JianDan_OkHttpWithVolley with 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 File: PictureFragment.java    From JianDan_OkHttp with 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 #19
Source File: IntentHelper.java    From JianDanRxJava with 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 #20
Source File: PictureFragment.java    From JianDan_OkHttpWithVolley with 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 File: SisterCache.java    From JianDan_OkHttp with 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 File: SisterCache.java    From JianDan with 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 #23
Source File: JDApi.java    From JianDanRxJava with 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 #24
Source File: PictureFragment.java    From JianDan with 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 #25
Source File: PictureAdapter.java    From JianDan_OkHttpWithVolley with 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 File: PictureAdapter.java    From JianDan with 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 #27
Source File: PictureAdapter.java    From JianDan_OkHttp with 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 #28
Source File: PictureFragment.java    From JianDan_OkHttp with Apache License 2.0 4 votes vote down vote up
public void setType(Picture.PictureType mType) {
    this.mType = mType;
}
 
Example #29
Source File: SisterFragment.java    From JianDan_OkHttp with 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 #30
Source File: SisterFragment.java    From JianDanRxJava with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    mType = Picture.Sister;
}