Merge branch 'master' into page
1 files renamed
7 files modified
| | |
| | | |
| | | public static class StringApiResult extends HttpApiResult<String> { } |
| | | |
| | | //短信验证码 |
| | | public static class SmsResult { public String sms; } |
| | | |
| | | //资讯信息 |
| | | public class Message { |
| | | public String id,title,content,cTime; |
| | |
| | | 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; |
| | |
| | | |
| | | @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); |
| | | |
| | | /** |
| | | * 重置密码 |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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<>(); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 解密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; |
| | | } |
| | | |
| | | } |
File was renamed from app/src/main/java/com/runt/open/mvvm/retrofit/converter/DecryptGsonConverterFactory.java |
| | |
| | | * |
| | | * @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; |
| | |
| | | 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; |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | 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); |
| | | } |
| | |
| | | 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); |
| | | } |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | 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>(){ |
| | |
| | | return loginResult; |
| | | } |
| | | |
| | | public MutableLiveData<Results.StringApiResult> getVerifyResult() { |
| | | public MutableLiveData<Integer> getVerifyResult() { |
| | | return verifyResult; |
| | | } |
| | | |
| | |
| | | */ |
| | | 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); |
| | | } |
| | | }); |
| | | } |
| | |
| | | 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 -> { |
| | |
| | | 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(); |
| | |
| | | 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; |
| | |
| | | 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 |