nilupeng
2022-08-09 c746c5117023148ce7d95c822f5487239b8151f1
Merge branch 'master' into page
1 files renamed
7 files modified
99 ■■■■ changed files
app/src/main/java/com/runt/open/mvvm/data/Results.java 3 ●●●●● patch | view | raw | blame | history
app/src/main/java/com/runt/open/mvvm/retrofit/api/LoginApiCenter.java 3 ●●●● patch | view | raw | blame | history
app/src/main/java/com/runt/open/mvvm/retrofit/converter/DecryptGsonResponseBodyConverter.java 27 ●●●●● patch | view | raw | blame | history
app/src/main/java/com/runt/open/mvvm/retrofit/converter/GsonConverterFactory.java 12 ●●●● patch | view | raw | blame | history
app/src/main/java/com/runt/open/mvvm/retrofit/utils/RetrofitUtils.java 10 ●●●● patch | view | raw | blame | history
app/src/main/java/com/runt/open/mvvm/ui/login/LoginViewModel.java 17 ●●●● patch | view | raw | blame | history
app/src/main/java/com/runt/open/mvvm/ui/login/RegisterLoginActivity.java 12 ●●●●● patch | view | raw | blame | history
app/src/main/java/com/runt/open/mvvm/ui/splash/SplashActivity.java 15 ●●●● patch | view | raw | blame | history
app/src/main/java/com/runt/open/mvvm/data/Results.java
@@ -13,6 +13,9 @@
    public static class StringApiResult extends HttpApiResult<String> { }
    //短信验证码
    public static class SmsResult { public String sms; }
    //资讯信息
    public class Message {
        public String id,title,content,cTime;
app/src/main/java/com/runt/open/mvvm/retrofit/api/LoginApiCenter.java
@@ -1,6 +1,7 @@
package com.runt.open.mvvm.retrofit.api;
import com.runt.open.mvvm.config.Configuration;
import com.runt.open.mvvm.data.HttpApiResult;
import com.runt.open.mvvm.data.Results;
import io.reactivex.Observable;
@@ -36,7 +37,7 @@
    @FormUrlEncoded
    @POST
    Observable<Results.StringApiResult> getVerifyCode(@Url String url, @Field(Configuration.KEY_PHONE) String phone, @Field(Configuration.KEY_CODE) String code, @Field("time") String time);
    Observable<HttpApiResult<Results.SmsResult>> getVerifyCode(@Url String url, @Field(Configuration.KEY_PHONE) String phone, @Field(Configuration.KEY_CODE) String code, @Field("time") String time);
    /**
     * 重置密码
app/src/main/java/com/runt/open/mvvm/retrofit/converter/DecryptGsonResponseBodyConverter.java
@@ -17,8 +17,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import okhttp3.ResponseBody;
import retrofit2.Converter;
@@ -34,7 +32,6 @@
    private final TypeAdapter<T> adapter;
    private final Charset UTF_8 = Charset.forName("UTF-8");
    private final boolean transHump;//驼峰转换
    private final String ENCRYPT = "encrypt";
    public DecryptGsonResponseBodyConverter(Gson gson, TypeAdapter<T> adapter, boolean transHump) {
        this.gson = gson;
@@ -47,13 +44,8 @@
        String response = null;
        try {
            String val = new String(value.bytes(),UTF_8);
            response = decryptJsonStr(val);//解密
        } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
            e.printStackTrace();
            HttpApiResult apiResult = new HttpApiResult<>();
            apiResult.code = 412;
            apiResult.msg = "解密数据出错"+e.getMessage();
            response = new Gson().toJson(apiResult);
            Log.e("Converter","val body:"+val);
            response = transHump? GsonUtils.toHumpJson(val):val;
        } catch (JSONException e) {
            e.printStackTrace();
            HttpApiResult apiResult = new HttpApiResult<>();
@@ -75,20 +67,5 @@
        }
    }
    /**
     * 解密json
     * @param body
     * @return
     * @throws Exception
     */
    protected String decryptJsonStr(String body) throws Exception {
        Log.e("Converter","decryptJsonStr body:"+body);
        /*if(body.indexOf("{") == 0) {
            JSONObject json = new JSONObject(body);
            body = json.toString();
            //body = RSAUtils.decrypt(json.getString(ENCRYPT), RSAUtils.getPublicKey(RSAUtils.PUBLIC_KEY));//
        }*/
        return transHump? GsonUtils.toHumpJson(body):body;
    }
}
app/src/main/java/com/runt/open/mvvm/retrofit/converter/GsonConverterFactory.java
File was renamed from app/src/main/java/com/runt/open/mvvm/retrofit/converter/DecryptGsonConverterFactory.java
@@ -17,26 +17,26 @@
 *
 * @purpose Created by Runt (qingingrunt2010@qq.com) on 2021-7-22.
 */
public class DecryptGsonConverterFactory extends Converter.Factory {
public class GsonConverterFactory extends Converter.Factory {
    public static DecryptGsonConverterFactory create() {
    public static GsonConverterFactory create() {
        return create(new Gson(),false);
    }
    public static DecryptGsonConverterFactory create(boolean transHump) {
    public static GsonConverterFactory create(boolean transHump) {
        return create(new Gson(),transHump);
    }
    public static DecryptGsonConverterFactory create(Gson gson,boolean transHump) {
        return new DecryptGsonConverterFactory(gson,transHump);
    public static GsonConverterFactory create(Gson gson, boolean transHump) {
        return new GsonConverterFactory(gson,transHump);
    }
    private final Gson gson;
    private final boolean transHump;
    public DecryptGsonConverterFactory(Gson gson, boolean transHump) {
    public GsonConverterFactory(Gson gson, boolean transHump) {
        if (gson == null) throw new NullPointerException("gson == null");
        this.gson = gson;
        this.transHump = transHump;
app/src/main/java/com/runt/open/mvvm/retrofit/utils/RetrofitUtils.java
@@ -5,7 +5,7 @@
import com.runt.open.mvvm.retrofit.Interceptor.EncryptInterceptor;
import com.runt.open.mvvm.retrofit.Interceptor.HttpLoggingInterceptor;
import com.runt.open.mvvm.retrofit.api.CommonApiCenter;
import com.runt.open.mvvm.retrofit.converter.DecryptGsonConverterFactory;
import com.runt.open.mvvm.retrofit.converter.GsonConverterFactory;
import com.runt.open.mvvm.retrofit.net.NetWorkListenear;
import java.util.Collections;
@@ -47,7 +47,7 @@
    public <T> T getRetrofit(Class<T> clas) {
        if(retrofit == null){
            retrofit = getRetrofit(getOkHttpClient(logBuilder),
                    new Retrofit.Builder().addConverterFactory(DecryptGsonConverterFactory.create(true))) ;
                    new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create(true))) ;
        }
        if(!BuildConfig.DEBUG){//正式版 不打印log
            return getUnLogRetrofit(clas);
@@ -62,7 +62,7 @@
    public <T> T getUnHumpRetrofit(Class<T> clas) {
        if(unHumpRetrofit == null){
            unHumpRetrofit = getRetrofit(getOkHttpClient(logBuilder),
                    new Retrofit.Builder().addConverterFactory(DecryptGsonConverterFactory.create())) ;
                    new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create())) ;
        }
        if(!BuildConfig.DEBUG){//正式版 不打印log
            return getUnLogHumpRetorfit(clas);
@@ -77,7 +77,7 @@
    public <T> T  getUnLogRetrofit(Class<T> clas) {
        if(unLogRetrofit == null){
            unLogRetrofit = getRetrofit(getOkHttpClient(builder),
                    new Retrofit.Builder().addConverterFactory(DecryptGsonConverterFactory.create(true))) ;
                    new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create(true))) ;
        }
        return unLogRetrofit.create(clas);
    }
@@ -89,7 +89,7 @@
    public <T> T getUnLogHumpRetorfit(Class<T> clas) {
        if(unLogHumpRetorfit == null){
            unLogHumpRetorfit = getRetrofit(getOkHttpClient(builder),
                    new Retrofit.Builder().addConverterFactory(DecryptGsonConverterFactory.create())) ;
                    new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create())) ;
        }
        return unLogHumpRetorfit.create(clas);
    }
app/src/main/java/com/runt/open/mvvm/ui/login/LoginViewModel.java
@@ -3,6 +3,7 @@
import androidx.lifecycle.MutableLiveData;
import com.runt.open.mvvm.base.model.BaseViewModel;
import com.runt.open.mvvm.data.HttpApiResult;
import com.runt.open.mvvm.data.Results;
import com.runt.open.mvvm.retrofit.api.LoginApiCenter;
import com.runt.open.mvvm.retrofit.observable.HttpObserver;
@@ -26,7 +27,7 @@
    }
    MutableLiveData<Results.LoggedInUser> loginResult = new MutableLiveData<>();
    MutableLiveData<Results.StringApiResult> verifyResult = new MutableLiveData<>();
    MutableLiveData<Integer> verifyResult = new MutableLiveData<>();
    MutableLiveData<Results.StringApiResult> resetResult = new MutableLiveData<>();
    MutableLiveData<Results.StringApiResult> registerResult = new MutableLiveData<>();
    HttpObserver<Results.LoggedInUser> logginObserver = new HttpObserver<Results.LoggedInUser>(){
@@ -39,7 +40,7 @@
        return loginResult;
    }
    public MutableLiveData<Results.StringApiResult> getVerifyResult() {
    public MutableLiveData<Integer> getVerifyResult() {
        return verifyResult;
    }
@@ -119,10 +120,16 @@
     */
    public void getVerifyCode(String url,String phone){
        String time = new Date().getTime()+"";
        httpObserverOnLoading(loginApi.getVerifyCode(url, phone, randomString(phone, time), time), new HttpObserver<Results.StringApiResult>(){
        httpObserverOnLoading(loginApi.getVerifyCode(url, phone, randomString(phone, time), time), new HttpObserver<Results.SmsResult>(){
            @Override
            protected void onSuccess(Results.StringApiResult data) {
                verifyResult.setValue(data);
            protected void onSuccess(Results.SmsResult data) {
                verifyResult.setValue(0);
            }
            @Override
            protected void onFailed(HttpApiResult httpResult) {
                super.onFailed(httpResult);
                verifyResult.setValue(-1);
            }
        });
    }
app/src/main/java/com/runt/open/mvvm/ui/login/RegisterLoginActivity.java
@@ -35,11 +35,13 @@
        mBinding.txtRegister.setOnClickListener(onclick);
        mBinding.txtPrivacy.setOnClickListener(onclick);
        mBinding.editPhone.setText(getStringProjectPrefrence(Configuration.KEY_USERNAME));
        mViewModel.getVerifyResult().observe(this, stringApiResult -> {
           if(stringApiResult.code == 200){
        mViewModel.getVerifyResult().observe(this, result -> {
           if(result == 0){
               putLongProjectPrefrence(VERIFY_CODE,new Date().getTime());
               CodeTimer codeTimer = new CodeTimer(60000, 1000, mBinding.txtGetVerify);
               codeTimer.startUp();
           }else{
               showToast(stringApiResult.msg);
           }
        });
        mViewModel.getLoginResult().observe(this, loggedInUser -> {
@@ -65,7 +67,7 @@
        long getTime = getLongProjectPrefrence(VERIFY_CODE);
        long cha = new Date().getTime() - getTime;
        if(cha <1000*60){
            CodeTimer codeTimer = new CodeTimer(cha, 1000, mBinding.txtGetVerify);
            CodeTimer codeTimer = new CodeTimer((60) * 1000-cha, 1000, mBinding.txtGetVerify);
            codeTimer.startUp();
        }
        changeView();
app/src/main/java/com/runt/open/mvvm/ui/splash/SplashActivity.java
@@ -1,7 +1,9 @@
package com.runt.open.mvvm.ui.splash;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;
import com.runt.open.mvvm.base.activities.BaseActivity;
@@ -20,9 +22,16 @@
    final String TAG = "WelcomeActivity";
    @Override
    public void initViews() {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);//全屏
        hideBottomUIMenu();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            // 延伸显示区域到刘海
            WindowManager.LayoutParams attributes = getWindow().getAttributes();
            attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
            getWindow().setAttributes(attributes);
        }
        // 设置页面全屏显示 隐藏底部导航
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
    @Override