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();
}
});
}
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;
});
}
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);
}
});
}
}
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);
}
});
}
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();
}
});
}
}
Aggregations