Search in sources :

Example 11 with ResponseHandler

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

the class LoginActivity method startLogin.

private void startLogin() {
    if (haveValid && TextUtils.isEmpty(validValue)) {
        showInputValidDialog();
        return;
    }
    dialog = new ProgressDialog(this);
    dialog.setMessage("登陆中,请稍后......");
    dialog.show();
    final String username = edUsername.getText().toString().trim();
    final String passNo = edPassword.getText().toString().trim();
    Map<String, String> params = new HashMap<>();
    params.put("fastloginfield", "username");
    params.put("cookietime", "2592000");
    params.put("username", username);
    params.put("password", passNo);
    params.put("questionid", answerSelect + "");
    if (haveValid) {
        // 是否有验证码
        params.put("seccodehash", seccodehash);
        params.put("seccodeverify", validValue);
    }
    if (answerSelect == 0) {
        params.put("answer", "");
    } else {
        params.put("answer", edAnswer.getText().toString());
    }
    HttpUtil.post(loginUrl, params, new ResponseHandler() {

        @Override
        public void onSuccess(byte[] response) {
            String res = new String(response);
            if (res.contains("欢迎您回来")) {
                loginOk(res);
            } 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);
                if ("抱歉,验证码填写错误".equals(reason)) {
                    showInputValidDialog();
                } else if (reason.contains("登录失败") && reason.contains("您还可以尝试")) {
                    reason = reason.replace("登录失败", "账号或者密码错误");
                }
                networkErr(reason);
            } else {
                passwordOrUsernameErr();
            }
        }

        @Override
        public void onFailure(Throwable e) {
            networkErr("网络异常");
        }

        @Override
        public void onFinish() {
            dialog.dismiss();
        }
    });
}
Also used : ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) HashMap(java.util.HashMap) ProgressDialog(android.app.ProgressDialog)

Example 12 with ResponseHandler

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

the class FragSetting method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.setting);
    setting_user_tail = (EditTextPreference) findPreference("setting_user_tail");
    setting_forums_url = (ListPreference) findPreference("setting_forums_url");
    clearCache = findPreference("clean_cache");
    sharedPreferences = getPreferenceScreen().getSharedPreferences();
    boolean b = sharedPreferences.getBoolean("setting_show_tail", false);
    setting_user_tail.setEnabled(b);
    setting_user_tail.setSummary(sharedPreferences.getString("setting_user_tail", "无小尾巴"));
    setting_forums_url.setSummary(App.IS_SCHOOL_NET ? "当前网络校园网,点击切换" : "当前网络校外网,点击切换");
    setting_forums_url.setValue(App.IS_SCHOOL_NET ? "1" : "2");
    sharedPreferences.registerOnSharedPreferenceChangeListener(this);
    PackageManager manager;
    PackageInfo info = null;
    manager = getActivity().getPackageManager();
    try {
        info = manager.getPackageInfo(getActivity().getPackageName(), 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
    int version_code = 1;
    String version_name = "1.0";
    if (info != null) {
        version_code = info.versionCode;
        version_name = info.versionName;
    }
    findPreference("about_this").setSummary("当前版本" + version_name + "  version code:" + version_code);
    // [2016年6月9日更新][code:25]睿思手机客户端
    // 更新逻辑 检查睿思帖子标题 比对版本号
    final int finalversion_code = version_code;
    findPreference("about_this").setOnPreferenceClickListener(preference -> {
        Toast.makeText(getActivity(), "正在检查更新", Toast.LENGTH_SHORT).show();
        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();
                        new AlertDialog.Builder(getActivity()).setTitle("检测到新版本").setMessage(title).setPositiveButton("查看", (dialog, which) -> PostActivity.open(getActivity(), App.CHECK_UPDATE_URL, "谁用了FREEDOM")).setNegativeButton("取消", null).setCancelable(true).create().show();
                    } else {
                        Toast.makeText(getActivity(), "暂无更新", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
        return true;
    });
    findPreference("open_sourse").setOnPreferenceClickListener(preference -> {
        IntentUtils.openBroswer(getActivity(), "https://github.com/freedom10086/Ruisi");
        return false;
    });
    clearCache.setSummary("缓存大小:" + DataManager.getTotalCacheSize(getActivity()));
    clearCache.setOnPreferenceClickListener(preference -> {
        DataManager.cleanApplicationData(getActivity());
        Toast.makeText(getActivity(), "缓存清理成功!请重新登陆", Toast.LENGTH_SHORT).show();
        clearCache.setSummary("缓存大小:" + DataManager.getTotalCacheSize(getActivity()));
        return false;
    });
}
Also used : Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) IntentUtils(me.yluo.ruisiapp.utils.IntentUtils) ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) GetId(me.yluo.ruisiapp.utils.GetId) DataManager(me.yluo.ruisiapp.utils.DataManager) PackageInfo(android.content.pm.PackageInfo) R(me.yluo.ruisiapp.R) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) PreferenceFragment(android.preference.PreferenceFragment) Toast(android.widget.Toast) PostActivity(me.yluo.ruisiapp.activity.PostActivity) HttpUtil(me.yluo.ruisiapp.myhttp.HttpUtil) App(me.yluo.ruisiapp.App) PackageManager(android.content.pm.PackageManager) ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) PackageInfo(android.content.pm.PackageInfo)

Example 13 with ResponseHandler

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

the class FrageForums method initForums.

void initForums(boolean loginstate) {
    new GetForumList().execute(loginstate);
    if (App.IS_SCHOOL_NET) {
        // 是校园网
        String url = App.BASE_URL_RS + "forum.php";
        HttpUtil.get(url, new ResponseHandler() {

            @Override
            public void onSuccess(byte[] response) {
                List<WaterData> temps = new ArrayList<>();
                Document doc = Jsoup.parse(new String(response));
                Elements waters = doc.select("#portal_block_317").select("li");
                for (Element e : waters) {
                    Elements es = e.select("p").select("a[href^=home.php?mod=space]");
                    String uid = GetId.getId("uid=", es.attr("href"));
                    String imgSrc = e.select("img").attr("src");
                    String uname = es.text();
                    int num = 0;
                    if (e.select("p").size() > 1) {
                        if (e.select("p").get(1).text().contains("帖数")) {
                            num = GetId.getNumber(e.select("p").get(1).text());
                        }
                    }
                    temps.add(new WaterData(uname, uid, num, imgSrc));
                    if (temps.size() >= 16)
                        break;
                }
                if (temps.size() > 0)
                    adapter.setWaterData(temps);
            }
        });
    }
}
Also used : ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) Element(org.jsoup.nodes.Element) WaterData(me.yluo.ruisiapp.model.WaterData) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 14 with ResponseHandler

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

the class ChangePasswordActivity method submit.

private void submit() {
    checkInput();
    if (err)
        return;
    if (haveValid && TextUtils.isEmpty(validValue)) {
        showInputValidDialog();
        return;
    }
    if (!isLoad)
        loadData(true);
    String old = password1.getText().toString();
    String new1 = password2.getText().toString();
    String new2 = password3.getText().toString();
    if (TextUtils.isEmpty(old) || TextUtils.isEmpty(new1) || TextUtils.isEmpty(new2)) {
        Snackbar.make(findViewById(R.id.content), "输入不能为空", Snackbar.LENGTH_SHORT).show();
        return;
    }
    if (!Objects.equals(new1, new2)) {
        Snackbar.make(findViewById(R.id.content), "两次输入的密码不一致", Snackbar.LENGTH_SHORT).show();
        return;
    }
    dialog = new ProgressDialog(this);
    dialog.setMessage("提交中,请稍后......");
    dialog.show();
    Map<String, String> ps = new HashMap<>();
    // ps.put("formhash", "711c5dd9");
    ps.put("oldpassword", old);
    ps.put("newpassword", new1);
    ps.put("newpassword2", new1);
    ps.put("emailnew", emailNew);
    if (haveValid) {
        // 是否有验证码
        ps.put("seccodehash", seccodehash);
        ps.put("seccodeverify", validValue);
    }
    if (answerSelect <= 0) {
        ps.put("questionidnew", "");
        ps.put("answernew", "");
    } else {
        ps.put("questionidnew", String.valueOf(answerSelect - 1));
        ps.put("answernew", edAnswer.getText().toString());
    }
    ps.put("pwdsubmit", "true");
    ps.put("passwordsubmit", "true");
    HttpUtil.getClient().setConnectionTimeout(20000);
    HttpUtil.getClient().setReadTimeout(20000);
    HttpUtil.post("home.php?mod=spacecp&ac=profile&mobile=2", ps, new ResponseHandler() {

        @Override
        public void onSuccess(byte[] response) {
            dialog.dismiss();
            String res = new String(response);
            if (res.contains("个人资料保存成功")) {
                showLongToast("修改密码成功 请重新登陆");
                // DataManager.cleanApplicationData(ChangePasswordActivity.this);
                App.setUid(ChangePasswordActivity.this, "");
                HttpUtil.exit();
                finish();
                startActivity(new Intent(ChangePasswordActivity.this, LoginActivity.class));
            } 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);
                if ("抱歉,验证码填写错误".equals(reason)) {
                    showInputValidDialog();
                }
                Toast.makeText(ChangePasswordActivity.this, reason, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(ChangePasswordActivity.this, "我也不知道出了什么问题", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFailure(Throwable e) {
            Toast.makeText(ChangePasswordActivity.this, "连接超时,可能修改成功", Toast.LENGTH_SHORT).show();
            dialog.dismiss();
        }

        @Override
        public void onFinish() {
            HttpUtil.getClient().setConnectionTimeout(8000);
            HttpUtil.getClient().setReadTimeout(8000);
        }
    });
}
Also used : ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) HashMap(java.util.HashMap) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog)

Example 15 with ResponseHandler

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

the class ChatActivity method send_click.

private void send_click() {
    String text = input.getText().toString();
    int len = 0;
    try {
        len = text.getBytes("UTF-8").length;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    if (len == 0) {
        // input.setError("你还没写内容呢!");
        final Snackbar s = Snackbar.make(list, "你还没写内容呢", Snackbar.LENGTH_SHORT);
        s.setAction("好的", v -> s.dismiss()).show();
    } else {
        // 时间检测
        if (!(System.currentTimeMillis() - replyTime > 15000)) {
            Snackbar.make(list, "还没到15s呢,再等等吧!", Snackbar.LENGTH_SHORT).show();
            return;
        }
        // 字数补齐补丁
        if (len < 13) {
            int need = 14 - len;
            for (int i = 0; i < need; i++) {
                text += " ";
            }
        }
        final Snackbar snackbar = Snackbar.make(list, "回复发表中...", Snackbar.LENGTH_LONG);
        KeyboardUtil.hideKeyboard(this);
        snackbar.show();
        Map<String, String> params = new HashMap<>();
        params.put("touid", touid);
        params.put("message", text);
        HttpUtil.post(replyUrl, params, new ResponseHandler() {

            @Override
            public void onSuccess(byte[] response) {
                String res = new String(response);
                if (res.contains("操作成功")) {
                    list.postDelayed(() -> {
                        showToast("回复发表成功");
                        getData(false);
                    }, 600);
                    replyTime = System.currentTimeMillis();
                    input.setText("");
                } else {
                    if (res.contains("两次发送短消息太快")) {
                        showToast("两次发送短消息太快,请稍候再发送");
                    } else {
                        System.out.println(res);
                        showToast("由于未知原因发表失败");
                    }
                }
            }

            @Override
            public void onFailure(Throwable e) {
                showToast("网络错误!!!");
            }

            @Override
            public void onFinish() {
                list.postDelayed(() -> snackbar.dismiss(), 300);
                super.onFinish();
            }
        });
    }
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) UrlUtils(me.yluo.ruisiapp.utils.UrlUtils) EmotionInputHandler(me.yluo.ruisiapp.widget.emotioninput.EmotionInputHandler) ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) Intent(android.content.Intent) HashMap(java.util.HashMap) GetId(me.yluo.ruisiapp.utils.GetId) MySmileyPicker(me.yluo.ruisiapp.widget.MySmileyPicker) ArrayList(java.util.ArrayList) KeyboardUtil(me.yluo.ruisiapp.utils.KeyboardUtil) Element(org.jsoup.nodes.Element) Map(java.util.Map) View(android.view.View) HttpUtil(me.yluo.ruisiapp.myhttp.HttpUtil) Log(android.util.Log) TextResponseHandler(me.yluo.ruisiapp.myhttp.TextResponseHandler) DimmenUtils(me.yluo.ruisiapp.utils.DimmenUtils) AsyncTask(android.os.AsyncTask) ChatListAdapter(me.yluo.ruisiapp.adapter.ChatListAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) R(me.yluo.ruisiapp.R) RecyclerView(android.support.v7.widget.RecyclerView) Gravity(android.view.Gravity) List(java.util.List) ChatListData(me.yluo.ruisiapp.model.ChatListData) Document(org.jsoup.nodes.Document) Jsoup(org.jsoup.Jsoup) Elements(org.jsoup.select.Elements) Nullable(android.support.annotation.Nullable) Snackbar(android.support.design.widget.Snackbar) UnsupportedEncodingException(java.io.UnsupportedEncodingException) EditText(android.widget.EditText) ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) TextResponseHandler(me.yluo.ruisiapp.myhttp.TextResponseHandler) HashMap(java.util.HashMap) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Snackbar(android.support.design.widget.Snackbar)

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