2021-04-20 17:35:42 +08:00
|
|
|
|
package com.yizhuan.erban.application;
|
|
|
|
|
|
2021-11-19 16:31:47 +08:00
|
|
|
|
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_HEADER_TYPE_OPEN_ROOM_NOTI;
|
|
|
|
|
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import android.annotation.SuppressLint;
|
2022-10-19 16:39:34 +08:00
|
|
|
|
import android.app.Activity;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import android.app.Application;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.net.http.HttpResponseCache;
|
|
|
|
|
import android.os.Build;
|
2021-08-10 18:19:59 +08:00
|
|
|
|
import android.provider.Settings;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
import androidx.multidex.MultiDex;
|
|
|
|
|
|
|
|
|
|
import com.bumptech.glide.request.target.ViewTarget;
|
|
|
|
|
import com.coorchice.library.utils.LogUtils;
|
2021-11-16 15:00:41 +08:00
|
|
|
|
import com.hjq.toast.ToastUtils;
|
2021-09-09 17:09:45 +08:00
|
|
|
|
import com.mob.MobSDK;
|
2022-10-19 16:39:34 +08:00
|
|
|
|
import com.mob.moblink.MobLink;
|
|
|
|
|
import com.mob.moblink.RestoreSceneListener;
|
|
|
|
|
import com.mob.moblink.Scene;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import com.netease.nim.uikit.api.NimUIKit;
|
|
|
|
|
import com.netease.nim.uikit.common.util.log.LogUtil;
|
|
|
|
|
import com.netease.nimlib.sdk.NIMClient;
|
|
|
|
|
import com.netease.nimlib.sdk.NotificationFoldStyle;
|
|
|
|
|
import com.netease.nimlib.sdk.SDKOptions;
|
|
|
|
|
import com.netease.nimlib.sdk.StatusBarNotificationConfig;
|
|
|
|
|
import com.netease.nimlib.sdk.mixpush.MixPushConfig;
|
|
|
|
|
import com.netease.nimlib.sdk.mixpush.NIMPushClient;
|
|
|
|
|
import com.netease.nimlib.sdk.msg.MessageNotifierCustomization;
|
|
|
|
|
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
|
|
|
|
|
import com.netease.nimlib.sdk.msg.model.IMMessage;
|
2022-06-24 11:04:47 +08:00
|
|
|
|
import com.netease.nimlib.sdk.util.NIMUtil;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import com.opensource.svgaplayer.SVGAParser;
|
|
|
|
|
import com.orhanobut.logger.AndroidLogAdapter;
|
|
|
|
|
import com.orhanobut.logger.Logger;
|
|
|
|
|
import com.scwang.smartrefresh.header.MaterialHeader;
|
|
|
|
|
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
|
|
|
|
|
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
|
2021-12-20 10:27:23 +08:00
|
|
|
|
import com.tencent.vasdolly.helper.ChannelReaderUtil;
|
2022-10-19 16:39:34 +08:00
|
|
|
|
import com.yizhuan.erban.AgentActivity;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import com.yizhuan.erban.BuildConfig;
|
|
|
|
|
import com.yizhuan.erban.NimMiddleActivity;
|
|
|
|
|
import com.yizhuan.erban.R;
|
2022-11-16 17:46:15 +08:00
|
|
|
|
import com.yizhuan.erban.common.app.ActivityStack;
|
|
|
|
|
import com.yizhuan.erban.common.util.AppLifeCycleHelper;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import com.yizhuan.erban.module_hall.HallDataManager;
|
2021-09-09 17:09:45 +08:00
|
|
|
|
import com.yizhuan.erban.other.activity.SplashActivity;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import com.yizhuan.erban.radish.wallet.RadishWalletManager;
|
|
|
|
|
import com.yizhuan.erban.utils.PushMessageHandler;
|
|
|
|
|
import com.yizhuan.xchat_android_constants.XChatConstants;
|
|
|
|
|
import com.yizhuan.xchat_android_core.Constants;
|
|
|
|
|
import com.yizhuan.xchat_android_core.DemoCache;
|
|
|
|
|
import com.yizhuan.xchat_android_core.UriProvider;
|
|
|
|
|
import com.yizhuan.xchat_android_core.auth.AuthModel;
|
2021-06-22 17:31:01 +08:00
|
|
|
|
import com.yizhuan.xchat_android_core.bean.response.ServiceResult;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import com.yizhuan.xchat_android_core.channel.ChannelModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.family.model.FamilyModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.gift.GiftModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment;
|
|
|
|
|
import com.yizhuan.xchat_android_core.im.custom.bean.OpenSignInAttachment;
|
|
|
|
|
import com.yizhuan.xchat_android_core.initial.InitialModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.interceptor.NoParamsInterceptor;
|
|
|
|
|
import com.yizhuan.xchat_android_core.interceptor.ParamsInterceptor;
|
|
|
|
|
import com.yizhuan.xchat_android_core.manager.IMMessageManager;
|
|
|
|
|
import com.yizhuan.xchat_android_core.manager.IMSystemMsgManager;
|
|
|
|
|
import com.yizhuan.xchat_android_core.market_verify.MarketVerifyModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.mentoring_relationship.model.MentoringRelationshipModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.pay.PayModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.public_chat_hall.model.PublicChatHallModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.radish.RadishModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.radish.signin.bean.ImNotice;
|
|
|
|
|
import com.yizhuan.xchat_android_core.room.face.DynamicFaceModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.user.UserModel;
|
2021-06-22 17:31:01 +08:00
|
|
|
|
import com.yizhuan.xchat_android_core.user.event.NeedCompleteInfoEvent;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import com.yizhuan.xchat_android_core.utils.SharedPreferenceUtils;
|
2021-06-22 17:31:01 +08:00
|
|
|
|
import com.yizhuan.xchat_android_core.utils.net.ServerException;
|
2022-12-01 20:35:52 +08:00
|
|
|
|
import com.yizhuan.xchat_android_library.common.application.BaseApp;
|
2022-12-05 20:47:11 +08:00
|
|
|
|
import com.yizhuan.xchat_android_library.common.application.Env;
|
2022-12-09 16:19:23 +08:00
|
|
|
|
import com.yizhuan.xchat_android_library.common.file.FileHelper;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import com.yizhuan.xchat_android_library.net.rxnet.RxNet;
|
2021-06-22 17:31:01 +08:00
|
|
|
|
import com.yizhuan.xchat_android_library.net.rxnet.converter.GsonConverterPlugins;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import com.yizhuan.xchat_android_library.utils.AppMetaDataUtil;
|
|
|
|
|
import com.yizhuan.xchat_android_library.utils.AppUtils;
|
|
|
|
|
import com.yizhuan.xchat_android_library.utils.DeviceUuidFactory;
|
2022-10-14 15:55:31 +08:00
|
|
|
|
import com.yizhuan.xchat_android_library.utils.ResUtil;
|
2021-06-22 17:31:01 +08:00
|
|
|
|
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import com.yizhuan.xchat_android_library.utils.SystemUtils;
|
|
|
|
|
import com.yizhuan.xchat_android_library.utils.VersionUtil;
|
2021-08-10 18:19:59 +08:00
|
|
|
|
import com.yizhuan.xchat_android_library.utils.codec.MD5Utils;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import com.yizhuan.xchat_android_library.utils.config.BasicConfig;
|
|
|
|
|
|
2021-06-22 17:31:01 +08:00
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
2022-12-05 20:47:11 +08:00
|
|
|
|
import java.util.HashMap;
|
2023-05-23 11:34:26 +08:00
|
|
|
|
import java.util.Locale;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
import java.util.Map;
|
2022-05-11 11:26:51 +08:00
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2021-04-20 17:35:42 +08:00
|
|
|
|
|
|
|
|
|
import io.reactivex.plugins.RxJavaPlugins;
|
|
|
|
|
import io.realm.Realm;
|
|
|
|
|
import io.realm.RealmConfiguration;
|
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
/**
|
|
|
|
|
* @author chenran
|
|
|
|
|
* @date 2017/2/11
|
|
|
|
|
*/
|
|
|
|
|
|
2022-12-01 20:35:52 +08:00
|
|
|
|
public class XChatApplication extends BaseApp {
|
2020-04-02 10:43:40 +08:00
|
|
|
|
public static final String TAG = "XChatApplication";
|
2022-10-19 16:42:06 +08:00
|
|
|
|
public static Application gContext;
|
2021-12-10 15:30:58 +08:00
|
|
|
|
private static final MessageNotifierCustomization messageNotifierCustomization = new MessageNotifierCustomization() {
|
|
|
|
|
@Override
|
|
|
|
|
public String makeNotifyContent(String nick, IMMessage message) {
|
|
|
|
|
if (message.getMsgType() == MsgTypeEnum.custom) {
|
|
|
|
|
CustomAttachment customAttachment = (CustomAttachment) message.getAttachment();
|
|
|
|
|
if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_OPEN_ROOM_NOTI) {
|
|
|
|
|
return message.getFromNick();
|
|
|
|
|
} else if (customAttachment instanceof OpenSignInAttachment) {
|
|
|
|
|
return getContentFromOpenSignIn(customAttachment);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 采用SDK默认文案
|
2022-10-14 15:55:31 +08:00
|
|
|
|
return ResUtil.getString(R.string.erban_application_xchatapplication_01);
|
2021-12-10 15:30:58 +08:00
|
|
|
|
}
|
2020-06-08 20:54:09 +08:00
|
|
|
|
|
2021-12-10 15:30:58 +08:00
|
|
|
|
@Override
|
|
|
|
|
public String makeTicker(String nick, IMMessage message) {
|
|
|
|
|
if (message.getMsgType() == MsgTypeEnum.custom) {
|
|
|
|
|
CustomAttachment customAttachment = (CustomAttachment) message.getAttachment();
|
|
|
|
|
if (customAttachment != null) {
|
|
|
|
|
if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_OPEN_ROOM_NOTI) {
|
|
|
|
|
return message.getFromNick();
|
|
|
|
|
} else if (customAttachment instanceof OpenSignInAttachment) {
|
|
|
|
|
return getContentFromOpenSignIn(customAttachment);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 采用SDK默认文案
|
2022-10-14 15:55:31 +08:00
|
|
|
|
return ResUtil.getString(R.string.erban_application_xchatapplication_02);
|
2021-12-10 15:30:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getContentFromOpenSignIn(CustomAttachment attachment) {
|
|
|
|
|
String result = null;
|
|
|
|
|
if (attachment instanceof OpenSignInAttachment) {
|
|
|
|
|
ImNotice notice = ((OpenSignInAttachment) attachment).getImNotice();
|
|
|
|
|
if (notice != null) {
|
|
|
|
|
result = notice.getContent();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (TextUtils.isEmpty(result)) {
|
2022-10-14 15:55:31 +08:00
|
|
|
|
result = ResUtil.getString(R.string.erban_application_xchatapplication_03);
|
2021-12-10 15:30:58 +08:00
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2020-04-02 10:43:40 +08:00
|
|
|
|
|
2021-12-10 15:30:58 +08:00
|
|
|
|
@Override
|
|
|
|
|
public String makeRevokeMsgTip(String s, IMMessage imMessage) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
private static XChatApplication instance;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
//生命周期监听
|
2022-11-16 17:46:15 +08:00
|
|
|
|
private static AppLifeCycleHelper lifeCycleHelper;
|
|
|
|
|
public static ActivityStack gStack = new ActivityStack();
|
2021-12-10 15:30:58 +08:00
|
|
|
|
private static boolean isInitOtherSDK = false;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
|
|
|
|
|
//static 代码段可以防止内存泄露
|
|
|
|
|
static {
|
|
|
|
|
SmartRefreshLayout.setDefaultRefreshHeaderCreater(
|
|
|
|
|
(context, layout) -> {
|
|
|
|
|
layout.setEnableHeaderTranslationContent(false);
|
|
|
|
|
MaterialHeader materialHeader = new MaterialHeader(context);
|
|
|
|
|
materialHeader.setShowBezierWave(false);
|
|
|
|
|
return materialHeader;
|
|
|
|
|
});
|
|
|
|
|
SmartRefreshLayout.setDefaultRefreshFooterCreater(
|
|
|
|
|
(context, layout) -> new ClassicsFooter(context).setDrawableSize(20));
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-10 15:30:58 +08:00
|
|
|
|
public static XChatApplication instance() {
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void initOtherSDK() {
|
|
|
|
|
if (isInitOtherSDK) return;
|
|
|
|
|
isInitOtherSDK = true;
|
|
|
|
|
Context context = BasicConfig.INSTANCE.getAppContext();
|
|
|
|
|
Application application = (Application) context.getApplicationContext();
|
|
|
|
|
// 初始化 sp
|
2020-12-01 14:22:11 +08:00
|
|
|
|
long startTime = System.currentTimeMillis();
|
2021-12-10 15:30:58 +08:00
|
|
|
|
|
2021-09-27 15:47:21 +08:00
|
|
|
|
String channel = "";
|
2022-05-11 11:26:51 +08:00
|
|
|
|
channel = ChannelReaderUtil.getChannel(instance);
|
2020-05-12 12:31:13 +08:00
|
|
|
|
if (TextUtils.isEmpty(channel)) {
|
2022-11-08 14:59:51 +08:00
|
|
|
|
channel = Constants.GOOGLE;
|
2020-05-12 12:31:13 +08:00
|
|
|
|
}
|
2021-09-27 15:47:21 +08:00
|
|
|
|
|
|
|
|
|
BasicConfig.INSTANCE.setOriginalChannel(channel);
|
|
|
|
|
|
|
|
|
|
BasicConfig.INSTANCE.setChannel(channel);
|
|
|
|
|
|
|
|
|
|
initEnv();
|
2020-04-07 16:41:24 +08:00
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
//延迟初始化云信
|
2021-12-10 15:30:58 +08:00
|
|
|
|
NIMClient.init(context, null, options());
|
2020-04-02 10:43:40 +08:00
|
|
|
|
|
|
|
|
|
//logger 配置
|
|
|
|
|
Logger.addLogAdapter(new AndroidLogAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isLoggable(int priority, String tag) {
|
2021-02-24 15:15:03 +08:00
|
|
|
|
return BuildConfig.DEBUG;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-10 15:30:58 +08:00
|
|
|
|
ToastUtils.init(application);
|
2021-11-16 15:00:41 +08:00
|
|
|
|
|
2021-12-10 15:30:58 +08:00
|
|
|
|
if (inMainProcess(context)) {
|
2022-08-01 17:04:27 +08:00
|
|
|
|
DemoCache.saveLaunchCount();
|
2021-06-22 17:31:01 +08:00
|
|
|
|
// 注册自定义推送消息处理,这个是可选项
|
2020-08-04 20:39:21 +08:00
|
|
|
|
NIMPushClient.registerMixPushMessageHandler(new PushMessageHandler());
|
2021-06-22 17:31:01 +08:00
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
RxJavaPlugins.setErrorHandler(throwable -> {
|
2021-06-22 17:31:01 +08:00
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
|
Log.e(TAG, "the subscribe() method default error handler", throwable);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//需要完善资料错误码全局处理
|
|
|
|
|
GsonConverterPlugins.setResultHandler(result -> {
|
|
|
|
|
if (result instanceof ServiceResult<?>) {
|
|
|
|
|
ServiceResult<?> serviceResult = (ServiceResult<?>) result;
|
|
|
|
|
if (serviceResult.getCode() == ServiceResult.CODE_NEED_COMPLETE_USER_INFO) {
|
|
|
|
|
SingleToastUtil.showToast(serviceResult.getMessage());
|
|
|
|
|
EventBus.getDefault().post(new NeedCompleteInfoEvent());
|
|
|
|
|
throw new ServerException(serviceResult.getMessage(), serviceResult.getCode());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
});
|
2021-06-22 17:31:01 +08:00
|
|
|
|
GsonConverterPlugins.lockdown();
|
|
|
|
|
|
2022-10-19 16:39:34 +08:00
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
//fixed: Glide Exception:"You must not call setTag() on a view Glide is targeting"
|
|
|
|
|
ViewTarget.setTagId(R.id.tag_glide);
|
|
|
|
|
|
|
|
|
|
init(channel);
|
|
|
|
|
|
|
|
|
|
//生命周期监听
|
2022-11-16 17:46:15 +08:00
|
|
|
|
if (lifeCycleHelper == null) {
|
|
|
|
|
lifeCycleHelper = new AppLifeCycleHelper();
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
2022-11-16 17:46:15 +08:00
|
|
|
|
registerActivityLifecycleCallback(lifeCycleHelper);
|
2022-06-24 11:04:47 +08:00
|
|
|
|
initLinkedMe();
|
|
|
|
|
MobSDK.init(context);
|
2022-08-29 11:35:39 +08:00
|
|
|
|
MobSDK.submitPolicyGrantResult(true);
|
2021-04-13 19:04:28 +08:00
|
|
|
|
}
|
2022-06-24 11:04:47 +08:00
|
|
|
|
|
2022-06-23 16:07:55 +08:00
|
|
|
|
LogUtils.d("init time = " + (System.currentTimeMillis() - startTime) + "ms");
|
|
|
|
|
|
2021-09-09 17:09:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 17:46:15 +08:00
|
|
|
|
public static void registerActivityLifecycleCallback(Application.ActivityLifecycleCallbacks callbacks) {
|
|
|
|
|
((Application) BasicConfig.INSTANCE.getAppContext().getApplicationContext()).registerActivityLifecycleCallbacks(callbacks);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
/**
|
|
|
|
|
* 初始化linkedMe
|
|
|
|
|
*/
|
2021-12-10 15:30:58 +08:00
|
|
|
|
private static void initLinkedMe() {
|
2022-10-19 16:39:34 +08:00
|
|
|
|
MobSDK.init(instance, "36b91eeac7469", "63ec0702513aca17e20615dd5dfdc03f");
|
|
|
|
|
MobLink.setRestoreSceneListener(new RestoreSceneListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public Class<? extends Activity> willRestoreScene(Scene scene) {
|
|
|
|
|
return AgentActivity.class;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void completeRestore(Scene scene) {
|
|
|
|
|
}
|
2022-09-15 15:17:31 +08:00
|
|
|
|
|
2022-10-19 16:39:34 +08:00
|
|
|
|
@Override
|
|
|
|
|
public void notFoundScene(Scene scene) {
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 16:39:34 +08:00
|
|
|
|
|
2021-12-10 15:30:58 +08:00
|
|
|
|
private static void initEnv() {
|
2020-04-02 10:43:40 +08:00
|
|
|
|
//首先初始化环境
|
|
|
|
|
Env.initEnv(BuildConfig.BUILD_TYPE, BuildConfig.DEBUG);
|
|
|
|
|
//切换生产坏境和测试环境 true/测试环境 false/生产环境
|
|
|
|
|
BasicConfig.INSTANCE.setDebuggable(Env.isDebug());
|
|
|
|
|
BasicConfig.INSTANCE.setRootDir(Constants.ERBAN_DIR_NAME);
|
|
|
|
|
BasicConfig.INSTANCE.setLogDir(Constants.LOG_DIR);
|
|
|
|
|
BasicConfig.INSTANCE.setConfigDir(Constants.CONFIG_DIR);
|
|
|
|
|
BasicConfig.INSTANCE.setVoiceDir(Constants.VOICE_DIR);
|
|
|
|
|
BasicConfig.INSTANCE.setCacheDir(Constants.CACHE_DIR);
|
|
|
|
|
BasicConfig.INSTANCE.setImageDir(Constants.IMAGE_CACHE_DIR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 云信配置
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2021-12-10 15:30:58 +08:00
|
|
|
|
public static SDKOptions options() {
|
2020-04-02 10:43:40 +08:00
|
|
|
|
SDKOptions options = new SDKOptions();
|
|
|
|
|
options.disableAwake = true;
|
|
|
|
|
options.asyncInitSDK = true;
|
2020-08-04 20:39:21 +08:00
|
|
|
|
// options.customPushContentType = "";
|
2020-04-02 10:43:40 +08:00
|
|
|
|
if (isDebug()) {
|
|
|
|
|
options.checkManifestConfig = true;
|
|
|
|
|
}
|
|
|
|
|
// 如果将新消息通知提醒托管给 SDK 完成,需要添加以下配置。否则无需设置。
|
|
|
|
|
StatusBarNotificationConfig config = new StatusBarNotificationConfig();
|
|
|
|
|
// 点击通知栏跳转到该Activity
|
|
|
|
|
config.notificationEntrance = NimMiddleActivity.class;
|
|
|
|
|
// config.notificationSmallIconId = R.drawable.icon_msg_normal;
|
|
|
|
|
// 呼吸灯配置
|
|
|
|
|
config.ledARGB = Color.GREEN;
|
|
|
|
|
config.ledOnMs = 1000;
|
|
|
|
|
config.ledOffMs = 1500;
|
2020-07-31 19:43:17 +08:00
|
|
|
|
config.notificationFoldStyle = NotificationFoldStyle.CONTACT;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
// 通知铃声的uri字符串
|
|
|
|
|
config.notificationSound = "android.resource://com.netease.nim.demo/raw/msg";
|
|
|
|
|
options.statusBarNotificationConfig = config;
|
|
|
|
|
// 定制通知栏提醒文案(可选,如果不定制将采用SDK默认文案)
|
|
|
|
|
options.messageNotifierCustomization = messageNotifierCustomization;
|
|
|
|
|
|
|
|
|
|
options.appKey = Constants.nimAppKey;
|
|
|
|
|
|
|
|
|
|
// 配置保存图片,文件,log 等数据的目录
|
|
|
|
|
// 如果 options 中没有设置这个值,SDK 会使用下面代码示例中的位置作为 SDK 的数据目录。
|
|
|
|
|
// 该目录目前包含 log, file, image, audio, video, thumb 这6个目录。
|
|
|
|
|
// 如果第三方 APP 需要缓存清理功能, 清理这个目录下面个子目录的内容即可。
|
|
|
|
|
String sdkPath = null;
|
|
|
|
|
try {
|
2022-12-21 15:54:19 +08:00
|
|
|
|
sdkPath = FileHelper.getRootCacheDir().getAbsolutePath() + "/nim";
|
2020-04-02 10:43:40 +08:00
|
|
|
|
} catch (ArrayIndexOutOfBoundsException e) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
options.sdkStorageRootPath = sdkPath;
|
|
|
|
|
|
|
|
|
|
// 配置是否需要预下载附件缩略图,默认为 true
|
|
|
|
|
options.preloadAttach = true;
|
|
|
|
|
|
|
|
|
|
// 配置附件缩略图的尺寸大小。表示向服务器请求缩略图文件的大小
|
|
|
|
|
// 该值一般应根据屏幕尺寸来确定, 默认值为 Screen.width / 2
|
2021-12-10 15:30:58 +08:00
|
|
|
|
int widthPixels = BasicConfig.INSTANCE.getAppContext().getResources().getDisplayMetrics().widthPixels;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
options.thumbnailSize = widthPixels / 2;
|
|
|
|
|
// // save cache,留做切换账号备用
|
|
|
|
|
DemoCache.setNotificationConfig(config);
|
|
|
|
|
|
2020-05-07 18:51:04 +08:00
|
|
|
|
MixPushConfig mixPushConfig = new MixPushConfig();
|
2022-09-15 15:17:31 +08:00
|
|
|
|
|
|
|
|
|
|
2020-05-07 18:51:04 +08:00
|
|
|
|
options.mixPushConfig = mixPushConfig;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
|
|
|
|
|
return options;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断当前进程是否主进程
|
|
|
|
|
*
|
|
|
|
|
* @param context
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private static boolean inMainProcess(Context context) {
|
|
|
|
|
String packageName = context.getPackageName();
|
2022-06-24 11:04:47 +08:00
|
|
|
|
String processName = NIMUtil.getProcessName(context);
|
2020-04-02 10:43:40 +08:00
|
|
|
|
return packageName.equals(processName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化RxNet
|
|
|
|
|
*
|
|
|
|
|
* @param context
|
|
|
|
|
* @param url
|
|
|
|
|
*/
|
|
|
|
|
@SuppressLint("CheckResult")
|
2021-12-10 15:30:58 +08:00
|
|
|
|
public static void initRxNet(Context context, String url) {
|
2022-05-11 11:26:51 +08:00
|
|
|
|
Map<String, String> httpParams = new ConcurrentHashMap<>();
|
2020-04-02 10:43:40 +08:00
|
|
|
|
httpParams.put("os", "android");
|
|
|
|
|
httpParams.put("osVersion", Build.VERSION.RELEASE);
|
2021-04-01 17:00:46 +08:00
|
|
|
|
httpParams.put("app", XChatConstants.APP_MARK);
|
2020-04-02 10:43:40 +08:00
|
|
|
|
httpParams.put("ispType", String.valueOf(SystemUtils.getIspType(context)));
|
|
|
|
|
httpParams.put("netType", String.valueOf(SystemUtils.getNetworkType(context)));
|
|
|
|
|
httpParams.put("model", SystemUtils.getPhoneModel());
|
|
|
|
|
httpParams.put("appVersion", VersionUtil.getLocalName(context));
|
|
|
|
|
httpParams.put("appVersionCode", String.valueOf(AppUtils.getVersionCode(context)));
|
|
|
|
|
httpParams.put("deviceId", DeviceUuidFactory.getDeviceId(context));
|
2021-08-10 18:19:59 +08:00
|
|
|
|
httpParams.put("androidId", MD5Utils.getMD5String(Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID)));
|
2020-04-02 10:43:40 +08:00
|
|
|
|
httpParams.put("channel", AppMetaDataUtil.getChannelID());
|
|
|
|
|
RxNet.init(context)
|
2020-05-14 19:34:53 +08:00
|
|
|
|
.debug(BuildConfig.DEBUG)
|
2020-04-02 10:43:40 +08:00
|
|
|
|
.setBaseUrl(url)
|
|
|
|
|
.addInterceptors(new ParamsInterceptor(httpParams))
|
|
|
|
|
.addInterceptors(new NoParamsInterceptor())//注意:拦截器的添加顺序,请求的拦截顺序
|
|
|
|
|
.certificates()
|
|
|
|
|
.build();
|
|
|
|
|
//单例的model 初始化
|
|
|
|
|
initModel();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-10 15:30:58 +08:00
|
|
|
|
private static void init(String channel) {
|
2020-04-02 10:43:40 +08:00
|
|
|
|
initNimUIKit();
|
|
|
|
|
UriProvider.initUri(BuildConfig.BASE_URL_DEBUG, BuildConfig.BASE_URL_STAGING, BuildConfig.BASE_URL_RELEASE);
|
2021-12-10 15:30:58 +08:00
|
|
|
|
SVGAParser.Companion.shareParser().init(BasicConfig.INSTANCE.getAppContext());
|
2020-04-02 10:43:40 +08:00
|
|
|
|
try {
|
|
|
|
|
/** svga动画缓存路径 */
|
2021-12-10 15:30:58 +08:00
|
|
|
|
File cacheDir = new File(BasicConfig.INSTANCE.getAppContext().getApplicationContext().getExternalCacheDir(), "http");
|
2020-04-02 10:43:40 +08:00
|
|
|
|
if (!cacheDir.exists()) cacheDir.mkdirs();
|
|
|
|
|
HttpResponseCache.install(cacheDir, 1024 * 1024 * 128);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
Log.e(TAG, "testtest", e);
|
|
|
|
|
}
|
2020-12-01 14:22:11 +08:00
|
|
|
|
|
2020-04-02 10:43:40 +08:00
|
|
|
|
initRxNet(BasicConfig.INSTANCE.getAppContext(), UriProvider.JAVA_WEB_URL);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 使用到realm 数据库,这里配置数据库 这里必须先于模块初始化前进行初始化配置
|
|
|
|
|
*/
|
|
|
|
|
Realm.init(BasicConfig.INSTANCE.getAppContext());
|
|
|
|
|
RealmConfiguration config = new RealmConfiguration.Builder()
|
2020-04-03 16:54:53 +08:00
|
|
|
|
.name("accompany.realm")
|
2020-04-02 10:43:40 +08:00
|
|
|
|
.deleteRealmIfMigrationNeeded()
|
|
|
|
|
.build();
|
|
|
|
|
Realm.setDefaultConfiguration(config);
|
|
|
|
|
|
|
|
|
|
LogUtil.i(TAG, channel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 一些单例的 model
|
|
|
|
|
*/
|
2021-12-10 15:30:58 +08:00
|
|
|
|
private static void initModel() {
|
2020-04-02 10:43:40 +08:00
|
|
|
|
DynamicFaceModel.get().init();
|
|
|
|
|
PayModel.get();
|
|
|
|
|
UserModel.get();
|
|
|
|
|
//ui层的萝卜钱包
|
|
|
|
|
RadishWalletManager.get();
|
|
|
|
|
//model层的
|
|
|
|
|
RadishModel.get();
|
|
|
|
|
|
|
|
|
|
IMMessageManager.get().init();
|
|
|
|
|
IMSystemMsgManager.get().init();
|
|
|
|
|
|
|
|
|
|
FamilyModel.Instance();
|
|
|
|
|
AuthModel.get();
|
|
|
|
|
|
|
|
|
|
ChannelModel.get();
|
|
|
|
|
MarketVerifyModel.get();
|
|
|
|
|
GiftModel.get();
|
|
|
|
|
PublicChatHallModel.get();
|
|
|
|
|
// 模厅
|
|
|
|
|
HallDataManager.get().application();
|
|
|
|
|
// 师徒
|
|
|
|
|
MentoringRelationshipModel.get();
|
|
|
|
|
//全局处理
|
|
|
|
|
GlobalHandleManager.get().init();
|
2020-12-01 14:22:11 +08:00
|
|
|
|
|
|
|
|
|
InitialModel.get().init(true).subscribe();
|
|
|
|
|
|
2022-11-10 21:39:52 +08:00
|
|
|
|
//上报平台初始化
|
|
|
|
|
ReportManager.get().init();
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-10 15:30:58 +08:00
|
|
|
|
private static void initNimUIKit() {
|
2020-04-02 10:43:40 +08:00
|
|
|
|
// 初始化
|
2021-12-10 15:30:58 +08:00
|
|
|
|
NimUIKit.init(BasicConfig.INSTANCE.getAppContext());
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* debug 环境 受到实验室模式影响
|
|
|
|
|
*/
|
|
|
|
|
public static boolean isDebug() {
|
|
|
|
|
return Env.isDebug();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 是否是真实的debug的环境 不受实验室模式影响
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static boolean isRealDebug() {
|
|
|
|
|
return Env.isRealDebug();
|
|
|
|
|
}
|
2021-12-10 15:30:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户没同意隐私协议之前,啥也不干!!
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreate() {
|
|
|
|
|
super.onCreate();
|
|
|
|
|
instance = this;
|
2022-12-09 16:19:23 +08:00
|
|
|
|
BaseApp.init(this);
|
2021-12-10 15:30:58 +08:00
|
|
|
|
BasicConfig.INSTANCE.setAppContext(this.getApplicationContext());
|
|
|
|
|
SharedPreferenceUtils.init(this);
|
2022-10-14 15:55:31 +08:00
|
|
|
|
ResUtil.init(this);
|
2021-12-10 15:30:58 +08:00
|
|
|
|
boolean isShowPrivacyAgreement = (boolean) SharedPreferenceUtils.get(SplashActivity.SHOW_PRIVACY_AGREEMENT, true);
|
|
|
|
|
if (!isShowPrivacyAgreement) {
|
|
|
|
|
initOtherSDK();
|
|
|
|
|
}
|
2022-10-19 16:42:06 +08:00
|
|
|
|
initContext(this);
|
2022-12-05 20:47:11 +08:00
|
|
|
|
//首次启动事件
|
|
|
|
|
HashMap<String, Object> map = new HashMap<>(2);
|
|
|
|
|
map.put(IReportConstants.MODULE, IReportConstants.PEKO_ACTIVATE);
|
|
|
|
|
ReportManager.get().reportEvent(IReportConstants.ACTIVATE_FIRST, map);
|
2022-10-19 16:42:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化Application实例
|
|
|
|
|
*/
|
|
|
|
|
public void initContext(Application application) {
|
|
|
|
|
gContext = application;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return 获取Application实例
|
|
|
|
|
*/
|
|
|
|
|
public static Application getApplication() {
|
|
|
|
|
return gContext;
|
2021-12-10 15:30:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void attachBaseContext(Context base) {
|
|
|
|
|
super.attachBaseContext(base);
|
|
|
|
|
MultiDex.install(base);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onTerminate() {
|
|
|
|
|
super.onTerminate();
|
|
|
|
|
GlobalHandleManager.get().unInit();
|
2022-11-16 17:46:15 +08:00
|
|
|
|
if (lifeCycleHelper != null) {
|
|
|
|
|
unregisterActivityLifecycleCallbacks(lifeCycleHelper);
|
|
|
|
|
}
|
2021-12-10 15:30:58 +08:00
|
|
|
|
}
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|