Search in sources :

Example 16 with ResponseHandler

use of me.yluo.ruisiapp.myhttp.ResponseHandler in project Ruisi by freedom10086.

the class EditActivity method startPost.

private void startPost() {
    String url = "forum.php?mod=post&action=edit&extra=&editsubmit=yes&mobile=2&handlekey=postform&inajax=1";
    params.put("editsubmit", "yes");
    if (typeId > 0) {
        params.put("typeid", String.valueOf(typeId));
    }
    params.put("subject", edTitle.getText().toString());
    params.put("message", edContent.getText().toString());
    HttpUtil.post(url, params, new ResponseHandler() {

        @Override
        public void onSuccess(byte[] response) {
            String res = new String(response);
            Log.e("resoult", res);
            if (res.contains("帖子编辑成功")) {
                dialog.dismiss();
                showToast("帖子编辑成功");
                Intent i = new Intent();
                if (edTitle.getVisibility() == View.VISIBLE) {
                    i.putExtra("TITLE", edTitle.getText().toString());
                }
                i.putExtra("CONTENT", edContent.getText().toString());
                i.putExtra("PID", pid);
                setResult(RESULT_OK, i);
                EditActivity.this.finish();
            } else if (res.contains("class=\"jump_c\"")) {
                int start = res.indexOf("<p>", res.indexOf("class=\"jump_c\"")) + 3;
                int end = res.indexOf("</p>", start);
                String reason = res.substring(start, end);
                postFail(reason);
            } else {
                postFail("编辑失败:我也不知道哪儿错了");
            }
        }

        @Override
        public void onFailure(Throwable e) {
            super.onFailure(e);
            dialog.dismiss();
            showToast("网络错误");
        }
    });
}
Also used : ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) Intent(android.content.Intent)

Example 17 with ResponseHandler

use of me.yluo.ruisiapp.myhttp.ResponseHandler in project Ruisi by freedom10086.

the class FriendActivity method OnAddFriendOkClick.

@Override
public void OnAddFriendOkClick(String mes, String uid) {
    final ProgressDialog dialog1 = new ProgressDialog(this);
    dialog1.setTitle("正在发送请求");
    dialog1.setMessage("请等待......");
    Map<String, String> paras = new HashMap<>();
    paras.put("addsubmit", "true");
    paras.put("handlekey", "friend_" + uid);
    paras.put("note", mes);
    paras.put("gid", "1");
    paras.put("addsubmit_btn", "true");
    HttpUtil.post(UrlUtils.getAddFrirndUrl(uid), paras, new ResponseHandler() {

        @Override
        public void onSuccess(byte[] response) {
            String res = new String(response);
            if (res.contains("好友请求已")) {
                Toast.makeText(getApplicationContext(), "请求已发送成功,正在请等待对方验证", Toast.LENGTH_SHORT).show();
            } else if (res.contains("正在等待验证")) {
                Toast.makeText(getApplicationContext(), "好友请求已经发送了,正在等待对方验证", Toast.LENGTH_SHORT).show();
            } else if (res.contains("你们已成为好友")) {
                Toast.makeText(getApplicationContext(), "你们已经是好友了不用添加了...", Toast.LENGTH_SHORT).show();
            }
            dialog1.dismiss();
        }

        @Override
        public void onFailure(Throwable e) {
            super.onFailure(e);
            Toast.makeText(getApplicationContext(), "出错了,我也不知道哪儿错了...", Toast.LENGTH_SHORT).show();
            dialog1.dismiss();
        }
    });
}
Also used : ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) TextResponseHandler(me.yluo.ruisiapp.myhttp.TextResponseHandler) HashMap(java.util.HashMap) ProgressDialog(android.app.ProgressDialog)

Example 18 with ResponseHandler

use of me.yluo.ruisiapp.myhttp.ResponseHandler in project Ruisi by freedom10086.

the class FriendActivity method removeFriend.

private void removeFriend(String uid, final int pos) {
    // 操作成功
    String url = "home.php?mod=spacecp&ac=friend&op=ignore&uid=" + uid + "&confirm=1";
    if (App.ISLOGIN(this)) {
        url = url + "&mobile=2";
    }
    HashMap<String, String> pa = new HashMap<>();
    pa.put("friendsubmit", "true");
    HttpUtil.post(url, pa, new ResponseHandler() {

        @Override
        public void onSuccess(byte[] response) {
            String s = new String(response);
            if (s.contains("操作成功")) {
                removeRes(true, pos);
            } else {
                removeRes(false, pos);
            }
        }

        @Override
        public void onFailure(Throwable e) {
            super.onFailure(e);
            removeRes(false, pos);
        }
    });
}
Also used : ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) TextResponseHandler(me.yluo.ruisiapp.myhttp.TextResponseHandler) HashMap(java.util.HashMap)

Example 19 with ResponseHandler

use of me.yluo.ruisiapp.myhttp.ResponseHandler in project Ruisi by freedom10086.

the class HomeActivity method checkUpdate.

/**
 * check update
 */
private void checkUpdate() {
    PackageManager manager;
    PackageInfo info = null;
    manager = getPackageManager();
    try {
        info = manager.getPackageInfo(getPackageName(), 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
    int version_code = 1;
    if (info != null) {
        version_code = info.versionCode;
    }
    final int finalVersion_code = version_code;
    HttpUtil.get(App.CHECK_UPDATE_URL, new ResponseHandler() {

        @Override
        public void onSuccess(byte[] response) {
            String res = new String(response);
            int ih = res.indexOf("keywords");
            int h_start = res.indexOf('\"', ih + 15);
            int h_end = res.indexOf('\"', h_start + 1);
            String title = res.substring(h_start + 1, h_end);
            if (title.contains("code")) {
                int st = title.indexOf("code");
                int code = GetId.getNumber(title.substring(st));
                if (code > finalVersion_code) {
                    SharedPreferences.Editor editor = sharedPreferences.edit();
                    editor.putLong(App.CHECK_UPDATE_KEY, System.currentTimeMillis());
                    editor.apply();
                    isNeedCheckUpdate = false;
                    new AlertDialog.Builder(HomeActivity.this).setTitle("检测到新版本").setMessage(title).setPositiveButton("查看", (dialog, which) -> PostActivity.open(HomeActivity.this, App.CHECK_UPDATE_URL, "谁用了FREEDOM")).setNegativeButton("取消", null).setCancelable(true).create().show();
                }
            }
        }
    });
}
Also used : Context(android.content.Context) MainPageAdapter(me.yluo.ruisiapp.adapter.MainPageAdapter) Bundle(android.os.Bundle) FragmentMy(me.yluo.ruisiapp.fragment.FragmentMy) PackageManager(android.content.pm.PackageManager) ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) Timer(java.util.Timer) GetId(me.yluo.ruisiapp.utils.GetId) PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) Calendar(java.util.Calendar) MyBottomTab(me.yluo.ruisiapp.widget.MyBottomTab) Handler(android.os.Handler) Toast(android.widget.Toast) View(android.view.View) PreferenceManager(android.preference.PreferenceManager) WeakReference(java.lang.ref.WeakReference) TimerTask(java.util.TimerTask) HttpUtil(me.yluo.ruisiapp.myhttp.HttpUtil) Log(android.util.Log) NotificationManager(android.app.NotificationManager) FrageMessage(me.yluo.ruisiapp.fragment.FrageMessage) BaseLazyFragment(me.yluo.ruisiapp.fragment.BaseLazyFragment) R(me.yluo.ruisiapp.R) List(java.util.List) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) Message(android.os.Message) FrageHotsNews(me.yluo.ruisiapp.fragment.FrageHotsNews) Document(org.jsoup.nodes.Document) FrageForums(me.yluo.ruisiapp.fragment.FrageForums) Notification(android.app.Notification) Jsoup(org.jsoup.Jsoup) Elements(org.jsoup.select.Elements) App(me.yluo.ruisiapp.App) PackageManager(android.content.pm.PackageManager) ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) PackageInfo(android.content.pm.PackageInfo)

Example 20 with ResponseHandler

use of me.yluo.ruisiapp.myhttp.ResponseHandler in project Ruisi by freedom10086.

the class NewPostActivity method switchFid.

private void switchFid(int fid) {
    typeiddatas.clear();
    typeId = 0;
    String url = "forum.php?mod=post&action=newthread&fid=" + fid + "&mobile=2";
    HttpUtil.get(url, new ResponseHandler() {

        @Override
        public void onSuccess(byte[] response) {
            Document document = Jsoup.parse(new String(response));
            Elements types = document.select("#typeid").select("option");
            for (Element e : types) {
                typeiddatas.add(new Forum(Integer.parseInt(e.attr("value")), e.text()));
            }
            if (typeiddatas.size() > 0) {
                typeIdContainer.setVisibility(View.VISIBLE);
                tvSelectType.setText(typeiddatas.get(0).name);
                typeId = typeiddatas.get(0).fid;
            } else {
                typeIdContainer.setVisibility(View.GONE);
            }
            // 检查是否能上传图片
            // uploadformdata:{uid:"252553", hash:"fe626ed21ff334263dfe552cd9a4c209"},
            String res = new String(response);
            int index = res.indexOf("uploadformdata:");
            if (index > 0) {
                int start = res.indexOf("hash", index) + 6;
                int end = res.indexOf("\"", start + 5);
                uploadHash = res.substring(start, end);
                Log.v("===", "uploadhash:" + uploadHash);
            }
        }
    });
}
Also used : ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) UploadImageResponseHandler(me.yluo.ruisiapp.myhttp.UploadImageResponseHandler) Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Forum(me.yluo.ruisiapp.model.Forum)

Aggregations

ResponseHandler (me.yluo.ruisiapp.myhttp.ResponseHandler)38 Document (org.jsoup.nodes.Document)13 HashMap (java.util.HashMap)12 ProgressDialog (android.app.ProgressDialog)8 Bundle (android.os.Bundle)8 Element (org.jsoup.nodes.Element)7 Elements (org.jsoup.select.Elements)7 Intent (android.content.Intent)5 View (android.view.View)5 R (me.yluo.ruisiapp.R)5 HttpUtil (me.yluo.ruisiapp.myhttp.HttpUtil)5 GetId (me.yluo.ruisiapp.utils.GetId)5 SharedPreferences (android.content.SharedPreferences)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 App (me.yluo.ruisiapp.App)4 Context (android.content.Context)3 PackageInfo (android.content.pm.PackageInfo)3 PackageManager (android.content.pm.PackageManager)3 Log (android.util.Log)3