mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-17 08:25:53 +08:00
更新安卓文件夹
This commit is contained in:
16
android/.gitignore
vendored
16
android/.gitignore
vendored
@@ -1,16 +0,0 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/LocalRepository
|
||||
/keystores
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/codeStyles
|
||||
/.idea/inspectionProfiles
|
||||
/.idea/libraries
|
||||
/.idea/dictionaries
|
||||
/.idea/markdown-navigator
|
||||
/.idea/*.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
7
android/.idea/copyright/profiles_settings.xml
generated
7
android/.idea/copyright/profiles_settings.xml
generated
@@ -1,7 +0,0 @@
|
||||
<component name="CopyrightManager">
|
||||
<settings default="xuexiang">
|
||||
<module2copyright>
|
||||
<element module="Project Files" copyright="xuexiang" />
|
||||
</module2copyright>
|
||||
</settings>
|
||||
</component>
|
||||
6
android/.idea/copyright/xuexiang.xml
generated
6
android/.idea/copyright/xuexiang.xml
generated
@@ -1,6 +0,0 @@
|
||||
<component name="CopyrightManager">
|
||||
<copyright>
|
||||
<option name="notice" value="Copyright (C) &#36;today.year xuexiangjys(xuexiangjys@163.com) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. " />
|
||||
<option name="myName" value="xuexiang" />
|
||||
</copyright>
|
||||
</component>
|
||||
191
android/LICENSE
191
android/LICENSE
@@ -1,191 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and
|
||||
distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
||||
owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities
|
||||
that control, are controlled by, or are under common control with that entity.
|
||||
For the purposes of this definition, "control" means (i) the power, direct or
|
||||
indirect, to cause the direction or management of such entity, whether by
|
||||
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
||||
permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including
|
||||
but not limited to software source code, documentation source, and configuration
|
||||
files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or
|
||||
translation of a Source form, including but not limited to compiled object code,
|
||||
generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
||||
available under the License, as indicated by a copyright notice that is included
|
||||
in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
||||
is based on (or derived from) the Work and for which the editorial revisions,
|
||||
annotations, elaborations, or other modifications represent, as a whole, an
|
||||
original work of authorship. For the purposes of this License, Derivative Works
|
||||
shall not include works that remain separable from, or merely link (or bind by
|
||||
name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version
|
||||
of the Work and any modifications or additions to that Work or Derivative Works
|
||||
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
||||
by the copyright owner or by an individual or Legal Entity authorized to submit
|
||||
on behalf of the copyright owner. For the purposes of this definition,
|
||||
"submitted" means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems, and
|
||||
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
||||
the purpose of discussing and improving the Work, but excluding communication
|
||||
that is conspicuously marked or otherwise designated in writing by the copyright
|
||||
owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
||||
of whom a Contribution has been received by Licensor and subsequently
|
||||
incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the Work and such
|
||||
Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable (except as stated in this section) patent license to make, have
|
||||
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
||||
such license applies only to those patent claims licensable by such Contributor
|
||||
that are necessarily infringed by their Contribution(s) alone or by combination
|
||||
of their Contribution(s) with the Work to which such Contribution(s) was
|
||||
submitted. If You institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
||||
Contribution incorporated within the Work constitutes direct or contributory
|
||||
patent infringement, then any patent licenses granted to You under this License
|
||||
for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution.
|
||||
|
||||
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
||||
in any medium, with or without modifications, and in Source or Object form,
|
||||
provided that You meet the following conditions:
|
||||
|
||||
You must give any other recipients of the Work or Derivative Works a copy of
|
||||
this License; and
|
||||
You must cause any modified files to carry prominent notices stating that You
|
||||
changed the files; and
|
||||
You must retain, in the Source form of any Derivative Works that You distribute,
|
||||
all copyright, patent, trademark, and attribution notices from the Source form
|
||||
of the Work, excluding those notices that do not pertain to any part of the
|
||||
Derivative Works; and
|
||||
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
||||
Derivative Works that You distribute must include a readable copy of the
|
||||
attribution notices contained within such NOTICE file, excluding those notices
|
||||
that do not pertain to any part of the Derivative Works, in at least one of the
|
||||
following places: within a NOTICE text file distributed as part of the
|
||||
Derivative Works; within the Source form or documentation, if provided along
|
||||
with the Derivative Works; or, within a display generated by the Derivative
|
||||
Works, if and wherever such third-party notices normally appear. The contents of
|
||||
the NOTICE file are for informational purposes only and do not modify the
|
||||
License. You may add Your own attribution notices within Derivative Works that
|
||||
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
||||
provided that such additional attribution notices cannot be construed as
|
||||
modifying the License.
|
||||
You may add Your own copyright statement to Your modifications and may provide
|
||||
additional or different license terms and conditions for use, reproduction, or
|
||||
distribution of Your modifications, or for any such Derivative Works as a whole,
|
||||
provided Your use, reproduction, and distribution of the Work otherwise complies
|
||||
with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions.
|
||||
|
||||
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
||||
for inclusion in the Work by You to the Licensor shall be under the terms and
|
||||
conditions of this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
||||
any separate license agreement you may have executed with Licensor regarding
|
||||
such Contributions.
|
||||
|
||||
6. Trademarks.
|
||||
|
||||
This License does not grant permission to use the trade names, trademarks,
|
||||
service marks, or product names of the Licensor, except as required for
|
||||
reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, Licensor provides the
|
||||
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
||||
including, without limitation, any warranties or conditions of TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
||||
solely responsible for determining the appropriateness of using or
|
||||
redistributing the Work and assume any risks associated with Your exercise of
|
||||
permissions under this License.
|
||||
|
||||
8. Limitation of Liability.
|
||||
|
||||
In no event and under no legal theory, whether in tort (including negligence),
|
||||
contract, or otherwise, unless required by applicable law (such as deliberate
|
||||
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special, incidental,
|
||||
or consequential damages of any character arising as a result of this License or
|
||||
out of the use or inability to use the Work (including but not limited to
|
||||
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
||||
any and all other commercial damages or losses), even if such Contributor has
|
||||
been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability.
|
||||
|
||||
While redistributing the Work or Derivative Works thereof, You may choose to
|
||||
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
||||
other liability obligations and/or rights consistent with this License. However,
|
||||
in accepting such obligations, You may act only on Your own behalf and on Your
|
||||
sole responsibility, not on behalf of any other Contributor, and only if You
|
||||
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason of your
|
||||
accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work
|
||||
|
||||
To apply the Apache License to your work, attach the following boilerplate
|
||||
notice, with the fields enclosed by brackets "{}" replaced with your own
|
||||
identifying information. (Don't include the brackets!) The text should be
|
||||
enclosed in the appropriate comment syntax for the file format. We also
|
||||
recommend that a file or class name and description of purpose be included on
|
||||
the same "printed page" as the copyright notice for easier identification within
|
||||
third-party archives.
|
||||
|
||||
Copyright 2018 xuexiangjys
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -1,5 +0,0 @@
|
||||
Android项目打包
|
||||
1. 修改工程根目录的gradle.properties中的isNeedPackage=true。
|
||||
2. 添加并配置keystore,在versions.gradle中修改app_release相关参数。
|
||||
3. 如果考虑使用友盟统计的话,在local.properties中设置应用的友盟ID:APP_ID_UMENG。
|
||||
4. 使用./gradlew clean assembleReleaseChannels进行多渠道打包。
|
||||
1
android/app/.gitignore
vendored
1
android/app/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/build
|
||||
@@ -1,139 +0,0 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'img-optimizer'
|
||||
//打包时,记得设置true启用
|
||||
if (isNeedPackage.toBoolean() && isUseBooster.toBoolean()) {
|
||||
apply plugin: 'com.didiglobal.booster'
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion build_versions.target_sdk
|
||||
buildToolsVersion build_versions.build_tools
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.kerwin.wumei"
|
||||
minSdkVersion 17
|
||||
targetSdkVersion build_versions.target_sdk
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
multiDexEnabled true
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
arguments = [ moduleName : project.getName() ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
if (isNeedPackage.toBoolean()) {
|
||||
release {
|
||||
storeFile file(app_release.storeFile)
|
||||
storePassword app_release.storePassword
|
||||
keyAlias app_release.keyAlias
|
||||
keyPassword app_release.keyPassword
|
||||
}
|
||||
}
|
||||
|
||||
debug {
|
||||
storeFile file("./debug.jks")
|
||||
storePassword "123456"
|
||||
keyAlias "debug"
|
||||
keyPassword "123456"
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
if (isNeedPackage.toBoolean()) {
|
||||
signingConfig signingConfigs.release
|
||||
|
||||
Properties properties = new Properties()
|
||||
properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||
def appID = properties.getProperty("APP_ID_UMENG")
|
||||
if (appID != null) {
|
||||
buildConfigField "String", "APP_ID_UMENG", appID
|
||||
} else {
|
||||
buildConfigField "String", "APP_ID_UMENG", '""'
|
||||
}
|
||||
} else {
|
||||
signingConfig signingConfigs.debug
|
||||
buildConfigField "String", "APP_ID_UMENG", '""'
|
||||
}
|
||||
}
|
||||
|
||||
debug {
|
||||
debuggable true
|
||||
minifyEnabled false
|
||||
|
||||
signingConfig signingConfigs.debug
|
||||
buildConfigField "String", "APP_ID_UMENG", '""'
|
||||
}
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation project(path: ':esptouch')
|
||||
testImplementation deps.junit
|
||||
androidTestImplementation deps.runner
|
||||
androidTestImplementation deps.espresso.core
|
||||
|
||||
//分包
|
||||
implementation deps.androidx.multidex
|
||||
|
||||
implementation 'com.alibaba.android:vlayout:1.2.36'
|
||||
//下拉刷新
|
||||
implementation 'com.github.xuexiangjys.SmartRefreshLayout:refresh-header:1.1.5'
|
||||
implementation 'com.github.xuexiangjys.SmartRefreshLayout:refresh-layout:1.1.5'
|
||||
//WebView
|
||||
implementation 'com.github.xuexiangjys.AgentWeb:agentweb-core:1.0.0'
|
||||
implementation 'com.github.xuexiangjys.AgentWeb:agentweb-download:1.0.0'//选填
|
||||
//腾讯的键值对存储mmkv
|
||||
implementation 'com.tencent:mmkv:1.0.22'
|
||||
//屏幕适配AutoSize
|
||||
implementation 'me.jessyan:autosize:1.1.2'
|
||||
//umeng统计
|
||||
// implementation 'com.umeng.umsdk:analytics:8.0.2'
|
||||
// implementation 'com.umeng.umsdk:common:2.0.2'
|
||||
implementation group: 'com.umeng.umsdk', name: 'common', version: '9.3.8'
|
||||
|
||||
//预加载占位控件
|
||||
implementation 'me.samlss:broccoli:1.0.0'
|
||||
|
||||
implementation 'com.zzhoujay.richtext:richtext:3.0.8'
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
|
||||
|
||||
//ANR异常捕获
|
||||
implementation 'com.github.anrwatchdog:anrwatchdog:1.4.0'
|
||||
|
||||
//美团多渠道打包
|
||||
implementation 'com.meituan.android.walle:library:1.1.6'
|
||||
|
||||
//rxutil2
|
||||
implementation deps.rxbinding
|
||||
implementation 'com.github.xuexiangjys:rxutil2:1.2.0'
|
||||
|
||||
// circleprogressview 圆形进度动画控件
|
||||
implementation 'com.king.view:circleprogressview:1.1.2'
|
||||
}
|
||||
//自动添加X-Library依赖
|
||||
apply from: 'x-library.gradle'
|
||||
//walle多渠道打包
|
||||
apply from: 'multiple-channel.gradle'
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
# 美团
|
||||
meituan
|
||||
# 三星
|
||||
samsungapps
|
||||
# 小米
|
||||
xiaomi
|
||||
# 91助手
|
||||
91com
|
||||
# 魅族
|
||||
meizu
|
||||
# 豌豆荚
|
||||
wandou
|
||||
# Google Play
|
||||
googleplay
|
||||
# 百度
|
||||
baidu
|
||||
# 360
|
||||
360cn
|
||||
# 应用宝
|
||||
myapp
|
||||
# 华为
|
||||
huawei
|
||||
# 蒲公英
|
||||
pgyer
|
||||
github
|
||||
Binary file not shown.
@@ -1,10 +0,0 @@
|
||||
apply plugin: 'walle'
|
||||
|
||||
walle {
|
||||
// 指定渠道包的输出路径
|
||||
apkOutputFolder = new File("${project.buildDir}/outputs/channels")
|
||||
// 定制渠道包的APK的文件名称
|
||||
apkFileNameFormat = '${appName}-${packageName}-${channel}-${buildType}-v${versionName}-${versionCode}-${buildTime}.apk'
|
||||
// 渠道配置文件
|
||||
channelFile = new File("${project.getProjectDir()}/channel")
|
||||
}
|
||||
276
android/app/proguard-rules.pro
vendored
276
android/app/proguard-rules.pro
vendored
@@ -1,276 +0,0 @@
|
||||
#=========================================基础不变的混淆配置=========================================##
|
||||
#指定代码的压缩级别
|
||||
-optimizationpasses 5
|
||||
#包名不混合大小写
|
||||
-dontusemixedcaseclassnames
|
||||
#不去忽略非公共的库类
|
||||
-dontskipnonpubliclibraryclasses
|
||||
# 指定不去忽略非公共的库的类的成员
|
||||
-dontskipnonpubliclibraryclassmembers
|
||||
#优化 不优化输入的类文件
|
||||
-dontoptimize
|
||||
#预校验
|
||||
-dontpreverify
|
||||
#混淆时是否记录日志
|
||||
-verbose
|
||||
# 混淆时所采用的算法
|
||||
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
|
||||
#保护注解
|
||||
-keepattributes *Annotation*
|
||||
#忽略警告
|
||||
-ignorewarnings
|
||||
|
||||
##记录生成的日志数据,gradle build时在本项目根目录输出##
|
||||
#apk 包内所有 class 的内部结构
|
||||
-dump class_files.txt
|
||||
#未混淆的类和成员
|
||||
-printseeds seeds.txt
|
||||
#列出从 apk 中删除的代码
|
||||
-printusage unused.txt
|
||||
#混淆前后的映射
|
||||
-printmapping mapping.txt
|
||||
# 并保留源文件名为"Proguard"字符串,而非原始的类名 并保留行号
|
||||
-keepattributes SourceFile,LineNumberTable
|
||||
########记录生成的日志数据,gradle build时 在本项目根目录输出-end#####
|
||||
|
||||
#需要保留的东西
|
||||
# 保持哪些类不被混淆
|
||||
-keep public class * extends android.app.Fragment
|
||||
-keep public class * extends android.app.Activity
|
||||
-keep public class * extends android.app.Application
|
||||
-keep public class * extends android.app.Service
|
||||
-keep public class * extends android.content.BroadcastReceiver
|
||||
-keep public class * extends android.content.ContentProvider
|
||||
-keep public class * extends android.app.backup.BackupAgentHelper
|
||||
-keep public class * extends android.preference.Preference
|
||||
-keep public class * extends android.support.v4.**
|
||||
-keep public class com.android.vending.licensing.ILicensingService
|
||||
|
||||
#如果有引用v4包可以添加下面这行
|
||||
-keep public class * extends android.support.v4.app.Fragment
|
||||
|
||||
##########JS接口类不混淆,否则执行不了
|
||||
-dontwarn com.android.JsInterface.**
|
||||
-keep class com.android.JsInterface.** {*; }
|
||||
|
||||
#极光推送和百度lbs android sdk一起使用proguard 混淆的问题#http的类被混淆后,导致apk定位失败,保持apache 的http类不被混淆就好了
|
||||
-dontwarn org.apache.**
|
||||
-keep class org.apache.**{ *; }
|
||||
|
||||
-keep public class * extends android.view.View {
|
||||
public <init>(android.content.Context);
|
||||
public <init>(android.content.Context, android.util.AttributeSet);
|
||||
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||
public void set*(...);
|
||||
}
|
||||
|
||||
#保持 native 方法不被混淆
|
||||
-keepclasseswithmembernames class * {
|
||||
native <methods>;
|
||||
}
|
||||
|
||||
#保持自定义控件类不被混淆
|
||||
-keepclasseswithmembers class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet);
|
||||
}
|
||||
|
||||
#保持自定义控件类不被混淆
|
||||
-keepclassmembers class * extends android.app.Activity {
|
||||
public void *(android.view.View);
|
||||
}
|
||||
|
||||
#保持 Parcelable 不被混淆
|
||||
-keep class * implements android.os.Parcelable {
|
||||
public static final android.os.Parcelable$Creator *;
|
||||
}
|
||||
|
||||
#保持 Serializable 不被混淆
|
||||
-keepnames class * implements java.io.Serializable
|
||||
|
||||
#保持 Serializable 不被混淆并且enum 类也不被混淆
|
||||
-keepclassmembers class * implements java.io.Serializable {
|
||||
static final long serialVersionUID;
|
||||
private static final java.io.ObjectStreamField[] serialPersistentFields;
|
||||
!static !transient <fields>;
|
||||
!private <fields>;
|
||||
!private <methods>;
|
||||
private void writeObject(java.io.ObjectOutputStream);
|
||||
private void readObject(java.io.ObjectInputStream);
|
||||
java.lang.Object writeReplace();
|
||||
java.lang.Object readResolve();
|
||||
}
|
||||
|
||||
#保持枚举 enum 类不被混淆 如果混淆报错,建议直接使用上面的 -keepclassmembers class * implements java.io.Serializable即可
|
||||
-keepclassmembers enum * {
|
||||
public static **[] values();
|
||||
public static ** valueOf(java.lang.String);
|
||||
}
|
||||
|
||||
-keepclassmembers class * {
|
||||
public void *ButtonClicked(android.view.View);
|
||||
}
|
||||
|
||||
#不混淆资源类
|
||||
-keep class **.R$* {*;}
|
||||
|
||||
#===================================混淆保护自己项目的部分代码以及引用的第三方jar包library=============================#######
|
||||
#如果引用了v4或者v7包
|
||||
-dontwarn android.support.**
|
||||
|
||||
|
||||
# AndroidX 防止混淆
|
||||
-dontwarn com.google.android.material.**
|
||||
-dontnote com.google.android.material.**
|
||||
-dontwarn androidx.**
|
||||
-keep class com.google.android.material.** {*;}
|
||||
-keep class androidx.** {*;}
|
||||
-keep public class * extends androidx.**
|
||||
-keep interface androidx.** {*;}
|
||||
-keepclassmembers class * {
|
||||
@androidx.annotation.Keep *;
|
||||
}
|
||||
|
||||
# zxing
|
||||
-dontwarn com.google.zxing.**
|
||||
-keep class com.google.zxing.**{*;}
|
||||
|
||||
#SignalR推送
|
||||
-keep class microsoft.aspnet.signalr.** { *; }
|
||||
|
||||
# 极光推送混淆
|
||||
-dontoptimize
|
||||
-dontpreverify
|
||||
-dontwarn cn.jpush.**
|
||||
-keep class cn.jpush.** { *; }
|
||||
-dontwarn cn.jiguang.**
|
||||
-keep class cn.jiguang.** { *; }
|
||||
|
||||
# 数据库框架OrmLite
|
||||
-keepattributes *DatabaseField*
|
||||
-keepattributes *DatabaseTable*
|
||||
-keepattributes *SerializedName*
|
||||
-keep class com.j256.**
|
||||
-keepclassmembers class com.j256.** { *; }
|
||||
-keep enum com.j256.**
|
||||
-keepclassmembers enum com.j256.** { *; }
|
||||
-keep interface com.j256.**
|
||||
-keepclassmembers interface com.j256.** { *; }
|
||||
|
||||
#XHttp2
|
||||
-keep class com.xuexiang.xhttp2.model.** { *; }
|
||||
-keep class com.xuexiang.xhttp2.cache.model.** { *; }
|
||||
-keep class com.xuexiang.xhttp2.cache.stategy.**{*;}
|
||||
-keep class com.xuexiang.xhttp2.annotation.** { *; }
|
||||
|
||||
#okhttp
|
||||
-dontwarn com.squareup.okhttp3.**
|
||||
-keep class com.squareup.okhttp3.** { *;}
|
||||
-dontwarn okio.**
|
||||
-dontwarn javax.annotation.Nullable
|
||||
-dontwarn javax.annotation.ParametersAreNonnullByDefault
|
||||
-dontwarn javax.annotation.**
|
||||
|
||||
#如果用到Gson解析包的,直接添加下面这几行就能成功混淆,不然会报错
|
||||
-keepattributes Signature
|
||||
-keep class com.google.gson.stream.** { *; }
|
||||
-keepattributes EnclosingMethod
|
||||
-keep class org.xz_sale.entity.**{*;}
|
||||
-keep class com.google.gson.** {*;}
|
||||
-keep class com.google.**{*;}
|
||||
-keep class sun.misc.Unsafe { *; }
|
||||
-keep class com.google.gson.stream.** { *; }
|
||||
-keep class com.google.gson.examples.android.model.** { *; }
|
||||
|
||||
# Glide
|
||||
-keep public class * implements com.bumptech.glide.module.GlideModule
|
||||
-keep public class * extends com.bumptech.glide.module.AppGlideModule
|
||||
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
|
||||
**[] $VALUES;
|
||||
public *;
|
||||
}
|
||||
|
||||
# Retrofit
|
||||
-dontwarn retrofit2.**
|
||||
-keep class retrofit2.** { *; }
|
||||
-keepattributes Exceptions
|
||||
|
||||
# RxJava RxAndroid
|
||||
-dontwarn sun.misc.**
|
||||
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
|
||||
long producerIndex;
|
||||
long consumerIndex;
|
||||
}
|
||||
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
|
||||
rx.internal.util.atomic.LinkedQueueNode producerNode;
|
||||
}
|
||||
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
|
||||
rx.internal.util.atomic.LinkedQueueNode consumerNode;
|
||||
}
|
||||
|
||||
-dontwarn okio.**
|
||||
-dontwarn javax.annotation.Nullable
|
||||
-dontwarn javax.annotation.ParametersAreNonnullByDefault
|
||||
-dontwarn javax.annotation.**
|
||||
|
||||
# fastjson
|
||||
-dontwarn com.alibaba.fastjson.**
|
||||
-keep class com.alibaba.fastjson.** { *; }
|
||||
-keepattributes Signature
|
||||
|
||||
# xpage
|
||||
-keep class com.xuexiang.xpage.annotation.** { *; }
|
||||
-keep class com.xuexiang.xpage.config.** { *; }
|
||||
|
||||
# xaop
|
||||
-keep @com.xuexiang.xaop.annotation.* class * {*;}
|
||||
-keep @org.aspectj.lang.annotation.* class * {*;}
|
||||
-keep class * {
|
||||
@com.xuexiang.xaop.annotation.* <fields>;
|
||||
@org.aspectj.lang.annotation.* <fields>;
|
||||
}
|
||||
-keepclassmembers class * {
|
||||
@com.xuexiang.xaop.annotation.* <methods>;
|
||||
@org.aspectj.lang.annotation.* <methods>;
|
||||
}
|
||||
|
||||
# xrouter
|
||||
-keep public class com.xuexiang.xrouter.routes.**{*;}
|
||||
-keep class * implements com.xuexiang.xrouter.facade.template.ISyringe{*;}
|
||||
# 如果使用了 byType 的方式获取 Service,需添加下面规则,保护接口
|
||||
-keep interface * implements com.xuexiang.xrouter.facade.template.IProvider
|
||||
# 如果使用了 单类注入,即不定义接口实现 IProvider,需添加下面规则,保护实现
|
||||
-keep class * implements com.xuexiang.xrouter.facade.template.IProvider
|
||||
|
||||
# xupdate
|
||||
-keep class com.xuexiang.xupdate.entity.** { *; }
|
||||
|
||||
# xvideo
|
||||
-keep class com.xuexiang.xvideo.jniinterface.** { *; }
|
||||
|
||||
# xipc
|
||||
-keep @com.xuexiang.xipc.annotation.* class * {*;}
|
||||
-keep class * {
|
||||
@com.xuexiang.xipc.annotation.* <fields>;
|
||||
}
|
||||
-keepclassmembers class * {
|
||||
@com.xuexiang.xipc.annotation.* <methods>;
|
||||
}
|
||||
|
||||
# umeng统计
|
||||
-keep class com.umeng.** {*;}
|
||||
-keepclassmembers class * {
|
||||
public <init> (org.json.JSONObject);
|
||||
}
|
||||
-keepclassmembers enum * {
|
||||
public static **[] values();
|
||||
public static ** valueOf(java.lang.String);
|
||||
}
|
||||
|
||||
-keep class com.xuexiang.xui.widget.edittext.materialedittext.** { *; }
|
||||
|
||||
## 接口请求使用了gson序列化的对象
|
||||
-keep class com.kerwin.wumei.entity.** { *; }
|
||||
-keep class com.kerwin.wumei.entity.vo.** { *; }
|
||||
-keep class com.kerwin.wumei.entity.bo.** { *; }
|
||||
-keep class com.kerwin.wumei.http.request.** { *; }
|
||||
-keep class com.kerwin.wumei.http.** { *; }
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
|
||||
assertEquals("com.kerwin.wumei", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.kerwin.wumei">
|
||||
|
||||
<!--进程杀死-->
|
||||
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
|
||||
<application
|
||||
android:name="com.kerwin.wumei.MyApp"
|
||||
android:allowBackup="false"
|
||||
android:configChanges="screenSize|keyboardHidden|orientation|keyboard"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:windowSoftInputMode="adjustPan|stateHidden"
|
||||
tools:ignore="LockedOrientationActivity"
|
||||
tools:targetApi="n">
|
||||
|
||||
<activity
|
||||
android:name="com.kerwin.wumei.activity.SplashActivity"
|
||||
android:configChanges="screenSize|keyboardHidden|orientation|keyboard"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/AppTheme.Launch.App"
|
||||
android:windowSoftInputMode="adjustPan|stateHidden">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.kerwin.wumei.activity.MainActivity"
|
||||
android:configChanges="screenSize|keyboardHidden|orientation|keyboard"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/AppTheme"
|
||||
android:windowSoftInputMode="adjustPan|stateHidden" />
|
||||
<activity
|
||||
android:name="com.kerwin.wumei.activity.LoginActivity"
|
||||
android:configChanges="screenSize|keyboardHidden|orientation|keyboard"
|
||||
android:launchMode="singleInstance"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="adjustPan|stateHidden" />
|
||||
<activity
|
||||
android:name="com.kerwin.wumei.activity.AddDeviceActivity"
|
||||
android:configChanges="screenSize|keyboardHidden|orientation|keyboard"
|
||||
android:screenOrientation="portrait"
|
||||
android:launchMode="singleInstance"
|
||||
android:theme="@style/AppTheme"
|
||||
android:windowSoftInputMode="adjustPan|stateHidden" />
|
||||
|
||||
<!--通用浏览器-->
|
||||
<activity
|
||||
android:name="com.kerwin.wumei.core.webview.AgentWebActivity"
|
||||
android:configChanges="screenSize|keyboardHidden|orientation|keyboard"
|
||||
android:hardwareAccelerated="true"
|
||||
android:label="@string/app_browser_name"
|
||||
android:theme="@style/AppTheme">
|
||||
<!-- Scheme -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<action android:name="com.xuexiang.xui.applink" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
|
||||
<data android:scheme="http" />
|
||||
<data android:scheme="https" />
|
||||
<data android:scheme="about" />
|
||||
<data android:scheme="javascript" />
|
||||
<!-- 设置自己的deeplink -->
|
||||
<!-- <data-->
|
||||
<!-- android:host="xxx.com"-->
|
||||
<!-- android:scheme="xui"/>-->
|
||||
</intent-filter>
|
||||
<!-- AppLink -->
|
||||
<intent-filter
|
||||
android:autoVerify="true"
|
||||
tools:targetApi="m">
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<data android:scheme="http" />
|
||||
<data android:scheme="https" />
|
||||
<data android:scheme="inline" />
|
||||
<data android:mimeType="text/html" />
|
||||
<data android:mimeType="text/plain" />
|
||||
<data android:mimeType="application/xhtml+xml" />
|
||||
<data android:mimeType="application/vnd.wap.xhtml+xml" />
|
||||
<!-- 设置自己的applink -->
|
||||
<!-- <data-->
|
||||
<!-- android:host="xxx.com"-->
|
||||
<!-- android:scheme="http"/>-->
|
||||
<!-- <data-->
|
||||
<!-- android:host="xxx.com"-->
|
||||
<!-- android:scheme="https"/>-->
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!--fragment的页面容器-->
|
||||
<activity
|
||||
android:name="com.kerwin.wumei.core.BaseActivity"
|
||||
android:configChanges="screenSize|keyboardHidden|orientation|keyboard"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="adjustPan|stateHidden" />
|
||||
<!-- 版本更新提示-->
|
||||
<activity
|
||||
android:name="com.kerwin.wumei.utils.update.UpdateTipDialog"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/DialogTheme" />
|
||||
<!-- Webview拦截提示弹窗-->
|
||||
<activity
|
||||
android:name="com.kerwin.wumei.core.webview.WebViewInterceptDialog"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/DialogTheme" />
|
||||
<!-- applink的中转页面 -->
|
||||
<activity
|
||||
android:name="com.kerwin.wumei.core.XPageTransferActivity"
|
||||
android:configChanges="screenSize|keyboardHidden|orientation|keyboard"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="adjustPan|stateHidden" />
|
||||
|
||||
<!--屏幕自适应设计图-->
|
||||
<meta-data
|
||||
android:name="design_width_in_dp"
|
||||
android:value="360" />
|
||||
<meta-data
|
||||
android:name="design_height_in_dp"
|
||||
android:value="640" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"Code": 0,
|
||||
"Data": [
|
||||
{
|
||||
"title": "微信公众号",
|
||||
"content": "<a href=\"http://www.wumei.live\">获取更多资讯内容,欢迎微信搜索公众号:「我的Android开源之旅」</a>"
|
||||
},
|
||||
{
|
||||
"title": "关于作者",
|
||||
"content": "点击关注作者,了解最新动态!<br /><a href=\"https://gitee.com/kerwincui/wumei-smart\"><font color=\"#800080\">Gitee</font></a><br />"
|
||||
},
|
||||
{
|
||||
"title": "QQ交流群",
|
||||
"content": "<a href=\"https://qm.qq.com/cgi-bin/qm/qr?k=P_oc91N6KC39zp2PEV_-BY3xMnAokeZ8\">物美智能交流群</a><br />"
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 31 KiB |
@@ -1,115 +0,0 @@
|
||||
package com.kerwin.wumei;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.location.LocationManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.multidex.MultiDex;
|
||||
|
||||
import com.kerwin.wumei.utils.sdkinit.ANRWatchDogInit;
|
||||
import com.kerwin.wumei.utils.sdkinit.UMengInit;
|
||||
import com.kerwin.wumei.utils.sdkinit.XBasicLibInit;
|
||||
import com.kerwin.wumei.utils.sdkinit.XUpdateInit;
|
||||
|
||||
/**
|
||||
* @author xuexiang
|
||||
* @since 2018/11/7 下午1:12
|
||||
*/
|
||||
public class MyApp extends Application {
|
||||
|
||||
private static MyApp app;
|
||||
private MutableLiveData<String> mBroadcastData;
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case WifiManager.NETWORK_STATE_CHANGED_ACTION:
|
||||
case LocationManager.PROVIDERS_CHANGED_ACTION:
|
||||
mBroadcastData.setValue(action);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(base);
|
||||
//解决4.x运行崩溃的问题
|
||||
MultiDex.install(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
initLibs();
|
||||
app = this;
|
||||
mBroadcastData = new MutableLiveData<>();
|
||||
IntentFilter filter = new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
filter.addAction(LocationManager.PROVIDERS_CHANGED_ACTION);
|
||||
}
|
||||
registerReceiver(mReceiver, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTerminate() {
|
||||
super.onTerminate();
|
||||
unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
public static MyApp getInstance() {
|
||||
return app;
|
||||
}
|
||||
|
||||
public void observeBroadcast(LifecycleOwner owner, Observer<String> observer) {
|
||||
mBroadcastData.observe(owner, observer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化基础库
|
||||
*/
|
||||
private void initLibs() {
|
||||
XBasicLibInit.init(this);
|
||||
|
||||
XUpdateInit.init(this);
|
||||
|
||||
//运营统计数据运行时不初始化
|
||||
if (!MyApp.isDebug()) {
|
||||
UMengInit.init(this);
|
||||
}
|
||||
|
||||
//ANR监控
|
||||
ANRWatchDogInit.init();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return 当前app是否是调试开发模式
|
||||
*/
|
||||
public static boolean isDebug() {
|
||||
return BuildConfig.DEBUG;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,384 +0,0 @@
|
||||
|
||||
package com.kerwin.wumei.activity;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.LocationManager;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.location.LocationManagerCompat;
|
||||
|
||||
import com.espressif.iot.esptouch.EsptouchTask;
|
||||
import com.espressif.iot.esptouch.IEsptouchResult;
|
||||
import com.espressif.iot.esptouch.IEsptouchTask;
|
||||
import com.espressif.iot.esptouch.util.ByteUtil;
|
||||
import com.espressif.iot.esptouch.util.TouchNetUtil;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.adapter.entity.EspTouchViewModel;
|
||||
import com.kerwin.wumei.core.BaseActivity;
|
||||
import com.kerwin.wumei.fragment.device.AddDeviceFragment;
|
||||
import com.kerwin.wumei.utils.NetUtils;
|
||||
import com.xuexiang.xui.utils.KeyboardUtils;
|
||||
import com.xuexiang.xui.utils.StatusBarUtils;
|
||||
import com.xuexiang.xutil.display.Colors;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class AddDeviceActivity extends BaseActivity {
|
||||
|
||||
// begin esptouch -------------------------------------
|
||||
private static final String TAG = AddDeviceActivity.class.getSimpleName();
|
||||
private static final int REQUEST_PERMISSION = 0x01;
|
||||
private EspTouchViewModel mViewModel;
|
||||
private EsptouchAsyncTask4 mTask;
|
||||
private WifiManager mWifiManager;
|
||||
private List<String> ssids;
|
||||
private String selectedSSID;
|
||||
|
||||
public String GetSelectedSSID(){
|
||||
return selectedSSID;
|
||||
}
|
||||
public List<String> GetSsids(){
|
||||
return ssids;
|
||||
}
|
||||
public EspTouchViewModel GetMViewModel(){
|
||||
return mViewModel;
|
||||
}
|
||||
|
||||
private AddDeviceFragment addDeviceFragment;
|
||||
private IEsptouchTask mEsptouchTask;
|
||||
|
||||
|
||||
public void executeEsptouch() {
|
||||
EspTouchViewModel viewModel = mViewModel;
|
||||
// byte[] ssid = viewModel.ssidBytes == null ? ByteUtil.getBytesByString(viewModel.ssid): viewModel.ssidBytes;
|
||||
CharSequence ssidStr=mViewModel.ssidSpinner.getText();
|
||||
byte[] ssid= ByteUtil.getBytesByString(ssidStr.toString());
|
||||
CharSequence pwdStr = mViewModel.apPasswordEdit.getText();
|
||||
byte[] password = pwdStr == null ? null : ByteUtil.getBytesByString(pwdStr.toString());
|
||||
byte[] bssid = TouchNetUtil.parseBssid2bytes(viewModel.bssid);
|
||||
byte[] broadcast = {(byte) (mViewModel.packageModeGroup.getCheckedRadioButtonId() == R.id.packageBroadcast? 1 : 0)};
|
||||
int count = mViewModel.xsbDeviceCount.getSelectedNumber();
|
||||
byte[] deviceCount = String.valueOf(count).getBytes();
|
||||
if (mTask != null) {
|
||||
mTask.cancelEsptouch();
|
||||
}
|
||||
mTask = new EsptouchAsyncTask4(this);
|
||||
mTask.execute(ssid, bssid, password, deviceCount, broadcast);
|
||||
}
|
||||
|
||||
public void onWifiChanged() {
|
||||
StateResult stateResult = check();
|
||||
mViewModel.message = stateResult.message;
|
||||
mViewModel.ssid = stateResult.ssid;
|
||||
mViewModel.ssidBytes = stateResult.ssidBytes;
|
||||
mViewModel.bssid = stateResult.bssid;
|
||||
mViewModel.confirmEnable = false;
|
||||
if (stateResult.wifiConnected) {
|
||||
mViewModel.confirmEnable = true;
|
||||
if (stateResult.is5G) {
|
||||
mViewModel.message = getString(R.string.esptouch1_wifi_5g_message);
|
||||
}
|
||||
} else {
|
||||
if (mTask != null) {
|
||||
mTask.cancelEsptouch();
|
||||
mTask = null;
|
||||
new AlertDialog.Builder(AddDeviceActivity.this)
|
||||
.setMessage(R.string.esptouch1_configure_wifi_change_message)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
mViewModel.invalidateAll();
|
||||
}
|
||||
|
||||
protected static class StateResult {
|
||||
public CharSequence message = null;
|
||||
public boolean permissionGranted = false;
|
||||
public boolean locationRequirement = false;
|
||||
public boolean wifiConnected = false;
|
||||
public boolean is5G = false;
|
||||
public InetAddress address = null;
|
||||
public String ssid = null;
|
||||
public byte[] ssidBytes = null;
|
||||
public String bssid = null;
|
||||
}
|
||||
|
||||
private StateResult check() {
|
||||
StateResult result = checkPermission();
|
||||
if (!result.permissionGranted) {
|
||||
return result;
|
||||
}
|
||||
result = checkLocation();
|
||||
result.permissionGranted = true;
|
||||
if (result.locationRequirement) {
|
||||
return result;
|
||||
}
|
||||
result = checkWifi();
|
||||
result.permissionGranted = true;
|
||||
result.locationRequirement = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
protected StateResult checkWifi() {
|
||||
StateResult result = new StateResult();
|
||||
result.wifiConnected = false;
|
||||
WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
|
||||
|
||||
// 获取wifi列表
|
||||
mWifiManager.startScan();
|
||||
List<ScanResult> scanWifiList = mWifiManager.getScanResults();
|
||||
List<ScanResult> wifiList = new ArrayList<>();
|
||||
ssids=new ArrayList<>();
|
||||
if (scanWifiList != null && scanWifiList.size() > 0) {
|
||||
HashMap<String, Integer> signalStrength = new HashMap<String, Integer>();
|
||||
for (int i = 0; i < scanWifiList.size(); i++) {
|
||||
ScanResult scanResult = scanWifiList.get(i);
|
||||
Log.e(TAG, "搜索的wifi-ssid:" + scanResult.SSID);
|
||||
if (!scanResult.SSID.isEmpty()) {
|
||||
String key = scanResult.SSID + " " + scanResult.capabilities;
|
||||
if (!signalStrength.containsKey(key)) {
|
||||
signalStrength.put(key, i);
|
||||
wifiList.add(scanResult);
|
||||
ssids.add(scanResult.SSID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean connected = NetUtils.isWifiConnected(mWifiManager);
|
||||
if (!connected) {
|
||||
result.message = getString(R.string.esptouch_message_wifi_connection);
|
||||
return result;
|
||||
}
|
||||
|
||||
String ssid = NetUtils.getSsidString(wifiInfo);
|
||||
selectedSSID=ssid;
|
||||
int ipValue = wifiInfo.getIpAddress();
|
||||
if (ipValue != 0) {
|
||||
result.address = NetUtils.getAddress(wifiInfo.getIpAddress());
|
||||
} else {
|
||||
result.address = NetUtils.getIPv4Address();
|
||||
if (result.address == null) {
|
||||
result.address = NetUtils.getIPv6Address();
|
||||
}
|
||||
}
|
||||
|
||||
result.wifiConnected = true;
|
||||
result.message = "";
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
result.is5G = NetUtils.is5G(wifiInfo.getFrequency());
|
||||
}
|
||||
if (result.is5G) {
|
||||
result.message = getString(R.string.esptouch_message_wifi_frequency);
|
||||
}
|
||||
result.ssid = ssid;
|
||||
result.ssidBytes = NetUtils.getRawSsidBytesOrElse(wifiInfo, ssid.getBytes());
|
||||
result.bssid = wifiInfo.getBSSID();
|
||||
return result;
|
||||
}
|
||||
|
||||
protected StateResult checkLocation() {
|
||||
StateResult result = new StateResult();
|
||||
result.locationRequirement = true;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
LocationManager manager = getSystemService(LocationManager.class);
|
||||
boolean enable = manager != null && LocationManagerCompat.isLocationEnabled(manager);
|
||||
if (!enable) {
|
||||
result.message = getString(R.string.esptouch_message_location);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
result.locationRequirement = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
protected StateResult checkPermission() {
|
||||
StateResult result = new StateResult();
|
||||
result.permissionGranted = false;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
boolean locationGranted = checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
== PackageManager.PERMISSION_GRANTED;
|
||||
if (!locationGranted) {
|
||||
String[] splits = getString(R.string.esptouch_message_permission).split("\n");
|
||||
if (splits.length != 2) {
|
||||
throw new IllegalArgumentException("Invalid String @RES esptouch_message_permission");
|
||||
}
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(splits[0]);
|
||||
ssb.append('\n');
|
||||
SpannableString clickMsg = new SpannableString(splits[1]);
|
||||
ForegroundColorSpan clickSpan = new ForegroundColorSpan(0xFF0022FF);
|
||||
clickMsg.setSpan(clickSpan, 0, clickMsg.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
ssb.append(clickMsg);
|
||||
result.message = ssb;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
result.permissionGranted = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
if (requestCode == REQUEST_PERMISSION) {
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
onWifiChanged();
|
||||
} else {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.esptouch1_location_permission_title)
|
||||
.setMessage(R.string.esptouch1_location_permission_message)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> finish())
|
||||
.show();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
/**
|
||||
* 中断配网任务
|
||||
*/
|
||||
public void interruptEspTouchTask(){
|
||||
if (mEsptouchTask != null) {
|
||||
mEsptouchTask.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public class EsptouchAsyncTask4 extends AsyncTask<byte[], IEsptouchResult, List<IEsptouchResult>> {
|
||||
private WeakReference<AddDeviceActivity> mActivity;
|
||||
private final Object mLock = new Object();
|
||||
|
||||
|
||||
EsptouchAsyncTask4(AddDeviceActivity activity) {
|
||||
mActivity = new WeakReference<>(activity);
|
||||
}
|
||||
|
||||
public void cancelEsptouch() {
|
||||
cancel(true);
|
||||
if (mEsptouchTask != null) {
|
||||
mEsptouchTask.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
addDeviceFragment = (AddDeviceFragment) getSupportFragmentManager().getFragments().get(0);
|
||||
addDeviceFragment.beginCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(IEsptouchResult... values) {
|
||||
Context context = mActivity.get();
|
||||
if (context != null) {
|
||||
IEsptouchResult result = values[0];
|
||||
Log.i(TAG, "EspTouchResult: " + result);
|
||||
String text = result.getBssid() + " is connected to the wifi";
|
||||
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<IEsptouchResult> doInBackground(byte[]... params) {
|
||||
AddDeviceActivity activity = mActivity.get();
|
||||
int taskResultCount;
|
||||
synchronized (mLock) {
|
||||
byte[] apSsid = params[0];
|
||||
byte[] apBssid = params[1];
|
||||
byte[] apPassword = params[2];
|
||||
byte[] deviceCountData = params[3];
|
||||
byte[] broadcastData = params[4];
|
||||
taskResultCount = deviceCountData.length == 0 ? -1 : Integer.parseInt(new String(deviceCountData));
|
||||
Context context = activity.getApplicationContext();
|
||||
mEsptouchTask = new EsptouchTask(apSsid, apBssid, apPassword, context);
|
||||
mEsptouchTask.setPackageBroadcast(broadcastData[0] == 1);
|
||||
mEsptouchTask.setEsptouchListener(this::publishProgress);
|
||||
}
|
||||
return mEsptouchTask.executeForResults(taskResultCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<IEsptouchResult> result) {
|
||||
AddDeviceActivity activity = mActivity.get();
|
||||
activity.mTask = null;
|
||||
if (result == null) {
|
||||
addDeviceFragment.showMessage("建立 EspTouch 任务失败, 端口可能被其他程序占用",false);
|
||||
addDeviceFragment.cancleCounter();
|
||||
return;
|
||||
}
|
||||
|
||||
// check whether the task is cancelled and no results received
|
||||
IEsptouchResult firstResult = result.get(0);
|
||||
if (firstResult.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!firstResult.isSuc()) {
|
||||
addDeviceFragment.showMessage("配网失败",false);
|
||||
addDeviceFragment.cancleCounter();
|
||||
return;
|
||||
}
|
||||
|
||||
String message="";
|
||||
for (IEsptouchResult touchResult : result) {
|
||||
message += "BSSID: "+touchResult.getBssid()+"\n 地址: "+touchResult.getInetAddress().getHostAddress()+"\n";
|
||||
}
|
||||
|
||||
addDeviceFragment.completeCounter();
|
||||
addDeviceFragment.showMessage("完成配网\n"+message,true);
|
||||
}
|
||||
}
|
||||
|
||||
// end esptouch ----------------------------------------
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mWifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||
mViewModel = new EspTouchViewModel();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSupportSlideBack() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initStatusBarStyle() {
|
||||
StatusBarUtils.initStatusBarStyle(this, false, Colors.WHITE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
return KeyboardUtils.onDisableBackKeyDown(keyCode) && super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
|
||||
package com.kerwin.wumei.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.kerwin.wumei.core.BaseActivity;
|
||||
import com.kerwin.wumei.fragment.LoginFragment;
|
||||
import com.kerwin.wumei.fragment.device.DeviceDetailFragment;
|
||||
import com.xuexiang.xui.utils.KeyboardUtils;
|
||||
import com.xuexiang.xui.utils.StatusBarUtils;
|
||||
import com.xuexiang.xutil.display.Colors;
|
||||
|
||||
|
||||
public class LoginActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
openPage(LoginFragment.class, getIntent().getExtras());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSupportSlideBack() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initStatusBarStyle() {
|
||||
StatusBarUtils.initStatusBarStyle(this, false, Colors.WHITE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
return KeyboardUtils.onDisableBackKeyDown(keyCode) && super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
||||
@@ -1,380 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.activity;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.LocationManager;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.location.LocationManagerCompat;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.kerwin.wumei.entity.User;
|
||||
import com.kerwin.wumei.fragment.profile.AccountFragment;
|
||||
import com.kerwin.wumei.http.callback.TipRequestCallBack;
|
||||
import com.kerwin.wumei.http.request.UserInfoApiResult;
|
||||
import com.kerwin.wumei.utils.sdkinit.XUpdateInit;
|
||||
|
||||
import com.espressif.iot.esptouch.EsptouchTask;
|
||||
import com.espressif.iot.esptouch.IEsptouchResult;
|
||||
import com.espressif.iot.esptouch.IEsptouchTask;
|
||||
import com.espressif.iot.esptouch.util.ByteUtil;
|
||||
import com.espressif.iot.esptouch.util.TouchNetUtil;
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.adapter.entity.EspTouchViewModel;
|
||||
import com.kerwin.wumei.core.BaseActivity;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.fragment.AboutFragment;
|
||||
import com.kerwin.wumei.fragment.FeedbackFragment;
|
||||
import com.kerwin.wumei.fragment.MessageFragment;
|
||||
import com.kerwin.wumei.fragment.SettingsFragment;
|
||||
import com.kerwin.wumei.fragment.device.AddDeviceFragment;
|
||||
import com.kerwin.wumei.fragment.device.GroupFragment;
|
||||
import com.kerwin.wumei.fragment.device.SceneFragment;
|
||||
import com.kerwin.wumei.fragment.device.ShareDeviceFragment;
|
||||
import com.kerwin.wumei.fragment.news.HomePageFragment;
|
||||
import com.kerwin.wumei.fragment.news.NewsFragment;
|
||||
import com.kerwin.wumei.fragment.profile.ProfileFragment;
|
||||
import com.kerwin.wumei.fragment.device.DeviceFragment;
|
||||
import com.kerwin.wumei.utils.NetUtils;
|
||||
import com.kerwin.wumei.utils.Utils;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.kerwin.wumei.widget.GuideTipsDialog;
|
||||
import com.xuexiang.xaop.annotation.SingleClick;
|
||||
import com.xuexiang.xhttp2.XHttp;
|
||||
import com.xuexiang.xhttp2.callback.CallBackProxy;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xpage.core.PageOption;
|
||||
import com.xuexiang.xpage.enums.CoreAnim;
|
||||
import com.xuexiang.xui.adapter.FragmentAdapter;
|
||||
import com.xuexiang.xui.adapter.simple.AdapterItem;
|
||||
import com.xuexiang.xui.utils.ResUtils;
|
||||
import com.xuexiang.xui.utils.ThemeUtils;
|
||||
import com.xuexiang.xui.widget.imageview.RadiusImageView;
|
||||
import com.xuexiang.xui.widget.popupwindow.popup.XUISimplePopup;
|
||||
import com.xuexiang.xutil.XUtil;
|
||||
import com.xuexiang.xutil.common.ClickUtils;
|
||||
import com.xuexiang.xutil.common.CollectionUtils;
|
||||
import com.xuexiang.xutil.display.Colors;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
import static com.kerwin.wumei.utils.SettingUtils.getServerPath;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.clearToken;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.getToken;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.hasToken;
|
||||
|
||||
public class MainActivity extends BaseActivity implements View.OnClickListener, ViewPager.OnPageChangeListener, BottomNavigationView.OnNavigationItemSelectedListener, ClickUtils.OnClick2ExitListener, Toolbar.OnMenuItemClickListener {
|
||||
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
@BindView(R.id.view_pager)
|
||||
ViewPager viewPager;
|
||||
/**
|
||||
* 底部导航栏
|
||||
*/
|
||||
@BindView(R.id.bottom_navigation)
|
||||
BottomNavigationView bottomNavigation;
|
||||
/**
|
||||
* 侧边栏
|
||||
*/
|
||||
@BindView(R.id.nav_view)
|
||||
NavigationView navView;
|
||||
@BindView(R.id.drawer_layout)
|
||||
DrawerLayout drawerLayout;
|
||||
|
||||
private String[] mTitles;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_main;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
initViews();
|
||||
// initData();
|
||||
initListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSupportSlideBack() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
mTitles = ResUtils.getStringArray(R.array.home_titles);
|
||||
toolbar.setTitle(mTitles[0]);
|
||||
toolbar.inflateMenu(R.menu.menu_main);
|
||||
toolbar.setOnMenuItemClickListener(this);
|
||||
initHeader();
|
||||
|
||||
//主页内容填充
|
||||
BaseFragment[] fragments = new BaseFragment[]{
|
||||
new DeviceFragment(),
|
||||
new SceneFragment(),
|
||||
new HomePageFragment(),
|
||||
new ProfileFragment(),
|
||||
};
|
||||
FragmentAdapter<BaseFragment> adapter = new FragmentAdapter<>(getSupportFragmentManager(), fragments);
|
||||
viewPager.setOffscreenPageLimit(mTitles.length - 1);
|
||||
viewPager.setAdapter(adapter);
|
||||
|
||||
//显示提示
|
||||
// GuideTipsDialog.showTips(this);
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
GuideTipsDialog.showTips(this);
|
||||
XUpdateInit.checkUpdate(this, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 侧边栏头部
|
||||
*/
|
||||
private void initHeader() {
|
||||
navView.setItemIconTintList(null);
|
||||
View headerView = navView.getHeaderView(0);
|
||||
LinearLayout navHeader = headerView.findViewById(R.id.nav_header);
|
||||
RadiusImageView ivAvatar = headerView.findViewById(R.id.iv_avatar);
|
||||
TextView tvAvatar = headerView.findViewById(R.id.tv_avatar);
|
||||
TextView tvSign = headerView.findViewById(R.id.tv_sign);
|
||||
|
||||
if (Utils.isColorDark(ThemeUtils.resolveColor(this, R.attr.colorAccent))) {
|
||||
tvAvatar.setTextColor(Colors.WHITE);
|
||||
tvSign.setTextColor(Colors.WHITE);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
ivAvatar.setImageTintList(ResUtils.getColors(R.color.xui_config_color_white));
|
||||
}
|
||||
} else {
|
||||
tvAvatar.setTextColor(ThemeUtils.resolveColor(this, R.attr.xui_config_color_title_text));
|
||||
tvSign.setTextColor(ThemeUtils.resolveColor(this, R.attr.xui_config_color_explain_text));
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
ivAvatar.setImageTintList(ResUtils.getColors(R.color.xui_config_color_gray_3));
|
||||
}
|
||||
}
|
||||
|
||||
// 绑定数据
|
||||
ivAvatar.setImageResource(R.drawable.ic_default_head);
|
||||
tvAvatar.setText("匿名用户");
|
||||
tvSign.setText("物美智能点亮智慧生活...");
|
||||
getUserInfo(tvAvatar,tvSign );
|
||||
navHeader.setOnClickListener(this);
|
||||
}
|
||||
|
||||
protected void initListeners() {
|
||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||
drawerLayout.addDrawerListener(toggle);
|
||||
toggle.syncState();
|
||||
|
||||
//侧边栏点击事件
|
||||
navView.setNavigationItemSelectedListener(menuItem -> {
|
||||
|
||||
switch (menuItem.getItemId()) {
|
||||
case R.id.nav_add_device:
|
||||
PageOption.to(AddDeviceFragment.class) //跳转的fragment
|
||||
.setAnim(CoreAnim.slide) //页面转场动画
|
||||
.setRequestCode(100) //请求码,用于返回结果
|
||||
.setAddToBackStack(true) //是否加入堆栈
|
||||
.setNewActivity(true, AddDeviceActivity.class) //是否使用新的Activity打开
|
||||
.open(this); //打开页面进行跳转
|
||||
break;
|
||||
case R.id.nav_about:
|
||||
openNewPage(AboutFragment.class);
|
||||
break;
|
||||
case R.id.nav_serve_config:
|
||||
drawerLayout.closeDrawers();
|
||||
toolbar.setTitle(menuItem.getTitle());
|
||||
viewPager.setCurrentItem(1, false);
|
||||
break;
|
||||
case R.id.nav_message:
|
||||
openNewPage(MessageFragment.class);
|
||||
break;
|
||||
default:
|
||||
XToastUtils.toast("点击了:" + menuItem.getTitle());
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
//主页事件监听
|
||||
viewPager.addOnPageChangeListener(this);
|
||||
bottomNavigation.setOnNavigationItemSelectedListener(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.add_device:
|
||||
PageOption.to(AddDeviceFragment.class) //跳转的fragment
|
||||
.setAnim(CoreAnim.slide) //页面转场动画
|
||||
.setRequestCode(100) //请求码,用于返回结果
|
||||
.setAddToBackStack(true) //是否加入堆栈
|
||||
.setNewActivity(true, AddDeviceActivity.class) //是否使用新的Activity打开
|
||||
.open(this); //打开页面进行跳转
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SingleClick
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.nav_header:
|
||||
openNewPage(AccountFragment.class);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//=============ViewPager===================//
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int i, float v, int i1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
MenuItem item = bottomNavigation.getMenu().getItem(position);
|
||||
toolbar.setTitle(item.getTitle());
|
||||
item.setChecked(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int i) {
|
||||
|
||||
}
|
||||
|
||||
//================Navigation================//
|
||||
|
||||
/**
|
||||
* 底部导航栏点击事件
|
||||
*
|
||||
* @param menuItem
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
||||
int index = CollectionUtils.arrayIndexOf(mTitles, menuItem.getTitle());
|
||||
if (index != -1) {
|
||||
toolbar.setTitle(menuItem.getTitle());
|
||||
viewPager.setCurrentItem(index, false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 菜单、返回键响应
|
||||
*/
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
ClickUtils.exitBy2Click(2000, this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetry() {
|
||||
XToastUtils.toast("再按一次退出程序");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit() {
|
||||
XUtil.exitApp();
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP获取用户信息
|
||||
*/
|
||||
private void getUserInfo(TextView avatar,TextView sign){
|
||||
if(!hasToken()) return;
|
||||
XHttp.get(getServerPath()+"/getInfo")
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new CallBackProxy<UserInfoApiResult<User>, User>(new TipRequestCallBack<User>() {
|
||||
@Override
|
||||
public void onSuccess(User user) throws Throwable {
|
||||
Log.d("user:",user.getNickName());
|
||||
if(user.getNickName()!=null && user.getNickName().length()!=0)
|
||||
{
|
||||
avatar.setText(user.getNickName());
|
||||
}else{
|
||||
avatar.setText(user.getUserName());
|
||||
}
|
||||
sign.setText("物美智能开源项目(wumei-smart)");
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package com.kerwin.wumei.activity;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.utils.SettingUtils;
|
||||
import com.kerwin.wumei.utils.TokenUtils;
|
||||
import com.kerwin.wumei.utils.Utils;
|
||||
import com.xuexiang.xui.utils.KeyboardUtils;
|
||||
import com.xuexiang.xui.widget.activity.BaseSplashActivity;
|
||||
import com.xuexiang.xutil.app.ActivityUtils;
|
||||
|
||||
import me.jessyan.autosize.internal.CancelAdapt;
|
||||
|
||||
/**
|
||||
* 启动页【无需适配屏幕大小】
|
||||
*
|
||||
*/
|
||||
public class SplashActivity extends BaseSplashActivity implements CancelAdapt {
|
||||
|
||||
@Override
|
||||
protected long getSplashDurationMillis() {
|
||||
return 500;
|
||||
}
|
||||
|
||||
/**
|
||||
* activity启动后的初始化
|
||||
*/
|
||||
@Override
|
||||
protected void onCreateActivity() {
|
||||
initSplashView(R.drawable.xui_config_bg_splash);
|
||||
startSplash(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 启动页结束后的动作
|
||||
*/
|
||||
@Override
|
||||
protected void onSplashFinished() {
|
||||
loginOrGoMainPage();
|
||||
// if (SettingUtils.isAgreePrivacy()) {
|
||||
// loginOrGoMainPage();
|
||||
// } else {
|
||||
// Utils.showPrivacyDialog(this, (dialog, which) -> {
|
||||
// dialog.dismiss();
|
||||
// SettingUtils.setIsAgreePrivacy(true);
|
||||
// loginOrGoMainPage();
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
||||
private void loginOrGoMainPage() {
|
||||
if (TokenUtils.hasToken()) {
|
||||
ActivityUtils.startActivity(MainActivity.class);
|
||||
} else {
|
||||
ActivityUtils.startActivity(LoginActivity.class);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单、返回键响应
|
||||
*/
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
return KeyboardUtils.onDisableBackKeyDown(keyCode) && super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.adapter.base.broccoli;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.xuexiang.xui.adapter.recyclerview.BaseRecyclerAdapter;
|
||||
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;
|
||||
import com.xuexiang.xui.adapter.recyclerview.XRecyclerAdapter;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import me.samlss.broccoli.Broccoli;
|
||||
|
||||
/**
|
||||
* 使用Broccoli占位的基础适配器
|
||||
*
|
||||
* @author XUE
|
||||
* @since 2019/4/8 16:33
|
||||
*/
|
||||
public abstract class BroccoliRecyclerAdapter<T> extends BaseRecyclerAdapter<T> {
|
||||
/**
|
||||
* 是否已经加载成功
|
||||
*/
|
||||
private boolean mHasLoad = false;
|
||||
private Map<View, Broccoli> mBroccoliMap = new HashMap<>();
|
||||
|
||||
public BroccoliRecyclerAdapter(Collection<T> collection) {
|
||||
super(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindData(@NonNull RecyclerViewHolder holder, int position, T item) {
|
||||
Broccoli broccoli = mBroccoliMap.get(holder.itemView);
|
||||
if (broccoli == null) {
|
||||
broccoli = new Broccoli();
|
||||
mBroccoliMap.put(holder.itemView, broccoli);
|
||||
}
|
||||
if (mHasLoad) {
|
||||
broccoli.removeAllPlaceholders();
|
||||
|
||||
onBindData(holder, item, position);
|
||||
} else {
|
||||
onBindBroccoli(holder, broccoli);
|
||||
broccoli.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定控件
|
||||
*
|
||||
* @param holder
|
||||
* @param model
|
||||
* @param position
|
||||
*/
|
||||
protected abstract void onBindData(RecyclerViewHolder holder, T model, int position);
|
||||
|
||||
/**
|
||||
* 绑定占位控件
|
||||
*
|
||||
* @param broccoli
|
||||
*/
|
||||
protected abstract void onBindBroccoli(RecyclerViewHolder holder, Broccoli broccoli);
|
||||
|
||||
@Override
|
||||
public XRecyclerAdapter refresh(Collection<T> collection) {
|
||||
mHasLoad = true;
|
||||
return super.refresh(collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* 资源释放,防止内存泄漏
|
||||
*/
|
||||
public void recycle() {
|
||||
for (Broccoli broccoli : mBroccoliMap.values()) {
|
||||
broccoli.removeAllPlaceholders();
|
||||
}
|
||||
mBroccoliMap.clear();
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.adapter.base.broccoli;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.alibaba.android.vlayout.LayoutHelper;
|
||||
import com.kerwin.wumei.adapter.base.delegate.SimpleDelegateAdapter;
|
||||
import com.kerwin.wumei.adapter.base.delegate.XDelegateAdapter;
|
||||
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import me.samlss.broccoli.Broccoli;
|
||||
|
||||
/**
|
||||
* 使用Broccoli占位的基础适配器
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2021/1/9 4:52 PM
|
||||
*/
|
||||
public abstract class BroccoliSimpleDelegateAdapter<T> extends SimpleDelegateAdapter<T> {
|
||||
|
||||
/**
|
||||
* 是否已经加载成功
|
||||
*/
|
||||
private boolean mHasLoad = false;
|
||||
private Map<View, Broccoli> mBroccoliMap = new HashMap<>();
|
||||
|
||||
public BroccoliSimpleDelegateAdapter(int layoutId, LayoutHelper layoutHelper) {
|
||||
super(layoutId, layoutHelper);
|
||||
}
|
||||
|
||||
public BroccoliSimpleDelegateAdapter(int layoutId, LayoutHelper layoutHelper, Collection<T> list) {
|
||||
super(layoutId, layoutHelper, list);
|
||||
}
|
||||
|
||||
public BroccoliSimpleDelegateAdapter(int layoutId, LayoutHelper layoutHelper, T[] data) {
|
||||
super(layoutId, layoutHelper, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindData(@NonNull RecyclerViewHolder holder, int position, T item) {
|
||||
Broccoli broccoli = mBroccoliMap.get(holder.itemView);
|
||||
if (broccoli == null) {
|
||||
broccoli = new Broccoli();
|
||||
mBroccoliMap.put(holder.itemView, broccoli);
|
||||
}
|
||||
if (mHasLoad) {
|
||||
broccoli.removeAllPlaceholders();
|
||||
|
||||
onBindData(holder, item, position);
|
||||
} else {
|
||||
onBindBroccoli(holder, broccoli);
|
||||
broccoli.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 绑定控件
|
||||
*
|
||||
* @param holder
|
||||
* @param model
|
||||
* @param position
|
||||
*/
|
||||
protected abstract void onBindData(RecyclerViewHolder holder, T model, int position);
|
||||
|
||||
/**
|
||||
* 绑定占位控件
|
||||
*
|
||||
* @param holder
|
||||
* @param broccoli
|
||||
*/
|
||||
protected abstract void onBindBroccoli(RecyclerViewHolder holder, Broccoli broccoli);
|
||||
|
||||
@Override
|
||||
public XDelegateAdapter refresh(Collection<T> collection) {
|
||||
mHasLoad = true;
|
||||
return super.refresh(collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* 资源释放,防止内存泄漏
|
||||
*/
|
||||
public void recycle() {
|
||||
for (Broccoli broccoli : mBroccoliMap.values()) {
|
||||
broccoli.removeAllPlaceholders();
|
||||
}
|
||||
mBroccoliMap.clear();
|
||||
clear();
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.adapter.base.delegate;
|
||||
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 通用的DelegateAdapter适配器
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2020/3/20 12:44 AM
|
||||
*/
|
||||
public abstract class BaseDelegateAdapter<T> extends XDelegateAdapter<T, RecyclerViewHolder> {
|
||||
|
||||
public BaseDelegateAdapter() {
|
||||
super();
|
||||
}
|
||||
|
||||
public BaseDelegateAdapter(Collection<T> list) {
|
||||
super(list);
|
||||
}
|
||||
|
||||
public BaseDelegateAdapter(T[] data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 适配的布局
|
||||
*
|
||||
* @param viewType
|
||||
* @return
|
||||
*/
|
||||
protected abstract int getItemLayoutId(int viewType);
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected RecyclerViewHolder getViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
return new RecyclerViewHolder(inflateView(parent, getItemLayoutId(viewType)));
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.adapter.base.delegate;
|
||||
|
||||
import com.alibaba.android.vlayout.LayoutHelper;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 简易DelegateAdapter适配器
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2020/3/20 12:55 AM
|
||||
*/
|
||||
public abstract class SimpleDelegateAdapter<T> extends BaseDelegateAdapter<T> {
|
||||
|
||||
private int mLayoutId;
|
||||
|
||||
private LayoutHelper mLayoutHelper;
|
||||
|
||||
public SimpleDelegateAdapter(int layoutId, LayoutHelper layoutHelper) {
|
||||
super();
|
||||
mLayoutId = layoutId;
|
||||
mLayoutHelper = layoutHelper;
|
||||
}
|
||||
|
||||
public SimpleDelegateAdapter(int layoutId, LayoutHelper layoutHelper, Collection<T> list) {
|
||||
super(list);
|
||||
mLayoutId = layoutId;
|
||||
mLayoutHelper = layoutHelper;
|
||||
}
|
||||
|
||||
public SimpleDelegateAdapter(int layoutId, LayoutHelper layoutHelper, T[] data) {
|
||||
super(data);
|
||||
mLayoutId = layoutId;
|
||||
mLayoutHelper = layoutHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getItemLayoutId(int viewType) {
|
||||
return mLayoutId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public LayoutHelper onCreateLayoutHelper() {
|
||||
return mLayoutHelper;
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.adapter.base.delegate;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.alibaba.android.vlayout.DelegateAdapter;
|
||||
import com.alibaba.android.vlayout.LayoutHelper;
|
||||
import com.alibaba.android.vlayout.layout.SingleLayoutHelper;
|
||||
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;
|
||||
|
||||
/**
|
||||
* 单独布局的DelegateAdapter
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2020/3/20 1:04 AM
|
||||
*/
|
||||
public abstract class SingleDelegateAdapter extends DelegateAdapter.Adapter<RecyclerViewHolder> {
|
||||
|
||||
private int mLayoutId;
|
||||
|
||||
public SingleDelegateAdapter(int layoutId) {
|
||||
mLayoutId = layoutId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LayoutHelper onCreateLayoutHelper() {
|
||||
return new SingleLayoutHelper();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载布局获取控件
|
||||
*
|
||||
* @param parent 父布局
|
||||
* @param layoutId 布局ID
|
||||
* @return
|
||||
*/
|
||||
protected View inflateView(ViewGroup parent, @LayoutRes int layoutId) {
|
||||
return LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
return new RecyclerViewHolder(inflateView(parent, mLayoutId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -1,300 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.adapter.base.delegate;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.alibaba.android.vlayout.DelegateAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 基础DelegateAdapter
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2020/3/20 12:17 AM
|
||||
*/
|
||||
public abstract class XDelegateAdapter<T, V extends RecyclerView.ViewHolder> extends DelegateAdapter.Adapter<V> {
|
||||
/**
|
||||
* 数据源
|
||||
*/
|
||||
protected final List<T> mData = new ArrayList<>();
|
||||
/**
|
||||
* 当前点击的条目
|
||||
*/
|
||||
protected int mSelectPosition = -1;
|
||||
|
||||
public XDelegateAdapter() {
|
||||
|
||||
}
|
||||
|
||||
public XDelegateAdapter(Collection<T> list) {
|
||||
if (list != null) {
|
||||
mData.addAll(list);
|
||||
}
|
||||
}
|
||||
|
||||
public XDelegateAdapter(T[] data) {
|
||||
if (data != null && data.length > 0) {
|
||||
mData.addAll(Arrays.asList(data));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建自定义的ViewHolder
|
||||
*
|
||||
* @param parent
|
||||
* @param viewType
|
||||
* @return
|
||||
*/
|
||||
@NonNull
|
||||
protected abstract V getViewHolder(@NonNull ViewGroup parent, int viewType);
|
||||
|
||||
/**
|
||||
* 绑定数据
|
||||
*
|
||||
* @param holder
|
||||
* @param position 索引
|
||||
* @param item 列表项
|
||||
*/
|
||||
protected abstract void bindData(@NonNull V holder, int position, T item);
|
||||
|
||||
/**
|
||||
* 加载布局获取控件
|
||||
*
|
||||
* @param parent 父布局
|
||||
* @param layoutId 布局ID
|
||||
* @return
|
||||
*/
|
||||
protected View inflateView(ViewGroup parent, @LayoutRes int layoutId) {
|
||||
return LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public V onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
return getViewHolder(parent, viewType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull V holder, int position) {
|
||||
bindData(holder, position, mData.get(position));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表项
|
||||
*
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
public T getItem(int position) {
|
||||
return checkPosition(position) ? mData.get(position) : null;
|
||||
}
|
||||
|
||||
private boolean checkPosition(int position) {
|
||||
return position >= 0 && position <= mData.size() - 1;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getItemCount() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mData.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 数据源
|
||||
*/
|
||||
public List<T> getData() {
|
||||
return mData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给指定位置添加一项
|
||||
*
|
||||
* @param pos
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
public XDelegateAdapter add(int pos, T item) {
|
||||
mData.add(pos, item);
|
||||
notifyItemInserted(pos);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在列表末端增加一项
|
||||
*
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
public XDelegateAdapter add(T item) {
|
||||
mData.add(item);
|
||||
notifyItemInserted(mData.size() - 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除列表中指定索引的数据
|
||||
*
|
||||
* @param pos
|
||||
* @return
|
||||
*/
|
||||
public XDelegateAdapter delete(int pos) {
|
||||
mData.remove(pos);
|
||||
notifyItemRemoved(pos);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新列表中指定位置的数据
|
||||
*
|
||||
* @param pos
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
public XDelegateAdapter refresh(int pos, T item) {
|
||||
mData.set(pos, item);
|
||||
notifyItemChanged(pos);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新列表数据
|
||||
*
|
||||
* @param collection
|
||||
* @return
|
||||
*/
|
||||
public XDelegateAdapter refresh(Collection<T> collection) {
|
||||
if (collection != null) {
|
||||
mData.clear();
|
||||
mData.addAll(collection);
|
||||
mSelectPosition = -1;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新列表数据
|
||||
*
|
||||
* @param array
|
||||
* @return
|
||||
*/
|
||||
public XDelegateAdapter refresh(T[] array) {
|
||||
if (array != null && array.length > 0) {
|
||||
mData.clear();
|
||||
mData.addAll(Arrays.asList(array));
|
||||
mSelectPosition = -1;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载更多
|
||||
*
|
||||
* @param collection
|
||||
* @return
|
||||
*/
|
||||
public XDelegateAdapter loadMore(Collection<T> collection) {
|
||||
if (collection != null) {
|
||||
mData.addAll(collection);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载更多
|
||||
*
|
||||
* @param array
|
||||
* @return
|
||||
*/
|
||||
public XDelegateAdapter loadMore(T[] array) {
|
||||
if (array != null && array.length > 0) {
|
||||
mData.addAll(Arrays.asList(array));
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一个
|
||||
*
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
public XDelegateAdapter load(T item) {
|
||||
if (item != null) {
|
||||
mData.add(item);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 当前列表的选中项
|
||||
*/
|
||||
public int getSelectPosition() {
|
||||
return mSelectPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前列表的选中项
|
||||
*
|
||||
* @param selectPosition
|
||||
* @return
|
||||
*/
|
||||
public XDelegateAdapter setSelectPosition(int selectPosition) {
|
||||
mSelectPosition = selectPosition;
|
||||
notifyDataSetChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前列表选中项
|
||||
*
|
||||
* @return 当前列表选中项
|
||||
*/
|
||||
public T getSelectItem() {
|
||||
return getItem(mSelectPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除数据
|
||||
*/
|
||||
public void clear() {
|
||||
if (!isEmpty()) {
|
||||
mData.clear();
|
||||
mSelectPosition = -1;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.kerwin.wumei.adapter.entity;
|
||||
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.xuexiang.xui.widget.picker.XSeekBar;
|
||||
import com.xuexiang.xui.widget.spinner.materialspinner.MaterialSpinner;
|
||||
|
||||
public class EspTouchViewModel {
|
||||
public MaterialSpinner ssidSpinner;
|
||||
public EditText apPasswordEdit;
|
||||
public XSeekBar xsbDeviceCount;
|
||||
public RadioGroup packageModeGroup;
|
||||
public TextView messageView;
|
||||
public Button confirmBtn;
|
||||
|
||||
public String ssid;
|
||||
public byte[] ssidBytes;
|
||||
public String bssid;
|
||||
|
||||
public CharSequence message;
|
||||
|
||||
public boolean confirmEnable;
|
||||
|
||||
public void invalidateAll() {
|
||||
ssidSpinner.setText(ssid);
|
||||
messageView.setText(message);
|
||||
confirmBtn.setEnabled(confirmEnable);
|
||||
}
|
||||
}
|
||||
@@ -1,183 +0,0 @@
|
||||
|
||||
package com.kerwin.wumei.adapter.entity;
|
||||
|
||||
/**
|
||||
* 新闻信息
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019/4/7 下午12:07
|
||||
*/
|
||||
public class NewInfo {
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String UserName = "kerwin";
|
||||
/**
|
||||
* 标签
|
||||
*/
|
||||
private String Tag;
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String Title;
|
||||
/**
|
||||
* 摘要
|
||||
*/
|
||||
private String Summary;
|
||||
|
||||
/**
|
||||
* 图片
|
||||
*/
|
||||
private String ImageUrl;
|
||||
/**
|
||||
* 点赞数
|
||||
*/
|
||||
private int Praise;
|
||||
/**
|
||||
* 评论数
|
||||
*/
|
||||
private int Comment;
|
||||
/**
|
||||
* 阅读量
|
||||
*/
|
||||
private int Read;
|
||||
/**
|
||||
* 新闻的详情地址
|
||||
*/
|
||||
private String DetailUrl;
|
||||
|
||||
|
||||
public NewInfo() {
|
||||
|
||||
}
|
||||
|
||||
public NewInfo(String userName, String tag, String title, String summary, String imageUrl, int praise, int comment, int read, String detailUrl) {
|
||||
UserName = userName;
|
||||
Tag = tag;
|
||||
Title = title;
|
||||
Summary = summary;
|
||||
ImageUrl = imageUrl;
|
||||
Praise = praise;
|
||||
Comment = comment;
|
||||
Read = read;
|
||||
DetailUrl = detailUrl;
|
||||
}
|
||||
|
||||
|
||||
public NewInfo(String tag, String title, String summary, String imageUrl, String detailUrl) {
|
||||
Tag = tag;
|
||||
Title = title;
|
||||
Summary = summary;
|
||||
ImageUrl = imageUrl;
|
||||
DetailUrl = detailUrl;
|
||||
}
|
||||
|
||||
|
||||
public NewInfo(String tag, String title) {
|
||||
Tag = tag;
|
||||
Title = title;
|
||||
|
||||
Praise = (int) (Math.random() * 100 + 5);
|
||||
Comment = (int) (Math.random() * 50 + 5);
|
||||
Read = (int) (Math.random() * 500 + 50);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getUserName() {
|
||||
return UserName;
|
||||
}
|
||||
|
||||
public NewInfo setUserName(String userName) {
|
||||
UserName = userName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return Tag;
|
||||
}
|
||||
|
||||
public NewInfo setTag(String tag) {
|
||||
Tag = tag;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return Title;
|
||||
}
|
||||
|
||||
public NewInfo setTitle(String title) {
|
||||
Title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
return Summary;
|
||||
}
|
||||
|
||||
public NewInfo setSummary(String summary) {
|
||||
Summary = summary;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return ImageUrl;
|
||||
}
|
||||
|
||||
public NewInfo setImageUrl(String imageUrl) {
|
||||
ImageUrl = imageUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getPraise() {
|
||||
return Praise;
|
||||
}
|
||||
|
||||
public NewInfo setPraise(int praise) {
|
||||
Praise = praise;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getComment() {
|
||||
return Comment;
|
||||
}
|
||||
|
||||
public NewInfo setComment(int comment) {
|
||||
Comment = comment;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getRead() {
|
||||
return Read;
|
||||
}
|
||||
|
||||
public NewInfo setRead(int read) {
|
||||
Read = read;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDetailUrl() {
|
||||
return DetailUrl;
|
||||
}
|
||||
|
||||
public NewInfo setDetailUrl(String detailUrl) {
|
||||
DetailUrl = detailUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NewInfo{" +
|
||||
"UserName='" + UserName + '\'' +
|
||||
", Tag='" + Tag + '\'' +
|
||||
", Title='" + Title + '\'' +
|
||||
", Summary='" + Summary + '\'' +
|
||||
", ImageUrl='" + ImageUrl + '\'' +
|
||||
", Praise=" + Praise +
|
||||
", Comment=" + Comment +
|
||||
", Read=" + Read +
|
||||
", DetailUrl='" + DetailUrl + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.xuexiang.xpage.base.XPageActivity;
|
||||
import com.xuexiang.xpage.base.XPageFragment;
|
||||
import com.xuexiang.xpage.core.CoreSwitchBean;
|
||||
import com.xuexiang.xrouter.facade.service.SerializationService;
|
||||
import com.xuexiang.xrouter.launcher.XRouter;
|
||||
import com.xuexiang.xui.utils.ResUtils;
|
||||
import com.xuexiang.xui.widget.slideback.SlideBack;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper;
|
||||
|
||||
/**
|
||||
* 基础容器Activity
|
||||
*
|
||||
* @author XUE
|
||||
* @since 2019/3/22 11:21
|
||||
*/
|
||||
public class BaseActivity extends XPageActivity {
|
||||
|
||||
Unbinder mUnbinder;
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
//注入字体
|
||||
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase));
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否支持侧滑返回
|
||||
*/
|
||||
public static final String KEY_SUPPORT_SLIDE_BACK = "key_support_slide_back";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
initStatusBarStyle();
|
||||
super.onCreate(savedInstanceState);
|
||||
mUnbinder = ButterKnife.bind(this);
|
||||
|
||||
registerSlideBack();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化状态栏的样式
|
||||
*/
|
||||
protected void initStatusBarStyle() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开fragment
|
||||
*
|
||||
* @param clazz 页面类
|
||||
* @param addToBackStack 是否添加到栈中
|
||||
* @return 打开的fragment对象
|
||||
*/
|
||||
public <T extends XPageFragment> T openPage(Class<T> clazz, boolean addToBackStack) {
|
||||
CoreSwitchBean page = new CoreSwitchBean(clazz)
|
||||
.setAddToBackStack(addToBackStack);
|
||||
return (T) openPage(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开fragment
|
||||
*
|
||||
* @return 打开的fragment对象
|
||||
*/
|
||||
public <T extends XPageFragment> T openNewPage(Class<T> clazz) {
|
||||
CoreSwitchBean page = new CoreSwitchBean(clazz)
|
||||
.setNewActivity(true);
|
||||
return (T) openPage(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换fragment
|
||||
*
|
||||
* @param clazz 页面类
|
||||
* @return 打开的fragment对象
|
||||
*/
|
||||
public <T extends XPageFragment> T switchPage(Class<T> clazz) {
|
||||
return openPage(clazz, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 序列化对象
|
||||
*
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
public String serializeObject(Object object) {
|
||||
return XRouter.getInstance().navigation(SerializationService.class).object2Json(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRelease() {
|
||||
mUnbinder.unbind();
|
||||
unregisterSlideBack();
|
||||
super.onRelease();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册侧滑回调
|
||||
*/
|
||||
protected void registerSlideBack() {
|
||||
if (isSupportSlideBack()) {
|
||||
SlideBack.with(this)
|
||||
.haveScroll(true)
|
||||
.edgeMode(ResUtils.isRtl() ? SlideBack.EDGE_RIGHT : SlideBack.EDGE_LEFT)
|
||||
.callBack(this::popPage)
|
||||
.register();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销侧滑回调
|
||||
*/
|
||||
protected void unregisterSlideBack() {
|
||||
if (isSupportSlideBack()) {
|
||||
SlideBack.unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 是否支持侧滑返回
|
||||
*/
|
||||
protected boolean isSupportSlideBack() {
|
||||
CoreSwitchBean page = getIntent().getParcelableExtra(CoreSwitchBean.KEY_SWITCH_BEAN);
|
||||
return page == null || page.getBundle() == null || page.getBundle().getBoolean(KEY_SUPPORT_SLIDE_BACK, true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
|
||||
import com.umeng.analytics.MobclickAgent;
|
||||
import com.xuexiang.xaop.annotation.SingleClick;
|
||||
import com.xuexiang.xpage.base.XPageContainerListFragment;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.kerwin.wumei.core.SimpleListAdapter.KEY_SUB_TITLE;
|
||||
import static com.kerwin.wumei.core.SimpleListAdapter.KEY_TITLE;
|
||||
|
||||
/**
|
||||
* 修改列表样式为主副标题显示
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2018/11/22 上午11:26
|
||||
*/
|
||||
public abstract class BaseContainerFragment extends XPageContainerListFragment {
|
||||
|
||||
@Override
|
||||
protected void initPage() {
|
||||
initTitle();
|
||||
initViews();
|
||||
initListeners();
|
||||
}
|
||||
|
||||
protected TitleBar initTitle() {
|
||||
return TitleUtils.addTitleBarDynamic((ViewGroup) getRootView(), getPageTitle(), new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
popToBack();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
mSimpleData = initSimpleData(mSimpleData);
|
||||
|
||||
List<Map<String, String>> data = new ArrayList<>();
|
||||
for (String content : mSimpleData) {
|
||||
Map<String, String> item = new HashMap<>();
|
||||
int index = content.indexOf("\n");
|
||||
if (index > 0) {
|
||||
item.put(KEY_TITLE, String.valueOf(content.subSequence(0, index)));
|
||||
item.put(KEY_SUB_TITLE, String.valueOf(content.subSequence(index + 1, content.length())));
|
||||
} else {
|
||||
item.put(KEY_TITLE, content);
|
||||
item.put(KEY_SUB_TITLE, "");
|
||||
}
|
||||
data.add(item);
|
||||
}
|
||||
|
||||
getListView().setAdapter(new SimpleListAdapter(getContext(), data));
|
||||
initSimply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
|
||||
onItemClick(view, position);
|
||||
}
|
||||
|
||||
@SingleClick
|
||||
private void onItemClick(View view, int position) {
|
||||
onItemClick(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
getListView().setOnItemClickListener(null);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
//屏幕旋转时刷新一下title
|
||||
super.onConfigurationChanged(newConfig);
|
||||
ViewGroup root = (ViewGroup) getRootView();
|
||||
if (root.getChildAt(0) instanceof TitleBar) {
|
||||
root.removeViewAt(0);
|
||||
initTitle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
MobclickAgent.onPageStart(getPageName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
MobclickAgent.onPageEnd(getPageName());
|
||||
}
|
||||
}
|
||||
@@ -1,346 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Parcelable;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.umeng.analytics.MobclickAgent;
|
||||
import com.kerwin.wumei.core.http.loader.ProgressLoader;
|
||||
import com.xuexiang.xhttp2.subsciber.impl.IProgressLoader;
|
||||
import com.xuexiang.xpage.base.XPageActivity;
|
||||
import com.xuexiang.xpage.base.XPageFragment;
|
||||
import com.xuexiang.xpage.core.PageOption;
|
||||
import com.xuexiang.xpage.enums.CoreAnim;
|
||||
import com.xuexiang.xpage.utils.Utils;
|
||||
import com.xuexiang.xrouter.facade.service.SerializationService;
|
||||
import com.xuexiang.xrouter.launcher.XRouter;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* 基础fragment
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2018/5/25 下午3:44
|
||||
*/
|
||||
public abstract class BaseFragment extends XPageFragment {
|
||||
|
||||
private IProgressLoader mIProgressLoader;
|
||||
|
||||
@Override
|
||||
protected void initPage() {
|
||||
initTitle();
|
||||
initViews();
|
||||
initListeners();
|
||||
}
|
||||
|
||||
protected TitleBar initTitle() {
|
||||
return TitleUtils.addTitleBarDynamic((ViewGroup) getRootView(), getPageTitle(), v -> popToBack());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initListeners() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取进度条加载者
|
||||
*
|
||||
* @return 进度条加载者
|
||||
*/
|
||||
public IProgressLoader getProgressLoader() {
|
||||
if (mIProgressLoader == null) {
|
||||
mIProgressLoader = ProgressLoader.create(getContext());
|
||||
}
|
||||
return mIProgressLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取进度条加载者
|
||||
*
|
||||
* @param message
|
||||
* @return 进度条加载者
|
||||
*/
|
||||
public IProgressLoader getProgressLoader(String message) {
|
||||
if (mIProgressLoader == null) {
|
||||
mIProgressLoader = ProgressLoader.create(getContext(), message);
|
||||
} else {
|
||||
mIProgressLoader.updateMessage(message);
|
||||
}
|
||||
return mIProgressLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
//屏幕旋转时刷新一下title
|
||||
super.onConfigurationChanged(newConfig);
|
||||
ViewGroup root = (ViewGroup) getRootView();
|
||||
if (root.getChildAt(0) instanceof TitleBar) {
|
||||
root.removeViewAt(0);
|
||||
initTitle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (mIProgressLoader != null) {
|
||||
mIProgressLoader.dismissLoading();
|
||||
}
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
MobclickAgent.onPageStart(getPageName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
MobclickAgent.onPageEnd(getPageName());
|
||||
}
|
||||
|
||||
//==============================页面跳转api===================================//
|
||||
|
||||
/**
|
||||
* 打开一个新的页面【建议只在主tab页使用】
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openNewPage(Class<T> clazz) {
|
||||
return new PageOption(clazz)
|
||||
.setNewActivity(true)
|
||||
.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开一个新的页面【建议只在主tab页使用】
|
||||
*
|
||||
* @param pageName 页面名
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openNewPage(String pageName) {
|
||||
return new PageOption(pageName)
|
||||
.setAnim(CoreAnim.slide)
|
||||
.setNewActivity(true)
|
||||
.open(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 打开一个新的页面【建议只在主tab页使用】
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param containActivityClazz 页面容器
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openNewPage(Class<T> clazz, @NonNull Class<? extends XPageActivity> containActivityClazz) {
|
||||
return new PageOption(clazz)
|
||||
.setNewActivity(true)
|
||||
.setContainActivityClazz(containActivityClazz)
|
||||
.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开一个新的页面【建议只在主tab页使用】
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param key 入参的键
|
||||
* @param value 入参的值
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openNewPage(Class<T> clazz, String key, Object value) {
|
||||
PageOption option = new PageOption(clazz).setNewActivity(true);
|
||||
return openPage(option, key, value);
|
||||
}
|
||||
|
||||
public Fragment openPage(PageOption option, String key, Object value) {
|
||||
if (value instanceof Integer) {
|
||||
option.putInt(key, (Integer) value);
|
||||
} else if (value instanceof Float) {
|
||||
option.putFloat(key, (Float) value);
|
||||
} else if (value instanceof String) {
|
||||
option.putString(key, (String) value);
|
||||
} else if (value instanceof Boolean) {
|
||||
option.putBoolean(key, (Boolean) value);
|
||||
} else if (value instanceof Long) {
|
||||
option.putLong(key, (Long) value);
|
||||
} else if (value instanceof Double) {
|
||||
option.putDouble(key, (Double) value);
|
||||
} else if (value instanceof Parcelable) {
|
||||
option.putParcelable(key, (Parcelable) value);
|
||||
} else if (value instanceof Serializable) {
|
||||
option.putSerializable(key, (Serializable) value);
|
||||
} else {
|
||||
option.putString(key, serializeObject(value));
|
||||
}
|
||||
return option.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param addToBackStack 是否加入回退栈
|
||||
* @param key 入参的键
|
||||
* @param value 入参的值
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openPage(Class<T> clazz, boolean addToBackStack, String key, String value) {
|
||||
return new PageOption(clazz)
|
||||
.setAddToBackStack(addToBackStack)
|
||||
.putString(key, value)
|
||||
.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param key 入参的键
|
||||
* @param value 入参的值
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openPage(Class<T> clazz, String key, Object value) {
|
||||
return openPage(clazz, true, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param addToBackStack 是否加入回退栈
|
||||
* @param key 入参的键
|
||||
* @param value 入参的值
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openPage(Class<T> clazz, boolean addToBackStack, String key, Object value) {
|
||||
PageOption option = new PageOption(clazz).setAddToBackStack(addToBackStack);
|
||||
return openPage(option, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param key 入参的键
|
||||
* @param value 入参的值
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openPage(Class<T> clazz, String key, String value) {
|
||||
return new PageOption(clazz)
|
||||
.putString(key, value)
|
||||
.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面,需要结果返回
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param key 入参的键
|
||||
* @param value 入参的值
|
||||
* @param requestCode 请求码
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openPageForResult(Class<T> clazz, String key, Object value, int requestCode) {
|
||||
PageOption option = new PageOption(clazz).setRequestCode(requestCode);
|
||||
return openPage(option, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面,需要结果返回
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param key 入参的键
|
||||
* @param value 入参的值
|
||||
* @param requestCode 请求码
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openPageForResult(Class<T> clazz, String key, String value, int requestCode) {
|
||||
return new PageOption(clazz)
|
||||
.setRequestCode(requestCode)
|
||||
.putString(key, value)
|
||||
.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面,需要结果返回
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param requestCode 请求码
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openPageForResult(Class<T> clazz, int requestCode) {
|
||||
return new PageOption(clazz)
|
||||
.setRequestCode(requestCode)
|
||||
.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 序列化对象
|
||||
*
|
||||
* @param object 需要序列化的对象
|
||||
* @return 序列化结果
|
||||
*/
|
||||
public String serializeObject(Object object) {
|
||||
return XRouter.getInstance().navigation(SerializationService.class).object2Json(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* 反序列化对象
|
||||
*
|
||||
* @param input 反序列化的内容
|
||||
* @param clazz 类型
|
||||
* @return 反序列化结果
|
||||
*/
|
||||
public <T> T deserializeObject(String input, Type clazz) {
|
||||
return XRouter.getInstance().navigation(SerializationService.class).parseObject(input, clazz);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void hideCurrentPageSoftInput() {
|
||||
if (getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
// 记住,要在xml的父布局加上android:focusable="true" 和 android:focusableInTouchMode="true"
|
||||
Utils.hideSoftInputClearFocus(getActivity().getCurrentFocus());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,284 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Parcelable;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.umeng.analytics.MobclickAgent;
|
||||
import com.xuexiang.xpage.base.XPageActivity;
|
||||
import com.xuexiang.xpage.base.XPageFragment;
|
||||
import com.xuexiang.xpage.base.XPageSimpleListFragment;
|
||||
import com.xuexiang.xpage.core.PageOption;
|
||||
import com.xuexiang.xpage.enums.CoreAnim;
|
||||
import com.xuexiang.xrouter.facade.service.SerializationService;
|
||||
import com.xuexiang.xrouter.launcher.XRouter;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author xuexiang
|
||||
* @since 2018/12/29 下午12:41
|
||||
*/
|
||||
public abstract class BaseSimpleListFragment extends XPageSimpleListFragment {
|
||||
|
||||
@Override
|
||||
protected void initPage() {
|
||||
initTitle();
|
||||
initViews();
|
||||
initListeners();
|
||||
}
|
||||
|
||||
protected TitleBar initTitle() {
|
||||
return TitleUtils.addTitleBarDynamic((ViewGroup) getRootView(), getPageTitle(), new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
popToBack();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
//屏幕旋转时刷新一下title
|
||||
super.onConfigurationChanged(newConfig);
|
||||
ViewGroup root = (ViewGroup) getRootView();
|
||||
if (root.getChildAt(0) instanceof TitleBar) {
|
||||
root.removeViewAt(0);
|
||||
initTitle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
MobclickAgent.onPageStart(getPageName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
MobclickAgent.onPageEnd(getPageName());
|
||||
}
|
||||
|
||||
//==============================页面跳转api===================================//
|
||||
|
||||
/**
|
||||
* 打开一个新的页面【建议只在主tab页使用】
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openNewPage(Class<T> clazz) {
|
||||
return new PageOption(clazz)
|
||||
.setNewActivity(true)
|
||||
.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开一个新的页面【建议只在主tab页使用】
|
||||
*
|
||||
* @param pageName 页面名
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openNewPage(String pageName) {
|
||||
return new PageOption(pageName)
|
||||
.setAnim(CoreAnim.slide)
|
||||
.setNewActivity(true)
|
||||
.open(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 打开一个新的页面【建议只在主tab页使用】
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param containActivityClazz 页面容器
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openNewPage(Class<T> clazz, @NonNull Class<? extends XPageActivity> containActivityClazz) {
|
||||
return new PageOption(clazz)
|
||||
.setNewActivity(true)
|
||||
.setContainActivityClazz(containActivityClazz)
|
||||
.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开一个新的页面【建议只在主tab页使用】
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param key 入参的键
|
||||
* @param value 入参的值
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openNewPage(Class<T> clazz, String key, Object value) {
|
||||
PageOption option = new PageOption(clazz).setNewActivity(true);
|
||||
return openPage(option, key, value);
|
||||
}
|
||||
|
||||
public Fragment openPage(PageOption option, String key, Object value) {
|
||||
if (value instanceof Integer) {
|
||||
option.putInt(key, (Integer) value);
|
||||
} else if (value instanceof Float) {
|
||||
option.putFloat(key, (Float) value);
|
||||
} else if (value instanceof String) {
|
||||
option.putString(key, (String) value);
|
||||
} else if (value instanceof Boolean) {
|
||||
option.putBoolean(key, (Boolean) value);
|
||||
} else if (value instanceof Long) {
|
||||
option.putLong(key, (Long) value);
|
||||
} else if (value instanceof Double) {
|
||||
option.putDouble(key, (Double) value);
|
||||
} else if (value instanceof Parcelable) {
|
||||
option.putParcelable(key, (Parcelable) value);
|
||||
} else if (value instanceof Serializable) {
|
||||
option.putSerializable(key, (Serializable) value);
|
||||
} else {
|
||||
option.putString(key, serializeObject(value));
|
||||
}
|
||||
return option.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param addToBackStack 是否加入回退栈
|
||||
* @param key 入参的键
|
||||
* @param value 入参的值
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openPage(Class<T> clazz, boolean addToBackStack, String key, String value) {
|
||||
return new PageOption(clazz)
|
||||
.setAddToBackStack(addToBackStack)
|
||||
.putString(key, value)
|
||||
.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param key 入参的键
|
||||
* @param value 入参的值
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openPage(Class<T> clazz, String key, Object value) {
|
||||
return openPage(clazz, true, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param addToBackStack 是否加入回退栈
|
||||
* @param key 入参的键
|
||||
* @param value 入参的值
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openPage(Class<T> clazz, boolean addToBackStack, String key, Object value) {
|
||||
PageOption option = new PageOption(clazz).setAddToBackStack(addToBackStack);
|
||||
return openPage(option, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param key 入参的键
|
||||
* @param value 入参的值
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openPage(Class<T> clazz, String key, String value) {
|
||||
return new PageOption(clazz)
|
||||
.putString(key, value)
|
||||
.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面,需要结果返回
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param key 入参的键
|
||||
* @param value 入参的值
|
||||
* @param requestCode 请求码
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openPageForResult(Class<T> clazz, String key, Object value, int requestCode) {
|
||||
PageOption option = new PageOption(clazz).setRequestCode(requestCode);
|
||||
return openPage(option, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面,需要结果返回
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param key 入参的键
|
||||
* @param value 入参的值
|
||||
* @param requestCode 请求码
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openPageForResult(Class<T> clazz, String key, String value, int requestCode) {
|
||||
return new PageOption(clazz)
|
||||
.setRequestCode(requestCode)
|
||||
.putString(key, value)
|
||||
.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面,需要结果返回
|
||||
*
|
||||
* @param clazz 页面的类
|
||||
* @param requestCode 请求码
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends XPageFragment> Fragment openPageForResult(Class<T> clazz, int requestCode) {
|
||||
return new PageOption(clazz)
|
||||
.setRequestCode(requestCode)
|
||||
.open(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 序列化对象
|
||||
*
|
||||
* @param object 需要序列化的对象
|
||||
* @return 序列化结果
|
||||
*/
|
||||
public String serializeObject(Object object) {
|
||||
return XRouter.getInstance().navigation(SerializationService.class).object2Json(object);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.xuexiang.xui.adapter.listview.BaseListAdapter;
|
||||
import com.xuexiang.xutil.common.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 主副标题显示适配器
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2018/12/19 上午12:19
|
||||
*/
|
||||
public class SimpleListAdapter extends BaseListAdapter<Map<String, String>, SimpleListAdapter.ViewHolder> {
|
||||
|
||||
public static final String KEY_TITLE = "key_title";
|
||||
public static final String KEY_SUB_TITLE = "key_sub_title";
|
||||
|
||||
public SimpleListAdapter(Context context, List<Map<String, String>> data) {
|
||||
super(context, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ViewHolder newViewHolder(View convertView) {
|
||||
ViewHolder holder = new ViewHolder();
|
||||
holder.mTvTitle = convertView.findViewById(R.id.device_item_title);
|
||||
holder.mTvSubTitle = convertView.findViewById(R.id.tv_sub_title);
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.adapter_item_simple_list_2;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(ViewHolder holder, Map<String, String> item, int position) {
|
||||
holder.mTvTitle.setText(item.get(KEY_TITLE));
|
||||
if (!StringUtils.isEmpty(item.get(KEY_SUB_TITLE))) {
|
||||
holder.mTvSubTitle.setText(item.get(KEY_SUB_TITLE));
|
||||
holder.mTvSubTitle.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.mTvSubTitle.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ViewHolder {
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
public TextView mTvTitle;
|
||||
/**
|
||||
* 副标题
|
||||
*/
|
||||
public TextView mTvSubTitle;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xrouter.annotation.AutoWired;
|
||||
import com.xuexiang.xrouter.annotation.Router;
|
||||
import com.xuexiang.xrouter.launcher.XRouter;
|
||||
import com.xuexiang.xutil.common.StringUtils;
|
||||
|
||||
/**
|
||||
* https://xuexiangjys.club/xpage/transfer?pageName=xxxxx&....
|
||||
* applink的中转
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-07-06 9:37
|
||||
*/
|
||||
@Router(path = "/xpage/transfer")
|
||||
public class XPageTransferActivity extends BaseActivity {
|
||||
|
||||
@AutoWired(name = "pageName")
|
||||
String pageName;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
XRouter.getInstance().inject(this);
|
||||
|
||||
if (!StringUtils.isEmpty(pageName)) {
|
||||
if (openPage(pageName, getIntent().getExtras()) == null) {
|
||||
XToastUtils.error("页面未找到!");
|
||||
finish();
|
||||
}
|
||||
} else {
|
||||
XToastUtils.error("页面未找到!");
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.http.api;
|
||||
|
||||
import com.kerwin.wumei.core.http.entity.TipInfo;
|
||||
import com.xuexiang.xhttp2.model.ApiResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.GET;
|
||||
|
||||
/**
|
||||
* @author xuexiang
|
||||
* @since 2021/1/9 7:01 PM
|
||||
*/
|
||||
public class ApiService {
|
||||
|
||||
/**
|
||||
* 使用的是retrofit的接口定义
|
||||
*/
|
||||
public interface IGetService {
|
||||
|
||||
/**
|
||||
* 获得小贴士
|
||||
*/
|
||||
@GET("http://wumei.live/tips.json")
|
||||
Observable<ApiResult<List<TipInfo>>> getTips();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.http.callback;
|
||||
|
||||
import com.xuexiang.xhttp2.callback.SimpleCallBack;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xhttp2.model.XHttpRequest;
|
||||
import com.xuexiang.xutil.common.StringUtils;
|
||||
import com.xuexiang.xutil.common.logger.Logger;
|
||||
|
||||
/**
|
||||
* 不带错误提示的网络请求回调
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-11-18 23:02
|
||||
*/
|
||||
public abstract class NoTipCallBack<T> extends SimpleCallBack<T> {
|
||||
|
||||
/**
|
||||
* 记录一下请求的url,确定出错的请求是哪个请求
|
||||
*/
|
||||
private String mUrl;
|
||||
|
||||
public NoTipCallBack() {
|
||||
|
||||
}
|
||||
|
||||
public NoTipCallBack(XHttpRequest req) {
|
||||
this(req.getUrl());
|
||||
}
|
||||
|
||||
public NoTipCallBack(String url) {
|
||||
mUrl = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if (!StringUtils.isEmpty(mUrl)) {
|
||||
Logger.e("网络请求的url:" + mUrl, e);
|
||||
} else {
|
||||
Logger.e(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.http.callback;
|
||||
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xhttp2.callback.SimpleCallBack;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xhttp2.model.XHttpRequest;
|
||||
import com.xuexiang.xutil.common.StringUtils;
|
||||
import com.xuexiang.xutil.common.logger.Logger;
|
||||
|
||||
/**
|
||||
* 带错误toast提示的网络请求回调
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-11-18 23:02
|
||||
*/
|
||||
public abstract class TipCallBack<T> extends SimpleCallBack<T> {
|
||||
|
||||
/**
|
||||
* 记录一下请求的url,确定出错的请求是哪个请求
|
||||
*/
|
||||
private String mUrl;
|
||||
|
||||
public TipCallBack() {
|
||||
|
||||
}
|
||||
|
||||
public TipCallBack(XHttpRequest req) {
|
||||
this(req.getUrl());
|
||||
}
|
||||
|
||||
public TipCallBack(String url) {
|
||||
mUrl = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
XToastUtils.error(e);
|
||||
if (!StringUtils.isEmpty(mUrl)) {
|
||||
Logger.e("网络请求的url:" + mUrl, e);
|
||||
} else {
|
||||
Logger.e(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.http.callback;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xhttp2.callback.ProgressLoadingCallBack;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xhttp2.model.XHttpRequest;
|
||||
import com.xuexiang.xhttp2.subsciber.impl.IProgressLoader;
|
||||
import com.xuexiang.xutil.common.StringUtils;
|
||||
import com.xuexiang.xutil.common.logger.Logger;
|
||||
|
||||
/**
|
||||
* 带错误toast提示和加载进度条的网络请求回调
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-11-18 23:16
|
||||
*/
|
||||
public abstract class TipProgressLoadingCallBack<T> extends ProgressLoadingCallBack<T> {
|
||||
/**
|
||||
* 记录一下请求的url,确定出错的请求是哪个请求
|
||||
*/
|
||||
private String mUrl;
|
||||
|
||||
public TipProgressLoadingCallBack(BaseFragment fragment) {
|
||||
super(fragment.getProgressLoader());
|
||||
}
|
||||
|
||||
public TipProgressLoadingCallBack(IProgressLoader iProgressLoader) {
|
||||
super(iProgressLoader);
|
||||
}
|
||||
|
||||
public TipProgressLoadingCallBack(@NonNull XHttpRequest req, IProgressLoader iProgressLoader) {
|
||||
this(req.getUrl(), iProgressLoader);
|
||||
}
|
||||
|
||||
public TipProgressLoadingCallBack(String url, IProgressLoader iProgressLoader) {
|
||||
super(iProgressLoader);
|
||||
mUrl = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
super.onError(e);
|
||||
XToastUtils.error(e);
|
||||
if (!StringUtils.isEmpty(mUrl)) {
|
||||
Logger.e("网络请求的url:" + mUrl, e);
|
||||
} else {
|
||||
Logger.e(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.http.entity;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
/**
|
||||
* @author xuexiang
|
||||
* @since 2019-08-28 15:35
|
||||
*/
|
||||
@Keep
|
||||
public class TipInfo {
|
||||
|
||||
/**
|
||||
* title : 小贴士3
|
||||
* content : <p style=";font-family:'Microsoft YaHei';font-size:15px">欢迎关注我的微信公众号:我的Android开源之旅。</p><p><br/></p>
|
||||
*/
|
||||
|
||||
private String title;
|
||||
private String content;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TipInfo{" +
|
||||
"title='" + title + '\'' +
|
||||
", content='" + content + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.http.loader;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.xuexiang.xhttp2.subsciber.impl.IProgressLoader;
|
||||
|
||||
/**
|
||||
* IProgressLoader的创建工厂实现接口
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-11-18 23:17
|
||||
*/
|
||||
public interface IProgressLoaderFactory {
|
||||
|
||||
|
||||
/**
|
||||
* 创建进度加载者
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
IProgressLoader create(Context context);
|
||||
|
||||
|
||||
/**
|
||||
* 创建进度加载者
|
||||
*
|
||||
* @param context
|
||||
* @param message 默认提示
|
||||
* @return
|
||||
*/
|
||||
IProgressLoader create(Context context, String message);
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.http.loader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
||||
import com.xuexiang.xhttp2.subsciber.impl.IProgressLoader;
|
||||
import com.xuexiang.xhttp2.subsciber.impl.OnProgressCancelListener;
|
||||
import com.xuexiang.xui.widget.dialog.MiniLoadingDialog;
|
||||
|
||||
/**
|
||||
* 默认进度加载
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-11-18 23:07
|
||||
*/
|
||||
public class MiniLoadingDialogLoader implements IProgressLoader {
|
||||
/**
|
||||
* 进度loading弹窗
|
||||
*/
|
||||
private MiniLoadingDialog mDialog;
|
||||
/**
|
||||
* 进度框取消监听
|
||||
*/
|
||||
private OnProgressCancelListener mOnProgressCancelListener;
|
||||
|
||||
public MiniLoadingDialogLoader(Context context) {
|
||||
this(context, "请求中...");
|
||||
}
|
||||
|
||||
public MiniLoadingDialogLoader(Context context, String msg) {
|
||||
mDialog = new MiniLoadingDialog(context, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoading() {
|
||||
return mDialog != null && mDialog.isShowing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMessage(String msg) {
|
||||
if (mDialog != null) {
|
||||
mDialog.updateMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLoading() {
|
||||
if (mDialog != null && !mDialog.isShowing()) {
|
||||
mDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismissLoading() {
|
||||
if (mDialog != null && mDialog.isShowing()) {
|
||||
mDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelable(boolean flag) {
|
||||
mDialog.setCancelable(flag);
|
||||
if (flag) {
|
||||
mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialogInterface) {
|
||||
if (mOnProgressCancelListener != null) {
|
||||
mOnProgressCancelListener.onCancelProgress();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnProgressCancelListener(OnProgressCancelListener listener) {
|
||||
mOnProgressCancelListener = listener;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.http.loader;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.xuexiang.xhttp2.subsciber.impl.IProgressLoader;
|
||||
|
||||
/**
|
||||
* 迷你加载框创建工厂
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-11-18 23:23
|
||||
*/
|
||||
public class MiniProgressLoaderFactory implements IProgressLoaderFactory {
|
||||
|
||||
@Override
|
||||
public IProgressLoader create(Context context) {
|
||||
return new MiniLoadingDialogLoader(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProgressLoader create(Context context, String message) {
|
||||
return new MiniLoadingDialogLoader(context, message);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.http.loader;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.xuexiang.xhttp2.subsciber.impl.IProgressLoader;
|
||||
|
||||
/**
|
||||
* 创建进度加载者
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-07-02 12:51
|
||||
*/
|
||||
public final class ProgressLoader {
|
||||
|
||||
private ProgressLoader() {
|
||||
throw new UnsupportedOperationException("u can't instantiate me...");
|
||||
}
|
||||
|
||||
private static IProgressLoaderFactory sIProgressLoaderFactory = new MiniProgressLoaderFactory();
|
||||
|
||||
public static void setIProgressLoaderFactory(IProgressLoaderFactory sIProgressLoaderFactory) {
|
||||
ProgressLoader.sIProgressLoaderFactory = sIProgressLoaderFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建进度加载者
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static IProgressLoader create(Context context) {
|
||||
return sIProgressLoaderFactory.create(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建进度加载者
|
||||
*
|
||||
* @param context
|
||||
* @param message 默认提示信息
|
||||
* @return
|
||||
*/
|
||||
public static IProgressLoader create(Context context, String message) {
|
||||
return sIProgressLoaderFactory.create(context, message);
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.http.subscriber;
|
||||
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xhttp2.model.XHttpRequest;
|
||||
import com.xuexiang.xhttp2.subsciber.BaseSubscriber;
|
||||
import com.xuexiang.xutil.common.StringUtils;
|
||||
import com.xuexiang.xutil.common.logger.Logger;
|
||||
|
||||
/**
|
||||
* 不带错误toast提示的网络请求订阅,只存储错误的日志
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-11-18 23:11
|
||||
*/
|
||||
public abstract class NoTipRequestSubscriber<T> extends BaseSubscriber<T> {
|
||||
|
||||
/**
|
||||
* 记录一下请求的url,确定出错的请求是哪个请求
|
||||
*/
|
||||
private String mUrl;
|
||||
|
||||
public NoTipRequestSubscriber() {
|
||||
|
||||
}
|
||||
|
||||
public NoTipRequestSubscriber(XHttpRequest req) {
|
||||
this(req.getUrl());
|
||||
}
|
||||
|
||||
public NoTipRequestSubscriber(String url) {
|
||||
mUrl = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if (!StringUtils.isEmpty(mUrl)) {
|
||||
Logger.e("网络请求的url:" + mUrl, e);
|
||||
} else {
|
||||
Logger.e(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.http.subscriber;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xhttp2.model.XHttpRequest;
|
||||
import com.xuexiang.xhttp2.subsciber.ProgressLoadingSubscriber;
|
||||
import com.xuexiang.xhttp2.subsciber.impl.IProgressLoader;
|
||||
import com.xuexiang.xutil.common.StringUtils;
|
||||
import com.xuexiang.xutil.common.logger.Logger;
|
||||
|
||||
/**
|
||||
* 带错误toast提示和加载进度条的网络请求订阅
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-11-18 23:11
|
||||
*/
|
||||
public abstract class TipProgressLoadingSubscriber<T> extends ProgressLoadingSubscriber<T> {
|
||||
|
||||
/**
|
||||
* 记录一下请求的url,确定出错的请求是哪个请求
|
||||
*/
|
||||
private String mUrl;
|
||||
|
||||
public TipProgressLoadingSubscriber() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TipProgressLoadingSubscriber(BaseFragment fragment) {
|
||||
super(fragment.getProgressLoader());
|
||||
}
|
||||
|
||||
public TipProgressLoadingSubscriber(IProgressLoader iProgressLoader) {
|
||||
super(iProgressLoader);
|
||||
}
|
||||
|
||||
public TipProgressLoadingSubscriber(@NonNull XHttpRequest req) {
|
||||
this(req.getUrl());
|
||||
}
|
||||
|
||||
public TipProgressLoadingSubscriber(String url) {
|
||||
super();
|
||||
mUrl = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
super.onError(e);
|
||||
XToastUtils.error(e);
|
||||
if (!StringUtils.isEmpty(mUrl)) {
|
||||
Logger.e("网络请求的url:" + mUrl, e);
|
||||
} else {
|
||||
Logger.e(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.http.subscriber;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xhttp2.model.XHttpRequest;
|
||||
import com.xuexiang.xhttp2.subsciber.BaseSubscriber;
|
||||
import com.xuexiang.xutil.common.StringUtils;
|
||||
import com.xuexiang.xutil.common.logger.Logger;
|
||||
|
||||
/**
|
||||
* 带错误toast提示的网络请求订阅
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-11-18 23:10
|
||||
*/
|
||||
public abstract class TipRequestSubscriber<T> extends BaseSubscriber<T> {
|
||||
/**
|
||||
* 记录一下请求的url,确定出错的请求是哪个请求
|
||||
*/
|
||||
private String mUrl;
|
||||
|
||||
public TipRequestSubscriber() {
|
||||
|
||||
}
|
||||
|
||||
public TipRequestSubscriber(@NonNull XHttpRequest req) {
|
||||
this(req.getUrl());
|
||||
}
|
||||
|
||||
public TipRequestSubscriber(String url) {
|
||||
mUrl = url;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
XToastUtils.error(e);
|
||||
if (!StringUtils.isEmpty(mUrl)) {
|
||||
Logger.e("网络请求的url:" + mUrl, e);
|
||||
} else {
|
||||
Logger.e(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.webview;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xrouter.facade.Postcard;
|
||||
import com.xuexiang.xrouter.facade.callback.NavCallback;
|
||||
import com.xuexiang.xrouter.launcher.XRouter;
|
||||
import com.xuexiang.xui.widget.slideback.SlideBack;
|
||||
|
||||
/**
|
||||
* 壳浏览器
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019/1/5 上午12:15
|
||||
*/
|
||||
public class AgentWebActivity extends AppCompatActivity {
|
||||
|
||||
/**
|
||||
* 请求浏览器
|
||||
*
|
||||
* @param url
|
||||
*/
|
||||
public static void goWeb(Context context, final String url) {
|
||||
Intent intent = new Intent(context, AgentWebActivity.class);
|
||||
intent.putExtra(AgentWebFragment.KEY_URL, url);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_agent_web);
|
||||
|
||||
SlideBack.with(this)
|
||||
.haveScroll(true)
|
||||
.callBack(this::finish)
|
||||
.register();
|
||||
|
||||
Uri uri = getIntent().getData();
|
||||
if (uri != null) {
|
||||
XRouter.getInstance().build(uri).navigation(this, new NavCallback() {
|
||||
@Override
|
||||
public void onArrival(Postcard postcard) {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLost(Postcard postcard) {
|
||||
loadUrl(uri.toString());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
String url = getIntent().getStringExtra(AgentWebFragment.KEY_URL);
|
||||
loadUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadUrl(String url) {
|
||||
if (url != null) {
|
||||
openFragment(url);
|
||||
} else {
|
||||
XToastUtils.error("数据出错!");
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private AgentWebFragment mAgentWebFragment;
|
||||
|
||||
private void openFragment(String url) {
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
ft.add(R.id.container_frame_layout, mAgentWebFragment = AgentWebFragment.getInstance(url));
|
||||
ft.commit();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
AgentWebFragment agentWebFragment = mAgentWebFragment;
|
||||
if (agentWebFragment != null) {
|
||||
if (((FragmentKeyDown) agentWebFragment).onFragmentKeyDown(keyCode, event)) {
|
||||
return true;
|
||||
} else {
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
SlideBack.unregister(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
@@ -1,658 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.webview;
|
||||
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebResourceError;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebResourceResponse;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.just.agentweb.action.PermissionInterceptor;
|
||||
import com.just.agentweb.core.AgentWeb;
|
||||
import com.just.agentweb.core.client.MiddlewareWebChromeBase;
|
||||
import com.just.agentweb.core.client.MiddlewareWebClientBase;
|
||||
import com.just.agentweb.core.client.WebListenerManager;
|
||||
import com.just.agentweb.core.web.AbsAgentWebSettings;
|
||||
import com.just.agentweb.core.web.AgentWebConfig;
|
||||
import com.just.agentweb.core.web.IAgentWebSettings;
|
||||
import com.just.agentweb.download.AgentWebDownloader;
|
||||
import com.just.agentweb.download.DefaultDownloadImpl;
|
||||
import com.just.agentweb.download.DownloadListenerAdapter;
|
||||
import com.just.agentweb.download.DownloadingService;
|
||||
import com.just.agentweb.utils.LogUtils;
|
||||
import com.just.agentweb.widget.IWebLayout;
|
||||
import com.kerwin.wumei.MyApp;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xutil.net.JsonUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* 通用WebView页面
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019/1/4 下午11:13
|
||||
*/
|
||||
public class AgentWebFragment extends Fragment implements FragmentKeyDown {
|
||||
public static final String KEY_URL = "com.xuexiang.xuidemo.base.webview.key_url";
|
||||
|
||||
private ImageView mBackImageView;
|
||||
private View mLineView;
|
||||
private ImageView mFinishImageView;
|
||||
private TextView mTitleTextView;
|
||||
private AgentWeb mAgentWeb;
|
||||
private ImageView mMoreImageView;
|
||||
private PopupMenu mPopupMenu;
|
||||
public static final String TAG = AgentWebFragment.class.getSimpleName();
|
||||
private DownloadingService mDownloadingService;
|
||||
|
||||
public static AgentWebFragment getInstance(String url) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(KEY_URL, url);
|
||||
return getInstance(bundle);
|
||||
}
|
||||
|
||||
public static AgentWebFragment getInstance(Bundle bundle) {
|
||||
AgentWebFragment fragment = new AgentWebFragment();
|
||||
if (bundle != null) {
|
||||
fragment.setArguments(bundle);
|
||||
}
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_agentweb, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mAgentWeb = AgentWeb.with(this)
|
||||
//传入AgentWeb的父控件。
|
||||
.setAgentWebParent((LinearLayout) view, -1, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
||||
//设置进度条颜色与高度,-1为默认值,高度为2,单位为dp。
|
||||
.useDefaultIndicator(-1, 3)
|
||||
//设置 IAgentWebSettings。
|
||||
.setAgentWebWebSettings(getSettings())
|
||||
//WebViewClient , 与 WebView 使用一致 ,但是请勿获取WebView调用setWebViewClient(xx)方法了,会覆盖AgentWeb DefaultWebClient,同时相应的中间件也会失效。
|
||||
.setWebViewClient(mWebViewClient)
|
||||
//WebChromeClient
|
||||
.setWebChromeClient(mWebChromeClient)
|
||||
//设置WebChromeClient中间件,支持多个WebChromeClient,AgentWeb 3.0.0 加入。
|
||||
.useMiddlewareWebChrome(getMiddlewareWebChrome())
|
||||
//设置WebViewClient中间件,支持多个WebViewClient, AgentWeb 3.0.0 加入。
|
||||
.useMiddlewareWebClient(getMiddlewareWebClient())
|
||||
//权限拦截 2.0.0 加入。
|
||||
.setPermissionInterceptor(mPermissionInterceptor)
|
||||
//严格模式 Android 4.2.2 以下会放弃注入对象 ,使用AgentWebView没影响。
|
||||
.setSecurityType(AgentWeb.SecurityType.STRICT_CHECK)
|
||||
//自定义UI AgentWeb3.0.0 加入。
|
||||
.setAgentWebUIController(new UIController(getActivity()))
|
||||
//参数1是错误显示的布局,参数2点击刷新控件ID -1表示点击整个布局都刷新, AgentWeb 3.0.0 加入。
|
||||
.setMainFrameErrorView(R.layout.agentweb_error_page, -1)
|
||||
.setWebLayout(getWebLayout())
|
||||
.interceptUnkownUrl()
|
||||
//创建AgentWeb。
|
||||
.createAgentWeb()
|
||||
.ready()//设置 WebSettings。
|
||||
//WebView载入该url地址的页面并显示。
|
||||
.go(getUrl());
|
||||
|
||||
if (MyApp.isDebug()) {
|
||||
AgentWebConfig.debug();
|
||||
}
|
||||
|
||||
// 得到 AgentWeb 最底层的控件
|
||||
addBackgroundChild(mAgentWeb.getWebCreator().getWebParentLayout());
|
||||
|
||||
initView(view);
|
||||
|
||||
// AgentWeb 没有把WebView的功能全面覆盖 ,所以某些设置 AgentWeb 没有提供,请从WebView方面入手设置。
|
||||
mAgentWeb.getWebCreator().getWebView().setOverScrollMode(WebView.OVER_SCROLL_NEVER);
|
||||
}
|
||||
|
||||
protected IWebLayout getWebLayout() {
|
||||
return new WebLayout(getActivity());
|
||||
}
|
||||
|
||||
protected void initView(View view) {
|
||||
mBackImageView = view.findViewById(R.id.iv_back);
|
||||
mLineView = view.findViewById(R.id.view_line);
|
||||
mFinishImageView = view.findViewById(R.id.iv_finish);
|
||||
mTitleTextView = view.findViewById(R.id.toolbar_title);
|
||||
mBackImageView.setOnClickListener(mOnClickListener);
|
||||
mFinishImageView.setOnClickListener(mOnClickListener);
|
||||
mMoreImageView = view.findViewById(R.id.iv_more);
|
||||
mMoreImageView.setOnClickListener(mOnClickListener);
|
||||
pageNavigator(View.GONE);
|
||||
}
|
||||
|
||||
protected void addBackgroundChild(FrameLayout frameLayout) {
|
||||
TextView textView = new TextView(frameLayout.getContext());
|
||||
textView.setText("技术由 AgentWeb 提供");
|
||||
textView.setTextSize(16);
|
||||
textView.setTextColor(Color.parseColor("#727779"));
|
||||
frameLayout.setBackgroundColor(Color.parseColor("#272b2d"));
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(-2, -2);
|
||||
params.gravity = Gravity.CENTER_HORIZONTAL;
|
||||
final float scale = frameLayout.getContext().getResources().getDisplayMetrics().density;
|
||||
params.topMargin = (int) (15 * scale + 0.5f);
|
||||
frameLayout.addView(textView, 0, params);
|
||||
}
|
||||
|
||||
|
||||
private void pageNavigator(int tag) {
|
||||
mBackImageView.setVisibility(tag);
|
||||
mLineView.setVisibility(tag);
|
||||
}
|
||||
|
||||
private View.OnClickListener mOnClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.iv_back:
|
||||
// true表示AgentWeb处理了该事件
|
||||
if (!mAgentWeb.back()) {
|
||||
AgentWebFragment.this.getActivity().finish();
|
||||
}
|
||||
break;
|
||||
case R.id.iv_finish:
|
||||
AgentWebFragment.this.getActivity().finish();
|
||||
break;
|
||||
case R.id.iv_more:
|
||||
showPoPup(v);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//========================================//
|
||||
|
||||
/**
|
||||
* 权限申请拦截器
|
||||
*/
|
||||
protected PermissionInterceptor mPermissionInterceptor = new PermissionInterceptor() {
|
||||
/**
|
||||
* PermissionInterceptor 能达到 url1 允许授权, url2 拒绝授权的效果。
|
||||
* @param url
|
||||
* @param permissions
|
||||
* @param action
|
||||
* @return true 该Url对应页面请求权限进行拦截 ,false 表示不拦截。
|
||||
*/
|
||||
@Override
|
||||
public boolean intercept(String url, String[] permissions, String action) {
|
||||
Log.i(TAG, "mUrl:" + url + " permission:" + JsonUtil.toJson(permissions) + " action:" + action);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
//=====================下载============================//
|
||||
|
||||
/**
|
||||
* 更新于 AgentWeb 4.0.0,下载监听
|
||||
*/
|
||||
protected DownloadListenerAdapter mDownloadListenerAdapter = new DownloadListenerAdapter() {
|
||||
/**
|
||||
*
|
||||
* @param url 下载链接
|
||||
* @param userAgent UserAgent
|
||||
* @param contentDisposition ContentDisposition
|
||||
* @param mimetype 资源的媒体类型
|
||||
* @param contentLength 文件长度
|
||||
* @param extra 下载配置 , 用户可以通过 Extra 修改下载icon , 关闭进度条 , 是否强制下载。
|
||||
* @return true 表示用户处理了该下载事件 , false 交给 AgentWeb 下载
|
||||
*/
|
||||
@Override
|
||||
public boolean onStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength, AgentWebDownloader.Extra extra) {
|
||||
LogUtils.i(TAG, "onStart:" + url);
|
||||
// 是否开启断点续传
|
||||
extra.setOpenBreakPointDownload(true)
|
||||
//下载通知的icon
|
||||
.setIcon(R.drawable.ic_file_download_black_24dp)
|
||||
// 连接的超时时间
|
||||
.setConnectTimeOut(6000)
|
||||
// 以8KB位单位,默认60s ,如果60s内无法从网络流中读满8KB数据,则抛出异常
|
||||
.setBlockMaxTime(10 * 60 * 1000)
|
||||
// 下载的超时时间
|
||||
.setDownloadTimeOut(Long.MAX_VALUE)
|
||||
// 串行下载更节省资源哦
|
||||
.setParallelDownload(false)
|
||||
// false 关闭进度通知
|
||||
.setEnableIndicator(true)
|
||||
// 自定义请求头
|
||||
.addHeader("Cookie", "xx")
|
||||
// 下载完成自动打开
|
||||
.setAutoOpen(true)
|
||||
// 强制下载,不管网络网络类型
|
||||
.setForceDownload(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 不需要暂停或者停止下载该方法可以不必实现
|
||||
* @param url
|
||||
* @param downloadingService 用户可以通过 DownloadingService#shutdownNow 终止下载
|
||||
*/
|
||||
@Override
|
||||
public void onBindService(String url, DownloadingService downloadingService) {
|
||||
super.onBindService(url, downloadingService);
|
||||
mDownloadingService = downloadingService;
|
||||
LogUtils.i(TAG, "onBindService:" + url + " DownloadingService:" + downloadingService);
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调onUnbindService方法,让用户释放掉 DownloadingService。
|
||||
* @param url
|
||||
* @param downloadingService
|
||||
*/
|
||||
@Override
|
||||
public void onUnbindService(String url, DownloadingService downloadingService) {
|
||||
super.onUnbindService(url, downloadingService);
|
||||
mDownloadingService = null;
|
||||
LogUtils.i(TAG, "onUnbindService:" + url);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param url 下载链接
|
||||
* @param loaded 已经下载的长度
|
||||
* @param length 文件的总大小
|
||||
* @param usedTime 耗时 ,单位ms
|
||||
* 注意该方法回调在子线程 ,线程名 AsyncTask #XX 或者 AgentWeb # XX
|
||||
*/
|
||||
@Override
|
||||
public void onProgress(String url, long loaded, long length, long usedTime) {
|
||||
int mProgress = (int) ((loaded) / Float.valueOf(length) * 100);
|
||||
LogUtils.i(TAG, "onProgress:" + mProgress);
|
||||
super.onProgress(url, loaded, length, usedTime);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param path 文件的绝对路径
|
||||
* @param url 下载地址
|
||||
* @param throwable 如果异常,返回给用户异常
|
||||
* @return true 表示用户处理了下载完成后续的事件 ,false 默认交给AgentWeb 处理
|
||||
*/
|
||||
@Override
|
||||
public boolean onResult(String path, String url, Throwable throwable) {
|
||||
//下载成功
|
||||
if (null == throwable) {
|
||||
//do you work
|
||||
} else {//下载失败
|
||||
|
||||
}
|
||||
// true 不会发出下载完成的通知 , 或者打开文件
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return IAgentWebSettings
|
||||
*/
|
||||
public IAgentWebSettings getSettings() {
|
||||
return new AbsAgentWebSettings() {
|
||||
private AgentWeb mAgentWeb;
|
||||
|
||||
@Override
|
||||
protected void bindAgentWebSupport(AgentWeb agentWeb) {
|
||||
this.mAgentWeb = agentWeb;
|
||||
}
|
||||
|
||||
/**
|
||||
* AgentWeb 4.0.0 内部删除了 DownloadListener 监听 ,以及相关API ,将 Download 部分完全抽离出来独立一个库,
|
||||
* 如果你需要使用 AgentWeb Download 部分 , 请依赖上 compile 'com.just.agentweb:download:4.0.0 ,
|
||||
* 如果你需要监听下载结果,请自定义 AgentWebSetting , New 出 DefaultDownloadImpl,传入DownloadListenerAdapter
|
||||
* 实现进度或者结果监听,例如下面这个例子,如果你不需要监听进度,或者下载结果,下面 setDownloader 的例子可以忽略。
|
||||
* @param webView
|
||||
* @param downloadListener
|
||||
* @return WebListenerManager
|
||||
*/
|
||||
@Override
|
||||
public WebListenerManager setDownloader(WebView webView, android.webkit.DownloadListener downloadListener) {
|
||||
return super.setDownloader(webView,
|
||||
DefaultDownloadImpl
|
||||
.create(getActivity(),
|
||||
webView,
|
||||
mDownloadListenerAdapter,
|
||||
mDownloadListenerAdapter,
|
||||
this.mAgentWeb.getPermissionInterceptor()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//===================WebChromeClient 和 WebViewClient===========================//
|
||||
/**
|
||||
* 页面空白,请检查scheme是否加上, scheme://host:port/path?query&query 。
|
||||
*
|
||||
* @return mUrl
|
||||
*/
|
||||
public String getUrl() {
|
||||
String target = "";
|
||||
Bundle bundle = getArguments();
|
||||
if (bundle != null) {
|
||||
target = bundle.getString(KEY_URL);
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(target)) {
|
||||
target = "https://github.com/xuexiangjys";
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
protected WebChromeClient mWebChromeClient = new WebChromeClient() {
|
||||
@Override
|
||||
public void onProgressChanged(WebView view, int newProgress) {
|
||||
Log.i(TAG, "onProgressChanged:" + newProgress + " view:" + view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivedTitle(WebView view, String title) {
|
||||
super.onReceivedTitle(view, title);
|
||||
if (mTitleTextView != null && !TextUtils.isEmpty(title)) {
|
||||
if (title.length() > 10) {
|
||||
title = title.substring(0, 10).concat("...");
|
||||
}
|
||||
mTitleTextView.setText(title);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
protected WebViewClient mWebViewClient = new WebViewClient() {
|
||||
|
||||
private HashMap<String, Long> timer = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
|
||||
super.onReceivedError(view, request, error);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
||||
return shouldOverrideUrlLoading(view, request.getUrl() + "");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
||||
return super.shouldInterceptRequest(view, request);
|
||||
}
|
||||
|
||||
//
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(final WebView view, String url) {
|
||||
//intent:// scheme的处理 如果返回false , 则交给 DefaultWebClient 处理 , 默认会打开该Activity , 如果Activity不存在则跳到应用市场上去. true 表示拦截
|
||||
//例如优酷视频播放 ,intent://play?...package=com.youku.phone;end;
|
||||
//优酷想唤起自己应用播放该视频 , 下面拦截地址返回 true 则会在应用内 H5 播放 ,禁止优酷唤起播放该视频, 如果返回 false , DefaultWebClient 会根据intent 协议处理 该地址 , 首先匹配该应用存不存在 ,如果存在 , 唤起该应用播放 , 如果不存在 , 则跳到应用市场下载该应用 .
|
||||
if (url.startsWith("intent://") && url.contains("com.youku.phone")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
||||
Log.i(TAG, "mUrl:" + url + " onPageStarted target:" + getUrl());
|
||||
timer.put(url, System.currentTimeMillis());
|
||||
if (url.equals(getUrl())) {
|
||||
pageNavigator(View.GONE);
|
||||
} else {
|
||||
pageNavigator(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
super.onPageFinished(view, url);
|
||||
|
||||
if (timer.get(url) != null) {
|
||||
long overTime = System.currentTimeMillis();
|
||||
Long startTime = timer.get(url);
|
||||
Log.i(TAG, " page mUrl:" + url + " used time:" + (overTime - startTime));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
|
||||
super.onReceivedHttpError(view, request, errorResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
||||
super.onReceivedError(view, errorCode, description, failingUrl);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
|
||||
//========================菜单功能================================//
|
||||
|
||||
/**
|
||||
* 打开浏览器
|
||||
*
|
||||
* @param targetUrl 外部浏览器打开的地址
|
||||
*/
|
||||
private void openBrowser(String targetUrl) {
|
||||
if (TextUtils.isEmpty(targetUrl) || targetUrl.startsWith("file://")) {
|
||||
XToastUtils.toast(targetUrl + " 该链接无法使用浏览器打开。");
|
||||
return;
|
||||
}
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("android.intent.action.VIEW");
|
||||
Uri uri = Uri.parse(targetUrl);
|
||||
intent.setData(uri);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 显示更多菜单
|
||||
*
|
||||
* @param view 菜单依附在该View下面
|
||||
*/
|
||||
private void showPoPup(View view) {
|
||||
if (mPopupMenu == null) {
|
||||
mPopupMenu = new PopupMenu(getContext(), view);
|
||||
mPopupMenu.inflate(R.menu.menu_toolbar_web);
|
||||
mPopupMenu.setOnMenuItemClickListener(mOnMenuItemClickListener);
|
||||
}
|
||||
mPopupMenu.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单事件
|
||||
*/
|
||||
private PopupMenu.OnMenuItemClickListener mOnMenuItemClickListener = new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.refresh:
|
||||
if (mAgentWeb != null) {
|
||||
mAgentWeb.getUrlLoader().reload(); // 刷新
|
||||
}
|
||||
return true;
|
||||
|
||||
case R.id.copy:
|
||||
if (mAgentWeb != null) {
|
||||
toCopy(getContext(), mAgentWeb.getWebCreator().getWebView().getUrl());
|
||||
}
|
||||
return true;
|
||||
case R.id.default_browser:
|
||||
if (mAgentWeb != null) {
|
||||
openBrowser(mAgentWeb.getWebCreator().getWebView().getUrl());
|
||||
}
|
||||
return true;
|
||||
case R.id.share:
|
||||
if (mAgentWeb != null) {
|
||||
shareWebUrl(mAgentWeb.getWebCreator().getWebView().getUrl());
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 分享网页链接
|
||||
*
|
||||
* @param url 网页链接
|
||||
*/
|
||||
private void shareWebUrl(String url) {
|
||||
Intent shareIntent = new Intent();
|
||||
shareIntent.setAction(Intent.ACTION_SEND);
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, url);
|
||||
shareIntent.setType("text/plain");
|
||||
//设置分享列表的标题,并且每次都显示分享列表
|
||||
startActivity(Intent.createChooser(shareIntent, "分享到"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 复制字符串
|
||||
*
|
||||
* @param context
|
||||
* @param text
|
||||
*/
|
||||
private void toCopy(Context context, String text) {
|
||||
ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
if (manager == null) {
|
||||
return;
|
||||
}
|
||||
manager.setPrimaryClip(ClipData.newPlainText(null, text));
|
||||
}
|
||||
|
||||
//===================生命周期管理===========================//
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
mAgentWeb.getWebLifeCycle().onResume();//恢复
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
mAgentWeb.getWebLifeCycle().onPause(); //暂停应用内所有WebView , 调用mWebView.resumeTimers();/mAgentWeb.getWebLifeCycle().onResume(); 恢复。
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onFragmentKeyDown(int keyCode, KeyEvent event) {
|
||||
return mAgentWeb.handleKeyEvent(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
mAgentWeb.getWebLifeCycle().onDestroy();
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
//===================中间键===========================//
|
||||
|
||||
|
||||
/**
|
||||
* MiddlewareWebClientBase 是 AgentWeb 3.0.0 提供一个强大的功能,
|
||||
* 如果用户需要使用 AgentWeb 提供的功能, 不想重写 WebClientView方
|
||||
* 法覆盖AgentWeb提供的功能,那么 MiddlewareWebClientBase 是一个
|
||||
* 不错的选择 。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected MiddlewareWebClientBase getMiddlewareWebClient() {
|
||||
return new MiddlewareWebViewClient() {
|
||||
/**
|
||||
*
|
||||
* @param view
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
// 拦截 url,不执行 DefaultWebClient#shouldOverrideUrlLoading
|
||||
if (url.startsWith("agentweb")) {
|
||||
Log.i(TAG, "agentweb scheme ~");
|
||||
return true;
|
||||
}
|
||||
// 执行 DefaultWebClient#shouldOverrideUrlLoading
|
||||
if (super.shouldOverrideUrlLoading(view, url)) {
|
||||
return true;
|
||||
}
|
||||
// do you work
|
||||
return false;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
||||
return super.shouldOverrideUrlLoading(view, request);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected MiddlewareWebChromeBase getMiddlewareWebChrome() {
|
||||
return new MiddlewareChromeClient() {
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.webview;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.just.agentweb.core.AgentWeb;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
|
||||
/**
|
||||
* 基础web
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019/5/28 10:22
|
||||
*/
|
||||
public abstract class BaseWebViewFragment extends BaseFragment {
|
||||
|
||||
protected AgentWeb mAgentWeb;
|
||||
|
||||
//===================生命周期管理===========================//
|
||||
@Override
|
||||
public void onResume() {
|
||||
if (mAgentWeb != null) {
|
||||
//恢复
|
||||
mAgentWeb.getWebLifeCycle().onResume();
|
||||
}
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if (mAgentWeb != null) {
|
||||
//暂停应用内所有WebView , 调用mWebView.resumeTimers();/mAgentWeb.getWebLifeCycle().onResume(); 恢复。
|
||||
mAgentWeb.getWebLifeCycle().onPause();
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
return mAgentWeb != null && mAgentWeb.handleKeyEvent(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (mAgentWeb != null) {
|
||||
mAgentWeb.destroy();
|
||||
}
|
||||
super.onDestroyView();
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.webview;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019/1/4 下午11:32
|
||||
*/
|
||||
public interface FragmentKeyDown {
|
||||
|
||||
/**
|
||||
* fragment按键监听
|
||||
* @param keyCode
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
boolean onFragmentKeyDown(int keyCode, KeyEvent event);
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.webview;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.webkit.WebView;
|
||||
|
||||
/**
|
||||
* 修复 Android 5.0 & 5.1 打开 WebView 闪退问题:
|
||||
* 参阅 https://stackoverflow.com/questions/41025200/android-view-inflateexception-error-inflating-class-android-webkit-webview
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class LollipopFixedWebView extends WebView {
|
||||
public LollipopFixedWebView(Context context) {
|
||||
super(getFixedContext(context));
|
||||
}
|
||||
|
||||
public LollipopFixedWebView(Context context, AttributeSet attrs) {
|
||||
super(getFixedContext(context), attrs);
|
||||
}
|
||||
|
||||
public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(getFixedContext(context), attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(getFixedContext(context), attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
|
||||
super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing);
|
||||
}
|
||||
|
||||
public static Context getFixedContext(Context context) {
|
||||
if (isLollipopWebViewBug()) {
|
||||
// Avoid crashing on Android 5 and 6 (API level 21 to 23)
|
||||
return context.createConfigurationContext(new Configuration());
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
public static boolean isLollipopWebViewBug() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Build.VERSION.SDK_INT < Build.VERSION_CODES.M;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.webview;
|
||||
|
||||
import android.util.Log;
|
||||
import android.webkit.JsResult;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.just.agentweb.core.client.MiddlewareWebChromeBase;
|
||||
|
||||
/**
|
||||
* WebChrome(WebChromeClient主要辅助WebView处理JavaScript的对话框、网站图片、网站title、加载进度等)中间件
|
||||
* 【浏览器】
|
||||
* @author xuexiang
|
||||
* @since 2019/1/4 下午11:31
|
||||
*/
|
||||
public class MiddlewareChromeClient extends MiddlewareWebChromeBase {
|
||||
|
||||
public MiddlewareChromeClient() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
|
||||
Log.i("Info", "onJsAlert:" + url);
|
||||
return super.onJsAlert(view, url, message, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(WebView view, int newProgress) {
|
||||
super.onProgressChanged(view, newProgress);
|
||||
Log.i("Info", "onProgressChanged:");
|
||||
}
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.webview;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebResourceResponse;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import com.just.agentweb.core.client.MiddlewareWebClientBase;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.xuexiang.xui.utils.ResUtils;
|
||||
|
||||
/**
|
||||
* 【网络请求、加载】
|
||||
* WebClient(WebViewClient 这个类主要帮助WebView处理各种通知、url加载,请求时间的)中间件
|
||||
* <p>
|
||||
* <p>
|
||||
* 方法的执行顺序,例如下面用了7个中间件一个 WebViewClient
|
||||
* <p>
|
||||
* .useMiddlewareWebClient(getMiddlewareWebClient()) // 1
|
||||
* .useMiddlewareWebClient(getMiddlewareWebClient()) // 2
|
||||
* .useMiddlewareWebClient(getMiddlewareWebClient()) // 3
|
||||
* .useMiddlewareWebClient(getMiddlewareWebClient()) // 4
|
||||
* .useMiddlewareWebClient(getMiddlewareWebClient()) // 5
|
||||
* .useMiddlewareWebClient(getMiddlewareWebClient()) // 6
|
||||
* .useMiddlewareWebClient(getMiddlewareWebClient()) // 7
|
||||
* DefaultWebClient // 8
|
||||
* .setWebViewClient(mWebViewClient) // 9
|
||||
* <p>
|
||||
* <p>
|
||||
* 典型的洋葱模型
|
||||
* 对象内部的方法执行顺序: 1->2->3->4->5->6->7->8->9->8->7->6->5->4->3->2->1
|
||||
* <p>
|
||||
* <p>
|
||||
* 中断中间件的执行, 删除super.methodName(...) 这行即可
|
||||
* <p>
|
||||
* 这里主要是做去广告的工作
|
||||
*/
|
||||
public class MiddlewareWebViewClient extends MiddlewareWebClientBase {
|
||||
|
||||
public MiddlewareWebViewClient() {
|
||||
}
|
||||
|
||||
private static int count = 1;
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
||||
Log.i("Info", "MiddlewareWebViewClient -- > shouldOverrideUrlLoading:" + request.getUrl().toString() + " c:" + (count++));
|
||||
if (shouldOverrideUrlLoadingByApp(view, request.getUrl().toString())) {
|
||||
return true;
|
||||
}
|
||||
return super.shouldOverrideUrlLoading(view, request);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
Log.i("Info", "MiddlewareWebViewClient -- > shouldOverrideUrlLoading:" + url + " c:" + (count++));
|
||||
if (shouldOverrideUrlLoadingByApp(view, url)) {
|
||||
return true;
|
||||
}
|
||||
return super.shouldOverrideUrlLoading(view, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
|
||||
url = url.toLowerCase();
|
||||
if (!hasAdUrl(url)) {
|
||||
//正常加载
|
||||
return super.shouldInterceptRequest(view, url);
|
||||
} else {
|
||||
//含有广告资源屏蔽请求
|
||||
return new WebResourceResponse(null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
||||
String url = request.getUrl().toString().toLowerCase();
|
||||
if (!hasAdUrl(url)) {
|
||||
//正常加载
|
||||
return super.shouldInterceptRequest(view, request);
|
||||
} else {
|
||||
//含有广告资源屏蔽请求
|
||||
return new WebResourceResponse(null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否存在广告的链接
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
private static boolean hasAdUrl(String url) {
|
||||
String[] adUrls = ResUtils.getStringArray(R.array.adBlockUrl);
|
||||
for (String adUrl : adUrls) {
|
||||
if (url.contains(adUrl)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据url的scheme处理跳转第三方app的业务,true代表拦截,false代表不拦截
|
||||
*/
|
||||
private boolean shouldOverrideUrlLoadingByApp(WebView webView, final String url) {
|
||||
if (url.startsWith("http") || url.startsWith("https") || url.startsWith("ftp")) {
|
||||
//不拦截http, https, ftp的请求
|
||||
Uri uri = Uri.parse(url);
|
||||
if (uri != null && !(WebViewInterceptDialog.APP_LINK_HOST.equals(uri.getHost())
|
||||
//防止xui官网被拦截
|
||||
&& url.contains("xpage"))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
WebViewInterceptDialog.show(url);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.webview;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.just.agentweb.core.web.AgentWebUIControllerImplBase;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* 如果你需要修改某一个AgentWeb 内部的某一个弹窗 ,请看下面的例子
|
||||
* 注意写法一定要参照 DefaultUIController 的写法 ,因为UI自由定制,但是回调的方式是固定的,并且一定要回调。
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-10-30 23:18
|
||||
*/
|
||||
public class UIController extends AgentWebUIControllerImplBase {
|
||||
|
||||
private WeakReference<Activity> mActivity;
|
||||
|
||||
public UIController(Activity activity) {
|
||||
mActivity = new WeakReference<>(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowMessage(String message, String from) {
|
||||
super.onShowMessage(message, from);
|
||||
Log.i(TAG, "message:" + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectItemsPrompt(WebView view, String url, String[] items, Handler.Callback callback) {
|
||||
// 使用默认的UI
|
||||
super.onSelectItemsPrompt(view, url, items, callback);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.webview;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.just.agentweb.widget.IWebLayout;
|
||||
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
|
||||
import com.kerwin.wumei.R;
|
||||
|
||||
/**
|
||||
* 定义支持下来回弹的WebView
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019/1/5 上午2:01
|
||||
*/
|
||||
public class WebLayout implements IWebLayout {
|
||||
|
||||
private final SmartRefreshLayout mSmartRefreshLayout;
|
||||
private WebView mWebView;
|
||||
|
||||
public WebLayout(Activity activity) {
|
||||
mSmartRefreshLayout = (SmartRefreshLayout) LayoutInflater.from(activity).inflate(R.layout.fragment_pulldown_web, null);
|
||||
mWebView = mSmartRefreshLayout.findViewById(R.id.webView);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewGroup getLayout() {
|
||||
return mSmartRefreshLayout;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public WebView getWebView() {
|
||||
return mWebView;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.webview;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xui.utils.ResUtils;
|
||||
import com.xuexiang.xui.widget.dialog.DialogLoader;
|
||||
import com.xuexiang.xutil.XUtil;
|
||||
import com.xuexiang.xutil.app.ActivityUtils;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* WebView拦截提示
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-10-21 9:51
|
||||
*/
|
||||
public class WebViewInterceptDialog extends AppCompatActivity implements DialogInterface.OnDismissListener {
|
||||
|
||||
private static final String KEY_INTERCEPT_URL = "key_intercept_url";
|
||||
|
||||
// TODO: 2019-10-30 这里修改你的applink
|
||||
public static final String APP_LINK_HOST = "xuexiangjys.club";
|
||||
public static final String APP_LINK_ACTION = "com.xuexiang.xui.applink";
|
||||
|
||||
|
||||
/**
|
||||
* 显示WebView拦截提示
|
||||
*
|
||||
* @param url 需要拦截处理的url
|
||||
*/
|
||||
public static void show(String url) {
|
||||
ActivityUtils.startActivity(WebViewInterceptDialog.class, KEY_INTERCEPT_URL, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
String url = getIntent().getStringExtra(KEY_INTERCEPT_URL);
|
||||
|
||||
DialogLoader.getInstance().showConfirmDialog(
|
||||
this,
|
||||
getOpenTitle(url),
|
||||
ResUtils.getString(R.string.lab_yes),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
if (isAppLink(url)) {
|
||||
openAppLink(this, url);
|
||||
} else {
|
||||
openApp(url);
|
||||
}
|
||||
},
|
||||
ResUtils.getString(R.string.lab_no),
|
||||
(dialog, which) -> dialog.dismiss()
|
||||
).setOnDismissListener(this);
|
||||
|
||||
}
|
||||
|
||||
private String getOpenTitle(String url) {
|
||||
String scheme = getScheme(url);
|
||||
if ("mqqopensdkapi".equals(scheme)) {
|
||||
return "是否允许页面打开\"QQ\"?";
|
||||
} else {
|
||||
return ResUtils.getString(R.string.lab_open_third_app);
|
||||
}
|
||||
}
|
||||
|
||||
private String getScheme(String url) {
|
||||
try {
|
||||
Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
|
||||
return intent.getScheme();
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private boolean isAppLink(String url) {
|
||||
Uri uri = Uri.parse(url);
|
||||
return uri != null
|
||||
&& APP_LINK_HOST.equals(uri.getHost())
|
||||
&& (url.startsWith("http") || url.startsWith("https"));
|
||||
}
|
||||
|
||||
|
||||
private void openApp(String url) {
|
||||
Intent intent;
|
||||
try {
|
||||
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
XUtil.getContext().startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
XToastUtils.error("您所打开的第三方App未安装!");
|
||||
}
|
||||
}
|
||||
|
||||
private void openAppLink(Context context, String url) {
|
||||
try {
|
||||
Intent intent = new Intent(APP_LINK_ACTION);
|
||||
intent.setData(Uri.parse(url));
|
||||
context.startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
XToastUtils.error("您所打开的第三方App未安装!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -1,677 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.core.webview;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebResourceError;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebResourceResponse;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.just.agentweb.action.PermissionInterceptor;
|
||||
import com.just.agentweb.core.AgentWeb;
|
||||
import com.just.agentweb.core.client.DefaultWebClient;
|
||||
import com.just.agentweb.core.client.MiddlewareWebChromeBase;
|
||||
import com.just.agentweb.core.client.MiddlewareWebClientBase;
|
||||
import com.just.agentweb.core.client.WebListenerManager;
|
||||
import com.just.agentweb.core.web.AbsAgentWebSettings;
|
||||
import com.just.agentweb.core.web.AgentWebConfig;
|
||||
import com.just.agentweb.core.web.IAgentWebSettings;
|
||||
import com.just.agentweb.download.AgentWebDownloader;
|
||||
import com.just.agentweb.download.DefaultDownloadImpl;
|
||||
import com.just.agentweb.download.DownloadListenerAdapter;
|
||||
import com.just.agentweb.download.DownloadingService;
|
||||
import com.just.agentweb.widget.IWebLayout;
|
||||
import com.kerwin.wumei.MyApp;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xaop.annotation.SingleClick;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xpage.base.XPageActivity;
|
||||
import com.xuexiang.xpage.base.XPageFragment;
|
||||
import com.xuexiang.xpage.core.PageOption;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xutil.common.logger.Logger;
|
||||
import com.xuexiang.xutil.net.JsonUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* 使用XPageFragment
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-05-26 18:15
|
||||
*/
|
||||
@Page(params = {AgentWebFragment.KEY_URL})
|
||||
public class XPageWebViewFragment extends BaseFragment {
|
||||
|
||||
@BindView(R.id.iv_back)
|
||||
AppCompatImageView mIvBack;
|
||||
@BindView(R.id.view_line)
|
||||
View mLineView;
|
||||
@BindView(R.id.toolbar_title)
|
||||
TextView mTvTitle;
|
||||
|
||||
protected AgentWeb mAgentWeb;
|
||||
private PopupMenu mPopupMenu;
|
||||
|
||||
private DownloadingService mDownloadingService;
|
||||
|
||||
/**
|
||||
* 打开网页
|
||||
*
|
||||
* @param xPageActivity
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static Fragment openUrl(XPageActivity xPageActivity, String url) {
|
||||
return PageOption.to(XPageWebViewFragment.class)
|
||||
.putString(AgentWebFragment.KEY_URL, url)
|
||||
.open(xPageActivity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开网页
|
||||
*
|
||||
* @param fragment
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static Fragment openUrl(XPageFragment fragment, String url) {
|
||||
return PageOption.to(XPageWebViewFragment.class)
|
||||
.setNewActivity(true)
|
||||
.putString(AgentWebFragment.KEY_URL, url)
|
||||
.open(fragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_agentweb;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
mAgentWeb = AgentWeb.with(this)
|
||||
//传入AgentWeb的父控件。
|
||||
.setAgentWebParent((LinearLayout) getRootView(), -1, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
||||
//设置进度条颜色与高度,-1为默认值,高度为2,单位为dp。
|
||||
.useDefaultIndicator(-1, 3)
|
||||
//设置 IAgentWebSettings。
|
||||
.setAgentWebWebSettings(getSettings())
|
||||
//WebViewClient , 与 WebView 使用一致 ,但是请勿获取WebView调用setWebViewClient(xx)方法了,会覆盖AgentWeb DefaultWebClient,同时相应的中间件也会失效。
|
||||
.setWebViewClient(mWebViewClient)
|
||||
//WebChromeClient
|
||||
.setWebChromeClient(mWebChromeClient)
|
||||
//设置WebChromeClient中间件,支持多个WebChromeClient,AgentWeb 3.0.0 加入。
|
||||
.useMiddlewareWebChrome(getMiddlewareWebChrome())
|
||||
//设置WebViewClient中间件,支持多个WebViewClient, AgentWeb 3.0.0 加入。
|
||||
.useMiddlewareWebClient(getMiddlewareWebClient())
|
||||
//权限拦截 2.0.0 加入。
|
||||
.setPermissionInterceptor(mPermissionInterceptor)
|
||||
//严格模式 Android 4.2.2 以下会放弃注入对象 ,使用AgentWebView没影响。
|
||||
.setSecurityType(AgentWeb.SecurityType.STRICT_CHECK)
|
||||
//自定义UI AgentWeb3.0.0 加入。
|
||||
.setAgentWebUIController(new UIController(getActivity()))
|
||||
//参数1是错误显示的布局,参数2点击刷新控件ID -1表示点击整个布局都刷新, AgentWeb 3.0.0 加入。
|
||||
.setMainFrameErrorView(R.layout.agentweb_error_page, -1)
|
||||
.setWebLayout(getWebLayout())
|
||||
//打开其他页面时,弹窗质询用户前往其他应用 AgentWeb 3.0.0 加入。
|
||||
.setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.DISALLOW)
|
||||
//拦截找不到相关页面的Url AgentWeb 3.0.0 加入。
|
||||
.interceptUnkownUrl()
|
||||
//创建AgentWeb。
|
||||
.createAgentWeb()
|
||||
.ready()//设置 WebSettings。
|
||||
//WebView载入该url地址的页面并显示。
|
||||
.go(getUrl());
|
||||
|
||||
if (MyApp.isDebug()) {
|
||||
AgentWebConfig.debug();
|
||||
}
|
||||
|
||||
pageNavigator(View.GONE);
|
||||
// 得到 AgentWeb 最底层的控件
|
||||
addBackgroundChild(mAgentWeb.getWebCreator().getWebParentLayout());
|
||||
|
||||
// AgentWeb 没有把WebView的功能全面覆盖 ,所以某些设置 AgentWeb 没有提供,请从WebView方面入手设置。
|
||||
mAgentWeb.getWebCreator().getWebView().setOverScrollMode(WebView.OVER_SCROLL_NEVER);
|
||||
}
|
||||
|
||||
protected IWebLayout getWebLayout() {
|
||||
return new WebLayout(getActivity());
|
||||
}
|
||||
|
||||
protected void addBackgroundChild(FrameLayout frameLayout) {
|
||||
TextView textView = new TextView(frameLayout.getContext());
|
||||
textView.setText("技术由 AgentWeb 提供");
|
||||
textView.setTextSize(16);
|
||||
textView.setTextColor(Color.parseColor("#727779"));
|
||||
frameLayout.setBackgroundColor(Color.parseColor("#272b2d"));
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(-2, -2);
|
||||
params.gravity = Gravity.CENTER_HORIZONTAL;
|
||||
final float scale = frameLayout.getContext().getResources().getDisplayMetrics().density;
|
||||
params.topMargin = (int) (15 * scale + 0.5f);
|
||||
frameLayout.addView(textView, 0, params);
|
||||
}
|
||||
|
||||
|
||||
private void pageNavigator(int tag) {
|
||||
//返回的导航按钮
|
||||
mIvBack.setVisibility(tag);
|
||||
mLineView.setVisibility(tag);
|
||||
}
|
||||
|
||||
@SingleClick
|
||||
@OnClick({R.id.iv_back, R.id.iv_finish, R.id.iv_more})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.iv_back:
|
||||
// true表示AgentWeb处理了该事件
|
||||
if (!mAgentWeb.back()) {
|
||||
popToBack();
|
||||
}
|
||||
break;
|
||||
case R.id.iv_finish:
|
||||
popToBack();
|
||||
break;
|
||||
case R.id.iv_more:
|
||||
showPoPup(view);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//=====================下载============================//
|
||||
|
||||
/**
|
||||
* 更新于 AgentWeb 4.0.0,下载监听
|
||||
*/
|
||||
protected DownloadListenerAdapter mDownloadListenerAdapter = new DownloadListenerAdapter() {
|
||||
/**
|
||||
*
|
||||
* @param url 下载链接
|
||||
* @param userAgent UserAgent
|
||||
* @param contentDisposition ContentDisposition
|
||||
* @param mimeType 资源的媒体类型
|
||||
* @param contentLength 文件长度
|
||||
* @param extra 下载配置 , 用户可以通过 Extra 修改下载icon , 关闭进度条 , 是否强制下载。
|
||||
* @return true 表示用户处理了该下载事件 , false 交给 AgentWeb 下载
|
||||
*/
|
||||
@Override
|
||||
public boolean onStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength, AgentWebDownloader.Extra extra) {
|
||||
Logger.i("onStart:" + url);
|
||||
// 是否开启断点续传
|
||||
extra.setOpenBreakPointDownload(true)
|
||||
//下载通知的icon
|
||||
.setIcon(R.drawable.ic_file_download_black_24dp)
|
||||
// 连接的超时时间
|
||||
.setConnectTimeOut(6000)
|
||||
// 以8KB位单位,默认60s ,如果60s内无法从网络流中读满8KB数据,则抛出异常
|
||||
.setBlockMaxTime(10 * 60 * 1000)
|
||||
// 下载的超时时间
|
||||
.setDownloadTimeOut(Long.MAX_VALUE)
|
||||
// 串行下载更节省资源哦
|
||||
.setParallelDownload(false)
|
||||
// false 关闭进度通知
|
||||
.setEnableIndicator(true)
|
||||
// 自定义请求头
|
||||
.addHeader("Cookie", "xx")
|
||||
// 下载完成自动打开
|
||||
.setAutoOpen(true)
|
||||
// 强制下载,不管网络网络类型
|
||||
.setForceDownload(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 不需要暂停或者停止下载该方法可以不必实现
|
||||
* @param url
|
||||
* @param downloadingService 用户可以通过 DownloadingService#shutdownNow 终止下载
|
||||
*/
|
||||
@Override
|
||||
public void onBindService(String url, DownloadingService downloadingService) {
|
||||
super.onBindService(url, downloadingService);
|
||||
mDownloadingService = downloadingService;
|
||||
Logger.i("onBindService:" + url + " DownloadingService:" + downloadingService);
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调onUnbindService方法,让用户释放掉 DownloadingService。
|
||||
* @param url
|
||||
* @param downloadingService
|
||||
*/
|
||||
@Override
|
||||
public void onUnbindService(String url, DownloadingService downloadingService) {
|
||||
super.onUnbindService(url, downloadingService);
|
||||
mDownloadingService = null;
|
||||
Logger.i("onUnbindService:" + url);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param url 下载链接
|
||||
* @param loaded 已经下载的长度
|
||||
* @param length 文件的总大小
|
||||
* @param usedTime 耗时 ,单位ms
|
||||
* 注意该方法回调在子线程 ,线程名 AsyncTask #XX 或者 AgentWeb # XX
|
||||
*/
|
||||
@Override
|
||||
public void onProgress(String url, long loaded, long length, long usedTime) {
|
||||
int mProgress = (int) ((loaded) / (float) length * 100);
|
||||
Logger.i("onProgress:" + mProgress);
|
||||
super.onProgress(url, loaded, length, usedTime);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param path 文件的绝对路径
|
||||
* @param url 下载地址
|
||||
* @param throwable 如果异常,返回给用户异常
|
||||
* @return true 表示用户处理了下载完成后续的事件 ,false 默认交给AgentWeb 处理
|
||||
*/
|
||||
@Override
|
||||
public boolean onResult(String path, String url, Throwable throwable) {
|
||||
//下载成功
|
||||
if (null == throwable) {
|
||||
//do you work
|
||||
} else {//下载失败
|
||||
|
||||
}
|
||||
// true 不会发出下载完成的通知 , 或者打开文件
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 下载服务设置
|
||||
*
|
||||
* @return IAgentWebSettings
|
||||
*/
|
||||
public IAgentWebSettings getSettings() {
|
||||
return new AbsAgentWebSettings() {
|
||||
private AgentWeb mAgentWeb;
|
||||
|
||||
@Override
|
||||
protected void bindAgentWebSupport(AgentWeb agentWeb) {
|
||||
this.mAgentWeb = agentWeb;
|
||||
}
|
||||
|
||||
/**
|
||||
* AgentWeb 4.0.0 内部删除了 DownloadListener 监听 ,以及相关API ,将 Download 部分完全抽离出来独立一个库,
|
||||
* 如果你需要使用 AgentWeb Download 部分 , 请依赖上 compile 'com.just.agentweb:download:4.0.0 ,
|
||||
* 如果你需要监听下载结果,请自定义 AgentWebSetting , New 出 DefaultDownloadImpl,传入DownloadListenerAdapter
|
||||
* 实现进度或者结果监听,例如下面这个例子,如果你不需要监听进度,或者下载结果,下面 setDownloader 的例子可以忽略。
|
||||
* @param webView
|
||||
* @param downloadListener
|
||||
* @return WebListenerManager
|
||||
*/
|
||||
@Override
|
||||
public WebListenerManager setDownloader(WebView webView, android.webkit.DownloadListener downloadListener) {
|
||||
return super.setDownloader(webView,
|
||||
DefaultDownloadImpl
|
||||
.create(getActivity(),
|
||||
webView,
|
||||
mDownloadListenerAdapter,
|
||||
mDownloadListenerAdapter,
|
||||
mAgentWeb.getPermissionInterceptor()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//===================WebChromeClient 和 WebViewClient===========================//
|
||||
|
||||
/**
|
||||
* 页面空白,请检查scheme是否加上, scheme://host:port/path?query&query 。
|
||||
*
|
||||
* @return mUrl
|
||||
*/
|
||||
public String getUrl() {
|
||||
String target = "";
|
||||
Bundle bundle = getArguments();
|
||||
if (bundle != null) {
|
||||
target = bundle.getString(AgentWebFragment.KEY_URL);
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(target)) {
|
||||
target = "https://github.com/xuexiangjys";
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* 和浏览器相关,包括和JS的交互
|
||||
*/
|
||||
protected WebChromeClient mWebChromeClient = new WebChromeClient() {
|
||||
@Override
|
||||
public void onProgressChanged(WebView view, int newProgress) {
|
||||
super.onProgressChanged(view, newProgress);
|
||||
//网页加载进度
|
||||
}
|
||||
@Override
|
||||
public void onReceivedTitle(WebView view, String title) {
|
||||
super.onReceivedTitle(view, title);
|
||||
if (mTvTitle != null && !TextUtils.isEmpty(title)) {
|
||||
if (title.length() > 10) {
|
||||
title = title.substring(0, 10).concat("...");
|
||||
}
|
||||
mTvTitle.setText(title);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 和网页url加载相关,统计加载时间
|
||||
*/
|
||||
protected WebViewClient mWebViewClient = new WebViewClient() {
|
||||
private HashMap<String, Long> mTimer = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
|
||||
super.onReceivedError(view, request, error);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
||||
return shouldOverrideUrlLoading(view, request.getUrl() + "");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
||||
return super.shouldInterceptRequest(view, request);
|
||||
}
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(final WebView view, String url) {
|
||||
//intent:// scheme的处理 如果返回false , 则交给 DefaultWebClient 处理 , 默认会打开该Activity , 如果Activity不存在则跳到应用市场上去. true 表示拦截
|
||||
//例如优酷视频播放 ,intent://play?...package=com.youku.phone;end;
|
||||
//优酷想唤起自己应用播放该视频 , 下面拦截地址返回 true 则会在应用内 H5 播放 ,禁止优酷唤起播放该视频, 如果返回 false , DefaultWebClient 会根据intent 协议处理 该地址 , 首先匹配该应用存不存在 ,如果存在 , 唤起该应用播放 , 如果不存在 , 则跳到应用市场下载该应用 .
|
||||
if (url.startsWith("intent://") && url.contains("com.youku.phone")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
||||
mTimer.put(url, System.currentTimeMillis());
|
||||
if (url.equals(getUrl())) {
|
||||
pageNavigator(View.GONE);
|
||||
} else {
|
||||
pageNavigator(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
super.onPageFinished(view, url);
|
||||
if (mTimer.get(url) != null) {
|
||||
long overTime = System.currentTimeMillis();
|
||||
Long startTime = mTimer.get(url);
|
||||
//统计页面的使用时长
|
||||
Logger.i(" page mUrl:" + url + " used time:" + (overTime - startTime));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
|
||||
super.onReceivedHttpError(view, request, errorResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
||||
super.onReceivedError(view, errorCode, description, failingUrl);
|
||||
}
|
||||
};
|
||||
|
||||
//=====================菜单========================//
|
||||
|
||||
/**
|
||||
* 显示更多菜单
|
||||
*
|
||||
* @param view 菜单依附在该View下面
|
||||
*/
|
||||
private void showPoPup(View view) {
|
||||
if (mPopupMenu == null) {
|
||||
mPopupMenu = new PopupMenu(getContext(), view);
|
||||
mPopupMenu.inflate(R.menu.menu_toolbar_web);
|
||||
mPopupMenu.setOnMenuItemClickListener(mOnMenuItemClickListener);
|
||||
}
|
||||
mPopupMenu.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单事件
|
||||
*/
|
||||
private PopupMenu.OnMenuItemClickListener mOnMenuItemClickListener = new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.refresh:
|
||||
if (mAgentWeb != null) {
|
||||
mAgentWeb.getUrlLoader().reload(); // 刷新
|
||||
}
|
||||
return true;
|
||||
case R.id.copy:
|
||||
if (mAgentWeb != null) {
|
||||
toCopy(getContext(), mAgentWeb.getWebCreator().getWebView().getUrl());
|
||||
}
|
||||
return true;
|
||||
case R.id.default_browser:
|
||||
if (mAgentWeb != null) {
|
||||
openBrowser(mAgentWeb.getWebCreator().getWebView().getUrl());
|
||||
}
|
||||
return true;
|
||||
case R.id.share:
|
||||
if (mAgentWeb != null) {
|
||||
shareWebUrl(mAgentWeb.getWebCreator().getWebView().getUrl());
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开浏览器
|
||||
*
|
||||
* @param targetUrl 外部浏览器打开的地址
|
||||
*/
|
||||
private void openBrowser(String targetUrl) {
|
||||
if (TextUtils.isEmpty(targetUrl) || targetUrl.startsWith("file://")) {
|
||||
XToastUtils.toast(targetUrl + " 该链接无法使用浏览器打开。");
|
||||
return;
|
||||
}
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("android.intent.action.VIEW");
|
||||
Uri uri = Uri.parse(targetUrl);
|
||||
intent.setData(uri);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分享网页链接
|
||||
*
|
||||
* @param url 网页链接
|
||||
*/
|
||||
private void shareWebUrl(String url) {
|
||||
Intent shareIntent = new Intent();
|
||||
shareIntent.setAction(Intent.ACTION_SEND);
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, url);
|
||||
shareIntent.setType("text/plain");
|
||||
//设置分享列表的标题,并且每次都显示分享列表
|
||||
startActivity(Intent.createChooser(shareIntent, "分享到"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制字符串
|
||||
*
|
||||
* @param context
|
||||
* @param text
|
||||
*/
|
||||
private void toCopy(Context context, String text) {
|
||||
ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
if (manager == null) {
|
||||
return;
|
||||
}
|
||||
manager.setPrimaryClip(ClipData.newPlainText(null, text));
|
||||
}
|
||||
|
||||
//===================生命周期管理===========================//
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
if (mAgentWeb != null) {
|
||||
mAgentWeb.getWebLifeCycle().onResume();//恢复
|
||||
}
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if (mAgentWeb != null) {
|
||||
mAgentWeb.getWebLifeCycle().onPause(); //暂停应用内所有WebView , 调用mWebView.resumeTimers();/mAgentWeb.getWebLifeCycle().onResume(); 恢复。
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
return mAgentWeb != null && mAgentWeb.handleKeyEvent(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (mAgentWeb != null) {
|
||||
mAgentWeb.destroy();
|
||||
}
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
|
||||
//===================中间键===========================//
|
||||
|
||||
|
||||
/**
|
||||
* MiddlewareWebClientBase 是 AgentWeb 3.0.0 提供一个强大的功能,
|
||||
* 如果用户需要使用 AgentWeb 提供的功能, 不想重写 WebClientView方
|
||||
* 法覆盖AgentWeb提供的功能,那么 MiddlewareWebClientBase 是一个
|
||||
* 不错的选择 。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected MiddlewareWebClientBase getMiddlewareWebClient() {
|
||||
return new MiddlewareWebViewClient() {
|
||||
/**
|
||||
*
|
||||
* @param view
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
// 拦截 url,不执行 DefaultWebClient#shouldOverrideUrlLoading
|
||||
if (url.startsWith("agentweb")) {
|
||||
return true;
|
||||
}
|
||||
// 执行 DefaultWebClient#shouldOverrideUrlLoading
|
||||
if (super.shouldOverrideUrlLoading(view, url)) {
|
||||
return true;
|
||||
}
|
||||
// do you work
|
||||
return false;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
||||
return super.shouldOverrideUrlLoading(view, request);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected MiddlewareWebChromeBase getMiddlewareWebChrome() {
|
||||
return new MiddlewareChromeClient() {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限申请拦截器
|
||||
*/
|
||||
protected PermissionInterceptor mPermissionInterceptor = new PermissionInterceptor() {
|
||||
/**
|
||||
* PermissionInterceptor 能达到 url1 允许授权, url2 拒绝授权的效果。
|
||||
* @param url
|
||||
* @param permissions
|
||||
* @param action
|
||||
* @return true 该Url对应页面请求权限进行拦截 ,false 表示不拦截。
|
||||
*/
|
||||
@Override
|
||||
public boolean intercept(String url, String[] permissions, String action) {
|
||||
Logger.i("mUrl:" + url + " permission:" + JsonUtil.toJson(permissions) + " action:" + action);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Dept {
|
||||
private String remark;
|
||||
|
||||
private int deptId;
|
||||
|
||||
private int parentId;
|
||||
|
||||
private String ancestors;
|
||||
|
||||
private String deptName;
|
||||
|
||||
private String orderNum;
|
||||
|
||||
private String leader;
|
||||
|
||||
private String phone;
|
||||
|
||||
private String email;
|
||||
|
||||
private String status;
|
||||
|
||||
private String delFlag;
|
||||
|
||||
private String parentName;
|
||||
|
||||
private List<Dept> children ;
|
||||
|
||||
public void setRemark(String remark){
|
||||
this.remark = remark;
|
||||
}
|
||||
public String getRemark(){
|
||||
return this.remark;
|
||||
}
|
||||
public void setDeptId(int deptId){
|
||||
this.deptId = deptId;
|
||||
}
|
||||
public int getDeptId(){
|
||||
return this.deptId;
|
||||
}
|
||||
public void setParentId(int parentId){
|
||||
this.parentId = parentId;
|
||||
}
|
||||
public int getParentId(){
|
||||
return this.parentId;
|
||||
}
|
||||
public void setAncestors(String ancestors){
|
||||
this.ancestors = ancestors;
|
||||
}
|
||||
public String getAncestors(){
|
||||
return this.ancestors;
|
||||
}
|
||||
public void setDeptName(String deptName){
|
||||
this.deptName = deptName;
|
||||
}
|
||||
public String getDeptName(){
|
||||
return this.deptName;
|
||||
}
|
||||
public void setOrderNum(String orderNum){
|
||||
this.orderNum = orderNum;
|
||||
}
|
||||
public String getOrderNum(){
|
||||
return this.orderNum;
|
||||
}
|
||||
public void setLeader(String leader){
|
||||
this.leader = leader;
|
||||
}
|
||||
public String getLeader(){
|
||||
return this.leader;
|
||||
}
|
||||
public void setPhone(String phone){
|
||||
this.phone = phone;
|
||||
}
|
||||
public String getPhone(){
|
||||
return this.phone;
|
||||
}
|
||||
public void setEmail(String email){
|
||||
this.email = email;
|
||||
}
|
||||
public String getEmail(){
|
||||
return this.email;
|
||||
}
|
||||
public void setStatus(String status){
|
||||
this.status = status;
|
||||
}
|
||||
public String getStatus(){
|
||||
return this.status;
|
||||
}
|
||||
public void setDelFlag(String delFlag){
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
public String getDelFlag(){
|
||||
return this.delFlag;
|
||||
}
|
||||
public void setParentName(String parentName){
|
||||
this.parentName = parentName;
|
||||
}
|
||||
public String getParentName(){
|
||||
return this.parentName;
|
||||
}
|
||||
public void setChildren(List<Dept> children){
|
||||
this.children = children;
|
||||
}
|
||||
public List<Dept> getChildren(){
|
||||
return this.children;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.entity;
|
||||
|
||||
public class DictData {
|
||||
|
||||
/** 字典标签 */
|
||||
private String dictLabel;
|
||||
|
||||
/** 字典键值 */
|
||||
private Integer dictValue;
|
||||
|
||||
/** 字典编码 */
|
||||
private Long dictCode;
|
||||
|
||||
/** 字典类型 */
|
||||
private String dictType;
|
||||
|
||||
|
||||
public Long getDictCode()
|
||||
{
|
||||
return dictCode;
|
||||
}
|
||||
public void setDictCode(Long dictCode)
|
||||
{
|
||||
this.dictCode = dictCode;
|
||||
}
|
||||
|
||||
public String getDictLabel()
|
||||
{
|
||||
return dictLabel;
|
||||
}
|
||||
public void setDictLabel(String dictLabel)
|
||||
{
|
||||
this.dictLabel = dictLabel;
|
||||
}
|
||||
|
||||
public Integer getDictValue()
|
||||
{
|
||||
return dictValue;
|
||||
}
|
||||
public void setDictValue(Integer dictValue)
|
||||
{
|
||||
this.dictValue = dictValue;
|
||||
}
|
||||
|
||||
public String getDictType()
|
||||
{
|
||||
return dictType;
|
||||
}
|
||||
public void setDictType(String dictType)
|
||||
{
|
||||
this.dictType = dictType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.entity;
|
||||
|
||||
public class IotCategory {
|
||||
/** 序号 */
|
||||
private Long categoryId;
|
||||
|
||||
/** 分类名称 */
|
||||
private String categoryName;
|
||||
|
||||
public void setCategoryId(Long categoryId)
|
||||
{
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
public Long getCategoryId()
|
||||
{
|
||||
return categoryId;
|
||||
}
|
||||
|
||||
public void setCategoryName(String categoryName)
|
||||
{
|
||||
this.categoryName = categoryName;
|
||||
}
|
||||
public String getCategoryName()
|
||||
{
|
||||
return categoryName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.entity;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
public class IotDevice {
|
||||
/** 序号 */
|
||||
private Long deviceId;
|
||||
|
||||
/** 编号 */
|
||||
private String deviceNum;
|
||||
|
||||
/** 分类 */
|
||||
private String categoryName;
|
||||
|
||||
/** 名称 */
|
||||
private String deviceName;
|
||||
|
||||
/** 固件版本 */
|
||||
private String firmwareVersion;
|
||||
|
||||
/** 用户 */
|
||||
private String ownerId;
|
||||
|
||||
/** 备注 */
|
||||
private String remark;
|
||||
|
||||
/** 设备温度 */
|
||||
private String deviceTemp;
|
||||
|
||||
/** 创建时间 */
|
||||
private String createTime;
|
||||
|
||||
public void setDeviceId(Long deviceId)
|
||||
{
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public Long getDeviceId()
|
||||
{
|
||||
return deviceId;
|
||||
}
|
||||
public void setDeviceNum(String deviceNum)
|
||||
{
|
||||
this.deviceNum = deviceNum;
|
||||
}
|
||||
|
||||
public String getDeviceNum()
|
||||
{
|
||||
return deviceNum;
|
||||
}
|
||||
public void setCategoryId(String categoryId)
|
||||
{
|
||||
this.categoryName = categoryName;
|
||||
}
|
||||
|
||||
public String getCategoryName()
|
||||
{
|
||||
return categoryName;
|
||||
}
|
||||
public void setDeviceName(String deviceName)
|
||||
{
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
|
||||
public String getDeviceName()
|
||||
{
|
||||
return deviceName;
|
||||
}
|
||||
public void setFirmwareVersion(String firmwareVersion)
|
||||
{
|
||||
this.firmwareVersion = firmwareVersion;
|
||||
}
|
||||
|
||||
public String getFirmwareVersion()
|
||||
{
|
||||
return firmwareVersion;
|
||||
}
|
||||
public void setOwnerId(String ownerId)
|
||||
{
|
||||
this.ownerId = ownerId;
|
||||
}
|
||||
|
||||
public String getOwnerId()
|
||||
{
|
||||
return ownerId;
|
||||
}
|
||||
|
||||
public void setRemark(String remark)
|
||||
{
|
||||
this.remark = remark;
|
||||
}
|
||||
public String getRemark()
|
||||
{
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setDeviceTemp(String deviceTemperature)
|
||||
{
|
||||
this.deviceTemp = deviceTemperature;
|
||||
}
|
||||
public String getDeviceTemp()
|
||||
{
|
||||
return deviceTemp;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime)
|
||||
{
|
||||
this.createTime = createTime;
|
||||
}
|
||||
public String getCreateTime()
|
||||
{
|
||||
return createTime;
|
||||
}
|
||||
}
|
||||
@@ -1,282 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.entity;
|
||||
|
||||
public class IotDeviceSet {
|
||||
/** 序号 */
|
||||
private Long deviceSetId;
|
||||
|
||||
/** 设备 */
|
||||
private Long deviceId;
|
||||
|
||||
/** 设备编号 */
|
||||
private String deviceNum;
|
||||
|
||||
/** 报警 */
|
||||
private Integer isAlarm;
|
||||
|
||||
/** 雷达感应 */
|
||||
private Integer isRadar;
|
||||
|
||||
/** 托管 */
|
||||
private Integer isHost;
|
||||
|
||||
/** 重启 */
|
||||
private Integer isReset;
|
||||
|
||||
/** 打开AP */
|
||||
private Integer isAp;
|
||||
|
||||
/** 是否离线使用 */
|
||||
private Integer isWifiOffline;
|
||||
|
||||
/** 是否使用证书 */
|
||||
private Integer isOpenCertifi;
|
||||
|
||||
/** 智能配网 */
|
||||
private Integer isSmartConfig;
|
||||
|
||||
/** 射频遥控 */
|
||||
private Integer isRfControl;
|
||||
|
||||
/** 遥控配对 */
|
||||
private Integer isRfLearn;
|
||||
|
||||
/** 遥控清码 */
|
||||
private Integer isRfClear;
|
||||
|
||||
/** 按键一 */
|
||||
private Integer rfOneFunc;
|
||||
|
||||
/** 按键二 */
|
||||
private Integer rfTwoFunc;
|
||||
|
||||
/** 按键三 */
|
||||
private Integer rfThreeFunc;
|
||||
|
||||
/** 按键四 */
|
||||
private Integer rfFourFunc;
|
||||
|
||||
/** 用户 */
|
||||
private String ownerId;
|
||||
|
||||
/** 配网地址 */
|
||||
private String networkAddress;
|
||||
|
||||
/** 配网IP */
|
||||
private String networkIp;
|
||||
|
||||
/** 雷达感应间隔 */
|
||||
private Integer radarInterval;
|
||||
|
||||
public void setDeviceSetId(Long deviceSetId)
|
||||
{
|
||||
this.deviceSetId = deviceSetId;
|
||||
}
|
||||
|
||||
public Long getDeviceSetId()
|
||||
{
|
||||
return deviceSetId;
|
||||
}
|
||||
public void setDeviceId(Long deviceId)
|
||||
{
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public Long getDeviceId()
|
||||
{
|
||||
return deviceId;
|
||||
}
|
||||
public void setDeviceNum(String deviceNum)
|
||||
{
|
||||
this.deviceNum = deviceNum;
|
||||
}
|
||||
|
||||
public String getDeviceNum()
|
||||
{
|
||||
return deviceNum;
|
||||
}
|
||||
public void setIsAlarm(Integer isAlarm)
|
||||
{
|
||||
this.isAlarm = isAlarm;
|
||||
}
|
||||
|
||||
public Integer getIsAlarm()
|
||||
{
|
||||
return isAlarm;
|
||||
}
|
||||
public void setIsRadar(Integer isRadar)
|
||||
{
|
||||
this.isRadar = isRadar;
|
||||
}
|
||||
|
||||
public Integer getIsRadar()
|
||||
{
|
||||
return isRadar;
|
||||
}
|
||||
public void setIsHost(Integer isHost)
|
||||
{
|
||||
this.isHost = isHost;
|
||||
}
|
||||
|
||||
public Integer getIsHost()
|
||||
{
|
||||
return isHost;
|
||||
}
|
||||
public void setIsReset(Integer isReset)
|
||||
{
|
||||
this.isReset = isReset;
|
||||
}
|
||||
|
||||
public Integer getIsReset()
|
||||
{
|
||||
return isReset;
|
||||
}
|
||||
|
||||
public void setIsAp(Integer isAp)
|
||||
{
|
||||
this.isAp = isAp;
|
||||
}
|
||||
public Integer getIsAp()
|
||||
{
|
||||
return isAp;
|
||||
}
|
||||
|
||||
public void setIsWifiOffline(Integer isWifiOffline)
|
||||
{
|
||||
this.isWifiOffline = isWifiOffline;
|
||||
}
|
||||
public Integer getIsWifiOffline()
|
||||
{
|
||||
return isWifiOffline;
|
||||
}
|
||||
|
||||
public void setIsOpenCertifi(Integer isOpenCertifi)
|
||||
{
|
||||
this.isOpenCertifi = isOpenCertifi;
|
||||
}
|
||||
public Integer getIsOpenCertifi()
|
||||
{
|
||||
return isOpenCertifi;
|
||||
}
|
||||
|
||||
public void setIsSmartConfig(Integer isSmartConfig)
|
||||
{
|
||||
this.isSmartConfig = isSmartConfig;
|
||||
}
|
||||
|
||||
public Integer getIsSmartConfig()
|
||||
{
|
||||
return isSmartConfig;
|
||||
}
|
||||
public void setIsRfControl(Integer isRfControl)
|
||||
{
|
||||
this.isRfControl = isRfControl;
|
||||
}
|
||||
|
||||
public Integer getIsRfControl()
|
||||
{
|
||||
return isRfControl;
|
||||
}
|
||||
public void setIsRfLearn(Integer isRfLearn)
|
||||
{
|
||||
this.isRfLearn = isRfLearn;
|
||||
}
|
||||
|
||||
public Integer getIsRfLearn()
|
||||
{
|
||||
return isRfLearn;
|
||||
}
|
||||
public void setIsRfClear(Integer isRfClear)
|
||||
{
|
||||
this.isRfClear = isRfClear;
|
||||
}
|
||||
|
||||
public Integer getIsRfClear()
|
||||
{
|
||||
return isRfClear;
|
||||
}
|
||||
public void setRfOneFunc(Integer rfOneFunc)
|
||||
{
|
||||
this.rfOneFunc = rfOneFunc;
|
||||
}
|
||||
|
||||
public Integer getRfOneFunc()
|
||||
{
|
||||
return rfOneFunc;
|
||||
}
|
||||
public void setRfTwoFunc(Integer rfTwoFunc)
|
||||
{
|
||||
this.rfTwoFunc = rfTwoFunc;
|
||||
}
|
||||
|
||||
public Integer getRfTwoFunc()
|
||||
{
|
||||
return rfTwoFunc;
|
||||
}
|
||||
public void setRfThreeFunc(Integer rfThreeFunc)
|
||||
{
|
||||
this.rfThreeFunc = rfThreeFunc;
|
||||
}
|
||||
|
||||
public Integer getRfThreeFunc()
|
||||
{
|
||||
return rfThreeFunc;
|
||||
}
|
||||
public void setRfFourFunc(Integer rfFourFunc)
|
||||
{
|
||||
this.rfFourFunc = rfFourFunc;
|
||||
}
|
||||
|
||||
public Integer getRfFourFunc()
|
||||
{
|
||||
return rfFourFunc;
|
||||
}
|
||||
public void setOwnerId(String ownerId)
|
||||
{
|
||||
this.ownerId = ownerId;
|
||||
}
|
||||
|
||||
public String getOwnerId()
|
||||
{
|
||||
return ownerId;
|
||||
}
|
||||
public void setNetworkAddress(String networkAddress)
|
||||
{
|
||||
this.networkAddress = networkAddress;
|
||||
}
|
||||
|
||||
public String getNetworkAddress()
|
||||
{
|
||||
return networkAddress;
|
||||
}
|
||||
public void setNetworkIp(String networkIp)
|
||||
{
|
||||
this.networkIp = networkIp;
|
||||
}
|
||||
|
||||
public String getNetworkIp()
|
||||
{
|
||||
return networkIp;
|
||||
}
|
||||
|
||||
public void setRadarInterval(Integer radarInterval)
|
||||
{
|
||||
this.radarInterval = radarInterval;
|
||||
}
|
||||
|
||||
public Integer getRadarInterval()
|
||||
{
|
||||
return radarInterval;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.entity;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class IotDeviceStatus {
|
||||
/** 序号 */
|
||||
private Long deviceStatusId;
|
||||
|
||||
/** 设备 */
|
||||
private Long deviceId;
|
||||
|
||||
/** 设备编号 */
|
||||
private String deviceNum;
|
||||
|
||||
/** 继电器 */
|
||||
private Integer relayStatus;
|
||||
|
||||
/** 灯状态 */
|
||||
private Integer lightStatus;
|
||||
|
||||
/** 在线 */
|
||||
private Integer isOnline;
|
||||
|
||||
/** 设备温度 */
|
||||
private BigDecimal deviceTemperature;
|
||||
|
||||
/** 设备湿度 */
|
||||
private Integer rssi;
|
||||
|
||||
/** 空气温度 */
|
||||
private BigDecimal airTemperature;
|
||||
|
||||
/** 空气湿度 */
|
||||
private BigDecimal airHumidity;
|
||||
|
||||
/** 触发源 */
|
||||
private Integer triggerSource;
|
||||
|
||||
/** 彩灯亮度 */
|
||||
private Integer brightness;
|
||||
|
||||
/** 渐变间隔 */
|
||||
private Integer lightInterval;
|
||||
|
||||
/** 彩灯模式 */
|
||||
private Integer lightMode;
|
||||
|
||||
/** 灯渐变时间 */
|
||||
private Integer fadeTime;
|
||||
|
||||
/** 红灯 */
|
||||
private Integer red;
|
||||
|
||||
/** 绿灯 */
|
||||
private Integer green;
|
||||
|
||||
/** 蓝灯 */
|
||||
private Integer blue;
|
||||
|
||||
public void setDeviceStatusId(Long deviceStatusId)
|
||||
{
|
||||
this.deviceStatusId = deviceStatusId;
|
||||
}
|
||||
|
||||
public Long getDeviceStatusId()
|
||||
{
|
||||
return deviceStatusId;
|
||||
}
|
||||
public void setDeviceId(Long deviceId)
|
||||
{
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public Long getDeviceId()
|
||||
{
|
||||
return deviceId;
|
||||
}
|
||||
public void setDeviceNum(String deviceNum)
|
||||
{
|
||||
this.deviceNum = deviceNum;
|
||||
}
|
||||
|
||||
public String getDeviceNum()
|
||||
{
|
||||
return deviceNum;
|
||||
}
|
||||
public void setRelayStatus(Integer relayStatus)
|
||||
{
|
||||
this.relayStatus = relayStatus;
|
||||
}
|
||||
|
||||
public Integer getRelayStatus()
|
||||
{
|
||||
return relayStatus;
|
||||
}
|
||||
public void setLightStatus(Integer lightStatus)
|
||||
{
|
||||
this.lightStatus = lightStatus;
|
||||
}
|
||||
|
||||
public Integer getLightStatus()
|
||||
{
|
||||
return lightStatus;
|
||||
}
|
||||
public void setIsOnline(Integer isOnline)
|
||||
{
|
||||
this.isOnline = isOnline;
|
||||
}
|
||||
|
||||
public Integer getIsOnline()
|
||||
{
|
||||
return isOnline;
|
||||
}
|
||||
public void setDeviceTemperature(BigDecimal deviceTemperature)
|
||||
{
|
||||
this.deviceTemperature = deviceTemperature;
|
||||
}
|
||||
|
||||
public BigDecimal getDeviceTemperature()
|
||||
{
|
||||
return deviceTemperature;
|
||||
}
|
||||
public void setRssi(Integer rssi)
|
||||
{
|
||||
this.rssi = rssi;
|
||||
}
|
||||
|
||||
public Integer getRssi()
|
||||
{
|
||||
return rssi;
|
||||
}
|
||||
public void setAirTemperature(BigDecimal airTemperature)
|
||||
{
|
||||
this.airTemperature = airTemperature;
|
||||
}
|
||||
|
||||
public BigDecimal getAirTemperature()
|
||||
{
|
||||
return airTemperature;
|
||||
}
|
||||
public void setAirHumidity(BigDecimal airHumidity)
|
||||
{
|
||||
this.airHumidity = airHumidity;
|
||||
}
|
||||
|
||||
public BigDecimal getAirHumidity()
|
||||
{
|
||||
return airHumidity;
|
||||
}
|
||||
public void setTriggerSource(Integer triggerSource)
|
||||
{
|
||||
this.triggerSource = triggerSource;
|
||||
}
|
||||
|
||||
public Integer getTriggerSource()
|
||||
{
|
||||
return triggerSource;
|
||||
}
|
||||
public void setBrightness(Integer brightness)
|
||||
{
|
||||
this.brightness = brightness;
|
||||
}
|
||||
|
||||
public Integer getBrightness()
|
||||
{
|
||||
return brightness;
|
||||
}
|
||||
public void setLightInterval(Integer lightInterval)
|
||||
{
|
||||
this.lightInterval = lightInterval;
|
||||
}
|
||||
|
||||
public Integer getLightInterval()
|
||||
{
|
||||
return lightInterval;
|
||||
}
|
||||
public void setLightMode(Integer lightMode)
|
||||
{
|
||||
this.lightMode = lightMode;
|
||||
}
|
||||
|
||||
public Integer getLightMode()
|
||||
{
|
||||
return lightMode;
|
||||
}
|
||||
public void setRed(Integer red)
|
||||
{
|
||||
this.red = red;
|
||||
}
|
||||
|
||||
public Integer getRed()
|
||||
{
|
||||
return red;
|
||||
}
|
||||
public void setGreen(Integer green)
|
||||
{
|
||||
this.green = green;
|
||||
}
|
||||
|
||||
public Integer getGreen()
|
||||
{
|
||||
return green;
|
||||
}
|
||||
public void setBlue(Integer blue)
|
||||
{
|
||||
this.blue = blue;
|
||||
}
|
||||
|
||||
public Integer getBlue()
|
||||
{
|
||||
return blue;
|
||||
}
|
||||
|
||||
public void setFadeTime(Integer fadeTime)
|
||||
{
|
||||
this.fadeTime = fadeTime;
|
||||
}
|
||||
public Integer getFadeTime()
|
||||
{
|
||||
return fadeTime;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.entity;
|
||||
|
||||
public class IotGroup {
|
||||
/** 设备分组 */
|
||||
private Long groupId;
|
||||
|
||||
/** 用户 */
|
||||
private Long userId;
|
||||
|
||||
/** 分组名称 */
|
||||
private String groupName;
|
||||
|
||||
/** 排序 */
|
||||
private Integer groupOrder;
|
||||
|
||||
public void setGroupId(Long groupId)
|
||||
{
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public Long getGroupId()
|
||||
{
|
||||
return groupId;
|
||||
}
|
||||
public void setUserId(Long userId)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getUserId()
|
||||
{
|
||||
return userId;
|
||||
}
|
||||
public void setGroupName(String groupName)
|
||||
{
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
public String getGroupName()
|
||||
{
|
||||
return groupName;
|
||||
}
|
||||
public void setGroupOrder(Integer groupOrder)
|
||||
{
|
||||
this.groupOrder = groupOrder;
|
||||
}
|
||||
|
||||
public Integer getGroupOrder()
|
||||
{
|
||||
return groupOrder;
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.entity;
|
||||
|
||||
public class Roles {
|
||||
private String remark;
|
||||
|
||||
private int roleId;
|
||||
|
||||
private String roleName;
|
||||
|
||||
private String roleKey;
|
||||
|
||||
private String roleSort;
|
||||
|
||||
private String dataScope;
|
||||
|
||||
private boolean menuCheckStrictly;
|
||||
|
||||
private boolean deptCheckStrictly;
|
||||
|
||||
private String status;
|
||||
|
||||
private boolean flag;
|
||||
|
||||
private String menuIds;
|
||||
|
||||
private String deptIds;
|
||||
|
||||
private boolean admin;
|
||||
|
||||
public void setRemark(String remark){
|
||||
this.remark = remark;
|
||||
}
|
||||
public String getRemark(){
|
||||
return this.remark;
|
||||
}
|
||||
public void setRoleId(int roleId){
|
||||
this.roleId = roleId;
|
||||
}
|
||||
public int getRoleId(){
|
||||
return this.roleId;
|
||||
}
|
||||
public void setRoleName(String roleName){
|
||||
this.roleName = roleName;
|
||||
}
|
||||
public String getRoleName(){
|
||||
return this.roleName;
|
||||
}
|
||||
public void setRoleKey(String roleKey){
|
||||
this.roleKey = roleKey;
|
||||
}
|
||||
public String getRoleKey(){
|
||||
return this.roleKey;
|
||||
}
|
||||
public void setRoleSort(String roleSort){
|
||||
this.roleSort = roleSort;
|
||||
}
|
||||
public String getRoleSort(){
|
||||
return this.roleSort;
|
||||
}
|
||||
public void setDataScope(String dataScope){
|
||||
this.dataScope = dataScope;
|
||||
}
|
||||
public String getDataScope(){
|
||||
return this.dataScope;
|
||||
}
|
||||
public void setMenuCheckStrictly(boolean menuCheckStrictly){
|
||||
this.menuCheckStrictly = menuCheckStrictly;
|
||||
}
|
||||
public boolean getMenuCheckStrictly(){
|
||||
return this.menuCheckStrictly;
|
||||
}
|
||||
public void setDeptCheckStrictly(boolean deptCheckStrictly){
|
||||
this.deptCheckStrictly = deptCheckStrictly;
|
||||
}
|
||||
public boolean getDeptCheckStrictly(){
|
||||
return this.deptCheckStrictly;
|
||||
}
|
||||
public void setStatus(String status){
|
||||
this.status = status;
|
||||
}
|
||||
public String getStatus(){
|
||||
return this.status;
|
||||
}
|
||||
public void setFlag(boolean flag){
|
||||
this.flag = flag;
|
||||
}
|
||||
public boolean getFlag(){
|
||||
return this.flag;
|
||||
}
|
||||
public void setMenuIds(String menuIds){
|
||||
this.menuIds = menuIds;
|
||||
}
|
||||
public String getMenuIds(){
|
||||
return this.menuIds;
|
||||
}
|
||||
public void setDeptIds(String deptIds){
|
||||
this.deptIds = deptIds;
|
||||
}
|
||||
public String getDeptIds(){
|
||||
return this.deptIds;
|
||||
}
|
||||
public void setAdmin(boolean admin){
|
||||
this.admin = admin;
|
||||
}
|
||||
public boolean getAdmin(){
|
||||
return this.admin;
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class User {
|
||||
|
||||
private String remark;
|
||||
|
||||
private int userId;
|
||||
|
||||
private int deptId;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String email;
|
||||
|
||||
private String phonenumber;
|
||||
|
||||
private String sex;
|
||||
|
||||
private String avatar;
|
||||
|
||||
private String status;
|
||||
|
||||
private String loginIp;
|
||||
|
||||
private String loginDate;
|
||||
|
||||
private Dept dept;
|
||||
|
||||
private List<Roles> roles ;
|
||||
|
||||
private String roleIds;
|
||||
|
||||
private String postIds;
|
||||
|
||||
private boolean admin;
|
||||
|
||||
private String createTime;
|
||||
|
||||
public void setRemark(String remark){
|
||||
this.remark = remark;
|
||||
}
|
||||
public String getRemark(){
|
||||
return this.remark;
|
||||
}
|
||||
public void setUserId(int userId){
|
||||
this.userId = userId;
|
||||
}
|
||||
public int getUserId(){
|
||||
return this.userId;
|
||||
}
|
||||
public void setDeptId(int deptId){
|
||||
this.deptId = deptId;
|
||||
}
|
||||
public int getDeptId(){
|
||||
return this.deptId;
|
||||
}
|
||||
public void setUserName(String userName){
|
||||
this.userName = userName;
|
||||
}
|
||||
public String getUserName(){
|
||||
return this.userName;
|
||||
}
|
||||
public void setNickName(String nickName){
|
||||
this.nickName = nickName;
|
||||
}
|
||||
public String getNickName(){
|
||||
return this.nickName;
|
||||
}
|
||||
public void setEmail(String email){
|
||||
this.email = email;
|
||||
}
|
||||
public String getEmail(){
|
||||
return this.email;
|
||||
}
|
||||
public void setPhonenumber(String phonenumber){
|
||||
this.phonenumber = phonenumber;
|
||||
}
|
||||
public String getPhonenumber(){
|
||||
return this.phonenumber;
|
||||
}
|
||||
public void setSex(String sex){
|
||||
this.sex = sex;
|
||||
}
|
||||
public String getSex(){
|
||||
return this.sex;
|
||||
}
|
||||
public void setAvatar(String avatar){
|
||||
this.avatar = avatar;
|
||||
}
|
||||
public String getAvatar(){
|
||||
return this.avatar;
|
||||
}
|
||||
public void setStatus(String status){
|
||||
this.status = status;
|
||||
}
|
||||
public String getStatus(){
|
||||
return this.status;
|
||||
}
|
||||
public void setLoginIp(String loginIp){
|
||||
this.loginIp = loginIp;
|
||||
}
|
||||
public String getLoginIp(){
|
||||
return this.loginIp;
|
||||
}
|
||||
public void setLoginDate(String loginDate){
|
||||
this.loginDate = loginDate;
|
||||
}
|
||||
public String getLoginDate(){
|
||||
return this.loginDate;
|
||||
}
|
||||
public void setDept(Dept dept){
|
||||
this.dept = dept;
|
||||
}
|
||||
public Dept getDept(){
|
||||
return this.dept;
|
||||
}
|
||||
public void setRoles(List<Roles> roles){
|
||||
this.roles = roles;
|
||||
}
|
||||
public List<Roles> getRoles(){
|
||||
return this.roles;
|
||||
}
|
||||
public void setRoleIds(String roleIds){
|
||||
this.roleIds = roleIds;
|
||||
}
|
||||
public String getRoleIds(){
|
||||
return this.roleIds;
|
||||
}
|
||||
public void setPostIds(String postIds){
|
||||
this.postIds = postIds;
|
||||
}
|
||||
public String getPostIds(){
|
||||
return this.postIds;
|
||||
}
|
||||
public void setAdmin(boolean admin){
|
||||
this.admin = admin;
|
||||
}
|
||||
public boolean getAdmin(){
|
||||
return this.admin;
|
||||
}
|
||||
public void setCreateTime(String createTime){
|
||||
this.createTime = createTime;
|
||||
}
|
||||
public String getCreateTime(){
|
||||
return this.createTime;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.entity.bo;
|
||||
|
||||
public class CaptureImage {
|
||||
private String uuid;
|
||||
|
||||
private String img;
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid ;
|
||||
}
|
||||
|
||||
public String getImg() {
|
||||
return img;
|
||||
}
|
||||
public void setImg(String img) {
|
||||
this.img = img ;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.entity.vo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class IotDeviceVo {
|
||||
private Long deviceId;
|
||||
|
||||
/** 编号 */
|
||||
private String deviceNum;
|
||||
|
||||
/** 分类 */
|
||||
private Long categoryId;
|
||||
|
||||
/** 分类名称 */
|
||||
private String categoryName;
|
||||
|
||||
/** 名称 */
|
||||
private String deviceName;
|
||||
|
||||
/** 固件版本 */
|
||||
private String firmwareVersion;
|
||||
|
||||
/** 用户 */
|
||||
private String ownerId;
|
||||
|
||||
private String nickName;
|
||||
|
||||
/** 删除标志(0代表存在 2代表删除) */
|
||||
private String delFlag;
|
||||
|
||||
/** 报警 */
|
||||
private Integer isAlarm;
|
||||
|
||||
/** 雷达感应 */
|
||||
private Integer isRadar;
|
||||
|
||||
/** 射频遥控 */
|
||||
private Integer isRfControl;
|
||||
|
||||
/** 配网地址 */
|
||||
private String networkAddress;
|
||||
|
||||
/** 配网IP */
|
||||
private String networkIp;
|
||||
|
||||
/** 继电器 */
|
||||
private Integer relayStatus;
|
||||
|
||||
/** 灯状态 */
|
||||
private Integer lightStatus;
|
||||
|
||||
/** 在线 */
|
||||
private Integer isOnline;
|
||||
|
||||
/** 设备温度 */
|
||||
private BigDecimal deviceTemperature;
|
||||
|
||||
/** 设备湿度 */
|
||||
private Integer rssi;
|
||||
|
||||
|
||||
|
||||
public void setDeviceId(Long deviceId)
|
||||
{
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
public Long getDeviceId()
|
||||
{
|
||||
return deviceId;
|
||||
}
|
||||
public void setDeviceNum(String deviceNum)
|
||||
{
|
||||
this.deviceNum = deviceNum;
|
||||
}
|
||||
public String getDeviceNum()
|
||||
{
|
||||
return deviceNum;
|
||||
}
|
||||
public void setCategoryId(Long categoryId)
|
||||
{
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
public Long getCategoryId()
|
||||
{
|
||||
return categoryId;
|
||||
}
|
||||
public void setCategoryName(String categoryName)
|
||||
{
|
||||
this.categoryName = categoryName;
|
||||
}
|
||||
public String getCategoryName()
|
||||
{
|
||||
return categoryName;
|
||||
}
|
||||
public void setDeviceName(String deviceName)
|
||||
{
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
public String getDeviceName()
|
||||
{
|
||||
return deviceName;
|
||||
}
|
||||
public void setFirmwareVersion(String firmwareVersion) { this.firmwareVersion = firmwareVersion; }
|
||||
public String getFirmwareVersion()
|
||||
{
|
||||
return firmwareVersion;
|
||||
}
|
||||
public void setOwnerId(String ownerId)
|
||||
{
|
||||
this.ownerId = ownerId;
|
||||
}
|
||||
public String getOwnerId()
|
||||
{
|
||||
return ownerId;
|
||||
}
|
||||
public void setNickName(String nickName)
|
||||
{
|
||||
this.nickName = nickName;
|
||||
}
|
||||
public String getNickName()
|
||||
{
|
||||
return nickName;
|
||||
}
|
||||
public void setDelFlag(String delFlag)
|
||||
{
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
public String getDelFlag()
|
||||
{
|
||||
return delFlag;
|
||||
}
|
||||
|
||||
public void setIsAlarm(Integer isAlarm)
|
||||
{
|
||||
this.isAlarm = isAlarm;
|
||||
}
|
||||
public Integer getIsAlarm()
|
||||
{
|
||||
return isAlarm;
|
||||
}
|
||||
public void setIsRadar(Integer isRadar)
|
||||
{
|
||||
this.isRadar = isRadar;
|
||||
}
|
||||
public Integer getIsRadar()
|
||||
{
|
||||
return isRadar;
|
||||
}
|
||||
public void setIsRfControl(Integer isRfControl)
|
||||
{
|
||||
this.isRfControl = isRfControl;
|
||||
}
|
||||
public Integer getIsRfControl()
|
||||
{
|
||||
return isRfControl;
|
||||
}
|
||||
public void setNetworkAddress(String networkAddress)
|
||||
{
|
||||
this.networkAddress = networkAddress;
|
||||
}
|
||||
public String getNetworkAddress()
|
||||
{
|
||||
return networkAddress;
|
||||
}
|
||||
public void setNetworkIp(String networkIp)
|
||||
{
|
||||
this.networkIp = networkIp;
|
||||
}
|
||||
public String getNetworkIp()
|
||||
{
|
||||
return networkIp;
|
||||
}
|
||||
|
||||
public void setRelayStatus(Integer relayStatus)
|
||||
{
|
||||
this.relayStatus = relayStatus;
|
||||
}
|
||||
public Integer getRelayStatus()
|
||||
{
|
||||
return relayStatus;
|
||||
}
|
||||
public void setLightStatus(Integer lightStatus)
|
||||
{
|
||||
this.lightStatus = lightStatus;
|
||||
}
|
||||
public Integer getLightStatus()
|
||||
{
|
||||
return lightStatus;
|
||||
}
|
||||
public void setIsOnline(Integer isOnline)
|
||||
{
|
||||
this.isOnline = isOnline;
|
||||
}
|
||||
public Integer getIsOnline()
|
||||
{
|
||||
return isOnline;
|
||||
}
|
||||
public void setDeviceTemperature(BigDecimal deviceTemperature) { this.deviceTemperature = deviceTemperature; }
|
||||
public BigDecimal getDeviceTemperature()
|
||||
{
|
||||
return deviceTemperature;
|
||||
}
|
||||
public void setRssi(Integer rssi)
|
||||
{
|
||||
this.rssi = rssi;
|
||||
}
|
||||
public Integer getRssi()
|
||||
{
|
||||
return rssi;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.fragment;
|
||||
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.core.webview.AgentWebActivity;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.grouplist.XUIGroupListView;
|
||||
import com.xuexiang.xutil.app.AppUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
|
||||
@Page(name = "关于")
|
||||
public class AboutFragment extends BaseFragment {
|
||||
@BindView(R.id.titlebar_min)
|
||||
TitleBar titleBarMin;
|
||||
|
||||
@BindView(R.id.tv_version)
|
||||
TextView mVersionTextView;
|
||||
@BindView(R.id.about_list)
|
||||
XUIGroupListView mAboutGroupListView;
|
||||
@BindView(R.id.tv_copyright)
|
||||
TextView mCopyrightTextView;
|
||||
@BindView(R.id.tv_autho)
|
||||
TextView tvAutho;
|
||||
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_about;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
titleBarMin.setLeftClickListener(v -> popToBack());
|
||||
|
||||
mVersionTextView.setText(String.format("版本号:%s", AppUtils.getAppVersionName()));
|
||||
tvAutho.setText("Author:kerwinci Website:www.wumei.live");
|
||||
|
||||
XUIGroupListView.newSection(getContext())
|
||||
.addItemView(mAboutGroupListView.createItemView(getResources().getString(R.string.about_item_homepage)), v -> AgentWebActivity.goWeb(getContext(), getString(R.string.url_project_github)))
|
||||
.addItemView(mAboutGroupListView.createItemView(getResources().getString(R.string.about_item_author_github)), v -> AgentWebActivity.goWeb(getContext(), getString(R.string.url_author_github)))
|
||||
.addItemView(mAboutGroupListView.createItemView(getResources().getString(R.string.about_item_add_qq_group)), v -> AgentWebActivity.goWeb(getContext(), getString(R.string.url_add_qq_group)))
|
||||
.addTo(mAboutGroupListView);
|
||||
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy", Locale.CHINA);
|
||||
String currentYear = dateFormat.format(new Date());
|
||||
mCopyrightTextView.setText(String.format(getResources().getString(R.string.about_copyright), currentYear));
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.kerwin.wumei.fragment;
|
||||
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.core.webview.AgentWebActivity;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xui.widget.grouplist.XUIGroupListView;
|
||||
import com.xuexiang.xutil.app.AppUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
@Page(name = "意见反馈")
|
||||
public class FeedbackFragment extends BaseFragment {
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_feedback;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,213 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.fragment;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.kerwin.wumei.activity.LoginActivity;
|
||||
import com.kerwin.wumei.activity.MainActivity;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.entity.IotGroup;
|
||||
import com.kerwin.wumei.entity.bo.CaptureImage;
|
||||
import com.kerwin.wumei.entity.User;
|
||||
import com.kerwin.wumei.http.callback.TipRequestCallBack;
|
||||
import com.kerwin.wumei.http.request.CaptchaImageApiResult;
|
||||
import com.kerwin.wumei.http.request.ListApiResult;
|
||||
import com.kerwin.wumei.http.request.TokenApiResult;
|
||||
import com.kerwin.wumei.http.request.UserInfoApiResult;
|
||||
import com.kerwin.wumei.utils.MMKVUtils;
|
||||
import com.kerwin.wumei.utils.SettingUtils;
|
||||
import com.kerwin.wumei.utils.TokenUtils;
|
||||
import com.kerwin.wumei.utils.Utils;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xaop.annotation.SingleClick;
|
||||
import com.xuexiang.xhttp2.XHttp;
|
||||
import com.xuexiang.xhttp2.callback.CallBackProxy;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xpage.enums.CoreAnim;
|
||||
import com.xuexiang.xui.utils.ResUtils;
|
||||
import com.xuexiang.xui.utils.ThemeUtils;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.button.roundbutton.RoundButton;
|
||||
import com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText;
|
||||
import com.xuexiang.xutil.app.ActivityUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
import static com.kerwin.wumei.utils.SettingUtils.getServerPath;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.clearToken;
|
||||
|
||||
|
||||
/**
|
||||
* 登录页面
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2019-11-17 22:15
|
||||
*/
|
||||
@Page(anim = CoreAnim.none)
|
||||
public class LoginFragment extends BaseFragment {
|
||||
|
||||
@BindView(R.id.et_phone_number)
|
||||
MaterialEditText etPhoneNumber;
|
||||
@BindView(R.id.et_password)
|
||||
MaterialEditText etPassword;
|
||||
@BindView(R.id.et_verify_code)
|
||||
MaterialEditText etVerifyCode;
|
||||
@BindView(R.id.iv_code)
|
||||
ImageView imgVertifyCode;
|
||||
@BindView(R.id.btn_clear)
|
||||
RoundButton btnClear;
|
||||
|
||||
private String uuid="";
|
||||
private String token="";
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_login;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
TitleBar titleBar = super.initTitle()
|
||||
.setImmersive(true);
|
||||
titleBar.setBackgroundColor(Color.TRANSPARENT);
|
||||
titleBar.setTitle("");
|
||||
titleBar.setLeftImageDrawable(ResUtils.getVectorDrawable(getContext(), R.drawable.ic_login_close));
|
||||
titleBar.setActionTextColor(ThemeUtils.resolveColor(getContext(), R.attr.colorAccent));
|
||||
titleBar.addAction(new TitleBar.TextAction(R.string.title_jump_login) {
|
||||
@Override
|
||||
public void performAction(View view) {
|
||||
clearToken();
|
||||
onLoginSuccess();
|
||||
}
|
||||
});
|
||||
return titleBar;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
//隐私政策弹窗
|
||||
// if (!SettingUtils.isAgreePrivacy()) {
|
||||
// Utils.showPrivacyDialog(getContext(), (dialog, which) -> {
|
||||
// dialog.dismiss();
|
||||
// SettingUtils.setIsAgreePrivacy(true);
|
||||
// });
|
||||
// }
|
||||
getCatpureImage();
|
||||
getLocalAccount();
|
||||
}
|
||||
|
||||
@SingleClick
|
||||
@OnClick({ R.id.btn_login,R.id.iv_code,R.id.btn_clear})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.btn_clear:
|
||||
SettingUtils.clearPassword();
|
||||
etPassword.clear();
|
||||
break;
|
||||
case R.id.iv_code:
|
||||
getCatpureImage();
|
||||
break;
|
||||
case R.id.btn_login:
|
||||
if(etPhoneNumber.getEditValue().length()==0 || etPassword.getEditValue().length()==0 || etVerifyCode.getEditValue().length()==0){
|
||||
XToastUtils.error("请正确填写账号、密码和验证码");
|
||||
}else {
|
||||
loginByVerifyCode(etPhoneNumber.getEditValue(), etPassword.getEditValue(), etVerifyCode.getEditValue());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录成功的处理
|
||||
*/
|
||||
private void onLoginSuccess() {
|
||||
TokenUtils.handleLoginSuccess(token);
|
||||
popToBack();
|
||||
ActivityUtils.startActivity(MainActivity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地存储的账号
|
||||
*/
|
||||
private void getLocalAccount(){
|
||||
etPhoneNumber.setText(SettingUtils.getUserName());
|
||||
etPassword.setText(SettingUtils.getPassword());
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP获取验证码
|
||||
*/
|
||||
private void getCatpureImage(){
|
||||
XHttp.get(getServerPath()+"/captchaImage")
|
||||
.execute(new CallBackProxy<CaptchaImageApiResult<CaptureImage>, CaptureImage>(new TipRequestCallBack<CaptureImage>() {
|
||||
@Override
|
||||
public void onSuccess(CaptureImage image) throws Throwable {
|
||||
uuid=image.getUuid();
|
||||
byte[] decode = Base64.decode(image.getImg(), Base64.DEFAULT);
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(decode, 0, decode.length);
|
||||
imgVertifyCode.setImageBitmap(bitmap);
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP登录
|
||||
*
|
||||
* @param phoneNumber 手机号
|
||||
* @param verifyCode 验证码
|
||||
*/
|
||||
private void loginByVerifyCode(String phoneNumber,String password, String verifyCode) {
|
||||
XHttp.post(getServerPath()+ "/login")
|
||||
.upJson("{\"username\":\""+phoneNumber+"\",\"password\":\""+password+"\",\"code\":\""+verifyCode+"\",\"uuid\":\""+uuid+"\"}")
|
||||
.execute(new CallBackProxy<TokenApiResult<String>, String>(new TipRequestCallBack<String>() {
|
||||
@Override
|
||||
public void onSuccess(String tokenResult) throws Throwable {
|
||||
SettingUtils.setAccount(etPhoneNumber.getEditValue(),etPassword.getEditValue());
|
||||
token=tokenResult;
|
||||
onLoginSuccess();
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
clearToken();
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.kerwin.wumei.fragment;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.core.webview.AgentWebActivity;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xaop.annotation.SingleClick;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.grouplist.XUIGroupListView;
|
||||
import com.xuexiang.xutil.app.AppUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
|
||||
@Page(name = "消息")
|
||||
public class MessageFragment extends BaseFragment {
|
||||
@BindView(R.id.titlebar_min)
|
||||
TitleBar titleBarMin;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_message;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
titleBarMin.setLeftClickListener(v -> popToBack());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.fragment;
|
||||
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.http.callback.TipRequestCallBack;
|
||||
import com.kerwin.wumei.http.request.NoDataApiResult;
|
||||
import com.kerwin.wumei.http.request.TokenApiResult;
|
||||
import com.kerwin.wumei.utils.TokenUtils;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xaop.annotation.SingleClick;
|
||||
import com.xuexiang.xhttp2.XHttp;
|
||||
import com.xuexiang.xhttp2.callback.CallBackProxy;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xui.widget.dialog.DialogLoader;
|
||||
import com.xuexiang.xui.widget.textview.supertextview.SuperTextView;
|
||||
import com.xuexiang.xutil.XUtil;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
import static com.kerwin.wumei.utils.SettingUtils.getServerPath;
|
||||
|
||||
/**
|
||||
* @author xuexiang
|
||||
* @since 2019-10-15 22:38
|
||||
*/
|
||||
@Page(name = "设置")
|
||||
public class SettingsFragment extends BaseFragment implements SuperTextView.OnSuperTextViewClickListener {
|
||||
|
||||
@BindView(R.id.menu_common)
|
||||
SuperTextView menuCommon;
|
||||
@BindView(R.id.menu_privacy)
|
||||
SuperTextView menuPrivacy;
|
||||
@BindView(R.id.menu_push)
|
||||
SuperTextView menuPush;
|
||||
@BindView(R.id.menu_helper)
|
||||
SuperTextView menuHelper;
|
||||
@BindView(R.id.menu_change_account)
|
||||
SuperTextView menuChangeAccount;
|
||||
@BindView(R.id.menu_logout)
|
||||
SuperTextView menuLogout;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
menuCommon.setOnSuperTextViewClickListener(this);
|
||||
menuPrivacy.setOnSuperTextViewClickListener(this);
|
||||
menuPush.setOnSuperTextViewClickListener(this);
|
||||
menuHelper.setOnSuperTextViewClickListener(this);
|
||||
menuChangeAccount.setOnSuperTextViewClickListener(this);
|
||||
menuLogout.setOnSuperTextViewClickListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP退出登录
|
||||
*/
|
||||
private void logout(){
|
||||
XHttp.post(getServerPath()+"/logout")
|
||||
.execute(new CallBackProxy<NoDataApiResult<String>, String>(new TipRequestCallBack<String>() {
|
||||
@Override
|
||||
public void onSuccess(String tokenResult) throws Throwable {
|
||||
XToastUtils.success("登出成功" );
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
@SingleClick
|
||||
@Override
|
||||
public void onClick(SuperTextView superTextView) {
|
||||
switch (superTextView.getId()) {
|
||||
case R.id.menu_common:
|
||||
case R.id.menu_privacy:
|
||||
case R.id.menu_push:
|
||||
case R.id.menu_helper:
|
||||
XToastUtils.toast(superTextView.getLeftString());
|
||||
break;
|
||||
case R.id.menu_change_account:
|
||||
XToastUtils.toast(superTextView.getCenterString());
|
||||
break;
|
||||
case R.id.menu_logout:
|
||||
DialogLoader.getInstance().showConfirmDialog(
|
||||
getContext(),
|
||||
getString(R.string.lab_logout_confirm),
|
||||
getString(R.string.lab_yes),
|
||||
(dialog, which) -> {
|
||||
logout();
|
||||
dialog.dismiss();
|
||||
XUtil.getActivityLifecycleHelper().exit();
|
||||
TokenUtils.handleLogoutSuccess();
|
||||
},
|
||||
getString(R.string.lab_no),
|
||||
(dialog, which) -> dialog.dismiss()
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,303 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
*****************************************************************************/
|
||||
package com.kerwin.wumei.fragment.device;
|
||||
|
||||
import android.Manifest;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.text.method.HideReturnsTransformationMethod;
|
||||
import android.text.method.PasswordTransformationMethod;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
|
||||
import com.kerwin.wumei.MyApp;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.activity.AddDeviceActivity;
|
||||
import com.kerwin.wumei.adapter.entity.EspTouchViewModel;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.king.view.circleprogressview.CircleProgressView;
|
||||
|
||||
import com.xuexiang.xui.widget.textview.supertextview.SuperButton;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
import static com.kerwin.wumei.utils.SettingUtils.getWifiPassword;
|
||||
import static com.kerwin.wumei.utils.SettingUtils.setWifiPassword;
|
||||
|
||||
|
||||
@Page(name = "智能配网")
|
||||
public class AddDeviceFragment extends BaseFragment {
|
||||
@BindView(R.id.advance_frame_layout)
|
||||
FrameLayout advanceFrameLayout;
|
||||
@BindView(R.id.advance_linear_layout)
|
||||
LinearLayout advanceLinearLayout;
|
||||
@BindView(R.id.advance_icon)
|
||||
AppCompatImageView advanceIcon;
|
||||
@BindView(R.id.wifi_password_icon)
|
||||
AppCompatImageView wifiPasswordIcon;
|
||||
// @BindView(R.id.progressView_circle_main)
|
||||
// CircleProgressView progressViewCircleMain;
|
||||
@BindView(R.id.progress_text_main)
|
||||
TextView progressTextMain;
|
||||
@BindView(R.id.btn_config_cancle)
|
||||
SuperButton btnConfigCancle;
|
||||
@BindView(R.id.btn_return)
|
||||
SuperButton btnReturn;
|
||||
@BindView(R.id.chk_remeber)
|
||||
CheckBox chk_remeber;
|
||||
@BindView(R.id.circleProgressView)
|
||||
CircleProgressView circleProgressView;
|
||||
|
||||
private static final String TAG = AddDeviceFragment.class.getSimpleName();
|
||||
private static final int REQUEST_PERMISSION = 0x01;
|
||||
private EspTouchViewModel mViewModel;
|
||||
|
||||
private boolean bStart=false;
|
||||
|
||||
private Handler mHander=new Handler();
|
||||
private int mCount=0;
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_add_device;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
//智能配网
|
||||
mViewModel = ((AddDeviceActivity)this.getActivity()).GetMViewModel();
|
||||
|
||||
mViewModel.apPasswordEdit = findViewById(R.id.wifi_password_txt);
|
||||
mViewModel.apPasswordEdit.setText(getWifiPassword());
|
||||
|
||||
mViewModel.ssidSpinner = findViewById(R.id.ssid_spinner);
|
||||
mViewModel.packageModeGroup = findViewById(R.id.packageModeGroup);
|
||||
mViewModel.messageView = findViewById(R.id.txt_config_message);
|
||||
mViewModel.messageView.setText("");
|
||||
|
||||
mViewModel.xsbDeviceCount = findViewById(R.id.xsb_device_count);
|
||||
mViewModel.xsbDeviceCount.setDefaultValue(1);
|
||||
|
||||
mViewModel.confirmBtn = findViewById(R.id.btn_begin);
|
||||
mViewModel.confirmBtn.setOnClickListener(v ->
|
||||
{
|
||||
|
||||
((AddDeviceActivity)this.getActivity()).executeEsptouch();
|
||||
|
||||
//存储wifi密码
|
||||
if(chk_remeber.isChecked()){
|
||||
setWifiPassword(mViewModel.apPasswordEdit.getText().toString());
|
||||
}else{
|
||||
setWifiPassword("");
|
||||
}
|
||||
|
||||
// PageOption.to(AddDeviceTwoFragment.class) //跳转的fragment
|
||||
// .setAnim(CoreAnim.slide) //页面转场动画
|
||||
// .setRequestCode(100) //请求码,用于返回结果
|
||||
// .setAddToBackStack(true) //是否加入堆栈
|
||||
// .putString("device_mac","0908070605040306")
|
||||
// .open(this); //打开页面进行跳转
|
||||
});
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION};
|
||||
requestPermissions(permissions, REQUEST_PERMISSION);
|
||||
}
|
||||
|
||||
MyApp.getInstance().observeBroadcast(this, broadcast -> {
|
||||
Log.d(TAG, "onCreate: Broadcast=" + broadcast);
|
||||
((AddDeviceActivity)this.getActivity()).onWifiChanged();
|
||||
|
||||
List<String> ssids=((AddDeviceActivity)this.getActivity()).GetSsids();
|
||||
if(ssids!=null && ssids.size()>0){
|
||||
Log.e(TAG, "进入数据绑定 " );
|
||||
mViewModel.ssidSpinner.setItems(ssids);
|
||||
// ssidSpinner.setOnItemSelectedListener((spinner, position, id, item) -> SnackbarUtils.Long(spinner, "Clicked " + item).show());
|
||||
// ssidSpinner.setOnNothingSelectedListener(spinner -> SnackbarUtils.Long(spinner, "Nothing selected").show());
|
||||
String ssid=((AddDeviceActivity)this.getActivity()).GetSelectedSSID();
|
||||
if(ssid!=null && ssid.length()>0 && ssids.contains(ssid)) {
|
||||
mViewModel.ssidSpinner.setSelectedItem(ssid);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initListeners() {
|
||||
//单击高级设置项
|
||||
advanceFrameLayout.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int visible=advanceLinearLayout.getVisibility();
|
||||
if(visible!=0) {
|
||||
advanceLinearLayout.setVisibility(View.VISIBLE);
|
||||
advanceIcon.setImageDrawable(getResources().getDrawable((R.drawable.up)));
|
||||
}else{
|
||||
advanceLinearLayout.setVisibility(View.GONE);
|
||||
advanceIcon.setImageDrawable(getResources().getDrawable((R.drawable.down)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//显示和隐藏密码
|
||||
wifiPasswordIcon.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view){
|
||||
if(wifiPasswordIcon.getTag()==null) return;
|
||||
if(wifiPasswordIcon.getTag().toString().equals("show")){
|
||||
wifiPasswordIcon.setImageDrawable(getResources().getDrawable((R.drawable.hide)));
|
||||
wifiPasswordIcon.setTag("hide");
|
||||
mViewModel.apPasswordEdit.setTransformationMethod(PasswordTransformationMethod.getInstance());
|
||||
}else{
|
||||
wifiPasswordIcon.setImageDrawable(getResources().getDrawable((R.drawable.show)));
|
||||
wifiPasswordIcon.setTag("show");
|
||||
mViewModel.apPasswordEdit.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
btnConfigCancle.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view){
|
||||
((AddDeviceActivity)getActivity()).interruptEspTouchTask();
|
||||
cancleCounter();
|
||||
}
|
||||
});
|
||||
|
||||
btnReturn.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view){
|
||||
popToBack();
|
||||
cancleCounter();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
cancleCounter();
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开计时器
|
||||
*/
|
||||
public void beginCounter(){
|
||||
mViewModel.confirmBtn.setEnabled(false);
|
||||
btnConfigCancle.setEnabled(true);
|
||||
showMessage("配网中...",true);
|
||||
mHander.post(mCounter);
|
||||
|
||||
//显示进度动画,进度,动画时长
|
||||
circleProgressView.showAnimation(100,3000);
|
||||
//设置进度改变监听
|
||||
circleProgressView.setOnChangeListener(new CircleProgressView.OnChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(float progress, float max) {
|
||||
if(progress==100){
|
||||
circleProgressView.setProgress(0);
|
||||
circleProgressView.showAnimation(100);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 计时器完成
|
||||
*/
|
||||
public void completeCounter(){
|
||||
mCount=0;
|
||||
mHander.removeCallbacks(mCounter);
|
||||
progressTextMain.setText("100");
|
||||
circleProgressView.setOnChangeListener(null);
|
||||
circleProgressView.showAppendAnimation(100);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭计时器
|
||||
*/
|
||||
public void cancleCounter(){
|
||||
mViewModel.confirmBtn.setEnabled(true);
|
||||
btnConfigCancle.setEnabled(false);
|
||||
showMessage("",true);
|
||||
|
||||
mCount=0;
|
||||
mHander.removeCallbacks(mCounter);
|
||||
progressTextMain.setText("0");
|
||||
circleProgressView.setOnChangeListener(null);
|
||||
circleProgressView.showAppendAnimation(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计时器
|
||||
*/
|
||||
private Runnable mCounter=new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int delay=300;
|
||||
if(mCount<30){
|
||||
mCount++;
|
||||
}else if(mCount<50){
|
||||
mCount++;
|
||||
delay=500;
|
||||
}else if(mCount<80){
|
||||
mCount++;
|
||||
delay=1000;
|
||||
}else if(mCount<90){
|
||||
mCount++;
|
||||
delay=3000;
|
||||
}else if(mCount<98){
|
||||
mCount++;
|
||||
delay=10000;
|
||||
}
|
||||
progressTextMain.setText(mCount + "");
|
||||
mHander.postDelayed(this, delay);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 消息提示
|
||||
* @param message
|
||||
* @param isSuccess
|
||||
*/
|
||||
public void showMessage(String message,boolean isSuccess){
|
||||
if(isSuccess){
|
||||
mViewModel.messageView.setTextColor(Color.argb(255, 103, 194, 58)); // 绿色
|
||||
}else{
|
||||
mViewModel.messageView.setTextColor(Color.argb(255, 245, 108, 108)); //红色
|
||||
}
|
||||
mViewModel.messageView.setText(message);
|
||||
mViewModel.messageView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
***************************************************************************/
|
||||
package com.kerwin.wumei.fragment.device;
|
||||
|
||||
import android.Manifest;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.method.HideReturnsTransformationMethod;
|
||||
import android.text.method.PasswordTransformationMethod;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
|
||||
import com.kerwin.wumei.MyApp;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.activity.AddDeviceActivity;
|
||||
import com.kerwin.wumei.activity.MainActivity;
|
||||
import com.kerwin.wumei.adapter.entity.EspTouchViewModel;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xui.widget.spinner.materialspinner.MaterialSpinner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
|
||||
@Page(name = "设备信息")
|
||||
public class AddDeviceTwoFragment extends BaseFragment {
|
||||
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_add_device_two;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
|
||||
Bundle arguments = getArguments();
|
||||
String mac = arguments.getString("device_mac");
|
||||
XToastUtils.toast("设备MAC:" + mac);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initListeners() {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.fragment.device;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.core.webview.AgentWebActivity;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xui.adapter.FragmentAdapter;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.grouplist.XUIGroupListView;
|
||||
import com.xuexiang.xui.widget.tabbar.TabSegment;
|
||||
import com.xuexiang.xutil.app.AppUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
|
||||
@Page(name = "设备详情")
|
||||
public class DeviceDetailFragment extends BaseFragment {
|
||||
@BindView(R.id.titlebar_min)
|
||||
TitleBar titleBarMin;
|
||||
@BindView(R.id.tabSegment)
|
||||
TabSegment tabSegment;
|
||||
@BindView(R.id.contentViewPager)
|
||||
ViewPager contentViewPager;
|
||||
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_device_detail;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
titleBarMin.setLeftClickListener(v -> popToBack());
|
||||
|
||||
Bundle arguments = getArguments();
|
||||
Long device_id = arguments.getLong("device_id");
|
||||
String device_num=arguments.getString("device_num");
|
||||
tabSegment.addTab(new TabSegment.Tab("设备"));
|
||||
tabSegment.addTab(new TabSegment.Tab("状态"));
|
||||
tabSegment.addTab(new TabSegment.Tab("配置"));
|
||||
|
||||
FragmentAdapter<BaseFragment> adapter = new FragmentAdapter<>(getChildFragmentManager());
|
||||
adapter.addFragment(new DeviceEditFragment(device_id,device_num), "");
|
||||
adapter.addFragment(new DeviceStatusFragment(device_id,device_num), "");
|
||||
adapter.addFragment(new DeviceSetFragment(device_id,device_num), "");
|
||||
|
||||
contentViewPager.setAdapter(adapter);
|
||||
contentViewPager.setCurrentItem(0, false);
|
||||
tabSegment.setupWithViewPager(contentViewPager, false);
|
||||
tabSegment.setMode(TabSegment.MODE_FIXED);
|
||||
}
|
||||
}
|
||||
@@ -1,244 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.kerwin.wumei.fragment.device;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.entity.DictData;
|
||||
import com.kerwin.wumei.entity.IotDevice;
|
||||
import com.kerwin.wumei.entity.IotDeviceStatus;
|
||||
import com.kerwin.wumei.http.callback.TipRequestCallBack;
|
||||
import com.kerwin.wumei.http.request.NoDataApiResult;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.rxutil2.rxjava.RxJavaUtils;
|
||||
import com.xuexiang.xaop.annotation.SingleClick;
|
||||
import com.xuexiang.xhttp2.XHttp;
|
||||
import com.xuexiang.xhttp2.callback.CallBackProxy;
|
||||
import com.xuexiang.xhttp2.callback.SimpleCallBack;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText;
|
||||
import com.xuexiang.xui.widget.textview.supertextview.SuperButton;
|
||||
import com.xuexiang.xui.widget.toast.XToast;
|
||||
import com.xuexiang.xutil.net.JsonUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
import static com.kerwin.wumei.utils.SettingUtils.getServerPath;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.clearToken;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.getToken;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.hasToken;
|
||||
|
||||
@Page(name = "编辑设备")
|
||||
public class DeviceEditFragment extends BaseFragment {
|
||||
|
||||
@BindView(R.id.et_device_name)
|
||||
MaterialEditText et_device_name;
|
||||
@BindView(R.id.et_device_remark)
|
||||
MaterialEditText et_device_remark;
|
||||
@BindView(R.id.txt_device_num)
|
||||
TextView txt_device_num;
|
||||
@BindView(R.id.txt_device_category)
|
||||
TextView txt_device_category;
|
||||
@BindView(R.id.txt_firmware_version)
|
||||
TextView txt_firmware_version;
|
||||
@BindView(R.id.txt_create_time)
|
||||
TextView txt_create_time;
|
||||
@BindView(R.id.sp_device_temperature)
|
||||
SuperButton sp_device_temperature;
|
||||
@BindView(R.id.update_device_temp_icon)
|
||||
AppCompatImageView update_temp_icon;
|
||||
@BindView(R.id.sp_upgrade)
|
||||
SuperButton sp_upgrade;
|
||||
|
||||
private Long deviceId=0L;
|
||||
private String deviceNum="";
|
||||
|
||||
public DeviceEditFragment(Long device_id,String device_num){
|
||||
deviceId=device_id;
|
||||
deviceNum=device_num;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 返回为 null意为不需要导航栏
|
||||
*/
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_device_edit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
getDevice(deviceId);
|
||||
}
|
||||
|
||||
@SingleClick
|
||||
@OnClick({ R.id.btn_save,R.id.btn_cancle_edit,R.id.update_device_temp_icon,R.id.sp_upgrade})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.btn_save:
|
||||
updateDevice(buildDevice());
|
||||
break;
|
||||
case R.id.btn_cancle_edit:
|
||||
popToBack();
|
||||
break;
|
||||
case R.id.update_device_temp_icon:
|
||||
getNewStatusData();
|
||||
update_temp_icon.setVisibility(View.GONE);
|
||||
break;
|
||||
case R.id.sp_upgrade:
|
||||
XToastUtils.success("固件已经是最新版本");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构建设备数据
|
||||
*/
|
||||
private IotDevice buildDevice(){
|
||||
IotDevice device=new IotDevice();
|
||||
device.setDeviceId(deviceId);
|
||||
device.setDeviceNum((String) txt_device_num.getText());
|
||||
device.setDeviceName(et_device_name.getEditValue());
|
||||
device.setRemark(et_device_remark.getEditValue());
|
||||
return device;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP获取最新设备信息
|
||||
*/
|
||||
private void getNewStatusData(){
|
||||
XHttp.get(getServerPath()+"/system/status/getStatus/"+deviceNum)
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new CallBackProxy<NoDataApiResult<String>, String>(new TipRequestCallBack<String>() {
|
||||
@Override
|
||||
public void onSuccess(String response) {
|
||||
getDeviceStatus(deviceId);
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP获取设备状态
|
||||
*/
|
||||
private void getDeviceStatus(Long device_id){
|
||||
XHttp.get(getServerPath()+"/system/status/new/"+device_id)
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new SimpleCallBack<IotDeviceStatus>() {
|
||||
@Override
|
||||
public void onSuccess(IotDeviceStatus status) throws Throwable {
|
||||
//更新温度
|
||||
sp_device_temperature.setText(status.getDeviceTemperature()+"℃");
|
||||
update_temp_icon.setVisibility(View.VISIBLE);
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP获取设备信息
|
||||
*/
|
||||
private void getDevice(Long device_id){
|
||||
XHttp.get(getServerPath()+"/system/device/"+device_id)
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new SimpleCallBack<IotDevice>() {
|
||||
@Override
|
||||
public void onSuccess(IotDevice device) throws Throwable {
|
||||
//绑定数据
|
||||
Log.d("deviceName:",device.getDeviceName());
|
||||
et_device_name.setText(device.getDeviceName());
|
||||
et_device_remark.setText(device.getRemark());
|
||||
txt_device_num.setText(device.getDeviceNum());
|
||||
txt_device_category.setText(device.getCategoryName());
|
||||
txt_firmware_version.setText("v"+(device.getFirmwareVersion()==null || device.getFirmwareVersion().length()==0? "1.0" : device.getFirmwareVersion()));
|
||||
txt_create_time.setText(device.getCreateTime());
|
||||
sp_device_temperature.setText(device.getDeviceTemp()==null?0+"℃":device.getDeviceTemp()+"℃");
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP更新设备信息
|
||||
*/
|
||||
private void updateDevice(IotDevice device){
|
||||
if(!hasToken()) return;
|
||||
XHttp.put(getServerPath()+"/system/device")
|
||||
.upJson(JsonUtil.toJson(device))
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new CallBackProxy<NoDataApiResult<String>, String>(new TipRequestCallBack<String>() {
|
||||
@Override
|
||||
public void onSuccess(String response) throws Throwable {
|
||||
Log.d("response:",response);
|
||||
XToastUtils.success("数据保存成功");
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}){});
|
||||
}
|
||||
}
|
||||
@@ -1,307 +0,0 @@
|
||||
/****************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
****************************************************************************/
|
||||
package com.kerwin.wumei.fragment.device;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.google.android.material.tabs.TabLayoutMediator;
|
||||
import com.kerwin.wumei.activity.LoginActivity;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.entity.DictData;
|
||||
import com.kerwin.wumei.entity.IotCategory;
|
||||
import com.kerwin.wumei.entity.IotDevice;
|
||||
import com.kerwin.wumei.entity.IotDeviceSet;
|
||||
import com.kerwin.wumei.entity.IotDeviceStatus;
|
||||
import com.kerwin.wumei.entity.IotGroup;
|
||||
import com.kerwin.wumei.fragment.LoginFragment;
|
||||
import com.kerwin.wumei.http.callback.TipRequestCallBack;
|
||||
import com.kerwin.wumei.http.request.ListApiResult;
|
||||
import com.kerwin.wumei.http.request.NoDataApiResult;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xhttp2.XHttp;
|
||||
import com.xuexiang.xhttp2.callback.CallBackProxy;
|
||||
import com.xuexiang.xhttp2.callback.SimpleCallBack;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xui.utils.WidgetUtils;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.toast.XToast;
|
||||
import com.xuexiang.xutil.app.ActivityUtils;
|
||||
import com.xuexiang.xutil.net.JsonUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
import static com.google.android.material.tabs.TabLayout.MODE_SCROLLABLE;
|
||||
import static com.kerwin.wumei.utils.SettingUtils.getServerPath;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.clearToken;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.getToken;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.hasToken;
|
||||
|
||||
@Page(name = "设备")
|
||||
public class DeviceFragment extends BaseFragment implements TabLayout.OnTabSelectedListener{
|
||||
|
||||
@BindView(R.id.tab_layout)
|
||||
TabLayout tabLayout;
|
||||
@BindView(R.id.view_pager)
|
||||
ViewPager2 viewPager;
|
||||
|
||||
private boolean mIsShowNavigationView;
|
||||
private FragmentStateViewPager2Adapter mAdapter;
|
||||
|
||||
/**
|
||||
* @return 返回为 null意为不需要导航栏
|
||||
*/
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
// mAdapter.addFragment(2, SimpleTabFragment.newInstance("动态加入"), "动态加入");
|
||||
// mAdapter.removeFragment(2);
|
||||
// mAdapter.notifyDataSetChanged();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_device;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
//获取分组列表
|
||||
getGroupList(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化设备列表
|
||||
* @param listener
|
||||
* @param groupList
|
||||
*/
|
||||
private void initDeviceListView(@NonNull TabLayout.OnTabSelectedListener listener,List<IotGroup> groupList){
|
||||
mAdapter = new FragmentStateViewPager2Adapter((Fragment) listener);
|
||||
tabLayout.setTabMode(MODE_SCROLLABLE);
|
||||
tabLayout.addOnTabSelectedListener(listener);
|
||||
viewPager.setAdapter(mAdapter);
|
||||
// 设置缓存的数量
|
||||
viewPager.setOffscreenPageLimit(10);
|
||||
new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> tab.setText(mAdapter.getPageTitle(position))).attach();
|
||||
|
||||
// 动态加载选项卡内容
|
||||
for (IotGroup group: groupList) {
|
||||
mAdapter.addFragment(SimpleTabFragment.newInstance(group.getGroupId()), group.getGroupName());
|
||||
}
|
||||
mAdapter.notifyDataSetChanged();
|
||||
viewPager.setCurrentItem(0, false);
|
||||
WidgetUtils.setTabLayoutTextFont(tabLayout);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP获取分组列表
|
||||
*/
|
||||
private void getGroupList(@NonNull TabLayout.OnTabSelectedListener listener){
|
||||
XHttp.get(getServerPath()+"/system/group/list?pageNum=1&pageSize=100")
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new CallBackProxy<ListApiResult<List<IotGroup>>, List<IotGroup>>(new TipRequestCallBack<List<IotGroup>>() {
|
||||
@Override
|
||||
public void onSuccess(List<IotGroup> list) throws Throwable {
|
||||
List<IotGroup> groupList=list;
|
||||
IotGroup iotGroup=new IotGroup();
|
||||
iotGroup.setGroupId(0L);
|
||||
iotGroup.setGroupName("全部");
|
||||
iotGroup.setGroupOrder(0);
|
||||
groupList.add(0,iotGroup);
|
||||
|
||||
initDeviceListView(listener,groupList);
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
List<IotGroup> groupList=new ArrayList<IotGroup>();
|
||||
IotGroup group=new IotGroup();
|
||||
group.setGroupId(0L);
|
||||
group.setGroupName("全部");
|
||||
groupList.add(group);
|
||||
initDeviceListView(listener,groupList);
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* HTTP获取触发源字典列表
|
||||
*/
|
||||
private void getTriggerSourceDic(){
|
||||
XHttp.get(getServerPath()+"/system/dict/data/type/iot_trigger_source")
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new SimpleCallBack<List<DictData>>() {
|
||||
@Override
|
||||
public void onSuccess(List<DictData> response) {
|
||||
Log.d("group name:",response.get(0).getDictLabel());
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* HTTP获取分组详情
|
||||
*/
|
||||
private void getGroup(Long groupId){
|
||||
if(!hasToken()) return;
|
||||
XHttp.get(getServerPath()+"/system/group/"+groupId)
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new SimpleCallBack<IotGroup>(){
|
||||
@Override
|
||||
public void onSuccess(IotGroup response) throws Throwable {
|
||||
|
||||
Log.d("response:","response");
|
||||
XToastUtils.info("response");
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP新增分组
|
||||
*/
|
||||
private void addGroup(IotGroup group){
|
||||
if(!hasToken()) return;
|
||||
XHttp.post(getServerPath()+"/system/group")
|
||||
.upJson(JsonUtil.toJson(group))
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new CallBackProxy<NoDataApiResult<String>, String>(new TipRequestCallBack<String>() {
|
||||
@Override
|
||||
public void onSuccess(String response) throws Throwable {
|
||||
|
||||
Log.d("response:","response");
|
||||
XToastUtils.info("response");
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP编辑分组
|
||||
*/
|
||||
private void editGroup(IotGroup group){
|
||||
if(!hasToken()) return;
|
||||
XHttp.put(getServerPath()+"/system/group")
|
||||
.upJson(JsonUtil.toJson(group))
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new CallBackProxy<NoDataApiResult<String>, String>(new TipRequestCallBack<String>() {
|
||||
@Override
|
||||
public void onSuccess(String response) throws Throwable {
|
||||
Log.d("response:","response");
|
||||
XToastUtils.info("response");
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP删除分组
|
||||
*/
|
||||
private void deleteGroup(Long groupId){
|
||||
if(!hasToken()) return;
|
||||
XHttp.delete(getServerPath()+"/system/group/"+groupId)
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new CallBackProxy<NoDataApiResult<String>, String>(new TipRequestCallBack<String>() {
|
||||
@Override
|
||||
public void onSuccess(String response) throws Throwable {
|
||||
Log.d("response:","response");
|
||||
XToastUtils.info("response");
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,269 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
***************************************************************************/
|
||||
package com.kerwin.wumei.fragment.device;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.entity.DictData;
|
||||
import com.kerwin.wumei.entity.IotDevice;
|
||||
import com.kerwin.wumei.entity.IotDeviceSet;
|
||||
import com.kerwin.wumei.http.callback.TipRequestCallBack;
|
||||
import com.kerwin.wumei.http.request.ListApiResult;
|
||||
import com.kerwin.wumei.http.request.NoDataApiResult;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xaop.annotation.SingleClick;
|
||||
import com.xuexiang.xhttp2.XHttp;
|
||||
import com.xuexiang.xhttp2.callback.CallBackProxy;
|
||||
import com.xuexiang.xhttp2.callback.SimpleCallBack;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xui.utils.WidgetUtils;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.button.switchbutton.SwitchButton;
|
||||
import com.xuexiang.xui.widget.picker.XSeekBar;
|
||||
import com.xuexiang.xutil.net.JsonUtil;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
import static com.kerwin.wumei.utils.SettingUtils.getServerPath;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.clearToken;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.getToken;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.hasToken;
|
||||
|
||||
@Page(name = "编辑设备配置")
|
||||
public class DeviceSetFragment extends BaseFragment {
|
||||
|
||||
@BindView(R.id.sb_radar)
|
||||
SwitchButton sb_radar;
|
||||
@BindView(R.id.sb_alarm)
|
||||
SwitchButton sb_alarm;
|
||||
@BindView(R.id.sb_rf_control)
|
||||
SwitchButton sb_rf_control;
|
||||
@BindView(R.id.sb_rf_learn)
|
||||
SwitchButton sb_rf_learn;
|
||||
@BindView(R.id.sb_rf_clear)
|
||||
SwitchButton sb_rf_clear;
|
||||
@BindView(R.id.sb_reset)
|
||||
SwitchButton sb_reset;
|
||||
@BindView(R.id.sb_open_ap)
|
||||
SwitchButton sb_open_ap;
|
||||
|
||||
@BindView(R.id.spinner_rf_func_one)
|
||||
Spinner spinner_rf_func_one;
|
||||
@BindView(R.id.spinner_rf_func_two)
|
||||
Spinner spinner_rf_func_two;
|
||||
@BindView(R.id.spinner_rf_func_three)
|
||||
Spinner spinner_rf_func_three;
|
||||
@BindView(R.id.spinner_rf_func_four)
|
||||
Spinner spinner_rf_func_four;
|
||||
|
||||
@BindView(R.id.xsb_radar_interval)
|
||||
XSeekBar xsb_radar_interval;
|
||||
|
||||
private Long deviceId=0L;
|
||||
private String deviceNum="";
|
||||
private List<DictData> rfFunctionList;
|
||||
private String[] rfFunctionStrings;
|
||||
|
||||
public DeviceSetFragment(Long device_id,String device_num){
|
||||
deviceId=device_id;
|
||||
deviceNum=device_num;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 返回为 null意为不需要导航栏
|
||||
*/
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_device_set;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
getRFFunctionDic();
|
||||
|
||||
}
|
||||
|
||||
@SingleClick
|
||||
@OnClick({ R.id.btn_apply_set,R.id.btn_cancle_set})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.btn_apply_set:
|
||||
updateDeviceSet(buildDeviceSet());
|
||||
break;
|
||||
case R.id.btn_cancle_set:
|
||||
popToBack();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建设备配置数据
|
||||
*/
|
||||
private IotDeviceSet buildDeviceSet(){
|
||||
IotDeviceSet deviceSet=new IotDeviceSet();
|
||||
deviceSet.setDeviceId(deviceId);
|
||||
deviceSet.setDeviceNum(deviceNum);
|
||||
deviceSet.setIsHost(0); //不托管
|
||||
deviceSet.setIsRadar(sb_radar.isChecked()==true?1:0);
|
||||
deviceSet.setIsAlarm(sb_alarm.isChecked()==true?1:0);
|
||||
deviceSet.setIsRfLearn(sb_rf_learn.isChecked()==true?1:0);
|
||||
deviceSet.setIsRfClear(sb_rf_clear.isChecked()==true?1:0);
|
||||
deviceSet.setIsAp(sb_open_ap.isChecked()==true?1:0);
|
||||
deviceSet.setIsReset(sb_reset.isChecked()==true?1:0);
|
||||
deviceSet.setIsRfControl(sb_rf_control.isChecked()==true?1:0);
|
||||
deviceSet.setRadarInterval(xsb_radar_interval.getSelectedNumber());
|
||||
deviceSet.setRfOneFunc(getValueByDicString(spinner_rf_func_one.getSelectedItem().toString()));
|
||||
deviceSet.setRfTwoFunc(getValueByDicString(spinner_rf_func_two.getSelectedItem().toString()));
|
||||
deviceSet.setRfThreeFunc(getValueByDicString(spinner_rf_func_three.getSelectedItem().toString()));
|
||||
deviceSet.setRfFourFunc(getValueByDicString(spinner_rf_func_four.getSelectedItem().toString()));
|
||||
return deviceSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典标签获取字典值
|
||||
* @param label
|
||||
* @return
|
||||
*/
|
||||
private int getValueByDicString(String label){
|
||||
for(DictData dict:rfFunctionList){
|
||||
if(dict.getDictLabel().equals(label)){
|
||||
return dict.getDictValue();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典值获取索引
|
||||
*/
|
||||
private int getIndexByDicValue(int value){
|
||||
for(int i=0;i<rfFunctionList.size();i++)
|
||||
{
|
||||
if(rfFunctionList.get(i).getDictValue()==value){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP获取遥控按键功能字典列表
|
||||
*/
|
||||
private void getRFFunctionDic(){
|
||||
XHttp.get(getServerPath()+"/system/dict/data/type/rf_function")
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new SimpleCallBack<List<DictData>>() {
|
||||
@Override
|
||||
public void onSuccess(List<DictData> list) {
|
||||
//绑定数据
|
||||
rfFunctionList=list;
|
||||
rfFunctionStrings=new String[rfFunctionList.size()];
|
||||
for(int i=0;i<rfFunctionList.size();i++){
|
||||
rfFunctionStrings[i]=rfFunctionList.get(i).getDictLabel();
|
||||
}
|
||||
WidgetUtils.initSpinnerStyle(spinner_rf_func_one, rfFunctionStrings);
|
||||
WidgetUtils.initSpinnerStyle(spinner_rf_func_two, rfFunctionStrings);
|
||||
WidgetUtils.initSpinnerStyle(spinner_rf_func_three, rfFunctionStrings);
|
||||
WidgetUtils.initSpinnerStyle(spinner_rf_func_four, rfFunctionStrings);
|
||||
//获取设备配置
|
||||
getDeviceSet(deviceId);
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP获取设备配置
|
||||
*/
|
||||
private void getDeviceSet(Long device_id){
|
||||
XHttp.get(getServerPath()+"/system/set/new/"+device_id)
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new SimpleCallBack<IotDeviceSet>() {
|
||||
@Override
|
||||
public void onSuccess(IotDeviceSet set) throws Throwable {
|
||||
//绑定数据
|
||||
Log.d("device num:",set.getDeviceNum());
|
||||
sb_radar.setChecked(set.getIsRadar()==1);
|
||||
sb_alarm.setChecked(set.getIsAlarm()==1);
|
||||
sb_rf_control.setChecked(set.getIsRfControl()==1);
|
||||
xsb_radar_interval.setDefaultValue(set.getRadarInterval());
|
||||
spinner_rf_func_one.setSelection(getIndexByDicValue(set.getRfOneFunc()));
|
||||
spinner_rf_func_two.setSelection(getIndexByDicValue(set.getRfTwoFunc()));
|
||||
spinner_rf_func_three.setSelection(getIndexByDicValue(set.getRfThreeFunc()));
|
||||
spinner_rf_func_four.setSelection(getIndexByDicValue(set.getRfFourFunc()));
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP更新设备配置
|
||||
*/
|
||||
private void updateDeviceSet(IotDeviceSet deviceSet){
|
||||
if(!hasToken()) return;
|
||||
XHttp.put(getServerPath()+"/system/set")
|
||||
.upJson(JsonUtil.toJson(deviceSet))
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new CallBackProxy<NoDataApiResult<String>, String>(new TipRequestCallBack<String>() {
|
||||
@Override
|
||||
public void onSuccess(String response) throws Throwable {
|
||||
Log.d("response:",response);
|
||||
XToastUtils.success("设备配置更新成功");
|
||||
sb_reset.setChecked(false);
|
||||
sb_open_ap.setChecked(false);
|
||||
sb_rf_clear.setChecked(false);
|
||||
sb_rf_learn.setChecked(false);
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}){});
|
||||
}
|
||||
}
|
||||
@@ -1,308 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
*****************************************************************************/
|
||||
package com.kerwin.wumei.fragment.device;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.entity.DictData;
|
||||
import com.kerwin.wumei.entity.IotDeviceStatus;
|
||||
import com.kerwin.wumei.http.callback.TipRequestCallBack;
|
||||
import com.kerwin.wumei.http.request.NoDataApiResult;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.rxutil2.rxjava.RxJavaUtils;
|
||||
import com.xuexiang.xaop.annotation.SingleClick;
|
||||
import com.xuexiang.xhttp2.XHttp;
|
||||
import com.xuexiang.xhttp2.callback.CallBackProxy;
|
||||
import com.xuexiang.xhttp2.callback.SimpleCallBack;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xui.utils.WidgetUtils;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.button.switchbutton.SwitchButton;
|
||||
import com.xuexiang.xui.widget.dialog.MiniLoadingDialog;
|
||||
import com.xuexiang.xui.widget.picker.XSeekBar;
|
||||
import com.xuexiang.xui.widget.textview.supertextview.SuperButton;
|
||||
import com.xuexiang.xutil.net.JsonUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
import static android.R.layout.simple_spinner_item;
|
||||
import static com.kerwin.wumei.utils.SettingUtils.getServerPath;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.clearToken;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.getToken;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.hasToken;
|
||||
|
||||
@Page(name = "编辑设备状态")
|
||||
public class DeviceStatusFragment extends BaseFragment implements CompoundButton.OnCheckedChangeListener {
|
||||
|
||||
@BindView(R.id.sb_relay)
|
||||
SwitchButton sb_relay;
|
||||
@BindView(R.id.sb_light)
|
||||
SwitchButton sb_light;
|
||||
@BindView(R.id.spinner_light_mode)
|
||||
Spinner spinner_light_mode;
|
||||
@BindView(R.id.xsb_fade_interval)
|
||||
XSeekBar xsb_fade_interval;
|
||||
@BindView(R.id.xsb_fade_time)
|
||||
XSeekBar xsb_fade_time;
|
||||
@BindView(R.id.xsb_brightness)
|
||||
XSeekBar xsb_brightness;
|
||||
@BindView(R.id.xsb_red)
|
||||
XSeekBar xsb_red;
|
||||
@BindView(R.id.xsb_green)
|
||||
XSeekBar xsb_green;
|
||||
@BindView(R.id.xsb_blue)
|
||||
XSeekBar xsb_blue;
|
||||
@BindView(R.id.sp_temperature)
|
||||
SuperButton sp_temperature;
|
||||
@BindView(R.id.sp_humidity)
|
||||
SuperButton sp_humidity;
|
||||
@BindView(R.id.frame_layout_loading_status)
|
||||
FrameLayout frame_layout_loading_status;
|
||||
|
||||
private Long deviceId=0L;
|
||||
private String deviceNum="";
|
||||
private List<DictData> lightModeList;
|
||||
private String[] lightModeStrings;
|
||||
|
||||
public DeviceStatusFragment(Long device_id,String device_num){
|
||||
deviceId=device_id;
|
||||
deviceNum=device_num;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 返回为 null意为不需要导航栏
|
||||
*/
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_device_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
getLightModeDic();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化监听
|
||||
*/
|
||||
@Override
|
||||
protected void initListeners() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
XToastUtils.toast("isChecked:" + isChecked);
|
||||
}
|
||||
|
||||
@SingleClick
|
||||
@OnClick({ R.id.btn_apply_status,R.id.btn_cancle_status,R.id.frame_layout_loading_status})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.btn_apply_status:
|
||||
updateDeviceStatus(buildDeviceStatus());
|
||||
break;
|
||||
case R.id.btn_cancle_status:
|
||||
popToBack();
|
||||
break;
|
||||
case R.id.frame_layout_loading_status:
|
||||
getNewStatusData();
|
||||
frame_layout_loading_status.setVisibility(View.INVISIBLE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建设备状态数据
|
||||
*/
|
||||
private IotDeviceStatus buildDeviceStatus(){
|
||||
IotDeviceStatus deviceStatus=new IotDeviceStatus();
|
||||
deviceStatus.setDeviceId(deviceId);
|
||||
deviceStatus.setDeviceNum(deviceNum);
|
||||
deviceStatus.setRelayStatus(sb_relay.isChecked()==true?1:0);
|
||||
deviceStatus.setLightStatus(sb_light.isChecked()==true?1:0);
|
||||
deviceStatus.setLightMode(getValueByDicString(spinner_light_mode.getSelectedItem().toString()));
|
||||
deviceStatus.setLightInterval(xsb_fade_interval.getSelectedNumber());
|
||||
deviceStatus.setFadeTime(xsb_fade_time.getSelectedNumber());
|
||||
deviceStatus.setBrightness(xsb_brightness.getSelectedNumber());
|
||||
deviceStatus.setRed(xsb_red.getSelectedNumber());
|
||||
deviceStatus.setBlue(xsb_blue.getSelectedNumber());
|
||||
deviceStatus.setGreen(xsb_green.getSelectedNumber());
|
||||
deviceStatus.setTriggerSource(1); //0-无、1-按键、2.手机、3-浏览器、4-射频遥控、5-雷达、6-报警、7-定时
|
||||
return deviceStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典标签获取字典值
|
||||
*/
|
||||
private int getValueByDicString(String label){
|
||||
for(DictData dict:lightModeList){
|
||||
if(dict.getDictLabel().equals(label)){
|
||||
return dict.getDictValue();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典值获取索引
|
||||
*/
|
||||
private int getIndexByDicValue(int value){
|
||||
for(int i=0;i<lightModeList.size();i++)
|
||||
{
|
||||
if(lightModeList.get(i).getDictValue()==value){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP获取最新设备信息
|
||||
*/
|
||||
private void getNewStatusData(){
|
||||
XHttp.get(getServerPath()+"/system/status/getStatus/"+deviceNum)
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new CallBackProxy<NoDataApiResult<String>, String>(new TipRequestCallBack<String>() {
|
||||
@Override
|
||||
public void onSuccess(String response) {
|
||||
getDeviceStatus(deviceId);
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP获取灯模式字典列表
|
||||
*/
|
||||
private void getLightModeDic(){
|
||||
XHttp.get(getServerPath()+"/system/dict/data/type/light_mode")
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new SimpleCallBack<List<DictData>>() {
|
||||
@Override
|
||||
public void onSuccess(List<DictData> list) {
|
||||
lightModeList=list;
|
||||
lightModeStrings=new String[lightModeList.size()];
|
||||
for (int i=0;i<lightModeList.size();i++) {
|
||||
lightModeStrings[i]=lightModeList.get(i).getDictLabel();
|
||||
}
|
||||
WidgetUtils.initSpinnerStyle(spinner_light_mode, lightModeStrings);
|
||||
//获取设备状态
|
||||
getDeviceStatus(deviceId);
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP获取设备状态
|
||||
*/
|
||||
private void getDeviceStatus(Long device_id){
|
||||
XHttp.get(getServerPath()+"/system/status/new/"+device_id)
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new SimpleCallBack<IotDeviceStatus>() {
|
||||
@Override
|
||||
public void onSuccess(IotDeviceStatus status) throws Throwable {
|
||||
//绑定数据
|
||||
Log.d("device num:",status.getDeviceNum());
|
||||
sb_relay.setChecked(status.getRelayStatus()==1);
|
||||
sb_light.setChecked(status.getLightStatus()==1);
|
||||
xsb_fade_interval.setDefaultValue(status.getLightInterval());
|
||||
xsb_fade_time.setDefaultValue(status.getFadeTime());
|
||||
xsb_red.setDefaultValue(status.getRed());
|
||||
xsb_green.setDefaultValue(status.getGreen());
|
||||
xsb_blue.setDefaultValue(status.getBlue());
|
||||
xsb_blue.setDefaultValue(status.getBrightness());
|
||||
sp_temperature.setText(status.getAirTemperature()+"℃");
|
||||
sp_humidity.setText(status.getAirHumidity()+"RH%");
|
||||
spinner_light_mode.setSelection(getIndexByDicValue(status.getLightMode()));
|
||||
frame_layout_loading_status.setVisibility(View.VISIBLE);
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP更新设备状态
|
||||
*/
|
||||
private void updateDeviceStatus(IotDeviceStatus deviceStatus){
|
||||
if(!hasToken()) return;
|
||||
XHttp.put(getServerPath()+"/system/status")
|
||||
.upJson(JsonUtil.toJson(deviceStatus))
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new CallBackProxy<NoDataApiResult<String>, String>(new TipRequestCallBack<String>() {
|
||||
@Override
|
||||
public void onSuccess(String response) throws Throwable {
|
||||
Log.d("response:",response);
|
||||
XToastUtils.success("设备状态更新成功");
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}){});
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.kerwin.wumei.fragment.device;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
|
||||
@Page(name = "分享设备")
|
||||
public class EditDeviceFragment extends BaseFragment {
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_edit_device;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
*****************************************************************************/
|
||||
package com.kerwin.wumei.fragment.device;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* @author xuexiang
|
||||
* @since 2020/5/21 1:27 AM
|
||||
*/
|
||||
public class FragmentStateViewPager2Adapter extends FragmentStateAdapter {
|
||||
|
||||
private List<Fragment> mFragmentList = new ArrayList<>();
|
||||
|
||||
private List<String> mTitleList = new ArrayList<>();
|
||||
|
||||
private List<Long> mIds = new ArrayList<>();
|
||||
|
||||
private AtomicLong mAtomicLong = new AtomicLong(0);
|
||||
|
||||
public FragmentStateViewPager2Adapter(@NonNull Fragment fragment) {
|
||||
super(fragment);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
return mFragmentList.get(position);
|
||||
}
|
||||
|
||||
public FragmentStateViewPager2Adapter addFragment(Fragment fragment, String title) {
|
||||
if (fragment != null) {
|
||||
mFragmentList.add(fragment);
|
||||
mTitleList.add(title);
|
||||
mIds.add(getAtomicGeneratedId());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public FragmentStateViewPager2Adapter addFragment(int index, Fragment fragment, String title) {
|
||||
if (fragment != null && index >= 0 && index <= mFragmentList.size()) {
|
||||
mFragmentList.add(index, fragment);
|
||||
mTitleList.add(index, title);
|
||||
mIds.add(index, getAtomicGeneratedId());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public FragmentStateViewPager2Adapter removeFragment(int index) {
|
||||
if (index >= 0 && index < mFragmentList.size()) {
|
||||
mFragmentList.remove(index);
|
||||
mTitleList.remove(index);
|
||||
mIds.remove(index);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private long getAtomicGeneratedId() {
|
||||
return mAtomicLong.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mFragmentList.size();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
mFragmentList.clear();
|
||||
mTitleList.clear();
|
||||
mIds.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return mTitleList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return mIds.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItem(long itemId) {
|
||||
return mIds.contains(itemId);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.kerwin.wumei.fragment.device;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
|
||||
@Page(name = "分组管理")
|
||||
public class GroupFragment extends BaseFragment {
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_group;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.kerwin.wumei.fragment.device;/*
|
||||
|
||||
|
||||
/**
|
||||
* @author xuexiang
|
||||
* @since 2018/12/26 下午11:49
|
||||
*/
|
||||
public enum MultiPage {
|
||||
|
||||
全部(0),
|
||||
浇灌(1),
|
||||
一楼(2),
|
||||
二楼(3),
|
||||
三楼(4),
|
||||
走廊(5);
|
||||
|
||||
private final int position;
|
||||
|
||||
MultiPage(int pos) {
|
||||
position = pos;
|
||||
}
|
||||
|
||||
public static MultiPage getPage(int position) {
|
||||
return MultiPage.values()[position];
|
||||
}
|
||||
|
||||
public static int size() {
|
||||
return MultiPage.values().length;
|
||||
}
|
||||
|
||||
public static String[] getPageNames() {
|
||||
MultiPage[] pages = MultiPage.values();
|
||||
String[] pageNames = new String[pages.length];
|
||||
for (int i = 0; i < pages.length; i++) {
|
||||
pageNames[i] = pages[i].name();
|
||||
}
|
||||
return pageNames;
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.kerwin.wumei.fragment.device;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.core.webview.AgentWebActivity;
|
||||
import com.kerwin.wumei.entity.bo.CaptureImage;
|
||||
import com.kerwin.wumei.http.callback.TipRequestCallBack;
|
||||
import com.kerwin.wumei.http.request.CaptchaImageApiResult;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xaop.annotation.SingleClick;
|
||||
import com.xuexiang.xhttp2.XHttp;
|
||||
import com.xuexiang.xhttp2.callback.CallBackProxy;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xpage.enums.CoreAnim;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.button.switchbutton.SwitchButton;
|
||||
import com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText;
|
||||
import com.xuexiang.xui.widget.textview.supertextview.SuperButton;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
import static com.kerwin.wumei.utils.SettingUtils.getApIp;
|
||||
import static com.kerwin.wumei.utils.SettingUtils.getServerAddress;
|
||||
import static com.kerwin.wumei.utils.SettingUtils.getServerPath;
|
||||
import static com.kerwin.wumei.utils.SettingUtils.setAccount;
|
||||
import static com.kerwin.wumei.utils.SettingUtils.setApIp;
|
||||
import static com.kerwin.wumei.utils.SettingUtils.setServeAddress;
|
||||
import static com.kerwin.wumei.utils.SettingUtils.setServePath;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.clearToken;
|
||||
|
||||
|
||||
@Page(name = "用户信息")
|
||||
public class SceneFragment extends BaseFragment {
|
||||
|
||||
@BindView(R.id.btn_connect_test)
|
||||
SuperButton btn_connect_test;
|
||||
@BindView(R.id.btn_save_serve)
|
||||
SuperButton btn_save_serve;
|
||||
@BindView(R.id.txt_message)
|
||||
TextView txt_message;
|
||||
@BindView(R.id.et_serve)
|
||||
MaterialEditText et_serve_address;
|
||||
@BindView(R.id.et_path)
|
||||
MaterialEditText et_serve_path;
|
||||
@BindView(R.id.et_ap_address)
|
||||
MaterialEditText et_ap_address;
|
||||
|
||||
/**
|
||||
* @return 返回为 null意为不需要导航栏
|
||||
*/
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_scene;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
et_serve_address.setText(getServerAddress());
|
||||
et_serve_path.setText(getServerPath());
|
||||
et_ap_address.setText(getApIp());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initListeners() { }
|
||||
|
||||
@SingleClick
|
||||
@OnClick({ R.id.btn_save_serve,R.id.btn_connect_test,R.id.btn_open_ap})
|
||||
public void onViewClicked(View view) {
|
||||
if(et_serve_address.getEditValue().length()==0)
|
||||
{
|
||||
showMessage("接口地址不能为空",false);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (view.getId()) {
|
||||
case R.id.btn_save_serve:
|
||||
setServeAddress(et_serve_address.getEditValue());
|
||||
setServePath(et_serve_path.getEditValue());
|
||||
clearToken();
|
||||
setAccount("","");
|
||||
showMessage("服务端地址信息存储成功,请重新启动APP!",true);
|
||||
break;
|
||||
case R.id.btn_connect_test:
|
||||
getCatpureImage();
|
||||
break;
|
||||
case R.id.btn_open_ap:
|
||||
if(et_ap_address.getEditValue()==null || et_ap_address.getEditValue().length()==0){
|
||||
XToastUtils.error("AP的地址不能为空");
|
||||
}else {
|
||||
AgentWebActivity.goWeb(getContext(), et_ap_address.getEditValue());
|
||||
setApIp(et_ap_address.getEditValue());
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* HTTP获取验证码(用于连接测试)
|
||||
*/
|
||||
private void getCatpureImage(){
|
||||
String address=et_serve_address.getEditValue();
|
||||
String path=et_serve_path.getEditValue();
|
||||
if(path==null || path.length()==0){
|
||||
Log.d("地址", address.substring(address.length()-1));
|
||||
if(address.substring(address.length()-1).equals("/")){
|
||||
address=address.substring(0,address.length()-1);
|
||||
}
|
||||
}
|
||||
String fullPath=address+path;
|
||||
XHttp.get(fullPath+ "/captchaImage")
|
||||
.execute(new CallBackProxy<CaptchaImageApiResult<CaptureImage>, CaptureImage>(new TipRequestCallBack<CaptureImage>() {
|
||||
@Override
|
||||
public void onSuccess(CaptureImage image) throws Throwable {
|
||||
String uuid=image.getUuid();
|
||||
showMessage("服务端连接成功",true);
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
showMessage("服务端连接失败\n"+"地址:"+et_serve_address.getEditValue()+et_serve_path.getEditValue()+"\n错误提示:"+e.getMessage(),false);
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示提示
|
||||
* @param message
|
||||
* @param isSuccess
|
||||
*/
|
||||
private void showMessage(String message,boolean isSuccess){
|
||||
if(isSuccess){
|
||||
txt_message.setTextColor(Color.argb(255, 103, 194, 58)); // 绿色
|
||||
}else{
|
||||
txt_message.setTextColor(Color.argb(255, 245, 108, 108)); //红色
|
||||
}
|
||||
txt_message.setText(message);
|
||||
txt_message.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.kerwin.wumei.fragment.device;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xpage.enums.CoreAnim;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
|
||||
@Page(name = "分享设备")
|
||||
public class ShareDeviceFragment extends BaseFragment {
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_share_device;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,386 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.kerwin.wumei.fragment.device;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Vibrator;
|
||||
import android.util.Log;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.alibaba.android.vlayout.DelegateAdapter;
|
||||
import com.alibaba.android.vlayout.VirtualLayoutManager;
|
||||
import com.alibaba.android.vlayout.layout.StaggeredGridLayoutHelper;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.adapter.base.broccoli.BroccoliSimpleDelegateAdapter;
|
||||
import com.kerwin.wumei.adapter.base.delegate.SimpleDelegateAdapter;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.entity.IotCategory;
|
||||
import com.kerwin.wumei.entity.IotDeviceStatus;
|
||||
import com.kerwin.wumei.entity.vo.IotDeviceVo;
|
||||
import com.kerwin.wumei.http.callback.TipRequestCallBack;
|
||||
import com.kerwin.wumei.http.request.ListApiResult;
|
||||
import com.kerwin.wumei.http.request.NoDataApiResult;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
|
||||
import com.xuexiang.xhttp2.XHttp;
|
||||
import com.xuexiang.xhttp2.callback.CallBackProxy;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xpage.base.XPageFragment;
|
||||
import com.xuexiang.xpage.core.PageOption;
|
||||
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.button.SwitchIconView;
|
||||
import com.xuexiang.xutil.net.JsonUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import me.samlss.broccoli.Broccoli;
|
||||
|
||||
import static com.kerwin.wumei.utils.SettingUtils.getServerPath;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.clearToken;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.getToken;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.hasToken;
|
||||
|
||||
@Page(name = "设备")
|
||||
public class SimpleTabFragment extends BaseFragment {
|
||||
private static final String TAG = "SimpleTabFragment";
|
||||
|
||||
|
||||
@BindView(R.id.recyclerView)
|
||||
RecyclerView recyclerView;
|
||||
@BindView(R.id.refreshLayout)
|
||||
SmartRefreshLayout refreshLayout;
|
||||
|
||||
private SimpleDelegateAdapter<IotDeviceVo> deviceAdapter;
|
||||
private List<IotDeviceVo> devices=new ArrayList<IotDeviceVo>() {};
|
||||
private int pageNum=1;
|
||||
private int pageSize=10;
|
||||
private Long groupId=0L;
|
||||
|
||||
|
||||
public static SimpleTabFragment newInstance(Long groupId) {
|
||||
SimpleTabFragment fragment = new SimpleTabFragment();
|
||||
fragment.groupId=groupId;
|
||||
return fragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_simple_tab;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 返回为 null意为不需要导航栏
|
||||
*/
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
initView();
|
||||
//Http获取设备列表
|
||||
getDeviceList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
Log.e(TAG, "onAttach:" + groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
Log.e(TAG, "onDetach:" + groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Log.e(TAG, "onResume:" + groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
Log.e(TAG, "onStop:" + groupId);
|
||||
}
|
||||
|
||||
|
||||
private void initView() {
|
||||
|
||||
VirtualLayoutManager virtualLayoutManager = new VirtualLayoutManager(getContext());
|
||||
recyclerView.setLayoutManager(virtualLayoutManager);
|
||||
RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
|
||||
recyclerView.setRecycledViewPool(viewPool);
|
||||
viewPool.setMaxRecycledViews(0, 10);
|
||||
|
||||
// 设备
|
||||
FragmentActivity activity=this.getActivity();
|
||||
XPageFragment fragment= this;
|
||||
deviceAdapter = new BroccoliSimpleDelegateAdapter<IotDeviceVo>(R.layout.adapter_device_card_view_list_item, new StaggeredGridLayoutHelper(2,0), devices) {
|
||||
@SuppressLint("ResourceType")
|
||||
@Override
|
||||
protected void onBindData(RecyclerViewHolder holder, IotDeviceVo device, int position) {
|
||||
if (device == null) {return;}
|
||||
|
||||
//设置item宽度,适配屏幕分辨率
|
||||
// CardView view=holder.findViewById(R.id.device_item_card_view);
|
||||
// int widthPixels = getScreenWidth(activity);
|
||||
// int space=dip2px(40); //间隙=左边距+右边距+中间间隔
|
||||
// ViewGroup.LayoutParams cardViewParams=view.getLayoutParams();
|
||||
// cardViewParams.width=(widthPixels-space)/2;
|
||||
|
||||
holder.text(R.id.device_item_title, device.getDeviceName());
|
||||
holder.text(R.id.device_item_temp, device.getDeviceTemperature()==null? 0+"℃":device.getDeviceTemperature()+"℃");
|
||||
holder.text(R.id.device_item_category, device.getCategoryName());
|
||||
|
||||
//状态图标
|
||||
SwitchIconView radarView=holder.findViewById(R.id.device_item_radar_icon);
|
||||
SwitchIconView alarmView=holder.findViewById(R.id.device_item_alarm_icon);
|
||||
SwitchIconView switchIconView=holder.findViewById(R.id.device_item_switch_button);
|
||||
SwitchIconView lightIconView=holder.findViewById(R.id.device_item_light_button);
|
||||
radarView.setIconEnabled(device.getIsRadar()!=null && device.getIsRadar()==1 && device.getIsOnline()==1?true:false);
|
||||
alarmView.setIconEnabled(device.getIsAlarm()!=null && device.getIsAlarm()==1 && device.getIsOnline()==1?true:false);
|
||||
switchIconView.setIconEnabled(device.getRelayStatus()!=null && device.getRelayStatus()==1 && device.getIsOnline()==1?true:false);
|
||||
lightIconView.setIconEnabled(device.getLightStatus()!=null && device.getLightStatus()==1 && device.getIsOnline()==1?true:false);
|
||||
|
||||
//显示网络信号:wifi信号强度(信号极好4格[-55—— 0],信号好3格[-70—— -55),信号一般2格[-85—— -70),信号差1格[-100—— -85))
|
||||
AppCompatImageView wifiView=holder.findViewById(R.id.device_item_wifi_icon);
|
||||
if(device.getIsOnline()!=null && device.getRssi()!=null) {
|
||||
if (device.getIsOnline() == 1 && device.getRssi() >= -55) {
|
||||
wifiView.setImageDrawable(getResources().getDrawable((R.drawable.wifi_4)));
|
||||
} else if (device.getIsOnline() == 1 && device.getRssi() >= 70) {
|
||||
wifiView.setImageDrawable(getResources().getDrawable((R.drawable.wifi_3)));
|
||||
} else if (device.getIsOnline() == 1 && device.getRssi() >= -85) {
|
||||
wifiView.setImageDrawable(getResources().getDrawable((R.drawable.wifi_2)));
|
||||
} else if (device.getIsOnline() == 1 && device.getRssi() >= -100) {
|
||||
wifiView.setImageDrawable(getResources().getDrawable((R.drawable.wifi_1)));
|
||||
}
|
||||
}
|
||||
|
||||
//其他文字、标题和图片
|
||||
FrameLayout flTitle=holder.findViewById(R.id.device_item_fl_title);
|
||||
if(device.getIsOnline()!=null && device.getIsOnline()==1){
|
||||
holder.text(R.id.device_item_wifi, "在线");
|
||||
flTitle.setBackgroundColor(Color.argb(255, 63, 208, 173));
|
||||
}else{
|
||||
holder.text(R.id.device_item_wifi, "离线");
|
||||
flTitle.setBackgroundColor(Color.argb(255, 220, 220, 220));
|
||||
//显示图标
|
||||
AppCompatImageView categoryIcon=holder.findViewById(R.id.device_item_category_icon);
|
||||
AppCompatImageView temp=holder.findViewById(R.id.device_item_temp_icon);
|
||||
categoryIcon.setColorFilter(Color.parseColor("#909399"));
|
||||
temp.setColorFilter(Color.parseColor("#909399"));
|
||||
}
|
||||
|
||||
holder.click(R.id.device_item_light_button, v -> {
|
||||
if(device.getIsOnline()==null || device.getIsOnline()==0) return;
|
||||
//震动
|
||||
Vibrator vibrator = (Vibrator) activity.getSystemService(activity.VIBRATOR_SERVICE);
|
||||
vibrator.vibrate(100);
|
||||
// 更新灯状态
|
||||
updateDeviceStatus(
|
||||
buildDeviceLightStatus(device.getDeviceId(), device.getDeviceNum(),lightIconView.isIconEnabled()==true?0:1)
|
||||
, lightIconView);
|
||||
});
|
||||
holder.click(R.id.device_item_switch_button, v -> {
|
||||
if(device.getIsOnline()==null || device.getIsOnline()==0) return;
|
||||
//震动
|
||||
Vibrator vibrator = (Vibrator) activity.getSystemService(activity.VIBRATOR_SERVICE);
|
||||
vibrator.vibrate(100);
|
||||
// 更新继电器状态
|
||||
updateDeviceStatus(
|
||||
buildDeviceRelayStatus(device.getDeviceId(),device.getDeviceNum(),switchIconView.isIconEnabled()==true?0:1)
|
||||
, switchIconView);
|
||||
});
|
||||
holder.click(R.id.device_item_card_view, v -> {
|
||||
|
||||
PageOption.to(DeviceDetailFragment.class) //跳转的fragment
|
||||
.setAddToBackStack(true) //是否加入堆栈
|
||||
.putLong("device_id", device.getDeviceId()) //传递的参数
|
||||
.putString("device_num",device.getDeviceNum())
|
||||
.setNewActivity(true)
|
||||
.open(fragment); //打开页面进行跳转
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindBroccoli(RecyclerViewHolder holder, Broccoli broccoli) {
|
||||
broccoli.addPlaceholders(
|
||||
holder.findView(R.id.device_item_title),
|
||||
holder.findView(R.id.update_device_temp_icon),
|
||||
holder.findView(R.id.device_item_category),
|
||||
holder.findView(R.id.device_item_category_icon),
|
||||
holder.findView(R.id.device_item_wifi),
|
||||
holder.findView(R.id.device_item_wifi_icon),
|
||||
holder.findView(R.id.device_item_temp),
|
||||
holder.findView(R.id.device_item_temp_icon),
|
||||
holder.findView(R.id.device_item_alarm_icon),
|
||||
holder.findView(R.id.device_item_alarm),
|
||||
holder.findView(R.id.device_item_radar),
|
||||
holder.findView(R.id.device_item_radar_icon),
|
||||
holder.findView(R.id.device_item_switch_button),
|
||||
holder.findView(R.id.device_item_light_button)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
DelegateAdapter delegateAdapter = new DelegateAdapter(virtualLayoutManager);
|
||||
delegateAdapter.addAdapter(deviceAdapter);
|
||||
recyclerView.setAdapter(delegateAdapter);
|
||||
|
||||
//下拉刷新
|
||||
refreshLayout.setOnRefreshListener(refreshLayout -> {
|
||||
refreshLayout.getLayout().postDelayed(() -> {
|
||||
pageNum=1;
|
||||
getDeviceList();
|
||||
}, 1000);
|
||||
});
|
||||
//上拉加载
|
||||
refreshLayout.setOnLoadMoreListener(refreshLayout -> {
|
||||
refreshLayout.getLayout().postDelayed(() -> {
|
||||
pageNum=pageNum+1;
|
||||
getDeviceList();
|
||||
}, 1000);
|
||||
});
|
||||
// refreshLayout.autoRefresh();//第一次进入触发自动刷新
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建设备状态数据
|
||||
*/
|
||||
private IotDeviceStatus buildDeviceLightStatus(Long deviceId,String deviceNum,int lightStatus){
|
||||
IotDeviceStatus deviceStatus=new IotDeviceStatus();
|
||||
deviceStatus.setDeviceId(deviceId);
|
||||
deviceStatus.setDeviceNum(deviceNum);
|
||||
deviceStatus.setLightStatus(lightStatus);
|
||||
deviceStatus.setTriggerSource(1); //0-无、1-按键、2.手机、3-浏览器、4-射频遥控、5-雷达、6-报警、7-定时
|
||||
return deviceStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建设备状态数据
|
||||
*/
|
||||
private IotDeviceStatus buildDeviceRelayStatus(Long deviceId,String deviceNum,int relayStatus){
|
||||
IotDeviceStatus deviceStatus=new IotDeviceStatus();
|
||||
deviceStatus.setDeviceId(deviceId);
|
||||
deviceStatus.setDeviceNum(deviceNum);
|
||||
deviceStatus.setRelayStatus(relayStatus);
|
||||
deviceStatus.setTriggerSource(1); //0-无、1-按键、2.手机、3-浏览器、4-射频遥控、5-雷达、6-报警、7-定时
|
||||
return deviceStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP更新设备状态
|
||||
*/
|
||||
private void updateDeviceStatus(IotDeviceStatus deviceStatus,SwitchIconView iconView){
|
||||
if(!hasToken()) return;
|
||||
XHttp.put(getServerPath()+"/system/status")
|
||||
.upJson(JsonUtil.toJson(deviceStatus))
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new CallBackProxy<NoDataApiResult<String>, String>(new TipRequestCallBack<String>() {
|
||||
@Override
|
||||
public void onSuccess(String response) throws Throwable {
|
||||
Log.d("response:",response);
|
||||
iconView.switchState(true);
|
||||
XToastUtils.success("设备状态更新成功");
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP获取设备列表
|
||||
*/
|
||||
private void getDeviceList(){
|
||||
XHttp.get(getServerPath()+"/system/device/list?"+"pageNum="+pageNum+"&pageSize="+pageSize+"&groupId="+groupId)
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new CallBackProxy<ListApiResult<List<IotDeviceVo>>, List<IotDeviceVo>>(new TipRequestCallBack<List<IotDeviceVo>>() {
|
||||
@Override
|
||||
public void onSuccess(List<IotDeviceVo> list) throws Throwable {
|
||||
if(pageNum==1) {
|
||||
deviceAdapter.refresh(list);
|
||||
refreshLayout.finishRefresh();
|
||||
}else {
|
||||
deviceAdapter.loadMore(list);
|
||||
refreshLayout.finishLoadMore();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP获取分类列表
|
||||
*/
|
||||
private void getCategoryList(){
|
||||
XHttp.get(getServerPath()+"/system/category/list?pageNum=1&pageSize=100")
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new CallBackProxy<ListApiResult<List<IotCategory>>, List<IotCategory>>(new TipRequestCallBack<List<IotCategory>>() {
|
||||
@Override
|
||||
public void onSuccess(List<IotCategory> list) throws Throwable {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.kerwin.wumei.fragment.news;
|
||||
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.alibaba.android.vlayout.DelegateAdapter;
|
||||
import com.alibaba.android.vlayout.VirtualLayoutManager;
|
||||
import com.alibaba.android.vlayout.layout.GridLayoutHelper;
|
||||
import com.alibaba.android.vlayout.layout.LinearLayoutHelper;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.adapter.base.broccoli.BroccoliSimpleDelegateAdapter;
|
||||
import com.kerwin.wumei.adapter.base.delegate.SimpleDelegateAdapter;
|
||||
import com.kerwin.wumei.adapter.base.delegate.SingleDelegateAdapter;
|
||||
import com.kerwin.wumei.adapter.entity.NewInfo;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.utils.DemoDataProvider;
|
||||
import com.kerwin.wumei.utils.Utils;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xpage.enums.CoreAnim;
|
||||
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;
|
||||
import com.xuexiang.xui.adapter.simple.AdapterItem;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.banner.widget.banner.SimpleImageBanner;
|
||||
import com.xuexiang.xui.widget.imageview.ImageLoader;
|
||||
import com.xuexiang.xui.widget.imageview.RadiusImageView;
|
||||
|
||||
import butterknife.BindView;
|
||||
import me.samlss.broccoli.Broccoli;
|
||||
|
||||
@Page(anim = CoreAnim.none)
|
||||
public class HomePageFragment extends BaseFragment {
|
||||
|
||||
@BindView(R.id.webview_home)
|
||||
WebView webView;
|
||||
@BindView(R.id.refreshLayout)
|
||||
SmartRefreshLayout refreshLayout;
|
||||
|
||||
private SimpleDelegateAdapter<NewInfo> mNewsAdapter;
|
||||
|
||||
/**
|
||||
* @return 返回为 null意为不需要导航栏
|
||||
*/
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_home_page;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
webView.loadUrl("http://wumei.live");
|
||||
//系统默认会通过手机浏览器打开网页,为了能够直接通过WebView显示网页,则必须设置
|
||||
webView.setWebViewClient(new WebViewClient(){
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
//使用WebView加载显示url
|
||||
view.loadUrl(url);
|
||||
//返回true
|
||||
return true;
|
||||
}
|
||||
});
|
||||
// 支持js中alert弹窗提示
|
||||
webView.setWebChromeClient(new WebChromeClient());
|
||||
|
||||
//声明WebSettings子类
|
||||
WebSettings webSettings = webView.getSettings();
|
||||
//如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //关闭webview中缓存
|
||||
webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
|
||||
webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initListeners() {
|
||||
//下拉刷新
|
||||
refreshLayout.setOnRefreshListener(refreshLayout -> {
|
||||
refreshLayout.getLayout().postDelayed(() -> {
|
||||
webView.reload();
|
||||
refreshLayout.finishRefresh();
|
||||
}, 1000);
|
||||
});
|
||||
//上拉加载
|
||||
refreshLayout.setOnLoadMoreListener(refreshLayout -> {
|
||||
// TODO: 2020-02-25 这里只是模拟了网络请求
|
||||
refreshLayout.getLayout().postDelayed(() -> {
|
||||
webView.reload();
|
||||
refreshLayout.finishLoadMore();
|
||||
}, 1000);
|
||||
});
|
||||
refreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
|
||||
}
|
||||
}
|
||||
@@ -1,183 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.kerwin.wumei.fragment.news;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.alibaba.android.vlayout.DelegateAdapter;
|
||||
import com.alibaba.android.vlayout.VirtualLayoutManager;
|
||||
import com.alibaba.android.vlayout.layout.GridLayoutHelper;
|
||||
import com.alibaba.android.vlayout.layout.LinearLayoutHelper;
|
||||
import com.kerwin.wumei.adapter.base.broccoli.BroccoliSimpleDelegateAdapter;
|
||||
import com.kerwin.wumei.adapter.base.delegate.SimpleDelegateAdapter;
|
||||
import com.kerwin.wumei.adapter.base.delegate.SingleDelegateAdapter;
|
||||
import com.kerwin.wumei.adapter.entity.NewInfo;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.utils.DemoDataProvider;
|
||||
import com.kerwin.wumei.utils.Utils;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xpage.enums.CoreAnim;
|
||||
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;
|
||||
import com.xuexiang.xui.adapter.simple.AdapterItem;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.banner.widget.banner.SimpleImageBanner;
|
||||
import com.xuexiang.xui.widget.imageview.ImageLoader;
|
||||
import com.xuexiang.xui.widget.imageview.RadiusImageView;
|
||||
|
||||
import butterknife.BindView;
|
||||
import me.samlss.broccoli.Broccoli;
|
||||
|
||||
@Page(anim = CoreAnim.none)
|
||||
public class NewsFragment extends BaseFragment {
|
||||
|
||||
@BindView(R.id.recyclerView)
|
||||
RecyclerView recyclerView;
|
||||
@BindView(R.id.refreshLayout)
|
||||
SmartRefreshLayout refreshLayout;
|
||||
|
||||
private SimpleDelegateAdapter<NewInfo> mNewsAdapter;
|
||||
|
||||
/**
|
||||
* @return 返回为 null意为不需要导航栏
|
||||
*/
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_news;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
VirtualLayoutManager virtualLayoutManager = new VirtualLayoutManager(getContext());
|
||||
recyclerView.setLayoutManager(virtualLayoutManager);
|
||||
RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
|
||||
recyclerView.setRecycledViewPool(viewPool);
|
||||
viewPool.setMaxRecycledViews(0, 10);
|
||||
|
||||
//轮播条
|
||||
SingleDelegateAdapter bannerAdapter = new SingleDelegateAdapter(R.layout.include_head_view_banner) {
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {
|
||||
SimpleImageBanner banner = holder.findViewById(R.id.sib_simple_usage);
|
||||
banner.setSource(DemoDataProvider.getBannerList())
|
||||
.setOnItemClickListener((view, item, position1) -> XToastUtils.toast("headBanner position--->" + position1)).startScroll();
|
||||
}
|
||||
};
|
||||
|
||||
//九宫格菜单
|
||||
GridLayoutHelper gridLayoutHelper = new GridLayoutHelper(4);
|
||||
gridLayoutHelper.setPadding(0, 16, 0, 0);
|
||||
gridLayoutHelper.setVGap(10);
|
||||
gridLayoutHelper.setHGap(0);
|
||||
SimpleDelegateAdapter<AdapterItem> commonAdapter = new SimpleDelegateAdapter<AdapterItem>(R.layout.adapter_common_grid_item, gridLayoutHelper, DemoDataProvider.getGridItems(getContext())) {
|
||||
@Override
|
||||
protected void bindData(@NonNull RecyclerViewHolder holder, int position, AdapterItem item) {
|
||||
if (item != null) {
|
||||
RadiusImageView imageView = holder.findViewById(R.id.riv_item);
|
||||
imageView.setCircle(true);
|
||||
ImageLoader.get().loadImage(imageView, item.getIcon());
|
||||
holder.text(R.id.device_item_title, item.getTitle().toString().substring(0, 1));
|
||||
holder.text(R.id.tv_sub_title, item.getTitle());
|
||||
|
||||
holder.click(R.id.ll_container, v -> XToastUtils.toast("点击了:" + item.getTitle()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//动态的标题
|
||||
SingleDelegateAdapter titleAdapter = new SingleDelegateAdapter(R.layout.adapter_title_item) {
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {
|
||||
holder.text(R.id.device_item_title, "动态");
|
||||
holder.text(R.id.tv_action, "更多");
|
||||
holder.click(R.id.tv_action, v -> XToastUtils.toast("更多"));
|
||||
}
|
||||
};
|
||||
|
||||
// 动态
|
||||
mNewsAdapter = new BroccoliSimpleDelegateAdapter<NewInfo>(R.layout.adapter_news_card_view_list_item, new LinearLayoutHelper(), DemoDataProvider.getEmptyNewInfo()) {
|
||||
@Override
|
||||
protected void onBindData(RecyclerViewHolder holder, NewInfo model, int position) {
|
||||
if (model != null) {
|
||||
holder.text(R.id.tv_user_name, model.getUserName());
|
||||
holder.text(R.id.tv_tag, model.getTag());
|
||||
holder.text(R.id.device_item_title, model.getTitle());
|
||||
holder.text(R.id.tv_summary, model.getSummary());
|
||||
holder.text(R.id.tv_praise, model.getPraise() == 0 ? "点赞" : String.valueOf(model.getPraise()));
|
||||
holder.text(R.id.tv_comment, model.getComment() == 0 ? "评论" : String.valueOf(model.getComment()));
|
||||
holder.text(R.id.tv_read, "阅读量 " + model.getRead());
|
||||
holder.image(R.id.iv_image, model.getImageUrl());
|
||||
|
||||
holder.click(R.id.card_view, v -> Utils.goWeb(getContext(), model.getDetailUrl()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindBroccoli(RecyclerViewHolder holder, Broccoli broccoli) {
|
||||
broccoli.addPlaceholders(
|
||||
holder.findView(R.id.tv_user_name),
|
||||
holder.findView(R.id.tv_tag),
|
||||
holder.findView(R.id.device_item_title),
|
||||
holder.findView(R.id.tv_summary),
|
||||
holder.findView(R.id.tv_praise),
|
||||
holder.findView(R.id.tv_comment),
|
||||
holder.findView(R.id.tv_read),
|
||||
holder.findView(R.id.iv_image)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
DelegateAdapter delegateAdapter = new DelegateAdapter(virtualLayoutManager);
|
||||
delegateAdapter.addAdapter(bannerAdapter);
|
||||
delegateAdapter.addAdapter(commonAdapter);
|
||||
delegateAdapter.addAdapter(titleAdapter);
|
||||
delegateAdapter.addAdapter(mNewsAdapter);
|
||||
|
||||
recyclerView.setAdapter(delegateAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initListeners() {
|
||||
//下拉刷新
|
||||
refreshLayout.setOnRefreshListener(refreshLayout -> {
|
||||
// TODO: 2020-02-25 这里只是模拟了网络请求
|
||||
refreshLayout.getLayout().postDelayed(() -> {
|
||||
mNewsAdapter.refresh(DemoDataProvider.getDemoNewInfos());
|
||||
refreshLayout.finishRefresh();
|
||||
}, 1000);
|
||||
});
|
||||
//上拉加载
|
||||
refreshLayout.setOnLoadMoreListener(refreshLayout -> {
|
||||
// TODO: 2020-02-25 这里只是模拟了网络请求
|
||||
refreshLayout.getLayout().postDelayed(() -> {
|
||||
mNewsAdapter.loadMore(DemoDataProvider.getDemoNewInfos());
|
||||
refreshLayout.finishLoadMore();
|
||||
}, 1000);
|
||||
});
|
||||
refreshLayout.autoRefresh();//第一次进入触发自动刷新,演示效果
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.kerwin.wumei.fragment.profile;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.entity.User;
|
||||
import com.kerwin.wumei.entity.bo.CaptureImage;
|
||||
import com.kerwin.wumei.http.callback.TipRequestCallBack;
|
||||
import com.kerwin.wumei.http.request.CaptchaImageApiResult;
|
||||
import com.kerwin.wumei.http.request.UserInfoApiResult;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xaop.annotation.SingleClick;
|
||||
import com.xuexiang.xhttp2.XHttp;
|
||||
import com.xuexiang.xhttp2.callback.CallBackProxy;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xpage.enums.CoreAnim;
|
||||
import com.xuexiang.xui.utils.ResUtils;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.button.switchbutton.SwitchButton;
|
||||
import com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText;
|
||||
import com.xuexiang.xui.widget.imageview.RadiusImageView;
|
||||
import com.xuexiang.xui.widget.textview.supertextview.SuperButton;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
import static com.kerwin.wumei.utils.SettingUtils.getServerPath;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.clearToken;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.getToken;
|
||||
import static com.kerwin.wumei.utils.TokenUtils.hasToken;
|
||||
|
||||
|
||||
@Page(name = "账户信息")
|
||||
public class AccountFragment extends BaseFragment {
|
||||
@BindView(R.id.titlebar_min)
|
||||
TitleBar titleBarMin;
|
||||
|
||||
@BindView(R.id.txt_user_name)
|
||||
TextView txt_user_name;
|
||||
@BindView(R.id.txt_nick_name)
|
||||
TextView txt_nick_name;
|
||||
@BindView(R.id.txt_email)
|
||||
TextView txt_email;
|
||||
@BindView(R.id.txt_phone_num)
|
||||
TextView txt_phone_num;
|
||||
@BindView(R.id.txt_create_time)
|
||||
TextView txt_create_time;
|
||||
@BindView(R.id.txt_remark)
|
||||
TextView txt_remark;
|
||||
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_account;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
titleBarMin.setLeftClickListener(v -> popToBack());
|
||||
getUserInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initListeners() { }
|
||||
|
||||
@SingleClick
|
||||
@OnClick({ R.id.btn_confirm})
|
||||
public void onViewClicked(View view) {
|
||||
popToBack();
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP获取用户信息
|
||||
*/
|
||||
private void getUserInfo(){
|
||||
if(!hasToken()) return;
|
||||
XHttp.get(getServerPath()+"/getInfo")
|
||||
.headers("Authorization","Bearer "+getToken())
|
||||
.execute(new CallBackProxy<UserInfoApiResult<User>, User>(new TipRequestCallBack<User>() {
|
||||
@Override
|
||||
public void onSuccess(User user) throws Throwable {
|
||||
txt_user_name.setText(user.getUserName());
|
||||
txt_nick_name.setText(user.getNickName());
|
||||
txt_email.setText(user.getEmail());
|
||||
txt_phone_num.setText(user.getPhonenumber());
|
||||
txt_remark.setText(user.getRemark());
|
||||
txt_create_time.setText(user.getCreateTime());
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if(e.getCode()==401){
|
||||
XToastUtils.info("匿名登录状态,功能受限");
|
||||
clearToken();
|
||||
}else{
|
||||
XToastUtils.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.kerwin.wumei.fragment.profile;
|
||||
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kerwin.wumei.core.BaseFragment;
|
||||
import com.kerwin.wumei.R;
|
||||
import com.kerwin.wumei.core.webview.AgentWebActivity;
|
||||
import com.kerwin.wumei.fragment.AboutFragment;
|
||||
import com.kerwin.wumei.fragment.FeedbackFragment;
|
||||
import com.kerwin.wumei.fragment.MessageFragment;
|
||||
import com.kerwin.wumei.fragment.SettingsFragment;
|
||||
import com.kerwin.wumei.http.callback.TipRequestCallBack;
|
||||
import com.kerwin.wumei.http.request.NoDataApiResult;
|
||||
import com.kerwin.wumei.utils.TokenUtils;
|
||||
import com.kerwin.wumei.utils.XToastUtils;
|
||||
import com.xuexiang.xaop.annotation.SingleClick;
|
||||
import com.xuexiang.xhttp2.XHttp;
|
||||
import com.xuexiang.xhttp2.callback.CallBackProxy;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xpage.annotation.Page;
|
||||
import com.xuexiang.xpage.enums.CoreAnim;
|
||||
import com.xuexiang.xpage.utils.Utils;
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar;
|
||||
import com.xuexiang.xui.widget.dialog.DialogLoader;
|
||||
import com.xuexiang.xui.widget.grouplist.XUIGroupListView;
|
||||
import com.xuexiang.xui.widget.imageview.RadiusImageView;
|
||||
import com.xuexiang.xui.widget.textview.supertextview.SuperTextView;
|
||||
import com.xuexiang.xutil.XUtil;
|
||||
import com.xuexiang.xutil.app.AppUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
import static com.kerwin.wumei.utils.SettingUtils.getServerPath;
|
||||
|
||||
@Page(anim = CoreAnim.none)
|
||||
public class ProfileFragment extends BaseFragment implements SuperTextView.OnSuperTextViewClickListener {
|
||||
@BindView(R.id.riv_head_pic)
|
||||
RadiusImageView rivHeadPic;
|
||||
@BindView(R.id.menu_message)
|
||||
SuperTextView menuMessage;
|
||||
@BindView(R.id.menu_logout)
|
||||
SuperTextView menuLogout;
|
||||
@BindView(R.id.control_list)
|
||||
XUIGroupListView mControlGroupListView;
|
||||
@BindView(R.id.tv_copyright)
|
||||
TextView mCopyrightTextView;
|
||||
@BindView(R.id.menu_account)
|
||||
SuperTextView menuAccount;
|
||||
|
||||
/**
|
||||
* @return 返回为 null意为不需要导航栏
|
||||
*/
|
||||
@Override
|
||||
protected TitleBar initTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 布局的资源id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_profile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
@Override
|
||||
protected void initViews() {
|
||||
XUIGroupListView.newSection(getContext())
|
||||
.addItemView(mControlGroupListView.createItemView(getResources().getString(R.string.about_item_add_qq_group)), v -> AgentWebActivity.goWeb(getContext(), getString(R.string.url_add_qq_group)))
|
||||
.addItemView(mControlGroupListView.createItemView("应用版本 - V" + AppUtils.getAppVersionName()), v -> XToastUtils.toast("官网下载最新版本"))
|
||||
.addTo(mControlGroupListView);
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy", Locale.CHINA);
|
||||
String currentYear = dateFormat.format(new Date());
|
||||
mCopyrightTextView.setText(String.format(getResources().getString(R.string.about_copyright), currentYear));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initListeners() {
|
||||
menuMessage.setOnSuperTextViewClickListener(this);
|
||||
menuLogout.setOnSuperTextViewClickListener(this);
|
||||
menuAccount.setOnSuperTextViewClickListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP退出登录
|
||||
*/
|
||||
private void logout(){
|
||||
XHttp.post(getServerPath()+"/logout")
|
||||
.execute(new CallBackProxy<NoDataApiResult<String>, String>(new TipRequestCallBack<String>() {
|
||||
@Override
|
||||
public void onSuccess(String tokenResult) throws Throwable {
|
||||
XToastUtils.success("登出成功" );
|
||||
}
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
|
||||
}
|
||||
}){});
|
||||
}
|
||||
|
||||
@SingleClick
|
||||
@Override
|
||||
public void onClick(SuperTextView view) {
|
||||
switch(view.getId()) {
|
||||
case R.id.menu_message:
|
||||
openNewPage(MessageFragment.class);
|
||||
break;
|
||||
case R.id.menu_account:
|
||||
openNewPage(AccountFragment.class);
|
||||
break;
|
||||
case R.id.menu_logout:
|
||||
DialogLoader.getInstance().showConfirmDialog(
|
||||
getContext(),
|
||||
getString(R.string.lab_logout_confirm),
|
||||
getString(R.string.lab_yes),
|
||||
(dialog, which) -> {
|
||||
logout();
|
||||
dialog.dismiss();
|
||||
XUtil.getActivityLifecycleHelper().exit();
|
||||
TokenUtils.handleLogoutSuccess();
|
||||
},
|
||||
getString(R.string.lab_no),
|
||||
(dialog, which) -> dialog.dismiss()
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.http.callback;
|
||||
|
||||
import com.xuexiang.xhttp2.callback.SimpleCallBack;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xhttp2.model.XHttpRequest;
|
||||
import com.xuexiang.xutil.common.StringUtils;
|
||||
import com.xuexiang.xutil.common.logger.Logger;
|
||||
|
||||
/**
|
||||
* @author xuexiang
|
||||
* @since 2018/8/8 上午10:23
|
||||
*/
|
||||
public abstract class NoTipRequestCallBack<T> extends SimpleCallBack<T> {
|
||||
/**
|
||||
* 记录一下请求的url,确定出错的请求是哪个请求
|
||||
*/
|
||||
private String mUrl;
|
||||
|
||||
public NoTipRequestCallBack() {
|
||||
|
||||
}
|
||||
|
||||
public NoTipRequestCallBack(XHttpRequest req) {
|
||||
this(req.getUrl());
|
||||
}
|
||||
|
||||
public NoTipRequestCallBack(String url) {
|
||||
mUrl = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
if (!StringUtils.isEmpty(mUrl)) {
|
||||
Logger.e("网络请求的url:" + mUrl, e);
|
||||
} else {
|
||||
Logger.e(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.http.callback;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.xuexiang.xhttp2.callback.SimpleCallBack;
|
||||
import com.xuexiang.xhttp2.exception.ApiException;
|
||||
import com.xuexiang.xhttp2.model.XHttpRequest;
|
||||
import com.xuexiang.xutil.common.StringUtils;
|
||||
import com.xuexiang.xutil.common.logger.Logger;
|
||||
import com.xuexiang.xutil.tip.ToastUtils;
|
||||
|
||||
/**
|
||||
* @author xuexiang
|
||||
* @since 2018/8/8 上午10:20
|
||||
*/
|
||||
public abstract class TipRequestCallBack<T> extends SimpleCallBack<T> {
|
||||
|
||||
/**
|
||||
* 记录一下请求的url,确定出错的请求是哪个请求
|
||||
*/
|
||||
private String mUrl;
|
||||
|
||||
public TipRequestCallBack() {
|
||||
|
||||
}
|
||||
|
||||
public TipRequestCallBack(@NonNull XHttpRequest req) {
|
||||
this(req.getUrl());
|
||||
}
|
||||
|
||||
public TipRequestCallBack(String url) {
|
||||
mUrl = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ApiException e) {
|
||||
ToastUtils.toast(e.getDisplayMessage());
|
||||
if (!StringUtils.isEmpty(mUrl)) {
|
||||
Logger.e("网络请求的url:" + mUrl, e);
|
||||
} else {
|
||||
Logger.e(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.http.interceptor;
|
||||
|
||||
import com.xuexiang.xhttp2.interceptor.HttpLoggingInterceptor;
|
||||
import com.xuexiang.xhttp2.utils.HttpUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Connection;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.internal.http.HttpHeaders;
|
||||
|
||||
/**
|
||||
* 自定义日志拦截器【简单打印入参和出参】
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2018/8/6 上午11:53
|
||||
*/
|
||||
public class CustomLoggingInterceptor extends HttpLoggingInterceptor {
|
||||
|
||||
public CustomLoggingInterceptor() {
|
||||
super("custom");
|
||||
setLevel(Level.PARAM);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void logForRequest(Request request, Connection connection) throws IOException {
|
||||
RequestBody requestBody = request.body();
|
||||
boolean hasRequestBody = requestBody != null;
|
||||
Protocol protocol = connection != null ? connection.protocol() : Protocol.HTTP_1_1;
|
||||
|
||||
StringBuilder logBuilder = new StringBuilder();
|
||||
try {
|
||||
logBuilder.append("--> ")
|
||||
.append(request.method())
|
||||
.append(' ')
|
||||
.append(request.url())
|
||||
.append(' ')
|
||||
.append(protocol)
|
||||
.append("\r\n");
|
||||
if (hasRequestBody) {
|
||||
logBuilder.append("入参:");
|
||||
if (HttpUtils.isPlaintext(requestBody.contentType())) {
|
||||
logBuilder.append(bodyToString(request));
|
||||
} else {
|
||||
logBuilder.append("maybe [file part] , too large too print , ignored!");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
log(logBuilder.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Response logForResponse(Response response, long tookMs) {
|
||||
Response clone = response.newBuilder().build();
|
||||
ResponseBody responseBody = clone.body();
|
||||
log("<-- " + clone.code() + ' ' + clone.message() + ' ' + clone.request().url() + " (" + tookMs + "ms)");
|
||||
try {
|
||||
if (HttpHeaders.hasBody(clone)) {
|
||||
if (responseBody == null) {
|
||||
return response;
|
||||
}
|
||||
if (HttpUtils.isPlaintext(responseBody.contentType())) {
|
||||
String body = responseBody.string();
|
||||
log("\t出参:" + body);
|
||||
responseBody = ResponseBody.create(responseBody.contentType(), body);
|
||||
return response.newBuilder().body(responseBody).build();
|
||||
} else {
|
||||
log("\t出参: maybe [file part] , too large too print , ignored!");
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.http.request;
|
||||
|
||||
import com.kerwin.wumei.entity.bo.CaptureImage;
|
||||
import com.xuexiang.xhttp2.model.ApiResult;
|
||||
|
||||
|
||||
public class CaptchaImageApiResult<T> extends ApiResult<T> {
|
||||
private String uuid;
|
||||
private String img;
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
public CaptchaImageApiResult<T> setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getImg() {
|
||||
return img;
|
||||
}
|
||||
public CaptchaImageApiResult<T> setImg(String img) {
|
||||
this.img = img;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isSuccess() {
|
||||
return getCode()==200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getData() {
|
||||
CaptureImage image=new CaptureImage();
|
||||
image.setImg(getImg());
|
||||
image.setUuid(getUuid());
|
||||
return (T) image;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ApiResult{" +
|
||||
"code='" + CODE + '\'' +
|
||||
", msg='" + MSG + '\'' +
|
||||
", uuid='" + uuid + '\'' +
|
||||
", img=" + img +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.http.request;
|
||||
|
||||
import com.xuexiang.xhttp2.model.ApiResult;
|
||||
|
||||
/**
|
||||
* @author xuexiang
|
||||
* @since 2018/8/7 下午5:23
|
||||
*/
|
||||
public class CustomApiResult<T> extends ApiResult<T> {
|
||||
|
||||
private int errorCode;
|
||||
private String errorInfo;
|
||||
private T result;
|
||||
private long timeStamp;
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public CustomApiResult<T> setErrorCode(int errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getErrorInfo() {
|
||||
return errorInfo;
|
||||
}
|
||||
|
||||
public CustomApiResult<T> setErrorInfo(String errorInfo) {
|
||||
this.errorInfo = errorInfo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public T getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public CustomApiResult<T> setResult(T result) {
|
||||
this.result = result;
|
||||
return this;
|
||||
}
|
||||
|
||||
public long getTimeStamp() {
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
public CustomApiResult<T> setTimeStamp(long timeStamp) {
|
||||
this.timeStamp = timeStamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMsg() {
|
||||
return errorInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuccess() {
|
||||
return errorCode == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getData() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ApiResult{" +
|
||||
"errorCode='" + errorCode + '\'' +
|
||||
", errorInfo='" + errorInfo + '\'' +
|
||||
", timeStamp='" + timeStamp + '\'' +
|
||||
", result=" + result +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kerwin.wumei.http.request;
|
||||
|
||||
import com.xuexiang.xhttp2.callback.CallBack;
|
||||
import com.xuexiang.xhttp2.callback.CallBackProxy;
|
||||
import com.xuexiang.xhttp2.callback.CallClazzProxy;
|
||||
import com.xuexiang.xhttp2.model.ApiResult;
|
||||
import com.xuexiang.xhttp2.request.GetRequest;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
/**
|
||||
* 自定义请求的形式
|
||||
*
|
||||
* @author xuexiang
|
||||
* @since 2018/8/7 下午6:09
|
||||
*/
|
||||
public class CustomGetRequest extends GetRequest {
|
||||
|
||||
public CustomGetRequest(String url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Observable<T> execute(Type type) {
|
||||
return execute(new CallClazzProxy<CustomApiResult<T>, T>(type) {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Disposable execute(CallBack<T> callBack) {
|
||||
return execute(new CallBackProxy<CustomApiResult<T>, T>(callBack) {
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.http.request;
|
||||
|
||||
import com.xuexiang.xhttp2.model.ApiResult;
|
||||
|
||||
public class ListApiResult<T> extends ApiResult<T> {
|
||||
|
||||
private T rows;
|
||||
private int total;
|
||||
|
||||
public T getRows() {
|
||||
return rows;
|
||||
}
|
||||
public ListApiResult<T> setRows(T rows) {
|
||||
this.rows = rows;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getTotal(){return total;}
|
||||
public ListApiResult<T> setTotal(int total){
|
||||
this.total=total;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuccess() {
|
||||
return getCode() == 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getData() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ApiResult{" +
|
||||
"code='" + CODE + '\'' +
|
||||
", msg='" + MSG + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.http.request;
|
||||
|
||||
import com.xuexiang.xhttp2.model.ApiResult;
|
||||
|
||||
|
||||
public class NoDataApiResult<T> extends ApiResult<T> {
|
||||
|
||||
@Override
|
||||
public boolean isSuccess() {
|
||||
return getCode() == 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getData() {
|
||||
return (T) "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ApiResult{" +
|
||||
"code='" + CODE + '\'' +
|
||||
", msg='" + MSG + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
|
||||
package com.kerwin.wumei.http.request;
|
||||
|
||||
import com.xuexiang.xhttp2.model.ApiResult;
|
||||
|
||||
|
||||
public class TokenApiResult<T> extends ApiResult<T> {
|
||||
|
||||
private T token= (T) "";
|
||||
|
||||
public T getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public TokenApiResult<T> setToken(T token) {
|
||||
this.token = token;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuccess() {
|
||||
return getCode() == 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getData() {
|
||||
return token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ApiResult{" +
|
||||
"code='" + CODE + '\'' +
|
||||
", msg='" + MSG + '\'' +
|
||||
", token=" + token +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user