use of org.mazhuang.guanggoo.data.OnResponseListener in project guanggoo-android by mzlogin.
the class TopicDetailPresenter method favorite.
@Override
public void favorite() {
String topicId = UrlUtil.getTid(getUrl());
String favouriteUrl = ConstantUtil.FAVORITE_URL + "?topic_id=" + topicId;
NetworkTaskScheduler.getInstance().execute(new FavouriteTask(favouriteUrl, new OnResponseListener<String>() {
@Override
public void onSucceed(String data) {
mView.onFavoriteSucceed();
}
@Override
public void onFailed(String msg) {
mView.onFavoriteFail(msg);
}
}));
}
use of org.mazhuang.guanggoo.data.OnResponseListener in project guanggoo-android by mzlogin.
the class TopicDetailPresenter method unfavorite.
@Override
public void unfavorite() {
String topicId = UrlUtil.getTid(getUrl());
String favouriteUrl = ConstantUtil.UN_FAVORITE_URL + "?topic_id=" + topicId;
NetworkTaskScheduler.getInstance().execute(new FavouriteTask(favouriteUrl, new OnResponseListener<String>() {
@Override
public void onSucceed(String data) {
mView.onUnfavoriteSucceed();
}
@Override
public void onFailed(String msg) {
mView.onUnfavoriteFailed(msg);
}
}));
}
use of org.mazhuang.guanggoo.data.OnResponseListener in project guanggoo-android by mzlogin.
the class TopicDetailPresenter method comment.
@Override
public void comment(String content) {
mView.startLoading();
content = EmojiParser.parseToAliases(content);
NetworkTaskScheduler.getInstance().execute(new CommentTask(getUrl(), content, new OnResponseListener<String>() {
@Override
public void onSucceed(String data) {
mView.stopLoading();
mView.onCommentSucceed();
}
@Override
public void onFailed(String msg) {
mView.stopLoading();
mView.onCommentFailed(msg);
}
}));
}
use of org.mazhuang.guanggoo.data.OnResponseListener in project guanggoo-android by mzlogin.
the class LoginTask method run.
@Override
public void run() {
String xsrf = UUID.randomUUID().toString().replaceAll("-", "");
Map<String, String> headers = new HashMap<>();
headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
headers.put("Content-Type", "application/x-www-form-urlencoded");
headers.put(ConstantUtil.KEY_COOKIE, "_xsrf=" + xsrf);
Map<String, String> datas = new HashMap<>();
datas.put("email", mEmail);
datas.put("password", mPassword);
datas.put(ConstantUtil.KEY_XSRF, xsrf);
try {
Connection.Response res = Jsoup.connect(ConstantUtil.LOGIN_URL).data(datas).headers(headers).method(Connection.Method.POST).execute();
Map<String, String> cookies = res.cookies();
if (cookies != null) {
if (cookies.containsKey("user")) {
JSONObject jsonObject = new JSONObject();
for (String key : cookies.keySet()) {
jsonObject.put(key, cookies.get(key));
}
PrefsUtil.putString(App.getInstance(), ConstantUtil.KEY_COOKIE, jsonObject.toString());
PrefsUtil.putString(App.getInstance(), ConstantUtil.KEY_XSRF, xsrf);
NetworkTaskScheduler.getInstance().execute(new AuthCheckTask(new OnResponseListener<String>() {
@Override
public void onSucceed(String data) {
successOnUI("");
}
@Override
public void onFailed(String msg) {
failedOnUI(msg);
}
}));
return;
}
}
} catch (IOException | JSONException e) {
e.printStackTrace();
}
failedOnUI("登录失败");
}
use of org.mazhuang.guanggoo.data.OnResponseListener in project guanggoo-android by mzlogin.
the class TopicListPresenter method getMoreTopic.
@Override
public void getMoreTopic(int page) {
if (mCurrentTask != null) {
mCurrentTask.cancel();
}
mCurrentTask = new GetTopicListTask(UrlUtil.appendPage(mView.getUrl(), page), new OnResponseListener<TopicList>() {
@Override
public void onSucceed(TopicList data) {
mView.onGetMoreTopicSucceed(data);
mCurrentTask = null;
}
@Override
public void onFailed(String msg) {
mView.onGetMoreTopicFailed(msg);
mCurrentTask = null;
}
});
NetworkTaskScheduler.getInstance().execute(mCurrentTask);
}
Aggregations