Search in sources :

Example 1 with OnResponseListener

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);
        }
    }));
}
Also used : OnResponseListener(org.mazhuang.guanggoo.data.OnResponseListener) FavouriteTask(org.mazhuang.guanggoo.data.task.FavouriteTask)

Example 2 with OnResponseListener

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);
        }
    }));
}
Also used : OnResponseListener(org.mazhuang.guanggoo.data.OnResponseListener) FavouriteTask(org.mazhuang.guanggoo.data.task.FavouriteTask)

Example 3 with OnResponseListener

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);
        }
    }));
}
Also used : OnResponseListener(org.mazhuang.guanggoo.data.OnResponseListener) CommentTask(org.mazhuang.guanggoo.data.task.CommentTask)

Example 4 with OnResponseListener

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("登录失败");
}
Also used : JSONObject(org.json.JSONObject) OnResponseListener(org.mazhuang.guanggoo.data.OnResponseListener) HashMap(java.util.HashMap) Connection(org.jsoup.Connection) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 5 with OnResponseListener

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);
}
Also used : GetTopicListTask(org.mazhuang.guanggoo.data.task.GetTopicListTask) OnResponseListener(org.mazhuang.guanggoo.data.OnResponseListener) TopicList(org.mazhuang.guanggoo.data.entity.TopicList)

Aggregations

OnResponseListener (org.mazhuang.guanggoo.data.OnResponseListener)12 TopicList (org.mazhuang.guanggoo.data.entity.TopicList)2 FavouriteTask (org.mazhuang.guanggoo.data.task.FavouriteTask)2 GetTopicListTask (org.mazhuang.guanggoo.data.task.GetTopicListTask)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 Connection (org.jsoup.Connection)1 NodeCategory (org.mazhuang.guanggoo.data.entity.NodeCategory)1 TopicDetail (org.mazhuang.guanggoo.data.entity.TopicDetail)1 UserProfile (org.mazhuang.guanggoo.data.entity.UserProfile)1 AuthCheckTask (org.mazhuang.guanggoo.data.task.AuthCheckTask)1 CommentTask (org.mazhuang.guanggoo.data.task.CommentTask)1 GetNodesCloudTask (org.mazhuang.guanggoo.data.task.GetNodesCloudTask)1 GetTopicDetailTask (org.mazhuang.guanggoo.data.task.GetTopicDetailTask)1 GetUserProfileTask (org.mazhuang.guanggoo.data.task.GetUserProfileTask)1 LoginTask (org.mazhuang.guanggoo.data.task.LoginTask)1 NewTopicTask (org.mazhuang.guanggoo.data.task.NewTopicTask)1