Compare commits
249 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 44deb59624 | |||
| 27fc39cb70 | |||
| 5480caf44e | |||
| a448a974f1 | |||
| 1738fac5fd | |||
| 7b74318ca5 | |||
| 6dabbe19dd | |||
| e286be7f1e | |||
| ef040f68c7 | |||
| b134d077cf | |||
| 69fe3b3d76 | |||
| c134c4bf9e | |||
| 633acb9236 | |||
| cf84205571 | |||
| 5aced2c03c | |||
| 6cfa949493 | |||
| dcfe3dee0e | |||
| 8348568ea7 | |||
| 1d5dece894 | |||
| 64594c4457 | |||
| c2274d6b6f | |||
| 165059ca2d | |||
| 89e05d1a29 | |||
| 9f00cab409 | |||
| e8a795f97b | |||
| 96c233ebd0 | |||
| 36ef13b237 | |||
| f54fdd6016 | |||
| a43947077a | |||
| a863b7be13 | |||
| ab1ce8e179 | |||
| d391ab20b7 | |||
| 8403bc3a64 | |||
| 038e736eb1 | |||
| a215192175 | |||
| 22a1895050 | |||
| 2df42c772b | |||
| 82fea04460 | |||
| 6ccd70dad2 | |||
| ec2d14bffe | |||
| 1d544ff558 | |||
| 867cd29e0f | |||
| d1cf660af6 | |||
| adabe3a227 | |||
| b57ef6c3b4 | |||
| 1b50823843 | |||
| 18ddad522a | |||
| 85b034ecfb | |||
| 5a04749ef2 | |||
| bcd32dde85 | |||
| 7832cb810b | |||
| cb652721a7 | |||
| 4ad005fb53 | |||
| ce312aea72 | |||
| 6c5dc556e8 | |||
| 95dc18f1d0 | |||
| f284cc8676 | |||
| 0cc456c4a1 | |||
| 0666146374 | |||
| 5860ca720e | |||
| 91ee8362ba | |||
| dd81460826 | |||
| 5180916d9f | |||
| 4d92ddcc75 | |||
| f1f0900e13 | |||
| 6edf68d03c | |||
| c643ae507b | |||
| fdc843a93a | |||
| 383c06c72a | |||
| a255ce3e36 | |||
| fa58e820c1 | |||
| fad011e2fc | |||
| 9fad040e14 | |||
| 8d0ab82f15 | |||
| 3d7e994b93 | |||
| 4d40c0f431 | |||
| d9bb60e66b | |||
| 52433ba347 | |||
| 4290846698 | |||
| 6bbd7ec00d | |||
| dc535ddb38 | |||
| dfe087e702 | |||
| 930e0b92eb | |||
| 3199bc6118 | |||
| b1384375a3 | |||
| 81dd98cefd | |||
| 02108b3273 | |||
| c5deb87c23 | |||
| 572274a2e3 | |||
| 7f303b362d | |||
| 41ce6cce05 | |||
| f6e1c55749 | |||
| d24bcf8e6e | |||
| 2b497ff679 | |||
| 627c20f6fd | |||
| cfab918bea | |||
| 89746203fe | |||
| 8bc6947c94 | |||
| 5a264804da | |||
| 1f5e025fea | |||
| 3201e220a0 | |||
| d41129011b | |||
| 6eb1aefb1c | |||
| 433646b455 | |||
| 257e7d1d27 | |||
| f668d6492a | |||
| b8ea968a58 | |||
| 5b361afc67 | |||
| 0947cd1e24 | |||
| f8ab1f108b | |||
| 84f53bbf81 | |||
| ad2656a24b | |||
| 4734fbd651 | |||
| a947755383 | |||
| f4a1283073 | |||
| f37a2c5b24 | |||
| cca7d770f1 | |||
| 2c7f3f2321 | |||
| cc92e025f2 | |||
| ce0e28dad6 | |||
| b483f7cdb6 | |||
| 8ce0694099 | |||
| 910b356a05 | |||
| d74e0310f8 | |||
| ee19879577 | |||
| 5e3d7d2f2b | |||
| f292eb0fc6 | |||
| 475de2281b | |||
| 949c8331d2 | |||
| a5e0fa8402 | |||
| f0066b3dac | |||
| 10480a533c | |||
| d36dcac817 | |||
| d6d49ac7ad | |||
| 573e127fc7 | |||
| 9cb6e599a4 | |||
| f42dd1013e | |||
| 70441658e5 | |||
| 0ca71f25f6 | |||
| 5d3a4e24f9 | |||
| 3b8faf47c4 | |||
| ac21776d3b | |||
| e5127c9040 | |||
| 8533d06943 | |||
| 066dd6103f | |||
| 670f9c280c | |||
| 5ea3c58b77 | |||
| 6e15571ef4 | |||
| ad46fced4f | |||
| 5acf42423e | |||
| 2a2bef8a47 | |||
| 2ffb0f59a2 | |||
| 400bdaa6f5 | |||
| fa449966f3 | |||
| f4078493f6 | |||
| 5007f7e83d | |||
| ca1a8e15cb | |||
| b9f299805f | |||
| acde49012f | |||
| 76c69f0d19 | |||
| c0b91b4a63 | |||
| f6a194ae92 | |||
| 9e7d178972 | |||
| 17b2e2dca7 | |||
| eb73bcd25f | |||
| f96c090120 | |||
| aefdaee424 | |||
| 27ceee37c0 | |||
| e1c2e3c984 | |||
| 48e3718fc2 | |||
| ee20f65a9b | |||
| 235a13855b | |||
| acec42c6af | |||
| 6d009eddf5 | |||
| b0dde281ea | |||
| 1e7d43bc72 | |||
| 8576a1edaf | |||
| 5dc97d2191 | |||
| a32b45e067 | |||
| ff8210c72b | |||
| 85031e89b6 | |||
| f2676532ce | |||
| 7a996ee8f4 | |||
| d09e28d653 | |||
| e446f4190f | |||
| f53534b803 | |||
| fb6792f71b | |||
| 5d66d55db1 | |||
| d3bdd48425 | |||
| c89f675ccf | |||
| f0b989d20e | |||
| 3b950b6b28 | |||
| d10a0f956e | |||
| 2317228642 | |||
| 78a4571a8a | |||
| c7b16ce91b | |||
| 2e84aeaccf | |||
| 49e9a532b8 | |||
| 47f7d70cfb | |||
| a3b03efcbe | |||
| 814d4faf3e | |||
| c487dc2f03 | |||
| f552a06bd7 | |||
| 4de5593802 | |||
| 4294e9f98d | |||
| 05a911f1e3 | |||
| 464f8d7851 | |||
| 370b07be31 | |||
| cb49c71279 | |||
| f637fb9596 | |||
| 5c8072cc9e | |||
| 40cd057c28 | |||
| 0bcd37c1f1 | |||
| 6fce6fd80b | |||
| bc13a6056d | |||
| 00879964e4 | |||
| 64711d6175 | |||
| 0d3704f55d | |||
| 0856eed7fc | |||
| 8efaa9e724 | |||
| 98983ff4eb | |||
| 0ae36ed7a7 | |||
| 8e8b20c3dd | |||
| 82e2aa45c6 | |||
| e4be47e7e7 | |||
| 404c605a1e | |||
| 4966d85634 | |||
| 043eebf013 | |||
| 3b521ddd08 | |||
| bd74d3a1a3 | |||
| 0dc867ce64 | |||
| dde08e2d67 | |||
| 3c5871526d | |||
| 49f4ba2da8 | |||
| 77b660576a | |||
| a15ab62f03 | |||
| c65250973c | |||
| d5872aad55 | |||
| 9d27bba6fd | |||
| caeecce50b | |||
| f6c82dd767 | |||
| f88205f957 | |||
| 3a0a4726b9 | |||
| a113fc1c73 | |||
| 92d122b0a3 | |||
| d96a2d22e0 | |||
| 8d96b9fe7f | |||
| fdf7bdd64d | |||
| 4f4c90f792 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,4 +5,5 @@ local.properties
|
||||
# sign.properties
|
||||
.DS_Store
|
||||
captures/
|
||||
build/
|
||||
build/
|
||||
release-app/
|
||||
@ -1,5 +1,12 @@
|
||||
### Ver 3.0
|
||||
* x
|
||||
* 升级账号系统(登录流程/用户信息相关/用户账号相关操作(评论,礼包...))
|
||||
* 新增收藏功能(文章/工具箱)
|
||||
* 删除用户相关的所有本地数据库
|
||||
* 重做总开服表
|
||||
* 重做首页插件化模块
|
||||
* 礼包重复领取机制改变(可重复领取的礼包,领取后立刻显示再领一个/再淘一个)
|
||||
* 游戏下载平台面板修改(加快弹出速度,不再读取本地平台图片)
|
||||
* 接入bugly(tinker)
|
||||
|
||||
### Ver 2.6
|
||||
* xx
|
||||
|
||||
23
README.md
23
README.md
@ -1,8 +1,11 @@
|
||||
# 光环助手Android客户端
|
||||
|
||||
### Sourceset/debug/release
|
||||
* https://developer.android.com/studio/build/build-variants.html#sourcesets
|
||||
|
||||
### 多渠道打包配置
|
||||
* 使用[ApkChannelPackage](https://github.com/ltlovezh/ApkChannelPackage)的方案
|
||||
* 正式打包命令:请使用./gradlew channelRelease打包渠道包
|
||||
* 正式打包命令:请使用./gradlew channelPubRelease打包渠道包
|
||||
|
||||
### 混淆配置
|
||||
* 配置文件:Android默认配置+proguard-rules.txt等
|
||||
@ -19,9 +22,19 @@
|
||||
* 通过gradle文件内的resValue/buildConfigField/manifestPlaceHolder方式实现编译期间修改,具体情况请参考``./build.gradle``和``./app/build.gradle``配置
|
||||
|
||||
### 拉取代码步骤
|
||||
1. 拉取主项目代码: `git clone -b master git@gitlab.ghzhushou.com:halo/assistant-android.git`
|
||||
2. 初始化公用类库: `git submodule init && git submodule update`
|
||||
1. 拉取主项目代码: `git clone -b dev git@gitlab.ghzhushou.com:halo/assistant-android.git`
|
||||
2. 初始化公用类库: `bash ./scripts/init_submodules.sh`
|
||||
|
||||
### submodule管理方式(只拉取master)
|
||||
* 拉取子模块代码:`git submodule foreach git pull origin master`
|
||||
* 提交代码,需要cd到submodule文件夹去做修改
|
||||
* 提交代码,需要cd到submodule文件夹去做修改
|
||||
|
||||
|
||||
|
||||
### TODO
|
||||
* GSON 序列化用统一的一个, GsonUtil fromJson
|
||||
* CleanApkAdapter 转化字符串size工具函数 比如SpeedUtils
|
||||
* getString 解决 字符串hardcode问题
|
||||
* Adapter 里面clicklistener 用接口传参将点击操作委托给controller
|
||||
* Adapter ViewHolder的功能,部分重写到ViewHolder类本身
|
||||
|
||||
* activity 统一入口未完成(外部入口相关)
|
||||
|
||||
165
app/build.gradle
165
app/build.gradle
@ -1,14 +1,12 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
apply plugin: 'com.neenbedankt.android-apt'
|
||||
|
||||
apply plugin: 'kotlin-android' // kotlin
|
||||
//tinker插件
|
||||
//apply plugin: 'com.tencent.tinker.patch'
|
||||
|
||||
// apkChannelPackage
|
||||
apply plugin: 'channel'
|
||||
|
||||
apply from: 'tinker-support.gradle'
|
||||
|
||||
android {
|
||||
|
||||
compileOptions {
|
||||
@ -22,9 +20,10 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
|
||||
multiDexEnabled true
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
arguments = [ eventBusIndex : 'com.gh.EventBusIndex' ]
|
||||
arguments = [eventBusIndex: 'com.gh.EventBusIndex']
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,16 +40,12 @@ android {
|
||||
// 由于app只针对中文用户,所以仅保留zh资源,其他删掉
|
||||
resConfigs "zh"
|
||||
|
||||
// jackOptions {
|
||||
// enabled true
|
||||
// }
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.versionCode
|
||||
versionName rootProject.ext.versionName
|
||||
applicationId rootProject.ext.applicationId
|
||||
|
||||
multiDexEnabled true
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt', 'proguard-fresco.txt'
|
||||
|
||||
/**
|
||||
@ -62,6 +57,7 @@ android {
|
||||
buildConfigField "String", "WEIBO_APPKEY", "\"${WEIBO_APPKEY}\""
|
||||
buildConfigField "String", "MTA_APPKEY", "\"${MTA_APPKEY}\""
|
||||
buildConfigField "String", "TD_APPID", "\"${TD_APPID}\""
|
||||
buildConfigField "String", "PATCH_VERSION_NAME", "\"${PATCH_VERSION_NAME}\""
|
||||
|
||||
}
|
||||
|
||||
@ -83,6 +79,7 @@ android {
|
||||
minifyEnabled false
|
||||
zipAlignEnabled false
|
||||
versionNameSuffix "-debug"
|
||||
signingConfig signingConfigs.debug
|
||||
|
||||
buildConfigField "String", "UMENG_APPKEY", "\"${DEBUG_UMENG_APPKEY}\""
|
||||
buildConfigField "String", "UMENG_MESSAGE_SECRET", "\"${DEBUG_UMENG_MESSAGE_SECRET}\""
|
||||
@ -103,27 +100,43 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
flavorDimensions "nonsense"
|
||||
|
||||
/**
|
||||
* 多渠道打包,渠道请参考"channel.txt"文件,所有渠道值均通过java code设置
|
||||
*/
|
||||
productFlavors {
|
||||
// public release host
|
||||
pub {
|
||||
buildConfigField "String", "HOST", "\"${HOST}\""
|
||||
// publish release host
|
||||
publish {
|
||||
dimension "nonsense"
|
||||
buildConfigField "String", "API_HOST", "\"${API_HOST}\""
|
||||
buildConfigField "String", "USER_HOST", "\"${USER_HOST}\""
|
||||
buildConfigField "String", "COMMENT_HOST", "\"${COMMENT_HOST}\""
|
||||
buildConfigField "String", "LIBAO_HOST", "\"${LIBAO_HOST}\""
|
||||
buildConfigField "String", "MESSAGE_HOST", "\"${MESSAGE_HOST}\""
|
||||
buildConfigField "String", "DATA_HOST", "\"${DATA_HOST}\""
|
||||
buildConfigField "String", "USERSEA_HOST", "\"${USERSEA_HOST}\""
|
||||
|
||||
buildConfigField "String", "BUGLY_APPID", "\"${BUGLY_APPID}\""
|
||||
|
||||
buildConfigField "String", "USERSEA_APP_ID", "\"${USERSEA_APP_ID}\""
|
||||
buildConfigField "String", "USERSEA_APP_SECRET", "\"${USERSEA_APP_SECRET}\""
|
||||
}
|
||||
// internal dev host
|
||||
dev {
|
||||
buildConfigField "String", "HOST", "\"${DEV_HOST}\""
|
||||
// internal test dev host
|
||||
internal {
|
||||
dimension "nonsense"
|
||||
buildConfigField "String", "API_HOST", "\"${DEV_API_HOST}\""
|
||||
buildConfigField "String", "USER_HOST", "\"${DEV_USER_HOST}\""
|
||||
buildConfigField "String", "COMMENT_HOST", "\"${DEV_COMMENT_HOST}\""
|
||||
buildConfigField "String", "LIBAO_HOST", "\"${DEV_LIBAO_HOST}\""
|
||||
buildConfigField "String", "MESSAGE_HOST", "\"${DEV_MESSAGE_HOST}\""
|
||||
buildConfigField "String", "DATA_HOST", "\"${DEV_DATA_HOST}\""
|
||||
buildConfigField "String", "USERSEA_HOST", "\"${DEV_USERSEA_HOST}\""
|
||||
|
||||
buildConfigField "String", "BUGLY_APPID", "\"${DEBUG_BUGLY_APPID}\""
|
||||
|
||||
buildConfigField "String", "USERSEA_APP_ID", "\"${DEV_USERSEA_APP_ID}\""
|
||||
buildConfigField "String", "USERSEA_APP_SECRET", "\"${DEV_USERSEA_APP_SECRET}\""
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,12 +154,6 @@ channel {
|
||||
apkNameFormat = '${appName}-${versionName}-${versionCode}-${flavorName}-${buildType}'
|
||||
}
|
||||
|
||||
apt {
|
||||
arguments {
|
||||
eventBusIndex "com.gh.EventBusIndex"
|
||||
}
|
||||
}
|
||||
|
||||
rebuildChannel {
|
||||
// baseDebugApk = 已有Debug APK
|
||||
// baseReleaseApk = 已有Release APK
|
||||
@ -157,71 +164,80 @@ rebuildChannel {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile test.junit
|
||||
compile fileTree(include: '*.jar', dir: 'libs')
|
||||
compile libs.supportMultidex
|
||||
compile libs.supportDesign
|
||||
compile libs.supportAppCompat
|
||||
compile libs.supportAnnotation
|
||||
compile libs.supportPercent
|
||||
compile libs.supportDesign
|
||||
|
||||
compile libs.switchButton
|
||||
implementation fileTree(include: '*.jar', dir: 'libs')
|
||||
|
||||
compile libs.systemBarTint
|
||||
debugImplementation "com.squareup.leakcanary:leakcanary-android:${leakcanary}"
|
||||
debugImplementation "com.facebook.stetho:stetho:${stetho}"
|
||||
debugImplementation "com.facebook.stetho:stetho-okhttp3:${stetho}"
|
||||
debugImplementation "com.squareup.okhttp3:logging-interceptor:${okHttp}"
|
||||
|
||||
compile libs.fresco
|
||||
compile libs.frescoAnimatedGif
|
||||
implementation "com.android.support:multidex:${multidex}"
|
||||
implementation "com.android.support:design:${androidSupport}"
|
||||
implementation "com.android.support:support-v4:${androidSupport}"
|
||||
implementation "com.android.support:appcompat-v7:${androidSupport}"
|
||||
implementation "com.android.support:support-annotations:${androidSupport}"
|
||||
implementation "com.android.support:percent:${androidSupport}"
|
||||
|
||||
compile libs.okHttp
|
||||
compile libs.okHttpLogInterceptor
|
||||
implementation "com.kyleduo.switchbutton:library:${switchButton}"
|
||||
implementation "com.readystatesoftware.systembartint:systembartint:${systemBarTint}"
|
||||
|
||||
compile libs.apkChannelPackage
|
||||
implementation "com.facebook.fresco:fresco:${fresco}"
|
||||
implementation "com.facebook.fresco:animated-gif:${fresco}"
|
||||
|
||||
// debugCompile libs.stetho
|
||||
// debugCompile libs.stethoWithOkHttp
|
||||
implementation "com.squareup.okhttp3:okhttp:${okHttp}"
|
||||
|
||||
compile libs.retrofit
|
||||
compile libs.retrofitWithGson // include gson 2.7
|
||||
compile libs.retrofitWithRxJava
|
||||
// compile libs.gson
|
||||
implementation "com.leon.channel:helper:${apkChannelPackage}"
|
||||
|
||||
compile libs.ormliteAndroid
|
||||
compile libs.ormliteCore
|
||||
implementation "com.squareup.retrofit2:retrofit:${retrofit}"
|
||||
implementation "com.squareup.retrofit2:converter-gson:${retrofit}" // include gson 2.7
|
||||
implementation "com.squareup.retrofit2:adapter-rxjava:${retrofit}"
|
||||
// implementation "com.google.code.gson:gson:${gson}"
|
||||
|
||||
compile libs.butterKnife
|
||||
apt libs.butterKnifeApt
|
||||
implementation "com.j256.ormlite:ormlite-android:${ormlite}"
|
||||
implementation "com.j256.ormlite:ormlite-core:${ormlite}"
|
||||
|
||||
compile libs.rxJava
|
||||
compile libs.rxAndroid
|
||||
compile libs.rxBinding
|
||||
compile libs.zxing
|
||||
compile libs.zxingAndroid
|
||||
implementation "com.jakewharton:butterknife:${butterKnife}"
|
||||
annotationProcessor "com.jakewharton:butterknife-compiler:${butterKnife}"
|
||||
|
||||
compile libs.swipeLayout
|
||||
compile(libs.autoScrollViewPager) {
|
||||
implementation "org.greenrobot:eventbus:${eventbus}"
|
||||
annotationProcessor "org.greenrobot:eventbus-annotation-processor:${eventbusApt}"
|
||||
|
||||
implementation "io.reactivex:rxjava:${rxJava}"
|
||||
implementation "io.reactivex:rxandroid:${rxAndroid}"
|
||||
implementation "com.jakewharton.rxbinding:rxbinding:${rxBinding}"
|
||||
|
||||
//TODO update to rx 2.x
|
||||
// implementation "io.reactivex.rxjava2:rxjava:${rxJava2}"
|
||||
// implementation "io.reactivex.rxjava2:rxandroid:${rxAndroid2}"
|
||||
// implementation "com.jakewharton.rxbinding2:rxbinding:${rxBinding2}"
|
||||
|
||||
implementation "com.google.zxing:core:${zxing}"
|
||||
implementation "com.google.zxing:android-core:${zxing}"
|
||||
|
||||
implementation "com.daimajia.swipelayout:library:${swipeLayout}"
|
||||
implementation("cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:${autoScrollViewPager}") {
|
||||
exclude module: 'support-v4'
|
||||
}
|
||||
|
||||
// tinker
|
||||
// provided libs.tinker_anno
|
||||
// compile libs.tinker_lib
|
||||
implementation "com.sina.weibo.sdk:core:${weiboSDK}"
|
||||
|
||||
compile libs.weiboSDK
|
||||
// bugly with tinker support
|
||||
implementation "com.tencent.bugly:crashreport_upgrade:${buglyTinkerSupport}"
|
||||
|
||||
compile libs.eventbus
|
||||
apt libs.eventbusApt
|
||||
compile project(':libraries:LGLibrary')
|
||||
compile project(':libraries:MiPush')
|
||||
compile project(':libraries:MTA')
|
||||
compile project(':libraries:QQShare')
|
||||
compile project(':libraries:TalkingData')
|
||||
compile project(':libraries:UmengPush')
|
||||
compile project(':libraries:WechatShare')
|
||||
compile project(':libraries:iosched')
|
||||
implementation "pub.devrel:easypermissions:${easypermissions}"
|
||||
|
||||
implementation project(':libraries:MiPush')
|
||||
implementation project(':libraries:MTA')
|
||||
implementation project(':libraries:QQShare')
|
||||
implementation project(':libraries:TalkingData')
|
||||
implementation project(':libraries:UmengPush')
|
||||
implementation project(':libraries:WechatShare')
|
||||
implementation project(':libraries:iosched')
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
|
||||
}
|
||||
File propFile = file('sign.properties');
|
||||
File propFile = file('sign.properties')
|
||||
if (propFile.exists()) {
|
||||
def Properties props = new Properties()
|
||||
props.load(new FileInputStream(propFile))
|
||||
@ -229,12 +245,13 @@ if (propFile.exists()) {
|
||||
if (props.containsKey('keyAlias') && props.containsKey('keyPassword') &&
|
||||
props.containsKey('storeFile') && props.containsKey('storePassword')) {
|
||||
android.signingConfigs {
|
||||
debug {
|
||||
keyAlias props.get('keyAlias')
|
||||
keyPassword props.get('keyPassword')
|
||||
storeFile file(props.get('storeFile'))
|
||||
storePassword props.get('storePassword')
|
||||
}
|
||||
// debug 不要使用正式签名,这样tinker才不会打补丁。
|
||||
debug {
|
||||
keyAlias props.get('keyAlias')
|
||||
keyPassword props.get('keyPassword')
|
||||
storeFile file(props.get('storeFile'))
|
||||
storePassword props.get('storePassword')
|
||||
}
|
||||
release {
|
||||
keyAlias props.get('keyAlias')
|
||||
keyPassword props.get('keyPassword')
|
||||
|
||||
@ -16,9 +16,23 @@
|
||||
# public *;
|
||||
#}
|
||||
|
||||
#--------- remove logs start ----------------
|
||||
-assumenosideeffects class com.lightgame.config.CommonDebug {
|
||||
private static String getLogTag(...);
|
||||
private static String getMethodName();
|
||||
public static void logMethodName(...);
|
||||
public static void logParams(...);
|
||||
public static void logFields(...);
|
||||
public static void logMethodWithParams(...);
|
||||
}
|
||||
|
||||
#-assumenosideeffects class com.lightgame.config.CommonDebug {*;}
|
||||
|
||||
#-dontoptimize
|
||||
#--------- remove logs end ----------------
|
||||
|
||||
-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod
|
||||
-dontwarn InnerClasses
|
||||
-dontoptimize
|
||||
|
||||
# OrmLite uses reflection
|
||||
-keep class com.j256.**
|
||||
@ -161,4 +175,18 @@
|
||||
|
||||
-keepclassmembers enum * { *; }
|
||||
|
||||
##---------------End: proguard configuration for Gson ----------
|
||||
##---------------End: proguard configuration for Gson ----------
|
||||
|
||||
# ------ bugly ---------
|
||||
-dontwarn com.tencent.bugly.**
|
||||
-keep public class com.tencent.bugly.**{*;}
|
||||
|
||||
# easypermission
|
||||
-keepclassmembers class * {
|
||||
@pub.devrel.easypermissions.AfterPermissionGranted <methods>;
|
||||
}
|
||||
|
||||
# 重命名文件为SourceFile,再配合mapping符号表,可以拿到真实的类名
|
||||
-renamesourcefileattribute SourceFile
|
||||
# 保留源文件行号
|
||||
-keepattributes SourceFile,LineNumberTable
|
||||
69
app/src/debug/java/com/gh/gamecenter/Injection.java
Normal file
69
app/src/debug/java/com/gh/gamecenter/Injection.java
Normal file
@ -0,0 +1,69 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.facebook.stetho.Stetho;
|
||||
import com.facebook.stetho.okhttp3.StethoInterceptor;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.squareup.leakcanary.LeakCanary;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
|
||||
/**
|
||||
* @author CsHeng
|
||||
* @Date 03/09/2017
|
||||
* @Time 4:34 PM
|
||||
*/
|
||||
|
||||
public class Injection {
|
||||
|
||||
public static boolean appInit(Application application) {
|
||||
|
||||
// init leakcanary
|
||||
if (LeakCanary.isInAnalyzerProcess(application)) {
|
||||
// This process is dedicated to LeakCanary for heap analysis.
|
||||
// You should not init your app in this process.
|
||||
return false;
|
||||
}
|
||||
LeakCanary.install(application);
|
||||
|
||||
// init stetho
|
||||
Stetho.initializeWithDefaults(application);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static OkHttpClient.Builder provideRetrofitBuilder() {
|
||||
// HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
|
||||
//
|
||||
// @Override
|
||||
// public void log(String message) {
|
||||
// //分段打印retrofit日志
|
||||
// if (message.startsWith("{") || message.startsWith("["))
|
||||
// if (message.length() > 4000) {
|
||||
// for (int i = 0; i < message.length(); i += 4000) {
|
||||
// if (i + 4000 < message.length())
|
||||
// Utils.log("OkHttp_Body::" + i, message.substring(i, i + 4000));
|
||||
// else
|
||||
// Utils.log("OkHttp_Body::" + i, message.substring(i, message.length()));
|
||||
// }
|
||||
// } else
|
||||
// Utils.log("OkHttp_Body::", message);
|
||||
// }
|
||||
// });
|
||||
// loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
|
||||
interceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
|
||||
builder.addNetworkInterceptor(interceptor);
|
||||
builder.addNetworkInterceptor(new StethoInterceptor());
|
||||
// if (BuildConfig.DEBUG) {
|
||||
// builder.addNetworkInterceptor(loggingInterceptor);
|
||||
// }
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -39,6 +39,14 @@
|
||||
<!-- 修改系统设置的权限 -->
|
||||
<uses-permission android:name = "android.permission.WRITE_SETTINGS" />
|
||||
|
||||
<!-- bugly with tinker -->
|
||||
<uses-permission android:name = "android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name = "android.permission.INTERNET" />
|
||||
<uses-permission android:name = "android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name = "android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name = "android.permission.READ_LOGS" />
|
||||
<uses-permission android:name = "android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<supports-screens
|
||||
android:anyDensity = "true"
|
||||
android:largeScreens = "true"
|
||||
@ -48,7 +56,7 @@
|
||||
|
||||
<!--android:largeHeap = "true"-->
|
||||
<application
|
||||
android:name = "com.gh.base.AppController"
|
||||
android:name = "com.halo.assistant.TinkerApp"
|
||||
android:allowBackup = "true"
|
||||
android:icon = "@drawable/logo"
|
||||
android:label = "@string/app_name"
|
||||
@ -66,6 +74,16 @@
|
||||
|
||||
<category android:name = "android.intent.category.LAUNCHER" />
|
||||
</intent-filter >
|
||||
|
||||
<!-- MTA可视化启动连接接口 -->
|
||||
<intent-filter >
|
||||
<data android:scheme = "${tencentAppScheme}" />
|
||||
<action android:name = "android.intent.action.VIEW" />
|
||||
|
||||
<category android:name = "android.intent.category.DEFAULT" />
|
||||
<category android:name = "android.intent.category.BROWSABLE" />
|
||||
</intent-filter >
|
||||
|
||||
</activity >
|
||||
|
||||
<activity
|
||||
@ -160,9 +178,6 @@
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.AboutActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.KaiFuActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.CommentDetailActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
@ -202,15 +217,28 @@
|
||||
android:screenOrientation = "portrait" />
|
||||
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.UserAreaActivity"
|
||||
android:name = "com.gh.gamecenter.UserRegionActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
|
||||
<!--非全屏+ScrollView+adjustResize-->
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.CollectionActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.MessageActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.UserInfoEditActivity"
|
||||
android:screenOrientation = "portrait"
|
||||
android:windowSoftInputMode = "stateHidden" />
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.KaiFuActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.NormalActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.SkipActivity"
|
||||
android:theme = "@style/Theme.AppCompat.Light.Fullscreen.Transparent" >
|
||||
@ -271,7 +299,7 @@
|
||||
</intent-filter >
|
||||
</receiver >
|
||||
|
||||
<service android:name = "com.gh.gamecenter.statistics.AppStaticService" />
|
||||
<!--<service android:name = "com.gh.gamecenter.statistics.AppStaticService" />-->
|
||||
|
||||
</application >
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -5,16 +5,19 @@ import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Looper;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataCollectionUtils;
|
||||
import com.gh.gamecenter.SplashScreenActivity;
|
||||
import com.lightgame.config.CommonDebug;
|
||||
import com.lightgame.download.FileUtils;
|
||||
import com.lightgame.utils.AppManager;
|
||||
import com.lightgame.utils.RuntimeUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.tencent.stat.StatService;
|
||||
import com.tendcloud.tenddata.TCAgent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
@ -26,80 +29,58 @@ import java.util.Locale;
|
||||
|
||||
public class AppUncaughtHandler implements UncaughtExceptionHandler {
|
||||
|
||||
private UncaughtExceptionHandler mDefaultHandler;
|
||||
private Context mContext;
|
||||
|
||||
public AppUncaughtHandler(Context context) {
|
||||
// 获取系统默认的UncaughtException处理器
|
||||
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncaughtException(Thread thread, Throwable ex) {
|
||||
if (!handleException(ex) && mDefaultHandler != null) {
|
||||
// 如果用户没有处理则让系统默认的异常处理器来处理
|
||||
mDefaultHandler.uncaughtException(thread, ex);
|
||||
} else {
|
||||
RuntimeUtils.getInstance().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(mContext.getApplicationContext(),
|
||||
"\"光环助手\"发生错误", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Looper.prepare();
|
||||
Utils.toast(mContext.getApplicationContext(), "\"光环助手\"发生错误");
|
||||
Looper.loop();
|
||||
}
|
||||
|
||||
// 防止重复奔溃,导致助手一直重启,20秒内不做处理
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
long time = sp.getLong("last_restart_time", 0);
|
||||
if (System.currentTimeMillis() - time > 20 * 1000) {
|
||||
sp.edit().putLong("last_restart_time", System.currentTimeMillis()).apply();
|
||||
Intent intent = new Intent(mContext, SplashScreenActivity.class);
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
PendingIntent restartIntent = PendingIntent.getActivity(mContext, 0, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
// 退出程序并重启
|
||||
AlarmManager mgr = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
|
||||
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, restartIntent); // 1秒钟后重启应用
|
||||
}
|
||||
AppManager.getInstance().finishAllActivity();
|
||||
}
|
||||
});
|
||||
saveLocalLog(mContext, ex);
|
||||
restart(mContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义错误处理,收集错误信息 发送错误报告等操作均在此完成.
|
||||
*
|
||||
* @param ex
|
||||
* @return true:如果处理了该异常信息;否则返回false.
|
||||
*/
|
||||
private boolean handleException(Throwable ex) {
|
||||
if (ex == null) {
|
||||
return false;
|
||||
public static void restart(final Context context) {
|
||||
|
||||
// 防止重复奔溃,导致助手一直重启,20秒内不做处理
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
long curTime = System.currentTimeMillis();
|
||||
long time = sp.getLong("last_restart_time", 0);
|
||||
if (curTime - time > 20 * 1000) {
|
||||
sp.edit().putLong("last_restart_time", curTime).apply();
|
||||
Intent intent = new Intent(context, SplashScreenActivity.class);
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
PendingIntent restartIntent = PendingIntent.getActivity(context, 0, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
// 退出程序并重启
|
||||
AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
mgr.set(AlarmManager.RTC, curTime + 3000, restartIntent); // 1秒钟后重启应用
|
||||
}
|
||||
saveLog(ex);
|
||||
return true;
|
||||
|
||||
//error restart
|
||||
// System.exit(2);
|
||||
AppManager.getInstance().finishAllActivity();
|
||||
}
|
||||
|
||||
// 保存log到本地
|
||||
private void saveLog(Throwable ex) {
|
||||
public static void saveLocalLog(Context context, Throwable ex) {
|
||||
String errorMsg = Log.getStackTraceString(ex);
|
||||
|
||||
// MTA主动上传错误
|
||||
// StatService.reportError(mContext.getApplicationContext(), errorMsg);
|
||||
StatService.reportException(mContext, ex);
|
||||
|
||||
// 上传错误数据
|
||||
DataCollectionUtils.uploadError(mContext, errorMsg);
|
||||
Config.setExceptionMsg(context, errorMsg);
|
||||
|
||||
// 保存到本地
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.getDefault());
|
||||
File file = new File(FileUtils.getLogPath(mContext.getApplicationContext(),
|
||||
File file = new File(FileUtils.getLogPath(context.getApplicationContext(),
|
||||
format.format(new Date()) + "_gh_assist" + ".log"));
|
||||
FileWriter writer = null;
|
||||
try {
|
||||
@ -120,4 +101,41 @@ public class AppUncaughtHandler implements UncaughtExceptionHandler {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 下次应用启动再上报
|
||||
*
|
||||
* @param context
|
||||
* @param throwable
|
||||
*/
|
||||
public static void reportException(Context context, Throwable throwable) {
|
||||
|
||||
CommonDebug.logMethodWithParams(context, "ERRMSG", throwable);
|
||||
|
||||
// 上传错误数据
|
||||
try {
|
||||
DataCollectionUtils.uploadError(context, Log.getStackTraceString(throwable));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// MTA主动上传错误
|
||||
try {
|
||||
StatService.reportException(context, throwable);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// //bugly 作为默认处理异常的类库,已经上报了,此处不重复上报
|
||||
// try {
|
||||
// CrashReport.postCatchedException(throwable);
|
||||
// } catch (Exception e) {
|
||||
// }
|
||||
|
||||
//talkingdata
|
||||
try {
|
||||
TCAgent.onError(context, throwable);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
package com.gh.base;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.TextView;
|
||||
@ -12,25 +12,30 @@ import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.RunningUtils;
|
||||
import com.gh.common.util.ShareUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.common.util.StringUtils;
|
||||
import com.gh.gamecenter.LoginActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBShowDialog;
|
||||
import com.lightgame.download.FileUtils;
|
||||
import com.lightgame.utils.AppManager;
|
||||
import com.readystatesoftware.systembartint.SystemBarTintManager.SystemBarConfig;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import pub.devrel.easypermissions.EasyPermissions;
|
||||
|
||||
import static com.gh.common.util.EntranceUtils.KEY_DATA;
|
||||
import static com.gh.common.util.EntranceUtils.KEY_ENTRANCE;
|
||||
|
||||
public abstract class BaseActivity extends BaseAppCompatToolBarActivity {
|
||||
public abstract class BaseActivity extends BaseAppCompatToolBarActivity implements EasyPermissions.PermissionCallbacks{
|
||||
|
||||
protected String mEntrance;
|
||||
private boolean mIsPause;
|
||||
@ -53,10 +58,6 @@ public abstract class BaseActivity extends BaseAppCompatToolBarActivity {
|
||||
}
|
||||
|
||||
private void init(View contentView) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
SystemBarConfig config = getTintManager().getConfig();
|
||||
contentView.setPadding(0, config.getPixelInsetTop(false), 0, config.getPixelInsetBottom());
|
||||
}
|
||||
setContentView(contentView);
|
||||
|
||||
ButterKnife.bind(this);
|
||||
@ -78,7 +79,7 @@ public abstract class BaseActivity extends BaseAppCompatToolBarActivity {
|
||||
}
|
||||
|
||||
public void toast(String msg) {
|
||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(this, msg);
|
||||
}
|
||||
|
||||
public void toast(int msg) {
|
||||
@ -110,6 +111,7 @@ public abstract class BaseActivity extends BaseAppCompatToolBarActivity {
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(final EBShowDialog showDialog) {
|
||||
//TODO 改为缓存到UI可见时才调用,参考beier-assist
|
||||
if (!mIsPause && this.getClass().getName().equals(RunningUtils.getTopActivity(this))) {
|
||||
if ("hijack".equals(showDialog.getType())) {
|
||||
DialogUtils.showQqSessionDialog(this, "2586716223");// 建议用户联系客服
|
||||
@ -118,12 +120,32 @@ public abstract class BaseActivity extends BaseAppCompatToolBarActivity {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
if (FileUtils.isEmptyFile(showDialog.getPath())) {
|
||||
Toast.makeText(BaseActivity.this, "解析包出错(可能被误删了),请重新下载", Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(BaseActivity.this, getString(R.string.install_failure_hint));
|
||||
} else {
|
||||
startActivity(PackageUtils.getUninstallIntent(BaseActivity.this, showDialog.getPath()));
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if ("loginException".equals(showDialog.getType())) {
|
||||
try {
|
||||
JSONObject object = new JSONObject(showDialog.getPath());
|
||||
JSONObject device = object.getJSONObject("device");
|
||||
String manufacturer = device.getString("manufacturer");
|
||||
String model = device.getString("model");
|
||||
DialogUtils.showAlertDialog(this, "你的账号已在另外一台设备登录"
|
||||
, StringUtils.buildString("(", manufacturer, " - ", model, ")")
|
||||
, "知道了", "重新登录"
|
||||
, null, new DialogUtils.CancelListener() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
startActivity(LoginActivity.getIntent(BaseActivity.this, false));
|
||||
}
|
||||
});
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -138,16 +160,31 @@ public abstract class BaseActivity extends BaseAppCompatToolBarActivity {
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
DataUtils.onPause(this);
|
||||
// DataUtils.onPause(this);
|
||||
mIsPause = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
DataUtils.onResume(this);
|
||||
// DataUtils.onResume(this);
|
||||
mIsPause = false;
|
||||
DownloadManager.getInstance(this).initGameMap();
|
||||
// DownloadManager.getInstance(this).initGameMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionsDenied(int requestCode, List<String> perms) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionsGranted(int requestCode, List<String> perms) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,126 +1,37 @@
|
||||
package com.gh.base;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
import com.lightgame.BaseAppCompatActivity;
|
||||
import com.lightgame.ToolbarContainer;
|
||||
import com.lightgame.ToolbarController;
|
||||
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Created by csheng on 15-10-12.
|
||||
*/
|
||||
@ToolbarContainer
|
||||
public abstract class BaseAppCompatToolBarActivity extends BaseAppCompatActivity implements ToolbarController {
|
||||
|
||||
public abstract class BaseAppCompatToolBarActivity extends BaseAppCompatActivity {
|
||||
|
||||
private Toolbar mToolbar;
|
||||
private SystemBarTintManager mTintManager;
|
||||
|
||||
// TODO 获取沉浸栏管理,要进行版本判断或者判断是否为空
|
||||
public SystemBarTintManager getTintManager() {
|
||||
return mTintManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
initToolbar();
|
||||
// Util_Window.initStatusBarColor(getWindow(), ContextCompat.getColor(this, R.color.theme));
|
||||
initStatusBar();
|
||||
}
|
||||
|
||||
private void initToolbar() {
|
||||
mToolbar = (Toolbar) findViewById(R.id.toolbar_navigation);
|
||||
if (mToolbar != null) {
|
||||
// mToolbar.setTitle("");
|
||||
setSupportActionBar(mToolbar);
|
||||
mToolbar.addView(View.inflate(this, R.layout.reuse_actionbar, null));
|
||||
getSupportActionBar().setHomeButtonEnabled(false);
|
||||
// getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||
// getSupportActionBar().setDisplayShowHomeEnabled(false);
|
||||
// getSupportActionBar().setDisplayOptions();
|
||||
}
|
||||
}
|
||||
|
||||
private void initStatusBar() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
setTranslucentStatus(true);
|
||||
mTintManager = new SystemBarTintManager(this);
|
||||
mTintManager.setStatusBarTintEnabled(true);
|
||||
// mTintManager.setNavigationBarTintEnabled(true);
|
||||
if (Build.MANUFACTURER.equals("Meizu") || Build.MANUFACTURER.equals("Xiaomi")) {
|
||||
mTintManager.setStatusBarTintColor(Color.WHITE);
|
||||
} else {
|
||||
mTintManager.setStatusBarTintColor(Color.BLACK);
|
||||
}
|
||||
|
||||
switch (Build.MANUFACTURER) {
|
||||
case "Meizu":
|
||||
try {
|
||||
Window window = getWindow();
|
||||
if (window != null) {
|
||||
WindowManager.LayoutParams lp = window.getAttributes();
|
||||
Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
|
||||
Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
|
||||
darkFlag.setAccessible(true);
|
||||
meizuFlags.setAccessible(true);
|
||||
int bit = darkFlag.getInt(null);
|
||||
int value = meizuFlags.getInt(lp);
|
||||
value |= bit;
|
||||
meizuFlags.setInt(lp, value);
|
||||
window.setAttributes(lp);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case "Xiaomi":
|
||||
try {
|
||||
Window window = getWindow();
|
||||
if (window != null) {
|
||||
Class<?> clazz = window.getClass();
|
||||
Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
|
||||
Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
|
||||
int darkModeFlag = field.getInt(layoutParams);
|
||||
Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
|
||||
extraFlagField.invoke(window, darkModeFlag, darkModeFlag);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
protected void setTranslucentStatus(boolean status) {
|
||||
Window window = getWindow();
|
||||
WindowManager.LayoutParams winParams = window.getAttributes();
|
||||
final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
|
||||
if (status) {
|
||||
winParams.flags |= bits;
|
||||
} else {
|
||||
winParams.flags &= ~bits;
|
||||
}
|
||||
window.setAttributes(winParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
@ -132,23 +43,4 @@ public abstract class BaseAppCompatToolBarActivity extends BaseAppCompatActivity
|
||||
|
||||
protected abstract boolean onNavigationIconClicked();
|
||||
|
||||
@Override
|
||||
public void setNavigationTitle(int res) {
|
||||
if (mToolbar != null) {
|
||||
mToolbar.setTitle(res);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNavigationTitle(CharSequence res) {
|
||||
if (mToolbar != null) {
|
||||
mToolbar.setTitle(res);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Toolbar getToolBar() {
|
||||
return mToolbar;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,397 +0,0 @@
|
||||
//package com.gh.base;
|
||||
//
|
||||
//import android.content.Intent;
|
||||
//import android.os.Bundle;
|
||||
//import android.support.v4.content.ContextCompat;
|
||||
//import android.support.v7.widget.RecyclerView;
|
||||
//import android.text.TextUtils;
|
||||
//import android.view.View;
|
||||
//import android.widget.ImageView;
|
||||
//import android.widget.LinearLayout;
|
||||
//import android.widget.ProgressBar;
|
||||
//import android.widget.RelativeLayout;
|
||||
//import android.widget.TextView;
|
||||
//
|
||||
//import com.gh.common.constant.Config;
|
||||
//import com.gh.common.util.ApkActiveUtils;
|
||||
//import com.gh.common.util.DataUtils;
|
||||
//import com.gh.common.util.DialogUtils;
|
||||
//import com.gh.common.util.DisplayUtils;
|
||||
//import com.gh.common.util.GameUtils;
|
||||
//import com.gh.common.util.NetworkUtils;
|
||||
//import com.gh.common.util.PackageUtils;
|
||||
//import com.gh.common.util.ShareUtils;
|
||||
//import com.gh.common.view.DownloadDialog;
|
||||
//import com.gh.download.DownloadManager;
|
||||
//import com.gh.gamecenter.DownloadManagerActivity;
|
||||
//import com.gh.gamecenter.R;
|
||||
//import com.gh.gamecenter.entity.ApkEntity;
|
||||
//import com.gh.gamecenter.entity.GameEntity;
|
||||
//import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
//import com.gh.gamecenter.eventbus.EBPackage;
|
||||
//import com.gh.gamecenter.manager.PackageManager;
|
||||
//import com.lightgame.download.DataWatcher;
|
||||
//import com.lightgame.download.DownloadEntity;
|
||||
//import com.lightgame.download.FileUtils;
|
||||
//import com.tencent.tauth.Tencent;
|
||||
//
|
||||
//import org.greenrobot.eventbus.Subscribe;
|
||||
//import org.greenrobot.eventbus.ThreadMode;
|
||||
//
|
||||
///**
|
||||
// * Created by Administrator on 2016/9/19.
|
||||
// * 游戏详情、新闻详情基类(控制底部下载栏)
|
||||
// */
|
||||
//public abstract class BaseDetailActivity extends BaseActivity implements View.OnClickListener {
|
||||
//
|
||||
// protected TextView actionbar_tv_title;
|
||||
// protected RecyclerView detail_rv_show;
|
||||
// protected LinearLayout detail_ll_bottom;
|
||||
// protected TextView detail_tv_download;
|
||||
// protected ProgressBar detail_pb_progressbar;
|
||||
// protected TextView detail_tv_per;
|
||||
// protected LinearLayout reuse_ll_loading;
|
||||
// protected LinearLayout reuse_no_connection;
|
||||
// protected LinearLayout reuse_none_data;
|
||||
// protected TextView reuse_tv_none_data;
|
||||
// protected ImageView iv_share;
|
||||
//
|
||||
// protected GameEntity gameEntity;
|
||||
// protected DownloadEntity mDownloadEntity;
|
||||
//
|
||||
// protected String name;
|
||||
// protected String title;
|
||||
// protected String downloadAddWord;
|
||||
// protected String downloadOffText;
|
||||
//
|
||||
// private DataWatcher dataWatcher = new DataWatcher() {
|
||||
// @Override
|
||||
// public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
// if (gameEntity != null && gameEntity.getApk().size() == 1) {
|
||||
// String url = gameEntity.getApk().get(0).getUrl();
|
||||
// if (url.equals(downloadEntity.getUrl())) {
|
||||
// if (!"pause".equals(DownloadManager.getInstance(BaseDetailActivity.this).
|
||||
// getStatus(downloadEntity.getUrl()))) {
|
||||
// mDownloadEntity = downloadEntity;
|
||||
// invalidate();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// @Override
|
||||
// protected int getLayoutId() {
|
||||
// return R.layout.activity_detail;
|
||||
// }
|
||||
//
|
||||
// //接收QQ或者QQ空间分享回调
|
||||
// @Override
|
||||
// protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// super.onActivityResult(requestCode, resultCode, data);
|
||||
//
|
||||
// if (requestCode == com.tencent.connect.common.Constants.REQUEST_QQ_SHARE
|
||||
// || requestCode == com.tencent.connect.common.Constants.REQUEST_QZONE_SHARE) {
|
||||
// Tencent.onActivityResultData(requestCode, resultCode, data, ShareUtils.getInstance(this).QqShareListener);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onCreate(Bundle savedInstanceState) {
|
||||
// super.onCreate(savedInstanceState);
|
||||
//
|
||||
// // 添加分享图标
|
||||
// iv_share = new ImageView(this);
|
||||
// iv_share.setImageResource(R.drawable.ic_share);
|
||||
// iv_share.setOnClickListener(this);
|
||||
// iv_share.setVisibility(View.GONE);
|
||||
// iv_share.setPadding(DisplayUtils.dip2px(this, 13), DisplayUtils.dip2px(this, 11)
|
||||
// , DisplayUtils.dip2px(this, 11), DisplayUtils.dip2px(this, 13));
|
||||
// RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
||||
// DisplayUtils.dip2px(this, 48), DisplayUtils.dip2px(this, 48));
|
||||
// params.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
// params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
// RelativeLayout reuse_actionbar = (RelativeLayout) mContentView.findViewById(
|
||||
// R.id.reuse_actionbar);
|
||||
// reuse_actionbar.addView(iv_share, params);
|
||||
//
|
||||
// actionbar_tv_title = (TextView) findViewById(R.id.actionbar_tv_title);
|
||||
// detail_rv_show = (RecyclerView) findViewById(R.id.detail_rv_show);
|
||||
// detail_ll_bottom = (LinearLayout) findViewById(R.id.detail_ll_bottom);
|
||||
// detail_tv_download = (TextView) findViewById(R.id.detail_tv_download);
|
||||
// detail_pb_progressbar = (ProgressBar) findViewById(R.id.detail_pb_progressbar);
|
||||
// detail_tv_per = (TextView) findViewById(R.id.detail_tv_per);
|
||||
// reuse_ll_loading = (LinearLayout) findViewById(R.id.reuse_ll_loading);
|
||||
// reuse_no_connection = (LinearLayout) findViewById(R.id.reuse_no_connection);
|
||||
// reuse_none_data = (LinearLayout) findViewById(R.id.reuse_none_data);
|
||||
// reuse_tv_none_data = (TextView) findViewById(R.id.reuse_tv_none_data);
|
||||
//
|
||||
// detail_ll_bottom.setOnClickListener(this);
|
||||
// detail_tv_download.setOnClickListener(this);
|
||||
// detail_pb_progressbar.setOnClickListener(this);
|
||||
// detail_tv_per.setOnClickListener(this);
|
||||
// reuse_no_connection.setOnClickListener(this);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onPause() {
|
||||
// super.onPause();
|
||||
// DownloadManager.getInstance(this).removeObserver(dataWatcher);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onResume() {
|
||||
// super.onResume();
|
||||
// if (gameEntity != null
|
||||
// && gameEntity.getApk() != null
|
||||
// && gameEntity.getApk().size() == 1) {
|
||||
// initDownload(true);
|
||||
// }
|
||||
// DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
// }
|
||||
//
|
||||
// protected void initDownload(boolean isCheck) {
|
||||
// if (Config.isShow(this)) {
|
||||
// detail_ll_bottom.setVisibility(View.VISIBLE);
|
||||
// detail_rv_show.setPadding(0, 0, 0,
|
||||
// DisplayUtils.dip2px(getApplicationContext(), 60));
|
||||
// } else {
|
||||
// detail_ll_bottom.setVisibility(View.GONE);
|
||||
// detail_rv_show.setPadding(0, 0, 0, 0);
|
||||
// }
|
||||
// if (gameEntity != null && "光环助手".equals(gameEntity.getName())) {
|
||||
// detail_ll_bottom.setVisibility(View.GONE);
|
||||
// detail_rv_show.setPadding(0, 0, 0, 0);
|
||||
// } else if (gameEntity == null || gameEntity.getApk().isEmpty()) {
|
||||
// detail_tv_download.setVisibility(View.VISIBLE);
|
||||
// detail_pb_progressbar.setVisibility(View.GONE);
|
||||
// detail_tv_per.setVisibility(View.GONE);
|
||||
// if (TextUtils.isEmpty(downloadOffText)) {
|
||||
// detail_tv_download.setText("暂无下载");
|
||||
// } else {
|
||||
// detail_tv_download.setText(downloadOffText);
|
||||
// }
|
||||
// detail_tv_download.setBackgroundResource(R.drawable.game_item_btn_pause_style);
|
||||
// detail_tv_download.setTextColor(0xFF999999);
|
||||
// detail_tv_download.setClickable(false);
|
||||
// } else {
|
||||
// detail_tv_download.setVisibility(View.VISIBLE);
|
||||
// detail_pb_progressbar.setVisibility(View.GONE);
|
||||
// detail_tv_per.setVisibility(View.GONE);
|
||||
// boolean isInstalled = false;
|
||||
// if (gameEntity.getApk() != null && gameEntity.getApk().size() == 1
|
||||
// && PackageManager.isInstalled(gameEntity.getApk().get(0).getPackageName())) {
|
||||
// isInstalled = true;
|
||||
// }
|
||||
// if (isInstalled) {
|
||||
// if (PackageManager.isCanUpdate(gameEntity.getId(), gameEntity.getApk().get(0).getPackageName())) {
|
||||
// if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
// detail_tv_download.setBackgroundResource(
|
||||
// R.drawable.game_item_btn_download_style);
|
||||
// detail_tv_download.setText(String.format("更新《%s》",
|
||||
// gameEntity.getName()));
|
||||
// } else {
|
||||
// detail_tv_download.setBackgroundResource(
|
||||
// R.drawable.game_item_btn_download_style);
|
||||
// detail_tv_download.setText(String.format("更新《%s》%s",
|
||||
// gameEntity.getName(), downloadAddWord));
|
||||
// }
|
||||
// } else {
|
||||
// if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
// && !TextUtils.isEmpty(gameEntity.getApk().get(0).getGhVersion())
|
||||
// && !PackageUtils.isSignature(this, gameEntity.getApk().get(0).getPackageName())) {
|
||||
// if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
// detail_tv_download.setBackgroundResource(
|
||||
// R.drawable.game_item_btn_plugin_style);
|
||||
// detail_tv_download.setText(String.format("插件化《%s》",
|
||||
// gameEntity.getName()));
|
||||
// } else {
|
||||
// detail_tv_download.setBackgroundResource(
|
||||
// R.drawable.game_item_btn_plugin_style);
|
||||
// detail_tv_download.setText(String.format("插件化《%s》%s",
|
||||
// gameEntity.getName(), downloadAddWord));
|
||||
// }
|
||||
// } else {
|
||||
// if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
// detail_tv_download.setBackgroundResource(
|
||||
// R.drawable.game_item_btn_launch_style);
|
||||
// detail_tv_download.setText(String.format("启动《%s》",
|
||||
// gameEntity.getName()));
|
||||
// } else {
|
||||
// detail_tv_download.setBackgroundResource(
|
||||
// R.drawable.game_item_btn_launch_style);
|
||||
// detail_tv_download.setText(String.format("启动《%s》%s",
|
||||
// gameEntity.getName(), downloadAddWord));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// String status = GameUtils.getDownloadBtnText(this, gameEntity);
|
||||
//
|
||||
// switch (status) {
|
||||
// case "插件化":
|
||||
// detail_tv_download.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
// break;
|
||||
// case "打开":
|
||||
// detail_tv_download.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
// break;
|
||||
// default:
|
||||
// detail_tv_download.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
// detail_tv_download.setText(String.format(status + "《%s》",
|
||||
// gameEntity.getName()));
|
||||
// } else {
|
||||
// detail_tv_download.setText(String.format(status + "《%s》%s",
|
||||
// gameEntity.getName(), downloadAddWord));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (isCheck && gameEntity != null
|
||||
// && gameEntity.getApk() != null
|
||||
// && gameEntity.getApk().size() == 1) {
|
||||
// String url = gameEntity.getApk().get(0).getUrl();
|
||||
// DownloadEntity downloadEntity = DownloadManager.getInstance(getApplicationContext()).get(url);
|
||||
// if (downloadEntity != null) {
|
||||
// mDownloadEntity = downloadEntity;
|
||||
// detail_tv_download.setVisibility(View.GONE);
|
||||
// detail_pb_progressbar.setVisibility(View.VISIBLE);
|
||||
// detail_tv_per.setVisibility(View.VISIBLE);
|
||||
// invalidate();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void invalidate() {
|
||||
// detail_pb_progressbar.setProgress((int) (mDownloadEntity.getPercent() * 10));
|
||||
// detail_tv_per.setTextColor(0xFFFFFFFF);
|
||||
// switch (mDownloadEntity.getStatus()) {
|
||||
// case downloading:
|
||||
// case pause:
|
||||
// case timeout:
|
||||
// case neterror:
|
||||
// case waiting:
|
||||
// detail_tv_per.setText("下载中");
|
||||
// break;
|
||||
// case done:
|
||||
// detail_tv_per.setText("安装");
|
||||
// if (mDownloadEntity.isPluggable()
|
||||
// && PackageManager.isInstalled(mDownloadEntity.getPackageName())) {
|
||||
// detail_pb_progressbar.setProgressDrawable(ContextCompat.getDrawable(this, R.drawable.progressbar_plugin_radius_style));
|
||||
// } else {
|
||||
// detail_pb_progressbar.setProgressDrawable(ContextCompat.getDrawable(this, R.drawable.progressbar_normal_radius_style));
|
||||
// }
|
||||
// break;
|
||||
// case cancel:
|
||||
// case hijack:
|
||||
// case notfound:
|
||||
// initDownload(false);
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 接收下载被删除消息
|
||||
// @Subscribe(threadMode = ThreadMode.MAIN)
|
||||
// public void onEvent(EBDownloadStatus status) {
|
||||
// if ("delete".equals(status.getStatus())
|
||||
// && gameEntity != null
|
||||
// && gameEntity.getApk() != null
|
||||
// && gameEntity.getApk().size() == 1) {
|
||||
// String url = gameEntity.getApk().get(0).getUrl();
|
||||
// if (url.equals(status.getUrl())) {
|
||||
// initDownload(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 接受安装、卸载消息
|
||||
// @Subscribe(threadMode = ThreadMode.MAIN)
|
||||
// public void onEventMainThread(EBPackage busFour) {
|
||||
// if (gameEntity != null
|
||||
// && gameEntity.getApk() != null
|
||||
// && gameEntity.getApk().size() > 0) {
|
||||
// for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
// String packageName = apkEntity.getPackageName();
|
||||
// if (packageName.equals(busFour.getPackageName())) {
|
||||
// ApkActiveUtils.filterHideApk(gameEntity);
|
||||
// initDownload(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// if (v == detail_tv_download) {
|
||||
// if (gameEntity != null && !gameEntity.getApk().isEmpty()) {
|
||||
// if (gameEntity.getApk().size() == 1) {
|
||||
// if (NetworkUtils.isWifiConnected(this)) {
|
||||
// download();
|
||||
// } else {
|
||||
// DialogUtils.showDownloadDialog(this, new DialogUtils.ConfirmListener() {
|
||||
// @Override
|
||||
// public void onConfirm() {
|
||||
// download();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// } else {
|
||||
// DownloadDialog.getInstance(this).showPopupWindow(v, gameEntity, mEntrance, name + ":" + title);
|
||||
// }
|
||||
// } else {
|
||||
// toast("稍等片刻~!游戏正在上传中...");
|
||||
// }
|
||||
// } else if (v == detail_pb_progressbar || v == detail_tv_per) {
|
||||
// String str = detail_tv_per.getText().toString();
|
||||
// if ("下载中".equals(str)) {
|
||||
// DownloadManagerActivity.startDownloadManagerActivity(this, gameEntity.getApk().get(0).getUrl()
|
||||
// , mEntrance + "+(" + name + "[" + title + "])");
|
||||
// } else if ("安装".equals(str)) {
|
||||
// PackageUtils.launchSetup(this, mDownloadEntity.getPath());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void download() {
|
||||
// String str = detail_tv_download.getText().toString();
|
||||
// if (str.contains("启动")) {
|
||||
// DataUtils.onGameLaunchEvent(this, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), name);
|
||||
//
|
||||
// PackageUtils.launchApplicationByPackageName(this, gameEntity.getApk().get(0).getPackageName());
|
||||
// } else {
|
||||
// String method;
|
||||
// if (str.contains("更新")) {
|
||||
// method = "更新";
|
||||
// } else if (str.contains("插件化")) {
|
||||
// method = "插件化";
|
||||
// } else {
|
||||
// method = "下载";
|
||||
// }
|
||||
// ApkEntity apkEntity = gameEntity.getApk().get(0);
|
||||
// String msg = FileUtils.isCanDownload(this, apkEntity.getSize());
|
||||
// if (TextUtils.isEmpty(msg)) {
|
||||
// DataUtils.onGameDownloadEvent(this, gameEntity.getName(), apkEntity.getPlatform(), mEntrance, "下载开始");
|
||||
//
|
||||
// DownloadManager.createDownload(this, apkEntity, gameEntity, method, mEntrance, name + ":" + title);
|
||||
//
|
||||
// detail_tv_download.setVisibility(View.GONE);
|
||||
// detail_pb_progressbar.setVisibility(View.VISIBLE);
|
||||
// detail_tv_per.setVisibility(View.VISIBLE);
|
||||
// detail_pb_progressbar.setProgress(0);
|
||||
// detail_tv_per.setText("0.0%");
|
||||
//
|
||||
//// DownloadManager.getInstance(BaseDetailActivity.this).putStatus(apkEntity.getUrl(), "downloading");
|
||||
// } else {
|
||||
// toast(msg);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//>>>>>>> b239407c25cb85374c0f50c257411b4b98e10e77
|
||||
@ -13,11 +13,31 @@ import butterknife.ButterKnife;
|
||||
* @Time 9:55 AM
|
||||
*/
|
||||
|
||||
public abstract class BaseRecyclerViewHolder extends RecyclerView.ViewHolder {
|
||||
public abstract class BaseRecyclerViewHolder<T> extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
||||
private T data;
|
||||
private OnListClickListener mListClickListener;
|
||||
|
||||
public BaseRecyclerViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 具体的设置监听在childViewHolder 设置
|
||||
* @param itemView
|
||||
* @param data 一般情况下只传列表数据
|
||||
* @param listClickListener 列表事件接口
|
||||
*/
|
||||
public BaseRecyclerViewHolder(View itemView, T data, OnListClickListener listClickListener) {
|
||||
this(itemView);
|
||||
this.data = data;
|
||||
this.mListClickListener = listClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mListClickListener.onListClick(view, getAdapterPosition(), data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,6 +4,9 @@ import android.app.Activity;
|
||||
import android.app.Application.ActivityLifecycleCallbacks;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
|
||||
/**
|
||||
* 1、写点针对生命周期的统计代码
|
||||
* 2、写点通用的逻辑
|
||||
@ -29,11 +32,18 @@ public class GHActivityLifecycleCallbacksImpl implements ActivityLifecycleCallba
|
||||
@Override
|
||||
public void onActivityResumed(Activity activity) {
|
||||
|
||||
DataUtils.onResume(activity);
|
||||
try {
|
||||
// 初始化gameMap
|
||||
DownloadManager.getInstance(activity).initGameMap();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(Activity activity) {
|
||||
|
||||
DataUtils.onPause(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -17,12 +17,13 @@ import android.widget.RemoteViews;
|
||||
|
||||
import com.gh.common.util.AppDebugConfig;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.lightgame.download.FileUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.gh.gamecenter.BuildConfig;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.download.FileUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.xiaomi.mipush.sdk.ErrorCode;
|
||||
import com.xiaomi.mipush.sdk.MiPushClient;
|
||||
import com.xiaomi.mipush.sdk.MiPushCommandMessage;
|
||||
@ -44,7 +45,7 @@ import static com.gh.common.util.EntranceUtils.ENTRANCE_MIPUSH;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_ARTICLE;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_GAME;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_WEB;
|
||||
import static com.gh.common.util.EntranceUtils.HOSt_COLUMN;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_COLUMN;
|
||||
import static com.gh.common.util.EntranceUtils.KEY_ENTRANCE;
|
||||
import static com.gh.common.util.EntranceUtils.KEY_GAMEID;
|
||||
import static com.gh.common.util.EntranceUtils.KEY_ID;
|
||||
@ -95,7 +96,7 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
Utils.log("channel = " + channel);
|
||||
|
||||
// 1判断渠道号是否一致或是否为ALL
|
||||
String packageChannel = AppController.getInstance().getChannel();
|
||||
String packageChannel = HaloApp.getInstance().getChannel();
|
||||
if ("ALL".equals(channel) || channel.equalsIgnoreCase(packageChannel)) {
|
||||
String type = jsonObject.getString(KEY_TYPE);
|
||||
Utils.log("type = " + type);
|
||||
@ -148,6 +149,9 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
case "NEW_GAME":
|
||||
// 新游推送
|
||||
showNotification(context, jsonObject, 2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,13 +178,6 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
|
||||
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
Notification notification = new NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.logo)
|
||||
.setTicker(jsonObject.getString("pushTitle"))
|
||||
.setContentTitle(jsonObject.getString("pushTitle"))
|
||||
.setContentText(jsonObject.getString("pushDesc"))
|
||||
.setContentIntent(pendingIntent).build();
|
||||
|
||||
RemoteViews remoteViews = null;
|
||||
|
||||
if (Build.MANUFACTURER.equals("Meizu") &&
|
||||
@ -207,6 +204,14 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
path = null;
|
||||
}
|
||||
|
||||
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
|
||||
.setTicker(jsonObject.getString("pushTitle"))
|
||||
.setContentTitle(jsonObject.getString("pushTitle"))
|
||||
.setContentText(jsonObject.getString("pushDesc"))
|
||||
.setContentIntent(pendingIntent)
|
||||
.setDefaults(Notification.DEFAULT_SOUND) // 添加系统默认声音
|
||||
.setAutoCancel(true); // FLAG_AUTO_CANCEL表明当通知被用户点击时,通知将被清除。
|
||||
|
||||
if (remoteViews != null) {
|
||||
if (path == null) {
|
||||
remoteViews.setImageViewBitmap(R.id.icon, BitmapFactory.decodeResource(context.getResources(), R.drawable.logo));
|
||||
@ -215,25 +220,20 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
}
|
||||
remoteViews.setTextViewText(R.id.title, jsonObject.getString("pushTitle"));
|
||||
remoteViews.setTextViewText(R.id.intro, jsonObject.getString("pushDesc"));
|
||||
notification.contentView = remoteViews;
|
||||
|
||||
builder.setSmallIcon(R.drawable.logo);
|
||||
builder.setCustomContentView(remoteViews);
|
||||
|
||||
} else {
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.logo_black)
|
||||
.setTicker(jsonObject.getString("pushTitle"))
|
||||
.setContentTitle(jsonObject.getString("pushTitle"))
|
||||
.setContentText(jsonObject.getString("pushDesc"))
|
||||
.setContentIntent(pendingIntent);
|
||||
builder.setSmallIcon(R.drawable.logo_black);
|
||||
if (path == null) {
|
||||
builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.logo));
|
||||
} else {
|
||||
builder.setLargeIcon(BitmapFactory.decodeFile(path));
|
||||
}
|
||||
notification = builder.build();
|
||||
}
|
||||
|
||||
notification.defaults = Notification.DEFAULT_SOUND;// 添加系统默认声音
|
||||
notification.flags |= Notification.FLAG_AUTO_CANCEL; // FLAG_AUTO_CANCEL表明当通知被用户点击时,通知将被清除。
|
||||
nManager.notify(((int) System.currentTimeMillis() / 1000), notification);// 通过通知管理器来发起通知。如果id不同,则每click,在status哪里增加一个提示
|
||||
nManager.notify(((int) System.currentTimeMillis() / 1000), builder.build());// 通过通知管理器来发起通知。如果id不同,则每click,在status哪里增加一个提示
|
||||
}
|
||||
|
||||
private ArrayList<String> getAllPackageName(Context context) {
|
||||
@ -269,7 +269,7 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
bundle.putString(KEY_TO, "GameDetailActivity");
|
||||
bundle.putString(KEY_GAMEID, target);
|
||||
break;
|
||||
case HOSt_COLUMN:
|
||||
case HOST_COLUMN:
|
||||
bundle.putString(KEY_TO, "SubjectActivity");
|
||||
bundle.putString(KEY_ID, target);
|
||||
break;
|
||||
@ -285,8 +285,7 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotificationMessageArrived(Context context,
|
||||
MiPushMessage message) {
|
||||
public void onNotificationMessageArrived(Context context, MiPushMessage message) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
AppDebugConfig.logMethodWithParams(this, message);
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ public class GHUmengNotificationClickHandler extends UmengNotificationClickHandl
|
||||
bundle.putString(EntranceUtils.KEY_TO, "GameDetailActivity");
|
||||
bundle.putString(EntranceUtils.KEY_GAMEID, target);
|
||||
break;
|
||||
case EntranceUtils.HOSt_COLUMN:
|
||||
case EntranceUtils.HOST_COLUMN:
|
||||
bundle.putString(EntranceUtils.KEY_TO, "SubjectActivity");
|
||||
bundle.putString(EntranceUtils.KEY_ID, target);
|
||||
break;
|
||||
|
||||
19
app/src/main/java/com/gh/base/OnListClickListener.java
Normal file
19
app/src/main/java/com/gh/base/OnListClickListener.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.gh.base;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Created by khy on 26/09/17.
|
||||
*/
|
||||
|
||||
public interface OnListClickListener {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param view
|
||||
* @param position list position
|
||||
* @param data list data (直接强转 如果列表传入不同数据类型 请做好判断)
|
||||
* @param <T>
|
||||
*/
|
||||
<T> void onListClick(View view, int position, T data);
|
||||
}
|
||||
@ -3,32 +3,33 @@ package com.gh.base.fragment;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.base.OnListClickListener;
|
||||
import com.gh.base.OnRequestCallBackListener;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.gamecenter.eventbus.EBMiPush;
|
||||
import com.lightgame.ToolbarController;
|
||||
import com.lightgame.utils.RuntimeUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/4.
|
||||
* Fragment 基类
|
||||
*/
|
||||
public abstract class BaseFragment<T> extends Fragment implements OnRequestCallBackListener<T>,
|
||||
View.OnClickListener, ToolbarController {
|
||||
View.OnClickListener, OnListClickListener{
|
||||
|
||||
// TODO private view
|
||||
protected View view;
|
||||
@ -61,32 +62,11 @@ public abstract class BaseFragment<T> extends Fragment implements OnRequestCallB
|
||||
RuntimeUtils.getInstance().runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
// 定时任务全部改用这个方法, 在onDestroy做统一取消定时
|
||||
protected void postDelayedRunnable(Runnable runnable, long delayMillis) {
|
||||
RuntimeUtils.getInstance().runOnUiThread(runnable, delayMillis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNavigationTitle(@StringRes int res) {
|
||||
if (getActivity() instanceof ToolbarController) {
|
||||
((ToolbarController) getActivity()).setNavigationTitle(res);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNavigationTitle(CharSequence res) {
|
||||
if (getActivity() instanceof ToolbarController) {
|
||||
((ToolbarController) getActivity()).setNavigationTitle(res);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Toolbar getToolBar() {
|
||||
if (getActivity() instanceof ToolbarController) {
|
||||
return ((ToolbarController) getActivity()).getToolBar();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -128,11 +108,12 @@ public abstract class BaseFragment<T> extends Fragment implements OnRequestCallB
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
RuntimeUtils.getInstance().removeRunnable();
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
public void toast(String msg) {
|
||||
Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(getContext(), msg);
|
||||
}
|
||||
|
||||
public boolean isEverPause() {
|
||||
@ -159,4 +140,13 @@ public abstract class BaseFragment<T> extends Fragment implements OnRequestCallB
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void onListClick(View view, int position, T data) {
|
||||
|
||||
}
|
||||
|
||||
protected <K> Observable<K> asyncCall(Observable<K> observable) {
|
||||
return observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -9,12 +9,13 @@ import com.gh.gamecenter.BuildConfig;
|
||||
|
||||
public class Config {
|
||||
|
||||
public static final String HOST = BuildConfig.HOST;
|
||||
public static final String API_HOST = BuildConfig.API_HOST;
|
||||
public static final String USER_HOST = BuildConfig.USER_HOST;
|
||||
public static final String COMMENT_HOST = BuildConfig.COMMENT_HOST;
|
||||
public static final String DATA_HOST = BuildConfig.DATA_HOST;
|
||||
public static final String LIBAO_HOST = BuildConfig.LIBAO_HOST;
|
||||
public static final String MESSAGE_HOST = BuildConfig.MESSAGE_HOST;
|
||||
public static final String USERSEA_HOST = BuildConfig.USERSEA_HOST;
|
||||
|
||||
/**
|
||||
* 需要配置的请使用{@link PreferenceManager#getDefaultSharedPreferences(Context)}
|
||||
@ -30,13 +31,29 @@ public class Config {
|
||||
public static final String MIPUSH_APPID = BuildConfig.MIPUSH_APPID;
|
||||
public static final String MIPUSH_APPKEY = BuildConfig.MIPUSH_APPKEY;
|
||||
public static final String MTA_APPKEY = BuildConfig.MTA_APPKEY;
|
||||
public static final String TD_APPID = BuildConfig.TD_APPID;// TalkingData
|
||||
public static final String TALKINGDATA_APPID = BuildConfig.TD_APPID;// TalkingData
|
||||
public static final String UMENG_APPKEY = BuildConfig.UMENG_APPKEY;
|
||||
public static final String UMENG_MESSAGE_SECRET = BuildConfig.UMENG_MESSAGE_SECRET;
|
||||
public static final String USERSEA_APP_ID = BuildConfig.USERSEA_APP_ID; // 登录验证
|
||||
public static final String USERSEA_APP_SECRET = BuildConfig.USERSEA_APP_SECRET; // 登录验证
|
||||
public static final String BUGLY_APPID = BuildConfig.BUGLY_APPID;
|
||||
public static final String PATCH_VERSION_NAME = BuildConfig.PATCH_VERSION_NAME; // 补丁包版本 对应关于->版本号
|
||||
// http://www.ghzs666.com/article/${articleId}.html
|
||||
public static final String URL_ARTICLE = "http://www.ghzs666.com/article/"; // TODO ghzs/ghzs666 统一
|
||||
public static final String PATCHES = "patches";
|
||||
|
||||
public static boolean isShow(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return sp.getBoolean("isShow", true);
|
||||
}
|
||||
|
||||
public static String getExceptionMsg(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return sp.getString("errMsg", null);
|
||||
}
|
||||
|
||||
public static void setExceptionMsg(Context context, String errMsg) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putString("errMsg", errMsg).apply();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,6 +5,11 @@ public class Constants {
|
||||
public static final int SEND_NEWS_FEEDBACK = 0x126;
|
||||
public static final int SEND_COMMENT_FEEDBACK = 0x127;
|
||||
|
||||
public final static int LIST_FOOTER_ITEM = 1;
|
||||
public final static int LIST_HEAD_ITEM = 1;
|
||||
|
||||
public final static int NOT_NETWORK_CODE = 504; // 没有网络的状态码(应该是这个吧!)
|
||||
|
||||
//手机号码匹配规则
|
||||
public static final String REGEX_MOBILE = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
|
||||
public static final String REGEX_ACCOUNT = "^[a-zA-Z_]\\w{5,17}$";
|
||||
|
||||
@ -21,6 +21,7 @@ public class ItemViewType {
|
||||
public static final int LOADING = 14; // 加载布局
|
||||
public static final int LIBAO_NORMAL = 15; // 礼包正常布局
|
||||
public static final int LIBAO_SKIP_CONCERN = 16; // 跳转关注管理页面布局
|
||||
public static final int KC_HINT = 16;
|
||||
public static final int KC_HINT = 17;
|
||||
public static final int GAME_PULGIN = 18; // 游戏插件模块
|
||||
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.gamecenter.LoginActivity;
|
||||
|
||||
@ -12,13 +13,13 @@ import com.gh.gamecenter.LoginActivity;
|
||||
public class CheckLoginUtils {
|
||||
|
||||
public static void checkLogin(final Context context, OnLoggenInListener listener) {
|
||||
String token = "";
|
||||
if (token == null) {
|
||||
String token = LoginUtils.getToken(context);
|
||||
if (TextUtils.isEmpty(token)) {
|
||||
DialogUtils.showWarningDialog(context, "登录提示", "需要登录才能使用该功能喔!", "取消", "快速登录",
|
||||
new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
Intent intent = LoginActivity.getIntent(context);
|
||||
Intent intent = LoginActivity.getIntent(context, false);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}, null);
|
||||
|
||||
103
app/src/main/java/com/gh/common/util/CollectionUtils.kt
Normal file
103
app/src/main/java/com/gh/common/util/CollectionUtils.kt
Normal file
@ -0,0 +1,103 @@
|
||||
package com.gh.common.util
|
||||
|
||||
import android.content.Context
|
||||
import com.gh.gamecenter.eventbus.EBCollectionChanged
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.ResponseBody
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.json.JSONObject
|
||||
import retrofit2.HttpException
|
||||
import rx.Observable
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
import rx.schedulers.Schedulers
|
||||
|
||||
/**
|
||||
* Created by khy on 26/07/17.
|
||||
*/
|
||||
object CollectionUtils {
|
||||
|
||||
enum class CollectionType {
|
||||
toolkit, article
|
||||
}
|
||||
|
||||
fun postCollection(context: Context, content: String, type: CollectionType, listener: OnCollectionListener) {
|
||||
|
||||
val body = RequestBody.create(MediaType.parse("application/json"), content)
|
||||
val postCollection = when (type) {
|
||||
CollectionType.article -> RetrofitManager.getInstance(context).getApi().postCollectionArticle(body)
|
||||
CollectionType.toolkit -> RetrofitManager.getInstance(context).getApi().postCollectionTools(body)
|
||||
}
|
||||
postCollection
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<ResponseBody>() {
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
super.onResponse(response)
|
||||
listener.onSuccess()
|
||||
EventBus.getDefault().post(EBCollectionChanged(JSONObject(content).getString("_id"), true, type))
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
super.onFailure(e)
|
||||
if (e != null) {
|
||||
try {
|
||||
val string = e.response()?.errorBody()?.string()
|
||||
val errorBody = JSONObject(string)
|
||||
if (errorBody.getInt("status") == 40031) {
|
||||
listener.onSuccess()
|
||||
return
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
listener.onError()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun deleteCollection(context: Context, id: String, type: CollectionType, listener: OnCollectionListener) {
|
||||
|
||||
val postCollection: Observable<ResponseBody>
|
||||
when (type) {
|
||||
CollectionType.article -> postCollection = RetrofitManager.getInstance(context).getApi().deletaCollectionArticle(id)
|
||||
CollectionType.toolkit -> postCollection = RetrofitManager.getInstance(context).getApi().deleteCollectionTools(id)
|
||||
}
|
||||
postCollection
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<ResponseBody>() {
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
super.onResponse(response)
|
||||
listener.onSuccess()
|
||||
EventBus.getDefault().post(EBCollectionChanged(id, false, type))
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
super.onFailure(e)
|
||||
listener.onError()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun patchCollection(context: Context, id: String, type: CollectionType) {
|
||||
val postCollection = when (type) {
|
||||
CollectionType.article -> RetrofitManager.getInstance(context).getApi().patchCollectionArticle(id)
|
||||
CollectionType.toolkit -> RetrofitManager.getInstance(context).getApi().patchCollectionTools(id)
|
||||
}
|
||||
postCollection
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<ResponseBody>() {})
|
||||
}
|
||||
|
||||
|
||||
interface OnCollectionListener {
|
||||
fun onSuccess()
|
||||
fun onError()
|
||||
}
|
||||
|
||||
}
|
||||
@ -15,10 +15,10 @@ import com.gh.gamecenter.CommentDetailActivity;
|
||||
import com.gh.gamecenter.MessageDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.OnCommentCallBackListener;
|
||||
import com.gh.gamecenter.db.CommentDao;
|
||||
import com.gh.gamecenter.db.VoteDao;
|
||||
import com.gh.gamecenter.db.info.VoteInfo;
|
||||
import com.gh.gamecenter.adapter.viewholder.CommentViewHolder;
|
||||
import com.gh.gamecenter.entity.CommentEntity;
|
||||
import com.gh.gamecenter.entity.UserDataEntity;
|
||||
import com.gh.gamecenter.entity.UserInfoEntity;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.json.JSONException;
|
||||
@ -72,8 +72,6 @@ public class CommentUtils {
|
||||
public static void showReportDialog(final CommentEntity commentEntity, final Context context,
|
||||
final OnCommentCallBackListener listener, final String newsId) {
|
||||
|
||||
CommentDao commentDao = new CommentDao(context);
|
||||
|
||||
final Dialog dialog = new Dialog(context);
|
||||
|
||||
LinearLayout container = new LinearLayout(context);
|
||||
@ -83,7 +81,7 @@ public class CommentUtils {
|
||||
|
||||
List<String> dialogType = new ArrayList<>();
|
||||
|
||||
if (!commentDao.isMyComment(commentEntity.getId())) {
|
||||
if (commentEntity.getUserData() == null || !commentEntity.getUserData().isCommentOwn()) {
|
||||
dialogType.add("回复");
|
||||
}
|
||||
|
||||
@ -186,7 +184,7 @@ public class CommentUtils {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
PostCommentUtils.addReportData(mContext, jsonObject.toString(), true,
|
||||
PostCommentUtils.addReportData(mContext, jsonObject.toString(),
|
||||
new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSuccess(JSONObject response) {
|
||||
@ -208,7 +206,7 @@ public class CommentUtils {
|
||||
reportTypeDialog.show();
|
||||
}
|
||||
|
||||
public static void initVote(final Context context, final CommentEntity commentEntity, final VoteDao voteDao,
|
||||
public static void postVote(final Context context, final CommentEntity commentEntity,
|
||||
final TextView commentLikeCountTv, final ImageView commentLikeIv, final OnVoteListener listener) {
|
||||
CheckLoginUtils.checkLogin(context, new CheckLoginUtils.OnLoggenInListener() {
|
||||
@Override
|
||||
@ -223,11 +221,10 @@ public class CommentUtils {
|
||||
commentLikeCountTv.setText(String.valueOf(commentEntity.getVote()));
|
||||
commentLikeCountTv.setVisibility(View.VISIBLE);
|
||||
|
||||
PostCommentUtils.addCommentVoto(context, commentEntity.getId(), true,
|
||||
PostCommentUtils.addCommentVoto(context, commentEntity.getId(),
|
||||
new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSuccess(JSONObject response) {
|
||||
voteDao.add(new VoteInfo(commentEntity.getId()));
|
||||
if (listener != null) {
|
||||
listener.onVote();
|
||||
}
|
||||
@ -251,7 +248,7 @@ public class CommentUtils {
|
||||
if (exception.code() == 403) {
|
||||
try {
|
||||
String detail = new JSONObject(exception.response().errorBody().string()).getString("detail");
|
||||
if (detail.equals("voted")) {
|
||||
if ("voted".equals(detail)) {
|
||||
Utils.toast(context, "已经点过赞啦!");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
@ -267,6 +264,39 @@ public class CommentUtils {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 设置评论item 用户相关的view(点赞/头像/用户名)
|
||||
public static void setCommentUserView(Context mContext, CommentViewHolder holder, CommentEntity entity) {
|
||||
UserDataEntity userDataEntity = entity.getUserData();
|
||||
holder.commentLikeCountTv.setTextColor(ContextCompat.getColor(mContext, R.color.hint));
|
||||
holder.commentLikeIv.setImageResource(R.drawable.ic_like_unselect);
|
||||
|
||||
if (entity.getVote() == 0) {
|
||||
holder.commentLikeCountTv.setVisibility(View.GONE);
|
||||
} else { // 检查是否已点赞
|
||||
if (userDataEntity != null && userDataEntity.isCommentVoted()) {
|
||||
holder.commentLikeCountTv.setTextColor(ContextCompat.getColor(mContext, R.color.theme));
|
||||
holder.commentLikeIv.setImageResource(R.drawable.ic_like_select);
|
||||
}
|
||||
holder.commentLikeCountTv.setVisibility(View.VISIBLE);
|
||||
holder.commentLikeCountTv.setText(String.valueOf(entity.getVote()));
|
||||
}
|
||||
|
||||
//检查是否是自身评论
|
||||
UserInfoEntity userInfo = LoginUtils.getUserInfo(mContext);
|
||||
if (userDataEntity != null && userDataEntity.isCommentOwn() && userInfo != null) {
|
||||
holder.commentUserNameTv.setText(userInfo.getName());
|
||||
ImageUtils.Companion.display(holder.commentUserIconDv, userInfo.getIcon());
|
||||
} else {
|
||||
holder.commentUserNameTv.setText(entity.getUser().getName());
|
||||
if (TextUtils.isEmpty(entity.getUser().getIcon())) {
|
||||
ImageUtils.Companion.display(holder.commentUserIconDv, R.drawable.user_default_icon_comment);
|
||||
} else {
|
||||
ImageUtils.Companion.display(holder.commentUserIconDv, entity.getUser().getIcon());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnVoteListener {
|
||||
void onVote();
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package com.gh.common.util
|
||||
|
||||
import android.content.Context
|
||||
import com.gh.gamecenter.eventbus.EBReuse
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import okhttp3.MediaType
|
||||
@ -10,6 +10,7 @@ import okhttp3.ResponseBody
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.json.JSONArray
|
||||
import retrofit2.HttpException
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
import rx.schedulers.Schedulers
|
||||
|
||||
/**
|
||||
@ -18,46 +19,67 @@ import rx.schedulers.Schedulers
|
||||
*/
|
||||
object ConcernUtils {
|
||||
|
||||
fun postConcernGameId(context: Context, gameId: String) {
|
||||
TokenUtils.getToken(context, true)
|
||||
.flatMap { token ->
|
||||
val params = JSONArray()
|
||||
params.put(gameId)
|
||||
val body = RequestBody.create(MediaType.parse("application/json"), params.toString())
|
||||
RetrofitManager.getUser().postConcern(token, body)
|
||||
}.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(Response<ResponseBody>())
|
||||
fun postConcernGameId(context: Context, gameId: String, listener: onConcernListener?) {
|
||||
val params = JSONArray()
|
||||
params.put(gameId)
|
||||
val body = RequestBody.create(MediaType.parse("application/json"), params.toString())
|
||||
RetrofitManager.getInstance(context).getApi()
|
||||
.postConcern(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<ResponseBody>(){
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
super.onResponse(response)
|
||||
listener?.onSuccess()
|
||||
EventBus.getDefault().post(EBConcernChanged(gameId, true))
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
super.onFailure(e)
|
||||
listener?.onError()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun deleteConcernData(context: Context, gameId: String) {
|
||||
TokenUtils.getToken(context, true)
|
||||
.flatMap { token -> RetrofitManager.getUser().deleteConcern(token, gameId) }.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(Response<ResponseBody>())
|
||||
fun deleteConcernData(context: Context, gameId: String, listener: onConcernListener?) {
|
||||
RetrofitManager.getInstance(context).getApi()
|
||||
.deleteConcern(gameId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<ResponseBody>(){
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
super.onResponse(response)
|
||||
listener?.onSuccess()
|
||||
EventBus.getDefault().post(EBConcernChanged(gameId, false))
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
super.onFailure(e)
|
||||
listener?.onError()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun updateConcernData(context: Context, data: JSONArray) {
|
||||
TokenUtils.getToken(context, true)
|
||||
.flatMap { token ->
|
||||
val body = RequestBody.create(MediaType.parse("application/json"),
|
||||
data.toString())
|
||||
RetrofitManager.getUser().putConcern(token, body)
|
||||
}
|
||||
val body = RequestBody.create(MediaType.parse("application/json"),
|
||||
data.toString())
|
||||
RetrofitManager.getInstance(context).getApi()
|
||||
.putConcern(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(object : Response<ResponseBody>() {
|
||||
override fun onResponse(response: ResponseBody) {
|
||||
super.onResponse(response)
|
||||
EventBus.getDefault().post(EBReuse("UpdateConcernSuccess"))
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException) {
|
||||
super.onFailure(e)
|
||||
EventBus.getDefault().post(EBReuse("UpdateConcernFailure"))
|
||||
EventBus.getDefault().post(EBConcernChanged())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
interface onConcernListener {
|
||||
fun onSuccess()
|
||||
fun onError()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
@ -37,9 +37,9 @@ public class DataLogUtils {
|
||||
|
||||
// 上传日志
|
||||
public static void uploadLog(Context context, String topic, Map<String, Object> map) {
|
||||
String version = PackageUtils.getVersionName(context);
|
||||
String version = PackageUtils.getPatchVersionName();
|
||||
String user = Installation.getUUID(context);
|
||||
String channel = AppController.getInstance().getChannel();
|
||||
String channel = HaloApp.getInstance().getChannel();
|
||||
map.put("version", version);
|
||||
map.put("user", user);
|
||||
map.put("device_id", TokenUtils.getDeviceId(context));
|
||||
@ -53,7 +53,7 @@ public class DataLogUtils {
|
||||
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
RetrofitManager.getData().postLog(body)
|
||||
RetrofitManager.getInstance(context).getData().postLog(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
|
||||
@ -5,11 +5,16 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.halo.assistant.TinkerApp;
|
||||
import com.tencent.bugly.beta.tinker.TinkerManager;
|
||||
import com.tencent.bugly.crashreport.CrashReport;
|
||||
import com.tencent.mta.track.StatisticsDataAPI;
|
||||
import com.tencent.stat.MtaSDkException;
|
||||
import com.tencent.stat.StatConfig;
|
||||
import com.tencent.stat.StatCrashReporter;
|
||||
import com.tencent.stat.StatReportStrategy;
|
||||
import com.tencent.stat.StatService;
|
||||
import com.tencent.tinker.lib.tinker.Tinker;
|
||||
import com.tendcloud.tenddata.TCAgent;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -29,52 +34,76 @@ public class DataUtils {
|
||||
* @param debug 是否debug模式
|
||||
* @param channel
|
||||
*/
|
||||
public static void init(Application context, final boolean debug, String channel) {
|
||||
public static void init(final Application context, final boolean debug, String channel) {
|
||||
|
||||
//TalkingData
|
||||
TCAgent.LOG_ON = debug;
|
||||
if (!debug) {
|
||||
TCAgent.init(context, Config.TD_APPID, channel);
|
||||
//TODO 去除为了测试MTA的问题,这个版本不启用
|
||||
TCAgent.setReportUncaughtExceptions(true);
|
||||
try {
|
||||
TCAgent.LOG_ON = debug;
|
||||
TCAgent.init(context, Config.TALKINGDATA_APPID, channel);
|
||||
/**
|
||||
*
|
||||
* 不要启用!!!!不要启用,全部由{@link com.gh.base.AppUncaughtHandler}处理
|
||||
*/
|
||||
TCAgent.setReportUncaughtExceptions(false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 打开debug开关,可查看mta上报日志或错误
|
||||
// debug true release false
|
||||
StatConfig.setDebugEnable(debug);
|
||||
|
||||
//MTA
|
||||
if (!debug) {
|
||||
try {
|
||||
/**
|
||||
*
|
||||
* 不要启用!!!!全部由{@link com.gh.base.AppUncaughtHandler}处理
|
||||
*/
|
||||
StatConfig.setAutoExceptionCaught(false);
|
||||
|
||||
//TODO 加入账号之后设置用户
|
||||
// StatConfig.setCustomUserId(context, "userid");
|
||||
StatCrashReporter crashReporter = StatCrashReporter.getStatCrashReporter(context);
|
||||
crashReporter.setJavaCrashHandlerStatus(false);
|
||||
// crashReporter.setEnableInstantReporting(true);
|
||||
|
||||
// 收集未处理的异常
|
||||
StatConfig.setAutoExceptionCaught(true);
|
||||
|
||||
StatConfig.setAntoActivityLifecycleStat(true);
|
||||
StatConfig.setDebugEnable(debug);
|
||||
|
||||
// 设置数据上报策略
|
||||
StatConfig.setStatSendStrategy(StatReportStrategy.PERIOD);
|
||||
StatConfig.setSendPeriodMinutes(5);
|
||||
if (debug) {
|
||||
StatConfig.setStatSendStrategy(StatReportStrategy.INSTANT);
|
||||
} else {
|
||||
StatConfig.setStatSendStrategy(StatReportStrategy.PERIOD);
|
||||
StatConfig.setSendPeriodMinutes(5);
|
||||
}
|
||||
|
||||
// 设置启用Tlink
|
||||
StatConfig.setTLinkStatus(true);
|
||||
|
||||
// 设置启用可视化埋点
|
||||
StatisticsDataAPI.instance(context);
|
||||
|
||||
StatConfig.init(context);
|
||||
StatConfig.setInstallChannel(channel);
|
||||
StatConfig.setAntoActivityLifecycleStat(true);
|
||||
StatConfig.setAppVersion(PackageUtils.getPatchVersionName());
|
||||
|
||||
StatService.setContext(context);
|
||||
StatService.registerActivityLifecycleCallbacks(context);
|
||||
// 开启收集服务
|
||||
StatService.startStatService(context, Config.MTA_APPKEY, com.tencent.stat.common.StatConstants.VERSION);
|
||||
} catch (MtaSDkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
StatCrashReporter crashReporter = StatCrashReporter.getStatCrashReporter(context);
|
||||
// 开启异常时的实时上报
|
||||
crashReporter.setEnableInstantReporting(true);
|
||||
// 开启java异常捕获
|
||||
crashReporter.setJavaCrashHandlerStatus(true);
|
||||
// init bugly
|
||||
try {
|
||||
CrashReport.setIsDevelopmentDevice(context, debug);
|
||||
|
||||
try {
|
||||
// 开启收集服务
|
||||
StatService.startStatService(context, Config.MTA_APPKEY, com.tencent.stat.common.StatConstants.VERSION);
|
||||
} catch (MtaSDkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(context);
|
||||
strategy.setEnableANRCrashMonitor(false);
|
||||
strategy.setEnableNativeCrashMonitor(false);
|
||||
strategy.setAppChannel(channel);
|
||||
strategy.setAppVersion(PackageUtils.getPatchVersionName());
|
||||
|
||||
CrashReport.initCrashReport(context, Config.BUGLY_APPID, debug, strategy);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
@ -85,12 +114,12 @@ public class DataUtils {
|
||||
}
|
||||
|
||||
public static void onPause(Activity var0) {
|
||||
TCAgent.onPause(var0);
|
||||
TCAgent.onPageEnd(var0, var0.getClass().getSimpleName());
|
||||
StatService.onPause(var0);
|
||||
}
|
||||
|
||||
public static void onResume(Activity var0) {
|
||||
TCAgent.onResume(var0);
|
||||
TCAgent.onPageStart(var0, var0.getClass().getSimpleName());
|
||||
StatService.onResume(var0);
|
||||
}
|
||||
|
||||
|
||||
@ -50,14 +50,14 @@ public class DetailDownloadUtils {
|
||||
viewHolder.downloadPb.setVisibility(View.GONE);
|
||||
viewHolder.downloadPer.setVisibility(View.GONE);
|
||||
boolean isInstalled = false;
|
||||
if (viewHolder.gameEntity.getApk() != null && viewHolder.gameEntity.getApk().size() == 1
|
||||
if (viewHolder.gameEntity.getApk().size() == 1
|
||||
&& PackageManager.isInstalled(viewHolder.gameEntity.getApk().get(0).getPackageName())) {
|
||||
isInstalled = true;
|
||||
}
|
||||
if (isInstalled) {
|
||||
if (PackageManager.isCanUpdate(viewHolder.gameEntity.getId(), viewHolder.gameEntity.getApk().get(0).getPackageName())) {
|
||||
if (viewHolder.isNewsDetail) {
|
||||
viewHolder.downloadTv.setText("更新");
|
||||
viewHolder.downloadTv.setText(R.string.update);
|
||||
} else if (TextUtils.isEmpty(viewHolder.downloadAddWord)) {
|
||||
viewHolder.downloadTv.setText(String.format("更新《%s》",
|
||||
viewHolder.gameEntity.getName()));
|
||||
@ -72,7 +72,7 @@ public class DetailDownloadUtils {
|
||||
&& !TextUtils.isEmpty(viewHolder.gameEntity.getApk().get(0).getGhVersion())
|
||||
&& !PackageUtils.isSignature(viewHolder.context, viewHolder.gameEntity.getApk().get(0).getPackageName())) {
|
||||
if (viewHolder.isNewsDetail) {
|
||||
viewHolder.downloadTv.setText("插件化");
|
||||
viewHolder.downloadTv.setText(R.string.pluggable);
|
||||
} else if (TextUtils.isEmpty(viewHolder.downloadAddWord)) {
|
||||
viewHolder.downloadTv.setText(String.format("插件化《%s》",
|
||||
viewHolder.gameEntity.getName()));
|
||||
@ -84,7 +84,7 @@ public class DetailDownloadUtils {
|
||||
R.drawable.game_item_btn_plugin_style);
|
||||
} else {
|
||||
if (viewHolder.isNewsDetail) {
|
||||
viewHolder.downloadTv.setText("启动");
|
||||
viewHolder.downloadTv.setText(R.string.launch);
|
||||
} else if (TextUtils.isEmpty(viewHolder.downloadAddWord)) {
|
||||
viewHolder.downloadTv.setText(String.format("启动《%s》",
|
||||
viewHolder.gameEntity.getName()));
|
||||
@ -122,7 +122,6 @@ public class DetailDownloadUtils {
|
||||
}
|
||||
}
|
||||
if (isCheck && viewHolder.gameEntity != null
|
||||
&& viewHolder.gameEntity.getApk() != null
|
||||
&& viewHolder.gameEntity.getApk().size() == 1) {
|
||||
String url = viewHolder.gameEntity.getApk().get(0).getUrl();
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(viewHolder.context).getDownloadEntityByUrl(url);
|
||||
@ -146,7 +145,7 @@ public class DetailDownloadUtils {
|
||||
case timeout:
|
||||
case neterror:
|
||||
case waiting:
|
||||
viewHolder.downloadPer.setText("下载中");
|
||||
viewHolder.downloadPer.setText(R.string.downloading);
|
||||
break;
|
||||
case done:
|
||||
viewHolder.downloadPer.setText("安装");
|
||||
@ -189,7 +188,11 @@ public class DetailDownloadUtils {
|
||||
if (v == mViewHolder.downloadTv) {
|
||||
if (mGameEntity != null && !mGameEntity.getApk().isEmpty()) {
|
||||
if (mGameEntity.getApk().size() == 1) {
|
||||
if (NetworkUtils.isWifiConnected(mViewHolder.context)) {
|
||||
String str = mViewHolder.downloadTv.getText().toString();
|
||||
if (str.contains("启动")) {
|
||||
DataUtils.onGameLaunchEvent(mViewHolder.context, mGameEntity.getName(), mGameEntity.getApk().get(0).getPlatform(), mName);
|
||||
PackageUtils.launchApplicationByPackageName(mViewHolder.context, mGameEntity.getApk().get(0).getPackageName());
|
||||
} else if (NetworkUtils.isWifiConnected(mViewHolder.context)) {
|
||||
download();
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(mViewHolder.context, new DialogUtils.ConfirmListener() {
|
||||
@ -201,7 +204,7 @@ public class DetailDownloadUtils {
|
||||
}
|
||||
} else {
|
||||
DownloadDialog.getInstance(mViewHolder.context)
|
||||
.showPopupWindow(v, mGameEntity, mEntrance, mName + ":" + mTitle);
|
||||
.showPopupWindow(v, mGameEntity, StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"), mName + ":" + mTitle);
|
||||
}
|
||||
} else {
|
||||
Utils.toast(mViewHolder.context, "稍等片刻~!游戏正在上传中...");
|
||||
@ -210,46 +213,46 @@ public class DetailDownloadUtils {
|
||||
String str = mViewHolder.downloadPer.getText().toString();
|
||||
if ("下载中".equals(str)) {
|
||||
Intent intent = DownloadManagerActivity.getDownloadMangerIntent(mViewHolder.context,
|
||||
mGameEntity.getApk().get(0).getUrl(), mEntrance + "("+ mName +"[" + mTitle + "])");
|
||||
mGameEntity.getApk().get(0).getUrl(), StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"));
|
||||
mViewHolder.context.startActivity(intent);
|
||||
} else if ("安装".equals(str)) {
|
||||
PackageUtils.launchSetup(mViewHolder.context, mDownloadEntity.getPath());
|
||||
if (mDownloadEntity == null) {
|
||||
mDownloadEntity = DownloadManager.getInstance(mViewHolder.context).getDownloadEntityByUrl(mGameEntity.getApk().get(0).getUrl());
|
||||
}
|
||||
|
||||
if (mDownloadEntity != null) {
|
||||
PackageUtils.launchSetup(mViewHolder.context, mDownloadEntity.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void download() {
|
||||
String str = mViewHolder.downloadTv.getText().toString();
|
||||
if (str.contains("启动")) {
|
||||
DataUtils.onGameLaunchEvent(mViewHolder.context, mGameEntity.getName(), mGameEntity.getApk().get(0).getPlatform(), mName);
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(mViewHolder.context, mGameEntity.getApk().get(0).getPackageName());
|
||||
String method;
|
||||
if (str.contains("更新")) {
|
||||
method = "更新";
|
||||
} else if (str.contains("插件化")) {
|
||||
method = "插件化";
|
||||
} else {
|
||||
String method;
|
||||
if (str.contains("更新")) {
|
||||
method = "更新";
|
||||
} else if (str.contains("插件化")) {
|
||||
method = "插件化";
|
||||
} else {
|
||||
method = "下载";
|
||||
}
|
||||
ApkEntity apkEntity = mGameEntity.getApk().get(0);
|
||||
String msg = FileUtils.isCanDownload(mViewHolder.context, apkEntity.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
DataUtils.onGameDownloadEvent(mViewHolder.context, mGameEntity.getName(), apkEntity.getPlatform(), mEntrance, "下载开始");
|
||||
method = mViewHolder.context.getString(R.string.download);
|
||||
}
|
||||
ApkEntity apkEntity = mGameEntity.getApk().get(0);
|
||||
String msg = FileUtils.isCanDownload(mViewHolder.context, apkEntity.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
DataUtils.onGameDownloadEvent(mViewHolder.context, mGameEntity.getName(), apkEntity.getPlatform(), StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"), "下载开始");
|
||||
|
||||
DownloadManager.createDownload(mViewHolder.context, apkEntity, mGameEntity, method, mEntrance, mName + ":" + mTitle);
|
||||
DownloadManager.createDownload(mViewHolder.context, apkEntity, mGameEntity, method, StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"), mName + ":" + mTitle);
|
||||
|
||||
mViewHolder.downloadTv.setVisibility(View.GONE);
|
||||
mViewHolder.downloadPb.setVisibility(View.VISIBLE);
|
||||
mViewHolder.downloadPer.setVisibility(View.VISIBLE);
|
||||
mViewHolder.downloadPb.setProgress(0);
|
||||
mViewHolder.downloadPer.setText("0.0%");
|
||||
mViewHolder.downloadTv.setVisibility(View.GONE);
|
||||
mViewHolder.downloadPb.setVisibility(View.VISIBLE);
|
||||
mViewHolder.downloadPer.setVisibility(View.VISIBLE);
|
||||
mViewHolder.downloadPb.setProgress(0);
|
||||
mViewHolder.downloadPer.setText("0.0%");
|
||||
|
||||
// DownloadManager.getInstance(mViewHolder.context).putStatus(apkEntity.getUrl(), "downloading");
|
||||
} else {
|
||||
Utils.toast(mViewHolder.context, msg);
|
||||
}
|
||||
} else {
|
||||
Utils.toast(mViewHolder.context, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
197
app/src/main/java/com/gh/common/util/DeviceUtils.java
Normal file
197
app/src/main/java/com/gh/common/util/DeviceUtils.java
Normal file
@ -0,0 +1,197 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||||
import com.lightgame.utils.Util_System_Phone_State;
|
||||
import com.tencent.stat.StatConfig;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Reader;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import static android.os.Build.MANUFACTURER;
|
||||
import static android.os.Build.MODEL;
|
||||
|
||||
/**
|
||||
* Created by khy on 2/08/17.
|
||||
*/
|
||||
|
||||
public class DeviceUtils {
|
||||
|
||||
public static JSONObject getLoginDevice(Context context) throws JSONException { // device数据
|
||||
context = context.getApplicationContext();
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("os", "Android");
|
||||
object.put("imei", Util_System_Phone_State.getDeviceId(context));
|
||||
object.put("mac", getMac(context));
|
||||
object.put("model", MODEL);
|
||||
object.put("manufacturer", MANUFACTURER);
|
||||
object.put("android_id", Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID));
|
||||
object.put("android_sdk", Build.VERSION.SDK_INT);
|
||||
object.put("android_version", android.os.Build.VERSION.RELEASE);
|
||||
object.put("ip", getIPAddress(context));
|
||||
object.put("network", getNetwork(context));
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
public static JSONObject getUserDevice(Context context) { // 判断新老用户device数据
|
||||
JSONObject object = new JSONObject();
|
||||
try {
|
||||
object.put("IMEI", Util_System_Phone_State.getDeviceId(context));
|
||||
object.put("ANDROID_ID", Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID));
|
||||
object.put("MAC", getMac(context));
|
||||
object.put("MTA_ID", StatConfig.getMid(context));
|
||||
object.put("MANUFACTURER", MANUFACTURER);
|
||||
object.put("MODEL", MODEL);
|
||||
object.put("ANDROID_SDK", Build.VERSION.SDK_INT);
|
||||
object.put("ANDROID_VERSION", android.os.Build.VERSION.RELEASE);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
private static String getMac(Context context) {
|
||||
String str = "";
|
||||
String macSerial = "";
|
||||
try {
|
||||
Process pp = Runtime.getRuntime().exec(
|
||||
"cat /sys/class/net/wlan0/address ");
|
||||
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
|
||||
LineNumberReader input = new LineNumberReader(ir);
|
||||
|
||||
for (; null != str;) {
|
||||
str = input.readLine();
|
||||
if (str != null) {
|
||||
macSerial = str.trim();// 去空格
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
if ("".equals(macSerial)) {
|
||||
try {
|
||||
return loadFileAsString("/sys/class/net/eth0/address")
|
||||
.toUpperCase().substring(0, 17);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (TextUtils.isEmpty(macSerial)) { // 备用方案
|
||||
macSerial = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)).getConnectionInfo().getMacAddress();
|
||||
}
|
||||
return macSerial;
|
||||
}
|
||||
|
||||
private static String loadFileAsString(String fileName) throws Exception {
|
||||
FileReader reader = new FileReader(fileName);
|
||||
String text = loadReaderAsString(reader);
|
||||
reader.close();
|
||||
return text;
|
||||
}
|
||||
|
||||
private static String loadReaderAsString(Reader reader) throws Exception {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
char[] buffer = new char[4096];
|
||||
int readLength = reader.read(buffer);
|
||||
while (readLength >= 0) {
|
||||
builder.append(buffer, 0, readLength);
|
||||
readLength = reader.read(buffer);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
private static String getIPAddress(Context context) {
|
||||
NetworkInfo info = ((ConnectivityManager) context
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
|
||||
if (info != null && info.isConnected()) {
|
||||
if (info.getType() == ConnectivityManager.TYPE_MOBILE) {//当前使用2G/3G/4G网络
|
||||
try {
|
||||
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
|
||||
NetworkInterface intf = en.nextElement();
|
||||
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
|
||||
InetAddress inetAddress = enumIpAddr.nextElement();
|
||||
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
|
||||
return inetAddress.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} else if (info.getType() == ConnectivityManager.TYPE_WIFI) {//当前使用无线网络
|
||||
return WifiMgr.getInstance(context).getCurrentIpAddress();
|
||||
}
|
||||
} else {
|
||||
//当前无网络连接,请在设置中打开网络
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getNetwork(Context context) {
|
||||
NetworkInfo info = ((ConnectivityManager) context
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
|
||||
if (info != null && info.isConnected()) {
|
||||
int typeMobile = info.getType();
|
||||
if (typeMobile == ConnectivityManager.TYPE_WIFI) {
|
||||
return "WIFI";
|
||||
} else if (typeMobile == ConnectivityManager.TYPE_MOBILE) {
|
||||
String status;
|
||||
switch (typeMobile) {
|
||||
case TelephonyManager.NETWORK_TYPE_GPRS:
|
||||
case TelephonyManager.NETWORK_TYPE_EDGE:
|
||||
case TelephonyManager.NETWORK_TYPE_CDMA:
|
||||
case TelephonyManager.NETWORK_TYPE_1xRTT:
|
||||
case TelephonyManager.NETWORK_TYPE_IDEN:
|
||||
status = "2G";
|
||||
break;
|
||||
case TelephonyManager.NETWORK_TYPE_UMTS:
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_0:
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_A:
|
||||
case TelephonyManager.NETWORK_TYPE_HSDPA:
|
||||
case TelephonyManager.NETWORK_TYPE_HSUPA:
|
||||
case TelephonyManager.NETWORK_TYPE_HSPA:
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_B:
|
||||
case TelephonyManager.NETWORK_TYPE_EHRPD:
|
||||
case TelephonyManager.NETWORK_TYPE_HSPAP:
|
||||
status = "3G";
|
||||
break;
|
||||
case TelephonyManager.NETWORK_TYPE_LTE:
|
||||
status = "4G";
|
||||
break;
|
||||
default:
|
||||
status = "未知";
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -15,6 +15,7 @@ import android.text.Spanned;
|
||||
import android.text.TextPaint;
|
||||
import android.view.Display;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
@ -23,9 +24,9 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||||
import com.halo.assistant.HaloApp;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
@ -54,9 +55,9 @@ public class DialogUtils {
|
||||
// 快传成绩单
|
||||
public static void showKuaiChuanResult(final Activity activity, Handler handler, int requestCode, final String picName) {
|
||||
|
||||
AppController.remove("FileInfo");
|
||||
HaloApp.remove("FileInfo");
|
||||
|
||||
List<Map<String, String>> mapList = (List<Map<String, String>>) AppController.get("sendData", true);
|
||||
List<Map<String, String>> mapList = (List<Map<String, String>>) HaloApp.get("sendData", true);
|
||||
if (mapList == null || mapList.size() == 0) return;
|
||||
|
||||
WifiMgr.getInstance(activity).disconnectCurrentNetwork(); // 断开当前WiFi
|
||||
@ -153,8 +154,8 @@ public class DialogUtils {
|
||||
sizeName = df.format(size) + "MB";
|
||||
}
|
||||
|
||||
if (sendTime == 0) {
|
||||
sendTime = 1;
|
||||
if (sendTime < 1000) { // 最少设置发送时间为1s(为了简易计算)
|
||||
sendTime = 1000;
|
||||
}
|
||||
|
||||
int i = (filesSize / 1024) / (sendTime / 1000);
|
||||
@ -331,61 +332,6 @@ public class DialogUtils {
|
||||
final ConfirmListener cmListener, final CancelListener clListener) {
|
||||
|
||||
showAlertDialog(context, title, msg, confirm, cancel, cmListener, clListener);
|
||||
if (true) return; // TODO TEST
|
||||
|
||||
if (isShow) {
|
||||
return;
|
||||
}
|
||||
isShow = true;
|
||||
|
||||
final Dialog dialog = new Dialog(context);
|
||||
|
||||
View view = View.inflate(context, R.layout.common_alertdialog, null);
|
||||
|
||||
// 标题
|
||||
TextView alertdialog_title = (TextView) view.findViewById(R.id.alertdialog_title);
|
||||
alertdialog_title.setText(title);
|
||||
|
||||
// 内容
|
||||
TextView alertdialog_content = (TextView) view.findViewById(R.id.alertdialog_content);
|
||||
alertdialog_content.setText(msg);
|
||||
|
||||
// 取消按钮
|
||||
TextView alertdialog_cannel = (TextView) view.findViewById(R.id.alertdialog_cannel);
|
||||
alertdialog_cannel.setText(cancel);
|
||||
alertdialog_cannel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
if (clListener != null) {
|
||||
clListener.onCancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 确定按钮
|
||||
TextView alertdialog_confirm = (TextView) view.findViewById(R.id.alertdialog_confirm);
|
||||
alertdialog_confirm.setText(confirm);
|
||||
alertdialog_confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
if (cmListener != null) {
|
||||
cmListener.onConfirm();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dialog.setOnDismissListener(new Dialog.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
isShow = false;
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
// 网络劫持时 打开QQ客户端,创建临时会话
|
||||
@ -400,19 +346,17 @@ public class DialogUtils {
|
||||
}, null);
|
||||
}
|
||||
|
||||
public static void showDownloadDialog(Context context, ConfirmListener listener, CancelListener cancelListener){
|
||||
showWarningDialog(context, "下载提示", "您当前使用的网络为2G/3G/4G,开始下载将会消耗移动流量,确定下载?", "取消", "确定", listener, cancelListener);
|
||||
public static void showDownloadDialog(Context context, ConfirmListener listener, CancelListener cancelListener) {
|
||||
showWarningDialog(context, "下载提示", "您当前使用的网络为2G/3G/4G,开始下载将会消耗移动流量,确定下载?", "取消", "确定", listener, cancelListener);
|
||||
}
|
||||
|
||||
public static void showDownloadDialog(Context context, ConfirmListener listener) {
|
||||
showWarningDialog(context, "下载提示", "您当前使用的网络为2G/3G/4G,开始下载将会消耗移动流量,确定下载?", listener);
|
||||
}
|
||||
|
||||
public static void showCancelDialog(Context context, final ConfirmListener listener) {
|
||||
Spanned content = Html.fromHtml("取消关注游戏后,您将无法及时收到游戏" +
|
||||
"<font color=\"#ff0000\">攻略</font>、" +
|
||||
"<font color=\"#ff0000\">资讯</font>等最新动态提醒。");
|
||||
showWarningDialog(context, "取消关注", content, "暂不取消", "确定取消", listener, null);
|
||||
public static void showCancelDialog(Context context, final ConfirmListener listener, CancelListener cancelListener) {
|
||||
Spanned content = Html.fromHtml(context.getString(R.string.cancel_concern_dialog));
|
||||
showCancelListenerDialog(context, "取消关注", content, "确定取消", "暂不取消", listener, cancelListener);
|
||||
}
|
||||
|
||||
public static void showPluginDialog(Context context, final ConfirmListener listener) {
|
||||
@ -461,41 +405,352 @@ public class DialogUtils {
|
||||
public static void showAlertDialog(Context context, String title, CharSequence message
|
||||
, String positive, String negative, final ConfirmListener cmListener, final CancelListener clListener) {
|
||||
|
||||
AlertDialog alertDialog = new AlertDialog.Builder(context, R.style.GhAlertDialog)
|
||||
.setTitle(title)
|
||||
.setMessage(message)
|
||||
.setPositiveButton(positive, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (cmListener != null) {
|
||||
cmListener.onConfirm();
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton(negative, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (clListener != null) {
|
||||
clListener.onCancel();
|
||||
}
|
||||
}
|
||||
})
|
||||
.create();
|
||||
alertDialog.show();
|
||||
// AlertDialog alertDialog = new AlertDialog.Builder(context, R.style.GhAlertDialog)
|
||||
// .setTitle(title)
|
||||
// .setMessage(message)
|
||||
// .setPositiveButton(positive, new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// if (cmListener != null) {
|
||||
// cmListener.onConfirm();
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// .setNegativeButton(negative, new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// if (clListener != null) {
|
||||
// clListener.onCancel();
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// .create();
|
||||
// alertDialog.show();
|
||||
//
|
||||
// TextView mesage = (TextView) alertDialog.findViewById(android.R.id.message);
|
||||
// Button positiveBtn = alertDialog.getButton(android.app.AlertDialog.BUTTON_POSITIVE);
|
||||
// Button negativeBtn = alertDialog.getButton(android.app.AlertDialog.BUTTON_NEGATIVE);
|
||||
//
|
||||
// positiveBtn.setTextSize(14);
|
||||
// positiveBtn.setTextColor(ContextCompat.getColor(context, R.color.theme));
|
||||
// negativeBtn.setTextSize(14);
|
||||
// negativeBtn.setTextColor(ContextCompat.getColor(context, R.color.theme));
|
||||
// if (mesage != null) {
|
||||
// mesage.setTextSize(14);
|
||||
// mesage.setTextColor(ContextCompat.getColor(context, R.color.system_bar));
|
||||
// mesage.setLineSpacing(1.0f, 1.3f);
|
||||
// }
|
||||
|
||||
TextView mesage = (TextView) alertDialog.findViewById(android.R.id.message);
|
||||
Button positiveBtn = alertDialog.getButton(android.app.AlertDialog.BUTTON_POSITIVE);
|
||||
Button negativeBtn = alertDialog.getButton(android.app.AlertDialog.BUTTON_NEGATIVE);
|
||||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||||
|
||||
positiveBtn.setTextSize(13);
|
||||
positiveBtn.setTextColor(ContextCompat.getColor(context, R.color.theme));
|
||||
negativeBtn.setTextSize(13);
|
||||
negativeBtn.setTextColor(ContextCompat.getColor(context, R.color.theme));
|
||||
if (mesage != null) {
|
||||
mesage.setTextSize(13);
|
||||
mesage.setTextColor(ContextCompat.getColor(context, R.color.title));
|
||||
}
|
||||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_alert, null);
|
||||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||||
|
||||
contentTv.setText(message);
|
||||
titleTv.setText(title);
|
||||
negativeTv.setText(negative);
|
||||
positiveTv.setText(positive);
|
||||
|
||||
negativeTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (clListener != null) {
|
||||
clListener.onCancel();
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
positiveTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (cmListener != null) {
|
||||
cmListener.onConfirm();
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(contentView);
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消按钮灰色
|
||||
*
|
||||
* @param context
|
||||
* @param title
|
||||
* @param message
|
||||
* @param positive
|
||||
* @param negative
|
||||
* @param cmListener
|
||||
*/
|
||||
|
||||
// TODO: 8/10/17 将下面几个弹窗整理在一起
|
||||
public static void showAlertDialog(Context context, String title, CharSequence message
|
||||
, String positive, String negative, final ConfirmListener cmListener) {
|
||||
|
||||
// AlertDialog alertDialog = new AlertDialog.Builder(context, R.style.GhAlertDialog)
|
||||
// .setTitle(title)
|
||||
// .setMessage(message)
|
||||
// .setPositiveButton(positive, new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// if (cmListener != null) {
|
||||
// cmListener.onConfirm();
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// .setNegativeButton(negative, null)
|
||||
// .create();
|
||||
// alertDialog.show();
|
||||
//
|
||||
// TextView mesage = (TextView) alertDialog.findViewById(android.R.id.message);
|
||||
// Button positiveBtn = alertDialog.getButton(android.app.AlertDialog.BUTTON_POSITIVE);
|
||||
// Button negativeBtn = alertDialog.getButton(android.app.AlertDialog.BUTTON_NEGATIVE);
|
||||
//
|
||||
// positiveBtn.setTextSize(14);
|
||||
// positiveBtn.setTextColor(ContextCompat.getColor(context, R.color.theme));
|
||||
// negativeBtn.setTextSize(14);
|
||||
// negativeBtn.setTextColor(ContextCompat.getColor(context, R.color.hint));
|
||||
// if (mesage != null) {
|
||||
// mesage.setTextSize(14);
|
||||
// mesage.setTextColor(ContextCompat.getColor(context, R.color.system_bar));
|
||||
// mesage.setLineSpacing(1.0f, 1.3f);
|
||||
// }
|
||||
|
||||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||||
|
||||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_alert, null);
|
||||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||||
|
||||
contentTv.setText(message);
|
||||
titleTv.setText(title);
|
||||
negativeTv.setText(negative);
|
||||
negativeTv.setTextColor(ContextCompat.getColor(context, R.color.hint));
|
||||
positiveTv.setText(positive);
|
||||
|
||||
negativeTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
positiveTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (cmListener != null) {
|
||||
cmListener.onConfirm();
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(contentView);
|
||||
dialog.show();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击外部退出和取消监听绑定
|
||||
*/
|
||||
public static void showCancelListenerDialog(Context context, String title, CharSequence message
|
||||
, String positive, String negative, final ConfirmListener cmListener, final CancelListener clListener) {
|
||||
|
||||
// AlertDialog alertDialog = new AlertDialog.Builder(context, R.style.GhAlertDialog)
|
||||
// .setTitle(title)
|
||||
// .setMessage(message)
|
||||
// .setPositiveButton(positive, new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// if (cmListener != null) {
|
||||
// cmListener.onConfirm();
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// .setNegativeButton(negative, new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// if (clListener != null) {
|
||||
// clListener.onCancel();
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// .setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
// @Override
|
||||
// public void onCancel(DialogInterface dialogInterface) {
|
||||
// clListener.onCancel();
|
||||
// }
|
||||
// })
|
||||
// .create();
|
||||
//
|
||||
// alertDialog.show();
|
||||
//
|
||||
// TextView mesage = (TextView) alertDialog.findViewById(android.R.id.message);
|
||||
// Button positiveBtn = alertDialog.getButton(android.app.AlertDialog.BUTTON_POSITIVE);
|
||||
// Button negativeBtn = alertDialog.getButton(android.app.AlertDialog.BUTTON_NEGATIVE);
|
||||
//
|
||||
// positiveBtn.setTextSize(14);
|
||||
// positiveBtn.setTextColor(ContextCompat.getColor(context, R.color.theme));
|
||||
// negativeBtn.setTextSize(14);
|
||||
// negativeBtn.setTextColor(ContextCompat.getColor(context, R.color.hint));
|
||||
// if (mesage != null) {
|
||||
// mesage.setTextSize(14);
|
||||
// mesage.setTextColor(ContextCompat.getColor(context, R.color.system_bar));
|
||||
// mesage.setLineSpacing(1.0f, 1.3f);
|
||||
// }
|
||||
|
||||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||||
|
||||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_alert, null);
|
||||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||||
|
||||
contentTv.setText(message);
|
||||
titleTv.setText(title);
|
||||
negativeTv.setText(negative);
|
||||
negativeTv.setTextColor(ContextCompat.getColor(context, R.color.hint));
|
||||
positiveTv.setText(positive);
|
||||
|
||||
negativeTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (clListener != null) {
|
||||
clListener.onCancel();
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
positiveTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (cmListener != null) {
|
||||
cmListener.onConfirm();
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(contentView);
|
||||
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialogInterface) {
|
||||
if (clListener != null)
|
||||
clListener.onCancel();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 权限弹窗
|
||||
* 只能在弹窗内取消
|
||||
*/
|
||||
public static void showPermissionDialog(Context context, String title, CharSequence message
|
||||
, String positive, String negative, final ConfirmListener cmListener, final CancelListener clListener) {
|
||||
|
||||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||||
|
||||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_alert, null);
|
||||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||||
|
||||
contentTv.setText(message);
|
||||
titleTv.setText(title);
|
||||
negativeTv.setText(negative);
|
||||
negativeTv.setTextColor(ContextCompat.getColor(context, R.color.hint));
|
||||
positiveTv.setText(positive);
|
||||
|
||||
negativeTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (clListener != null) {
|
||||
clListener.onCancel();
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
positiveTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (cmListener != null) {
|
||||
cmListener.onConfirm();
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(contentView);
|
||||
dialog.setCancelable(false);
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 只能在弹窗内取消
|
||||
*/
|
||||
public static void showForceDialog(Context context, String title, CharSequence message
|
||||
, String positive, String negative, final ConfirmListener cmListener, final CancelListener clListener) {
|
||||
|
||||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||||
|
||||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_alert, null);
|
||||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||||
|
||||
contentTv.setText(message);
|
||||
titleTv.setText(title);
|
||||
negativeTv.setText(negative);
|
||||
positiveTv.setText(positive);
|
||||
|
||||
negativeTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (clListener != null) {
|
||||
clListener.onCancel();
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
positiveTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (cmListener != null) {
|
||||
cmListener.onConfirm();
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(contentView);
|
||||
dialog.setCancelable(false);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -9,7 +9,6 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
@ -24,6 +23,7 @@ import com.lightgame.download.DownloadConfig;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
import com.lightgame.download.DownloadStatus;
|
||||
import com.lightgame.download.FileUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
@ -147,25 +147,25 @@ public class DownloadItemUtils {
|
||||
final String packageName = apkEntity.getPackageName();
|
||||
|
||||
if (gameEntity.isPluggable()) {
|
||||
holder.gameDownloadBtn.setText("插件化");
|
||||
holder.gameDownloadBtn.setText(R.string.pluggable);
|
||||
setwhat(context, holder, apkEntity, packageName);
|
||||
} else if (PackageManager.isInstalled(packageName)) {
|
||||
if (PackageManager.isCanUpdate(gameEntity.getId(), packageName)) {
|
||||
holder.gameDownloadBtn.setText("更新");
|
||||
holder.gameDownloadBtn.setText(R.string.update);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
} else {
|
||||
if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& !TextUtils.isEmpty(apkEntity.getGhVersion())
|
||||
&& !PackageUtils.isSignature(context, packageName)) {
|
||||
holder.gameDownloadBtn.setText("插件化");
|
||||
holder.gameDownloadBtn.setText(R.string.pluggable);
|
||||
setwhat(context, holder, apkEntity, packageName);
|
||||
} else {
|
||||
holder.gameDownloadBtn.setText("启动");
|
||||
holder.gameDownloadBtn.setText(R.string.launch);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
holder.gameDownloadBtn.setText("下载");
|
||||
holder.gameDownloadBtn.setText(R.string.download);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
}
|
||||
}
|
||||
@ -244,7 +244,7 @@ public class DownloadItemUtils {
|
||||
}
|
||||
|
||||
if (isNormal) {
|
||||
holder.gameDownloadBtn.setText("下载中");
|
||||
holder.gameDownloadBtn.setText(R.string.downloading);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
holder.gameDownloadBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.text_downloading_style));
|
||||
}
|
||||
@ -258,7 +258,7 @@ public class DownloadItemUtils {
|
||||
holder.gameDownloadPercentage.setText(downloadEntity.getPercent() + "%");
|
||||
|
||||
if (isNormal) {
|
||||
holder.gameDownloadBtn.setText("下载中");
|
||||
holder.gameDownloadBtn.setText(R.string.downloading);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
holder.gameDownloadBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.text_downloading_style));
|
||||
}
|
||||
@ -274,7 +274,7 @@ public class DownloadItemUtils {
|
||||
holder.gameDownloadPercentage.setText(downloadEntity.getPercent() + "%");
|
||||
|
||||
if (isNormal) {
|
||||
holder.gameDownloadBtn.setText("下载中");
|
||||
holder.gameDownloadBtn.setText(R.string.downloading);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
holder.gameDownloadBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.text_downloading_style));
|
||||
}
|
||||
@ -397,16 +397,16 @@ public class DownloadItemUtils {
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
DataUtils.onGameDownloadEvent(context, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), entrance, "下载开始");
|
||||
|
||||
DownloadManager.createDownload(context, gameEntity, "下载", entrance, location);
|
||||
Toast.makeText(context, gameEntity.getName() + "已加入下载队列", Toast.LENGTH_SHORT).show();
|
||||
DownloadManager.createDownload(context, gameEntity, context.getString(R.string.download), entrance, location);
|
||||
Utils.toast(context, gameEntity.getName() + "已加入下载队列");
|
||||
|
||||
downloadBtn.setText("下载中");
|
||||
downloadBtn.setText(R.string.downloading);
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
downloadBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.text_downloading_style));
|
||||
|
||||
// DownloadManager.getInstance(context).putStatus(gameEntity.getApk().get(0).getUrl(), "downloading");
|
||||
} else {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(context, msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -418,15 +418,15 @@ public class DownloadItemUtils {
|
||||
DataUtils.onGameDownloadEvent(context, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), entrance, "下载开始");
|
||||
|
||||
DownloadManager.createDownload(context, gameEntity, "插件化", entrance, location);
|
||||
Toast.makeText(context, gameEntity.getName() + "已加入下载队列", Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(context, gameEntity.getName() + "已加入下载队列");
|
||||
|
||||
downloadBtn.setText("下载中");
|
||||
downloadBtn.setText(R.string.downloading);
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
downloadBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.text_downloading_style));
|
||||
|
||||
// DownloadManager.getInstance(context).putStatus(gameEntity.getApk().get(0).getUrl(), "downloading");
|
||||
} else {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(context, msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -438,7 +438,7 @@ public class DownloadItemUtils {
|
||||
if (downloadEntity != null) {
|
||||
final String path = downloadEntity.getPath();
|
||||
if (FileUtils.isEmptyFile(path)) {
|
||||
Toast.makeText(context, "解析包出错(可能被误删了),请重新下载", Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(context, context.getString(R.string.install_failure_hint));
|
||||
DownloadManager.getInstance(context).cancel(downloadEntity.getUrl());
|
||||
if (gameEntity.getEntryMap() != null) {
|
||||
gameEntity.getEntryMap().remove(apkEntity.getPlatform());
|
||||
|
||||
@ -21,9 +21,10 @@ public class EntranceUtils {
|
||||
public static final String KEY_GAMEID = "gameId";
|
||||
public static final String KEY_ID = "id";
|
||||
public static final String KEY_URL = "url";
|
||||
public static final String KEY_GAMENAME = "gameName";
|
||||
public static final String HOST_ARTICLE = "article";
|
||||
public static final String HOST_GAME = "game";
|
||||
public static final String HOSt_COLUMN = "column";
|
||||
public static final String HOST_COLUMN = "column";
|
||||
public static final String HOST_WEB = "web";
|
||||
public static final String HOST_DOWNLOAD = "download";
|
||||
public static final String HOST_SUGGESTION = "suggestion";
|
||||
@ -43,7 +44,18 @@ public class EntranceUtils {
|
||||
public static final String KEY_VERSION = "version";
|
||||
public static final String KEY_CONTENT = "content";
|
||||
public static final String KEY_PLUGIN = "plugin";
|
||||
public static final String KEY_CURRENT_ITEM = "currentItem";
|
||||
public static final String KEY_CURRENTITEM = "currentItem";
|
||||
public static final String KEY_COMMENTID = "commentId";
|
||||
public static final String KEY_PATH = "path";
|
||||
public static final String KEY_OLDERUSER = "isOldUser";
|
||||
public static final String KEY_SEARCHKEY = "searchKey";
|
||||
public static final String KEY_HINT = "hint";
|
||||
public static final String KEY_GAME_ICON_URL = "gameIconUrl";
|
||||
public static final String KEY_SHARECONTENT = "shareContent";
|
||||
public static final String KEY_SUGGESTTYPE = "suggestType";
|
||||
public static final String KEY_PROLIST = "provinceList";
|
||||
public static final String KEY_ORDER = "order";
|
||||
public static final String KEY_TAGTYPE = "tagType";
|
||||
|
||||
public static void jumpActivity(Context context, Bundle bundle) {
|
||||
|
||||
|
||||
@ -65,7 +65,7 @@ public class GameViewUtils {
|
||||
tag.setTextColor(ContextCompat.getColor(context, R.color.tag_green));
|
||||
} else {
|
||||
String colorStr;
|
||||
if (!TextUtils.isEmpty(tagType) && tagType.equals("type")) { // 游戏标签
|
||||
if (!TextUtils.isEmpty(tagType) && "type".equals(tagType)) { // 游戏标签
|
||||
colorStr = "#ff6a28";
|
||||
} else {
|
||||
colorStr = TagUtils.getInstance(context).getColor(tagStr);
|
||||
@ -99,23 +99,21 @@ public class GameViewUtils {
|
||||
try {
|
||||
long today = format.parse(format.format(new Date())).getTime();
|
||||
long day = Long.parseLong(testTime + "000");
|
||||
Calendar calendar = Calendar.getInstance(TimeZone
|
||||
.getTimeZone("Asia/Shanghai"));
|
||||
calendar.setTimeInMillis(day);
|
||||
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm", Locale.CHINA);
|
||||
String time = timeFormat.format(day);
|
||||
|
||||
if (day >= today && day < today + 86400 * 1000) {
|
||||
testDate = "今天" + hour + "点";
|
||||
testDate = "今天 " + time;
|
||||
} else if (day >= today + 86400 * 1000
|
||||
&& day < today + 86400 * 1000 * 2) {
|
||||
testDate = "明天" + hour + "点";
|
||||
testDate = "明天 " + time;
|
||||
} else if (day >= today + 86400 * 1000 * 2
|
||||
&& day < today + 86400 * 1000 * 3) {
|
||||
testDate = "后天" + hour + "点";
|
||||
testDate = "后天 " + time;
|
||||
} else if (day >= today - 86400 * 1000 && day < today) {
|
||||
testDate = "昨天" + hour + "点";
|
||||
testDate = "昨天 " + time;
|
||||
} else {
|
||||
format = new SimpleDateFormat("MM-dd", Locale.CHINA);
|
||||
testDate = format.format(day) + " " + hour + "点";
|
||||
testDate = new SimpleDateFormat("MM-dd HH:mm", Locale.CHINA).format(day);
|
||||
}
|
||||
return testDate;
|
||||
} catch (ParseException e) {
|
||||
|
||||
@ -75,7 +75,6 @@ public class GetLoginDataUtils {
|
||||
public IUiListener QqLoginListener = new IUiListener() {
|
||||
@Override
|
||||
public void onComplete(Object o) {
|
||||
Toast.makeText(mContext, "登录成功", Toast.LENGTH_SHORT).show();
|
||||
Utils.log(GetLoginDataUtils.class.getSimpleName(), "QQ 登录成功");
|
||||
if (o instanceof JSONObject) {
|
||||
JSONObject jsonObject = (JSONObject) o;
|
||||
@ -90,7 +89,7 @@ public class GetLoginDataUtils {
|
||||
content.put("access_token_expire", Utils.getTime(mContext) + jsonObject.getLong("expires_in"));
|
||||
content.put("access_token", jsonObject.getString("access_token"));
|
||||
if (mLoginListener != null) {
|
||||
mLoginListener.OnLoginData(jsonObject, LoginUtils.LoginTag.qq);// QQ 登录回调
|
||||
mLoginListener.OnLoginData(content, LoginUtils.LoginTag.qq);// QQ 登录回调
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
@ -123,13 +122,13 @@ public class GetLoginDataUtils {
|
||||
|
||||
@Override
|
||||
public void onError(UiError uiError) {
|
||||
Toast.makeText(mContext, "登录失败", Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(mContext, "登录失败");
|
||||
Utils.log(GetLoginDataUtils.class.getSimpleName(), "QQ 登录失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
Toast.makeText(mContext, "登录取消", Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(mContext, "登录取消");
|
||||
Utils.log(GetLoginDataUtils.class.getSimpleName(), "QQ 登录取消");
|
||||
}
|
||||
};
|
||||
@ -147,6 +146,12 @@ public class GetLoginDataUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public void QQLogout() {
|
||||
if (mTencent != null && mTencent.isSessionValid()) {
|
||||
mTencent.logout(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 微信登录
|
||||
public void WCLogin(OnLoginDataListener listener) {
|
||||
@ -159,6 +164,9 @@ public class GetLoginDataUtils {
|
||||
req.state = "光环助手";
|
||||
boolean b = mIWXAPI.sendReq(req);
|
||||
Utils.log(GetLoginDataUtils.class.getSimpleName(), "微信注册状态::" + register + "\n 发送状态::" + b);
|
||||
if (!register || !b) {
|
||||
Utils.toast(mContext, "请检查是否安装微信客户端");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,9 +217,9 @@ public class GetLoginDataUtils {
|
||||
content.put("access_token", token.getToken());
|
||||
content.put("access_token_expire", Utils.getTime(mContext) + token.getExpiresTime());
|
||||
content.put("refresh_token", token.getRefreshToken());
|
||||
// content.put("refresh_token_expire", ""); // TODO refresh_token 好像没有有效期
|
||||
// content.put("refresh_token_expire", Utils.getTime(mContext) + 86400 * 30); // refresh_token 有效期30天
|
||||
if (mLoginListener != null) {
|
||||
mLoginListener.OnLoginData(content, LoginUtils.LoginTag.qq);// QQ 登录回调
|
||||
mLoginListener.OnLoginData(content, LoginUtils.LoginTag.weibo);// 微博 登录回调
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@ -227,12 +235,12 @@ public class GetLoginDataUtils {
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
Toast.makeText(mContext, "取消授权", Toast.LENGTH_LONG).show();
|
||||
Utils.toast(mContext, "取消授权");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(WbConnectErrorMessage errorMessage) {
|
||||
Toast.makeText(mContext, errorMessage.getErrorMessage(), Toast.LENGTH_LONG).show();
|
||||
Utils.toast(mContext, "微博登录需要客户端支持,请先安装微博");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
35
app/src/main/java/com/gh/common/util/GsonUtils.kt
Normal file
35
app/src/main/java/com/gh/common/util/GsonUtils.kt
Normal file
@ -0,0 +1,35 @@
|
||||
package com.gh.common.util
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
|
||||
|
||||
/**
|
||||
* Created by khy on 11/10/17.
|
||||
*/
|
||||
class GsonUtils private constructor() {
|
||||
val mGson: Gson = Gson()
|
||||
|
||||
companion object {
|
||||
fun getInstance(): GsonUtils {
|
||||
return Inner.anotherSingle
|
||||
}
|
||||
|
||||
private object Inner {
|
||||
val anotherSingle = GsonUtils()
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> fromJsonBean(json: String, t: Class<T>): T {
|
||||
return mGson.fromJson(json, t)
|
||||
}
|
||||
|
||||
fun <T> fromJsonList(json: String, t: Class<T>): T {
|
||||
val type = object : TypeToken<List<T>>() {}.type
|
||||
return mGson.fromJson(json, type)
|
||||
}
|
||||
|
||||
fun toJson(any: Any): String {
|
||||
return mGson.toJson(any)
|
||||
}
|
||||
}
|
||||
36
app/src/main/java/com/gh/common/util/HMACUtils.java
Normal file
36
app/src/main/java/com/gh/common/util/HMACUtils.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
public class HMACUtils {
|
||||
|
||||
public static String encrypt(String data, String key) {
|
||||
try {
|
||||
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), "HmacSHA256");
|
||||
Mac mac = Mac.getInstance("HmacSHA256");
|
||||
mac.init(signingKey);
|
||||
return byte2hex(mac.doFinal(data.getBytes()));
|
||||
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String byte2hex(byte[] ciphertext) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String stmp;
|
||||
for (int i = 0; ciphertext != null && i < ciphertext.length; i++) {
|
||||
stmp = Integer.toHexString(ciphertext[i] & 0XFF);
|
||||
if (stmp.length() == 1) {
|
||||
builder.append('0');
|
||||
}
|
||||
builder.append(stmp);
|
||||
}
|
||||
return builder.toString().toLowerCase();
|
||||
}
|
||||
|
||||
}
|
||||
@ -5,6 +5,7 @@ import android.content.res.Resources
|
||||
import android.graphics.drawable.Animatable
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.net.Uri
|
||||
import android.support.annotation.DrawableRes
|
||||
import android.support.v4.content.ContextCompat
|
||||
import com.facebook.common.executors.CallerThreadExecutor
|
||||
import com.facebook.drawee.backends.pipeline.Fresco
|
||||
@ -19,10 +20,10 @@ import com.facebook.imagepipeline.request.ImageRequest
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder
|
||||
import com.gh.gamecenter.R
|
||||
|
||||
class ImageUtils {
|
||||
class ImageUtils private constructor() {
|
||||
|
||||
// 自适应图片宽高
|
||||
fun display(simpleDraweeView: SimpleDraweeView, url: String, width: Int) {
|
||||
fun display(simpleDraweeView: SimpleDraweeView, url: String?, width: Int) {
|
||||
val listener = object : BaseControllerListener<ImageInfo>() {
|
||||
override fun onFinalImageSet(id: String?, imageInfo: ImageInfo?, animatable: Animatable?) {
|
||||
if (imageInfo == null) {
|
||||
@ -42,7 +43,7 @@ class ImageUtils {
|
||||
|
||||
// 设置缩放类型,设置按压状态下的叠加图
|
||||
fun display(resources: Resources, simpleDraweeView: SimpleDraweeView,
|
||||
scaleType: ScalingUtils.ScaleType, url: String) {
|
||||
scaleType: ScalingUtils.ScaleType, url: String?) {
|
||||
val context = simpleDraweeView.context
|
||||
simpleDraweeView.hierarchy = GenericDraweeHierarchyBuilder(resources)
|
||||
.setFadeDuration(500)
|
||||
@ -56,7 +57,7 @@ class ImageUtils {
|
||||
}
|
||||
|
||||
// 设置占位符
|
||||
fun display(resources: Resources, simpleDraweeView: SimpleDraweeView, url: String, placeholderImage: Int) {
|
||||
fun display(resources: Resources, simpleDraweeView: SimpleDraweeView, url: String?, placeholderImage: Int) {
|
||||
val context = simpleDraweeView.context
|
||||
simpleDraweeView.hierarchy = GenericDraweeHierarchyBuilder(resources)
|
||||
.setFadeDuration(500)
|
||||
@ -69,7 +70,7 @@ class ImageUtils {
|
||||
}
|
||||
|
||||
// 图片下载监听和设置低高分辨率图片
|
||||
fun display(simpleDraweeView: SimpleDraweeView, url: String, lowUrl: String,
|
||||
fun display(simpleDraweeView: SimpleDraweeView, url: String?, lowUrl: String?,
|
||||
listener: ControllerListener<in ImageInfo>) {
|
||||
simpleDraweeView.controller = Fresco.newDraweeControllerBuilder()
|
||||
.setImageRequest(ImageRequest.fromUri(url))
|
||||
@ -79,7 +80,7 @@ class ImageUtils {
|
||||
}
|
||||
|
||||
// 获取bitmap
|
||||
fun display(context: Context, url: String, dataSubscriber: BaseBitmapDataSubscriber) {
|
||||
fun display(context: Context, url: String?, dataSubscriber: BaseBitmapDataSubscriber) {
|
||||
val imageRequest = ImageRequestBuilder
|
||||
.newBuilderWithSource(Uri.parse(url))
|
||||
.setProgressiveRenderingEnabled(true)
|
||||
@ -100,12 +101,16 @@ class ImageUtils {
|
||||
val anotherSingle = ImageUtils()
|
||||
}
|
||||
|
||||
fun display(simpleDraweeView: SimpleDraweeView, url: String) {
|
||||
fun display(simpleDraweeView: SimpleDraweeView, url: String?) {
|
||||
// if (url.startsWith("http://image.ghzs666.com") && url.endsWith(".jpg")) {
|
||||
// url = url + "?x-oss-process=image/format,webp";
|
||||
// }
|
||||
simpleDraweeView.setImageURI(url)
|
||||
}
|
||||
|
||||
fun display(draweeView: SimpleDraweeView, @DrawableRes res: Int?) {
|
||||
draweeView.setImageURI("res:///" + res)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ import java.util.Map;
|
||||
public class InstallUtils {
|
||||
|
||||
private static final int MAX_TIME = 5 * 60 * 1000;
|
||||
private static int INSTALL_WHAT = 20;
|
||||
|
||||
private static Map<String, Long> installMap;
|
||||
private static Map<String, Long> uninstallMap;
|
||||
@ -42,7 +43,7 @@ public class InstallUtils {
|
||||
handler = new Handler(context.getMainLooper()) {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (msg.what == 0x123 && packageManager != null) {
|
||||
if (msg.what == INSTALL_WHAT && packageManager != null) {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0);
|
||||
for (PackageInfo packageInfo : packageInfos) {
|
||||
@ -82,7 +83,7 @@ public class InstallUtils {
|
||||
}
|
||||
if ((installMap != null && installMap.size() != 0)
|
||||
|| (uninstallMap != null && uninstallMap.size() != 0)) {
|
||||
sendEmptyMessageDelayed(0x123, 3000);
|
||||
sendEmptyMessageDelayed(INSTALL_WHAT, 3000);
|
||||
} else {
|
||||
isRunning = false;
|
||||
}
|
||||
@ -118,7 +119,7 @@ public class InstallUtils {
|
||||
return;
|
||||
}
|
||||
isRunning = true;
|
||||
handler.sendEmptyMessageDelayed(0x123, 10000);
|
||||
handler.sendEmptyMessageDelayed(INSTALL_WHAT, 10000);
|
||||
}
|
||||
|
||||
public void removeInstall(String packageName) {
|
||||
|
||||
@ -50,7 +50,7 @@ public class IntentUtils {
|
||||
"\n" +
|
||||
"光环助手官网地址:\n" +
|
||||
"\n" +
|
||||
"http://www.ghzs666.com/link?source=appshare333");
|
||||
"http://www.ghzs.com/link?source=appshare333");
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,149 +1,29 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.KaiFuServerEntity;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/19.
|
||||
*/
|
||||
public class KaiFuUtils {
|
||||
|
||||
public static void setKaiFuTimeHint(long curTime, long lastTime, GameEntity entity, boolean isTop) {
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd", Locale.getDefault());
|
||||
String curDay = format.format(curTime);
|
||||
String lastDay = format.format(lastTime);
|
||||
if (!curDay.equals(lastDay)) {
|
||||
if (isTop) {
|
||||
entity.setKaifuTimeHint(curTime);
|
||||
} else {
|
||||
entity.setKaifuTimeHint(lastTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void initKaiFuTimeHintView(TextView view, Long time) {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault());
|
||||
try {
|
||||
long today = format.parse(format.format(new Date())).getTime();
|
||||
if (time >= today && time < today + 86400 * 1000) {
|
||||
view.setText("↓今天开服");
|
||||
view.setTextColor(Color.parseColor("#ffb13c"));
|
||||
} else if (time >= today - 86400 * 1000 && time < today) {
|
||||
view.setText("↑历史开服");
|
||||
view.setTextColor(Color.parseColor("#c7c7c7"));
|
||||
} else if (time > today && time < today + 86400 * 1000 * 2) {
|
||||
view.setText("↓明天开服");
|
||||
view.setTextColor(Color.parseColor("#ffb13c"));
|
||||
} else if (time < today) {
|
||||
view.setText("↑历史开服");
|
||||
view.setTextColor(Color.parseColor("#c7c7c7"));
|
||||
} else if (time > today && time < today + 86400 * 1000 * 3) {
|
||||
view.setText("↓后天开服");
|
||||
view.setTextColor(Color.parseColor("#c7c7c7"));
|
||||
} else {
|
||||
format.applyPattern("↓M月d日开服");
|
||||
view.setText(format.format(time));
|
||||
view.setTextColor(Color.parseColor("#c7c7c7"));
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
format.applyPattern("M月d日开服");
|
||||
view.setText(format.format(time));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setKaiFuTimeHint(TextView top, TextView bottom, List<GameEntity> gameList, int position) {
|
||||
if (position == 0 || position + 1 >= gameList.size()) return;
|
||||
|
||||
GameEntity curGameEntity = gameList.get(position);
|
||||
GameEntity lastGameEntity = gameList.get(position);
|
||||
KaiFuServerEntity curServerEntity = curGameEntity.getServerEntity();
|
||||
KaiFuServerEntity lastServerEntity = lastGameEntity.getServerEntity();
|
||||
|
||||
if (curServerEntity == null || lastServerEntity == null) return;
|
||||
|
||||
long curTime = curServerEntity.getTime() * 1000;
|
||||
long lastTime = lastServerEntity.getTime() * 1000;
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd", Locale.getDefault());
|
||||
String curDay = format.format(curTime);
|
||||
String lastDay = format.format(lastTime);
|
||||
if (!curDay.equals(lastDay)) {
|
||||
|
||||
bottom.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
bottom.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setKaiFuTime(TextView textView, long time) {
|
||||
time = time * 1000;
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault());
|
||||
try {
|
||||
long today = format.parse(format.format(new Date())).getTime();
|
||||
if (time >= today && time < today + 86400 * 1000) {
|
||||
format.applyPattern("HH:mm");
|
||||
textView.setText(String.format("今天 %s", format.format(time)));
|
||||
textView.setBackgroundResource(R.drawable.border_white_bg);
|
||||
textView.setTextColor(Color.parseColor("#ffb13c"));
|
||||
} else if (time >= today - 86400 * 1000 && time < today) {
|
||||
format.applyPattern("HH:mm");
|
||||
textView.setText(String.format("昨天 %s", format.format(time)));
|
||||
textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray);
|
||||
textView.setTextColor(Color.parseColor("#c7c7c7"));
|
||||
} else if (time > today && time < today + 86400 * 1000 * 2) {
|
||||
format.applyPattern("HH:mm");
|
||||
textView.setText(String.format("明天 %s", format.format(time)));
|
||||
textView.setBackgroundResource(R.drawable.border_white_bg);
|
||||
textView.setTextColor(Color.parseColor("#ffb13c"));
|
||||
} else if (time >= today - 86400 * 1000 * 2 && time < today) {
|
||||
format.applyPattern("HH:mm");
|
||||
textView.setText(String.format("前天 %s", format.format(time)));
|
||||
textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray);
|
||||
textView.setTextColor(Color.parseColor("#c7c7c7"));
|
||||
} else if (time > today && time < today + 86400 * 1000 * 3) {
|
||||
format.applyPattern("HH:mm");
|
||||
textView.setText(String.format("后天 %s", format.format(time)));
|
||||
textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray);
|
||||
textView.setTextColor(Color.parseColor("#c7c7c7"));
|
||||
} else {
|
||||
format.applyPattern("MM-dd HH:mm");
|
||||
textView.setText(format.format(time));
|
||||
textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray);
|
||||
textView.setTextColor(Color.parseColor("#c7c7c7"));
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
format.applyPattern("yyyy年MM月dd日 HH:mm");
|
||||
textView.setText(format.format(time));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setKaiFuType(TextView textView, String type) {
|
||||
textView.setText(type);
|
||||
switch (type) {
|
||||
case "不删档内测":
|
||||
textView.setBackgroundColor(Color.parseColor("#c7c7c7"));
|
||||
textView.setBackgroundColor(ContextCompat.getColor(textView.getContext(), R.color.content));
|
||||
break;
|
||||
case "删档内测":
|
||||
textView.setBackgroundColor(Color.parseColor("#c7c7c7"));
|
||||
textView.setBackgroundColor(ContextCompat.getColor(textView.getContext(), R.color.content));
|
||||
break;
|
||||
case "公测":
|
||||
textView.setBackgroundColor(Color.parseColor("#06d0a8"));
|
||||
textView.setBackgroundColor(ContextCompat.getColor(textView.getContext(), R.color.tag_yellow));
|
||||
break;
|
||||
default:
|
||||
textView.setBackgroundColor(Color.parseColor("#06d0a8"));
|
||||
textView.setBackgroundColor(ContextCompat.getColor(textView.getContext(), R.color.tag_yellow));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
@ -17,10 +18,10 @@ import com.gh.gamecenter.BuildConfig;
|
||||
import com.gh.gamecenter.LibaoDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.LibaoDetailAdapter;
|
||||
import com.gh.gamecenter.db.LibaoDao;
|
||||
import com.gh.gamecenter.db.info.LibaoInfo;
|
||||
import com.gh.gamecenter.entity.LibaoEntity;
|
||||
import com.gh.gamecenter.entity.LibaoStatusEntity;
|
||||
import com.gh.gamecenter.entity.UserDataEntity;
|
||||
import com.gh.gamecenter.entity.UserDataLibaoEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.geetest.GeetestListener;
|
||||
@ -40,7 +41,6 @@ import okhttp3.ResponseBody;
|
||||
import retrofit2.HttpException;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Func1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
@ -71,59 +71,16 @@ public class LibaoUtils {
|
||||
return rawList;
|
||||
}
|
||||
|
||||
//初始化存号箱 获取存号箱所有礼包
|
||||
public static void getCunHaoXiang(final Context context, final boolean isCheck) {
|
||||
TokenUtils.getToken(context, isCheck)
|
||||
.flatMap(new Func1<String, Observable<List<LibaoEntity>>>() {
|
||||
@Override
|
||||
public Observable<List<LibaoEntity>> call(String token) {
|
||||
return RetrofitManager.getLibao().getCunHaoXiang(token);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<LibaoEntity>>() {
|
||||
@Override
|
||||
public void onResponse(List<LibaoEntity> response) {
|
||||
LibaoDao libaoDao = new LibaoDao(context);
|
||||
libaoDao.deleteAll(); // 清空之前所有数据
|
||||
for (LibaoEntity libaoEntity : response) {
|
||||
|
||||
if ("ling".equals(libaoEntity.getStatus())) {
|
||||
libaoEntity.setStatus("linged");
|
||||
} else {
|
||||
libaoEntity.setStatus("taoed");
|
||||
}
|
||||
|
||||
LibaoInfo libaoInfo = LibaoInfo.createLibaoInfo(libaoEntity);
|
||||
libaoInfo.setActive(libaoEntity.isActive());
|
||||
libaoDao.add(libaoInfo);
|
||||
}
|
||||
|
||||
EventBus.getDefault().post(new EBReuse("libaoChanged"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
if (e != null && e.code() == 401) {
|
||||
getCunHaoXiang(context, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void postLibaoLing(final Context context, final String libaoId, final boolean isCheck,
|
||||
private static void postLibaoLing(final Context context, final String libaoId,
|
||||
final PostLibaoListener listener, final String captchaCode) {
|
||||
TokenUtils.getToken(context, isCheck)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
if (!TextUtils.isEmpty(captchaCode)) {
|
||||
return RetrofitManager.getLibao().postLibaoLing(token, captchaCode, libaoId);
|
||||
} else {
|
||||
return RetrofitManager.getLibao().postLibaoLing(token, libaoId);
|
||||
}
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
|
||||
Observable<ResponseBody> observable;
|
||||
if (!TextUtils.isEmpty(captchaCode)) {
|
||||
observable = RetrofitManager.getInstance(context).getApi().postLibaoLing(captchaCode, libaoId);
|
||||
} else {
|
||||
observable = RetrofitManager.getInstance(context).getApi().postLibaoLing(libaoId);
|
||||
}
|
||||
observable.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
@Override
|
||||
@ -133,10 +90,7 @@ public class LibaoUtils {
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
if (e != null && e.code() == 401) {
|
||||
postLibaoLing(context, libaoId, false, listener, captchaCode);
|
||||
return;
|
||||
} else if (e != null && e.code() == 410) { // 该接口已废弃
|
||||
if (e != null && e.code() == 410) { // 该接口已废弃
|
||||
Utils.toast(context, "领取失败,请安装最新版本的光环助手");
|
||||
}
|
||||
listener.postFailed(e);
|
||||
@ -144,15 +98,10 @@ public class LibaoUtils {
|
||||
});
|
||||
}
|
||||
|
||||
private static void postLibaoTao(final Context context, final String libaoId, final boolean isCheck,
|
||||
private static void postLibaoTao(final Context context, final String libaoId,
|
||||
final PostLibaoListener listener) {
|
||||
TokenUtils.getToken(context, isCheck)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
return RetrofitManager.getLibao().postLibaoTao(token, libaoId);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
RetrofitManager.getInstance(context).getApi().postLibaoTao(libaoId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
@Override
|
||||
@ -162,24 +111,15 @@ public class LibaoUtils {
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
if (e != null && e.code() == 401) {
|
||||
postLibaoTao(context, libaoId, false, listener);
|
||||
return;
|
||||
}
|
||||
listener.postFailed(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void deleteLibaoCode(final Context context, final String code, final boolean isCheck,
|
||||
public static void deleteLibaoCode(final Context context, final String code,
|
||||
final PostLibaoListener listener) {
|
||||
TokenUtils.getToken(context, isCheck)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
return RetrofitManager.getLibao().deleteLibaoCode(token, code);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
RetrofitManager.getInstance(context).getApi().deleteLibaoCode(code)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@Override
|
||||
@ -189,17 +129,13 @@ public class LibaoUtils {
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
if (e != null && e.code() == 401) {
|
||||
deleteLibaoCode(context, code, false, listener);
|
||||
return;
|
||||
}
|
||||
listener.postFailed(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void getLibaoStatus(String ids, final PostLibaoListener listener) {
|
||||
RetrofitManager.getLibao().getLibaoStatus(ids)
|
||||
public static void getLibaoStatus(Context context, String ids, final PostLibaoListener listener) {
|
||||
RetrofitManager.getInstance(context).getApi().getLibaoStatus(ids)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<LibaoStatusEntity>>() {
|
||||
@ -215,61 +151,72 @@ public class LibaoUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static void initLibaoBtn(final Context context, final TextView libaoBtn, final LibaoEntity libaoEntity, final LibaoDao libaoDao,
|
||||
public static void initLibaoBtn(final Context context, final TextView libaoBtn, final LibaoEntity libaoEntity,
|
||||
final boolean isInstallRequired, final LibaoDetailAdapter adapter, final String entrance) {
|
||||
|
||||
libaoBtn.setTextColor(Color.WHITE);
|
||||
String status = libaoEntity.getStatus();
|
||||
final String status = libaoEntity.getStatus();
|
||||
if (TextUtils.isEmpty(status)) return;
|
||||
switch (status) {
|
||||
case "coming":
|
||||
libaoBtn.setText("未开抢");
|
||||
libaoBtn.setText(R.string.libao_coming);
|
||||
libaoBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
break;
|
||||
case "ling":
|
||||
libaoBtn.setText("领取");
|
||||
libaoBtn.setText(R.string.libao_ling);
|
||||
libaoBtn.setBackgroundResource(R.drawable.textview_green_style);
|
||||
break;
|
||||
case "tao":
|
||||
libaoBtn.setText("淘号");
|
||||
libaoBtn.setText(R.string.libao_tao);
|
||||
libaoBtn.setBackgroundResource(R.drawable.textview_orange_style);
|
||||
break;
|
||||
case "used_up":
|
||||
libaoBtn.setText("已领光");
|
||||
libaoBtn.setText(R.string.libao_used_up);
|
||||
libaoBtn.setBackgroundResource(R.drawable.textview_cancel_up);
|
||||
break;
|
||||
case "finish":
|
||||
libaoBtn.setText("已结束");
|
||||
libaoBtn.setText(R.string.libao_finish);
|
||||
libaoBtn.setBackgroundResource(R.drawable.textview_cancel_up);
|
||||
break;
|
||||
case "linged":
|
||||
int[][] states = new int[2][];
|
||||
states[0] = new int[]{android.R.attr.state_pressed};
|
||||
states[1] = new int[]{};
|
||||
int[] colors = new int[]{Color.WHITE,
|
||||
Color.parseColor("#06D0A8")};
|
||||
ColorStateList sl = new ColorStateList(states, colors);
|
||||
libaoBtn.setText("已领取");
|
||||
libaoBtn.setText(R.string.libao_linged);
|
||||
libaoBtn.setBackgroundResource(R.drawable.libao_linged_style);
|
||||
libaoBtn.setTextColor(sl);
|
||||
libaoBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.libao_linged_selector));
|
||||
break;
|
||||
case "taoed":
|
||||
int[][] states2 = new int[2][];
|
||||
states2[0] = new int[]{android.R.attr.state_pressed};
|
||||
states2[1] = new int[]{};
|
||||
int[] colors2 = new int[]{Color.WHITE, Color.parseColor("#ffb13c")};
|
||||
ColorStateList sl2 = new ColorStateList(states2, colors2);
|
||||
libaoBtn.setText("已淘号");
|
||||
libaoBtn.setText(R.string.libao_taoed);
|
||||
libaoBtn.setBackgroundResource(R.drawable.libao_taoed_style);
|
||||
libaoBtn.setTextColor(sl2);
|
||||
libaoBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.libao_taoed_selector));
|
||||
break;
|
||||
case "copy":
|
||||
libaoBtn.setText("复制");
|
||||
libaoBtn.setText(R.string.libao_copy);
|
||||
libaoBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
break;
|
||||
case "repeatLing":
|
||||
libaoBtn.setText(R.string.libao_repeat_ling);
|
||||
libaoBtn.setBackgroundResource(R.drawable.textview_cancel_up);
|
||||
break;
|
||||
case "repeatLinged":
|
||||
libaoBtn.setText(R.string.libao_repeat_ling);
|
||||
libaoBtn.setBackgroundResource(R.drawable.textview_green_style);
|
||||
break;
|
||||
|
||||
case "repeatTao":
|
||||
libaoBtn.setText(R.string.libao_repeat_tao);
|
||||
libaoBtn.setBackgroundResource(R.drawable.textview_cancel_up);
|
||||
break;
|
||||
case "repeatTaoed":
|
||||
libaoBtn.setText(R.string.libao_repeat_tao);
|
||||
libaoBtn.setBackgroundResource(R.drawable.textview_orange_style);
|
||||
break;
|
||||
case "unshelve":
|
||||
libaoBtn.setBackgroundResource(R.drawable.textview_cancel_style);
|
||||
libaoBtn.setText(R.string.libao_unshelve);
|
||||
break;
|
||||
default:
|
||||
libaoBtn.setBackgroundResource(R.drawable.textview_cancel_style);
|
||||
libaoBtn.setText("异常");
|
||||
break;
|
||||
}
|
||||
|
||||
libaoBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@ -289,10 +236,9 @@ public class LibaoUtils {
|
||||
.getPlatformName(libaoEntity.getPlatform()) + "版";
|
||||
}
|
||||
|
||||
String dialogContent = context.getString(R.string.ling_rules_dialog, libaoEntity.getGame().getName(), platform);
|
||||
DialogUtils.showWarningDialog(context, "条件不符",
|
||||
Html.fromHtml("请先" + "<font color=\"#06D0A8\">"
|
||||
+ "安装《" + libaoEntity.getGame().getName() + "》 "
|
||||
+ platform + "</font>"), "关闭", "立即安装"
|
||||
Html.fromHtml(dialogContent), "关闭", "立即安装"
|
||||
, new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
@ -311,14 +257,29 @@ public class LibaoUtils {
|
||||
Intent intent = LibaoDetailActivity.getIntent(context, libaoEntity, entrance);
|
||||
context.startActivity(intent);
|
||||
break;
|
||||
case "再领一个":
|
||||
case "领取":
|
||||
libaoLing(context, libaoBtn, libaoEntity, adapter, isInstallRequired, libaoDao, null, entrance);
|
||||
if ("repeatLing".equals(status)) {
|
||||
DialogUtils.showWarningDialog(context, "礼包刷新提醒"
|
||||
, "礼包每天0点刷新,换新区或者换新角色需要继续领取礼包的童鞋,请于明天0点之后回来即可[再领一个]"
|
||||
, null, "知道了", null, null);
|
||||
} else {
|
||||
libaoLing(context, libaoBtn, libaoEntity, adapter, isInstallRequired, null, entrance);
|
||||
}
|
||||
break;
|
||||
case "再淘一个":
|
||||
case "淘号":
|
||||
postLibaoTao(context, libaoEntity.getId(), true, new PostLibaoListener() {
|
||||
if ("repeatTao".equals(status)) {
|
||||
Utils.toast(context, "没到重复淘号时间, 礼包每天0点刷新");
|
||||
return;
|
||||
}
|
||||
final Dialog loadingDialog = DialogUtils.showWaitDialog(context, "淘号中...");
|
||||
postLibaoTao(context, libaoEntity.getId(), new PostLibaoListener() {
|
||||
@Override
|
||||
public void postSucced(Object response) {
|
||||
|
||||
if (loadingDialog != null) loadingDialog.dismiss();
|
||||
|
||||
JSONObject responseBody = (JSONObject) response;
|
||||
Utils.log("postLibaoTao=====" + responseBody);
|
||||
String libaoCode = null;
|
||||
@ -352,35 +313,28 @@ public class LibaoUtils {
|
||||
|
||||
libaoEntity.setStatus("taoed");
|
||||
|
||||
LibaoInfo libaoInfo = LibaoInfo.createLibaoInfo(libaoEntity);
|
||||
libaoInfo.setCode(libaoCode);
|
||||
libaoInfo.setTime(Utils.getTime(context));
|
||||
libaoDao.add(libaoInfo);
|
||||
|
||||
EventBus.getDefault().post(new EBReuse("libaoChanged"));
|
||||
|
||||
adapter.initLibaoDao();
|
||||
adapter.notifyDataSetChanged();
|
||||
adapter.initLibaoCode(new UserDataLibaoEntity(libaoCode, "tao", Utils.getTime(context)));
|
||||
|
||||
final String finalLibaoCode = libaoCode;
|
||||
DialogUtils.showWarningDialog(context, "淘号成功", Html.fromHtml("礼包码:"
|
||||
+ "<font color=\"#ffb13c\">" + libaoCode + "</font>" +
|
||||
"<br/>淘号礼包不保证可用,请尽快进入游戏尝试兑换")
|
||||
|
||||
DialogUtils.showWarningDialog(context, "淘号成功"
|
||||
, Html.fromHtml(context.getString(R.string.taoed_dialog, libaoCode))
|
||||
, "关闭", " 复制礼包码"
|
||||
, new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
copyLink(finalLibaoCode, context);
|
||||
|
||||
if (isInstallRequired) {
|
||||
libaoBtn.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Spanned msg = Html.fromHtml(
|
||||
context.getString(R.string.taoed_copy_dialog
|
||||
, finalLibaoCode));
|
||||
lunningAppDialog(context
|
||||
, Html.fromHtml("礼包码:"
|
||||
+ "<font color=\"#ffb13c\">" + finalLibaoCode + "</font>"
|
||||
+ " 复制成功"
|
||||
+ "<br/>淘号礼包不保证可用,请尽快进入游戏尝试兑换"), libaoEntity);
|
||||
, msg, libaoEntity);
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
@ -392,13 +346,15 @@ public class LibaoUtils {
|
||||
public void postFailed(Throwable error) {
|
||||
Utils.log("---" + error.toString());
|
||||
|
||||
if (loadingDialog != null) loadingDialog.dismiss();
|
||||
|
||||
if (error instanceof HttpException) {
|
||||
HttpException exception = (HttpException) error;
|
||||
if (exception.code() == 403) {
|
||||
try {
|
||||
JSONObject errorJson = new JSONObject(exception.response().errorBody().string());
|
||||
String detail = errorJson.getString("detail");
|
||||
Utils.toast(context, "返回::" + detail);
|
||||
// Utils.toast(context, "返回::" + detail);
|
||||
switch (detail) {
|
||||
case "coming":
|
||||
Utils.toast(context, "礼包领取时间未开始");
|
||||
@ -407,18 +363,11 @@ public class LibaoUtils {
|
||||
Utils.toast(context, "礼包领取时间已结束");
|
||||
break;
|
||||
case "fetched":
|
||||
Utils.toast(context, "你已领过这个礼包了");
|
||||
getCunHaoXiang(context, true);
|
||||
Utils.toast(context, "你今天已领过这个礼包了, 不能再淘号");
|
||||
|
||||
int[][] states2 = new int[2][];
|
||||
states2[0] = new int[]{android.R.attr.state_pressed};
|
||||
states2[1] = new int[]{};
|
||||
int[] colors2 = new int[]{Color.WHITE,
|
||||
Color.parseColor("#ffb13c")};
|
||||
ColorStateList sl2 = new ColorStateList(states2, colors2);
|
||||
libaoBtn.setText("已淘号");
|
||||
libaoBtn.setBackgroundResource(R.drawable.libao_taoed_style);
|
||||
libaoBtn.setTextColor(sl2);
|
||||
libaoBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.libao_taoed_selector));
|
||||
libaoEntity.setStatus("taoed");
|
||||
break;
|
||||
case "try tao":
|
||||
@ -456,15 +405,18 @@ public class LibaoUtils {
|
||||
}
|
||||
|
||||
private static void libaoLing(final Context context, final TextView libaoBtn, final LibaoEntity libaoEntity, final LibaoDetailAdapter adapter,
|
||||
final boolean isInstallRequired, final LibaoDao libaoDao, String captchaCode, final String entrance) {
|
||||
final boolean isInstallRequired, String captchaCode, final String entrance) {
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.e("LIBAO", "context? " + context + libaoBtn.getContext());
|
||||
}
|
||||
|
||||
postLibaoLing(context, libaoEntity.getId(), true, new PostLibaoListener() {
|
||||
final Dialog loadingDialog = DialogUtils.showWaitDialog(context, "领取中...");
|
||||
|
||||
postLibaoLing(context, libaoEntity.getId(), new PostLibaoListener() {
|
||||
@Override
|
||||
public void postSucced(Object response) {
|
||||
if (loadingDialog != null) loadingDialog.dismiss();
|
||||
|
||||
JSONObject responseBody = (JSONObject) response;
|
||||
Utils.log("postLibaoLing=====" + responseBody);
|
||||
@ -483,20 +435,13 @@ public class LibaoUtils {
|
||||
|
||||
libaoEntity.setStatus("linged");
|
||||
|
||||
LibaoInfo libaoInfo = LibaoInfo.createLibaoInfo(libaoEntity);
|
||||
libaoInfo.setTime(Utils.getTime(context));
|
||||
libaoInfo.setCode(libaoCode);
|
||||
libaoDao.add(libaoInfo);
|
||||
|
||||
EventBus.getDefault().post(new EBReuse("libaoChanged"));
|
||||
|
||||
adapter.initLibaoDao();
|
||||
adapter.initLibaoCode(new UserDataLibaoEntity(libaoCode, "ling", Utils.getTime(context)));
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
final String finalLibaoCode = libaoCode;
|
||||
DialogUtils.showWarningDialog(context, "领取成功", Html.fromHtml("礼包码:"
|
||||
+ "<font color=\"#00B7FA\">" + libaoCode + "</font>" +
|
||||
"<br/>请尽快使用,礼包码将于60分钟后进入淘号池")
|
||||
DialogUtils.showWarningDialog(context, "领取成功", Html.fromHtml(context.getString(R.string.linged_dialog, libaoCode))
|
||||
, "关闭", " 复制礼包码"
|
||||
, new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
@ -506,10 +451,9 @@ public class LibaoUtils {
|
||||
libaoBtn.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Spanned msg = Html.fromHtml(context.getString(R.string.linged_copy_dialog, finalLibaoCode));
|
||||
lunningAppDialog(context
|
||||
, Html.fromHtml("礼包码:"
|
||||
+ "<font color=\"#00B7FA\">" + finalLibaoCode + "</font>"
|
||||
+ " 复制成功" + "<br/>请尽快进入游戏兑换"), libaoEntity);
|
||||
, msg, libaoEntity);
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
@ -519,7 +463,7 @@ public class LibaoUtils {
|
||||
|
||||
@Override
|
||||
public void postFailed(Throwable error) {
|
||||
Utils.log("-----" + error.toString());
|
||||
if (loadingDialog != null) loadingDialog.dismiss();
|
||||
|
||||
if (error instanceof HttpException) {
|
||||
HttpException exception = (HttpException) error;
|
||||
@ -528,7 +472,7 @@ public class LibaoUtils {
|
||||
String string = exception.response().errorBody().string();
|
||||
JSONObject errorJson = new JSONObject(string);
|
||||
String detail = errorJson.getString("detail");
|
||||
|
||||
Utils.log("=======detail ::" + errorJson.toString());
|
||||
switch (detail) {
|
||||
case "coming":
|
||||
Utils.toast(context, "礼包领取时间未开始");
|
||||
@ -544,19 +488,11 @@ public class LibaoUtils {
|
||||
}
|
||||
if (countdown > 0 && countdown < 60 * 10) {
|
||||
EventBus.getDefault().post(new EBUISwitch(REFRESH_LIBAO_TIME, countdown));
|
||||
} else {
|
||||
getCunHaoXiang(context, true);
|
||||
}
|
||||
|
||||
int[][] states = new int[2][];
|
||||
states[0] = new int[]{android.R.attr.state_pressed};
|
||||
states[1] = new int[]{};
|
||||
int[] colors = new int[]{Color.WHITE,
|
||||
Color.parseColor("#06D0A8")};
|
||||
ColorStateList sl = new ColorStateList(states, colors);
|
||||
libaoBtn.setText("已领取");
|
||||
libaoBtn.setText(R.string.libao_linged);
|
||||
libaoBtn.setBackgroundResource(R.drawable.libao_linged_style);
|
||||
libaoBtn.setTextColor(sl);
|
||||
libaoBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.libao_linged_selector));
|
||||
|
||||
libaoEntity.setStatus("linged");
|
||||
break;
|
||||
@ -565,7 +501,7 @@ public class LibaoUtils {
|
||||
DialogUtils.showHintDialog(context, "礼包已领光"
|
||||
, "手速不够快,礼包已经被抢光了,十分抱歉", "知道了");
|
||||
libaoEntity.setStatus("used_up");
|
||||
initLibaoBtn(context, libaoBtn, libaoEntity, libaoDao, isInstallRequired, adapter, entrance);
|
||||
initLibaoBtn(context, libaoBtn, libaoEntity, isInstallRequired, adapter, entrance);
|
||||
break;
|
||||
case "maintaining":
|
||||
Utils.toast(context, "网络状态异常,请稍后再试");
|
||||
@ -584,7 +520,7 @@ public class LibaoUtils {
|
||||
GeetestUtils.getInstance().showDialog(context, new GeetestListener() {
|
||||
@Override
|
||||
public void onVerified(String captcha) {
|
||||
libaoLing(context, libaoBtn, libaoEntity, adapter, isInstallRequired, libaoDao, captcha, entrance);
|
||||
libaoLing(context, libaoBtn, libaoEntity, adapter, isInstallRequired, captcha, entrance);
|
||||
}
|
||||
});
|
||||
return;
|
||||
@ -635,63 +571,58 @@ public class LibaoUtils {
|
||||
}
|
||||
|
||||
|
||||
// 合并List<LibaoStatusEntity> 和 List<LibaoEntity> 并检查重复领取的礼包
|
||||
public static void initLiBaoEntity(LibaoDao libaoDao, List<LibaoStatusEntity> statusList,
|
||||
List<LibaoEntity> libaoEntities, Context mContext) {
|
||||
|
||||
for (LibaoInfo libaoInfo : libaoDao.getAll()) {
|
||||
for (LibaoStatusEntity libaoStatusEntity : statusList) {
|
||||
if (TextUtils.isEmpty(libaoInfo.getLibaoId()) || TextUtils.isEmpty(libaoStatusEntity.getId())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(libaoStatusEntity.getBeforeStatus())) {
|
||||
libaoStatusEntity.setBeforeStatus(libaoStatusEntity.getStatus());
|
||||
}
|
||||
|
||||
if (libaoInfo.getLibaoId().equals(libaoStatusEntity.getId())) {
|
||||
if ("ling".equals(libaoInfo.getStatus()) || "linged".equals(libaoInfo.getStatus())) {
|
||||
libaoStatusEntity.setStatus("linged");
|
||||
} else {
|
||||
libaoStatusEntity.setStatus("taoed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 合并List<LibaoStatusEntity> 和 List<LibaoEntity>
|
||||
public static void initLiBaoEntity(List<LibaoStatusEntity> statusList,
|
||||
List<LibaoEntity> libaoEntities) {
|
||||
|
||||
for (LibaoEntity libaoEntity : libaoEntities) {
|
||||
for (LibaoStatusEntity libaoStatusEntity : statusList) {
|
||||
if (libaoEntity.getId().equals(libaoStatusEntity.getId())) {
|
||||
libaoEntity.setAvailable(libaoStatusEntity.getAvailable());
|
||||
libaoEntity.setTotal(libaoStatusEntity.getTotal());
|
||||
libaoEntity.setBeforeStatus(libaoStatusEntity.getStatus());
|
||||
libaoStatusEntity.setBeforeStatus(libaoStatusEntity.getStatus());
|
||||
|
||||
String beforeStatus = libaoStatusEntity.getBeforeStatus();
|
||||
int repeat = libaoEntity.getRepeat();
|
||||
if (repeat > 0
|
||||
&& libaoDao.isCanLing(libaoEntity.getId(), mContext)
|
||||
&& ("ling".equals(beforeStatus) || "tao".equals(beforeStatus))) { // 判断是否可以重复领取
|
||||
if ("ling".equals(beforeStatus)) {
|
||||
if (libaoDao.repeatedLingedCount(libaoStatusEntity.getId()) >= repeat) {
|
||||
libaoEntity.setStatus(libaoStatusEntity.getStatus());
|
||||
} else {
|
||||
libaoEntity.setStatus(beforeStatus);
|
||||
}
|
||||
UserDataEntity userData = libaoEntity.getUserData();
|
||||
if (userData != null && userData.getUserDataLibaoList() != null && userData.getUserDataLibaoList().size() > 0) {
|
||||
List<UserDataLibaoEntity> userDataLibaoList = userData.getUserDataLibaoList();
|
||||
UserDataLibaoEntity userDataLibaoEntity = userDataLibaoList.get(userDataLibaoList.size() - 1);
|
||||
if ("ling".equals(userDataLibaoEntity.getType())) { // 拿最后一次领取的状态判断
|
||||
libaoEntity.setStatus("linged");
|
||||
} else {
|
||||
if (libaoDao.repeatedTaoedCount(libaoStatusEntity.getId()) >= repeat) {
|
||||
libaoEntity.setStatus(libaoStatusEntity.getStatus());
|
||||
} else {
|
||||
libaoEntity.setStatus(beforeStatus);
|
||||
}
|
||||
libaoEntity.setStatus("taoed");
|
||||
}
|
||||
} else {
|
||||
libaoEntity.setStatus(libaoStatusEntity.getStatus());
|
||||
}
|
||||
libaoEntity.setBeforeStatus(beforeStatus);
|
||||
libaoEntity.setAvailable(libaoStatusEntity.getAvailable());
|
||||
libaoEntity.setTotal(libaoStatusEntity.getTotal());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void initLiBaoEntity(LibaoStatusEntity libaoStatusEntity,
|
||||
LibaoEntity libaoEntity) {
|
||||
if (libaoEntity.getId().equals(libaoStatusEntity.getId())) {
|
||||
libaoEntity.setBeforeStatus(libaoStatusEntity.getStatus());
|
||||
libaoStatusEntity.setBeforeStatus(libaoStatusEntity.getStatus());
|
||||
|
||||
UserDataEntity userData = libaoEntity.getUserData();
|
||||
if (userData != null && userData.getUserDataLibaoList() != null && userData.getUserDataLibaoList().size() > 0) {
|
||||
List<UserDataLibaoEntity> userDataLibaoList = userData.getUserDataLibaoList();
|
||||
UserDataLibaoEntity userDataLibaoEntity = userDataLibaoList.get(userDataLibaoList.size() - 1);
|
||||
if ("ling".equals(userDataLibaoEntity.getType())) { // 拿最后一次领取的状态判断
|
||||
libaoEntity.setStatus("linged");
|
||||
} else {
|
||||
libaoEntity.setStatus("taoed");
|
||||
}
|
||||
} else {
|
||||
libaoEntity.setStatus(libaoStatusEntity.getStatus());
|
||||
}
|
||||
libaoEntity.setAvailable(libaoStatusEntity.getAvailable());
|
||||
libaoEntity.setTotal(libaoStatusEntity.getTotal());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface PostLibaoListener {
|
||||
void postSucced(Object response);
|
||||
|
||||
@ -1,21 +1,35 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.LoginResponseEntity;
|
||||
import com.gh.gamecenter.entity.UserInfoEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.manager.RefreshTokenManager;
|
||||
import com.gh.gamecenter.personal.PersonalFragment;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.HttpException;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
@ -28,17 +42,66 @@ import rx.schedulers.Schedulers;
|
||||
public class LoginUtils {
|
||||
|
||||
public enum LoginTag {
|
||||
qq, wechat, weibo, phone
|
||||
qq, wechat, weibo, phone, refresh, oldUserPhone
|
||||
}
|
||||
|
||||
public static void checkPhoneNum(final Context context, final String phoneName, final onCaptchaCallBackListener listener) { // 老用户登录检查手机是否登录过
|
||||
RetrofitManager.getInstance(context).getApi()
|
||||
.checkPhoneNum(phoneName)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@Override
|
||||
public void onResponse(ResponseBody response) {
|
||||
super.onResponse(response);
|
||||
try {
|
||||
JSONObject content = new JSONObject(response.string());
|
||||
String status = content.getString("status");
|
||||
if ("ok".equals(status)) {
|
||||
getPhoneCaptcha(context, phoneName, listener);
|
||||
} else {
|
||||
DialogUtils.showWarningDialog(context, null, "手机号已存在,请使用未登录过的手机号,以保证数据正常同步到新账号上"
|
||||
, null, "我知道了", null, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
if (e == null) {
|
||||
Utils.toast(context, "请检查网络是否可用");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ResponseBody responseBody = e.response().errorBody();
|
||||
String string = responseBody.string();
|
||||
JSONObject content = new JSONObject(string);
|
||||
int code = content.getInt("code");
|
||||
outputErrorHint(context, code);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// 获取验证码
|
||||
public static void getPhoneCaptcha(final Context context, String phoneNum, final onCaptchaCallBackListener listener) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("mobile", phoneNum);
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
RetrofitManager
|
||||
.getUser()
|
||||
JSONObject content = new JSONObject();
|
||||
try {
|
||||
content.put("mobile", phoneNum);
|
||||
content.put("device", DeviceUtils.getLoginDevice(context.getApplicationContext()));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), content.toString());
|
||||
RetrofitManager.getInstance(context)
|
||||
.getUsersea()
|
||||
.loginByCaptcha(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -56,20 +119,19 @@ public class LoginUtils {
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
int code = e.code();
|
||||
switch (code) {
|
||||
case 40001:
|
||||
Utils.toast(context, "缺少mobile参数");
|
||||
break;
|
||||
case 40002:
|
||||
Utils.toast(context, "mobile格式错误");
|
||||
break;
|
||||
case 40003:
|
||||
Utils.toast(context, "一分钟内已发送过验证码");
|
||||
break;
|
||||
default:
|
||||
Utils.toast(context, "未知错误");
|
||||
break;
|
||||
if (e == null) {
|
||||
Utils.toast(context, "无法获取验证码,请检查你的网络状态");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ResponseBody responseBody = e.response().errorBody();
|
||||
String string = responseBody.string();
|
||||
JSONObject content = new JSONObject(string);
|
||||
int code = content.getInt("code");
|
||||
outputErrorHint(context, code);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
Utils.toast(context, "无法获取验证码,请检查你的网络状态");
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -77,21 +139,39 @@ public class LoginUtils {
|
||||
|
||||
|
||||
// 登录前,做好body判断
|
||||
public static void login(final Context context, RequestBody body, final LoginTag loginTag,
|
||||
public static void login(final Context context, final JSONObject content, final LoginTag loginTag,
|
||||
final onLoginCallBackListener listener) {
|
||||
|
||||
Observable<LoginResponseEntity> observable;
|
||||
Observable<LoginResponseEntity> observable = null;
|
||||
String userToken = null;
|
||||
|
||||
if (loginTag == LoginTag.weibo) {
|
||||
observable = RetrofitManager.getUser().loginByWeibo(body);
|
||||
} else if (loginTag == LoginTag.qq){
|
||||
observable = RetrofitManager.getUser().loginByQQ(body);
|
||||
} else if (loginTag == LoginTag.wechat) {
|
||||
observable = RetrofitManager.getUser().loginByWechat(body);
|
||||
} else {
|
||||
observable = RetrofitManager.getUser().loginByMobile(body);
|
||||
try {
|
||||
JSONObject device = DeviceUtils.getLoginDevice(context.getApplicationContext());
|
||||
content.put("device", device);
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), content.toString());
|
||||
|
||||
if (loginTag == LoginTag.weibo) {
|
||||
userToken = content.getString("uid");
|
||||
observable = RetrofitManager.getInstance(context).getUsersea().loginByWeibo(body);
|
||||
} else if (loginTag == LoginTag.qq) {
|
||||
userToken = content.getString("openid");
|
||||
observable = RetrofitManager.getInstance(context).getUsersea().loginByQQ(body);
|
||||
} else if (loginTag == LoginTag.wechat) {
|
||||
userToken = content.getString("openid");
|
||||
observable = RetrofitManager.getInstance(context).getUsersea().loginByWechat(body);
|
||||
} else if (loginTag == LoginTag.phone || loginTag == LoginTag.oldUserPhone) {
|
||||
userToken = content.getString("mobile");
|
||||
observable = RetrofitManager.getInstance(context).getUsersea().loginByMobile(body);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (observable == null) return;
|
||||
|
||||
final String finalUserToken = userToken;
|
||||
observable
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -99,56 +179,498 @@ public class LoginUtils {
|
||||
@Override
|
||||
public void onResponse(LoginResponseEntity response) {
|
||||
super.onResponse(response);
|
||||
listener.onLogin(response, loginTag);
|
||||
if (loginTag.equals(LoginTag.phone) || loginTag.equals(LoginTag.oldUserPhone)) {
|
||||
try {
|
||||
response.setLoginType(content.getString("mobile"));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
response.setLoginType(loginTag.name());
|
||||
}
|
||||
response.setUserToken(finalUserToken);
|
||||
saveLoginToken(context, response);
|
||||
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String syncDeviceID = sp.getString("syncDeviceID", null);
|
||||
if (!TextUtils.isEmpty(syncDeviceID)) {
|
||||
syncUserData(context, syncDeviceID, listener, loginTag);
|
||||
sp.edit().putString("syncDeviceID", null).apply(); // 清空
|
||||
} else {
|
||||
getUserData(context, false, listener, loginTag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
int code = e.code();
|
||||
switch (code) {
|
||||
case 40000:
|
||||
Utils.toast(context,"参数错误或不完整");
|
||||
case 40004:
|
||||
Utils.toast(context,"缺少mobile参数");
|
||||
break;
|
||||
case 40005:
|
||||
Utils.toast(context,"缺少code参数");
|
||||
break;
|
||||
case 40006:
|
||||
Utils.toast(context,"缺少service_id参数");
|
||||
break;
|
||||
case 40007:
|
||||
Utils.toast(context,"服务已超时");
|
||||
break;
|
||||
case 40008:
|
||||
Utils.toast(context,"验证码已超时");
|
||||
break;
|
||||
case 40009:
|
||||
Utils.toast(context,"验证码错误");
|
||||
break;
|
||||
case 40010:
|
||||
Utils.toast(context,"登录授权失败");
|
||||
break;
|
||||
case 40011:
|
||||
Utils.toast(context,"缺少token参数");
|
||||
break;
|
||||
case 40012:
|
||||
Utils.toast(context,"令牌已过期");
|
||||
break;
|
||||
default:
|
||||
Utils.toast(context,"未知错误");
|
||||
break;
|
||||
if (listener != null) {
|
||||
listener.onLoginFailure();
|
||||
}
|
||||
try {
|
||||
ResponseBody responseBody = e.response().errorBody();
|
||||
String string = responseBody.string();
|
||||
JSONObject content = new JSONObject(string);
|
||||
int code = content.getInt("code");
|
||||
|
||||
if (loginTag.equals(LoginTag.phone)) {
|
||||
outputErrorHint(context, code);
|
||||
} else {
|
||||
if (loginTag.equals(LoginTag.qq)) {
|
||||
GetLoginDataUtils.getInstance(context).QQLogout();
|
||||
}
|
||||
Utils.toast(context, context.getString(R.string.login_failure_hint));
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
Utils.toast(context, context.getString(R.string.login_failure_hint));
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void syncUserData(final Context context, String syncDeviceID,
|
||||
final onLoginCallBackListener listener,
|
||||
final LoginTag loginTag) {
|
||||
|
||||
String loginType;
|
||||
if (LoginTag.phone.equals(loginTag)) {
|
||||
loginType = "mobile";
|
||||
} else {
|
||||
loginType = loginTag.toString();
|
||||
}
|
||||
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("device_id", syncDeviceID);
|
||||
map.put("login_type", loginType);
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), new JSONObject(map).toString());
|
||||
RetrofitManager.getInstance(context).getApi().syncUserData(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(userInfoResponse(context, loginTag, listener));
|
||||
}
|
||||
|
||||
// 注销登录
|
||||
public static void logout(final Context context, final OnLogoutListener listener) {
|
||||
|
||||
RetrofitManager.getInstance(context)
|
||||
.getUsersea()
|
||||
.logout()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(ResponseBody response) {
|
||||
super.onResponse(response);
|
||||
listener.onCompleted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
listener.onCompleted();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 清除本地用户相关信息
|
||||
public static void cleanUserData(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences.Editor edit = sp.edit();
|
||||
edit.putString("user_info", null);
|
||||
edit.putString("login_token", null);
|
||||
edit.apply();
|
||||
|
||||
GetLoginDataUtils.getInstance(context).QQLogout();
|
||||
|
||||
EventBus.getDefault().post(new EBReuse(PersonalFragment.LOGOUT_TAG));
|
||||
}
|
||||
|
||||
// 检查本地是否有缓存token,有则马上登录
|
||||
public static void checkLogin(Context context, onLoginCallBackListener listener) {
|
||||
LoginResponseEntity loginToken = getLoginToken(context);
|
||||
|
||||
if (loginToken != null && loginToken.getAccessToken() != null) {
|
||||
LoginResponseEntity.AccessToken accessToken = loginToken.getAccessToken();
|
||||
Long accessExpire = accessToken.getExpire();
|
||||
if (accessExpire != null && accessExpire > Utils.getTime(context)) {
|
||||
getUserData(context, false, listener, null);
|
||||
} else {
|
||||
LoginResponseEntity.RefreshToken refreshToken = loginToken.getRefreshToken();
|
||||
Long refreshExpire = refreshToken.getExpire();
|
||||
if (refreshExpire != null && refreshExpire > Utils.getTime(context)) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("refresh_token", refreshToken.getValue());
|
||||
RefreshTokenManager.getInstance().refreshToken(context, false, new JSONObject(params), listener);
|
||||
} else {
|
||||
// 重新登录
|
||||
cleanUserData(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Response<UserInfoEntity> userInfoResponse(final Context context,
|
||||
final LoginTag loginTag,
|
||||
final onLoginCallBackListener listener) {
|
||||
return new Response<UserInfoEntity>() {
|
||||
@Override
|
||||
public void onResponse(UserInfoEntity response) {
|
||||
super.onResponse(response);
|
||||
|
||||
saveUserInfo(context, response);
|
||||
if (listener != null) {
|
||||
listener.onLogin(response, loginTag);
|
||||
}
|
||||
|
||||
if (loginTag != null && !LoginTag.refresh.equals(loginTag)) {
|
||||
Utils.toast(context, "登录成功");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
if (listener != null) {
|
||||
listener.onLoginFailure();
|
||||
}
|
||||
if (loginTag != null) {
|
||||
Utils.toast(context, context.getString(R.string.login_failure_hint));
|
||||
}
|
||||
if (loginTag != null && loginTag.equals(LoginTag.qq)) {
|
||||
GetLoginDataUtils.getInstance(context).QQLogout();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
public static void getUserData(final Context context, boolean isRunMainThread, final onLoginCallBackListener listener, final LoginTag loginTag) {
|
||||
|
||||
Observable<UserInfoEntity> observable;
|
||||
if (isRunMainThread) {
|
||||
observable = RetrofitManager.getInstance(context)
|
||||
.getApi()
|
||||
.getUserInfo();
|
||||
} else {
|
||||
observable = RetrofitManager.getInstance(context)
|
||||
.getApi()
|
||||
.getUserInfo()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
observable.subscribe(userInfoResponse(context, loginTag, listener));
|
||||
}
|
||||
|
||||
// 获取本地缓存用户信息
|
||||
public static UserInfoEntity getUserInfo(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String loginData = sp.getString("user_info", null);
|
||||
if (!TextUtils.isEmpty(loginData)) {
|
||||
Type listType = new TypeToken<UserInfoEntity>() {
|
||||
}.getType();
|
||||
return new Gson().fromJson(loginData, listType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// 在本地缓存用户信息
|
||||
public static void saveUserInfo(Context context, UserInfoEntity entity) {
|
||||
if (entity != null) {
|
||||
String region = entity.getRegion();
|
||||
if (region != null && region.contains("中国")) { // 转换地区格式
|
||||
String replace = region.replace("中国 ", "");
|
||||
entity.setRegion(replace);
|
||||
}
|
||||
|
||||
String s = new Gson().toJson(entity);
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences.Editor edit = sp.edit();
|
||||
edit.putString("user_info", s);
|
||||
edit.apply();
|
||||
}
|
||||
}
|
||||
|
||||
//获取本地缓存用户token
|
||||
public static LoginResponseEntity getLoginToken(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String loginData = sp.getString("login_token", null);
|
||||
if (!TextUtils.isEmpty(loginData)) {
|
||||
Type listType = new TypeToken<LoginResponseEntity>() {
|
||||
}.getType();
|
||||
return new Gson().fromJson(loginData, listType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//获取本地缓存用户token
|
||||
public static String getToken(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String loginData = sp.getString("login_token", null);
|
||||
if (!TextUtils.isEmpty(loginData)) {
|
||||
Type listType = new TypeToken<LoginResponseEntity>() {
|
||||
}.getType();
|
||||
LoginResponseEntity entity = new Gson().fromJson(loginData, listType);
|
||||
if (entity != null && entity.getAccessToken() != null) {
|
||||
return entity.getAccessToken().getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 在本地缓存用户token
|
||||
public static void saveLoginToken(Context context, LoginResponseEntity entity) {
|
||||
if (entity != null) {
|
||||
if (TextUtils.isEmpty(entity.getLoginType())) {
|
||||
LoginResponseEntity loginToken = getLoginToken(context);
|
||||
if (loginToken != null) {
|
||||
entity.setLoginType(loginToken.getLoginType());
|
||||
}
|
||||
}
|
||||
|
||||
String s = new Gson().toJson(entity);
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences.Editor edit = sp.edit();
|
||||
edit.putString("login_token", s);
|
||||
edit.apply();
|
||||
}
|
||||
}
|
||||
|
||||
//更改用户信息
|
||||
public static void changeUserInfo(final onChangeUserInfoListener listener, final Context context,
|
||||
final String content, final String editType) {
|
||||
final UserInfoEntity entity = getUserInfo(context);
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(editType, content);
|
||||
|
||||
final Dialog loadingDialog = DialogUtils.showWaitDialog(context, "正在修改信息...");
|
||||
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(map).toString());
|
||||
RetrofitManager.getInstance(context)
|
||||
.getUsersea()
|
||||
.changeUserInfo(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@Override
|
||||
public void onResponse(ResponseBody response) {
|
||||
super.onResponse(response);
|
||||
if (loadingDialog != null) {
|
||||
loadingDialog.dismiss();
|
||||
}
|
||||
switch (editType) {
|
||||
case "name":
|
||||
entity.setName(content);
|
||||
break;
|
||||
case "contact":
|
||||
entity.setContact(content);
|
||||
break;
|
||||
case "gender":
|
||||
entity.setGender(content);
|
||||
break;
|
||||
case "region":
|
||||
entity.setRegion(content);
|
||||
break;
|
||||
case "icon":
|
||||
entity.setIcon(content);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
saveUserInfo(context, entity);
|
||||
|
||||
|
||||
listener.onChange();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
if (loadingDialog != null) {
|
||||
loadingDialog.dismiss();
|
||||
}
|
||||
Utils.toast(context, "修改失败");
|
||||
|
||||
if (e == null) {
|
||||
Utils.toast(context, "请检查网络是否可用");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ResponseBody responseBody = e.response().errorBody();
|
||||
String string = responseBody.string();
|
||||
JSONObject content = new JSONObject(string);
|
||||
int code = content.getInt("code");
|
||||
outputErrorHint(context, code);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void outputErrorHint(Context context, int code) {
|
||||
|
||||
switch (code) {
|
||||
case 40000:
|
||||
Utils.toast(context, "参数不全");
|
||||
break;
|
||||
case 40001:
|
||||
Utils.toast(context, "验证码获取过快,请稍后重试");// 已经发送过短信
|
||||
break;
|
||||
case 40002:
|
||||
Utils.toast(context, "请求第三方开放平台时发生错误");
|
||||
break;
|
||||
case 40003:
|
||||
Utils.toast(context, "上传用户头像时发生错误");
|
||||
break;
|
||||
case 40101:
|
||||
Utils.toast(context, "缺少参数 app_id");
|
||||
break;
|
||||
case 40102:
|
||||
Utils.toast(context, "缺少签名验证的头信息");
|
||||
break;
|
||||
case 40104:
|
||||
Utils.toast(context, "缺少token");
|
||||
break;
|
||||
case 40105:
|
||||
Utils.toast(context, "缺少手机号码");
|
||||
break;
|
||||
case 40106:
|
||||
Utils.toast(context, "缺少用户名");
|
||||
break;
|
||||
case 40107:
|
||||
Utils.toast(context, "缺少密码参数");
|
||||
break;
|
||||
case 40202:
|
||||
Utils.toast(context, "无效的手机号码");
|
||||
break;
|
||||
case 40203:
|
||||
Utils.toast(context, "无效的用户名");
|
||||
break;
|
||||
case 40204:
|
||||
Utils.toast(context, "无效的头像地址");
|
||||
break;
|
||||
case 40205:
|
||||
Utils.toast(context, "无效的性别参数");
|
||||
break;
|
||||
case 40206:
|
||||
Utils.toast(context, "无效的地区参数");
|
||||
break;
|
||||
case 40208:
|
||||
Utils.toast(context, "无效的密码");
|
||||
break;
|
||||
case 40209:
|
||||
Utils.toast(context, "无效的URL 地址");
|
||||
break;
|
||||
case 42000:
|
||||
Utils.toast(context, "无效的app_id");
|
||||
break;
|
||||
case 42001:
|
||||
Utils.toast(context, "无效的app_secret");
|
||||
break;
|
||||
case 42002:
|
||||
Utils.toast(context, "无效的Union_id");
|
||||
break;
|
||||
case 42003:
|
||||
Utils.toast(context, "无效的设备信息");
|
||||
break;
|
||||
case 42004:
|
||||
Utils.toast(context, "无效的请求");
|
||||
break;
|
||||
case 40301:
|
||||
Utils.toast(context, "签名验证失败");
|
||||
break;
|
||||
case 40302:
|
||||
Utils.toast(context, "验证码错误");
|
||||
break;
|
||||
case 40303:
|
||||
Utils.toast(context, "密码错误");
|
||||
break;
|
||||
case 40304:
|
||||
Utils.toast(context, "不支持该种方式登录");
|
||||
break;
|
||||
case 40305:
|
||||
Utils.toast(context, "错误的状态值(应用只有两种状态: working / stop)");
|
||||
break;
|
||||
case 40306:
|
||||
Utils.toast(context, "传递了无法识别的参数");
|
||||
break;
|
||||
case 40401:
|
||||
Utils.toast(context, "token过期");
|
||||
break;
|
||||
case 40402:
|
||||
Utils.toast(context, "Service_id过期,主要原因是:收到手机短信验证码后长时间没有进行登录操作");
|
||||
break;
|
||||
case 40403:
|
||||
Utils.toast(context, "验证码已过期");
|
||||
break;
|
||||
case 40501:
|
||||
Utils.toast(context, "同名应用已经存在");
|
||||
break;
|
||||
case 40502:
|
||||
Utils.toast(context, "用户名已存在");
|
||||
break;
|
||||
case 40503:
|
||||
Utils.toast(context, "名称已经存在");
|
||||
break;
|
||||
case 40601:
|
||||
Utils.toast(context, "应用不存在");
|
||||
break;
|
||||
case 40602:
|
||||
Utils.toast(context, "用户不存在");
|
||||
break;
|
||||
case 40603:
|
||||
Utils.toast(context, "用户系统不存在");
|
||||
break;
|
||||
case 40604:
|
||||
Utils.toast(context, "用户已被冻结");
|
||||
break;
|
||||
case 40605:
|
||||
Utils.toast(context, "用户没有冻结");
|
||||
break;
|
||||
case 40606:
|
||||
Utils.toast(context, "该应用被停止运行了");
|
||||
break;
|
||||
case 40801:
|
||||
Utils.toast(context, "访问过于频繁");
|
||||
break;
|
||||
case 403001:
|
||||
Utils.toast(context, "设备异常,获取验证码失败,请更换登陆方式或明天再试");
|
||||
break;
|
||||
default:
|
||||
Utils.toast(context, "未知错误");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 更改用户信息回调
|
||||
public interface OnLogoutListener {
|
||||
void onCompleted();
|
||||
}
|
||||
|
||||
// 更改用户信息回调
|
||||
public interface onChangeUserInfoListener {
|
||||
void onChange();
|
||||
}
|
||||
|
||||
// 获取验证码回调
|
||||
public interface onCaptchaCallBackListener {
|
||||
void onCaptcha(String serviceId);
|
||||
}
|
||||
|
||||
// 登录回调
|
||||
public interface onLoginCallBackListener {
|
||||
void onLogin(LoginResponseEntity entity, LoginTag loginTag);
|
||||
void onLogin(UserInfoEntity entity, LoginTag loginTag);
|
||||
|
||||
void onLoginFailure();
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ public class MessageShareUtils {
|
||||
if (pinfo != null) {
|
||||
for (int i = 0; i < pinfo.size(); i++) {
|
||||
String pn = pinfo.get(i).packageName;
|
||||
if (pn.equals("com.tencent.mobileqq")) {
|
||||
if ("com.tencent.mobileqq".equals(pn)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.widget.TextView;
|
||||
|
||||
@ -44,8 +45,8 @@ public class NewsUtils {
|
||||
/**
|
||||
* 统计阅读量
|
||||
*/
|
||||
public static void statNewsViews(String news_id) {
|
||||
RetrofitManager.getData().postNewsViews(news_id)
|
||||
public static void statNewsViews(Context context, String news_id) {
|
||||
RetrofitManager.getInstance(context).getData().postNewsViews(news_id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
@ -79,9 +80,9 @@ public class NewsUtils {
|
||||
public static void setNewsType(TextView textView, String type, int priority, int position) {
|
||||
if (priority != 0) {
|
||||
if (position == 0) {
|
||||
textView.setText("置顶");
|
||||
textView.setText(R.string.article_top);
|
||||
} else {
|
||||
textView.setText("热门");
|
||||
textView.setText(R.string.article_hot);
|
||||
}
|
||||
textView.setBackgroundResource(R.drawable.textview_all_red_style);
|
||||
return;
|
||||
|
||||
@ -12,7 +12,9 @@ import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@ -200,6 +202,16 @@ public class PackageUtils {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据统计或反馈用PatchVersionName
|
||||
* 判断助手是否是第一次启动或版本更新提交的版本号用AppVersionName{@link PackageUtils#getVersionName(Context)}
|
||||
*
|
||||
* @return 补丁包版本号
|
||||
*/
|
||||
public static String getPatchVersionName() {
|
||||
return Config.PATCH_VERSION_NAME;
|
||||
}
|
||||
|
||||
/*
|
||||
* 返回光环助手的版本信息
|
||||
*/
|
||||
@ -286,11 +298,11 @@ public class PackageUtils {
|
||||
if (intent != null) {
|
||||
context.startActivity(intent);
|
||||
} else {
|
||||
Toast.makeText(context, "启动失败", Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(context, "启动失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(context, "启动失败", Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(context, "启动失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,13 +7,14 @@ import android.os.Handler;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.download.FileUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.PlatformEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
@ -128,7 +129,7 @@ public class PlatformUtils {
|
||||
}
|
||||
}
|
||||
if (urls.size() != 0) {
|
||||
checkPlatformPic(urls);
|
||||
// checkPlatformPic(urls);
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,7 +153,7 @@ public class PlatformUtils {
|
||||
}
|
||||
}
|
||||
if (urls.size() != 0) {
|
||||
AppController.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
HaloApp.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int success = 0;
|
||||
@ -221,29 +222,8 @@ public class PlatformUtils {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getPlatformPicPath(String platform) {
|
||||
String path = null;
|
||||
String url = platformPicUrlMap.get(platform);
|
||||
if (url != null) {
|
||||
String fileName = url.substring(url.lastIndexOf("/") + 1);
|
||||
File file = new File(FileUtils.getPlatformPicDir(context));
|
||||
if (file.isDirectory()) {
|
||||
for (File f : file.listFiles()) {
|
||||
if (f.getName().equals(fileName)) {
|
||||
path = f.getAbsolutePath();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (path == null && !isCheck) {
|
||||
ArrayList<String> urls = new ArrayList<>();
|
||||
for (String value : platformPicUrlMap.values()) {
|
||||
urls.add(value);
|
||||
}
|
||||
checkPlatformPic(urls);
|
||||
}
|
||||
}
|
||||
return path;
|
||||
public String getPlatformPicUrl(String platform) {
|
||||
return platformPicUrlMap.get(platform);
|
||||
}
|
||||
|
||||
public String getPlatformName(String platform) {
|
||||
@ -262,7 +242,7 @@ public class PlatformUtils {
|
||||
return;
|
||||
}
|
||||
isUpdate = true;
|
||||
RetrofitManager.getApi().getGamePlatform()
|
||||
RetrofitManager.getInstance(context).getApi().getGamePlatform()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<PlatformEntity>>() {
|
||||
|
||||
@ -16,7 +16,6 @@ import okhttp3.ResponseBody;
|
||||
import retrofit2.HttpException;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Func1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
@ -25,22 +24,16 @@ import rx.schedulers.Schedulers;
|
||||
public class PostCommentUtils {
|
||||
|
||||
public static void addCommentData(final Context context, final String newsId, final String content,
|
||||
final boolean isCheck, final CommentEntity commentEntity,
|
||||
final CommentEntity commentEntity,
|
||||
final PostCommentListener listener) {
|
||||
TokenUtils.getToken(context, isCheck)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), content);
|
||||
|
||||
if (commentEntity != null) {
|
||||
return RetrofitManager.getComment().postReplyComment(token, commentEntity.getId(), body);
|
||||
} else {
|
||||
return RetrofitManager.getComment().postNewsComment(token, newsId, body);
|
||||
}
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), content);
|
||||
Observable<ResponseBody> observable;
|
||||
if (commentEntity != null) {
|
||||
observable = RetrofitManager.getInstance(context).getApi().postReplyComment(commentEntity.getId(), body);
|
||||
} else {
|
||||
observable = RetrofitManager.getInstance(context).getApi().postNewsComment(newsId, body);
|
||||
}
|
||||
observable.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
@Override
|
||||
@ -54,18 +47,8 @@ public class PostCommentUtils {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
super.onError(e);
|
||||
Utils.log("======" + e.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
if (e != null && e.code() == 401) {
|
||||
addCommentData(context, newsId, content, false, commentEntity, listener);
|
||||
return;
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.postFailed(e);
|
||||
}
|
||||
@ -73,15 +56,10 @@ public class PostCommentUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static void addCommentVoto(final Context context, final String commentId, final boolean isCheck,
|
||||
public static void addCommentVoto(final Context context, final String commentId,
|
||||
final PostCommentListener listener) {
|
||||
TokenUtils.getToken(context, isCheck)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
return RetrofitManager.getComment().postCommentVote(token, commentId);
|
||||
}
|
||||
})
|
||||
RetrofitManager.getInstance(context).getApi()
|
||||
.postCommentVote(commentId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@ -94,10 +72,6 @@ public class PostCommentUtils {
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
if (e != null && e.code() == 401) {
|
||||
addCommentVoto(context, commentId, false, listener);
|
||||
return;
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.postFailed(e);
|
||||
}
|
||||
@ -105,16 +79,11 @@ public class PostCommentUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static void addReportData(final Context context, final String reportData, boolean isCheck,
|
||||
public static void addReportData(final Context context, final String reportData,
|
||||
final PostCommentListener listener) {
|
||||
TokenUtils.getToken(context, isCheck)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), reportData);
|
||||
return RetrofitManager.getComment().postReportData(body, token);
|
||||
}
|
||||
})
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), reportData);
|
||||
RetrofitManager.getInstance(context).getApi()
|
||||
.postReportData(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@ -125,10 +94,6 @@ public class PostCommentUtils {
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
if (e != null && e.code() == 401) {
|
||||
addReportData(context, reportData, false, listener);
|
||||
return;
|
||||
}
|
||||
listener.postFailed(e);
|
||||
}
|
||||
});
|
||||
|
||||
@ -19,7 +19,13 @@ public class QQUtils {
|
||||
}
|
||||
if (ShareUtils.isQQClientAvailable(context)) {
|
||||
//安装了QQ会直接调用QQ,打开手机QQ进行会话 QQ号:2586716223
|
||||
String str = "mqqwpa://im/chat?chat_type=wpa&uin=" + qq + "&version=1&src_type=web&web_src=oicqzone.com";
|
||||
String chatType;
|
||||
if (qq.startsWith("400") || qq.startsWith("800")) {
|
||||
chatType = "crm";
|
||||
} else {
|
||||
chatType = "wpa";
|
||||
}
|
||||
String str = "mqqwpa://im/chat?chat_type=" + chatType + "&uin=" + qq + "&version=1&src_type=web";
|
||||
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(str)));
|
||||
} else {
|
||||
//没有安装QQ 复制账号
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
@ -41,4 +42,13 @@ public class RandomUtils {
|
||||
return random.nextInt(size);
|
||||
}
|
||||
|
||||
/**
|
||||
* 四舍五入取整
|
||||
* @return
|
||||
*/
|
||||
public static int getInt(double d) {
|
||||
BigDecimal bigDecimal = new BigDecimal(d).setScale(0, BigDecimal.ROUND_HALF_UP);
|
||||
return bigDecimal.intValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -105,6 +105,7 @@ public class ShareUtils {
|
||||
mTencent = Tencent.createInstance(Config.TENCENT_APPID, context); //初始化QQ分享
|
||||
mIWXAPI = WXAPIFactory.createWXAPI(context, Config.WECHAT_APPID); //初始化微信分享
|
||||
WbSdk.install(context,new AuthInfo(context, Config.WEIBO_APPKEY, "http://www.sina.com", SCOPE));
|
||||
// FIXME 此处严重泄露,把Activity Context 存为static?????
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@ -122,7 +123,7 @@ public class ShareUtils {
|
||||
if (pinfo != null) {
|
||||
for (int i = 0; i < pinfo.size(); i++) {
|
||||
String pn = pinfo.get(i).packageName;
|
||||
if (pn.equals("com.tencent.mobileqq")) {
|
||||
if ("com.tencent.mobileqq".equals(pn)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import android.view.ViewTreeObserver;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
/**
|
||||
* 用于解决因为沉浸式状态栏时键盘不遮挡输入框
|
||||
* 用于解决因为沉浸式状态栏(自定义)时键盘不遮挡输入框
|
||||
*/
|
||||
public class SoftInputHidWidgetUtils {
|
||||
private View mChildOfContent;
|
||||
|
||||
@ -66,7 +66,7 @@ public class TagUtils {
|
||||
return;
|
||||
}
|
||||
isUpdate = true;
|
||||
RetrofitManager.getApi().getTags()
|
||||
RetrofitManager.getInstance(context).getApi().getTags()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<TagEntity>>() {
|
||||
|
||||
@ -23,78 +23,78 @@ public class TimestampUtils {
|
||||
|
||||
private static void initIntervalMap() {
|
||||
intervalMap = new ArrayMap<>();
|
||||
intervalMap.put("^" + Config.HOST + "index/slides" + "$", 5);
|
||||
intervalMap.put("^" + Config.HOST + "game/chajian" + "$", 10);
|
||||
intervalMap.put("^" + Config.HOST + "game/tuijian" + "$", 15);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/detail" + "$", 20);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/digest" + "$", 25);
|
||||
intervalMap.put("^" + Config.HOST + "game/remenkapai" + "$", 30);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news_digest" + "$", 35);
|
||||
intervalMap.put("^" + Config.HOST + "game/column/.+\\?page=.+" + "$", 40);
|
||||
intervalMap.put("^" + Config.HOST + "support/package/.+/game/digest" + "$", 45);
|
||||
intervalMap.put("^" + Config.HOST + "game/danjiyouxi\\?limit=20\\&offset=.+" + "$", 50);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/digest" + "$", 55);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/detail" + "$", 60);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/suggestion" + "$", 65);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=3" + "$", 70);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/zixun\\?limit=20\\&offset=.+" + "$", 75);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+" + "$", 80);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/yuanchuang\\?limit=20\\&offset=.+" + "$", 85);
|
||||
intervalMap.put("^" + Config.HOST + "news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", 90);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", 95);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", 100);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", 105);
|
||||
intervalMap.put("^" + Config.HOST + "search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", 110);
|
||||
intervalMap.put("^" + Config.HOST + "search/game\\?keyword=.+" + "$", 115);
|
||||
intervalMap.put("^" + Config.HOST + "support/setting/platform" + "$", 120);
|
||||
intervalMap.put("^" + Config.HOST + "update/package/.+" + "$", 125);
|
||||
intervalMap.put("^" + Config.HOST + "update/game/.+/package/.+" + "$", 130);
|
||||
intervalMap.put("^" + Config.API_HOST + "index/slides" + "$", 5);
|
||||
intervalMap.put("^" + Config.API_HOST + "game/chajian" + "$", 10);
|
||||
intervalMap.put("^" + Config.API_HOST + "game/tuijian" + "$", 15);
|
||||
intervalMap.put("^" + Config.API_HOST + "game/.+/detail" + "$", 20);
|
||||
intervalMap.put("^" + Config.API_HOST + "game/.+/digest" + "$", 25);
|
||||
intervalMap.put("^" + Config.API_HOST + "game/remenkapai" + "$", 30);
|
||||
intervalMap.put("^" + Config.API_HOST + "game/.+/news_digest" + "$", 35);
|
||||
intervalMap.put("^" + Config.API_HOST + "game/column/.+\\?page=.+" + "$", 40);
|
||||
intervalMap.put("^" + Config.API_HOST + "support/package/.+/game/digest" + "$", 45);
|
||||
intervalMap.put("^" + Config.API_HOST + "game/danjiyouxi\\?limit=20\\&offset=.+" + "$", 50);
|
||||
intervalMap.put("^" + Config.API_HOST + "news/.+/digest" + "$", 55);
|
||||
intervalMap.put("^" + Config.API_HOST + "news/.+/detail" + "$", 60);
|
||||
intervalMap.put("^" + Config.API_HOST + "news/.+/suggestion" + "$", 65);
|
||||
intervalMap.put("^" + Config.API_HOST + "game/.+/news\\?limit=3" + "$", 70);
|
||||
intervalMap.put("^" + Config.API_HOST + "zixun/zixun\\?limit=20\\&offset=.+" + "$", 75);
|
||||
intervalMap.put("^" + Config.API_HOST + "game/.+/news\\?limit=20\\&offset=.+" + "$", 80);
|
||||
intervalMap.put("^" + Config.API_HOST + "zixun/yuanchuang\\?limit=20\\&offset=.+" + "$", 85);
|
||||
intervalMap.put("^" + Config.API_HOST + "news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", 90);
|
||||
intervalMap.put("^" + Config.API_HOST + "zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", 95);
|
||||
intervalMap.put("^" + Config.API_HOST + "game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", 100);
|
||||
intervalMap.put("^" + Config.API_HOST + "zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", 105);
|
||||
intervalMap.put("^" + Config.API_HOST + "search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", 110);
|
||||
intervalMap.put("^" + Config.API_HOST + "search/game\\?keyword=.+" + "$", 115);
|
||||
intervalMap.put("^" + Config.API_HOST + "support/setting/platform" + "$", 120);
|
||||
intervalMap.put("^" + Config.API_HOST + "update/package/.+" + "$", 125);
|
||||
intervalMap.put("^" + Config.API_HOST + "update/game/.+/package/.+" + "$", 130);
|
||||
intervalMap.put("^" + Config.COMMENT_HOST + "article/.+/comment\\?limit=10\\&offset=.+" + "$", 135);
|
||||
intervalMap.put("^" + Config.COMMENT_HOST + "article/.+/comment\\?order=hot\\&limit=10\\&offset=.+" + "$", 140);
|
||||
}
|
||||
|
||||
private static void initCDMap() {
|
||||
cdMap = new ArrayMap<>();
|
||||
cdMap.put("^" + Config.HOST + "index/slides" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/chajian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/tuijian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/detail" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/remenkapai" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news_digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/column/.+\\?page=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "support/package/.+/game/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/danjiyouxi\\?limit=20\\&offset=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/digest" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/detail" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/suggestion" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=3" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/zixun\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/yuanchuang\\?limit=10\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "search/game\\?keyword=.+" + "$", Constants.SEARCH_CD);
|
||||
cdMap.put("^" + Config.HOST + "support/setting/platform" + "$", Constants.PLATFORM_CD);
|
||||
cdMap.put("^" + Config.HOST + "update/package/.+" + "$", Constants.UPDATE_CD);
|
||||
cdMap.put("^" + Config.HOST + "update/game/.+/package/.+" + "$", Constants.UPDATE_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "index/slides" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "game/chajian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "game/tuijian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "game/.+/detail" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "game/.+/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "game/remenkapai" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "game/.+/news_digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "game/column/.+\\?page=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "support/package/.+/game/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "game/danjiyouxi\\?limit=20\\&offset=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "news/.+/digest" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "news/.+/detail" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "news/.+/suggestion" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "game/.+/news\\?limit=3" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "zixun/zixun\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "game/.+/news\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "zixun/yuanchuang\\?limit=10\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "search/game\\?keyword=.+" + "$", Constants.SEARCH_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "support/setting/platform" + "$", Constants.PLATFORM_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "update/package/.+" + "$", Constants.UPDATE_CD);
|
||||
cdMap.put("^" + Config.API_HOST + "update/game/.+/package/.+" + "$", Constants.UPDATE_CD);
|
||||
cdMap.put("^" + Config.COMMENT_HOST + "article/.+/comment\\?limit=10\\&offset=.+" + "$", Constants.COMMENT_CD);
|
||||
cdMap.put("^" + Config.COMMENT_HOST + "article/.+/comment\\?order=hot\\&limit=10\\&offset=.+" + "$", Constants.COMMENT_CD);
|
||||
cdMap.put("^" + Config.HOST + "device/.+/concern" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "device/.+/concern/.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "stat/download" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "disclaimer" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "search/game/default" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/upgrade\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/time/current" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/setting/ui" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/download_status\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/suggestion" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/serverInfo" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/package/unused\\?skip=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.API_HOST + "device/.+/concern" + "$", 0);
|
||||
cdMap.put("^" + Config.API_HOST + "device/.+/concern/.+" + "$", 0);
|
||||
cdMap.put("^" + Config.API_HOST + "stat/download" + "$", 0);
|
||||
cdMap.put("^" + Config.API_HOST + "disclaimer" + "$", 0);
|
||||
cdMap.put("^" + Config.API_HOST + "search/game/default" + "$", 0);
|
||||
cdMap.put("^" + Config.API_HOST + "support/upgrade\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.API_HOST + "support/time/current" + "$", 0);
|
||||
cdMap.put("^" + Config.API_HOST + "support/setting/ui" + "$", 0);
|
||||
cdMap.put("^" + Config.API_HOST + "support/download_status\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.API_HOST + "support/suggestion" + "$", 0);
|
||||
cdMap.put("^" + Config.API_HOST + "game/.+/serverInfo" + "$", 0);
|
||||
cdMap.put("^" + Config.API_HOST + "support/package/unused\\?skip=.+" + "$", 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -160,6 +160,8 @@ public class TimestampUtils {
|
||||
* 去除url中的timestamp
|
||||
*/
|
||||
public static String removeTimestamp(String url) {
|
||||
if (!url.contains("timestamp")) return url;
|
||||
|
||||
int index = url.lastIndexOf("timestamp");
|
||||
String params = url.substring(index);
|
||||
//连接符
|
||||
|
||||
@ -3,92 +3,74 @@ package com.gh.common.util;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.gamecenter.BuildConfig;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.gh.gamecenter.retrofit.StringResponse;
|
||||
import com.lightgame.utils.Util_System_Phone_State;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.tencent.stat.StatConfig;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Func1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
public class TokenUtils {
|
||||
|
||||
// 注册设备
|
||||
public static synchronized void register(final Context context) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("MANUFACTURER", Build.MANUFACTURER);
|
||||
params.put("MODEL", Build.MODEL);
|
||||
params.put("ANDROID_SDK", String.valueOf(Build.VERSION.SDK_INT));
|
||||
params.put("ANDROID_VERSION", Build.VERSION.RELEASE);
|
||||
String android_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
if (!TextUtils.isEmpty(android_id)) {
|
||||
params.put("ANDROID_ID", android_id);
|
||||
}
|
||||
String imei = Util_System_Phone_State.getDeviceId(context);
|
||||
if (!TextUtils.isEmpty(imei)) {
|
||||
params.put("IMEI", imei);
|
||||
}
|
||||
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
String mac = wm.getConnectionInfo().getMacAddress();
|
||||
if (!TextUtils.isEmpty(mac) || !":::::".equals(mac)) {
|
||||
params.put("MAC", mac);
|
||||
} else {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
sp.edit().putBoolean("isUploadMac", false).apply();
|
||||
}
|
||||
String mid = StatConfig.getMid(context);
|
||||
if (!TextUtils.isEmpty(mid) || !"0".equals(mid)) {
|
||||
params.put("MTA_ID", mid);
|
||||
} else {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
sp.edit().putBoolean("isUploadMid", false).apply();
|
||||
}
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), new JSONObject(params).toString());
|
||||
RetrofitManager.getUser().postRegister(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
try {
|
||||
// 保存device_id
|
||||
saveDeviceId(context, response.getString("device_id"));
|
||||
Utils.log("device_id = " + response.getString("device_id"));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// public static synchronized void register(final Context context) {
|
||||
// Map<String, String> params = new HashMap<>();
|
||||
// params.put("MANUFACTURER", Build.MANUFACTURER);
|
||||
// params.put("MODEL", Build.MODEL);
|
||||
// params.put("ANDROID_SDK", String.valueOf(Build.VERSION.SDK_INT));
|
||||
// params.put("ANDROID_VERSION", Build.VERSION.RELEASE);
|
||||
// String android_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
// if (!TextUtils.isEmpty(android_id)) {
|
||||
// params.put("ANDROID_ID", android_id);
|
||||
// }
|
||||
// String imei = Util_System_Phone_State.getDeviceId(context);
|
||||
// if (!TextUtils.isEmpty(imei)) {
|
||||
// params.put("IMEI", imei);
|
||||
// }
|
||||
// WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
// String mac = wm.getConnectionInfo().getMacAddress();
|
||||
// if (!TextUtils.isEmpty(mac) || !":::::".equals(mac)) {
|
||||
// params.put("MAC", mac);
|
||||
// } else {
|
||||
// SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
// sp.edit().putBoolean("isUploadMac", false).apply();
|
||||
// }
|
||||
// String mid = StatConfig.getMid(context);
|
||||
// if (!TextUtils.isEmpty(mid) || !"0".equals(mid)) {
|
||||
// params.put("MTA_ID", mid);
|
||||
// } else {
|
||||
// SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
// sp.edit().putBoolean("isUploadMid", false).apply();
|
||||
// }
|
||||
// RequestBody body = RequestBody.create(MediaType.parse("application/json"), new JSONObject(params).toString());
|
||||
// RetrofitManager.getInstance(context).getApi().postRegister(body)
|
||||
// .subscribeOn(Schedulers.io())
|
||||
// .observeOn(Schedulers.io())
|
||||
// .subscribe(new JSONObjectResponse() {
|
||||
// @Override
|
||||
// public void onResponse(JSONObject response) {
|
||||
// if (response.length() != 0) {
|
||||
// try {
|
||||
// // 保存device_id
|
||||
// saveDeviceId(context, response.getString("device_id"));
|
||||
// Utils.log("device_id = " + response.getString("device_id"));
|
||||
// } catch (JSONException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
public static synchronized void saveDeviceId(Context context, String device_id) {
|
||||
saveSharedPreferences(context, device_id);
|
||||
@ -152,58 +134,63 @@ public class TokenUtils {
|
||||
|
||||
}
|
||||
|
||||
// 获取用户token
|
||||
public static synchronized Observable<String> getToken(final Context context, boolean isCheck) {
|
||||
String token = null;
|
||||
if (isCheck) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
token = sp.getString("token", null);
|
||||
if (token != null) {
|
||||
long expire = sp.getLong("token_expire", 0) * 1000 - 10 * 1000;
|
||||
long time = Utils.getTime(context);
|
||||
// 判断token是否过期
|
||||
if (time >= expire) {
|
||||
// token已过期
|
||||
token = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (token == null) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("device_id", getDeviceId(context));
|
||||
return RetrofitManager.getUser()
|
||||
.postLogin(RequestBody.create(MediaType.parse("application/json"), new JSONObject(params).toString()))
|
||||
.flatMap(new Func1<ResponseBody, Observable<String>>() {
|
||||
@Override
|
||||
public Observable<String> call(ResponseBody responseBody) {
|
||||
String value = null;
|
||||
try {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
Editor editor = sp.edit();
|
||||
JSONObject response = new JSONObject(responseBody.string());
|
||||
editor.putString("user_name", response.getString("name"));
|
||||
editor.putString("user_icon", response.getString("icon"));
|
||||
response = response.getJSONObject("token");
|
||||
editor.putString("token", response.getString("value"));
|
||||
editor.putLong("token_expire", response.getLong("expire"));
|
||||
editor.apply();
|
||||
// 服务器返回的token和本地已存的token相同,更新本地时间
|
||||
getTime(context);
|
||||
value = response.getString("value");
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Observable.just(value);
|
||||
}
|
||||
}).onErrorResumeNext(new Func1<Throwable, Observable<? extends String>>() {
|
||||
@Override
|
||||
public Observable<? extends String> call(Throwable throwable) {
|
||||
return Observable.error(throwable);
|
||||
}
|
||||
});
|
||||
}
|
||||
return Observable.just(token);
|
||||
}
|
||||
// // 获取用户token
|
||||
// public static synchronized Observable<String> getToken(final Context context, boolean isCheck) {
|
||||
//
|
||||
// if (true) { // TODO TEST
|
||||
// return Observable.just(LoginUtils.getToken(context));
|
||||
// }
|
||||
//
|
||||
// String token = null;
|
||||
// if (isCheck) {
|
||||
// SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
// token = sp.getString("token", null);
|
||||
// if (token != null) {
|
||||
// long expire = sp.getLong("token_expire", 0) * 1000 - 10 * 1000;
|
||||
// long time = Utils.getTime(context);
|
||||
// // 判断token是否过期
|
||||
// if (time >= expire) {
|
||||
// // token已过期
|
||||
// token = null;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (token == null) {
|
||||
// Map<String, String> params = new HashMap<>();
|
||||
// params.put("device_id", getDeviceId(context));
|
||||
// return RetrofitManager.getInstance(context).getApi()
|
||||
// .postLogin(RequestBody.create(MediaType.parse("application/json"), new JSONObject(params).toString()))
|
||||
// .flatMap(new Func1<ResponseBody, Observable<String>>() {
|
||||
// @Override
|
||||
// public Observable<String> call(ResponseBody responseBody) {
|
||||
// String value = null;
|
||||
// try {
|
||||
// SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
// Editor editor = sp.edit();
|
||||
// JSONObject response = new JSONObject(responseBody.string());
|
||||
// editor.putString("user_name", response.getString("name"));
|
||||
// editor.putString("user_icon", response.getString("icon"));
|
||||
// response = response.getJSONObject("token");
|
||||
// editor.putString("token", response.getString("value"));
|
||||
// editor.putLong("token_expire", response.getLong("expire"));
|
||||
// editor.apply();
|
||||
// // 服务器返回的token和本地已存的token相同,更新本地时间
|
||||
// getTime(context);
|
||||
// value = response.getString("value");
|
||||
// } catch (IOException | JSONException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return Observable.just(value);
|
||||
// }
|
||||
// }).onErrorResumeNext(new Func1<Throwable, Observable<? extends String>>() {
|
||||
// @Override
|
||||
// public Observable<? extends String> call(Throwable throwable) {
|
||||
// return Observable.error(throwable);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// return Observable.just(token);
|
||||
// }
|
||||
|
||||
public static synchronized String getDeviceId(Context context) {
|
||||
return loadSharedPreferences(context, false);
|
||||
@ -212,7 +199,7 @@ public class TokenUtils {
|
||||
// 获取服务器时间
|
||||
public static synchronized void getTime(Context context) {
|
||||
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
RetrofitManager.getApi().getTime()
|
||||
RetrofitManager.getInstance(context).getApi().getTime()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new StringResponse() {
|
||||
@ -304,46 +291,46 @@ public class TokenUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 检查设备信息是否已经上传完整
|
||||
public static synchronized void checkDeviceInfo(Context context, String token) {
|
||||
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
final HashMap<String, String> params = new HashMap<>();
|
||||
if (!sp.getBoolean("isUploadExtra", false)) {
|
||||
params.put("MANUFACTURER", Build.MANUFACTURER);
|
||||
params.put("MODEL", Build.MODEL);
|
||||
params.put("ANDROID_SDK", String.valueOf(Build.VERSION.SDK_INT));
|
||||
params.put("ANDROID_VERSION", Build.VERSION.RELEASE);
|
||||
}
|
||||
if (!sp.getBoolean("isUploadMac", true)) {
|
||||
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
String mac = wm.getConnectionInfo().getMacAddress();
|
||||
if (!TextUtils.isEmpty(mac) || !":::::".equals(mac)) {
|
||||
params.put("MAC", mac);
|
||||
}
|
||||
}
|
||||
if (!sp.getBoolean("isUploadMid", true)) {
|
||||
String mid = StatConfig.getMid(context);
|
||||
if (!TextUtils.isEmpty(mid) || !"0".equals(mid)) {
|
||||
params.put("MTA_ID", mid);
|
||||
}
|
||||
}
|
||||
if (params.size() != 0) {
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
RetrofitManager.getUser().postDevice(token, body, TokenUtils.getDeviceId(context))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@Override
|
||||
public void onResponse(ResponseBody response) {
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.putBoolean("isUploadExtra", true);
|
||||
editor.putBoolean("isUploadMac", true);
|
||||
editor.putBoolean("isUploadMid", true);
|
||||
editor.apply();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
// // 检查设备信息是否已经上传完整
|
||||
// public static synchronized void checkDeviceInfo(Context context, String token) {
|
||||
// final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
// final HashMap<String, String> params = new HashMap<>();
|
||||
// if (!sp.getBoolean("isUploadExtra", false)) {
|
||||
// params.put("MANUFACTURER", Build.MANUFACTURER);
|
||||
// params.put("MODEL", Build.MODEL);
|
||||
// params.put("ANDROID_SDK", String.valueOf(Build.VERSION.SDK_INT));
|
||||
// params.put("ANDROID_VERSION", Build.VERSION.RELEASE);
|
||||
// }
|
||||
// if (!sp.getBoolean("isUploadMac", true)) {
|
||||
// WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
// String mac = wm.getConnectionInfo().getMacAddress();
|
||||
// if (!TextUtils.isEmpty(mac) || !":::::".equals(mac)) {
|
||||
// params.put("MAC", mac);
|
||||
// }
|
||||
// }
|
||||
// if (!sp.getBoolean("isUploadMid", true)) {
|
||||
// String mid = StatConfig.getMid(context);
|
||||
// if (!TextUtils.isEmpty(mid) || !"0".equals(mid)) {
|
||||
// params.put("MTA_ID", mid);
|
||||
// }
|
||||
// }
|
||||
// if (params.size() != 0) {
|
||||
// RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
// new JSONObject(params).toString());
|
||||
// RetrofitManager.getInstance(context).getApi().postDevice(token, body, TokenUtils.getDeviceId(context))
|
||||
// .subscribeOn(Schedulers.io())
|
||||
// .observeOn(AndroidSchedulers.mainThread())
|
||||
// .subscribe(new Response<ResponseBody>() {
|
||||
// @Override
|
||||
// public void onResponse(ResponseBody response) {
|
||||
// SharedPreferences.Editor editor = sp.edit();
|
||||
// editor.putBoolean("isUploadExtra", true);
|
||||
// editor.putBoolean("isUploadMac", true);
|
||||
// editor.putBoolean("isUploadMid", true);
|
||||
// editor.apply();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ public class Concern_LinearLayout extends LinearLayout {
|
||||
concern_rv_recommend.setLayoutParams(lparams);
|
||||
invalidate();
|
||||
if (concern_rv_recommend.getHeight() < height) {
|
||||
postDelayed(show, 10);
|
||||
postDelayed(show, 5);
|
||||
} else {
|
||||
concern_iv_delete.setImageResource(R.drawable.concern_down);
|
||||
}
|
||||
@ -49,7 +49,7 @@ public class Concern_LinearLayout extends LinearLayout {
|
||||
concern_rv_recommend.setLayoutParams(lparams);
|
||||
invalidate();
|
||||
if (concern_rv_recommend.getHeight() > 0) {
|
||||
postDelayed(hide, 10);
|
||||
postDelayed(hide, 5);
|
||||
} else {
|
||||
concern_rv_recommend.setVisibility(View.GONE);
|
||||
concern_iv_delete.setImageResource(R.drawable.concern_up);
|
||||
@ -60,7 +60,7 @@ public class Concern_LinearLayout extends LinearLayout {
|
||||
public Concern_LinearLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
height = DisplayUtils.dip2px(context, 150);
|
||||
distance = DisplayUtils.dip2px(context, 6);
|
||||
distance = DisplayUtils.dip2px(context, 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -91,17 +91,14 @@ public class DownloadDialog implements OnCollectionCallBackListener {
|
||||
private boolean isLoadPlatform;
|
||||
|
||||
private DownloadDialog() {
|
||||
}
|
||||
|
||||
private DownloadDialog(Context context) {
|
||||
mContext = context;
|
||||
isShow = false;
|
||||
}
|
||||
|
||||
public static DownloadDialog getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
instance = new DownloadDialog(context);
|
||||
instance = new DownloadDialog();
|
||||
}
|
||||
instance.mContext = context; // 每次创建context重新赋值, Dialog持有context问题
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -234,7 +231,7 @@ public class DownloadDialog implements OnCollectionCallBackListener {
|
||||
String platform = apkEntity.getPlatform();
|
||||
int id = PlatformUtils.getInstance(mContext).getPlatformPic(platform);
|
||||
if (id == 0) {
|
||||
String path = PlatformUtils.getInstance(mContext).getPlatformPicPath(platform);
|
||||
String path = PlatformUtils.getInstance(mContext).getPlatformPicUrl(platform);
|
||||
if (path == null) {
|
||||
apkEntity.setOrder(0);
|
||||
}
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Workaround AppBarLayout.Behavior for https://issuetracker.google.com/66996774
|
||||
*
|
||||
* See https://gist.github.com/chrisbanes/8391b5adb9ee42180893300850ed02f2 for
|
||||
* example usage.
|
||||
*
|
||||
* Change the package name as you wish.
|
||||
*/
|
||||
public class FixAppBarLayoutBehavior extends AppBarLayout.Behavior {
|
||||
|
||||
public FixAppBarLayoutBehavior() {
|
||||
super();
|
||||
}
|
||||
|
||||
public FixAppBarLayoutBehavior(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target,
|
||||
int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) {
|
||||
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed,
|
||||
dxUnconsumed, dyUnconsumed, type);
|
||||
stopNestedScrollIfNeeded(dyUnconsumed, child, target, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child,
|
||||
View target, int dx, int dy, int[] consumed, int type) {
|
||||
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type);
|
||||
stopNestedScrollIfNeeded(dy, child, target, type);
|
||||
}
|
||||
|
||||
private void stopNestedScrollIfNeeded(int dy, AppBarLayout child, View target, int type) {
|
||||
if (type == ViewCompat.TYPE_NON_TOUCH) {
|
||||
final int currOffset = getTopAndBottomOffset();
|
||||
if ((dy < 0 && currOffset == 0)
|
||||
|| (dy > 0 && currOffset == -child.getTotalScrollRange())) {
|
||||
ViewCompat.stopNestedScroll(target, ViewCompat.TYPE_NON_TOUCH);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,6 @@ import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.common.util.AppDebugConfig;
|
||||
import com.gh.common.util.DataCollectionUtils;
|
||||
@ -19,6 +18,7 @@ import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.lightgame.config.CommonDebug;
|
||||
import com.lightgame.download.ConnectionUtils;
|
||||
import com.lightgame.download.DataChanger;
|
||||
import com.lightgame.download.DataWatcher;
|
||||
@ -228,9 +228,9 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
}
|
||||
}
|
||||
downloadEntity.setInstalled(installed);
|
||||
if (method.equals("更新")) {
|
||||
if ("更新".equals(method)) {
|
||||
downloadEntity.setUpdate(true);
|
||||
} else if (method.equals("插件化")) {
|
||||
} else if ("插件化".equals(method)) {
|
||||
downloadEntity.setPluggable(true);
|
||||
}
|
||||
downloadEntity.setPlugin(gameEntity.getTag() != null && gameEntity.getTag().size() != 0);
|
||||
@ -387,7 +387,9 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
* @return null表示没有下载任务
|
||||
*/
|
||||
public List<DownloadEntity> getAll() {
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "getAll");
|
||||
if (CommonDebug.IS_DEBUG) {
|
||||
CommonDebug.logMethodName(this);
|
||||
}
|
||||
return mDownloadDao.getAll();
|
||||
}
|
||||
|
||||
@ -423,7 +425,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
|
||||
// 暂停任务后,把文件删除,然后点继续,文件不存在,需要重新加入下载队列进行下载
|
||||
if (checkDownloadEntryRecordValidate(url)) {
|
||||
Toast.makeText(mContext, "文件不存在!已重新加入下载队列", Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(mContext, "文件不存在!已重新加入下载队列");
|
||||
add(entry);
|
||||
} else {
|
||||
if (entry != null) {
|
||||
|
||||
@ -8,6 +8,7 @@ import android.content.Intent;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import com.gh.common.util.AppDebugConfig;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
@ -37,9 +38,9 @@ public class DownloadNotification {
|
||||
public static void showDownloadDoneNotification(Context context, DownloadEntity downloadEntity) {
|
||||
final NotificationManager manager = getNotificationManager(context);
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("path", downloadEntity.getPath());
|
||||
intent.putExtra(EntranceUtils.KEY_PATH, downloadEntity.getPath());
|
||||
intent.setAction(ACTION_INSTALL);
|
||||
final int requestCode = downloadEntity.getUrl().hashCode();
|
||||
final int requestCode = downloadEntity.getPackageName().hashCode();
|
||||
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
String text;
|
||||
String title;
|
||||
|
||||
@ -6,20 +6,24 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.StringUtils;
|
||||
import com.gh.gamecenter.manager.UpdateManager;
|
||||
import com.tencent.bugly.beta.tinker.TinkerManager;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.OnLongClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/2/28.
|
||||
@ -32,6 +36,8 @@ public class AboutActivity extends BaseActivity {
|
||||
RelativeLayout mAboutUpdateRl;
|
||||
@BindView(R.id.about_version_pb)
|
||||
ProgressBar mAboutPb;
|
||||
@BindView(R.id.about_tv_version)
|
||||
TextView mVersionName;
|
||||
|
||||
private Handler handler = new MyHandler(this);
|
||||
|
||||
@ -51,7 +57,8 @@ public class AboutActivity extends BaseActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
initTitle(getString(R.string.title_about));
|
||||
|
||||
((TextView) findViewById(R.id.about_tv_version)).setText("V" + PackageUtils.getVersionName(this));
|
||||
// ((TextView) findViewById(R.id.about_tv_version)).setText("V" + PackageUtils.getVersionName(this));
|
||||
mVersionName.setText("V" + PackageUtils.getPatchVersionName()); // TODO 版本号暂时与gradle versionName不一致
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -70,6 +77,19 @@ public class AboutActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@OnLongClick(R.id.about_tv_version)
|
||||
public boolean OnLongClick(View view) {
|
||||
if (view.getId() == R.id.about_tv_version) {
|
||||
String tinkerId = TinkerManager.getNewTinkerId();
|
||||
if (!TextUtils.isEmpty(tinkerId)) {
|
||||
mVersionName.setText("V" + PackageUtils.getPatchVersionName() + "." + tinkerId);
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), R.string.toast_upload_latest, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static class MyHandler extends Handler {
|
||||
|
||||
private WeakReference<AboutActivity> mWeakReference;
|
||||
@ -87,7 +107,7 @@ public class AboutActivity extends BaseActivity {
|
||||
final String version = (String) msg.obj;
|
||||
activity.mAboutVersion.setText(StringUtils.buildString("发现新版本 V", version));
|
||||
} else if (msg.what == 1) {
|
||||
activity.mAboutVersion.setText("已是最新版本");
|
||||
activity.mAboutVersion.setText(R.string.toast_upload_latest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,12 +28,10 @@ import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.UserIconUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.gh.common.view.RadarView;
|
||||
import com.gh.gamecenter.kuaichuan.BaseTransfer;
|
||||
import com.gh.gamecenter.kuaichuan.Constant;
|
||||
@ -41,7 +39,8 @@ import com.gh.gamecenter.kuaichuan.FileInfo;
|
||||
import com.gh.gamecenter.kuaichuan.HotspotManager;
|
||||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||||
import com.gh.gamecenter.kuaichuan.WifiUtils;
|
||||
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -57,6 +56,8 @@ import java.util.Map;
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
import static com.gh.gamecenter.KcSelectGameActivity.SEND_OVER_REQUEST;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/1/20.
|
||||
*/
|
||||
@ -114,6 +115,8 @@ public class ChooseReceiverActivity extends BaseActivity implements View.OnClick
|
||||
TextView mTitleTv;
|
||||
|
||||
|
||||
private static final String KET_SHOWCONNHINTDIALOG = "showConnHintDialog";
|
||||
|
||||
private List<ScanResult> mScanResultList;
|
||||
|
||||
private DatagramSocket mDatagramSocket;
|
||||
@ -135,7 +138,7 @@ public class ChooseReceiverActivity extends BaseActivity implements View.OnClick
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context, boolean showConnHintDialog) {
|
||||
Intent intent = new Intent(context, ChooseReceiverActivity.class);
|
||||
intent.putExtra("showConnHintDialog", showConnHintDialog);
|
||||
intent.putExtra(KET_SHOWCONNHINTDIALOG, showConnHintDialog);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@ -148,7 +151,7 @@ public class ChooseReceiverActivity extends BaseActivity implements View.OnClick
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
closeSocket();
|
||||
AppController.remove("FileInfo");
|
||||
HaloApp.remove("FileInfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -176,11 +179,11 @@ public class ChooseReceiverActivity extends BaseActivity implements View.OnClick
|
||||
|
||||
//修改沉浸栏以及ActionBar 颜色
|
||||
mActionbar.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.scan_bg));
|
||||
SystemBarTintManager tintManager = getTintManager();
|
||||
if (tintManager != null) {
|
||||
tintManager.setStatusBarTintResource(R.color.scan_bg);
|
||||
}
|
||||
|
||||
// SystemBarTintManager tintManager = getTintManager(); // TODO: 27/09/17 更改沉浸栏颜色??
|
||||
// if (tintManager != null) {
|
||||
// tintManager.setStatusBarTintResource(R.color.scan_bg);
|
||||
// }
|
||||
//
|
||||
init();
|
||||
|
||||
hintTv.setOnClickListener(new View.OnClickListener() {
|
||||
@ -190,11 +193,11 @@ public class ChooseReceiverActivity extends BaseActivity implements View.OnClick
|
||||
}
|
||||
});
|
||||
|
||||
boolean showConnHintDialog = sp.getBoolean("showConnHintDialog", true);
|
||||
boolean showConnHintDialog = sp.getBoolean(KET_SHOWCONNHINTDIALOG, true);
|
||||
if (showConnHintDialog || (getIntent() != null && getIntent().getExtras() != null
|
||||
&& getIntent().getExtras().getBoolean("showConnHintDialog"))) {
|
||||
&& getIntent().getExtras().getBoolean(KET_SHOWCONNHINTDIALOG))) {
|
||||
if (showConnHintDialog) {
|
||||
sp.edit().putBoolean("showConnHintDialog", false).apply();
|
||||
sp.edit().putBoolean(KET_SHOWCONNHINTDIALOG, false).apply();
|
||||
}
|
||||
showConnHintDialog();
|
||||
}
|
||||
@ -205,7 +208,7 @@ public class ChooseReceiverActivity extends BaseActivity implements View.OnClick
|
||||
conUserIconTag = 1;
|
||||
mRadarView.setSearching(true);
|
||||
|
||||
mScanHint.setText(Html.fromHtml("<u>" + "好友还没安装光环助手?请点这里" + "</u>"));
|
||||
mScanHint.setText(Html.fromHtml(getString(R.string.kc_scan_hint)));
|
||||
|
||||
isStopScan = false;
|
||||
isDestroy = false;
|
||||
@ -326,7 +329,7 @@ public class ChooseReceiverActivity extends BaseActivity implements View.OnClick
|
||||
// "\n2.点击首页左上角,进入下载管理 \n3.点击“零流量传送”,再点击“我要接收”",
|
||||
// "确定");
|
||||
|
||||
// TODO 关闭扫描??
|
||||
// TODO 是否需要关闭扫描??
|
||||
|
||||
startActivity(ShareGhActivity.getIntent(this));
|
||||
} //1.连接网络
|
||||
@ -377,11 +380,11 @@ public class ChooseReceiverActivity extends BaseActivity implements View.OnClick
|
||||
@OnClick(R.id.actionbar_rl_back)
|
||||
public void onBackListener() {
|
||||
closeSocket();
|
||||
AppController.remove("FileInfo");
|
||||
HaloApp.remove("FileInfo");
|
||||
} //发送UDP通知信息到 文件接收方 开启ServerSocketRunnable
|
||||
|
||||
private void createSendMsgToServerRunnable(final String ipAddress) {
|
||||
AppController.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
HaloApp.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -449,7 +452,7 @@ public class ChooseReceiverActivity extends BaseActivity implements View.OnClick
|
||||
byte[] receiveData = new byte[1024];
|
||||
byte[] sendData;
|
||||
Utils.log("=====ip::" + ipAddress);
|
||||
if (!ipAddress.equals("192.168.43.1")) {
|
||||
if (!"192.168.43.1".equals(ipAddress)) {
|
||||
// 连接失败,可能是连接的热点已经关闭, 关闭动画,开启扫描
|
||||
isStopScan = false;
|
||||
handler.sendEmptyMessage(0);
|
||||
@ -490,7 +493,7 @@ public class ChooseReceiverActivity extends BaseActivity implements View.OnClick
|
||||
userMap.put("receiverName", jsonObject.getString(Constant.MSG_FILE_RECEIVER_INIT_SUCCESS));
|
||||
userMap.put("usericon", String.valueOf(conUserIconTag));
|
||||
|
||||
AppController.put("userMap", userMap);
|
||||
HaloApp.put("userMap", userMap);
|
||||
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
@ -506,7 +509,7 @@ public class ChooseReceiverActivity extends BaseActivity implements View.OnClick
|
||||
}
|
||||
|
||||
private void sendFileInfoListToFileReceiverWithUdp(int serverPort, InetAddress ipAddress) {
|
||||
List<FileInfo> fileInfoList = (List<FileInfo>) AppController.get("FileInfo", false);
|
||||
List<FileInfo> fileInfoList = (List<FileInfo>) HaloApp.get("FileInfo", false);
|
||||
if (fileInfoList == null) {
|
||||
return;
|
||||
}
|
||||
@ -601,7 +604,7 @@ public class ChooseReceiverActivity extends BaseActivity implements View.OnClick
|
||||
closeSocket();
|
||||
Intent resultIntent = new Intent();
|
||||
resultIntent.putExtra("isFinish", true);
|
||||
setResult(0x123, resultIntent);
|
||||
setResult(SEND_OVER_REQUEST, resultIntent);
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
@ -18,12 +18,11 @@ import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.StringUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.CleanApkAdapter;
|
||||
import com.gh.gamecenter.entity.InstallGameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
@ -132,7 +131,7 @@ public class CleanApkActivity extends BaseActivity implements CleanApkAdapter.On
|
||||
if ("停止扫描".equals(s)) {
|
||||
mAdapter.isStopScan();
|
||||
} else {
|
||||
if (s.equals("一键删除")) {
|
||||
if ("一键删除".equals(s)) {
|
||||
Utils.toast(CleanApkActivity.this, "请选择需要删除的安装包");
|
||||
return;
|
||||
}
|
||||
@ -143,7 +142,7 @@ public class CleanApkActivity extends BaseActivity implements CleanApkAdapter.On
|
||||
for (int i = 0; i < apkList.size(); i++) {
|
||||
if (selectPosition.get(i) && apkList.get(i).getInstallStatus() == 1) {
|
||||
DialogUtils.showWarningDialog(CleanApkActivity.this, "删除安装包"
|
||||
, Html.fromHtml("你选择的安装包中包含 <font color=\"#ff0000\">未安装</font> 的应用,确定删除吗?")
|
||||
, Html.fromHtml(getString(R.string.delete_apk_hint))
|
||||
, "取消 ", "确定"
|
||||
, new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
@ -216,8 +215,7 @@ public class CleanApkActivity extends BaseActivity implements CleanApkAdapter.On
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
String sizeName = df.format(size) + "MB";
|
||||
|
||||
mApkCount.setText(Html.fromHtml(StringUtils.buildString("找到", String.valueOf(apkList.size()), "个安装包,占用"
|
||||
, "<font color=\"#ff4147\">", sizeName, "</font>", "空间")));
|
||||
mApkCount.setText(Html.fromHtml(getString(R.string.clean_apk_count, apkList.size(), sizeName)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
35
app/src/main/java/com/gh/gamecenter/CollectionActivity.java
Normal file
35
app/src/main/java/com/gh/gamecenter/CollectionActivity.java
Normal file
@ -0,0 +1,35 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.gamecenter.collection.CollectionFragment;
|
||||
|
||||
/**
|
||||
* Created by khy on 18/07/17.
|
||||
*/
|
||||
|
||||
public class CollectionActivity extends BaseActivity {
|
||||
|
||||
|
||||
public static final Intent getCollectionActivity(Context context) {
|
||||
Intent intent = new Intent(context, CollectionActivity.class);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_collection;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
initTitle("我的收藏");
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(
|
||||
R.id.layout_fragment_content, CollectionFragment.newInstance(0)).commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
@ -1,30 +1,79 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.CheckLoginUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.common.util.PostCommentUtils;
|
||||
import com.gh.gamecenter.adapter.CommentDetailAdapter;
|
||||
import com.gh.gamecenter.adapter.OnCommentCallBackListener;
|
||||
import com.gh.gamecenter.entity.CommentEntity;
|
||||
import com.gh.gamecenter.entity.UserInfoEntity;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.OnTouch;
|
||||
import retrofit2.HttpException;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/22.
|
||||
*/
|
||||
public class CommentDetailActivity extends BaseActivity {
|
||||
|
||||
// TODO: 16/11/17 时间比较紧 先暂时这么做 最好发表评论那块和评论详情整合
|
||||
public class CommentDetailActivity extends BaseActivity implements OnCommentCallBackListener {
|
||||
|
||||
@BindView(R.id.comment_detail_rv)
|
||||
RecyclerView mRecyclerView;
|
||||
@BindView(R.id.comment_detail_close_comment)
|
||||
View mCommentDetailCloseComment;
|
||||
@BindView(R.id.comment_detail_comment_et)
|
||||
EditText mCommentDetailCommentEt;
|
||||
@BindView(R.id.comment_user_icon)
|
||||
SimpleDraweeView mCommentUserIcon;
|
||||
@BindView(R.id.comment_user_name)
|
||||
TextView mCommentUserName;
|
||||
@BindView(R.id.comment_send)
|
||||
TextView mCommentSend;
|
||||
@BindView(R.id.comment_detail_user_rl)
|
||||
RelativeLayout mCommentDetailUserRl;
|
||||
@BindView(R.id.comment_detail_comment_rl)
|
||||
RelativeLayout mCommentDetailCommentRl;
|
||||
@BindView(R.id.comment_detail_sv)
|
||||
ScrollView mCommentDetailSv;
|
||||
@BindView(R.id.reuse_none_data)
|
||||
View mNoData;
|
||||
|
||||
private Dialog mSendingDialog;
|
||||
|
||||
private UserInfoEntity mUserInfo;
|
||||
private CommentEntity mCommentEntity; // 回复评论的实体 用完马上清空
|
||||
|
||||
private CommentDetailAdapter mAdapter;
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
|
||||
public static Intent getCommentDetailIntent(Context context, String commentId) {
|
||||
Intent intent = new Intent(context, CommentDetailActivity.class);
|
||||
intent.putExtra("commentId", commentId);
|
||||
intent.putExtra(EntranceUtils.KEY_COMMENTID, commentId);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@ -39,9 +88,9 @@ public class CommentDetailActivity extends BaseActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
initTitle(getString(R.string.title_comment_detail));
|
||||
|
||||
String commentId = getIntent().getExtras().getString("commentId");
|
||||
String commentId = getIntent().getStringExtra(EntranceUtils.KEY_COMMENTID);
|
||||
|
||||
mAdapter = new CommentDetailAdapter(this, commentId);
|
||||
mAdapter = new CommentDetailAdapter(this, commentId, this, mNoData, mRecyclerView);
|
||||
mLayoutManager = new LinearLayoutManager(this);
|
||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
@ -55,5 +104,138 @@ public class CommentDetailActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mUserInfo = LoginUtils.getUserInfo(this);
|
||||
if (mUserInfo != null) {
|
||||
ImageUtils.Companion.display(mCommentUserIcon, mUserInfo.getIcon());
|
||||
mCommentUserName.setText(mUserInfo.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommentCallback(CommentEntity entity) {
|
||||
mCommentEntity = entity;
|
||||
setSoftInput(true);
|
||||
}
|
||||
|
||||
@OnTouch(R.id.comment_detail_close_comment)
|
||||
public boolean OnRecyclerTouchListener() {
|
||||
if (mCommentDetailCloseComment.getVisibility() == View.VISIBLE) {
|
||||
setSoftInput(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@OnClick(R.id.comment_send)
|
||||
public void OnSendCommentListener() {
|
||||
final String content = mCommentDetailCommentEt.getText().toString();
|
||||
|
||||
if (content.length() == 0) {
|
||||
Utils.toast(this, "评论内容不能为空!");
|
||||
return;
|
||||
}
|
||||
|
||||
mSendingDialog = DialogUtils.showWaitDialog(this, "正在提交");
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
try {
|
||||
jsonObject.put("content", content);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (mCommentEntity != null && mCommentEntity.getId() == null) {
|
||||
Utils.toast(this, "评论异常 id null");
|
||||
mSendingDialog.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
PostCommentUtils.addCommentData(CommentDetailActivity.this, null, jsonObject.toString(), mCommentEntity,
|
||||
new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSuccess(JSONObject response) {
|
||||
mSendingDialog.dismiss();
|
||||
toast("发表成功");
|
||||
mCommentDetailCommentEt.setText("");
|
||||
|
||||
setSoftInput(false);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postFailed(Throwable e) {
|
||||
mSendingDialog.dismiss();
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
HttpException exception = (HttpException) e;
|
||||
if (exception.code() == 403) {
|
||||
try {
|
||||
JSONObject errorJson = new JSONObject(exception.response().errorBody().string());
|
||||
String detail = errorJson.getString("detail");
|
||||
switch (detail) {
|
||||
case "too frequent":
|
||||
toast("别话痨哦~休息一会再来评论吧~");
|
||||
break;
|
||||
case "user blocked":
|
||||
toast("账号状态异常,暂时无法发表评论");
|
||||
break;
|
||||
case "article blocked":
|
||||
toast("文章异常,无法发表评论");
|
||||
setSoftInput(false);
|
||||
break;
|
||||
case "illegal":
|
||||
toast("评论内容可能包括敏感信息,请修改后再发表");
|
||||
break;
|
||||
default:
|
||||
toast("评论失败,未知原因");
|
||||
break;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
toast("评论异常");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
toast("提交失败,请检查网络设置");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//软键盘控制
|
||||
private void setSoftInput(boolean isShow) {
|
||||
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if (isShow) {
|
||||
CheckLoginUtils.checkLogin(this, new CheckLoginUtils.OnLoggenInListener() {
|
||||
@Override
|
||||
public void onLoggedIn() {
|
||||
imm.showSoftInputFromInputMethod(mCommentDetailCommentEt.getWindowToken(), 0);
|
||||
imm.toggleSoftInputFromWindow(mCommentDetailCommentEt.getWindowToken(), 0, InputMethodManager.HIDE_NOT_ALWAYS);
|
||||
mCommentDetailCommentRl.setVisibility(View.VISIBLE);
|
||||
mCommentDetailCommentEt.setFocusable(true);
|
||||
mCommentDetailCommentEt.setFocusableInTouchMode(true);
|
||||
mCommentDetailCommentEt.requestFocus();
|
||||
mCommentDetailCloseComment.setVisibility(View.VISIBLE);
|
||||
|
||||
if (mCommentEntity != null && mCommentEntity.getUser() != null) {
|
||||
mCommentDetailCommentEt.setHint("回复" + mCommentEntity.getUser().getName() + ":");
|
||||
} else {
|
||||
mCommentDetailCommentEt.setHint("优质评论会被优先展示");
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
|
||||
|
||||
mCommentDetailCloseComment.setVisibility(View.GONE);
|
||||
|
||||
mCommentDetailCommentRl.setVisibility(View.GONE);
|
||||
if (mCommentEntity != null) {
|
||||
mCommentEntity = null; // 清空当前评论实体
|
||||
mCommentDetailCommentEt.setHint("优质评论会被优先展示");
|
||||
mCommentDetailCommentEt.setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,33 +4,34 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.base.OnRequestCallBackListener;
|
||||
import com.gh.common.util.ConcernUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.view.Concern_LinearLayout;
|
||||
import com.gh.gamecenter.adapter.ConcernAdapter;
|
||||
import com.gh.gamecenter.adapter.ConcernRecommendAdapter;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
import static com.gh.gamecenter.personal.PersonalFragment.LOGIN_TAG;
|
||||
|
||||
public class ConcernActivity extends BaseActivity implements OnClickListener, OnRequestCallBackListener {
|
||||
|
||||
@ -42,11 +43,14 @@ public class ConcernActivity extends BaseActivity implements OnClickListener, On
|
||||
RelativeLayout mConcernTitleRl;
|
||||
@BindView(R.id.reuse_none_data)
|
||||
LinearLayout mNoneData;
|
||||
@BindView(R.id.reuse_tv_none_data)
|
||||
TextView mNoDataTv;
|
||||
@BindView(R.id.reuse_no_connection)
|
||||
LinearLayout mNoConn;
|
||||
|
||||
private ConcernAdapter concernAdapter;
|
||||
private ConcernRecommendAdapter concernRecommendAdapter;
|
||||
private ConcernManager concernManager;
|
||||
private boolean isPause = false;
|
||||
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context, String entrance) {
|
||||
@ -66,14 +70,6 @@ public class ConcernActivity extends BaseActivity implements OnClickListener, On
|
||||
|
||||
initTitle(getString(R.string.title_concern));
|
||||
|
||||
concernManager = new ConcernManager(getApplicationContext());
|
||||
|
||||
List<ConcernInfo> concernList = concernManager.getConcernGame();
|
||||
if (concernList == null || concernList.isEmpty()) {
|
||||
mNoneData.setVisibility(View.VISIBLE);
|
||||
mConcernRv.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
mConcernTitleRl.setOnClickListener(this);
|
||||
|
||||
mConcernRv.setHasFixedSize(true);
|
||||
@ -84,56 +80,11 @@ public class ConcernActivity extends BaseActivity implements OnClickListener, On
|
||||
mConcernRecommendRv.setHasFixedSize(true);
|
||||
mConcernRecommendRv.setLayoutManager(new GridLayoutManager(this, 4));
|
||||
|
||||
concernRecommendAdapter = new ConcernRecommendAdapter(this, this, mEntrance);
|
||||
mConcernRecommendRv.setAdapter(concernRecommendAdapter);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
JSONArray data = new JSONArray();
|
||||
for (ConcernInfo concernInfo : concernManager.getConcernGame()) {
|
||||
data.put(concernInfo.getId());
|
||||
}
|
||||
ConcernUtils.INSTANCE.updateConcernData(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
isPause = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
Utils.log("isPause = " + isPause);
|
||||
if (isPause) {
|
||||
List<ConcernInfo> concernList = concernManager.getConcernGame();
|
||||
boolean isChanged = false;
|
||||
if (concernList == null) {
|
||||
if (concernAdapter.getConcernList().size() != 0) {
|
||||
isChanged = true;
|
||||
}
|
||||
} else {
|
||||
if (concernAdapter.getConcernList() == null
|
||||
|| concernAdapter.getConcernList().isEmpty()
|
||||
|| concernList.size() > concernAdapter.getConcernList().size()
|
||||
|| concernList.size() < concernAdapter.getConcernList().size()) {
|
||||
isChanged = true;
|
||||
}
|
||||
}
|
||||
Utils.log("isChanged = " + isChanged);
|
||||
if (isChanged) {
|
||||
concernAdapter = new ConcernAdapter(this, this, mEntrance);
|
||||
mConcernRv.setAdapter(concernAdapter);
|
||||
}
|
||||
isPause = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone() {
|
||||
public void loadDone() { // 关注推荐 回调
|
||||
mConcernTitleRl.setVisibility(View.VISIBLE);
|
||||
mConcernRecommendRv.setVisibility(View.VISIBLE);
|
||||
int size = concernRecommendAdapter.getRecommendGameList().size();
|
||||
@ -141,22 +92,37 @@ public class ConcernActivity extends BaseActivity implements OnClickListener, On
|
||||
mConcernRecommendRv.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
// 关注的游戏加载完成 再加载热门推荐(根据已关注的游戏过滤)
|
||||
@Override
|
||||
public void loadDone(Object obj) {
|
||||
mNoConn.setVisibility(View.GONE);
|
||||
mNoneData.setVisibility(View.GONE);
|
||||
|
||||
concernRecommendAdapter = new ConcernRecommendAdapter(this, this, (List<GameEntity>)obj, mEntrance);
|
||||
mConcernRecommendRv.setAdapter(concernRecommendAdapter);
|
||||
|
||||
if (obj == null) { // 未登录状态
|
||||
mNoneData.setVisibility(View.VISIBLE);
|
||||
mConcernRv.setVisibility(View.GONE);
|
||||
mNoDataTv.setText(R.string.login_hint);
|
||||
mNoDataTv.setTextColor(ContextCompat.getColor(ConcernActivity.this, R.color.theme));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadError() {
|
||||
|
||||
mNoConn.setVisibility(View.VISIBLE);
|
||||
mNoneData.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadEmpty() {
|
||||
if (concernAdapter.getConcernList() == null
|
||||
|| concernAdapter.getConcernList().isEmpty()) {
|
||||
if (concernAdapter.getConcernGameList() == null
|
||||
|| concernAdapter.getConcernGameList().isEmpty()) {
|
||||
mNoneData.setVisibility(View.VISIBLE);
|
||||
mConcernRv.setVisibility(View.GONE);
|
||||
mNoDataTv.setText(R.string.game_empty);
|
||||
mNoDataTv.setTextColor(ContextCompat.getColor(ConcernActivity.this, R.color.c7c7c7));
|
||||
}
|
||||
if (concernRecommendAdapter.getRecommendGameList() == null
|
||||
|| concernRecommendAdapter.getRecommendGameList().isEmpty()) {
|
||||
@ -170,17 +136,23 @@ public class ConcernActivity extends BaseActivity implements OnClickListener, On
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnClick({R.id.concern_rl_title, R.id.reuse_tv_none_data})
|
||||
public void onClick(View v) {
|
||||
if (v == mConcernTitleRl) {
|
||||
if (mConcernRecommendRv.getVisibility() == View.VISIBLE) {
|
||||
((Concern_LinearLayout) mContentView).hideRecyclerView();
|
||||
} else {
|
||||
((Concern_LinearLayout) mContentView).showRecyclerView();
|
||||
}
|
||||
switch (v.getId()) {
|
||||
case R.id.concern_rl_title:
|
||||
if (mConcernRecommendRv.getVisibility() == View.VISIBLE) {
|
||||
((Concern_LinearLayout) mContentView).hideRecyclerView();
|
||||
} else {
|
||||
((Concern_LinearLayout) mContentView).showRecyclerView();
|
||||
}
|
||||
break;
|
||||
case R.id.reuse_tv_none_data:
|
||||
String hint = getString(R.string.login_hint);
|
||||
if (hint.equals(mNoDataTv.getText().toString()))
|
||||
startActivity(LoginActivity.getIntent(this, false));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 关注事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBConcernChanged changed) {
|
||||
@ -188,47 +160,36 @@ public class ConcernActivity extends BaseActivity implements OnClickListener, On
|
||||
return;
|
||||
}
|
||||
if (changed.isConcern()) {
|
||||
for (GameEntity gameEntity : concernRecommendAdapter.getGameList()) {
|
||||
if (changed.getGameId().equals(gameEntity.getId())) {
|
||||
ConcernInfo concernInfo = new ConcernInfo();
|
||||
concernInfo.setGameName(gameEntity.getName());
|
||||
concernInfo.setConcern(true);
|
||||
concernInfo.setIcon(gameEntity.getIcon());
|
||||
concernInfo.setId(gameEntity.getId());
|
||||
concernAdapter.getConcernList().add(0, concernInfo);
|
||||
concernAdapter.getConcernGameList().add(0, gameEntity);
|
||||
if (mNoneData.getVisibility() == View.VISIBLE) {
|
||||
mNoneData.setVisibility(View.GONE);
|
||||
mConcernRv.setVisibility(View.VISIBLE);
|
||||
}
|
||||
concernAdapter.notifyDataSetChanged();
|
||||
GameEntity concernGame = concernRecommendAdapter.concernGame(changed.getGameId());
|
||||
|
||||
if (concernGame != null) {
|
||||
concernAdapter.getConcernGameList().add(0, concernGame);
|
||||
concernAdapter.notifyDataSetChanged();
|
||||
if (mNoneData.getVisibility() == View.VISIBLE) {
|
||||
mNoneData.setVisibility(View.GONE);
|
||||
mConcernRv.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0, size = concernRecommendAdapter.getRecommendGameList().size(); i < size; i++) {
|
||||
if (changed.getGameId().equals(concernRecommendAdapter.getRecommendGameList().get(i).getId())) {
|
||||
concernRecommendAdapter.getRecommendGameList().remove(i);
|
||||
concernRecommendAdapter.notifyDataSetChanged();
|
||||
concernRecommendAdapter.notifyItemRemoved(i); // 删除动画
|
||||
concernRecommendAdapter.notifyDataSetChanged(); // 防止列表串行
|
||||
if (concernRecommendAdapter.getRecommendGameList().isEmpty()) {
|
||||
mConcernTitleRl.setVisibility(View.GONE);
|
||||
mConcernRecommendRv.setVisibility(View.GONE);
|
||||
}
|
||||
if (concernRecommendAdapter.getRecommendGameList().size() < 4) {
|
||||
mConcernRecommendRv.setLayoutManager(
|
||||
new GridLayoutManager(this, concernRecommendAdapter.getRecommendGameList().size()));
|
||||
} else {
|
||||
mConcernRecommendRv.setLayoutManager(new GridLayoutManager(this, 4));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
concernRecommendAdapter.getRecommendGameList().clear();
|
||||
for (GameEntity gameEntity : concernRecommendAdapter.getGameList()) {
|
||||
if (!concernManager.isConcern(gameEntity.getId())) {
|
||||
concernRecommendAdapter.getRecommendGameList().add(gameEntity);
|
||||
}
|
||||
GameEntity gameEntity = concernAdapter.cancelConcern(changed.getGameId());
|
||||
if (gameEntity != null) {
|
||||
concernRecommendAdapter.getRecommendGameList().add(0, gameEntity);
|
||||
concernRecommendAdapter.notifyDataSetChanged();
|
||||
}
|
||||
concernRecommendAdapter.notifyDataSetChanged();
|
||||
|
||||
if (concernRecommendAdapter.getRecommendGameList().isEmpty()) {
|
||||
mConcernTitleRl.setVisibility(View.GONE);
|
||||
mConcernRecommendRv.setVisibility(View.GONE);
|
||||
@ -236,12 +197,16 @@ public class ConcernActivity extends BaseActivity implements OnClickListener, On
|
||||
mConcernTitleRl.setVisibility(View.VISIBLE);
|
||||
mConcernRecommendRv.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (concernRecommendAdapter.getRecommendGameList().size() < 4) {
|
||||
mConcernRecommendRv.setLayoutManager(
|
||||
new GridLayoutManager(this, concernRecommendAdapter.getRecommendGameList().size()));
|
||||
} else {
|
||||
mConcernRecommendRv.setLayoutManager(new GridLayoutManager(this, 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 登录事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBReuse reuse) {
|
||||
if (reuse.getType().equals(LOGIN_TAG)) { // 登入
|
||||
concernAdapter = new ConcernAdapter(this, this, mEntrance);
|
||||
mConcernRv.setAdapter(concernAdapter);
|
||||
mConcernRv.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ import com.gh.common.util.BitmapUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.common.view.CropImageCustom;
|
||||
import com.lightgame.download.FileUtils;
|
||||
|
||||
@ -74,7 +74,7 @@ public class CropImageActivity extends BaseActivity {
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context, String picturePath, String entrance) {
|
||||
Intent intent = new Intent(context, CropImageActivity.class);
|
||||
intent.putExtra("path", picturePath);
|
||||
intent.putExtra(EntranceUtils.KEY_PATH, picturePath);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
return intent;
|
||||
}
|
||||
@ -119,13 +119,13 @@ public class CropImageActivity extends BaseActivity {
|
||||
handler.sendEmptyMessage(1);
|
||||
return null;
|
||||
}
|
||||
return TokenUtils.getToken(CropImageActivity.this, true);
|
||||
return Observable.just(LoginUtils.getToken(CropImageActivity.this));
|
||||
}
|
||||
}).flatMap(new Func1<String, Observable<JSONObject>>() {
|
||||
@Override
|
||||
public Observable<JSONObject> call(String token) {
|
||||
if (token != null) {
|
||||
return Observable.just(FileUtils.uploadFile(Config.USER_HOST + "icon", path, token));
|
||||
return Observable.just(FileUtils.uploadFile(Config.API_HOST + "support/upload/img?type=icon", path, token));
|
||||
}
|
||||
dialog.dismiss();
|
||||
handler.sendEmptyMessage(1);
|
||||
@ -137,13 +137,7 @@ public class CropImageActivity extends BaseActivity {
|
||||
if (result != null) {
|
||||
try {
|
||||
if (result.getInt("statusCode") == 401) {
|
||||
return TokenUtils.getToken(CropImageActivity.this, false)
|
||||
.flatMap(new Func1<String, Observable<JSONObject>>() {
|
||||
@Override
|
||||
public Observable<JSONObject> call(String token) {
|
||||
return Observable.just(FileUtils.uploadFile(Config.USER_HOST + "icon", path, token));
|
||||
}
|
||||
});
|
||||
return Observable.just(FileUtils.uploadFile(Config.API_HOST + "support/upload/img?type=icon", path, LoginUtils.getToken(CropImageActivity.this)));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@ -190,7 +184,7 @@ public class CropImageActivity extends BaseActivity {
|
||||
sp.edit().putString("updateIconCount", jsonObject.toString()).apply();
|
||||
|
||||
Intent data = new Intent();
|
||||
data.putExtra("url", result.getString("icon"));
|
||||
data.putExtra(EntranceUtils.KEY_URL, result.getString("icon"));
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
|
||||
@ -232,7 +226,7 @@ public class CropImageActivity extends BaseActivity {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
if (hasFocus && (reference == null || reference.get() == null)) {
|
||||
ImageView imageView = mCropimageCustom.getCropImageZoomView();
|
||||
Bitmap bitmap = BitmapUtils.getBitmapByFile(getIntent().getStringExtra("path"),
|
||||
Bitmap bitmap = BitmapUtils.getBitmapByFile(getIntent().getStringExtra(EntranceUtils.KEY_PATH),
|
||||
imageView.getWidth(), imageView.getHeight());
|
||||
if (bitmap != null) {
|
||||
reference = new SoftReference<>(bitmap);
|
||||
|
||||
@ -21,16 +21,18 @@ public class DownloadManagerActivity extends BaseActivity {
|
||||
|
||||
public static final String TAG = "DownloadManagerActivity";
|
||||
|
||||
|
||||
// TODO: 20/09/17 增加currentItem 入口 插件更新可能需要
|
||||
public static Intent getDownloadMangerIntent(Context context, String url, String entrance) {
|
||||
Intent intent = new Intent(context, DownloadManagerActivity.class);
|
||||
intent.putExtra("url", url);
|
||||
intent.putExtra(EntranceUtils.KEY_URL, url);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static void startDownloadManagerActivity(Context context, String url, String entrance) {
|
||||
Intent intent = new Intent(context, DownloadManagerActivity.class);
|
||||
intent.putExtra("url", url);
|
||||
intent.putExtra(EntranceUtils.KEY_URL, url);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
@ -47,14 +49,24 @@ public class DownloadManagerActivity extends BaseActivity {
|
||||
|
||||
initTitle(getString(R.string.title_downloadmanager));
|
||||
|
||||
int currentItem = getIntent().getIntExtra("currentItem", 0);
|
||||
if (getIntent().getBundleExtra("data") != null) {
|
||||
currentItem = getIntent().getBundleExtra("data").getInt("currentItem", 0);
|
||||
startDownloadFragment();
|
||||
}
|
||||
|
||||
private void startDownloadFragment() {
|
||||
int currentItem = getIntent().getIntExtra(EntranceUtils.KEY_CURRENTITEM, 0);
|
||||
Bundle data = getIntent().getBundleExtra(EntranceUtils.KEY_DATA);
|
||||
if (data != null) {
|
||||
currentItem = data.getInt(EntranceUtils.KEY_CURRENTITEM, 0);
|
||||
}
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(
|
||||
R.id.layout_fragment_content, DownloadFragment.newInstance(currentItem)).commitAllowingStateLoss();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
startDownloadFragment();
|
||||
setIntent(intent);
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
@ -22,13 +21,12 @@ import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.StringUtils;
|
||||
import com.gh.common.util.UserIconUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.FileReceiverAdapter;
|
||||
import com.gh.gamecenter.adapter.FileReceiverAdapter.OnReceiverCancelListener;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadChanged;
|
||||
@ -43,9 +41,11 @@ import com.gh.gamecenter.kuaichuan.IpPortInfo;
|
||||
import com.gh.gamecenter.kuaichuan.KuaichuanNotification;
|
||||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.download.DownloadDao;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
import com.lightgame.download.DownloadStatus;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
@ -243,14 +243,16 @@ public class FileReceiverActivity extends BaseActivity implements OnReceiverCanc
|
||||
}
|
||||
}
|
||||
List<DownloadEntity> all = DownloadDao.getInstance(this).getAll();
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.VISIBLE, all.size()));
|
||||
if (all.size() > 0) {
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.VISIBLE, all.size()));
|
||||
}
|
||||
EventBus.getDefault().post(new EBDownloadStatus("download"));
|
||||
|
||||
mReceiverServer.close();
|
||||
// AppController.remove("FileInfo");
|
||||
// HaloApp.remove("FileInfo");
|
||||
mFileInfos.clear();
|
||||
|
||||
AppController.put("sendData", sendData);
|
||||
HaloApp.put("sendData", sendData);
|
||||
|
||||
finish();
|
||||
}
|
||||
@ -262,7 +264,7 @@ public class FileReceiverActivity extends BaseActivity implements OnReceiverCanc
|
||||
|
||||
isDestroy = false;
|
||||
|
||||
// mFileInfos = (List<FileInfo>) AppController.get("FileInfo", false);
|
||||
// mFileInfos = (List<FileInfo>) HaloApp.get("FileInfo", false);
|
||||
|
||||
sendData = new ArrayList<>();
|
||||
|
||||
@ -273,6 +275,7 @@ public class FileReceiverActivity extends BaseActivity implements OnReceiverCanc
|
||||
|
||||
mFileReceiverAdapter = new FileReceiverAdapter(this, this, mFileInfos);
|
||||
mReceiverRv.setLayoutManager(new LinearLayoutManager(this));
|
||||
mReceiverRv.addItemDecoration(new VerticalItemDecoration(this, 8, true));
|
||||
mReceiverRv.setAdapter(mFileReceiverAdapter);
|
||||
|
||||
|
||||
@ -318,9 +321,9 @@ public class FileReceiverActivity extends BaseActivity implements OnReceiverCanc
|
||||
*/
|
||||
private void initServer() {
|
||||
mReceiverServer = new ServerRunnable(Constant.DEFAULT_SERVER_PORT);
|
||||
AppController.MAIN_EXECUTOR.execute(mReceiverServer);
|
||||
HaloApp.MAIN_EXECUTOR.execute(mReceiverServer);
|
||||
|
||||
AppController.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
HaloApp.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -368,7 +371,7 @@ public class FileReceiverActivity extends BaseActivity implements OnReceiverCanc
|
||||
}
|
||||
|
||||
private void sendMessageToSender(final String sendData) throws Exception {
|
||||
AppController.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
HaloApp.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -391,12 +394,12 @@ public class FileReceiverActivity extends BaseActivity implements OnReceiverCanc
|
||||
* @param msg
|
||||
*/
|
||||
private void parseFileInfo(String msg) {
|
||||
// mFileInfos = (List<FileInfo>) AppController.get("FileInfo", false); // mFileInfos 数据异常 需要重新获取
|
||||
// mFileInfos = (List<FileInfo>) HaloApp.get("FileInfo", false); // mFileInfos 数据异常 需要重新获取
|
||||
FileInfo fileInfo = FileInfo.toObject(msg);
|
||||
if (fileInfo != null && fileInfo.getFilePath() != null) {
|
||||
mFileInfos.add(fileInfo);
|
||||
Utils.log("FileReceiverActivity 添加一条数据::" + msg);
|
||||
// AppController.put("FileInfo", mFileInfos);
|
||||
// HaloApp.put("FileInfo", mFileInfos);
|
||||
|
||||
}
|
||||
}
|
||||
@ -508,7 +511,7 @@ public class FileReceiverActivity extends BaseActivity implements OnReceiverCanc
|
||||
mKeepReceiverTv.setBackgroundResource(R.drawable.game_item_btn_pause_style);
|
||||
Utils.toast(FileReceiverActivity.this, "无需操作,请让对方继续发送即可");
|
||||
} else { // 跳转安装包清理
|
||||
startActivity(new Intent(this, CleanApkActivity.class));
|
||||
startActivity(CleanApkActivity.getIntent(this));
|
||||
}
|
||||
break;
|
||||
|
||||
@ -647,7 +650,7 @@ public class FileReceiverActivity extends BaseActivity implements OnReceiverCanc
|
||||
}
|
||||
});
|
||||
|
||||
AppController.MAIN_EXECUTOR.execute(mFileReceiver);
|
||||
HaloApp.MAIN_EXECUTOR.execute(mFileReceiver);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@ -18,16 +18,17 @@ import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.UserIconUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.FileSenderAdapter;
|
||||
import com.gh.gamecenter.kuaichuan.Constant;
|
||||
import com.gh.gamecenter.kuaichuan.FileInfo;
|
||||
import com.gh.gamecenter.kuaichuan.FileSender;
|
||||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -72,6 +73,8 @@ public class FileSenderActivity extends BaseActivity implements FileSenderAdapte
|
||||
private List<Map<String, String>> sendData; // 传送成绩单数据
|
||||
private List<FileSender> mFileSenderList;
|
||||
|
||||
public final static int KC_REPEAT_RESULT = 15; // 快传继续发送获取APK信息回调
|
||||
|
||||
private boolean isSendOver;
|
||||
private boolean isDestroy;
|
||||
|
||||
@ -120,10 +123,10 @@ public class FileSenderActivity extends BaseActivity implements FileSenderAdapte
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == 0x130 && requestCode == 0x178) {
|
||||
if (resultCode == KC_REPEAT_RESULT && requestCode == KC_REPEAT_RESULT) {
|
||||
mSenderAdapter.notifyDataSetChanged();
|
||||
initUserData();
|
||||
AppController.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
HaloApp.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -172,7 +175,7 @@ public class FileSenderActivity extends BaseActivity implements FileSenderAdapte
|
||||
super.onCreate(savedInstanceState);
|
||||
initTitle(getString(R.string.title_file_sender));
|
||||
|
||||
mFileInfos = (List<FileInfo>) AppController.get("FileInfo", false);
|
||||
mFileInfos = (List<FileInfo>) HaloApp.get("FileInfo", false);
|
||||
|
||||
isDestroy = false;
|
||||
|
||||
@ -180,6 +183,7 @@ public class FileSenderActivity extends BaseActivity implements FileSenderAdapte
|
||||
mFileSenderList = new ArrayList<>();
|
||||
mSenderAdapter = new FileSenderAdapter(this, this, mFileInfos);
|
||||
mSenderRv.setLayoutManager(new LinearLayoutManager(this));
|
||||
mSenderRv.addItemDecoration(new VerticalItemDecoration(this, 8, true));
|
||||
mSenderRv.setAdapter(mSenderAdapter);
|
||||
|
||||
init();
|
||||
@ -234,7 +238,7 @@ public class FileSenderActivity extends BaseActivity implements FileSenderAdapte
|
||||
private void initUserData() {
|
||||
isSendOver = false;
|
||||
|
||||
Map<String, String> map = (Map<String, String>) AppController.get("userMap", false);
|
||||
Map<String, String> map = (Map<String, String>) HaloApp.get("userMap", false);
|
||||
|
||||
long allGameSize = 0;
|
||||
for (FileInfo mFileInfo : mFileInfos) {
|
||||
@ -260,7 +264,7 @@ public class FileSenderActivity extends BaseActivity implements FileSenderAdapte
|
||||
Utils.log("====FileSenderActivity传送个数::" + mFileInfos.size());
|
||||
|
||||
|
||||
// TODO: 发送的首个游戏 socket被拒绝的概率较大 延迟0.5秒发送试试
|
||||
//发送的首个游戏 socket被拒绝的概率较大 延迟0.5秒发送试试
|
||||
Thread.sleep(500); //test
|
||||
|
||||
for (final FileInfo fileInfo : mFileInfos) {
|
||||
@ -323,12 +327,12 @@ public class FileSenderActivity extends BaseActivity implements FileSenderAdapte
|
||||
|
||||
});
|
||||
mFileSenderList.add(fileSender);
|
||||
AppController.FILE_SENDER_EXECUTOR.execute(fileSender);
|
||||
HaloApp.FILE_SENDER_EXECUTOR.execute(fileSender);
|
||||
}
|
||||
}
|
||||
|
||||
private void startReceiver() {
|
||||
AppController.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
HaloApp.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -348,8 +352,8 @@ public class FileSenderActivity extends BaseActivity implements FileSenderAdapte
|
||||
}
|
||||
|
||||
stopAllFileSendingTask();
|
||||
AppController.remove("FileInfo");
|
||||
AppController.put("sendData", sendData);
|
||||
HaloApp.remove("FileInfo");
|
||||
HaloApp.put("sendData", sendData);
|
||||
|
||||
FileSenderActivity.this.finish();
|
||||
}
|
||||
@ -478,7 +482,7 @@ public class FileSenderActivity extends BaseActivity implements FileSenderAdapte
|
||||
backHint();
|
||||
break;
|
||||
case R.id.sender_keep_send:
|
||||
startActivityForResult(KcSelectGameActivity.getIntent(this, true), 0x178);
|
||||
startActivityForResult(KcSelectGameActivity.getIntent(this, true), KC_REPEAT_RESULT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@ -7,14 +7,15 @@ import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.BaseActivity;
|
||||
@ -27,6 +28,7 @@ import com.gh.common.util.DataCollectionUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DetailDownloadUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.ShareUtils;
|
||||
@ -35,13 +37,13 @@ import com.gh.gamecenter.adapter.viewholder.DetailViewHolder;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameDetailEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.UserDataEntity;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.gamedetail.FuliFragment;
|
||||
import com.gh.gamecenter.gamedetail.XinXiFragment;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.jakewharton.rxbinding.view.RxView;
|
||||
@ -51,6 +53,7 @@ import com.lightgame.utils.Utils;
|
||||
import com.lightgame.view.NoScrollableViewPager;
|
||||
import com.tencent.tauth.Tencent;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
@ -76,6 +79,7 @@ public class GameDetailActivity extends BaseActivity {
|
||||
public static final String SKIP_XINXI = "skipXinxi";
|
||||
public static final String SKIP_FULI = "skipFuli";
|
||||
public static final String OPEN_APPBAR = "openappbar";
|
||||
public static final String SCROLL_TO_KAIFU = "scrollToKaiFu";
|
||||
|
||||
@BindView(R.id.gamedetail_vp)
|
||||
NoScrollableViewPager mViewPager;
|
||||
@ -99,21 +103,30 @@ public class GameDetailActivity extends BaseActivity {
|
||||
TextView mTanBarFuLiTv;
|
||||
@BindView(R.id.gamedetail_tabbar_xinxi_tv)
|
||||
TextView mTanBarXinXiTv;
|
||||
@BindView(R.id.gamedetail_share)
|
||||
ImageView mShareIv;
|
||||
@BindView(R.id.gamedetail_appbar)
|
||||
AppBarLayout mAppBarLayout;
|
||||
@BindView(R.id.gamedetail_kaifu_hint)
|
||||
View mKaifuHint;
|
||||
@BindView(R.id.gamedetail_iv_libao)
|
||||
View mLibaoIcon;
|
||||
@BindView(R.id.gamedetail_game_server_type)
|
||||
TextView mServerType;
|
||||
|
||||
View mShareIv;
|
||||
|
||||
private ConcernManager mConcernManager;
|
||||
private String mGameId;
|
||||
private GameEntity mGameEntity;
|
||||
private DownloadEntity mDownloadEntity;
|
||||
private GameDetailEntity mGameDetailEntity;
|
||||
private String downloadAddWord;
|
||||
private String downloadOffText;
|
||||
private String name; // 页面位置
|
||||
private String title; // 页面标题
|
||||
private String shareCode;
|
||||
private boolean mIsTouchScreen = false;
|
||||
private boolean mIsShowKaifuHint;
|
||||
private boolean mIsScrollToKaiFu;
|
||||
private int mCurVpPosition;
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
@ -154,7 +167,7 @@ public class GameDetailActivity extends BaseActivity {
|
||||
public static void startGameDetailActivity(Context context, String gameId, String entrance) {
|
||||
Intent intent = new Intent(context, GameDetailActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra("gameId", gameId);
|
||||
intent.putExtra(EntranceUtils.KEY_GAMEID, gameId);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
@ -182,21 +195,27 @@ public class GameDetailActivity extends BaseActivity {
|
||||
|
||||
initTitle("");
|
||||
|
||||
mViewPager.setScrollable(true);
|
||||
// 增加actionBar Button
|
||||
RelativeLayout reuse_actionbar = mContentView.findViewById(R.id.reuse_actionbar);
|
||||
mShareIv = LayoutInflater.from(this).inflate(R.layout.menu_action_share, reuse_actionbar, false); // 绑定parentView 否则会丢失宽高
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mShareIv.getLayoutParams();
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
params.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
reuse_actionbar.addView(mShareIv, params);
|
||||
|
||||
mConcernManager = new ConcernManager(this);
|
||||
mViewPager.setScrollable(true);
|
||||
|
||||
name = "游戏详情";
|
||||
|
||||
mGameId = getIntent().getStringExtra("gameId");
|
||||
mGameId = getIntent().getStringExtra(EntranceUtils.KEY_GAMEID);
|
||||
mEntrance = getIntent().getStringExtra(EntranceUtils.KEY_ENTRANCE);
|
||||
if (getIntent().getBundleExtra("data") != null) {
|
||||
mGameId = getIntent().getBundleExtra("data").getString("gameId");
|
||||
Bundle data = getIntent().getBundleExtra(EntranceUtils.KEY_DATA);
|
||||
if (data != null) {
|
||||
mGameId = data.getString(EntranceUtils.KEY_GAMEID);
|
||||
}
|
||||
|
||||
if (mGameId == null) {
|
||||
mGameEntity = getIntent().getParcelableExtra(GameEntity.class.getSimpleName());
|
||||
// mGameEntity = getIntent().getExtras().getParcelable(GameEntity.class.getSimpleName());
|
||||
if (mGameEntity != null) {
|
||||
mGameId = mGameEntity.getId();
|
||||
mTitle.setText(mGameEntity.getName());
|
||||
@ -225,14 +244,19 @@ public class GameDetailActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
mCurVpPosition = position;
|
||||
if (position == 0) {
|
||||
if (mIsShowKaifuHint) {
|
||||
mKaifuHint.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mTanBarFuLiTv.setTextColor(Color.WHITE);
|
||||
mTanBarFuLiTv.setBackgroundResource(R.drawable.gamedetail_tag_select_bg);
|
||||
mTanBarFuLiTv.setBackgroundResource(R.drawable.tabbar_left_bg);
|
||||
mTanBarXinXiTv.setTextColor(Color.BLACK);
|
||||
mTanBarXinXiTv.setBackgroundDrawable(new ColorDrawable(0));
|
||||
} else {
|
||||
mKaifuHint.setVisibility(View.GONE);
|
||||
mTanBarXinXiTv.setTextColor(Color.WHITE);
|
||||
mTanBarXinXiTv.setBackgroundResource(R.drawable.gamedetail_tag_unselect_bg);
|
||||
mTanBarXinXiTv.setBackgroundResource(R.drawable.tabbar_right_bg);
|
||||
mTanBarFuLiTv.setTextColor(Color.BLACK);
|
||||
mTanBarFuLiTv.setBackgroundDrawable(new ColorDrawable(0));
|
||||
}
|
||||
@ -253,9 +277,31 @@ public class GameDetailActivity extends BaseActivity {
|
||||
} else {
|
||||
mTitle.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (Math.abs(verticalOffset) == total && mIsScrollToKaiFu) {
|
||||
mIsScrollToKaiFu = false;
|
||||
EventBus.getDefault().post(new EBReuse("scrollToKaiFu"));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 防抖处理
|
||||
RxView.clicks(mShareIv)
|
||||
.throttleFirst(1, TimeUnit.SECONDS)
|
||||
.subscribe(new Action1<Void>() {
|
||||
@Override
|
||||
public void call(Void aVoid) {
|
||||
if (TextUtils.isEmpty(shareCode)) return;
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("点击", "分享");
|
||||
DataUtils.onEvent(GameDetailActivity.this, "插件数据", mGameEntity.getName(), kv);
|
||||
|
||||
DataCollectionUtils.uploadClick(GameDetailActivity.this, "分享", "游戏详情", mGameEntity.getName());
|
||||
|
||||
String url = "http://www.ghzs666.com/game/" + shareCode;
|
||||
showShare(url, mGameEntity.getName(), mGameEntity.getIcon(), null, mGameEntity.getTag(), false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -280,12 +326,12 @@ public class GameDetailActivity extends BaseActivity {
|
||||
mLoading.setVisibility(View.GONE);
|
||||
mAppBarLayout.setVisibility(View.VISIBLE);
|
||||
|
||||
if (mConcernManager.isConcern(mGameEntity.getId())) {
|
||||
mGameConcern.setText("取消关注");
|
||||
if (mGameDetailEntity.getUserData() != null && mGameDetailEntity.getUserData().isGameConcerned()) {
|
||||
mGameConcern.setText(getString(R.string.cancel_concern));
|
||||
mGameConcern.setBackgroundResource(R.drawable.border_red_bg);
|
||||
mGameConcern.setTextColor(Color.parseColor("#ff4147"));
|
||||
mGameConcern.setTextColor(ContextCompat.getColor(this, R.color.red));
|
||||
} else {
|
||||
mGameConcern.setText("关注");
|
||||
mGameConcern.setText(getString(R.string.concern));
|
||||
mGameConcern.setBackgroundResource(R.drawable.textview_concern_red_style);
|
||||
mGameConcern.setTextColor(0xffffffff);
|
||||
}
|
||||
@ -298,11 +344,38 @@ public class GameDetailActivity extends BaseActivity {
|
||||
ApkEntity apkEntity = mGameEntity.getApk().get(0);
|
||||
mGameInfo.setText(String.format("V%s | %s", apkEntity.getVersion(), apkEntity.getSize()));
|
||||
}
|
||||
|
||||
int paddRight = 0;
|
||||
String serverType = mGameEntity.getServerType();
|
||||
if (TextUtils.isEmpty(serverType)) {
|
||||
mServerType.setVisibility(View.GONE);
|
||||
} else {
|
||||
mServerType.setVisibility(View.VISIBLE);
|
||||
mServerType.setText(serverType);
|
||||
if ("删档内测".equals(serverType) || "不删档内测".equals(serverType)) {
|
||||
mServerType.setBackgroundResource(R.drawable.textview_server_tag);
|
||||
if ("删档内测".equals(serverType)) {
|
||||
paddRight = DisplayUtils.dip2px(this, 50);
|
||||
} else {
|
||||
paddRight = DisplayUtils.dip2px(this, 60);
|
||||
}
|
||||
} else {
|
||||
mServerType.setBackgroundResource(R.drawable.textview_orange_up);
|
||||
paddRight = DisplayUtils.dip2px(this, 30);
|
||||
}
|
||||
}
|
||||
mGameName.setPadding(0, 0, paddRight, 0);
|
||||
|
||||
if (mGameEntity.isLibaoExists()) {
|
||||
mLibaoIcon.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mLibaoIcon.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取游戏摘要
|
||||
private void getGameDigest() {
|
||||
RetrofitManager.getApi().getGameDigest(mGameId)
|
||||
RetrofitManager.getInstance(this).getApi().getGameDigest(mGameId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@ -319,7 +392,6 @@ public class GameDetailActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
Utils.log("=======onError::getGameDetail");
|
||||
mLoading.setVisibility(View.GONE);
|
||||
mNoConnection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
@ -329,7 +401,7 @@ public class GameDetailActivity extends BaseActivity {
|
||||
// 获取游戏详情
|
||||
public void getGameDetail() {
|
||||
|
||||
RetrofitManager.getApi().getGameDetail(mGameId)
|
||||
RetrofitManager.getInstance(this).getApi().getGameDetail(mGameId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameDetailEntity>() {
|
||||
@ -343,6 +415,8 @@ public class GameDetailActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void onResponse(GameDetailEntity response) {
|
||||
mGameDetailEntity = response;
|
||||
|
||||
// 过滤过期公告
|
||||
if (response.getNotice() != null && response.getNotice().size() > 0) {
|
||||
long l = System.currentTimeMillis();
|
||||
@ -376,7 +450,7 @@ public class GameDetailActivity extends BaseActivity {
|
||||
|
||||
DetailDownloadUtils.detailInitDownload(getDetailViewHolder(), true);
|
||||
|
||||
if (!mConcernManager.isConcern(mGameId)) {
|
||||
if (mGameDetailEntity.getUserData() == null || !mGameDetailEntity.getUserData().isGameConcerned()) {
|
||||
mTanBarXinXiTv.performClick();
|
||||
}
|
||||
}
|
||||
@ -405,6 +479,19 @@ public class GameDetailActivity extends BaseActivity {
|
||||
mAppBarLayout.setExpanded(true, true);
|
||||
} else if (SKIP_FULI.equals(reuse.getType())) {
|
||||
mViewPager.setCurrentItem(0);
|
||||
} else if ("hideKaifuHint".equals(reuse.getType())) {
|
||||
mIsShowKaifuHint = false;
|
||||
mKaifuHint.setVisibility(View.GONE);
|
||||
} else if ("showKaifuHint".equals(reuse.getType())) {
|
||||
mIsShowKaifuHint = true;
|
||||
if (mCurVpPosition == 0) {
|
||||
mKaifuHint.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mKaifuHint.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -441,15 +528,20 @@ public class GameDetailActivity extends BaseActivity {
|
||||
// 关注事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBConcernChanged changed) {
|
||||
if (mGameEntity != null && changed.isSingle() && changed.getGameId().equals(mGameEntity.getId())) {
|
||||
if (mGameDetailEntity != null && mGameEntity != null && changed.isSingle() && changed.getGameId().equals(mGameEntity.getId())) {
|
||||
if (mGameDetailEntity.getUserData() == null) {
|
||||
mGameDetailEntity.setUserData(new UserDataEntity());
|
||||
}
|
||||
mGameDetailEntity.getUserData().setGameConcerned(changed.isConcern());
|
||||
initGameDetailTop();
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick({R.id.detail_tv_download, R.id.detail_pb_progressbar, R.id.reuse_no_connection
|
||||
, R.id.detail_tv_per, R.id.gamedetail_tabbar_xinxi_tv, R.id.gamedetail_tv_concern
|
||||
, R.id.gamedetail_tabbar_fuli_tv, R.id.gamedetail_share})
|
||||
, R.id.detail_tv_per, R.id.gamedetail_tabbar_xinxi_tv, R.id.gamedetail_tabbar_fuli_tv
|
||||
, R.id.gamedetail_kaifu_hint, R.id.gamedetail_tv_concern})
|
||||
public void onClick(View v) {
|
||||
|
||||
switch (v.getId()) {
|
||||
case R.id.gamedetail_tabbar_fuli_tv:
|
||||
mViewPager.setCurrentItem(0);
|
||||
@ -457,25 +549,6 @@ public class GameDetailActivity extends BaseActivity {
|
||||
case R.id.gamedetail_tabbar_xinxi_tv:
|
||||
mViewPager.setCurrentItem(1);
|
||||
break;
|
||||
case R.id.gamedetail_share:
|
||||
if (TextUtils.isEmpty(shareCode)) return;
|
||||
// 防抖处理
|
||||
RxView.clicks(mShareIv)
|
||||
.throttleFirst(1, TimeUnit.SECONDS)
|
||||
.subscribe(new Action1<Void>() {
|
||||
@Override
|
||||
public void call(Void aVoid) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("点击", "分享");
|
||||
DataUtils.onEvent(GameDetailActivity.this, "插件数据", mGameEntity.getName(), kv);
|
||||
|
||||
DataCollectionUtils.uploadClick(GameDetailActivity.this, "分享", "游戏详情", mGameEntity.getName());
|
||||
|
||||
String url = "http://www.ghzs666.com/game/" + shareCode;
|
||||
showShare(url, mGameEntity.getName(), mGameEntity.getIcon(), null, mGameEntity.getTag(), false);
|
||||
}
|
||||
});
|
||||
break;
|
||||
case R.id.reuse_no_connection:
|
||||
mLoading.setVisibility(View.VISIBLE);
|
||||
mNoConnection.setVisibility(View.GONE);
|
||||
@ -490,27 +563,37 @@ public class GameDetailActivity extends BaseActivity {
|
||||
CheckLoginUtils.checkLogin(GameDetailActivity.this, new CheckLoginUtils.OnLoggenInListener() {
|
||||
@Override
|
||||
public void onLoggedIn() {
|
||||
if ("关注".equals(mGameConcern.getText().toString())) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("状态", "关注");
|
||||
DataUtils.onEvent(GameDetailActivity.this, "游戏关注", mGameEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<>();
|
||||
kv2.put("点击", "关注");
|
||||
DataUtils.onEvent(GameDetailActivity.this, "插件数据", mGameEntity.getName(), kv2);
|
||||
|
||||
DataCollectionUtils.uploadConcern(GameDetailActivity.this, mGameEntity.getName(), mGameEntity.getId(), "关注");
|
||||
|
||||
mConcernManager.addByEntity(mGameEntity);
|
||||
mGameConcern.setText("取消关注");
|
||||
mGameConcern.setBackgroundResource(R.drawable.border_red_bg);
|
||||
mGameConcern.setTextColor(Color.parseColor("#ff4147"));
|
||||
|
||||
Toast.makeText(GameDetailActivity.this, "关注成功", Toast.LENGTH_SHORT).show();
|
||||
|
||||
mGameConcern.setEnabled(false);
|
||||
if (getString(R.string.concern).equals(mGameConcern.getText().toString())) {
|
||||
// 添加关注
|
||||
ConcernUtils.INSTANCE.postConcernGameId(GameDetailActivity.this, mGameEntity.getId());
|
||||
ConcernUtils.INSTANCE.postConcernGameId(GameDetailActivity.this, mGameEntity.getId()
|
||||
, new ConcernUtils.onConcernListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("状态", R.string.concern);
|
||||
DataUtils.onEvent(GameDetailActivity.this, "游戏关注", mGameEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<>();
|
||||
kv2.put("点击", R.string.concern);
|
||||
DataUtils.onEvent(GameDetailActivity.this, "插件数据", mGameEntity.getName(), kv2);
|
||||
|
||||
DataCollectionUtils.uploadConcern(GameDetailActivity.this, mGameEntity.getName(), mGameEntity.getId(), "关注");
|
||||
|
||||
mGameConcern.setText(R.string.cancel_concern);
|
||||
mGameConcern.setBackgroundResource(R.drawable.border_red_bg);
|
||||
mGameConcern.setTextColor(ContextCompat.getColor(GameDetailActivity.this, R.color.red));
|
||||
|
||||
toast(R.string.concern_success);
|
||||
mGameConcern.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
mGameConcern.setEnabled(true);
|
||||
toast(R.string.concern_failure);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Map<String, Object> kv2 = new HashMap<>();
|
||||
kv2.put("点击", "取消关注");
|
||||
@ -519,26 +602,45 @@ public class GameDetailActivity extends BaseActivity {
|
||||
DialogUtils.showCancelDialog(GameDetailActivity.this, new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("状态", "取消关注");
|
||||
DataUtils.onEvent(GameDetailActivity.this, "游戏关注", mGameEntity.getName(), kv);
|
||||
|
||||
DataCollectionUtils.uploadConcern(GameDetailActivity.this,
|
||||
mGameEntity.getName(), mGameEntity.getId(), "取消关注");
|
||||
|
||||
mConcernManager.deleteConcern(mGameEntity.getId());
|
||||
mGameConcern.setText("关注");
|
||||
mGameConcern.setBackgroundResource(R.drawable.textview_concern_red_style);
|
||||
mGameConcern.setTextColor(0xffffffff);
|
||||
|
||||
// 取消关注
|
||||
ConcernUtils.INSTANCE.deleteConcernData(GameDetailActivity.this, mGameEntity.getId());
|
||||
ConcernUtils.INSTANCE.deleteConcernData(GameDetailActivity.this, mGameEntity.getId()
|
||||
, new ConcernUtils.onConcernListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("状态", "取消关注");
|
||||
DataUtils.onEvent(GameDetailActivity.this, "游戏关注", mGameEntity.getName(), kv);
|
||||
|
||||
DataCollectionUtils.uploadConcern(GameDetailActivity.this,
|
||||
mGameEntity.getName(), mGameEntity.getId(), "取消关注");
|
||||
|
||||
mGameConcern.setText(getString(R.string.concern));
|
||||
mGameConcern.setBackgroundResource(R.drawable.textview_concern_red_style);
|
||||
mGameConcern.setTextColor(0xffffffff);
|
||||
mGameConcern.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
mGameConcern.setEnabled(true);
|
||||
toast(R.string.cancel_concern_failure);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, new DialogUtils.CancelListener() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
mGameConcern.setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
case R.id.gamedetail_kaifu_hint:
|
||||
mAppBarLayout.setExpanded(false, true);
|
||||
mIsScrollToKaiFu = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -68,8 +68,8 @@ public class GameNewsActivity extends BaseActivity implements View.OnClickListen
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context, String gameName, String gameId, String entrance) {
|
||||
Intent intent = new Intent(context, GameNewsActivity.class);
|
||||
intent.putExtra("gameName", gameName);
|
||||
intent.putExtra("gameId", gameId);
|
||||
intent.putExtra(EntranceUtils.KEY_GAMENAME, gameName);
|
||||
intent.putExtra(EntranceUtils.KEY_GAMEID, gameId);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
return intent;
|
||||
}
|
||||
@ -97,7 +97,7 @@ public class GameNewsActivity extends BaseActivity implements View.OnClickListen
|
||||
ivSearch.setOnClickListener(this);
|
||||
ivSearch.setVisibility(View.GONE);
|
||||
|
||||
String gameName = getIntent().getStringExtra("gameName");
|
||||
String gameName = getIntent().getStringExtra(EntranceUtils.KEY_GAMENAME);
|
||||
initTitle(gameName);
|
||||
|
||||
mNoDataTv.setText("暂无内容");
|
||||
@ -106,7 +106,7 @@ public class GameNewsActivity extends BaseActivity implements View.OnClickListen
|
||||
|
||||
typeList = new ArrayList<>();
|
||||
|
||||
gameId = getIntent().getStringExtra("gameId");
|
||||
gameId = getIntent().getStringExtra(EntranceUtils.KEY_GAMEID);
|
||||
|
||||
mGameNewsRv.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
@ -163,7 +163,7 @@ public class GameNewsActivity extends BaseActivity implements View.OnClickListen
|
||||
}
|
||||
|
||||
private void getGameArticleType() {
|
||||
RetrofitManager.getApi()
|
||||
RetrofitManager.getInstance(this).getApi()
|
||||
.getGameArticleType(gameId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
||||
@ -17,14 +17,15 @@ import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.view.SwipeLayout;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.lightgame.download.DataWatcher;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.InstallFragmentAdapter;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.lightgame.download.DataWatcher;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
@ -36,6 +37,7 @@ import butterknife.BindView;
|
||||
|
||||
import static com.gh.gamecenter.R.id.reuse_nodata_skip_tv_btn;
|
||||
import static com.gh.gamecenter.R.id.reuse_nodata_skip_tv_hint;
|
||||
import static com.gh.gamecenter.download.FileSendFragment.KC_REQUEST;
|
||||
|
||||
/**
|
||||
* Created by khy on 15/06/17.
|
||||
@ -84,7 +86,7 @@ public class InstallActivity extends BaseActivity implements InstallFragmentAdap
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
|
||||
// 分享成绩单
|
||||
if (requestCode == 0x170 || requestCode == 0x180) {
|
||||
if (requestCode == KC_REQUEST) {
|
||||
DialogUtils.showKuaiChuanResult(this, new Handler(), requestCode, "shareKc.jpg");
|
||||
|
||||
}
|
||||
@ -119,6 +121,7 @@ public class InstallActivity extends BaseActivity implements InstallFragmentAdap
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
for (GameEntity entity : mAdapter.getGameList()) {
|
||||
entity.setEntryMap(DownloadManager.getInstance(this).getEntryMap(entity.getName()));
|
||||
@ -126,7 +129,6 @@ public class InstallActivity extends BaseActivity implements InstallFragmentAdap
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
isEverpause = false;
|
||||
super.onResume();
|
||||
DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@ -178,6 +180,27 @@ public class InstallActivity extends BaseActivity implements InstallFragmentAdap
|
||||
}
|
||||
}
|
||||
|
||||
//下载被删除事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBDownloadStatus status) {
|
||||
if ("delete".equals(status.getStatus())) {
|
||||
DownloadManager.getInstance(this).removePlatform(status.getName(), status.getPlatform());
|
||||
|
||||
ArrayList<Integer> locationList = mAdapter.getLocationMap().get(status.getPackageName());
|
||||
GameEntity gameEntity;
|
||||
if (locationList != null && locationList.size() != 0) {
|
||||
for (int location : locationList) {
|
||||
gameEntity = mAdapter.getGameList().get(location);
|
||||
if (gameEntity != null && gameEntity.getEntryMap() != null) {
|
||||
gameEntity.getEntryMap().remove(status.getPlatform());
|
||||
}
|
||||
mAdapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 滑动item
|
||||
@Override
|
||||
public void onSmooth() {
|
||||
@ -187,4 +210,9 @@ public class InstallActivity extends BaseActivity implements InstallFragmentAdap
|
||||
swipeLayout.openAndColse();
|
||||
// swipeLayout.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen() {
|
||||
startActivityForResult(ChooseReceiverActivity.getIntent(this, true), KC_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,111 +1,43 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.base.OnRequestCallBackListener;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.KaiFuAdapter;
|
||||
import com.gh.gamecenter.adapter.KaiFuDialogAdapter;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.jakewharton.rxbinding.view.RxView;
|
||||
import com.lightgame.download.DataWatcher;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
import com.gh.gamecenter.eventbus.EBKaiFuReset;
|
||||
import com.gh.gamecenter.kaifu.KaiFuFragment;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import butterknife.BindView;
|
||||
import rx.functions.Action1;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/16.
|
||||
* 首页-开服表
|
||||
* Created by khy on 18/08/17.
|
||||
*/
|
||||
public class KaiFuActivity extends BaseActivity implements OnRequestCallBackListener,
|
||||
KaiFuDialogAdapter.OnKaiFuDialogCallBackListener, KaiFuAdapter.OnScrollToKaiFuIndexListener,
|
||||
SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
@BindView(R.id.kaifu_rv)
|
||||
RecyclerView mRecyclerView;
|
||||
@BindView(R.id.kaifu_pb)
|
||||
ProgressBarCircularIndeterminate mPbLoading;
|
||||
@BindView(R.id.kaifu_refresh)
|
||||
SwipeRefreshLayout mRefreshLayout;
|
||||
@BindView(R.id.kaifu_game_name)
|
||||
TextView mGameName;
|
||||
@BindView(R.id.popup_bg)
|
||||
View mPopupBg;
|
||||
@BindView(R.id.kaifu_select_game_rl)
|
||||
RelativeLayout mSelectGameRl;
|
||||
@BindView(R.id.reuse_no_connection)
|
||||
LinearLayout mNoConnection;
|
||||
@BindView(R.id.reuse_none_data)
|
||||
LinearLayout mNoData;
|
||||
private PopupWindow mPopupWindow;
|
||||
public class KaiFuActivity extends BaseActivity {
|
||||
|
||||
private KaiFuAdapter mAdapter;
|
||||
@BindView(R.id.reuse_actionbar)
|
||||
RelativeLayout mReuseActionbar;
|
||||
|
||||
private LinearLayoutManager layoutManager;
|
||||
private TextView mResetTv;
|
||||
|
||||
private boolean isEverpause = false;
|
||||
private boolean move = false;
|
||||
private boolean smoothMove = false;
|
||||
private KaiFuFragment mKaiFuFragment;
|
||||
private KaiFuFragment mGameKaiFuFragment;
|
||||
|
||||
private String kaifuType;
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mAdapter = new KaiFuAdapter(KaiFuActivity.this, KaiFuActivity.this, KaiFuActivity.this, kaifuType);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
};
|
||||
private int mDialogGamePosition; // 顶部弹窗过滤位置
|
||||
private int kaifuOffset = 0;
|
||||
private int mInitMovePosition; // 首次进入移动的位置
|
||||
private int mMovePosition; // 移动位置
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
ArrayList<Integer> locationList = mAdapter.getLocationMap().get(downloadEntity.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
gameEntity = mAdapter.getSubjectList().get(location - getGameEntityIndex());
|
||||
if (gameEntity != null) {
|
||||
DownloadItemUtils.processDate(KaiFuActivity.this, gameEntity, downloadEntity,
|
||||
mAdapter, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
public static final String SINGLE_GAME_KAIFU = "SINGLE_GAME_KAIFU";
|
||||
public static final String ALL_GAME_KAIFU = "ALL_GAME_KAIFU";
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context, String entrance) {
|
||||
@ -114,6 +46,7 @@ public class KaiFuActivity extends BaseActivity implements OnRequestCallBackList
|
||||
return intent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_kaifu;
|
||||
@ -122,365 +55,67 @@ public class KaiFuActivity extends BaseActivity implements OnRequestCallBackList
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
initTitle(getString(R.string.title_kaifu));
|
||||
initTitle("开服表");
|
||||
|
||||
kaifuType = "全部";
|
||||
|
||||
mRefreshLayout.setColorSchemeResources(R.color.theme);
|
||||
mRefreshLayout.setOnRefreshListener(this);
|
||||
mRefreshLayout.setEnabled(false);
|
||||
|
||||
mAdapter = new KaiFuAdapter(this, this, this, kaifuType);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
((DefaultItemAnimator) mRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
|
||||
mRecyclerView.addItemDecoration(new VerticalItemDecoration(this, 8, false));
|
||||
mRecyclerView.setLayoutManager(layoutManager);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
|
||||
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (smoothMove && newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
smoothMove = false;
|
||||
int n = mMovePosition - layoutManager.findFirstVisibleItemPosition();
|
||||
if (0 <= n && n < mRecyclerView.getChildCount()) {
|
||||
View view = layoutManager.findViewByPosition(n);
|
||||
if (view != null) {
|
||||
int top = view.getTop();
|
||||
mRecyclerView.smoothScrollBy(0, top);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//上拉加载
|
||||
if (mAdapter.isLoadedBottom() && newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& mAdapter.getItemCount() == layoutManager.findLastVisibleItemPosition() + 1) {
|
||||
mAdapter.initListBottom(kaifuOffset + mAdapter.loadCountBottom());
|
||||
}
|
||||
//下拉加载
|
||||
if (kaifuOffset > 0 && mAdapter.isLoadedTop() && newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& layoutManager.findFirstVisibleItemPosition() == 0) {
|
||||
int countTop = mAdapter.loadCountTop();
|
||||
// if (countTop % 20 == 0) { // 不是20的倍数 证明加载完毕
|
||||
int offset = kaifuOffset - countTop;
|
||||
int limit = 20;
|
||||
if (offset < 0) {
|
||||
limit = limit + offset;
|
||||
offset = 0;
|
||||
}
|
||||
if (limit == 0) return;
|
||||
|
||||
mAdapter.initListTop(offset, limit);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
if (move) {
|
||||
move = false;
|
||||
int n = mMovePosition - layoutManager.findFirstVisibleItemPosition();
|
||||
if (0 <= n && n < mRecyclerView.getChildCount()) {
|
||||
int top = mRecyclerView.getChildAt(n).getTop();
|
||||
mRecyclerView.scrollBy(0, top);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
mResetTv = new TextView(this);
|
||||
mResetTv.setText("重置");
|
||||
mResetTv.setTextColor(ContextCompat.getColor(this, R.color.title));
|
||||
mResetTv.setGravity(Gravity.CENTER);
|
||||
mResetTv.setVisibility(View.GONE);
|
||||
mResetTv.setBackgroundResource(R.drawable.border_black_bg);
|
||||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
||||
DisplayUtils.dip2px(this, 48), DisplayUtils.dip2px(this, 28));
|
||||
params.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
params.setMargins(0, 0, DisplayUtils.dip2px(this, 8), 0);
|
||||
mReuseActionbar.addView(mResetTv, params);
|
||||
|
||||
|
||||
// 防抖处理
|
||||
RxView.clicks(mSelectGameRl)
|
||||
.throttleFirst(1, TimeUnit.SECONDS)
|
||||
.subscribe(new Action1<Void>() {
|
||||
@Override
|
||||
public void call(Void aVoid) {
|
||||
initSelectGameDialog();
|
||||
}
|
||||
});
|
||||
|
||||
mNoConnection.setOnClickListener(new View.OnClickListener() {
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
mKaiFuFragment = new KaiFuFragment();
|
||||
fragmentTransaction.add(R.id.layout_fragment_content, mKaiFuFragment);
|
||||
fragmentTransaction.commit();
|
||||
mResetTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mAdapter.initKaiFuOffset();
|
||||
mNoConnection.setVisibility(View.GONE);
|
||||
mPbLoading.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void initSelectGameDialog() {
|
||||
isShowPopupBg(true);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.dialog_kaifu_select_game, null);
|
||||
RecyclerView selectGameRv = (RecyclerView) contentView.findViewById(R.id.dialog_kaifu_select_game_rv);
|
||||
final TextView selectGameTitle = (TextView) contentView.findViewById(R.id.dialog_kaifu_title);
|
||||
|
||||
final LinearLayoutManager layout = new LinearLayoutManager(this);
|
||||
selectGameRv.setLayoutManager(layout);
|
||||
selectGameRv.setAdapter(new KaiFuDialogAdapter(this, this, mDialogGamePosition));
|
||||
|
||||
|
||||
mPopupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT
|
||||
, LinearLayout.LayoutParams.MATCH_PARENT, true);
|
||||
mPopupWindow.setAnimationStyle(R.style.scale_popwindow_anim_style);
|
||||
mPopupWindow.showAtLocation(mSelectGameRl, 0, 0, 0);
|
||||
|
||||
selectGameRv.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
|
||||
if (layout.findFirstVisibleItemPosition() >= 5) {
|
||||
selectGameTitle.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
selectGameTitle.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
selectGameRv.setOnKeyListener(new View.OnKeyListener() {
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK
|
||||
&& event.getRepeatCount() == 0
|
||||
&& mPopupWindow != null
|
||||
&& mPopupWindow.isShowing()) {
|
||||
isShowPopupBg(false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
contentView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isShowPopupBg(false);
|
||||
resetFragment();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void moveToPosition(int n, boolean isSmooth) {
|
||||
int firstItem = layoutManager.findFirstVisibleItemPosition();
|
||||
int lastItem = layoutManager.findLastVisibleItemPosition();
|
||||
if (n <= firstItem) {
|
||||
if (isSmooth) {
|
||||
mRecyclerView.smoothScrollToPosition(n);
|
||||
} else {
|
||||
mRecyclerView.scrollToPosition(n);
|
||||
}
|
||||
} else if (n <= lastItem) {
|
||||
int top = layoutManager.findViewByPosition(n).getTop();
|
||||
if (isSmooth) {
|
||||
mRecyclerView.smoothScrollBy(0, top);
|
||||
} else {
|
||||
mRecyclerView.scrollBy(0, top);
|
||||
}
|
||||
} else {
|
||||
if (isSmooth) {
|
||||
mRecyclerView.smoothScrollToPosition(n);
|
||||
smoothMove = true;
|
||||
} else {
|
||||
mRecyclerView.scrollToPosition(n);
|
||||
move = true;
|
||||
}
|
||||
}
|
||||
private void resetFragment() {
|
||||
mKaiFuFragment.setCurPage(mGameKaiFuFragment.getCurPage());
|
||||
|
||||
mResetTv.setVisibility(View.GONE);
|
||||
mKaiFuFragment.onResume(); // 启动观察者
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.remove(mGameKaiFuFragment);
|
||||
fragmentTransaction.show(mKaiFuFragment);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
public void isShowPopupBg(boolean isShow) {
|
||||
if (isShow) {
|
||||
mPopupBg.setVisibility(View.VISIBLE);
|
||||
mPopupBg.animate()
|
||||
.alpha(1f)
|
||||
.setDuration(300)
|
||||
.setListener(null);
|
||||
} else {
|
||||
mPopupWindow.dismiss();
|
||||
mPopupBg.animate()
|
||||
.alpha(0f)
|
||||
.setDuration(300)
|
||||
.setListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mPopupBg.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
DownloadManager.getInstance(getApplicationContext()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
for (GameEntity entity : mAdapter.getSubjectList()) {
|
||||
entity.setEntryMap(DownloadManager.getInstance(this).getEntryMap(entity.getName()));
|
||||
}
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getApplicationContext()).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone() {
|
||||
mNoData.setVisibility(View.GONE);
|
||||
if (mPbLoading != null && mPbLoading.getVisibility() == View.VISIBLE) {
|
||||
mPbLoading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (mRefreshLayout.isRefreshing()) {
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone(Object obj) {
|
||||
kaifuOffset = (int) obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadError() {
|
||||
if (mPbLoading != null && mPbLoading.getVisibility() == View.VISIBLE) {
|
||||
mPbLoading.setVisibility(View.GONE);
|
||||
}
|
||||
toast("加载失败,请检查网络状态");
|
||||
mPbLoading.setVisibility(View.GONE);
|
||||
mNoData.setVisibility(View.GONE);
|
||||
mNoConnection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadEmpty() {
|
||||
mNoData.setVisibility(View.VISIBLE);
|
||||
mNoConnection.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectPosition(int position, String tag, String gameName) {
|
||||
mDialogGamePosition = position;
|
||||
if (!TextUtils.isEmpty(gameName)) {
|
||||
mGameName.setText(gameName);
|
||||
} else {
|
||||
mGameName.setText(tag);
|
||||
}
|
||||
isShowPopupBg(false);
|
||||
|
||||
kaifuOffset = 0;
|
||||
kaifuType = tag;
|
||||
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
mPbLoading.setVisibility(View.VISIBLE);
|
||||
mNoConnection.setVisibility(View.GONE);
|
||||
mNoData.setVisibility(View.GONE);
|
||||
|
||||
mAdapter = new KaiFuAdapter(this, this, this, kaifuType);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
|
||||
}
|
||||
|
||||
// 下载被删除事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBDownloadStatus status) {
|
||||
if ("delete".equals(status.getStatus())) {
|
||||
DownloadManager.getInstance(this).removePlatform(status.getName(), status.getPlatform());
|
||||
|
||||
ArrayList<Integer> locationList = mAdapter.getLocationMap().get(status.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
|
||||
gameEntity = mAdapter.getSubjectList().get(location - getGameEntityIndex());
|
||||
if (gameEntity != null && gameEntity.getEntryMap() != null) {
|
||||
gameEntity.getEntryMap().remove(status.getPlatform());
|
||||
}
|
||||
mAdapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getGameEntityIndex() {
|
||||
if (kaifuOffset != 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
ArrayList<Integer> locationList = mAdapter.getLocationMap().get(busFour.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
gameEntity = mAdapter.getSubjectList().get(location - getGameEntityIndex());
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(busFour.getPackageName())) {
|
||||
if (gameEntity.getEntryMap() != null) {
|
||||
gameEntity.getEntryMap().remove(apkEntity.getPlatform());
|
||||
}
|
||||
mAdapter.notifyItemChanged(location + getGameEntityIndex());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
mAdapter.notifyItemChanged(location + getGameEntityIndex());
|
||||
}
|
||||
}
|
||||
public void onEventMainThread(EBKaiFuReset reset) {
|
||||
if (SINGLE_GAME_KAIFU.equals(reset.getControl())) {
|
||||
mResetTv.setVisibility(View.VISIBLE);
|
||||
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.hide(mKaiFuFragment);
|
||||
mKaiFuFragment.onPause();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString(EntranceUtils.KEY_GAMEID, reset.getGameId());
|
||||
args.putInt("curPage", mKaiFuFragment.getCurPage());
|
||||
|
||||
mGameKaiFuFragment = new KaiFuFragment();
|
||||
mGameKaiFuFragment.setArguments(args);
|
||||
|
||||
fragmentTransaction.add(R.id.layout_fragment_content, mGameKaiFuFragment, KaiFuFragment.class.getSimpleName());
|
||||
fragmentTransaction.commit();
|
||||
} else if (ALL_GAME_KAIFU.equals(reset.getControl())) {
|
||||
resetFragment();
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (mNoConnection.getVisibility() == View.VISIBLE) {
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
mPbLoading.setVisibility(View.VISIBLE);
|
||||
mNoConnection.setVisibility(View.GONE);
|
||||
mAdapter = new KaiFuAdapter(this, this, this, kaifuType);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScroll(int scrollPosition) {
|
||||
mInitMovePosition = scrollPosition + getGameEntityIndex() + 1;
|
||||
moveToPosition(mInitMovePosition, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
mRecyclerView.postDelayed(runnable, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
@ -28,6 +28,8 @@ import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
import static com.gh.gamecenter.FileSenderActivity.KC_REPEAT_RESULT;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/1/20.
|
||||
* 快传-选择游戏
|
||||
@ -49,6 +51,9 @@ public class KcSelectGameActivity extends BaseActivity {
|
||||
|
||||
private KcSelectGameAdapter mAdapter;
|
||||
|
||||
public final static String KEY_ISCONN = "isConn";
|
||||
public final static int SEND_OVER_REQUEST = 16; // 快传 传输完成后直接退出选择游戏(当前)页面
|
||||
|
||||
private boolean mIsConn;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
@ -56,7 +61,7 @@ public class KcSelectGameActivity extends BaseActivity {
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context, boolean isConn) {
|
||||
Intent intent = new Intent(context, KcSelectGameActivity.class);
|
||||
intent.putExtra("isConn", isConn);
|
||||
intent.putExtra(KEY_ISCONN, isConn);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@ -68,7 +73,7 @@ public class KcSelectGameActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == 0x123) {
|
||||
if (requestCode == SEND_OVER_REQUEST) {
|
||||
if (data != null && data.getExtras() != null && data.getExtras().getBoolean("isFinish")) {
|
||||
finish();
|
||||
}
|
||||
@ -81,7 +86,7 @@ public class KcSelectGameActivity extends BaseActivity {
|
||||
initTitle(getString(R.string.title_select_game));
|
||||
|
||||
if (getIntent() != null && getIntent().getExtras() != null) {
|
||||
mIsConn = getIntent().getExtras().getBoolean("isConn");
|
||||
mIsConn = getIntent().getExtras().getBoolean(KEY_ISCONN);
|
||||
} else {
|
||||
mIsConn = false;
|
||||
}
|
||||
@ -107,18 +112,18 @@ public class KcSelectGameActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
if (mIsConn) {
|
||||
List<FileInfo> oldInfo = (List<FileInfo>) AppController.get("FileInfo", false);
|
||||
List<FileInfo> oldInfo = (List<FileInfo>) HaloApp.get("FileInfo", false);
|
||||
if (oldInfo == null) {
|
||||
oldInfo = new ArrayList<>();
|
||||
}
|
||||
for (FileInfo fileInfo : selectData) {
|
||||
oldInfo.add(fileInfo);
|
||||
}
|
||||
setResult(0x130);
|
||||
setResult(KC_REPEAT_RESULT);
|
||||
finish();
|
||||
} else {
|
||||
AppController.put("FileInfo", selectData);
|
||||
startActivityForResult(ChooseReceiverActivity.getIntent(KcSelectGameActivity.this, false), 0x123);
|
||||
HaloApp.put("FileInfo", selectData);
|
||||
startActivityForResult(ChooseReceiverActivity.getIntent(KcSelectGameActivity.this, false), SEND_OVER_REQUEST);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
@ -16,6 +17,7 @@ import com.gh.base.BaseActivity;
|
||||
import com.gh.base.adapter.FragmentAdapter;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.RandomUtils;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.libao.Libao1Fragment;
|
||||
@ -39,7 +41,7 @@ import butterknife.OnClick;
|
||||
public class LibaoActivity extends BaseActivity implements View.OnClickListener,
|
||||
ViewPager.OnPageChangeListener {
|
||||
|
||||
public final static String EB_LIBAOACTIVITY_TAG = "LibaoActivity";
|
||||
|
||||
@BindView(R.id.libao_vp_content)
|
||||
NoScrollableViewPager mLibaoVp;
|
||||
@BindView(R.id.libao_ll_top)
|
||||
@ -56,9 +58,16 @@ public class LibaoActivity extends BaseActivity implements View.OnClickListener,
|
||||
TextView mGuanzhuTv;
|
||||
@BindView(R.id.libao_chunhaoxiang_tv)
|
||||
TextView mChunhaoxiangTv;
|
||||
|
||||
private LinearLayout.LayoutParams lparams;
|
||||
|
||||
public static final String EB_LIBAOACTIVITY_TAG = "LibaoActivity";
|
||||
public static final String LIBAO_OPENPAGE = "openPage";
|
||||
public static final String LIBAO_CLOSEPAGE = "closePage";
|
||||
|
||||
private int currentItem;
|
||||
private int width;
|
||||
private LinearLayout.LayoutParams lparams;
|
||||
private Libao1Fragment mLibao1Fragment;
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context, String entrance) {
|
||||
@ -80,7 +89,8 @@ public class LibaoActivity extends BaseActivity implements View.OnClickListener,
|
||||
mZuixinTv.setSelected(true);
|
||||
|
||||
List<Fragment> list = new ArrayList<>();
|
||||
list.add(new Libao1Fragment());
|
||||
mLibao1Fragment = new Libao1Fragment();
|
||||
list.add(mLibao1Fragment);
|
||||
list.add(new Libao2Fragment());
|
||||
list.add(new Libao3Fragment());
|
||||
mLibaoVp.setAdapter(new FragmentAdapter(getSupportFragmentManager(), list));
|
||||
@ -91,7 +101,7 @@ public class LibaoActivity extends BaseActivity implements View.OnClickListener,
|
||||
width = outMetrics.widthPixels / 3;
|
||||
lparams = new LinearLayout.LayoutParams(width / 2,
|
||||
DisplayUtils.dip2px(this, 2));
|
||||
lparams.leftMargin = (int) (width * (currentItem + 0.25f));
|
||||
lparams.leftMargin = RandomUtils.getInt(width * (currentItem + 0.25));
|
||||
mLibaoLine.setLayoutParams(lparams);
|
||||
|
||||
mLibaoTopLl.postDelayed(new Runnable() {
|
||||
@ -117,7 +127,7 @@ public class LibaoActivity extends BaseActivity implements View.OnClickListener,
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
if (positionOffset != 0) {
|
||||
lparams.leftMargin = (int) (width * (position + positionOffset + 0.25f));
|
||||
lparams.leftMargin = RandomUtils.getInt(width * (position + positionOffset + 0.25));
|
||||
mLibaoLine.setLayoutParams(lparams);
|
||||
} else {
|
||||
if (currentItem != mLibaoVp.getCurrentItem()) {
|
||||
@ -148,6 +158,12 @@ public class LibaoActivity extends BaseActivity implements View.OnClickListener,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
if (mLibao1Fragment != null) mLibao1Fragment.onTouchEvent(ev);
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
@ -156,13 +172,13 @@ public class LibaoActivity extends BaseActivity implements View.OnClickListener,
|
||||
// 页面切换事件(查看历史礼包的页面)
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBReuse reuse) {
|
||||
if ("openPage".equals(reuse.getType())) {
|
||||
if (LIBAO_OPENPAGE.equals(reuse.getType())) {
|
||||
mLibaoTopLl.setVisibility(View.GONE);
|
||||
mLibaoLine.setVisibility(View.GONE);
|
||||
mHistoryTitle.setVisibility(View.VISIBLE);
|
||||
mHistoryTitle.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.hint));
|
||||
mLibaoVp.setScrollable(false);
|
||||
} else if ("closePage".equals(reuse.getType())) {
|
||||
} else if (LIBAO_CLOSEPAGE.equals(reuse.getType())) {
|
||||
mLibaoTopLl.setVisibility(View.VISIBLE);
|
||||
mLibaoLine.setVisibility(View.VISIBLE);
|
||||
mHistoryTitle.setVisibility(View.GONE);
|
||||
|
||||
@ -24,15 +24,18 @@ import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.LibaoDetailAdapter;
|
||||
import com.gh.gamecenter.adapter.viewholder.DetailViewHolder;
|
||||
import com.gh.gamecenter.db.LibaoDao;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.LibaoEntity;
|
||||
import com.gh.gamecenter.entity.LibaoStatusEntity;
|
||||
import com.gh.gamecenter.entity.UserDataEntity;
|
||||
import com.gh.gamecenter.entity.UserDataLibaoEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.download.DataWatcher;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
import com.lightgame.utils.Utils;
|
||||
@ -40,8 +43,11 @@ import com.lightgame.utils.Utils;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
import retrofit2.HttpException;
|
||||
@ -49,6 +55,7 @@ import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
import static com.gh.gamecenter.R.id.reuse_tv_none_data;
|
||||
import static com.gh.gamecenter.news.News2Fragment.NEWS2_LIBAO_REQUEST;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/12/13.
|
||||
@ -76,7 +83,8 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
private GameEntity mGameEntity;
|
||||
|
||||
private boolean mIsScroll;
|
||||
|
||||
|
||||
private String mListStatus; // 记录列表领取状态(防止状态在详情改变导致列表状态改变)
|
||||
private String mName;
|
||||
private String mTitle;
|
||||
protected String mDownloadAddWord;
|
||||
@ -104,7 +112,12 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
}
|
||||
handler.sendEmptyMessageDelayed(1, delayedTime);
|
||||
} else if (msg.what == 1) {
|
||||
mLibaoEntity.setStatus(mLibaoEntity.getBeforeStatus());
|
||||
String beforeStatus = mLibaoEntity.getBeforeStatus();
|
||||
if ("ling".equals(beforeStatus)) {
|
||||
mLibaoEntity.setStatus("repeatLinged"); // 可以重复领取
|
||||
} else {
|
||||
mLibaoEntity.setStatus("repeatTaoed"); // 可以重复领取
|
||||
}
|
||||
mAdapter.notifyItemChanged(0);
|
||||
}
|
||||
}
|
||||
@ -135,9 +148,9 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context, LibaoEntity libaoEntity, String entrance) {
|
||||
HaloApp.put(LibaoDetailActivity.class.getSimpleName(), libaoEntity);
|
||||
Intent intent = new Intent(context, LibaoDetailActivity.class);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
intent.putExtra(LibaoDetailActivity.class.getSimpleName(), libaoEntity);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@ -145,7 +158,7 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
public static Intent getIntentById(Context context, String id, String entrance) {
|
||||
Intent intent = new Intent(context, LibaoDetailActivity.class);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
intent.putExtra("id", id);
|
||||
intent.putExtra(EntranceUtils.KEY_ID, id);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@ -153,19 +166,15 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(LibaoDetailActivity.class.getSimpleName(), mAdapter.getLibaoEntity());
|
||||
HaloApp.put(LibaoDetailActivity.class.getSimpleName(), mAdapter.getLibaoEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
initTitle("礼包详情");
|
||||
if (savedInstanceState != null) {
|
||||
mLibaoEntity = savedInstanceState.getParcelable(LibaoDetailActivity.class.getSimpleName());
|
||||
} else {
|
||||
mLibaoEntity = getIntent().getParcelableExtra(LibaoDetailActivity.class.getSimpleName());
|
||||
}
|
||||
mName = "礼包详情";
|
||||
mName = getString(R.string.libao_detail);
|
||||
initTitle(mName);
|
||||
mLibaoEntity = (LibaoEntity) HaloApp.get(LibaoDetailActivity.class.getSimpleName(), true);
|
||||
|
||||
mIsScroll = true;
|
||||
|
||||
@ -192,14 +201,23 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
findViewById(R.id.actionbar_rl_back).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
onBackPressed();
|
||||
}
|
||||
});
|
||||
|
||||
if (mLibaoEntity == null) {
|
||||
String id = getIntent().getStringExtra("id");
|
||||
String id = getIntent().getStringExtra(EntranceUtils.KEY_ID);
|
||||
if (!TextUtils.isEmpty(id)) {
|
||||
getLibaoDigest(id);
|
||||
}
|
||||
} else {
|
||||
init();
|
||||
getGameDigest();
|
||||
if (!mLibaoEntity.isActive()) {
|
||||
checkLibaoStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,7 +231,6 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (mGameEntity != null
|
||||
&& mGameEntity.getApk() != null
|
||||
&& mGameEntity.getApk().size() == 1) {
|
||||
DetailDownloadUtils.detailInitDownload(getDetailViewHolder(), true);
|
||||
}
|
||||
@ -226,19 +243,52 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (mLibaoEntity != null && mLibaoEntity.getGame() != null && mLibaoEntity.getGame().getId() != null) {
|
||||
// 检查礼包是否可以重复领取
|
||||
private void checkLibaoStatus() {
|
||||
if (mLibaoEntity != null && mLibaoEntity.getRepeat() > 0 && mLibaoEntity.getUserData() != null
|
||||
&& mLibaoEntity.getUserData().getUserDataLibaoList() != null) {
|
||||
|
||||
mTitle = mLibaoEntity.getName();
|
||||
getGameDigest();
|
||||
String status = mLibaoEntity.getStatus();
|
||||
String beforeStatus = mLibaoEntity.getBeforeStatus();
|
||||
if (mLibaoEntity.getRepeat() > 0 &&
|
||||
(("linged").equals(status) || ("taoed").equals(status)) &&
|
||||
("ling".equals(beforeStatus) || "tao".equals(beforeStatus))) {
|
||||
LibaoDao libaoDao = new LibaoDao(this);
|
||||
if (libaoDao.isCanLing(mLibaoEntity.getLibaoId(), this)) { // 再次检查重复重复领取条件,防止再礼包列表逗留时间过长,导致到了可领取时间
|
||||
|
||||
UserDataEntity userData = mLibaoEntity.getUserData();
|
||||
List<UserDataLibaoEntity> userDataLibaoList = userData.getUserDataLibaoList();
|
||||
|
||||
int repeat = mLibaoEntity.getRepeat();
|
||||
int curStatusCount = 0; // 当前状态的领取/淘号数量
|
||||
|
||||
for (UserDataLibaoEntity userDataLibaoEntity : userDataLibaoList) {
|
||||
if (beforeStatus != null && beforeStatus.equals(userDataLibaoEntity.getType())) {
|
||||
curStatusCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// 由领取到淘号的状态转换
|
||||
if (repeat <= curStatusCount || curStatusCount == 0) { // 当前领取/淘号总数是否超过总重复领取次数 / 当前状态的礼包没有领取/淘号过
|
||||
if (curStatusCount == 0 && ("ling".equals(beforeStatus) || "tao".equals(beforeStatus))) {
|
||||
if (isCanLing()) { // 恢复原始状态
|
||||
mLibaoEntity.setStatus(beforeStatus);
|
||||
mAdapter.notifyItemChanged(0);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ((("linged").equals(status) || ("taoed").equals(status)) &&
|
||||
("ling".equals(beforeStatus) || "tao".equals(beforeStatus))) { //检查是否到了重复领取时间
|
||||
mListStatus = mLibaoEntity.getStatus();
|
||||
if (isCanLing()) {
|
||||
handler.sendEmptyMessage(1);
|
||||
} else {
|
||||
if ("ling".equals(beforeStatus)) {
|
||||
mLibaoEntity.setStatus("repeatLing"); // 预备重复领取
|
||||
} else {
|
||||
mLibaoEntity.setStatus("repeatTao"); // 预备重复领取
|
||||
}
|
||||
mAdapter.notifyItemChanged(0);
|
||||
|
||||
TokenUtils.getTime(LibaoDetailActivity.this);
|
||||
handler.sendEmptyMessageDelayed(0, 5000);
|
||||
}
|
||||
@ -246,24 +296,66 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
}
|
||||
}
|
||||
|
||||
private void getLibaoDigest(String libao_id) {
|
||||
RetrofitManager.getLibao().getLibaoDigest(libao_id)
|
||||
/**
|
||||
* 检查是否可以领取/淘号
|
||||
* 最后领取/淘号时间不是当天
|
||||
*/
|
||||
public boolean isCanLing() {
|
||||
List<UserDataLibaoEntity> userDataLibaoList = mLibaoEntity.getUserData().getUserDataLibaoList();
|
||||
UserDataLibaoEntity userDataLibaoEntity = userDataLibaoList.get(userDataLibaoList.size() - 1);
|
||||
SimpleDateFormat formatDay = new SimpleDateFormat("dd", Locale.CHINA);
|
||||
long lingTime = userDataLibaoEntity.getTime() * 1000;
|
||||
long curTime = Utils.getTime(this) * 1000;
|
||||
int lingDay = Integer.parseInt(formatDay.format(lingTime));
|
||||
int curDay = Integer.parseInt(formatDay.format(curTime));
|
||||
if (curDay != lingDay || curTime - lingTime > 24 * 60 * 60 * 1000) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void getLibaoDigest(final String libaoId) {
|
||||
RetrofitManager.getInstance(this).getApi().getLibaoDigest(libaoId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<LibaoEntity>() {
|
||||
@Override
|
||||
public void onResponse(LibaoEntity response) {
|
||||
mLibaoEntity = response;
|
||||
mLibaoEntity.setActive(true); // addLibaoDetail设置userData
|
||||
mAdapter.setLibaoEntity(mLibaoEntity);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
init();
|
||||
getGameDigest();
|
||||
getLibaoStatus(libaoId);
|
||||
checkLibaoStatus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getLibaoStatus(String libaoId) {
|
||||
LibaoUtils.getLibaoStatus(this, libaoId, new LibaoUtils.PostLibaoListener() {
|
||||
@Override
|
||||
public void postSucced(Object response) {
|
||||
List<LibaoStatusEntity> statusList = (List<LibaoStatusEntity>) response;
|
||||
|
||||
LibaoUtils.initLiBaoEntity(statusList.get(0), mLibaoEntity);
|
||||
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postFailed(Throwable error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 获取游戏摘要
|
||||
private void getGameDigest() {
|
||||
RetrofitManager.getApi().getGameNewsDigest(mLibaoEntity.getGame().getId())
|
||||
if (mLibaoEntity.getGame() == null) return;
|
||||
String gameId = mLibaoEntity.getGame().getId();
|
||||
RetrofitManager.getInstance(this).getApi().getGameNewsDigest(gameId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@ -276,7 +368,7 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
mDownloadOffText = mGameEntity.getDownloadOffText();
|
||||
DetailDownloadUtils.detailInitDownload(getDetailViewHolder(), true);
|
||||
|
||||
mAdapter.addLibaoDetail();
|
||||
mAdapter.addLibaoDetail(LibaoDetailActivity.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -300,17 +392,49 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
// 重置领取状态
|
||||
String status = mLibaoEntity.getStatus();
|
||||
if (!TextUtils.isEmpty(status) && status.contains("repeat")) {
|
||||
mLibaoEntity.setStatus(mListStatus);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone() {
|
||||
if (mLlLoading != null) {
|
||||
mLlLoading.setVisibility(View.GONE);
|
||||
mLibaoDetailRv.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
// 从存号箱进入 获取userData后 检查领取状态(是否可以重复领取/重复淘号)
|
||||
if (mLibaoEntity.isActive() && mLibaoEntity.getUserData() != null) {
|
||||
|
||||
if ("ling".equals(mLibaoEntity.getStatus()) || "tao".equals(mLibaoEntity.getStatus())) {
|
||||
List<UserDataLibaoEntity> userLibaooList = mLibaoEntity.getUserData().getUserDataLibaoList();
|
||||
if (userLibaooList != null && userLibaooList.size() > 0) {
|
||||
UserDataLibaoEntity userDataLibaoEntity = userLibaooList.get(userLibaooList.size() - 1);
|
||||
if ("ling".equals(userDataLibaoEntity.getType())) {
|
||||
mLibaoEntity.setStatus("linged");
|
||||
} else {
|
||||
mLibaoEntity.setStatus("taoed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkLibaoStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone(Object obj) {
|
||||
|
||||
public void loadDone(Object obj) { // 在当前详情页领取获取淘号的数据
|
||||
if (obj != null) {
|
||||
Intent data = new Intent();
|
||||
data.putExtra("UserDataLibaoEntity", (UserDataLibaoEntity) obj);
|
||||
setResult(NEWS2_LIBAO_REQUEST, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -343,7 +467,6 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
public void onEvent(EBDownloadStatus status) {
|
||||
if ("delete".equals(status.getStatus())
|
||||
&& mGameEntity != null
|
||||
&& mGameEntity.getApk() != null
|
||||
&& mGameEntity.getApk().size() == 1) {
|
||||
String url = mGameEntity.getApk().get(0).getUrl();
|
||||
if (url.equals(status.getUrl())) {
|
||||
@ -356,7 +479,6 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
if (mGameEntity != null
|
||||
&& mGameEntity.getApk() != null
|
||||
&& mGameEntity.getApk().size() > 0) {
|
||||
for (ApkEntity apkEntity : mGameEntity.getApk()) {
|
||||
String packageName = apkEntity.getPackageName();
|
||||
|
||||
@ -2,103 +2,41 @@ package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.GetLoginDataUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.common.util.PatternUtils;
|
||||
import com.gh.gamecenter.entity.LoginResponseEntity;
|
||||
import com.lightgame.utils.Util_System_Keyboard;
|
||||
import com.gh.gamecenter.login.LoginFragment;
|
||||
import com.gh.gamecenter.login.LoginOldUserFragment;
|
||||
import com.tencent.connect.common.Constants;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import static com.gh.gamecenter.personal.PersonalFragment.LOGIN_CODE;
|
||||
import static com.gh.gamecenter.personal.PersonalFragment.LOGIN_TAG;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by khy on 19/06/17.
|
||||
* Created by khy on 14/08/17.
|
||||
*/
|
||||
|
||||
public class LoginActivity extends BaseActivity implements GetLoginDataUtils.OnLoginDataListener,
|
||||
LoginUtils.onCaptchaCallBackListener, LoginUtils.onLoginCallBackListener {
|
||||
public class LoginActivity extends BaseActivity {
|
||||
|
||||
ImageView mOldUserIcon;
|
||||
|
||||
@BindView(R.id.login_phone_et)
|
||||
EditText mLoginPhoneEt;
|
||||
@BindView(R.id.login_pass_et)
|
||||
EditText mLoginPassEt;
|
||||
@BindView(R.id.login_captcha)
|
||||
TextView mLoginCaptcha;
|
||||
@BindView(R.id.login_phone_btn)
|
||||
TextView mLoginBtn;
|
||||
@BindView(R.id.login_qq_btn)
|
||||
LinearLayout mLoginQqBtn;
|
||||
@BindView(R.id.login_wechat_btn)
|
||||
LinearLayout mLoginWechatBtn;
|
||||
@BindView(R.id.login_weibo_btn)
|
||||
LinearLayout mLoginWeiboBtn;
|
||||
@BindView(R.id.login_bottom)
|
||||
LinearLayout mLoginBottom;
|
||||
@BindView(R.id.login_bottom_olduser)
|
||||
LinearLayout mLoginBottomOlduser;
|
||||
private boolean mIsOlderUser;
|
||||
|
||||
ImageView mOldUser;
|
||||
|
||||
private String mServiceId;
|
||||
|
||||
Handler mHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
if (msg.what == 0) { // 验证码倒计时
|
||||
int arg1 = msg.arg1;
|
||||
arg1--;
|
||||
if (arg1 >= 0) {
|
||||
Message message = new Message();
|
||||
message.what = 0;
|
||||
message.arg1 = arg1;
|
||||
mHandler.sendMessageDelayed(message, 1000);
|
||||
mLoginCaptcha.setText(String.valueOf(arg1));
|
||||
} else {
|
||||
mLoginCaptcha.setText("重新获取");
|
||||
mLoginCaptcha.setTextColor(ContextCompat.getColor(LoginActivity.this, R.color.title));
|
||||
mLoginCaptcha.setBackgroundResource(R.drawable.border_black_bg);
|
||||
mLoginCaptcha.setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context) {
|
||||
public static Intent getIntent(Context context, boolean isOldUser) {
|
||||
Intent intent = new Intent(context, LoginActivity.class);
|
||||
intent.putExtra(EntranceUtils.KEY_OLDERUSER, isOldUser);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@ -107,30 +45,42 @@ public class LoginActivity extends BaseActivity implements GetLoginDataUtils.OnL
|
||||
return R.layout.activity_login;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == Constants.REQUEST_LOGIN) { // QQ Login callback
|
||||
GetLoginDataUtils.getInstance(this).onQQCallback(requestCode, resultCode, data);
|
||||
} else if (requestCode == 32973) {
|
||||
GetLoginDataUtils.getInstance(this).onWeiboCallback(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
initTitle("登录光环助手");
|
||||
if (getIntent() != null) {
|
||||
mIsOlderUser = getIntent().getBooleanExtra(EntranceUtils.KEY_OLDERUSER, false);
|
||||
}
|
||||
|
||||
// 添加老用户入口
|
||||
mOldUser = new ImageView(this);
|
||||
mOldUser.setImageResource(R.drawable.login_olduser_icon);
|
||||
mOldUser.setPadding(DisplayUtils.dip2px(this, 13), DisplayUtils.dip2px(this, 11),
|
||||
mOldUserIcon = new ImageView(this);
|
||||
mOldUserIcon.setImageResource(R.drawable.login_olduser_icon);
|
||||
mOldUserIcon.setPadding(DisplayUtils.dip2px(this, 13), DisplayUtils.dip2px(this, 11),
|
||||
DisplayUtils.dip2px(this, 11), DisplayUtils.dip2px(this, 13));
|
||||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
DisplayUtils.dip2px(this, 48), ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
params.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
RelativeLayout reuseActionbar = (RelativeLayout) mContentView.findViewById(R.id.reuse_actionbar);
|
||||
reuseActionbar.addView(mOldUser, params);
|
||||
reuseActionbar.addView(mOldUserIcon, params);
|
||||
mOldUserIcon.setVisibility(View.GONE);
|
||||
|
||||
mLoginPassEt.addTextChangedListener(new LoginTextWatcher(mLoginPassEt));
|
||||
mLoginPhoneEt.addTextChangedListener(new LoginTextWatcher(mLoginPhoneEt));
|
||||
|
||||
mOldUser.setOnClickListener(new View.OnClickListener() {
|
||||
mOldUserIcon.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
changeUserLogin(true);
|
||||
mIsOlderUser = true;
|
||||
changeFragment();
|
||||
}
|
||||
});
|
||||
|
||||
@ -138,170 +88,76 @@ public class LoginActivity extends BaseActivity implements GetLoginDataUtils.OnL
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mOldUser.getVisibility() == View.GONE) {
|
||||
changeUserLogin(false);
|
||||
if (mIsOlderUser) {
|
||||
mIsOlderUser = false;
|
||||
changeFragment();
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@OnClick({R.id.login_captcha, R.id.login_phone_btn, R.id.login_qq_btn,
|
||||
R.id.login_wechat_btn, R.id.login_weibo_btn})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.login_captcha:
|
||||
final String phoneNum = mLoginPhoneEt.getText().toString().trim();
|
||||
if (PatternUtils.isPhoneNum(phoneNum) && phoneNum.length() == 11) {
|
||||
DialogUtils.checkPhoneNumDialog(this, phoneNum, new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
LoginUtils.getPhoneCaptcha(LoginActivity.this, phoneNum, LoginActivity.this);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toast("请输入正确的手机号");
|
||||
}
|
||||
break;
|
||||
case R.id.login_phone_btn:
|
||||
loginByMobile();
|
||||
break;
|
||||
case R.id.login_qq_btn:
|
||||
GetLoginDataUtils.getInstance(this).QQLogin(this, this);
|
||||
break;
|
||||
case R.id.login_weibo_btn:
|
||||
GetLoginDataUtils.getInstance(this).WeiBoLogin(this, this);
|
||||
break;
|
||||
case R.id.login_wechat_btn:
|
||||
GetLoginDataUtils.getInstance(this).WCLogin(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mHandler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
// 登录成功返回
|
||||
@Override
|
||||
public void OnLoginData(JSONObject content, LoginUtils.LoginTag loginTag) {
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), content.toString());
|
||||
LoginUtils.login(this, body, loginTag, this);
|
||||
}
|
||||
|
||||
// 登录
|
||||
private void loginByMobile() {
|
||||
String code = mLoginPassEt.getText().toString().trim();
|
||||
String phoneNum = mLoginPhoneEt.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(mServiceId)) {
|
||||
toast("验证码错误,请重新获取");
|
||||
return;
|
||||
} else if (TextUtils.isEmpty(code)) {
|
||||
toast("验证码不能为空");
|
||||
return;
|
||||
} else if (TextUtils.isEmpty(phoneNum)) {
|
||||
toast("手机号码不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("mobile", phoneNum);
|
||||
params.put("code", code);
|
||||
params.put("service_id", mServiceId);
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
|
||||
LoginUtils.login(LoginActivity.this, body, LoginUtils.LoginTag.phone, LoginActivity.this);
|
||||
}
|
||||
|
||||
private void changeUserLogin(boolean isOldUser) {
|
||||
if (isOldUser) {
|
||||
mLoginBottom.setVisibility(View.GONE);
|
||||
mLoginBottomOlduser.setVisibility(View.VISIBLE);
|
||||
mOldUser.setVisibility(View.GONE);
|
||||
initTitle("老用户登录");
|
||||
} else {
|
||||
mLoginBottom.setVisibility(View.VISIBLE);
|
||||
mLoginBottomOlduser.setVisibility(View.GONE);
|
||||
mOldUser.setVisibility(View.VISIBLE);
|
||||
initTitle("登录光环助手");
|
||||
}
|
||||
Util_System_Keyboard.hideSoftKeyboard(this);
|
||||
// String syncDeviceID = PreferenceManager.getDefaultSharedPreferences(this).getString("syncDeviceID", null);
|
||||
// if (TextUtils.isEmpty(syncDeviceID)) {
|
||||
// mOldUserIcon.setVisibility(View.GONE);
|
||||
// }
|
||||
|
||||
changeFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && mOldUser.getVisibility() == View.GONE) {
|
||||
changeUserLogin(false);
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && mIsOlderUser) {
|
||||
mIsOlderUser = false;
|
||||
changeFragment();
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCaptcha(String serviceId) {
|
||||
if (!TextUtils.isEmpty(serviceId)) {
|
||||
mServiceId = serviceId;
|
||||
|
||||
// 启动验证码倒计时
|
||||
Message message = new Message();
|
||||
message.what = 0;
|
||||
message.arg1 = 60; // 倒数时间
|
||||
mHandler.sendMessage(message);
|
||||
mLoginCaptcha.setTextColor(ContextCompat.getColor(LoginActivity.this, R.color.hint));
|
||||
mLoginCaptcha.setBackgroundResource(R.drawable.border_captcha_bg);
|
||||
mLoginCaptcha.setEnabled(false);
|
||||
private void changeFragment() {
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
hideFragments(transaction);
|
||||
if (mIsOlderUser) {
|
||||
alterFragment(transaction, LoginOldUserFragment.class);
|
||||
initTitle("老用户登录");
|
||||
// mOldUserIcon.setVisibility(View.GONE);
|
||||
} else {
|
||||
alterFragment(transaction, LoginFragment.class);
|
||||
initTitle("登录光环助手");
|
||||
// mOldUserIcon.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLogin(LoginResponseEntity entity, LoginUtils.LoginTag loginTag) { // 登录成功
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("loginStatus", LOGIN_TAG);
|
||||
setResult(LOGIN_CODE, intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
private class LoginTextWatcher implements TextWatcher {
|
||||
private EditText mEditText;
|
||||
|
||||
public LoginTextWatcher(EditText e) {
|
||||
mEditText = e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
Drawable drawable;
|
||||
int tvCount = s.length();
|
||||
if (mEditText == mLoginPassEt) {
|
||||
if (tvCount > 0) {
|
||||
drawable = ContextCompat.getDrawable(LoginActivity.this, R.drawable.login_password_focused);
|
||||
} else {
|
||||
drawable = ContextCompat.getDrawable(LoginActivity.this, R.drawable.login_password_unfocused);
|
||||
}
|
||||
} else {
|
||||
if (tvCount > 0) {
|
||||
drawable = ContextCompat.getDrawable(LoginActivity.this, R.drawable.login_phone_focused);
|
||||
} else {
|
||||
drawable = ContextCompat.getDrawable(LoginActivity.this, R.drawable.login_phone_unfocused);
|
||||
}
|
||||
// 将所有的Fragment都置为隐藏状态。
|
||||
private void hideFragments(FragmentTransaction transaction) {
|
||||
List<Fragment> list = getSupportFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
for (Fragment fragment : list) {
|
||||
transaction.hide(fragment);
|
||||
}
|
||||
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
|
||||
mEditText.setCompoundDrawables(drawable, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private <T extends Fragment> T alterFragment(FragmentTransaction transaction, Class<T> cls) {
|
||||
T fragmentByTag = (T) getSupportFragmentManager().findFragmentByTag(cls.getSimpleName());
|
||||
try {
|
||||
if (fragmentByTag != null) {
|
||||
transaction.show(fragmentByTag);
|
||||
} else {
|
||||
fragmentByTag = cls.newInstance();
|
||||
Bundle args = new Bundle();
|
||||
args.putBoolean(EntranceUtils.KEY_OLDERUSER, mIsOlderUser);
|
||||
fragmentByTag.setArguments(args);
|
||||
transaction.add(R.id.layout_fragment_content, fragmentByTag, cls.getSimpleName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return fragmentByTag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@ -12,25 +15,31 @@ import android.os.SystemClock;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.AppUncaughtHandler;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.ClassUtils;
|
||||
import com.gh.common.util.ConcernUtils;
|
||||
import com.gh.common.util.DataCollectionUtils;
|
||||
import com.gh.common.util.DataLogUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DeviceUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.LibaoUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.TrafficUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
@ -40,9 +49,10 @@ import com.gh.gamecenter.entity.GameDigestEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBShowDialog;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.fragment.MainFragment;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
@ -50,15 +60,20 @@ import com.gh.gamecenter.manager.FilterManager;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.manager.UpdateManager;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
import com.gh.gamecenter.retrofit.ObservableUtil;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.config.CommonDebug;
|
||||
import com.lightgame.download.DataWatcher;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
import com.lightgame.download.DownloadStatus;
|
||||
import com.lightgame.download.FileUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.tencent.bugly.beta.tinker.TinkerManager;
|
||||
import com.tencent.bugly.crashreport.CrashReport;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
@ -67,11 +82,14 @@ import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
@ -83,9 +101,11 @@ import retrofit2.HttpException;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Action1;
|
||||
import rx.functions.Func1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
import static com.gh.common.util.EntranceUtils.KEY_DATA;
|
||||
import static com.gh.common.util.EntranceUtils.KEY_TO;
|
||||
|
||||
/**
|
||||
* 项目的主Activity,3个Fragment都嵌入在这里。
|
||||
*/
|
||||
@ -96,15 +116,18 @@ public class MainActivity extends BaseActivity {
|
||||
private SharedPreferences sp;
|
||||
private ConcernManager concernManager;
|
||||
|
||||
private static final int SKIP_SETTING_REQUEST = 14;
|
||||
private boolean isSkipped;
|
||||
public static boolean isNewFirstLaunch;
|
||||
|
||||
Runnable skipRun = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (getIntent() != null && getIntent().getExtras() != null && !isSkipped) {
|
||||
isSkipped = true;
|
||||
Bundle bundle = getIntent().getBundleExtra("data");
|
||||
Bundle bundle = getIntent().getBundleExtra(KEY_DATA);
|
||||
if (bundle != null) {
|
||||
String to = bundle.getString("to");
|
||||
String to = bundle.getString(KEY_TO);
|
||||
if (!TextUtils.isEmpty(to)) {
|
||||
Class<?> clazz = ClassUtils.forName(to);
|
||||
if (clazz != null) {
|
||||
@ -116,10 +139,10 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
String packageName = bundle.getString("packageName");
|
||||
if (packageName != null) {
|
||||
bundle.putInt("currentItem", 1);
|
||||
bundle.putInt(EntranceUtils.KEY_CURRENTITEM, 1);
|
||||
}
|
||||
|
||||
skipIntent.putExtra("data", bundle);
|
||||
skipIntent.putExtra(KEY_DATA, bundle);
|
||||
startActivity(skipIntent);
|
||||
}
|
||||
}
|
||||
@ -174,7 +197,7 @@ public class MainActivity extends BaseActivity {
|
||||
// 是否是自动安装
|
||||
if (sp.getBoolean("autoinstall", true)) {
|
||||
if (FileUtils.isEmptyFile(downloadEntity.getPath())) {
|
||||
toast("解析包出错(可能被误删了),请重新下载");
|
||||
toast(R.string.install_failure_hint);
|
||||
DownloadManager.getInstance(MainActivity.this).cancel(downloadEntity.getUrl());
|
||||
} else {
|
||||
if (PackageUtils.isCanLaunchSetup(getApplicationContext(), downloadEntity.getPath())) {
|
||||
@ -212,7 +235,7 @@ public class MainActivity extends BaseActivity {
|
||||
params.put("platform", platform);
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
RetrofitManager.getApi().postDownload(body)
|
||||
RetrofitManager.getInstance(this).getApi().postDownload(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
@ -338,12 +361,7 @@ public class MainActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
// if(requestCode == Constants.REQUEST_LOGIN) { // QQ Login callback
|
||||
// Tencent.onActivityResultData(requestCode,resultCode,data, GetLoginDataUtils.getInstance(this).QqLoginListener);
|
||||
// } else if (requestCode == 32973 && GetLoginDataUtils.getInstance(this).mSsoHandler != null) {
|
||||
// GetLoginDataUtils.getInstance(this).mSsoHandler.authorizeCallBack(requestCode, resultCode, data);
|
||||
// } else if (requestCode == 0x123) {
|
||||
if (requestCode == 0x123) {
|
||||
if (requestCode == SKIP_SETTING_REQUEST) {
|
||||
List<PackageInfo> installedList = getPackageManager().getInstalledPackages(0);
|
||||
if (installedList.isEmpty()) {
|
||||
toast("读取应用列表失败");
|
||||
@ -380,7 +398,7 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
for (int i = 0, size = localList.size(); i < size; i++) {
|
||||
final String packageName = localList.get(i);
|
||||
RetrofitManager.getApi().getGameDigestByPackageName(packageName)
|
||||
RetrofitManager.getInstance(this).getApi().getGameDigestByPackageName(packageName)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<GameDigestEntity>>() {
|
||||
@ -423,7 +441,7 @@ public class MainActivity extends BaseActivity {
|
||||
} else {
|
||||
List<Observable<GameEntity>> sequences = new ArrayList<>();
|
||||
for (String id : concernIdList) {
|
||||
sequences.add(RetrofitManager.getApi().getGameDigest(id));
|
||||
sequences.add(RetrofitManager.getInstance(this).getApi().getGameDigest(id));
|
||||
}
|
||||
Observable.merge(sequences)
|
||||
.subscribeOn(Schedulers.io())
|
||||
@ -432,7 +450,7 @@ public class MainActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onNext(GameEntity response) {
|
||||
ConcernInfo concernInfo = concernManager.findConcernById(response.getId());
|
||||
if (concernInfo != null && response.getApk() != null && response.getApk().size() != 0) {
|
||||
if (concernInfo != null && response.getApk().size() != 0) {
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
for (ApkEntity apkEntity : response.getApk()) {
|
||||
if (PackageManager.isInstalled(apkEntity.getPackageName())) {
|
||||
@ -459,7 +477,7 @@ public class MainActivity extends BaseActivity {
|
||||
* 更新关注列表数据
|
||||
*/
|
||||
private void update() {
|
||||
AppController.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
HaloApp.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final List<String> installed = new ArrayList<>();
|
||||
@ -510,15 +528,10 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
// 更新用户已安装游戏
|
||||
TokenUtils.getToken(MainActivity.this, true)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONArray(installed).toString());
|
||||
return RetrofitManager.getUser().putPackage(token, body);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONArray(installed).toString());
|
||||
RetrofitManager.getInstance(MainActivity.this).getApi().putPackage(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
|
||||
@ -554,7 +567,7 @@ public class MainActivity extends BaseActivity {
|
||||
final List<GameEntity> list = new ArrayList<>();
|
||||
List<Observable<GameEntity>> sequences = new ArrayList<>();
|
||||
for (ConcernInfo info : concernManager.getInstalledGame()) {
|
||||
sequences.add(RetrofitManager.getApi().getGameDigest(info.getId()));
|
||||
sequences.add(RetrofitManager.getInstance(this).getApi().getGameDigest(info.getId()));
|
||||
}
|
||||
Observable.merge(sequences)
|
||||
.subscribeOn(Schedulers.io())
|
||||
@ -576,9 +589,9 @@ public class MainActivity extends BaseActivity {
|
||||
Object gh_id = PackageUtils.getMetaData(this, packageName, "gh_id");
|
||||
Observable<GameUpdateEntity> observable;
|
||||
if (gh_id == null) {
|
||||
observable = RetrofitManager.getApi().getGameUpdate(packageName);
|
||||
observable = RetrofitManager.getInstance(this).getApi().getGameUpdate(packageName);
|
||||
} else {
|
||||
observable = RetrofitManager.getApi().getGameUpdate((String) gh_id, packageName);
|
||||
observable = RetrofitManager.getInstance(this).getApi().getGameUpdate((String) gh_id, packageName);
|
||||
}
|
||||
observable.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -630,20 +643,16 @@ public class MainActivity extends BaseActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// 初始化gameMap
|
||||
DownloadManager.getInstance(this).initGameMap();
|
||||
// 上传数据
|
||||
DataCollectionManager.getInstance(getApplicationContext()).upload();
|
||||
|
||||
sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
boolean isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(this), true);
|
||||
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(this), true);
|
||||
|
||||
isSkipped = false;
|
||||
|
||||
// initViews();
|
||||
if (savedInstanceState != null) {
|
||||
// currentTab = savedInstanceState.getInt("currentTab");
|
||||
isSkipped = savedInstanceState.getBoolean("isSkipped");
|
||||
// } else {
|
||||
// currentTab = 0;
|
||||
}
|
||||
|
||||
replaceFragment(new MainFragment());
|
||||
@ -657,6 +666,8 @@ public class MainActivity extends BaseActivity {
|
||||
if (isNewFirstLaunch) {
|
||||
getPluginUpdate();
|
||||
sp.edit().putBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(this), false).apply();
|
||||
|
||||
checkDevice(); // 根据设备信息判断用户是否是新用户
|
||||
}
|
||||
|
||||
// 初始化PlatformUtils
|
||||
@ -668,38 +679,118 @@ public class MainActivity extends BaseActivity {
|
||||
// 检查是否有权限读取应用列表
|
||||
checkPermission();
|
||||
|
||||
if (isNewFirstLaunch || TokenUtils.getDeviceId(this) == null) {
|
||||
AppController.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 注册设备
|
||||
TokenUtils.register(MainActivity.this.getApplicationContext());
|
||||
TokenUtils.getToken(MainActivity.this.getApplicationContext(), false)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<String>() {
|
||||
@Override
|
||||
public void onResponse(String token) {
|
||||
TokenUtils.checkDeviceInfo(MainActivity.this.getApplicationContext(), token);
|
||||
}
|
||||
});
|
||||
updateUserGhzs();
|
||||
initConcern(); // 初始化关注
|
||||
LibaoUtils.getCunHaoXiang(MainActivity.this, true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
updateUserGhzs();
|
||||
getSuggestionType();
|
||||
|
||||
final String message = Config.getExceptionMsg(this);
|
||||
if (LoginUtils.getUserInfo(this) != null && !TextUtils.isEmpty(message)) {
|
||||
Config.setExceptionMsg(this, null);
|
||||
AppUncaughtHandler.reportException(this, new Throwable(message));
|
||||
DialogUtils.showWarningDialog(this, "发生闪退", "光环助手刚刚发生了闪退,马上反馈以帮助我们更好地修复问题?(只需简单描述你刚才的操作)"
|
||||
, "暂不", "马上反馈", new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
SuggestionActivity.startSuggestionActivity(MainActivity.this, 3, null, null);
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
checkTinkerPath();
|
||||
|
||||
checkRetryDownload();
|
||||
|
||||
// 执行跳转事件
|
||||
handler.postDelayed(skipRun, 500);
|
||||
}
|
||||
|
||||
if (sp.getBoolean("changeDefaultIcon", false) && sp.getInt("default_user_icon", 0) != 0) {
|
||||
postDefaultIcon(true, sp.getInt("default_user_icon", 0), 1);
|
||||
private void checkRetryDownload() {
|
||||
if (!NetworkUtils.isWifiConnected(this)) return;
|
||||
|
||||
for (DownloadEntity downloadEntity : DownloadManager.getInstance(this).getAll()) {
|
||||
if (DownloadStatus.neterror.equals(downloadEntity.getStatus()) ||
|
||||
DownloadStatus.timeout.equals(downloadEntity.getStatus())) {
|
||||
DownloadManager.getInstance(this).add(downloadEntity);
|
||||
}
|
||||
Utils.log("checkRetryDownload::" + downloadEntity.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkTinkerPath() {
|
||||
CommonDebug.logMethodWithParams(this, TinkerManager.getTinkerId(), TinkerManager.getNewTinkerId());
|
||||
CommonDebug.logMethodWithParams(this, CrashReport.getAppVer(), CrashReport.getAppID(), CrashReport.getAppChannel(), CrashReport.getSdkExtraData());
|
||||
|
||||
// 1.(母包)首次启动,tinkerId不为空,newTinkerId(patchTinkerId)应该是空的
|
||||
// 2. 补丁包启动,tinkerId和之前一致,但newTinkerId不一致
|
||||
// 2.1 显示更新信息弹窗,记录tinkerId+newTinkerId
|
||||
// 2.1.1 若tinkerId一致,但newTinkerId不一致才能认为是一次补丁更新
|
||||
|
||||
String tinkerId = TinkerManager.getTinkerId();
|
||||
String newTinkerId = TinkerManager.getNewTinkerId();
|
||||
|
||||
if (TextUtils.isEmpty(newTinkerId)) {
|
||||
//这是一个新的母包,没有任何补丁信息
|
||||
return;
|
||||
}
|
||||
|
||||
getSuggestionType();
|
||||
final Gson gson = new Gson();
|
||||
|
||||
Type type = new TypeToken<HashMap<String, Set<String>>>() {
|
||||
}.getType();
|
||||
|
||||
final Map<String, Set<String>> tinkerIdMap;
|
||||
final String tinkerMapJson = sp.getString(Config.PATCHES, "");
|
||||
if (!TextUtils.isEmpty(tinkerMapJson)) {
|
||||
tinkerIdMap = gson.fromJson(tinkerMapJson, type);
|
||||
} else {
|
||||
tinkerIdMap = new HashMap<>();
|
||||
}
|
||||
|
||||
Set<String> tinkerIdSet = tinkerIdMap.get(tinkerId);
|
||||
if (tinkerIdSet == null) {
|
||||
tinkerIdSet = new HashSet<>();
|
||||
tinkerIdMap.put(tinkerId, tinkerIdSet);
|
||||
}
|
||||
|
||||
// 有新的补丁,没有显示过
|
||||
if (!tinkerIdSet.contains(newTinkerId)) {
|
||||
tinkerIdSet.add(newTinkerId);
|
||||
|
||||
final Dialog dialog = new Dialog(this, R.style.GhAlertDialog);
|
||||
|
||||
View contentView = LayoutInflater.from(this).inflate(R.layout.dialog_alert, null);
|
||||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||||
|
||||
titleTv.setText("补丁更新成功");
|
||||
contentTv.setText("光环助手已成功更新到V" + PackageUtils.getPatchVersionName());
|
||||
positiveTv.setText("知道了");
|
||||
negativeTv.setText(null);
|
||||
|
||||
negativeTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
positiveTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
sp.edit().putString(Config.PATCHES, gson.toJson(tinkerIdMap)).apply();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(contentView);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -708,16 +799,47 @@ public class MainActivity extends BaseActivity {
|
||||
super.onDestroy();
|
||||
DownloadManager.getInstance(this).removeObserver(dataWatcher);
|
||||
|
||||
if (sp.getBoolean("changeDefaultIcon", false) && sp.getInt("default_user_icon", 0) != 0) {
|
||||
postDefaultIcon(true, sp.getInt("default_user_icon", 0), 1);
|
||||
}
|
||||
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
private void checkDevice() {
|
||||
String content = DeviceUtils.getUserDevice(MainActivity.this).toString();
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), content);
|
||||
RetrofitManager.getInstance(this).getApi().checkDevice(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@Override
|
||||
public void onResponse(ResponseBody response) {
|
||||
super.onResponse(response);
|
||||
try {
|
||||
String string = response.string();
|
||||
JSONObject object = new JSONObject(string);
|
||||
String deviceId = object.getString("device_id");
|
||||
if (!TextUtils.isEmpty(deviceId)) {
|
||||
oldUserSkip(deviceId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void oldUserSkip(String deviceId) {
|
||||
sp.edit().putString("syncDeviceID", deviceId).apply();
|
||||
DialogUtils.showForceDialog(MainActivity.this, "数据同步提醒"
|
||||
, "系统检测到你是光环助手的老用户,为了避免数据丢失,请尽快登录"
|
||||
, "前往登录", "残忍拒绝", new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
EventBus.getDefault().post(new EBSkip(MainActivity.EB_SKIP_GAMEFRAGMENT, 2));
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
private void getSuggestionType() {
|
||||
RetrofitManager
|
||||
.getApi()
|
||||
RetrofitManager.getInstance(this).getApi()
|
||||
.getSuggestionType()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -744,117 +866,6 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
// 更新用户使用的助手信息
|
||||
private void updateUserGhzs() {
|
||||
String version_code = sp.getString("version_code", null);
|
||||
String version_name = sp.getString("version_name", null);
|
||||
String channel = sp.getString("channel", null);
|
||||
|
||||
final String versionCode = PackageUtils.getVersionCode(MainActivity.this);
|
||||
final String versionName = PackageUtils.getVersionName(MainActivity.this);
|
||||
final String packageChannel = AppController.getInstance().getChannel();
|
||||
if ((TextUtils.isEmpty(version_code) || TextUtils.isEmpty(version_name) || TextUtils.isEmpty(channel))
|
||||
|| (!version_code.equals(versionCode) || !version_name.equals(versionName) || !channel.equals(packageChannel))) {
|
||||
TokenUtils.getToken(MainActivity.this, true)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
Map<String, String> params = new ArrayMap<>();
|
||||
params.put("version_code", versionCode);
|
||||
params.put("version_name", versionName);
|
||||
params.put("channel", packageChannel);
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
return RetrofitManager.getUser().postGhzs(token, body);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@Override
|
||||
public void onResponse(ResponseBody response) {
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.putString("version_code", versionCode);
|
||||
editor.putString("version_name", versionName);
|
||||
editor.putString("channel", packageChannel);
|
||||
editor.apply();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化关注
|
||||
private void initConcern() {
|
||||
String versionName = PackageUtils.getVersionName(MainActivity.this);
|
||||
if ("2.3".equals(versionName) && !sp.getBoolean("isSwitchConcern", false)) {
|
||||
// 针对助手2.3版本关注数据的迁移
|
||||
RetrofitManager.getApi().getConcern(TokenUtils.getDeviceId(MainActivity.this))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<String>>() {
|
||||
@Override
|
||||
public void onResponse(final List<String> response) {
|
||||
if (response.size() != 0) {
|
||||
TokenUtils.getToken(MainActivity.this, true)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONArray(response).toString());
|
||||
return RetrofitManager.getUser().putConcern(token, body);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
}
|
||||
sp.edit().putBoolean("isSwitchConcern", true).apply();
|
||||
getConcernDigest(response);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
TokenUtils.getToken(MainActivity.this, true)
|
||||
.flatMap(new Func1<String, Observable<List<String>>>() {
|
||||
@Override
|
||||
public Observable<List<String>> call(String token) {
|
||||
return RetrofitManager.getUser().getConcern(token);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(new Response<List<String>>() {
|
||||
@Override
|
||||
public void onResponse(List<String> response) {
|
||||
getConcernDigest(response);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void getConcernDigest(final List<String> arrGameId) {
|
||||
final ArrayList<GameEntity> concernDigest = new ArrayList<>();
|
||||
|
||||
if (arrGameId.size() == 0) {
|
||||
EventBus.getDefault().post(new EBUISwitch("NewsWrapperFragment", -2)); // 没有关注
|
||||
}
|
||||
|
||||
List<Observable<GameEntity>> list = new ArrayList<>();
|
||||
for (String gameId : arrGameId) {
|
||||
list.add(RetrofitManager.getApi().getGameDigest(gameId));
|
||||
}
|
||||
Observable.merge(list)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
concernManager.addByList(concernDigest);
|
||||
} @Override
|
||||
public void onNext(GameEntity response) {
|
||||
concernDigest.add(response);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void checkPermission() {
|
||||
List<PackageInfo> installedList = getPackageManager().getInstalledPackages(0);
|
||||
if (installedList.isEmpty()) {
|
||||
@ -870,7 +881,7 @@ public class MainActivity extends BaseActivity {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
startActivityForResult(intent, 0x123);
|
||||
startActivityForResult(intent, SKIP_SETTING_REQUEST);
|
||||
}
|
||||
}, null);
|
||||
} else {
|
||||
@ -889,7 +900,7 @@ public class MainActivity extends BaseActivity {
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = ((ZipEntry) entries.nextElement());
|
||||
String entryName = entry.getName();
|
||||
if (entryName.contains("gh_assist")) {
|
||||
if (entryName.contains("gh_assist")) { // TODO: 20/09/17 统一入口
|
||||
String packageName = entryName.substring(entryName.lastIndexOf("_") + 1);
|
||||
Intent intent = new Intent(MainActivity.this, DownloadManagerActivity.class);
|
||||
intent.putExtra("currentItem", 1);
|
||||
@ -912,9 +923,24 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
// 连接上网络事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
checkRetryDownload();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: 30/10/17 整理这个方法
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
final String packageName = busFour.getPackageName();
|
||||
if ("安装".equals(busFour.getType())) { // 删除下载完成 弹窗
|
||||
NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nManager.cancel(packageName.hashCode());
|
||||
}
|
||||
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
// 添加进已安装map中
|
||||
PackageManager.addInstalled(packageName);
|
||||
@ -950,7 +976,7 @@ public class MainActivity extends BaseActivity {
|
||||
startActivity(PackageUtils.getInstallIntent(this, mDownloadEntity.getPath()));
|
||||
}
|
||||
}
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
if ("安装".equals(busFour.getType()) && sp.getBoolean("concerngame", true)) {
|
||||
GameManager gameManager = new GameManager(getApplicationContext());
|
||||
GameInfo gameInfo = gameManager.findGame(packageName);
|
||||
if (gameInfo != null) {
|
||||
@ -967,7 +993,7 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
if ("安装".equals(busFour.getType()) && sp.getBoolean("concerngame", true)) {//设置页面控制是否安装后自动关注
|
||||
// 安装后关注游戏
|
||||
RetrofitManager.getApi().getGameDigestByPackageName(packageName)
|
||||
RetrofitManager.getInstance(this).getApi().getGameDigestByPackageName(packageName)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<GameDigestEntity>>() {
|
||||
@ -978,25 +1004,24 @@ public class MainActivity extends BaseActivity {
|
||||
gameInfo.setId(gameDigestEntity.getId());
|
||||
gameInfo.setPackageName(packageName);
|
||||
gameInfo.setGameName(gameDigestEntity.getName());
|
||||
concernManager.updateByEntity(gameInfo);
|
||||
concernGame(gameDigestEntity.getId(), packageName);
|
||||
if (PackageUtils.getMetaData(getApplicationContext(),
|
||||
packageName, "gh_version") != null) {
|
||||
checkGameUpdate(packageName);
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(gameDigestEntity.getId())) { // 关注游戏
|
||||
ConcernUtils.INSTANCE.postConcernGameId(MainActivity.this, gameDigestEntity.getId(), null);
|
||||
}
|
||||
}
|
||||
// 更新已安装游戏
|
||||
TokenUtils.getToken(MainActivity.this, true)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
JSONArray params = new JSONArray();
|
||||
params.put(packageName);
|
||||
RequestBody body = RequestBody.create(
|
||||
MediaType.parse("application/json"), params.toString());
|
||||
return RetrofitManager.getUser().postPackage(token, body);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
JSONArray params = new JSONArray();
|
||||
params.put(packageName);
|
||||
RequestBody body = RequestBody.create(
|
||||
MediaType.parse("application/json"), params.toString());
|
||||
RetrofitManager.getInstance(MainActivity.this).getApi()
|
||||
.postPackage(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
}
|
||||
@ -1005,13 +1030,9 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
if ("卸载".equals(busFour.getType())) {
|
||||
// 更新已安装游戏
|
||||
TokenUtils.getToken(MainActivity.this, true)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
return RetrofitManager.getUser().deletePackage(token, packageName);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
RetrofitManager.getInstance(this).getApi()
|
||||
.deletePackage(packageName)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
}
|
||||
@ -1020,7 +1041,7 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void concernGame(final String id, final String packageName) {
|
||||
RetrofitManager.getApi().getGameDigest(id)
|
||||
RetrofitManager.getInstance(this).getApi().getGameDigest(id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@ -1028,14 +1049,10 @@ public class MainActivity extends BaseActivity {
|
||||
public void onResponse(GameEntity response) {
|
||||
GameManager manager = new GameManager(getApplicationContext());
|
||||
manager.addOrUpdate(response.getApk(), response.getId(), response.getName());
|
||||
if (!concernManager.isConcern(id)) {
|
||||
concernManager.addByEntity(response);
|
||||
}
|
||||
// 检查是否能插件化
|
||||
if (response.getTag() != null && response.getTag().size() != 0
|
||||
&& response.getApk() != null) {
|
||||
if (response.getTag() != null && response.getTag().size() != 0) {
|
||||
for (ApkEntity apkEntity : response.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(packageName)
|
||||
if (packageName.equals(apkEntity.getPackageName())
|
||||
&& !TextUtils.isEmpty(apkEntity.getGhVersion())
|
||||
&& !PackageUtils.isSignature(getApplicationContext(), apkEntity.getPackageName())) {
|
||||
PackageManager.addUpdate(GameUtils.getGameUpdateEntity(response, apkEntity));
|
||||
@ -1048,37 +1065,4 @@ public class MainActivity extends BaseActivity {
|
||||
});
|
||||
}
|
||||
|
||||
// 提交默认头像
|
||||
private void postDefaultIcon(boolean isCheck, final int i, final int count) {
|
||||
TokenUtils.getToken(this, isCheck)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("icon_key", "icon" + i);
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
return RetrofitManager.getUser().postDefaultIcon(token, body);
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
sp.edit().putBoolean("changeDefaultIcon", false).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
if (e != null) {
|
||||
if (e.code() == 401) {
|
||||
postDefaultIcon(true, i, count - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
32
app/src/main/java/com/gh/gamecenter/MessageActivity.java
Normal file
32
app/src/main/java/com/gh/gamecenter/MessageActivity.java
Normal file
@ -0,0 +1,32 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.gamecenter.message.MessageFragment;
|
||||
|
||||
/**
|
||||
* Created by khy on 21/07/17.
|
||||
*/
|
||||
|
||||
public class MessageActivity extends BaseActivity {
|
||||
|
||||
public static Intent getIntent(Context context) {
|
||||
return new Intent(context, MessageActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_message;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
initTitle(getString(R.string.title_message_center));
|
||||
getSupportFragmentManager().beginTransaction().replace(
|
||||
R.id.layout_fragment_content, MessageFragment.newInstance(0)).commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
@ -3,10 +3,7 @@ package com.gh.gamecenter;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Editable;
|
||||
@ -22,31 +19,34 @@ import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.CheckLoginUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.common.util.PostCommentUtils;
|
||||
import com.gh.common.util.SoftInputHidWidgetUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.gamecenter.adapter.MessageDetailAdapter;
|
||||
import com.gh.gamecenter.adapter.OnCommentCallBackListener;
|
||||
import com.gh.gamecenter.db.CommentDao;
|
||||
import com.gh.gamecenter.db.info.CommentInfo;
|
||||
import com.gh.gamecenter.entity.CommentEntity;
|
||||
import com.gh.gamecenter.entity.CommentnumEntity;
|
||||
import com.gh.gamecenter.entity.ConcernEntity;
|
||||
import com.gh.gamecenter.entity.UserInfoEntity;
|
||||
import com.gh.gamecenter.entity.ViewsEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.manager.CommentManager;
|
||||
import com.gh.gamecenter.retrofit.OkHttpCache;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.google.gson.Gson;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@ -60,6 +60,8 @@ import retrofit2.HttpException;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
import static com.gh.gamecenter.personal.PersonalFragment.LOGIN_TAG;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/8.
|
||||
* 消息详情界面
|
||||
@ -95,15 +97,13 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
|
||||
|
||||
private MessageDetailAdapter adapter;
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
private Dialog mSendingDialog;
|
||||
|
||||
private CommentDao mCommentDao;
|
||||
|
||||
private ConcernEntity mConcernEntity;
|
||||
private CommentEntity mCommentEntity; // 回复评论的实体 用完马上清空
|
||||
|
||||
private UserInfoEntity mUserInfo;
|
||||
|
||||
private String newsId;
|
||||
|
||||
private int commentNum = -1; //区分来源 -1:资讯关注列表 !=-1 :新闻详情
|
||||
@ -133,19 +133,37 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
|
||||
}
|
||||
};
|
||||
|
||||
// 评论回复
|
||||
public static Intent getMessageDetailIntent(Context context, CommentEntity entity, String newsId) {
|
||||
HaloApp.put("CommentEntity", entity);
|
||||
Intent intent = new Intent(context, MessageDetailActivity.class);
|
||||
AppController.put("CommentEntity", entity);
|
||||
intent.putExtra("commentNum", -1);
|
||||
intent.putExtra("newsId", newsId);
|
||||
intent.putExtra(EntranceUtils.KEY_NEWSID, newsId);
|
||||
intent.putExtra("openSoftInput", true);
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static Intent getIntentByEntity(Context context, ConcernEntity concernEntity, String entrance) {
|
||||
HaloApp.put("ConcernEntity", concernEntity);
|
||||
Intent intent = new Intent(context, MessageDetailActivity.class);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static Intent getIntentById(Context context, String newsId, Integer commentNum, Boolean openSoftInput, String entrance) {
|
||||
Intent intent = new Intent(context, MessageDetailActivity.class);
|
||||
intent.putExtra(EntranceUtils.KEY_NEWSID, newsId);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
intent.putExtra("commentNum", commentNum);
|
||||
intent.putExtra("openSoftInput", openSoftInput);
|
||||
return intent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
AppController.put("ConcernEntity", adapter.getConcernEntity());
|
||||
HaloApp.put("ConcernEntity", adapter.getConcernEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -157,13 +175,13 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mConcernEntity = (ConcernEntity) AppController.get("ConcernEntity", true);
|
||||
mConcernEntity = (ConcernEntity) HaloApp.get("ConcernEntity", true);
|
||||
|
||||
mCommentEntity = (CommentEntity) AppController.get("CommentEntity", true); // 来自新闻详情-评论回复
|
||||
mCommentEntity = (CommentEntity) HaloApp.get("CommentEntity", true); // 来自新闻详情-评论回复
|
||||
|
||||
Intent intent = getIntent();
|
||||
newsId = intent.getExtras().getString("newsId");
|
||||
commentNum = intent.getExtras().getInt("commentNum");
|
||||
newsId = intent.getExtras().getString(EntranceUtils.KEY_NEWSID);
|
||||
commentNum = intent.getExtras().getInt("commentNum", -1);
|
||||
|
||||
//复用问题 mConcernEntity对应的文章有可能和跳转之前的文章不一致
|
||||
if (mConcernEntity != null && newsId != null && !newsId.equals(mConcernEntity.getId())) {
|
||||
@ -172,11 +190,7 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
|
||||
|
||||
initTitle(getString(R.string.title_message_detail));
|
||||
|
||||
sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
mCommentDao = new CommentDao(this);
|
||||
|
||||
adapter = new MessageDetailAdapter(this, this, mCommentDao, mMessageDetailRv, mConcernEntity, mEntrance);
|
||||
adapter = new MessageDetailAdapter(this, this, mMessageDetailRv, mConcernEntity, mEntrance);
|
||||
mLayoutManager = new LinearLayoutManager(this);
|
||||
mMessageDetailRv.setLayoutManager(mLayoutManager);
|
||||
mMessageDetailRv.setAdapter(adapter);
|
||||
@ -198,50 +212,24 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
|
||||
}
|
||||
});
|
||||
|
||||
//检查sp是否有用户信息
|
||||
if (TextUtils.isEmpty(sp.getString("user_name", null))) {
|
||||
|
||||
TokenUtils.getToken(this, true)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<String>() {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
super.onResponse(response);
|
||||
String icon = sp.getString("user_icon", null);
|
||||
if (TextUtils.isEmpty(icon)) {
|
||||
mMessageDetailIconDv.setImageURI(
|
||||
Uri.parse("res:///" + R.drawable.user_default_icon_comment));
|
||||
} else {
|
||||
ImageUtils.Companion.display(mMessageDetailIconDv, icon);
|
||||
}
|
||||
mMessageDetailUserNameTv.setText(sp.getString("user_name", "光环用户"));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
String icon = sp.getString("user_icon", null);
|
||||
if (TextUtils.isEmpty(icon)) {
|
||||
mMessageDetailIconDv.setImageURI(
|
||||
Uri.parse("res:///" + R.drawable.user_default_icon_comment));
|
||||
} else {
|
||||
ImageUtils.Companion.display(mMessageDetailIconDv, icon);
|
||||
}
|
||||
mMessageDetailUserNameTv.setText(sp.getString("user_name", "光环用户"));
|
||||
mUserInfo = LoginUtils.getUserInfo(this);
|
||||
if (mUserInfo != null) {
|
||||
ImageUtils.Companion.display(mMessageDetailIconDv, mUserInfo.getIcon());
|
||||
mMessageDetailUserNameTv.setText(mUserInfo.getName());
|
||||
}
|
||||
|
||||
if (newsId != null && mConcernEntity == null) {
|
||||
getConcernDigest();
|
||||
}
|
||||
|
||||
if (intent.getExtras().getBoolean("openSoftInput")) {//新闻详情的发表评论
|
||||
if (intent.getExtras().getBoolean("openSoftInput", false)) {//新闻详情的发表评论
|
||||
setSoftInput(true);
|
||||
}
|
||||
|
||||
SoftInputHidWidgetUtils.assistActivity(this);
|
||||
}
|
||||
|
||||
public void getCommentNum() {
|
||||
RetrofitManager.getComment()
|
||||
RetrofitManager.getInstance(this).getApi()
|
||||
.getNewsCommentnum(newsId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -262,7 +250,7 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
|
||||
}
|
||||
|
||||
private void getConcernDigest() {
|
||||
RetrofitManager.getApi().getNewsRichDigest(newsId)
|
||||
RetrofitManager.getInstance(this).getApi().getNewsRichDigest(newsId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ConcernEntity>() {
|
||||
@ -293,7 +281,7 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
|
||||
}
|
||||
|
||||
private void getNewsViews() {
|
||||
RetrofitManager.getData()
|
||||
RetrofitManager.getInstance(this).getData()
|
||||
.getNewsViews(newsId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -398,7 +386,7 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
|
||||
newsId = mConcernEntity.getId();
|
||||
}
|
||||
|
||||
PostCommentUtils.addCommentData(MessageDetailActivity.this, newsId, jsonObject.toString(), true, mCommentEntity,
|
||||
PostCommentUtils.addCommentData(MessageDetailActivity.this, newsId, jsonObject.toString(), mCommentEntity,
|
||||
new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSuccess(JSONObject response) {
|
||||
@ -407,17 +395,19 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
|
||||
mMessageDetailEt.setText("");
|
||||
|
||||
try {
|
||||
mCommentDao.add(new CommentInfo(response.getString("_id")));//添加评论id到数据库, 后续判断是否是自身评论
|
||||
JSONObject cacheObject = new JSONObject();
|
||||
JSONObject cacheUser = new JSONObject();
|
||||
JSONObject userData = new JSONObject();
|
||||
cacheUser.put("_id", TokenUtils.getDeviceId(MessageDetailActivity.this));
|
||||
cacheUser.put("icon", sp.getString("user_icon", null));
|
||||
cacheUser.put("name", sp.getString("user_name", "光环用户"));
|
||||
cacheUser.put("icon", mUserInfo.getIcon());
|
||||
cacheUser.put("name", mUserInfo.getName());
|
||||
userData.put("is_comment_own", true);
|
||||
cacheObject.put("_id", response.getString("_id"));
|
||||
cacheObject.put("content", content);
|
||||
cacheObject.put("time", System.currentTimeMillis() / 1000);
|
||||
cacheObject.put("vote", 0);
|
||||
cacheObject.put("user", cacheUser);
|
||||
cacheObject.put("user_data", userData);
|
||||
|
||||
if (mCommentEntity != null) {
|
||||
JSONObject cacheParent = new JSONObject();
|
||||
@ -442,8 +432,8 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
|
||||
// 完成评论操作,添加评论数
|
||||
adapter.addCommentCount();
|
||||
//修改评论缓存
|
||||
CommentManager.updateOkhttpCacheForId(newsId);
|
||||
CommentManager.updateOkhttpCache(newsId);
|
||||
CommentManager.updateOkhttpCacheForId(MessageDetailActivity.this, newsId);
|
||||
CommentManager.updateOkhttpCache(MessageDetailActivity.this, newsId);
|
||||
adapter.notifyItemInserted(adapter.getHotCommentListSize() + 2);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1); //刷新脚布局高度
|
||||
} else {
|
||||
@ -497,7 +487,7 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
|
||||
|
||||
private void modifyNewsCommentOkhttpCache(int offset, JSONObject commentData, String id) {
|
||||
String key = TimestampUtils.addTimestamp(Config.COMMENT_HOST + "article/" + id + "/comment?limit=10&offset=" + offset);
|
||||
byte[] data = OkHttpCache.getCache(key);
|
||||
byte[] data = OkHttpCache.getCache(this, key);
|
||||
if (data != null) {
|
||||
try {
|
||||
JSONArray jsonArray = new JSONArray(new String(data));
|
||||
@ -506,7 +496,7 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
|
||||
for (int i = 0, size = jsonArray.length() > 9 ? 9 : jsonArray.length(); i < size; i++) {
|
||||
newComment.put(jsonArray.get(i));
|
||||
}
|
||||
OkHttpCache.updateCache(key, newComment.toString().getBytes());
|
||||
OkHttpCache.updateCache(this, key, newComment.toString().getBytes());
|
||||
if (jsonArray.length() == 10) {
|
||||
modifyNewsCommentOkhttpCache(offset + 10, jsonArray.getJSONObject(9), id);
|
||||
}
|
||||
@ -533,6 +523,18 @@ public class MessageDetailActivity extends BaseActivity implements OnCommentCall
|
||||
}
|
||||
}
|
||||
|
||||
// 登录事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBReuse reuse) {
|
||||
if (reuse.getType().equals(LOGIN_TAG)) { // 登入
|
||||
mUserInfo = LoginUtils.getUserInfo(this);
|
||||
if (mUserInfo != null) {
|
||||
ImageUtils.Companion.display(mMessageDetailIconDv, mUserInfo.getIcon());
|
||||
mMessageDetailUserNameTv.setText(mUserInfo.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommentCallback(CommentEntity entity) {
|
||||
mCommentEntity = entity;
|
||||
|
||||
@ -12,21 +12,21 @@ import android.support.v4.view.MotionEventCompat;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.base.OnRequestCallBackListener;
|
||||
import com.gh.common.util.ApkActiveUtils;
|
||||
import com.gh.common.util.CheckLoginUtils;
|
||||
import com.gh.common.util.CollectionUtils;
|
||||
import com.gh.common.util.DataCollectionUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DetailDownloadUtils;
|
||||
@ -37,7 +37,9 @@ import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.viewholder.DetailViewHolder;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.NewsDetailEntity;
|
||||
import com.gh.gamecenter.entity.NewsEntity;
|
||||
import com.gh.gamecenter.entity.UserDataEntity;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
@ -45,13 +47,16 @@ import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.newsdetail.NewsDetailAdapter;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.google.gson.Gson;
|
||||
import com.jakewharton.rxbinding.view.RxView;
|
||||
import com.lightgame.download.DataWatcher;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.tencent.tauth.Tencent;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -88,12 +93,16 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
@BindView(R.id.news_detail_ll_coment)
|
||||
RelativeLayout mDetailCommentLl;
|
||||
|
||||
private ImageView iv_share;
|
||||
View mNewsShare;
|
||||
ImageView mNewsCollection;
|
||||
|
||||
private NewsDetailAdapter adapter;
|
||||
|
||||
private static final String KEY_COLLECTIONNEWS = "isCollectionNews";
|
||||
|
||||
private boolean isSentReport = false;
|
||||
private boolean isSecondDown = false;
|
||||
private boolean mIsCollectionNews;
|
||||
private float Y11, Y12, Y21, Y22;
|
||||
private float X11, X12, X21, X22;
|
||||
private double R11;
|
||||
@ -107,6 +116,7 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
private SharedPreferences sp;
|
||||
|
||||
private GameEntity gameEntity;
|
||||
private NewsEntity mNewsEntity;
|
||||
private DownloadEntity mDownloadEntity;
|
||||
|
||||
private Handler handler = new Handler();
|
||||
@ -135,15 +145,13 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
if (newsId != null) {
|
||||
getNewsDigest(newsId);
|
||||
} else {
|
||||
String id = getIntent().getStringExtra("id");
|
||||
String type = getIntent().getStringExtra("type");
|
||||
String title = getIntent().getStringExtra("title");
|
||||
if (type != null) {
|
||||
mActionbarTitle.setText(type);
|
||||
if (mNewsEntity == null) return;
|
||||
if (mNewsEntity.getType() != null) {
|
||||
mActionbarTitle.setText(mNewsEntity.getType());
|
||||
}
|
||||
adapter.setId(id);
|
||||
adapter.setType(type);
|
||||
adapter.setTitle(title);
|
||||
adapter.setId(mNewsEntity.getId());
|
||||
adapter.setType(mNewsEntity.getType());
|
||||
adapter.setTitle(mNewsEntity.getTitle());
|
||||
adapter.getNewsDetail();
|
||||
}
|
||||
}
|
||||
@ -160,29 +168,50 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
*/
|
||||
public static void startNewsDetailActivity(Context context, NewsEntity newsEntity, String entrance) {
|
||||
if (!TextUtils.isEmpty(newsEntity.getLink())) {
|
||||
Intent intent = new Intent(context, WebActivity.class);
|
||||
intent.putExtra("url", newsEntity.getLink());
|
||||
intent.putExtra("gameName", newsEntity.getGameName());
|
||||
intent.putExtra("newsId", newsEntity.getId());
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance + "+(消息详情[" + newsEntity.getGameName() + "])");
|
||||
context.startActivity(WebActivity.getIntentByNews(context, newsEntity, entrance));
|
||||
} else {
|
||||
Intent intent = new Intent(context, NewsDetailActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
intent.putExtra(NewsEntity.class.getSimpleName(), newsEntity);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 在收藏启动新闻详情页面
|
||||
*/
|
||||
public static void startNewsDetailByCollection(Context context, NewsEntity newsEntity, String entrance) {
|
||||
if (!TextUtils.isEmpty(newsEntity.getLink())) {
|
||||
Intent intent = WebActivity.getIntentByNews(context, newsEntity, entrance);
|
||||
context.startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(context, NewsDetailActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra("id", newsEntity.getId());
|
||||
intent.putExtra("title", newsEntity.getTitle());
|
||||
intent.putExtra("type", newsEntity.getType());
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
intent.putExtra(NewsEntity.class.getSimpleName(), newsEntity);
|
||||
intent.putExtra(KEY_COLLECTIONNEWS, true);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntentById(Context context, String newsId, boolean isCollectionNews, String entrance) {
|
||||
Intent intent = new Intent(context, NewsDetailActivity.class);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
intent.putExtra(KEY_COLLECTIONNEWS, isCollectionNews);
|
||||
intent.putExtra(EntranceUtils.KEY_NEWSID, newsId);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntentById(Context context, String newsId, String entrance) {
|
||||
Intent intent = new Intent(context, NewsDetailActivity.class);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
intent.putExtra("newsId", newsId);
|
||||
intent.putExtra(EntranceUtils.KEY_NEWSID, newsId);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@ -218,20 +247,22 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
|
||||
initTitle("");
|
||||
|
||||
// 添加分享图标
|
||||
iv_share = new ImageView(this);
|
||||
iv_share.setImageResource(R.drawable.ic_share);
|
||||
iv_share.setOnClickListener(this);
|
||||
iv_share.setVisibility(View.GONE);
|
||||
iv_share.setPadding(DisplayUtils.dip2px(this, 13), DisplayUtils.dip2px(this, 11)
|
||||
, DisplayUtils.dip2px(this, 11), DisplayUtils.dip2px(this, 13));
|
||||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
||||
DisplayUtils.dip2px(this, 48), ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
params.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
// 增加actionBar Button
|
||||
RelativeLayout reuse_actionbar = mContentView.findViewById(R.id.reuse_actionbar);
|
||||
mNewsShare = LayoutInflater.from(this).inflate(R.layout.menu_action_share, reuse_actionbar, false); // 绑定parentView 否则会丢失宽高
|
||||
mNewsShare.setVisibility(View.GONE);
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mNewsShare.getLayoutParams();
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
ViewGroup reuse_actionbar = (ViewGroup) mContentView.findViewById(
|
||||
R.id.reuse_actionbar);
|
||||
reuse_actionbar.addView(iv_share, params);
|
||||
params.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
reuse_actionbar.addView(mNewsShare, params);
|
||||
|
||||
mNewsCollection = (ImageView) LayoutInflater.from(this).inflate(R.layout.menu_action_collection, reuse_actionbar, false);
|
||||
mNewsCollection.setVisibility(View.GONE);
|
||||
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mNewsCollection.getLayoutParams();
|
||||
params2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
params2.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
params2.setMargins(0, 0 ,params.width, 0);
|
||||
reuse_actionbar.addView(mNewsCollection, params2);
|
||||
|
||||
mDetailRv.setHasFixedSize(true);
|
||||
mDetailRv.setLayoutManager(new LinearLayoutManager(this));
|
||||
@ -239,23 +270,27 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
adapter = new NewsDetailAdapter(this, this, mEntrance);
|
||||
mDetailRv.setAdapter(adapter);
|
||||
|
||||
newsId = getIntent().getStringExtra("newsId");
|
||||
if (getIntent().getBundleExtra("data") != null) {
|
||||
newsId = getIntent().getBundleExtra("data").getString("newsId");
|
||||
newsId = getIntent().getStringExtra(EntranceUtils.KEY_NEWSID);
|
||||
mIsCollectionNews = getIntent().getBooleanExtra(KEY_COLLECTIONNEWS, false);
|
||||
if (getIntent().getBundleExtra(EntranceUtils.KEY_DATA) != null) {
|
||||
newsId = getIntent().getBundleExtra(EntranceUtils.KEY_DATA).getString(EntranceUtils.KEY_NEWSID);
|
||||
}
|
||||
if (newsId == null) {
|
||||
String id = getIntent().getStringExtra("id");
|
||||
String type = getIntent().getStringExtra("type");
|
||||
String title = getIntent().getStringExtra("title");
|
||||
if (type != null) {
|
||||
mActionbarTitle.setText(type);
|
||||
}
|
||||
adapter.setId(id);
|
||||
adapter.setType(type);
|
||||
adapter.setTitle(title);
|
||||
adapter.getNewsDetail();
|
||||
mNewsEntity = getIntent().getParcelableExtra(NewsEntity.class.getSimpleName());
|
||||
if (mNewsEntity != null) {
|
||||
if (mNewsEntity.getType() != null) {
|
||||
mActionbarTitle.setText(mNewsEntity.getType());
|
||||
}
|
||||
adapter.setId(mNewsEntity.getId());
|
||||
adapter.setType(mNewsEntity.getType());
|
||||
adapter.setTitle(mNewsEntity.getTitle());
|
||||
adapter.getNewsDetail();
|
||||
mNewsShare.setVisibility(View.VISIBLE);
|
||||
|
||||
iv_share.setVisibility(View.VISIBLE);
|
||||
if (mIsCollectionNews) {
|
||||
getNewsDigest(mNewsEntity.getId());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getNewsDigest(newsId);
|
||||
}
|
||||
@ -284,9 +319,10 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
|
||||
mNoConn.setOnClickListener(this);
|
||||
mDetailCommentLl.setOnClickListener(this);
|
||||
mNewsCollection.setOnClickListener(this);
|
||||
|
||||
// 防抖处理
|
||||
RxView.clicks(iv_share)
|
||||
RxView.clicks(mNewsShare)
|
||||
.throttleFirst(1, TimeUnit.SECONDS)
|
||||
.subscribe(new Action1<Void>() {
|
||||
@Override
|
||||
@ -374,8 +410,14 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone() {
|
||||
|
||||
public void loadDone() { // 通知更新收藏按钮
|
||||
mNewsCollection.setVisibility(View.VISIBLE);
|
||||
NewsDetailEntity newsDetailEntity = adapter.getNewsDetailEntity();
|
||||
if (newsDetailEntity.getUserData() != null && newsDetailEntity.getUserData().isArticleFavorite()) {
|
||||
mNewsCollection.setImageResource(R.drawable.detail_collection_select);
|
||||
} else {
|
||||
mNewsCollection.setImageResource(R.drawable.detail_collection_unselect);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -401,12 +443,28 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
}
|
||||
|
||||
private void getNewsDigest(final String newsId) {
|
||||
RetrofitManager.getApi().getNewsDigest(newsId)
|
||||
RetrofitManager.getInstance(this).getApi().getNewsDigest(newsId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<NewsEntity>() {
|
||||
@Override
|
||||
public void onResponse(NewsEntity response) {
|
||||
if (mIsCollectionNews && mNewsEntity != null && response != null) { // 对比查看收藏文章是否修改
|
||||
Gson gson = new Gson();
|
||||
|
||||
|
||||
String newEntity = gson.toJson(response.getThumbnail());
|
||||
String entity = gson.toJson(mNewsEntity.getThumbnail());
|
||||
if (!newEntity.equals(entity) || !response.getType().equals(mNewsEntity.getType())
|
||||
|| !response.getTitle().equals(mNewsEntity.getTitle())) {
|
||||
CollectionUtils.INSTANCE.patchCollection(NewsDetailActivity.this, response.getId(), CollectionUtils.CollectionType.article);
|
||||
} else {
|
||||
Utils.log("========相同");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
mNewsEntity = response;
|
||||
if (response.getType() != null) {
|
||||
mActionbarTitle.setText(response.getType());
|
||||
}
|
||||
@ -416,7 +474,7 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
adapter.setTitle(response.getTitle());
|
||||
adapter.getNewsDetail();
|
||||
|
||||
iv_share.setVisibility(View.VISIBLE);
|
||||
mNewsShare.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -458,14 +516,14 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
adapter.setFontSize(fontsize);
|
||||
sp.edit().putInt("fontsize", fontsize).apply();
|
||||
String fontSizeText = getFontSize(fontsize);
|
||||
Toast.makeText(this, fontSizeText, Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(this, fontSizeText);
|
||||
}
|
||||
if ((R11 - R12) < -scrollSize && fontsize < 4) {
|
||||
fontsize++;
|
||||
adapter.setFontSize(fontsize);
|
||||
sp.edit().putInt("fontsize", fontsize).apply();
|
||||
String fontSizeText = getFontSize(fontsize);
|
||||
Toast.makeText(this, fontSizeText, Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(this, fontSizeText);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -506,14 +564,64 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
CheckLoginUtils.checkLogin(this, new CheckLoginUtils.OnLoggenInListener() {
|
||||
@Override
|
||||
public void onLoggedIn() {
|
||||
Intent intent = new Intent(NewsDetailActivity.this, MessageDetailActivity.class);
|
||||
intent.putExtra("commentNum", -1);
|
||||
intent.putExtra("newsId", adapter.getNewsDetailEntity().getId());
|
||||
intent.putExtra("openSoftInput", true);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, mEntrance + "(新闻详情[" + adapter.getTitle() + "])");
|
||||
Intent intent = MessageDetailActivity.getIntentById(NewsDetailActivity.this, adapter.getNewsDetailEntity().getId(), null, true
|
||||
, mEntrance + "(新闻详情[" + adapter.getTitle() + "])");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
} else if (v == mNewsCollection) {
|
||||
CheckLoginUtils.checkLogin(this, new CheckLoginUtils.OnLoggenInListener() {
|
||||
@Override
|
||||
public void onLoggedIn() {
|
||||
final NewsDetailEntity newsDetailEntity = adapter.getNewsDetailEntity();
|
||||
mNewsCollection.setEnabled(false);
|
||||
if (newsDetailEntity.getUserData() != null && newsDetailEntity.getUserData().isArticleFavorite()) {
|
||||
CollectionUtils.INSTANCE.deleteCollection(NewsDetailActivity.this, mNewsEntity.getId(),
|
||||
CollectionUtils.CollectionType.article,
|
||||
new CollectionUtils.OnCollectionListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
newsDetailEntity.getUserData().setArticleFavorite(false);
|
||||
mNewsCollection.setEnabled(true);
|
||||
mNewsCollection.setImageResource(R.drawable.detail_collection_unselect);
|
||||
toast("取消收藏");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
mNewsCollection.setEnabled(true);
|
||||
toast("取消收藏失败");
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("_id", mNewsEntity.getId());
|
||||
CollectionUtils.INSTANCE.postCollection(NewsDetailActivity.this, new JSONObject(map).toString(),
|
||||
CollectionUtils.CollectionType.article,
|
||||
new CollectionUtils.OnCollectionListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
UserDataEntity userData = newsDetailEntity.getUserData();
|
||||
if (userData == null) {
|
||||
userData = new UserDataEntity();
|
||||
newsDetailEntity.setUserData(userData);
|
||||
}
|
||||
userData.setArticleFavorite(true);
|
||||
mNewsCollection.setEnabled(true);
|
||||
mNewsCollection.setImageResource(R.drawable.detail_collection_select);
|
||||
toast("收藏成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
mNewsCollection.setEnabled(true);
|
||||
toast("收藏失败");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -537,7 +645,7 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
mDetailBottomLl.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
RetrofitManager.getApi().getGameNewsDigest(gameId)
|
||||
RetrofitManager.getInstance(this).getApi().getGameNewsDigest(gameId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@ -558,7 +666,12 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
// 关注事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBConcernChanged changed) {
|
||||
if (gameEntity != null && changed.isSingle() && changed.getGameId().equals(gameEntity.getId())) {
|
||||
NewsDetailEntity newsDetailEntity = adapter.getNewsDetailEntity();
|
||||
if (newsDetailEntity != null && gameEntity != null && changed.isSingle() && changed.getGameId().equals(gameEntity.getId())) {
|
||||
if (newsDetailEntity.getUserData() == null) {
|
||||
newsDetailEntity.setUserData(new UserDataEntity());
|
||||
}
|
||||
newsDetailEntity.getUserData().setGameConcerned(changed.isConcern());
|
||||
adapter.notifyItemChanged(1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,7 +16,6 @@ import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DataCollectionUtils;
|
||||
@ -29,6 +28,7 @@ import com.gh.gamecenter.adapter.viewholder.NewsTextViewHolder;
|
||||
import com.gh.gamecenter.entity.NewsEntity;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -78,9 +78,9 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context, String gameName, String searchKey, String gameId, String entrance) {
|
||||
Intent intent = new Intent(context, NewsSearchActivity.class);
|
||||
intent.putExtra("gameName", gameName);
|
||||
intent.putExtra("searchKey", searchKey);
|
||||
intent.putExtra("gameId", gameId);
|
||||
intent.putExtra(EntranceUtils.KEY_GAMENAME, gameName);
|
||||
intent.putExtra(EntranceUtils.KEY_SEARCHKEY, searchKey);
|
||||
intent.putExtra(EntranceUtils.KEY_GAMEID, gameId);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
return intent;
|
||||
}
|
||||
@ -96,9 +96,9 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Intent intent = getIntent();
|
||||
String gameName = intent.getExtras().getString("gameName");
|
||||
searchKey = intent.getExtras().getString("searchKey");
|
||||
gameId = intent.getExtras().getString("gameId");
|
||||
String gameName = intent.getExtras().getString(EntranceUtils.KEY_GAMENAME);
|
||||
searchKey = intent.getExtras().getString(EntranceUtils.KEY_SEARCHKEY);
|
||||
gameId = intent.getExtras().getString(EntranceUtils.KEY_GAMEID);
|
||||
|
||||
initTitle(gameName);
|
||||
|
||||
@ -138,7 +138,7 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
}, 500);
|
||||
|
||||
} else {
|
||||
Toast.makeText(NewsSearchActivity.this, "请输入关键字", Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(NewsSearchActivity.this, getString(R.string.search_hint));
|
||||
}
|
||||
|
||||
}
|
||||
@ -183,7 +183,7 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
// DataUtils.onEvent(this, "游戏新闻搜索", searchKey);
|
||||
// DataCollectionUtils.uploadSearch(this, searchKey, "游戏新闻搜索");
|
||||
|
||||
RetrofitManager.getApi().getSearchNews(gameId, searchKey, page, 20)
|
||||
RetrofitManager.getInstance(this).getApi().getSearchNews(gameId, searchKey, page, 20)
|
||||
.map(new Func1<List<NewsEntity>, List<NewsEntity>>() {
|
||||
@Override
|
||||
public List<NewsEntity> call(List<NewsEntity> list) {
|
||||
@ -224,7 +224,7 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
mLoading.setVisibility(View.GONE);
|
||||
}
|
||||
isLoadOver = true;
|
||||
toast("加载失败,请检查网络状态");
|
||||
toast(R.string.loading_failed_hint);
|
||||
isNetworkError = true;
|
||||
searchAdapter.notifyItemChanged(searchAdapter.getItemCount() - 1);
|
||||
}
|
||||
@ -266,8 +266,9 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
"列表", "游戏新闻搜索", newsEntity.getTitle());
|
||||
|
||||
// 统计阅读量
|
||||
NewsUtils.statNewsViews(newsEntity.getId());
|
||||
NewsDetailActivity.startNewsDetailActivity(NewsSearchActivity.this, newsEntity, mEntrance + "+(游戏新闻搜索:" + searchKey + ")");
|
||||
NewsUtils.statNewsViews(NewsSearchActivity.this, newsEntity.getId());
|
||||
NewsDetailActivity.startNewsDetailActivity(NewsSearchActivity.this, newsEntity,
|
||||
mEntrance + "+(游戏新闻搜索[" + searchKey + "])");
|
||||
}
|
||||
});
|
||||
} else if (holder instanceof FooterViewHolder) {
|
||||
|
||||
138
app/src/main/java/com/gh/gamecenter/NormalActivity.java
Normal file
138
app/src/main/java/com/gh/gamecenter/NormalActivity.java
Normal file
@ -0,0 +1,138 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.MenuRes;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.gamecenter.normal.NormalFragment;
|
||||
import com.gh.gamecenter.normal.ToolbarController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by khy on 17/10/17.
|
||||
*/
|
||||
|
||||
public class NormalActivity extends BaseActivity implements ToolbarController, Toolbar.OnMenuItemClickListener {
|
||||
|
||||
@BindView(R.id.normal_toolbar)
|
||||
Toolbar mNormalToolbar;
|
||||
@BindView(R.id.normal_title)
|
||||
TextView mNormalTitle;
|
||||
|
||||
private Fragment mTargetFragment;
|
||||
|
||||
public static final String NORMAL_FRAGMENT_NAME = "normalFragmentName";
|
||||
public static final String NORMAL_FRAGMENT_BUNDLE = "normalFragmentBundle";
|
||||
|
||||
public static void startFragment(Context context, Class<? extends NormalFragment> t) {
|
||||
Intent intent = new Intent(context, NormalActivity.class);
|
||||
intent.putExtra(NORMAL_FRAGMENT_NAME, t.getCanonicalName());
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static void startFragment(Context context, Class<? extends NormalFragment> t, Bundle bundle) {
|
||||
Intent intent = new Intent(context, NormalActivity.class);
|
||||
intent.putExtra(NORMAL_FRAGMENT_NAME, t.getCanonicalName());
|
||||
intent.putExtra(NORMAL_FRAGMENT_BUNDLE, bundle);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static void startFragmentForResult(Context context, Class<? extends NormalFragment> t, int requestCode) {
|
||||
Intent intent = new Intent(context, NormalActivity.class);
|
||||
intent.putExtra(NORMAL_FRAGMENT_NAME, t.getCanonicalName());
|
||||
if (context instanceof Activity) {
|
||||
((Activity) context).startActivityForResult(intent, requestCode);
|
||||
}
|
||||
}
|
||||
|
||||
public static void startFragmentForResult(Context context, Class<? extends NormalFragment> t, Bundle bundle, int requestCode) {
|
||||
Intent intent = new Intent(context, NormalActivity.class);
|
||||
intent.putExtra(NORMAL_FRAGMENT_NAME, t.getCanonicalName());
|
||||
intent.putExtra(NORMAL_FRAGMENT_BUNDLE, bundle);
|
||||
if (context instanceof Activity) {
|
||||
((Activity) context).startActivityForResult(intent, requestCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_normal;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState == null && getIntent() != null) {
|
||||
handleIntent(getIntent());
|
||||
}
|
||||
// setSupportActionBar(mNormalToolbar); // 替换actionBar后 toolBar无法控制
|
||||
mNormalToolbar.setNavigationIcon(R.drawable.ic_bar_back);
|
||||
mNormalToolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
onBackPressed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
if (getIntent() != null) handleIntent(intent);
|
||||
}
|
||||
|
||||
private void handleIntent(Intent intent) {
|
||||
String fraName = intent.getStringExtra(NORMAL_FRAGMENT_NAME);
|
||||
Bundle bundle = intent.getBundleExtra(NORMAL_FRAGMENT_BUNDLE);
|
||||
if (TextUtils.isEmpty(fraName)) return;
|
||||
mTargetFragment = Fragment.instantiate(this, fraName, bundle);
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.normal_content, mTargetFragment).commitNowAllowingStateLoss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNavigationTitle(@StringRes int res) {
|
||||
mNormalTitle.setText(res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNavigationTitle(CharSequence res) {
|
||||
mNormalTitle.setText(res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setToolbarMenu(@MenuRes int res) {
|
||||
mNormalToolbar.inflateMenu(res);
|
||||
mNormalToolbar.setOnMenuItemClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
||||
if (mTargetFragment instanceof NormalFragment) {
|
||||
((NormalFragment) mTargetFragment).onMenuItemClick(menuItem);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
List<Fragment> fragments = getSupportFragmentManager().getFragments();
|
||||
for (Fragment fragment : fragments) {
|
||||
fragment.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -22,13 +22,11 @@ import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.RandomUtils;
|
||||
import com.gh.common.util.UserIconUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.gh.common.view.RadarLayout;
|
||||
import com.gh.gamecenter.kuaichuan.BaseTransfer;
|
||||
import com.gh.gamecenter.kuaichuan.Constant;
|
||||
@ -37,7 +35,8 @@ import com.gh.gamecenter.kuaichuan.HotspotManager;
|
||||
import com.gh.gamecenter.kuaichuan.IpPortInfo;
|
||||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||||
import com.gh.gamecenter.receiver.WifiAPBroadcastReceiver;
|
||||
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -145,10 +144,10 @@ public class ReceiverWaitingActivity extends BaseActivity {
|
||||
|
||||
//修改沉浸栏以及ActionBar 颜色
|
||||
mActionbar.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.scan_bg));
|
||||
SystemBarTintManager tintManager = getTintManager();
|
||||
if (tintManager != null) {
|
||||
tintManager.setStatusBarTintResource(R.color.scan_bg);
|
||||
}
|
||||
// SystemBarTintManager tintManager = getTintManager(); // TODO: 27/09/17 更改沉浸栏颜色
|
||||
// if (tintManager != null) {
|
||||
// tintManager.setStatusBarTintResource(R.color.scan_bg);
|
||||
// }
|
||||
|
||||
sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
mIsInitialized = false;
|
||||
@ -182,11 +181,11 @@ public class ReceiverWaitingActivity extends BaseActivity {
|
||||
public void onWifiApEnabled() {
|
||||
if (!mIsInitialized) {
|
||||
mUdpServerRunnable = createSendMsgToFileSenderRunnable();
|
||||
AppController.MAIN_EXECUTOR.execute(mUdpServerRunnable);
|
||||
HaloApp.MAIN_EXECUTOR.execute(mUdpServerRunnable);
|
||||
mIsInitialized = true;
|
||||
|
||||
mWaitingConn.setVisibility(View.VISIBLE);
|
||||
mUserStatus.setText(Html.fromHtml("成功创建热点:" + "<font color=\"#fff500\">" + mySsid + "</font>"));
|
||||
mUserStatus.setText(Html.fromHtml(getString(R.string.create_hotspot, mySsid)));
|
||||
mWaitingHint.setVisibility(View.GONE);
|
||||
mUserName.setVisibility(View.GONE);
|
||||
mGPRSHint.setVisibility(View.VISIBLE);
|
||||
@ -332,7 +331,7 @@ public class ReceiverWaitingActivity extends BaseActivity {
|
||||
if (msg != null && msg.contains(Constant.MSG_FILE_RECEIVER_INIT)) {
|
||||
Utils.log("接收方初始化完毕准备进去传输页面 并回馈消息给发送者" + inetAddress);
|
||||
|
||||
// AppController.put("FileInfo", mFileInfos); //保存数据列表 启用改为Intent传输
|
||||
// HaloApp.put("FileInfo", mFileInfos); //保存数据列表 启用改为Intent传输
|
||||
|
||||
// 反馈 文件发送方的消息
|
||||
// sendData = Constant.MSG_FILE_RECEIVER_INIT_SUCCESS.getBytes(BaseTransfer.UTF_8);
|
||||
@ -370,17 +369,6 @@ public class ReceiverWaitingActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
// @OnClick(R.id.actionbar_rl_back)
|
||||
// public void onBackListener() {
|
||||
// Utils.log("=========back");
|
||||
// colsePage();
|
||||
// //关闭热点
|
||||
// HotspotManager.disableAp(this);
|
||||
//
|
||||
// if (isOpenWifi) {
|
||||
// WifiMgr.getInstance(this).openWifi();
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 解析FileInfo
|
||||
|
||||
@ -42,6 +42,10 @@ public class SearchActivity extends BaseActivity {
|
||||
|
||||
private SearchHistoryDao dao;
|
||||
|
||||
private static final String KEY_CURRENTTAG = "currentTab";
|
||||
private static final String KEY_SEARCHTYPE = "searchType";
|
||||
private static final String KEY_CLICKED = "clicked";
|
||||
|
||||
private String searchKey;
|
||||
private String searchType;
|
||||
|
||||
@ -61,8 +65,8 @@ public class SearchActivity extends BaseActivity {
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context,boolean clicked, String hint, String entrance) {
|
||||
Intent intent = new Intent(context, SearchActivity.class);
|
||||
intent.putExtra("clicked", clicked);
|
||||
intent.putExtra("hint", hint);
|
||||
intent.putExtra(KEY_CLICKED, clicked);
|
||||
intent.putExtra(EntranceUtils.KEY_HINT, hint);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
return intent;
|
||||
}
|
||||
@ -70,9 +74,9 @@ public class SearchActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("currentTab", currentTab);
|
||||
outState.putString("searchKey", searchKey);
|
||||
outState.putString("searchType", searchType);
|
||||
outState.putInt(KEY_CURRENTTAG, currentTab);
|
||||
outState.putString(EntranceUtils.KEY_SEARCHKEY, searchKey);
|
||||
outState.putString(KEY_SEARCHTYPE, searchType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -86,16 +90,16 @@ public class SearchActivity extends BaseActivity {
|
||||
|
||||
dao = new SearchHistoryDao(this);
|
||||
|
||||
boolean isFromHome = getIntent().getBooleanExtra("clicked", false);
|
||||
String hint = getIntent().getStringExtra("hint");
|
||||
boolean isFromHome = getIntent().getBooleanExtra(KEY_CLICKED, false);
|
||||
String hint = getIntent().getStringExtra(EntranceUtils.KEY_HINT);
|
||||
|
||||
setActionBarLayout();
|
||||
|
||||
currentTab = 0;
|
||||
if (savedInstanceState != null) {
|
||||
currentTab = savedInstanceState.getInt("currentTab", 0);
|
||||
searchKey = savedInstanceState.getString("searchKey", null);
|
||||
searchType = savedInstanceState.getString("searchType", null);
|
||||
currentTab = savedInstanceState.getInt(KEY_CURRENTTAG, 0);
|
||||
searchKey = savedInstanceState.getString(EntranceUtils.KEY_SEARCHKEY, null);
|
||||
searchType = savedInstanceState.getString(KEY_SEARCHTYPE, null);
|
||||
if (currentTab != 0 && !TextUtils.isEmpty(searchKey)) {
|
||||
search(searchType, searchKey);
|
||||
}
|
||||
|
||||
@ -14,6 +14,8 @@ import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.common.util.RandomUtils;
|
||||
import com.gh.common.util.UserIconUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
@ -23,18 +25,24 @@ import org.json.JSONObject;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
import static com.gh.gamecenter.UserInfoActivity.USERINFO_CHANGE_REQUEST;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/2/10.
|
||||
*/
|
||||
public class SelectUserIconActivity extends BaseActivity {
|
||||
public class SelectUserIconActivity extends BaseActivity implements LoginUtils.onChangeUserInfoListener {
|
||||
|
||||
@BindView(R.id.skip_media_store)
|
||||
TextView mSkipMediaStore;
|
||||
|
||||
public final static int CROP_ICON_REQUEST = 12;
|
||||
public final static int MEDIA_ICON_REQUEST = 13;
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
@NonNull
|
||||
@ -51,7 +59,7 @@ public class SelectUserIconActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (data != null && requestCode == 0x123) {
|
||||
if (data != null && requestCode == MEDIA_ICON_REQUEST) {
|
||||
Uri selectedImage = data.getData();
|
||||
if (selectedImage == null) {
|
||||
return;
|
||||
@ -71,13 +79,14 @@ public class SelectUserIconActivity extends BaseActivity {
|
||||
Utils.log("picturePath = " + picturePath);
|
||||
// 上传头像
|
||||
Intent intent = CropImageActivity.getIntent(this, picturePath, "我的光环(选择头像)");
|
||||
startActivityForResult(intent, 0x124);
|
||||
} else if (data != null && requestCode == 0x124) {
|
||||
String url = data.getExtras().getString("url");
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("url", url);
|
||||
setResult(0x125, intent);
|
||||
finish();
|
||||
startActivityForResult(intent, CROP_ICON_REQUEST);
|
||||
} else if (data != null && requestCode == CROP_ICON_REQUEST) {
|
||||
String url = data.getExtras().getString(EntranceUtils.KEY_URL);
|
||||
// Intent intent = new Intent();
|
||||
// intent.putExtra("url", url);
|
||||
// setResult(0x125, intent);
|
||||
// finish();
|
||||
LoginUtils.changeUserInfo(this, this, url, "icon");
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,7 +132,7 @@ public class SelectUserIconActivity extends BaseActivity {
|
||||
String iconCount = sp.getString("updateIconCount", null);
|
||||
if (!TextUtils.isEmpty(iconCount)) {
|
||||
long l = System.currentTimeMillis();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.CHINA);
|
||||
String time = format.format(new Date(l));
|
||||
|
||||
JSONObject json;
|
||||
@ -139,7 +148,7 @@ public class SelectUserIconActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
startActivityForResult(intent, 0x123);
|
||||
startActivityForResult(intent, MEDIA_ICON_REQUEST);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -166,10 +175,16 @@ public class SelectUserIconActivity extends BaseActivity {
|
||||
|
||||
sp.edit().putBoolean("changeDefaultIcon", true).apply();
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("url", iconUrl);
|
||||
setResult(0x125, intent);
|
||||
finish();
|
||||
// Intent intent = new Intent();
|
||||
// intent.putExtra("url", iconUrl);
|
||||
// setResult(0x125, intent);
|
||||
// finish();
|
||||
LoginUtils.changeUserInfo(this, this, iconUrl, "icon");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange() {
|
||||
setResult(USERINFO_CHANGE_REQUEST);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,21 +9,29 @@ import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.common.util.StringUtils;
|
||||
import com.gh.gamecenter.entity.LoginResponseEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.kyleduo.switchbutton.SwitchButton;
|
||||
import com.lightgame.download.FileUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.tencent.bugly.beta.Beta;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
@ -39,14 +47,12 @@ import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
import static com.gh.gamecenter.R.id.setting_rl_about;
|
||||
import static com.gh.gamecenter.personal.PersonalFragment.LOGIN_CODE;
|
||||
import static com.gh.gamecenter.personal.PersonalFragment.LOGOUT_TAG;
|
||||
import static java.lang.Thread.sleep;
|
||||
|
||||
/**
|
||||
* 游戏设置页面
|
||||
*
|
||||
* @author 吕方
|
||||
* @ 吕方
|
||||
* @since 0814
|
||||
*/
|
||||
public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
@ -61,6 +67,10 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
TextView mSettingCacheTv;
|
||||
@BindView(R.id.setting_tv_size)
|
||||
TextView mSettingSizeTv;
|
||||
@BindView(R.id.setting_logout_tv)
|
||||
TextView mSettingLoginType;
|
||||
@BindView(R.id.setting_logout_rl)
|
||||
RelativeLayout mSettingLoginRl;
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
@ -110,6 +120,39 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
checkSizeIndex = 1;
|
||||
}
|
||||
fontTextSize(checkSizeIndex);
|
||||
|
||||
initLoginStatus();
|
||||
}
|
||||
|
||||
private void initLoginStatus() {
|
||||
LoginResponseEntity loginToken = LoginUtils.getLoginToken(this);
|
||||
if (loginToken != null) {
|
||||
if (!TextUtils.isEmpty(loginToken.getLoginType())) {
|
||||
String loginType = loginToken.getLoginType().trim();
|
||||
switch (loginType) {
|
||||
case "qq":
|
||||
loginType = "QQ";
|
||||
break;
|
||||
case "wechat":
|
||||
loginType = "微信";
|
||||
break;
|
||||
case "weibo":
|
||||
loginType = "新浪微博";
|
||||
break;
|
||||
default:
|
||||
if (loginType.length() == 11) {
|
||||
String sub1 = loginType.substring(0, 3);
|
||||
String sub2 = loginType.substring(9, 11);
|
||||
loginType = StringUtils.buildString(sub1, "******", sub2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
mSettingLoginType.setText(loginType);
|
||||
}
|
||||
mSettingLoginRl.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mSettingLoginRl.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -216,20 +259,28 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
fontSize();
|
||||
break;
|
||||
case setting_rl_about:
|
||||
if (BuildConfig.DEBUG) {
|
||||
Beta.checkUpgrade(); // 手动检查热补丁
|
||||
}
|
||||
startActivity(AboutActivity.getIntent(this));
|
||||
break;
|
||||
case R.id.setting_rl_concerngame:
|
||||
mSettingConcerngameSb.performClick();
|
||||
break;
|
||||
case R.id.setting_logout_rl:
|
||||
DialogUtils.showAlertDialog(this, "注销登录", "退出账号即会回到游客状态,很多功能将无法使用(例如评论、客服消息),确定退出吗?",
|
||||
DialogUtils.showForceDialog(this, "注销登录", "退出账号即会回到游客状态,很多功能将无法使用(例如评论、客服消息),确定退出吗?",
|
||||
"确定退出", "取消", new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("loginStatus", LOGOUT_TAG);
|
||||
setResult(LOGIN_CODE, intent);
|
||||
finish();
|
||||
loadingDialog = DialogUtils.showWaitDialog(SettingActivity.this, "退出登录中...");
|
||||
LoginUtils.logout(SettingActivity.this, new LoginUtils.OnLogoutListener() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
LoginUtils.cleanUserData(SettingActivity.this);
|
||||
if (loadingDialog != null) loadingDialog.dismiss();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, null);
|
||||
break;
|
||||
@ -285,6 +336,19 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
.create();
|
||||
alertDialog.show();
|
||||
|
||||
TextView mesage = (TextView) alertDialog.findViewById(android.R.id.message);
|
||||
Button positiveBtn = alertDialog.getButton(android.app.AlertDialog.BUTTON_POSITIVE);
|
||||
Button negativeBtn = alertDialog.getButton(android.app.AlertDialog.BUTTON_NEGATIVE);
|
||||
|
||||
positiveBtn.setTextSize(14);
|
||||
positiveBtn.setTextColor(ContextCompat.getColor(this, R.color.theme));
|
||||
negativeBtn.setTextSize(14);
|
||||
negativeBtn.setTextColor(ContextCompat.getColor(this, R.color.theme));
|
||||
if (mesage != null) {
|
||||
mesage.setTextSize(14);
|
||||
mesage.setTextColor(ContextCompat.getColor(this, R.color.system_bar));
|
||||
}
|
||||
|
||||
|
||||
// final Dialog dialog = new Dialog(this);
|
||||
// View inflate = View.inflate(this, R.layout.dialog_font_size, null);
|
||||
@ -345,7 +409,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
loadingDialog.dismiss();
|
||||
}
|
||||
mSettingCacheTv.setText(getCacheSize());
|
||||
Toast.makeText(SettingActivity.this, "缓存清除成功", Toast.LENGTH_SHORT).show();
|
||||
Utils.toast(SettingActivity.this, "缓存清除成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -21,7 +21,6 @@ import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.MessageShareUtils;
|
||||
import com.gh.common.util.QRCodeUtils;
|
||||
import com.gh.gamecenter.entity.ConcernEntity;
|
||||
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
||||
import com.tencent.tauth.Tencent;
|
||||
|
||||
import java.io.File;
|
||||
@ -59,11 +58,11 @@ public class ShareCardActivity extends BaseActivity {
|
||||
public static Intent getIntent(Context context, ConcernEntity concernEntity, String shareContent) {
|
||||
Intent intent = new Intent(context, ShareCardActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("gameName", concernEntity.getGameName());
|
||||
bundle.putString("gameIconUrl", concernEntity.getGameIcon());
|
||||
bundle.putString("shareContent", shareContent);
|
||||
bundle.putString(EntranceUtils.KEY_GAMENAME, concernEntity.getGameName());
|
||||
bundle.putString(EntranceUtils.KEY_GAME_ICON_URL, concernEntity.getGameIcon());
|
||||
bundle.putString(EntranceUtils.KEY_SHARECONTENT, shareContent);
|
||||
if (concernEntity.getLink() == null) {
|
||||
bundle.putString("newsId", concernEntity.getId());
|
||||
bundle.putString(EntranceUtils.KEY_NEWSID, concernEntity.getId());
|
||||
}
|
||||
intent.putExtras(bundle);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, "(资讯:关注[2-4])");
|
||||
@ -90,10 +89,10 @@ public class ShareCardActivity extends BaseActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Bundle extras = getIntent().getExtras();
|
||||
gameName = extras.getString("gameName");
|
||||
gameIconUrl = extras.getString("gameIconUrl");
|
||||
shareContent = extras.getString("shareContent");
|
||||
newsId = extras.getString("newsId");
|
||||
gameName = extras.getString(EntranceUtils.KEY_GAMENAME);
|
||||
gameIconUrl = extras.getString(EntranceUtils.KEY_GAME_ICON_URL);
|
||||
shareContent = extras.getString(EntranceUtils.KEY_SHARECONTENT);
|
||||
newsId = extras.getString(EntranceUtils.KEY_NEWSID);
|
||||
|
||||
picName = "shareImg.jpg";
|
||||
|
||||
@ -101,10 +100,6 @@ public class ShareCardActivity extends BaseActivity {
|
||||
|
||||
//修改沉浸栏以及ActionBar 颜色
|
||||
mActionbar.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), android.R.color.black));
|
||||
SystemBarTintManager tintManager = getTintManager();
|
||||
if (tintManager != null) {
|
||||
tintManager.setStatusBarTintResource(android.R.color.black);
|
||||
}
|
||||
|
||||
mShareGameNameTv.setText(gameName);
|
||||
mShareContentTv.setText(Html.fromHtml(shareContent));
|
||||
|
||||
@ -30,7 +30,6 @@ import com.gh.common.util.QRCodeUtils;
|
||||
import com.gh.common.util.StringUtils;
|
||||
import com.gh.gamecenter.entity.ConcernEntity;
|
||||
import com.gh.gamecenter.retrofit.ObservableUtil;
|
||||
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
||||
import com.tencent.tauth.Tencent;
|
||||
|
||||
import java.io.File;
|
||||
@ -73,11 +72,16 @@ public class ShareCardPicActivity extends BaseActivity {
|
||||
ImageView mShareChangImageIcon;
|
||||
@BindView(R.id.sharecard_chang_img_tv)
|
||||
TextView mShareChangImageTv;
|
||||
int currentImgPosition;
|
||||
|
||||
public static final String KEY_SHARE_ARRIMG = "shareArrImg";
|
||||
|
||||
private String gameName;
|
||||
private String gameIconUrl;
|
||||
private String shareContent;
|
||||
private String picName;
|
||||
|
||||
private int currentImgPosition;
|
||||
|
||||
private List<String> shareArrImg;
|
||||
|
||||
private Bitmap shareBm;
|
||||
@ -97,14 +101,14 @@ public class ShareCardPicActivity extends BaseActivity {
|
||||
|
||||
Intent intent = new Intent(context, ShareCardPicActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("gameName", concernEntity.getGameName());
|
||||
bundle.putString("gameIconUrl", concernEntity.getGameIcon());
|
||||
bundle.putString("shareContent", shareContent);
|
||||
bundle.putString(EntranceUtils.KEY_GAMENAME, concernEntity.getGameName());
|
||||
bundle.putString(EntranceUtils.KEY_GAME_ICON_URL, concernEntity.getGameIcon());
|
||||
bundle.putString(EntranceUtils.KEY_SHARECONTENT, shareContent);
|
||||
if (concernEntity.getLink() == null) {
|
||||
bundle.putString("newsId", concernEntity.getId());
|
||||
bundle.putString(EntranceUtils.KEY_NEWSID, concernEntity.getId());
|
||||
}
|
||||
if (concernEntity.getImg() != null && concernEntity.getImg().size() > 0) {
|
||||
bundle.putStringArrayList("shareArrImg", (ArrayList<String>) concernEntity.getImg());
|
||||
bundle.putStringArrayList(KEY_SHARE_ARRIMG, (ArrayList<String>) concernEntity.getImg());
|
||||
}
|
||||
intent.putExtras(bundle);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, StringUtils.buildString(entrance, "+(消息详情[", concernEntity.getGameName(), "])"));
|
||||
@ -131,11 +135,11 @@ public class ShareCardPicActivity extends BaseActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Bundle extras = getIntent().getExtras();
|
||||
gameName = extras.getString("gameName");
|
||||
gameIconUrl = extras.getString("gameIconUrl");
|
||||
shareContent = extras.getString("shareContent");
|
||||
newsId = extras.getString("newsId");
|
||||
List<String> arrImg = extras.getStringArrayList("shareArrImg");
|
||||
gameName = extras.getString(EntranceUtils.KEY_GAMENAME);
|
||||
gameIconUrl = extras.getString(EntranceUtils.KEY_GAME_ICON_URL);
|
||||
shareContent = extras.getString(EntranceUtils.KEY_SHARECONTENT);
|
||||
newsId = extras.getString(EntranceUtils.KEY_NEWSID);
|
||||
List<String> arrImg = extras.getStringArrayList(KEY_SHARE_ARRIMG);
|
||||
|
||||
picName = "shareImgPic.jpg";
|
||||
currentImgPosition = 0;
|
||||
@ -146,10 +150,6 @@ public class ShareCardPicActivity extends BaseActivity {
|
||||
shareArrImg.addAll(arrImg);
|
||||
|
||||
mActionbar.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), android.R.color.black));
|
||||
SystemBarTintManager tintManager = getTintManager();
|
||||
if (tintManager != null) {
|
||||
tintManager.setStatusBarTintResource(android.R.color.black);
|
||||
}
|
||||
|
||||
latch = ObservableUtil.latch(shareArrImg.size(), new Action1<Object>() {
|
||||
@Override
|
||||
@ -289,8 +289,7 @@ public class ShareCardPicActivity extends BaseActivity {
|
||||
// 获取scrollview实际高度
|
||||
for (int i = 0; i < scrollView.getChildCount(); i++) {
|
||||
h += scrollView.getChildAt(i).getHeight();
|
||||
scrollView.getChildAt(i).setBackgroundColor(
|
||||
Color.parseColor("#ffffff"));
|
||||
scrollView.getChildAt(i).setBackgroundColor(Color.WHITE);
|
||||
}
|
||||
|
||||
// 创建对应大小的bitmap
|
||||
|
||||
@ -65,9 +65,9 @@ public class ShareGhActivity extends BaseActivity {
|
||||
initTitle(getString(R.string.title_share_gh));
|
||||
ButterKnife.bind(this);
|
||||
|
||||
mGhAddress.setText(Html.fromHtml("<u>" + "www.ghzs666.com" + "</u>"));
|
||||
QRCodeUtils.setQRCode(this, "http://www.ghzs666.com/link?source=appshare100", mGhQrcode);
|
||||
ShareUtils.getInstance(this).showShareWindows(mShareRl, "http://www.ghzs666.com/link?source=appshare300", "光环助手"
|
||||
mGhAddress.setText(Html.fromHtml("<u>" + "www.ghzs.com" + "</u>"));
|
||||
QRCodeUtils.setQRCode(this, "http://www.ghzs.com/link?source=appshare100", mGhQrcode);
|
||||
ShareUtils.getInstance(this).showShareWindows(mShareRl, "http://www.ghzs.com/link?source=appshare300", "光环助手"
|
||||
, "http://image.ghzs666.com/pic/57d604808ab49e467d8b4568.png", null, false, false, false);
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ public class ShareGhActivity extends BaseActivity {
|
||||
@OnClick(R.id.gh_address_tv)
|
||||
public void copyAddress() {
|
||||
ClipboardManager cmb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cmb.setText("http://www.ghzs666.com/link?source=appshare100");
|
||||
cmb.setText("http://www.ghzs.com/link?source=appshare100");
|
||||
|
||||
Utils.toast(this, "网址复制成功,请到微信/QQ粘贴分享");
|
||||
}
|
||||
|
||||
@ -4,7 +4,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
@ -17,11 +16,9 @@ import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.RandomUtils;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.gh.gamecenter.entity.KcWebRequestEntity;
|
||||
import com.gh.gamecenter.kuaichuan.Constant;
|
||||
import com.gh.gamecenter.kuaichuan.DownloadUriHandler;
|
||||
@ -31,6 +28,8 @@ import com.gh.gamecenter.kuaichuan.ImageUriHandler;
|
||||
import com.gh.gamecenter.kuaichuan.KcUriHandler;
|
||||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||||
import com.gh.gamecenter.receiver.WifiAPBroadcastReceiver;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -185,12 +184,12 @@ public class ShareGhWfifActivity extends BaseActivity {
|
||||
case 1:
|
||||
mInitStatusIcon.setVisibility(View.VISIBLE);
|
||||
mInitStatusIcon.setImageResource(R.drawable.kc_checkbox_select);
|
||||
mInitStatusTv.setText(Html.fromHtml("热点创建成功:" + "<font color=\"#00B7FA\">" + mySsid + "</font>"));
|
||||
mInitStatusTv.setText(Html.fromHtml(getString(R.string.create_hotspot_blue, mySsid)));
|
||||
mInitHotpostHint.setVisibility(View.VISIBLE);
|
||||
mInitHotpostHint.setText("为了避免消耗流量,请关闭你手机的移动网络");
|
||||
mInitHotspostPb.setVisibility(View.GONE);
|
||||
|
||||
initConnHint.setText(Html.fromHtml("请好友打开Wi-Fi设置,连接我的热点:" + "<font color=\"#00B7FA\">" + mySsid + "</font>"));
|
||||
initConnHint.setText(Html.fromHtml(getString(R.string.kc_conn_hint, mySsid)));
|
||||
mInitSuccessLl.setVisibility(View.VISIBLE);
|
||||
initSuccess = true;
|
||||
break;
|
||||
@ -198,7 +197,7 @@ public class ShareGhWfifActivity extends BaseActivity {
|
||||
mInitStatusIcon.setVisibility(View.VISIBLE);
|
||||
mInitStatusIcon.setImageResource(R.drawable.hotspot_failed_icon);
|
||||
mInitStatusTv.setText("初始化失败, 请退出重试");
|
||||
mInitStatusTv.setTextColor(Color.parseColor("#ff4147"));
|
||||
mInitStatusTv.setTextColor(ContextCompat.getColor(this, R.color.red));
|
||||
mInitHotpostHint.setVisibility(View.VISIBLE);
|
||||
mInitHotspostPb.setVisibility(View.GONE);
|
||||
break;
|
||||
@ -213,7 +212,7 @@ public class ShareGhWfifActivity extends BaseActivity {
|
||||
public void onWifiApEnabled() {
|
||||
if (!mIsInitialized) {
|
||||
Utils.log("===初始化热点成功");
|
||||
AppController.MAIN_EXECUTOR.execute(checkHotSpot());
|
||||
HaloApp.MAIN_EXECUTOR.execute(checkHotSpot());
|
||||
mIsInitialized = true;
|
||||
// mHotSpotName.setText(mySsid);
|
||||
}
|
||||
@ -280,7 +279,7 @@ public class ShareGhWfifActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void initMicroServer() {
|
||||
AppController.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
HaloApp.MAIN_EXECUTOR.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
@ -6,15 +6,16 @@ import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.RunningUtils;
|
||||
|
||||
import static com.gh.common.util.EntranceUtils.ENTRANCE_BROWSER;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_ARTICLE;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_COLUMN;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_DOWNLOAD;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_GAME;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_SUGGESTION;
|
||||
import static com.gh.common.util.EntranceUtils.HOSt_COLUMN;
|
||||
import static com.gh.common.util.EntranceUtils.KEY_CONTENT;
|
||||
import static com.gh.common.util.EntranceUtils.KEY_ENTRANCE;
|
||||
import static com.gh.common.util.EntranceUtils.KEY_GAMEID;
|
||||
@ -70,7 +71,7 @@ public class SkipActivity extends BaseActivity {
|
||||
intent.setClass(this, GameDetailActivity.class);
|
||||
intent.putExtra(KEY_GAMEID, id);
|
||||
break;
|
||||
case HOSt_COLUMN:
|
||||
case HOST_COLUMN:
|
||||
intent.setClass(this, SubjectActivity.class);
|
||||
intent.putExtra(KEY_ID, id);
|
||||
intent.putExtra(KEY_NAME, getIntent().getData().getQueryParameter(KEY_NAME));
|
||||
@ -82,6 +83,7 @@ public class SkipActivity extends BaseActivity {
|
||||
uri.getQueryParameter(KEY_VERSION));
|
||||
intent.putExtra(KEY_CONTENT, content);
|
||||
intent.putExtra(KEY_SUGGEST_HINT_TYPE, KEY_PLUGIN);
|
||||
intent.putExtra(EntranceUtils.KEY_SUGGESTTYPE, 4);
|
||||
intent.setClass(this, SuggestionActivity.class);
|
||||
break;
|
||||
case HOST_DOWNLOAD:
|
||||
@ -109,7 +111,7 @@ public class SkipActivity extends BaseActivity {
|
||||
intent.putExtra(KEY_NEWSID, id);
|
||||
intent.putExtra(KEY_TO, "GameDetailActivity");
|
||||
break;
|
||||
case HOSt_COLUMN:
|
||||
case HOST_COLUMN:
|
||||
intent.putExtra(KEY_TO, "SubjectActivity");
|
||||
intent.putExtra(KEY_ID, id);
|
||||
intent.putExtra(KEY_NAME, getIntent().getData().getQueryParameter(KEY_NAME));
|
||||
@ -120,6 +122,8 @@ public class SkipActivity extends BaseActivity {
|
||||
PlatformUtils.getInstance(this).getPlatformName(uri.getQueryParameter(KEY_PLATFORM)),
|
||||
uri.getQueryParameter(KEY_VERSION));
|
||||
intent.putExtra(KEY_CONTENT, content);
|
||||
intent.putExtra(KEY_SUGGEST_HINT_TYPE, KEY_PLUGIN);
|
||||
intent.putExtra(EntranceUtils.KEY_SUGGESTTYPE, 4);
|
||||
intent.putExtra(KEY_TO, "SuggestionActivity");
|
||||
break;
|
||||
case HOST_DOWNLOAD:
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
@ -17,8 +19,9 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.TagUtils;
|
||||
@ -26,14 +29,13 @@ import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.FilterManager;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.download.FileUtils;
|
||||
import com.lightgame.utils.AppManager;
|
||||
import com.lightgame.utils.Utils;
|
||||
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.json.JSONException;
|
||||
@ -46,10 +48,15 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import pub.devrel.easypermissions.AfterPermissionGranted;
|
||||
import pub.devrel.easypermissions.EasyPermissions;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
import static com.gh.common.util.EntranceUtils.ENTRANCE_DOWNLOAD;
|
||||
import static com.gh.common.util.EntranceUtils.KEY_DATA;
|
||||
import static com.gh.common.util.EntranceUtils.KEY_ENTRANCE;
|
||||
import static com.gh.common.util.EntranceUtils.KEY_TO;
|
||||
|
||||
/**
|
||||
* 引导页面
|
||||
@ -63,6 +70,10 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
private boolean isFirst;
|
||||
private boolean isNewFirstLaunch;
|
||||
|
||||
private final static int REQUEST_PERMISSION_TAG = 30001;
|
||||
private String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.READ_PHONE_STATE};
|
||||
|
||||
public static Intent[] getRedirectIntents(Context context, Uri uri) {
|
||||
List<Intent> intentList = new ArrayList<>();
|
||||
if (AppManager.getInstance().isEmpty()) {
|
||||
@ -86,6 +97,30 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
return intent;
|
||||
}
|
||||
|
||||
// 下载消息栏跳转
|
||||
public static Intent getIntentByDownload(Context context, String keyTo) {
|
||||
Intent intent = new Intent(context, SplashScreenActivity.class);
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
intent.putExtra(KEY_TO, keyTo);
|
||||
intent.putExtra(KEY_ENTRANCE, ENTRANCE_DOWNLOAD);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
return intent;
|
||||
}
|
||||
|
||||
// 下载完成 安装消息栏跳转
|
||||
public static Intent getIntentByInstall(Context context, String path) {
|
||||
Intent intent = new Intent(context, SplashScreenActivity.class);
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
intent.putExtra(KEY_TO, DownloadManagerActivity.TAG);
|
||||
intent.putExtra(EntranceUtils.KEY_CURRENTITEM, 0);
|
||||
intent.putExtra(EntranceUtils.KEY_PATH, path);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, "(安装跳转)");
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
@ -111,37 +146,16 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
isFirst = true;
|
||||
|
||||
// if (isNewFirstLaunch || mSharedPreferences.getInt("actionbar_height", 0) != 0) {
|
||||
if (isNewFirstLaunch) {
|
||||
setTheme(R.style.AppGuideTheme);
|
||||
} else {
|
||||
setTheme(R.style.AppFullScreenTheme);
|
||||
// 自定义ActionBar
|
||||
// ActionBar actionBar = getActionBar();
|
||||
// if (actionBar != null) {
|
||||
// actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||
// RelativeLayout relativeLayout = new RelativeLayout(this);
|
||||
// relativeLayout.setBackgroundResource(R.color.theme);
|
||||
// LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
// actionBar.setCustomView(relativeLayout, params);// 自定义ActionBar布局
|
||||
// }
|
||||
}
|
||||
|
||||
if (isNewFirstLaunch) {
|
||||
mContentView.setPadding(0, 0, 0, 0);
|
||||
ViewPager guideLayout = (ViewPager) findViewById(R.id.splash_intro_vp_guide);
|
||||
guideLayout.setAdapter(new GuidePagerAdapter());
|
||||
SystemBarTintManager tintManager = getTintManager();
|
||||
if (tintManager != null) {
|
||||
tintManager.setTintAlpha(0);
|
||||
}
|
||||
}
|
||||
|
||||
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
SystemBarTintManager tintManager = getTintManager();
|
||||
if (tintManager != null) {
|
||||
tintManager.setStatusBarTintColor(ContextCompat.getColor(getApplicationContext(), R.color.theme));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -169,7 +183,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
|
||||
if (isNewFirstLaunch) {
|
||||
if (isNewFirstLaunch && EasyPermissions.hasPermissions(this, permissions)) {
|
||||
launch();
|
||||
} else {
|
||||
return true;
|
||||
@ -229,36 +243,77 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
// 更新本地时间
|
||||
TokenUtils.getTime(this);
|
||||
|
||||
// 上传数据
|
||||
DataCollectionManager.getInstance(getApplicationContext()).upload();
|
||||
// // 上传数据---基于上报信息涉及用户权限 防止由于未授予权限导致的闪退 移动MainActivity上报
|
||||
// DataCollectionManager.getInstance(getApplicationContext()).upload();
|
||||
|
||||
// 解决助手奔溃后导致的下载状态保留问题
|
||||
DownloadManager.getInstance(this).checkAll();
|
||||
|
||||
// 不是第一次启动
|
||||
if (!isNewFirstLaunch) {
|
||||
// int height = mSharedPreferences.getInt("actionbar_height", 0);
|
||||
// if (height == 0) {
|
||||
// final ActionBar actionBar = getActionBar();
|
||||
// if (actionBar != null) {
|
||||
// mSharedPreferences.edit().putInt("actionbar_height", actionBar.getHeight()).apply();
|
||||
// }
|
||||
// }
|
||||
long end = System.currentTimeMillis() - start;
|
||||
if (end < 3000) {
|
||||
getWindow().getDecorView().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
launch();
|
||||
}
|
||||
}, 3000 - end);
|
||||
} else {
|
||||
launch();
|
||||
// 检查权限
|
||||
if (EasyPermissions.hasPermissions(this, permissions)) {
|
||||
if (!isNewFirstLaunch) {
|
||||
long end = System.currentTimeMillis() - start;
|
||||
if (end < 2000) {
|
||||
getWindow().getDecorView().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
launch();
|
||||
}
|
||||
}, 2000 - end);
|
||||
} else {
|
||||
launch();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
checkAndRequestPermission();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AfterPermissionGranted(REQUEST_PERMISSION_TAG)
|
||||
private void checkAndRequestPermission() {
|
||||
if (EasyPermissions.hasPermissions(this, permissions)) {
|
||||
launch();
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(this, permissions, REQUEST_PERMISSION_TAG);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionsDenied(int requestCode, List<String> perms) {
|
||||
if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) { // 设置"不要再询问",必须手动到系统设置授权
|
||||
DialogUtils.showPermissionDialog(this, "重要提醒",
|
||||
"请授予光环助手权限,否则将无法使用\n请点击\"设置\"-\"应用\"-\"光环助手\"-\"权限\"-打开所需权限", "去设置", "退出",
|
||||
new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
intent.setData(Uri.parse("package:" + getPackageName()));
|
||||
startActivity(intent);
|
||||
}
|
||||
}, new DialogUtils.CancelListener() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
DialogUtils.showPermissionDialog(this, "重要提醒",
|
||||
"请授予光环助手权限,否则将无法使用", "重试", "退出",
|
||||
new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
checkAndRequestPermission();
|
||||
}
|
||||
}, new DialogUtils.CancelListener() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 检查下载文件夹下是否有旧版本的光环助手的包,有则删除
|
||||
private void checkOldGhFile() {
|
||||
File folder = new File(FileUtils.getDownloadDir(this) + File.separator);
|
||||
@ -281,8 +336,9 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
// 获取下载按钮显示状态
|
||||
private void getDownloadStatus() {
|
||||
String channel = AppController.getInstance().getChannel();
|
||||
RetrofitManager.getApi().getDownloadStatus(PackageUtils.getVersionName(getApplicationContext()), channel)
|
||||
String channel = HaloApp.getInstance().getChannel();
|
||||
RetrofitManager.getInstance(this).getApi().getDownloadStatus(
|
||||
PackageUtils.getVersionName(getApplicationContext()), channel)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
@ -310,7 +366,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
// 获取界面设置
|
||||
private void getUISetting() {
|
||||
RetrofitManager.getApi().getUISetting()
|
||||
RetrofitManager.getInstance(this).getApi().getUISetting()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
@ -353,7 +409,9 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
tvSkip.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
launch();
|
||||
if (EasyPermissions.hasPermissions(SplashScreenActivity.this, permissions)) {
|
||||
launch();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -18,12 +18,15 @@ import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.gamecenter.adapter.VPFragmentAdapter;
|
||||
import com.gh.gamecenter.entity.SubjectHeadEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.gh.gamecenter.subject.OnSubjectTitleListener;
|
||||
import com.gh.gamecenter.subject.SubjectFragment;
|
||||
import com.gh.gamecenter.subject.SubjectTileFragment;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -31,15 +34,19 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import retrofit2.HttpException;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
import static com.gh.gamecenter.R.id.actionbar_tv_title;
|
||||
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/4/29.
|
||||
*/
|
||||
|
||||
public class SubjectActivity extends BaseActivity {
|
||||
public class SubjectActivity extends BaseActivity implements OnSubjectTitleListener {
|
||||
|
||||
@BindView(R.id.subject_viewpager)
|
||||
ViewPager mViewPager;
|
||||
@ -51,6 +58,8 @@ public class SubjectActivity extends BaseActivity {
|
||||
FrameLayout mSubjectTiled;
|
||||
@BindView(R.id.reuse_no_connection)
|
||||
View mNoConn;
|
||||
@BindView(R.id.actionbar_tv_title)
|
||||
TextView mActionBarTitle;
|
||||
|
||||
private String mId;
|
||||
private String mName;
|
||||
@ -63,9 +72,9 @@ public class SubjectActivity extends BaseActivity {
|
||||
*/
|
||||
public static void startSubjectActivity(Context context, String id, String name, boolean isOrder, String entrance) {
|
||||
Intent intent = new Intent(context, SubjectActivity.class);
|
||||
intent.putExtra("id", id);
|
||||
intent.putExtra("name", name);
|
||||
intent.putExtra("order", isOrder);
|
||||
intent.putExtra(EntranceUtils.KEY_ID, id);
|
||||
intent.putExtra(EntranceUtils.KEY_NAME, name);
|
||||
intent.putExtra(EntranceUtils.KEY_ORDER, isOrder);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
@ -79,12 +88,12 @@ public class SubjectActivity extends BaseActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mBundle = getIntent().getExtras();
|
||||
if (getIntent().getBundleExtra("data") != null) {
|
||||
mBundle = getIntent().getBundleExtra("data");
|
||||
if (getIntent().getBundleExtra(EntranceUtils.KEY_DATA) != null) {
|
||||
mBundle = getIntent().getBundleExtra(EntranceUtils.KEY_DATA);
|
||||
}
|
||||
|
||||
mId = mBundle.getString("id");
|
||||
mName = mBundle.getString("name");
|
||||
mId = mBundle.getString(EntranceUtils.KEY_ID);
|
||||
mName = mBundle.getString(EntranceUtils.KEY_NAME);
|
||||
|
||||
initTitle(mName);
|
||||
|
||||
@ -93,27 +102,31 @@ public class SubjectActivity extends BaseActivity {
|
||||
} else {
|
||||
loadSubjectType();
|
||||
}
|
||||
|
||||
mNoConn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mNoConn.setVisibility(View.GONE);
|
||||
mLoading.setVisibility(View.VISIBLE);
|
||||
loadSubjectType();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
if (mTileFragment != null) {
|
||||
mTileFragment.onTouchEvent(ev);
|
||||
}
|
||||
if (mTileFragment != null) mTileFragment.onTouchEvent(ev);
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
@OnClick({actionbar_tv_title, R.id.reuse_no_connection})
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case actionbar_tv_title:
|
||||
if (mTileFragment != null)
|
||||
EventBus.getDefault().post(new EBReuse(SubjectFragment.SCROLL_TOP));
|
||||
break;
|
||||
case R.id.reuse_no_connection:
|
||||
mNoConn.setVisibility(View.GONE);
|
||||
mLoading.setVisibility(View.VISIBLE);
|
||||
loadSubjectType();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void getSubjectName(String id) {
|
||||
RetrofitManager.getApi()
|
||||
RetrofitManager.getInstance(this).getApi()
|
||||
.getSubjectName(id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -123,9 +136,8 @@ public class SubjectActivity extends BaseActivity {
|
||||
try {
|
||||
String name = response.getString("name");
|
||||
|
||||
TextView actionbar_tv_title = (TextView) findViewById(R.id.actionbar_tv_title);
|
||||
actionbar_tv_title.setText(name);
|
||||
mBundle.putString("name", name);
|
||||
mActionBarTitle.setText(name);
|
||||
mBundle.putString(EntranceUtils.KEY_NAME, name);
|
||||
loadSubjectType();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@ -135,17 +147,15 @@ public class SubjectActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
TextView actionbar_tv_title = (TextView) findViewById(R.id.actionbar_tv_title);
|
||||
actionbar_tv_title.setText("专题");
|
||||
mBundle.putString("name", "专题");
|
||||
mActionBarTitle.setText("专题");
|
||||
mBundle.putString(EntranceUtils.KEY_NAME, "专题");
|
||||
loadSubjectType();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadSubjectType() {
|
||||
RetrofitManager
|
||||
.getApi()
|
||||
RetrofitManager.getInstance(this).getApi()
|
||||
.getColumnSettings(mId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -171,7 +181,7 @@ public class SubjectActivity extends BaseActivity {
|
||||
if ("tile".equals(headEntity.getTypeEntity().getLayout())) {
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
Bundle clone = (Bundle) mBundle.clone();
|
||||
clone.putString("tagType", headEntity.getTag());
|
||||
clone.putString(EntranceUtils.KEY_TAGTYPE, headEntity.getTag());
|
||||
clone.putStringArrayList("contentTitle", new ArrayList<>(headEntity.getTypeEntity().getContent()));
|
||||
mTileFragment = new SubjectTileFragment();
|
||||
mTileFragment.setArguments(clone);
|
||||
@ -186,8 +196,8 @@ public class SubjectActivity extends BaseActivity {
|
||||
for (String s : tag) {
|
||||
mTabLayout.addTab(mTabLayout.newTab().setText(s));
|
||||
Bundle clone = (Bundle) mBundle.clone();
|
||||
clone.putString("type", s);
|
||||
clone.putString("tagType", headEntity.getTag());
|
||||
clone.putString(EntranceUtils.KEY_TYPE, s);
|
||||
clone.putString(EntranceUtils.KEY_TAGTYPE, headEntity.getTag());
|
||||
fragments.add(SubjectFragment.newInstance(clone));
|
||||
}
|
||||
|
||||
@ -198,4 +208,9 @@ public class SubjectActivity extends BaseActivity {
|
||||
// mTabLayout.setTabsFromPagerAdapter(adapter);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(String title) {
|
||||
mActionBarTitle.setText(title);
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,8 @@ import butterknife.OnClick;
|
||||
*/
|
||||
public class SuggestSelectActivity extends BaseActivity {
|
||||
|
||||
public final static int SUGGEST_TYPE_REQUEST = 11; // 只要进入反馈页面(下一个), 无论怎么回退当前页面都会退出
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context) {
|
||||
Intent intent = new Intent(context, SuggestSelectActivity.class);
|
||||
@ -30,7 +32,7 @@ public class SuggestSelectActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == 0x121 && resultCode == 0x122) {
|
||||
if (requestCode == SUGGEST_TYPE_REQUEST && resultCode == SUGGEST_TYPE_REQUEST) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@ -69,9 +71,8 @@ public class SuggestSelectActivity extends BaseActivity {
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, SuggestionActivity.class);
|
||||
intent.putExtra("suggestType", type);
|
||||
startActivityForResult(intent, 0x121);
|
||||
Intent intent = SuggestionActivity.getIntent(this, type);
|
||||
startActivityForResult(intent, SUGGEST_TYPE_REQUEST);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
@ -24,19 +25,21 @@ import android.widget.ProgressBar;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.base.OnListClickListener;
|
||||
import com.gh.base.OnRequestCallBackListener;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.BitmapUtils;
|
||||
import com.gh.common.util.CheckLoginUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PatternUtils;
|
||||
import com.gh.common.util.SoftInputHidWidgetUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.gamecenter.entity.InstallGameEntity;
|
||||
import com.gh.gamecenter.entity.SuggestionTypeEntity;
|
||||
import com.gh.gamecenter.entity.UserInfoEntity;
|
||||
import com.gh.gamecenter.fragment.WaitingDialogFragment;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
@ -44,6 +47,7 @@ import com.gh.gamecenter.suggest.SuggestPicAdapter;
|
||||
import com.gh.gamecenter.suggest.SuggestSelectGameAdapter;
|
||||
import com.gh.gamecenter.suggest.SuggestTypeAdapter;
|
||||
import com.google.gson.Gson;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.download.FileUtils;
|
||||
import com.lightgame.utils.Util_System_Keyboard;
|
||||
import com.lightgame.utils.Util_System_Phone_State;
|
||||
@ -69,20 +73,20 @@ import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.HttpException;
|
||||
import rx.Observable;
|
||||
import rx.Observer;
|
||||
import rx.Subscriber;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Func1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
import static com.gh.gamecenter.SuggestSelectActivity.SUGGEST_TYPE_REQUEST;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/31.
|
||||
*/
|
||||
public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapter.OnSelectTypeListener,
|
||||
OnRequestCallBackListener<InstallGameEntity> {
|
||||
OnRequestCallBackListener<InstallGameEntity>, OnListClickListener {
|
||||
|
||||
@BindView(R.id.suggest_content_et)
|
||||
EditText mSuggestContentEt;
|
||||
@ -109,22 +113,31 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
@BindView(R.id.suggest_scrollview)
|
||||
ScrollView mScrollView;
|
||||
|
||||
public static final int MEDIA_STORE_REQUEST = 1;
|
||||
|
||||
private SuggestPicAdapter mAdapter;
|
||||
|
||||
private Dialog selectGameDialog;
|
||||
private WaitingDialogFragment postDialog;
|
||||
|
||||
private String[] arrType = {"普通反馈", "功能建议", "发生闪退", "游戏问题", "游戏收录", "文章投稿"};
|
||||
private String[] arrType;
|
||||
|
||||
private int curType = -1;
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context, int suggestType) {
|
||||
Intent intent = new Intent(context, SuggestionActivity.class);
|
||||
intent.putExtra(EntranceUtils.KEY_SUGGESTTYPE, suggestType);
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static void startSuggestionActivity(Context context, int suggestType, String suggestHintType, String content) {
|
||||
Intent intent = new Intent(context, SuggestionActivity.class);
|
||||
intent.putExtra("suggestType", suggestType);
|
||||
intent.putExtra("suggestHintType", suggestHintType);
|
||||
intent.putExtra("content", content);
|
||||
intent.putExtra(EntranceUtils.KEY_SUGGESTTYPE, suggestType);
|
||||
intent.putExtra(EntranceUtils.KEY_SUGGEST_HINT_TYPE, suggestHintType);
|
||||
intent.putExtra(EntranceUtils.KEY_CONTENT, content);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
@ -136,7 +149,7 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (data != null && requestCode == 0x233) {
|
||||
if (data != null && requestCode == MEDIA_STORE_REQUEST) {
|
||||
Uri selectedImage = data.getData();
|
||||
if (selectedImage == null) {
|
||||
return;
|
||||
@ -170,12 +183,17 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
super.onCreate(savedInstanceState);
|
||||
initTitle(getString(R.string.title_suggestion));
|
||||
|
||||
curType = getIntent().getExtras().getInt("suggestType");
|
||||
String suggestContent = getIntent().getExtras().getString("content");
|
||||
String suggestHintType = getIntent().getExtras().getString("suggestHintType");
|
||||
arrType = getResources().getStringArray(R.array.suggestion_type);
|
||||
Bundle extras = getIntent().getExtras();
|
||||
curType = extras.getInt(EntranceUtils.KEY_SUGGESTTYPE);
|
||||
String suggestContent = extras.getString(EntranceUtils.KEY_CONTENT);
|
||||
String suggestHintType = extras.getString(EntranceUtils.KEY_SUGGEST_HINT_TYPE);
|
||||
|
||||
if (getIntent().getBundleExtra("data") != null) {
|
||||
suggestContent = getIntent().getBundleExtra("data").getString("content");
|
||||
Bundle data = getIntent().getBundleExtra(EntranceUtils.KEY_DATA);
|
||||
if (data != null) {
|
||||
suggestContent = data.getString(EntranceUtils.KEY_CONTENT);
|
||||
suggestHintType = data.getString(EntranceUtils.KEY_SUGGEST_HINT_TYPE);
|
||||
curType = data.getInt(EntranceUtils.KEY_SUGGESTTYPE);
|
||||
}
|
||||
|
||||
sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
@ -200,8 +218,6 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
mAdapter = new SuggestPicAdapter(this);
|
||||
mSuggestPicRv.setAdapter(mAdapter);
|
||||
|
||||
SoftInputHidWidgetUtils.assistActivity(this);
|
||||
|
||||
if (!TextUtils.isEmpty(suggestContent)) {
|
||||
mSuggestContentEt.setText(suggestContent);
|
||||
}
|
||||
@ -245,6 +261,11 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UserInfoEntity userInfo = LoginUtils.getUserInfo(this);
|
||||
if (userInfo != null && !TextUtils.isEmpty(userInfo.getContact())) {
|
||||
mSuggestEmailEt.setText(userInfo.getContact());
|
||||
}
|
||||
}
|
||||
|
||||
private void initSuggest(int type) {
|
||||
@ -360,27 +381,32 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
return;
|
||||
}
|
||||
|
||||
String email = mSuggestEmailEt.getText().toString().trim();
|
||||
String url = mSuggestNewsLinkEt.getText().toString().trim();
|
||||
CheckLoginUtils.checkLogin(this, new CheckLoginUtils.OnLoggenInListener() {
|
||||
@Override
|
||||
public void onLoggedIn() {
|
||||
String email = mSuggestEmailEt.getText().toString().trim();
|
||||
String url = mSuggestNewsLinkEt.getText().toString().trim();
|
||||
|
||||
if (!TextUtils.isEmpty(url) && !PatternUtils.isUrlAddress(url)) {
|
||||
Utils.toast(SuggestionActivity.this, "请输入正确的链接");
|
||||
return;
|
||||
}
|
||||
if (!TextUtils.isEmpty(url) && !PatternUtils.isUrlAddress(url)) {
|
||||
Utils.toast(SuggestionActivity.this, "请输入正确的链接");
|
||||
return;
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(email)) {
|
||||
showConfirmDialog(email);
|
||||
} else {
|
||||
postDialog = WaitingDialogFragment.newInstance(getString(R.string.dialog_feedback_doing));
|
||||
postDialog.show(getSupportFragmentManager(), null);
|
||||
if (TextUtils.isEmpty(email)) {
|
||||
showConfirmDialog(email);
|
||||
} else {
|
||||
postDialog = WaitingDialogFragment.newInstance(getString(R.string.dialog_feedback_doing));
|
||||
postDialog.show(getSupportFragmentManager(), null);
|
||||
|
||||
List<String> fileList = mAdapter.getFileList();
|
||||
if (fileList != null && fileList.size() > 0) {
|
||||
postPic(email);
|
||||
} else {
|
||||
initPostData(email, null);
|
||||
List<String> fileList = mAdapter.getFileList();
|
||||
if (fileList != null && fileList.size() > 0) {
|
||||
postPic(email);
|
||||
} else {
|
||||
initPostData(email, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
case R.id.suggest_select_game:
|
||||
showSelectDialog();
|
||||
@ -436,10 +462,10 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
for (String s : mAdapter.getFileList()) {
|
||||
path = getCacheDir() + File.separator + System.currentTimeMillis() + index + ".jpg";
|
||||
if (BitmapUtils.savePicture(path, s)) {
|
||||
subscriber.onNext(FileUtils.uploadFile(Config.HOST + "support/user/suggestion/img", path, null));
|
||||
subscriber.onNext(FileUtils.uploadFile(Config.API_HOST + "support/upload/img?type=suggestion", path, LoginUtils.getToken(SuggestionActivity.this)));
|
||||
index++;
|
||||
} else {
|
||||
subscriber.onNext(FileUtils.uploadFile(Config.HOST + "support/user/suggestion/img", s, null));
|
||||
subscriber.onNext(FileUtils.uploadFile(Config.API_HOST + "support/upload/img?type=suggestion", s, LoginUtils.getToken(SuggestionActivity.this)));
|
||||
}
|
||||
}
|
||||
subscriber.onCompleted();
|
||||
@ -449,7 +475,7 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
.subscribe(new Observer<JSONObject>() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
Utils.log("=========完成");
|
||||
Utils.log("意见反馈:图片上传完成");
|
||||
initPostData(email, picArray);
|
||||
}
|
||||
|
||||
@ -459,17 +485,16 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
postDialog.dismissAllowingStateLoss();
|
||||
}
|
||||
Utils.toast(SuggestionActivity.this, "上传失败");
|
||||
Utils.log("=========上传失败" + e.toString());
|
||||
Utils.log("意见反馈:图片上传失败" + e.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(JSONObject result) {
|
||||
if (result != null) {
|
||||
try {
|
||||
Utils.log("===========" + result);
|
||||
int statusCode = result.getInt("statusCode");
|
||||
if (statusCode == HttpURLConnection.HTTP_OK) {
|
||||
picArray.put(result.getString("img"));
|
||||
picArray.put(result.getString("icon"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -483,12 +508,12 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("message", mSuggestContentEt.getText().toString().trim());
|
||||
params.put("from", email);
|
||||
params.put("ghversion", PackageUtils.getVersionName(this));
|
||||
params.put("channel", AppController.getInstance().getChannel());
|
||||
params.put("ghversion", PackageUtils.getPatchVersionName());
|
||||
params.put("channel", HaloApp.getInstance().getChannel());
|
||||
params.put("type", android.os.Build.MODEL);
|
||||
params.put("sdk", String.valueOf(android.os.Build.VERSION.SDK_INT));
|
||||
params.put("version", android.os.Build.VERSION.RELEASE);
|
||||
params.put("source", "光环助手");
|
||||
params.put("source", getString(R.string.app_name));
|
||||
params.put("imei", Util_System_Phone_State.getDeviceId(this));
|
||||
|
||||
if ((curType == 6 || curType == 5) && !TextUtils.isEmpty(mSuggestNewsLinkEt.getText().toString())) {
|
||||
@ -514,19 +539,13 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
jsonObject.toString());
|
||||
|
||||
Utils.log("=======postBody" + jsonObject.toString());
|
||||
|
||||
sendSuggestion(body, true);
|
||||
sendSuggestion(body);
|
||||
}
|
||||
|
||||
private void sendSuggestion(final RequestBody body, boolean isCheck) {
|
||||
private void sendSuggestion(final RequestBody body) {
|
||||
|
||||
TokenUtils.getToken(SuggestionActivity.this, isCheck).flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
return RetrofitManager.getApi().postSuggestion(body, token);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
RetrofitManager.getInstance(this).getApi().postSuggestion(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
@Override
|
||||
@ -539,7 +558,7 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
if ("ok".equals(response.getString("status"))) {
|
||||
|
||||
toast("感谢您的反馈!");
|
||||
setResult(0x122);
|
||||
setResult(SUGGEST_TYPE_REQUEST);
|
||||
finish();
|
||||
} else {
|
||||
toast("提交失败,请稍后尝试!");
|
||||
@ -552,35 +571,22 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
super.onError(e);
|
||||
Utils.log("======ERROR" + e.toString());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
try {
|
||||
if (e != null) {
|
||||
String string = e.response().errorBody().string();
|
||||
Utils.log("===========onFailure" + string);
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
if (e != null && e.code() == 401) {
|
||||
sendSuggestion(body, false);
|
||||
return;
|
||||
} else {
|
||||
if (postDialog != null) {
|
||||
postDialog.dismissAllowingStateLoss();
|
||||
}
|
||||
|
||||
toast("提交失败,请检查网络状态");
|
||||
if (postDialog != null) {
|
||||
postDialog.dismissAllowingStateLoss();
|
||||
}
|
||||
|
||||
toast("提交失败,请检查网络状态");
|
||||
}
|
||||
});
|
||||
|
||||
@ -659,4 +665,12 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T> void onListClick(View view, int position, T data) {
|
||||
List<String> picList = (List<String>) data;
|
||||
if (position == mAdapter.getItemCount() - 1 && picList.size() < 5) {
|
||||
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
startActivityForResult(intent, MEDIA_STORE_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ import android.widget.TextView;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.base.OnRequestCallBackListener;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.ToolBoxRvAdapter;
|
||||
|
||||
@ -56,8 +57,9 @@ public class ToolBoxActivity extends BaseActivity implements SwipeRefreshLayout.
|
||||
};
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context) {
|
||||
public static Intent getIntent(Context context, String entrance) {
|
||||
Intent intent = new Intent(context, ToolBoxActivity.class);
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
return intent;
|
||||
}
|
||||
|
||||
|
||||
@ -1,147 +0,0 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.AreaAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by khy on 23/06/17.
|
||||
*/
|
||||
|
||||
public class UserAreaActivity extends BaseActivity implements AreaAdapter.OnAreaCallBackLintener {
|
||||
|
||||
@BindView(R.id.area_rv_title)
|
||||
TextView mAreaRvTitle;
|
||||
@BindView(R.id.area_rv)
|
||||
RecyclerView mAreaRv;
|
||||
|
||||
private ArrayList<String> mProList;
|
||||
|
||||
private String mProvinceName;
|
||||
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
|
||||
public static Intent getIntent(Context context) {
|
||||
Intent intent = new Intent(context, UserAreaActivity.class);
|
||||
return intent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 二级地区
|
||||
*/
|
||||
public static Intent getIntent(Context context, ArrayList<String> list, String provinceName) {
|
||||
Intent intent = new Intent(context, UserAreaActivity.class);
|
||||
intent.putExtra("provinceList", list);
|
||||
intent.putExtra("provinceName", provinceName);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == 0x222) {
|
||||
setResult(0x122, data);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_area;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (getIntent() != null && getIntent().getExtras() != null) {
|
||||
Bundle extras = getIntent().getExtras();
|
||||
mProList = extras.getStringArrayList("provinceList");
|
||||
mProvinceName = extras.getString("provinceName");
|
||||
initTitle(mProvinceName);
|
||||
} else {
|
||||
initTitle("选择地区");
|
||||
}
|
||||
|
||||
rparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
DisplayUtils.dip2px(this, 50));
|
||||
|
||||
mLayoutManager = new LinearLayoutManager(this);
|
||||
mAreaRv.setLayoutManager(mLayoutManager);
|
||||
mAreaRv.addItemDecoration(new VerticalItemDecoration(this, 1, false));
|
||||
mAreaRv.setAdapter(new AreaAdapter(this, mProList, this));
|
||||
|
||||
mAreaRv.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
|
||||
if (mProList != null) {
|
||||
mAreaRvTitle.setVisibility(View.GONE);
|
||||
return;
|
||||
} else {
|
||||
mAreaRvTitle.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
int position = mLayoutManager.findFirstVisibleItemPosition();
|
||||
if (position == 34) {
|
||||
mAreaRvTitle.setText("国内");
|
||||
int buttom = mLayoutManager.findViewByPosition(position).getBottom();
|
||||
if (buttom <= mAreaRvTitle.getHeight()) {
|
||||
rparams.topMargin = buttom - mAreaRvTitle.getHeight();
|
||||
mAreaRvTitle.setLayoutParams(rparams);
|
||||
} else {
|
||||
rparams.topMargin = 0;
|
||||
mAreaRvTitle.setLayoutParams(rparams);
|
||||
}
|
||||
} else {
|
||||
rparams.topMargin = 0;
|
||||
mAreaRvTitle.setLayoutParams(rparams);
|
||||
if (position > 34) {
|
||||
mAreaRvTitle.setText("国外");
|
||||
} else {
|
||||
mAreaRvTitle.setText("国内");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAreaResult(String area, List<String> cityList) {
|
||||
if (cityList != null) {
|
||||
Intent intent = getIntent(this, new ArrayList<>(cityList), area);
|
||||
startActivityForResult(intent, 0x221);
|
||||
} else {
|
||||
Intent data = new Intent();
|
||||
if (mProvinceName != null) {
|
||||
data.putExtra("area", mProvinceName + " - " + area);
|
||||
setResult(0x222, data);
|
||||
} else {
|
||||
data.putExtra("area", area);
|
||||
setResult(0x122, data);
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,7 +10,8 @@ import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.gamecenter.entity.UserInfoEntity;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
@ -42,6 +43,8 @@ public class UserInfoActivity extends BaseActivity {
|
||||
@BindView(R.id.userinfo_contact_rl)
|
||||
RelativeLayout mUserinfoContactRl;
|
||||
|
||||
public final static int USERINFO_CHANGE_REQUEST = 10; // 用户信息修改后更新界面
|
||||
|
||||
public static Intent getIntent(Context context) {
|
||||
Intent intent = new Intent(context, UserInfoActivity.class);
|
||||
return intent;
|
||||
@ -50,35 +53,9 @@ public class UserInfoActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == 0x121 && resultCode == 0x122) {
|
||||
String stringExtra = data.getStringExtra("area");
|
||||
mUserinfoAreaTv.setText(stringExtra);
|
||||
toast(stringExtra);
|
||||
if (requestCode == USERINFO_CHANGE_REQUEST && resultCode == USERINFO_CHANGE_REQUEST) {
|
||||
initView();
|
||||
}
|
||||
|
||||
String editContent = null;
|
||||
if (data != null) {
|
||||
if (requestCode == 0x130) {
|
||||
editContent = data.getStringExtra("url");
|
||||
} else {
|
||||
editContent = data.getStringExtra("editContent");
|
||||
}
|
||||
}
|
||||
if (!TextUtils.isEmpty(editContent))
|
||||
switch (requestCode) {
|
||||
case 0x130:
|
||||
ImageUtils.Companion.display(mUserinfoIconSd, editContent);
|
||||
break;
|
||||
case 0x131:
|
||||
mUserinfoNicknameTv.setText(editContent);
|
||||
break;
|
||||
case 0x132:
|
||||
mUserinfoSexTv.setText(editContent);
|
||||
break;
|
||||
case 0x133:
|
||||
mUserinfoContactTv.setText(editContent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -91,6 +68,37 @@ public class UserInfoActivity extends BaseActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
initTitle(getString(R.string.personal_userinfo));
|
||||
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
UserInfoEntity userInfo = LoginUtils.getUserInfo(this);
|
||||
if (userInfo != null) {
|
||||
mUserinfoIconSd.setImageURI(userInfo.getIcon());
|
||||
mUserinfoNicknameTv.setText(userInfo.getName());
|
||||
|
||||
String region = userInfo.getRegion();
|
||||
if (!TextUtils.isEmpty(region)) {
|
||||
mUserinfoAreaTv.setText(region);
|
||||
} else {
|
||||
mUserinfoAreaTv.setText("未选择");
|
||||
}
|
||||
|
||||
String gender = userInfo.getGender();
|
||||
if (!TextUtils.isEmpty(gender)) {
|
||||
mUserinfoSexTv.setText(gender);
|
||||
} else {
|
||||
mUserinfoSexTv.setText("未选择");
|
||||
}
|
||||
|
||||
String contact = userInfo.getContact();
|
||||
if (!TextUtils.isEmpty(contact)) {
|
||||
mUserinfoContactTv.setText(contact);
|
||||
} else {
|
||||
mUserinfoContactTv.setText("未填写");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick({R.id.userinfo_icon_rl, R.id.userinfo_nickname_rl, R.id.userinfo_sex_rl,
|
||||
@ -98,21 +106,19 @@ public class UserInfoActivity extends BaseActivity {
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.userinfo_icon_rl:
|
||||
startActivityForResult(SelectUserIconActivity.getIntent(this), 0x130);
|
||||
startActivityForResult(SelectUserIconActivity.getIntent(this), USERINFO_CHANGE_REQUEST);
|
||||
break;
|
||||
case R.id.userinfo_nickname_rl:
|
||||
String nickName = mUserinfoNicknameTv.getText().toString();
|
||||
startActivityForResult(UserInfoEditActivity.getIntent(this, "nickName", nickName), 0x131);
|
||||
startActivityForResult(UserInfoEditActivity.getIntent(this, "name"), USERINFO_CHANGE_REQUEST);
|
||||
break;
|
||||
case R.id.userinfo_sex_rl:
|
||||
startActivityForResult(UserInfoEditActivity.getIntent(this, "sex", null), 0x132);
|
||||
startActivityForResult(UserInfoEditActivity.getIntent(this, "gender"), USERINFO_CHANGE_REQUEST);
|
||||
break;
|
||||
case R.id.userinfo_area_rl:
|
||||
startActivityForResult(UserAreaActivity.getIntent(this), 0x121);
|
||||
startActivityForResult(UserRegionActivity.getIntent(this), USERINFO_CHANGE_REQUEST);
|
||||
break;
|
||||
case R.id.userinfo_contact_rl:
|
||||
String contact = mUserinfoContactTv.getText().toString();
|
||||
startActivityForResult(UserInfoEditActivity.getIntent(this, "contact", contact), 0x133);
|
||||
startActivityForResult(UserInfoEditActivity.getIntent(this, "contact"), USERINFO_CHANGE_REQUEST);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,11 +4,10 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
@ -18,15 +17,20 @@ import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.gamecenter.entity.UserInfoEntity;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
import static com.gh.gamecenter.UserInfoActivity.USERINFO_CHANGE_REQUEST;
|
||||
|
||||
/**
|
||||
* Created by khy on 30/06/17.
|
||||
*/
|
||||
|
||||
public class UserInfoEditActivity extends BaseActivity {
|
||||
public class UserInfoEditActivity extends BaseActivity implements LoginUtils.onChangeUserInfoListener {
|
||||
|
||||
@BindView(R.id.userinfo_sex_man)
|
||||
TextView mUserinfoSexMan;
|
||||
@BindView(R.id.userinfo_sex_woman)
|
||||
@ -45,17 +49,23 @@ public class UserInfoEditActivity extends BaseActivity {
|
||||
ImageView mUserinfoContactIv;
|
||||
@BindView(R.id.userinfo_edit_contact)
|
||||
LinearLayout mUserinfoEditContact;
|
||||
@BindView(R.id.userinfo_sex_man_select)
|
||||
View mUserinfoSexmanSelect;
|
||||
@BindView(R.id.userinfo_sex_woman_select)
|
||||
View mUserinfoSexWomanSelect;
|
||||
|
||||
TextView mSaveTv;
|
||||
|
||||
private static final String KEY_EDITTYPE = "editType";
|
||||
|
||||
private UserInfoEntity mUserInfoEntity;
|
||||
|
||||
private String mEditType;
|
||||
private String mEditContent;
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context, String editType, String editContent) {
|
||||
public static Intent getIntent(Context context, String editType) {
|
||||
Intent intent = new Intent(context, UserInfoEditActivity.class);
|
||||
intent.putExtra("editType", editType);
|
||||
intent.putExtra("editContent", editContent);
|
||||
intent.putExtra(KEY_EDITTYPE, editType);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@ -67,27 +77,23 @@ public class UserInfoEditActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mEditType = getIntent().getStringExtra("editType");
|
||||
mEditContent = getIntent().getStringExtra("editContent");
|
||||
mEditType = getIntent().getStringExtra(KEY_EDITTYPE);
|
||||
mUserInfoEntity = LoginUtils.getUserInfo(this);
|
||||
|
||||
// 添加分享图标
|
||||
mSaveTv = new TextView(this);
|
||||
mSaveTv.setBackgroundResource(R.drawable.border_black_bg);
|
||||
mSaveTv = (TextView) LayoutInflater.from(this).inflate(R.layout.menu_action_save, null);
|
||||
mSaveTv.setVisibility(View.GONE);
|
||||
mSaveTv.setText("保存");
|
||||
mSaveTv.setTextSize(13);
|
||||
mSaveTv.setGravity(Gravity.CENTER);
|
||||
mSaveTv.setTextColor(ContextCompat.getColor(this, R.color.title));
|
||||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
||||
DisplayUtils.dip2px(this, 48), DisplayUtils.dip2px(this, 24));
|
||||
params.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
params.setMargins(0, 0, DisplayUtils.dip2px(this, 18), 0);
|
||||
RelativeLayout reuse_actionbar = (RelativeLayout) mContentView.findViewById(
|
||||
R.id.reuse_actionbar);
|
||||
RelativeLayout reuse_actionbar = mContentView.findViewById(R.id.reuse_actionbar);
|
||||
reuse_actionbar.addView(mSaveTv, params);
|
||||
|
||||
initView();
|
||||
if (mUserInfoEntity != null) {
|
||||
initView();
|
||||
}
|
||||
|
||||
mSaveTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -100,17 +106,28 @@ public class UserInfoEditActivity extends BaseActivity {
|
||||
private void initView() {
|
||||
String title;
|
||||
switch (mEditType) {
|
||||
case "sex":
|
||||
case "gender":
|
||||
mUserinfoEditSex.setVisibility(View.VISIBLE);
|
||||
title = "选择性别";
|
||||
String gender = mUserInfoEntity.getGender();
|
||||
if (!TextUtils.isEmpty(gender)) {
|
||||
if ("男".equals(gender)) {
|
||||
mUserinfoSexmanSelect.setVisibility(View.VISIBLE);
|
||||
mUserinfoSexWomanSelect.setVisibility(View.GONE);
|
||||
} else {
|
||||
mUserinfoSexmanSelect.setVisibility(View.GONE);
|
||||
mUserinfoSexWomanSelect.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "nickName":
|
||||
case "name":
|
||||
mUserinfoEditNickname.setVisibility(View.VISIBLE);
|
||||
mSaveTv.setVisibility(View.VISIBLE);
|
||||
mUserinfoNicknameEt.addTextChangedListener(new UserInfoEditTextWatcher(mUserinfoNicknameEt));
|
||||
title = "修改昵称";
|
||||
if (!TextUtils.isEmpty(mEditContent)) {
|
||||
mUserinfoNicknameEt.setText(mEditContent);
|
||||
String name = mUserInfoEntity.getName();
|
||||
if (!TextUtils.isEmpty(name)) {
|
||||
mUserinfoNicknameEt.setText(name);
|
||||
}
|
||||
break;
|
||||
case "contact":
|
||||
@ -118,8 +135,9 @@ public class UserInfoEditActivity extends BaseActivity {
|
||||
mSaveTv.setVisibility(View.VISIBLE);
|
||||
mUserinfoContactEt.addTextChangedListener(new UserInfoEditTextWatcher(mUserinfoContactEt));
|
||||
title = "联系方式";
|
||||
if (!TextUtils.isEmpty(mEditContent)) {
|
||||
mUserinfoContactEt.setText(mEditContent);
|
||||
String contact = mUserInfoEntity.getContact();
|
||||
if (!TextUtils.isEmpty(contact)) {
|
||||
mUserinfoContactEt.setText(contact);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -130,25 +148,20 @@ public class UserInfoEditActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void saveData() {
|
||||
Intent data = new Intent();
|
||||
if ("nickName".equals(mEditType)) {
|
||||
String value = mUserinfoNicknameEt.getText().toString();
|
||||
if ("name".equals(mEditType)) {
|
||||
String value = mUserinfoNicknameEt.getText().toString().trim();
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
data.putExtra("editContent", value);
|
||||
setResult(0x131, data);
|
||||
finish();
|
||||
if (value.equals(mUserInfoEntity.getName())) {
|
||||
finish();
|
||||
} else {
|
||||
LoginUtils.changeUserInfo(this, this, value, mEditType);
|
||||
}
|
||||
} else {
|
||||
toast("昵称不能为空");
|
||||
}
|
||||
} else if ("contact".equals(mEditType)) {
|
||||
String value = mUserinfoContactEt.getText().toString();
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
data.putExtra("editContent", value);
|
||||
setResult(0x133, data);
|
||||
finish();
|
||||
} else {
|
||||
toast("请输入QQ或邮箱");
|
||||
}
|
||||
LoginUtils.changeUserInfo(this, this, value, mEditType);
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,20 +175,20 @@ public class UserInfoEditActivity extends BaseActivity {
|
||||
mUserinfoContactEt.setText("");
|
||||
break;
|
||||
case R.id.userinfo_sex_man:
|
||||
Intent data = new Intent();
|
||||
data.putExtra("editContent", "男");
|
||||
setResult(0x132, data);
|
||||
finish();
|
||||
LoginUtils.changeUserInfo(this, this, "男", mEditType);
|
||||
break;
|
||||
case R.id.userinfo_sex_woman:
|
||||
Intent data2 = new Intent();
|
||||
data2.putExtra("editContent", "女");
|
||||
setResult(0x132, data2);
|
||||
finish();
|
||||
LoginUtils.changeUserInfo(this, this, "女", mEditType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange() {
|
||||
setResult(USERINFO_CHANGE_REQUEST);
|
||||
finish();
|
||||
}
|
||||
|
||||
private class UserInfoEditTextWatcher implements TextWatcher {
|
||||
private EditText mEditText;
|
||||
|
||||
@ -192,11 +205,11 @@ public class UserInfoEditActivity extends BaseActivity {
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
int tvCount = s.length();
|
||||
if (mEditText == mUserinfoNicknameEt) {
|
||||
if (tvCount > 0) {
|
||||
mUserinfoNicknameIv.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mUserinfoNicknameIv.setVisibility(View.GONE);
|
||||
}
|
||||
if (tvCount > 0) {
|
||||
mUserinfoNicknameIv.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mUserinfoNicknameIv.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
if (tvCount > 0) {
|
||||
mUserinfoContactIv.setVisibility(View.VISIBLE);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user