From 5b5c35da79939ad7f91f4f8e63f5c50e4d9858a1 Mon Sep 17 00:00:00 2001 From: huangjian Date: Fri, 10 Dec 2021 15:30:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=84=8F=E9=9A=90=E7=A7=81=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE=E7=AD=BE=E4=B8=8D=E5=88=9D=E5=A7=8B=E5=8C=96=E4=BB=BB?= =?UTF-8?q?=E4=BD=95=E4=B8=9C=E8=A5=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android_crop_lib/build.gradle | 2 +- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 2 +- .../erban/application/XChatApplication.java | 618 +++++++++--------- .../erban/other/activity/SplashActivity.java | 21 +- .../other/dialog/PrivacyAgreementDialog.java | 4 +- core/build.gradle | 2 +- library/build.gradle | 2 +- nim_uikit/build.gradle | 2 +- 9 files changed, 319 insertions(+), 336 deletions(-) diff --git a/android_crop_lib/build.gradle b/android_crop_lib/build.gradle index 17b97a7a0..a52b7c7a3 100644 --- a/android_crop_lib/build.gradle +++ b/android_crop_lib/build.gradle @@ -5,7 +5,7 @@ android { compileSdkVersion 29 defaultConfig { - minSdkVersion 19 + minSdkVersion 21 targetSdkVersion 29 testApplicationId 'com.soundcloud.android.crop.test' diff --git a/app/build.gradle b/app/build.gradle index ef102dc9c..27ae2220b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,7 +14,7 @@ android { defaultConfig { applicationId "com.mango.yinyou" - minSdkVersion 19 + minSdkVersion 21 targetSdkVersion 29 versionCode Integer.valueOf(version_code) versionName version_name diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4ed018636..6109eb052 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -80,7 +80,7 @@ { - layout.setEnableHeaderTranslationContent(false); - MaterialHeader materialHeader = new MaterialHeader(context); - materialHeader.setShowBezierWave(false); - return materialHeader; - }); - SmartRefreshLayout.setDefaultRefreshFooterCreater( - (context, layout) -> new ClassicsFooter(context).setDrawableSize(20)); - } - - @Override - public void onCreate() { - long startTime = System.currentTimeMillis(); - super.onCreate(); - instance = this; - String channel = ""; - try { - ApplicationInfo appInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA); - channel = appInfo.metaData.getString("CHANNEL"); - } catch (Exception e) { - e.printStackTrace(); - } - if (TextUtils.isEmpty(channel)) { - channel = "official"; - } - - BasicConfig.INSTANCE.setOriginalChannel(channel); - - //头条分包渠道 - if (BasicConfig.INSTANCE.isByteDanceChannel()) { - String byteDanceChannel = HumeSDK.getChannel(this); - if (!TextUtils.isEmpty(byteDanceChannel)) { - channel = byteDanceChannel; - } - } - BasicConfig.INSTANCE.setChannel(channel); - - LogUtils.d(channel + ""); - initEnv(); - - //延迟初始化云信 - NIMClient.init(this, null, options()); - - //logger 配置 - Logger.addLogAdapter(new AndroidLogAdapter() { - @Override - public boolean isLoggable(int priority, String tag) { - return BuildConfig.DEBUG; - } - }); - - ToastUtils.init(this); - - if (inMainProcess(this)) { - // 注册自定义推送消息处理,这个是可选项 - NIMPushClient.registerMixPushMessageHandler(new PushMessageHandler()); - - RxJavaPlugins.setErrorHandler(throwable -> { - 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; - }); - GsonConverterPlugins.lockdown(); - - //fixed: Glide Exception:"You must not call setTag() on a view Glide is targeting" - ViewTarget.setTagId(R.id.tag_glide); - - // 初始化 sp - SharedPreferenceUtils.init(this); - - init(channel); - - initLinkedMe(); - - if (!TextUtils.isEmpty(channel)) { - CrashReport.setAppChannel(this, channel); - } - - initBuglyUpdate(); - Bugly.init(this, BuildConfig.DEBUG ? XChatConstants.BUGLY_KEY_DEBUG : XChatConstants.BUGLY_KEY_RELEASE, BuildConfig.DEBUG); - if (!TextUtils.isEmpty(channel)) { - Bugly.setAppChannel(this, channel); - } - - //生命周期监听 - if (lifeManager == null) { - lifeManager = new ActivityLifeManager(); - } - registerActivityLifecycleCallback(lifeManager); - ActivityMgr.INST.init(this); - - boolean isShowPrivacyAgreement = (boolean) SharedPreferenceUtils.get(SplashActivity.SHOW_PRIVACY_AGREEMENT, true); - if (!isShowPrivacyAgreement) { - initOtherSDK(); - } - } - dealHuaWeiCrash(); - - if (BuildConfig.APPLICATION_ID.equals(getProcessName(this))) { - FlutterBoost.instance().setup(this, new XplanFlutterBoostDelegate(), new XplanFlutterBoostCallback()); - } - LogUtils.d("init time = " + (System.currentTimeMillis() - startTime) + "ms"); - } - - private static boolean isInitOtherSDK = false; - - public static void initOtherSDK() { - - if (isInitOtherSDK) return; - - isInitOtherSDK = true; - Context context = BasicConfig.INSTANCE.getAppContext(); - LinkedME.getInstance().setImmediate(true); - // 网易易盾初始化 - watchman.init(context, XChatConstants.YI_DUN_PRODUCT_NUMBER); // 网易易盾初始化 - MobSDK.init(context); - MobSDK.submitPolicyGrantResult(true, null); - // 友盟统计初始化 - UMConfigure.init(context, XChatConstants.UMENG_APP_KEY, - BasicConfig.INSTANCE.getChannel(), UMConfigure.DEVICE_TYPE_PHONE, null); - // 选用MANUAL页面采集模式 - MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.MANUAL); - // 支持在子进程中统计自定义事件 - UMConfigure.setProcessEvent(true); - // 日志加密 - UMConfigure.setEncryptEnabled(true); - // 集成测试 - UMConfigure.setLogEnabled(BuildConfig.DEBUG); - //实人认证 - RPSDK.initialize(context); - } - - - /** - * 初始化linkedMe - */ - private void initLinkedMe() { - LinkedME.getInstance(this, XChatConstants.LINKED_ME_KEY); - if (isDebug()) { - //设置debug模式下打印LinkedME日志 - LinkedME.getInstance().setDebug(); - } - //初始时请设置为false - LinkedME.getInstance().setImmediate(false); - //设置处理跳转逻辑的中转页,MiddleActivity详见后续配置 - LinkedME.getInstance().setHandleActivity(MiddleActivity.class.getName()); - } - - private void initEnv() { - BasicConfig.INSTANCE.setAppContext(this.getApplicationContext()); - - //首先初始化环境 - 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); - } - - - private void dealHuaWeiCrash() { - String brand = Build.BRAND; - String manufacturer = Build.MANUFACTURER; - if (!TextUtils.isEmpty(brand) && ( - "HUAWEI".toLowerCase().equals(brand.toLowerCase()) - || "HONOR".toLowerCase().equals(brand.toLowerCase()) - || "HUAWEI".equals(manufacturer))) { - LoadedApkHuaWei.hookHuaWeiVerifier(this); - } - } - - @Override - protected void attachBaseContext(Context base) { - super.attachBaseContext(base); - MultiDex.install(base); - } - - - @Override - public void onTerminate() { - super.onTerminate(); - CrashReport.closeBugly(); - if (lifeManager != null) { - unregisterActivityLifecycleCallbacks(lifeManager); - } - GlobalHandleManager.get().unInit(); - } - - @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) - public void registerActivityLifecycleCallback(Application.ActivityLifecycleCallbacks callbacks) { - this.registerActivityLifecycleCallbacks(callbacks); - } - - /** - * 云信配置 - * - * @return - */ - public SDKOptions options() { - SDKOptions options = new SDKOptions(); - options.disableAwake = true; - options.asyncInitSDK = true; -// options.customPushContentType = ""; - 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; - config.notificationFoldStyle = NotificationFoldStyle.CONTACT; - // 通知铃声的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 { - sdkPath = Environment.getExternalStorageDirectory() + "/" + this.getPackageName() + "/nim"; - } catch (ArrayIndexOutOfBoundsException e) { - - } - options.sdkStorageRootPath = sdkPath; - - // 配置是否需要预下载附件缩略图,默认为 true - options.preloadAttach = true; - - // 配置附件缩略图的尺寸大小。表示向服务器请求缩略图文件的大小 - // 该值一般应根据屏幕尺寸来确定, 默认值为 Screen.width / 2 - int widthPixels = this.getResources().getDisplayMetrics().widthPixels; - options.thumbnailSize = widthPixels / 2; -// // save cache,留做切换账号备用 - DemoCache.setNotificationConfig(config); - - MixPushConfig mixPushConfig = new MixPushConfig(); - //华为推送 - mixPushConfig.hwAppId = HW_APP_ID; - mixPushConfig.hwCertificateName = HW_CERTIFICATE_NAME; - //小米推送 - mixPushConfig.xmAppId = XM_APP_ID; - mixPushConfig.xmAppKey = XM_APP_KEY; - mixPushConfig.xmCertificateName = XM_CERTIFICATE_NAME; - //魅族推送 - mixPushConfig.mzAppId = MZ_APP_ID; - mixPushConfig.mzAppKey = MZ_APP_KEY; - mixPushConfig.mzCertificateName = MZ_CERTIFICATE_NAME; - //vivo推送 - mixPushConfig.vivoCertificateName = VIVO_CERTIFICATE_NAME; - //oppo推送 - mixPushConfig.oppoAppId = OPPO_APP_ID; - mixPushConfig.oppoAppKey = OPPO_APP_KEY; - mixPushConfig.oppoAppSercet = OPPO_SECRET; - mixPushConfig.oppoCertificateName = OPPO_CERTIFICATE_NAME; - options.mixPushConfig = mixPushConfig; - - return options; - } - - private final MessageNotifierCustomization messageNotifierCustomization = new MessageNotifierCustomization() { + private static final MessageNotifierCustomization messageNotifierCustomization = new MessageNotifierCustomization() { @Override public String makeNotifyContent(String nick, IMMessage message) { if (message.getMsgType() == MsgTypeEnum.custom) { @@ -486,6 +187,272 @@ public class XChatApplication extends Application { return null; } }; + private static XChatApplication instance; + //生命周期监听 + private static ActivityLifeManager lifeManager; + private static boolean isInitOtherSDK = false; + + //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)); + } + + 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 + long startTime = System.currentTimeMillis(); + + String channel = ""; + try { + ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); + channel = appInfo.metaData.getString("CHANNEL"); + } catch (Exception e) { + e.printStackTrace(); + } + if (TextUtils.isEmpty(channel)) { + channel = "official"; + } + + BasicConfig.INSTANCE.setOriginalChannel(channel); + + //头条分包渠道 + if (BasicConfig.INSTANCE.isByteDanceChannel()) { + String byteDanceChannel = HumeSDK.getChannel(context); + if (!TextUtils.isEmpty(byteDanceChannel)) { + channel = byteDanceChannel; + } + } + BasicConfig.INSTANCE.setChannel(channel); + + LogUtils.d(channel + ""); + initEnv(); + + //延迟初始化云信 + NIMClient.init(context, null, options()); + + //logger 配置 + Logger.addLogAdapter(new AndroidLogAdapter() { + @Override + public boolean isLoggable(int priority, String tag) { + return BuildConfig.DEBUG; + } + }); + + ToastUtils.init(application); + + if (inMainProcess(context)) { + // 注册自定义推送消息处理,这个是可选项 + NIMPushClient.registerMixPushMessageHandler(new PushMessageHandler()); + + RxJavaPlugins.setErrorHandler(throwable -> { + 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; + }); + GsonConverterPlugins.lockdown(); + + //fixed: Glide Exception:"You must not call setTag() on a view Glide is targeting" + ViewTarget.setTagId(R.id.tag_glide); + + + init(channel); + + if (!TextUtils.isEmpty(channel)) { + CrashReport.setAppChannel(context, channel); + } + + initBuglyUpdate(); + Bugly.init(context, BuildConfig.DEBUG ? XChatConstants.BUGLY_KEY_DEBUG : XChatConstants.BUGLY_KEY_RELEASE, BuildConfig.DEBUG); + if (!TextUtils.isEmpty(channel)) { + Bugly.setAppChannel(context, channel); + } + + //生命周期监听 + if (lifeManager == null) { + lifeManager = new ActivityLifeManager(); + } + registerActivityLifecycleCallback(lifeManager); + + + } + dealHuaWeiCrash(); + + if (BuildConfig.APPLICATION_ID.equals(getProcessName(context))) { + FlutterBoost.instance().setup((Application) context.getApplicationContext(), new XplanFlutterBoostDelegate(), new XplanFlutterBoostCallback()); + } + LogUtils.d("init time = " + (System.currentTimeMillis() - startTime) + "ms"); + initLinkedMe(); + ActivityMgr.INST.init((Application) context); + LinkedME.getInstance().setImmediate(true); + // 网易易盾初始化 + watchman.init(context, XChatConstants.YI_DUN_PRODUCT_NUMBER); // 网易易盾初始化 + MobSDK.init(context); + MobSDK.submitPolicyGrantResult(true, null); + // 友盟统计初始化 + UMConfigure.init(context, XChatConstants.UMENG_APP_KEY, + BasicConfig.INSTANCE.getChannel(), UMConfigure.DEVICE_TYPE_PHONE, null); + // 选用MANUAL页面采集模式 + MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.MANUAL); + // 支持在子进程中统计自定义事件 + UMConfigure.setProcessEvent(true); + // 日志加密 + UMConfigure.setEncryptEnabled(true); + // 集成测试 + UMConfigure.setLogEnabled(BuildConfig.DEBUG); + //实人认证 + RPSDK.initialize(context); + } + + + /** + * 初始化linkedMe + */ + private static void initLinkedMe() { + LinkedME.getInstance(BasicConfig.INSTANCE.getAppContext(), XChatConstants.LINKED_ME_KEY); + if (isDebug()) { + //设置debug模式下打印LinkedME日志 + LinkedME.getInstance().setDebug(); + } + //初始时请设置为false + LinkedME.getInstance().setImmediate(false); + //设置处理跳转逻辑的中转页,MiddleActivity详见后续配置 + LinkedME.getInstance().setHandleActivity(MiddleActivity.class.getName()); + } + + private static void initEnv() { + //首先初始化环境 + 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); + } + + + private static void dealHuaWeiCrash() { + String brand = Build.BRAND; + String manufacturer = Build.MANUFACTURER; + if (!TextUtils.isEmpty(brand) && ( + "HUAWEI".toLowerCase().equals(brand.toLowerCase()) + || "HONOR".toLowerCase().equals(brand.toLowerCase()) + || "HUAWEI".equals(manufacturer))) { + LoadedApkHuaWei.hookHuaWeiVerifier((Application) BasicConfig.INSTANCE.getAppContext().getApplicationContext()); + } + } + + @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) + public static void registerActivityLifecycleCallback(Application.ActivityLifecycleCallbacks callbacks) { + ((Application) BasicConfig.INSTANCE.getAppContext().getApplicationContext()).registerActivityLifecycleCallbacks(callbacks); + } + + /** + * 云信配置 + * + * @return + */ + public static SDKOptions options() { + SDKOptions options = new SDKOptions(); + options.disableAwake = true; + options.asyncInitSDK = true; +// options.customPushContentType = ""; + 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; + config.notificationFoldStyle = NotificationFoldStyle.CONTACT; + // 通知铃声的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 { + sdkPath = Environment.getExternalStorageDirectory() + "/" + BasicConfig.INSTANCE.getAppContext().getPackageName() + "/nim"; + } catch (ArrayIndexOutOfBoundsException e) { + + } + options.sdkStorageRootPath = sdkPath; + + // 配置是否需要预下载附件缩略图,默认为 true + options.preloadAttach = true; + + // 配置附件缩略图的尺寸大小。表示向服务器请求缩略图文件的大小 + // 该值一般应根据屏幕尺寸来确定, 默认值为 Screen.width / 2 + int widthPixels = BasicConfig.INSTANCE.getAppContext().getResources().getDisplayMetrics().widthPixels; + options.thumbnailSize = widthPixels / 2; +// // save cache,留做切换账号备用 + DemoCache.setNotificationConfig(config); + + MixPushConfig mixPushConfig = new MixPushConfig(); + //华为推送 + mixPushConfig.hwAppId = HW_APP_ID; + mixPushConfig.hwCertificateName = HW_CERTIFICATE_NAME; + //小米推送 + mixPushConfig.xmAppId = XM_APP_ID; + mixPushConfig.xmAppKey = XM_APP_KEY; + mixPushConfig.xmCertificateName = XM_CERTIFICATE_NAME; + //魅族推送 + mixPushConfig.mzAppId = MZ_APP_ID; + mixPushConfig.mzAppKey = MZ_APP_KEY; + mixPushConfig.mzCertificateName = MZ_CERTIFICATE_NAME; + //vivo推送 + mixPushConfig.vivoCertificateName = VIVO_CERTIFICATE_NAME; + //oppo推送 + mixPushConfig.oppoAppId = OPPO_APP_ID; + mixPushConfig.oppoAppKey = OPPO_APP_KEY; + mixPushConfig.oppoAppSercet = OPPO_SECRET; + mixPushConfig.oppoCertificateName = OPPO_CERTIFICATE_NAME; + options.mixPushConfig = mixPushConfig; + + return options; + } /** * 判断当前进程是否主进程 @@ -502,7 +469,7 @@ public class XChatApplication extends Application { /** * 初始化bugly版本升级 */ - private void initBuglyUpdate() { + private static void initBuglyUpdate() { /***** Beta高级设置 *****/ /** * true表示app启动自动初始化升级模块; @@ -592,7 +559,7 @@ public class XChatApplication extends Application { * @param url */ @SuppressLint("CheckResult") - public void initRxNet(Context context, String url) { + public static void initRxNet(Context context, String url) { Map httpParams = new ArrayMap<>(); httpParams.put("os", "android"); httpParams.put("osVersion", Build.VERSION.RELEASE); @@ -616,14 +583,13 @@ public class XChatApplication extends Application { initModel(); } - - private void init(String channel) { + private static void init(String channel) { initNimUIKit(); UriProvider.initUri(BuildConfig.BASE_URL_DEBUG, BuildConfig.BASE_URL_STAGING, BuildConfig.BASE_URL_RELEASE); - SVGAParser.Companion.shareParser().init(this); + SVGAParser.Companion.shareParser().init(BasicConfig.INSTANCE.getAppContext()); try { /** svga动画缓存路径 */ - File cacheDir = new File(this.getApplicationContext().getExternalCacheDir(), "http"); + File cacheDir = new File(BasicConfig.INSTANCE.getAppContext().getApplicationContext().getExternalCacheDir(), "http"); if (!cacheDir.exists()) cacheDir.mkdirs(); HttpResponseCache.install(cacheDir, 1024 * 1024 * 128); } catch (IOException e) { @@ -632,7 +598,7 @@ public class XChatApplication extends Application { initRxNet(BasicConfig.INSTANCE.getAppContext(), UriProvider.JAVA_WEB_URL); - ConnectiveChangedReceiver.getInstance().init(this.getApplicationContext()); + ConnectiveChangedReceiver.getInstance().init(BasicConfig.INSTANCE.getAppContext()); /** * 使用到realm 数据库,这里配置数据库 这里必须先于模块初始化前进行初始化配置 */ @@ -652,7 +618,7 @@ public class XChatApplication extends Application { /** * 一些单例的 model */ - private void initModel() { + private static void initModel() { DynamicFaceModel.get().init(); PayModel.get(); UserModel.get(); @@ -682,9 +648,9 @@ public class XChatApplication extends Application { } - private void initNimUIKit() { + private static void initNimUIKit() { // 初始化 - NimUIKit.init(this); + NimUIKit.init(BasicConfig.INSTANCE.getAppContext()); } /** @@ -702,4 +668,36 @@ public class XChatApplication extends Application { public static boolean isRealDebug() { return Env.isRealDebug(); } + + + /** + * 用户没同意隐私协议之前,啥也不干!! + */ + @Override + public void onCreate() { + super.onCreate(); + instance = this; + BasicConfig.INSTANCE.setAppContext(this.getApplicationContext()); + SharedPreferenceUtils.init(this); + boolean isShowPrivacyAgreement = (boolean) SharedPreferenceUtils.get(SplashActivity.SHOW_PRIVACY_AGREEMENT, true); + if (!isShowPrivacyAgreement) { + initOtherSDK(); + } + } + + @Override + protected void attachBaseContext(Context base) { + super.attachBaseContext(base); + MultiDex.install(base); + } + + @Override + public void onTerminate() { + super.onTerminate(); + CrashReport.closeBugly(); + if (lifeManager != null) { + unregisterActivityLifecycleCallbacks(lifeManager); + } + GlobalHandleManager.get().unInit(); + } } diff --git a/app/src/main/java/com/yizhuan/erban/other/activity/SplashActivity.java b/app/src/main/java/com/yizhuan/erban/other/activity/SplashActivity.java index 904f5a4b0..a50b7c239 100644 --- a/app/src/main/java/com/yizhuan/erban/other/activity/SplashActivity.java +++ b/app/src/main/java/com/yizhuan/erban/other/activity/SplashActivity.java @@ -7,6 +7,7 @@ import android.text.TextUtils; import android.view.View; import android.view.animation.AlphaAnimation; +import androidx.appcompat.app.AppCompatActivity; import androidx.databinding.DataBindingUtil; import com.bumptech.glide.request.RequestOptions; @@ -17,22 +18,20 @@ import com.yizhuan.erban.MainActivity; import com.yizhuan.erban.NimMiddleActivity; import com.yizhuan.erban.R; import com.yizhuan.erban.application.XChatApplication; -import com.yizhuan.erban.base.BaseActivity; import com.yizhuan.erban.databinding.ActivitySplashBinding; import com.yizhuan.erban.other.SplashBitmapTransformation; import com.yizhuan.erban.other.dialog.PrivacyAgreementDialog; -import com.yizhuan.xchat_android_core.utils.OaidUtil; -import com.yizhuan.xchat_android_constants.XChatConstants; import com.yizhuan.xchat_android_core.channel_page.model.ChannelPageModel; import com.yizhuan.xchat_android_core.initial.InitialModel; import com.yizhuan.xchat_android_core.initial.SplashComponent; +import com.yizhuan.xchat_android_core.utils.OaidUtil; import com.yizhuan.xchat_android_core.utils.SharedPreferenceUtils; /** * @author xiaoyu * @date 2017/12/30 */ -public class SplashActivity extends BaseActivity implements View.OnClickListener, PrivacyAgreementDialog.OnCallBack { +public class SplashActivity extends AppCompatActivity implements View.OnClickListener, PrivacyAgreementDialog.OnCallBack { public static final String SHOW_PRIVACY_AGREEMENT = "show_privacy_agreement"; private static final int COUNT_DOWN_TIME = 3; @@ -59,8 +58,8 @@ public class SplashActivity extends BaseActivity implements View.OnClickListener // 从堆栈恢复,不再重复解析之前的intent setIntent(new Intent()); } - initiate(); + StatusBarUtil.transparencyBar(this); } @Override @@ -163,18 +162,6 @@ public class SplashActivity extends BaseActivity implements View.OnClickListener } - - @Override - protected boolean needSteepStateBar() { - return true; - } - - @Override - protected void setStatusBar() { - super.setStatusBar(); - StatusBarUtil.transparencyBar(this); - } - @Override public void onFinish(boolean isConfirm) { if (isConfirm) { diff --git a/app/src/main/java/com/yizhuan/erban/other/dialog/PrivacyAgreementDialog.java b/app/src/main/java/com/yizhuan/erban/other/dialog/PrivacyAgreementDialog.java index a73101cfd..666fa278f 100644 --- a/app/src/main/java/com/yizhuan/erban/other/dialog/PrivacyAgreementDialog.java +++ b/app/src/main/java/com/yizhuan/erban/other/dialog/PrivacyAgreementDialog.java @@ -85,16 +85,14 @@ public class PrivacyAgreementDialog extends Dialog implements View.OnClickListen window.setAttributes(lp); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); - - } @Override public void onClick(View v) { + cancel(); if (onCallBack != null) { onCallBack.onFinish(v.getId() == R.id.tv_confirm); } - cancel(); } public interface OnCallBack { diff --git a/core/build.gradle b/core/build.gradle index 09cd2a148..6b12a008c 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -6,7 +6,7 @@ apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 29 defaultConfig { - minSdkVersion 19 + minSdkVersion 21 targetSdkVersion 29 versionCode 1 versionName "1.0" diff --git a/library/build.gradle b/library/build.gradle index ffbeae3d2..a3e2ef91d 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'kotlin-android' android { compileSdkVersion 29 defaultConfig { - minSdkVersion 19 + minSdkVersion 21 targetSdkVersion 29 versionCode 1 versionName "1.0" diff --git a/nim_uikit/build.gradle b/nim_uikit/build.gradle index ee3cede00..f0a691145 100644 --- a/nim_uikit/build.gradle +++ b/nim_uikit/build.gradle @@ -7,7 +7,7 @@ android { buildToolsVersion '28.0.3' defaultConfig { - minSdkVersion 19 + minSdkVersion 21 targetSdkVersion 29 renderscriptTargetApi 26