Compare commits
92 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ac3e2375bc | |||
| 3b8e0fcad2 | |||
| f8e3158e8f | |||
| 7bb5f380a7 | |||
| 618077c128 | |||
| 23aa0ebde7 | |||
| 17e98407c7 | |||
| 6d8605ed4d | |||
| d02a136e2f | |||
| 1a9b23ca10 | |||
| 3d82162b4d | |||
| 39a42e224a | |||
| f93e5d38f2 | |||
| 2f4688cb13 | |||
| 24c41107d2 | |||
| 9eef163e70 | |||
| e82f202a17 | |||
| da8ca7dbfb | |||
| 0fcf70a2bf | |||
| 68f8bee146 | |||
| e35a0ffc17 | |||
| 21f1a161c9 | |||
| a31d2cd28b | |||
| 47f978a4fa | |||
| c2f2672421 | |||
| aaf6598e43 | |||
| f77a4eb3cb | |||
| 3435da0124 | |||
| d705a3172b | |||
| 82cf8cb877 | |||
| 2dabd5492f | |||
| 64827028b5 | |||
| 753ca3abc0 | |||
| a6bf61bc48 | |||
| 0d79bc2600 | |||
| 3273e9879b | |||
| 9c8898faa4 | |||
| 0ed314ed81 | |||
| 14fa92e0be | |||
| aeb5346606 | |||
| 0ab734f777 | |||
| 72a4b4e267 | |||
| 7052c6f68b | |||
| 4beba85de4 | |||
| 51edbd9baa | |||
| e249968662 | |||
| 567634c958 | |||
| 2a92c10777 | |||
| 7c801366ef | |||
| bbffe7737b | |||
| 88bb8949dd | |||
| d7d9027afa | |||
| 1917462ea3 | |||
| 4c69888938 | |||
| 639ca433a2 | |||
| 44c1a2adb6 | |||
| 6369c480f9 | |||
| b2a7de0a72 | |||
| 19825aa844 | |||
| 14ece26b85 | |||
| 9a17352156 | |||
| b9eb8de88a | |||
| 04cfbcb7e4 | |||
| d74d91532b | |||
| f28a54506e | |||
| b6797131e7 | |||
| 20a5f25901 | |||
| 6ccc3e5cc6 | |||
| 9eb68e641c | |||
| 3f5a94e710 | |||
| 22e51f1216 | |||
| 7060c906a7 | |||
| e61c265418 | |||
| 1149751ae4 | |||
| d35a798a80 | |||
| 175b07875a | |||
| 8cb2ecd113 | |||
| 362de65b36 | |||
| c753663079 | |||
| f243d98094 | |||
| d711a9a14c | |||
| e399a81ee3 | |||
| f030f88029 | |||
| 54f2959d6a | |||
| d5a63da257 | |||
| 2a09f39fdb | |||
| 61a22cc910 | |||
| 7c3a8fda4b | |||
| c8ff5bf624 | |||
| dfd791ffb5 | |||
| 345800ba25 | |||
| 4c3a5492c7 |
4
.idea/gradle.xml
generated
4
.idea/gradle.xml
generated
@ -10,16 +10,12 @@
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
<option value="$PROJECT_DIR$/buildSrc" />
|
||||
<option value="$PROJECT_DIR$/hackdex" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="myModules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
<option value="$PROJECT_DIR$/buildSrc" />
|
||||
<option value="$PROJECT_DIR$/hackdex" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
|
||||
3
.idea/modules.xml
generated
3
.idea/modules.xml
generated
@ -3,10 +3,7 @@
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/GH-ASSISTv1.45.iml" filepath="$PROJECT_DIR$/GH-ASSISTv1.45.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/GH-ASSISTv1.50.iml" filepath="$PROJECT_DIR$/GH-ASSISTv1.50.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/buildSrc/buildSrc.iml" filepath="$PROJECT_DIR$/buildSrc/buildSrc.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/hackdex/hackdex.iml" filepath="$PROJECT_DIR$/hackdex/hackdex.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
@ -1,38 +1,5 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
task('processWithJavassist') << {
|
||||
String classPath = file('build/intermediates/classes/debug')//项目编译class所在目录
|
||||
dodola.patch.PatchClass.process(classPath, project(':hackdex').buildDir
|
||||
.absolutePath + '/intermediates/classes/debug')//第二个参数是hackdex的class所在目录
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出jar包
|
||||
*/
|
||||
task buildJar(dependsOn: ['compileReleaseJavaWithJavac'], type: Jar) {
|
||||
|
||||
baseName = "news"
|
||||
//后缀名
|
||||
extension = "jar"
|
||||
//最终的 Jar 包名,如果没设置,默认为 [baseName]-[appendix]-[version]-[classifier].[extension]
|
||||
archiveName = "news.jar";
|
||||
|
||||
//需打包的资源所在的路径集
|
||||
def srcClassDir = [project.buildDir.absolutePath + "/intermediates/classes/debug"];
|
||||
from srcClassDir
|
||||
|
||||
//去除路径集下部分的资源
|
||||
exclude "com/gh/gamecenter/BuildConfig.class"
|
||||
exclude "com/gh/gamecenter/R.class"
|
||||
exclude "com/gh/gamecenter/BuildConfig/\$*.class"
|
||||
exclude "com/gh/gamecenter/R/\$*.class"
|
||||
|
||||
//只导入资源路径集下的部分资源
|
||||
include "com/gh/gamecenter/NewsActivity.class"
|
||||
include "com/gh/gamecenter/NewsActivity\$*.class"
|
||||
//注: exclude include 支持可变长参数
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 21
|
||||
buildToolsVersion "23.0.3"
|
||||
@ -41,8 +8,8 @@ android {
|
||||
applicationId "com.gh.gamecenter"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 21
|
||||
versionCode 16
|
||||
versionName "2.1"
|
||||
versionCode 17
|
||||
versionName "2.2"
|
||||
|
||||
// 默认的渠道
|
||||
// manifestPlaceholders = [CHANNEL_VALUE: "GH_TEST"]
|
||||
@ -72,10 +39,6 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
// applicationVariants.all { variant ->
|
||||
// variant.dex.dependsOn << processWithJavassist //在执行dx命令之前将代码打入到class中
|
||||
// }
|
||||
|
||||
/**
|
||||
* 多渠道打包
|
||||
*/
|
||||
@ -87,6 +50,7 @@ android {
|
||||
GH_104 {}
|
||||
GH_106 {}
|
||||
GH_107 {}
|
||||
GH_108 {}
|
||||
GH_109 {}
|
||||
GH_110 {}
|
||||
GH_111 {}
|
||||
@ -94,6 +58,7 @@ android {
|
||||
GH_114 {}
|
||||
GH_115 {}
|
||||
GH_116 {}
|
||||
GH_117 {}
|
||||
GH_118 {}
|
||||
GH_119 {}
|
||||
GH_120 {}
|
||||
@ -115,15 +80,48 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
//butterknife
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
||||
}
|
||||
}
|
||||
apply plugin: 'com.neenbedankt.android-apt'
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:21.0.0'
|
||||
compile 'com.android.support:cardview-v7:21.0.0'
|
||||
|
||||
compile ('com.facebook.fresco:fresco:0.12.0') {
|
||||
exclude module: 'support-v4'
|
||||
}
|
||||
compile ('com.facebook.fresco:animated-gif:0.12.0') {
|
||||
exclude module: 'support-v4'
|
||||
}
|
||||
// fresco图片框架
|
||||
compile 'com.facebook.fresco:fresco:0.12.0'
|
||||
compile 'com.facebook.fresco:animated-gif:0.12.0'
|
||||
// Retrofit2所需要的包
|
||||
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
|
||||
// okhttp
|
||||
compile 'com.squareup.okhttp3:okhttp:3.2.0'
|
||||
// ConverterFactory的Gson依赖包
|
||||
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
|
||||
// ConverterFactory的String依赖包
|
||||
compile 'com.squareup.retrofit2:converter-scalars:2.0.0-beta4'
|
||||
// ConverterFactory的RxJava依赖包
|
||||
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4'
|
||||
// gson
|
||||
compile 'com.google.code.gson:gson:2.8.0'
|
||||
// OrmLite数据库
|
||||
compile 'com.j256.ormlite:ormlite-android:5.0'
|
||||
compile 'com.j256.ormlite:ormlite-core:5.0'
|
||||
// butterknife
|
||||
compile 'com.jakewharton:butterknife:8.4.0'
|
||||
apt 'com.jakewharton:butterknife-compiler:8.4.0'
|
||||
// RxJava && RxAndroid
|
||||
compile 'io.reactivex:rxandroid:1.1.0'
|
||||
compile 'io.reactivex:rxjava:1.1.0'
|
||||
// RxBinding
|
||||
compile 'com.jakewharton.rxbinding:rxbinding:0.3.0'
|
||||
// compile 'com.jakewharton.rxbinding:rxbinding-appcompat-v7:0.3.0'
|
||||
// compile 'com.jakewharton.rxbinding:rxbinding-design:0.3.0'
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
app/libs/weiboSDKCore_3.1.4.jar
Normal file
BIN
app/libs/weiboSDKCore_3.1.4.jar
Normal file
Binary file not shown.
@ -61,8 +61,7 @@
|
||||
android:value="81DB144D555386A38A70B833537EC256" />
|
||||
<meta-data
|
||||
android:name="TD_CHANNEL_ID"
|
||||
android:value="GH_TEST"
|
||||
/>
|
||||
android:value="${CHANNEL_VALUE}"/>
|
||||
<!--android:value="${CHANNEL_VALUE}"-->
|
||||
|
||||
<!-- MTA -->
|
||||
@ -71,7 +70,7 @@
|
||||
android:value="APV567FTBS7J"/>
|
||||
<meta-data
|
||||
android:name="InstallChannel"
|
||||
android:value="GH_TEST"/>
|
||||
android:value="${CHANNEL_VALUE}"/>
|
||||
<!--android:value="${CHANNEL_VALUE}"-->
|
||||
|
||||
<activity
|
||||
@ -132,8 +131,28 @@
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.CropImageActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity android:name="com.gh.gamecenter.WebActivity"
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.WebActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.ShareCardPicActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.ShareCardActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.MessageDetailActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity android:name="com.gh.gamecenter.SkipActivity"
|
||||
android:theme="@android:style/Theme.Translucent">
|
||||
<intent-filter>
|
||||
<data android:scheme="ghzhushou"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.mob.tools.MobUIShell"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
@ -179,6 +198,25 @@
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:screenOrientation="behind"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
|
||||
<!--微博分享-->
|
||||
<activity
|
||||
android:name="com.sina.weibo.sdk.component.WeiboSdkBrowser"
|
||||
android:configChanges="keyboardHidden|orientation"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:exported="false" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.WeiBoShareActivity"
|
||||
android:configChanges="keyboardHidden|orientation"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver android:name="com.gh.gamecenter.receiver.InstallAndUninstallReceiver" >
|
||||
<intent-filter>
|
||||
|
||||
@ -1,127 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<DevInfor>
|
||||
<!--
|
||||
说明:
|
||||
|
||||
1、表格中的第一项
|
||||
<ShareSDK
|
||||
AppKey="api20" />
|
||||
是必须的,其中的AppKey是您在ShareSDK上注册的开发者帐号的AppKey
|
||||
|
||||
2、所有集成到您项目的平台都应该为其在表格中填写相对应的开发者信息,以新浪微博为例:
|
||||
<SinaWeibo
|
||||
Id="1"
|
||||
SortId="1"
|
||||
AppKey="568898243"
|
||||
AppSecret="38a4f8204cc784f81f9f0daaf31e02e3"
|
||||
RedirectUrl="http://www.mob.com"
|
||||
Enable="true" />
|
||||
其中的SortId是此平台在分享列表中的位置,由开发者自行定义,可以是任何整型数字,数值越大
|
||||
越靠后AppKey、AppSecret和RedirectUrl是您在新浪微博上注册开发者信息和应用后得到的信息
|
||||
Id是一个保留的识别符,整型,ShareSDK不使用此字段,供您在自己的项目中当作平台的识别符。
|
||||
Enable字段表示此平台是否有效,布尔值,默认为true,如果Enable为false,即便平台的jar包
|
||||
已经添加到应用中,平台实例依然不可获取。
|
||||
|
||||
各个平台注册应用信息的地址如下:
|
||||
新浪微博 http://open.weibo.com
|
||||
腾讯微博 http://dev.t.qq.com
|
||||
QQ空间 http://connect.qq.com/intro/login/
|
||||
微信好友 http://open.weixin.qq.com
|
||||
Facebook https://developers.facebook.com
|
||||
Twitter https://dev.twitter.com
|
||||
人人网 http://dev.renren.com
|
||||
开心网 http://open.kaixin001.com
|
||||
搜狐微博 http://open.t.sohu.com
|
||||
网易微博 http://open.t.163.com
|
||||
豆瓣 http://developers.douban.com
|
||||
|
||||
有道云笔记 http://note.youdao.com/open/developguide.html#app
|
||||
印象笔记 https://dev.evernote.com/
|
||||
Linkedin https://developer.linkedin.com
|
||||
FourSquare https://developer.foursquare.com/
|
||||
搜狐随身看 https://open.sohu.com/
|
||||
Flickr http://www.flickr.com/services/
|
||||
Pinterest http://developers.pinterest.com/
|
||||
Tumblr http://www.tumblr.com/developers
|
||||
Dropbox https://www.dropbox.com/developers
|
||||
Instagram http://instagram.com/developer#
|
||||
VKontakte http://vk.com/dev
|
||||
易信好友 http://open.yixin.im/
|
||||
明道 http://open.mingdao.com/
|
||||
Line http://media.line.me/zh-hant/
|
||||
Pocket http://getpocket.com/developer/apps/new
|
||||
-->
|
||||
<ShareSDK
|
||||
AppKey = "6f286c8a261a"/> <!-- 修改成你在sharesdk后台注册的应用的appkey"-->
|
||||
|
||||
<!-- ShareByAppClient标识是否使用微博客户端分享,默认是false -->
|
||||
<SinaWeibo
|
||||
Id="1"
|
||||
SortId="1"
|
||||
AppKey="568898243"
|
||||
AppSecret="38a4f8204cc784f81f9f0daaf31e02e3"
|
||||
RedirectUrl="http://www.sharesdk.cn"
|
||||
ShareByAppClient="false"
|
||||
Enable="true" />
|
||||
|
||||
<TencentWeibo
|
||||
Id="2"
|
||||
SortId="2"
|
||||
AppKey="801307650"
|
||||
AppSecret="ae36f4ee3946e1cbb98d6965b0b2ff5c"
|
||||
RedirectUri="http://sharesdk.cn"
|
||||
Enable="true" />
|
||||
|
||||
<!-- ShareByAppClient标识是否使用微博客户端分享,默认是false -->
|
||||
<QZone
|
||||
Id="3"
|
||||
SortId="3"
|
||||
AppId="1104659243"
|
||||
AppKey="OfjHS7bWyxPiH0t8"
|
||||
ShareByAppClient="true"
|
||||
Enable="true" />
|
||||
|
||||
<!--
|
||||
Wechat微信和WechatMoments微信朋友圈的appid是一样的;
|
||||
|
||||
注意:开发者不能用我们这两个平台的appid,否则分享不了
|
||||
微信测试的时候,微信测试需要先签名打包出apk,
|
||||
sample测试微信,要先签名打包,keystore在sample项目中,密码123456
|
||||
|
||||
BypassApproval是绕过审核的标记,设置为true后AppId将被忽略,故不经过
|
||||
审核的应用也可以执行分享,但是仅限于分享文字和图片,不能分享其他类型,
|
||||
默认值为false。此外,微信收藏不支持此字段。
|
||||
-->
|
||||
<Wechat
|
||||
Id="4"
|
||||
SortId="4"
|
||||
AppId="wx3ffd0785fad18396"
|
||||
AppSecret="368b49e8471857575a033b206218f9fb"
|
||||
BypassApproval="false"
|
||||
Enable="true" />
|
||||
|
||||
<WechatMoments
|
||||
Id="5"
|
||||
SortId="5"
|
||||
AppId="wx3ffd0785fad18396"
|
||||
AppSecret="368b49e8471857575a033b206218f9fb"
|
||||
BypassApproval="false"
|
||||
Enable="true" />
|
||||
|
||||
<WechatFavorite
|
||||
Id="6"
|
||||
SortId="6"
|
||||
AppId="wx3ffd0785fad18396"
|
||||
AppSecret="368b49e8471857575a033b206218f9fb"
|
||||
Enable="true" />
|
||||
|
||||
<!-- ShareByAppClient标识是否使用微博客户端分享,默认是false -->
|
||||
<QQ
|
||||
Id="7"
|
||||
SortId="7"
|
||||
AppId="1104659243"
|
||||
AppKey="OfjHS7bWyxPiH0t8"
|
||||
ShareByAppClient="true"
|
||||
Enable="true" />
|
||||
|
||||
</DevInfor>
|
||||
Binary file not shown.
@ -19,8 +19,6 @@ package com.android.volley;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import com.gh.common.util.Utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
@ -206,9 +204,6 @@ public class RequestQueue {
|
||||
cancelAll(new RequestFilter() {
|
||||
@Override
|
||||
public boolean apply(Request<?> request) {
|
||||
Utils.log("111" + request.getTag().toString());
|
||||
Utils.log("111" + tag);
|
||||
Utils.log("111" + (request.getTag() == tag));
|
||||
return request.getTag() == tag;
|
||||
}
|
||||
});
|
||||
|
||||
@ -15,6 +15,7 @@ import com.android.volley.RequestQueue;
|
||||
import com.android.volley.toolbox.Volley;
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.HttpsUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.xiaomi.channel.commonutils.logger.LoggerInterface;
|
||||
import com.xiaomi.mipush.sdk.Logger;
|
||||
@ -46,28 +47,10 @@ public class AppController extends Application {
|
||||
//初始化Fresco
|
||||
Fresco.initialize(this);
|
||||
|
||||
// File dexPath = new File(getDir("dex", Context.MODE_PRIVATE), "hackdex_dex.jar");
|
||||
// DexUtils.prepareAssetsDex(this, dexPath, "hackdex_dex.jar");
|
||||
// HotFix.patch(this, dexPath.getAbsolutePath(), "dodola.hackdex.AntilazyLoad");
|
||||
|
||||
// SharedPreferences sp = this.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
// File directory = new File(this.getFilesDir().getAbsolutePath() + File.separator + "hotfix");
|
||||
// if (directory.exists()) {
|
||||
// File[] files = directory.listFiles();
|
||||
// for (File file : files) {
|
||||
// Utils.log("dex file = " + file.getName());
|
||||
// String clazz = sp.getString(file.getName(), null);
|
||||
// if (clazz != null) {
|
||||
// dexPath = new File(getDir("dex", Context.MODE_PRIVATE), file.getName());
|
||||
// DexUtils.prepareDex(this, dexPath, file);
|
||||
// HotFix.patch(this, dexPath.getAbsolutePath(), clazz);
|
||||
// Utils.log(file.getName() + " patch success");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
DataUtils.init(this);
|
||||
|
||||
HttpsUtils.initHttpsUrlConnection(this);
|
||||
|
||||
AppUncaHandler uncaHandler = new AppUncaHandler(this);
|
||||
Thread.setDefaultUncaughtExceptionHandler(uncaHandler);
|
||||
mInstance = this;
|
||||
@ -182,14 +165,6 @@ public class AppController extends Application {
|
||||
getInstance().addRequest(request);
|
||||
}
|
||||
|
||||
public static <T> void addToRequestQueue(Request<T> request, String tag) {
|
||||
if (TextUtils.isEmpty(tag)) {
|
||||
tag = TAG;
|
||||
}
|
||||
request.setTag(tag);
|
||||
getInstance().addRequest(request);
|
||||
}
|
||||
|
||||
public static void canclePendingRequests(String tag) {
|
||||
if (TextUtils.isEmpty(tag)) {
|
||||
tag = TAG;
|
||||
|
||||
@ -34,7 +34,6 @@ import com.gh.gamecenter.manager.SystemBarTintManager.SystemBarConfig;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cn.sharesdk.framework.ShareSDK;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
public class BaseActivity extends Activity implements OnCallBackListener {
|
||||
@ -142,8 +141,6 @@ public class BaseActivity extends Activity implements OnCallBackListener {
|
||||
//如果是游戏分享,newsTitle默认为空
|
||||
public void showShare(String url, String gameName, String icon, String newsTitle, ArrayList<String> tag, String entrance, String type) {
|
||||
|
||||
ShareSDK.initSDK(this);
|
||||
|
||||
//判断是否是官方版
|
||||
boolean isPlugin = false;
|
||||
if (tag != null){
|
||||
|
||||
@ -17,6 +17,7 @@ import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
@ -25,6 +26,7 @@ import com.gh.common.view.DownloadDialog;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadStatus;
|
||||
import com.gh.gamecenter.DownloadManagerActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
@ -40,8 +42,9 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2016/9/19.
|
||||
* 游戏详情、新闻详情基类(控制底部下载栏)
|
||||
*/
|
||||
public abstract class DetailActivity extends BaseActivity implements View.OnClickListener {
|
||||
public abstract class BaseDetailActivity extends BaseActivity implements View.OnClickListener {
|
||||
|
||||
protected TextView actionbar_tv_title;
|
||||
protected RecyclerView detail_rv_show;
|
||||
@ -70,7 +73,7 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
if (gameEntity != null && gameEntity.getApk().size() == 1) {
|
||||
String url = gameEntity.getApk().get(0).getUrl();
|
||||
if (url.equals(downloadEntity.getUrl())) {
|
||||
if (!"pause".equals(DownloadManager.getInstance(DetailActivity.this).
|
||||
if (!"pause".equals(DownloadManager.getInstance(BaseDetailActivity.this).
|
||||
getStatus(downloadEntity.getUrl()))) {
|
||||
mDownloadEntity = downloadEntity;
|
||||
invalidate();
|
||||
@ -227,15 +230,20 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String status = GameUtils.getDownloadBtnText(this, gameEntity);
|
||||
if ("插件化".equals(status)) {
|
||||
detail_tv_download.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else if ("打开".equals(status)) {
|
||||
detail_tv_download.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
} else {
|
||||
detail_tv_download.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_download_style);
|
||||
detail_tv_download.setText(String.format("下载《%s》",
|
||||
detail_tv_download.setText(String.format(status + "《%s》",
|
||||
gameEntity.getName()));
|
||||
} else {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_download_style);
|
||||
detail_tv_download.setText(String.format("下载《%s》%s",
|
||||
detail_tv_download.setText(String.format(status + "《%s》%s",
|
||||
gameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
}
|
||||
@ -350,7 +358,7 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", gameEntity.getApk().get(0).getPlatform());
|
||||
kv.put("页面", name);
|
||||
DataUtils.onEvent(DetailActivity.this, "游戏启动", gameEntity.getName(), kv);
|
||||
DataUtils.onEvent(BaseDetailActivity.this, "游戏启动", gameEntity.getName(), kv);
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(this, gameEntity.getApk().get(0).getPackageName());
|
||||
} else {
|
||||
@ -368,19 +376,19 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(DetailActivity.this, "游戏下载", gameEntity.getName(), kv);
|
||||
DataUtils.onEvent(BaseDetailActivity.this, "游戏下载", gameEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<>();
|
||||
kv2.put("版本", apkEntity.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("页面", name);
|
||||
kv2.put("位置", entrance);
|
||||
DataUtils.onEvent(DetailActivity.this, "游戏下载位置", gameEntity.getName(), kv2);
|
||||
DataUtils.onEvent(BaseDetailActivity.this, "游戏下载位置", gameEntity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv3 = new HashMap<>();
|
||||
kv3.put(entrance, "下载数");
|
||||
kv3.put(entrance, "下载开始");
|
||||
DataUtils.onEvent(DetailActivity.this, "应用数据", gameEntity.getName(), kv3);
|
||||
DataUtils.onEvent(BaseDetailActivity.this, "应用数据", gameEntity.getName(), kv3);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("game", gameEntity.getName());
|
||||
@ -403,7 +411,7 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
detail_pb_progressbar.setProgress(0);
|
||||
detail_tv_per.setText("0.0%");
|
||||
|
||||
DownloadManager.getInstance(DetailActivity.this).putStatus(apkEntity.getUrl(), "downloading");
|
||||
DownloadManager.getInstance(BaseDetailActivity.this).putStatus(apkEntity.getUrl(), "downloading");
|
||||
} else {
|
||||
toast(msg);
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package com.gh.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
@ -12,41 +13,61 @@ import com.gh.gamecenter.listener.OnCallBackListener;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/4.
|
||||
* Fragment 基类
|
||||
*/
|
||||
public class BaseFragment extends Fragment implements OnCallBackListener {
|
||||
|
||||
// private Unbinder unbinder;
|
||||
|
||||
protected View view;
|
||||
|
||||
protected void init(int layout) {
|
||||
protected Handler handler = new Handler();
|
||||
|
||||
protected boolean isEverpause;
|
||||
|
||||
protected void init(int layout, boolean flag) {
|
||||
view = View.inflate(getActivity(), layout, null);
|
||||
|
||||
//简化findViewById
|
||||
try {
|
||||
Class<?> clazz = this.getClass();
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
int id = Utils.getId(field.getName());
|
||||
if (id != -1) {
|
||||
Utils.log("reflect name = " + field.getName());
|
||||
field.setAccessible(true);
|
||||
Class<?> fieldType = field.getType();
|
||||
Object injectedValue = fieldType.cast(view.findViewById(id));
|
||||
field.set(this, injectedValue);
|
||||
field.setAccessible(false);
|
||||
// unbinder = ButterKnife.bind(this, view);
|
||||
|
||||
if (flag) {
|
||||
//简化findViewById
|
||||
try {
|
||||
Class<?> clazz = this.getClass();
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
int id = Utils.getId(field.getName());
|
||||
if (id != -1) {
|
||||
Utils.log("reflect name = " + field.getName());
|
||||
field.setAccessible(true);
|
||||
Class<?> fieldType = field.getType();
|
||||
Object injectedValue = fieldType.cast(view.findViewById(id));
|
||||
field.set(this, injectedValue);
|
||||
field.setAccessible(false);
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} else {
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void init(int layout) {
|
||||
init(layout, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
isEverpause = false;
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@ -60,10 +81,27 @@ public class BaseFragment extends Fragment implements OnCallBackListener {
|
||||
return view;
|
||||
}
|
||||
|
||||
public boolean isEverpause() {
|
||||
return isEverpause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
isEverpause = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().unregister(this);
|
||||
// unbinder.unbind();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,4 +123,5 @@ public class BaseFragment extends Fragment implements OnCallBackListener {
|
||||
public void loadEmpty() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -33,7 +33,6 @@ import com.gh.gamecenter.manager.SystemBarTintManager.SystemBarConfig;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cn.sharesdk.framework.ShareSDK;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
public class BaseFragmentActivity extends FragmentActivity {
|
||||
@ -134,8 +133,6 @@ public class BaseFragmentActivity extends FragmentActivity {
|
||||
//如果是游戏分享,newsTitle默认为空
|
||||
public void showShare(String url, String gameName, String icon, String newsTitle, ArrayList<String> tag, String entrance, String type) {
|
||||
|
||||
ShareSDK.initSDK(this);
|
||||
|
||||
//判断是否是官方版
|
||||
boolean isPlugin = false;
|
||||
if (tag != null){
|
||||
|
||||
@ -23,12 +23,10 @@ import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.ConcernActivity;
|
||||
import com.gh.gamecenter.DownloadManagerActivity;
|
||||
import com.gh.gamecenter.MainActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SearchActivity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBTopStatus;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
@ -40,6 +38,7 @@ import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/9.
|
||||
* 工具栏 搜索控制
|
||||
*/
|
||||
public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
|
||||
@ -57,10 +56,22 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
|
||||
private String hint;
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
if (!TextUtils.isEmpty(hint)) {
|
||||
outState.putString("hint", hint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
hint = savedInstanceState.getString("hint");
|
||||
}
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.fragment_home, null);
|
||||
|
||||
SharedPreferences sp = getActivity().getSharedPreferences(
|
||||
@ -71,8 +82,7 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
DisplayUtils.dip2px(getActivity(), 48)));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
int top = DisplayUtils.getInternalDimensionSize(getResources(),
|
||||
"status_bar_height");
|
||||
int top = DisplayUtils.getInternalDimensionSize(getResources(), "status_bar_height");
|
||||
home_actionbar.setPadding(0, top, 0, 0);
|
||||
lparams.height += top;
|
||||
}
|
||||
@ -123,8 +133,7 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
|
||||
searchHint = (TextView) view.findViewById(R.id.actionbar_search_input);
|
||||
searchHint.setOnClickListener(this);
|
||||
if (!TextUtils.isEmpty(MainActivity.searchHint)) {
|
||||
hint = MainActivity.searchHint;
|
||||
if (!TextUtils.isEmpty(hint)) {
|
||||
searchHint.setHint(hint);
|
||||
}
|
||||
}
|
||||
@ -188,10 +197,12 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBTopStatus status) {
|
||||
if (!TextUtils.isEmpty(status.getSearchHint())) {
|
||||
hint = status.getSearchHint();
|
||||
searchHint.setHint(hint);
|
||||
public void setHint(String hint) {
|
||||
if (!TextUtils.isEmpty(hint)) {
|
||||
this.hint = hint;
|
||||
if (searchHint != null) {
|
||||
searchHint.setHint(hint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,9 +6,10 @@ import android.content.SharedPreferences;
|
||||
|
||||
public class Config {
|
||||
|
||||
public static final String HOST = "http://api.ghzhushou.com/v2d1/";
|
||||
public static final String HOST = "http://api.ghzhushou.com/v2d2/";
|
||||
public static final String USER_HOST = "http://user.ghzhushou.com/v1d0/";
|
||||
public static final String COMMENT_HOST = "http://comment.ghzhushou.com/v1d0/";
|
||||
public static final String DATA_HOST = "http://data.ghzhushou.com/";
|
||||
public static final String PREFERENCE = "ghzhushou";
|
||||
|
||||
public static boolean isShow(Context context) {
|
||||
|
||||
77
app/src/main/java/com/gh/common/util/AccessTokenKeeper.java
Normal file
77
app/src/main/java/com/gh/common/util/AccessTokenKeeper.java
Normal file
@ -0,0 +1,77 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.sina.weibo.sdk.auth.Oauth2AccessToken;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/24.
|
||||
* 该类定义了微博授权时所需要的参数。
|
||||
*/
|
||||
public class AccessTokenKeeper {
|
||||
private static final String PREFERENCES_NAME = "com_weibo_sdk_android";
|
||||
|
||||
private static final String KEY_UID = "uid";
|
||||
private static final String KEY_ACCESS_TOKEN = "access_token";
|
||||
private static final String KEY_EXPIRES_IN = "expires_in";
|
||||
private static final String KEY_REFRESH_TOKEN = "refresh_token";
|
||||
|
||||
/**
|
||||
* 保存 Token 对象到 SharedPreferences。
|
||||
*
|
||||
* @param context 应用程序上下文环境
|
||||
* @param token Token 对象
|
||||
*/
|
||||
public static void writeAccessToken(Context context, Oauth2AccessToken token) {
|
||||
if (null == context || null == token) {
|
||||
return;
|
||||
}
|
||||
|
||||
SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
|
||||
SharedPreferences.Editor editor = pref.edit();
|
||||
editor.putString(KEY_UID, token.getUid());
|
||||
editor.putString(KEY_ACCESS_TOKEN, token.getToken());
|
||||
editor.putString(KEY_REFRESH_TOKEN, token.getRefreshToken());
|
||||
editor.putLong(KEY_EXPIRES_IN, token.getExpiresTime());
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 SharedPreferences 读取 Token 信息。
|
||||
*
|
||||
* @param context 应用程序上下文环境
|
||||
*
|
||||
* @return 返回 Token 对象
|
||||
*/
|
||||
public static Oauth2AccessToken readAccessToken(Context context) {
|
||||
if (null == context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Oauth2AccessToken token = new Oauth2AccessToken();
|
||||
SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
|
||||
token.setUid(pref.getString(KEY_UID, ""));
|
||||
token.setToken(pref.getString(KEY_ACCESS_TOKEN, ""));
|
||||
token.setRefreshToken(pref.getString(KEY_REFRESH_TOKEN, ""));
|
||||
token.setExpiresTime(pref.getLong(KEY_EXPIRES_IN, 0));
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空 SharedPreferences 中 Token信息。
|
||||
*
|
||||
* @param context 应用程序上下文环境
|
||||
*/
|
||||
public static void clear(Context context) {
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
|
||||
SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
|
||||
SharedPreferences.Editor editor = pref.edit();
|
||||
editor.clear();
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.facebook.drawee.drawable.ScalingUtils;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.ViewImageActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/8.
|
||||
*
|
||||
* 初始化资讯关注-内容图片
|
||||
*
|
||||
**/
|
||||
public class ConcernContentUtils {
|
||||
|
||||
public static void addContentPic(int width, LinearLayout linearLayout, List<String> list, Context context) {
|
||||
int count = list.size();
|
||||
LinearLayout ll;
|
||||
int index = 0;
|
||||
for (int i = 0, size = (int) Math.ceil(list.size() / 3.0f); i < size; i++) {
|
||||
switch (count % 3) {
|
||||
case 0:
|
||||
ll = new LinearLayout(context);
|
||||
ll.setOrientation(LinearLayout.HORIZONTAL);
|
||||
for (int j = 0; j < 3; j++) {
|
||||
ll.addView(getImageView(list, index, width, 0, context));
|
||||
index += 1;
|
||||
}
|
||||
linearLayout.addView(ll);
|
||||
count -= 3;
|
||||
break;
|
||||
case 1:
|
||||
linearLayout.addView(getImageView(list, index, width, 1, context));
|
||||
count -= 1;
|
||||
index += 1;
|
||||
break;
|
||||
case 2:
|
||||
ll = new LinearLayout(context);
|
||||
ll.setOrientation(LinearLayout.HORIZONTAL);
|
||||
for (int j = 0; j < 2; j++) {
|
||||
ll.addView(getImageView(list, index, width, 2, context));
|
||||
index += 1;
|
||||
}
|
||||
linearLayout.addView(ll);
|
||||
count -= 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static SimpleDraweeView getImageView(final List<String> list, final int position, int width, int type, final Context context) {
|
||||
SimpleDraweeView imageView;
|
||||
if (type == 0) {
|
||||
imageView = new SimpleDraweeView(context);
|
||||
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
||||
0, width / 3 - DisplayUtils.dip2px(context, 4));
|
||||
lparams.setMargins(DisplayUtils.dip2px(context, 2), 0,
|
||||
DisplayUtils.dip2px(context, 2), DisplayUtils.dip2px(context, 4));
|
||||
lparams.weight = 1;
|
||||
imageView.setLayoutParams(lparams);
|
||||
ImageUtils.getInstance().display(context.getResources(), imageView, ScalingUtils.ScaleType.CENTER_CROP, list.get(position));
|
||||
} else if (type == 1) {
|
||||
imageView = new SimpleDraweeView(context);
|
||||
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(width, width / 2);
|
||||
lparams.setMargins(DisplayUtils.dip2px(context, 2), 0,
|
||||
DisplayUtils.dip2px(context, 2), DisplayUtils.dip2px(context, 4));
|
||||
imageView.setLayoutParams(lparams);
|
||||
ImageUtils.getInstance().display(context.getResources(), imageView, ScalingUtils.ScaleType.CENTER_CROP, list.get(position));
|
||||
} else {
|
||||
imageView = new SimpleDraweeView(context);
|
||||
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
||||
0, width / 2 - DisplayUtils.dip2px(context, 4));
|
||||
lparams.setMargins(DisplayUtils.dip2px(context, 2), 0,
|
||||
DisplayUtils.dip2px(context, 2), DisplayUtils.dip2px(context, 4));
|
||||
lparams.weight = 1;
|
||||
imageView.setLayoutParams(lparams);
|
||||
ImageUtils.getInstance().display(context.getResources(), imageView, ScalingUtils.ScaleType.CENTER_CROP, list.get(position));
|
||||
}
|
||||
imageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent checkIntent = new Intent(context, ViewImageActivity.class);
|
||||
checkIntent.putExtra("urls", (ArrayList<String>) list);
|
||||
checkIntent.putExtra("current", position);
|
||||
checkIntent.putExtra("ScaleType", "FIT_CENTER");
|
||||
context.startActivity(checkIntent);
|
||||
}
|
||||
});
|
||||
return imageView;
|
||||
}
|
||||
}
|
||||
@ -144,9 +144,9 @@ public class DialogUtils {
|
||||
}
|
||||
|
||||
public static void showPluginDialog(Context context, final ConfiremListener listener) {
|
||||
Spanned spanned = Html.fromHtml("您将进行插件化安装以实现插件功能,此过程将"
|
||||
Spanned spanned = Html.fromHtml("您将进行插件化安装以实现插件功能,此过程将"
|
||||
+ "<font color=\"#ff0000\">卸载</font>" + "当前使用的版本并"
|
||||
+ "<font color=\"#ff0000\">安装插件版本</font>" + "。");
|
||||
+ "<font color=\"#ff0000\">安装插件版本</font>");
|
||||
showWarningDialog(context, "插件化安装", spanned, listener);
|
||||
}
|
||||
|
||||
|
||||
@ -166,63 +166,17 @@ public class DownloadItemUtils {
|
||||
TextView download_speed,
|
||||
TextView download_percentage,
|
||||
TextView downloadBtn,
|
||||
GameEntity entity,
|
||||
GameEntity gameEntity,
|
||||
boolean isShowPlatform) {
|
||||
|
||||
ArrayMap<String, DownloadEntity> entryMap = entity.getEntryMap();
|
||||
|
||||
// 更新下载按钮状态
|
||||
int doneCount = 0; // 下载完成数量
|
||||
int updateCount = 0; // 可更新数量
|
||||
int installCount = 0; // 已安装数量
|
||||
int pluginCount = 0; // 可插件化数量
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
for (String key : entryMap.keySet()) {
|
||||
if (entryMap.get(key).getStatus().equals(DownloadStatus.done)) {
|
||||
doneCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
if (PackageManager.isCanUpdate(entity.getId(), apkEntity.getPackageName())) {
|
||||
updateCount++;
|
||||
}
|
||||
}
|
||||
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
if (PackageManager.isInstalled(apkEntity.getPackageName())) {
|
||||
if (!PackageUtils.isSignature(context, apkEntity.getPackageName())) {
|
||||
pluginCount++;
|
||||
} else {
|
||||
installCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
downloadBtn.setTextColor(Color.WHITE);
|
||||
if (doneCount != 0) {
|
||||
downloadBtn.setText("安装");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
} else if (updateCount != 0) {
|
||||
downloadBtn.setText("更新");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
} else if (installCount != 0) {
|
||||
downloadBtn.setText("打开");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
} else if (pluginCount != 0) {
|
||||
downloadBtn.setText("插件化");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else {
|
||||
downloadBtn.setText("下载");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
}
|
||||
GameUtils.setDownloadBtnStatus(context, gameEntity, downloadBtn);
|
||||
|
||||
ArrayMap<String, DownloadEntity> entryMap = gameEntity.getEntryMap();
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
|
||||
DownloadEntity downloadEntity;
|
||||
|
||||
LinkedBlockingQueue<String> queue = DownloadManager.getInstance(context).getQueue(entity.getName());
|
||||
LinkedBlockingQueue<String> queue = DownloadManager.getInstance(context).getQueue(gameEntity.getName());
|
||||
if (queue != null && !queue.isEmpty()) {
|
||||
downloadEntity = entryMap.get(queue.peek());
|
||||
} else {
|
||||
@ -343,21 +297,19 @@ public class DownloadItemUtils {
|
||||
boolean isShowPlatform) {
|
||||
|
||||
// 控制是否显示下载按钮
|
||||
if (Config.isShow(context)) {
|
||||
downloadBtn.setVisibility(View.VISIBLE);
|
||||
if (!Config.isShow(context) || "光环助手".equals(entity.getName())) {
|
||||
downloadBtn.setVisibility(View.GONE);
|
||||
} else {
|
||||
downloadBtn.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if ("光环助手".equals(entity.getName())) {
|
||||
downloadBtn.setVisibility(View.GONE);
|
||||
downloadBtn.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
textView.setVisibility(View.VISIBLE);
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
downloadBtn.setVisibility(View.GONE);
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_pause_style);
|
||||
downloadBtn.setText("暂无");
|
||||
downloadBtn.setClickable(false);
|
||||
} else if (entity.getApk().size() == 1) {
|
||||
updateNormalItem(context, textView, game_progressbar, game_ll_info, download_speed,
|
||||
download_percentage, downloadBtn, entity, isShowPlatform);
|
||||
|
||||
@ -7,6 +7,8 @@ import android.os.StrictMode;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
@ -44,7 +46,7 @@ public class FileUtils {
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
//cannot create file
|
||||
// cannot create file
|
||||
Utils.log("cannot create file");
|
||||
dir = null;
|
||||
}
|
||||
@ -53,6 +55,11 @@ public class FileUtils {
|
||||
if (dir == null) {
|
||||
String baseDir = context.getFilesDir().getAbsolutePath();
|
||||
dir = checkDir(baseDir + File.separator + "gh-download");
|
||||
try {
|
||||
Runtime.getRuntime().exec("chmod 755 " + dir);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
@ -79,7 +86,10 @@ public class FileUtils {
|
||||
|
||||
private static String checkDir(String dir) {
|
||||
File directory = new File(dir);
|
||||
if (!directory.exists() || !directory.isDirectory()) {
|
||||
if (directory.exists() && !directory.isDirectory()) {
|
||||
directory.delete();
|
||||
}
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs();
|
||||
}
|
||||
return dir;
|
||||
@ -273,14 +283,18 @@ public class FileUtils {
|
||||
|
||||
int statusCode = connection.getResponseCode();
|
||||
Utils.log("statusCode = " + statusCode);
|
||||
if (statusCode == HttpURLConnection.HTTP_OK) {
|
||||
if (statusCode == 200) {
|
||||
// {"icon":"http:\/\/gh-test-1.oss-cn-qingdao.aliyuncs.com\/pic\/57e4f4d58a3200042d29492f.jpg"}
|
||||
JSONObject response = new JSONObject(b.toString().trim());
|
||||
response.put("statusCode", HttpURLConnection.HTTP_OK);
|
||||
response.put("statusCode", 200);
|
||||
return response;
|
||||
} else if (statusCode == HttpURLConnection.HTTP_FORBIDDEN) {
|
||||
} else if (statusCode == 403) {
|
||||
JSONObject response = new JSONObject(b.toString().trim());
|
||||
response.put("statusCode", HttpURLConnection.HTTP_FORBIDDEN);
|
||||
response.put("statusCode", 403);
|
||||
return response;
|
||||
} else if (statusCode == 401) {
|
||||
JSONObject response = new JSONObject();
|
||||
response.put("statusCode", 401);
|
||||
return response;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -291,4 +305,78 @@ public class FileUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 读取文件,返回byte[]
|
||||
public static byte[] readFile(File file) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
FileInputStream fis = null;
|
||||
ByteArrayOutputStream bos = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
bos = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[2048];
|
||||
int len;
|
||||
while ((len = fis.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, len);
|
||||
}
|
||||
bos.flush();
|
||||
return bos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (bos != null) {
|
||||
try {
|
||||
bos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 根据byte[],保存文件
|
||||
public static void saveFile(File file, byte[] data) {
|
||||
if (file == null || data == null) {
|
||||
return;
|
||||
}
|
||||
ByteArrayInputStream bis = null;
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
bis = new ByteArrayInputStream(data);
|
||||
fos = new FileOutputStream(file);
|
||||
byte[] buffer = new byte[2048];
|
||||
int len;
|
||||
while ((len = bis.read(buffer)) != -1) {
|
||||
fos.write(buffer, 0, len);
|
||||
}
|
||||
fos.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (bis != null) {
|
||||
try {
|
||||
bis.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,10 +2,19 @@ package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadStatus;
|
||||
import com.gh.gamecenter.GameDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/29.
|
||||
@ -34,4 +43,66 @@ public class GameUtils {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置下载按钮状态
|
||||
*/
|
||||
public static void setDownloadBtnStatus(Context context, GameEntity gameEntity, TextView downloadBtn) {
|
||||
String status = getDownloadBtnText(context, gameEntity);
|
||||
downloadBtn.setTextColor(Color.WHITE);
|
||||
downloadBtn.setText(status);
|
||||
if ("插件化".equals(status)) {
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else if ("打开".equals(status)) {
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
} else {
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下载按钮文案
|
||||
*/
|
||||
public static String getDownloadBtnText(Context context, GameEntity gameEntity) {
|
||||
int doneCount = 0; // 下载完成数量
|
||||
int pluginCount = 0; // 可插件化数量
|
||||
int updateCount = 0; // 可更新数量
|
||||
int installCount = 0; // 已安装数量
|
||||
DownloadEntity downloadEntity;
|
||||
Object gh_id;
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
downloadEntity = DownloadManager.getInstance(context).get(apkEntity.getUrl());
|
||||
if (downloadEntity != null) {
|
||||
if (downloadEntity.getStatus().equals(DownloadStatus.done)) {
|
||||
doneCount++;
|
||||
} else if (downloadEntity.isPluggable()) {
|
||||
pluginCount++;
|
||||
} else if (downloadEntity.isUpdate()) {
|
||||
updateCount++;
|
||||
}
|
||||
}
|
||||
if (PackageManager.isCanUpdate(gameEntity.getId(), apkEntity.getPackageName())) {
|
||||
updateCount++;
|
||||
}
|
||||
if (PackageManager.isInstalled(apkEntity.getPackageName())) {
|
||||
gh_id = PackageUtils.getMetaData(context, apkEntity.getPackageName(), "gh_id");
|
||||
if (!PackageUtils.isSignature(context, apkEntity.getPackageName())) {
|
||||
pluginCount++;
|
||||
} else if (gh_id == null || gh_id.equals(gameEntity.getId())) {
|
||||
installCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (doneCount != 0) {
|
||||
return "安装";
|
||||
} else if (pluginCount != 0) {
|
||||
return "插件化";
|
||||
} else if (updateCount != 0) {
|
||||
return "更新";
|
||||
} else if (installCount != 0) {
|
||||
return "打开";
|
||||
} else {
|
||||
return "下载";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,8 +1,16 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.KeyStore;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
@ -11,55 +19,119 @@ import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import okhttp3.internal.tls.OkHostnameVerifier;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/10/8.
|
||||
*
|
||||
*/
|
||||
public class HttpsUtils {
|
||||
|
||||
private static class MyTrustManager implements X509TrustManager {
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType)
|
||||
throws CertificateException {
|
||||
}
|
||||
private static final TrustManager[] TRUST_MANAGERS = new TrustManager[] {
|
||||
new X509TrustManager() {
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType)
|
||||
}
|
||||
|
||||
throws CertificateException {
|
||||
}
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return new X509Certificate[0];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static class MyHostnameVerifier implements HostnameVerifier {
|
||||
private static final HostnameVerifier HOSTNAME_VERIFIER = new HostnameVerifier() {
|
||||
@Override
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
private static SSLSocketFactory mSSLSocketFactory;
|
||||
private static HostnameVerifier mHostnameVerifier;
|
||||
|
||||
public static HttpsURLConnection getHttpsURLConnection(URL url) throws Exception {
|
||||
if (mSSLSocketFactory == null || mHostnameVerifier == null) {
|
||||
SSLContext sc = SSLContext.getInstance("TLS");
|
||||
sc.init(null, new TrustManager[]{new MyTrustManager()}, new SecureRandom());
|
||||
mSSLSocketFactory = sc.getSocketFactory();
|
||||
public static void initHttpsUrlConnection(Context context) {
|
||||
try {
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
|
||||
mHostnameVerifier = new MyHostnameVerifier();
|
||||
KeyStore keyStore = getHttpsKeyStore(context);
|
||||
if (keyStore != null) {
|
||||
String algorithm = TrustManagerFactory.getDefaultAlgorithm();
|
||||
TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
|
||||
tmf.init(keyStore);
|
||||
sslContext.init(null, tmf.getTrustManagers(), null);
|
||||
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(mSSLSocketFactory);
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(mHostnameVerifier);
|
||||
mHostnameVerifier = OkHostnameVerifier.INSTANCE;
|
||||
} else {
|
||||
sslContext.init(null, TRUST_MANAGERS, null);
|
||||
|
||||
mHostnameVerifier = HOSTNAME_VERIFIER;
|
||||
}
|
||||
mSSLSocketFactory = sslContext.getSocketFactory();
|
||||
|
||||
// HttpsURLConnection.setDefaultSSLSocketFactory(mSSLSocketFactory);
|
||||
// HttpsURLConnection.setDefaultHostnameVerifier(mHostnameVerifier);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return (HttpsURLConnection) url.openConnection();
|
||||
}
|
||||
|
||||
private static KeyStore getHttpsKeyStore(Context context) {
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = context.getResources().openRawResource(R.raw.download);
|
||||
//读取证书
|
||||
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
|
||||
certificateFactory.generateCertificate(is);
|
||||
Certificate certificate = certificateFactory.generateCertificate(is);
|
||||
//创建一个证书库,并将证书导入证书库
|
||||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keyStore.load(null, null);
|
||||
keyStore.setCertificateEntry("trust", certificate);
|
||||
return keyStore;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static HttpsURLConnection getHttpsURLConnection(URL url) throws Exception {
|
||||
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
if ("apk2.ghzhushou.com".equals(url.getHost())
|
||||
|| "download.ghzhushou.com".equals(url.getHost())) {
|
||||
if (mSSLSocketFactory == null || mHostnameVerifier == null) {
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(null, TRUST_MANAGERS, null);
|
||||
mSSLSocketFactory = sslContext.getSocketFactory();
|
||||
|
||||
mHostnameVerifier = HOSTNAME_VERIFIER;
|
||||
}
|
||||
httpsURLConnection.setSSLSocketFactory(mSSLSocketFactory);
|
||||
httpsURLConnection.setHostnameVerifier(mHostnameVerifier);
|
||||
} else {
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(null, TRUST_MANAGERS, null);
|
||||
httpsURLConnection.setSSLSocketFactory(sslContext.getSocketFactory());
|
||||
httpsURLConnection.setHostnameVerifier(HOSTNAME_VERIFIER);
|
||||
}
|
||||
return httpsURLConnection;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,35 +1,30 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.net.Uri;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.facebook.common.executors.CallerThreadExecutor;
|
||||
import com.facebook.common.references.CloseableReference;
|
||||
import com.facebook.datasource.DataSource;
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.drawee.controller.BaseControllerListener;
|
||||
import com.facebook.drawee.controller.ControllerListener;
|
||||
import com.facebook.drawee.drawable.ScalingUtils;
|
||||
import com.facebook.drawee.generic.GenericDraweeHierarchy;
|
||||
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
|
||||
import com.facebook.drawee.interfaces.DraweeController;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.facebook.imagepipeline.core.ImagePipeline;
|
||||
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
|
||||
import com.facebook.imagepipeline.image.CloseableImage;
|
||||
import com.facebook.imagepipeline.image.ImageInfo;
|
||||
import com.facebook.imagepipeline.request.ImageRequest;
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
public class ImageUtils {
|
||||
|
||||
private static ImageUtils singleton;
|
||||
|
||||
public static ImageUtils getInstance(Context context) {
|
||||
public static ImageUtils getInstance() {
|
||||
if (singleton == null) {
|
||||
synchronized (ImageUtils.class) {
|
||||
if (singleton == null) {
|
||||
@ -41,121 +36,70 @@ public class ImageUtils {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
|
||||
// 自适应图片宽高
|
||||
public void display (String url , final SimpleDraweeView simpleDraweeView, final Context context, final int paddingSize){
|
||||
ControllerListener listener = new BaseControllerListener(){
|
||||
public void display(final SimpleDraweeView simpleDraweeView, String url, final int width) {
|
||||
ControllerListener<ImageInfo> listener = new BaseControllerListener<ImageInfo>(){
|
||||
@Override
|
||||
public void onFinalImageSet(String id, Object imageInfo, Animatable animatable) {
|
||||
super.onFinalImageSet(id, imageInfo, animatable);
|
||||
public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
|
||||
if (imageInfo == null){
|
||||
return;
|
||||
}
|
||||
ImageInfo imageInfo1 = (ImageInfo) imageInfo;
|
||||
int height = imageInfo1.getHeight();
|
||||
int width = imageInfo1.getWidth();
|
||||
int widthPixels = context.getResources().getDisplayMetrics().widthPixels - DisplayUtils.dip2px(context,paddingSize);
|
||||
float index = (float) height / (float) width;
|
||||
int newHeight = (int)(index * widthPixels);
|
||||
ViewGroup.LayoutParams layoutParams = simpleDraweeView.getLayoutParams();
|
||||
layoutParams.height = newHeight;
|
||||
float scale = (float) imageInfo.getHeight() / (float) imageInfo.getWidth();
|
||||
layoutParams.height = (int)(width * scale);
|
||||
simpleDraweeView.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIntermediateImageSet(String id, Object imageInfo) {
|
||||
super.onIntermediateImageSet(id, imageInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIntermediateImageFailed(String id, Throwable throwable) {
|
||||
super.onIntermediateImageFailed(id, throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(String id, Throwable throwable) {
|
||||
super.onFailure(id, throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRelease(String id) {
|
||||
super.onRelease(id);
|
||||
}
|
||||
};
|
||||
|
||||
DraweeController controller = Fresco.newDraweeControllerBuilder()
|
||||
simpleDraweeView.setController(Fresco.newDraweeControllerBuilder()
|
||||
.setUri(url)
|
||||
.setControllerListener(listener)
|
||||
.build();
|
||||
|
||||
simpleDraweeView.setController(controller);
|
||||
|
||||
.build());
|
||||
}
|
||||
|
||||
//设置缩放类型,设置按压状态下的叠加图
|
||||
public void display (String url , SimpleDraweeView simpleDraweeView, ScalingUtils.ScaleType scaleType, Context context){
|
||||
GenericDraweeHierarchyBuilder builder =
|
||||
new GenericDraweeHierarchyBuilder(context.getResources());
|
||||
GenericDraweeHierarchy hierarchy = builder
|
||||
// 设置缩放类型,设置按压状态下的叠加图
|
||||
public void display(Resources resources, SimpleDraweeView simpleDraweeView,
|
||||
ScalingUtils.ScaleType scaleType, String url) {
|
||||
simpleDraweeView.setHierarchy(new GenericDraweeHierarchyBuilder(resources)
|
||||
.setFadeDuration(500)
|
||||
.setPressedStateOverlay(new ColorDrawable(context.getResources().getColor(R.color.pressed_bg)))
|
||||
.setPressedStateOverlay(new ColorDrawable(resources.getColor(R.color.pressed_bg)))
|
||||
.setPlaceholderImage(R.drawable.ocupy2, ScalingUtils.ScaleType.CENTER)
|
||||
.setBackground(new ColorDrawable(Color.parseColor("#ececec")))
|
||||
.setBackground(new ColorDrawable(resources.getColor(R.color.placeholder_bg)))
|
||||
.setActualImageScaleType(scaleType)
|
||||
.build();
|
||||
simpleDraweeView.setHierarchy(hierarchy);
|
||||
.build());
|
||||
simpleDraweeView.setImageURI(url);
|
||||
|
||||
}
|
||||
|
||||
//设置占位符
|
||||
public void display (String url , SimpleDraweeView simpleDraweeView, int placeholderImage, Context context){
|
||||
|
||||
GenericDraweeHierarchyBuilder builder =
|
||||
new GenericDraweeHierarchyBuilder(context.getResources());
|
||||
GenericDraweeHierarchy hierarchy = builder
|
||||
// 设置占位符
|
||||
public void display(Resources resources, SimpleDraweeView simpleDraweeView, String url, int placeholderImage) {
|
||||
simpleDraweeView.setHierarchy(new GenericDraweeHierarchyBuilder(resources)
|
||||
.setFadeDuration(500)
|
||||
.setPressedStateOverlay(new ColorDrawable(context.getResources().getColor(R.color.pressed_bg)))
|
||||
.setBackground(new ColorDrawable(Color.parseColor("#ececec")))
|
||||
.setPressedStateOverlay(new ColorDrawable(resources.getColor(R.color.pressed_bg)))
|
||||
.setBackground(new ColorDrawable(resources.getColor(R.color.placeholder_bg)))
|
||||
.setPlaceholderImage(placeholderImage)
|
||||
.build();
|
||||
simpleDraweeView.setHierarchy(hierarchy);
|
||||
.build());
|
||||
simpleDraweeView.setImageURI(url);
|
||||
|
||||
}
|
||||
|
||||
//图片下载监听和设置低高分辨率图片
|
||||
public void display (String url, String lowUrl, SimpleDraweeView simpleDraweeView, ControllerListener listener){
|
||||
|
||||
DraweeController controller = Fresco.newDraweeControllerBuilder()
|
||||
// 图片下载监听和设置低高分辨率图片
|
||||
public void display(SimpleDraweeView simpleDraweeView, String url, String lowUrl,
|
||||
ControllerListener<? super ImageInfo> listener) {
|
||||
simpleDraweeView.setController(Fresco.newDraweeControllerBuilder()
|
||||
.setImageRequest(ImageRequest.fromUri(url))
|
||||
.setControllerListener(listener)
|
||||
.setLowResImageRequest(ImageRequest.fromUri(lowUrl)) //低分辨率图片
|
||||
.build();
|
||||
simpleDraweeView.setController(controller);
|
||||
.setLowResImageRequest(ImageRequest.fromUri(lowUrl)) // 低分辨率图片
|
||||
.build());
|
||||
}
|
||||
|
||||
public void display (String url, SimpleDraweeView simpleDraweeView, ControllerListener listener){
|
||||
|
||||
DraweeController controller = Fresco.newDraweeControllerBuilder()
|
||||
.setImageRequest(ImageRequest.fromUri(url))
|
||||
.setControllerListener(listener)
|
||||
.build();
|
||||
simpleDraweeView.setController(controller);
|
||||
}
|
||||
|
||||
//获取bitmap
|
||||
public void display (String url, BaseBitmapDataSubscriber dataSubscriber, Context context){
|
||||
// 获取bitmap
|
||||
public void display(Context context, String url, BaseBitmapDataSubscriber dataSubscriber) {
|
||||
ImageRequest imageRequest = ImageRequestBuilder
|
||||
.newBuilderWithSource(Uri.parse(url))
|
||||
.setProgressiveRenderingEnabled(true)
|
||||
.build();
|
||||
|
||||
ImagePipeline imagePipeline = Fresco.getImagePipeline();
|
||||
DataSource<CloseableReference<CloseableImage>>
|
||||
dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
|
||||
dataSource.subscribe(dataSubscriber, CallerThreadExecutor.getInstance());
|
||||
|
||||
Fresco.getImagePipeline()
|
||||
.fetchDecodedImage(imageRequest, context)
|
||||
.subscribe(dataSubscriber, CallerThreadExecutor.getInstance());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
441
app/src/main/java/com/gh/common/util/MessageShareUtils.java
Normal file
441
app/src/main/java/com/gh/common/util/MessageShareUtils.java
Normal file
@ -0,0 +1,441 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
import com.tencent.connect.share.QQShare;
|
||||
import com.tencent.mm.sdk.openapi.IWXAPI;
|
||||
import com.tencent.mm.sdk.openapi.SendMessageToWX;
|
||||
import com.tencent.mm.sdk.openapi.WXAPIFactory;
|
||||
import com.tencent.mm.sdk.openapi.WXImageObject;
|
||||
import com.tencent.mm.sdk.openapi.WXMediaMessage;
|
||||
import com.tencent.mm.sdk.platformtools.Util;
|
||||
import com.tencent.tauth.IUiListener;
|
||||
import com.tencent.tauth.Tencent;
|
||||
import com.tencent.tauth.UiError;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/8.
|
||||
*/
|
||||
public class MessageShareUtils {
|
||||
private static MessageShareUtils instance;
|
||||
|
||||
private Bitmap shareBm; //分享截图
|
||||
|
||||
private String picName;
|
||||
|
||||
private boolean isPlugin = false;
|
||||
|
||||
private static IWXAPI api;
|
||||
private static Tencent mTencent;
|
||||
|
||||
private Handler handler;
|
||||
|
||||
private int[] arrLogo = {R.drawable.share_wechat_logo, R.drawable.share_wechatmoments_logo, R.drawable.share_qq_logo
|
||||
, R.drawable.share_qzone_logo, R.drawable.share_save};
|
||||
private String[] arrLabel = {"微信好友", "朋友圈", "QQ好友", "QQ空间", "保存"};
|
||||
|
||||
private PopupWindow popupWindow;
|
||||
|
||||
private Context context;
|
||||
|
||||
private Activity activity; // 用来关闭分享页面
|
||||
|
||||
public static MessageShareUtils getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
instance = new MessageShareUtils();
|
||||
mTencent = Tencent.createInstance("1104659243", context); //初始化QQ分享
|
||||
api = WXAPIFactory.createWXAPI(context, "wx3ffd0785fad18396"); //初始化微信分享
|
||||
}
|
||||
instance.context = context;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void showShareWindows(View view, Bitmap bitmap, String picName, boolean ispopupWindow){
|
||||
this.shareBm = bitmap;
|
||||
this.picName = picName;
|
||||
this.activity= (Activity) context;
|
||||
|
||||
RelativeLayout contentView = new RelativeLayout(context);
|
||||
contentView.setBackgroundColor(0x8c000000);
|
||||
contentView.setFocusable(true);
|
||||
contentView.setFocusableInTouchMode(true);
|
||||
|
||||
RecyclerView shareRecyclerView = new RecyclerView(context);
|
||||
shareRecyclerView.setPadding(DisplayUtils.dip2px(context, 10), DisplayUtils.dip2px(context, 10), DisplayUtils.dip2px(context, 10), 0);
|
||||
shareRecyclerView.setBackgroundColor(Color.WHITE);
|
||||
|
||||
//RecyclerView禁止滑动
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 5){
|
||||
@Override
|
||||
public boolean canScrollVertically() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
shareRecyclerView.setLayoutManager(gridLayoutManager);
|
||||
shareRecyclerView.setAdapter(new ShareRecyclerViewAdapter());
|
||||
|
||||
if (!ispopupWindow) {
|
||||
LinearLayout llBottom = (LinearLayout) view;
|
||||
ViewGroup.LayoutParams layoutParams = llBottom.getLayoutParams();
|
||||
layoutParams.height = DisplayUtils.dip2px(context, 100);
|
||||
llBottom.addView(shareRecyclerView);
|
||||
return;
|
||||
}
|
||||
|
||||
RelativeLayout.LayoutParams rlParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT
|
||||
, DisplayUtils.dip2px(context, 106));
|
||||
rlParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
contentView.addView(shareRecyclerView,rlParams);
|
||||
|
||||
popupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT
|
||||
, LinearLayout.LayoutParams.MATCH_PARENT, true);
|
||||
popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
|
||||
popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
|
||||
|
||||
contentView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
contentView.setOnKeyListener(new View.OnKeyListener() {
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK
|
||||
&& event.getRepeatCount() == 0 && popupWindow != null
|
||||
&& popupWindow.isShowing()) {
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public class ShareRecyclerViewAdapter extends RecyclerView.Adapter<ShareRecyclerViewAdapter.ViewHolder>{
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
LinearLayout linearLayout = new LinearLayout(context);
|
||||
linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, DisplayUtils.dip2px(context, 90)));
|
||||
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
linearLayout.setBackgroundResource(R.drawable.cardview_item_style);
|
||||
|
||||
ImageView shareLogo = new ImageView(context);
|
||||
LinearLayout.LayoutParams logoParams = new LinearLayout.LayoutParams(DisplayUtils.dip2px(context, 43), DisplayUtils.dip2px(context, 43));
|
||||
logoParams.setMargins(0, DisplayUtils.dip2px(context, 10), 0, 0);
|
||||
shareLogo.setLayoutParams(logoParams);
|
||||
|
||||
TextView shareLabel = new TextView(context);
|
||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
layoutParams.setMargins(0, DisplayUtils.dip2px(context,10), 0, 0);
|
||||
shareLabel.setLayoutParams(layoutParams);
|
||||
shareLabel.setGravity(Gravity.CENTER);
|
||||
shareLabel.setTextColor(Color.parseColor("#3a3a3a"));
|
||||
shareLabel.setTextSize(13);
|
||||
|
||||
linearLayout.addView(shareLogo);
|
||||
linearLayout.addView(shareLabel);
|
||||
|
||||
return new ViewHolder(linearLayout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||
holder.shareLogo.setImageResource(arrLogo[position]);
|
||||
holder.shareLabel.setText(arrLabel[position]);
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (holder.getPosition()){
|
||||
case 0:
|
||||
wechatSahre();
|
||||
activity.finish();
|
||||
break;
|
||||
case 1:
|
||||
wechatMomentsSahre();
|
||||
activity.finish();
|
||||
break;
|
||||
case 2:
|
||||
qqSahre();
|
||||
break;
|
||||
case 3:
|
||||
qZoneSahre();
|
||||
break;
|
||||
case 4:
|
||||
String savePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures/ghzhushou/";
|
||||
writeBitmap(savePath, "gh-" + new Date().getTime() + ".jpg", shareBm, true);
|
||||
|
||||
if (popupWindow == null) return;
|
||||
popupWindow.dismiss();
|
||||
activity.finish();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return arrLogo.length;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder{
|
||||
LinearLayout linearLayout;
|
||||
TextView shareLabel;
|
||||
ImageView shareLogo;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
linearLayout = (LinearLayout) itemView;
|
||||
shareLogo = (ImageView) linearLayout.getChildAt(0);
|
||||
shareLabel = (TextView) linearLayout.getChildAt(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//QQ分享
|
||||
private void qqSahre(){
|
||||
Utils.toast(context,"分享跳转中...");
|
||||
Bundle params = new Bundle();
|
||||
params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE,
|
||||
QQShare.SHARE_TO_QQ_TYPE_IMAGE);
|
||||
params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, context.getExternalCacheDir().getPath() + "/ShareImg/" + picName);
|
||||
params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "光环助手");
|
||||
params.putInt(QQShare.SHARE_TO_QQ_EXT_INT,
|
||||
QQShare.SHARE_TO_QQ_FLAG_QZONE_ITEM_HIDE);
|
||||
mTencent.shareToQQ(
|
||||
(Activity) context, params,QqShareListener);
|
||||
if (popupWindow == null) return;
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
|
||||
//QQ空间分享
|
||||
private void qZoneSahre(){
|
||||
Utils.toast(context,"分享跳转中...");
|
||||
Bundle params = new Bundle();
|
||||
params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE,
|
||||
QQShare.SHARE_TO_QQ_TYPE_IMAGE);
|
||||
params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, context.getExternalCacheDir().getPath() + "/ShareImg/" + picName);
|
||||
params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "光环助手");
|
||||
params.putInt(QQShare.SHARE_TO_QQ_EXT_INT,
|
||||
QQShare.SHARE_TO_QQ_FLAG_QZONE_AUTO_OPEN);
|
||||
mTencent.shareToQQ(
|
||||
(Activity) context, params,QqShareListener);
|
||||
if (popupWindow == null) return;
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
|
||||
//微信好友分享
|
||||
private void wechatSahre(){
|
||||
Utils.toast(context,"分享跳转中...");
|
||||
|
||||
//官方分享
|
||||
// WXImageObject imgObj = new WXImageObject();
|
||||
// imgObj.setImagePath(context.getExternalCacheDir().getPath() + "/ShareImg/" + picName);
|
||||
// WXMediaMessage msg = new WXMediaMessage();
|
||||
// msg.mediaObject = imgObj;
|
||||
//
|
||||
// SendMessageToWX.Req req = new SendMessageToWX.Req();
|
||||
// req.transaction = buildTransaction("img");
|
||||
// req.message = msg;
|
||||
// req.scene = SendMessageToWX.Req.WXSceneSession;
|
||||
//
|
||||
// Bitmap compressBp = compressBitmap(shareBm);
|
||||
// msg.thumbData = Util.bmpToByteArray(compressBp, true);
|
||||
// api.sendReq(req);
|
||||
|
||||
//调用手机系统分享
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setType("image/*");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + context.getExternalCacheDir().getPath() + "/ShareImg/" + picName));
|
||||
intent.setComponent(new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI"));
|
||||
context.startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
Utils.toast(context,"分享失败!请检查是否已安装微信");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (popupWindow == null) return;
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
|
||||
//微信朋友圈分享
|
||||
private void wechatMomentsSahre(){
|
||||
Utils.toast(context,"分享跳转中...");
|
||||
|
||||
WXImageObject imgObj = new WXImageObject();
|
||||
imgObj.setImagePath(context.getExternalCacheDir().getPath() + "/ShareImg/" + picName);
|
||||
WXMediaMessage msg = new WXMediaMessage();
|
||||
msg.mediaObject = imgObj;
|
||||
|
||||
SendMessageToWX.Req req = new SendMessageToWX.Req();
|
||||
|
||||
req.transaction = buildTransaction("img");
|
||||
req.message = msg;
|
||||
req.scene = SendMessageToWX.Req.WXSceneTimeline;
|
||||
|
||||
Bitmap compressBp = compressBitmap(shareBm);
|
||||
msg.thumbData = Util.bmpToByteArray(compressBp, true);
|
||||
api.sendReq(req);
|
||||
|
||||
if (popupWindow == null) return;
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String buildTransaction(final String type) {
|
||||
return (type == null) ? String.valueOf(System.currentTimeMillis()) : type + System.currentTimeMillis();
|
||||
}
|
||||
|
||||
//压缩图片
|
||||
private Bitmap compressBitmap(Bitmap bitmap) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, bos);
|
||||
float zoom = (float) Math.sqrt(10 * 1024 / (float) bos.toByteArray().length);
|
||||
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.setScale(zoom, zoom);
|
||||
|
||||
Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
|
||||
bos.reset();
|
||||
|
||||
result.compress(Bitmap.CompressFormat.JPEG, 85, bos);
|
||||
|
||||
while(bos.toByteArray().length > 10 * 1024){
|
||||
System.out.println(bos.toByteArray().length);
|
||||
matrix.setScale(0.9f, 0.9f);
|
||||
result = Bitmap.createBitmap(result, 0, 0, result.getWidth(), result.getHeight(), matrix, true);
|
||||
bos.reset();
|
||||
result.compress(Bitmap.CompressFormat.JPEG, 85, bos);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//QQ或者QQ空间分享回调处理
|
||||
public IUiListener QqShareListener = new IUiListener() {
|
||||
@Override
|
||||
public void onComplete(Object o) {
|
||||
activity.finish();
|
||||
activity.overridePendingTransition(0, 0);//禁止退出Activity 动画
|
||||
Utils.toast(context, "分享成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(UiError uiError) {
|
||||
Utils.toast(context, "分享失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
activity.finish();
|
||||
activity.overridePendingTransition(0, 0);//禁止退出Activity 动画
|
||||
Utils.toast(context, "分享已取消");
|
||||
}
|
||||
};
|
||||
|
||||
//检查是否安装手机QQ
|
||||
public static boolean isQQClientAvailable(Context context){
|
||||
final PackageManager packageManager = context.getPackageManager();
|
||||
List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
|
||||
if (pinfo != null) {
|
||||
for (int i = 0; i < pinfo.size(); i++) {
|
||||
String pn = pinfo.get(i).packageName; if (pn.equals("com.tencent.mobileqq")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//写到存储卡中
|
||||
public void writeBitmap(String path, String name, Bitmap bitmap, boolean isToast) {
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
|
||||
File _file = new File(path , name);
|
||||
if (_file.exists()) {
|
||||
_file.delete();
|
||||
}
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(_file);
|
||||
if (name != null && !"".equals(name)) {
|
||||
int index = name.lastIndexOf(".");
|
||||
if (index != -1 && (index + 1) < name.length()) {
|
||||
String extension = name.substring(index + 1).toLowerCase();
|
||||
if ("png".equals(extension)) {
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
|
||||
} else if ("jpg".equals(extension)
|
||||
|| "jpeg".equals(extension)) {
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 75, fos);
|
||||
}
|
||||
if (isToast) {
|
||||
Utils.toast(context,"成功保存到相册");
|
||||
//刷新手机图片库
|
||||
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
|
||||
Uri uri = Uri.fromFile(_file);
|
||||
intent.setData(uri);
|
||||
context.sendBroadcast(intent);
|
||||
Utils.log("保存分享图片路径:" + _file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Utils.log("消息分享异常" + e.toString());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,21 +2,29 @@ package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.gamecenter.MessageDetailActivity;
|
||||
import com.gh.gamecenter.NewsDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.ConcernEntity;
|
||||
import com.gh.gamecenter.entity.NewsEntity;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class NewsUtils {
|
||||
|
||||
/**
|
||||
* 根据新闻类型获取标签背景资源
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public static int getDrawableIdByType(String type) {
|
||||
if ("活动".equals(type) || "高阶".equals(type)) {
|
||||
@ -32,11 +40,6 @@ public class NewsUtils {
|
||||
|
||||
/**
|
||||
* 启动新闻详情页面
|
||||
*
|
||||
* @param context
|
||||
* @param newsEntity
|
||||
* @param entrance
|
||||
* @return
|
||||
*/
|
||||
public static void startNewsActivity(Context context, NewsEntity newsEntity, String entrance) {
|
||||
Intent intent = new Intent(context, NewsDetailActivity.class);
|
||||
@ -48,16 +51,94 @@ public class NewsUtils {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动消息详情页面
|
||||
*/
|
||||
public static void startMessageActivity(Context context, ConcernEntity concernEntity, String entrance) {
|
||||
AppController.put("ConcernEntity", concernEntity);
|
||||
Intent intent = new Intent(context, MessageDetailActivity.class);
|
||||
intent.putExtra("entrance", entrance);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计阅读量
|
||||
* @param news_id
|
||||
*/
|
||||
public static void statNewsViews(String news_id) {
|
||||
String url = "http://data.ghzhushou.com/news/stat?news_id=" + news_id;
|
||||
String url = Config.DATA_HOST + "news/stat?news_id=" + news_id;
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Request.Method.POST, url, null, null);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 去除与重复sourceList相同的数据
|
||||
*/
|
||||
public static List<NewsEntity> removeDuplicateData(List<NewsEntity> sourceList, List<NewsEntity> rawList) {
|
||||
if (sourceList == null || sourceList.isEmpty()
|
||||
|| rawList == null || rawList.isEmpty()) {
|
||||
return rawList;
|
||||
}
|
||||
String id;
|
||||
for (int i = 0; i < rawList.size(); i++) {
|
||||
id = rawList.get(i).getId();
|
||||
for (NewsEntity newsEntity : sourceList) {
|
||||
if (id.equals(newsEntity.getId())) {
|
||||
rawList.remove(i);
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rawList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置新闻类型
|
||||
*/
|
||||
public static void setNewsType(TextView textView, String type) {
|
||||
textView.setText(type);
|
||||
textView.setTextColor(Color.WHITE);
|
||||
if ("活动".equals(type)) {
|
||||
textView.setBackgroundResource(R.drawable.textview_orange_style);
|
||||
} else if ("公告".equals(type)) {
|
||||
textView.setBackgroundResource(R.drawable.textview_red_style);
|
||||
} else if ("评测".equals(type)) {
|
||||
textView.setBackgroundResource(R.drawable.textview_red_style);
|
||||
} else if ("杂谈".equals(type)) {
|
||||
textView.setBackgroundResource(R.drawable.textview_orange_style);
|
||||
} else if ("专题".equals(type)) {
|
||||
textView.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
} else {
|
||||
textView.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置新闻发布时间
|
||||
*/
|
||||
public static void setNewsPublishOn(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)));
|
||||
} else if (time >= today - 86400 * 1000 && time < today) {
|
||||
format.applyPattern("HH:mm");
|
||||
textView.setText(String.format("昨天 %s", format.format(time)));
|
||||
} else {
|
||||
format.applyPattern("yyyy年MM月dd日 HH:mm");
|
||||
textView.setText(format.format(time));
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
format.applyPattern("yyyy年MM月dd日 HH:mm");
|
||||
textView.setText(format.format(time));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -73,28 +73,19 @@ public class PackageUtils {
|
||||
}
|
||||
|
||||
/*
|
||||
* 判断是否可以更新
|
||||
* 判断是否可以更新,只判断gh_version的大小
|
||||
*/
|
||||
public static boolean isCanUpdate(Context context, GameUpdateEntity gameUpdateEntity) {
|
||||
// 判断是否gh_version是否相同
|
||||
// 判断是否gh_version是否存在
|
||||
String gh_version = (String) PackageUtils.getMetaData(
|
||||
context, gameUpdateEntity.getPackageName(), "gh_version");
|
||||
if (gh_version != null) {
|
||||
gh_version = gh_version.substring(2);
|
||||
// 判断gh_version是否相同
|
||||
if (gh_version.equals(gameUpdateEntity.getGhVersion())) {
|
||||
// 判断version是否相同
|
||||
String version = PackageUtils.getVersionByPackage(
|
||||
context, gameUpdateEntity.getPackageName());
|
||||
if (version != null && version.equals(gameUpdateEntity.getVersion())) {
|
||||
// 版本相同,无需显示插件更新,继续查看是否有可更新的游戏包
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 判断gh_version的大小
|
||||
return Long.parseLong(gh_version) < Long.parseLong(gameUpdateEntity.getGhVersion());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -102,10 +93,7 @@ public class PackageUtils {
|
||||
*/
|
||||
public static boolean isSignature(Context context, String packageName) {
|
||||
String signature = getApkSignatureByPackageName(context, packageName);
|
||||
if (publicKey.equals(signature)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return publicKey.equals(signature);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -250,7 +250,11 @@ public class PlatformUtils {
|
||||
if ("".equals(platform) || "官方版".equals(platform)) {
|
||||
return "官方版";
|
||||
}
|
||||
return platformMap.get(platform);
|
||||
String platformName = platformMap.get(platform);
|
||||
if (TextUtils.isEmpty(platformName)) {
|
||||
getPlatform();
|
||||
}
|
||||
return platformName;
|
||||
}
|
||||
|
||||
boolean isUpdate = false;
|
||||
|
||||
97
app/src/main/java/com/gh/common/util/PostCommentUtils.java
Normal file
97
app/src/main/java/com/gh/common/util/PostCommentUtils.java
Normal file
@ -0,0 +1,97 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.StringExtendedRequest;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/9.
|
||||
*
|
||||
*/
|
||||
public class PostCommentUtils {
|
||||
|
||||
public static void addCommentData(Context context, String url, String content, PostCommentListener listener) {
|
||||
addCommentData(context, url, content, true, listener);
|
||||
}
|
||||
|
||||
public static void addCommentData(final Context context, final String url, final String content,
|
||||
final boolean isCheck, final PostCommentListener listener) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Request.Method.POST, url, content,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (listener != null){
|
||||
listener.postSucced(response);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
if (error.networkResponse != null && error.networkResponse.statusCode == 401) {
|
||||
addCommentData(context, url, content, false, listener);
|
||||
return;
|
||||
}
|
||||
if (listener != null){
|
||||
listener.postFailed(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
request.setShouldCache(false);
|
||||
request.addHeader("TOKEN", TokenUtils.getToken(context, isCheck));
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public static void addCommentVoto(final Context context, final String newsId, final PostCommentListener listener) {
|
||||
addCommentVoto(context, newsId, true, listener);
|
||||
}
|
||||
|
||||
public static void addCommentVoto(final Context context, final String newsId, final boolean isCheck
|
||||
, final PostCommentListener listener) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
StringExtendedRequest request = new StringExtendedRequest(
|
||||
Request.Method.POST, Config.COMMENT_HOST + "comment/" + newsId + "/vote",
|
||||
new Response.Listener<String>() {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
listener.postSucced(null);
|
||||
}
|
||||
},
|
||||
new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
if (error.networkResponse != null && error.networkResponse.statusCode == 401) {
|
||||
addCommentVoto(context, newsId, false,listener);
|
||||
} else {
|
||||
listener.postFailed(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
request.setShouldCache(false);
|
||||
request.addHeader("TOKEN", TokenUtils.getToken(context, isCheck));
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public interface PostCommentListener {
|
||||
void postSucced(JSONObject response);
|
||||
void postFailed(VolleyError error);
|
||||
}
|
||||
|
||||
}
|
||||
@ -85,8 +85,8 @@ public class RunningUtils {
|
||||
.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
List<RunningTaskInfo> infos = activityManager.getRunningTasks(100);
|
||||
for (RunningTaskInfo info : infos) {
|
||||
if (info.topActivity.getPackageName().equals(
|
||||
context.getPackageName())) {
|
||||
if (info.topActivity.getPackageName().equals(context.getPackageName())
|
||||
&& info.baseActivity.getPackageName().equals(context.getPackageName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,12 +3,14 @@ package com.gh.common.util;
|
||||
import android.app.Activity;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
@ -28,6 +30,7 @@ import com.facebook.datasource.DataSource;
|
||||
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
|
||||
import com.facebook.imagepipeline.image.CloseableImage;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.WeiBoShareActivity;
|
||||
import com.tencent.connect.share.QQShare;
|
||||
import com.tencent.connect.share.QzoneShare;
|
||||
import com.tencent.mm.sdk.openapi.IWXAPI;
|
||||
@ -42,15 +45,8 @@ import com.tencent.tauth.UiError;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import cn.sharesdk.framework.Platform;
|
||||
import cn.sharesdk.framework.PlatformActionListener;
|
||||
import cn.sharesdk.framework.ShareSDK;
|
||||
import cn.sharesdk.sina.weibo.SinaWeibo;
|
||||
import cn.sharesdk.system.text.ShortMessage;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/9/4.
|
||||
*/
|
||||
@ -346,71 +342,43 @@ public class ShareUtils {
|
||||
|
||||
//新浪微博分享
|
||||
private void sinaWeiboSahre(){
|
||||
SinaWeibo.ShareParams sinaWeiboParams = new SinaWeibo.ShareParams();
|
||||
handler = new Handler();
|
||||
Intent intent = new Intent(context, WeiBoShareActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("shareNewsTitle", shareNewsTitle);
|
||||
bundle.putString("shareIcon", shareIcon);
|
||||
bundle.putString("shareGameName", shareGameName);
|
||||
bundle.putString("shareUrl", shareUrl);
|
||||
bundle.putBoolean("isPlugin",isPlugin);
|
||||
intent.putExtras(bundle);
|
||||
context.startActivity(intent);
|
||||
|
||||
if (shareNewsTitle != null){
|
||||
sinaWeiboParams.setText(shareNewsTitle + " " + shareUrl);
|
||||
}else {
|
||||
if (isPlugin){
|
||||
sinaWeiboParams.setText("向你推荐:" + shareGameName + "(光环加速版) " + shareUrl);
|
||||
}else {
|
||||
sinaWeiboParams.setText("向你推荐:" + shareGameName + " " + shareUrl);
|
||||
}
|
||||
}
|
||||
sinaWeiboParams.setImageUrl(shareIcon);
|
||||
sharePlatform(sinaWeiboParams, SinaWeibo.NAME);
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Utils.toast(context, "分享成功");
|
||||
}
|
||||
}, 3000);
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
|
||||
//短信分享
|
||||
private void shortMessageSahre(){
|
||||
ShortMessage.ShareParams shortMessageParams = new ShortMessage.ShareParams();
|
||||
|
||||
String smsBody;
|
||||
if (shareNewsTitle != null){
|
||||
shortMessageParams.setText(shareNewsTitle + shareUrl);
|
||||
smsBody = shareNewsTitle + shareUrl;
|
||||
}else {
|
||||
if (isPlugin){
|
||||
shortMessageParams.setText("向你推荐:" + shareGameName + "(光环加速版)" + shareUrl);
|
||||
smsBody = "向你推荐:" + shareGameName + "(光环加速版)" + shareUrl;
|
||||
}else {
|
||||
shortMessageParams.setText("向你推荐:" + shareGameName + shareUrl);
|
||||
smsBody = "向你推荐:" + shareGameName + shareUrl;
|
||||
}
|
||||
}
|
||||
shortMessageParams.setUrl(shareUrl);
|
||||
shortMessageParams.setTitleUrl(shareUrl);
|
||||
|
||||
sharePlatform(shortMessageParams, ShortMessage.NAME);
|
||||
}
|
||||
Intent sendIntent = new Intent(Intent.ACTION_VIEW, Uri.parse( "smsto:" ));
|
||||
sendIntent.putExtra( "sms_body", smsBody);
|
||||
sendIntent.setType( "vnd.android-dir/mms-sms" );
|
||||
|
||||
//分享平台回调
|
||||
private void sharePlatform(Platform.ShareParams params, String name) {
|
||||
Utils.toast(context,"分享跳转中...");
|
||||
Platform platform = ShareSDK.getPlatform(name);
|
||||
if (platform.getName().equals(SinaWeibo.NAME)){
|
||||
platform.SSOSetting(true);
|
||||
try {
|
||||
context.startActivity(sendIntent);
|
||||
} catch (Exception e) {
|
||||
Utils.toast(context, "系统异常,分享失败");
|
||||
e.printStackTrace();
|
||||
}
|
||||
platform.setPlatformActionListener(new PlatformActionListener() {
|
||||
@Override
|
||||
public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
|
||||
Utils.log("分享成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Platform platform, int i, Throwable throwable) {
|
||||
Utils.log("分享失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(Platform platform, int i) {
|
||||
Utils.log("取消分享");
|
||||
}
|
||||
});
|
||||
platform.share(params);
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
|
||||
@ -428,7 +396,7 @@ public class ShareUtils {
|
||||
}
|
||||
|
||||
private void loadBitMap(final String iconUrl, final WXMediaMessage msg, final SendMessageToWX.Req req){
|
||||
ImageUtils.getInstance(context).display(iconUrl, new BaseBitmapDataSubscriber() {
|
||||
ImageUtils.getInstance().display(context, iconUrl, new BaseBitmapDataSubscriber() {
|
||||
@Override
|
||||
protected void onNewResultImpl(Bitmap bitmap) {
|
||||
Bitmap compressBp = compressBitmap(bitmap);
|
||||
@ -441,11 +409,11 @@ public class ShareUtils {
|
||||
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
|
||||
Utils.log("分享获取bitmap失败");
|
||||
}
|
||||
}, context);
|
||||
});
|
||||
}
|
||||
|
||||
//添加背景,防止图片格式为PNG的图片分享出现黑框问题
|
||||
private Bitmap addBackGround(Bitmap result) {
|
||||
public Bitmap addBackGround(Bitmap result) {
|
||||
Bitmap bgBitmap;
|
||||
int[] colors = new int[result.getWidth()*result.getHeight()];
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
|
||||
@ -39,7 +39,7 @@ public class TimestampUtils {
|
||||
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=10\\&offset=.+" + "$", 85);
|
||||
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);
|
||||
@ -49,6 +49,8 @@ public class TimestampUtils {
|
||||
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.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() {
|
||||
@ -79,6 +81,8 @@ public class TimestampUtils {
|
||||
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.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);
|
||||
|
||||
@ -9,7 +9,11 @@ import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.gamecenter.volley.extended.StringExtendedRequest;
|
||||
import com.tencent.stat.StatConfig;
|
||||
|
||||
import org.json.JSONException;
|
||||
@ -43,7 +47,7 @@ public class TokenUtils {
|
||||
}
|
||||
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
String mac = wm.getConnectionInfo().getMacAddress();
|
||||
if (!TextUtils.isEmpty(mac)) {
|
||||
if (!TextUtils.isEmpty(mac) || !":::::".equals(mac)) {
|
||||
params.put("MAC", mac);
|
||||
} else {
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
@ -66,7 +70,6 @@ public class TokenUtils {
|
||||
connection.setRequestMethod("POST");
|
||||
|
||||
connection.addRequestProperty("Content-Type", "application/json; charset=utf-8");
|
||||
connection.addRequestProperty("Device", DeviceUtils.getDeviceHeader(context));
|
||||
|
||||
connection.connect();
|
||||
|
||||
@ -103,18 +106,24 @@ public class TokenUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取用户token
|
||||
public static synchronized String getToken(Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE,
|
||||
Context.MODE_PRIVATE);
|
||||
return getToken(context, true);
|
||||
}
|
||||
|
||||
// 获取用户token
|
||||
public static synchronized String getToken(Context context, boolean isCheck) {
|
||||
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
String token = sp.getString("token", null);
|
||||
if (token != null) {
|
||||
long expire = sp.getLong("token_expire", 0) * 1000 - 10 * 1000;
|
||||
long time = System.currentTimeMillis();
|
||||
// 判断token是否过期
|
||||
if (time < expire) {
|
||||
// token未过期
|
||||
return token;
|
||||
if (isCheck) {
|
||||
if (token != null) {
|
||||
long expire = sp.getLong("token_expire", 0) * 1000 - 10 * 1000;
|
||||
long time = Utils.getTime(context);
|
||||
// 判断token是否过期
|
||||
if (time < expire) {
|
||||
// token未过期
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +140,6 @@ public class TokenUtils {
|
||||
connection.setRequestMethod("POST");
|
||||
|
||||
connection.addRequestProperty("Content-Type", "application/json; charset=utf-8");
|
||||
connection.addRequestProperty("Device", DeviceUtils.getDeviceHeader(context));
|
||||
|
||||
connection.connect();
|
||||
|
||||
@ -159,6 +167,10 @@ public class TokenUtils {
|
||||
editor.putString("token", jsonObject.getString("value"));
|
||||
editor.putLong("token_expire", jsonObject.getLong("expire"));
|
||||
editor.apply();
|
||||
if (token != null && token.equals(jsonObject.getString("value"))) {
|
||||
// 服务器返回的token和本地已存的token相同,更新本地时间
|
||||
getTime(context);
|
||||
}
|
||||
return jsonObject.getString("value");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@ -170,12 +182,36 @@ public class TokenUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取服务器时间
|
||||
public static synchronized void getTime(Context context) {
|
||||
final SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
StringExtendedRequest request = new StringExtendedRequest(
|
||||
Request.Method.GET, Config.HOST + "support/time/current",
|
||||
new Response.Listener<String>() {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
if (response.matches("^[0-9]{10}$")) {
|
||||
try {
|
||||
Editor editor = sp.edit();
|
||||
editor.putLong("server_time", Long.parseLong(response));
|
||||
editor.putLong("client_time", System.currentTimeMillis() / 1000);
|
||||
editor.apply();
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
public static synchronized void saveDeviceId(Context context, String device_id){
|
||||
saveSharedPreferences(context, device_id);
|
||||
saveDataFile(context, device_id);
|
||||
svaeSDCard(device_id, "/gh-uuid");//SDCard根目录
|
||||
svaeSDCard(device_id, "/system");//SDCard system目录
|
||||
svaeSDCard(device_id, "/data");//SDCard data目录
|
||||
svaeSDCard(device_id, "/gh-uuid");// SDCard根目录
|
||||
svaeSDCard(device_id, "/system"); // SDCard system目录
|
||||
svaeSDCard(device_id, "/data"); // SDCard data目录
|
||||
}
|
||||
|
||||
//将uuid存到sp
|
||||
|
||||
@ -276,49 +276,45 @@ public class DownloadDialog implements OnCollectionCallBackListener {
|
||||
}
|
||||
|
||||
private ArrayList<ApkEntity> sortApk(List<ApkEntity> apkList) {
|
||||
DownloadEntity downloadEntity;
|
||||
List<ApkEntity> doneList = new ArrayList<>();
|
||||
List<ApkEntity> updateList = new ArrayList<>();
|
||||
List<ApkEntity> installedList = new ArrayList<>();
|
||||
List<ApkEntity> pluginList = new ArrayList<>();
|
||||
List<ApkEntity> downloadList = new ArrayList<>();
|
||||
List<ApkEntity> noPicList = new ArrayList<>();
|
||||
List<ApkEntity> pluginDoneList = new ArrayList<>(); // 安装插件
|
||||
List<ApkEntity> pluginDownloadList = new ArrayList<>(); // 插件化下载中
|
||||
List<ApkEntity> pluginList = new ArrayList<>(); // 插件化
|
||||
List<ApkEntity> updateDoneList = new ArrayList<>(); // 安装更新
|
||||
List<ApkEntity> updateDownloadList = new ArrayList<>(); // 更新下载中
|
||||
List<ApkEntity> updateList = new ArrayList<>(); // 更新
|
||||
List<ApkEntity> doneList = new ArrayList<>(); // 安装
|
||||
List<ApkEntity> downloadList = new ArrayList<>(); // 下载中
|
||||
List<ApkEntity> installList = new ArrayList<>(); // 启动
|
||||
List<ApkEntity> noPicList = new ArrayList<>(); // 默认(无图片)
|
||||
|
||||
DownloadEntity downloadEntity;
|
||||
String packageName;
|
||||
Object gh_id;
|
||||
for (int i = 0, size = apkList.size(); i < size; i++) {
|
||||
String packageName = apkList.get(i).getPackageName();
|
||||
Object gh_id = PackageUtils.getMetaData(context, packageName, "gh_id");
|
||||
if (PackageManager.isInstalled(packageName)
|
||||
&& (gh_id == null || gh_id.equals(gameEntity.getId()))) {
|
||||
if (PackageManager.isCanUpdate(gameEntity.getId(), packageName)) {
|
||||
updateList.add(apkList.remove(i));
|
||||
size--;
|
||||
i--;
|
||||
} else if (!PackageUtils.isSignature(context, packageName)) {
|
||||
pluginList.add(apkList.remove(i));
|
||||
size--;
|
||||
i--;
|
||||
} else {
|
||||
installedList.add(apkList.remove(i));
|
||||
size--;
|
||||
i--;
|
||||
}
|
||||
} else {
|
||||
downloadEntity = DownloadManager.getInstance(context).get(apkList.get(i).getUrl());
|
||||
if (downloadEntity != null) {
|
||||
if (downloadEntity.getStatus().equals(DownloadStatus.done)) {
|
||||
doneList.add(apkList.remove(i));
|
||||
downloadEntity = DownloadManager.getInstance(context).get(apkList.get(i).getUrl());
|
||||
packageName = apkList.get(i).getPackageName();
|
||||
gh_id = PackageUtils.getMetaData(context, packageName, "gh_id");
|
||||
if (downloadEntity == null) {
|
||||
if (PackageManager.isInstalled(packageName)
|
||||
&& (gh_id == null || gh_id.equals(gameEntity.getId()))) {
|
||||
if (PackageManager.isCanUpdate(gameEntity.getId(), packageName)) {
|
||||
updateList.add(apkList.remove(i));
|
||||
size--;
|
||||
i--;
|
||||
} else if (!PackageUtils.isSignature(context, packageName)) {
|
||||
pluginList.add(apkList.remove(i));
|
||||
size--;
|
||||
i--;
|
||||
} else {
|
||||
downloadList.add(apkList.remove(i));
|
||||
installList.add(apkList.remove(i));
|
||||
size--;
|
||||
i--;
|
||||
}
|
||||
size--;
|
||||
i--;
|
||||
} else {
|
||||
String platform = apkList.get(i).getPlatform();
|
||||
int id = PlatformUtils.getInstance(context).getPlatformPic(
|
||||
platform);
|
||||
int id = PlatformUtils.getInstance(context).getPlatformPic(platform);
|
||||
if (id == 0) {
|
||||
String path = PlatformUtils.getInstance(context)
|
||||
.getPlatformPicPath(platform);
|
||||
String path = PlatformUtils.getInstance(context).getPlatformPicPath(platform);
|
||||
if (path == null) {
|
||||
noPicList.add(apkList.remove(i));
|
||||
size--;
|
||||
@ -326,14 +322,48 @@ public class DownloadDialog implements OnCollectionCallBackListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (downloadEntity.getStatus().equals(DownloadStatus.done)) {
|
||||
if (downloadEntity.isPluggable()) {
|
||||
pluginDoneList.add(apkList.remove(i));
|
||||
size--;
|
||||
i--;
|
||||
} else if (downloadEntity.isUpdate()) {
|
||||
updateDoneList.add(apkList.remove(i));
|
||||
size--;
|
||||
i--;
|
||||
} else {
|
||||
doneList.add(apkList.remove(i));
|
||||
size--;
|
||||
i--;
|
||||
}
|
||||
} else {
|
||||
if (downloadEntity.isPluggable()) {
|
||||
pluginDownloadList.add(apkList.remove(i));
|
||||
size--;
|
||||
i--;
|
||||
} else if (downloadEntity.isUpdate()) {
|
||||
updateDownloadList.add(apkList.remove(i));
|
||||
size--;
|
||||
i--;
|
||||
} else {
|
||||
downloadList.add(apkList.remove(i));
|
||||
size--;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ArrayList<ApkEntity> list = new ArrayList<>();
|
||||
list.addAll(doneList);
|
||||
list.addAll(updateList);
|
||||
list.addAll(installedList);
|
||||
list.addAll(pluginDoneList);
|
||||
list.addAll(pluginDownloadList);
|
||||
list.addAll(pluginList);
|
||||
list.addAll(updateDoneList);
|
||||
list.addAll(updateDownloadList);
|
||||
list.addAll(updateList);
|
||||
list.addAll(doneList);
|
||||
list.addAll(downloadList);
|
||||
list.addAll(installList);
|
||||
list.addAll(apkList);
|
||||
list.addAll(noPicList);
|
||||
return list;
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
public class KeyboardLayout extends RelativeLayout {
|
||||
|
||||
private OnKeyboardChangedListener mListener;
|
||||
|
||||
public KeyboardLayout(Context context) {
|
||||
super(context);
|
||||
|
||||
}
|
||||
|
||||
public KeyboardLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
if (mListener != null) {
|
||||
mListener.OnKeyboardChanged(w, h, oldw, oldh);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnKeyboardChangedListener {
|
||||
void OnKeyboardChanged(int w, int h, int oldw, int oldh);
|
||||
}
|
||||
|
||||
public void setOnKeyboardChangedListener(OnKeyboardChangedListener listener) {
|
||||
this.mListener = listener;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
/**
|
||||
* 重写RecyclerView 解决触摸事件
|
||||
*
|
||||
* @author 黄壮华
|
||||
*
|
||||
*/
|
||||
public class MyRecyclerView extends RecyclerView {
|
||||
|
||||
public static boolean isCanMove = false;
|
||||
|
||||
public MyRecyclerView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
}
|
||||
|
||||
private float xDis;
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
|
||||
switch (ev.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
xDis = ev.getX();
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (isCanMove) {
|
||||
if (xDis - ev.getX() > 0) {
|
||||
MyViewPager.isCanMove = true;
|
||||
return false;
|
||||
} else if (xDis - ev.getX() < 0) {
|
||||
isCanMove = false;
|
||||
}
|
||||
}
|
||||
xDis = ev.getX();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
/**
|
||||
* 重写ViewPager 解决触摸事件
|
||||
*
|
||||
* @author 黄壮华
|
||||
*
|
||||
*/
|
||||
public class MyViewPager extends ViewPager {
|
||||
|
||||
public static boolean isCanMove = false;
|
||||
|
||||
public MyViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
|
||||
switch (ev.getAction()) {
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (isCanMove) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
|
||||
switch (ev.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
isCanMove = false;
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (isCanMove) {
|
||||
return onTouchEvent(ev);
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (isCanMove) {
|
||||
return onTouchEvent(ev);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
}
|
||||
@ -10,7 +10,6 @@ import android.widget.Toast;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.MD5Utils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
|
||||
@ -14,7 +14,6 @@ import com.gh.common.util.NotificationUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
@ -123,6 +123,9 @@ public class DownloadTask implements DownloadListener {
|
||||
|| status == DownloadStatus.notfound) {
|
||||
entry.setProgress(0);
|
||||
entry.setPercent(0);
|
||||
if (status == DownloadStatus.hijack) {
|
||||
entry.setError(error);
|
||||
}
|
||||
FileUtils.deleteFile(entry.getPath());
|
||||
DownloadDao.getInstance(context).delete(entry.getUrl());
|
||||
Utils.log(DownloadTask.class.getSimpleName(),
|
||||
|
||||
@ -86,7 +86,7 @@ public class DownloadThread extends Thread {
|
||||
//链接被劫持,抛出异常
|
||||
Utils.log("eTag = " + eTag);
|
||||
Utils.log("eTag2 = " + eTag2);
|
||||
listener.onStatusChanged(DownloadStatus.hijack);
|
||||
listener.onStatusChanged(DownloadStatus.hijack, connection.getURL().toString());
|
||||
Utils.log(DownloadThread.class.getSimpleName(), "error-->链接被劫持");
|
||||
return;
|
||||
}
|
||||
@ -126,6 +126,15 @@ public class DownloadThread extends Thread {
|
||||
"flush==>" + targetFile.length() + ",progress==>"
|
||||
+ entry.getProgress() + ",size==>" + entry.getSize());
|
||||
|
||||
if (entry.getPath().contains("/data/data/com.gh.gamecenter")) {
|
||||
// 存储在/data/data/包名目录下,添加apk的权限,避免权限导致的解析出错
|
||||
try {
|
||||
Runtime.getRuntime().exec("chmod 755 " + entry.getPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (targetFile.length() == entry.getSize()) {
|
||||
listener.onStatusChanged(DownloadStatus.done);
|
||||
}
|
||||
|
||||
@ -8,7 +8,6 @@ import android.view.View.OnClickListener;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.ConcernUtils;
|
||||
@ -28,8 +27,6 @@ import java.util.List;
|
||||
|
||||
public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
|
||||
public static final String TAG = ConcernActivity.class.getSimpleName();
|
||||
|
||||
private Concern_LinearLayout view;
|
||||
private RecyclerView concern_rv_show, concern_rv_recommend;
|
||||
private ConcernAdapter concernAdapter;
|
||||
@ -210,7 +207,6 @@ public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
String uuid = TokenUtils.getDeviceId(this);
|
||||
JSONArray data = new JSONArray();
|
||||
for (ConcernInfo concernInfo : concernManager.getConcernGame()) {
|
||||
|
||||
@ -78,26 +78,34 @@ public class CropImageActivity extends BaseActivity {
|
||||
// 上传图片
|
||||
JSONObject result = FileUtils.uploadFile(Config.USER_HOST + "icon",
|
||||
path, TokenUtils.getToken(CropImageActivity.this));
|
||||
dialog.dismiss();
|
||||
if (result != null) {
|
||||
try {
|
||||
int statusCode = result.getInt("statusCode");
|
||||
if (statusCode == HttpURLConnection.HTTP_OK) {
|
||||
Intent data = new Intent();
|
||||
data.putExtra("url", result.getString("icon"));
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
handler.sendEmptyMessage(0);
|
||||
} else if (statusCode == HttpURLConnection.HTTP_FORBIDDEN
|
||||
&& "too frequent".equals(result.getString("detail"))) {
|
||||
handler.sendEmptyMessage(2);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
if (result != null && result.getInt("statusCode") == 401) {
|
||||
result = FileUtils.uploadFile(Config.USER_HOST + "icon",
|
||||
path, TokenUtils.getToken(CropImageActivity.this, false));
|
||||
}
|
||||
} else {
|
||||
handler.sendEmptyMessage(1);
|
||||
if (result != null) {
|
||||
try {
|
||||
int statusCode = result.getInt("statusCode");
|
||||
if (statusCode == HttpURLConnection.HTTP_OK) {
|
||||
Intent data = new Intent();
|
||||
data.putExtra("url", result.getString("icon"));
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
handler.sendEmptyMessage(0);
|
||||
} else if (statusCode == HttpURLConnection.HTTP_FORBIDDEN
|
||||
&& "too frequent".equals(result.getString("detail"))) {
|
||||
handler.sendEmptyMessage(2);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
handler.sendEmptyMessage(1);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
dialog.dismiss();
|
||||
} else {
|
||||
dialog.dismiss();
|
||||
handler.sendEmptyMessage(1);
|
||||
|
||||
@ -3,8 +3,6 @@ package com.gh.gamecenter;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.util.DisplayMetrics;
|
||||
@ -16,6 +14,7 @@ import android.widget.TextView;
|
||||
import com.gh.base.BaseFragmentActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.FragmentAdapter;
|
||||
import com.gh.gamecenter.download.GameDownLoadFragment;
|
||||
import com.gh.gamecenter.download.GameUpdateFragment;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadChanged;
|
||||
@ -24,6 +23,9 @@ import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
@ -81,7 +83,12 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
downloadmanager_download_number.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
int currentItem = getIntent().getIntExtra("currentItem", -1);
|
||||
int currentItem;
|
||||
if (savedInstanceState != null) {
|
||||
currentItem = savedInstanceState.getInt("CurrentItem");
|
||||
} else {
|
||||
currentItem = getIntent().getIntExtra("currentItem", -1);
|
||||
}
|
||||
if (currentItem == -1) {
|
||||
if (updateSize != 0 && downloadSize == 0) {
|
||||
currentItem = 1;
|
||||
@ -94,101 +101,52 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
width = outMetrics.widthPixels / 2;
|
||||
lparams = new LinearLayout.LayoutParams(width / 2, DisplayUtils.dip2px(getApplicationContext(), 2));
|
||||
lparams.leftMargin = outMetrics.widthPixels / 8;
|
||||
if (currentItem != 0) {
|
||||
downloadmanager_ll_download.setClickable(true);
|
||||
downloadmanager_ll_update.setClickable(false);
|
||||
lparams.leftMargin = width + width / 4;
|
||||
} else {
|
||||
downloadmanager_ll_download.setClickable(false);
|
||||
downloadmanager_ll_update.setClickable(true);
|
||||
}
|
||||
lparams.leftMargin = (int) (width * (currentItem + 0.25f));
|
||||
downloadmanager_slide_line.setLayoutParams(lparams);
|
||||
|
||||
downloadmanager_viewPager.setAdapter(new FragmentAdapter(
|
||||
getSupportFragmentManager()));
|
||||
List<Fragment> list = new ArrayList<>();
|
||||
list.add(new GameDownLoadFragment());
|
||||
list.add(new GameUpdateFragment());
|
||||
downloadmanager_viewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager(), list));
|
||||
downloadmanager_viewPager.addOnPageChangeListener(this);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
lparams.leftMargin = width * savedInstanceState.getInt("CurrentItem") + width / 4;
|
||||
downloadmanager_slide_line.setLayoutParams(lparams);
|
||||
} else {
|
||||
downloadmanager_viewPager.setCurrentItem(currentItem);
|
||||
}
|
||||
}
|
||||
|
||||
private class FragmentAdapter extends FragmentPagerAdapter {
|
||||
|
||||
public FragmentAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
if (position == 0) {
|
||||
return new GameDownLoadFragment();
|
||||
} else {
|
||||
return new GameUpdateFragment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
downloadmanager_viewPager.setCurrentItem(currentItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
|
||||
if (position == 0) {
|
||||
EventBus.getDefault().post(
|
||||
new EBUISwitch("DownloadManagerActivity", 0));
|
||||
downloadmanager_ll_download.setClickable(false);
|
||||
downloadmanager_ll_update.setClickable(true);
|
||||
EventBus.getDefault().post(new EBUISwitch("DownloadManagerActivity", 0));
|
||||
downloadmanager_tv_download.setTextColor(getResources().getColor(R.color.theme));
|
||||
downloadmanager_tv_update.setTextColor(getResources().getColor(R.color.title));
|
||||
} else {
|
||||
EventBus.getDefault().post(
|
||||
new EBUISwitch("DownloadManagerActivity", 1));
|
||||
downloadmanager_ll_download.setClickable(true);
|
||||
downloadmanager_ll_update.setClickable(false);
|
||||
EventBus.getDefault().post(new EBUISwitch("DownloadManagerActivity", 1));
|
||||
downloadmanager_tv_download.setTextColor(getResources().getColor(R.color.title));
|
||||
downloadmanager_tv_update.setTextColor(getResources().getColor(R.color.theme));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset,
|
||||
int positionOffsetPixels) {
|
||||
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
if (positionOffset != 0) {
|
||||
lparams.leftMargin = (int) (width * positionOffset) + width / 4;
|
||||
lparams.leftMargin = (int) (width * (positionOffset + 0.25f));
|
||||
downloadmanager_slide_line.setLayoutParams(lparams);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.actionbar_rl_back:
|
||||
final int id = view.getId();
|
||||
if (id == R.id.actionbar_rl_back) {
|
||||
finish();
|
||||
break;
|
||||
case R.id.downloadmanager_ll_download:
|
||||
} else if (id == R.id.downloadmanager_ll_download) {
|
||||
downloadmanager_viewPager.setCurrentItem(0);
|
||||
break;
|
||||
case R.id.downloadmanager_ll_update:
|
||||
} else if (id == R.id.downloadmanager_ll_update) {
|
||||
downloadmanager_viewPager.setCurrentItem(1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,8 +168,7 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
downloadmanager_download_number.setText(String.valueOf(changed.getSize()));
|
||||
} else if ("update".equals(changed.getType())) {
|
||||
if (changed.getSize() == -1) {
|
||||
int number = Integer.valueOf(downloadmanager_update_number
|
||||
.getText().toString());
|
||||
int number = Integer.valueOf(downloadmanager_update_number.getText().toString());
|
||||
if (number == 1) {
|
||||
downloadmanager_update_number.setVisibility(View.GONE);
|
||||
} else {
|
||||
|
||||
@ -3,14 +3,18 @@ package com.gh.gamecenter;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.DetailActivity;
|
||||
import com.gh.base.BaseDetailActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.gamecenter.changeskin.ChangeSkinUtils;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.gamedetail.GameDetailAdapter;
|
||||
@ -26,9 +30,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Created by khy on 2016/8/12.
|
||||
*/
|
||||
public class GameDetailActivity extends DetailActivity implements View.OnClickListener{
|
||||
|
||||
public static final String TAG = GameDetailActivity.class.getSimpleName();
|
||||
public class GameDetailActivity extends BaseDetailActivity implements View.OnClickListener{
|
||||
|
||||
private GameDetailAdapter adapter;
|
||||
|
||||
@ -38,6 +40,8 @@ public class GameDetailActivity extends DetailActivity implements View.OnClickLi
|
||||
|
||||
private boolean isSentReport;
|
||||
|
||||
private RelativeLayout actionbar_rl_back;
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
@ -70,6 +74,7 @@ public class GameDetailActivity extends DetailActivity implements View.OnClickLi
|
||||
detail_tv_download.setOnClickListener(this);
|
||||
detail_tv_per.setOnClickListener(this);
|
||||
reuse_no_connection.setOnClickListener(this);
|
||||
actionbar_rl_back.setOnClickListener(this);
|
||||
|
||||
if (gameEntity != null) {
|
||||
adapter.setGameEntity(gameEntity);
|
||||
@ -91,7 +96,7 @@ public class GameDetailActivity extends DetailActivity implements View.OnClickLi
|
||||
iv_share.setVisibility(View.VISIBLE);
|
||||
}
|
||||
downloadAddWord = adapter.getGameDetailEntity().getDownloadAddWord();
|
||||
downloadOffText = gameEntity.getDownloadOffText();
|
||||
downloadOffText = adapter.getGameDetailEntity().getDownloadOffText();
|
||||
initDownload(true);
|
||||
}
|
||||
|
||||
@ -133,6 +138,20 @@ public class GameDetailActivity extends DetailActivity implements View.OnClickLi
|
||||
|
||||
String url = "http://www.ghzhushou.com/game/" + adapter.getGameDetailEntity().getShareCode();
|
||||
showShare(url, gameEntity.getName(), gameEntity.getIcon(), null, gameEntity.getTag(), entrance, "游戏");
|
||||
} else if (v == actionbar_rl_back) {
|
||||
if (ChangeSkinUtils.isChecking) {
|
||||
DialogUtils.showWarningDialog(GameDetailActivity.this, "退出提示",
|
||||
"素材更新还在检测中,如果强行退出会中断所有进度,确定退出?",
|
||||
"取消", "强行退出", new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
finish();
|
||||
}
|
||||
}, null);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,7 +179,7 @@ public class GameDetailActivity extends DetailActivity implements View.OnClickLi
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
// 关注事件
|
||||
@ -209,9 +228,19 @@ public class GameDetailActivity extends DetailActivity implements View.OnClickLi
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
}
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 && ChangeSkinUtils.isChecking) {
|
||||
DialogUtils.showWarningDialog(GameDetailActivity.this, "退出提示",
|
||||
"素材更新还在检测中,如果强行退出会中断所有进度,确定退出?",
|
||||
"取消", "强行退出", new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
finish();
|
||||
}
|
||||
}, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,6 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.gamecenter.adapter.GameNewsAdapter;
|
||||
@ -25,8 +24,6 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class GameNewsActivity extends BaseActivity implements View.OnClickListener{
|
||||
|
||||
public static final String TAG = GameNewsActivity.class.getSimpleName();
|
||||
|
||||
private GameNewsAdapter adapter;
|
||||
private GameNewsTypeListAdapter typeListAdapter;
|
||||
|
||||
@ -148,12 +145,6 @@ public class GameNewsActivity extends BaseActivity implements View.OnClickListen
|
||||
typeListAdapter.setNewsType(change.getType(), change.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == ivSearch){
|
||||
|
||||
@ -28,6 +28,7 @@ import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Request.Method;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
@ -63,7 +64,6 @@ import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBShowDialog;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.eventbus.EBTopStatus;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.game.GameFragment;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
@ -108,10 +108,6 @@ import de.greenrobot.event.EventBus;
|
||||
*/
|
||||
public class MainActivity extends BaseFragmentActivity implements OnClickListener {
|
||||
|
||||
public static final String TAG = MainActivity.class.getSimpleName();
|
||||
|
||||
public static String searchHint;
|
||||
|
||||
private GameFragment gameFragment;
|
||||
private NewsFragment newsFragment;
|
||||
private PersonalFragment personalFragment;
|
||||
@ -129,10 +125,13 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
private SharedPreferences sp;
|
||||
private ConcernManager concernManager;
|
||||
|
||||
private String searchHint;
|
||||
|
||||
private int currentTab;
|
||||
|
||||
private boolean isShowDownload = false;
|
||||
private boolean isNewFirstLaunch;
|
||||
private boolean isSkipped;
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
@ -216,7 +215,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
JSONObject jsonObject = new JSONObject(params);
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(Method.POST,
|
||||
Config.HOST + "stat/download", jsonObject.toString(), null, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
// 统计下载完成事件
|
||||
@ -265,6 +264,48 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
map.put("installed", downloadEntity.getInstalled());
|
||||
map.put("network", NetworkUtils.getConnectedType(MainActivity.this));
|
||||
DataCollectionManager.onEvent(MainActivity.this, "download", map);
|
||||
|
||||
if (downloadEntity.getEntrance().matches("^" + "\\(游戏\\-插件:滚动图\\[.+\\]\\)" + "$")) {
|
||||
// 首页轮播图数据统计
|
||||
statLunbotuData(downloadEntity.getEntrance());
|
||||
}
|
||||
}
|
||||
|
||||
// 首页轮播图数据统计
|
||||
private void statLunbotuData(String entrance) {
|
||||
int start = entrance.indexOf("[");
|
||||
int end = entrance.indexOf("]");
|
||||
if (start != -1 && end != -1) {
|
||||
entrance = entrance.substring(start + 1, end);
|
||||
String[] values = entrance.split("=");
|
||||
if (values.length == 3) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("location", values[2]);
|
||||
map.put("type", values[1]);
|
||||
map.put("title", values[0]);
|
||||
map.put("form", "download");
|
||||
|
||||
String version = PackageUtils.getVersion(this);
|
||||
String user = DeviceUtils.getDeviceID(this);
|
||||
String channel = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID");
|
||||
map.put("version", version);
|
||||
map.put("user", user);
|
||||
map.put("device_id", TokenUtils.getDeviceId(this));
|
||||
map.put("channel", channel);
|
||||
String url = Config.DATA_HOST + "api/v1d0/log";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("topic", "lunbotu");
|
||||
params.put("source", "GH-ASSIST-Client");
|
||||
params.put("time", String.valueOf(Utils.getTime(this)));
|
||||
params.put("content", new JSONObject(map).toString());
|
||||
StringExtendedRequest request = new StringExtendedRequest(Request.Method.POST, url, null, null);
|
||||
request.setParams(params);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processHijack(DownloadEntity downloadEntity) {
|
||||
@ -279,6 +320,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
map.put("game", downloadEntity.getName());
|
||||
map.put("game_id", downloadEntity.getGameId());
|
||||
map.put("platform", downloadEntity.getPlatform());
|
||||
map.put("hijack_url", downloadEntity.getError());
|
||||
DataCollectionManager.onEvent(MainActivity.this, "hijack", map);
|
||||
// 上传劫持log
|
||||
uploadHijackLog(new HashMap<>(map));
|
||||
@ -293,7 +335,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
map.put("user", user);
|
||||
map.put("device_id", TokenUtils.getDeviceId(this));
|
||||
map.put("channel", channel);
|
||||
String url = "http://data.ghzhushou.com/api/v1d0/log";
|
||||
String url = Config.DATA_HOST + "api/v1d0/log";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("topic", "hijack");
|
||||
params.put("source", "GH-ASSIST-Client");
|
||||
@ -302,7 +344,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
StringExtendedRequest request = new StringExtendedRequest(Method.POST, url, null, null);
|
||||
request.setParams(params);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
// 上传网络错误log
|
||||
@ -321,7 +363,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
map.put("device_id", TokenUtils.getDeviceId(this));
|
||||
map.put("channel", channel);
|
||||
map.put("error", downloadEntity.getError());
|
||||
String url = "http://data.ghzhushou.com/api/v1d0/log";
|
||||
String url = Config.DATA_HOST + "api/v1d0/log";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("topic", "neterror");
|
||||
params.put("source", "GH-ASSIST-Client");
|
||||
@ -330,7 +372,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
StringExtendedRequest request = new StringExtendedRequest(Method.POST, url, null, null);
|
||||
request.setParams(params);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -401,6 +443,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("currentTab", currentTab);
|
||||
outState.putBoolean("isSkipped", isSkipped);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -417,28 +460,33 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
setContentView(contentView);
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersion(getApplicationContext()), true);
|
||||
|
||||
isSkipped = false;
|
||||
|
||||
initViews();
|
||||
if (savedInstanceState != null) {
|
||||
currentTab = savedInstanceState.getInt("currentTab");
|
||||
isSkipped = savedInstanceState.getBoolean("isSkipped");
|
||||
} else if (isNewFirstLaunch) {
|
||||
currentTab = 1;
|
||||
} else {
|
||||
currentTab = 0;
|
||||
}
|
||||
setTabSelection(currentTab);
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
concernManager = new ConcernManager(getApplicationContext());
|
||||
|
||||
getSearchHints();
|
||||
|
||||
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersion(getApplicationContext()), true);
|
||||
if (!isNewFirstLaunch && sp.getBoolean("autoupdate", true)) {
|
||||
// 检查助手更新
|
||||
checkUpdate();
|
||||
}
|
||||
if (isNewFirstLaunch) {
|
||||
getPluginUpdate();
|
||||
initConcern(); // 初始化关注
|
||||
sp.edit().putBoolean("isNewFirstLaunchV" + PackageUtils.getVersion(getApplicationContext()), false).apply();
|
||||
// sp.edit().putBoolean("isNewFirstLaunchV" + PackageUtils.getVersion(getApplicationContext()), false).apply();
|
||||
}
|
||||
|
||||
// 获取免责声明
|
||||
@ -450,9 +498,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
// 添加观察者
|
||||
DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
|
||||
// //检查是否存在更新的dex包
|
||||
// checkHotfix();
|
||||
|
||||
// 检查是否有权限读取应用列表
|
||||
checkPermission();
|
||||
|
||||
@ -460,8 +505,9 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
// 注册设备
|
||||
// 注册设备
|
||||
TokenUtils.register(MainActivity.this);
|
||||
initConcern(); // 初始化关注
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
@ -512,6 +558,11 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
final ArrayList<GameEntity> concernDigest = new ArrayList<>();
|
||||
|
||||
final int size = arrGameId.size();
|
||||
|
||||
if (size == 0) {
|
||||
EventBus.getDefault().post(new EBUISwitch("NewsFragment", -2)); // 没有关注
|
||||
}
|
||||
|
||||
initConcernCount = 0;
|
||||
for (String gameId : arrGameId) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
@ -541,7 +592,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
}
|
||||
@ -596,6 +647,14 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
private void getInstalledListFromServer() {
|
||||
ArrayList<String> list = PackageUtils.getAllPackageName(getApplicationContext());
|
||||
if (list.isEmpty()) {
|
||||
if (isNewFirstLaunch) { // 延迟0.3s,防止页面未注册eventbus,接收消息失败
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
EventBus.getDefault().post(new EBUISwitch("NewsFragment", -1)); //通知更新推荐关注小版块
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -636,7 +695,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
}
|
||||
|
||||
@ -684,13 +743,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
concernInfo.setPackageNames(packageNames);
|
||||
concernManager.updateByConcern(concernInfo);
|
||||
}
|
||||
//无需默认关注
|
||||
// if (isNewFirstLaunch) {
|
||||
// //默认安装即为关注
|
||||
// if (!concernManager.isConcern(gameEntity.getId())) {
|
||||
// concernManager.addByEntity(gameEntity);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
addConcernCount();
|
||||
if (cCount == size) {
|
||||
@ -706,7 +758,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -715,6 +767,9 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
* 更新关注列表数据
|
||||
*/
|
||||
private void update() {
|
||||
if (isNewFirstLaunch) {
|
||||
EventBus.getDefault().post(new EBUISwitch("NewsFragment", -1)); //通知更新推荐关注小版块
|
||||
}
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
@ -838,7 +893,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
private int count;
|
||||
@ -879,7 +934,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
}
|
||||
|
||||
@ -947,53 +1002,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
|
||||
private void checkHotfix() {
|
||||
String version = PackageUtils.getVersion(getApplicationContext());
|
||||
String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID");
|
||||
String url = "http://api.ghzhushou.com/v1d45/hotfix?channel=" + TD_CHANNEL_ID + "&version=" + version;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(url,
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
Utils.log("hotfix = " + response.toString());
|
||||
try {
|
||||
for (int i = 0; i < response.length(); i++) {
|
||||
JSONObject jsonObject = response.getJSONObject(i);
|
||||
String clazz = jsonObject.getString("class");
|
||||
final String url = jsonObject.getString("url");
|
||||
String fileName = url.substring(url.lastIndexOf("/"));
|
||||
File directory = new File(getFilesDir().getAbsolutePath() + File.separator + "hotfix");
|
||||
if (!directory.exists() || !directory.isDirectory()) {
|
||||
directory.mkdirs();
|
||||
}
|
||||
File file = new File(directory.getAbsolutePath() + File.separator + fileName);
|
||||
if (file.exists()) {
|
||||
break;
|
||||
}
|
||||
//下载文件
|
||||
final String savePath = file.getAbsolutePath();
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
FileUtils.downloadFile(url, savePath);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Utils.log(savePath + " download success");
|
||||
}
|
||||
}.start();
|
||||
//存储class
|
||||
sp.edit().putString(file.getName(),clazz).apply();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
// 获取免责声明
|
||||
private void getDisclaimer(final boolean isFirst) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
@ -1018,7 +1026,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
private Class<?> intentClass(String to) {
|
||||
@ -1038,7 +1046,9 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (getIntent() != null && getIntent().getExtras() != null) {
|
||||
if (getIntent() != null && getIntent().getExtras() != null
|
||||
&& !isSkipped) {
|
||||
isSkipped = true;
|
||||
String to = getIntent().getExtras().getString("to");
|
||||
if(!TextUtils.isEmpty(to)){
|
||||
Class<?> clazz = intentClass(to);
|
||||
@ -1046,7 +1056,11 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
Intent toIntent = new Intent(MainActivity.this, clazz);
|
||||
if ("NewsActivity".equals(to) || "NewsDetailActivity".equals(to)) {
|
||||
toIntent.putExtra("newsId", getIntent().getExtras().getString("newsId"));
|
||||
toIntent.putExtra("entrance", "(插件跳转)");
|
||||
String entrance = getIntent().getExtras().getString("entrance");
|
||||
if (TextUtils.isEmpty(entrance) || !entrance.startsWith("(") || !entrance.endsWith(")")) {
|
||||
entrance = "(插件跳转)";
|
||||
}
|
||||
toIntent.putExtra("entrance", entrance);
|
||||
} else if("DownloadManagerActivity".equals(to)) {
|
||||
String packageName = getIntent().getExtras().getString("packageName");
|
||||
if (packageName != null) {
|
||||
@ -1055,7 +1069,11 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
} else if ("GameDetailsActivity".equals(to) || "GameDetailActivity".equals(to)) {
|
||||
toIntent.putExtra("gameId", getIntent().getExtras().getString("gameId"));
|
||||
toIntent.putExtra("entrance", "(插件跳转)");
|
||||
String entrance = getIntent().getExtras().getString("entrance");
|
||||
if (TextUtils.isEmpty(entrance) || !entrance.startsWith("(") || !entrance.endsWith(")")) {
|
||||
entrance = "(插件跳转)";
|
||||
}
|
||||
toIntent.putExtra("entrance", entrance);
|
||||
} else if ("SubjectActivity".equals(to)) {
|
||||
toIntent.putExtra("id", getIntent().getExtras().getString("id"));
|
||||
toIntent.putExtra("name", getIntent().getExtras().getString("name"));
|
||||
@ -1064,6 +1082,11 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
toIntent.putExtra("urls" , getIntent().getExtras().getStringArrayList("urls"));
|
||||
toIntent.putExtra("current" , getIntent().getExtras().getInt("current",0));
|
||||
toIntent.putExtra("ScaleType" , getIntent().getExtras().getString("ScaleType"));
|
||||
} else if ("SubjectActivity".equals(to)) {
|
||||
toIntent.putExtra("id", getIntent().getExtras().getString("id"));
|
||||
toIntent.putExtra("name", getIntent().getExtras().getString("name"));
|
||||
} else if ("SuggestionActivity".equals(to)) {
|
||||
toIntent.putExtra("content", getIntent().getExtras().getString("content"));
|
||||
}
|
||||
startActivity(toIntent);
|
||||
}
|
||||
@ -1117,12 +1140,17 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
} else {
|
||||
searchHint = searchHintList.get(RandomUtils.nextInt(searchHintList.size()));
|
||||
}
|
||||
EventBus.getDefault().post(new EBTopStatus("搜索", searchHintList.get(0)));
|
||||
if (gameFragment != null) {
|
||||
gameFragment.setHint(searchHint);
|
||||
}
|
||||
if (newsFragment != null) {
|
||||
newsFragment.setHint(searchHint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
private void checkUpdate() {
|
||||
@ -1160,7 +1188,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
if ("EVERY_TIME_OPEN".equals(appEntity.getAlert())) {
|
||||
// 每次都提示
|
||||
showUpdateDialog(updateMD5);
|
||||
} else {
|
||||
} else if (!"NEVER".equals(appEntity.getAlert())){
|
||||
// 一天提示一次
|
||||
String showUpdateTime = sp.getString("show_update_tiem", null);
|
||||
SimpleDateFormat format = new SimpleDateFormat(
|
||||
@ -1176,7 +1204,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
private void showUpdateDialog(final String md5) {
|
||||
@ -1236,7 +1264,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
private ProgressBar app_pb_progress;
|
||||
private TextView app_tv_speed;
|
||||
private TextView app_tv_percent;
|
||||
private TextView app_tv_cancel;
|
||||
|
||||
private void showDownloadDialog(String md5) {
|
||||
downloadDialog = new Dialog(this);
|
||||
@ -1247,8 +1274,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
app_tv_speed = (TextView) view.findViewById(R.id.app_tv_speed);
|
||||
app_tv_percent = (TextView) view.findViewById(R.id.app_tv_percent);
|
||||
|
||||
app_tv_cancel = (TextView) view.findViewById(R.id.app_tv_cancel);
|
||||
app_tv_cancel.setOnClickListener(new OnClickListener() {
|
||||
view.findViewById(R.id.app_tv_cancel).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
DownloadManager.getInstance(getApplicationContext()).cancel(appEntity.getUrl());
|
||||
@ -1307,14 +1333,13 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String version = PackageUtils.getVersion(this);
|
||||
String user = DeviceUtils.getDeviceID(this);
|
||||
String channel = (String) PackageUtils.getMetaData(this,
|
||||
getPackageName(), "TD_CHANNEL_ID");
|
||||
String channel = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID");
|
||||
map.put("step", step);
|
||||
map.put("version", version);
|
||||
map.put("user", user);
|
||||
map.put("device_id", TokenUtils.getDeviceId(this));
|
||||
map.put("channel", channel);
|
||||
String url = "http://data.ghzhushou.com/api/v1d0/log";
|
||||
String url = Config.DATA_HOST + "api/v1d0/log";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("topic", "upgrade");
|
||||
params.put("source", "GH-ASSIST-Client");
|
||||
@ -1323,7 +1348,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
StringExtendedRequest request = new StringExtendedRequest(Method.POST, url, null, null);
|
||||
request.setParams(params);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
Utils.log("提交更新数据" + new JSONObject(params).toString());
|
||||
}
|
||||
|
||||
@ -1396,6 +1421,9 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
if (gameFragment == null) {
|
||||
gameFragment = new GameFragment();
|
||||
if (!TextUtils.isEmpty(searchHint)) {
|
||||
gameFragment.setHint(searchHint);
|
||||
}
|
||||
transaction.add(R.id.main_content, gameFragment);
|
||||
}
|
||||
} else {
|
||||
@ -1419,6 +1447,9 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
if (newsFragment == null) {
|
||||
newsFragment = new NewsFragment();
|
||||
if (!TextUtils.isEmpty(searchHint)) {
|
||||
newsFragment.setHint(searchHint);
|
||||
}
|
||||
transaction.add(R.id.main_content, newsFragment);
|
||||
}
|
||||
} else {
|
||||
@ -1548,7 +1579,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
if ("卸载".equals(busFour.getType()) || "安装".equals(busFour.getType())) {
|
||||
PackageManager.removeUpdate(packageName);
|
||||
}
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
if ("安装".equals(busFour.getType()) && sp.getBoolean("concerngame", true)) {//设置页面控制是否安装后自动关注
|
||||
// 安装后关注游戏
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "support/package/" + packageName + "/game/digest",
|
||||
@ -1574,7 +1605,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
@ -1613,7 +1644,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1626,7 +1657,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
DownloadManager.getInstance(this).removeObserver(dataWatcher);
|
||||
}
|
||||
}
|
||||
|
||||
494
app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java
Normal file
494
app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java
Normal file
@ -0,0 +1,494 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.android.volley.toolbox.DiskBasedCache;
|
||||
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.DialogUtils;
|
||||
import com.gh.common.util.GzipUtils;
|
||||
import com.gh.common.util.PostCommentUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.adapter.MessageDetailAdapter;
|
||||
import com.gh.gamecenter.db.CommentDao;
|
||||
import com.gh.gamecenter.db.info.CommentInfo;
|
||||
import com.gh.gamecenter.entity.CommentEntity;
|
||||
import com.gh.gamecenter.entity.ConcernEntity;
|
||||
import com.gh.gamecenter.entity.ViewsEntity;
|
||||
import com.gh.gamecenter.manager.CommentManager;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.OnTouch;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Action1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/8.
|
||||
* 消息详情界面
|
||||
*/
|
||||
public class MessageDetailActivity extends BaseActivity implements MessageDetailAdapter.OnCommentCallBackListener{
|
||||
|
||||
@BindView(R.id.message_detail_rv) RecyclerView mMessageDetailRv;
|
||||
@BindView(R.id.message_detail_user_rl) RelativeLayout mMessageDetailUserRl;
|
||||
@BindView(R.id.message_detail_comment_rl) RelativeLayout mMessageDetailCommentRl;
|
||||
@BindView(R.id.comment_user_icon) SimpleDraweeView mMessageDetailIconDv;
|
||||
@BindView(R.id.comment_user_name) TextView mMessageDetailUserNameTv;
|
||||
@BindView(R.id.comment_send) TextView mMessageDetailCommentSend;
|
||||
@BindView(R.id.message_detail_comment_et) EditText mMessageDetailEt;
|
||||
@BindView(R.id.message_detail_comment_hint_rl) RelativeLayout mMessageDetailCommentHintRl;
|
||||
@BindView(R.id.message_detail_sv) ScrollView mMessageDetailSv;
|
||||
@BindView(R.id.message_detail_hint_line) View mMessageDetailLine;
|
||||
@BindView(R.id.reuse_no_connection) LinearLayout mNoConnection;
|
||||
@BindView(R.id.message_detail_close_comment) View mColseCommentV;
|
||||
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
|
||||
private MessageDetailAdapter adapter;
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
private Dialog mSendingDialog;
|
||||
|
||||
private CommentDao mCommentDao;
|
||||
|
||||
private ConcernEntity mConcernEntity;
|
||||
|
||||
private String newsId;
|
||||
|
||||
private int commentNum = -1; //区分来源 -1:资讯关注列表 !=-1 :新闻详情
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
AppController.put("ConcernEntity", adapter.getConcernEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mConcernEntity = (ConcernEntity) AppController.get("ConcernEntity", true);
|
||||
|
||||
Intent intent = getIntent();
|
||||
newsId = intent.getExtras().getString("newsId");
|
||||
commentNum = intent.getExtras().getInt("commentNum");
|
||||
|
||||
//复用问题 mConcernEntity对应的文章有可能和跳转之前的文章不一致
|
||||
if (mConcernEntity != null && newsId != null && !newsId.equals(mConcernEntity.getId())) {
|
||||
mConcernEntity = null;
|
||||
}
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_messagedetail, null);
|
||||
init(contentView, "消息详情");
|
||||
|
||||
ButterKnife.bind(this);
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
|
||||
mCommentDao = new CommentDao(this);
|
||||
|
||||
adapter = new MessageDetailAdapter(this, mCommentDao, mMessageDetailRv, mConcernEntity);
|
||||
mLayoutManager = new LinearLayoutManager(this);
|
||||
mMessageDetailRv.setLayoutManager(mLayoutManager);
|
||||
mMessageDetailRv.setAdapter(adapter);
|
||||
|
||||
mMessageDetailEt.addTextChangedListener(watcher);
|
||||
mMessageDetailCommentSend.setEnabled(false);
|
||||
|
||||
mMessageDetailRv.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& !adapter.isOver() && !adapter.isLoading() && mConcernEntity != null
|
||||
&& mLayoutManager.findLastVisibleItemPosition() == adapter.getItemCount() - 1) {
|
||||
int offset = adapter.getItemCount() - adapter.getHotCommentListSize() - 3;
|
||||
if (offset >= 10) { // 防止自动上滑时触发
|
||||
adapter.addNormalComment(offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//检查sp是否有用户信息
|
||||
if (TextUtils.isEmpty(sp.getString("user_name", null))) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TokenUtils.getToken(MessageDetailActivity.this);
|
||||
MessageDetailActivity.this.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (sp.getString("user_icon", "res:///"+
|
||||
R.drawable.user_default_icon_comment).isEmpty()) {
|
||||
mMessageDetailIconDv.setImageURI("res:///" +
|
||||
R.drawable.user_default_icon_comment);
|
||||
} else {
|
||||
mMessageDetailIconDv.setImageURI(sp.getString("user_icon", "res:///"+
|
||||
R.drawable.user_default_icon_comment));
|
||||
}
|
||||
mMessageDetailUserNameTv.setText(sp.getString("user_name", "光环用户"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
} else {
|
||||
if (sp.getString("user_icon", "res:///"+ R.drawable.user_default_icon_comment).isEmpty()) {
|
||||
mMessageDetailIconDv.setImageURI("res:///" + R.drawable.user_default_icon_comment);
|
||||
} else {
|
||||
mMessageDetailIconDv.setImageURI(sp.getString("user_icon", "res:///"+
|
||||
R.drawable.user_default_icon_comment));
|
||||
}
|
||||
mMessageDetailUserNameTv.setText(sp.getString("user_name", "光环用户"));
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
//解决透明沉浸栏和软键盘冲突(重置ScrollView高度)
|
||||
final View decorView=getWindow().getDecorView();
|
||||
decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
Rect rect=new Rect();
|
||||
decorView.getWindowVisibleDisplayFrame(rect);
|
||||
int screenHeight = decorView.getRootView().getHeight();
|
||||
int heightDifference = screenHeight-rect.bottom;//计算软键盘占有的高度 = 屏幕高度 - 视图可见高度
|
||||
RelativeLayout.LayoutParams layoutParams= (RelativeLayout.LayoutParams) mMessageDetailSv.getLayoutParams();
|
||||
layoutParams.setMargins(0,0,0,heightDifference);//设置ScrollView的marginBottom的值为软键盘占有的高度即可
|
||||
mMessageDetailSv.requestLayout();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (newsId != null && mConcernEntity == null ) {
|
||||
getConcernDigest();
|
||||
}
|
||||
}
|
||||
|
||||
private void getConcernDigest() {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(Config.HOST + "article/"+ newsId +"/rich-digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Type listType = new TypeToken<ConcernEntity>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
mConcernEntity = gson.fromJson(response.toString(), listType);
|
||||
mConcernEntity.setCommentnum(commentNum);
|
||||
|
||||
adapter.addConcernEntity(mConcernEntity);
|
||||
adapter.notifyDataSetChanged();
|
||||
adapter.addHotComment(0);
|
||||
getNewsViews();
|
||||
|
||||
if (commentNum == 0) {
|
||||
setSoftInput(true);
|
||||
}
|
||||
}
|
||||
},
|
||||
new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
showNoConnection(true);
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
private void getNewsViews() {
|
||||
RetrofitManager.getData()
|
||||
.getNewsViews(newsId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Action1<List<ViewsEntity>>() {
|
||||
@Override
|
||||
public void call(List<ViewsEntity> viewsEntities) {
|
||||
if (viewsEntities.size() >0) {
|
||||
mConcernEntity.setViews(viewsEntities.get(0).getViews());
|
||||
adapter.notifyItemChanged(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private TextWatcher watcher = new TextWatcher() {
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
if (s.toString().trim().length() > 0) {
|
||||
mMessageDetailCommentSend.setEnabled(true);
|
||||
|
||||
if (count > 140) {
|
||||
mMessageDetailEt.setText("");
|
||||
String newText = s.toString().substring(0, 140);
|
||||
mMessageDetailEt.setText(newText);
|
||||
Utils.toast(MessageDetailActivity.this, "评论不能多于140字");
|
||||
}
|
||||
} else {
|
||||
mMessageDetailCommentSend.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@OnClick(R.id.message_detail_comment_hint_rl)
|
||||
public void OnHintClikListener() {
|
||||
setSoftInput(true);
|
||||
}
|
||||
|
||||
@OnClick(R.id.actionbar_rl_back)
|
||||
public void OnBackClikListener() {
|
||||
if (commentNum != -1 && commentNum != adapter.getConcernEntity().getCommentnum()) {
|
||||
Intent intent= new Intent();
|
||||
intent.putExtra("commentNum", adapter.getConcernEntity().getCommentnum());
|
||||
setResult(1001, intent);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
@OnTouch(R.id.message_detail_close_comment)
|
||||
public boolean OnRecyclerTouchListener() {
|
||||
if (mMessageDetailCommentRl.getVisibility() == View.VISIBLE) {
|
||||
setSoftInput(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@OnClick(R.id.comment_send)
|
||||
public void OnSendCommentListener() {
|
||||
final String content = mMessageDetailEt.getText().toString();
|
||||
|
||||
if (content.length() == 0) {
|
||||
Utils.toast(MessageDetailActivity.this, "评论内容不能为空!");
|
||||
return;
|
||||
}
|
||||
|
||||
mSendingDialog = DialogUtils.showWaitDialog(this, "正在提交");
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
try {
|
||||
jsonObject.put("content", content);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (newsId == null && mConcernEntity == null ||
|
||||
newsId == null && mConcernEntity!= null && mConcernEntity.getId() == null) {
|
||||
Utils.toast(this, "评论异常");
|
||||
return;
|
||||
} else if(newsId == null) {
|
||||
newsId = mConcernEntity.getId();
|
||||
}
|
||||
PostCommentUtils.addCommentData(MessageDetailActivity.this,
|
||||
Config.COMMENT_HOST + "article/" + newsId + "/comment", jsonObject.toString(),
|
||||
new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSucced(JSONObject response) {
|
||||
mSendingDialog.dismiss();
|
||||
Utils.toast(MessageDetailActivity.this, "发表成功");
|
||||
mMessageDetailEt.setText("");
|
||||
setSoftInput(false);
|
||||
|
||||
try {
|
||||
mCommentDao.add(new CommentInfo(response.getString("_id")));//添加评论id到数据库, 后续判断是否是自身评论
|
||||
JSONObject cacheObject = new JSONObject();
|
||||
JSONObject cacheUser = new JSONObject();
|
||||
cacheUser.put("_id", TokenUtils.getDeviceId(MessageDetailActivity.this));
|
||||
cacheUser.put("icon", sp.getString("user_icon", null));
|
||||
cacheUser.put("name", sp.getString("user_name", "光环用户"));
|
||||
cacheObject.put("_id", response.getString("_id"));
|
||||
cacheObject.put("content", content);
|
||||
cacheObject.put("time", System.currentTimeMillis() / 1000);
|
||||
cacheObject.put("vote", 0);
|
||||
cacheObject.put("user", cacheUser);
|
||||
|
||||
CommentEntity commentEntity = new Gson().fromJson(cacheObject.toString(), CommentEntity.class);
|
||||
if (mConcernEntity != null) {
|
||||
adapter.addNormalComment(commentEntity);
|
||||
}
|
||||
|
||||
modifyNewsCommentVolleyCache(0, cacheObject, newsId);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (mConcernEntity != null) {
|
||||
// 完成评论操作,添加评论数
|
||||
adapter.addCommentCount();
|
||||
//修改评论缓存
|
||||
CommentManager.updateOkhttpCacheForId(newsId);
|
||||
CommentManager.updateOkhttpCache(newsId);
|
||||
adapter.notifyItemInserted(adapter.getHotCommentListSize() + 2);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1); //刷新脚布局高度
|
||||
} else {
|
||||
showNoConnection(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postFailed(VolleyError error) {
|
||||
mSendingDialog.dismiss();
|
||||
|
||||
if (error.networkResponse == null) {
|
||||
Utils.toast(MessageDetailActivity.this, "提交失败,请检查网络设置");
|
||||
Utils.log("评论错误返回为空======");
|
||||
return;
|
||||
}
|
||||
|
||||
String errorData = new String(error.networkResponse.data);
|
||||
try {
|
||||
JSONObject errorJson = new JSONObject(errorData);
|
||||
String detail = errorJson.getString("detail");
|
||||
if ("too frequent".equals(detail)) {
|
||||
Utils.toast(MessageDetailActivity.this, "别话痨哦~休息一会再来评论吧~");
|
||||
} else if ("user blocked".equals(detail)) {
|
||||
Utils.toast(MessageDetailActivity.this, "账号状态异常,暂时无法发表评论");
|
||||
} else if ("article blocked".equals(detail)) {
|
||||
Utils.toast(MessageDetailActivity.this, "文章异常,无法发表评论");
|
||||
setSoftInput(false);
|
||||
} else if ("illegal".equals(detail)) {
|
||||
Utils.toast(MessageDetailActivity.this, "评论内容可能包括敏感信息,请修改后再发表");
|
||||
} else {
|
||||
Utils.toast(MessageDetailActivity.this, "评论失败,未知原因");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Utils.toast(MessageDetailActivity.this, "评论异常");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static final String DEFAULT_CACHE_DIR = "volley";
|
||||
|
||||
private void modifyNewsCommentVolleyCache(int offset, JSONObject commentData, String id) {
|
||||
File cacheDir = new File(getCacheDir(), DEFAULT_CACHE_DIR);
|
||||
DiskBasedCache cache = new DiskBasedCache(cacheDir);
|
||||
String key = TimestampUtils.addTimestamp(Config.COMMENT_HOST + "article/" + id + "/comment?limit=10&offset=" + offset);
|
||||
byte[] data = cache.getData(key);
|
||||
if (data != null) {
|
||||
try {
|
||||
JSONArray jsonArray = new JSONArray(new String(GzipUtils.decompressBytes(data)));
|
||||
JSONArray newComment = new JSONArray();
|
||||
newComment.put(commentData);
|
||||
for (int i = 0, size = jsonArray.length() > 9 ? 9 : jsonArray.length(); i < size; i++) {
|
||||
newComment.put(jsonArray.get(i));
|
||||
}
|
||||
Utils.log(newComment.toString());
|
||||
cache.modify(key, GzipUtils.compressBytes(newComment.toString().getBytes()));
|
||||
if (jsonArray.length() == 10) {
|
||||
modifyNewsCommentVolleyCache(offset + 10, jsonArray.getJSONObject(9), id);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
Utils.log("modifyNewsCommentVolleyCache is null");
|
||||
}
|
||||
}
|
||||
|
||||
private void showNoConnection(boolean isShow) {
|
||||
if (isShow) {
|
||||
mNoConnection.setVisibility(View.VISIBLE);
|
||||
mMessageDetailRv.setVisibility(View.GONE);
|
||||
} else {
|
||||
mNoConnection.setVisibility(View.GONE);
|
||||
mMessageDetailRv.setVisibility(View.VISIBLE);
|
||||
|
||||
if (newsId != null ) {
|
||||
getConcernDigest();
|
||||
}
|
||||
if (mMessageDetailCommentRl.getVisibility() == View.VISIBLE) {
|
||||
setSoftInput(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//软键盘控制
|
||||
private void setSoftInput(boolean isShow) {
|
||||
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if (isShow){
|
||||
imm.showSoftInputFromInputMethod(mMessageDetailEt.getWindowToken(), 0);
|
||||
imm.toggleSoftInputFromWindow(mMessageDetailEt.getWindowToken(), 0, InputMethodManager.HIDE_NOT_ALWAYS);
|
||||
mMessageDetailCommentHintRl.setVisibility(View.GONE);
|
||||
mMessageDetailLine.setVisibility(View.GONE);
|
||||
mMessageDetailCommentRl.setVisibility(View.VISIBLE);
|
||||
mMessageDetailUserRl.setVisibility(View.VISIBLE);
|
||||
mMessageDetailEt.setFocusable(true);
|
||||
mMessageDetailEt.setFocusableInTouchMode(true);
|
||||
mMessageDetailEt.requestFocus();
|
||||
mColseCommentV.setVisibility(View.VISIBLE);
|
||||
|
||||
} else {
|
||||
imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
|
||||
mMessageDetailCommentHintRl.setVisibility(View.VISIBLE);
|
||||
mMessageDetailLine.setVisibility(View.VISIBLE);
|
||||
mMessageDetailCommentRl.setVisibility(View.GONE);
|
||||
mMessageDetailUserRl.setVisibility(View.GONE);
|
||||
mColseCommentV.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showSoftInput() {
|
||||
setSoftInput(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
|
||||
if (commentNum != -1 && commentNum != adapter.getConcernEntity().getCommentnum()) {
|
||||
Intent intent= new Intent();
|
||||
intent.putExtra("commentNum", adapter.getConcernEntity().getCommentnum());
|
||||
setResult(1001, intent);
|
||||
}
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
@ -19,7 +20,7 @@ import com.android.volley.Response;
|
||||
import com.android.volley.TimeoutError;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.DetailActivity;
|
||||
import com.gh.base.BaseDetailActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
@ -42,9 +43,7 @@ import java.util.Map;
|
||||
*
|
||||
* @author 黄壮华
|
||||
*/
|
||||
public class NewsDetailActivity extends DetailActivity implements OnClickListener {
|
||||
|
||||
public static final String TAG = NewsDetailActivity.class.getSimpleName();
|
||||
public class NewsDetailActivity extends BaseDetailActivity implements OnClickListener {
|
||||
|
||||
private NewsDetailAdapter adapter;
|
||||
|
||||
@ -118,6 +117,14 @@ public class NewsDetailActivity extends DetailActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
// 刷新评论数
|
||||
if (resultCode == 1001 ) {
|
||||
adapter.commentChange(data.getExtras().getInt("commentNum"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone(Object obj) {
|
||||
@ -261,7 +268,7 @@ public class NewsDetailActivity extends DetailActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
private long[] mHits = new long[2];
|
||||
@ -270,7 +277,7 @@ public class NewsDetailActivity extends DetailActivity implements OnClickListene
|
||||
public void onClick(final View v) {
|
||||
super.onClick(v);
|
||||
if (v == iv_share) {
|
||||
if (adapter != null) {
|
||||
if (adapter != null && adapter.getNewsDetailEntity() != null) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("名字", adapter.getNewsDetailEntity().getTitle());
|
||||
kv.put("位置", "分享");
|
||||
@ -344,7 +351,7 @@ public class NewsDetailActivity extends DetailActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(gameRequest, TAG);
|
||||
AppController.addToRequestQueue(gameRequest);
|
||||
}
|
||||
|
||||
// 关注事件
|
||||
@ -417,10 +424,4 @@ public class NewsDetailActivity extends DetailActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -44,11 +44,10 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/8/22.
|
||||
* 新闻搜索界面
|
||||
*/
|
||||
public class NewsSearchActivity extends BaseActivity {
|
||||
|
||||
public static final String TAG = NewsSearchActivity.class.getSimpleName();
|
||||
|
||||
private RecyclerView gamedetail_news_rv;
|
||||
private List<NewsEntity> newsEntities;
|
||||
private NewsSearchAdapter searchAdapter;
|
||||
@ -221,7 +220,7 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
searchAdapter.notifyItemChanged(searchAdapter.getItemCount() - 1);
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
private void removeDuplicateData(ArrayList<NewsEntity> newsList) {
|
||||
@ -241,12 +240,6 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
}
|
||||
|
||||
public class NewsSearchAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
@ -314,8 +307,8 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
FooterViewHolder viewHolder = (FooterViewHolder) holder;
|
||||
viewHolder.itemView.setPadding(0, 0, 0, 0);
|
||||
if (isNetworkError) {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.GONE);
|
||||
viewHolder.footerview_tv_loading.setText("加载失败,点击重试");
|
||||
viewHolder.loading.setVisibility(View.GONE);
|
||||
viewHolder.hint.setText("加载失败,点击重试");
|
||||
viewHolder.itemView.setClickable(true);
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -326,12 +319,12 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
}
|
||||
});
|
||||
} else if (isRemove) {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.GONE);
|
||||
viewHolder.footerview_tv_loading.setText("加载完毕");
|
||||
viewHolder.loading.setVisibility(View.GONE);
|
||||
viewHolder.hint.setText("加载完毕");
|
||||
viewHolder.itemView.setClickable(false);
|
||||
} else {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.VISIBLE);
|
||||
viewHolder.footerview_tv_loading.setText("加载中...");
|
||||
viewHolder.loading.setVisibility(View.VISIBLE);
|
||||
viewHolder.hint.setText("加载中...");
|
||||
viewHolder.itemView.setClickable(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@ import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.download.DataWatcher;
|
||||
@ -24,11 +23,10 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/6.
|
||||
* 可插件化界面
|
||||
*/
|
||||
public class PluginActivity extends BaseActivity {
|
||||
|
||||
public static final String TAG = PluginActivity.class.getSimpleName();
|
||||
|
||||
private RecyclerView plugin_list;
|
||||
private PluginAdapter adapter;
|
||||
private ProgressBarCircularIndeterminate plugin_pb_loading;
|
||||
@ -165,9 +163,4 @@ public class PluginActivity extends BaseActivity {
|
||||
DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
@ -19,7 +18,6 @@ import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
|
||||
@ -37,7 +35,6 @@ import com.gh.gamecenter.search.SearchGameListFragment;
|
||||
import com.gh.gamecenter.search.SearchHistoryFragment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@ -47,7 +44,6 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
private SearchGameListFragment game_list_fragment;
|
||||
private SearchHistoryFragment search_history_fragment;
|
||||
|
||||
private RelativeLayout searchBack;
|
||||
private EditText searchInput;
|
||||
private ImageView searchCancel;
|
||||
private TextView searchButton;
|
||||
@ -163,7 +159,6 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
});
|
||||
searchButton = (TextView) findViewById(R.id.btnSearch);
|
||||
searchCancel = (ImageView) findViewById(R.id.ivDeleteText);
|
||||
searchBack = (RelativeLayout) findViewById(R.id.btnGoBack);
|
||||
|
||||
if (isFromHome && !TextUtils.isEmpty(hint)) {
|
||||
isSearchDetail = true;
|
||||
@ -241,7 +236,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
}
|
||||
});
|
||||
|
||||
searchBack.setOnClickListener(new OnClickListener() {
|
||||
findViewById(R.id.btnGoBack).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
@ -252,43 +247,16 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
|
||||
private void setResultPresentModel(int model) {
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
hideFragments(transaction);
|
||||
switch (model) {
|
||||
case 0:
|
||||
if (search_history_fragment == null) {
|
||||
List<Fragment> list = getSupportFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
for (Fragment fragment : list) {
|
||||
if (fragment.getClass().equals(SearchHistoryFragment.class)) {
|
||||
transaction.remove(fragment);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
transaction.remove(search_history_fragment);
|
||||
}
|
||||
search_history_fragment = new SearchHistoryFragment();
|
||||
transaction.add(R.id.search_result, search_history_fragment);
|
||||
transaction.replace(R.id.search_result, search_history_fragment);
|
||||
currentTab = 0;
|
||||
break;
|
||||
case 1:
|
||||
if (game_list_fragment == null) {
|
||||
List<Fragment> list = getSupportFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
for (Fragment fragment : list) {
|
||||
if (fragment.getClass().equals(SearchGameListFragment.class)) {
|
||||
transaction.remove(fragment);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
transaction.remove(game_list_fragment);
|
||||
}
|
||||
game_list_fragment = new SearchGameListFragment();
|
||||
game_list_fragment.setKey(searchKey);
|
||||
transaction.add(R.id.search_result, game_list_fragment);
|
||||
transaction.replace(R.id.search_result, game_list_fragment);
|
||||
currentTab = 1;
|
||||
break;
|
||||
case 2:
|
||||
@ -299,22 +267,9 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
map.put("from", "搜索页面");
|
||||
DataCollectionManager.onEvent(this, "search", map);
|
||||
|
||||
if (game_detail_fragment == null) {
|
||||
List<Fragment> list = getSupportFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
for (Fragment fragment : list) {
|
||||
if (fragment.getClass().equals(SearchGameDetailFragment.class)) {
|
||||
transaction.remove(fragment);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
transaction.remove(game_detail_fragment);
|
||||
}
|
||||
game_detail_fragment = new SearchGameDetailFragment();
|
||||
game_detail_fragment.setKey(searchKey);
|
||||
transaction.add(R.id.search_result, game_detail_fragment);
|
||||
transaction.replace(R.id.search_result, game_detail_fragment);
|
||||
currentTab = 2;
|
||||
break;
|
||||
default:
|
||||
@ -323,24 +278,6 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
private void hideFragments(FragmentTransaction transaction) {
|
||||
if (game_detail_fragment != null) {
|
||||
transaction.hide(game_detail_fragment);
|
||||
}
|
||||
if (game_list_fragment != null) {
|
||||
transaction.hide(game_list_fragment);
|
||||
}
|
||||
if (search_history_fragment != null) {
|
||||
transaction.hide(search_history_fragment);
|
||||
}
|
||||
List<Fragment> list = getSupportFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
for (Fragment fragment : list) {
|
||||
transaction.hide(fragment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEvent(EBSearch search) {
|
||||
isSearchDetail = true;
|
||||
String str = search.getKey();
|
||||
|
||||
@ -42,6 +42,7 @@ import com.gh.download.DownloadStatus;
|
||||
import com.gh.gamecenter.entity.AppEntity;
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.StringExtendedRequest;
|
||||
@ -64,10 +65,8 @@ import de.greenrobot.event.EventBus;
|
||||
*/
|
||||
public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
|
||||
public static final String TAG = SettingActivity.class.getSimpleName();
|
||||
|
||||
private SwitchButton setting_sb_autoinstall, setting_sb_autodelete,
|
||||
setting_sb_deletedata, setting_sb_autoupdate;
|
||||
setting_sb_deletedata, setting_sb_autoupdate, setting_sb_concerngame;
|
||||
private TextView setting_tv_version, app_tv_speed, app_tv_percent,
|
||||
app_btn_cancel, setting_tv_cache,setting_tv_size;
|
||||
private ProgressBar app_pb_progress;
|
||||
@ -136,6 +135,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
findViewById(R.id.setting_rl_feedback).setOnClickListener(this);
|
||||
findViewById(R.id.setting_rl_cache).setOnClickListener(this);
|
||||
findViewById(R.id.setting_cv_font_size).setOnClickListener(this);
|
||||
findViewById(R.id.setting_rl_concerngame).setOnClickListener(this);
|
||||
|
||||
setting_tv_version.setText("当前版本:V"
|
||||
+ PackageUtils.getVersion(getApplicationContext()));
|
||||
@ -154,6 +154,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
setting_sb_autodelete.setChecked(sp.getBoolean("autodelete", true));
|
||||
setting_sb_deletedata.setChecked(sp.getBoolean("deletedata", true));
|
||||
setting_sb_autoupdate.setChecked(sp.getBoolean("autoupdate", true));
|
||||
setting_sb_concerngame.setChecked(sp.getBoolean("concerngame", true));
|
||||
|
||||
if (sp.getBoolean("isShowDisclaimer", false)) {
|
||||
TextView setting_tv_disclaimer = (TextView) findViewById(R.id.setting_tv_disclaimer);
|
||||
@ -210,6 +211,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
mEditor.putBoolean("autodelete", setting_sb_autodelete.isChecked());
|
||||
mEditor.putBoolean("deletedata", setting_sb_deletedata.isChecked());
|
||||
mEditor.putBoolean("autoupdate", setting_sb_autoupdate.isChecked());
|
||||
mEditor.putBoolean("concerngame", setting_sb_concerngame.isChecked());
|
||||
mEditor.putInt("fontsize",checkSizeIndex);
|
||||
mEditor.apply();
|
||||
}
|
||||
@ -221,9 +223,24 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
finish();
|
||||
break;
|
||||
case R.id.setting_cv_fix_download:
|
||||
sp.edit().putBoolean("isShow", true).apply();
|
||||
toast("修复成功,快去首页看看吧");
|
||||
Editor editor = sp.edit();
|
||||
editor.putBoolean("isShow", true);
|
||||
editor.putBoolean("isCheckShow", false);
|
||||
editor.apply();
|
||||
toast("修复成功");
|
||||
EventBus.getDefault().post(new EBReuse("Refresh"));
|
||||
finish();
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sleep(800);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
EventBus.getDefault().post(new EBSkip("GameFragment", 0));
|
||||
}
|
||||
}.start();
|
||||
break;
|
||||
case R.id.setting_rl_autoinstall:
|
||||
setting_sb_autoinstall.performClick();
|
||||
@ -239,10 +256,10 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
break;
|
||||
case R.id.setting_rl_update:
|
||||
loadingDialog = DialogUtils.showWaitDialog(this, "检查更新中...");
|
||||
if (isChecking)
|
||||
break;
|
||||
isChecking = true;
|
||||
checkUpdate();
|
||||
if (!isChecking) {
|
||||
isChecking = true;
|
||||
checkUpdate();
|
||||
}
|
||||
break;
|
||||
case R.id.setting_rl_cache:
|
||||
DialogUtils.showWarningDialog(this, "清除缓存", "清空缓存后未安装的游戏可能需要重新下载,确定清空?",
|
||||
@ -255,8 +272,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
});
|
||||
break;
|
||||
case R.id.setting_rl_feedback:
|
||||
startActivity(new Intent(SettingActivity.this,
|
||||
SuggestionActivity.class));
|
||||
startActivity(new Intent(SettingActivity.this, SuggestionActivity.class));
|
||||
break;
|
||||
case R.id.setting_tv_disclaimer:
|
||||
String content = sp.getString("disclaimer", null);
|
||||
@ -267,6 +283,8 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
case R.id.setting_cv_font_size:
|
||||
fontSize();
|
||||
break;
|
||||
case R.id.setting_rl_concerngame:
|
||||
setting_sb_concerngame.performClick();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -389,8 +407,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
appEntity = gson.fromJson(response.toString(),
|
||||
AppEntity.class);
|
||||
|
||||
float version = Float.valueOf(appEntity
|
||||
.getVersion());
|
||||
float version = Float.valueOf(appEntity.getVersion());
|
||||
float currentVersion = Float.valueOf(PackageUtils.getVersion(getApplicationContext()));
|
||||
|
||||
if (version > currentVersion) {
|
||||
@ -430,7 +447,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
toast("检查更新失败");
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
private void showUpdateDialog(final String md5) {
|
||||
@ -452,10 +469,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (appEntity.isForce()) {
|
||||
Intent data = new Intent();
|
||||
data.putExtra("isForce", true);
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
AppController.getInstance().finishActivity();
|
||||
} else {
|
||||
updateDialog.dismiss();
|
||||
}
|
||||
@ -505,10 +519,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
DownloadManager.getInstance(getApplicationContext()).cancel(
|
||||
appEntity.getUrl());
|
||||
if (appEntity.isForce()) {
|
||||
Intent data = new Intent();
|
||||
data.putExtra("isForce", true);
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
AppController.getInstance().finishActivity();
|
||||
} else {
|
||||
downloadDialog.dismiss();
|
||||
isShowDownload = false;
|
||||
@ -557,7 +568,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
map.put("user", user);
|
||||
map.put("device_id", TokenUtils.getDeviceId(this));
|
||||
map.put("channel", channel);
|
||||
String url = "http://data.ghzhushou.com/api/v1d0/log";
|
||||
String url = Config.DATA_HOST + "api/v1d0/log";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("topic", "upgrade");
|
||||
params.put("source", "GH-ASSIST-Client");
|
||||
@ -566,7 +577,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
StringExtendedRequest request = new StringExtendedRequest(Request.Method.POST, url, null, null);
|
||||
request.setParams(params);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
Utils.log("提交更新数据" + new JSONObject(params).toString());
|
||||
}
|
||||
|
||||
@ -589,6 +600,5 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
protected void onDestroy() {
|
||||
saveCurrentSetting();
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
}
|
||||
}
|
||||
|
||||
109
app/src/main/java/com/gh/gamecenter/ShareCardActivity.java
Normal file
109
app/src/main/java/com/gh/gamecenter/ShareCardActivity.java
Normal file
@ -0,0 +1,109 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Html;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.MessageShareUtils;
|
||||
import com.gh.gamecenter.manager.SystemBarTintManager;
|
||||
import com.tencent.tauth.Tencent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/7.
|
||||
* 分享卡片
|
||||
*/
|
||||
public class ShareCardActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.sharecard_content) TextView mShareContentTv;
|
||||
@BindView(R.id.sharecard_game_name) TextView mShareGameNameTv;
|
||||
@BindView(R.id.sharecard_game_icon) SimpleDraweeView mShareGameIconDv;
|
||||
@BindView(R.id.sharecard_qrcode) SimpleDraweeView mShareQrCodeDv;
|
||||
@BindView(R.id.sharecard_screenshot) LinearLayout mShareScreenshotLl;
|
||||
@BindView(R.id.reuse_actionbar) RelativeLayout mActionbar;
|
||||
@BindView(R.id.sharecard_bottom) LinearLayout mShareBottomLl;
|
||||
|
||||
Handler handler = new Handler();
|
||||
|
||||
String gameName;
|
||||
String gameIconUrl;
|
||||
String shareContent;
|
||||
String picName;
|
||||
|
||||
//接收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, MessageShareUtils.getInstance(this).QqShareListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Bundle extras = getIntent().getExtras();
|
||||
gameName = extras.getString("gameName");
|
||||
gameIconUrl = extras.getString("gameIconUrl");
|
||||
shareContent = extras.getString("shareContent");
|
||||
|
||||
picName = "shareImg.jpg";
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_sharecard, null);
|
||||
init(contentView, "分享卡片");
|
||||
|
||||
ButterKnife.bind(this);
|
||||
|
||||
//修改沉浸栏以及ActionBar 颜色
|
||||
mActionbar.setBackgroundColor(getResources().getColor(R.color.back));
|
||||
SystemBarTintManager tintManager = getTintManager();
|
||||
if (tintManager != null) {
|
||||
tintManager.setStatusBarTintResource(R.color.back);
|
||||
}
|
||||
|
||||
mShareGameNameTv.setText(gameName);
|
||||
mShareContentTv.setText(Html.fromHtml(shareContent));
|
||||
mShareGameIconDv.setImageURI(gameIconUrl);
|
||||
mShareQrCodeDv.setImageURI("res:///" + R.drawable.test_qrcode);
|
||||
|
||||
// 延迟操作,等待截图部分绘制完成
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mShareScreenshotLl.setDrawingCacheEnabled(true);
|
||||
mShareScreenshotLl.buildDrawingCache();
|
||||
Bitmap drawingCache = mShareScreenshotLl.getDrawingCache();
|
||||
saveBitmap(drawingCache);
|
||||
MessageShareUtils.getInstance(ShareCardActivity.this).showShareWindows(mShareBottomLl, drawingCache, picName, false);
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
|
||||
public void saveBitmap(Bitmap bm) {
|
||||
File file = new File(getExternalCacheDir().getPath() + "/ShareImg");
|
||||
if (!file.isDirectory()) {
|
||||
file.delete();
|
||||
file.mkdirs();
|
||||
}
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
MessageShareUtils.getInstance(ShareCardActivity.this).writeBitmap(file.getPath(), picName, bm, false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
282
app/src/main/java/com/gh/gamecenter/ShareCardPicActivity.java
Normal file
282
app/src/main/java/com/gh/gamecenter/ShareCardPicActivity.java
Normal file
@ -0,0 +1,282 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.drawee.controller.BaseControllerListener;
|
||||
import com.facebook.drawee.controller.ControllerListener;
|
||||
import com.facebook.drawee.interfaces.DraweeController;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.facebook.imagepipeline.image.ImageInfo;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.MessageShareUtils;
|
||||
import com.gh.gamecenter.manager.SystemBarTintManager;
|
||||
import com.tencent.tauth.Tencent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/7.
|
||||
*/
|
||||
public class ShareCardPicActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.sharecard_content) TextView mShareContentTv;
|
||||
@BindView(R.id.sharecard_game_name) TextView mShareGameNameTv;
|
||||
@BindView(R.id.sharecard_game_icon) SimpleDraweeView mShareGameIconDv;
|
||||
@BindView(R.id.sharecard_qrcode) SimpleDraweeView mShareQrCodeDv;
|
||||
@BindView(R.id.sharecard_game_content_img) SimpleDraweeView mShareContentImgRv;
|
||||
@BindView(R.id.sharecard_screenshot) ScrollView mShareScreenshotRl;
|
||||
@BindView(R.id.reuse_actionbar) RelativeLayout mActionbar;
|
||||
@BindView(R.id.sharecard_chang_img) RelativeLayout mShareChangImageRl;
|
||||
@BindView(R.id.sharecard_share_btn) RelativeLayout mShareShareRl;
|
||||
@BindView(R.id.sharecard_chang_img_icon) ImageView mShareChangImageIcon;
|
||||
@BindView(R.id.sharecard_chang_img_tv) TextView mShareChangImageTv;
|
||||
|
||||
private String gameName;
|
||||
private String gameIconUrl;
|
||||
private String shareContent;
|
||||
private String picName;
|
||||
|
||||
int currentImgPosition;
|
||||
|
||||
private List<String> shareArrImg;
|
||||
|
||||
private Bitmap shareBm;
|
||||
|
||||
//接收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, MessageShareUtils.getInstance(this).QqShareListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Bundle extras = getIntent().getExtras();
|
||||
gameName = extras.getString("gameName");
|
||||
gameIconUrl = extras.getString("gameIconUrl");
|
||||
shareContent = extras.getString("shareContent");
|
||||
List<String> arrImg = extras.getStringArrayList("shareArrImg");
|
||||
|
||||
picName = "shareImgPic.jpg";
|
||||
currentImgPosition = 0;
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_sharecard_pic, null);
|
||||
init(contentView, "分享卡片");
|
||||
|
||||
ButterKnife.bind(this);
|
||||
|
||||
shareArrImg = new Vector<>();;
|
||||
shareArrImg.addAll(arrImg);
|
||||
|
||||
mActionbar.setBackgroundColor(getResources().getColor(R.color.back));
|
||||
SystemBarTintManager tintManager = getTintManager();
|
||||
if (tintManager != null) {
|
||||
tintManager.setStatusBarTintResource(R.color.back);
|
||||
}
|
||||
|
||||
for (int i = 0; i < shareArrImg.size(); i++) {
|
||||
checkUrl(shareArrImg.get(i), shareArrImg.size(), i);
|
||||
}
|
||||
|
||||
mShareGameNameTv.setText(gameName);
|
||||
mShareContentTv.setText(Html.fromHtml(shareContent));
|
||||
mShareGameIconDv.setImageURI(gameIconUrl);
|
||||
mShareQrCodeDv.setImageURI("res:///" + R.drawable.test_qrcode);
|
||||
|
||||
if (shareArrImg.size() > 1) {
|
||||
mShareChangImageIcon.setImageResource(R.drawable.sharecard_chang_img);
|
||||
mShareChangImageTv.setTextColor(Color.WHITE);
|
||||
} else {
|
||||
mShareChangImageIcon.setImageResource(R.drawable.sharecard_unchang_img);
|
||||
mShareChangImageTv.setTextColor(getResources().getColor(R.color.hint));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setContentImage(String url){
|
||||
ControllerListener listener = new BaseControllerListener(){
|
||||
@Override
|
||||
public void onFinalImageSet(String id, Object imageInfo, Animatable animatable) {
|
||||
super.onFinalImageSet(id, imageInfo, animatable);
|
||||
if (imageInfo == null){
|
||||
return;
|
||||
}
|
||||
ImageInfo imageInfo1 = (ImageInfo) imageInfo;
|
||||
int height = imageInfo1.getHeight();
|
||||
int width = imageInfo1.getWidth();
|
||||
float index = (float) height / (float) width;
|
||||
ViewGroup.LayoutParams layoutParams = mShareContentImgRv.getLayoutParams();
|
||||
int widthPixels = getResources().getDisplayMetrics().widthPixels;
|
||||
if (index > 1) {
|
||||
layoutParams.height = widthPixels;
|
||||
|
||||
}else {
|
||||
layoutParams.height = (int)(index * widthPixels);
|
||||
}
|
||||
mShareContentImgRv.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIntermediateImageSet(String id, Object imageInfo) {
|
||||
super.onIntermediateImageSet(id, imageInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIntermediateImageFailed(String id, Throwable throwable) {
|
||||
super.onIntermediateImageFailed(id, throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(String id, Throwable throwable) {
|
||||
super.onFailure(id, throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRelease(String id) {
|
||||
super.onRelease(id);
|
||||
}
|
||||
};
|
||||
|
||||
DraweeController controller = Fresco.newDraweeControllerBuilder()
|
||||
.setUri(url)
|
||||
.setControllerListener(listener)
|
||||
.build();
|
||||
|
||||
mShareContentImgRv.setController(controller);
|
||||
}
|
||||
|
||||
@OnClick(R.id.sharecard_share_btn)
|
||||
public void OnShareListener() {
|
||||
if (shareBm != null && shareBm.isRecycled()){
|
||||
shareBm.isRecycled();
|
||||
}
|
||||
|
||||
shareBm = getBitmapByView(mShareScreenshotRl);
|
||||
saveBitmap(shareBm);
|
||||
MessageShareUtils.getInstance(ShareCardPicActivity.this).showShareWindows(new View(ShareCardPicActivity.this), shareBm, picName, true);
|
||||
}
|
||||
|
||||
@OnClick(R.id.sharecard_chang_img)
|
||||
public void OnChangPicListener() {
|
||||
if (currentImgPosition > shareArrImg.size() -1){
|
||||
currentImgPosition = 0;
|
||||
}
|
||||
|
||||
setContentImage(shareArrImg.get(currentImgPosition));
|
||||
currentImgPosition ++;
|
||||
}
|
||||
|
||||
private void checkUrl(final String url,final int size, final int position) {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String newUrl = "http://image.ghzhushou.com/pic/hq" + url.substring(url.lastIndexOf("/"));
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(newUrl).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(5 * 1000);
|
||||
connection.setReadTimeout(5 * 1000);
|
||||
connection.connect();
|
||||
int code = connection.getResponseCode();
|
||||
if (code == 200) {
|
||||
addCount();
|
||||
shareArrImg.remove(position);
|
||||
shareArrImg.add(position, newUrl);
|
||||
if (count == size) {
|
||||
ShareCardPicActivity.this.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setContentImage(shareArrImg.get(0));
|
||||
currentImgPosition++;
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
addCount();
|
||||
if (count == size) {
|
||||
ShareCardPicActivity.this.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setContentImage(shareArrImg.get(0));
|
||||
currentImgPosition++;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
private int count;
|
||||
|
||||
private void addCount() {
|
||||
synchronized (ShareCardPicActivity.class) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap getBitmapByView(ScrollView scrollView) {
|
||||
int h = 0;
|
||||
Bitmap bitmap = null;
|
||||
|
||||
// 获取scrollview实际高度
|
||||
for (int i = 0; i < scrollView.getChildCount(); i++) {
|
||||
h += scrollView.getChildAt(i).getHeight();
|
||||
scrollView.getChildAt(i).setBackgroundColor(
|
||||
Color.parseColor("#ffffff"));
|
||||
}
|
||||
|
||||
// 创建对应大小的bitmap
|
||||
bitmap = Bitmap.createBitmap(scrollView.getWidth(), h,
|
||||
Bitmap.Config.ARGB_8888);
|
||||
final Canvas canvas = new Canvas(bitmap);
|
||||
scrollView.draw(canvas);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public void saveBitmap(Bitmap bm) {
|
||||
File file = new File(getExternalCacheDir().getPath() + "/ShareImg");
|
||||
if (!file.isDirectory()) {
|
||||
file.delete();
|
||||
file.mkdirs();
|
||||
}
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
|
||||
MessageShareUtils.getInstance(ShareCardPicActivity.this).writeBitmap(file.getPath(), picName, bm, false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
82
app/src/main/java/com/gh/gamecenter/SkipActivity.java
Normal file
82
app/src/main/java/com/gh/gamecenter/SkipActivity.java
Normal file
@ -0,0 +1,82 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.RunningUtils;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/11/16.
|
||||
* 链接跳转用
|
||||
*/
|
||||
public class SkipActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (getIntent() != null) {
|
||||
String host = getIntent().getData().getHost();
|
||||
String id = getIntent().getData().getPath();
|
||||
if (!TextUtils.isEmpty(id)) {
|
||||
id = id.substring(1);
|
||||
}
|
||||
Intent intent = new Intent();
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra("entrance", "(网页跳转)");
|
||||
if (RunningUtils.isRunning(this)) {
|
||||
// 应用正在运行,前台或后台
|
||||
if ("article".equals(host)) {
|
||||
intent.setClass(this, NewsDetailActivity.class);
|
||||
intent.putExtra("newsId", id);
|
||||
} else if ("game".equals(host)) {
|
||||
intent.setClass(this, GameDetailActivity.class);
|
||||
intent.putExtra("gameId", id);
|
||||
} else if ("column".equals(host)) {
|
||||
intent.setClass(this, SubjectActivity.class);
|
||||
intent.putExtra("id", id);
|
||||
intent.putExtra("name", getIntent().getData().getQueryParameter("name"));
|
||||
} else if ("suggestion".equals(host)) {
|
||||
Uri uri = getIntent().getData();
|
||||
String content = "【" + uri.getQueryParameter("game_name")
|
||||
+ "-" + PlatformUtils.getInstance(this).getPlatformName(uri.getQueryParameter("platform"))
|
||||
+ "-V" + uri.getQueryParameter("version") + "】";
|
||||
intent.putExtra("content", content);
|
||||
intent.setClass(this, SuggestionActivity.class);
|
||||
}
|
||||
} else {
|
||||
// 应用未在运行
|
||||
intent.setClass(this, SplashScreenActivity.class);
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
|
||||
if ("article".equals(host)) {
|
||||
intent.putExtra("newsId", id);
|
||||
intent.putExtra("to", "NewsDetailActivity");
|
||||
} else if ("game".equals(host)) {
|
||||
intent.putExtra("gameId", id);
|
||||
intent.putExtra("to", "GameDetailActivity");
|
||||
} else if ("column".equals(host)) {
|
||||
intent.putExtra("to", "SubjectActivity");
|
||||
intent.putExtra("id", id);
|
||||
intent.putExtra("name", getIntent().getData().getQueryParameter("name"));
|
||||
} else if ("suggestion".equals(host)) {
|
||||
Uri uri = getIntent().getData();
|
||||
String content = "【" + uri.getQueryParameter("game_name")
|
||||
+ "-" + PlatformUtils.getInstance(this).getPlatformName(uri.getQueryParameter("platform"))
|
||||
+ "-V" + uri.getQueryParameter("version") + "】";
|
||||
intent.putExtra("content", content);
|
||||
intent.putExtra("to", "SuggestionActivity");
|
||||
}
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
finish();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -19,7 +19,6 @@ import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
@ -27,6 +26,8 @@ import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadService;
|
||||
import com.gh.gamecenter.db.info.FilterInfo;
|
||||
@ -35,7 +36,6 @@ import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.FilterManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.StringExtendedRequest;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@ -63,8 +63,6 @@ import de.greenrobot.event.EventBus;
|
||||
*/
|
||||
public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
public static final String TAG = SplashScreenActivity.class.getSimpleName();
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
private String from;
|
||||
@ -80,6 +78,12 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// 处理助手已经在后台运行导致的再次启动助手
|
||||
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
TimestampUtils.initMap();
|
||||
@ -116,6 +120,12 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
Utils.log("flags---------------onNewIntent");
|
||||
}
|
||||
|
||||
private class ViewPagerAdapter extends PagerAdapter {
|
||||
|
||||
private int[] pics = { R.drawable.splash_01 };
|
||||
@ -220,11 +230,14 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
// 获取下载按钮状态、开启or关闭
|
||||
getDownloadStatus();
|
||||
if (sp.getBoolean("isCheckShow", true)) {
|
||||
getDownloadStatus();
|
||||
}
|
||||
|
||||
getUISetting();
|
||||
|
||||
getTime();
|
||||
// 更新本地时间
|
||||
TokenUtils.getTime(this);
|
||||
|
||||
/*
|
||||
* 上传数据
|
||||
@ -261,31 +274,6 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取服务器时间
|
||||
*/
|
||||
private void getTime() {
|
||||
StringExtendedRequest request = new StringExtendedRequest(
|
||||
Request.Method.GET, Config.HOST + "support/time/current",
|
||||
new Response.Listener<String>() {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
if (response.matches("^[0-9]{10}$")) {
|
||||
try {
|
||||
Editor editor = sp.edit();
|
||||
editor.putLong("server_time", Long.parseLong(response));
|
||||
editor.putLong("client_time", System.currentTimeMillis() / 1000);
|
||||
editor.apply();
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取界面设置
|
||||
*/
|
||||
@ -311,7 +299,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -330,7 +318,10 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
try {
|
||||
String status = response.getString("status");
|
||||
if ("on".equals(status)) {
|
||||
sp.edit().putBoolean("isShow", true).apply();
|
||||
Editor editor = sp.edit();
|
||||
editor.putBoolean("isShow", true);
|
||||
editor.putBoolean("isCheckShow", false);
|
||||
editor.apply();
|
||||
} else {
|
||||
sp.edit().putBoolean("isShow", false).apply();
|
||||
}
|
||||
@ -341,7 +332,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -395,7 +386,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
// 跳转到主界面
|
||||
@ -442,6 +433,11 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
intent.putExtra("urls", bundle.getStringArrayList("urls"));
|
||||
intent.putExtra("current", bundle.getInt("current",0));
|
||||
intent.putExtra("ScaleType", bundle.getString("ScaleType"));
|
||||
} else if ("SubjectActivity".equals(to)) {
|
||||
intent.putExtra("id", bundle.getString("id"));
|
||||
intent.putExtra("name", bundle.getString("name"));
|
||||
} else if ("SuggestionActivity".equals(to)) {
|
||||
intent.putExtra("content", bundle.getString("content"));
|
||||
}
|
||||
if ("NewsActivity".equals(to)) {
|
||||
intent.putExtra("to", "NewsDetailActivity");
|
||||
|
||||
@ -7,7 +7,6 @@ import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.download.DataWatcher;
|
||||
@ -24,8 +23,6 @@ import java.util.ArrayList;
|
||||
|
||||
public class SubjectActivity extends BaseActivity {
|
||||
|
||||
public static final String TAG = SubjectActivity.class.getSimpleName();
|
||||
|
||||
private RecyclerView subject_list;
|
||||
private SubjectAdapter adapter;
|
||||
private ProgressBarCircularIndeterminate subject_pb_loading;
|
||||
@ -184,9 +181,4 @@ public class SubjectActivity extends BaseActivity {
|
||||
DownloadManager.getInstance(getApplicationContext()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,8 +41,6 @@ import java.util.regex.Pattern;
|
||||
* */
|
||||
public class SuggestionActivity extends BaseActivity implements OnClickListener {
|
||||
|
||||
public static final String TAG = SuggestionActivity.class.getSimpleName();
|
||||
|
||||
private TextView tv_suggest_connectway;
|
||||
private EditText et_suggest_content, et_suggest_connectway;
|
||||
private CardView btn_suggest_post;
|
||||
@ -86,6 +84,12 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
String content = getIntent().getStringExtra("content");
|
||||
if (!TextUtils.isEmpty(content)) {
|
||||
et_suggest_content.setText(content);
|
||||
et_suggest_content.setSelection(et_suggest_content.getText().length());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -223,7 +227,7 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener
|
||||
}
|
||||
});
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
private boolean isEmailAddress(String email) {
|
||||
|
||||
@ -19,6 +19,7 @@ import com.facebook.drawee.controller.BaseControllerListener;
|
||||
import com.facebook.drawee.drawable.ScalingUtils;
|
||||
import com.facebook.drawee.interfaces.DraweeController;
|
||||
import com.facebook.imagepipeline.core.ImagePipeline;
|
||||
import com.facebook.imagepipeline.image.ImageInfo;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
@ -74,11 +75,10 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
final ZoomSimpleDraweeView imageView = (ZoomSimpleDraweeView) view.findViewById(R.id.viewimage_iv_show);
|
||||
final ProgressBarCircularIndeterminate progressBar = (ProgressBarCircularIndeterminate) view.findViewById(R.id.viewimage_pb_loading);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
ImageUtils.getInstance(getApplicationContext()).display(newUrls.get(position), urls.get(position), imageView
|
||||
, new BaseControllerListener(){
|
||||
ImageUtils.getInstance().display(imageView, newUrls.get(position), urls.get(position),
|
||||
new BaseControllerListener<ImageInfo>(){
|
||||
@Override
|
||||
public void onFinalImageSet(String id, Object imageInfo, Animatable animatable) {
|
||||
super.onFinalImageSet(id, imageInfo, animatable);
|
||||
public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
// if (imageInfo == null){
|
||||
// return;
|
||||
|
||||
@ -1,23 +1,43 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.webkit.DownloadListener;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.gamecenter.entity.CommentnumEntity;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/10/18.
|
||||
*/
|
||||
public class WebActivity extends BaseActivity {
|
||||
|
||||
private WebView news_webview;
|
||||
private ProgressBar web_progressbar;
|
||||
@BindView(R.id.news_webview) WebView webView;
|
||||
@BindView(R.id.web_progressbar) ProgressBar progressBar;
|
||||
@BindView(R.id.web_comment) TextView webComment;
|
||||
@BindView(R.id.news_bottom) RelativeLayout newsBottom;
|
||||
|
||||
private String newsId;
|
||||
private int commentNum;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -25,48 +45,110 @@ public class WebActivity extends BaseActivity {
|
||||
|
||||
String webUrl = getIntent().getStringExtra("url");
|
||||
String webTitle = getIntent().getStringExtra("gameName");
|
||||
newsId = getIntent().getStringExtra("newsId");
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_web, null);
|
||||
init(contentView, webTitle);
|
||||
|
||||
news_webview.loadUrl(webUrl);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
WebSettings settings = news_webview.getSettings();
|
||||
webView.loadUrl(webUrl);
|
||||
|
||||
WebSettings settings = webView.getSettings();
|
||||
settings.setJavaScriptEnabled(true);
|
||||
settings.setSupportZoom(true);
|
||||
|
||||
//用webview打开url
|
||||
news_webview.setWebViewClient(new WebViewClient(){
|
||||
webView.setWebViewClient(new WebViewClient(){
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
view.loadUrl(url);
|
||||
return true;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
|
||||
// 广告拦截操作
|
||||
// if (!url.contains(xxxx)) {
|
||||
// return new WebResourceResponse(null, null, null);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
});
|
||||
|
||||
// 页面里的下载跳转到自带浏览器
|
||||
webView.setDownloadListener(new DownloadListener() {
|
||||
@Override
|
||||
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
|
||||
Uri uri = Uri.parse(url);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
//设置加载进度条
|
||||
news_webview.setWebChromeClient(new WebChromeClient(){
|
||||
webView.setWebChromeClient(new WebChromeClient(){
|
||||
@Override
|
||||
public void onProgressChanged(WebView view, int newProgress) {
|
||||
web_progressbar.setProgress(newProgress);
|
||||
progressBar.setProgress(newProgress);
|
||||
if (newProgress == 100){
|
||||
web_progressbar.setVisibility(View.GONE);
|
||||
progressBar.setVisibility(View.GONE);
|
||||
if (newsBottom.getVisibility() == View.GONE) {
|
||||
newsBottom.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
if (web_progressbar.getVisibility() == View.GONE) {
|
||||
web_progressbar.setVisibility(View.VISIBLE);
|
||||
if (progressBar.getVisibility() == View.GONE) {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
getNewsCommentNum();
|
||||
}
|
||||
|
||||
@OnClick(R.id.web_comment)
|
||||
public void OnCommentClickListener() {
|
||||
Intent intent = new Intent(this, MessageDetailActivity.class);
|
||||
intent.putExtra("newsId", newsId);
|
||||
intent.putExtra("commentNum", commentNum);
|
||||
startActivityForResult(intent, 1001);
|
||||
}
|
||||
|
||||
public void getNewsCommentNum() {
|
||||
RetrofitManager.getComment()
|
||||
.getNewsCommentnum(newsId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new com.gh.gamecenter.retrofit.Response<List<CommentnumEntity>>(){
|
||||
|
||||
@Override
|
||||
public void onNext(List<CommentnumEntity> response) {
|
||||
super.onNext(response);
|
||||
if (response.size() > 0 && response.get(0).getNum() > 0) {
|
||||
commentNum = response.get(0).getNum();
|
||||
webComment.setText("查看评论(" + response.get(0).getNum() + ")");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && news_webview.canGoBack()) {
|
||||
news_webview.goBack();// 返回前一个页面
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
|
||||
webView.goBack();// 返回前一个页面
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
// 刷新评论数
|
||||
if (resultCode == 1001 ) {
|
||||
webComment.setText("查看评论(" + data.getExtras().getInt("commentNum") + ")");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
163
app/src/main/java/com/gh/gamecenter/WeiBoShareActivity.java
Normal file
163
app/src/main/java/com/gh/gamecenter/WeiBoShareActivity.java
Normal file
@ -0,0 +1,163 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.facebook.common.references.CloseableReference;
|
||||
import com.facebook.datasource.DataSource;
|
||||
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
|
||||
import com.facebook.imagepipeline.image.CloseableImage;
|
||||
import com.gh.common.util.AccessTokenKeeper;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.ShareUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.sina.weibo.sdk.api.ImageObject;
|
||||
import com.sina.weibo.sdk.api.TextObject;
|
||||
import com.sina.weibo.sdk.api.WebpageObject;
|
||||
import com.sina.weibo.sdk.api.WeiboMultiMessage;
|
||||
import com.sina.weibo.sdk.api.share.BaseResponse;
|
||||
import com.sina.weibo.sdk.api.share.IWeiboHandler;
|
||||
import com.sina.weibo.sdk.api.share.IWeiboShareAPI;
|
||||
import com.sina.weibo.sdk.api.share.SendMultiMessageToWeiboRequest;
|
||||
import com.sina.weibo.sdk.api.share.WeiboShareSDK;
|
||||
import com.sina.weibo.sdk.auth.AuthInfo;
|
||||
import com.sina.weibo.sdk.auth.Oauth2AccessToken;
|
||||
import com.sina.weibo.sdk.auth.WeiboAuthListener;
|
||||
import com.sina.weibo.sdk.constant.WBConstants;
|
||||
import com.sina.weibo.sdk.exception.WeiboException;
|
||||
import com.sina.weibo.sdk.utils.Utility;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/23.
|
||||
*
|
||||
* 微博分享
|
||||
*/
|
||||
public class WeiBoShareActivity extends Activity implements IWeiboHandler.Response{
|
||||
|
||||
private String shareUrl;
|
||||
private String shareGameName;
|
||||
private String shareIcon;
|
||||
private String shareNewsTitle; // shareNewsTitle不为空就是新闻分享,否则是游戏分享
|
||||
|
||||
private boolean isPlugin;
|
||||
|
||||
private IWeiboShareAPI mWeiboShareAPI;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Bundle extras = getIntent().getExtras();
|
||||
shareUrl = extras.getString("shareUrl");
|
||||
shareGameName = extras.getString("shareGameName");
|
||||
shareIcon = extras.getString("shareIcon");
|
||||
shareNewsTitle = extras.getString("shareNewsTitle");
|
||||
isPlugin = extras.getBoolean("isPlugin");
|
||||
|
||||
Utils.toast(this, "分享跳转中...");
|
||||
|
||||
mWeiboShareAPI = WeiboShareSDK.createWeiboAPI(this, "1723629218");
|
||||
mWeiboShareAPI.registerApp();
|
||||
|
||||
weiboLoadBitMap(shareIcon);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
mWeiboShareAPI.handleWeiboResponse(intent, this); //当前应用唤起微博分享后,返回当前应用
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResponse(BaseResponse baseResponse) {
|
||||
switch (baseResponse.errCode) {
|
||||
case WBConstants.ErrorCode.ERR_OK:
|
||||
Toast.makeText(this, "分享成功", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case WBConstants.ErrorCode.ERR_CANCEL:
|
||||
Toast.makeText(this, "分享取消", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case WBConstants.ErrorCode.ERR_FAIL:
|
||||
Toast.makeText(this, "分享失败", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
private void weiboLoadBitMap( String iconUrl){
|
||||
ImageUtils.getInstance().display(this, iconUrl, new BaseBitmapDataSubscriber() {
|
||||
@Override
|
||||
protected void onNewResultImpl(Bitmap bitmap) {
|
||||
Utils.log("分享获取bitmap成功,准备分享");
|
||||
|
||||
Bitmap bgBitmap = ShareUtils.getInstance(getApplication()).addBackGround(bitmap);
|
||||
|
||||
TextObject textObject = new TextObject();
|
||||
if (shareNewsTitle != null){
|
||||
textObject.text = shareNewsTitle + "@光环助手";
|
||||
}else {
|
||||
if (isPlugin){
|
||||
textObject.text ="向你推荐:" + shareGameName + "(光环加速版)" + " @光环助手 ";
|
||||
}else {
|
||||
textObject.text ="向你推荐:" + shareGameName + " @光环助手 " ;
|
||||
}
|
||||
}
|
||||
|
||||
ImageObject imageObject = new ImageObject();
|
||||
imageObject.setImageObject(bgBitmap);//设置缩略图。 注意:最终压缩过的缩略图大小不得超过 32kb。
|
||||
|
||||
WebpageObject webObject = new WebpageObject();
|
||||
webObject.identify = Utility.generateGUID();
|
||||
webObject.title = "";
|
||||
webObject.description = "光环助手";
|
||||
webObject.defaultText = "光环助手";
|
||||
webObject.actionUrl = shareUrl;
|
||||
webObject.setThumbImage(bgBitmap);
|
||||
|
||||
WeiboMultiMessage weiboMessage = new WeiboMultiMessage();//初始化微博的分享消息
|
||||
weiboMessage.textObject = textObject;
|
||||
weiboMessage.imageObject = imageObject;
|
||||
weiboMessage.mediaObject = webObject;
|
||||
SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
|
||||
request.transaction = String.valueOf(System.currentTimeMillis());
|
||||
request.multiMessage = weiboMessage;
|
||||
|
||||
AuthInfo authInfo = new AuthInfo(WeiBoShareActivity.this, "1723629218", "https://api.weibo.com/oauth2/default.html", "");
|
||||
Oauth2AccessToken accessToken = AccessTokenKeeper.readAccessToken(WeiBoShareActivity.this);
|
||||
String token = "";
|
||||
if (accessToken != null) {
|
||||
token = accessToken.getToken();
|
||||
}
|
||||
|
||||
mWeiboShareAPI.sendRequest(WeiBoShareActivity.this, request, authInfo, token, new WeiboAuthListener() {
|
||||
// 微博web端
|
||||
@Override
|
||||
public void onWeiboException( WeiboException arg0 ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete( Bundle bundle ) {
|
||||
// Oauth2AccessToken newToken = Oauth2AccessToken.parseAccessToken(bundle);
|
||||
// AccessTokenKeeper.writeAccessToken(getApplicationContext(), newToken);
|
||||
// Toast.makeText(getApplicationContext(), "onAuthorizeComplete token = " + newToken.getToken(), 0).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
|
||||
Utils.log("分享获取bitmap失败");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -92,7 +92,7 @@ public class ConcernAdapter extends RecyclerView.Adapter<ConcernViewHolder> {
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(concernObjectRequest, ConcernActivity.TAG);
|
||||
AppController.addToRequestQueue(concernObjectRequest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -98,7 +98,7 @@ public class ConcernRecommendAdapter extends RecyclerView.Adapter<ConcernViewHol
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, ConcernActivity.TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ public class ConcernRecommendAdapter extends RecyclerView.Adapter<ConcernViewHol
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(recommendRequest, ConcernActivity.TAG);
|
||||
AppController.addToRequestQueue(recommendRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
package com.gh.gamecenter.adapter;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/11/17.
|
||||
* ViewPager FragmentAdapter
|
||||
*/
|
||||
public class FragmentAdapter extends FragmentPagerAdapter {
|
||||
|
||||
private List<Fragment> list;
|
||||
|
||||
public FragmentAdapter(FragmentManager fm, List<Fragment> list) {
|
||||
super(fm);
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
return list.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
}
|
||||
@ -19,7 +19,6 @@ import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.NewsUtils;
|
||||
import com.gh.common.view.CardLinearLayout;
|
||||
import com.gh.gamecenter.GameNewsActivity;
|
||||
import com.gh.gamecenter.NewsSearchActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameNewsSearchViewHolder;
|
||||
@ -139,7 +138,7 @@ public class GameNewsAdapter extends RecyclerView.Adapter {
|
||||
isNetworkError = true;
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, GameNewsActivity.TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
private void removeDuplicateData(List<NewsEntity> list) {
|
||||
@ -171,11 +170,11 @@ public class GameNewsAdapter extends RecyclerView.Adapter {
|
||||
return new GameNewsTypeListViewHolder(view);
|
||||
} else if (newsList.size() > 0 && viewType > 1 && viewType <= 1 + newsList.size()) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.home_list_item_newsnormal_type, parent, false);
|
||||
R.layout.news_text_item, parent, false);
|
||||
return new NewsTextViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.gamedetail_item_loading, parent, false);
|
||||
R.layout.news_footer_item, parent, false);
|
||||
return new NewsFooterViewHolder(view);
|
||||
}
|
||||
}
|
||||
@ -196,14 +195,14 @@ public class GameNewsAdapter extends RecyclerView.Adapter {
|
||||
} else if (holder instanceof NewsTextViewHolder) {
|
||||
final NewsTextViewHolder viewHolder = (NewsTextViewHolder) holder;
|
||||
|
||||
viewHolder.newsType.setVisibility(View.GONE);
|
||||
viewHolder.type.setVisibility(View.GONE);
|
||||
|
||||
// 第一个
|
||||
if (position - 2 == 0) {
|
||||
viewHolder.news_line.setVisibility(View.GONE);
|
||||
viewHolder.line.setVisibility(View.GONE);
|
||||
// ((CardLinearLayout) holder.itemView).setmTop(DisplayUtils.dip2px(context, 8));
|
||||
} else {
|
||||
viewHolder.news_line.setVisibility(View.VISIBLE);
|
||||
viewHolder.line.setVisibility(View.VISIBLE);
|
||||
((CardLinearLayout) holder.itemView).setmTop(0);
|
||||
}
|
||||
|
||||
@ -217,9 +216,9 @@ public class GameNewsAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
|
||||
final NewsEntity newsEntity = newsList.get(position - 2);
|
||||
viewHolder.newsType.setBackgroundResource(NewsUtils.getDrawableIdByType(newsEntity.getType()));
|
||||
viewHolder.newsType.setText(newsEntity.getType());
|
||||
viewHolder.newsTitle.setText(newsEntity.getTitle());
|
||||
viewHolder.type.setBackgroundResource(NewsUtils.getDrawableIdByType(newsEntity.getType()));
|
||||
viewHolder.type.setText(newsEntity.getType());
|
||||
viewHolder.title.setText(newsEntity.getTitle());
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -243,11 +242,11 @@ public class GameNewsAdapter extends RecyclerView.Adapter {
|
||||
} else if (holder instanceof NewsFooterViewHolder){
|
||||
NewsFooterViewHolder footerViewHolder = ((NewsFooterViewHolder) holder);
|
||||
if (isRemove){
|
||||
footerViewHolder.item_tv_loading.setText("加载完毕");
|
||||
footerViewHolder.item_pb_loading.setVisibility(View.GONE);
|
||||
footerViewHolder.hint.setText("加载完毕");
|
||||
footerViewHolder.loading.setVisibility(View.GONE);
|
||||
}else {
|
||||
footerViewHolder.item_tv_loading.setText("加载中...");
|
||||
footerViewHolder.item_pb_loading.setVisibility(View.VISIBLE);
|
||||
footerViewHolder.hint.setText("加载中...");
|
||||
footerViewHolder.loading.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else if (holder instanceof GameNewsSearchViewHolder){
|
||||
if (isOpenKeyBoard){
|
||||
|
||||
@ -10,15 +10,25 @@ import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DeviceUtils;
|
||||
import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.NewsUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.NewsDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SubjectActivity;
|
||||
import com.gh.gamecenter.entity.SlideEntity;
|
||||
import com.gh.gamecenter.volley.extended.StringExtendedRequest;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -70,21 +80,17 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View view, ViewGroup container) {
|
||||
ViewHolder holder;
|
||||
if (view == null) {
|
||||
holder = new ViewHolder();
|
||||
view = holder.imageView = new SimpleDraweeView(context);
|
||||
view.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) view.getTag();
|
||||
view = new SimpleDraweeView(context);
|
||||
}
|
||||
|
||||
final SlideEntity slideEntity = slideList.get(getPosition(position));
|
||||
|
||||
ImageUtils.getInstance(context).display(slideEntity.getImage(), holder.imageView, R.drawable.preload, context);
|
||||
ImageUtils.getInstance().display(context.getResources(), (SimpleDraweeView) view,
|
||||
slideEntity.getImage(), R.drawable.preload);
|
||||
// indicator.setPosition(slideList.size(), getPosition(position));
|
||||
|
||||
holder.imageView.setOnClickListener(new View.OnClickListener() {
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
@ -93,15 +99,27 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
kv.put("位置", getPosition(position) + 1);
|
||||
DataUtils.onEvent(context, "点击", "游戏-插件-滚动图", kv);
|
||||
|
||||
// 首页轮播图数据统计
|
||||
statLunbotuData(getPosition(position));
|
||||
|
||||
if ("game".equals(slideEntity.getType())) {
|
||||
GameUtils.startGameDetailActivity(context, slideEntity.getLink(), "(游戏-插件:滚动图)");
|
||||
String entrance = "(游戏-插件:滚动图["
|
||||
+ slideEntity.getName()
|
||||
+ "=" + slideEntity.getType()
|
||||
+ "=" + (getPosition(position) + 1)
|
||||
+ "])";
|
||||
GameUtils.startGameDetailActivity(context, slideEntity.getLink(), entrance);
|
||||
} else if ("news".equals(slideEntity.getType())) {
|
||||
// 统计阅读量
|
||||
NewsUtils.statNewsViews(slideEntity.getLink());
|
||||
|
||||
Intent intent = new Intent(context, NewsDetailActivity.class);
|
||||
intent.putExtra("newsId", slideEntity.getLink());
|
||||
intent.putExtra("entrance", "(游戏-插件:滚动图)");
|
||||
intent.putExtra("entrance", "(游戏-插件:滚动图["
|
||||
+ slideEntity.getName()
|
||||
+ "=" + slideEntity.getType()
|
||||
+ "=" + (getPosition(position) + 1)
|
||||
+ "])");
|
||||
context.startActivity(intent);
|
||||
} else if ("column".equals(slideEntity.getType())) {
|
||||
Intent intent = new Intent(context, SubjectActivity.class);
|
||||
@ -116,8 +134,33 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
return view;
|
||||
}
|
||||
|
||||
private static class ViewHolder {
|
||||
SimpleDraweeView imageView;
|
||||
// 首页轮播图数据统计
|
||||
public void statLunbotuData(int position) {
|
||||
SlideEntity slideEntity = slideList.get(position);
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("location", String.valueOf(position + 1));
|
||||
map.put("type", slideEntity.getType());
|
||||
map.put("title", slideEntity.getName());
|
||||
map.put("form", "click");
|
||||
|
||||
String version = PackageUtils.getVersion(context);
|
||||
String user = DeviceUtils.getDeviceID(context);
|
||||
String channel = (String) PackageUtils.getMetaData(context, context.getPackageName(), "TD_CHANNEL_ID");
|
||||
map.put("version", version);
|
||||
map.put("user", user);
|
||||
map.put("device_id", TokenUtils.getDeviceId(context));
|
||||
map.put("channel", channel);
|
||||
String url = Config.DATA_HOST + "api/v1d0/log";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("topic", "lunbotu");
|
||||
params.put("source", "GH-ASSIST-Client");
|
||||
params.put("time", String.valueOf(Utils.getTime(context)));
|
||||
params.put("content", new JSONObject(map).toString());
|
||||
StringExtendedRequest request = new StringExtendedRequest(Request.Method.POST, url, null, null);
|
||||
request.setParams(params);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -135,4 +178,5 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
this.isInfiniteLoop = isInfiniteLoop;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,724 @@
|
||||
package com.gh.gamecenter.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Html;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.android.volley.toolbox.DiskBasedCache;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.ConcernContentUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.GzipUtils;
|
||||
import com.gh.common.util.NewsUtils;
|
||||
import com.gh.common.util.PostCommentUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.CardLinearLayout;
|
||||
import com.gh.gamecenter.MessageDetailActivity;
|
||||
import com.gh.gamecenter.NewsDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.ShareCardActivity;
|
||||
import com.gh.gamecenter.ShareCardPicActivity;
|
||||
import com.gh.gamecenter.WebActivity;
|
||||
import com.gh.gamecenter.adapter.viewholder.CommentHeadViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.CommentViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.NewsDigestViewHolder;
|
||||
import com.gh.gamecenter.db.CommentDao;
|
||||
import com.gh.gamecenter.db.VoteDao;
|
||||
import com.gh.gamecenter.db.info.VoteInfo;
|
||||
import com.gh.gamecenter.entity.CommentEntity;
|
||||
import com.gh.gamecenter.entity.ConcernEntity;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.VisitManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/8.
|
||||
* 消息详情-数据适配器
|
||||
*/
|
||||
public class MessageDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private ConcernEntity mConcernEntity;
|
||||
|
||||
private OnCommentCallBackListener mCallBackListener;
|
||||
|
||||
private RecyclerView mRecyclerView;
|
||||
|
||||
private List<CommentEntity> mHotCommentList;
|
||||
private List<CommentEntity> mNormalCommentList;
|
||||
|
||||
private VoteDao mVoteDao;
|
||||
private CommentDao mCommentDao;
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
private String userName; //用户名
|
||||
private String userIcon; //用户icon
|
||||
|
||||
private boolean isOver;
|
||||
private boolean isLoading;
|
||||
private boolean isNetworkError;
|
||||
private boolean isRefreshPosition;
|
||||
|
||||
private static final int ITEM_TOP = 100;
|
||||
private static final int ITEM_TITLE = 101;
|
||||
private static final int ITEM_COMMENT = 102;
|
||||
private static final int ITEM_FOOTER = 103;
|
||||
|
||||
public MessageDetailAdapter(MessageDetailActivity context, CommentDao commentDao, RecyclerView messageDetailRv ,
|
||||
ConcernEntity concernEntity) {
|
||||
this.mContext = context;
|
||||
this.mRecyclerView = messageDetailRv;
|
||||
|
||||
mCallBackListener = context;
|
||||
|
||||
mVoteDao = new VoteDao(context);
|
||||
mCommentDao = commentDao;
|
||||
|
||||
sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
|
||||
userName = sp.getString("user_name", null);
|
||||
userIcon = sp.getString("user_icon", null);
|
||||
|
||||
isOver = false;
|
||||
isLoading = false;
|
||||
isNetworkError = false;
|
||||
isRefreshPosition = true;
|
||||
|
||||
mHotCommentList = new ArrayList<>();
|
||||
mNormalCommentList = new ArrayList<>();
|
||||
|
||||
mConcernEntity = concernEntity;
|
||||
|
||||
if (mConcernEntity != null && mConcernEntity.getCommentnum() != 0) {
|
||||
addHotComment(0);
|
||||
} else if (mConcernEntity != null) {
|
||||
isOver = true;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
mCallBackListener.showSoftInput();
|
||||
}
|
||||
}
|
||||
|
||||
public void addHotComment(int offset) {
|
||||
|
||||
String hotCommentUrl = Config.COMMENT_HOST + "article/" + mConcernEntity.getId() +
|
||||
"/comment?order=hot&limit=10&offset=" + offset;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(hotCommentUrl,
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
Type listType = new TypeToken<ArrayList<CommentEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<CommentEntity> list = gson.fromJson(response.toString(), listType);
|
||||
|
||||
if (list.size() != 0) {
|
||||
mHotCommentList.clear();
|
||||
mHotCommentList.addAll(list);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
addNormalComment(mNormalCommentList.size()); // 考虑到断网刷新问题
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addNormalComment(mNormalCommentList.size());
|
||||
}
|
||||
});
|
||||
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
public void addNormalComment(int offset) {
|
||||
|
||||
isLoading = true;
|
||||
String commentUrl = Config.COMMENT_HOST + "article/" + mConcernEntity.getId() +
|
||||
"/comment?limit=10&offset=" + offset;
|
||||
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(commentUrl,
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
isLoading = false;
|
||||
|
||||
Type listType = new TypeToken<ArrayList<CommentEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<CommentEntity> list = gson.fromJson(response.toString(), listType);
|
||||
|
||||
if (list.size() < 10) {
|
||||
isOver = true;
|
||||
}
|
||||
|
||||
if (list.size() != 0) {
|
||||
mNormalCommentList.addAll(list);
|
||||
}
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
isLoading = false;
|
||||
|
||||
isNetworkError = true;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
int index;
|
||||
if (mHotCommentList.size() == 0) {
|
||||
index = 1;
|
||||
} else {
|
||||
index = 2;
|
||||
}
|
||||
|
||||
if (position == 0 && mConcernEntity != null) {
|
||||
return ITEM_TOP;
|
||||
} else if (mHotCommentList.size() != 0 && position == 1 ||
|
||||
mNormalCommentList.size() != 0 && mHotCommentList.size() + index == position ) {
|
||||
return ITEM_TITLE;
|
||||
} else if (getItemCount() == position + 1) {
|
||||
return ITEM_FOOTER;
|
||||
}
|
||||
return ITEM_COMMENT;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view;
|
||||
switch (viewType) {
|
||||
case ITEM_TOP:
|
||||
view = LayoutInflater.from(mContext).inflate(R.layout.news_digest_item, parent, false);
|
||||
return new NewsDigestViewHolder(view);
|
||||
case ITEM_TITLE:
|
||||
view = LayoutInflater.from(mContext).inflate(R.layout.comment_head_item, parent, false);
|
||||
return new CommentHeadViewHolder(view);
|
||||
case ITEM_COMMENT:
|
||||
view = LayoutInflater.from(mContext).inflate(R.layout.comment_item, parent, false);
|
||||
return new CommentViewHolder(view);
|
||||
case ITEM_FOOTER:
|
||||
view = LayoutInflater.from(mContext).inflate(R.layout.refresh_footerview, parent, false);
|
||||
return new FooterViewHolder(view);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof NewsDigestViewHolder) {
|
||||
initNewsDigestViewHolder((NewsDigestViewHolder) holder);
|
||||
} else if (holder instanceof CommentViewHolder) {
|
||||
initCommentViewHolder((CommentViewHolder) holder, position);
|
||||
} else if (holder instanceof FooterViewHolder) {
|
||||
initFooterViewHolder((FooterViewHolder) holder);
|
||||
} else if (holder instanceof CommentHeadViewHolder) {
|
||||
((CardLinearLayout) holder.itemView).setmTop(DisplayUtils.dip2px(mContext, 4));
|
||||
if (mHotCommentList.size() != 0 && position == 1) {
|
||||
((CommentHeadViewHolder) holder).commentHeadTitleTv.setText("热门评论");
|
||||
} else {
|
||||
((CommentHeadViewHolder) holder).commentHeadTitleTv.setText("最新评论");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int itemCount = 0;
|
||||
if (mHotCommentList.size() != 0) {
|
||||
itemCount = itemCount + mHotCommentList.size() + 1;
|
||||
}
|
||||
if (mNormalCommentList.size() != 0) {
|
||||
itemCount = itemCount + mNormalCommentList.size() + 1;
|
||||
}
|
||||
if (mConcernEntity != null) {
|
||||
itemCount = itemCount + 1;
|
||||
}
|
||||
return itemCount + 1;
|
||||
}
|
||||
|
||||
boolean isGetRvHeight = true; // 防止评论时弹出软键盘 影响RecyclerView高度
|
||||
int rvHeight;
|
||||
|
||||
private void initFooterViewHolder(final FooterViewHolder viewHolder) {
|
||||
if (isGetRvHeight) {
|
||||
rvHeight = mRecyclerView.getHeight();
|
||||
isGetRvHeight = false;
|
||||
}
|
||||
LinearLayout.LayoutParams params;
|
||||
int height = 0;
|
||||
if (mRecyclerView.getChildCount() != 1 ) {
|
||||
for (int i = 0; i < mRecyclerView.getChildCount(); i++) {
|
||||
if ( i != 0 || mRecyclerView.getChildAt(0).getHeight() < 200){
|
||||
height = height + mRecyclerView.getChildAt(i).getHeight();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rvHeight - height < 100 || (mNormalCommentList.size() + mHotCommentList.size()) * 220 > rvHeight) {
|
||||
params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
((LinearLayout)viewHolder.itemView).setGravity(Gravity.CENTER);
|
||||
} else {
|
||||
params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,rvHeight - height);
|
||||
((LinearLayout)viewHolder.itemView).setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
}
|
||||
viewHolder.itemView.setLayoutParams(params);
|
||||
|
||||
if(isNetworkError) {
|
||||
viewHolder.loading.setVisibility(View.GONE);
|
||||
viewHolder.hint.setText("网络错误,点击重试!");
|
||||
}else if (!isOver) {
|
||||
viewHolder.hint.setText("加载中...");
|
||||
viewHolder.loading.setVisibility(View.VISIBLE);
|
||||
} else if ( mNormalCommentList.size() == 0 && mHotCommentList.size() == 0) {
|
||||
viewHolder.loading.setVisibility(View.GONE);
|
||||
viewHolder.itemView.setLayoutParams(params);
|
||||
viewHolder.itemView.setPadding(0, DisplayUtils.dip2px(mContext, 30), 0, 0);
|
||||
viewHolder.hint.setText("目前还没有评论");
|
||||
} else {
|
||||
if (mNormalCommentList.size() > 10) {
|
||||
viewHolder.hint.setText("没有更多评论啦");
|
||||
} else {
|
||||
viewHolder.hint.setText("");
|
||||
}
|
||||
viewHolder.loading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (isNetworkError) {
|
||||
isNetworkError = false;
|
||||
viewHolder.loading.setVisibility(View.VISIBLE);
|
||||
viewHolder.hint.setText("加载中...");
|
||||
addHotComment(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initNewsDigestViewHolder(final NewsDigestViewHolder viewHolder) {
|
||||
((CardLinearLayout) viewHolder.itemView).setmTop(DisplayUtils.dip2px(mContext, 8));
|
||||
((CardLinearLayout) viewHolder.itemView).setmBottom(DisplayUtils.dip2px(mContext, 4));
|
||||
|
||||
if (mConcernEntity.getViews() != 0) {
|
||||
viewHolder.read.setText(String.format(Locale.getDefault(), "阅读 %d", mConcernEntity.getViews()));
|
||||
}
|
||||
|
||||
if (mConcernEntity.getCommentnum() != 0) {
|
||||
if (mConcernEntity.getCommentnum() > 999) {
|
||||
viewHolder.commentnum.setText(R.string.thousand);
|
||||
} else {
|
||||
viewHolder.commentnum.setText(String.valueOf(mConcernEntity.getCommentnum()));
|
||||
}
|
||||
}
|
||||
|
||||
if (mConcernEntity.getLink() != null) {
|
||||
viewHolder.link.setImageResource(R.drawable.link_iv);
|
||||
} else {
|
||||
viewHolder.link.setImageResource(R.drawable.concern_message_icon);
|
||||
}
|
||||
|
||||
if (mConcernEntity.getBrief() != null) {
|
||||
viewHolder.content.setText(Html.fromHtml(mConcernEntity.getBrief()));
|
||||
viewHolder.content.setMaxLines(100);
|
||||
} else {
|
||||
viewHolder.content.setText(Html.fromHtml(mConcernEntity.getContent()));
|
||||
viewHolder.content.setMaxLines(5);
|
||||
}
|
||||
|
||||
if (mConcernEntity.getImg().size() == 0) {
|
||||
viewHolder.imgLayout.setVisibility(View.GONE);
|
||||
viewHolder.imgLayout.removeAllViews();
|
||||
} else {
|
||||
viewHolder.imgLayout.setVisibility(View.VISIBLE);
|
||||
viewHolder.imgLayout.removeAllViews();
|
||||
ConcernContentUtils.addContentPic(mContext.getResources().getDisplayMetrics().widthPixels
|
||||
- DisplayUtils.dip2px(mContext, 34), viewHolder.imgLayout, mConcernEntity.getImg(), mContext);
|
||||
}
|
||||
|
||||
viewHolder.thumb.setImageURI(mConcernEntity.getGameIcon());
|
||||
viewHolder.title.setText(mConcernEntity.getGameName());
|
||||
NewsUtils.setNewsPublishOn(viewHolder.time, mConcernEntity.getTime());
|
||||
|
||||
viewHolder.share.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String shareContent;
|
||||
if (mConcernEntity.getBrief() != null) {
|
||||
shareContent = mConcernEntity.getBrief();
|
||||
} else {
|
||||
shareContent = mConcernEntity.getContent();
|
||||
}
|
||||
if (mConcernEntity.getImg() != null && mConcernEntity.getImg().size() > 0) {
|
||||
Intent intent = new Intent(mContext, ShareCardPicActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("gameName", mConcernEntity.getGameName());
|
||||
bundle.putString("gameIconUrl", mConcernEntity.getGameIcon());
|
||||
bundle.putString("shareContent", shareContent);
|
||||
bundle.putStringArrayList("shareArrImg", (ArrayList<String>) mConcernEntity.getImg());
|
||||
intent.putExtras(bundle);
|
||||
mContext.startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(mContext, ShareCardActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("gameName", mConcernEntity.getGameName());
|
||||
bundle.putString("gameIconUrl", mConcernEntity.getGameIcon());
|
||||
bundle.putString("shareContent", shareContent);
|
||||
intent.putExtras(bundle);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("名字", mConcernEntity.getTitle());
|
||||
DataUtils.onEvent(mContext, "点击", "消息详情", kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("page", "消息详情");
|
||||
map.put("news", mConcernEntity.getTitle());
|
||||
map.put("news_id", mConcernEntity.getId());
|
||||
DataCollectionManager.onEvent(mContext, "click-item", map);
|
||||
|
||||
// 统计阅读量
|
||||
statNewsViews(mConcernEntity.getId());
|
||||
|
||||
if (mConcernEntity.getLink() != null) {
|
||||
Intent intent = new Intent(mContext, WebActivity.class);
|
||||
intent.putExtra("url", mConcernEntity.getLink());
|
||||
intent.putExtra("gameName", mConcernEntity.getGameName());
|
||||
intent.putExtra("newsId", mConcernEntity.getId());
|
||||
mContext.startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(mContext, NewsDetailActivity.class);
|
||||
intent.putExtra("newsId", mConcernEntity.getId());
|
||||
intent.putExtra("entrance", "(消息详情)");
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
viewHolder.comment.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mCallBackListener.showSoftInput();
|
||||
}
|
||||
});
|
||||
|
||||
viewHolder.itemView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isRefreshPosition) {
|
||||
Timer timer = new Timer(); // 延迟半秒,防止出现闪屏现象
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
mRecyclerView.smoothScrollBy(0, viewHolder.itemView.getHeight()); //定位到评论顶部
|
||||
}
|
||||
}, 300);
|
||||
isRefreshPosition = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initCommentViewHolder(final CommentViewHolder holder, int position) {
|
||||
|
||||
int index;
|
||||
if (mHotCommentList.size() == 0) {
|
||||
index = 2;
|
||||
} else {
|
||||
index = 3;
|
||||
}
|
||||
|
||||
int commentPosition = 0;//
|
||||
boolean isHotComment = false; //区分热门评论和最新评论 - 修改缓存链接
|
||||
CommentEntity commentEntity = null;
|
||||
|
||||
// 初始化数据
|
||||
if (mHotCommentList.size() != 0 && mHotCommentList.size() > position -2) {
|
||||
commentEntity = mHotCommentList.get(position -2);
|
||||
isHotComment = true;
|
||||
|
||||
if (mHotCommentList.size() == position - 1) {
|
||||
((CardLinearLayout) holder.itemView).setmBottom(DisplayUtils.dip2px(mContext, 4));
|
||||
} else {
|
||||
((CardLinearLayout) holder.itemView).setmBottom(0);
|
||||
}
|
||||
} else if (mNormalCommentList.size() != 0 &&
|
||||
mNormalCommentList.size() > position - mHotCommentList.size() - index) {
|
||||
commentPosition = position - mHotCommentList.size() - index;
|
||||
commentEntity = mNormalCommentList.get(position - mHotCommentList.size() - index);
|
||||
isHotComment = false;
|
||||
|
||||
if ( mNormalCommentList.size() == position - mHotCommentList.size() - index + 1) {
|
||||
((CardLinearLayout) holder.itemView).setmBottom(DisplayUtils.dip2px(mContext, 4));
|
||||
} else {
|
||||
((CardLinearLayout) holder.itemView).setmBottom(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (commentEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
holder.commentContentTv.setText(commentEntity.getContent());
|
||||
|
||||
holder.commentLikeCountTv.setTextColor(mContext.getResources().getColor(R.color.hint));
|
||||
holder.commentLikeIv.setImageResource(R.drawable.comment_like_unselect);
|
||||
|
||||
if (commentEntity.getVote() == 0) {
|
||||
holder.commentLikeCountTv.setVisibility(View.GONE);
|
||||
} else { // 检查是否已点赞
|
||||
if (mVoteDao.isVote(commentEntity.getId()) && commentEntity.getVote() >= 1) {
|
||||
holder.commentLikeCountTv.setTextColor(mContext.getResources().getColor(R.color.theme));
|
||||
holder.commentLikeIv.setImageResource(R.drawable.comment_like_select);
|
||||
}
|
||||
holder.commentLikeCountTv.setVisibility(View.VISIBLE);
|
||||
holder.commentLikeCountTv.setText(String.valueOf(commentEntity.getVote()));
|
||||
}
|
||||
|
||||
//检查是否是自身评论
|
||||
if (userName != null && userIcon != null && !userIcon.isEmpty()&&
|
||||
!userIcon.isEmpty() && mCommentDao.isMyComment(commentEntity.getId())){
|
||||
holder.commentUserNameTv.setText(sp.getString("user_name", null));
|
||||
holder.commentUserIconDv.setImageURI(sp.getString("user_icon", null));
|
||||
} else {
|
||||
holder.commentUserNameTv.setText(commentEntity.getUser().getName());
|
||||
if(commentEntity.getUser().getIcon().isEmpty()) {
|
||||
holder.commentUserIconDv.setImageURI("res:///" + R.drawable.user_default_icon_comment);
|
||||
} else {
|
||||
holder.commentUserIconDv.setImageURI(commentEntity.getUser().getIcon());
|
||||
}
|
||||
}
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault());
|
||||
try {
|
||||
long today = format.parse(format.format(new Date())).getTime();
|
||||
long day = commentEntity.getTime() * 1000;
|
||||
if (day >= today && day < today + 86400 * 1000) {
|
||||
long min = new Date().getTime()/1000 - day/1000;
|
||||
int hour = (int) (min/ (60 * 60));
|
||||
if (hour == 0) {
|
||||
if (min < 60) {
|
||||
holder.commentTimeTv.setText("刚刚");
|
||||
} else {
|
||||
holder.commentTimeTv.setText(String.format(Locale.getDefault(), "%d分钟前", (int) (min / 60)));
|
||||
}
|
||||
} else {
|
||||
holder.commentTimeTv.setText(String.format(Locale.getDefault(), "%d小时前", hour));
|
||||
}
|
||||
} else if (day >= today - 86400 * 1000 && day < today) {
|
||||
format.applyPattern("HH:mm");
|
||||
holder.commentTimeTv.setText("昨天 ");
|
||||
} else {
|
||||
format.applyPattern("yyyy-MM-dd");
|
||||
holder.commentTimeTv.setText(format.format(day));
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
format.applyPattern("yyyy-MM-dd");
|
||||
holder.commentTimeTv.setText(format.format(commentEntity.getTime() * 1000));
|
||||
}
|
||||
|
||||
final CommentEntity finalCommentEntity = commentEntity;
|
||||
final boolean finalIsHotComment = isHotComment;
|
||||
final int finalCommentPosition = commentPosition;
|
||||
holder.commentLikeIv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (holder.commentLikeCountTv.getCurrentTextColor() == mContext.getResources().getColor(R.color.theme)) {
|
||||
Utils.toast(mContext, "已经点过赞啦!");
|
||||
return;
|
||||
}
|
||||
finalCommentEntity.setVote(finalCommentEntity.getVote() + 1);
|
||||
holder.commentLikeCountTv.setTextColor(mContext.getResources().getColor(R.color.theme));
|
||||
holder.commentLikeIv.setImageResource(R.drawable.comment_like_select);
|
||||
holder.commentLikeCountTv.setText(String.valueOf(finalCommentEntity.getVote()));
|
||||
holder.commentLikeCountTv.setVisibility(View.VISIBLE);
|
||||
|
||||
PostCommentUtils.addCommentVoto(mContext, finalCommentEntity.getId(), new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSucced(JSONObject response) {
|
||||
mVoteDao.add(new VoteInfo(finalCommentEntity.getId()));
|
||||
|
||||
int index = (finalCommentPosition /10) * 10;
|
||||
|
||||
//获取需要修改缓存的链接
|
||||
String cacheUrl;
|
||||
if (finalIsHotComment) {
|
||||
cacheUrl = Config.COMMENT_HOST + "article/" + mConcernEntity.getId() +
|
||||
"/comment?order=hot&limit=" + 10 + "&offset=" + 0; // 热门评论固定链接
|
||||
} else {
|
||||
cacheUrl = Config.COMMENT_HOST + "article/" + mConcernEntity.getId() +
|
||||
"/comment?limit=" + 10 + "&offset=" + index;
|
||||
}
|
||||
|
||||
modifyVolleyCache(finalCommentEntity.getId(), cacheUrl); //修改缓存
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postFailed(VolleyError error) {
|
||||
|
||||
|
||||
finalCommentEntity.setVote(finalCommentEntity.getVote() - 1);
|
||||
holder.commentLikeCountTv.setTextColor(mContext.getResources().getColor(R.color.hint));
|
||||
holder.commentLikeIv.setImageResource(R.drawable.comment_like_unselect);
|
||||
holder.commentLikeCountTv.setText(String.valueOf(finalCommentEntity.getVote()));
|
||||
if (finalCommentEntity.getVote() == 0) {
|
||||
holder.commentLikeCountTv.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.commentLikeCountTv.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (error.networkResponse != null && new String(error.networkResponse.data).contains("voted")) {
|
||||
Utils.toast(mContext, "已经点过赞啦!");
|
||||
} else {
|
||||
Utils.toast(mContext, "网络异常,点赞失败");
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void statNewsViews(final String news_id) {
|
||||
String url = Config.DATA_HOST + "news/stat?news_id=" + news_id;
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Request.Method.POST, url,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
try {
|
||||
if ("success".equals(response.getString("status"))) {
|
||||
|
||||
mConcernEntity.setViews(mConcernEntity.getViews() + 1);
|
||||
notifyItemChanged(0);
|
||||
|
||||
// 更新okhttp缓存数据
|
||||
VisitManager.updateOkhttpCache(mConcernEntity.getId());
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
private static final String DEFAULT_CACHE_DIR = "volley";
|
||||
|
||||
private void modifyVolleyCache(String id, String url) {
|
||||
if (url == null) {
|
||||
return;
|
||||
}
|
||||
url = TimestampUtils.addTimestamp(url);
|
||||
File cacheDir = new File(mContext.getCacheDir(), DEFAULT_CACHE_DIR);
|
||||
DiskBasedCache cache = new DiskBasedCache(cacheDir);
|
||||
byte[] data = cache.getData(url);
|
||||
if (data != null) {
|
||||
try {
|
||||
JSONArray jsonArray = new JSONArray(new String(GzipUtils.decompressBytes(data)));
|
||||
JSONObject jsonObject;
|
||||
for (int i = 0, size = jsonArray.length(); i < size; i++) {
|
||||
jsonObject = jsonArray.getJSONObject(i);
|
||||
if (jsonObject.getString("_id").equals(id)) {
|
||||
jsonObject.put("vote", jsonObject.getInt("vote") + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Utils.log(jsonArray.toString());
|
||||
cache.modify(url, GzipUtils.compressBytes(jsonArray.toString().getBytes()));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
Utils.log("modifyVolleyCache is null");
|
||||
}
|
||||
}
|
||||
|
||||
public ConcernEntity getConcernEntity() {
|
||||
return mConcernEntity;
|
||||
}
|
||||
|
||||
public boolean isLoading() {
|
||||
return isLoading;
|
||||
}
|
||||
|
||||
// 往位置0添加评论
|
||||
public void addNormalComment(CommentEntity commentEntity) {
|
||||
mNormalCommentList.add(0, commentEntity);
|
||||
}
|
||||
|
||||
public void addCommentCount() {
|
||||
mConcernEntity.setCommentnum(mConcernEntity.getCommentnum() + 1);
|
||||
notifyItemChanged(0);
|
||||
}
|
||||
|
||||
public int getHotCommentListSize() {
|
||||
int index = 0;
|
||||
if (mHotCommentList.size() != 0) {
|
||||
index = mHotCommentList.size() + 1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
public void addConcernEntity(ConcernEntity concernEntity) {
|
||||
this.mConcernEntity = concernEntity;
|
||||
}
|
||||
|
||||
public boolean isOver() {
|
||||
return isOver;
|
||||
}
|
||||
|
||||
public interface OnCommentCallBackListener {
|
||||
void showSoftInput();
|
||||
}
|
||||
}
|
||||
@ -246,7 +246,7 @@ public class PlatformAdapter extends RecyclerView.Adapter<PlatformViewHolder> {
|
||||
apkEntity.getPlatform());
|
||||
if (id != 0) {
|
||||
viewHolder.download_item_iv_pic.setVisibility(View.VISIBLE);
|
||||
viewHolder.download_item_iv_pic.setImageResource(id);
|
||||
viewHolder.download_item_iv_pic.setImageURI("res:///" + id);
|
||||
viewHolder.download_item_tv_hint.setVisibility(View.GONE);
|
||||
viewHolder.download_item_progressbar.setVisibility(View.GONE);
|
||||
viewHolder.download_item_tv_name.setVisibility(View.GONE);
|
||||
|
||||
@ -155,7 +155,6 @@ public class PluginAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
|
||||
viewHolder.home1_game_order.setVisibility(View.GONE);
|
||||
|
||||
// ImageUtils.getInstance(context).display(gameEntity.getIcon(), viewHolder.gameThumb);
|
||||
viewHolder.gameThumb.setImageURI(gameEntity.getIcon());
|
||||
if (gameEntity.isPluggable()) {
|
||||
viewHolder.gameNameAndSize.setText(gameEntity.getName() + " - " +
|
||||
|
||||
@ -118,7 +118,7 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, SubjectActivity.TAG);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
private void processingData(JSONArray response, int page) {
|
||||
@ -241,8 +241,8 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
|
||||
private void initFooterViewHolder(FooterViewHolder viewHolder) {
|
||||
if (isNetworkError) {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.GONE);
|
||||
viewHolder.footerview_tv_loading.setText("加载失败,点击重试");
|
||||
viewHolder.loading.setVisibility(View.GONE);
|
||||
viewHolder.hint.setText("加载失败,点击重试");
|
||||
viewHolder.itemView.setClickable(true);
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -253,12 +253,14 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
}
|
||||
});
|
||||
} else if (isRemove) {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.GONE);
|
||||
viewHolder.footerview_tv_loading.setText("加载完毕");
|
||||
viewHolder.loading.setVisibility(View.GONE);
|
||||
viewHolder.hint.setText("加载完毕~");
|
||||
viewHolder.itemView.setClickable(false);
|
||||
viewHolder.lineLeft.setVisibility(View.VISIBLE);
|
||||
viewHolder.lineRight.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.VISIBLE);
|
||||
viewHolder.footerview_tv_loading.setText("加载中...");
|
||||
viewHolder.loading.setVisibility(View.VISIBLE);
|
||||
viewHolder.hint.setText("加载中...");
|
||||
viewHolder.itemView.setClickable(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/9.
|
||||
*/
|
||||
public class CommentHeadViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@BindView(R.id.comment_head_line)
|
||||
public View commentHeadLine;
|
||||
@BindView(R.id.comment_head_title)
|
||||
public TextView commentHeadTitleTv;
|
||||
|
||||
public CommentHeadViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/9.
|
||||
*/
|
||||
public class CommentViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@BindView(R.id.comment_line)
|
||||
public View commentLine;
|
||||
@BindView(R.id.comment_content)
|
||||
public TextView commentContentTv;
|
||||
@BindView(R.id.comment_like)
|
||||
public ImageView commentLikeIv;
|
||||
@BindView(R.id.comment_like_count)
|
||||
public TextView commentLikeCountTv;
|
||||
@BindView(R.id.comment_time)
|
||||
public TextView commentTimeTv;
|
||||
@BindView(R.id.comment_user_icon)
|
||||
public SimpleDraweeView commentUserIconDv;
|
||||
@BindView(R.id.comment_user_name)
|
||||
public TextView commentUserNameTv;
|
||||
|
||||
public CommentViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,9 @@ import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
@ -17,18 +20,14 @@ import com.gh.gamecenter.R;
|
||||
*/
|
||||
public class FooterViewHolder extends ViewHolder {
|
||||
|
||||
public ContentLoadingProgressBar footerview_progressbar;
|
||||
public TextView footerview_tv_loading;
|
||||
public View footerview_line1;
|
||||
public View footerview_line2;
|
||||
@BindView(R.id.footerview_loading) public ContentLoadingProgressBar loading;
|
||||
@BindView(R.id.footerview_hint) public TextView hint;
|
||||
@BindView(R.id.footerview_line_left) public View lineLeft;
|
||||
@BindView(R.id.footerview_line_right) public View lineRight;
|
||||
|
||||
public FooterViewHolder(View view) {
|
||||
super(view);
|
||||
|
||||
footerview_progressbar = (ContentLoadingProgressBar) view.findViewById(R.id.footerview_progressbar);
|
||||
footerview_tv_loading = (TextView) view.findViewById(R.id.footerview_tv_loading);
|
||||
footerview_line1 = view.findViewById(R.id.footerview_line1);
|
||||
footerview_line2 = view.findViewById(R.id.footerview_line2);
|
||||
public FooterViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.common.view.AutoScrollViewPager;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/11/14.
|
||||
* viewHolder
|
||||
*/
|
||||
public class GameViewPagerViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public AutoScrollViewPager viewPager;
|
||||
public LinearLayout viewpager_ll_hint;
|
||||
public TextView viewpager_tv_failure;
|
||||
|
||||
public GameViewPagerViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
viewPager = (AutoScrollViewPager) itemView.findViewById(R.id.view_pager);
|
||||
viewpager_ll_hint = (LinearLayout) itemView.findViewById(R.id.viewpager_ll_hint);
|
||||
viewpager_tv_failure = (TextView) itemView.findViewById(R.id.viewpager_tv_failure);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2016/9/8.
|
||||
* viewholder
|
||||
*/
|
||||
public class NewsDigestViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@BindView(R.id.news_digest_thumb) public SimpleDraweeView thumb;
|
||||
@BindView(R.id.news_digest_title) public TextView title;
|
||||
@BindView(R.id.news_digest_time) public TextView time;
|
||||
@BindView(R.id.news_digest_content) public TextView content;
|
||||
@BindView(R.id.news_digest_ll_img) public LinearLayout imgLayout;
|
||||
@BindView(R.id.news_digest_read) public TextView read;
|
||||
@BindView(R.id.news_digest_comment) public LinearLayout comment;
|
||||
@BindView(R.id.news_digest_commentnum) public TextView commentnum;
|
||||
@BindView(R.id.news_digest_share) public ImageView share;
|
||||
@BindView(R.id.news_digest_link) public ImageView link;
|
||||
|
||||
public NewsDigestViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
}
|
||||
@ -7,20 +7,21 @@ import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/8/18.
|
||||
* viewholder
|
||||
*/
|
||||
public class NewsFooterViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ProgressBar item_pb_loading;
|
||||
public TextView item_tv_loading;
|
||||
@BindView(R.id.news_footer_loading) public ProgressBar loading;
|
||||
@BindView(R.id.news_footer_hint) public TextView hint;
|
||||
|
||||
public NewsFooterViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
item_pb_loading = (ProgressBar) itemView.findViewById(R.id.item_pb_loading);
|
||||
item_tv_loading = (TextView) itemView.findViewById(R.id.item_tv_loading);
|
||||
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,17 +6,20 @@ import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/8/18.
|
||||
* viewholder
|
||||
*/
|
||||
public class NewsHeadViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView headType;
|
||||
@BindView(R.id.news_head_label) public TextView label;
|
||||
|
||||
public NewsHeadViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
headType = (TextView) itemView.findViewById(R.id.tv_label);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -7,23 +7,23 @@ import android.widget.TextView;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/6/6.
|
||||
* viewholder
|
||||
*/
|
||||
public class NewsImage1ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public SimpleDraweeView fm_read_iv_thumb;
|
||||
public TextView fm_read_tv_title;
|
||||
public TextView fm_read_tv_read;
|
||||
public TextView fm_read_tv_type;
|
||||
@BindView(R.id.news_image1_thumb) public SimpleDraweeView thumb;
|
||||
@BindView(R.id.news_image1_title) public TextView title;
|
||||
@BindView(R.id.news_image1_read) public TextView read;
|
||||
@BindView(R.id.news_image1_type) public TextView type;
|
||||
|
||||
public NewsImage1ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
fm_read_iv_thumb = (SimpleDraweeView) itemView.findViewById(R.id.fm_read_iv_thumb);
|
||||
fm_read_tv_title = (TextView) itemView.findViewById(R.id.fm_read_tv_title);
|
||||
fm_read_tv_read = (TextView) itemView.findViewById(R.id.fm_read_tv_read);
|
||||
fm_read_tv_type = (TextView) itemView.findViewById(R.id.fm_read_tv_type);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -7,27 +7,25 @@ import android.widget.TextView;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/5.
|
||||
* viewholder
|
||||
*/
|
||||
public class NewsImage2ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView fm_read2_special2_title;
|
||||
public SimpleDraweeView fm_read2_special2_thumb1;
|
||||
public SimpleDraweeView fm_read2_special2_thumb2;
|
||||
public SimpleDraweeView fm_read2_special2_thumb3;
|
||||
public TextView fm_read2_special2_tv_read;
|
||||
public TextView fm_read2_special2_tv_type;
|
||||
@BindView(R.id.news_image2_title) public TextView title;
|
||||
@BindView(R.id.news_image2_thumb1) public SimpleDraweeView thumb1;
|
||||
@BindView(R.id.news_image2_thumb2) public SimpleDraweeView thumb2;
|
||||
@BindView(R.id.news_image2_thumb3) public SimpleDraweeView thumb3;
|
||||
@BindView(R.id.news_image2_read) public TextView read;
|
||||
@BindView(R.id.news_image2_type) public TextView type;
|
||||
|
||||
public NewsImage2ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
fm_read2_special2_title = (TextView) itemView.findViewById(R.id.fm_read2_special2_title);
|
||||
fm_read2_special2_thumb1 = (SimpleDraweeView) itemView.findViewById(R.id.fm_read2_special2_thumb1);
|
||||
fm_read2_special2_thumb2 = (SimpleDraweeView) itemView.findViewById(R.id.fm_read2_special2_thumb2);
|
||||
fm_read2_special2_thumb3 = (SimpleDraweeView) itemView.findViewById(R.id.fm_read2_special2_thumb3);
|
||||
fm_read2_special2_tv_read = (TextView) itemView.findViewById(R.id.fm_read2_special2_tv_read);
|
||||
fm_read2_special2_tv_type = (TextView) itemView.findViewById(R.id.fm_read2_special2_tv_type);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -7,23 +7,23 @@ import android.widget.TextView;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/5.
|
||||
* viewholder
|
||||
*/
|
||||
public class NewsImage3ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView fm_read2_special1_title;
|
||||
public SimpleDraweeView fm_read2_special1_thumb;
|
||||
public TextView fm_read2_special1_tv_read;
|
||||
public TextView fm_read2_special1_tv_type;
|
||||
@BindView(R.id.news_image3_title) public TextView title;
|
||||
@BindView(R.id.news_image3_thumb) public SimpleDraweeView thumb;
|
||||
@BindView(R.id.news_image3_read) public TextView read;
|
||||
@BindView(R.id.news_image3_type) public TextView type;
|
||||
|
||||
public NewsImage3ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
fm_read2_special1_title = (TextView) itemView.findViewById(R.id.fm_read2_special1_title);
|
||||
fm_read2_special1_thumb = (SimpleDraweeView) itemView.findViewById(R.id.fm_read2_special1_thumb);
|
||||
fm_read2_special1_tv_read = (TextView) itemView.findViewById(R.id.fm_read2_special1_tv_read);
|
||||
fm_read2_special1_tv_type = (TextView) itemView.findViewById(R.id.fm_read2_special1_tv_type);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -7,21 +7,22 @@ import android.widget.TextView;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/8/17.
|
||||
* viewholder
|
||||
*/
|
||||
public class NewsImageViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public SimpleDraweeView newsThumb;
|
||||
public TextView newsMainTitle;
|
||||
public TextView newsSubTitle;
|
||||
@BindView(R.id.news_image_thumb) public SimpleDraweeView thumb;
|
||||
@BindView(R.id.news_image_main_title) public TextView mainTitle;
|
||||
@BindView(R.id.news_image_sub_title) public TextView subTitle;
|
||||
|
||||
public NewsImageViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
newsThumb = (SimpleDraweeView) itemView.findViewById(R.id.news_thumb);
|
||||
newsMainTitle = (TextView) itemView.findViewById(R.id.news_main_title);
|
||||
newsSubTitle = (TextView) itemView.findViewById(R.id.news_sub_title);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,21 +6,22 @@ import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/8/17.
|
||||
* viewholder
|
||||
*/
|
||||
public class NewsTextViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public View news_line;
|
||||
public TextView newsType;
|
||||
public TextView newsTitle;
|
||||
@BindView(R.id.news_text_line) public View line;
|
||||
@BindView(R.id.news_text_type) public TextView type;
|
||||
@BindView(R.id.news_text_title) public TextView title;
|
||||
|
||||
public NewsTextViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
news_line = itemView.findViewById(R.id.news_line);
|
||||
newsType = (TextView) itemView.findViewById(R.id.news_type);
|
||||
newsTitle = (TextView) itemView.findViewById(R.id.news_title);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,359 @@
|
||||
package com.gh.gamecenter.changeskin;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.gamedetail.GameDetailSkinViewHolder;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/16.
|
||||
*/
|
||||
public class ChangeSkinUtils {
|
||||
|
||||
private static List<PatchEntity> patchDatas = new ArrayList<PatchEntity>();
|
||||
private static List<PatchEntity> updatePatchList;
|
||||
|
||||
private static Timer timer;
|
||||
private static Timer poiTimer;
|
||||
private static int pageNum = 1;
|
||||
private static int curProgress = 0;
|
||||
private static int pg = 0;
|
||||
private static int maxPoogress = 0;
|
||||
private static int curMD5Num; //当前检查过的本地MD5文件数量
|
||||
private static int localMD5Num;//文件总数量
|
||||
|
||||
private static ProgressBar pgPatch;
|
||||
|
||||
private static String checkPoint = ".";
|
||||
private static String speed = " 0KB/s";
|
||||
private static String filePath = "/mnt/sdcard/Android/data/" + SkinConfig.patchVersion + "/files";
|
||||
|
||||
private static TextView tvPatch;
|
||||
private static TextView tvPer;
|
||||
|
||||
private static int downPosition = -1;
|
||||
private static int downState = 0; // 0:无操作 1:暂停 2:正在下载 3:下载完成
|
||||
private static int patchSize;
|
||||
|
||||
public static boolean isChecking = false;
|
||||
|
||||
|
||||
private static Handler handler = new Handler(){
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
//下载完成
|
||||
case SkinConfig.MSG_DOWNLOAD_OVER :
|
||||
String jsonRuslt = (String) msg.obj;
|
||||
if( "".equals(jsonRuslt) ){
|
||||
startCheckMD5Thread();
|
||||
} else {
|
||||
List<PatchEntity> patchData = parseDesPatchJson(jsonRuslt);
|
||||
patchDatas.addAll(patchData);
|
||||
if( patchData.size() < SkinConfig.perPage ) {
|
||||
startCheckMD5Thread();
|
||||
} else {
|
||||
pageNum++;
|
||||
String urlPath = SkinConfig.JSON_PATCHURL + pageNum;
|
||||
DownloadUtils.downloadJson( urlPath, handler );
|
||||
}
|
||||
}
|
||||
break;
|
||||
//进度条更新
|
||||
case SkinConfig.MSG_PROGRESS_UPDATE :
|
||||
tvPatch.setVisibility(View.GONE);
|
||||
pgPatch.setVisibility(View.VISIBLE);
|
||||
tvPer.setVisibility(View.VISIBLE);
|
||||
curProgress++;
|
||||
pg = curProgress * 100 / maxPoogress;
|
||||
pgPatch.setProgress(pg);
|
||||
Utils.log("当前下载:" + pg + "% (" + speed + ")" + "::" + curProgress);
|
||||
if (pg >= 100) {
|
||||
tvPatch.setText("更新完成");
|
||||
tvPatch.setVisibility(View.VISIBLE);
|
||||
pgPatch.setVisibility(View.GONE);
|
||||
tvPer.setVisibility(View.GONE);
|
||||
tvPatch.setEnabled(false);
|
||||
pgPatch.setEnabled(false);
|
||||
tvPer.setEnabled(false);
|
||||
downState = 3;
|
||||
timer.cancel();
|
||||
} else {
|
||||
if (downState == 1) {
|
||||
tvPer.setText("继续");
|
||||
} else {
|
||||
tvPer.setText( pg + "% (" + speed + ")" );
|
||||
}
|
||||
}
|
||||
break;
|
||||
//更新下载速度
|
||||
case SkinConfig.MSG_NETWORK_SPEED :
|
||||
speed = (String) msg.obj;
|
||||
break;
|
||||
//更新检测当前文件MD5值数量
|
||||
case SkinConfig.MSG_MD5_PROGRSS :
|
||||
curMD5Num++;
|
||||
String showTxt = "检测中(" + curMD5Num + "/" + localMD5Num + ")" + checkPoint;
|
||||
changeViewState(showTxt, "blue", SkinConfig.TYPE_DESUPDATE, false);
|
||||
break;
|
||||
//文件MD5值检查完
|
||||
case SkinConfig.MSG_MD5_OVER :
|
||||
poiTimer.cancel();
|
||||
Map<String,String> map = (Map<String, String>) msg.obj;
|
||||
relMD5File( map );
|
||||
break;
|
||||
//网络error
|
||||
case SkinConfig.MSG_NETWORK_ERROR :
|
||||
changeViewState( "网络异常,请保持网络通畅", "gray", SkinConfig.TYPE_DESUPDATE, true );
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static void changeSkinControl(GameDetailSkinViewHolder holder, final Context context){
|
||||
|
||||
tvPatch = holder.skinDownloadTv;
|
||||
pgPatch = holder.skinDownloadPb;
|
||||
tvPer = holder.skinDownloadPerTv;
|
||||
pgPatch.setMax(100);
|
||||
|
||||
|
||||
if (SkinConfig.PG_STATE == SkinConfig.TYPE_UPDATE) {
|
||||
String showTxt = "点击开始更新(" + patchSize + "MB)";
|
||||
changeViewState( showTxt, "blue", SkinConfig.TYPE_UPDATE, true );
|
||||
} else if (downState == 0) {
|
||||
tvPatch.setText("检测更新");
|
||||
tvPatch.setVisibility(View.VISIBLE);
|
||||
pgPatch.setVisibility(View.GONE);
|
||||
tvPer.setVisibility(View.GONE);
|
||||
} else if (downState == 1) {
|
||||
tvPatch.setVisibility(View.GONE);
|
||||
pgPatch.setVisibility(View.VISIBLE);
|
||||
tvPer.setVisibility(View.VISIBLE);
|
||||
pgPatch.setProgress( pg );
|
||||
tvPer.setText("继续");
|
||||
} else if (downState == 2){
|
||||
tvPatch.setVisibility(View.GONE);
|
||||
pgPatch.setVisibility(View.VISIBLE);
|
||||
tvPer.setVisibility(View.VISIBLE);
|
||||
tvPer.setText( pg + "% (" + speed + ")" );
|
||||
} else if (downState == 3) {
|
||||
tvPatch.setText("更新完成");
|
||||
tvPatch.setVisibility(View.VISIBLE);
|
||||
pgPatch.setVisibility(View.GONE);
|
||||
tvPer.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
holder.skinDownloadTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if ("更新完成".equals(tvPatch.getText().toString())) return;
|
||||
switch ( SkinConfig.PG_STATE ){
|
||||
case SkinConfig.TYPE_DESUPDATE :
|
||||
if (!"检测更新".equals(tvPatch.getText().toString())) return;
|
||||
// /data/data目录下包名文件
|
||||
File pgFile = new File( "/data/data/" + SkinConfig.patchVersion );
|
||||
// 内部sdcard中版本文件
|
||||
String pgFilePath = "/mnt/sdcard/Android/data/" + SkinConfig.patchVersion + "/files";
|
||||
File verFile = new File( pgFilePath );
|
||||
if( !pgFile.exists() || !verFile.exists() ) {
|
||||
String showTxt = "请先安装游戏,并更新好所有补丁";
|
||||
tvPatch.setBackgroundResource(R.drawable.textview_cancel_style);
|
||||
changeViewState( showTxt, "gray", SkinConfig.TYPE_DESUPDATE, true );
|
||||
} else {
|
||||
isChecking = true;
|
||||
String showTxt = "检测中" + checkPoint;
|
||||
changeViewState( showTxt, "blue", SkinConfig.TYPE_DESUPDATE, false );
|
||||
startSetPoint();
|
||||
|
||||
String urlPath = SkinConfig.JSON_PATCHURL + pageNum;
|
||||
//下载数据json
|
||||
DownloadUtils.downloadJson( urlPath, handler);
|
||||
}
|
||||
break;
|
||||
case SkinConfig.TYPE_UPDATE :
|
||||
String showTxt = "开始更新...";
|
||||
changeViewState( showTxt, "blue", SkinConfig.TYPE_DESUPDATE, false );
|
||||
maxPoogress = updatePatchList.size();
|
||||
startTimer(context);
|
||||
|
||||
updateProgress();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tvPer.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if ("继续".equals(tvPer.getText().toString())){
|
||||
downState = 2;
|
||||
tvPer.setText( pg + "% (" + speed + ")" );
|
||||
updateProgress();
|
||||
} else {
|
||||
tvPer.setText("继续");
|
||||
downState = 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//按钮状态改变
|
||||
private static void changeViewState( String txt, String color, int type, boolean isEnabled) {
|
||||
tvPatch.setText( txt );
|
||||
SkinConfig.PG_STATE = type;
|
||||
pgPatch.setEnabled( isEnabled );
|
||||
}
|
||||
|
||||
//正在下载 ... 点用计时器控制
|
||||
private static void startSetPoint(){
|
||||
final int[] curPoint = {0};
|
||||
final TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
curPoint[0] += 1;
|
||||
if(curPoint[0] == 1){
|
||||
checkPoint = ".";
|
||||
}else if(curPoint[0] == 2){
|
||||
checkPoint = "..";
|
||||
}else if(curPoint[0] == 3){
|
||||
curPoint[0] = 0;
|
||||
checkPoint = "...";
|
||||
}
|
||||
}
|
||||
};
|
||||
poiTimer = new Timer( true );
|
||||
poiTimer.schedule( task, 1000, 1000 );
|
||||
}
|
||||
|
||||
//开启计时器,计算下载速度
|
||||
private static void startTimer(final Context context) {
|
||||
|
||||
final TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
NetSpeed.showNetSpeed(context, handler);
|
||||
}
|
||||
};
|
||||
timer = new Timer( true );
|
||||
timer.schedule( task, 1000, 1000 );
|
||||
}
|
||||
|
||||
//比较文件的MD5值,返回MD5值不同的文件个数
|
||||
private static void relMD5File( Map<String, String> dirMD5Map ) {
|
||||
updatePatchList = new ArrayList<PatchEntity>();
|
||||
patchSize = 0;
|
||||
curMD5Num = 0;
|
||||
//获取目录下所有文件的 MD5 值
|
||||
for ( int i = 0; i < patchDatas.size(); i++ ) {
|
||||
PatchEntity data = patchDatas.get( i );
|
||||
String path = data.path;
|
||||
String updateMD5 = data.md5;
|
||||
String updateUrl = data.url;
|
||||
String updateSize = data.size;
|
||||
|
||||
//替换地址中标识符&
|
||||
String replacePath = path.replace("&", SkinConfig.patchVersion);
|
||||
patchDatas.get(i).path = replacePath;
|
||||
|
||||
String localMD5 = dirMD5Map.get( "/" + replacePath );
|
||||
if ( localMD5 != null ) {
|
||||
if ( !updateMD5.equals( localMD5 ) ) {
|
||||
updatePatchList.add( data );
|
||||
patchSize += Integer.parseInt( updateSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isChecking = false;
|
||||
|
||||
if (patchSize == 0) {
|
||||
String showTxt = "暂无更新";
|
||||
tvPatch.setBackgroundResource(R.drawable.textview_cancel_style);
|
||||
changeViewState( showTxt, "gray", SkinConfig.TYPE_DESUPDATE, true);
|
||||
} else {
|
||||
patchSize = patchSize / 1024 / 1024;
|
||||
String showTxt = "点击开始更新(" + patchSize + "MB)";
|
||||
changeViewState( showTxt, "blue", SkinConfig.TYPE_UPDATE, true );
|
||||
}
|
||||
}
|
||||
|
||||
private static void startCheckMD5Thread(){
|
||||
final Thread checkMD5Thrad = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
localMD5Num = FileMD5Utils.getDirNum(new File(filePath));
|
||||
Map<String, String> dirMD5Map = FileMD5Utils.getDirMD5(new File(filePath), handler);
|
||||
Message msg = Message.obtain();
|
||||
msg.obj = dirMD5Map;
|
||||
msg.what = SkinConfig.MSG_MD5_OVER;
|
||||
handler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
checkMD5Thrad.start();
|
||||
}
|
||||
|
||||
//解析json数据
|
||||
private static List<PatchEntity> parseDesPatchJson(String jsonString) {
|
||||
Type listType = new TypeToken<ArrayList<PatchEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
return gson.fromJson(jsonString, listType);
|
||||
}
|
||||
|
||||
//指定目录,下载替换文件
|
||||
private static void updateProgress() {
|
||||
|
||||
Thread downThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for( int i = 0; i < updatePatchList.size(); i++ ) {
|
||||
if (downState == 1) {
|
||||
break;
|
||||
}
|
||||
if (i < downPosition) { // 重复下载暂停前的一张图片,防止断网下载失败 漏掉下载的图片
|
||||
continue;
|
||||
}
|
||||
downPosition = i;
|
||||
|
||||
PatchEntity patchData = updatePatchList.get( i );
|
||||
String filePath = patchData.path;
|
||||
Utils.log("updateProgress---" + updatePatchList.size() + "::" + i);
|
||||
DownloadUtils.saveUrlToFile( filePath, patchData.url, handler );
|
||||
}
|
||||
}
|
||||
});
|
||||
downThread.start();
|
||||
}
|
||||
|
||||
//断网或者写入文件失败的操作
|
||||
public static void NetWorkErrorControl (){
|
||||
downState = 1;
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tvPer.setText("继续");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,150 @@
|
||||
package com.gh.gamecenter.changeskin;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import com.gh.common.util.Utils;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
|
||||
/**
|
||||
* Created by yyq on 2016/11/3.
|
||||
*
|
||||
*/
|
||||
public class DownloadUtils {
|
||||
|
||||
private static final int BUFFER_SIZE = 2048 * 2048;
|
||||
private static final int CONNECT_TIME = 5000;
|
||||
private static final int READ_TIME = 5000;
|
||||
|
||||
//下载需要替换的文件
|
||||
public static void saveUrlToFile(String filePath, String url, Handler handler) {
|
||||
BufferedInputStream bis = null;
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
// 建立链接
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(CONNECT_TIME);
|
||||
connection.setReadTimeout(READ_TIME);
|
||||
connection.setDoInput(true);
|
||||
//连接指定的资源
|
||||
connection.connect();
|
||||
//获取网络输入流
|
||||
bis = new BufferedInputStream(connection.getInputStream());
|
||||
File file = new File(filePath);
|
||||
if(!file.exists()) {
|
||||
File dir = file.getParentFile();
|
||||
if (dir.exists() || dir.mkdirs()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
}
|
||||
Utils.log("createNewFile::" + file.getName() + "::" + file.getAbsolutePath() + "::" + file.exists() + "::" + file.isFile());
|
||||
fos = new FileOutputStream(file);
|
||||
|
||||
//保存文件
|
||||
int size;
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
while ((size = bis.read(buffer)) != -1) {
|
||||
fos.write(buffer, 0, size);
|
||||
}
|
||||
fos.flush();
|
||||
Utils.log("updateProgress---saveUrlToFile");
|
||||
handler.sendEmptyMessage(SkinConfig.MSG_PROGRESS_UPDATE);
|
||||
} catch (IOException e) {
|
||||
Utils.log("saveUrlToFile::" + e.toString());
|
||||
ChangeSkinUtils.NetWorkErrorControl();
|
||||
//出现异常暂停下载
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (bis != null) {
|
||||
try {
|
||||
bis.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//下载网络json
|
||||
public static void downloadJson(final String params, final Handler handler ) {
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
InputStream is = null;
|
||||
HttpURLConnection urlConnection = null;
|
||||
|
||||
try {
|
||||
URL url = new URL( params );
|
||||
urlConnection = (HttpURLConnection) url.openConnection();
|
||||
urlConnection.setRequestMethod("GET");
|
||||
int statusCode = urlConnection.getResponseCode();
|
||||
|
||||
/* 200 represents HTTP OK */
|
||||
if (statusCode == 200) {
|
||||
is = urlConnection.getInputStream();
|
||||
byte[] data = readStream(is);
|
||||
String json = new String(data);
|
||||
//下载完的json发送到handler
|
||||
Message msg = Message.obtain();
|
||||
msg.what = SkinConfig.MSG_DOWNLOAD_OVER ;
|
||||
msg.obj = json;
|
||||
handler.sendMessage(msg);
|
||||
}else if( statusCode == 404 ){
|
||||
handler.sendEmptyMessage(SkinConfig.MSG_DOWNLOAD_OVER);
|
||||
}else if( statusCode == 302 ){
|
||||
downloadJson( params, handler );
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
handler.sendEmptyMessage( SkinConfig.MSG_NETWORK_ERROR );
|
||||
e.printStackTrace();
|
||||
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (urlConnection != null) {
|
||||
urlConnection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
private static byte[] readStream(InputStream inputStream) throws IOException {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int len = 0;
|
||||
while ((len = inputStream.read(buffer)) != -1) {
|
||||
bout.write(buffer, 0, len);
|
||||
}
|
||||
bout.close();
|
||||
inputStream.close();
|
||||
return bout.toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
108
app/src/main/java/com/gh/gamecenter/changeskin/FileMD5Utils.java
Normal file
108
app/src/main/java/com/gh/gamecenter/changeskin/FileMD5Utils.java
Normal file
@ -0,0 +1,108 @@
|
||||
package com.gh.gamecenter.changeskin;
|
||||
|
||||
import android.os.Handler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by yyq on 2016/11/2.
|
||||
*
|
||||
*/
|
||||
public class FileMD5Utils {
|
||||
|
||||
/**
|
||||
* 获取单个文件的MD5值!
|
||||
* @param file 文件
|
||||
* @return md5
|
||||
*/
|
||||
public static String getFileMD5(File file) {
|
||||
if (!file.isFile()) {
|
||||
return null;
|
||||
}
|
||||
MessageDigest digest;
|
||||
FileInputStream in;
|
||||
byte buffer[] = new byte[1024];
|
||||
int len;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("MD5");
|
||||
in = new FileInputStream(file);
|
||||
while ((len = in.read(buffer, 0, 1024)) != -1) {
|
||||
digest.update(buffer, 0, len);
|
||||
}
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
BigInteger bigInt = new BigInteger(1, digest.digest());
|
||||
|
||||
if (bigInt.toString().length() < 39) {
|
||||
int length = bigInt.toString(16).length();
|
||||
if (length < 32) {
|
||||
String bigStr = bigInt.toString(16);
|
||||
for (int i = 0; i < (32 - length); i++) {
|
||||
bigStr = "0" + bigStr;
|
||||
}
|
||||
return bigStr;
|
||||
}
|
||||
}
|
||||
|
||||
return bigInt.toString(16);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取文件夹中文件的MD5值
|
||||
*
|
||||
* @param folder 文件夹
|
||||
* @param handler handler
|
||||
* @return 文件MD5 map
|
||||
*/
|
||||
public static Map<String, String> getDirMD5(File folder, Handler handler) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (!folder.isDirectory()) {
|
||||
return map;
|
||||
}
|
||||
String md5;
|
||||
for (File file : folder.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
map.putAll(getDirMD5(file, handler));
|
||||
} else {
|
||||
md5 = getFileMD5(file);
|
||||
handler.sendEmptyMessage(SkinConfig.MSG_MD5_PROGRSS);
|
||||
if (md5 != null) {
|
||||
map.put(file.getPath(), md5);
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件夹下文件数量
|
||||
* @param folder 文件夹
|
||||
* @return 文件数量
|
||||
*/
|
||||
public static int getDirNum(File folder) {
|
||||
int dirNum = 0;
|
||||
if (!folder.isDirectory()) {
|
||||
return dirNum;
|
||||
}
|
||||
for (File file : folder.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
dirNum += getDirNum(file);
|
||||
} else {
|
||||
dirNum++;
|
||||
}
|
||||
}
|
||||
return dirNum;
|
||||
}
|
||||
|
||||
}
|
||||
36
app/src/main/java/com/gh/gamecenter/changeskin/NetSpeed.java
Normal file
36
app/src/main/java/com/gh/gamecenter/changeskin/NetSpeed.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.gh.gamecenter.changeskin;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.TrafficStats;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
|
||||
/**
|
||||
* Created by yyq on 2016/11/4.
|
||||
*
|
||||
*/
|
||||
public class NetSpeed {
|
||||
|
||||
private static long lastTotalRxBytes = 0;
|
||||
private static long lastTimeStamp = 0;
|
||||
|
||||
private static long getTotalRxBytes(Context context) {
|
||||
return TrafficStats.getUidRxBytes( context.getApplicationInfo().uid ) == TrafficStats.UNSUPPORTED ? 0 : (TrafficStats.getTotalRxBytes() / 1024);//转为KB
|
||||
}
|
||||
|
||||
public static void showNetSpeed(Context context, Handler handler) {
|
||||
|
||||
long nowTotalRxBytes = getTotalRxBytes( context );
|
||||
long nowTimeStamp = System.currentTimeMillis();
|
||||
long speed = ((nowTotalRxBytes - lastTotalRxBytes) * 1000 / (nowTimeStamp - lastTimeStamp));//毫秒转换
|
||||
|
||||
lastTimeStamp = nowTimeStamp;
|
||||
lastTotalRxBytes = nowTotalRxBytes;
|
||||
|
||||
Message msg = handler.obtainMessage();
|
||||
msg.what = SkinConfig.MSG_NETWORK_SPEED ;
|
||||
msg.obj = String.valueOf(speed) + " KB/s";
|
||||
handler.sendMessage(msg);//更新界面
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package com.gh.gamecenter.changeskin;
|
||||
|
||||
/**
|
||||
* Created by yyq on 2016/11/2.
|
||||
*
|
||||
*/
|
||||
public class PatchEntity {
|
||||
public String md5;
|
||||
public String size;
|
||||
public String path;
|
||||
public String url;
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package com.gh.gamecenter.changeskin;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/16.
|
||||
*
|
||||
*/
|
||||
public class SkinConfig {
|
||||
|
||||
public static int PG_STATE = 1;
|
||||
|
||||
/*
|
||||
* pageNum : 页数
|
||||
* perPage : 请求数量
|
||||
*/
|
||||
public static int perPage = 300;
|
||||
|
||||
|
||||
public static final int TYPE_DESUPDATE = 1;
|
||||
public static final int TYPE_UPDATE = 2;
|
||||
public static final int TYPE_STOP = 3;
|
||||
public static final int TYPE_RESTART = 4;
|
||||
|
||||
public static final int MSG_DOWNLOAD_OVER = 100;
|
||||
public static final int MSG_PROGRESS_UPDATE = 101;
|
||||
public static final int MSG_NETWORK_SPEED = 102;
|
||||
public static final int MSG_MD5_PROGRSS = 103;
|
||||
public static final int MSG_MD5_OVER = 104;
|
||||
public static final int MSG_NETWORK_ERROR = 200;
|
||||
|
||||
public static final String GAME_ID = "57ce84f88ab49e83728b4572";
|
||||
|
||||
// http://api.ghzhushou.com/v2d2/game/57ce84f88ab49e83728b4572/skin/data?per_page=1000&page=1
|
||||
public static final String JSON_PATCHURL = "http://api.ghzhushou.com/v2d2/skin/game/"
|
||||
+ GAME_ID + "/data?per_page=" + perPage + "&page=";
|
||||
// public static final String JSON_PATCHURL = "http://api.ghzhushou.com/v2d2/skin/game/"
|
||||
// + GAME_ID + "/data?per_page=" + perPage + "&page="; // 原链接
|
||||
|
||||
// ewan.anfeng 安峰
|
||||
public static String patchVersion = "com.netease.ma.netease";
|
||||
// public static String patchVersion = "com.netease.ma.bili";
|
||||
|
||||
}
|
||||
51
app/src/main/java/com/gh/gamecenter/db/CommentDao.java
Normal file
51
app/src/main/java/com/gh/gamecenter/db/CommentDao.java
Normal file
@ -0,0 +1,51 @@
|
||||
package com.gh.gamecenter.db;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.gh.gamecenter.db.info.CommentInfo;
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/21.
|
||||
*/
|
||||
public class CommentDao {
|
||||
private DatabaseHelper helper;
|
||||
private Dao<CommentInfo, String> dao;
|
||||
|
||||
public CommentDao(Context context) {
|
||||
try {
|
||||
helper = DatabaseHelper.getHelper(context);
|
||||
dao = helper.getDao(CommentInfo.class);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一个评论
|
||||
*/
|
||||
public void add(CommentInfo comment) {
|
||||
try {
|
||||
dao.create(comment);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据commentId 查找是否是自己的评论
|
||||
*/
|
||||
public boolean isMyComment(String id) {
|
||||
try {
|
||||
if (dao.queryForId(id) != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -5,11 +5,13 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.db.info.CommentInfo;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.db.info.DataCollectionInfo;
|
||||
import com.gh.gamecenter.db.info.FilterInfo;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.db.info.SearchHistoryInfo;
|
||||
import com.gh.gamecenter.db.info.VoteInfo;
|
||||
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
@ -20,7 +22,7 @@ import java.sql.SQLException;
|
||||
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||
|
||||
private static final String DATABASE_NAME = "gh_assist.db";
|
||||
private static final int DATABASE_VERSION = 2;
|
||||
private static final int DATABASE_VERSION = 3;
|
||||
|
||||
private static DatabaseHelper instance;
|
||||
private ArrayMap<String, Dao> daos = new ArrayMap<String, Dao>();
|
||||
@ -58,6 +60,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||
TableUtils.createTable(connectionSource, GameInfo.class);
|
||||
TableUtils.createTable(connectionSource, FilterInfo.class);
|
||||
TableUtils.createTable(connectionSource, DataCollectionInfo.class);
|
||||
TableUtils.createTable(connectionSource, VoteInfo.class);
|
||||
TableUtils.createTable(connectionSource, CommentInfo.class);
|
||||
} catch (SQLException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
@ -75,6 +79,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||
TableUtils.dropTable(connectionSource, GameInfo.class, true);
|
||||
TableUtils.dropTable(connectionSource, FilterInfo.class, true);
|
||||
TableUtils.dropTable(connectionSource, DataCollectionInfo.class, true);
|
||||
TableUtils.dropTable(connectionSource, VoteInfo.class, true);
|
||||
TableUtils.dropTable(connectionSource, CommentInfo.class, true);;
|
||||
onCreate(database, connectionSource);
|
||||
} catch (SQLException e) {
|
||||
|
||||
|
||||
53
app/src/main/java/com/gh/gamecenter/db/VoteDao.java
Normal file
53
app/src/main/java/com/gh/gamecenter/db/VoteDao.java
Normal file
@ -0,0 +1,53 @@
|
||||
package com.gh.gamecenter.db;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.gh.gamecenter.db.info.VoteInfo;
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/11.
|
||||
*/
|
||||
|
||||
public class VoteDao {
|
||||
private DatabaseHelper helper;
|
||||
private Dao<VoteInfo, String> dao;
|
||||
|
||||
public VoteDao(Context context) {
|
||||
try {
|
||||
helper = DatabaseHelper.getHelper(context);
|
||||
dao = helper.getDao(VoteInfo.class);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一个点赞
|
||||
*/
|
||||
public void add(VoteInfo vote) {
|
||||
try {
|
||||
dao.create(vote);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据commentId 查找是否点过赞
|
||||
*/
|
||||
public boolean isVote(String id) {
|
||||
try {
|
||||
if (dao.queryForId(id) != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
33
app/src/main/java/com/gh/gamecenter/db/info/CommentInfo.java
Normal file
33
app/src/main/java/com/gh/gamecenter/db/info/CommentInfo.java
Normal file
@ -0,0 +1,33 @@
|
||||
package com.gh.gamecenter.db.info;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/21.
|
||||
*/
|
||||
|
||||
@DatabaseTable(tableName = "tb_comment")
|
||||
public class CommentInfo {
|
||||
@DatabaseField(id = true, columnName = "commentId")
|
||||
private String commentId;
|
||||
|
||||
public String getCommentId() {
|
||||
return commentId;
|
||||
}
|
||||
|
||||
public void setCommentId(String commentId) {
|
||||
this.commentId = commentId;
|
||||
}
|
||||
|
||||
public CommentInfo(String commentId) {
|
||||
this.commentId = commentId;
|
||||
}
|
||||
|
||||
public CommentInfo() {}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CommentEntity [commentId=" + commentId + "]";
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user