Showing
33 changed files
with
3631 additions
and
90 deletions
Too many changes to show.
To preserve performance only 33 of 33+ files are displayed.
| @@ -55,7 +55,13 @@ repositories { | @@ -55,7 +55,13 @@ repositories { | ||
| 55 | 55 | ||
| 56 | dependencies { | 56 | dependencies { |
| 57 | // implementation 'androidx.appcompat:appcompat:1.6.1' | 57 | // implementation 'androidx.appcompat:appcompat:1.6.1' |
| 58 | - implementation "com.google.android.material:material:1.4.0" | 58 | + //alpha 启动优化 |
| 59 | + implementation rootProject.ext.dependencies["alpha-start"] | ||
| 60 | + implementation rootProject.ext.dependencies["androidxAppCompat"] | ||
| 61 | + implementation rootProject.ext.dependencies["material"] | ||
| 59 | implementation project(':lib_base') | 62 | implementation project(':lib_base') |
| 63 | + implementation project(path: ':wdinterfaceimpl') | ||
| 64 | + implementation project(path: ':module_home') | ||
| 65 | +// annotationProcessor 'com.alibaba:arouter-compiler:1.5.2' | ||
| 60 | 66 | ||
| 61 | } | 67 | } |
| @@ -2,27 +2,36 @@ | @@ -2,27 +2,36 @@ | ||
| 2 | package com.wd.fastcoding.app; | 2 | package com.wd.fastcoding.app; |
| 3 | 3 | ||
| 4 | import android.app.Activity; | 4 | import android.app.Activity; |
| 5 | +import android.content.Intent; | ||
| 5 | import android.os.Bundle; | 6 | import android.os.Bundle; |
| 6 | 7 | ||
| 7 | import androidx.annotation.Nullable; | 8 | import androidx.annotation.Nullable; |
| 8 | 9 | ||
| 9 | -/** | ||
| 10 | - * @ProjectName: PeopleDailyVideo | ||
| 11 | - * @Package: com.people.displayui.main | ||
| 12 | - * @ClassName: WelcomeActivity | ||
| 13 | - * @Description: 启动APP过渡页面 | ||
| 14 | - * @Author: wd | ||
| 15 | - * @CreateDate: 2022/10/28 17:36 | ||
| 16 | - * @UpdateUser: wd | ||
| 17 | - * @UpdateDate: 2022/10/28 17:36 | ||
| 18 | - * @UpdateRemark: 更新说明: | ||
| 19 | - * @Version: 1.0 | ||
| 20 | - */ | 10 | +import com.wd.common.utils.ProcessUtils; |
| 11 | +import com.wd.module_home.AppMainActivity; | ||
| 12 | + | ||
| 21 | public class MainActivity extends Activity { | 13 | public class MainActivity extends Activity { |
| 22 | 14 | ||
| 23 | @Override | 15 | @Override |
| 24 | protected void onCreate(@Nullable Bundle savedInstanceState) { | 16 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| 25 | super.onCreate(savedInstanceState); | 17 | super.onCreate(savedInstanceState); |
| 26 | - // 直接进入首页 | 18 | + /* 解决部分手机点击home键返回桌面后,再回到应用时,会先进入启动页的问题*/ |
| 19 | + if (!this.isTaskRoot()) { | ||
| 20 | + Intent intent = getIntent(); | ||
| 21 | + if (intent != null) { | ||
| 22 | + if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(intent.getAction())) { | ||
| 23 | + finish(); | ||
| 24 | + return; | ||
| 25 | + } | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | +// Intent intent = new Intent(); | ||
| 30 | +// intent.setClass(this, AppMainActivity.class); | ||
| 31 | +// startActivity(intent); | ||
| 32 | + ProcessUtils.goMainPage(); | ||
| 33 | + overridePendingTransition(0, 0); | ||
| 34 | + | ||
| 35 | + finish(); | ||
| 27 | } | 36 | } |
| 28 | } | 37 | } |
| @@ -2,10 +2,14 @@ | @@ -2,10 +2,14 @@ | ||
| 2 | package com.wd.fastcoding.app; | 2 | package com.wd.fastcoding.app; |
| 3 | 3 | ||
| 4 | import android.app.Application; | 4 | import android.app.Application; |
| 5 | -import android.util.Log; | ||
| 6 | 5 | ||
| 6 | +import com.wd.capability.network.RetrofitClient; | ||
| 7 | +import com.wd.common.interceptor.TokenInterceptor; | ||
| 8 | +import com.wd.capability.router.ArouteInit; | ||
| 9 | +import com.wd.foundation.wdkit.utils.CommonUtil; | ||
| 7 | import com.wd.fastcoding.app.start.StartTaskConfig; | 10 | import com.wd.fastcoding.app.start.StartTaskConfig; |
| 8 | -import com.wd.fastcoding.app.start.StartTaskTool; | 11 | +import com.wd.foundation.wdkitcore.tools.AppContext; |
| 12 | +import com.wd.foundation.wdkitcore.tools.StringUtils; | ||
| 9 | 13 | ||
| 10 | /** | 14 | /** |
| 11 | * @author devel | 15 | * @author devel |
| @@ -15,12 +19,35 @@ public class MyApplication extends Application { | @@ -15,12 +19,35 @@ public class MyApplication extends Application { | ||
| 15 | @Override | 19 | @Override |
| 16 | public void onCreate() { | 20 | public void onCreate() { |
| 17 | super.onCreate(); | 21 | super.onCreate(); |
| 18 | - Log.e("zzzz","MyApplication onCreate"); | ||
| 19 | - // TODO 初始化实际业务 test | 22 | + AppContext.init(this,true); |
| 23 | + // 第三方库初始化 | ||
| 24 | + if (isCurProcess()) { | ||
| 25 | + initLibs(); | ||
| 26 | + // 主进程,只执行一次 | ||
| 27 | + // 启动初始化管理,子线程管理 | ||
| 20 | StartTaskConfig taskConfig = new StartTaskConfig(this); | 28 | StartTaskConfig taskConfig = new StartTaskConfig(this); |
| 21 | taskConfig.start(); | 29 | taskConfig.start(); |
| 22 | - StartTaskTool.startTaskInMain(this); | ||
| 23 | - StartTaskTool.startPrivate(this); | ||
| 24 | - StartTaskTool.startTaskInSplash(this); | 30 | + } |
| 31 | + } | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 初始化第三方库 | ||
| 36 | + */ | ||
| 37 | + private void initLibs() { | ||
| 38 | + // 网络请求初始化,主线程立即调用 | ||
| 39 | + RetrofitClient.init(this, new TokenInterceptor(RetrofitClient.getInterceptorHosts())); | ||
| 40 | + // 路由初始化,主线程立即调用 | ||
| 41 | + ArouteInit.getInstance().init(this); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 是否是主进程 | ||
| 46 | + * * @return true:是,false:否 | ||
| 47 | + */ | ||
| 48 | + public boolean isCurProcess() { | ||
| 49 | + String curProcessName = CommonUtil.getProcessName(this); | ||
| 50 | + String name = getPackageName(); | ||
| 51 | + return StringUtils.isEmpty(curProcessName) || StringUtils.isEmpty(name) || name.equals(curProcessName); | ||
| 25 | } | 52 | } |
| 26 | } | 53 | } |
| @@ -7,9 +7,9 @@ package com.wd.fastcoding.app.start; | @@ -7,9 +7,9 @@ package com.wd.fastcoding.app.start; | ||
| 7 | import android.content.Context; | 7 | import android.content.Context; |
| 8 | import android.util.Log; | 8 | import android.util.Log; |
| 9 | 9 | ||
| 10 | +import com.alibaba.android.alpha.AlphaManager; | ||
| 11 | +import com.alibaba.android.alpha.Project; | ||
| 10 | import com.wd.fastcoding.app.task.MyTaskCreator; | 12 | import com.wd.fastcoding.app.task.MyTaskCreator; |
| 11 | -import com.wd.base.starttask.AlphaManager; | ||
| 12 | -import com.wd.base.starttask.Project; | ||
| 13 | 13 | ||
| 14 | /** | 14 | /** |
| 15 | * 描述:启动初始化任务 | 15 | * 描述:启动初始化任务 |
| @@ -6,12 +6,8 @@ package com.wd.fastcoding.app.task; | @@ -6,12 +6,8 @@ package com.wd.fastcoding.app.task; | ||
| 6 | 6 | ||
| 7 | import android.content.Context; | 7 | import android.content.Context; |
| 8 | 8 | ||
| 9 | +import com.alibaba.android.alpha.Task; | ||
| 9 | import com.wd.base.log.Logger; | 10 | import com.wd.base.log.Logger; |
| 10 | -import com.wd.base.starttask.Task; | ||
| 11 | - | ||
| 12 | -//import com.people.kittools.constant.CommonConstant; | ||
| 13 | -//import com.people.kittools.sp.SpUtils; | ||
| 14 | -//import com.people.umeng.UmSdkHelper; | ||
| 15 | 11 | ||
| 16 | /** | 12 | /** |
| 17 | * 描述:在主页初始化,不着急使用,进入主页用户必然已经同意隐私政策 | 13 | * 描述:在主页初始化,不着急使用,进入主页用户必然已经同意隐私政策 |
| @@ -8,10 +8,9 @@ import java.lang.ref.WeakReference; | @@ -8,10 +8,9 @@ import java.lang.ref.WeakReference; | ||
| 8 | 8 | ||
| 9 | import android.content.Context; | 9 | import android.content.Context; |
| 10 | 10 | ||
| 11 | -import com.wd.base.starttask.Task; | 11 | +import com.alibaba.android.alpha.Task; |
| 12 | + | ||
| 12 | 13 | ||
| 13 | -//import com.people.kittools.file.MyFileUtils; | ||
| 14 | -//import com.people.uiframework.CompComponent; | ||
| 15 | 14 | ||
| 16 | /** | 15 | /** |
| 17 | * 描述:本地代码初始化context,都在子线程执行 | 16 | * 描述:本地代码初始化context,都在子线程执行 |
| @@ -4,11 +4,11 @@ | @@ -4,11 +4,11 @@ | ||
| 4 | 4 | ||
| 5 | package com.wd.fastcoding.app.task; | 5 | package com.wd.fastcoding.app.task; |
| 6 | 6 | ||
| 7 | +import com.alibaba.android.alpha.Task; | ||
| 7 | import com.wd.base.log.AndroidLogAdapter; | 8 | import com.wd.base.log.AndroidLogAdapter; |
| 8 | import com.wd.base.log.FormatStrategy; | 9 | import com.wd.base.log.FormatStrategy; |
| 9 | import com.wd.base.log.Logger; | 10 | import com.wd.base.log.Logger; |
| 10 | import com.wd.base.log.PrettyFormatStrategy; | 11 | import com.wd.base.log.PrettyFormatStrategy; |
| 11 | -import com.wd.base.starttask.Task; | ||
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * 描述:com.orhanobut.logger 初始化,子线程初始化 | 14 | * 描述:com.orhanobut.logger 初始化,子线程初始化 |
| @@ -7,8 +7,9 @@ package com.wd.fastcoding.app.task; | @@ -7,8 +7,9 @@ package com.wd.fastcoding.app.task; | ||
| 7 | import android.content.Context; | 7 | import android.content.Context; |
| 8 | import android.util.Log; | 8 | import android.util.Log; |
| 9 | 9 | ||
| 10 | -import com.wd.base.starttask.ITaskCreator; | ||
| 11 | -import com.wd.base.starttask.Task; | 10 | +import com.alibaba.android.alpha.ITaskCreator; |
| 11 | +import com.alibaba.android.alpha.Task; | ||
| 12 | + | ||
| 12 | 13 | ||
| 13 | /** | 14 | /** |
| 14 | * 描述:create task | 15 | * 描述:create task |
| @@ -6,13 +6,9 @@ package com.wd.fastcoding.app.task; | @@ -6,13 +6,9 @@ package com.wd.fastcoding.app.task; | ||
| 6 | 6 | ||
| 7 | import android.content.Context; | 7 | import android.content.Context; |
| 8 | 8 | ||
| 9 | -import com.wd.base.starttask.Task; | 9 | +import com.alibaba.android.alpha.Task; |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | -//import com.orhanobut.logger.Logger; | ||
| 13 | -//import com.people.kittools.sp.SpUtils; | ||
| 14 | -//import com.people.umeng.UmSdkHelper; | ||
| 15 | - | ||
| 16 | 12 | ||
| 17 | /** | 13 | /** |
| 18 | * 描述:需要用户同意隐私政策的SDK初始化 | 14 | * 描述:需要用户同意隐私政策的SDK初始化 |
| @@ -8,7 +8,8 @@ package com.wd.fastcoding.app.task; | @@ -8,7 +8,8 @@ package com.wd.fastcoding.app.task; | ||
| 8 | //import com.wondertek.wheat.ability.scheduler.listener.IComponentRegister; | 8 | //import com.wondertek.wheat.ability.scheduler.listener.IComponentRegister; |
| 9 | //import com.wondertek.wheat.ability.scheduler.listener.InitListener; | 9 | //import com.wondertek.wheat.ability.scheduler.listener.InitListener; |
| 10 | 10 | ||
| 11 | -import com.wd.base.starttask.Task; | 11 | + |
| 12 | +import com.alibaba.android.alpha.Task; | ||
| 12 | 13 | ||
| 13 | /** | 14 | /** |
| 14 | * 描述:组件注册,反射多了影响性能 | 15 | * 描述:组件注册,反射多了影响性能 |
| 1 | apply plugin: 'maven' | 1 | apply plugin: 'maven' |
| 2 | +apply from: "config.gradle" | ||
| 2 | 3 | ||
| 3 | buildscript { | 4 | buildscript { |
| 4 | ext.kotlin_version = "1.4.32" | 5 | ext.kotlin_version = "1.4.32" |
| @@ -11,17 +12,17 @@ buildscript { | @@ -11,17 +12,17 @@ buildscript { | ||
| 11 | maven { url 'https://maven.aliyun.com/repository/public' } | 12 | maven { url 'https://maven.aliyun.com/repository/public' } |
| 12 | maven { url 'https://maven.aliyun.com/repository/jcenter' } | 13 | maven { url 'https://maven.aliyun.com/repository/jcenter' } |
| 13 | maven { url 'https://maven.aliyun.com/nexus/content/repositories/releases' } | 14 | maven { url 'https://maven.aliyun.com/nexus/content/repositories/releases' } |
| 14 | -// //阿里云 maven | ||
| 15 | -// maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' } | ||
| 16 | -// maven { url 'https://maven.aliyun.com/repository/releases' } | 15 | + //阿里云 maven |
| 16 | + maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' } | ||
| 17 | + maven { url 'https://maven.aliyun.com/repository/releases' } | ||
| 17 | 18 | ||
| 18 | google() | 19 | google() |
| 19 | 20 | ||
| 20 | -// maven { url "https://jitpack.io" } | ||
| 21 | -// //华为 | ||
| 22 | -// maven { url 'https://developer.huawei.com/repo/' } | ||
| 23 | -// //阿里云QuickTracking | ||
| 24 | -// maven { url 'https://repo1.maven.org/maven2/' } | 21 | + maven { url "https://jitpack.io" } |
| 22 | + //华为 | ||
| 23 | + maven { url 'https://developer.huawei.com/repo/' } | ||
| 24 | + //阿里云QuickTracking | ||
| 25 | + maven { url 'https://repo1.maven.org/maven2/' } | ||
| 25 | 26 | ||
| 26 | maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' } | 27 | maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' } |
| 27 | maven { | 28 | maven { |
| @@ -37,6 +38,7 @@ buildscript { | @@ -37,6 +38,7 @@ buildscript { | ||
| 37 | classpath "com.android.tools.build:gradle:4.0.2" | 38 | classpath "com.android.tools.build:gradle:4.0.2" |
| 38 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | 39 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" |
| 39 | classpath 'com.billy.android:autoregister:1.4.2' | 40 | classpath 'com.billy.android:autoregister:1.4.2' |
| 41 | + classpath 'com.github.kezong:fat-aar:1.3.8' | ||
| 40 | // NOTE: Do not place your application dependencies here; they belong | 42 | // NOTE: Do not place your application dependencies here; they belong |
| 41 | // in the individual module build.gradle files | 43 | // in the individual module build.gradle files |
| 42 | } | 44 | } |
| @@ -53,20 +55,20 @@ allprojects { | @@ -53,20 +55,20 @@ allprojects { | ||
| 53 | maven { url 'https://maven.aliyun.com/repository/jcenter' } | 55 | maven { url 'https://maven.aliyun.com/repository/jcenter' } |
| 54 | maven { url 'https://maven.aliyun.com/nexus/content/repositories/releases' } | 56 | maven { url 'https://maven.aliyun.com/nexus/content/repositories/releases' } |
| 55 | //阿里云 maven | 57 | //阿里云 maven |
| 56 | -// maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' } | ||
| 57 | -// maven { url 'https://maven.aliyun.com/repository/releases' } | 58 | + maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' } |
| 59 | + maven { url 'https://maven.aliyun.com/repository/releases' } | ||
| 58 | google() | 60 | google() |
| 59 | 61 | ||
| 60 | -// maven { url "https://jitpack.io" } | 62 | + maven { url "https://jitpack.io" } |
| 61 | //华为 | 63 | //华为 |
| 62 | -// maven { url 'https://developer.huawei.com/repo/' } | 64 | + maven { url 'https://developer.huawei.com/repo/' } |
| 63 | //阿里云QuickTracking | 65 | //阿里云QuickTracking |
| 64 | -// maven { url 'https://repo1.maven.org/maven2/' } | ||
| 65 | -// maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' } | ||
| 66 | -// maven { | ||
| 67 | -// url 'https://maven.aliyun.com/nexus/content/repositories/google/' | ||
| 68 | -// name 'aliyun-google' | ||
| 69 | -// } | 66 | + maven { url 'https://repo1.maven.org/maven2/' } |
| 67 | + maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' } | ||
| 68 | + maven { | ||
| 69 | + url 'https://maven.aliyun.com/nexus/content/repositories/google/' | ||
| 70 | + name 'aliyun-google' | ||
| 71 | + } | ||
| 70 | 72 | ||
| 71 | flatDir { dirs 'src/main/libs' } | 73 | flatDir { dirs 'src/main/libs' } |
| 72 | 74 | ||
| @@ -90,7 +92,7 @@ allprojects { | @@ -90,7 +92,7 @@ allprojects { | ||
| 90 | 92 | ||
| 91 | // 强制依赖 | 93 | // 强制依赖 |
| 92 | configurations.configureEach { | 94 | configurations.configureEach { |
| 93 | - //exclude group: 'com.alipay.android.phone.thirdparty', module: 'securityguard-build' | 95 | + exclude group: 'com.alipay.android.phone.thirdparty', module: 'securityguard-build' |
| 94 | resolutionStrategy { | 96 | resolutionStrategy { |
| 95 | force 'androidx.activity:activity:1.2.1' | 97 | force 'androidx.activity:activity:1.2.1' |
| 96 | force 'androidx.annotation:annotation:1.1.0' | 98 | force 'androidx.annotation:annotation:1.1.0' |
| @@ -106,15 +108,15 @@ allprojects { | @@ -106,15 +108,15 @@ allprojects { | ||
| 106 | force 'androidx.fragment:fragment:1.3.1' | 108 | force 'androidx.fragment:fragment:1.3.1' |
| 107 | force 'androidx.lifecycle:lifecycle-common:2.3.0' | 109 | force 'androidx.lifecycle:lifecycle-common:2.3.0' |
| 108 | force 'androidx.multidex:multidex:2.0.1' | 110 | force 'androidx.multidex:multidex:2.0.1' |
| 109 | -// force 'androidx.recyclerview:recyclerview:1.2.0' | ||
| 110 | -// force 'androidx.vectordrawable:vectordrawable:1.1.0' | ||
| 111 | -// force 'androidx.vectordrawable:vectordrawable-animated:1.1.0' | ||
| 112 | -// force 'com.squareup.okhttp3:okhttp:4.9.1' | ||
| 113 | -// force 'com.squareup.okio:okio:2.7.0' | ||
| 114 | -// force 'org.jetbrains.kotlin:kotlin-stdlib:1.4.32' | ||
| 115 | -// force 'org.jetbrains.kotlin:kotilin-stdlib-jdk8:1.4.32' | ||
| 116 | -// force 'org.jetbrains:annotations:15.0' | ||
| 117 | -// force 'net.sf.proguard:proguard-base:6.1.0' | 111 | + force 'androidx.recyclerview:recyclerview:1.2.0' |
| 112 | + force 'androidx.vectordrawable:vectordrawable:1.1.0' | ||
| 113 | + force 'androidx.vectordrawable:vectordrawable-animated:1.1.0' | ||
| 114 | + force 'com.squareup.okhttp3:okhttp:4.9.1' | ||
| 115 | + force 'com.squareup.okio:okio:2.7.0' | ||
| 116 | + force 'org.jetbrains.kotlin:kotlin-stdlib:1.4.32' | ||
| 117 | + force 'org.jetbrains.kotlin:kotilin-stdlib-jdk8:1.4.32' | ||
| 118 | + force 'org.jetbrains:annotations:15.0' | ||
| 119 | + force 'net.sf.proguard:proguard-base:6.1.0' | ||
| 118 | } | 120 | } |
| 119 | } | 121 | } |
| 120 | } | 122 | } |
config.gradle
0 → 100644
| 1 | +ext { | ||
| 2 | + isRelease = true | ||
| 3 | + // version配置 | ||
| 4 | + versions = ["support-version": "1.2.0", | ||
| 5 | + "room-version" : "2.4.3",] | ||
| 6 | + | ||
| 7 | + // support配置 | ||
| 8 | + support = ["appcompat-v7" : "androidx.appcompat:appcompat:${versions["support-version"]}", | ||
| 9 | + "recyclerview-v7" : "androidx.recyclerview:recyclerview:${versions["support-version"]}", | ||
| 10 | + "support-fragment": "androidx.fragment:fragment:${versions["support-version"]}", | ||
| 11 | + "constraintlayout": "androidx.constraintlayout:constraintlayout:2.0.4", | ||
| 12 | + "annotation" : "androidx.annotation:annotation:1.1.0", | ||
| 13 | + "kotlin-jdk" : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.32",] | ||
| 14 | + | ||
| 15 | + // 依赖第三方配置 | ||
| 16 | + dependencies = ["rxjava" : "io.reactivex.rxjava2:rxjava:2.2.3", | ||
| 17 | + "rxandroid" : "io.reactivex.rxjava2:rxandroid:2.1.0", | ||
| 18 | + "okhttp" : "com.squareup.okhttp3:okhttp:4.9.1", | ||
| 19 | + "retrofit" : "com.squareup.retrofit2:retrofit:2.9.0", | ||
| 20 | + "converter-gson" : "com.squareup.retrofit2:converter-gson:2.9.0", | ||
| 21 | + "adapter-rxjava" : "com.squareup.retrofit2:adapter-rxjava2:2.9.0", | ||
| 22 | + // glide图片加载 | ||
| 23 | + "glide" : "com.github.bumptech.glide:glide:4.13.0", | ||
| 24 | + "glide-compiler" : "com.github.bumptech.glide:compiler:4.13.0", | ||
| 25 | + "glide-transformations" : "jp.wasabeef:glide-transformations:4.3.0", | ||
| 26 | + // json解析 | ||
| 27 | + "gson" : "com.google.code.gson:gson:2.9.1", | ||
| 28 | + "gsonfactory" : "com.github.getActivity:GsonFactory:6.3", | ||
| 29 | + "lifecycle-extensions" : "androidx.lifecycle:lifecycle-extensions:2.0.0", | ||
| 30 | + "lifecycle-compiler" : "androidx.lifecycle:lifecycle-compiler:2.0.0", | ||
| 31 | + "multidex" : "com.android.support:multidex:1.0.3", | ||
| 32 | + "refresh-layout" : "io.github.scwang90:refresh-layout-kernel:2.0.5", | ||
| 33 | + "refresh-header" : "io.github.scwang90:refresh-header-classics:2.0.5", | ||
| 34 | + "refresh-footer" : "io.github.scwang90:refresh-footer-classics:2.0.5", | ||
| 35 | + "arouter-api" : "com.alibaba:arouter-api:1.5.2", | ||
| 36 | + "arouter-compiler" : "com.alibaba:arouter-compiler:1.5.2", | ||
| 37 | + "umsdk-share" : "com.umeng.umsdk:share-core:7.1.7",//分享核心库,必选 | ||
| 38 | + "umsdk-share-wx" : "com.umeng.umsdk:share-wx:7.1.7", | ||
| 39 | + "umsdk-share-sina" : "com.umeng.umsdk:share-sina:7.1.7", | ||
| 40 | + "umsdk-share-qq" : 'com.umeng.umsdk:share-qq:7.1.7', | ||
| 41 | + "BaseRecyclerViewAdapterHelper": "com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.50", | ||
| 42 | + "ucrop" : "com.github.yalantis:ucrop:2.2.1-native", | ||
| 43 | + "fastjson" : "com.alibaba:fastjson:1.2.83", | ||
| 44 | + "jsoup" : "org.jsoup:jsoup:1.14.3", | ||
| 45 | + "material" : "com.google.android.material:material:1.4.0", | ||
| 46 | + "banner" : "com.youth.banner:banner:2.1.0", | ||
| 47 | + "googleflexbox" : "com.google.android.flexbox:flexbox:3.0.0", | ||
| 48 | + "MagicIndicator" : "com.github.hackware1993:MagicIndicator:1.5.0", | ||
| 49 | + "PagerIndicatorView" : "com.github.zhaohe9981:PagerIndicatorView:v200", | ||
| 50 | + "html-textview" : "org.sufficientlysecure:html-textview:4.0", | ||
| 51 | + "jetbrains-annotations" : "org.jetbrains:annotations:15.0", | ||
| 52 | + "fresco" : "com.facebook.fresco:fresco:1.13.0", | ||
| 53 | + "leanback" : "androidx.leanback:leanback:1.1.0-alpha03", | ||
| 54 | + "eventbus" : "org.greenrobot:eventbus:3.1.1", | ||
| 55 | + "tencent-opensdk" : "com.tencent.mm.opensdk:wechat-sdk-android-without-mta:6.8.0", | ||
| 56 | + "tencent-qqopensdk" : 'com.tencent.tauth:qqopensdk:3.52.0', | ||
| 57 | + // V5.4.7.1及之后版本的Android播放器SDK必须按以下操作配置License后,方可使用。播放器SDK现免费提供,License有效期为1年,1年后若无特殊约定我们将为您免费自动续期。License配置完成后,查看日志若无License相关报错,则表示License配置成功。使用5.4.6版本不用注册 | ||
| 58 | + "alirtcLivePusher" : "com.aliyun.sdk.android:AliyunPlayer:5.5.6.0-full", | ||
| 59 | + "netWorkInternetSpeed" : "com.facebook.network.connectionclass:connectionclass:1.0.1", | ||
| 60 | + "androidtagview" : "co.lujun:androidtagview:1.1.7", | ||
| 61 | + "android-pickerView" : 'com.contrarywind:Android-PickerView:4.1.9', | ||
| 62 | + // 日志 | ||
| 63 | + "orhanobut-logger" : 'com.orhanobut:logger:2.2.0', | ||
| 64 | + // Alpha是一个基于PERT图构建的Android异步启动框架,它简单,高效,功能完善。 | ||
| 65 | + "alpha-start" : 'com.alibaba.android:alpha:1.0.0.1@aar', | ||
| 66 | + "support-appcompat-v7" : 'com.android.support:appcompat-v7:28.0.0', | ||
| 67 | + // 点赞效果 | ||
| 68 | + "jd-LikeButton" : 'com.github.jd-alexander:LikeButton:0.2.3', | ||
| 69 | + // 折叠 textview | ||
| 70 | + "expandableTextView" : 'cn.carbs.android:ExpandableTextView:1.0.3', | ||
| 71 | + //高德定位和搜索 | ||
| 72 | + "gd-location" : 'com.amap.api:location:6.4.7', | ||
| 73 | + "gd-search" : 'com.amap.api:search:9.4.0', | ||
| 74 | + // QMUI | ||
| 75 | + "qmui" : 'com.qmuiteam:qmui:2.0.0-alpha07', | ||
| 76 | + // 权限请求框架:https://github.com/getActivity/XXPermissions | ||
| 77 | + "xxPermissions" : 'com.github.getActivity:XXPermissions:16.8', | ||
| 78 | + // lottie | ||
| 79 | + "lottie" : "com.airbnb.android:lottie:5.2.0", | ||
| 80 | + "pag" : "com.tencent.tav:libpag:4.3.33", | ||
| 81 | + "desugar_jdk_libs" : "com.android.tools:desugar_jdk_libs:1.1.5", | ||
| 82 | + "okhttp3-integration" : 'com.github.bumptech.glide:okhttp3-integration:4.3.1', | ||
| 83 | + "toaster" : 'com.github.getActivity:Toaster:12.0', | ||
| 84 | + "core-ktx" : 'androidx.core:core-ktx:1.6.0', | ||
| 85 | + "TagTextView" : 'com.github.ChinaLike:TagTextView:0.2.0', | ||
| 86 | + "androidxAppCompat" : 'androidx.appcompat:appcompat:1.6.1',] | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | + |
| @@ -36,28 +36,27 @@ android { | @@ -36,28 +36,27 @@ android { | ||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | dependencies { | 38 | dependencies { |
| 39 | + api fileTree(include: ['commons-lang3-3.0.jar'], dir: 'src/main/commonlibs') | ||
| 39 | // 快马基础库 | 40 | // 快马基础库 |
| 40 | - api 'com.wd:wdkitcore:1.0.5' | ||
| 41 | - api 'com.wd:wdkit:1.0.1' | ||
| 42 | - api 'com.wd:wdnetwork:1.0.0' | ||
| 43 | - api 'com.wd:wdinterface:1.0.3' | ||
| 44 | - // api 'com.wd:servicekit:1.0.3' | ||
| 45 | - api 'com.wd:wdrouter:1.0.0' | ||
| 46 | - api 'com.wd:log:1.0.1' | ||
| 47 | - api 'com.wd:startup:1.0.0' | ||
| 48 | - | 41 | + api project(path: ':wdrouter') |
| 42 | + api project(path: ':wdlog') | ||
| 43 | + api project(path: ':wdkit') | ||
| 44 | + api project(path: ':wdnetwork') | ||
| 49 | // 基础依赖库 | 45 | // 基础依赖库 |
| 50 | api 'com.alibaba:arouter-api:1.5.2' | 46 | api 'com.alibaba:arouter-api:1.5.2' |
| 51 | - api 'com.squareup.okhttp3:okhttp:4.8.0' | ||
| 52 | - api 'com.squareup.retrofit2:retrofit:2.9.0' | ||
| 53 | - api 'com.squareup.retrofit2:converter-gson:2.9.0' | ||
| 54 | - api 'com.squareup.retrofit2:adapter-rxjava2:2.9.0' | ||
| 55 | - //rxjava | ||
| 56 | - api 'io.reactivex.rxjava2:rxjava:2.2.8' | ||
| 57 | - api 'io.reactivex.rxjava2:rxandroid:2.1.0' | ||
| 58 | - //解析bean | ||
| 59 | - api 'com.alibaba:fastjson:1.2.62' | ||
| 60 | - api 'com.airbnb.android:lottie:5.2.0' | ||
| 61 | - api 'androidx.appcompat:appcompat:1.2.0' | ||
| 62 | - api 'androidx.lifecycle:lifecycle-extensions:2.2.0' | 47 | +// api 'com.wd:wdkitcore:1.0.5' |
| 48 | +// api 'com.wd:wdkit:1.0.1' | ||
| 49 | +// api 'com.wd:wdnetwork:1.0.0' | ||
| 50 | +// api 'com.wd:wdinterface:1.0.3' | ||
| 51 | + // api 'com.wd:servicekit:1.0.3' | ||
| 52 | +// api 'com.wd:wdrouter:1.0.0' | ||
| 53 | +// api 'com.wd:log:1.0.1' | ||
| 54 | +// api 'com.wd:startup:1.0.0' | ||
| 55 | + | ||
| 56 | + api rootProject.ext.dependencies["lifecycle-extensions"] | ||
| 57 | + api rootProject.ext.dependencies["lifecycle-compiler"] | ||
| 58 | + | ||
| 59 | + api rootProject.ext.dependencies["refresh-layout"]// 核心必须依赖 | ||
| 60 | + api rootProject.ext.dependencies["refresh-header"]// 经典刷新头 | ||
| 61 | + api rootProject.ext.dependencies["refresh-footer"]// 经典加载 | ||
| 63 | } | 62 | } |
| 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 3 | package="com.wd.fastcoding.base"> | 3 | package="com.wd.fastcoding.base"> |
| 4 | - | 4 | + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> |
| 5 | + <uses-permission android:name="android.permission.REORDER_TASKS" /> | ||
| 5 | </manifest> | 6 | </manifest> |
No preview for this file type
| 1 | +package com.wd.common.adv; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.wd.foundation.bean.adv.CompAdvBean; | ||
| 5 | +import com.wd.foundation.wdkit.utils.TimeUtil; | ||
| 6 | +import com.wd.foundation.wdkitcore.tools.ArrayUtils; | ||
| 7 | + | ||
| 8 | +import java.security.SecureRandom; | ||
| 9 | +import java.util.ArrayList; | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 广告工具类 | ||
| 14 | + * @author baozhaoxin | ||
| 15 | + * @version [V1.0.0, 2023/10/30] | ||
| 16 | + * @since V1.0.0 | ||
| 17 | + */ | ||
| 18 | +public class AdvUtils { | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 根据开屏广告规则,获取符合条件的数据 | ||
| 22 | + * @param launchAdInfo | ||
| 23 | + * @return | ||
| 24 | + */ | ||
| 25 | + public static CompAdvBean getLaunchAdInfoForRule(List<CompAdvBean> launchAdInfo){ | ||
| 26 | + if(ArrayUtils.isEmpty(launchAdInfo)){ | ||
| 27 | + return null; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + //A、按时间维度过滤数据 | ||
| 31 | + List<CompAdvBean> timeDatas = AdvUtils.getDataForTime(launchAdInfo); | ||
| 32 | + | ||
| 33 | + if(ArrayUtils.isEmpty(timeDatas)){ | ||
| 34 | + return null; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + //B、根据displayRound维度,获取符合条件的数据 | ||
| 38 | + CompAdvBean compAdvBean = AdvUtils.getDataForDisplayRound(timeDatas); | ||
| 39 | + return compAdvBean; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 获取符合时间要求的广告数据 | ||
| 44 | + * @param advBeanList | ||
| 45 | + * @return | ||
| 46 | + */ | ||
| 47 | + public static List<CompAdvBean> getDataForTime(List<CompAdvBean> advBeanList){ | ||
| 48 | + if(ArrayUtils.isEmpty(advBeanList)){ | ||
| 49 | + return null; | ||
| 50 | + } | ||
| 51 | + long serverTimeLong = TimeUtil.millis(); | ||
| 52 | + List<CompAdvBean> newDatas = new ArrayList<>(); | ||
| 53 | + for (CompAdvBean compAdvBean : advBeanList) { | ||
| 54 | + // 检测投放开始和结束日期 | ||
| 55 | + /*String startTimeStr = compAdvBean.getStartTime(); | ||
| 56 | + String endTimeStr = compAdvBean.getEndTime();*/ | ||
| 57 | + /*long startLong = TimeUtil.jsonToTimeInMillis2(startTimeStr); | ||
| 58 | + long endLong = TimeUtil.jsonToTimeInMillis2(endTimeStr);*/ | ||
| 59 | + //现在接口返回的是时间戳 | ||
| 60 | + long startLong = compAdvBean.getStartTime(); | ||
| 61 | + long endLong = compAdvBean.getEndTime(); | ||
| 62 | + if (serverTimeLong >= startLong && serverTimeLong <= endLong) { | ||
| 63 | + //符合开始时间和结束时间要求 | ||
| 64 | + newDatas.add(compAdvBean); | ||
| 65 | + } | ||
| 66 | + } | ||
| 67 | + return newDatas; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * 根据displayRound维度,获取符合条件的数据 | ||
| 72 | + * @param advBeanList | ||
| 73 | + * @return | ||
| 74 | + */ | ||
| 75 | + public static CompAdvBean getDataForDisplayRound(List<CompAdvBean> advBeanList){ | ||
| 76 | + if(ArrayUtils.isEmpty(advBeanList)){ | ||
| 77 | + return null; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + int totalRounds = 0; | ||
| 81 | + for (CompAdvBean compAdvBean : advBeanList) { | ||
| 82 | + totalRounds = totalRounds + compAdvBean.getDisplayRound(); | ||
| 83 | + } | ||
| 84 | + CompAdvBean resultAdvBean = null; | ||
| 85 | + try { | ||
| 86 | + SecureRandom random = new SecureRandom(); | ||
| 87 | + double randomNumber = random.nextDouble(); | ||
| 88 | + double adProbability = 0; | ||
| 89 | + for (CompAdvBean compAdvBean : advBeanList) { | ||
| 90 | + int adRound = compAdvBean.getDisplayRound(); | ||
| 91 | + double temp = (double) adRound / totalRounds; | ||
| 92 | + adProbability = temp + adProbability; | ||
| 93 | + if (randomNumber < adProbability && adRound > 0) { | ||
| 94 | + resultAdvBean = compAdvBean; | ||
| 95 | + break; | ||
| 96 | + } | ||
| 97 | + } | ||
| 98 | + } catch (Exception e) { | ||
| 99 | + e.printStackTrace(); | ||
| 100 | + } | ||
| 101 | + return resultAdvBean; | ||
| 102 | + } | ||
| 103 | +} |
| 1 | +package com.wd.common.adv; | ||
| 2 | + | ||
| 3 | +import android.app.Activity; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.view.ViewGroup; | ||
| 6 | +import android.view.Window; | ||
| 7 | +import android.widget.FrameLayout; | ||
| 8 | + | ||
| 9 | + | ||
| 10 | +import com.wd.common.utils.GrayManager; | ||
| 11 | +import com.wd.common.utils.ProcessUtils; | ||
| 12 | +import com.wd.common.widget.floating.DragView; | ||
| 13 | +import com.wd.foundation.bean.adv.AdvertsBean; | ||
| 14 | +import com.wd.foundation.bean.adv.AdvsRuleBean; | ||
| 15 | +import com.wd.foundation.bean.adv.CompAdvBean; | ||
| 16 | +import com.wd.foundation.bean.adv.CompAdvMatInfoBean; | ||
| 17 | +import com.wd.foundation.bean.adv.CompAdvSlotInfoBean; | ||
| 18 | +import com.wd.foundation.bean.custom.comp.PageBean; | ||
| 19 | +import com.wd.foundation.bean.custom.content.ContentBean; | ||
| 20 | +import com.wd.foundation.wdkit.system.FastClickUtil; | ||
| 21 | +import com.wd.foundation.wdkitcore.tools.ArrayUtils; | ||
| 22 | +import com.wd.foundation.wdkitcore.tools.StringUtils; | ||
| 23 | + | ||
| 24 | +import java.util.Collections; | ||
| 25 | +import java.util.Comparator; | ||
| 26 | +import java.util.List; | ||
| 27 | + | ||
| 28 | +/** | ||
| 29 | + * @Description: 挂角广告 | ||
| 30 | + * @Author: Li Yubing | ||
| 31 | + * @Email: liyubing@wondert.com.cn | ||
| 32 | + * @CreateDate: 2023/5/4 16:11 | ||
| 33 | + * @Version: 1.0 | ||
| 34 | + */ | ||
| 35 | +public class CornerAdvLogic { | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 挂角广告(左边) | ||
| 39 | + */ | ||
| 40 | + DragView leftDragView; | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 挂角广告(右边) | ||
| 44 | + */ | ||
| 45 | + DragView rightDragView; | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * 0:默认类型 | ||
| 49 | + * 1:系统状态栏 | ||
| 50 | + */ | ||
| 51 | + private int dragViewType = 0; | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 左挂角广告是否点击过关闭 | ||
| 55 | + */ | ||
| 56 | + private boolean isLeftDragViewClose = false; | ||
| 57 | + /** | ||
| 58 | + * 右挂角广告是否点击过关闭 | ||
| 59 | + */ | ||
| 60 | + private boolean isRightDragViewClose = false; | ||
| 61 | + | ||
| 62 | + private Activity activity; | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * 本地记录展示的广告数据(只有广告中心挂角才需要缓存) | ||
| 66 | + */ | ||
| 67 | + private CompAdvBean localCompAdvBean = null; | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * 本地记录展示的PageBean数据 | ||
| 71 | + */ | ||
| 72 | + private PageBean localPageBean = null; | ||
| 73 | + private String linkType = ""; | ||
| 74 | + | ||
| 75 | + public CornerAdvLogic(Activity activity) { | ||
| 76 | + this.activity = activity; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public void setDragViewType(int dragViewType) { | ||
| 80 | + this.dragViewType = dragViewType; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * 处理挂角广告view 展示逻辑 | ||
| 85 | + */ | ||
| 86 | + public void handlerAdLogic(Context mContext, PageBean mPageBean, boolean contryGrayFlag, | ||
| 87 | + Window window,boolean isResume) { | ||
| 88 | + if(isResume && localCompAdvBean != null){ | ||
| 89 | + //页面获取焦点且上次有展示的挂角,直接展示 | ||
| 90 | + removeAllDragView(false); | ||
| 91 | + showCornersAdv2(mContext,localCompAdvBean,mPageBean,contryGrayFlag,window,true, | ||
| 92 | + null); | ||
| 93 | + return; | ||
| 94 | + }else{ | ||
| 95 | + //false为接口刷新,更新挂角显示 | ||
| 96 | + isLeftDragViewClose = false; | ||
| 97 | + isRightDragViewClose = false; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + removeAllDragView(true); | ||
| 101 | + if (mPageBean == null) { | ||
| 102 | + return; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + if (mPageBean.isHasAdInfo() && mPageBean.getCornersAdv() != null) { | ||
| 106 | + // 优先展示展现中心广告 | ||
| 107 | + showDragView(mPageBean.getCornersAdv(), mPageBean, contryGrayFlag, window); | ||
| 108 | + } else if (!ArrayUtils.isEmpty(mPageBean.getCornersAdv2())) { | ||
| 109 | + // 广告中心-挂角广告信息 | ||
| 110 | + List<CompAdvBean> cornersAdv2 = mPageBean.getCornersAdv2(); | ||
| 111 | + List<CompAdvBean> compAdvBeanList = handlerCornersAdv2Data(mContext,cornersAdv2,mPageBean); | ||
| 112 | + if(ArrayUtils.isEmpty(compAdvBeanList)){ | ||
| 113 | + return; | ||
| 114 | + } | ||
| 115 | + CompAdvBean compAdvBean = compAdvBeanList.get(0); | ||
| 116 | + showCornersAdv2(mContext,compAdvBean,mPageBean,contryGrayFlag,window,false, | ||
| 117 | + compAdvBeanList); | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + /** | ||
| 122 | + * 显示挂角广告 | ||
| 123 | + * | ||
| 124 | + * @param cornersAdBean | ||
| 125 | + */ | ||
| 126 | + private void showDragView(AdvsRuleBean cornersAdBean, PageBean mPageBean, | ||
| 127 | + boolean contryGrayFlag, Window window) { | ||
| 128 | + ViewGroup.LayoutParams lp = | ||
| 129 | + new ViewGroup.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); | ||
| 130 | + if ("left_down".equals(cornersAdBean.getPos())) { | ||
| 131 | + if (isLeftDragViewClose) { | ||
| 132 | + return; | ||
| 133 | + } | ||
| 134 | + if (cornersAdBean.getAdvert() == null) { | ||
| 135 | + return; | ||
| 136 | + } | ||
| 137 | + if (leftDragView != null && leftDragView.getParent() != null) { | ||
| 138 | + ((ViewGroup) leftDragView.getParent()).removeView(leftDragView); | ||
| 139 | + } | ||
| 140 | + leftDragView = new DragView(activity, cornersAdBean, dragViewType); | ||
| 141 | + if (contryGrayFlag) { | ||
| 142 | + //处理挂角国殇模式 | ||
| 143 | + GrayManager.getInstance().setLayerGrayType(leftDragView); | ||
| 144 | + } | ||
| 145 | +// superRootLayout.addView(leftDragView, lp); | ||
| 146 | + ViewGroup viewgroup = (ViewGroup) window.getDecorView(); | ||
| 147 | + viewgroup.addView(leftDragView,lp); | ||
| 148 | + | ||
| 149 | + if (leftDragView.getAdvertsBean() != null) { | ||
| 150 | + // 挂角广告埋点-曝光事件 | ||
| 151 | +// AdvsTrack.dragViewContentTrack(0, mPageBean, cornersAdBean); | ||
| 152 | + } | ||
| 153 | + leftDragView.setOnDragViewClick(new DragView.DragViewClickListener() { | ||
| 154 | + @Override | ||
| 155 | + public void onImgClick() { | ||
| 156 | + if (FastClickUtil.isFastClick()) { | ||
| 157 | + return; | ||
| 158 | + } | ||
| 159 | + if (leftDragView.getAdvertsBean() != null) { | ||
| 160 | + // 挂角广告埋点-点击事件 | ||
| 161 | +// AdvsTrack.dragViewContentTrack(1, mPageBean, cornersAdBean); | ||
| 162 | + dragViewJump(leftDragView.getAdvertsBean()); | ||
| 163 | + } | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + @Override | ||
| 167 | + public void onCloseClick() { | ||
| 168 | + isLeftDragViewClose = true; | ||
| 169 | + removeLeftDragView(); | ||
| 170 | + } | ||
| 171 | + }); | ||
| 172 | + } else { | ||
| 173 | + if (isRightDragViewClose) { | ||
| 174 | + return; | ||
| 175 | + } | ||
| 176 | + if (cornersAdBean.getAdvert() == null) { | ||
| 177 | + return; | ||
| 178 | + } | ||
| 179 | + if (rightDragView != null && rightDragView.getParent() != null) { | ||
| 180 | + ((ViewGroup) rightDragView.getParent()).removeView(rightDragView); | ||
| 181 | + } | ||
| 182 | + rightDragView = new DragView(activity, cornersAdBean, dragViewType); | ||
| 183 | + if (contryGrayFlag) { | ||
| 184 | + //处理挂角国殇模式 | ||
| 185 | + GrayManager.getInstance().setLayerGrayType(rightDragView); | ||
| 186 | + } | ||
| 187 | +// superRootLayout.addView(rightDragView, lp); | ||
| 188 | +// window.addContentView(rightDragView,lp); | ||
| 189 | + ViewGroup viewgroup = (ViewGroup) window.getDecorView(); | ||
| 190 | + viewgroup.addView(rightDragView,lp); | ||
| 191 | + if (rightDragView.getAdvertsBean() != null) { | ||
| 192 | + // 挂角广告埋点-曝光事件 | ||
| 193 | +// AdvsTrack.dragViewContentTrack(0, mPageBean, cornersAdBean); | ||
| 194 | + } | ||
| 195 | + rightDragView.setOnDragViewClick(new DragView.DragViewClickListener() { | ||
| 196 | + @Override | ||
| 197 | + public void onImgClick() { | ||
| 198 | + if (FastClickUtil.isFastClick()) { | ||
| 199 | + return; | ||
| 200 | + } | ||
| 201 | + if (rightDragView.getAdvertsBean() != null) { | ||
| 202 | + // 挂角广告埋点-点击事件 | ||
| 203 | +// AdvsTrack.dragViewContentTrack(1, mPageBean, cornersAdBean); | ||
| 204 | + dragViewJump(rightDragView.getAdvertsBean()); | ||
| 205 | + } | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + @Override | ||
| 209 | + public void onCloseClick() { | ||
| 210 | + isRightDragViewClose = true; | ||
| 211 | + removeRightDragView(); | ||
| 212 | + } | ||
| 213 | + }); | ||
| 214 | + } | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + /** | ||
| 218 | + * 移除挂角广告 | ||
| 219 | + * @param clearLocalData 是否清除本地的广告数据(只有广告中心挂角才需要) | ||
| 220 | + */ | ||
| 221 | + public void removeAllDragView(boolean clearLocalData) { | ||
| 222 | + removeLeftDragView(); | ||
| 223 | + removeRightDragView(); | ||
| 224 | + if(clearLocalData){ | ||
| 225 | + localCompAdvBean = null; | ||
| 226 | + } | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + /** | ||
| 230 | + * 移除左边挂角广告 | ||
| 231 | + */ | ||
| 232 | + private void removeLeftDragView() { | ||
| 233 | + if (leftDragView != null && leftDragView.getParent() != null) { | ||
| 234 | + ((ViewGroup) leftDragView.getParent()).removeView(leftDragView); | ||
| 235 | + } | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + | ||
| 239 | + /** | ||
| 240 | + * 移除右边挂角广告 | ||
| 241 | + */ | ||
| 242 | + private void removeRightDragView() { | ||
| 243 | + if (rightDragView != null && rightDragView.getParent() != null) { | ||
| 244 | + ((ViewGroup) rightDragView.getParent()).removeView(rightDragView); | ||
| 245 | + } | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + | ||
| 249 | + /** | ||
| 250 | + * 挂角广告跳转 | ||
| 251 | + * | ||
| 252 | + * @param advertsBean | ||
| 253 | + */ | ||
| 254 | + private void dragViewJump(AdvertsBean advertsBean) { | ||
| 255 | + if (advertsBean == null) { | ||
| 256 | + return; | ||
| 257 | + } | ||
| 258 | + ContentBean contentBean = new ContentBean(); | ||
| 259 | + contentBean.setLinkUrl(advertsBean.getLinkUrl()); | ||
| 260 | + contentBean.setPageId(advertsBean.getPageId()); | ||
| 261 | + contentBean.setObjectId(advertsBean.getObjectId()); | ||
| 262 | + contentBean.setObjectLevel(advertsBean.getObjectLevel()); | ||
| 263 | + contentBean.setObjectType(advertsBean.getObjectType()); | ||
| 264 | + contentBean.setBottomNavId(advertsBean.getBottomNavId()); | ||
| 265 | + contentBean.setRelId(advertsBean.getRelId()); | ||
| 266 | + if(advertsBean.getShareInfo() != null){ | ||
| 267 | + contentBean.setShowH5Share(true); | ||
| 268 | + contentBean.setShareInfo(advertsBean.getShareInfo()); | ||
| 269 | + } | ||
| 270 | + //专题模板 --->专题样式 1:常规, 2:作者, 3:时间线 | ||
| 271 | + // contentBean.setTopicTemplate(advertsBean.getTopicTemplate()); | ||
| 272 | + ProcessUtils.processPage(contentBean); | ||
| 273 | + } | ||
| 274 | + | ||
| 275 | + /** | ||
| 276 | + * 处理广告中心挂角数据 | ||
| 277 | + * @param mContext | ||
| 278 | + * @param cornersAdv2 | ||
| 279 | + * @param mPageBean | ||
| 280 | + * @return | ||
| 281 | + */ | ||
| 282 | + private List<CompAdvBean> handlerCornersAdv2Data(Context mContext,List<CompAdvBean> cornersAdv2, | ||
| 283 | + PageBean mPageBean){ | ||
| 284 | + if(mPageBean == null){ | ||
| 285 | + return null; | ||
| 286 | + } | ||
| 287 | + if(ArrayUtils.isEmpty(cornersAdv2)){ | ||
| 288 | + return null; | ||
| 289 | + } | ||
| 290 | + //A、按时间维度过滤数据 | ||
| 291 | + List<CompAdvBean> timeDatas = AdvUtils.getDataForTime(cornersAdv2); | ||
| 292 | + if(ArrayUtils.isEmpty(timeDatas)){ | ||
| 293 | + return null; | ||
| 294 | + } | ||
| 295 | + | ||
| 296 | + //接口返回的数据已经过滤了符合时间规则的数据——页面会有缓存数据 | ||
| 297 | +// List<CompAdvBean> timeDatas = cornersAdv2; | ||
| 298 | + | ||
| 299 | + int size = timeDatas.size(); | ||
| 300 | + if (size > 1) { | ||
| 301 | + //B、按展现优先级维度 数值越小,等级越高 | ||
| 302 | + Collections.sort(timeDatas, new Comparator<CompAdvBean>() { | ||
| 303 | + @Override | ||
| 304 | + public int compare(CompAdvBean p1, CompAdvBean p2) { | ||
| 305 | + return p1.getDisplayPriority() - p2.getDisplayPriority(); | ||
| 306 | + } | ||
| 307 | + }); | ||
| 308 | + | ||
| 309 | + // C、 依据 展示的次数来过滤数据 | ||
| 310 | + //查询缓存数据,设置展示的次数 | ||
| 311 | +// for (CompAdvBean compAdvBean:timeDatas) { | ||
| 312 | +// String pageId = mPageBean.getId(); | ||
| 313 | +// String advId = compAdvBean.getId() + ""; | ||
| 314 | +// CornersAdvModel cornersAdvModel = CornersAdvDaoHelper.getInstance(mContext). | ||
| 315 | +// getByPageIdAndAdvId(pageId,advId); | ||
| 316 | +// if(cornersAdvModel != null){ | ||
| 317 | +// compAdvBean.setShowCount(cornersAdvModel.showCount); | ||
| 318 | +// } | ||
| 319 | +// } | ||
| 320 | + | ||
| 321 | + //通过展示次数进行排序,升序 | ||
| 322 | + Collections.sort(timeDatas, new Comparator<CompAdvBean>() { | ||
| 323 | + @Override | ||
| 324 | + public int compare(CompAdvBean p1, CompAdvBean p2) { | ||
| 325 | + return p1.getShowCount() - p2.getShowCount(); | ||
| 326 | + } | ||
| 327 | + }); | ||
| 328 | + } | ||
| 329 | + return timeDatas; | ||
| 330 | + } | ||
| 331 | + | ||
| 332 | + /** | ||
| 333 | + * 展示广告中心-挂角广告信息 | ||
| 334 | + * @param mContext | ||
| 335 | + * @param compAdvBean | ||
| 336 | + * @param mPageBean | ||
| 337 | + * @param contryGrayFlag | ||
| 338 | + * @param window | ||
| 339 | + */ | ||
| 340 | + private void showCornersAdv2(Context mContext,CompAdvBean compAdvBean, PageBean mPageBean, | ||
| 341 | + boolean contryGrayFlag, Window window,boolean isResume, | ||
| 342 | + List<CompAdvBean> compAdvBeanList) { | ||
| 343 | + if(mPageBean == null){ | ||
| 344 | + return; | ||
| 345 | + } | ||
| 346 | + if(compAdvBean == null ){ | ||
| 347 | + return; | ||
| 348 | + } | ||
| 349 | + compAdvBean.setPageId(mPageBean.getId()); | ||
| 350 | + CompAdvMatInfoBean compAdvMatInfoBean = compAdvBean.getMatInfo(); | ||
| 351 | + if(compAdvMatInfoBean == null){ | ||
| 352 | + return; | ||
| 353 | + } | ||
| 354 | + if(ArrayUtils.isEmpty(compAdvMatInfoBean.getMatImageUrl())){ | ||
| 355 | + return; | ||
| 356 | + } | ||
| 357 | + CompAdvSlotInfoBean compAdvSlotInfoBean = compAdvBean.getSlotInfo(); | ||
| 358 | + if(compAdvSlotInfoBean == null){ | ||
| 359 | + return; | ||
| 360 | + } | ||
| 361 | + localPageBean = mPageBean; | ||
| 362 | + localCompAdvBean = compAdvBean; | ||
| 363 | +// if(!isResume){ | ||
| 364 | +// //不是获取焦点 | ||
| 365 | +// int count = 0; | ||
| 366 | +// String pageId = mPageBean.getId(); | ||
| 367 | +// String advId = compAdvBean.getId() + ""; | ||
| 368 | +// CornersAdvModel cornersAdvModel = CornersAdvDaoHelper.getInstance(mContext). | ||
| 369 | +// getByPageIdAndAdvId(pageId,advId); | ||
| 370 | +// if(cornersAdvModel == null){ | ||
| 371 | +// //缓存中没有,为新广告,展示时存入缓存 | ||
| 372 | +// cornersAdvModel = new CornersAdvModel(); | ||
| 373 | +// cornersAdvModel.showCount = 1; | ||
| 374 | +// cornersAdvModel.pageId = pageId; | ||
| 375 | +// cornersAdvModel.advId = advId; | ||
| 376 | +// cornersAdvModel.keys = pageId+"_"+advId; | ||
| 377 | +// CornersAdvDaoHelper.getInstance(mContext).insert(cornersAdvModel); | ||
| 378 | +// count = 1; | ||
| 379 | +// }else { | ||
| 380 | +// int showCount = compAdvBean.getShowCount(); | ||
| 381 | +// if(showCount == 0){ | ||
| 382 | +// cornersAdvModel.showCount = 1; | ||
| 383 | +// count = 1; | ||
| 384 | +// CornersAdvDaoHelper.getInstance(mContext).insert(cornersAdvModel); | ||
| 385 | +// } | ||
| 386 | +// } | ||
| 387 | +// if(!ArrayUtils.isEmpty(compAdvBeanList)){ | ||
| 388 | +// | ||
| 389 | +// for (CompAdvBean bean:compAdvBeanList) { | ||
| 390 | +// if(bean.getShowCount() == 1){ | ||
| 391 | +// count++; | ||
| 392 | +// } | ||
| 393 | +// } | ||
| 394 | +// if(count == compAdvBeanList.size()){ | ||
| 395 | +// //新一轮开始 | ||
| 396 | +// CornersAdvDaoHelper.getInstance(mContext).updateAllShowCountTo0(); | ||
| 397 | +// } | ||
| 398 | +// } | ||
| 399 | +// } | ||
| 400 | + ViewGroup.LayoutParams lp = | ||
| 401 | + new ViewGroup.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, | ||
| 402 | + FrameLayout.LayoutParams.WRAP_CONTENT); | ||
| 403 | + if (compAdvSlotInfoBean.getPosition() == 0) { | ||
| 404 | + if (isLeftDragViewClose) { | ||
| 405 | + return; | ||
| 406 | + } | ||
| 407 | + if (leftDragView != null && leftDragView.getParent() != null) { | ||
| 408 | + ((ViewGroup) leftDragView.getParent()).removeView(leftDragView); | ||
| 409 | + } | ||
| 410 | + leftDragView = new DragView(activity, compAdvBean, dragViewType); | ||
| 411 | + if (contryGrayFlag) { | ||
| 412 | + //处理挂角国殇模式 | ||
| 413 | + GrayManager.getInstance().setLayerGrayType(leftDragView); | ||
| 414 | + } | ||
| 415 | +// superRootLayout.addView(leftDragView, lp); | ||
| 416 | +// window.addContentView(leftDragView,lp); | ||
| 417 | + ViewGroup viewgroup = (ViewGroup) window.getDecorView(); | ||
| 418 | + viewgroup.addView(leftDragView,lp); | ||
| 419 | + if (leftDragView.getCompAdvBean() != null) { | ||
| 420 | + // 挂角广告埋点-曝光事件 | ||
| 421 | +// AdvsTrack.dragViewContentTrack(0, mPageBean, cornersAdBean); | ||
| 422 | + } | ||
| 423 | + leftDragView.setOnDragViewClick(new DragView.DragViewClickListener() { | ||
| 424 | + @Override | ||
| 425 | + public void onImgClick() { | ||
| 426 | + if (FastClickUtil.isFastClick()) { | ||
| 427 | + return; | ||
| 428 | + } | ||
| 429 | + if (leftDragView.getCompAdvBean() != null) { | ||
| 430 | + // 挂角广告埋点-点击事件 | ||
| 431 | +// AdvsTrack.dragViewContentTrack(1, mPageBean, cornersAdBean); | ||
| 432 | + dragViewJump(mContext,leftDragView.getCompAdvBean()); | ||
| 433 | + } | ||
| 434 | + } | ||
| 435 | + | ||
| 436 | + @Override | ||
| 437 | + public void onCloseClick() { | ||
| 438 | + isLeftDragViewClose = true; | ||
| 439 | + removeLeftDragView(); | ||
| 440 | + } | ||
| 441 | + }); | ||
| 442 | + } else { | ||
| 443 | + if (isRightDragViewClose) { | ||
| 444 | + return; | ||
| 445 | + } | ||
| 446 | + if (rightDragView != null && rightDragView.getParent() != null) { | ||
| 447 | + ((ViewGroup) rightDragView.getParent()).removeView(rightDragView); | ||
| 448 | + } | ||
| 449 | + rightDragView = new DragView(activity, compAdvBean, dragViewType); | ||
| 450 | + if (contryGrayFlag) { | ||
| 451 | + //处理挂角国殇模式 | ||
| 452 | + GrayManager.getInstance().setLayerGrayType(rightDragView); | ||
| 453 | + } | ||
| 454 | +// superRootLayout.addView(rightDragView, lp); | ||
| 455 | +// window.addContentView(rightDragView,lp); | ||
| 456 | + ViewGroup viewgroup = (ViewGroup) window.getDecorView(); | ||
| 457 | + viewgroup.addView(rightDragView,lp); | ||
| 458 | + if (rightDragView.getCompAdvBean() != null) { | ||
| 459 | + // 挂角广告埋点-曝光事件 | ||
| 460 | +// AdvsTrack.dragViewContentTrack(0, mPageBean, cornersAdBean); | ||
| 461 | + } | ||
| 462 | + rightDragView.setOnDragViewClick(new DragView.DragViewClickListener() { | ||
| 463 | + @Override | ||
| 464 | + public void onImgClick() { | ||
| 465 | + if (FastClickUtil.isFastClick()) { | ||
| 466 | + return; | ||
| 467 | + } | ||
| 468 | + if (rightDragView.getCompAdvBean() != null) { | ||
| 469 | + // 挂角广告埋点-点击事件 | ||
| 470 | +// AdvsTrack.dragViewContentTrack(1, mPageBean, cornersAdBean); | ||
| 471 | + dragViewJump(mContext,rightDragView.getCompAdvBean()); | ||
| 472 | + } | ||
| 473 | + } | ||
| 474 | + | ||
| 475 | + @Override | ||
| 476 | + public void onCloseClick() { | ||
| 477 | + isRightDragViewClose = true; | ||
| 478 | + removeRightDragView(); | ||
| 479 | + } | ||
| 480 | + }); | ||
| 481 | + } | ||
| 482 | + } | ||
| 483 | + | ||
| 484 | + /** | ||
| 485 | + * 广告中心挂角广告跳转 | ||
| 486 | + * @param mContext | ||
| 487 | + * @param compAdvBean | ||
| 488 | + */ | ||
| 489 | + private void dragViewJump(Context mContext,CompAdvBean compAdvBean) { | ||
| 490 | + if (compAdvBean == null) { | ||
| 491 | + return; | ||
| 492 | + } | ||
| 493 | + CompAdvMatInfoBean matInfoBean = compAdvBean.getMatInfo(); | ||
| 494 | + if(matInfoBean == null){ | ||
| 495 | + return; | ||
| 496 | + } | ||
| 497 | + //优先openType,再取linkType | ||
| 498 | + if (StringUtils.isNotBlank(matInfoBean.getOpenType())){ | ||
| 499 | + linkType = matInfoBean.getOpenType(); | ||
| 500 | + }else { | ||
| 501 | + linkType = matInfoBean.getLinkType(); | ||
| 502 | + } | ||
| 503 | + | ||
| 504 | + if(StringUtils.isEqual("0",linkType)){ | ||
| 505 | + // 0:无链接; | ||
| 506 | + return; | ||
| 507 | + } | ||
| 508 | + String linkUrl = matInfoBean.getLinkUrl(); | ||
| 509 | + if(StringUtils.isEmpty(linkUrl)){ | ||
| 510 | + return; | ||
| 511 | + } | ||
| 512 | + if(StringUtils.isEqual("1",linkType)){ | ||
| 513 | + //内链 | ||
| 514 | +// ProcessUtils.goToH5Page(new ContentBean(linkUrl)); | ||
| 515 | + }else if(StringUtils.isEqual("2",linkType)){ | ||
| 516 | + //外链 | ||
| 517 | +// ProcessUtils.jumpBrowser(mContext,linkUrl); | ||
| 518 | + } | ||
| 519 | + } | ||
| 520 | + | ||
| 521 | + | ||
| 522 | +} |
| 1 | +package com.wd.common.api; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.wd.capability.network.bean.TokenBean; | ||
| 5 | +import com.wd.capability.network.response.BaseResponse; | ||
| 6 | + | ||
| 7 | +import io.reactivex.Observable; | ||
| 8 | +import okhttp3.RequestBody; | ||
| 9 | +import retrofit2.Call; | ||
| 10 | +import retrofit2.http.Body; | ||
| 11 | +import retrofit2.http.Header; | ||
| 12 | +import retrofit2.http.POST; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * 描述:接口定义 | ||
| 16 | + * | ||
| 17 | + * @author : lvjinhui | ||
| 18 | + * @since: 2022/12/15 | ||
| 19 | + */ | ||
| 20 | +public interface IRefreshToken { | ||
| 21 | + | ||
| 22 | + @POST("api/rmrb-user-center/auth/zh/c/refreshToken") | ||
| 23 | + Call<BaseResponse<TokenBean>> getJwtToken(@Header("RMRB-X-TOKEN")String token, @Body RequestBody body); | ||
| 24 | + | ||
| 25 | + @POST("api/rmrb-user-center/auth/zh/c/refreshToken") | ||
| 26 | + Observable<BaseResponse<TokenBean>> getJwtTokenForJS(@Header("RMRB-X-TOKEN")String token, @Body RequestBody body); | ||
| 27 | +} |
| 1 | + | ||
| 2 | +/* | ||
| 3 | + * Copyright (c) Wondertek Technologies Co., Ltd. 2019-2022. All rights reserved. | ||
| 4 | + */ | ||
| 5 | + | ||
| 6 | +package com.wd.common.api; | ||
| 7 | + | ||
| 8 | + | ||
| 9 | +import com.wd.capability.network.response.BaseResponse; | ||
| 10 | +import com.wd.foundation.bean.comment.DisplayWorkInfoBean; | ||
| 11 | +import com.wd.foundation.bean.custom.comp.CompBean; | ||
| 12 | +import com.wd.foundation.bean.custom.comp.GroupBean; | ||
| 13 | +import com.wd.foundation.bean.custom.comp.PageBean; | ||
| 14 | +import com.wd.foundation.bean.live.RoomDataBean; | ||
| 15 | +import com.wd.foundation.bean.paper.PaperBean; | ||
| 16 | +import com.wd.foundation.bean.paper.PaperNumInforListBean; | ||
| 17 | +import com.wd.foundation.bean.response.AreaTreeselectBean; | ||
| 18 | +import com.wd.foundation.bean.response.BottomNavBean; | ||
| 19 | +import com.wd.foundation.bean.response.ContentPageListBean; | ||
| 20 | +import com.wd.foundation.bean.response.FollowBean; | ||
| 21 | +import com.wd.foundation.bean.response.FollowListIndexBean; | ||
| 22 | +import com.wd.foundation.bean.response.FollowWorksBean; | ||
| 23 | +import com.wd.foundation.bean.response.LiveStatusBean; | ||
| 24 | +import com.wd.foundation.bean.response.MasterFollowsStatusBean; | ||
| 25 | +import com.wd.foundation.bean.response.PageTopNavBean; | ||
| 26 | +import com.wd.foundation.bean.response.PersonalInfoBean; | ||
| 27 | +import com.wd.foundation.bean.response.VideoItemBean; | ||
| 28 | + | ||
| 29 | +import java.util.List; | ||
| 30 | +import java.util.Map; | ||
| 31 | + | ||
| 32 | +import io.reactivex.Observable; | ||
| 33 | +import okhttp3.RequestBody; | ||
| 34 | +import okhttp3.ResponseBody; | ||
| 35 | +import retrofit2.http.Body; | ||
| 36 | +import retrofit2.http.GET; | ||
| 37 | +import retrofit2.http.Headers; | ||
| 38 | +import retrofit2.http.POST; | ||
| 39 | +import retrofit2.http.Query; | ||
| 40 | +import retrofit2.http.QueryMap; | ||
| 41 | + | ||
| 42 | +/** | ||
| 43 | + * 请求的接口 | ||
| 44 | + * | ||
| 45 | + * @author shishuagnxi | ||
| 46 | + */ | ||
| 47 | +public interface RequestApi { | ||
| 48 | + /** | ||
| 49 | + * 底部导航栏列表接口,底部导航栏 | ||
| 50 | + */ | ||
| 51 | + @GET("api/rmrb-bff-display-zh/display/zh/c/bottomNavGroup") | ||
| 52 | + Observable<BaseResponse<BottomNavBean>> getBottomNavGroup(); | ||
| 53 | + | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 根据底部导航栏id获取导航栏信息,头部频道 | ||
| 57 | + */ | ||
| 58 | + @GET("api/rmrb-bff-display-zh/display/zh/c/bottomNavGroup/detail") | ||
| 59 | + Observable<BaseResponse<PageTopNavBean>> getTopNavDetail(@QueryMap Map<String, Object> map); | ||
| 60 | + | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * 根据底部导航栏id获取导航栏信息V1.0--除默认启动时间线频道第一页情况外使用 | ||
| 64 | + */ | ||
| 65 | + @GET("api/rmrb-bff-display-zh/display/zh/c/pageInfo") | ||
| 66 | + Observable<BaseResponse<PageBean>> getPageData(@QueryMap Map<String, Object> map); | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * 根据底部导航栏id获取导航栏信息V1.0---热点频道第一页数据使用该接口,pageInfo合并了compInfo数据 | ||
| 70 | + */ | ||
| 71 | + @GET("api/rmrb-bff-display-zh/display/zh/c/pageInfo/v2") | ||
| 72 | + Observable<BaseResponse<PageBean>> getPageDataV2(@QueryMap Map<String, Object> map); | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * 根据楼层Id获取组件节目信息V1.0,【推荐频道】 | ||
| 76 | + */ | ||
| 77 | + @GET("api/rmrb-bff-display-zh/display/zh/c/rec/compInfo") | ||
| 78 | + Observable<BaseResponse<GroupBean>> getRecGroupData(@QueryMap Map<String, Object> map); | ||
| 79 | + | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * 根据楼层Id获取组件节目信息V1.0 | ||
| 83 | + */ | ||
| 84 | + @GET("api/rmrb-bff-display-zh/display/zh/c/compInfo") | ||
| 85 | + Observable<BaseResponse<GroupBean>> getGroupData(@QueryMap Map<String, Object> map); | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * 一级沉浸式视频推荐 | ||
| 89 | + * 4.2 视频分页列表 | ||
| 90 | + */ | ||
| 91 | + @GET("prod-api/content/content/list") | ||
| 92 | + Observable<BaseResponse<List<VideoItemBean>>> getImmersiveRecommend(@QueryMap Map<String, Object> map); | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * 一级二级 批量查询视频详情 | ||
| 96 | + * ids number [] | ||
| 97 | + * 点播播放详情批量查询 | ||
| 98 | + */ | ||
| 99 | + @POST("prod-api/content/content/detail") | ||
| 100 | + Observable<BaseResponse<List<VideoItemBean>>> getBatchShortPlayDetail(@Body RequestBody body); | ||
| 101 | + /** | ||
| 102 | + * 一级二级 查询单个视频详情 | ||
| 103 | + */ | ||
| 104 | + | ||
| 105 | + @GET("prod-api/content/content/{id}") | ||
| 106 | + Observable<BaseResponse<VideoItemBean>> getShortPlayDetail(@Query("Id") String Id); | ||
| 107 | + /** | ||
| 108 | + * 二级 推荐数据列表 | ||
| 109 | + */ | ||
| 110 | + @GET("prod-api/content/content/current/list") | ||
| 111 | + Observable<BaseResponse<List<VideoItemBean>>> getRecommendList(@QueryMap Map<String, Object> map); | ||
| 112 | + | ||
| 113 | + | ||
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * 获取指定日期电子报版面信息 | ||
| 117 | + * | ||
| 118 | + * @return | ||
| 119 | + */ | ||
| 120 | + @GET("api/rmrb-bff-display-zh/display/zh/c/paperApi/paperTime") | ||
| 121 | + Observable<BaseResponse<List<PaperNumInforListBean>>> paperTime(@QueryMap Map<String, Object> map); | ||
| 122 | + | ||
| 123 | + | ||
| 124 | + /** | ||
| 125 | + * 获取电子报版面数据 | ||
| 126 | + * | ||
| 127 | + * @return | ||
| 128 | + */ | ||
| 129 | + @GET("api/rmrb-bff-display-zh/display/zh/c/paperApi/paperList") | ||
| 130 | + Observable<BaseResponse<PaperBean>> paperList(@QueryMap Map<String, Object> map); | ||
| 131 | + | ||
| 132 | + /** | ||
| 133 | + * 获取电子报版面数据-查询最近一期电子报的首个版面信息 | ||
| 134 | + * | ||
| 135 | + * @return | ||
| 136 | + */ | ||
| 137 | + @GET("api/rmrb-bff-display-zh/display/zh/c/paperApi/firstPaper") | ||
| 138 | + Observable<BaseResponse<PaperBean>> firstPaperList(@QueryMap Map<String, Object> map); | ||
| 139 | + | ||
| 140 | + /** | ||
| 141 | + * 一键读报 | ||
| 142 | + * | ||
| 143 | + * @return | ||
| 144 | + */ | ||
| 145 | + @GET("api/rmrb-bff-display-zh/content/zh/c/newsPaper/read") | ||
| 146 | + Observable<BaseResponse<ContentPageListBean>> oneKeyRead(@QueryMap Map<String, Object> map); | ||
| 147 | + | ||
| 148 | + /** | ||
| 149 | + * 获取已发布默认词 | ||
| 150 | + */ | ||
| 151 | + @GET("api/rmrb-search-api/zh/c/hints") | ||
| 152 | + Observable<BaseResponse<List<String>>> getSearchHints(); | ||
| 153 | + | ||
| 154 | + /** | ||
| 155 | + * 兴趣标签卡选择标签 | ||
| 156 | + * @param body | ||
| 157 | + * @return | ||
| 158 | + */ | ||
| 159 | + @POST("api/rmrb-user-center/user/zh/c/tag/updateUserTagWord") | ||
| 160 | + Observable<BaseResponse<Object>> updateUserTagWord(@Body RequestBody body); | ||
| 161 | + | ||
| 162 | + /** | ||
| 163 | + * 直播内容回顾、预约组件-更多(预约列表) | ||
| 164 | + * | ||
| 165 | + * @return | ||
| 166 | + */ | ||
| 167 | + @GET("api/rmrb-bff-display-zh/display/zh/c/channel/live/reviewList") | ||
| 168 | + Observable<BaseResponse<ContentPageListBean>> queryLiveChannelReviewList(@QueryMap Map<String, Object> map); | ||
| 169 | + | ||
| 170 | + /** | ||
| 171 | + * 直播月度排行列表 | ||
| 172 | + * | ||
| 173 | + * @return | ||
| 174 | + */ | ||
| 175 | + @GET("api/rmrb-bff-display-zh/display/zh/c/channel/live/browseList") | ||
| 176 | + Observable<BaseResponse<ContentPageListBean>> queryLiveChannelBrowseList(@QueryMap Map<String, Object> map); | ||
| 177 | + | ||
| 178 | + /** | ||
| 179 | + * 直播频道直播列表 | ||
| 180 | + * | ||
| 181 | + * @return | ||
| 182 | + */ | ||
| 183 | + @GET("api/rmrb-bff-display-zh/display/zh/c/channel/live/list") | ||
| 184 | + Observable<BaseResponse<ContentPageListBean>> queryLiveChannelList(@QueryMap Map<String, Object> map); | ||
| 185 | + | ||
| 186 | + /** | ||
| 187 | + * 批查直播状态 | ||
| 188 | + * | ||
| 189 | + * @param liveIds | ||
| 190 | + * @return | ||
| 191 | + */ | ||
| 192 | + @GET("api/rmrb-bff-content/b/zh/content/c/liveRoom/batch/liveStatus") | ||
| 193 | + Observable<BaseResponse<List<LiveStatusBean>>> getLiveStatus(@Query("liveIds") String liveIds); | ||
| 194 | + | ||
| 195 | + /** | ||
| 196 | + * 获取行政区 | ||
| 197 | + */ | ||
| 198 | + @Headers({"urlname:https://restapi.amap.com/"}) | ||
| 199 | + @GET("v3/config/district") | ||
| 200 | + Observable<ResponseBody> getDistrictData(@QueryMap Map<String, Object> map); | ||
| 201 | + /** | ||
| 202 | + * 中文端的 | ||
| 203 | + */ | ||
| 204 | + @GET("api/rmrb-content-center/c/service/sys-area/treeselect") | ||
| 205 | + Observable<BaseResponse<List<AreaTreeselectBean>>> getAreaReveal(@Query("md5") String md5); | ||
| 206 | + | ||
| 207 | + /** | ||
| 208 | + * 获取二级地理信息 | ||
| 209 | + * @return | ||
| 210 | + */ | ||
| 211 | + @GET("api/rmrb-content-center/zh/c/sys-area/treeList") | ||
| 212 | + Observable<BaseResponse<List<AreaTreeselectBean>>> getTreeList(); | ||
| 213 | + | ||
| 214 | + | ||
| 215 | + /** | ||
| 216 | + * (关注/取消关注) | ||
| 217 | + */ | ||
| 218 | + @POST("api/rmrb-interact/interact/zh/c/attention/operation") | ||
| 219 | + Observable<BaseResponse<Object>> postFocusUser(@Body RequestBody body); | ||
| 220 | + | ||
| 221 | + | ||
| 222 | + /** | ||
| 223 | + * 一键关注接口 | ||
| 224 | + */ | ||
| 225 | + @POST("api/rmrb-interact/interact/zh/c/attention/batch") | ||
| 226 | + Observable<BaseResponse<Object>> batchAttention(@Body RequestBody body); | ||
| 227 | + | ||
| 228 | + /** | ||
| 229 | + * 批量查询创作者的关注状态 | ||
| 230 | + * | ||
| 231 | + * @param map | ||
| 232 | + * @return | ||
| 233 | + */ | ||
| 234 | + @POST("api/rmrb-interact/interact/zh/c/batchAttention/status") | ||
| 235 | + Observable<BaseResponse<List<MasterFollowsStatusBean>>> getBatchAttentionStatus(@Body RequestBody map); | ||
| 236 | + | ||
| 237 | + /** | ||
| 238 | + * 我的关注列表查询 | ||
| 239 | + * @param map | ||
| 240 | + */ | ||
| 241 | + @GET("api/rmrb-interact/interact/zh/c/attention/list") | ||
| 242 | + Observable<BaseResponse<FollowListIndexBean>> getAttentionList(@QueryMap Map<String, Object> map); | ||
| 243 | + /** | ||
| 244 | + * 客态查看别人的关注列表 | ||
| 245 | + * @param map | ||
| 246 | + * @return | ||
| 247 | + */ | ||
| 248 | + @GET("api/rmrb-interact/interact/zh/c/userAttention/list") | ||
| 249 | + Observable<BaseResponse<FollowListIndexBean>> getUserAttentionList(@QueryMap Map<String, Object> map); | ||
| 250 | + | ||
| 251 | + /** | ||
| 252 | + * 人民号关注页面 --人民号号主推荐 | ||
| 253 | + * | ||
| 254 | + * @return | ||
| 255 | + */ | ||
| 256 | + @POST("api/rmrb-bff-display-zh/recommend/zh/c/rmh") | ||
| 257 | + Observable<BaseResponse<List<FollowBean>>> recommendMaterList(@Body RequestBody map); | ||
| 258 | + | ||
| 259 | + /** | ||
| 260 | + * 我关注的创作者发布的内容列表查询 | ||
| 261 | + * | ||
| 262 | + * @return | ||
| 263 | + */ | ||
| 264 | + @POST("api/rmrb-bff-display-zh/content/zh/c/attention/contentList") | ||
| 265 | + Observable<BaseResponse<FollowWorksBean>> contentList(@Body RequestBody map); | ||
| 266 | + | ||
| 267 | + | ||
| 268 | + /** | ||
| 269 | + * 批量查询当前内容——用户点赞、收藏状态 | ||
| 270 | + */ | ||
| 271 | + @POST("api/rmrb-interact/interact/zh/c/batchLikeAndCollect/status") | ||
| 272 | + Observable<BaseResponse<List<DisplayWorkInfoBean>>> batchLikeAndCollectStatus(@Body RequestBody body); | ||
| 273 | + | ||
| 274 | + /** | ||
| 275 | + * C端批量查询直播信息 | ||
| 276 | + */ | ||
| 277 | + @GET("api/live-center-message/zh/a/live/room/number/batch/all") | ||
| 278 | + Observable<BaseResponse<List<RoomDataBean>>> getRoomBatchData(@QueryMap Map<String, Object> map); | ||
| 279 | + | ||
| 280 | + /** | ||
| 281 | + * 批量查询创作者信息 | ||
| 282 | + */ | ||
| 283 | + @POST("api/rmrb-contact/contact/zh/c/master/detailList") | ||
| 284 | + Observable<BaseResponse<List<PersonalInfoBean>>> getMasterInfoListData(@Body() RequestBody body); | ||
| 285 | + | ||
| 286 | + | ||
| 287 | + /** | ||
| 288 | + * 本地问政卡刷新接口 | ||
| 289 | + */ | ||
| 290 | + @GET("api/rmrb-bff-display-zh/display/zh/c/compInfo/localAsk") | ||
| 291 | + Observable<BaseResponse<CompBean>> localAsk(@QueryMap Map<String, Object> map); | ||
| 292 | + | ||
| 293 | +} |
| 1 | +/* | ||
| 2 | + * Copyright (c) Wondertek Technologies Co., Ltd. 2019-2022. All rights reserved. | ||
| 3 | + */ | ||
| 4 | + | ||
| 5 | +package com.wd.common.base; | ||
| 6 | + | ||
| 7 | + | ||
| 8 | + | ||
| 9 | +import android.app.Activity; | ||
| 10 | +import android.app.Dialog; | ||
| 11 | +import android.content.Intent; | ||
| 12 | +import android.content.pm.ActivityInfo; | ||
| 13 | +import android.content.res.TypedArray; | ||
| 14 | +import android.os.Build; | ||
| 15 | +import android.os.Bundle; | ||
| 16 | +import android.text.TextUtils; | ||
| 17 | +import android.util.Log; | ||
| 18 | +import android.view.View; | ||
| 19 | + | ||
| 20 | +import androidx.annotation.NonNull; | ||
| 21 | +import androidx.annotation.Nullable; | ||
| 22 | +import androidx.core.content.ContextCompat; | ||
| 23 | +import androidx.lifecycle.Observer; | ||
| 24 | + | ||
| 25 | + | ||
| 26 | +import com.wd.base.log.Logger; | ||
| 27 | +import com.wd.capability.network.constant.NetConstant; | ||
| 28 | +import com.wd.capability.router.data.ActionBean; | ||
| 29 | +import com.wd.capability.router.data.RouterParameter; | ||
| 30 | +import com.wd.capability.network.constant.EventConstants; | ||
| 31 | +import com.wd.common.dialog.DialogUtils; | ||
| 32 | +import com.wd.common.dialog.FlowTooBigDialog; | ||
| 33 | +import com.wd.common.permissions.IPmsCallBack; | ||
| 34 | +import com.wd.common.permissions.PermissionsUtils; | ||
| 35 | +import com.wd.common.utils.NotificationUtils; | ||
| 36 | +import com.wd.common.utils.ProcessUtils; | ||
| 37 | +import com.wd.common.utils.ToolsUtil; | ||
| 38 | +import com.wd.common.widget.CustomTitleBar; | ||
| 39 | +import com.wd.common.widget.DefaultView; | ||
| 40 | +import com.wd.fastcoding.base.R; | ||
| 41 | +import com.wd.foundation.bean.livedate.NetStateMessage; | ||
| 42 | +import com.wd.foundation.wdkit.mvvm.base.BaseMvvmActivity; | ||
| 43 | +import com.wd.foundation.wdkit.statusbar.StatusBarCompat; | ||
| 44 | +import com.wd.foundation.wdkit.statusbar.StatusBarStyleEnum; | ||
| 45 | +import com.wd.foundation.wdkit.utils.SpUtils; | ||
| 46 | +import com.wd.foundation.wdkitcore.livedata.LiveDataBus; | ||
| 47 | + | ||
| 48 | +import java.lang.reflect.Field; | ||
| 49 | +import java.lang.reflect.Method; | ||
| 50 | + | ||
| 51 | +/** | ||
| 52 | + * Activity的基类<BR> | ||
| 53 | + * | ||
| 54 | + * @author zhangbo | ||
| 55 | + * @version [V1.0.0, 2020/10/24] | ||
| 56 | + * @since V1.0.0 | ||
| 57 | + */ | ||
| 58 | +public abstract class BaseActivity extends BaseMvvmActivity implements CustomTitleBar.TitleBarClickListener, NotificationUtils.NotificationListener, StatusBarCompat.NavigationBarInterface { | ||
| 59 | + private NotificationUtils notificationUtils; | ||
| 60 | + | ||
| 61 | + | ||
| 62 | + protected static final int SEL_TYPE_PIC = 0; | ||
| 63 | + | ||
| 64 | + protected static final int SEL_TYPE_VIDEO = 1; | ||
| 65 | + | ||
| 66 | + protected static final int SEL_TYPE_ALL = 2; | ||
| 67 | + /** | ||
| 68 | + * 记录开启页面时间 | ||
| 69 | + */ | ||
| 70 | + private long startTime; | ||
| 71 | + /** | ||
| 72 | + * 浏览时长 | ||
| 73 | + */ | ||
| 74 | + public long duration; | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * 是否第一次加载 | ||
| 78 | + */ | ||
| 79 | + protected boolean isFirstLoad = true; | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * tag | ||
| 83 | + */ | ||
| 84 | + private static final String TAG = "BaseActivity"; | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * 导航栏控件 | ||
| 88 | + */ | ||
| 89 | + protected CustomTitleBar titleBar; | ||
| 90 | + | ||
| 91 | + /** | ||
| 92 | + * 导航栏标题内容 | ||
| 93 | + */ | ||
| 94 | + protected String titleContent; | ||
| 95 | + | ||
| 96 | + /** | ||
| 97 | + * 拍照保存路径 | ||
| 98 | + */ | ||
| 99 | + private String mPhotoPath; | ||
| 100 | + | ||
| 101 | + private Dialog mLoadingDialog; | ||
| 102 | + | ||
| 103 | + private boolean mIsShowTitleBar = true; | ||
| 104 | + | ||
| 105 | + private boolean mNetStateObserver; | ||
| 106 | + | ||
| 107 | + private Object actionBeanObject; | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * 缺省页 | ||
| 111 | + */ | ||
| 112 | + private DefaultView baseDefaultView; | ||
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * 重试按钮点击监听 | ||
| 116 | + */ | ||
| 117 | + private DefaultView.RetryClickListener retryClickListener; | ||
| 118 | + | ||
| 119 | + private FlowTooBigDialog flowTooBigDialog; | ||
| 120 | + | ||
| 121 | + public int statusHeight; | ||
| 122 | + | ||
| 123 | + /* | ||
| 124 | + Cannot add the same observer with different lifecycles异常 | ||
| 125 | + * 占位、规避 当liveData多次调用observe时, 如果Observer使用lambda, 并且lamba中没有引用非静态变量或方法时, 可能就会出现crash! (为什么是可能, 可以看 后续) | ||
| 126 | + * */ | ||
| 127 | + public int forLiveDataBus; | ||
| 128 | + /** | ||
| 129 | + * 是否显示音频播放浮窗 | ||
| 130 | + */ | ||
| 131 | + private boolean canShowMusicPlay; | ||
| 132 | + | ||
| 133 | + public Activity mBaseActivity; | ||
| 134 | + | ||
| 135 | + /** | ||
| 136 | + * 夜间模式是否需要保存原有状态 | ||
| 137 | + */ | ||
| 138 | + private boolean isNightKeep = false; | ||
| 139 | + | ||
| 140 | + @Override | ||
| 141 | + protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
| 142 | + try { | ||
| 143 | + parseExtrasKeyData(); | ||
| 144 | + } catch (Exception e) { | ||
| 145 | + Logger.t(TAG).e(e.getMessage()); | ||
| 146 | + } | ||
| 147 | + statusHeight = StatusBarCompat.getStatusBarHeight(this); | ||
| 148 | + super.onCreate(savedInstanceState); | ||
| 149 | + mBaseActivity = this; | ||
| 150 | + if (savedInstanceState != null) { | ||
| 151 | + // 重新启动App -> 杀进程 | ||
| 152 | + ProcessUtils.startWelcomeActivity(); | ||
| 153 | + android.os.Process.killProcess(android.os.Process.myPid()); | ||
| 154 | + return; | ||
| 155 | + } | ||
| 156 | + if (getTag() != null) { | ||
| 157 | + Logger.t(TAG).d(this.getClass().getName() + "//"); | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + isNightKeep = setNightKeep(); | ||
| 161 | + initStatusBar(); | ||
| 162 | + setTopMargin(statusHeight); | ||
| 163 | + initDataBus(); | ||
| 164 | + canShowMusicPlay = canShowMusicPlay(); | ||
| 165 | + notificationUtils = new NotificationUtils(this, this); | ||
| 166 | + | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + private void initDataBus() { | ||
| 170 | + | ||
| 171 | + // 接口是否流量超标 | ||
| 172 | + LiveDataBus.getInstance().with(EventConstants.FLOW_TOO_LARGE, Boolean.class).observe(this, isok -> { | ||
| 173 | + Log.e("!!!!", "isok " + isok); | ||
| 174 | + if (isok && NetConstant.isFlowTooLarge) { | ||
| 175 | + NetConstant.isFlowTooLarge = false; | ||
| 176 | + if (flowTooBigDialog == null) { | ||
| 177 | + flowTooBigDialog = new FlowTooBigDialog(this, new FlowTooBigDialog.OnCloseClickListener() { | ||
| 178 | + @Override | ||
| 179 | + public void back() { | ||
| 180 | + /*if (isTaskRoot()) { | ||
| 181 | + flowTooBigDialog.dismiss(); | ||
| 182 | + } else { | ||
| 183 | + finish(); | ||
| 184 | + }*/ | ||
| 185 | + flowTooBigDialog.dismiss(); | ||
| 186 | + } | ||
| 187 | + }); | ||
| 188 | + } | ||
| 189 | + flowTooBigDialog.setIsflowtoobig(true); | ||
| 190 | + if (!flowTooBigDialog.isShowing()) { | ||
| 191 | + flowTooBigDialog.show(); | ||
| 192 | + } | ||
| 193 | + } else { | ||
| 194 | + if (flowTooBigDialog == null) { | ||
| 195 | + return; | ||
| 196 | + } | ||
| 197 | + flowTooBigDialog.setIsflowtoobig(false); | ||
| 198 | + } | ||
| 199 | + }); | ||
| 200 | + | ||
| 201 | +// /** | ||
| 202 | +// * 全局监听 | ||
| 203 | +// * 1.夜间模式切换 | ||
| 204 | +// */ | ||
| 205 | +// LiveDataBus.getInstance().with(EventConstants.EVENT_GLOBALLISTENING, Integer.class).observe(this, eventType -> { | ||
| 206 | +// forLiveDataBus = 1; | ||
| 207 | +// switch (eventType) { | ||
| 208 | +// case 1: | ||
| 209 | +// //夜间模式切换,需要重新创建页面 | ||
| 210 | +// recreate(); | ||
| 211 | +// break; | ||
| 212 | +// default: | ||
| 213 | +// break; | ||
| 214 | +// } | ||
| 215 | +// }); | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + | ||
| 219 | + @Override | ||
| 220 | + protected void onStop() { | ||
| 221 | + super.onStop(); | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + | ||
| 225 | + /** | ||
| 226 | + * 解析额外key 数据 | ||
| 227 | + */ | ||
| 228 | + private void parseExtrasKeyData() { | ||
| 229 | + if (getIntent() == null || getIntent().getExtras() == null || getTag() == null) { | ||
| 230 | + return; | ||
| 231 | + } | ||
| 232 | + actionBeanObject = getIntent().getExtras().getSerializable(RouterParameter.ACTION_KEY); | ||
| 233 | + if (actionBeanObject == null) { | ||
| 234 | + Logger.t(getTag()).w("extras no data"); | ||
| 235 | + return; | ||
| 236 | + } | ||
| 237 | + if (!(actionBeanObject instanceof ActionBean)) { | ||
| 238 | + Logger.t(getTag()).w("action paramType error"); | ||
| 239 | + return; | ||
| 240 | + } | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + /** | ||
| 244 | + * 得到额外对象 | ||
| 245 | + * | ||
| 246 | + * @return Object | ||
| 247 | + */ | ||
| 248 | + public Object getExtrasSerializableObject() { | ||
| 249 | + return actionBeanObject; | ||
| 250 | + } | ||
| 251 | + | ||
| 252 | + @Override | ||
| 253 | + protected void onDestroy() { | ||
| 254 | + //浏览时长 | ||
| 255 | + isFirstLoad = true; | ||
| 256 | + long endTime = System.currentTimeMillis(); | ||
| 257 | + duration = (int) (endTime - startTime)/1000 ; | ||
| 258 | + | ||
| 259 | + releaseDialog(); | ||
| 260 | + if (mLoadingDialog != null) { | ||
| 261 | + mLoadingDialog.cancel(); | ||
| 262 | + mLoadingDialog = null; | ||
| 263 | + } | ||
| 264 | + super.onDestroy(); | ||
| 265 | + // remove activity | ||
| 266 | +// try { | ||
| 267 | +// UMShareAPI.get(this).release(); | ||
| 268 | +// } catch (Exception e) { | ||
| 269 | +// e.printStackTrace(); | ||
| 270 | +// } | ||
| 271 | + notificationUtils.unregisterReceiver(); | ||
| 272 | + | ||
| 273 | + } | ||
| 274 | + | ||
| 275 | + /** | ||
| 276 | + * 释放拥堵弹框 | ||
| 277 | + */ | ||
| 278 | + private void releaseDialog() { | ||
| 279 | + if (flowTooBigDialog != null) { | ||
| 280 | + flowTooBigDialog.cancel(); | ||
| 281 | + flowTooBigDialog = null; | ||
| 282 | + } | ||
| 283 | + } | ||
| 284 | + | ||
| 285 | + | ||
| 286 | + private void initStatusBar() { | ||
| 287 | + StatusBarStyleEnum statusBarStyle = getStatusBarStyle(); | ||
| 288 | + if (statusBarStyle == null || statusBarStyle == StatusBarStyleEnum.NONE) { | ||
| 289 | + return; | ||
| 290 | + } | ||
| 291 | + setStatusBarStyle(statusBarStyle); | ||
| 292 | + } | ||
| 293 | + | ||
| 294 | + /** | ||
| 295 | + * 获取状态栏类型 | ||
| 296 | + * | ||
| 297 | + * @return 状态栏类型 | ||
| 298 | + */ | ||
| 299 | + protected StatusBarStyleEnum getStatusBarStyle() { | ||
| 300 | + return SpUtils.isNightMode()&& !isNightKeep ? StatusBarStyleEnum.NORMAL_161827_LIGHT_ENUM : StatusBarStyleEnum.NORMAL_WHITE_DARK_ENUM; | ||
| 301 | + } | ||
| 302 | + | ||
| 303 | + public void setStatusBarStyle(@NonNull StatusBarStyleEnum statusBarStyle) { | ||
| 304 | + ToolsUtil.setStatusBarStyle(statusBarStyle, this); | ||
| 305 | + } | ||
| 306 | + | ||
| 307 | + /** | ||
| 308 | + * 底部导航栏背景 | ||
| 309 | + * @return 颜色值 | ||
| 310 | + */ | ||
| 311 | + public int getNavigationBarBgColor(){ | ||
| 312 | + return ContextCompat.getColor(getBaseContext(),isNightKeep ? | ||
| 313 | + R.color.res_color_common_C8_keep : R.color.res_color_common_C8); | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | + | ||
| 317 | + /** | ||
| 318 | + * 切换状态栏背景 | ||
| 319 | + * | ||
| 320 | + * @param labelIsBlack 状态文字是否黑色,即light还是dark | ||
| 321 | + * @param color 状态栏背景颜色 | ||
| 322 | + */ | ||
| 323 | + protected final void changeStatusBarStyle(boolean labelIsBlack, String color) { | ||
| 324 | + // 修改状态栏背景色,非全屏 | ||
| 325 | + int state = labelIsBlack ? View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR : View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; | ||
| 326 | + StatusBarCompat.setStatusBar(this, state, color); | ||
| 327 | + } | ||
| 328 | + | ||
| 329 | + | ||
| 330 | + /** | ||
| 331 | + * 拍照得到的 图片 | ||
| 332 | + * | ||
| 333 | + * @return mPhotoPath | ||
| 334 | + */ | ||
| 335 | + public String getPhotoPath() { | ||
| 336 | + return mPhotoPath; | ||
| 337 | + } | ||
| 338 | + | ||
| 339 | + @Override | ||
| 340 | + protected void onResume() { | ||
| 341 | + super.onResume(); | ||
| 342 | + if (mIsShowTitleBar) { | ||
| 343 | + initTitleBar(); | ||
| 344 | + } | ||
| 345 | + obserNetState(); | ||
| 346 | + | ||
| 347 | + if (isFirstLoad) { | ||
| 348 | + startTime = System.currentTimeMillis(); | ||
| 349 | + isFirstLoad = false; | ||
| 350 | + } | ||
| 351 | +// //短视频 竖屏直播直播 音频 | ||
| 352 | +// if (getClass().getSimpleName().contains("LiveDetailActivityVertical") || | ||
| 353 | +// getClass().getSimpleName().contains("ShortVideoActivity")) { | ||
| 354 | +// sendHiddenAudio(); | ||
| 355 | +// return; | ||
| 356 | +// } | ||
| 357 | +// if (canShowMusicPlay && FloatWindow.get() != null && !FloatWindow.get().getColseed()) { | ||
| 358 | +// FloatWindow.get().show(); | ||
| 359 | +// } else if (FloatWindow.get() != null) { | ||
| 360 | +//// PlayerManagerUtils.pauseAudio(); | ||
| 361 | +// FloatWindow.get().hide(); | ||
| 362 | +// FloatWindow.get().setAudioFloatingIsShow(false); | ||
| 363 | +// } | ||
| 364 | + | ||
| 365 | + } | ||
| 366 | + | ||
| 367 | + /** | ||
| 368 | + * 隐藏音频悬浮窗方法 | ||
| 369 | + */ | ||
| 370 | + public void sendHiddenAudio() { | ||
| 371 | + LiveDataBus.getInstance().with(EventConstants.FLOW_AUDIO_FREQUENCY, Integer.class).postValue(1); | ||
| 372 | + } | ||
| 373 | + | ||
| 374 | + /** | ||
| 375 | + * 子类控制是否设置titlebar | ||
| 376 | + * | ||
| 377 | + * @param isShowTitleBar | ||
| 378 | + */ | ||
| 379 | + protected void setShowTitleBar(boolean isShowTitleBar) { | ||
| 380 | + mIsShowTitleBar = isShowTitleBar; | ||
| 381 | + } | ||
| 382 | + | ||
| 383 | + /** | ||
| 384 | + * 初始化titlebar | ||
| 385 | + */ | ||
| 386 | + public void initTitleBar() { | ||
| 387 | + if (titleBar == null) { | ||
| 388 | + View view = findViewById(R.id.title_bar); | ||
| 389 | + if (view != null) { | ||
| 390 | + titleBar = (CustomTitleBar) view; | ||
| 391 | + titleBar.setTitleBarClickListener(this); | ||
| 392 | + if (!TextUtils.isEmpty(titleContent)) { | ||
| 393 | + titleBar.setTitle(titleContent); | ||
| 394 | + } | ||
| 395 | + } | ||
| 396 | + } | ||
| 397 | + } | ||
| 398 | + | ||
| 399 | + /** | ||
| 400 | + * 创建dialog 对象 | ||
| 401 | + * | ||
| 402 | + * @param allowCancel | ||
| 403 | + */ | ||
| 404 | + private void createLoadingDialog(boolean allowCancel, String interactCode) { | ||
| 405 | + mLoadingDialog = DialogUtils.createRequestDialog(this, allowCancel, interactCode); | ||
| 406 | + } | ||
| 407 | + | ||
| 408 | + /** | ||
| 409 | + * loading | ||
| 410 | + */ | ||
| 411 | + public void startLoading() { | ||
| 412 | + startLoading(true); | ||
| 413 | + } | ||
| 414 | + | ||
| 415 | + public void startLoading(boolean allowCancel) { | ||
| 416 | + startLoading(allowCancel, "refreshing_common_loading.json"); | ||
| 417 | + } | ||
| 418 | + | ||
| 419 | + protected void startLoading(boolean allowCancel, String interactCode) { | ||
| 420 | + | ||
| 421 | + if (isDestroyed() || isFinishing()) { | ||
| 422 | + return; | ||
| 423 | + } | ||
| 424 | + | ||
| 425 | + if (mLoadingDialog == null) { | ||
| 426 | + createLoadingDialog(allowCancel, interactCode); | ||
| 427 | + } | ||
| 428 | + | ||
| 429 | + if (mLoadingDialog != null && !mLoadingDialog.isShowing()) { | ||
| 430 | + mLoadingDialog.show(); | ||
| 431 | + } | ||
| 432 | + } | ||
| 433 | + | ||
| 434 | + /** | ||
| 435 | + * loading | ||
| 436 | + */ | ||
| 437 | + public void stopLoading() { | ||
| 438 | + if (isDestroyed() || isFinishing()) { | ||
| 439 | + return; | ||
| 440 | + } | ||
| 441 | + if (mLoadingDialog != null && mLoadingDialog.isShowing()) { | ||
| 442 | + mLoadingDialog.dismiss(); | ||
| 443 | + } | ||
| 444 | + | ||
| 445 | + } | ||
| 446 | + | ||
| 447 | + /** | ||
| 448 | + * 导航栏栏点击左侧按钮 | ||
| 449 | + */ | ||
| 450 | + @Override | ||
| 451 | + public void onLeftClick() { | ||
| 452 | + finish(); | ||
| 453 | + } | ||
| 454 | + | ||
| 455 | + /** | ||
| 456 | + * 导航栏栏点击右侧按钮 | ||
| 457 | + */ | ||
| 458 | + @Override | ||
| 459 | + public void onRightClick() { | ||
| 460 | + | ||
| 461 | + } | ||
| 462 | + | ||
| 463 | + /** | ||
| 464 | + * 展示缺省页 | ||
| 465 | + * | ||
| 466 | + * @param defaultView | ||
| 467 | + * @param type | ||
| 468 | + * @return | ||
| 469 | + */ | ||
| 470 | + protected View showDefaultView(DefaultView defaultView, int type) { | ||
| 471 | + if (defaultView != null) { | ||
| 472 | + baseDefaultView = defaultView; | ||
| 473 | + } else { | ||
| 474 | + baseDefaultView = new DefaultView(this, null, 0); | ||
| 475 | + } | ||
| 476 | + retryClickListener = new DefaultView.RetryClickListener() { | ||
| 477 | + @Override | ||
| 478 | + public void onRetryClick() { | ||
| 479 | + retryBtnClickListener(); | ||
| 480 | + } | ||
| 481 | + }; | ||
| 482 | + baseDefaultView.setRetryBtnClickListener(retryClickListener); | ||
| 483 | + baseDefaultView.show(type); | ||
| 484 | + | ||
| 485 | + return baseDefaultView; | ||
| 486 | + } | ||
| 487 | + | ||
| 488 | + /** | ||
| 489 | + * 关闭缺省页面 | ||
| 490 | + */ | ||
| 491 | + protected void hideDefaultView() { | ||
| 492 | + if (baseDefaultView != null) { | ||
| 493 | + baseDefaultView.hide(); | ||
| 494 | + } | ||
| 495 | + } | ||
| 496 | + | ||
| 497 | + /** | ||
| 498 | + * 回调提供 | ||
| 499 | + */ | ||
| 500 | + public void retryBtnClickListener() { | ||
| 501 | + | ||
| 502 | + } | ||
| 503 | + | ||
| 504 | + /** | ||
| 505 | + * 子类设置网络是否监听方法 | ||
| 506 | + * | ||
| 507 | + * @param isNetObserver | ||
| 508 | + */ | ||
| 509 | + protected void setNetStateObserver(boolean isNetObserver) { | ||
| 510 | + mNetStateObserver = isNetObserver; | ||
| 511 | + obserNetState(); | ||
| 512 | + } | ||
| 513 | + | ||
| 514 | + /** | ||
| 515 | + * 网络监听方法 | ||
| 516 | + */ | ||
| 517 | + private void obserNetState() { | ||
| 518 | + if (mNetStateObserver) { | ||
| 519 | + LiveDataBus.getInstance() | ||
| 520 | + .with(EventConstants.NETWORK_STATE_CHANGE, NetStateMessage.class) | ||
| 521 | + .observe(this, new Observer<NetStateMessage>() { | ||
| 522 | + @Override | ||
| 523 | + public void onChanged(@Nullable NetStateMessage mEventMessage) { | ||
| 524 | + Logger.t(TAG).d("Network status" + mEventMessage.type); | ||
| 525 | + netStateData(mEventMessage); | ||
| 526 | + } | ||
| 527 | + }); | ||
| 528 | + } | ||
| 529 | + | ||
| 530 | + } | ||
| 531 | + | ||
| 532 | + /** | ||
| 533 | + * 子类可以实现这个方法获取网络状态 | ||
| 534 | + * | ||
| 535 | + * @param msg | ||
| 536 | + */ | ||
| 537 | + protected void netStateData(NetStateMessage msg) { | ||
| 538 | + if (msg == null) { | ||
| 539 | + return; | ||
| 540 | + } | ||
| 541 | + | ||
| 542 | + if (msg.type.equals(NetConstant.NET_WIFI_TYPE)) { | ||
| 543 | + Logger.d("net is wifi type"); | ||
| 544 | + } else if (msg.type.equals(NetConstant.NET_CELL_TYPE)) { | ||
| 545 | + Logger.d("net is cell type"); | ||
| 546 | + } else if (msg.type.equals(NetConstant.NET_ERROR_TYPE)) { | ||
| 547 | + Logger.d("net is error type"); | ||
| 548 | + } | ||
| 549 | + } | ||
| 550 | + | ||
| 551 | + /** | ||
| 552 | + * 夜间模式保持原样 | ||
| 553 | + */ | ||
| 554 | + public boolean setNightKeep(){ | ||
| 555 | + return false; | ||
| 556 | + } | ||
| 557 | + | ||
| 558 | + /** | ||
| 559 | + * 设置沉浸式头部的间距 | ||
| 560 | + * | ||
| 561 | + * @param statusHeight | ||
| 562 | + */ | ||
| 563 | + | ||
| 564 | + public void setTopMargin(int statusHeight) { | ||
| 565 | + | ||
| 566 | + } | ||
| 567 | + | ||
| 568 | + /** | ||
| 569 | + * 进入到改页面是否显示音频播放浮窗 | ||
| 570 | + * | ||
| 571 | + * @return | ||
| 572 | + */ | ||
| 573 | + public boolean canShowMusicPlay() { | ||
| 574 | + return true; | ||
| 575 | + } | ||
| 576 | + | ||
| 577 | + | ||
| 578 | + public void setTitleContent(String titleContent) { | ||
| 579 | + this.titleContent = titleContent; | ||
| 580 | + } | ||
| 581 | + | ||
| 582 | + /** | ||
| 583 | + * 拍照 | ||
| 584 | + * | ||
| 585 | + * @param requestCode 请求码 | ||
| 586 | + */ | ||
| 587 | + protected void openCamera(final int requestCode) { | ||
| 588 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
| 589 | + PermissionsUtils.getCameraAndSdPermission(this, new IPmsCallBack() { | ||
| 590 | + @Override | ||
| 591 | + public void granted() { | ||
| 592 | + goCamera(requestCode); | ||
| 593 | + } | ||
| 594 | + | ||
| 595 | + @Override | ||
| 596 | + public void notGranted() { | ||
| 597 | + // ToastUtils.showShort(getResources().getString(R.string.permission_refuse)); | ||
| 598 | + } | ||
| 599 | + }); | ||
| 600 | + } else { | ||
| 601 | + goCamera(requestCode); | ||
| 602 | + } | ||
| 603 | + } | ||
| 604 | + | ||
| 605 | + /** | ||
| 606 | + * 拍照,在onResult 取 mPhotoPath | ||
| 607 | + * | ||
| 608 | + * @param requestCode 请求码 | ||
| 609 | + */ | ||
| 610 | + protected void goCamera(int requestCode) { | ||
| 611 | + mPhotoPath = ToolsUtil.openCamera(this, requestCode); | ||
| 612 | + } | ||
| 613 | + | ||
| 614 | + /** | ||
| 615 | + * 选择相册 | ||
| 616 | + * | ||
| 617 | + * @param maxNum 选择张数 | ||
| 618 | + * @param requestCode 请求码 | ||
| 619 | + * @param mItemList 存储相册数据 | ||
| 620 | + * @param type 0 图片,1 视频,2 图片和视频 | ||
| 621 | + */ | ||
| 622 | +// protected void openAlbum(final int maxNum, final int type, final List<Item> mItemList, final int requestCode) { | ||
| 623 | +// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
| 624 | +// PermissionsUtils.getSDPermission(this, new IPmsCallBack() { | ||
| 625 | +// @Override | ||
| 626 | +// public void granted() { | ||
| 627 | +// selectPics(maxNum, type, mItemList, requestCode); | ||
| 628 | +// } | ||
| 629 | +// | ||
| 630 | +// @Override | ||
| 631 | +// public void notGranted() { | ||
| 632 | +// // ToastUtils.showShort(getResources().getString(R.string.permission_refuse)); | ||
| 633 | +// } | ||
| 634 | +// }); | ||
| 635 | +// } else { | ||
| 636 | +// selectPics(maxNum, type, mItemList, requestCode); | ||
| 637 | +// } | ||
| 638 | +// } | ||
| 639 | + | ||
| 640 | + /** | ||
| 641 | + * 选择相册,在onResult | ||
| 642 | + * | ||
| 643 | + * @param maxNum 选取最大个数 | ||
| 644 | + * @param type 文件类型 | ||
| 645 | + * @param mItemList 存储相册数据 | ||
| 646 | + * @param requestCode 请求码 | ||
| 647 | + */ | ||
| 648 | +// protected void selectPics(int maxNum, int type, List<Item> mItemList, int requestCode) { | ||
| 649 | +// | ||
| 650 | +// ToolsUtil.setMaxNum(maxNum); | ||
| 651 | +// if (type == SEL_TYPE_PIC) { | ||
| 652 | +// ToolsUtil.selectPhotos(this, mItemList, requestCode,-1); | ||
| 653 | +// return; | ||
| 654 | +// } | ||
| 655 | +// if (type == SEL_TYPE_VIDEO) { | ||
| 656 | +// ToolsUtil.selectVideos(this, mItemList, requestCode,-1,-1); | ||
| 657 | +// return; | ||
| 658 | +// } | ||
| 659 | +// if (type == SEL_TYPE_ALL) { | ||
| 660 | +// ToolsUtil.selectPicsAndVideo(this, mItemList, requestCode,-1,-1,-1); | ||
| 661 | +// } | ||
| 662 | +// } | ||
| 663 | + | ||
| 664 | + /** | ||
| 665 | + * 友盟分享使用,不可以删除 | ||
| 666 | + */ | ||
| 667 | + @Override | ||
| 668 | + protected void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) { | ||
| 669 | + super.onActivityResult(requestCode, resultCode, data); | ||
| 670 | +// try { | ||
| 671 | +// UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data); | ||
| 672 | +// } catch (Exception e) { | ||
| 673 | +// e.printStackTrace(); | ||
| 674 | +// } | ||
| 675 | + } | ||
| 676 | + | ||
| 677 | +// @Override | ||
| 678 | +// protected void attachBaseContext(Context newBase) { | ||
| 679 | +// super.attachBaseContext(FoldingScreenUtils.attachBaseContext(newBase)); | ||
| 680 | +// } | ||
| 681 | + | ||
| 682 | +// @Override | ||
| 683 | +// public void onConfigurationChanged(@NonNull Configuration newConfig) { | ||
| 684 | +// FoldingScreenUtils.onConfigurationChanged(this, newConfig); | ||
| 685 | +// super.onConfigurationChanged(newConfig); | ||
| 686 | +// } | ||
| 687 | + | ||
| 688 | + public void sendNotification(String message) { | ||
| 689 | + notificationUtils.sendNotification(message); | ||
| 690 | + | ||
| 691 | + } | ||
| 692 | + | ||
| 693 | + @Override | ||
| 694 | + public void onNotificationReceived(String message) { | ||
| 695 | + // 处理接收到的通知消息 | ||
| 696 | + Log.d("Notification", "Received message: " + message); | ||
| 697 | + } | ||
| 698 | + | ||
| 699 | + /** | ||
| 700 | + * 判断当前activity是否销毁 | ||
| 701 | + * @return | ||
| 702 | + */ | ||
| 703 | + public boolean activityIsDestroy() { | ||
| 704 | + if(mBaseActivity == null || mBaseActivity.isFinishing() || mBaseActivity.isDestroyed()) | ||
| 705 | + { | ||
| 706 | + return true; | ||
| 707 | + } | ||
| 708 | + return false; | ||
| 709 | + } | ||
| 710 | + | ||
| 711 | + /** | ||
| 712 | + * hook反射方向检查 | ||
| 713 | + **/ | ||
| 714 | + public void fixOrientation(Activity activity) { | ||
| 715 | + try { | ||
| 716 | + Class activityClass = Activity.class; | ||
| 717 | + Field mActivityInfoField = activityClass.getDeclaredField("mActivityInfo"); | ||
| 718 | + mActivityInfoField.setAccessible(true); | ||
| 719 | + ActivityInfo activityInfo = (ActivityInfo) mActivityInfoField.get(activity); | ||
| 720 | + // 设置屏幕不固定 | ||
| 721 | + activityInfo.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; | ||
| 722 | + } catch (Exception e) { | ||
| 723 | + e.printStackTrace(); | ||
| 724 | + } | ||
| 725 | + } | ||
| 726 | + | ||
| 727 | + /** | ||
| 728 | + * hook反射检查是否透明色或者悬浮 | ||
| 729 | + **/ | ||
| 730 | + public boolean isTranslucentOrFloating() { | ||
| 731 | + | ||
| 732 | + boolean isTranslucentOrFloating = false; | ||
| 733 | + try { | ||
| 734 | + int[] styleableRes = (int[]) Class.forName("com.android.internal.R$styleable").getField("Window").get(null); | ||
| 735 | + final TypedArray typedArray = obtainStyledAttributes(styleableRes); | ||
| 736 | + Method method = ActivityInfo.class.getMethod("isTranslucentOrFloating", TypedArray.class); | ||
| 737 | + method.setAccessible(true); | ||
| 738 | + isTranslucentOrFloating = (boolean) method.invoke(null, typedArray); | ||
| 739 | + method.setAccessible(false); | ||
| 740 | + } catch (Exception e) { | ||
| 741 | + e.printStackTrace(); | ||
| 742 | + } | ||
| 743 | + return isTranslucentOrFloating; | ||
| 744 | + } | ||
| 745 | +} |
| 1 | + | ||
| 2 | +package com.wd.common.base; | ||
| 3 | + | ||
| 4 | +import android.app.Activity; | ||
| 5 | +import android.app.Application; | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +import com.wd.common.listener.UserActivityLifecycleCallbacks; | ||
| 9 | + | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | +public class BaseApplication extends Application { | ||
| 13 | + private final UserActivityLifecycleCallbacks mLifecycleCallbacks = new UserActivityLifecycleCallbacks(); | ||
| 14 | + | ||
| 15 | + public static BaseApplication instance; | ||
| 16 | + | ||
| 17 | + @Override | ||
| 18 | + public void onCreate() { | ||
| 19 | + super.onCreate(); | ||
| 20 | + instance = this; | ||
| 21 | + // 注册Activity生命周期监听 | ||
| 22 | + registerActivityLifecycleCallbacks(mLifecycleCallbacks); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 获取一个Application对象 | ||
| 27 | + */ | ||
| 28 | + public static synchronized BaseApplication getInstance() { | ||
| 29 | + return instance; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public UserActivityLifecycleCallbacks getLifecycleCallbacks() { | ||
| 33 | + return mLifecycleCallbacks; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * finish所有Activity | ||
| 38 | + */ | ||
| 39 | + public void finishAllActivity() { | ||
| 40 | + UserActivityLifecycleCallbacks lifecycleCallbacks = getLifecycleCallbacks(); | ||
| 41 | + if (lifecycleCallbacks == null) { | ||
| 42 | + return; | ||
| 43 | + } | ||
| 44 | + List<Activity> activities = lifecycleCallbacks.getActivityList(); | ||
| 45 | + if (activities == null || activities.isEmpty()) { | ||
| 46 | + return; | ||
| 47 | + } | ||
| 48 | + for (Activity activity : activities) { | ||
| 49 | + activity.finish(); | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | +} |
| 1 | +/* | ||
| 2 | + * Copyright (c) Wondertek Technologies Co., Ltd. 2019-2022. All rights reserved. | ||
| 3 | + */ | ||
| 4 | + | ||
| 5 | +package com.wd.common.base | ||
| 6 | + | ||
| 7 | +import android.app.Activity | ||
| 8 | +import android.app.AlertDialog | ||
| 9 | +import android.app.Dialog | ||
| 10 | +import android.content.Context | ||
| 11 | +import android.view.Gravity | ||
| 12 | +import android.view.View | ||
| 13 | +import android.view.ViewGroup | ||
| 14 | +import android.view.WindowManager | ||
| 15 | +import android.widget.LinearLayout | ||
| 16 | +import com.wd.foundation.wdkit.animator.AnimatorUtil | ||
| 17 | +import com.wd.fastcoding.base.R | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * BaseDialog | ||
| 22 | + * | ||
| 23 | + * @author liyubing | ||
| 24 | + * @version [V1.0.0, 2022/6/13] | ||
| 25 | + * @since V1.0.0 | ||
| 26 | + */ | ||
| 27 | +class BaseDialog { | ||
| 28 | + private var dialog: AlertDialog? = null | ||
| 29 | + private var mLayoutView: View? = null | ||
| 30 | + private var mContext: Context? = null | ||
| 31 | + private var width = 0.0 | ||
| 32 | + private var height = 0.4 | ||
| 33 | + private var isCancelable = true | ||
| 34 | + private var dialogHeight = ViewGroup.LayoutParams.WRAP_CONTENT | ||
| 35 | + private var onSureClickListener: OnSureClickListener? = null | ||
| 36 | + private val onCancelClickListener: OnCancelClickListener? = null | ||
| 37 | + | ||
| 38 | + private var onDismissListener: OnDismissListener? = null | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 任意控件点击事件接口 | ||
| 42 | + */ | ||
| 43 | + interface OnClickListener { | ||
| 44 | + fun onClick(view: View?, dialog: Dialog?) | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + fun setDismissListener(onDismissListener: OnDismissListener): BaseDialog { | ||
| 48 | + this.onDismissListener = onDismissListener | ||
| 49 | + return this | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + fun setDialogHeight(dialogHeight: Int): BaseDialog { | ||
| 53 | + this.dialogHeight = dialogHeight | ||
| 54 | + return this | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + fun isCancelable(isCancelable: Boolean): BaseDialog { | ||
| 58 | + this.isCancelable = isCancelable | ||
| 59 | + return this | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + interface OnAdapterChangeListener { | ||
| 63 | + fun onClick(position: Int, o: Any?, dialog: Dialog?) | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * 任意控件点击事件 | ||
| 68 | + */ | ||
| 69 | + fun setOnClickListener( | ||
| 70 | + view: View, | ||
| 71 | + onClickListener: OnClickListener? | ||
| 72 | + ): BaseDialog? { | ||
| 73 | + view.setOnClickListener { | ||
| 74 | + onClickListener?.onClick(view, dialog) | ||
| 75 | + } | ||
| 76 | + return mDialog | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * 弹窗消失接口 | ||
| 81 | + */ | ||
| 82 | + interface OnDismissListener { | ||
| 83 | + fun onDismiss() | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * 确定控件点击事件接口 | ||
| 88 | + */ | ||
| 89 | + interface OnSureClickListener { | ||
| 90 | + fun onClick(dialog: Dialog?) | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * 取消控件点击事件接口 | ||
| 95 | + */ | ||
| 96 | + interface OnCancelClickListener { | ||
| 97 | + fun onClick(dialog: Dialog?) | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * 取消控件点击事件 | ||
| 102 | + */ | ||
| 103 | + fun setOnCancelClickListener(view: View): BaseDialog? { | ||
| 104 | + view.setOnClickListener { dialog!!.dismiss() } | ||
| 105 | + return mDialog | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + /** | ||
| 109 | + * 取消控件点击事件 | ||
| 110 | + */ | ||
| 111 | + fun setOnCancelClickListener( | ||
| 112 | + view: View, | ||
| 113 | + onCancelClickListener: OnCancelClickListener? | ||
| 114 | + ): BaseDialog? { | ||
| 115 | + view.setOnClickListener { onCancelClickListener?.onClick(dialog) } | ||
| 116 | + return mDialog | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * 确定控件点击事件 | ||
| 121 | + */ | ||
| 122 | + fun setOnSureClickListener( | ||
| 123 | + view: View, onSureClickListener: OnSureClickListener? | ||
| 124 | + ): BaseDialog? { | ||
| 125 | + view.setOnClickListener { | ||
| 126 | + onSureClickListener?.onClick(dialog) | ||
| 127 | + } | ||
| 128 | + return mDialog | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + fun setWindow(width: Double, height: Double): BaseDialog { | ||
| 132 | + this.width = width | ||
| 133 | + this.height = height | ||
| 134 | + return this | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + fun setLayoutView( | ||
| 138 | + layoutView: View? | ||
| 139 | + ): BaseDialog? { | ||
| 140 | + mLayoutView = layoutView | ||
| 141 | + this.mContext = layoutView?.context | ||
| 142 | + return mDialog | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + /** | ||
| 146 | + * 弹窗位于中间 | ||
| 147 | + * | ||
| 148 | + * @return | ||
| 149 | + */ | ||
| 150 | + fun showCenter(): BaseDialog? { | ||
| 151 | + mContext?.apply { | ||
| 152 | + if (mLayoutView?.parent != null) { | ||
| 153 | + (mLayoutView?.parent as ViewGroup).removeAllViews() | ||
| 154 | + } | ||
| 155 | + dialog = AlertDialog.Builder(this, R.style.custom_dialog2).create() | ||
| 156 | + dialog?.setCancelable(isCancelable) | ||
| 157 | + dialog?.show() | ||
| 158 | + dialog?.setContentView(mLayoutView!!, ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dialogHeight)) | ||
| 159 | + val dialogWindow = dialog?.window | ||
| 160 | + dialogWindow?.setGravity(Gravity.CENTER) | ||
| 161 | + val lp = dialogWindow?.attributes | ||
| 162 | + val d = mContext?.resources?.displayMetrics // 获取屏幕宽、高用 | ||
| 163 | + | ||
| 164 | + if (width == 0.0) { | ||
| 165 | + lp?.width = LinearLayout.LayoutParams.WRAP_CONTENT | ||
| 166 | + } else { | ||
| 167 | + lp?.width = (d?.widthPixels?.times(width))?.toInt() | ||
| 168 | + } | ||
| 169 | + if (height == 0.0) { | ||
| 170 | + lp?.height = LinearLayout.LayoutParams.WRAP_CONTENT | ||
| 171 | + } else { | ||
| 172 | + lp?.height = (d?.heightPixels?.times(height))?.toInt() | ||
| 173 | + } | ||
| 174 | + dialog?.setOnDismissListener { | ||
| 175 | + onDismissListener?.onDismiss() | ||
| 176 | + dialog?.dismiss() } | ||
| 177 | + dialog?.setOnCancelListener { dialog?.dismiss() } | ||
| 178 | + dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) | ||
| 179 | + dialogWindow?.attributes = lp | ||
| 180 | + | ||
| 181 | + } | ||
| 182 | + return mDialog | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + /** | ||
| 186 | + * 弹窗位于底部 | ||
| 187 | + * | ||
| 188 | + * @return | ||
| 189 | + */ | ||
| 190 | + fun showBottom(): BaseDialog? { | ||
| 191 | + dialog = AlertDialog.Builder(mContext!!, R.style.custom_dialog2).create() | ||
| 192 | + dialog?.setCancelable(isCancelable) | ||
| 193 | + dialog?.show() | ||
| 194 | + dialog?.setContentView( | ||
| 195 | + mLayoutView!!, | ||
| 196 | + ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dialogHeight) | ||
| 197 | + ) | ||
| 198 | + val dialogWindow = dialog?.window | ||
| 199 | + dialogWindow?.setGravity(Gravity.BOTTOM) | ||
| 200 | + val lp = dialogWindow?.attributes | ||
| 201 | + lp?.width = WindowManager.LayoutParams.MATCH_PARENT | ||
| 202 | + lp?.y = 0 | ||
| 203 | + dialogWindow?.attributes = lp | ||
| 204 | + dialog?.setOnDismissListener { | ||
| 205 | + AnimatorUtil.startVerticalDown(mLayoutView, dialog) | ||
| 206 | + } | ||
| 207 | + dialog?.setOnCancelListener { AnimatorUtil.startVerticalDown(mLayoutView, dialog) } | ||
| 208 | + AnimatorUtil.startVerticalUp(mLayoutView) | ||
| 209 | + dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) | ||
| 210 | + dialog?.setOnCancelListener { onDismissListener?.onDismiss()} | ||
| 211 | + return mDialog | ||
| 212 | + } | ||
| 213 | + | ||
| 214 | + fun dismiss(): BaseDialog? { | ||
| 215 | + if (mDialog != null && dialog != null && dialog?.isShowing == true) { | ||
| 216 | + if (mContext is Activity) { | ||
| 217 | + if (!(mContext as Activity).isDestroyed && !(mContext as Activity).isFinishing) { | ||
| 218 | + dialog?.dismiss() | ||
| 219 | + } | ||
| 220 | + } | ||
| 221 | + } | ||
| 222 | + return mDialog | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + fun getDialog():AlertDialog?{ | ||
| 226 | + return dialog | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + companion object { | ||
| 230 | + private var mDialog: BaseDialog? = null | ||
| 231 | + val instance: BaseDialog? | ||
| 232 | + get() { | ||
| 233 | + mDialog = BaseDialog() | ||
| 234 | + return mDialog | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + | ||
| 238 | + } | ||
| 239 | +} |
| 1 | +/* | ||
| 2 | + * Copyright (c) Wondertek Technologies Co., Ltd. 2019-2022. All rights reserved. | ||
| 3 | + */ | ||
| 4 | + | ||
| 5 | +package com.wd.common.base; | ||
| 6 | + | ||
| 7 | +import android.annotation.TargetApi; | ||
| 8 | +import android.app.Activity; | ||
| 9 | +import android.app.Dialog; | ||
| 10 | +import android.content.Context; | ||
| 11 | +import android.os.Build; | ||
| 12 | +import android.os.Bundle; | ||
| 13 | +import android.util.Log; | ||
| 14 | +import android.view.KeyEvent; | ||
| 15 | +import android.view.LayoutInflater; | ||
| 16 | +import android.view.View; | ||
| 17 | +import android.view.ViewGroup; | ||
| 18 | +import android.widget.FrameLayout; | ||
| 19 | + | ||
| 20 | +import androidx.annotation.NonNull; | ||
| 21 | +import androidx.annotation.Nullable; | ||
| 22 | +import androidx.fragment.app.Fragment; | ||
| 23 | +import androidx.fragment.app.FragmentManager; | ||
| 24 | +import androidx.lifecycle.ViewModel; | ||
| 25 | +import androidx.lifecycle.ViewModelProviders; | ||
| 26 | + | ||
| 27 | +import com.wd.base.log.Logger; | ||
| 28 | +import com.wd.common.dialog.DialogUtils; | ||
| 29 | +import com.wd.common.utils.ToolsUtil; | ||
| 30 | +import com.wd.common.widget.DefaultView; | ||
| 31 | +import com.wd.fastcoding.base.R; | ||
| 32 | +import com.wd.foundation.wdkit.statusbar.StatusBarStyleEnum; | ||
| 33 | + | ||
| 34 | +import java.util.List; | ||
| 35 | + | ||
| 36 | +/** | ||
| 37 | + * fragment基类<BR> | ||
| 38 | + * | ||
| 39 | + * @author zhangbo | ||
| 40 | + * @version [V1.0.0, 2021/12/8] | ||
| 41 | + * @since V1.0.0 | ||
| 42 | + */ | ||
| 43 | +public abstract class BaseFragment extends Fragment { | ||
| 44 | + private boolean isUserVisible = true; | ||
| 45 | + | ||
| 46 | + private boolean isViewCreated = false; | ||
| 47 | + | ||
| 48 | + private Dialog mLoadingDialog; | ||
| 49 | + | ||
| 50 | + protected Activity activity; | ||
| 51 | + /** | ||
| 52 | + * true java布局,false xml布局 | ||
| 53 | + */ | ||
| 54 | + private boolean isjava; | ||
| 55 | + | ||
| 56 | + private Activity mActivity; | ||
| 57 | + | ||
| 58 | + FrameLayout layout; | ||
| 59 | + | ||
| 60 | + @Override | ||
| 61 | + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
| 62 | + this.perCreate(); | ||
| 63 | + View rootView; | ||
| 64 | + if (isjava) { | ||
| 65 | + rootView = getJavaLayout(); | ||
| 66 | + } else { | ||
| 67 | + rootView = inflater.inflate(getLayout(), container, false); | ||
| 68 | + } | ||
| 69 | + mActivity = getActivity(); | ||
| 70 | + initView(rootView); | ||
| 71 | + return rootView; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | ||
| 76 | + super.onViewCreated(view, savedInstanceState); | ||
| 77 | + isViewCreated = true; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * 获取指定类型的VM实例<BR> | ||
| 82 | + * 获取Activity对象的vm | ||
| 83 | + * | ||
| 84 | + * @param viewModelClazz VM的类实例 | ||
| 85 | + * @param <T> VM类型 | ||
| 86 | + * @return VM对象 | ||
| 87 | + */ | ||
| 88 | + protected <T extends ViewModel> T getViewModel(Class<T> viewModelClazz) { | ||
| 89 | + if (null != getActivity()) { | ||
| 90 | + return ViewModelProviders.of(getActivity()).get(viewModelClazz); | ||
| 91 | + } else { | ||
| 92 | + return ViewModelProviders.of(this).get(viewModelClazz); | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + /** | ||
| 97 | + * 获取指定类型的VM实例<BR> | ||
| 98 | + * 获取fragment自己的vm | ||
| 99 | + * | ||
| 100 | + * @param viewModelClazz VM的类实例 | ||
| 101 | + * @param <T> VM类型 | ||
| 102 | + * @return VM对象 | ||
| 103 | + */ | ||
| 104 | + protected <T extends ViewModel> T getViewModelThis(Class<T> viewModelClazz) { | ||
| 105 | + return ViewModelProviders.of(this).get(viewModelClazz); | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + @Override | ||
| 109 | + public void onDestroy() { | ||
| 110 | + super.onDestroy(); | ||
| 111 | + // 在fragment destroy的时候重置isUserVisible | ||
| 112 | + isUserVisible = true; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * 获取日志tag | ||
| 117 | + * | ||
| 118 | + * @return 日志tag | ||
| 119 | + */ | ||
| 120 | + protected abstract String getLogTag(); | ||
| 121 | + | ||
| 122 | + /** | ||
| 123 | + * 获取当前Fragment布局 | ||
| 124 | + * | ||
| 125 | + * @return 布局文件 | ||
| 126 | + */ | ||
| 127 | + protected abstract int getLayout(); | ||
| 128 | + | ||
| 129 | + /** | ||
| 130 | + * 初始化View<BR> | ||
| 131 | + * 不要有耗时操作,否则页面加载慢 | ||
| 132 | + * | ||
| 133 | + * @param rootView 布局根视图 | ||
| 134 | + */ | ||
| 135 | + protected abstract void initView(View rootView); | ||
| 136 | + | ||
| 137 | + /** | ||
| 138 | + * onKeyDown回调<BR> | ||
| 139 | + * 需要Activity主动触发 | ||
| 140 | + * | ||
| 141 | + * @param keyCode 按键类型 | ||
| 142 | + * @param event 按键事件 | ||
| 143 | + * @return 是否消费事件 | ||
| 144 | + */ | ||
| 145 | + public boolean onKeyDown(int keyCode, KeyEvent event) { | ||
| 146 | + return false; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + /** | ||
| 150 | + * onKeyUp 回调<BR> | ||
| 151 | + * 需要Activity主动触发 | ||
| 152 | + * | ||
| 153 | + * @param keyCode 按键类型 | ||
| 154 | + * @param event 按键事件 | ||
| 155 | + * @return 是否消费事件 | ||
| 156 | + */ | ||
| 157 | + public boolean onKeyUp(int keyCode, KeyEvent event) { | ||
| 158 | + return false; | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + // 标记onResume是否被刚刚调用 | ||
| 162 | + private boolean mResume = false; | ||
| 163 | + | ||
| 164 | + /** | ||
| 165 | + * 用于判断fragment真实展现,不要用其提供的isVisible()方法 | ||
| 166 | + * | ||
| 167 | + * @return true 可见 false不可见 | ||
| 168 | + */ | ||
| 169 | + public boolean isRealVisible() { | ||
| 170 | + return getUserVisibleHint() && mResume; | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + @Override | ||
| 174 | + public void onResume() { | ||
| 175 | + super.onResume(); | ||
| 176 | + mResume = true; | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + @Override | ||
| 180 | + public void onPause() { | ||
| 181 | + super.onPause(); | ||
| 182 | + mResume = false; | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + @Override | ||
| 186 | + public void onStop() { | ||
| 187 | + super.onStop(); | ||
| 188 | + mResume = false; | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + /** | ||
| 192 | + * 判断是否对用户可见 | ||
| 193 | + */ | ||
| 194 | + public boolean isUserVisible() { | ||
| 195 | + return /* isVisible() */ isAdded() && getUserVisibleHint() && isUserVisible && parentUserVisible(this); | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + @Override | ||
| 199 | + public void setUserVisibleHint(boolean isVisibleToUser) { | ||
| 200 | + super.setUserVisibleHint(isVisibleToUser); | ||
| 201 | + if (!isViewCreated) { | ||
| 202 | + isUserVisible = isVisibleToUser; | ||
| 203 | + return; | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + if (isVisibleToUser) { | ||
| 207 | + userVisible(false); | ||
| 208 | + } else { | ||
| 209 | + userInvisible(false); | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + Log.d("BaseFragment", this.getClass().getName()); | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + /** | ||
| 216 | + * 判断父Fragment是否可见 | ||
| 217 | + */ | ||
| 218 | + private static boolean parentUserVisible(Fragment fragment) { | ||
| 219 | + Fragment f = fragment.getParentFragment(); | ||
| 220 | + if (f instanceof BaseFragment) { | ||
| 221 | + return ((BaseFragment) f).isUserVisible(); | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + while (f != null) { | ||
| 225 | + if (!f.isVisible() || !f.getUserVisibleHint()) { | ||
| 226 | + return false; | ||
| 227 | + } | ||
| 228 | + f = f.getParentFragment(); | ||
| 229 | + } | ||
| 230 | + | ||
| 231 | + return true; | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + void userVisible(boolean fromActivity) { | ||
| 235 | + // 父Fragment不可见则不做处理 | ||
| 236 | + if (isUserVisible || (fromActivity && (!getUserVisibleHint() || !parentUserVisible(this)))) { | ||
| 237 | + return; | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + isUserVisible = true; | ||
| 241 | + | ||
| 242 | + FragmentManager fragmentManager; | ||
| 243 | + try { | ||
| 244 | + fragmentManager = getChildFragmentManager(); | ||
| 245 | + } catch (Exception e) { | ||
| 246 | + onUserVisible(fromActivity); | ||
| 247 | + return; | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + List<Fragment> fragments = fragmentManager.getFragments(); | ||
| 251 | + if (fragments == null || fragments.isEmpty()) { | ||
| 252 | + onUserVisible(fromActivity); | ||
| 253 | + return; | ||
| 254 | + } | ||
| 255 | + | ||
| 256 | + for (Fragment f : fragments) { | ||
| 257 | + /* | ||
| 258 | + * if (!f.isVisible()) { | ||
| 259 | + * continue; | ||
| 260 | + * } | ||
| 261 | + */ | ||
| 262 | + | ||
| 263 | + if (!(f instanceof BaseFragment)) { | ||
| 264 | + if (f.getUserVisibleHint() || (fromActivity && parentUserVisible(f))) { | ||
| 265 | + f.setUserVisibleHint(true); | ||
| 266 | + } | ||
| 267 | + continue; | ||
| 268 | + } | ||
| 269 | + | ||
| 270 | + BaseFragment lazy = (BaseFragment) f; | ||
| 271 | + // 忽略子fragment中有对用户不可见的fragment | ||
| 272 | + if (!lazy.getUserVisibleHint()) { | ||
| 273 | + continue; | ||
| 274 | + } | ||
| 275 | + | ||
| 276 | + lazy.userVisible(fromActivity); | ||
| 277 | + } | ||
| 278 | + onUserVisible(fromActivity); | ||
| 279 | + } | ||
| 280 | + | ||
| 281 | + void userInvisible(boolean fromActivity) { | ||
| 282 | + // 已经不可见则无需再调用 | ||
| 283 | + if (!isUserVisible) { | ||
| 284 | + return; | ||
| 285 | + } | ||
| 286 | + | ||
| 287 | + isUserVisible = false; | ||
| 288 | + | ||
| 289 | + FragmentManager fragmentManager; | ||
| 290 | + try { | ||
| 291 | + fragmentManager = getChildFragmentManager(); | ||
| 292 | + } catch (Exception e) { | ||
| 293 | + onUserInvisible(getUserVisibleHint(), fromActivity); | ||
| 294 | + return; | ||
| 295 | + } | ||
| 296 | + | ||
| 297 | + List<Fragment> fragments = fragmentManager.getFragments(); | ||
| 298 | + if (fragments == null || fragments.isEmpty()) { | ||
| 299 | + onUserInvisible(getUserVisibleHint(), fromActivity); | ||
| 300 | + return; | ||
| 301 | + } | ||
| 302 | + | ||
| 303 | + for (Fragment f : fragments) { | ||
| 304 | + /* | ||
| 305 | + * if (!f.isVisible()) { | ||
| 306 | + * continue; | ||
| 307 | + * } | ||
| 308 | + */ | ||
| 309 | + | ||
| 310 | + if (!(f instanceof BaseFragment)) { | ||
| 311 | + f.setUserVisibleHint(false); | ||
| 312 | + continue; | ||
| 313 | + } | ||
| 314 | + | ||
| 315 | + BaseFragment lazy = (BaseFragment) f; | ||
| 316 | + // 忽略子fragment中有对用户不可见的fragment | ||
| 317 | + if (!lazy.getUserVisibleHint()) { | ||
| 318 | + continue; | ||
| 319 | + } | ||
| 320 | + | ||
| 321 | + lazy.userInvisible(fromActivity); | ||
| 322 | + } | ||
| 323 | + onUserInvisible(getUserVisibleHint(), fromActivity); | ||
| 324 | + } | ||
| 325 | + | ||
| 326 | + /** | ||
| 327 | + * 进入用户可见壮状态 | ||
| 328 | + * | ||
| 329 | + * @param callFromActivity 是否是从activity层调用 | ||
| 330 | + */ | ||
| 331 | + protected void onUserVisible(boolean callFromActivity) { | ||
| 332 | + if (getLogTag() == null) { | ||
| 333 | + Logger.d("onUserVisible"); | ||
| 334 | + } else { | ||
| 335 | + Logger.t(getLogTag()).d("onUserVisible"); | ||
| 336 | + } | ||
| 337 | + } | ||
| 338 | + | ||
| 339 | + /** | ||
| 340 | + * 进入用户不可见状态, app进入后台,或者新的activity被启动时 | ||
| 341 | + * | ||
| 342 | + * @param userVisibleHint 表示在进入不可见状态时,是否是对用户可见状态,一般情况下在ViewPager里才起作用 | ||
| 343 | + * @param callFromActivity 是否是从activity层调用 | ||
| 344 | + */ | ||
| 345 | + protected void onUserInvisible(boolean userVisibleHint, boolean callFromActivity) { | ||
| 346 | + if (getLogTag() == null) { | ||
| 347 | + Logger.d("onUserInvisible"); | ||
| 348 | + } else { | ||
| 349 | + Logger.t(getLogTag()).d("onUserInvisible"); | ||
| 350 | + } | ||
| 351 | + } | ||
| 352 | + | ||
| 353 | + /** | ||
| 354 | + * loading 按返回键loading默认消失 | ||
| 355 | + */ | ||
| 356 | + public void startLoading() { | ||
| 357 | + startLoading(true); | ||
| 358 | + } | ||
| 359 | + | ||
| 360 | + /** | ||
| 361 | + * loading | ||
| 362 | + * @param allowCancel 按返回键loading是否消失 | ||
| 363 | + */ | ||
| 364 | + protected void startLoading(boolean allowCancel) { | ||
| 365 | + if (mActivity == null || mActivity.isFinishing() || mActivity.isDestroyed()) { | ||
| 366 | + return; | ||
| 367 | + } | ||
| 368 | + if (mLoadingDialog == null) { | ||
| 369 | + createLoadingDialog(allowCancel); | ||
| 370 | + } | ||
| 371 | + | ||
| 372 | + if (mLoadingDialog!=null&&!mLoadingDialog.isShowing()) { | ||
| 373 | + mLoadingDialog.show(); | ||
| 374 | + } | ||
| 375 | + } | ||
| 376 | + | ||
| 377 | + protected void stopLoading() { | ||
| 378 | + if (mActivity == null || mActivity.isFinishing() || mActivity.isDestroyed()) { | ||
| 379 | + return; | ||
| 380 | + } | ||
| 381 | + if (mLoadingDialog != null && mLoadingDialog.isShowing()) { | ||
| 382 | + mLoadingDialog.dismiss(); | ||
| 383 | + } | ||
| 384 | + } | ||
| 385 | + | ||
| 386 | + | ||
| 387 | + private void createLoadingDialog(boolean allowCancel) { | ||
| 388 | + mLoadingDialog = DialogUtils.createRequestDialog(mActivity, allowCancel); | ||
| 389 | + } | ||
| 390 | + | ||
| 391 | + /** | ||
| 392 | + * 增加空布局 | ||
| 393 | + */ | ||
| 394 | + protected View addEmptyView(int emptyType) { | ||
| 395 | + return addEmptyView(emptyType,null); | ||
| 396 | + } | ||
| 397 | + /** | ||
| 398 | + * 增加空布局 | ||
| 399 | + * | ||
| 400 | + * @return | ||
| 401 | + */ | ||
| 402 | + protected View addEmptyView(int type, DefaultView.RetryClickListener listener) { | ||
| 403 | + return addEmptyViewWithWeight(type,null,listener); | ||
| 404 | + } | ||
| 405 | + /** | ||
| 406 | + * 增加空布局 | ||
| 407 | + * | ||
| 408 | + * @return | ||
| 409 | + */ | ||
| 410 | + protected View addEmptyViewWithWeight(int type,Integer[] weight, DefaultView.RetryClickListener listener) { | ||
| 411 | + if(getContext() == null){ | ||
| 412 | + return null; | ||
| 413 | + } | ||
| 414 | + View emptyView = LayoutInflater.from(getContext()).inflate(R.layout.empty_view_layout, null); | ||
| 415 | + DefaultView mDefaultView = emptyView.findViewById(R.id.default_view); | ||
| 416 | + if (listener != null) { | ||
| 417 | + mDefaultView.setRetryBtnClickListener(listener); | ||
| 418 | + } | ||
| 419 | + if(weight == null || weight.length != 2){ | ||
| 420 | + mDefaultView.show(type); | ||
| 421 | + }else{ | ||
| 422 | + mDefaultView.showWithWeight(type,weight[0],weight[1]); | ||
| 423 | + } | ||
| 424 | + return emptyView; | ||
| 425 | + } | ||
| 426 | + | ||
| 427 | + | ||
| 428 | + @SuppressWarnings({"deprecation"}) | ||
| 429 | + @Override | ||
| 430 | + public void onAttach(@NonNull Activity activity) { | ||
| 431 | + super.onAttach(activity); | ||
| 432 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | ||
| 433 | + this.activity = activity; | ||
| 434 | + } | ||
| 435 | + } | ||
| 436 | + | ||
| 437 | + @TargetApi(23) | ||
| 438 | + @Override | ||
| 439 | + public void onAttach(@NonNull Context context) { | ||
| 440 | + super.onAttach(context); | ||
| 441 | + if (context instanceof Activity) { | ||
| 442 | + this.activity = (Activity) context; | ||
| 443 | + } | ||
| 444 | + } | ||
| 445 | + | ||
| 446 | + public void setStatusBarStyle(@NonNull StatusBarStyleEnum statusBarStyle) { | ||
| 447 | + ToolsUtil.setStatusBarStyle(statusBarStyle, getActivity()); | ||
| 448 | + } | ||
| 449 | + | ||
| 450 | + protected void perCreate() { | ||
| 451 | + | ||
| 452 | + } | ||
| 453 | + | ||
| 454 | + protected View getJavaLayout() { | ||
| 455 | + return null; | ||
| 456 | + } | ||
| 457 | + | ||
| 458 | + /** | ||
| 459 | + * 设置java布局标识 | ||
| 460 | + */ | ||
| 461 | + public void setIsjava(boolean isjava) { | ||
| 462 | + this.isjava = isjava; | ||
| 463 | + } | ||
| 464 | + | ||
| 465 | + | ||
| 466 | + public void onUserLeaveHint() { | ||
| 467 | + | ||
| 468 | + } | ||
| 469 | + | ||
| 470 | +} |
| 1 | +package com.wd.common.base; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import android.util.Log; | ||
| 5 | + | ||
| 6 | +import com.wd.foundation.wdkit.statusbar.StatusBarStyleEnum; | ||
| 7 | +import com.wd.foundation.wdkitcore.tools.StringUtils; | ||
| 8 | + | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 我的页面<BR> | ||
| 12 | + * @description :取消预加载的Fragment基类 | ||
| 13 | + * @author ouyang | ||
| 14 | + * @date 2022/7/4 | ||
| 15 | + */ | ||
| 16 | +public abstract class BaseLazyFragment extends BaseFragment { | ||
| 17 | + | ||
| 18 | + // 是否第一次加载 | ||
| 19 | + protected boolean isFirstLoad = true; | ||
| 20 | + | ||
| 21 | + public String mPageId; | ||
| 22 | + | ||
| 23 | + // 记录当前页面的原头信息的objectType,目前只用在专题中 | ||
| 24 | + public int objectType = 0; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 国殇标记(true:开启了国殇) | ||
| 28 | + */ | ||
| 29 | + public boolean contryGrayFlag = false; | ||
| 30 | + | ||
| 31 | + @Override | ||
| 32 | + public void setUserVisibleHint(boolean isVisibleToUser) { | ||
| 33 | + super.setUserVisibleHint(isVisibleToUser); | ||
| 34 | + Log.d("BaseLazyFragment", this.getClass().getName()); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Override | ||
| 38 | + public void onDestroyView() { | ||
| 39 | + super.onDestroyView(); | ||
| 40 | + isFirstLoad = true; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + @Override | ||
| 44 | + public void onResume() { | ||
| 45 | + super.onResume(); | ||
| 46 | + if (isFirstLoad) { | ||
| 47 | + lazyLoadData(); | ||
| 48 | + isFirstLoad = false; | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * viewModel 进入页面加载数据 | ||
| 55 | + */ | ||
| 56 | + protected abstract void lazyLoadData(); | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * 修改手机顶部状态,只支持白色和黑色 | ||
| 61 | + * @param isWhite | ||
| 62 | + */ | ||
| 63 | + public void changePhoneStatusBarWhiteOrBlack(boolean isWhite){ | ||
| 64 | + | ||
| 65 | + if(isWhite){ | ||
| 66 | + setStatusBarStyle(StatusBarStyleEnum.FULLSCREEN_LIGHT_ENUM); | ||
| 67 | + }else { | ||
| 68 | + setStatusBarStyle(StatusBarStyleEnum.FULLSCREEN_DARK_ENUM); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + | ||
| 74 | + protected int convertLikeStyle(String likeStyle) { | ||
| 75 | + // 1 心型 2拇指(弃用) 3蜡烛(新增) | ||
| 76 | + if (StringUtils.isBlank(likeStyle)) { | ||
| 77 | + return 1; | ||
| 78 | + } | ||
| 79 | + if ("candle".equals(likeStyle)) { | ||
| 80 | + return 3; | ||
| 81 | + } else { | ||
| 82 | + return 1; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public String getmPageId() { | ||
| 88 | + return mPageId; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + | ||
| 92 | +} |
| 1 | + | ||
| 2 | +/* | ||
| 3 | + * Copyright (c) People Technologies Co., Ltd. 2019-2022. All rights reserved. | ||
| 4 | + */ | ||
| 5 | + | ||
| 6 | +package com.wd.common.decoration; | ||
| 7 | + | ||
| 8 | +import android.graphics.Rect; | ||
| 9 | +import android.view.View; | ||
| 10 | + | ||
| 11 | +import androidx.annotation.NonNull; | ||
| 12 | +import androidx.recyclerview.widget.RecyclerView; | ||
| 13 | + | ||
| 14 | +public class Decoration extends RecyclerView.ItemDecoration { | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, | ||
| 18 | + @NonNull RecyclerView.State state) { | ||
| 19 | + // 设定边距为0px | ||
| 20 | + // outRect.set(0, 0, 0, 0); | ||
| 21 | + super.getItemOffsets(outRect, view, parent, state); | ||
| 22 | + } | ||
| 23 | +} |
| 1 | + | ||
| 2 | +/* | ||
| 3 | + * Copyright (c) Wondertek Technologies Co., Ltd. 2019-2022. All rights reserved. | ||
| 4 | + */ | ||
| 5 | + | ||
| 6 | +package com.wd.common.dialog; | ||
| 7 | + | ||
| 8 | +import android.app.Dialog; | ||
| 9 | +import android.content.Context; | ||
| 10 | +import android.view.Window; | ||
| 11 | +import android.view.WindowManager; | ||
| 12 | + | ||
| 13 | +import com.airbnb.lottie.LottieAnimationView; | ||
| 14 | +import com.wd.common.progress.PageLoadingView; | ||
| 15 | +import com.wd.fastcoding.base.R; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * @author yzm | ||
| 19 | + * @date 2022/6/27 | ||
| 20 | + * @time 9:34. | ||
| 21 | + */ | ||
| 22 | +public class DialogUtils { | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 构造方法 | ||
| 26 | + */ | ||
| 27 | + public static Dialog createRequestDialog(final Context context) { | ||
| 28 | + return createRequestDialog(context, true); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 创建请求弹窗 | ||
| 33 | + */ | ||
| 34 | + public static Dialog createRequestDialog(final Context context, boolean allowCancel) { | ||
| 35 | + return createRequestDialog(context, allowCancel, "refreshing_common_loading.json"); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 创建请求弹窗 | ||
| 40 | + */ | ||
| 41 | + public static Dialog createRequestDialog(final Context context, boolean allowCancel, String interactCode) { | ||
| 42 | + | ||
| 43 | + final Dialog dialog = new Dialog(context, R.style.CustomDialog); | ||
| 44 | + dialog.setContentView(R.layout.pdialog_layout); | ||
| 45 | + Window window = dialog.getWindow(); | ||
| 46 | + if (window != null) { | ||
| 47 | + WindowManager.LayoutParams lp = window.getAttributes(); | ||
| 48 | + int width = context.getResources().getDisplayMetrics().widthPixels; | ||
| 49 | + final double scaleFlag = 0.5; | ||
| 50 | + lp.width = (int) (scaleFlag * width); | ||
| 51 | + } | ||
| 52 | + dialog.setCanceledOnTouchOutside(allowCancel); | ||
| 53 | + dialog.setCancelable(allowCancel); | ||
| 54 | + | ||
| 55 | + PageLoadingView loadingView = dialog.findViewById(R.id.channelSmallLoading); | ||
| 56 | + loadingView.setInteractCode(interactCode); | ||
| 57 | + loadingView.showLoading(); | ||
| 58 | + return dialog; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * 一键登录的loading | ||
| 63 | + */ | ||
| 64 | +// public static Dialog createOneKeyAuthLoading(final Context context, boolean allowCancel) { | ||
| 65 | +// | ||
| 66 | +// final Dialog dialog = new Dialog(context, R.style.CustomDialog); | ||
| 67 | +// dialog.setContentView(R.layout.one_key_auth_login_loading); | ||
| 68 | +// Window window = dialog.getWindow(); | ||
| 69 | +// WindowManager.LayoutParams lp = window.getAttributes(); | ||
| 70 | +// int width = context.getResources().getDisplayMetrics().widthPixels; | ||
| 71 | +// int height = context.getResources().getDisplayMetrics().heightPixels; | ||
| 72 | +// lp.width = width; | ||
| 73 | +// lp.height = height; | ||
| 74 | +// dialog.setCanceledOnTouchOutside(false); | ||
| 75 | +// dialog.setCancelable(allowCancel); | ||
| 76 | +// | ||
| 77 | +// LottieAnimationView loadingView = dialog.findViewById(R.id.one_key_loading); | ||
| 78 | +// loadingView.setAnimation("login_loading.json"); | ||
| 79 | +// loadingView.playAnimation(); | ||
| 80 | +// | ||
| 81 | +// return dialog; | ||
| 82 | +// } | ||
| 83 | + | ||
| 84 | + public interface DialogOneButtonClickListener { | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * 确定 | ||
| 88 | + */ | ||
| 89 | + void okButtonClick(); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | +} |
| 1 | +package com.wd.common.dialog; | ||
| 2 | + | ||
| 3 | +import android.app.Activity; | ||
| 4 | +import android.app.Dialog; | ||
| 5 | +import android.content.Context; | ||
| 6 | +import android.content.DialogInterface; | ||
| 7 | +import android.os.Handler; | ||
| 8 | +import android.os.Looper; | ||
| 9 | +import android.view.Display; | ||
| 10 | +import android.view.LayoutInflater; | ||
| 11 | +import android.view.View; | ||
| 12 | +import android.view.WindowManager; | ||
| 13 | +import android.view.animation.Animation; | ||
| 14 | +import android.widget.FrameLayout; | ||
| 15 | +import android.widget.ImageView; | ||
| 16 | +import android.widget.LinearLayout; | ||
| 17 | +import android.widget.RelativeLayout; | ||
| 18 | + | ||
| 19 | +import com.wd.foundation.wdkit.constant.Constants; | ||
| 20 | +import com.wd.common.imageglide.ImageUtils; | ||
| 21 | +import com.wd.common.viewclick.BaseClickListener; | ||
| 22 | +import com.wd.fastcoding.base.R; | ||
| 23 | +import com.wd.foundation.wdkit.animator.MyAnimationUtils; | ||
| 24 | +import com.wd.foundation.wdkit.utils.UiUtils; | ||
| 25 | + | ||
| 26 | + | ||
| 27 | +/** | ||
| 28 | + * @author baozhaoxin | ||
| 29 | + * @version [V1.0.0, 2022/8/17] | ||
| 30 | + * @description 彩蛋弹窗 | ||
| 31 | + * @since V1.0.0 | ||
| 32 | + */ | ||
| 33 | +public class EasterEggsDialog { | ||
| 34 | + /** | ||
| 35 | + * 上下文环境 | ||
| 36 | + */ | ||
| 37 | + private Context context; | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * dialog | ||
| 41 | + */ | ||
| 42 | + private Dialog dialog; | ||
| 43 | + | ||
| 44 | + private Display display; | ||
| 45 | + /** | ||
| 46 | + * 弹窗布局 | ||
| 47 | + */ | ||
| 48 | + private RelativeLayout dialogLaout; | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 弹窗图片 | ||
| 52 | + */ | ||
| 53 | + private ImageView img; | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 弹窗关闭按钮 | ||
| 57 | + */ | ||
| 58 | + private ImageView closeImg; | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 监听 | ||
| 62 | + */ | ||
| 63 | + private DialogClickListener clickListener; | ||
| 64 | + | ||
| 65 | + public View view; | ||
| 66 | + | ||
| 67 | + | ||
| 68 | + public EasterEggsDialog(Context context) { | ||
| 69 | + this.context = context; | ||
| 70 | + display = UiUtils.getDisplay(context); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public Dialog getDialog() { | ||
| 74 | + return dialog; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * 创建布局 | ||
| 79 | + * @return | ||
| 80 | + */ | ||
| 81 | + public EasterEggsDialog builder() { | ||
| 82 | + // 获取Dialog布局 | ||
| 83 | + view = LayoutInflater.from(context).inflate(R.layout.dialog_easter_eggs, null); | ||
| 84 | + dialogLaout = view.findViewById(R.id.dialog_layout); | ||
| 85 | + img = view.findViewById(R.id.img); | ||
| 86 | + closeImg = view.findViewById(R.id.img_close); | ||
| 87 | + | ||
| 88 | + // 定义Dialog布局和参数 | ||
| 89 | + dialog = new Dialog(context, R.style.AlertDialogStyle); | ||
| 90 | + dialog.setContentView(view); | ||
| 91 | + | ||
| 92 | + WindowManager.LayoutParams lp = dialog.getWindow().getAttributes(); | ||
| 93 | + lp.dimAmount = 0.5f; | ||
| 94 | + // lp.y = 250; | ||
| 95 | + dialog.getWindow().setAttributes(lp); | ||
| 96 | + dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); | ||
| 97 | + | ||
| 98 | + // 调整dialog背景大小 | ||
| 99 | + dialogLaout.setLayoutParams( | ||
| 100 | + new FrameLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); | ||
| 101 | + dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { | ||
| 102 | + @Override | ||
| 103 | + public void onCancel(DialogInterface dialog) { | ||
| 104 | + //点击空白区域,更新状态 | ||
| 105 | + Constants.isShowingEasterEggs = false; | ||
| 106 | + } | ||
| 107 | + }); | ||
| 108 | + Animation animation = MyAnimationUtils.loadAnimation(context, R.anim.scale_easter_eggs_dialog); | ||
| 109 | + view.setAnimation(animation); | ||
| 110 | + animation.start(); | ||
| 111 | + | ||
| 112 | + img.setOnClickListener(new BaseClickListener() { | ||
| 113 | + @Override | ||
| 114 | + protected void onNoDoubleClick(View v) { | ||
| 115 | + if(clickListener!=null){ | ||
| 116 | + clickListener.onJump(); | ||
| 117 | + } | ||
| 118 | + dialog.dismiss(); | ||
| 119 | + } | ||
| 120 | + }); | ||
| 121 | + | ||
| 122 | + closeImg.setOnClickListener(view1 -> { | ||
| 123 | + if(clickListener!=null){ | ||
| 124 | + clickListener.onClose(); | ||
| 125 | + } | ||
| 126 | + dialog.dismiss(); | ||
| 127 | + }); | ||
| 128 | + return this; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * 设置监听 | ||
| 133 | + * @param clickListener | ||
| 134 | + */ | ||
| 135 | + public EasterEggsDialog setClickListener(DialogClickListener clickListener){ | ||
| 136 | + this.clickListener = clickListener; | ||
| 137 | + return this; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + /** | ||
| 141 | + * 设置彩蛋素材地址 | ||
| 142 | + * @param materialUrl | ||
| 143 | + * @return | ||
| 144 | + */ | ||
| 145 | + public EasterEggsDialog setMaterialUrl(String materialUrl){ | ||
| 146 | + if(img!=null){ | ||
| 147 | + ImageUtils.getInstance().loadImage(img,materialUrl); | ||
| 148 | + } | ||
| 149 | + return this; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + /** | ||
| 153 | + * 自动关闭时长: 0代表不自动关闭,其他为对应时长(s) | ||
| 154 | + * @param durations | ||
| 155 | + * @return | ||
| 156 | + */ | ||
| 157 | + public EasterEggsDialog setDurations(String durations){ | ||
| 158 | + try { | ||
| 159 | + int duration = Integer.parseInt(durations); | ||
| 160 | + if(duration>0){ | ||
| 161 | + long mDuration = duration*1000; | ||
| 162 | + //自动关闭 | ||
| 163 | + new Handler(Looper.myLooper()).postDelayed(() -> { | ||
| 164 | + if(dialog!=null){ | ||
| 165 | + Constants.isShowingEasterEggs = false; | ||
| 166 | + dialog.dismiss(); | ||
| 167 | + } | ||
| 168 | + },mDuration); | ||
| 169 | + } | ||
| 170 | + } catch (NumberFormatException e) { | ||
| 171 | + e.printStackTrace(); | ||
| 172 | + } | ||
| 173 | + return this; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + public boolean isShowing() { | ||
| 177 | + if (dialog!=null){ | ||
| 178 | + return dialog.isShowing(); | ||
| 179 | + } | ||
| 180 | + return false; | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + /** | ||
| 184 | + * 回调监听 | ||
| 185 | + */ | ||
| 186 | + public interface DialogClickListener { | ||
| 187 | + void onJump(); | ||
| 188 | + | ||
| 189 | + void onClose(); | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + /** | ||
| 193 | + * 显示 | ||
| 194 | + */ | ||
| 195 | + public EasterEggsDialog show() { | ||
| 196 | + if(context != null){ | ||
| 197 | + if(context instanceof Activity){ | ||
| 198 | + Activity activity = (Activity) context; | ||
| 199 | + if(!activity.isDestroyed() && !activity.isFinishing()){ | ||
| 200 | + if(dialog!=null){ | ||
| 201 | + dialog.show(); | ||
| 202 | + } | ||
| 203 | + } | ||
| 204 | + }else{ | ||
| 205 | + if(dialog!=null){ | ||
| 206 | + dialog.show(); | ||
| 207 | + } | ||
| 208 | + } | ||
| 209 | + } | ||
| 210 | + return this; | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + /** | ||
| 214 | + * 关闭 | ||
| 215 | + */ | ||
| 216 | + public EasterEggsDialog close() { | ||
| 217 | + Constants.isShowingEasterEggs = false; | ||
| 218 | + if(context != null){ | ||
| 219 | + if(context instanceof Activity){ | ||
| 220 | + Activity activity = (Activity) context; | ||
| 221 | + if(!activity.isDestroyed() && !activity.isFinishing()){ | ||
| 222 | + if(dialog!=null){ | ||
| 223 | + dialog.dismiss(); | ||
| 224 | + } | ||
| 225 | + } | ||
| 226 | + }else{ | ||
| 227 | + if(dialog!=null){ | ||
| 228 | + dialog.dismiss(); | ||
| 229 | + } | ||
| 230 | + } | ||
| 231 | + } | ||
| 232 | + return this; | ||
| 233 | + } | ||
| 234 | + | ||
| 235 | + | ||
| 236 | +} |
| 1 | +package com.wd.common.dialog; | ||
| 2 | + | ||
| 3 | +import android.app.Activity; | ||
| 4 | +import android.app.Dialog; | ||
| 5 | +import android.content.Context; | ||
| 6 | +import android.os.Bundle; | ||
| 7 | +import android.os.Handler; | ||
| 8 | +import android.os.Looper; | ||
| 9 | +import android.view.KeyEvent; | ||
| 10 | +import android.widget.TextView; | ||
| 11 | + | ||
| 12 | +import androidx.annotation.NonNull; | ||
| 13 | + | ||
| 14 | +import com.wd.fastcoding.base.R; | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * created by wxl and 2022/8/2 | ||
| 19 | + */ | ||
| 20 | +public class FlowTooBigDialog extends Dialog { | ||
| 21 | + | ||
| 22 | + private final OnCloseClickListener mOnCloseClickListener; | ||
| 23 | + private boolean isflowtoobig = true; | ||
| 24 | + private Runnable runnable; | ||
| 25 | + private Context context; | ||
| 26 | + | ||
| 27 | + public boolean isIsflowtoobig() { | ||
| 28 | + return isflowtoobig; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public void setIsflowtoobig(boolean isflowtoobig) { | ||
| 32 | + this.isflowtoobig = isflowtoobig; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public FlowTooBigDialog(@NonNull Context context, OnCloseClickListener onCloseClickListener) { | ||
| 36 | + super(context, R.style.AlertDialogStyle); | ||
| 37 | + this.context = context; | ||
| 38 | + mOnCloseClickListener = onCloseClickListener; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + int secnum = -100; | ||
| 42 | + TextView titlt; | ||
| 43 | + | ||
| 44 | + @Override | ||
| 45 | + protected void onCreate(Bundle savedInstanceState) { | ||
| 46 | + super.onCreate(savedInstanceState); | ||
| 47 | + setContentView(R.layout.dialog_flowbig_layout); | ||
| 48 | + titlt = findViewById(R.id.titlt); | ||
| 49 | + runnable = new Runnable() { | ||
| 50 | + @Override | ||
| 51 | + public void run() { | ||
| 52 | + if (secnum != -100) { | ||
| 53 | + if (secnum < 0) { | ||
| 54 | + secnum = -100; | ||
| 55 | + dismiss(); | ||
| 56 | + mOnCloseClickListener.back(); | ||
| 57 | + return; | ||
| 58 | + } | ||
| 59 | +// Log.e("!!!!", "secnum " + secnum); | ||
| 60 | + titlt.setText(secnum-- + ""); | ||
| 61 | + handler.postDelayed(this, 1100); | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + }; | ||
| 66 | + setCancelable(false); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + private Handler handler = new Handler(Looper.getMainLooper()); | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public void show() { | ||
| 73 | + if(getContext() != null){ | ||
| 74 | + if(getContext() instanceof Activity){ | ||
| 75 | + Activity activity = (Activity) getContext(); | ||
| 76 | + if(!activity.isDestroyed() && !activity.isFinishing()){ | ||
| 77 | + super.show(); | ||
| 78 | + if (secnum == -100) { | ||
| 79 | + secnum = 10; | ||
| 80 | + handler.post(runnable); | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + }else{ | ||
| 84 | + super.show(); | ||
| 85 | + if (secnum == -100) { | ||
| 86 | + secnum = 10; | ||
| 87 | + handler.post(runnable); | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + @Override | ||
| 94 | + public void dismiss() { | ||
| 95 | + try{ | ||
| 96 | + if(context != null && isShowing()){ | ||
| 97 | + if(context instanceof Activity){ | ||
| 98 | + Activity activity = (Activity) context; | ||
| 99 | + if(!activity.isDestroyed() && !activity.isFinishing()){ | ||
| 100 | + super.dismiss(); | ||
| 101 | + } | ||
| 102 | + }else{ | ||
| 103 | + super.dismiss(); | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + }catch (Exception e){ | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + secnum = -100; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + @Override | ||
| 113 | + public boolean onKeyDown(int keyCode, KeyEvent event) { | ||
| 114 | + if (keyCode == KeyEvent.KEYCODE_BACK) { | ||
| 115 | + return true; | ||
| 116 | + } | ||
| 117 | + return super.onKeyDown(keyCode, event); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + public interface OnCloseClickListener { | ||
| 121 | + | ||
| 122 | + void back(); | ||
| 123 | + } | ||
| 124 | +} |
| 1 | +package com.wd.common.dialog; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +import com.wd.base.log.Logger; | ||
| 7 | +import com.wd.foundation.wdkitcore.tools.HostUtil; | ||
| 8 | +import com.wd.common.utils.ProcessUtils; | ||
| 9 | +import com.wd.foundation.bean.custom.content.ContentBean; | ||
| 10 | +import com.wd.foundation.bean.pop.PopUpsBean; | ||
| 11 | +import com.wd.foundation.wdkit.utils.SpUtils; | ||
| 12 | +import com.wd.foundation.wdkit.utils.TimeUtil; | ||
| 13 | + | ||
| 14 | +import java.util.ArrayList; | ||
| 15 | +import java.util.List; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * 彩蛋工具类 | ||
| 19 | + * @author baozhaoxin | ||
| 20 | + * @version [V1.0.0, 2022/8/20] | ||
| 21 | + */ | ||
| 22 | +public class PopUpsUtils { | ||
| 23 | + | ||
| 24 | + private static String TAG = "PopUpsUtils"; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * | ||
| 28 | + * @param hasPopUp 是否有彩蛋 | ||
| 29 | + * @param originalList 原始数据集合 | ||
| 30 | + * @return | ||
| 31 | + */ | ||
| 32 | + public static PopUpsBean handlerPopUps(boolean hasPopUp, List<PopUpsBean> originalList, String type){ | ||
| 33 | + if(!hasPopUp){ | ||
| 34 | + //没有彩蛋 | ||
| 35 | + return null; | ||
| 36 | + } | ||
| 37 | + if(originalList==null||originalList.size()==0){ | ||
| 38 | + //彩蛋数据为空 | ||
| 39 | + return null; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + List<PopUpsBean> resultlList = new ArrayList<>(); | ||
| 43 | + | ||
| 44 | + //按时间和exposureOnce过滤数据 | ||
| 45 | + handlerByDataAndExposureOnce(resultlList,originalList,type); | ||
| 46 | + | ||
| 47 | + if(resultlList!=null&&resultlList.size()>0){ | ||
| 48 | + //返回符合条件的第一条数据 | ||
| 49 | + return resultlList.get(0); | ||
| 50 | + } | ||
| 51 | + return null; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + *按时间和exposureOnce过滤数据 | ||
| 56 | + * @param resultlList | ||
| 57 | + * @param originalList | ||
| 58 | + */ | ||
| 59 | + private static void handlerByDataAndExposureOnce(List<PopUpsBean> resultlList,List<PopUpsBean> originalList,String type){ | ||
| 60 | + long currentTimeStamp = HostUtil.serverTime; | ||
| 61 | + for (PopUpsBean bean : originalList) { | ||
| 62 | + PopUpsBean popUpsBean = SpUtils.getPopUpById(bean.getId()); | ||
| 63 | + if(popUpsBean != null && ( | ||
| 64 | + popUpsBean.getAlreadyDailyExposureTimes() == popUpsBean.getDailyExposureTimes() || | ||
| 65 | + popUpsBean.getAlreadyDailyExposureTimes() > popUpsBean.getDailyExposureTimes())){ | ||
| 66 | + //当日看到N次彩蛋后,当日不会再看到彩蛋 | ||
| 67 | + continue; | ||
| 68 | + } | ||
| 69 | + try { | ||
| 70 | + long startTimeStamp = TimeUtil.time2timestamp(bean.getStartTime()); | ||
| 71 | + long endTimeStamp = TimeUtil.time2timestamp(bean.getEndTime()); | ||
| 72 | + if (currentTimeStamp >= startTimeStamp | ||
| 73 | + && currentTimeStamp <= endTimeStamp) { | ||
| 74 | + resultlList.add(bean); | ||
| 75 | + } | ||
| 76 | + } catch (Exception e) { | ||
| 77 | + e.printStackTrace(); | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * 显示彩蛋 | ||
| 84 | + */ | ||
| 85 | + public static EasterEggsDialog showEasterEggsDialog(Context context,PopUpsBean mPopUpsBean,String type, | ||
| 86 | + EasterEggsDialog.DialogClickListener mListener) { | ||
| 87 | + if (mPopUpsBean != null) { | ||
| 88 | + EasterEggsDialog easterEggsDialog = new EasterEggsDialog(context).builder() | ||
| 89 | + .setMaterialUrl(mPopUpsBean.getMaterialUrl()) | ||
| 90 | + .setDurations(mPopUpsBean.getDurations()) | ||
| 91 | + .setClickListener(mListener) | ||
| 92 | + .show(); | ||
| 93 | + Logger.t(TAG).d("easterEggsResult=" + mPopUpsBean.toString()); | ||
| 94 | + SpUtils.savePopUpToCache(mPopUpsBean); | ||
| 95 | + return easterEggsDialog; | ||
| 96 | + } | ||
| 97 | + return null; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * 彩蛋点击跳转 | ||
| 102 | + * | ||
| 103 | + * @param mPopUpsBean | ||
| 104 | + */ | ||
| 105 | + public static void easterEggsDialogJump(PopUpsBean mPopUpsBean) { | ||
| 106 | + if(mPopUpsBean==null){ | ||
| 107 | + return; | ||
| 108 | + } | ||
| 109 | + ContentBean contentBean = new ContentBean(); | ||
| 110 | + contentBean.setPageId(mPopUpsBean.getPageId()); | ||
| 111 | + contentBean.setLinkUrl(mPopUpsBean.getLinkUrl()); | ||
| 112 | + contentBean.setObjectId(mPopUpsBean.getObjectId()); | ||
| 113 | + contentBean.setObjectType(mPopUpsBean.getObjectType()); | ||
| 114 | + contentBean.setObjectLevel(mPopUpsBean.getObjectLevel()); | ||
| 115 | + contentBean.setBottomNavId(mPopUpsBean.getBottomNavId()); | ||
| 116 | + contentBean.setRelId(mPopUpsBean.getRelId()); | ||
| 117 | + //专题模板 --->专题样式 1:常规, 2:作者, 3:时间线 | ||
| 118 | + // contentBean.setTopicTemplate(mPopUpsBean.getTopicTemplate()); | ||
| 119 | + ProcessUtils.processPage(contentBean); | ||
| 120 | + } | ||
| 121 | +} |
| 1 | +/* | ||
| 2 | + * Copyright (c) Wondertek Technologies Co., Ltd. 2019-2022. All rights reserved. | ||
| 3 | + */ | ||
| 4 | + | ||
| 5 | +package com.wd.common.dialog; | ||
| 6 | + | ||
| 7 | +import android.app.Activity; | ||
| 8 | +import android.app.Dialog; | ||
| 9 | +import android.content.Context; | ||
| 10 | +import android.text.TextUtils; | ||
| 11 | +import android.view.Display; | ||
| 12 | +import android.view.LayoutInflater; | ||
| 13 | +import android.view.View; | ||
| 14 | +import android.view.View.OnClickListener; | ||
| 15 | +import android.view.WindowManager; | ||
| 16 | +import android.widget.FrameLayout; | ||
| 17 | +import android.widget.LinearLayout; | ||
| 18 | +import android.widget.LinearLayout.LayoutParams; | ||
| 19 | +import android.widget.TextView; | ||
| 20 | + | ||
| 21 | +import com.wd.fastcoding.base.R; | ||
| 22 | +import com.wd.foundation.wdkit.utils.UiUtils; | ||
| 23 | +import com.wd.foundation.wdkitcore.tools.ResUtils; | ||
| 24 | + | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * @author baozhaoxin | ||
| 28 | + * @date 2022/8/4 | ||
| 29 | + */ | ||
| 30 | +public class TipsDialog { | ||
| 31 | + private Context context; | ||
| 32 | + | ||
| 33 | + private Dialog dialog; | ||
| 34 | + /** | ||
| 35 | + * 布局 | ||
| 36 | + */ | ||
| 37 | + private LinearLayout lLayout; | ||
| 38 | + /** | ||
| 39 | + * 标题 | ||
| 40 | + */ | ||
| 41 | + private TextView titleTv; | ||
| 42 | + /** | ||
| 43 | + * 内容 | ||
| 44 | + */ | ||
| 45 | + private TextView contentTv; | ||
| 46 | + /** | ||
| 47 | + * 左边按钮 | ||
| 48 | + */ | ||
| 49 | + private TextView disagreeTv; | ||
| 50 | + /** | ||
| 51 | + * 中间分隔线 | ||
| 52 | + */ | ||
| 53 | + private View centerLine; | ||
| 54 | + /** | ||
| 55 | + * 右边按钮 | ||
| 56 | + */ | ||
| 57 | + private TextView agreeTv; | ||
| 58 | + | ||
| 59 | + private boolean showLeftBtn = false; | ||
| 60 | + | ||
| 61 | + private boolean showRightBtn = false; | ||
| 62 | + | ||
| 63 | + private Display display; | ||
| 64 | + | ||
| 65 | + public TipsDialog(Context context) { | ||
| 66 | + this.context = context; | ||
| 67 | + display = UiUtils.getDisplay(context); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public TipsDialog builder() { | ||
| 71 | + // 获取Dialog布局 | ||
| 72 | + View view = LayoutInflater.from(context).inflate(R.layout.dialog_tips, null); | ||
| 73 | + | ||
| 74 | + lLayout = view.findViewById(R.id.lLayout_bg); | ||
| 75 | + titleTv = view.findViewById(R.id.tv_title); | ||
| 76 | + contentTv = view.findViewById(R.id.tv_content); | ||
| 77 | + disagreeTv = view.findViewById(R.id.tv_disagree); | ||
| 78 | + agreeTv = view.findViewById(R.id.tv_agree); | ||
| 79 | + centerLine = view.findViewById(R.id.line_center); | ||
| 80 | + disagreeTv.setVisibility(View.GONE); | ||
| 81 | + centerLine.setVisibility(View.GONE); | ||
| 82 | + agreeTv.setVisibility(View.GONE); | ||
| 83 | + | ||
| 84 | + // 定义Dialog布局和参数 | ||
| 85 | + dialog = new Dialog(context, R.style.AlertDialogStyle); | ||
| 86 | + dialog.setContentView(view); | ||
| 87 | + | ||
| 88 | + WindowManager.LayoutParams lp = dialog.getWindow().getAttributes(); | ||
| 89 | + lp.dimAmount = 0.6f; | ||
| 90 | + // lp.y = 250; | ||
| 91 | + dialog.getWindow().setAttributes(lp); | ||
| 92 | + dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); | ||
| 93 | + dialog.setCancelable(false); | ||
| 94 | + dialog.setCanceledOnTouchOutside(false); | ||
| 95 | + // 调整dialog背景大小 | ||
| 96 | + lLayout.setLayoutParams( | ||
| 97 | + new FrameLayout.LayoutParams((int) (display.getWidth() * 0.85), LayoutParams.WRAP_CONTENT)); | ||
| 98 | + | ||
| 99 | + return this; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + public TipsDialog setTitle(String title) { | ||
| 103 | + titleTv.setText(TextUtils.isEmpty(title)? ResUtils.getString(R.string.warm_prompt):title); | ||
| 104 | + return this; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public TipsDialog setMsg(String msg) { | ||
| 108 | + contentTv.setText(msg); | ||
| 109 | + return this; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public TipsDialog setCancelable(boolean cancel) { | ||
| 113 | + dialog.setCancelable(cancel); | ||
| 114 | + return this; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + public TipsDialog setLeftButton(String text, final OnClickListener listener) { | ||
| 118 | + showLeftBtn = true; | ||
| 119 | + disagreeTv.setText(TextUtils.isEmpty(text)?"取消":text); | ||
| 120 | + disagreeTv.setOnClickListener(new OnClickListener() { | ||
| 121 | + @Override | ||
| 122 | + public void onClick(View v) { | ||
| 123 | + listener.onClick(v); | ||
| 124 | + dialog.dismiss(); | ||
| 125 | + } | ||
| 126 | + }); | ||
| 127 | + return this; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + public TipsDialog setRightButton(String text, final OnClickListener listener) { | ||
| 131 | + showRightBtn = true; | ||
| 132 | + agreeTv.setText(TextUtils.isEmpty(text)?"确定":text); | ||
| 133 | + agreeTv.setOnClickListener(new OnClickListener() { | ||
| 134 | + @Override | ||
| 135 | + public void onClick(View v) { | ||
| 136 | + listener.onClick(v); | ||
| 137 | + dialog.dismiss(); | ||
| 138 | + } | ||
| 139 | + }); | ||
| 140 | + return this; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + private void setLayout() { | ||
| 144 | + titleTv.setText(ResUtils.getString(R.string.warm_prompt)); | ||
| 145 | + | ||
| 146 | + | ||
| 147 | + if (!showLeftBtn && !showRightBtn) { | ||
| 148 | + disagreeTv.setVisibility(View.GONE); | ||
| 149 | + centerLine.setVisibility(View.GONE); | ||
| 150 | + agreeTv.setText("确定"); | ||
| 151 | + agreeTv.setVisibility(View.VISIBLE); | ||
| 152 | + agreeTv.setOnClickListener(new OnClickListener() { | ||
| 153 | + @Override | ||
| 154 | + public void onClick(View v) { | ||
| 155 | + dialog.dismiss(); | ||
| 156 | + } | ||
| 157 | + }); | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + if (showLeftBtn && showRightBtn) { | ||
| 161 | + disagreeTv.setVisibility(View.VISIBLE); | ||
| 162 | + agreeTv.setVisibility(View.VISIBLE); | ||
| 163 | + centerLine.setVisibility(View.VISIBLE); | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + if (showLeftBtn && !showRightBtn) { | ||
| 167 | + disagreeTv.setVisibility(View.VISIBLE); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + if (!showLeftBtn && showRightBtn) { | ||
| 171 | + agreeTv.setVisibility(View.VISIBLE); | ||
| 172 | + } | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + public void show() { | ||
| 176 | + if(context != null && context instanceof Activity){ | ||
| 177 | + Activity activity = (Activity) context; | ||
| 178 | + if(activity.isDestroyed() || activity.isFinishing()){ | ||
| 179 | + return; | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + setLayout(); | ||
| 183 | + dialog.show(); | ||
| 184 | + } | ||
| 185 | +} |
| 1 | + | ||
| 2 | +package com.wd.common.imageglide; | ||
| 3 | + | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.content.res.Resources; | ||
| 6 | +import android.graphics.Bitmap; | ||
| 7 | +import android.graphics.BitmapShader; | ||
| 8 | +import android.graphics.Canvas; | ||
| 9 | +import android.graphics.Paint; | ||
| 10 | +import android.graphics.RectF; | ||
| 11 | + | ||
| 12 | +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; | ||
| 13 | +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; | ||
| 14 | +import com.bumptech.glide.load.resource.bitmap.TransformationUtils; | ||
| 15 | + | ||
| 16 | +import java.security.MessageDigest; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * @author yzm | ||
| 20 | + * @date 2022/7/9 | ||
| 21 | + * @time 16:53. | ||
| 22 | + */ | ||
| 23 | +public class GlideRoundTransform extends BitmapTransformation { | ||
| 24 | + | ||
| 25 | + private static float radius = 20f; | ||
| 26 | + | ||
| 27 | + public GlideRoundTransform(Context context) { | ||
| 28 | + this(context, 4); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public GlideRoundTransform(Context context, int dp) { | ||
| 32 | +// super(context); | ||
| 33 | + radius = Resources.getSystem().getDisplayMetrics().density * dp; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { | ||
| 38 | + Bitmap bitmap = TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight); | ||
| 39 | + return roundCrop(pool, bitmap); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + private static Bitmap roundCrop(BitmapPool pool, Bitmap source) { | ||
| 43 | + if (source == null) | ||
| 44 | + return null; | ||
| 45 | + | ||
| 46 | + Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); | ||
| 47 | + if (result == null) { | ||
| 48 | + result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + Canvas canvas = new Canvas(result); | ||
| 52 | + Paint paint = new Paint(); | ||
| 53 | + paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); | ||
| 54 | + paint.setAntiAlias(true); | ||
| 55 | + RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); | ||
| 56 | + canvas.drawRoundRect(rectF, radius, radius, paint); | ||
| 57 | + return result; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public String getId() { | ||
| 61 | + return getClass().getName() + Math.round(radius); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Override | ||
| 65 | + public void updateDiskCacheKey(MessageDigest messageDigest) { | ||
| 66 | + | ||
| 67 | + } | ||
| 68 | +} |
-
Please register or login to post a comment