Browse Source

退出登录与修改密码

aleyds 1 year ago
parent
commit
7a5f170022

+ 3 - 22
app/src/main/AndroidManifest.xml

@@ -116,6 +116,9 @@
         <activity android:name="com.hw.nativeapp.ui.activity.SettingActivity"
             android:configChanges="orientation|screenSize"
             android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
+        <activity android:name="com.hw.nativeapp.ui.activity.UpdatePasswordActivity"
+            android:configChanges="orientation|screenSize"
+            android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
 
         <provider
             android:name="androidx.core.content.FileProvider"
@@ -128,28 +131,6 @@
                 android:resource="@xml/file_paths" />
         </provider>
 
-<!--        <provider-->
-<!--            android:name="androidx.core.content.FileProvider"-->
-<!--            android:authorities="${applicationId}.fileprovider"-->
-<!--            android:exported="false"-->
-<!--            android:grantUriPermissions="true"-->
-<!--            tools:replace="android:authorities,android:exported">-->
-<!--            <meta-data-->
-<!--                android:name="android.support.FILE_PROVIDER_PATHS"-->
-<!--                android:resource="@xml/file_paths" />-->
-<!--        </provider>-->
-
-<!--        <provider-->
-<!--        android:name="androidx.core.content.FileProvider"-->
-<!--        android:authorities="${applicationId}.fileprovider"-->
-<!--        android:exported="false"-->
-<!--        android:grantUriPermissions="true"-->
-<!--        tools:replace="android:authorities,android:exported">-->
-<!--        <meta-data-->
-<!--            android:name="android.support.FILE_PROVIDER_PATHS"-->
-<!--            android:resource="@xml/file_paths" />-->
-<!--    </provider>-->
-
         <activity android:name=".ui.activity.ScanQRCodeActivity"
             android:screenOrientation="fullSensor"
             tools:replace="screenOrientation"/>

+ 9 - 0
app/src/main/java/com/hw/nativeapp/httpnet/ApiService.java

@@ -3,6 +3,7 @@ package com.hw.nativeapp.httpnet;
 
 import com.alibaba.fastjson.JSONObject;
 import com.hw.nativeapp.BuildConfig;
+import com.hw.nativeapp.httpnet.entity.ChangePsdRequestBean;
 import com.hw.nativeapp.httpnet.entity.LoginBean;
 import com.hw.nativeapp.httpnet.entity.LoginRequestBean;
 import com.hw.nativeapp.httpnet.entity.ResponseData;
@@ -15,6 +16,7 @@ import io.reactivex.Observable;
 import retrofit2.http.Body;
 import retrofit2.http.GET;
 import retrofit2.http.POST;
+import retrofit2.http.PUT;
 import retrofit2.http.Query;
 import retrofit2.http.QueryMap;
 
@@ -40,6 +42,13 @@ public interface ApiService {
             @Query("t") Long currtime
     );
 
+    //修改密码
+    @POST(COMMON + "/member/pdaUser/updatePwd")
+    Observable<ResponseData> updatePwd(
+            @Body ChangePsdRequestBean bean,
+            @Query("t") Long currtime
+    );
+
     //版本升级
     @POST(COMMON + "/system/appVersion/check")
     Observable<ResponseData<UpdateVerAskBean>> version(

+ 9 - 0
app/src/main/java/com/hw/nativeapp/httpnet/entity/ChangePsdRequestBean.java

@@ -0,0 +1,9 @@
+package com.hw.nativeapp.httpnet.entity;
+
+import java.io.Serializable;
+
+public class ChangePsdRequestBean implements Serializable {
+
+    public String oldPassword;
+    public String newPassword;
+}

+ 2 - 1
app/src/main/java/com/hw/nativeapp/ui/activity/LoginActivity.java

@@ -51,6 +51,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
     private ProgressDialog progressDialog;
     @Override
     void initView() {
+        isLogin();
 //        if (!isLogin()){
 //            UpgradeUtils.upgrade(this);
 //            String cacheStr = SPUtils.getInstance().getString(Contents.SPU_USERLOGININFO_KEY);
@@ -148,7 +149,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
             return false;
         }
         //TODO: 接口判断用户登录
-        ActivityUtils.launchActivity(this, MainActivity.class);
+        ActivityUtils.launchRoot(this, MainActivity.class);
         ActivityUtils.activityFinish(this, true);
         return true;
     }

+ 15 - 27
app/src/main/java/com/hw/nativeapp/ui/activity/SettingActivity.java

@@ -28,6 +28,7 @@ import com.hw.nativeapp.httpnet.entity.UpdateVerReqBean;
 import com.hw.nativeapp.ui.dialogs.Dialog_Update;
 import com.hw.nativeapp.ui.dialogs.Dialog_UpdateProgress;
 import com.hw.nativeapp.update.UpdateHandler;
+import com.hw.nativeapp.utils.ActivityUtils;
 import com.hw.nativeapp.utils.RxUtil;
 import com.hw.nativeapp.utils.sunmi.SunmiPrintHelper;
 
@@ -65,9 +66,7 @@ private static final String TAG = "SettingActivity";
     TextView txSerial;
     @BindView(R.id.tx_projectName)
     TextView projectName;
-    private Dialog_Update dialogUpdate;
-    private Dialog_UpdateProgress dialogUpdateProgress;
-    private EditText editText;
+
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -93,9 +92,11 @@ private static final String TAG = "SettingActivity";
         switch (view.getId()) {
             case R.id.btn_updatepassword:
 //                Start.start(SettingActivity.this, UpdatePasswordActivity.class);
+                ActivityUtils.launchActivity(this,UpdatePasswordActivity.class);
                 break;
             case R.id.btn_out:
 //                toCancellation();
+                loginout();
                 break;
             case R.id.btn_print:
                 SunmiPrintHelper.getInstance().print3Line();
@@ -108,6 +109,16 @@ private static final String TAG = "SettingActivity";
     }
 
 
+    private void loginout(){
+        DialogBuilder.alertDialog(this).setMessage("是否确认退出登录")
+                .setOnPositiveButtonClickListener((dialog, which) ->
+                {
+                    SPUtils.getInstance().remove(Contents.SPU_TOKEN_KEY);
+                    ActivityUtils.launchRoot(SettingActivity.this, LoginActivity.class);
+                    ActivityUtils.activityFinish(SettingActivity.this, true);
+                })
+                .create().show();
+    }
 
 
 
@@ -159,7 +170,6 @@ private static final String TAG = "SettingActivity";
         updateHandler.setOnListener(new UpdateHandler.OnDownloadListener() {
                     @Override
                     public void complate() {
-//                        progressHandler.();
                         dialogBuilder.dismiss();
                     }
 
@@ -174,34 +184,12 @@ private static final String TAG = "SettingActivity";
                         int pprogress = a.divide(b,2,BigDecimal.ROUND_HALF_UP)
                                 .multiply(BigDecimal.valueOf(100))
                                 .intValue();
-//                        Log.d("aleyds", "soFarBytes:" + soFarBytes  + ":: totalBytes:" + totalBytes + " -> "+ pprogress);
                         progressHandler.setProgress(pprogress);
                     }
                 });
                 updateHandler.start();
 
-        // 更新进度
-
-//            dialogUpdateProgress = new Dialog_UpdateProgress(this, new Dialog_UpdateProgress.OnDialogListener() {
-//            @Override
-//            public void opend() {
-//                UpdateHandler updateHandler = new UpdateHandler(SettingActivity.this,downUrl);
-//                updateHandler.setOnListener(new UpdateHandler.OnDownloadListener() {
-//                    @Override
-//                    public void complate() {
-//                        dialogUpdateProgress.dismiss();
-//                    }
-//
-//                    @Override
-//                    public void progress(int soFarBytes, int totalBytes) {
-//                        dialogUpdateProgress.setTxProgress(soFarBytes, totalBytes);
-//                        dialogUpdateProgress.setProgressBar(soFarBytes, totalBytes);
-//                    }
-//                });
-//                updateHandler.start();
-//            }
-//        });
-//        dialogUpdateProgress.show();
+
     }
 
 }

+ 99 - 0
app/src/main/java/com/hw/nativeapp/ui/activity/UpdatePasswordActivity.java

@@ -0,0 +1,99 @@
+package com.hw.nativeapp.ui.activity;
+
+import android.os.Bundle;
+import android.os.Handler;
+import android.text.TextUtils;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import com.blankj.utilcode.util.SPUtils;
+import com.blankj.utilcode.util.ToastUtils;
+import com.hw.nativeapp.MApplication;
+import com.hw.nativeapp.R;
+import com.hw.nativeapp.config.Contents;
+import com.hw.nativeapp.httpnet.ErrorConsumer;
+import com.hw.nativeapp.httpnet.ResponseConsumer;
+import com.hw.nativeapp.httpnet.entity.ChangePsdRequestBean;
+import com.hw.nativeapp.httpnet.entity.ResponseData;
+import com.hw.nativeapp.utils.ActivityUtils;
+import com.hw.nativeapp.utils.RxUtil;
+
+import butterknife.BindView;
+import butterknife.OnClick;
+
+public class UpdatePasswordActivity extends BaseActivity{
+
+    @BindView(R.id.textView20)
+    TextView textView20;
+    @BindView(R.id.ed_old_psd)
+    EditText edOldPsd;
+    @BindView(R.id.ed_new_psd)
+    EditText edNewPsd;
+    @BindView(R.id.ed_new_psd_agin)
+    EditText edNewPsdAgin;
+    @BindView(R.id.btn_sure)
+    TextView btnSure;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_update_password);
+    }
+
+    @OnClick({R.id.btn_sure})
+    public void onClick(View view) {
+        switch (view.getId()) {
+
+            case R.id.btn_sure:
+                if (TextUtils.isEmpty(edOldPsd.getText().toString().trim()))
+                    ToastUtils.showShort("请输入原密码");
+                else if (TextUtils.isEmpty(edNewPsd.getText().toString().trim()))
+                    ToastUtils.showShort("请输入新密码");
+                else if (TextUtils.isEmpty(edNewPsdAgin.getText().toString().trim()))
+                    ToastUtils.showShort("请输入确认新密码");
+                else if (!edNewPsd.getText().toString().trim().equals(edNewPsdAgin.getText().toString().trim()))
+                    ToastUtils.showShort("新密码和确认密码必须一致");
+                else
+                    changePsd();
+                break;
+
+        }
+    }
+
+
+
+    private void changePsd() {
+        ChangePsdRequestBean bean = new ChangePsdRequestBean();
+        bean.oldPassword = edOldPsd.getText().toString().trim();
+        bean.newPassword = edNewPsd.getText().toString().trim();
+        MApplication.getApiService().updatePwd(bean,System.currentTimeMillis()/1000)
+                .compose(RxUtil.applyObservableAsync())
+                .subscribe(new ResponseConsumer() {
+                    @Override
+                    public void onSuccess(Object data) {
+                        ToastUtils.showShort("密码修改成功,重新登录");
+                        toLogin();
+                    }
+
+                    @Override
+                    public void accept(ResponseData responseData) throws Exception {
+                        super.accept(responseData);
+                    }
+                }, new ErrorConsumer());
+    }
+
+    private void toLogin() {
+        new Handler().postDelayed(() -> {
+            SPUtils.getInstance().remove(Contents.SPU_TOKEN_KEY);
+            ActivityUtils.launchRoot(UpdatePasswordActivity.this, LoginActivity.class);
+            ActivityUtils.activityFinish(UpdatePasswordActivity.this, true);
+
+        }, 800);
+    }
+
+    @Override
+    void initView() {
+
+    }
+}

+ 125 - 0
app/src/main/res/layout/activity_update_password.xml

@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="#F4F4F4"
+    android:orientation="vertical">
+
+    <LinearLayout
+        android:layout_margin="@dimen/dp_10"
+        android:background="@drawable/bg_corners_01"
+        android:layout_width="match_parent"
+        android:layout_height="55dp"
+        android:gravity="center"
+        android:orientation="horizontal">
+
+        <TextView
+            android:layout_marginStart="@dimen/dp_10"
+            android:id="@+id/textView20"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textSize="23sp"
+            android:textColor="#484848"
+            android:text="原密码:" />
+
+        <EditText
+            android:id="@+id/ed_old_psd"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:background="@null"
+            android:hint="输入原密码"
+            android:importantForAutofill="no"
+            android:inputType="textPassword"
+            android:singleLine="true"
+            android:textColor="#484848"
+            android:textColorHint="#BDBDBD"
+            android:textSize="20sp" />
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_margin="@dimen/dp_10"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:background="@drawable/bg_corners_01"
+        android:orientation="vertical">
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="55dp"
+            android:gravity="center"
+            android:orientation="horizontal">
+
+            <TextView
+                android:layout_marginStart="@dimen/dp_10"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textSize="23sp"
+                android:textColor="#484848"
+                android:text="新密码:" />
+
+            <EditText
+                android:id="@+id/ed_new_psd"
+                android:layout_width="0dp"
+                android:layout_height="match_parent"
+                android:layout_weight="1"
+                android:background="@null"
+                android:hint="请输入新密码"
+                android:importantForAutofill="no"
+                android:inputType="textPassword"
+                android:singleLine="true"
+                android:textColor="#484848"
+                android:textColorHint="#BDBDBD"
+                android:textSize="20sp" />
+        </LinearLayout>
+        <View
+            android:layout_width="match_parent"
+            android:layout_height="1dp"
+            android:layout_marginStart="@dimen/dp_10"
+            android:layout_marginEnd="@dimen/dp_10"
+            android:background="#E9E9E9"/>
+        <LinearLayout
+
+            android:layout_width="match_parent"
+            android:layout_height="55dp"
+            android:gravity="center"
+            android:orientation="horizontal">
+
+            <TextView
+                android:layout_marginStart="@dimen/dp_10"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textSize="23sp"
+                android:textColor="#484848"
+                android:text="确认新密码:" />
+
+            <EditText
+                android:id="@+id/ed_new_psd_agin"
+                android:layout_width="0dp"
+                android:layout_height="match_parent"
+                android:layout_weight="1"
+                android:background="@null"
+                android:hint="请再次输入新密码"
+                android:importantForAutofill="no"
+                android:inputType="textPassword"
+                android:singleLine="true"
+                android:textColor="#484848"
+                android:textColorHint="#BDBDBD"
+                android:textSize="20sp" />
+        </LinearLayout>
+    </LinearLayout>
+    <TextView
+        android:id="@+id/btn_sure"
+        android:layout_marginTop="50dp"
+        android:layout_width="match_parent"
+        android:layout_height="55dp"
+        android:gravity="center"
+        android:layout_marginStart="20dp"
+        android:layout_marginEnd="20dp"
+        android:layout_marginBottom="20dp"
+        android:text="确认修改"
+        android:textSize="20sp"
+        android:textColor="@color/white"
+        android:background="@drawable/bg_corners_05"/>
+</LinearLayout>