From e235e1d91dfcee0421ed1fd45390c59c9f90ae5c Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Thu, 9 Apr 2020 07:57:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=88=91=E7=9A=84=E4=BF=A1?= =?UTF-8?q?=E6=81=AF-=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pocket/data/main/info/InfoRequest.java | 7 ++++++- .../pocket/ui/login/LoginActivity.java | 9 ++++++++- .../ui/main/ui/forum/post/ForumPostContent.java | 9 --------- .../pocket/ui/main/ui/info/InfoFragment.java | 17 ++++++++++++----- .../pocket/ui/main/ui/info/InfoResponse.java | 4 +++- .../pocket/ui/register/RegisterActivity.java | 3 ++- app/src/main/res/values-en-rUS/strings.xml | 1 + app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 34 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/community/pocket/data/main/info/InfoRequest.java b/app/src/main/java/com/community/pocket/data/main/info/InfoRequest.java index 62cb9a1..de61356 100644 --- a/app/src/main/java/com/community/pocket/data/main/info/InfoRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/info/InfoRequest.java @@ -36,6 +36,7 @@ public class InfoRequest { .add("oldPassword", oldPassword) .add("newPassword", newPassword) .add("token", LocalToken.getToken()) + .add("username", LocalToken.getUsername()) .build()); } @@ -43,6 +44,10 @@ public class InfoRequest { @HttpRequest("/my/info") public void loadInfo(MutableLiveData liveData) { HttpUtil.getRequest(HttpUtil.Method.GET, - new SimpleHttpParse(liveData).getInterface(InfoResponse.class)); + new SimpleHttpParse(liveData).getInterface(InfoResponse.class), + new FormBody.Builder() + .add("token", LocalToken.getToken()) + .add("username", LocalToken.getUsername()) + .build()); } } diff --git a/app/src/main/java/com/community/pocket/ui/login/LoginActivity.java b/app/src/main/java/com/community/pocket/ui/login/LoginActivity.java index 034dede..6262464 100644 --- a/app/src/main/java/com/community/pocket/ui/login/LoginActivity.java +++ b/app/src/main/java/com/community/pocket/ui/login/LoginActivity.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.content.Intent; import android.os.Build; import android.os.Bundle; +import android.os.Looper; import android.text.Editable; import android.text.TextWatcher; import android.view.View; @@ -94,7 +95,11 @@ public class LoginActivity extends BaseActivity { Token token = response.getToken(); LocalToken.getInstance(token); startActivity(new Intent(getBaseContext(), MainMenu.class)); - response.toast(getBaseContext()); + if (Looper.myLooper() == null) { + Looper.prepare(); + response.toast(getBaseContext()); + Looper.loop(); + } //Complete and destroy login activity once successful finish(); } @@ -149,6 +154,8 @@ public class LoginActivity extends BaseActivity { if (loginResponse.getResult() == Response.Result.OK) { saveTokenToDB(loginResponse); + } else { + loginResponse.toast(getApplicationContext()); } } }); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java index 2527612..5cb34fd 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java @@ -1,6 +1,5 @@ package com.community.pocket.ui.main.ui.forum.post; -import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.view.View; @@ -14,9 +13,7 @@ import androidx.constraintlayout.widget.ConstraintLayout; import androidx.lifecycle.Observer; import com.community.pocket.R; -import com.community.pocket.data.model.LocalToken; import com.community.pocket.ui.BaseFragment; -import com.community.pocket.ui.login.LoginActivity; import com.community.pocket.ui.main.ui.forum.main.ForumFragment; import com.community.pocket.ui.main.ui.share.Response; import com.community.pocket.ui.main.ui.share.ShowWordCount; @@ -78,12 +75,6 @@ abstract class ForumPostContent extends BaseFragment { return; } - if (invalidToken(forumPostResponse)) { - LocalToken.logout(); - startActivity(new Intent(getContext(), LoginActivity.class)); - return; - } - forumPostResponse.toast(getContext()); if (forumPostResponse.getResult() == Response.Result.OK) { ForumFragment forumFragment = getParentFragment(4); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java index 15d1b4a..5f96e45 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java @@ -199,7 +199,9 @@ public class InfoFragment extends BaseFragment { mobie.setText(myInfo.getMobie()); email.setText(myInfo.getEmail()); - loadChart(myInfo.getScoreHistory()); + if (myInfo.getScoreHistory() != null) { + loadChart(myInfo.getScoreHistory()); + } } /** @@ -260,10 +262,15 @@ public class InfoFragment extends BaseFragment { */ @RequiresApi(api = Build.VERSION_CODES.KITKAT) @Event(value = R.id.logout) - private void logout(View view) { - AppDatabase.getInstance(getContext()).tokenDao().delete(LocalToken.getTokenInstance()); - LocalToken.logout(); - startActivity(new Intent(view.getContext(), LoginActivity.class)); + private void logout(final View view) { + new Thread(new Runnable() { + @Override + public void run() { + AppDatabase.getInstance(getContext()).tokenDao().delete(LocalToken.getTokenInstance()); + LocalToken.logout(); + startActivity(new Intent(view.getContext(), LoginActivity.class)); + } + }).start(); } //加载图表数据 diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoResponse.java index 7db9f3b..f082e59 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoResponse.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoResponse.java @@ -30,7 +30,9 @@ public class InfoResponse extends ToastResponse { ok(R.string.load_info_ok), fail(R.string.load_info_fail), modify_pwd_ok(R.string.modify_pwd_ok), - modify_pwd_fail(R.string.modify_pwd_fail); + modify_pwd_fail(R.string.modify_pwd_fail), + modify_oldpwd_fail(R.string.modify_oldpwd_fail), + token(R.string.invalid_token); private Integer msg; diff --git a/app/src/main/java/com/community/pocket/ui/register/RegisterActivity.java b/app/src/main/java/com/community/pocket/ui/register/RegisterActivity.java index 85125c1..e2f85ec 100644 --- a/app/src/main/java/com/community/pocket/ui/register/RegisterActivity.java +++ b/app/src/main/java/com/community/pocket/ui/register/RegisterActivity.java @@ -17,6 +17,7 @@ import com.community.pocket.R; import com.community.pocket.ui.BaseActivity; import com.community.pocket.ui.listener.MyTextChange; import com.community.pocket.ui.login.LoginActivity; +import com.community.pocket.ui.main.ui.share.Response; import com.community.pocket.util.PropertiesUtil; import org.xutils.view.annotation.ContentView; @@ -114,7 +115,7 @@ public class RegisterActivity extends BaseActivity { } registerResponse.toast(getBaseContext()); - if (registerResponse.getBody() == RegisterResponse.Msg.ok) { + if (registerResponse.getResult() == Response.Result.OK) { startActivity(new Intent(getApplicationContext(), LoginActivity.class)); //Complete and destroy login activity once successful finish(); diff --git a/app/src/main/res/values-en-rUS/strings.xml b/app/src/main/res/values-en-rUS/strings.xml index 14daf5f..9f64b40 100644 --- a/app/src/main/res/values-en-rUS/strings.xml +++ b/app/src/main/res/values-en-rUS/strings.xml @@ -169,4 +169,5 @@ start date must be before end date token error,please login no more forum + modify error \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index cd62139..35dd2ac 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -169,4 +169,5 @@ 开始日期必须小于结束日期 身份有效期已过,请重新登录 没有更多帖子 + 修改密码失败,原密码不正确 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ba5b62e..6724020 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -170,6 +170,7 @@ start date must be before end date token error,please login no more forum + modify error