Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
KingsFish committed Aug 1, 2018
2 parents 385c171 + af72f8b commit 3fad6d0
Show file tree
Hide file tree
Showing 18 changed files with 429 additions and 192 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "me.yluo.ruisiapp"
minSdkVersion 21
targetSdkVersion 27
versionCode 30
versionName '2.9.4'
versionCode 31
versionName '2.9.5'
}

compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import me.yluo.ruisiapp.R;
import me.yluo.ruisiapp.myhttp.HttpUtil;
import me.yluo.ruisiapp.myhttp.ResponseHandler;
import me.yluo.ruisiapp.utils.RuisUtils;
import me.yluo.ruisiapp.widget.InputValidDialog;

public class ChangePasswordActivity extends BaseActivity implements
Expand Down Expand Up @@ -270,17 +271,16 @@ private void submit() {
public void onSuccess(byte[] response) {
dialog.dismiss();
String res = new String(response);
String reason;

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);
} else if ((reason = RuisUtils.getErrorText(res)) != null) {
if ("抱歉,验证码填写错误".equals(reason)) {
showInputValidDialog();
}
Expand Down
12 changes: 4 additions & 8 deletions app/src/main/java/me/yluo/ruisiapp/activity/EditActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
Expand Down Expand Up @@ -82,7 +81,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}
});

findViewById(R.id.forum_container).setVisibility(View.GONE);
typeIdContainer = findViewById(R.id.type_id_container);
typeIdContainer.setVisibility(View.GONE);
tvSelectType = findViewById(R.id.tv_select_type);
Expand Down Expand Up @@ -189,7 +187,8 @@ private void startPost() {
@Override
public void onSuccess(byte[] response) {
String res = new String(response);
Log.e("resoult", res);
String errorText;

if (res.contains("帖子编辑成功")) {
dialog.dismiss();
showToast("帖子编辑成功");
Expand All @@ -201,11 +200,8 @@ public void onSuccess(byte[] response) {
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 if ((errorText = RuisUtils.getErrorText(res)) != null) {
postFail(errorText);
} else {
postFail("编辑失败:我也不知道哪儿错了");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import me.yluo.ruisiapp.R;
import me.yluo.ruisiapp.myhttp.HttpUtil;
import me.yluo.ruisiapp.myhttp.ResponseHandler;
import me.yluo.ruisiapp.utils.RuisUtils;
import me.yluo.ruisiapp.utils.UrlUtils;

/**
Expand Down Expand Up @@ -45,7 +46,6 @@ protected void onCreate(Bundle savedInstanceState) {
+ App.BASE_URL_ME
+ "并加上尾缀&mobile=2\n举例:原始链接[http://rs.xidian.edu.cn/xxx]\n修改后:["
+ App.BASE_URL_ME + "xxx&mobile=2]");

btnSubmit.setOnClickListener(v -> submit());
edEmail.addTextChangedListener(new TextWatcher() {
@Override
Expand Down Expand Up @@ -89,13 +89,12 @@ private void submit() {
@Override
public void onSuccess(byte[] response) {
String res = new String(response);
String errorText;

if (res.contains("取回密码的方法已通过")) {
showLongToast("取回密码的方法已通过 Email 发送到您的信箱中,请尽快修改您的密码");
} 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);
emailTextInput.setError(reason);
} else if ((errorText = RuisUtils.getErrorText(res)) != null) {
emailTextInput.setError(errorText);
} else {
emailTextInput.setError("账号或者密码错误");
}
Expand Down
44 changes: 33 additions & 11 deletions app/src/main/java/me/yluo/ruisiapp/activity/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public class HomeActivity extends BaseActivity
private ViewPager viewPager;
private List<BaseLazyFragment> fragments = new ArrayList<>();

private static final int MSG_HAVE_REPLY = 1;
private static final int MSG_NO_REPLY = 2;
private static final int MSG_HAVE_PM = 3;
private static final int MSG_NO_PM = 4;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -151,7 +157,7 @@ protected void onStop() {

private void switchTab(int pos) {
if (pos == 2) {
bottomTab.setMessage(false);
bottomTab.clearMsg();
bottomTab.invalidate();
}
viewPager.setCurrentItem(pos, false);
Expand Down Expand Up @@ -277,10 +283,18 @@ private void dealMessage(boolean isReply, String res) {
}
}

if (ishaveReply || ishavePm) {
messageHandler.sendEmptyMessage(0);
if (isReply) {
if (ishaveReply) {
messageHandler.sendEmptyMessage(MSG_HAVE_REPLY);
} else {
messageHandler.sendEmptyMessage(MSG_NO_REPLY);
}
} else {
messageHandler.sendEmptyMessage(-1);
if (ishavePm) {
messageHandler.sendEmptyMessage(MSG_HAVE_PM);
} else {
messageHandler.sendEmptyMessage(MSG_NO_PM);
}
}
}

Expand All @@ -300,15 +314,23 @@ public void handleMessage(Message msg) {
MyBottomTab t = mytab.get();
HomeActivity a = act.get();
switch (msg.what) {
//-1 - 无消息 0-有
case -1:
Log.d("message", "无未读消息");
t.setMessage(false);
case MSG_HAVE_REPLY:
Log.d("message", "有新回复");
a.mkNotify();
t.setHaveReply(true);
break;
case 0:
case MSG_NO_REPLY:
Log.d("message", "无新回复");
t.setHaveReply(false);
break;
case MSG_HAVE_PM:
Log.d("message", "有新pm");
a.mkNotify();
Log.d("message", "有未读消息");
t.setMessage(true);
t.setHavePm(true);
break;
case MSG_NO_PM:
Log.d("message", "无新pm");
t.setHavePm(false);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import me.yluo.ruisiapp.myhttp.HttpUtil;
import me.yluo.ruisiapp.myhttp.ResponseHandler;
import me.yluo.ruisiapp.utils.GetId;
import me.yluo.ruisiapp.utils.RuisUtils;
import me.yluo.ruisiapp.utils.UrlUtils;
import me.yluo.ruisiapp.widget.InputValidDialog;

Expand Down Expand Up @@ -251,12 +252,10 @@ private void startLogin() {
@Override
public void onSuccess(byte[] response) {
String res = new String(response);
String reason;
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);
} else if ((reason = RuisUtils.getErrorText(res)) != null) {
if ("抱歉,验证码填写错误".equals(reason)) {
showInputValidDialog();
} else if (reason.contains("登录失败") && reason.contains("您还可以尝试")) {
Expand Down
81 changes: 33 additions & 48 deletions app/src/main/java/me/yluo/ruisiapp/activity/NewPostActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -47,7 +48,6 @@

import me.yluo.ruisiapp.App;
import me.yluo.ruisiapp.R;
import me.yluo.ruisiapp.model.Category;
import me.yluo.ruisiapp.model.Forum;
import me.yluo.ruisiapp.myhttp.HttpUtil;
import me.yluo.ruisiapp.myhttp.ResponseHandler;
Expand All @@ -64,15 +64,16 @@
/**
* Created by free2 on 16-3-6.
* 发帖activity
* 参数:FID TITLE
*/
public class NewPostActivity extends BaseActivity implements View.OnClickListener,
InputValidDialog.OnInputValidListener {

private EditText edTitle, edContent;
private MySpinner<Forum> forumSpinner, typeidSpinner;
private MySpinner<Forum> typeidSpinner;
private MyColorPicker myColorPicker;
private MySmileyPicker smileyPicker;
private TextView tvSelectForum, tvSelectType;
private TextView tvSelectType;

private View typeIdContainer;
private EmotionInputHandler handler;
Expand Down Expand Up @@ -105,53 +106,36 @@ public static void open(Context context, int fid, String title) {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_topic);
initToolBar(true, "发表新帖");

if (getIntent().getExtras() != null) {
fid = getIntent().getExtras().getInt("FID");
title = getIntent().getExtras().getString("TITLE");
}

if (!TextUtils.isEmpty(title)) {
title = "发表新帖-" + title;
}

initToolBar(true, "发表新帖");

addToolbarMenu(R.drawable.ic_send_white_24dp).setOnClickListener(this);
myColorPicker = new MyColorPicker(this);
smileyPicker = new MySmileyPicker(this);
forumSpinner = new MySpinner<>(this);
typeidSpinner = new MySpinner<>(this);
typeIdContainer = findViewById(R.id.type_id_container);
typeIdContainer.setVisibility(View.GONE);
tvSelectForum = findViewById(R.id.tv_select_forum);
tvSelectType = findViewById(R.id.tv_select_type);
tvSelectForum.setOnClickListener(this);

tvSelectType.setOnClickListener(this);
edTitle = findViewById(R.id.ed_title);
edContent = findViewById(R.id.ed_content);

List<Category> categories = RuisUtils.getForums(this, true);
if (categories == null) {
showLongToast("读取板块列表出错,请确保assets目录有forums.json文件");
finish();
if (fid <= 0) {
showToast("缺少必要参数无法发帖");
new Handler().postDelayed(() -> finish(), 500);
return;
}

for (Category c : categories) {
if (c.canPost) {
datas.addAll(c.forums);
}
}

if (TextUtils.isEmpty(title) || fid <= 0) {
title = datas.get(0).name;
fid = datas.get(0).fid;
}

tvSelectForum.setText(title);
forumSpinner.setData(datas);
forumSpinner.setListener((pos, v) -> {
fid = datas.get(pos).fid;
tvSelectForum.setText(datas.get(pos).name);
switchFid(fid);
});

typeidSpinner.setListener((pos, v) -> {
typeId = typeiddatas.get(pos).fid;
tvSelectType.setText(typeiddatas.get(pos).name);
Expand Down Expand Up @@ -208,7 +192,7 @@ public void onNothingSelected(AdapterView<?> adapterView) {
return true;
});

switchFid(fid);
loadTypeIds(fid);
checkValid();
}

Expand Down Expand Up @@ -295,16 +279,13 @@ private void beginPost() {
@Override
public void onSuccess(byte[] response) {
String res = new String(response);
//Log.e("==========", res);
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)) {
String errorText = RuisUtils.getErrorText(res);
if (errorText != null) {
if ("抱歉,验证码填写错误".equals(errorText)) {
showInputValidDialog();
reason = "抱歉,验证码填写错误";
errorText = "抱歉,验证码填写错误";
}
postFail(reason);
postFail(errorText);
} else {
postSuccess();
}
Expand Down Expand Up @@ -407,11 +388,6 @@ public void onClick(final View view) {
}
edContent.getText().delete(start, end);
break;
case R.id.tv_select_forum:
forumSpinner.setWidth(view.getWidth());
//MySpinner.setWidth(mTView.getWidth());
forumSpinner.showAsDropDown(view, 0, 15);
break;
case R.id.tv_select_type:
typeidSpinner.setData(typeiddatas);
typeidSpinner.setWidth(view.getWidth());
Expand All @@ -420,14 +396,24 @@ public void onClick(final View view) {

}

private void switchFid(int fid) {
private void loadTypeIds(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));
String res = new String(response);
String errorText = RuisUtils.getErrorText(res);

if (errorText != null) {
Log.e("==", errorText);
showToast(errorText);
new Handler().postDelayed(() -> finish(), 500);
return;
}

Document document = Jsoup.parse(res);
Elements types = document.select("#typeid").select("option");
for (Element e : types) {
typeiddatas.add(new Forum(Integer.parseInt(e.attr("value")), e.text()));
Expand All @@ -443,13 +429,12 @@ public void onSuccess(byte[] response) {

//检查是否能上传图片
//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);
Log.d("===", "uploadhash:" + uploadHash);
}
}
});
Expand Down
Loading

0 comments on commit 3fad6d0

Please sign in to comment.