Merge branch 'habu_3.3.1/isolate' into habu_3.3.1/test
This commit is contained in:
@@ -78,4 +78,5 @@ public interface IInitialModel extends IModel {
|
||||
@Nullable
|
||||
FairyOpenInfo getFairyOpenInfo();
|
||||
|
||||
void regionCheck();
|
||||
}
|
||||
|
@@ -1,11 +1,14 @@
|
||||
package com.yizhuan.xchat_android_core.initial;
|
||||
|
||||
import static io.reactivex.Single.timer;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -14,6 +17,9 @@ import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.bumptech.glide.request.FutureTarget;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.chuhai.utils.LanguageUtils;
|
||||
import com.chuhai.utils.ServiceTime;
|
||||
import com.chuhai.utils.TelephonyUtils;
|
||||
import com.netease.nim.uikit.support.glide.GlideApp;
|
||||
import com.yizhuan.xchat_android_core.R;
|
||||
import com.yizhuan.xchat_android_core.DemoCache;
|
||||
@@ -49,11 +55,15 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.SingleOnSubscribe;
|
||||
import io.reactivex.SingleSource;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Action;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.functions.Function;
|
||||
@@ -131,6 +141,8 @@ public class InitialModel extends BaseModel implements IInitialModel {
|
||||
@Nullable
|
||||
private InitInfo cacheInitInfo;
|
||||
|
||||
private Disposable regionCheckTimer;
|
||||
|
||||
private InitialModel() {
|
||||
api = RxNet.create(Api.class);
|
||||
loadMainTabInfoList();
|
||||
@@ -514,6 +526,31 @@ public class InitialModel extends BaseModel implements IInitialModel {
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
/**
|
||||
* 地区检测
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void regionCheck() {
|
||||
String operatorCode;
|
||||
if (TelephonyUtils.INSTANCE.isChinaOperator()) {
|
||||
operatorCode = "460";
|
||||
} else {
|
||||
operatorCode = TelephonyUtils.INSTANCE.getOperatorFirstSim();
|
||||
}
|
||||
api.regionCheck(LanguageUtils.INSTANCE.getSystemLanguage().toLanguageTag(), operatorCode)
|
||||
.compose(RxHelper.handleSchedulers())
|
||||
.doOnSuccess(longServiceResult -> {
|
||||
if (regionCheckTimer != null && !regionCheckTimer.isDisposed()) {
|
||||
regionCheckTimer.dispose();
|
||||
}
|
||||
if (longServiceResult.isSuccess() && longServiceResult.getData() != null && longServiceResult.getData() > 0) {
|
||||
regionCheckTimer = Observable.timer(Math.max(longServiceResult.getData(), 30 * 1000), TimeUnit.MILLISECONDS).subscribe(aLong -> {
|
||||
regionCheck();
|
||||
});
|
||||
}
|
||||
}).subscribe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTeenagerMode() {
|
||||
@@ -591,5 +628,16 @@ public class InitialModel extends BaseModel implements IInitialModel {
|
||||
@GET("act/seize-treasure/status")
|
||||
Single<ServiceResult<FairyOpenInfo>> getFairyOpenInfo();
|
||||
|
||||
/**
|
||||
* 地区检测
|
||||
*
|
||||
* @param lang 语言
|
||||
* @param mcc 运营商码
|
||||
* @return
|
||||
*/
|
||||
@POST("/ipRegion/check")
|
||||
@FormUrlEncoded
|
||||
Single<ServiceResult<Long>> regionCheck(@Field("lang") String lang, @Field("mcc") String mcc);
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.chuhai.utils.TelephonyUtils;
|
||||
import com.yizhuan.xchat_android_core.auth.AuthModel;
|
||||
import com.yizhuan.xchat_android_core.utils.APIEncryptUtil;
|
||||
import com.yizhuan.xchat_android_core.utils.OaidUtil;
|
||||
@@ -34,6 +35,12 @@ public class ParamsInterceptor implements Interceptor {
|
||||
|
||||
private Map<String, String> mHttpParams;
|
||||
|
||||
// 运营商码
|
||||
private String operatorCode;
|
||||
|
||||
// 运营商码的获取时间
|
||||
private long operatorCodeTime;
|
||||
|
||||
public ParamsInterceptor(Map<String, String> params) {
|
||||
this.mHttpParams = params;
|
||||
}
|
||||
@@ -127,7 +134,6 @@ public class ParamsInterceptor implements Interceptor {
|
||||
// Log.e("ParamsInterceptor", " url: " + oldRequest.url()+ " final params Map : " + paramsMap.toString());
|
||||
// Log.e("ParamsInterceptor", "timestamp:"+timestamp + " url: " + oldRequest.url()+ " sign : " + signStr);
|
||||
|
||||
|
||||
Headers headers = oldRequest.headers().newBuilder()
|
||||
.add("pub_ticket", ticket)
|
||||
.add("pub_uid", uid == 0 ? "" : String.valueOf(uid))
|
||||
@@ -140,6 +146,7 @@ public class ParamsInterceptor implements Interceptor {
|
||||
}
|
||||
builder.addQueryParameter("pub_timestamp", timestamp);
|
||||
builder.addQueryParameter("pub_sign", signStr);
|
||||
addHeaderWithOperator(builder);
|
||||
Request newRequest = oldRequest.newBuilder()
|
||||
.method(oldRequest.method(), oldRequest.body())
|
||||
.headers(headers)
|
||||
@@ -149,5 +156,19 @@ public class ParamsInterceptor implements Interceptor {
|
||||
|
||||
}
|
||||
|
||||
private void addHeaderWithOperator(HttpUrl.Builder builder) {
|
||||
if ((System.currentTimeMillis() - operatorCodeTime) > (1000 * 60 * 10)) {
|
||||
loadOperatorCode();
|
||||
}
|
||||
builder.addQueryParameter("mcc", operatorCode);
|
||||
}
|
||||
|
||||
private void loadOperatorCode() {
|
||||
if (TelephonyUtils.INSTANCE.isChinaOperator()) {
|
||||
operatorCode = "460";
|
||||
} else {
|
||||
operatorCode = TelephonyUtils.INSTANCE.getOperatorFirstSim();
|
||||
}
|
||||
operatorCodeTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user