Compare commits
73 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7862426144 | |||
| 6e196262a5 | |||
| 11abd6d60f | |||
| 54df9912eb | |||
| b46e1f3291 | |||
| 98eb063ea1 | |||
| ac29a19ee8 | |||
| 553d005ed0 | |||
| 96e59d764a | |||
| cb3c3eb046 | |||
| 8d50f12886 | |||
| c8821f2f54 | |||
| b3e2f3545d | |||
| 383b7bce21 | |||
| ab9a8fd106 | |||
| 2954260722 | |||
| 6f78ba604f | |||
| 4471d95482 | |||
| 929038fc30 | |||
| c2cf64dfa0 | |||
| 719177b816 | |||
| 190296e533 | |||
| f1f33112fc | |||
| b1fdeeef65 | |||
| 63b8e9551c | |||
| f6758d4d3a | |||
| e873b539eb | |||
| 95a3d7b494 | |||
| 1578925613 | |||
| f3ee2d2cf0 | |||
| 39d71f3627 | |||
| e52caa013d | |||
| 18d88ab298 | |||
| b768f5f661 | |||
| b756410982 | |||
| bcc58481ed | |||
| 2c6fd5d0d8 | |||
| 24238acf0e | |||
| 089399307f | |||
| 385d9155f7 | |||
| 6eaef8388b | |||
| 3100d6aede | |||
| 35b62c2bc6 | |||
| ded2fcdc7d | |||
| 0479cfca18 | |||
| 4f0a2dd3c8 | |||
| e082ad97ac | |||
| 40d8f17ce7 | |||
| 140f876164 | |||
| 5fa0fa8d17 | |||
| da8ac35932 | |||
| 9e6491b86b | |||
| fcdb0e3d80 | |||
| e42e4ee96d | |||
| a9d42403d9 | |||
| 561dd33044 | |||
| c5618bb3db | |||
| d9f5ba517d | |||
| 054ceda63a | |||
| ad0efd98ff | |||
| f0b473db2c | |||
| 58324c5d24 | |||
| 82d960c586 | |||
| ec9219ac7f | |||
| 28e7bd5304 | |||
| 4e4c2cd788 | |||
| 896c4e980c | |||
| 4262ec7386 | |||
| 08744c55ce | |||
| 6031161452 | |||
| 55c657aba6 | |||
| c4e01140a2 | |||
| c9cdf51b51 |
@ -41,8 +41,8 @@ android {
|
||||
applicationId "com.gh.gamecenter"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 21
|
||||
versionCode 15
|
||||
versionName "2.0"
|
||||
versionCode 16
|
||||
versionName "2.1"
|
||||
|
||||
// 默认的渠道
|
||||
// manifestPlaceholders = [CHANNEL_VALUE: "GH_TEST"]
|
||||
@ -118,6 +118,12 @@ android {
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.16'
|
||||
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'
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -52,7 +52,6 @@
|
||||
|
||||
<application
|
||||
android:name="com.gh.base.AppController"
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/logo"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppThemeNormal" >
|
||||
@ -62,7 +61,7 @@
|
||||
android:value="81DB144D555386A38A70B833537EC256" />
|
||||
<meta-data
|
||||
android:name="TD_CHANNEL_ID"
|
||||
android:value="${CHANNEL_VALUE}"
|
||||
android:value="GH_TEST"
|
||||
/>
|
||||
<!--android:value="${CHANNEL_VALUE}"-->
|
||||
|
||||
@ -72,7 +71,7 @@
|
||||
android:value="APV567FTBS7J"/>
|
||||
<meta-data
|
||||
android:name="InstallChannel"
|
||||
android:value="${CHANNEL_VALUE}"/>
|
||||
android:value="GH_TEST"/>
|
||||
<!--android:value="${CHANNEL_VALUE}"-->
|
||||
|
||||
<activity
|
||||
@ -133,6 +132,8 @@
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.CropImageActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity android:name="com.gh.gamecenter.WebActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.mob.tools.MobUIShell"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
@ -196,10 +197,17 @@
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name="com.gh.gamecenter.receiver.UninstallReceiver"
|
||||
android:name="com.gh.gamecenter.receiver.DownloadReceiver"
|
||||
android:exported="false" >
|
||||
<intent-filter>
|
||||
<action android:name="com.gh.gamecenter.UNINSTALL" />
|
||||
<action android:name="com.gh.gamecenter.DOWNLOAD" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name="com.gh.gamecenter.receiver.InstallReceiver"
|
||||
android:exported="false" >
|
||||
<intent-filter>
|
||||
<action android:name="com.gh.gamecenter.INSTALL" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name="com.gh.gamecenter.receiver.NetworkStateReceiver" >
|
||||
|
||||
@ -106,7 +106,7 @@ public class BasicNetwork implements Network {
|
||||
responseHeaders = convertHeaders(httpResponse.getAllHeaders());
|
||||
// Handle cache validation.
|
||||
if (statusCode == HttpStatus.SC_NOT_MODIFIED) {
|
||||
if (request.getUrl().startsWith(Config.HOST + "v2d0/support/upgrade")) {
|
||||
if (request.getUrl().startsWith(Config.HOST + "support/upgrade")) {
|
||||
if (request.getCacheEntry() != null) {
|
||||
return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED,
|
||||
request.getCacheEntry().data, responseHeaders, true);
|
||||
|
||||
@ -176,9 +176,8 @@ public class DiskBasedCache implements Cache {
|
||||
|
||||
public synchronized void modify(String key, byte[] data) {
|
||||
File file = getFileForKey(key);
|
||||
CountingInputStream cis = null;
|
||||
try {
|
||||
cis = new CountingInputStream(new FileInputStream(file));
|
||||
CountingInputStream cis = new CountingInputStream(new FileInputStream(file));
|
||||
CacheHeader e = CacheHeader.readHeader(cis); // eat header
|
||||
Entry entry = e.toCacheEntry(data);
|
||||
cis.close();
|
||||
|
||||
@ -13,6 +13,7 @@ import android.util.Log;
|
||||
import com.android.volley.Request;
|
||||
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.Utils;
|
||||
import com.xiaomi.channel.commonutils.logger.LoggerInterface;
|
||||
@ -42,6 +43,8 @@ public class AppController extends Application {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
//初始化Fresco
|
||||
Fresco.initialize(this);
|
||||
|
||||
// File dexPath = new File(getDir("dex", Context.MODE_PRIVATE), "hackdex_dex.jar");
|
||||
// DexUtils.prepareAssetsDex(this, dexPath, "hackdex_dex.jar");
|
||||
|
||||
@ -4,11 +4,14 @@ import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.gamecenter.SplashScreenActivity;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.tencent.stat.StatService;
|
||||
@ -55,18 +58,25 @@ public class AppUncaHandler implements UncaughtExceptionHandler {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Intent intent = new Intent(appController.getApplicationContext(),
|
||||
SplashScreenActivity.class);
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
PendingIntent restartIntent = PendingIntent.getActivity(
|
||||
appController.getApplicationContext(), 0, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
// 退出程序并重启
|
||||
AlarmManager mgr = (AlarmManager) appController
|
||||
.getSystemService(Context.ALARM_SERVICE);
|
||||
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000,
|
||||
restartIntent); // 1秒钟后重启应用
|
||||
// 防止重复奔溃,导致助手一直重启,20秒内不做处理
|
||||
SharedPreferences sp = appController.getApplicationContext().getSharedPreferences(
|
||||
Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
long time = sp.getLong("last_restart_time", 0);
|
||||
if (System.currentTimeMillis() - time > 20 * 1000) {
|
||||
sp.edit().putLong("last_restart_time", System.currentTimeMillis()).apply();
|
||||
Intent intent = new Intent(appController.getApplicationContext(),
|
||||
SplashScreenActivity.class);
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
PendingIntent restartIntent = PendingIntent.getActivity(
|
||||
appController.getApplicationContext(), 0, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
// 退出程序并重启
|
||||
AlarmManager mgr = (AlarmManager) appController
|
||||
.getSystemService(Context.ALARM_SERVICE);
|
||||
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000,
|
||||
restartIntent); // 1秒钟后重启应用
|
||||
}
|
||||
appController.finishActivity();
|
||||
}
|
||||
}
|
||||
@ -78,16 +88,16 @@ public class AppUncaHandler implements UncaughtExceptionHandler {
|
||||
// MTA主动上传错误
|
||||
StatService.reportError(appController.getApplicationContext(), errorMsg);
|
||||
|
||||
// WIFI实时上传错误数据
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("content", errorMsg);
|
||||
map.put("type", android.os.Build.MODEL);
|
||||
map.put("system", android.os.Build.VERSION.SDK_INT + "="
|
||||
+ android.os.Build.VERSION.RELEASE);
|
||||
DataCollectionManager.onEvent(appController.getApplicationContext(),
|
||||
"error", map, false);
|
||||
map.put("system", android.os.Build.VERSION.SDK_INT + "=" + android.os.Build.VERSION.RELEASE);
|
||||
DataCollectionManager.onEvent(appController.getApplicationContext(), "error", map,
|
||||
NetworkUtils.isWifiConnected(appController.getApplicationContext()));
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss",
|
||||
Locale.getDefault());
|
||||
// 保存到本地
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.getDefault());
|
||||
File file = new File(FileUtils.getLogPath(appController.getApplicationContext(),
|
||||
format.format(new Date()) + "_gh_assist" + ".log"));
|
||||
FileWriter writer = null;
|
||||
@ -107,6 +117,7 @@ public class AppUncaHandler implements UncaughtExceptionHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -167,7 +167,7 @@ public class BaseActivity extends Activity implements OnCallBackListener {
|
||||
public void onEventMainThread(final EBShowDialog showDialog) {
|
||||
if (!isPause && this.getClass().getName().equals(RunningUtils.getTopActivity(this))) {
|
||||
if ("hijack".equals(showDialog.getType())) {
|
||||
DialogUtils.showHijackDialog(this);
|
||||
DialogUtils.showQqSessionDialog(this, null);// 建议用户联系客服
|
||||
} else if ("plugin".equals(showDialog.getType())) {
|
||||
DialogUtils.showPluginDialog(this, new DialogUtils.ConfiremListener(){
|
||||
@Override
|
||||
|
||||
@ -158,7 +158,7 @@ public class BaseFragmentActivity extends FragmentActivity {
|
||||
public void onEventMainThread(final EBShowDialog showDialog) {
|
||||
if (!isPause && this.getClass().getName().equals(RunningUtils.getTopActivity(this))) {
|
||||
if ("hijack".equals(showDialog.getType())) {
|
||||
DialogUtils.showHijackDialog(this);
|
||||
DialogUtils.showQqSessionDialog(this, null);// 建议用户联系客服
|
||||
} else if ("plugin".equals(showDialog.getType())) {
|
||||
DialogUtils.showPluginDialog(this, new DialogUtils.ConfiremListener(){
|
||||
@Override
|
||||
|
||||
@ -36,7 +36,6 @@ import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.tencent.tauth.Tencent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -61,6 +60,7 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
protected String name;
|
||||
protected String title;
|
||||
protected String downloadAddWord;
|
||||
protected String downloadOffText;
|
||||
|
||||
protected Handler handler = new Handler();
|
||||
|
||||
@ -167,7 +167,11 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
detail_tv_download.setVisibility(View.VISIBLE);
|
||||
detail_pb_progressbar.setVisibility(View.GONE);
|
||||
detail_tv_per.setVisibility(View.GONE);
|
||||
detail_tv_download.setText("暂无下载");
|
||||
if (TextUtils.isEmpty(downloadOffText)) {
|
||||
detail_tv_download.setText("暂无下载");
|
||||
} else {
|
||||
detail_tv_download.setText(downloadOffText);
|
||||
}
|
||||
detail_tv_download.setBackgroundResource(R.drawable.game_item_btn_pause_style);
|
||||
detail_tv_download.setTextColor(0xFF999999);
|
||||
detail_tv_download.setClickable(false);
|
||||
@ -181,7 +185,7 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
isInstalled = true;
|
||||
}
|
||||
if (isInstalled) {
|
||||
if (PackageManager.isCanUpdate(gameEntity.getApk().get(0).getPackageName())) {
|
||||
if (PackageManager.isCanUpdate(gameEntity.getId(), gameEntity.getApk().get(0).getPackageName())) {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_download_style);
|
||||
@ -195,8 +199,8 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
}
|
||||
} else {
|
||||
if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& !PackageUtils.isSignature(this, gameEntity.getApk().get(0).getPackageName())
|
||||
) {
|
||||
&& !TextUtils.isEmpty(gameEntity.getApk().get(0).getGhVersion())
|
||||
&& !PackageUtils.isSignature(this, gameEntity.getApk().get(0).getPackageName())) {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_plugin_style);
|
||||
@ -240,16 +244,13 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
&& gameEntity.getApk() != null
|
||||
&& gameEntity.getApk().size() == 1) {
|
||||
String url = gameEntity.getApk().get(0).getUrl();
|
||||
List<DownloadEntity> list = DownloadManager.getInstance(getApplicationContext()).getAll();
|
||||
for (DownloadEntity entry : list) {
|
||||
if (url.equals(entry.getUrl())) {
|
||||
mDownloadEntity = entry;
|
||||
detail_tv_download.setVisibility(View.GONE);
|
||||
detail_pb_progressbar.setVisibility(View.VISIBLE);
|
||||
detail_tv_per.setVisibility(View.VISIBLE);
|
||||
invalidate();
|
||||
break;
|
||||
}
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(getApplicationContext()).get(url);
|
||||
if (downloadEntity != null) {
|
||||
mDownloadEntity = downloadEntity;
|
||||
detail_tv_download.setVisibility(View.GONE);
|
||||
detail_pb_progressbar.setVisibility(View.VISIBLE);
|
||||
detail_tv_per.setVisibility(View.VISIBLE);
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -276,6 +277,7 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
break;
|
||||
case cancel:
|
||||
case hijack:
|
||||
case notfound:
|
||||
initDownload(false);
|
||||
break;
|
||||
default:
|
||||
@ -333,7 +335,9 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
} else if (v == detail_pb_progressbar || v == detail_tv_per) {
|
||||
String str = detail_tv_per.getText().toString();
|
||||
if ("下载中".equals(str)) {
|
||||
startActivity(new Intent(this, DownloadManagerActivity.class));
|
||||
Intent intent = new Intent(this, DownloadManagerActivity.class);
|
||||
intent.putExtra("url", gameEntity.getApk().get(0).getUrl());
|
||||
startActivity(intent);
|
||||
} else if ("安装".equals(str)) {
|
||||
PackageUtils.launchSetup(this, mDownloadEntity.getPath());
|
||||
}
|
||||
@ -359,7 +363,7 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
method = "下载";
|
||||
}
|
||||
ApkEntity apkEntity = gameEntity.getApk().get(0);
|
||||
String msg = FileUtils.isCanDownload(apkEntity.getSize());
|
||||
String msg = FileUtils.isCanDownload(this, apkEntity.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
|
||||
@ -196,7 +196,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBDownloadStatus status) {
|
||||
downloadHint = (TextView) view.findViewById(R.id.action_tip);
|
||||
int updateSize = PackageManager.getUpdateListSize();
|
||||
int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size();
|
||||
if (downloadSize != 0) {
|
||||
|
||||
@ -6,7 +6,9 @@ import android.content.SharedPreferences;
|
||||
|
||||
public class Config {
|
||||
|
||||
public static final String HOST = "http://api.ghzhushou.com/";
|
||||
public static final String HOST = "http://api.ghzhushou.com/v2d1/";
|
||||
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 PREFERENCE = "ghzhushou";
|
||||
|
||||
public static boolean isShow(Context context) {
|
||||
|
||||
24
app/src/main/java/com/gh/common/constant/ItemViewType.java
Normal file
24
app/src/main/java/com/gh/common/constant/ItemViewType.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.gh.common.constant;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/10/16.
|
||||
*/
|
||||
public class ItemViewType {
|
||||
|
||||
public static final int COLUMN_HEADER = 0; // 专题头部布局
|
||||
public static final int GAME_SLIDE = 1; // 滚动图布局
|
||||
public static final int GAME_NORMAL = 2; // 正常游戏布局
|
||||
public static final int GAME_TEST = 3; // 测试游戏布局
|
||||
public static final int GAME_IMAGE = 4; // 游戏大图布局
|
||||
public static final int NEWS_HEADER = 5; // 新闻头部布局
|
||||
public static final int NEWS_TEXT = 6; // 新闻文本布局
|
||||
public static final int NEWS_IMAGE = 7; // 新闻带图布局
|
||||
public static final int NEWS_IMAGE1 = 8; // 新闻带一张小图布局
|
||||
public static final int NEWS_IMAGE2 = 9; // 新闻带三张小图布局
|
||||
public static final int NEWS_IMAGE3 = 10; // 新闻带一张大图布局
|
||||
public static final int NEWS_DIGEST = 11; // 新闻摘要布局
|
||||
public static final int SEARCH_NORMAL = 12; // 搜索正常布局
|
||||
public static final int SEARCH_DELETE = 13; // 清空历史记录布局
|
||||
public static final int LOADING = 14; // 加载布局
|
||||
|
||||
}
|
||||
87
app/src/main/java/com/gh/common/util/BitmapUtils.java
Normal file
87
app/src/main/java/com/gh/common/util/BitmapUtils.java
Normal file
@ -0,0 +1,87 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.media.ExifInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/10/21.
|
||||
*/
|
||||
public class BitmapUtils {
|
||||
|
||||
/**
|
||||
* 根据文件路径返回bitmap
|
||||
* @param filepath 文件路径
|
||||
* @param w 宽
|
||||
* @param h 高
|
||||
* @return bitmap
|
||||
*/
|
||||
public static Bitmap getBitmapByFile(String filepath, int w, int h) {
|
||||
try {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
// 设置为ture只获取图片大小
|
||||
options.inJustDecodeBounds = true;
|
||||
options.inPreferredConfig = Bitmap.Config.RGB_565;
|
||||
// 返回为空
|
||||
BitmapFactory.decodeFile(filepath, options);
|
||||
int width = options.outWidth;
|
||||
int height = options.outHeight;
|
||||
float scaleWidth = 0.f, scaleHeight = 0.f;
|
||||
if (width > w || height > h) {
|
||||
// 缩放
|
||||
scaleWidth = ((float) width) / w;
|
||||
scaleHeight = ((float) height) / h;
|
||||
}
|
||||
options.inJustDecodeBounds = false;
|
||||
int scale = (int) Math.ceil(Math.max(scaleWidth, scaleHeight));
|
||||
if (scale % 2 == 1) {
|
||||
scale += 1;
|
||||
}
|
||||
options.inSampleSize = scale;
|
||||
Bitmap bitmap = BitmapFactory.decodeFile(filepath, options);
|
||||
bitmap = rotatePicture(filepath, bitmap);
|
||||
if (bitmap != null) {
|
||||
return bitmap;
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap rotatePicture(String path, Bitmap bitmap) {
|
||||
int rotate = 0;
|
||||
try {
|
||||
ExifInterface exifInterface = new ExifInterface(path);
|
||||
int orientation = exifInterface.getAttributeInt(
|
||||
ExifInterface.TAG_ORIENTATION,
|
||||
ExifInterface.ORIENTATION_NORMAL);
|
||||
switch (orientation) {
|
||||
case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
rotate = 90;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_180:
|
||||
rotate = 180;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
rotate = 270;
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (rotate != 0) {
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.setRotate(rotate);
|
||||
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
|
||||
bitmap.getHeight(), matrix, true);
|
||||
} else {
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -21,14 +21,14 @@ public class DataUtils {
|
||||
public static void init(Application application) {
|
||||
//TalkingData
|
||||
//dubug true release false
|
||||
TCAgent.LOG_ON = false;
|
||||
TCAgent.LOG_ON = true;
|
||||
TCAgent.init(application);
|
||||
TCAgent.setReportUncaughtExceptions(true);
|
||||
|
||||
//MTA
|
||||
// 打开debug开关,可查看mta上报日志或错误
|
||||
// dubug true release false
|
||||
StatConfig.setDebugEnable(false);
|
||||
StatConfig.setDebugEnable(true);
|
||||
// 收集未处理的异常
|
||||
StatConfig.setAutoExceptionCaught(true);
|
||||
// 设置数据上报策略
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.view.View;
|
||||
@ -98,6 +100,34 @@ public class DialogUtils {
|
||||
});
|
||||
}
|
||||
|
||||
// 网络劫持时 打开QQ客户端,创建临时会话
|
||||
public static void showQqSessionDialog(final Context context, String qq) {
|
||||
if (qq == null) {
|
||||
qq = "2586716223";// 默认客服QQ
|
||||
}
|
||||
final String finalQq = qq;
|
||||
showWarningDialog(context, "警告", "您当前网络环境异常,下载地址可能被运营商恶意替换(网络劫持)" +
|
||||
",如多次下载失败,请联系客服获取正确的下载地址(客服QQ:" + qq + ")"
|
||||
, "取消", "前往QQ", new ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
if (ShareUtils.isQQClientAvailable(context)) {
|
||||
//安装了QQ会直接调用QQ,打开手机QQ进行会话 QQ号:2586716223
|
||||
String str = "mqqwpa://im/chat?chat_type=wpa&uin=" + finalQq + "&version=1&src_type=web&web_src=oicqzone.com";
|
||||
Uri uri = Uri.parse(str);
|
||||
Intent it = new Intent(Intent.ACTION_VIEW, uri);
|
||||
context.startActivity(it);
|
||||
} else {
|
||||
//没有安装QQ 复制账号
|
||||
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cmb.setText(finalQq);
|
||||
Utils.toast(context,"已复制" + finalQq);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
|
||||
public static void showWarningDialog(Context context, String title, CharSequence msg, final ConfiremListener listener) {
|
||||
showWarningDialog(context, title, msg, "取消", "确定", listener, null);
|
||||
}
|
||||
|
||||
@ -27,35 +27,23 @@ import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class DownloadItemUtils {
|
||||
|
||||
// 初始化gameMap
|
||||
public static void initializeGameMap(Context context, ArrayMap<String, ArrayMap<String, DownloadEntity>> gameMap) {
|
||||
gameMap.clear();
|
||||
List<DownloadEntity> list = DownloadManager.getInstance(context).getAll();
|
||||
String name;
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
name = list.get(i).getName();
|
||||
ArrayMap<String, DownloadEntity> map = gameMap.get(name);
|
||||
if (map == null) {
|
||||
map = new ArrayMap<>();
|
||||
gameMap.put(name, map);
|
||||
}
|
||||
map.put(list.get(i).getPlatform(), list.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
// 更新下载进度条
|
||||
public static void processDate(Context context,
|
||||
GameEntity detailedEntity,
|
||||
GameEntity gameEntity,
|
||||
DownloadEntity downloadEntity,
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> adapter,
|
||||
int index) {
|
||||
|
||||
if (!gameEntity.getId().equals(downloadEntity.getGameId())) {
|
||||
adapter.notifyItemChanged(index);
|
||||
return;
|
||||
}
|
||||
|
||||
LinkedBlockingQueue<String> queue = DownloadManager.getInstance(context).getQueue(downloadEntity.getName());
|
||||
if (queue == null) {
|
||||
queue = new LinkedBlockingQueue<>();
|
||||
@ -63,7 +51,7 @@ public class DownloadItemUtils {
|
||||
}
|
||||
|
||||
String platform = downloadEntity.getPlatform();
|
||||
ArrayMap<String, DownloadEntity> entryMap = detailedEntity.getEntryMap();
|
||||
ArrayMap<String, DownloadEntity> entryMap = gameEntity.getEntryMap();
|
||||
|
||||
DownloadStatus status = downloadEntity.getStatus();
|
||||
if (status.equals(DownloadStatus.pause)
|
||||
@ -72,7 +60,7 @@ public class DownloadItemUtils {
|
||||
queue.remove(platform);
|
||||
if (entryMap == null) {
|
||||
entryMap = new ArrayMap<>();
|
||||
detailedEntity.setEntryMap(entryMap);
|
||||
gameEntity.setEntryMap(entryMap);
|
||||
}
|
||||
entryMap.put(platform, downloadEntity);
|
||||
if (!"pause".equals(DownloadManager.getInstance(context).getStatus(downloadEntity.getUrl()))) {
|
||||
@ -91,7 +79,7 @@ public class DownloadItemUtils {
|
||||
if (platform.equals(queue.peek())) {
|
||||
if (entryMap == null) {
|
||||
entryMap = new ArrayMap<>();
|
||||
detailedEntity.setEntryMap(entryMap);
|
||||
gameEntity.setEntryMap(entryMap);
|
||||
}
|
||||
entryMap.put(platform, downloadEntity);
|
||||
if (!"pause".equals(DownloadManager.getInstance(context).getStatus(downloadEntity.getUrl()))) {
|
||||
@ -109,17 +97,13 @@ public class DownloadItemUtils {
|
||||
TextView download_speed,
|
||||
TextView download_percentage,
|
||||
TextView downloadBtn,
|
||||
GameEntity entity,
|
||||
GameEntity gameEntity,
|
||||
boolean isShowPlatform) {
|
||||
|
||||
ArrayMap<String, DownloadEntity> entryMap = entity.getEntryMap();
|
||||
ArrayMap<String, DownloadEntity> entryMap = gameEntity.getEntryMap();
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
|
||||
DownloadEntity downloadEntity = entryMap.get(entryMap.keyAt(0));
|
||||
if (!downloadEntity.isPluggable()
|
||||
|| entity.getApk().get(0).getPlatform().equals(downloadEntity.getPlatform())
|
||||
|| entity.getApk().get(0).getPlatform().equals("local_plugin")
|
||||
|| downloadEntity.getPlatform().equals("local_plugin")) {
|
||||
DownloadEntity downloadEntity = entryMap.get(gameEntity.getApk().get(0).getPlatform());
|
||||
if (downloadEntity != null) {
|
||||
// 更改进度条和提示文本的状态
|
||||
changeStatus(context, textView, game_progressbar, game_ll_info, download_speed, download_percentage, downloadBtn,
|
||||
downloadEntity, isShowPlatform, true);
|
||||
@ -132,18 +116,37 @@ public class DownloadItemUtils {
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
|
||||
downloadBtn.setTextColor(Color.WHITE);
|
||||
if (entity.isPluggable()) {
|
||||
if (gameEntity.isPluggable()) {
|
||||
downloadBtn.setText("插件化");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else if (PackageManager.isInstalled(entity.getApk().get(0).getPackageName())) {
|
||||
if (PackageManager.isCanUpdate(entity.getApk().get(0).getPackageName())) {
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(context).getByPackage(
|
||||
gameEntity.getApk().get(0).getPackageName());
|
||||
if (downloadEntity == null
|
||||
|| downloadEntity.getUrl().equals(gameEntity.getApk().get(0).getUrl())) {
|
||||
downloadBtn.setClickable(true);
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else {
|
||||
downloadBtn.setClickable(false);
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_pause_up);
|
||||
}
|
||||
} else if (PackageManager.isInstalled(gameEntity.getApk().get(0).getPackageName())) {
|
||||
if (PackageManager.isCanUpdate(gameEntity.getId(), gameEntity.getApk().get(0).getPackageName())) {
|
||||
downloadBtn.setText("更新");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
} else {
|
||||
if (entity.getTag() != null && entity.getTag().size() != 0
|
||||
&& !PackageUtils.isSignature(context, entity.getApk().get(0).getPackageName())) {
|
||||
if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& !TextUtils.isEmpty(gameEntity.getApk().get(0).getGhVersion())
|
||||
&& !PackageUtils.isSignature(context, gameEntity.getApk().get(0).getPackageName())) {
|
||||
downloadBtn.setText("插件化");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(context).getByPackage(
|
||||
gameEntity.getApk().get(0).getPackageName());
|
||||
if (downloadEntity == null
|
||||
|| downloadEntity.getUrl().equals(gameEntity.getApk().get(0).getUrl())) {
|
||||
downloadBtn.setClickable(true);
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else {
|
||||
downloadBtn.setClickable(false);
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_pause_up);
|
||||
}
|
||||
} else {
|
||||
downloadBtn.setText("启动");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
@ -153,7 +156,6 @@ public class DownloadItemUtils {
|
||||
downloadBtn.setText("下载");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 更新插件的条目,有多个apk包
|
||||
@ -183,7 +185,7 @@ public class DownloadItemUtils {
|
||||
}
|
||||
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
if (PackageManager.isCanUpdate(apkEntity.getPackageName())) {
|
||||
if (PackageManager.isCanUpdate(entity.getId(), apkEntity.getPackageName())) {
|
||||
updateCount++;
|
||||
}
|
||||
}
|
||||
@ -347,6 +349,10 @@ public class DownloadItemUtils {
|
||||
downloadBtn.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if ("光环助手".equals(entity.getName())) {
|
||||
downloadBtn.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
textView.setVisibility(View.VISIBLE);
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
@ -416,7 +422,9 @@ public class DownloadItemUtils {
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(context, gameEntity.getApk().get(0).getPackageName());
|
||||
} else if ("下载中".equals(str)) {
|
||||
context.startActivity(new Intent(context, DownloadManagerActivity.class));
|
||||
Intent intent = new Intent(context, DownloadManagerActivity.class);
|
||||
intent.putExtra("url", gameEntity.getApk().get(0).getUrl());
|
||||
context.startActivity(intent);
|
||||
} else if ("更新".equals(str)) {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
update(context, gameEntity, entrance, location);
|
||||
@ -496,7 +504,7 @@ public class DownloadItemUtils {
|
||||
TextView downloadBtn,
|
||||
String entrance,
|
||||
String location) {
|
||||
String msg = FileUtils.isCanDownload(gameEntity.getApk().get(0).getSize());
|
||||
String msg = FileUtils.isCanDownload(context, gameEntity.getApk().get(0).getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", gameEntity.getApk().get(0).getPlatform());
|
||||
@ -546,7 +554,7 @@ public class DownloadItemUtils {
|
||||
TextView downloadBtn,
|
||||
String entrance,
|
||||
String location) {
|
||||
String msg = FileUtils.isCanDownload(gameEntity.getApk().get(0).getSize());
|
||||
String msg = FileUtils.isCanDownload(context, gameEntity.getApk().get(0).getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", gameEntity.getApk().get(0).getPlatform());
|
||||
@ -601,8 +609,8 @@ public class DownloadItemUtils {
|
||||
if (FileUtils.isEmptyFile(path)) {
|
||||
Toast.makeText(context, "解析包出错(可能被误删了),请重新下载", Toast.LENGTH_SHORT).show();
|
||||
DownloadManager.getInstance(context).cancel(downloadEntity.getUrl());
|
||||
if (gameEntity.getEntryMap() != null && !gameEntity.getEntryMap().isEmpty()) {
|
||||
gameEntity.getEntryMap().remove(gameEntity.getEntryMap().keyAt(0));
|
||||
if (gameEntity.getEntryMap() != null) {
|
||||
gameEntity.getEntryMap().remove(gameEntity.getApk().get(0).getPlatform());
|
||||
}
|
||||
adapter.notifyItemChanged(position);
|
||||
} else {
|
||||
|
||||
@ -5,7 +5,6 @@ import android.os.Environment;
|
||||
import android.os.StatFs;
|
||||
import android.os.StrictMode;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@ -38,7 +37,11 @@ public class FileUtils {
|
||||
File file = new File(dir + File.separator + TEST_FILE_NAME);
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
if (!file.createNewFile()) {
|
||||
// cannot create file
|
||||
Utils.log("cannot create file");
|
||||
dir = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
//cannot create file
|
||||
@ -96,21 +99,6 @@ public class FileUtils {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void checkDirExists(String dirName) {
|
||||
File file = Environment.getExternalStorageDirectory();
|
||||
if (file.isDirectory()) {
|
||||
File[] fs = file.listFiles();
|
||||
for (int i = 0; i < fs.length; i++) {
|
||||
if (fs[i].isDirectory()
|
||||
&& fs[i].getName().equalsIgnoreCase(dirName)
|
||||
&& !fs[i].getName().equals(dirName)) {
|
||||
fs[i].delete();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isMounted() {
|
||||
return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
|
||||
@ -140,7 +128,7 @@ public class FileUtils {
|
||||
return availableBlocks * blockSize / 1024f / 1024f;
|
||||
}
|
||||
|
||||
public static String isCanDownload(String size) {
|
||||
public static String isCanDownload(Context context, String size) {
|
||||
String msg = null;
|
||||
String packageSizeStr = "";
|
||||
for (int i = 0; i < size.length(); i++) {
|
||||
@ -152,8 +140,7 @@ public class FileUtils {
|
||||
if (packageSizeStr.length() != 0) {
|
||||
packageSize = Float.valueOf(packageSizeStr);
|
||||
}
|
||||
float freeSpace = getFreeSpaceByPath(Environment
|
||||
.getExternalStorageDirectory().getAbsolutePath());
|
||||
float freeSpace = getFreeSpaceByPath(getDownloadDir(context));
|
||||
if (freeSpace < packageSize) {
|
||||
msg = "手机存储空间不足,无法进行下载!";
|
||||
}
|
||||
@ -256,7 +243,7 @@ public class FileUtils {
|
||||
// 设置每次写入8192bytes
|
||||
int bufferSize = 8192;
|
||||
byte[] buffer = new byte[bufferSize]; // 8k
|
||||
int length = -1;
|
||||
int length;
|
||||
// 从文件读取数据至缓冲区
|
||||
while ((length = fStream.read(buffer)) != -1) {
|
||||
// 将资料写入DataOutputStream中
|
||||
@ -286,14 +273,14 @@ public class FileUtils {
|
||||
|
||||
int statusCode = connection.getResponseCode();
|
||||
Utils.log("statusCode = " + statusCode);
|
||||
if (statusCode == HttpStatus.SC_OK) {
|
||||
if (statusCode == HttpURLConnection.HTTP_OK) {
|
||||
// {"icon":"http:\/\/gh-test-1.oss-cn-qingdao.aliyuncs.com\/pic\/57e4f4d58a3200042d29492f.jpg"}
|
||||
JSONObject response = new JSONObject(b.toString().trim());
|
||||
response.put("statusCode", HttpStatus.SC_OK);
|
||||
response.put("statusCode", HttpURLConnection.HTTP_OK);
|
||||
return response;
|
||||
} else if (statusCode == HttpStatus.SC_FORBIDDEN) {
|
||||
} else if (statusCode == HttpURLConnection.HTTP_FORBIDDEN) {
|
||||
JSONObject response = new JSONObject(b.toString().trim());
|
||||
response.put("statusCode", HttpStatus.SC_FORBIDDEN);
|
||||
response.put("statusCode", HttpURLConnection.HTTP_FORBIDDEN);
|
||||
return response;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -41,22 +41,6 @@ public class GameViewUtils {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取游戏标签列表视图
|
||||
public static void setLabelList(Context context, LinearLayout labelLayout, String tag) {
|
||||
labelLayout.removeAllViews();
|
||||
// 添加tag标签
|
||||
if (tag != null && !tag.isEmpty()) {
|
||||
String[] tags = tag.split(",");
|
||||
for (int i = 0; i < tags.length; i++) {
|
||||
if (i == tags.length - 1) {
|
||||
labelLayout.addView(getGameTagView(context, tags[i], 0));
|
||||
} else {
|
||||
labelLayout.addView(getGameTagView(context, tags[i], DisplayUtils.dip2px(context, 5)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TextView getGameTagView(Context context, String tagStr, int rightMargin) {
|
||||
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
||||
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
|
||||
@ -1,291 +1,161 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Matrix;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.view.View;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.net.Uri;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
|
||||
import com.gh.common.view.CircleImageView;
|
||||
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;
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class ImageUtils {
|
||||
private static ImageUtils singleton;
|
||||
private static ImageLoader imageLoader;
|
||||
private static DisplayImageOptions options;
|
||||
private ArrayMap<String, WeakReference<Bitmap>> imageCache = new ArrayMap<String, WeakReference<Bitmap>>();
|
||||
|
||||
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
|
||||
|
||||
public static ImageUtils getInstance(Context context) {
|
||||
if (singleton == null) {
|
||||
synchronized (ImageUtils.class) {
|
||||
if (singleton == null) {
|
||||
singleton = new ImageUtils(context.getApplicationContext(),
|
||||
(int) Runtime.getRuntime().maxMemory() / 10);
|
||||
singleton = new ImageUtils();
|
||||
return singleton;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return singleton;
|
||||
}
|
||||
|
||||
private ImageUtils(Context context, int size) {
|
||||
|
||||
options = new DisplayImageOptions.Builder().cacheInMemory(true)
|
||||
.cacheOnDisk(true).considerExifParams(true)
|
||||
.bitmapConfig(Bitmap.Config.RGB_565)
|
||||
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
|
||||
// .showImageOnLoading(R.drawable.ocupy)
|
||||
// .showImageForEmptyUri(R.drawable.ocupy)
|
||||
// .showImageOnFail(R.drawable.ocupy)
|
||||
// 自适应图片宽高
|
||||
public void display (String url , final SimpleDraweeView simpleDraweeView, final Context context, final int paddingSize){
|
||||
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();
|
||||
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;
|
||||
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()
|
||||
.setUri(url)
|
||||
.setControllerListener(listener)
|
||||
.build();
|
||||
|
||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
|
||||
context).writeDebugLogs()
|
||||
.memoryCacheExtraOptions(480, 800)
|
||||
.build();
|
||||
simpleDraweeView.setController(controller);
|
||||
|
||||
ImageLoader.getInstance().init(config);
|
||||
imageLoader = ImageLoader.getInstance();
|
||||
}
|
||||
|
||||
public void displayFile(String url, ImageView imageView) {
|
||||
imageLoader.displayImage(url, imageView, options,
|
||||
new ImageLoadingListener() {
|
||||
//设置缩放类型,设置按压状态下的叠加图
|
||||
public void display (String url , SimpleDraweeView simpleDraweeView, ScalingUtils.ScaleType scaleType, Context context){
|
||||
GenericDraweeHierarchyBuilder builder =
|
||||
new GenericDraweeHierarchyBuilder(context.getResources());
|
||||
GenericDraweeHierarchy hierarchy = builder
|
||||
.setFadeDuration(500)
|
||||
.setPressedStateOverlay(new ColorDrawable(context.getResources().getColor(R.color.pressed_bg)))
|
||||
.setPlaceholderImage(R.drawable.ocupy2, ScalingUtils.ScaleType.CENTER)
|
||||
.setBackground(new ColorDrawable(Color.parseColor("#ececec")))
|
||||
.setActualImageScaleType(scaleType)
|
||||
.build();
|
||||
simpleDraweeView.setHierarchy(hierarchy);
|
||||
simpleDraweeView.setImageURI(url);
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String arg0, View arg1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingComplete(String arg0, View view,
|
||||
Bitmap arg2) {
|
||||
AlphaAnimation animation = new AlphaAnimation(0f, 1f);
|
||||
animation.setDuration(500);
|
||||
view.startAnimation(animation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String arg0, View arg1,
|
||||
FailReason arg2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingStarted(String arg0, View arg1) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
//增加一个上下文环境,图片宽度设最大(paddSize为左右边距大小),高度自适应
|
||||
public void display(String url, ImageView imageView, int drawable, Context context, int paddingSize) {
|
||||
display(url, imageView, drawable, ScaleType.FIT_XY, null, context, paddingSize);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, int drawable) {
|
||||
display(url, imageView, drawable, ScaleType.FIT_XY, null);
|
||||
//设置占位符
|
||||
public void display (String url , SimpleDraweeView simpleDraweeView, int placeholderImage, Context context){
|
||||
|
||||
GenericDraweeHierarchyBuilder builder =
|
||||
new GenericDraweeHierarchyBuilder(context.getResources());
|
||||
GenericDraweeHierarchy hierarchy = builder
|
||||
.setFadeDuration(500)
|
||||
.setPressedStateOverlay(new ColorDrawable(context.getResources().getColor(R.color.pressed_bg)))
|
||||
.setBackground(new ColorDrawable(Color.parseColor("#ececec")))
|
||||
.setPlaceholderImage(placeholderImage)
|
||||
.build();
|
||||
simpleDraweeView.setHierarchy(hierarchy);
|
||||
simpleDraweeView.setImageURI(url);
|
||||
|
||||
}
|
||||
|
||||
public void display(final String url, final ImageView imageView,
|
||||
final int drawable, final ScaleType scaleType,
|
||||
final OnLoadingCompleteListener listener) {
|
||||
imageLoader.displayImage(url, imageView, options,
|
||||
new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view,
|
||||
Bitmap loadedImage) {
|
||||
if (imageView instanceof CircleImageView) {
|
||||
imageView.setScaleType(ScaleType.CENTER_CROP);
|
||||
} else {
|
||||
imageView.setScaleType(scaleType);
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onLoadingComplete();
|
||||
}
|
||||
}
|
||||
//图片下载监听和设置低高分辨率图片
|
||||
public void display (String url, String lowUrl, SimpleDraweeView simpleDraweeView, ControllerListener listener){
|
||||
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
if (imageView instanceof CircleImageView) {
|
||||
imageView.setScaleType(ScaleType.CENTER_CROP);
|
||||
} else {
|
||||
imageView.setScaleType(ScaleType.CENTER);
|
||||
}
|
||||
if (drawable != -1) {
|
||||
imageView.setImageResource(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view,
|
||||
FailReason reason) {
|
||||
|
||||
}
|
||||
});
|
||||
DraweeController controller = Fresco.newDraweeControllerBuilder()
|
||||
.setImageRequest(ImageRequest.fromUri(url))
|
||||
.setControllerListener(listener)
|
||||
.setLowResImageRequest(ImageRequest.fromUri(lowUrl)) //低分辨率图片
|
||||
.build();
|
||||
simpleDraweeView.setController(controller);
|
||||
}
|
||||
|
||||
public void display(final String url, final ImageView imageView,
|
||||
final int drawable, final ScaleType scaleType,
|
||||
final OnLoadingCompleteListener listener, final Context context, final int paddSize) {
|
||||
imageLoader.displayImage(url, imageView, options,
|
||||
new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view,
|
||||
Bitmap loadedImage) {
|
||||
int width = loadedImage.getWidth();
|
||||
int height = loadedImage.getHeight();
|
||||
int widthPixels = context.getResources().getDisplayMetrics().widthPixels;
|
||||
widthPixels = widthPixels - DisplayUtils.dip2px(context,paddSize);
|
||||
float index = (float) height / (float) width;
|
||||
int newHeight = (int)(index * widthPixels);
|
||||
public void display (String url, SimpleDraweeView simpleDraweeView, ControllerListener listener){
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
|
||||
if (layoutParams != null){
|
||||
layoutParams.height = newHeight;
|
||||
layoutParams.width = widthPixels;
|
||||
imageView.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
if (imageView instanceof CircleImageView) {
|
||||
imageView.setScaleType(ScaleType.CENTER_CROP);
|
||||
} else {
|
||||
imageView.setScaleType(scaleType);
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onLoadingComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
imageView.setScaleType(ScaleType.CENTER);
|
||||
if (drawable != -1) {
|
||||
imageView.setImageResource(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view,
|
||||
FailReason reason) {
|
||||
|
||||
}
|
||||
});
|
||||
DraweeController controller = Fresco.newDraweeControllerBuilder()
|
||||
.setImageRequest(ImageRequest.fromUri(url))
|
||||
.setControllerListener(listener)
|
||||
.build();
|
||||
simpleDraweeView.setController(controller);
|
||||
}
|
||||
|
||||
public void display(final String url, final ImageView imageView,
|
||||
final int drawable, final ScaleType scaleType,
|
||||
final OnLoadingCompleteListener listener, final int i) {
|
||||
imageLoader.displayImage(url, imageView, options,
|
||||
new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view,
|
||||
Bitmap loadedImage) {
|
||||
WeakReference<Bitmap> bitmapWeakReference = imageCache.get(imageUri);
|
||||
try {
|
||||
if (bitmapWeakReference!=null){
|
||||
Bitmap bitmap = bitmapWeakReference.get();
|
||||
imageView.setImageBitmap(bitmap);
|
||||
}else {
|
||||
Matrix m = new Matrix();
|
||||
m.setRotate(i, (float) loadedImage.getWidth() / 2, (float) loadedImage.getHeight() / 2);
|
||||
Bitmap bm1 = Bitmap.createBitmap(loadedImage, 0, 0, loadedImage.getWidth(), loadedImage.getHeight(), m, true);
|
||||
imageView.setImageBitmap(bm1);
|
||||
WeakReference<Bitmap> weakBM = new WeakReference<Bitmap>(bm1);
|
||||
imageCache.put(imageUri, weakBM);
|
||||
}
|
||||
//获取bitmap
|
||||
public void display (String url, BaseBitmapDataSubscriber dataSubscriber, Context context){
|
||||
ImageRequest imageRequest = ImageRequestBuilder
|
||||
.newBuilderWithSource(Uri.parse(url))
|
||||
.setProgressiveRenderingEnabled(true)
|
||||
.build();
|
||||
|
||||
} catch (OutOfMemoryError ex) {
|
||||
Utils.log("Bitmap:::内存溢出");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (imageView instanceof CircleImageView) {
|
||||
imageView.setScaleType(ScaleType.CENTER_CROP);
|
||||
} else {
|
||||
imageView.setScaleType(scaleType);
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onLoadingComplete();
|
||||
}
|
||||
}
|
||||
ImagePipeline imagePipeline = Fresco.getImagePipeline();
|
||||
DataSource<CloseableReference<CloseableImage>>
|
||||
dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
|
||||
dataSource.subscribe(dataSubscriber, CallerThreadExecutor.getInstance());
|
||||
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
imageView.setScaleType(ScaleType.CENTER);
|
||||
if (drawable != -1) {
|
||||
imageView.setImageResource(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view,
|
||||
FailReason reason) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//获取图片BitMap
|
||||
public void loadBitmap(String url, ImageLoadingListener listener){
|
||||
imageLoader.loadImage(url, listener);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, ScaleType scaleType) {
|
||||
display(url, imageView, R.drawable.ocupy, scaleType, null);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView) {
|
||||
display(url, imageView, R.drawable.ocupy, ScaleType.FIT_XY, null);
|
||||
}
|
||||
|
||||
//旋转图片 i表示角度
|
||||
public void display(String url, ImageView imageView, int i, boolean isHorizontal) {
|
||||
display(url, imageView, R.drawable.ocupy, ScaleType.FIT_XY, null, i);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, ScaleType scaleType, OnLoadingCompleteListener listener) {
|
||||
display(url, imageView, R.drawable.ocupy, scaleType, listener);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, OnLoadingCompleteListener listener) {
|
||||
display(url, imageView, R.drawable.ocupy, ScaleType.FIT_XY, listener);
|
||||
}
|
||||
|
||||
public interface OnLoadingCompleteListener {
|
||||
void onLoadingComplete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
85
app/src/main/java/com/gh/common/util/NotificationUtils.java
Normal file
85
app/src/main/java/com/gh/common/util/NotificationUtils.java
Normal file
@ -0,0 +1,85 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadStatus;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/10/10.
|
||||
*/
|
||||
public class NotificationUtils {
|
||||
|
||||
public static void showDownloadDoneNotification(Context context, DownloadEntity downloadEntity, int flag) {
|
||||
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("path", downloadEntity.getPath());
|
||||
intent.setAction("com.gh.gamecenter.INSTALL");
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, flag,
|
||||
intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
String text;
|
||||
String title;
|
||||
if (downloadEntity.isPluggable()) {
|
||||
text = "下载完成,点击继续插件化";
|
||||
title = downloadEntity.getName() + "-"
|
||||
+ PlatformUtils.getInstance(context).getPlatformName(downloadEntity.getPlatform());
|
||||
} else {
|
||||
if (downloadEntity.isPlugin()) {
|
||||
text = downloadEntity.getName() + "-"
|
||||
+ PlatformUtils.getInstance(context).getPlatformName(downloadEntity.getPlatform()) + " 下载完成";
|
||||
} else {
|
||||
text = downloadEntity.getName() + " 下载完成";
|
||||
}
|
||||
title = "点击立即安装";
|
||||
}
|
||||
Notification notification = new NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.logo)
|
||||
.setTicker(text)
|
||||
.setContentTitle(title)
|
||||
.setContentText(text)
|
||||
.setContentIntent(pendingIntent).build();
|
||||
// notification.defaults = Notification.DEFAULT_SOUND;// 添加系统默认声音
|
||||
notification.flags |= Notification.FLAG_AUTO_CANCEL; // // FLAG_AUTO_CANCEL表明当通知被用户点击时,通知将被清除。
|
||||
nManager.notify(flag, notification);
|
||||
}
|
||||
|
||||
public static void showDownloadingNotification(Context context) {
|
||||
int downloadingSize = 0;
|
||||
for (DownloadEntity entity : DownloadManager.getInstance(context).getAll()) {
|
||||
if (entity.getStatus().equals(DownloadStatus.downloading)
|
||||
|| entity.getStatus().equals(DownloadStatus.waiting)
|
||||
|| entity.getStatus().equals(DownloadStatus.pause)
|
||||
|| entity.getStatus().equals(DownloadStatus.timeout)
|
||||
|| entity.getStatus().equals(DownloadStatus.neterror)) {
|
||||
downloadingSize++;
|
||||
}
|
||||
}
|
||||
if (downloadingSize == 0) {
|
||||
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nManager.cancel(0x123);
|
||||
} else {
|
||||
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("com.gh.gamecenter.DOWNLOAD");
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0x123,
|
||||
intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
Notification notification = new NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.logo)
|
||||
.setTicker("你有" + downloadingSize + "个游戏正在下载中")
|
||||
.setContentTitle("点击查看详情")
|
||||
.setContentText("你有" + downloadingSize + "个游戏正在下载中")
|
||||
.setContentIntent(pendingIntent).build();
|
||||
// notification.defaults = Notification.DEFAULT_SOUND;// 添加系统默认声音
|
||||
notification.flags |= Notification.FLAG_NO_CLEAR; // 通知无法手动清除
|
||||
nManager.notify(0x123, notification);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -9,18 +9,14 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.Signature;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.manager.FilterManager;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
@ -31,65 +27,6 @@ public class PackageUtils {
|
||||
|
||||
public static final String publicKey = "OpenSSLRSAPublicKey{modulus=a8c4bb5748fec8d5c35db1a7a182d41ba4721a91131a417330af79ef4ddb43f9fa0ff4907b0a613bfe152de0ed8fc1b2e6f94a908aa98a5f7adc1ce814ba7ec919d75d9910bdfd8649b4789da6a90ffb61f0d23ac4f828a78fcd0d6f6120c1c43c1f87f7498a89eb40ca8e32dfc2f9d5c10d612b95192870223674e241e53305abf320d7eed76ded398778576e4db7b17b3bc6a792f13de5e43a6a5fae4276c73e6990ce97f68dff0ec16fc9594f175c8d49cd0d7877340d9de60942ca0efc737e50b6c295dfe0713e4532b4e810e1ea11b702b4a27753e41559cbceb247e7f044ec4e3ab2e8bccd8b9fd71286e63307550bcde86deee95adb8133076269135b,publicExponent=10001}";
|
||||
|
||||
/*
|
||||
* 根据apk路径,获取apk的签名信息,耗时
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static String getApkSignatureByPath(Context context, String path) {
|
||||
String PATH_PackageParser = "android.content.pm.PackageParser";
|
||||
try {
|
||||
// apk包的文件路径
|
||||
// 这是一个Package 解释器, 是隐藏的
|
||||
// 构造函数的参数只有一个, apk文件的路径
|
||||
// PackageParser packageParser = new PackageParser(apkPath);
|
||||
Class pkgParserCls = Class.forName(PATH_PackageParser);
|
||||
Class[] typeArgs = new Class[1];
|
||||
typeArgs[0] = String.class;
|
||||
Constructor pkgParserCt = pkgParserCls.getConstructor(typeArgs);
|
||||
Object[] valueArgs = new Object[1];
|
||||
valueArgs[0] = path;
|
||||
Object pkgParser = pkgParserCt.newInstance(valueArgs);
|
||||
// 这个是与显示有关的, 里面涉及到一些像素显示等等, 我们使用默认的情况
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
metrics.setToDefaults();
|
||||
// PackageParser.Package mPkgInfo = packageParser.parsePackage(new
|
||||
// File(apkPath), apkPath,
|
||||
// metrics, 0);
|
||||
typeArgs = new Class[4];
|
||||
typeArgs[0] = File.class;
|
||||
typeArgs[1] = String.class;
|
||||
typeArgs[2] = DisplayMetrics.class;
|
||||
typeArgs[3] = Integer.TYPE;
|
||||
Method pkgParser_parsePackageMtd = pkgParserCls.getDeclaredMethod(
|
||||
"parsePackage", typeArgs);
|
||||
valueArgs = new Object[4];
|
||||
valueArgs[0] = new File(path);
|
||||
valueArgs[1] = path;
|
||||
valueArgs[2] = metrics;
|
||||
valueArgs[3] = PackageManager.GET_SIGNATURES;
|
||||
Object pkgParserPkg = pkgParser_parsePackageMtd.invoke(pkgParser,
|
||||
valueArgs);
|
||||
|
||||
typeArgs = new Class[2];
|
||||
typeArgs[0] = pkgParserPkg.getClass();
|
||||
typeArgs[1] = Integer.TYPE;
|
||||
Method pkgParser_collectCertificatesMtd = pkgParserCls
|
||||
.getDeclaredMethod("collectCertificates", typeArgs);
|
||||
valueArgs = new Object[2];
|
||||
valueArgs[0] = pkgParserPkg;
|
||||
valueArgs[1] = PackageManager.GET_SIGNATURES;
|
||||
pkgParser_collectCertificatesMtd.invoke(pkgParser, valueArgs);
|
||||
// 应用程序信息包, 这个公开的, 不过有些函数, 变量没公开
|
||||
Field packageInfoFld = pkgParserPkg.getClass().getDeclaredField(
|
||||
"mSignatures");
|
||||
Signature[] info = (Signature[]) packageInfoFld.get(pkgParserPkg);
|
||||
return parseSignature(info[0].toByteArray())[0];
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据路径,获取apk的包名
|
||||
*/
|
||||
@ -104,6 +41,9 @@ public class PackageUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取meta-data
|
||||
*/
|
||||
public static Object getMetaData(Context context, String packageName, String name) {
|
||||
try {
|
||||
Bundle metaDate = context.getPackageManager().getApplicationInfo(
|
||||
@ -120,8 +60,7 @@ public class PackageUtils {
|
||||
/*
|
||||
* 根据包名,获取apk的签名信息
|
||||
*/
|
||||
public static String getApkSignatureByPackageName(Context context,
|
||||
String packageName) {
|
||||
public static String getApkSignatureByPackageName(Context context, String packageName) {
|
||||
try {
|
||||
PackageInfo packageInfo = context.getPackageManager()
|
||||
.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
|
||||
@ -133,6 +72,31 @@ public class PackageUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* 判断是否可以更新
|
||||
*/
|
||||
public static boolean isCanUpdate(Context context, GameUpdateEntity gameUpdateEntity) {
|
||||
// 判断是否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;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* 判断是否是插件包
|
||||
*/
|
||||
@ -144,16 +108,16 @@ public class PackageUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* 根据apk路径,获取apk包名、签名 根据包名 判断 是否已安装游戏 根据签名 判断 是否一致
|
||||
*
|
||||
* @param path apk路径
|
||||
* @return true 可执行安装 false 要卸载已安装的,再执行安装
|
||||
*/
|
||||
public static boolean isCanLaunchSetup(Context context, String path) {
|
||||
String packageName = getPackageNameByPath(context, path);
|
||||
|
||||
boolean isContain = isContain(context, packageName);
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
return true;
|
||||
}
|
||||
boolean isContain = com.gh.gamecenter.manager.PackageManager.isInstalled(packageName);
|
||||
if (!isContain) {
|
||||
return true;
|
||||
}
|
||||
@ -229,6 +193,9 @@ public class PackageUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取apk的版本
|
||||
*/
|
||||
public static String getVersionByPackage(Context context, String packageName) {
|
||||
try {
|
||||
return context.getPackageManager().getPackageInfo(packageName,
|
||||
@ -239,12 +206,8 @@ public class PackageUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* 获取所有已安装的软件的包名、版本(非系统应用)
|
||||
*
|
||||
* @param context
|
||||
* 上下文
|
||||
* @return 已安装软件的包名的集合
|
||||
*/
|
||||
public static ArrayList<String> getAllPackageName(Context context) {
|
||||
FilterManager filterManager = new FilterManager(context);
|
||||
@ -263,6 +226,9 @@ public class PackageUtils {
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
* 启动应用
|
||||
*/
|
||||
public static void launchApplicationByPackageName(Context context,
|
||||
String packageName) {
|
||||
Intent intent = context.getPackageManager().getLaunchIntentForPackage(
|
||||
@ -294,33 +260,8 @@ public class PackageUtils {
|
||||
* 根据包名,判断是否已安装该游戏
|
||||
*/
|
||||
public static boolean isInstalled(Context context, String packageName) {
|
||||
Intent intent = context.getPackageManager().getLaunchIntentForPackage(
|
||||
packageName);
|
||||
if (intent == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static ArrayMap<String, Boolean> map;
|
||||
|
||||
public static boolean isContain(Context context, String packageName) {
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
return false;
|
||||
}
|
||||
if (map == null) {
|
||||
map = new ArrayMap<>();
|
||||
List<PackageInfo> infos = context.getPackageManager()
|
||||
.getInstalledPackages(0);
|
||||
for (PackageInfo info : infos) {
|
||||
map.put(info.packageName, true);
|
||||
}
|
||||
}
|
||||
Boolean b = map.get(packageName);
|
||||
if (b != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
|
||||
return intent != null;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -347,13 +288,4 @@ public class PackageUtils {
|
||||
return installIntent;
|
||||
}
|
||||
|
||||
public static String getInstalledApkPath(Context context, String packageName) {
|
||||
try {
|
||||
return context.getPackageManager().getApplicationInfo(packageName,
|
||||
0).sourceDir;
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,13 +15,13 @@ import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Properties;
|
||||
@ -53,7 +53,7 @@ public class PlatformUtils {
|
||||
}
|
||||
|
||||
private void initMap() {
|
||||
ArrayMap<String, Integer> platformPicMap = new ArrayMap<String, Integer>();
|
||||
ArrayMap<String, Integer> platformPicMap = new ArrayMap<>();
|
||||
platformPicMap.put("360", R.drawable.platform_360);
|
||||
platformPicMap.put("37wan", R.drawable.platform_37);
|
||||
platformPicMap.put("91", R.drawable.platform_91);
|
||||
@ -72,7 +72,7 @@ public class PlatformUtils {
|
||||
platformPicMap.put("vivo", R.drawable.platform_vivo);
|
||||
platformPicMap.put("wdj", R.drawable.platform_wdj);
|
||||
|
||||
ArrayMap<String, String> platformColorMap = new ArrayMap<String, String>();
|
||||
ArrayMap<String, String> platformColorMap = new ArrayMap<>();
|
||||
platformColorMap.put("360", "#218FA4");
|
||||
platformColorMap.put("37wan", "#F5BD20");
|
||||
platformColorMap.put("91", "#6A63CB");
|
||||
@ -91,8 +91,8 @@ public class PlatformUtils {
|
||||
platformColorMap.put("vivo", "#3FA5E3");
|
||||
platformColorMap.put("wdj", "#5ABA3F");
|
||||
|
||||
ArrayMap<String, String> platformMap = new ArrayMap<String, String>();
|
||||
ArrayMap<String, String> platformPicUrlMap = new ArrayMap<String, String>();
|
||||
ArrayMap<String, String> platformMap = new ArrayMap<>();
|
||||
ArrayMap<String, String> platformPicUrlMap = new ArrayMap<>();
|
||||
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences(
|
||||
"gh_platform", Context.MODE_PRIVATE);
|
||||
@ -102,7 +102,7 @@ public class PlatformUtils {
|
||||
try {
|
||||
properties
|
||||
.load(context.getAssets().open("platform.properties"));
|
||||
Set<String> pset = new HashSet<String>();
|
||||
Set<String> pset = new HashSet<>();
|
||||
for (Object object : properties.keySet()) {
|
||||
platformMap.put(object.toString(),
|
||||
(String) properties.get(object));
|
||||
@ -116,7 +116,7 @@ public class PlatformUtils {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
ArrayList<String> urls = new ArrayList<String>();
|
||||
ArrayList<String> urls = new ArrayList<>();
|
||||
for (String str : set) {
|
||||
String[] platform = str.split("=");
|
||||
platformMap.put(platform[0], platform[1]);
|
||||
@ -175,7 +175,7 @@ public class PlatformUtils {
|
||||
+ url.substring(url.lastIndexOf("/") + 1);
|
||||
try {
|
||||
int code = FileUtils.downloadFile(url, savePath);
|
||||
if (code == HttpStatus.SC_OK) {
|
||||
if (code == HttpURLConnection.HTTP_OK) {
|
||||
success++;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@ -199,13 +199,8 @@ public class PlatformUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getPlatformMap() {
|
||||
return platformMap;
|
||||
}
|
||||
|
||||
public String getPlatformColor(String platform) {
|
||||
if ("".equals(platform) || "官方版".equals(platform)
|
||||
|| "local_plugin".equals(platform)) {
|
||||
if ("".equals(platform) || "官方版".equals(platform)) {
|
||||
return "#BB3D42";
|
||||
}
|
||||
String color = platformColorMap.get(platform);
|
||||
@ -216,8 +211,7 @@ public class PlatformUtils {
|
||||
}
|
||||
|
||||
public int getPlatformPic(String platform) {
|
||||
if ("".equals(platform) || "官方版".equals(platform)
|
||||
|| "local_plugin".equals(platform)) {
|
||||
if ("".equals(platform) || "官方版".equals(platform)) {
|
||||
return R.drawable.platform_gf;
|
||||
}
|
||||
Integer id = platformPicMap.get(platform);
|
||||
@ -242,7 +236,7 @@ public class PlatformUtils {
|
||||
}
|
||||
}
|
||||
if (path == null && !isCheck) {
|
||||
ArrayList<String> urls = new ArrayList<String>();
|
||||
ArrayList<String> urls = new ArrayList<>();
|
||||
for (String value : platformPicUrlMap.values()) {
|
||||
urls.add(value);
|
||||
}
|
||||
@ -253,8 +247,7 @@ public class PlatformUtils {
|
||||
}
|
||||
|
||||
public String getPlatformName(String platform) {
|
||||
if ("".equals(platform) || "官方版".equals(platform)
|
||||
|| "local_plugin".equals(platform)) {
|
||||
if ("".equals(platform) || "官方版".equals(platform)) {
|
||||
return "官方版";
|
||||
}
|
||||
return platformMap.get(platform);
|
||||
@ -268,7 +261,7 @@ public class PlatformUtils {
|
||||
}
|
||||
isUpdate = true;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "v1d45/support/setting/platform",
|
||||
Config.HOST + "support/setting/platform",
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
|
||||
@ -3,6 +3,8 @@ package com.gh.common.util;
|
||||
import android.app.Activity;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
@ -21,9 +23,11 @@ import android.widget.PopupWindow;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
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.gamecenter.R;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||
import com.tencent.connect.share.QQShare;
|
||||
import com.tencent.connect.share.QzoneShare;
|
||||
import com.tencent.mm.sdk.openapi.IWXAPI;
|
||||
@ -39,6 +43,7 @@ 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;
|
||||
@ -423,20 +428,9 @@ public class ShareUtils {
|
||||
}
|
||||
|
||||
private void loadBitMap(final String iconUrl, final WXMediaMessage msg, final SendMessageToWX.Req req){
|
||||
ImageUtils.getInstance(context).loadBitmap(iconUrl, new ImageLoadingListener() {
|
||||
ImageUtils.getInstance(context).display(iconUrl, new BaseBitmapDataSubscriber() {
|
||||
@Override
|
||||
public void onLoadingStarted(String s, View view) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String s, View view, FailReason failReason) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingComplete(String s, View view, Bitmap bitmap) {
|
||||
|
||||
protected void onNewResultImpl(Bitmap bitmap) {
|
||||
Bitmap compressBp = compressBitmap(bitmap);
|
||||
Bitmap resultBp = addBackGround(compressBp);
|
||||
msg.thumbData = Util.bmpToByteArray(resultBp, true);
|
||||
@ -444,10 +438,10 @@ public class ShareUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String s, View view) {
|
||||
|
||||
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
|
||||
Utils.log("分享获取bitmap失败");
|
||||
}
|
||||
});
|
||||
}, context);
|
||||
}
|
||||
|
||||
//添加背景,防止图片格式为PNG的图片分享出现黑框问题
|
||||
@ -515,5 +509,18 @@ public class ShareUtils {
|
||||
}
|
||||
};
|
||||
|
||||
//检查是否安装手机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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -16,18 +16,106 @@ public class TimestampUtils {
|
||||
private static ArrayMap<String, Integer> intervalMap; // 间隔
|
||||
private static ArrayMap<String, Integer> cdMap; // cd
|
||||
|
||||
public static void initMap() {
|
||||
initIntervalMap();
|
||||
initCDMap();
|
||||
}
|
||||
|
||||
private static void initIntervalMap() {
|
||||
intervalMap = new ArrayMap<>();
|
||||
intervalMap.put("^" + Config.HOST + "index/slides" + "$", 5);
|
||||
intervalMap.put("^" + Config.HOST + "game/chajian" + "$", 10);
|
||||
intervalMap.put("^" + Config.HOST + "game/tuijian" + "$", 15);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/detail" + "$", 20);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/digest" + "$", 25);
|
||||
intervalMap.put("^" + Config.HOST + "game/remenkapai" + "$", 30);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news_digest" + "$", 35);
|
||||
intervalMap.put("^" + Config.HOST + "game/column/.+\\?page=.+" + "$", 40);
|
||||
intervalMap.put("^" + Config.HOST + "support/package/.+/game/digest" + "$", 45);
|
||||
intervalMap.put("^" + Config.HOST + "game/danjiyouxi\\?limit=20\\&offset=.+" + "$", 50);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/digest" + "$", 55);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/detail" + "$", 60);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/suggestion" + "$", 65);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=3" + "$", 70);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/zixun\\?limit=20\\&offset=.+" + "$", 75);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+" + "$", 80);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/yuanchuang\\?limit=10\\&offset=.+" + "$", 85);
|
||||
intervalMap.put("^" + Config.HOST + "news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", 90);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", 95);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", 100);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", 105);
|
||||
intervalMap.put("^" + Config.HOST + "search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", 110);
|
||||
intervalMap.put("^" + Config.HOST + "search/game\\?keyword=.+" + "$", 115);
|
||||
intervalMap.put("^" + Config.HOST + "support/setting/platform" + "$", 120);
|
||||
intervalMap.put("^" + Config.HOST + "update/package/.+" + "$", 125);
|
||||
intervalMap.put("^" + Config.HOST + "update/game/.+/package/.+" + "$", 130);
|
||||
}
|
||||
|
||||
private static void initCDMap() {
|
||||
cdMap = new ArrayMap<>();
|
||||
cdMap.put("^" + Config.HOST + "index/slides" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/chajian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/tuijian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/detail" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/remenkapai" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news_digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/column/.+\\?page=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "support/package/.+/game/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/danjiyouxi\\?limit=20\\&offset=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/digest" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/detail" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/suggestion" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=3" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/zixun\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/yuanchuang\\?limit=10\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "search/game\\?keyword=.+" + "$", Constants.SEARCH_CD);
|
||||
cdMap.put("^" + Config.HOST + "support/setting/platform" + "$", Constants.PLATFORM_CD);
|
||||
cdMap.put("^" + Config.HOST + "update/package/.+" + "$", Constants.UPDATE_CD);
|
||||
cdMap.put("^" + Config.HOST + "update/game/.+/package/.+" + "$", Constants.UPDATE_CD);
|
||||
cdMap.put("^" + Config.HOST + "device/.+/concern" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "device/.+/concern/.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "stat/download" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "disclaimer" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "search/game/default" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/upgrade\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/time/current" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/setting/ui" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/download_status\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/suggestion" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/serverInfo" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/package/unused\\?skip=.+" + "$", 0);
|
||||
}
|
||||
|
||||
private static ArrayMap<String, Integer> getIntervalMap() {
|
||||
if (intervalMap == null) {
|
||||
intervalMap = new ArrayMap<>();
|
||||
}
|
||||
return intervalMap;
|
||||
}
|
||||
|
||||
private static ArrayMap<String, Integer> getCdMap() {
|
||||
if (cdMap == null) {
|
||||
cdMap = new ArrayMap<>();
|
||||
}
|
||||
return cdMap;
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据CD获取时间戳
|
||||
*/
|
||||
public static long getTimestamp(String url, int cd) {
|
||||
if (intervalMap == null) {
|
||||
initIntervalMap();
|
||||
}
|
||||
long base = BASE;
|
||||
for (String key : intervalMap.keySet()){
|
||||
for (String key : getIntervalMap().keySet()){
|
||||
if (Pattern.matches(key, url)) {
|
||||
Utils.log("url add base = " + url);
|
||||
base += intervalMap.get(key);
|
||||
base += getIntervalMap().get(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -36,76 +124,6 @@ public class TimestampUtils {
|
||||
return (long) (Math.ceil((now - base) / cd) * cd + base);
|
||||
}
|
||||
|
||||
private static void initCDMap() {
|
||||
cdMap = new ArrayMap<>();
|
||||
cdMap.put("^" + Config.HOST + "v1d50/index/slides" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d50/game/chajian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d50/game/tuijian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/game/.+/detail" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/game/.+/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/game/remenkapai" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/game/.+/news_digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d50/game/column/.+\\?page=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/support/package/.+/game/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d50/game/danjiyouxi\\?limit=20\\&offset=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/news/.+/digest" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/news/.+/detail" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/news/.+/suggestion" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=3" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d50/news/zixun\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d50/news/yuanchuang\\?limit=10\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/search/game\\?keyword=.+" + "$", Constants.SEARCH_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/support/setting/platform" + "$", Constants.PLATFORM_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/support/package/update\\?package=.+" + "$", Constants.UPDATE_CD);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/device/.+/concern" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/device/.+/concern/.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v2/stat/download" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v2/disclaimer" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/search/game/default" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/support/upgrade\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/support/time/current" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/support/setting/ui" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/support/download_status\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v1d46/support/suggestion" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v2/game/.+/serverInfo" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/support/package/unused\\?skip=.+" + "$", 0);
|
||||
}
|
||||
|
||||
private static void initIntervalMap() {
|
||||
intervalMap = new ArrayMap<>();
|
||||
intervalMap.put("^" + Config.HOST + "v1d50/index/slides" + "$", 5);
|
||||
intervalMap.put("^" + Config.HOST + "v1d50/game/chajian" + "$", 10);
|
||||
intervalMap.put("^" + Config.HOST + "v1d50/game/tuijian" + "$", 15);
|
||||
intervalMap.put("^" + Config.HOST + "v2d0/game/.+/detail" + "$", 20);
|
||||
intervalMap.put("^" + Config.HOST + "v2d0/game/.+/digest" + "$", 25);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/game/remenkapai" + "$", 30);
|
||||
intervalMap.put("^" + Config.HOST + "v2d0/game/.+/news_digest" + "$", 35);
|
||||
intervalMap.put("^" + Config.HOST + "v1d50/game/column/.+\\?page=.+" + "$", 40);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/support/package/.+/game/digest" + "$", 45);
|
||||
intervalMap.put("^" + Config.HOST + "v1d50/game/danjiyouxi\\?limit=20\\&offset=.+" + "$", 50);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/news/.+/digest" + "$", 55);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/news/.+/detail" + "$", 60);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/news/.+/suggestion" + "$", 65);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=3" + "$", 70);
|
||||
intervalMap.put("^" + Config.HOST + "v1d50/news/zixun\\?limit=20\\&offset=.+" + "$", 75);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=20\\&offset=.+" + "$", 80);
|
||||
intervalMap.put("^" + Config.HOST + "v1d50/news/yuanchuang\\?limit=10\\&offset=.+" + "$", 85);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", 90);
|
||||
intervalMap.put("^" + Config.HOST + "v2d0/zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", 95);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", 100);
|
||||
intervalMap.put("^" + Config.HOST + "v2d0/zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", 105);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", 110);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/search/game\\?keyword=.+" + "$", 115);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/support/setting/platform" + "$", 120);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/support/package/update\\?package=.+" + "$", 125);
|
||||
}
|
||||
|
||||
/*
|
||||
* 为url添加timestamp
|
||||
*/
|
||||
@ -113,13 +131,10 @@ public class TimestampUtils {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
return url;
|
||||
}
|
||||
if (cdMap == null) {
|
||||
initCDMap();
|
||||
}
|
||||
int cd = 0;
|
||||
for (String key : cdMap.keySet()){
|
||||
for (String key : getCdMap().keySet()){
|
||||
if (Pattern.matches(key, url)) {
|
||||
cd = cdMap.get(key);
|
||||
cd = getCdMap().get(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,11 +56,10 @@ public class TokenUtils {
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
sp.edit().putBoolean("isUploadMid", false).apply();
|
||||
}
|
||||
String url = "http://user.ghzhushou.com/v1d0/device/register";
|
||||
HttpURLConnection connection = null;
|
||||
String url = Config.USER_HOST + "device/register";
|
||||
try {
|
||||
JSONObject body = new JSONObject(params);
|
||||
connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
connection.setConnectTimeout(5000);
|
||||
@ -120,7 +119,7 @@ public class TokenUtils {
|
||||
}
|
||||
|
||||
// 重新获取token
|
||||
String url = "http://user.ghzhushou.com/v1d0/login";
|
||||
String url = Config.USER_HOST + "login";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("device_id", getDeviceId(context));
|
||||
try {
|
||||
|
||||
@ -26,14 +26,12 @@ public class TrafficUtils {
|
||||
synchronized (TrafficUtils.class) {
|
||||
if (instance == null) {
|
||||
instance = new TrafficUtils(context);
|
||||
if (update)
|
||||
instance.update();
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (update)
|
||||
if (update) {
|
||||
instance.update();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -47,9 +45,7 @@ public class TrafficUtils {
|
||||
// 获取所有的安装在手机上的应用软件的信息,并且获取这些软件里面的权限信息
|
||||
PackageManager pm = context.getPackageManager();// 获取系统应用包管理
|
||||
// 获取每个包内的androidmanifest.xml信息,它的权限等等
|
||||
List<PackageInfo> pinfos = pm
|
||||
.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES
|
||||
| PackageManager.GET_PERMISSIONS);
|
||||
List<PackageInfo> pinfos = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);
|
||||
// 遍历每个应用包信息
|
||||
for (PackageInfo info : pinfos) {
|
||||
// 请求每个程序包对应的androidManifest.xml里面的权限
|
||||
@ -64,9 +60,7 @@ public class TrafficUtils {
|
||||
long rx = TrafficStats.getUidRxBytes(uId);
|
||||
// 如果返回-1,代表不支持使用该方法,注意必须是2.2以上的
|
||||
long tx = TrafficStats.getUidTxBytes(uId);
|
||||
if (rx < 0 || tx < 0) {
|
||||
continue;
|
||||
} else {
|
||||
if (rx >= 0 && tx >= 0) {
|
||||
db.update(info.packageName, rx + tx);
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ import java.lang.reflect.Field;
|
||||
|
||||
public class Utils {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
private static final boolean DEBUG = true;
|
||||
private final static String TAG = "result";
|
||||
|
||||
public static void log(String msg) {
|
||||
|
||||
@ -1,67 +0,0 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/8/9.
|
||||
*/
|
||||
public class ChildLinearLayoutManager extends LinearLayoutManager {
|
||||
|
||||
public ChildLinearLayoutManager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ChildLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
|
||||
super(context, orientation, reverseLayout);
|
||||
}
|
||||
@Override
|
||||
public boolean canScrollVertically() {
|
||||
return false;
|
||||
}
|
||||
private int[] mMeasuredDimension = new int[1];
|
||||
|
||||
@Override
|
||||
public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state,
|
||||
int widthSpec, int heightSpec) {
|
||||
|
||||
final int heightMode = View.MeasureSpec.getMode(heightSpec);
|
||||
final int heightSize = View.MeasureSpec.getSize(heightSpec);
|
||||
|
||||
int height = 0;
|
||||
for (int i = 0; i < getItemCount(); i++) {
|
||||
measureScrapChild(recycler, i,
|
||||
View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
|
||||
View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
|
||||
mMeasuredDimension);
|
||||
height = height + mMeasuredDimension[0];
|
||||
|
||||
}
|
||||
if (heightMode == View.MeasureSpec.EXACTLY){
|
||||
height = heightSize;
|
||||
}
|
||||
|
||||
setMeasuredDimension(View.MeasureSpec.getSize(widthSpec), height);
|
||||
}
|
||||
|
||||
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
|
||||
int heightSpec, int[] measuredDimension) {
|
||||
View view = recycler.getViewForPosition(position);
|
||||
if (view.getVisibility() == View.GONE) {
|
||||
measuredDimension[0] = 0;
|
||||
return;
|
||||
}
|
||||
super.measureChildWithMargins(view, 0, 0);
|
||||
RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();
|
||||
int childHeightSpec = ViewGroup.getChildMeasureSpec(
|
||||
heightSpec,
|
||||
getPaddingTop() + getPaddingBottom() + getDecoratedTop(view) + getDecoratedBottom(view),
|
||||
p.height);
|
||||
view.measure(0, childHeightSpec);
|
||||
measuredDimension[0] = getDecoratedMeasuredHeight(view) + p.bottomMargin + p.topMargin;
|
||||
recycler.recycleView(view);
|
||||
}
|
||||
}
|
||||
@ -105,6 +105,9 @@ public class DownloadDialog implements OnCollectionCallBackListener {
|
||||
|
||||
public void showPopupWindow(View view, GameEntity gameEntity, String entrance, String location) {
|
||||
|
||||
if (isShow && (popupWindow == null || !popupWindow.isShowing())) {
|
||||
isShow = false;
|
||||
}
|
||||
if (isShow) {
|
||||
return;
|
||||
}
|
||||
@ -283,8 +286,10 @@ public class DownloadDialog implements OnCollectionCallBackListener {
|
||||
|
||||
for (int i = 0, size = apkList.size(); i < size; i++) {
|
||||
String packageName = apkList.get(i).getPackageName();
|
||||
if (PackageManager.isInstalled(packageName)) {
|
||||
if (PackageManager.isCanUpdate(packageName)) {
|
||||
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--;
|
||||
|
||||
@ -22,15 +22,15 @@ public class Gh_RelativeLayout extends RelativeLayout {
|
||||
mGestureDetector = new GestureDetector(context,
|
||||
new GestureDetector.SimpleOnGestureListener() {
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
if (listener != null) {
|
||||
listener.onSingleTap();
|
||||
}
|
||||
return super.onSingleTapUp(e);
|
||||
}
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
if (listener != null) {
|
||||
listener.onSingleTap();
|
||||
}
|
||||
return super.onSingleTapUp(e);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void setOnSingleTapListener(OnSingleTapListener listener) {
|
||||
|
||||
@ -5,22 +5,56 @@ import android.support.v4.view.ViewPager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
public class Gh_ViewPager extends ViewPager {
|
||||
|
||||
private boolean mChildIsBeingDragged=false;//当前子控件是否处理拖动状态
|
||||
|
||||
public Gh_ViewPager(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public Gh_ViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
getChildAt(i).dispatchTouchEvent(event);
|
||||
}
|
||||
// for (int i = 0; i < getChildCount(); i++) {
|
||||
// getChildAt(i).dispatchTouchEvent(event);
|
||||
// }
|
||||
return super.dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
if(mChildIsBeingDragged){
|
||||
return false;
|
||||
}
|
||||
|
||||
//指针索引超出范围异常
|
||||
try {
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void onEvent(EBReuse reuse) {
|
||||
if ("isStopMove".equals(reuse.getType())) {
|
||||
mChildIsBeingDragged = false;
|
||||
}
|
||||
if ("isStartove".equals(reuse.getType())){
|
||||
mChildIsBeingDragged = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void onDestory (){
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,91 +0,0 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBShowDone;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
public class MyGame_LinearLayout extends LinearLayout {
|
||||
|
||||
private LinearLayout mygame_ll;
|
||||
private RecyclerView mygame_rv_show;
|
||||
|
||||
private int height;
|
||||
private int distance;
|
||||
private int total;
|
||||
|
||||
private int position;
|
||||
|
||||
Runnable show = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LayoutParams lparams = new LayoutParams(
|
||||
LayoutParams.MATCH_PARENT, height);
|
||||
lparams.height = mygame_ll.getHeight() + distance;
|
||||
if (lparams.height > total) {
|
||||
lparams.height = total;
|
||||
}
|
||||
mygame_ll.setLayoutParams(lparams);
|
||||
invalidate();
|
||||
if (lparams.height < total) {
|
||||
postDelayed(show, 10);
|
||||
} else {
|
||||
EventBus.getDefault().post(new EBShowDone("我的游戏", position));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Runnable hide = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LayoutParams lparams = new LayoutParams(
|
||||
LayoutParams.MATCH_PARENT, height);
|
||||
lparams.height = mygame_ll.getHeight() - distance;
|
||||
if (lparams.height < height) {
|
||||
lparams.height = height;
|
||||
}
|
||||
mygame_ll.setLayoutParams(lparams);
|
||||
invalidate();
|
||||
if (lparams.height > height) {
|
||||
postDelayed(hide, 10);
|
||||
} else {
|
||||
mygame_rv_show.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public MyGame_LinearLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
height = DisplayUtils.dip2px(getContext(), 66);
|
||||
distance = DisplayUtils.dip2px(getContext(), 5);
|
||||
total = DisplayUtils.dip2px(getContext(), 136);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
|
||||
super.onAttachedToWindow();
|
||||
mygame_rv_show = (RecyclerView) findViewById(R.id.mygame_rv_show);
|
||||
mygame_ll = (LinearLayout) findViewById(R.id.mygame_ll);
|
||||
}
|
||||
|
||||
public void showRecyclerView(int position) {
|
||||
this.position = position;
|
||||
mygame_rv_show.setVisibility(View.VISIBLE);
|
||||
removeCallbacks(hide);
|
||||
post(show);
|
||||
}
|
||||
|
||||
public void hideRecyclerView() {
|
||||
removeCallbacks(show);
|
||||
post(hide);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/10/11.
|
||||
*/
|
||||
public class RecyclerViewExtended extends RecyclerView {
|
||||
|
||||
public RecyclerViewExtended(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public RecyclerViewExtended(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public RecyclerViewExtended(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
private OnDispatchTouchListener mListener;
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
if (mListener != null) {
|
||||
mListener.onDispatch(this, ev);
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
public void setOnDispatchTouchListener(OnDispatchTouchListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public interface OnDispatchTouchListener {
|
||||
void onDispatch(View v, MotionEvent event);
|
||||
}
|
||||
|
||||
}
|
||||
279
app/src/main/java/com/gh/common/view/ZoomSimpleDraweeView.java
Normal file
279
app/src/main/java/com/gh/common/view/ZoomSimpleDraweeView.java
Normal file
@ -0,0 +1,279 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.RectF;
|
||||
import android.net.Uri;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ScaleGestureDetector;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/10/26.
|
||||
*/
|
||||
public class ZoomSimpleDraweeView extends SimpleDraweeView {
|
||||
private ScaleGestureDetector mScaleDetector;
|
||||
private GestureDetector mGestureDetector;
|
||||
|
||||
private float mCurrentScale = 1f;
|
||||
private Matrix mCurrentMatrix;
|
||||
private setOnSingleClickListener mClickListener;
|
||||
|
||||
private float imgagePro = -1; // 图片宽高比
|
||||
|
||||
public ZoomSimpleDraweeView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public ZoomSimpleDraweeView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public ZoomSimpleDraweeView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mCurrentMatrix = new Matrix();
|
||||
|
||||
ScaleGestureDetector.OnScaleGestureListener scaleListener = new ScaleGestureDetector
|
||||
.SimpleOnScaleGestureListener() {
|
||||
|
||||
@Override
|
||||
public boolean onScale(ScaleGestureDetector detector) {
|
||||
float scaleFactor = detector.getScaleFactor();
|
||||
if (mCurrentScale < 4f || detector.getScaleFactor() < 1f){
|
||||
mCurrentScale *= scaleFactor;
|
||||
mCurrentMatrix.postScale(scaleFactor, scaleFactor, detector.getFocusX(), detector.getFocusY());
|
||||
invalidate();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScaleEnd(ScaleGestureDetector detector) {
|
||||
super.onScaleEnd(detector);
|
||||
|
||||
if (mCurrentScale < 1f) {
|
||||
reset();
|
||||
}
|
||||
checkBorder();
|
||||
}
|
||||
|
||||
};
|
||||
mScaleDetector = new ScaleGestureDetector(getContext(), scaleListener);
|
||||
|
||||
GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() {
|
||||
@Override
|
||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
if (mClickListener != null) {
|
||||
mClickListener.onClick();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
||||
if (mCurrentScale > 1f) {
|
||||
mCurrentMatrix.postTranslate(-distanceX, -distanceY);
|
||||
invalidate();
|
||||
checkBorder();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
final float x = e.getX();
|
||||
final float y = e.getY();
|
||||
float scaleSize ; //扩大或缩小的倍数
|
||||
|
||||
if (mCurrentScale > 1.5f){ //缩小时直接回到原画大小
|
||||
scaleSize = 0.5f;
|
||||
ZoomSimpleDraweeView.this.post(new AutoScaleRunnable(mCurrentScale * scaleSize, getWidth() / 2f, getHeight() / 2f, false));
|
||||
} else {
|
||||
scaleSize = 2.0f;
|
||||
ZoomSimpleDraweeView.this.post(new AutoScaleRunnable(mCurrentScale * scaleSize, x, y, true));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
|
||||
return super.onSingleTapUp(e);
|
||||
}
|
||||
};
|
||||
mGestureDetector = new GestureDetector(getContext(), gestureListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查图片边界是否移到view以内
|
||||
* 目的是让图片边缘不要移动到view里面
|
||||
*/
|
||||
private void checkBorder() {
|
||||
RectF rectF = getDisplayRect(mCurrentMatrix);
|
||||
boolean reset = false;
|
||||
float dx = 0;
|
||||
float dy = 0;
|
||||
|
||||
|
||||
if (rectF.left > 0) {
|
||||
dx = getLeft() - rectF.left;
|
||||
reset = true;
|
||||
}
|
||||
if (rectF.top > 0) {
|
||||
dy = getTop() - rectF.top;
|
||||
reset = true;
|
||||
}
|
||||
if (rectF.right < getRight()) {
|
||||
dx = getRight() - rectF.right;
|
||||
reset = true;
|
||||
}
|
||||
if (rectF.bottom < getHeight()) {
|
||||
dy = getHeight() - rectF.bottom;
|
||||
reset = true;
|
||||
}
|
||||
if (reset) {
|
||||
mCurrentMatrix.postTranslate(dx, dy);
|
||||
invalidate();
|
||||
}
|
||||
if (dy == 0 && reset || mCurrentScale == 1f){
|
||||
EventBus.getDefault().post(new EBReuse("isStopMove"));
|
||||
} else{
|
||||
EventBus.getDefault().post(new EBReuse("isStartove"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that maps the supplied Matrix to the current Drawable
|
||||
*
|
||||
* @param matrix - Matrix to map Drawable against
|
||||
* @return RectF - Displayed Rectangle
|
||||
*/
|
||||
private RectF getDisplayRect(Matrix matrix) {
|
||||
// int bottom;
|
||||
// if (imgagePro != -1){
|
||||
// bottom = (int) (getRight()*imgagePro);
|
||||
// } else {
|
||||
// bottom = getBottom();
|
||||
// }
|
||||
RectF rectF = new RectF(getLeft(), getTop(), getRight(), getBottom());
|
||||
matrix.mapRect(rectF);
|
||||
return rectF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setImageURI(Uri uri) {
|
||||
reset();
|
||||
super.setImageURI(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
int saveCount = canvas.save();
|
||||
canvas.concat(mCurrentMatrix);
|
||||
super.onDraw(canvas);
|
||||
canvas.restoreToCount(saveCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
mScaleDetector.onTouchEvent(event);
|
||||
if (!mScaleDetector.isInProgress()) {
|
||||
mGestureDetector.onTouchEvent(event);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置图片
|
||||
*/
|
||||
public void reset() {
|
||||
mCurrentMatrix.reset();
|
||||
mCurrentScale = 1f;
|
||||
invalidate();
|
||||
EventBus.getDefault().post(new EBReuse("isStopMove"));
|
||||
}
|
||||
private final float[] matrixValues = new float[9];
|
||||
public final float getScale() {
|
||||
mCurrentMatrix.getValues(matrixValues);
|
||||
return matrixValues[Matrix.MSCALE_X];
|
||||
}
|
||||
/**
|
||||
* 自动缩放的任务
|
||||
*/
|
||||
private class AutoScaleRunnable implements Runnable {
|
||||
static final float BIGGER = 1.07f;
|
||||
static final float SMALLER = 0.96f;
|
||||
private float mTargetScale;
|
||||
private boolean isExp;
|
||||
|
||||
/**
|
||||
* 缩放的中心
|
||||
*/
|
||||
private float x;
|
||||
private float y;
|
||||
|
||||
/**
|
||||
* @param isExp :判断是否是放大
|
||||
*/
|
||||
public AutoScaleRunnable(float targetScale, float x, float y, boolean isExp) {
|
||||
this.mTargetScale = targetScale;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.isExp = isExp;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (isExp){ //放大
|
||||
mCurrentMatrix.postScale(BIGGER, BIGGER, x, y);
|
||||
invalidate();
|
||||
if (mCurrentScale < mTargetScale && mCurrentScale <= 4) {
|
||||
ZoomSimpleDraweeView.this.postDelayed(this, 10);
|
||||
mCurrentScale = mCurrentScale * BIGGER;
|
||||
} else {
|
||||
checkBorder();
|
||||
mCurrentScale = getScale();
|
||||
}
|
||||
}else {//缩小
|
||||
mCurrentMatrix.postScale(SMALLER, SMALLER, x, y);
|
||||
invalidate();
|
||||
checkBorder();
|
||||
if (getScale() > 1.01) {
|
||||
ZoomSimpleDraweeView.this.postDelayed(this, 1);
|
||||
mCurrentScale = mCurrentScale * SMALLER;
|
||||
} else {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//图片宽高比例
|
||||
public void setImagePro (float imgPro){
|
||||
this.imgagePro = imgPro;
|
||||
}
|
||||
|
||||
|
||||
public void setOnSingleClickListener(setOnSingleClickListener listener) {
|
||||
mClickListener = listener;
|
||||
}
|
||||
|
||||
public interface setOnSingleClickListener {
|
||||
void onClick();
|
||||
}
|
||||
}
|
||||
@ -132,6 +132,22 @@ public class DownloadEntity implements Serializable {
|
||||
meta.put("isPluggable", String.valueOf(pluggable));
|
||||
}
|
||||
|
||||
public boolean isReset() {
|
||||
if (meta != null) {
|
||||
if ("true".equals(meta.get("isReset"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setReset(boolean reset) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("isReset", String.valueOf(reset));
|
||||
}
|
||||
|
||||
public String getPlatform() {
|
||||
if (meta != null) {
|
||||
return meta.get("platform");
|
||||
@ -210,6 +226,60 @@ public class DownloadEntity implements Serializable {
|
||||
meta.put("error", error);
|
||||
}
|
||||
|
||||
public long getStart() {
|
||||
if (meta != null) {
|
||||
String start = meta.get("start");
|
||||
if (start == null) {
|
||||
return 0;
|
||||
}
|
||||
return Long.valueOf(start);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setStart(long start) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("start", String.valueOf(start));
|
||||
}
|
||||
|
||||
public long getEnd() {
|
||||
if (meta != null) {
|
||||
String end = meta.get("end");
|
||||
if (end == null) {
|
||||
return 0;
|
||||
}
|
||||
return Long.valueOf(end);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setEnd(long end) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("end", String.valueOf(end));
|
||||
}
|
||||
|
||||
public long getInstalled() {
|
||||
if (meta != null) {
|
||||
String installed = meta.get("installed");
|
||||
if (installed == null) {
|
||||
return 0;
|
||||
}
|
||||
return Integer.valueOf(installed);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setInstalled(int installed) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("installed", String.valueOf(installed));
|
||||
}
|
||||
|
||||
public HashMap<String, String> getMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
@ -10,9 +10,11 @@ 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;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -66,7 +68,6 @@ public class DownloadManager {
|
||||
}
|
||||
}
|
||||
};
|
||||
context.startService(new Intent(context, DownloadService.class));
|
||||
}
|
||||
|
||||
public void put(String url, long time) {
|
||||
@ -91,7 +92,7 @@ public class DownloadManager {
|
||||
|
||||
public void initGameMap() {
|
||||
gameMap.clear();
|
||||
List<DownloadEntity> list = DownloadManager.getInstance(context).getAll();
|
||||
List<DownloadEntity> list = getAll();
|
||||
if (list != null && list.size() != 0) {
|
||||
String name;
|
||||
for (DownloadEntity downloadEntity : list) {
|
||||
@ -227,6 +228,13 @@ public class DownloadManager {
|
||||
downloadEntity.setGameId(gameEntity.getId());
|
||||
downloadEntity.setEntrance(entrance);
|
||||
downloadEntity.setLocation(location);
|
||||
int installed = 0;
|
||||
for (ApkEntity apk : gameEntity.getApk()) {
|
||||
if (PackageManager.isInstalled(apk.getPackageName())) {
|
||||
installed++;
|
||||
}
|
||||
}
|
||||
downloadEntity.setInstalled(installed);
|
||||
if (method.equals("更新")) {
|
||||
downloadEntity.setUpdate(true);
|
||||
} else if (method.equals("插件化")) {
|
||||
@ -339,13 +347,28 @@ public class DownloadManager {
|
||||
/**
|
||||
* 根据url获取某一个下载任务
|
||||
*
|
||||
* @param url
|
||||
* @param url 下载链接
|
||||
* @return null表示下载列表中不存在该任务,否则返回下载任务
|
||||
*/
|
||||
public DownloadEntity get(String url) {
|
||||
return DownloadDao.getInstance(context).get(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据包名获取某一个下载任务
|
||||
*
|
||||
* @param packageName 包名
|
||||
* @return null表示下载列表中不存在该任务,否则返回下载任务
|
||||
*/
|
||||
public DownloadEntity getByPackage(String packageName) {
|
||||
for (DownloadEntity downloadEntity : DownloadDao.getInstance(context).getAll()) {
|
||||
if (packageName.equals(downloadEntity.getPackageName())) {
|
||||
return downloadEntity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有下载列表中的任务
|
||||
*
|
||||
|
||||
@ -1,21 +1,30 @@
|
||||
package com.gh.download;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
|
||||
import com.gh.common.constant.Constants;
|
||||
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;
|
||||
|
||||
public class DownloadService extends Service {
|
||||
|
||||
private int mFlag = (int) System.currentTimeMillis() / 1000;
|
||||
|
||||
private ArrayMap<String, Integer> flagMap = new ArrayMap<>();
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
@ -24,19 +33,32 @@ public class DownloadService extends Service {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Utils.log(DownloadService.class.getSimpleName(), "onCreate");
|
||||
// ArrayList<DownloadEntity> doneList = new ArrayList<>();
|
||||
// for (DownloadEntity downloadEntity : DownloadManager.getInstance(this).getAll()) {
|
||||
// if (downloadEntity.getStatus().equals(DownloadStatus.done)) {
|
||||
// doneList.add(downloadEntity);
|
||||
// }
|
||||
// }
|
||||
NotificationUtils.showDownloadingNotification(this);
|
||||
// if (doneList.size() != 0) {
|
||||
// for (DownloadEntity downloadEntity : doneList) {
|
||||
// mFlag++;
|
||||
// flagMap.put(downloadEntity.getUrl(), mFlag);
|
||||
// NotificationUtils.showDownloadDoneNotification(this, downloadEntity, mFlag);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Utils.log(DownloadService.class.getSimpleName(), "onStartCommand");
|
||||
if (intent != null && intent.getExtras() != null) {
|
||||
DownloadStatus status = DownloadStatus.valueOf(intent
|
||||
.getStringExtra(Constants.KEY_DOWNLOAD_ACTION));
|
||||
DownloadEntity entry = (DownloadEntity) intent
|
||||
.getSerializableExtra(Constants.KEY_DOWNLOAD_ENTRY);
|
||||
DownloadStatus status = DownloadStatus.valueOf(intent.getStringExtra(Constants.KEY_DOWNLOAD_ACTION));
|
||||
DownloadEntity entry = (DownloadEntity) intent.getSerializableExtra(Constants.KEY_DOWNLOAD_ENTRY);
|
||||
switch (status) {
|
||||
case add:
|
||||
addDownload(entry);
|
||||
addDownload(entry, true);
|
||||
break;
|
||||
case pause:
|
||||
case timeout:
|
||||
@ -49,19 +71,18 @@ public class DownloadService extends Service {
|
||||
case cancel:
|
||||
cancelDownload(entry);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
private synchronized void addDownload(DownloadEntity entry) {
|
||||
DownloadEntity downloadEntity = DownloadDao.getInstance(this).get(
|
||||
entry.getUrl());
|
||||
private synchronized void addDownload(DownloadEntity entry, boolean isShow) {
|
||||
DownloadEntity downloadEntity = DownloadDao.getInstance(this).get(entry.getUrl());
|
||||
// 数据库下载历史中有这个任务的下载记录
|
||||
if (downloadEntity != null) {
|
||||
entry = downloadEntity;
|
||||
} else {
|
||||
entry.setStart(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
if (DataChanger.getInstance().getDownloadingTasks().size() >= Constants.MAX_DOWNLOADING_SIZE) {
|
||||
@ -77,6 +98,10 @@ public class DownloadService extends Service {
|
||||
}
|
||||
Utils.log(DownloadService.class.getSimpleName(), "addDownload==>" + entry);
|
||||
EventBus.getDefault().post(new EBDownloadStatus("download"));
|
||||
|
||||
if (isShow) {
|
||||
NotificationUtils.showDownloadingNotification(this);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void startDownload(DownloadEntity entry) {
|
||||
@ -95,14 +120,13 @@ public class DownloadService extends Service {
|
||||
}
|
||||
|
||||
private synchronized void resumeDownload(DownloadEntity entry) {
|
||||
addDownload(entry);
|
||||
addDownload(entry, false);
|
||||
Utils.log(DownloadService.class.getSimpleName(), "resumeDownload==>" + entry);
|
||||
}
|
||||
|
||||
private synchronized void pauseDownload(DownloadEntity entry) {
|
||||
if (entry != null) {
|
||||
DownloadTask task = DataChanger.getInstance().getDownloadingTasks()
|
||||
.get(entry.getUrl());
|
||||
DownloadTask task = DataChanger.getInstance().getDownloadingTasks().get(entry.getUrl());
|
||||
if (task != null) {
|
||||
// 1.改任务队列的状态
|
||||
entry.setStatus(DownloadStatus.pause);
|
||||
@ -132,9 +156,16 @@ public class DownloadService extends Service {
|
||||
}
|
||||
Utils.log(DownloadService.class.getSimpleName(), "cancelDownload==>" + downloadEntity);
|
||||
EBDownloadStatus status = new EBDownloadStatus("delete", downloadEntity.getName(),
|
||||
downloadEntity.getPlatform(), downloadEntity.getUrl());
|
||||
downloadEntity.getPlatform(), downloadEntity.getUrl(), downloadEntity.getPackageName());
|
||||
status.setPluggable(downloadEntity.isPluggable());
|
||||
EventBus.getDefault().post(status);
|
||||
|
||||
Integer flag = flagMap.get(downloadEntity.getUrl());
|
||||
if (flag != null) {
|
||||
NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nManager.cancel(flag);
|
||||
}
|
||||
NotificationUtils.showDownloadingNotification(DownloadService.this);
|
||||
}
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
@ -148,10 +179,19 @@ public class DownloadService extends Service {
|
||||
case downloading:
|
||||
break;
|
||||
case done:
|
||||
mFlag++;
|
||||
flagMap.put(entry.getUrl(), mFlag);
|
||||
NotificationUtils.showDownloadingNotification(DownloadService.this);
|
||||
NotificationUtils.showDownloadDoneNotification(DownloadService.this, entry, mFlag);
|
||||
removeAndCheckNext(entry);
|
||||
break;
|
||||
case pause:
|
||||
case cancel:
|
||||
removeAndCheckNext(entry);
|
||||
break;
|
||||
case timeout:
|
||||
case neterror:
|
||||
NotificationUtils.showDownloadingNotification(DownloadService.this);
|
||||
removeAndCheckNext(entry);
|
||||
break;
|
||||
default:
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
package com.gh.download;
|
||||
|
||||
public enum DownloadStatus {
|
||||
add, pause, cancel, downloading, done, waiting, resume, timeout, neterror, hijack
|
||||
add, pause, cancel, downloading, done, waiting, resume, timeout, neterror, hijack, notfound
|
||||
}
|
||||
|
||||
@ -119,7 +119,8 @@ public class DownloadTask implements DownloadListener {
|
||||
@Override
|
||||
public void onStatusChanged(DownloadStatus status, String error) {
|
||||
if (status == DownloadStatus.cancel
|
||||
|| status == DownloadStatus.hijack) {
|
||||
|| status == DownloadStatus.hijack
|
||||
|| status == DownloadStatus.notfound) {
|
||||
entry.setProgress(0);
|
||||
entry.setPercent(0);
|
||||
FileUtils.deleteFile(entry.getPath());
|
||||
@ -132,6 +133,7 @@ public class DownloadTask implements DownloadListener {
|
||||
entry.setSpeed(0);
|
||||
entry.setProgress(entry.getSize());
|
||||
entry.setPercent(100);
|
||||
entry.setEnd(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
if (status == DownloadStatus.pause) {
|
||||
|
||||
@ -7,12 +7,11 @@ import android.util.Log;
|
||||
import com.gh.common.util.HttpsUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
@ -26,9 +25,7 @@ public class DownloadThread extends Thread {
|
||||
private DownloadStatus status;
|
||||
private Context context;
|
||||
|
||||
public DownloadThread(Context context,
|
||||
DownloadEntity entry,
|
||||
DownloadListener listener) {
|
||||
public DownloadThread(Context context, DownloadEntity entry, DownloadListener listener) {
|
||||
this.entry = entry;
|
||||
this.listener = listener;
|
||||
this.context = context;
|
||||
@ -37,7 +34,19 @@ public class DownloadThread extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
download();
|
||||
}
|
||||
|
||||
private void download() {
|
||||
Utils.log("url = " + entry.getUrl());
|
||||
if (TextUtils.isEmpty(entry.getUrl())) {
|
||||
listener.onStatusChanged(DownloadStatus.notfound);
|
||||
Utils.log(DownloadThread.class.getSimpleName(), "error-->url is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
BufferedInputStream bis = null;
|
||||
BufferedOutputStream bos = null;
|
||||
try {
|
||||
File targetFile = new File(entry.getPath());
|
||||
if (!targetFile.exists()) {
|
||||
@ -47,56 +56,27 @@ public class DownloadThread extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
FileOutputStream fileOutputStream;
|
||||
if (targetFile.length() > 0) {
|
||||
fileOutputStream = new FileOutputStream(entry.getPath(), true);
|
||||
} else {
|
||||
fileOutputStream = new FileOutputStream(entry.getPath());
|
||||
}
|
||||
|
||||
URL url = new URL(entry.getUrl());
|
||||
Utils.log("url = " + entry.getUrl());
|
||||
|
||||
HttpURLConnection connection;
|
||||
if ("https".equals(url.getProtocol())) {
|
||||
connection = HttpsUtils.getHttpsURLConnection(url);
|
||||
} else {
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
}
|
||||
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(CONNECT_TIME);
|
||||
connection.setReadTimeout(READ_TIME);
|
||||
connection.setRequestProperty("RANGE",
|
||||
"bytes=" + targetFile.length() + "-");
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"startPosition-->" + targetFile.length());
|
||||
//设置自动重定向
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
HttpURLConnection connection = openConnection(new URL(entry.getUrl()), targetFile.length());
|
||||
Utils.log(DownloadThread.class.getSimpleName(), "startPosition-->" + targetFile.length());
|
||||
|
||||
int code = connection.getResponseCode();
|
||||
Utils.log("code = " +code);
|
||||
if (code == HttpStatus.SC_MOVED_PERMANENTLY
|
||||
|| code == HttpStatus.SC_MOVED_TEMPORARILY) {
|
||||
if (code == HttpURLConnection.HTTP_MOVED_PERM
|
||||
|| code == HttpURLConnection.HTTP_MOVED_TEMP) {
|
||||
//未自动重定向
|
||||
String location = connection.getHeaderField("Location");
|
||||
Utils.log("location = " + location);
|
||||
url = new URL(location);
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(CONNECT_TIME);
|
||||
connection.setReadTimeout(READ_TIME);
|
||||
connection.setRequestProperty("RANGE",
|
||||
"bytes=" + targetFile.length() + "-");
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"startPosition-->" + targetFile.length());
|
||||
//设置自动重定向
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
connection = openConnection(new URL(location), targetFile.length());
|
||||
|
||||
code = connection.getResponseCode();
|
||||
}
|
||||
Utils.log("code = " +code);
|
||||
if (code == HttpURLConnection.HTTP_NOT_FOUND) {
|
||||
// 404 Not Found
|
||||
listener.onStatusChanged(DownloadStatus.notfound);
|
||||
Utils.log(DownloadThread.class.getSimpleName(), "error-->404 Not Found");
|
||||
return;
|
||||
}
|
||||
|
||||
BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
|
||||
BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
|
||||
long conentLength = connection.getContentLength();
|
||||
String eTag = connection.getHeaderField("ETag");
|
||||
if (!TextUtils.isEmpty(eTag) && eTag.startsWith("\"") && eTag.endsWith("\"")) {
|
||||
eTag = eTag.substring(1, eTag.length() - 1);
|
||||
@ -107,59 +87,96 @@ public class DownloadThread extends Thread {
|
||||
Utils.log("eTag = " + eTag);
|
||||
Utils.log("eTag2 = " + eTag2);
|
||||
listener.onStatusChanged(DownloadStatus.hijack);
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"error-->链接被劫持");
|
||||
interrupt();
|
||||
} else {
|
||||
// 第一次下载记录文件长度
|
||||
if (entry.getSize() == 0) {
|
||||
entry.setSize(conentLength);
|
||||
DownloadDao.getInstance(context).newOrUpdate(entry);
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"记录第一次长度");
|
||||
}
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"progress:" + entry.getProgress() + "/curfilesize:"
|
||||
+ targetFile.length() + "=====contentLength:"
|
||||
+ conentLength + "/ totalSize:" + entry.getSize());
|
||||
|
||||
byte[] buffer = new byte[2048];
|
||||
int len;
|
||||
while ((len = bis.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, len);
|
||||
listener.onProgressChanged(targetFile.length(), len);
|
||||
if (status == DownloadStatus.pause
|
||||
|| status == DownloadStatus.cancel) {
|
||||
listener.onStatusChanged(status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (status != DownloadStatus.pause
|
||||
&& status != DownloadStatus.cancel) {
|
||||
listener.onStatusChanged(DownloadStatus.done);
|
||||
}
|
||||
bos.flush();
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"flush==>" + targetFile.length() + ",progress==>"
|
||||
+ entry.getProgress());
|
||||
|
||||
bis.close();
|
||||
bos.close();
|
||||
Utils.log(DownloadThread.class.getSimpleName(), "error-->链接被劫持");
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String errorMsg = Log.getStackTraceString(e);
|
||||
|
||||
//e.getMessage() will null error
|
||||
if (!TextUtils.isEmpty(e.getMessage()) && e.getMessage().contains("connection timeout")) {
|
||||
listener.onStatusChanged(DownloadStatus.timeout, errorMsg);
|
||||
} else {
|
||||
listener.onStatusChanged(DownloadStatus.neterror, errorMsg);
|
||||
long conentLength = connection.getContentLength();
|
||||
// 第一次下载记录文件长度
|
||||
if (entry.getSize() == 0) {
|
||||
entry.setSize(conentLength);
|
||||
DownloadDao.getInstance(context).newOrUpdate(entry);
|
||||
Utils.log(DownloadThread.class.getSimpleName(), "记录第一次长度");
|
||||
}
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"exception-->" + e.toString());
|
||||
"progress:" + entry.getProgress() + "/curfilesize:"
|
||||
+ targetFile.length() + "=====contentLength:"
|
||||
+ conentLength + "/ totalSize:" + entry.getSize());
|
||||
|
||||
bis = new BufferedInputStream(connection.getInputStream());
|
||||
if (targetFile.length() > 0) {
|
||||
bos = new BufferedOutputStream(new FileOutputStream(entry.getPath(), true));
|
||||
} else {
|
||||
bos = new BufferedOutputStream(new FileOutputStream(entry.getPath()));
|
||||
}
|
||||
|
||||
byte[] buffer = new byte[2048];
|
||||
int len;
|
||||
while ((len = bis.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, len);
|
||||
listener.onProgressChanged(targetFile.length(), len);
|
||||
if (status == DownloadStatus.pause
|
||||
|| status == DownloadStatus.cancel) {
|
||||
listener.onStatusChanged(status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
bos.flush();
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"flush==>" + targetFile.length() + ",progress==>"
|
||||
+ entry.getProgress() + ",size==>" + entry.getSize());
|
||||
|
||||
if (targetFile.length() == entry.getSize()) {
|
||||
listener.onStatusChanged(DownloadStatus.done);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!entry.isReset()) {
|
||||
entry.setReset(true);
|
||||
download();
|
||||
} else {
|
||||
String errorMsg = Log.getStackTraceString(e);
|
||||
if (!TextUtils.isEmpty(e.getMessage()) && e.getMessage().contains("connection timeout")) {
|
||||
listener.onStatusChanged(DownloadStatus.timeout, errorMsg);
|
||||
} else {
|
||||
listener.onStatusChanged(DownloadStatus.neterror, errorMsg);
|
||||
}
|
||||
Utils.log(DownloadThread.class.getSimpleName(), "exception-->" + e.toString());
|
||||
}
|
||||
} finally {
|
||||
if (bis != null) {
|
||||
try {
|
||||
bis.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (bos != null) {
|
||||
try {
|
||||
bos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private HttpURLConnection openConnection(URL url, long range) throws Exception {
|
||||
HttpURLConnection connection;
|
||||
if ("https".equals(url.getProtocol())) {
|
||||
connection = HttpsUtils.getHttpsURLConnection(url);
|
||||
} else {
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
}
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(CONNECT_TIME);
|
||||
connection.setReadTimeout(READ_TIME);
|
||||
connection.setDoInput(true);
|
||||
connection.setRequestProperty("RANGE", "bytes=" + range + "-");
|
||||
//设置自动重定向
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
return connection;
|
||||
}
|
||||
|
||||
public void setStatus(DownloadStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@ -108,8 +108,9 @@ public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
|
||||
// 关注事件
|
||||
public void onEventMainThread(EBConcernChanged changed) {
|
||||
Utils.log("changed = " + changed.getGameId());
|
||||
Utils.log("changed = " + changed.isConcern());
|
||||
if (!changed.isSingle()) {
|
||||
return;
|
||||
}
|
||||
if (changed.isConcern()) {
|
||||
for (GameEntity gameEntity : concernRecommendAdapter.getGameList()) {
|
||||
if (changed.getGameId().equals(gameEntity.getId())) {
|
||||
@ -215,7 +216,7 @@ public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
for (ConcernInfo concernInfo : concernManager.getConcernGame()) {
|
||||
data.put(concernInfo.getId());
|
||||
}
|
||||
ConcernUtils.updateConcernData(Config.HOST + "v2d0/device/" + uuid + "/concern", data,
|
||||
ConcernUtils.updateConcernData(Config.HOST + "device/" + uuid + "/concern", data,
|
||||
new ConcernUtils.DownJsonListener() {
|
||||
@Override
|
||||
public void downSucced(String str) {
|
||||
|
||||
@ -2,33 +2,39 @@ package com.gh.gamecenter;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.BitmapUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.view.CropImageCustom;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.net.HttpURLConnection;
|
||||
|
||||
public class CropImageActivity extends BaseActivity {
|
||||
|
||||
private CropImageCustom cropimage_custom;
|
||||
|
||||
private SoftReference<Bitmap> reference;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
@ -70,19 +76,19 @@ public class CropImageActivity extends BaseActivity {
|
||||
+ System.currentTimeMillis() + ".jpg";
|
||||
if (cropimage_custom.savePicture(path)) {
|
||||
// 上传图片
|
||||
JSONObject result = FileUtils.uploadFile("http://user.ghzhushou.com/v1d0/icon",
|
||||
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 == HttpStatus.SC_OK) {
|
||||
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 == HttpStatus.SC_FORBIDDEN
|
||||
} else if (statusCode == HttpURLConnection.HTTP_FORBIDDEN
|
||||
&& "too frequent".equals(result.getString("detail"))) {
|
||||
handler.sendEmptyMessage(2);
|
||||
}
|
||||
@ -106,12 +112,27 @@ public class CropImageActivity extends BaseActivity {
|
||||
rparams.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
confirm.setLayoutParams(rparams);
|
||||
reuse_actionbar.addView(confirm);
|
||||
|
||||
String path = getIntent().getStringExtra("path");
|
||||
|
||||
ImageUtils.getInstance(getApplicationContext()).displayFile(
|
||||
"file://" + path, cropimage_custom.getCropImageZoomView());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
if (hasFocus && (reference == null || reference.get() == null)) {
|
||||
ImageView imageView = cropimage_custom.getCropImageZoomView();
|
||||
Bitmap bitmap = BitmapUtils.getBitmapByFile(getIntent().getStringExtra("path"),
|
||||
imageView.getWidth(), imageView.getHeight());
|
||||
if (bitmap != null) {
|
||||
reference = new SoftReference<>(bitmap);
|
||||
imageView.setImageBitmap(reference.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (reference != null) {
|
||||
reference.get().recycle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
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;
|
||||
@ -19,7 +20,7 @@ import com.gh.gamecenter.download.GameDownLoadFragment;
|
||||
import com.gh.gamecenter.download.GameUpdateFragment;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadChanged;
|
||||
import com.gh.gamecenter.eventbus.EBMiPush;
|
||||
import com.gh.gamecenter.eventbus.EBPerformClick;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
@ -46,6 +47,8 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
|
||||
private int width;
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
@ -118,27 +121,19 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
|
||||
public FragmentAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
if (position == 0) {
|
||||
GameDownLoadFragment fragment = new GameDownLoadFragment();
|
||||
fragment.setPath(getIntent().getStringExtra("path"));
|
||||
return fragment;
|
||||
return new GameDownLoadFragment();
|
||||
} else {
|
||||
GameUpdateFragment fragment = new GameUpdateFragment();
|
||||
fragment.setParams(getIntent().getStringExtra(
|
||||
"packageName"), getIntent().getBooleanExtra(
|
||||
"isPushIntent", false));
|
||||
return fragment;
|
||||
return new GameUpdateFragment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
@ -238,11 +233,20 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPerformClick click) {
|
||||
if (click.getFrom().equals("update")) {
|
||||
downloadmanager_ll_download.performClick();
|
||||
|
||||
public void onEventMainThread(EBSkip skip) {
|
||||
if ("DownloadManagerActivity".equals(skip.getType())) {
|
||||
if (skip.getCurrentItem() == 0) {
|
||||
handler.postDelayed(runnable, 300);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
downloadmanager_ll_download.performClick();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@ -91,6 +91,7 @@ public class GameDetailActivity extends DetailActivity implements View.OnClickLi
|
||||
iv_share.setVisibility(View.VISIBLE);
|
||||
}
|
||||
downloadAddWord = adapter.getGameDetailEntity().getDownloadAddWord();
|
||||
downloadOffText = gameEntity.getDownloadOffText();
|
||||
initDownload(true);
|
||||
}
|
||||
|
||||
@ -138,16 +139,20 @@ public class GameDetailActivity extends DetailActivity implements View.OnClickLi
|
||||
// 获取游戏摘要
|
||||
private void getGameDigest() {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/game/" + gameId + "/digest",
|
||||
Config.HOST + "game/" + gameId + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Gson gson = new Gson();
|
||||
gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
title = gameEntity.getName();
|
||||
actionbar_tv_title.setText(gameEntity.getName());
|
||||
adapter.setGameEntity(gameEntity);
|
||||
adapter.getGameDetail();
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
title = gameEntity.getName();
|
||||
actionbar_tv_title.setText(gameEntity.getName());
|
||||
adapter.setGameEntity(gameEntity);
|
||||
adapter.getGameDetail();
|
||||
} else {
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
@ -160,7 +165,7 @@ public class GameDetailActivity extends DetailActivity implements View.OnClickLi
|
||||
|
||||
// 关注事件
|
||||
public void onEventMainThread(EBConcernChanged changed) {
|
||||
if (!TextUtils.isEmpty(gameId) && changed.getGameId().equals(gameId)) {
|
||||
if (!TextUtils.isEmpty(gameId) && changed.isSingle() && changed.getGameId().equals(gameId)) {
|
||||
adapter.notifyItemChanged(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@ -17,7 +14,6 @@ import android.os.SystemClock;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
@ -38,6 +34,7 @@ import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseFragmentActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.ConcernUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DeviceUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
@ -47,7 +44,6 @@ import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.RandomUtils;
|
||||
import com.gh.common.util.RunningUtils;
|
||||
import com.gh.common.util.SpeedUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.TrafficUtils;
|
||||
@ -58,7 +54,6 @@ import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadStatus;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.db.info.SuspectedGameInfo;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.AppEntity;
|
||||
import com.gh.gamecenter.entity.GameDigestEntity;
|
||||
@ -76,7 +71,6 @@ import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.FilterManager;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.manager.SuspectedGameManager;
|
||||
import com.gh.gamecenter.news.NewsFragment;
|
||||
import com.gh.gamecenter.personal.PersonalFragment;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
@ -94,8 +88,6 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
@ -148,12 +140,20 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
// 链接被劫持
|
||||
if (DownloadStatus.hijack.equals(downloadEntity.getStatus())) {
|
||||
// 链接被劫持
|
||||
processHijack(downloadEntity);
|
||||
return;
|
||||
} else if (DownloadStatus.notfound.equals(downloadEntity.getStatus())) {
|
||||
// 404 Not Found
|
||||
// 删除任务
|
||||
downloadEntity.setStatus(DownloadStatus.cancel);
|
||||
DownloadManager.getInstance(getApplicationContext()).cancel(downloadEntity.getUrl());
|
||||
toast("该链接已失效!请联系管理员。");
|
||||
return;
|
||||
} else if (DownloadStatus.neterror.equals(downloadEntity.getStatus())
|
||||
|| DownloadStatus.timeout.equals(downloadEntity.getStatus())) {
|
||||
toast("网络不稳定,下载任务已暂停");
|
||||
uploadNeterrorLog(downloadEntity);
|
||||
}
|
||||
if (downloadEntity.getName().contains("光环助手") && isShowDownload) {
|
||||
@ -163,66 +163,39 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
if (downloadEntity.getName().contains("光环助手")) {
|
||||
DataUtils.onEvent(MainActivity.this, "软件更新", "下载完成");
|
||||
startActivity(PackageUtils.getInstallIntent(downloadEntity.getPath()));
|
||||
uploadUpgradeLog("install");//上传更新安装数据
|
||||
if (appEntity != null && appEntity.isForce()) {
|
||||
finish();
|
||||
}
|
||||
} else {
|
||||
statDoneEvent(downloadEntity);
|
||||
|
||||
if (RunningUtils.isApplicationBroughtToBackground(getApplicationContext())) {
|
||||
// 应用程序在后台,如果是插件化下载,则弹出notification提示用户
|
||||
String platform = PlatformUtils.getInstance(getApplicationContext())
|
||||
.getPlatformName(downloadEntity.getPlatform());
|
||||
if (platform != null) {
|
||||
if (downloadEntity.isPluggable()) {
|
||||
String path = downloadEntity.getPath();
|
||||
String platform = PlatformUtils.getInstance(getApplicationContext())
|
||||
.getPlatformName(downloadEntity.getPlatform());
|
||||
String title = downloadEntity.getName() + " - " + platform;
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("path", path);
|
||||
intent.setAction("com.gh.gamecenter.UNINSTALL");
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(
|
||||
MainActivity.this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
|
||||
Notification notification = new NotificationCompat.Builder(MainActivity.this)
|
||||
.setSmallIcon(R.drawable.logo)
|
||||
.setTicker(title)
|
||||
.setContentTitle(title)
|
||||
.setContentText("下载完成,点击继续插件化。")
|
||||
.setContentIntent(pendingIntent)
|
||||
.build();
|
||||
notification.defaults = Notification.DEFAULT_SOUND;// 添加系统默认声音
|
||||
notification.flags |= Notification.FLAG_AUTO_CANCEL; // FLAG_AUTO_CANCEL表明当通知被用户点击时,通知将被清除。
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(
|
||||
Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.notify(((int) System.currentTimeMillis() / 1000), notification);
|
||||
}
|
||||
} else {
|
||||
String platform = PlatformUtils.getInstance(getApplicationContext())
|
||||
.getPlatformName(downloadEntity.getPlatform());
|
||||
if (platform != null) {
|
||||
if (downloadEntity.isPluggable()) {
|
||||
// 弹出插件化提示框
|
||||
EventBus.getDefault().post(new EBShowDialog("plugin", downloadEntity.getPath()));
|
||||
} else if (platform.equals("官方版")) {
|
||||
toast(downloadEntity.getName() + " - 下载完成");
|
||||
} else {
|
||||
toast(downloadEntity.getName() + " - " + platform + " - 下载完成");
|
||||
}
|
||||
// 弹出插件化提示框
|
||||
EventBus.getDefault().post(new EBShowDialog("plugin", downloadEntity.getPath()));
|
||||
} else if (downloadEntity.isPlugin()) {
|
||||
toast(downloadEntity.getName() + " - " + platform + " - 下载完成");
|
||||
} else {
|
||||
toast(downloadEntity.getName() + " - 下载完成");
|
||||
}
|
||||
if (!downloadEntity.isPluggable()) {
|
||||
// 是否是自动安装
|
||||
if (sp.getBoolean("autoinstall", true)) {
|
||||
if (FileUtils.isEmptyFile(downloadEntity.getPath())) {
|
||||
toast("解析包出错(可能被误删了),请重新下载");
|
||||
DownloadManager.getInstance(MainActivity.this).cancel(downloadEntity.getUrl());
|
||||
} else {
|
||||
toast(downloadEntity.getName() + " - 下载完成");
|
||||
}
|
||||
if (!downloadEntity.isPluggable()) {
|
||||
// 是否是自动安装
|
||||
if (sp.getBoolean("autoinstall", true)) {
|
||||
if (FileUtils.isEmptyFile(downloadEntity.getPath())) {
|
||||
toast("解析包出错(可能被误删了),请重新下载");
|
||||
DownloadManager.getInstance(MainActivity.this).cancel(downloadEntity.getUrl());
|
||||
} else {
|
||||
if (PackageUtils.isCanLaunchSetup(getApplicationContext(), downloadEntity.getPath())) {
|
||||
startActivity(PackageUtils.getInstallIntent(downloadEntity.getPath()));
|
||||
} else {
|
||||
if (PackageUtils.isCanLaunchSetup(getApplicationContext(), downloadEntity.getPath())) {
|
||||
startActivity(PackageUtils.getInstallIntent(downloadEntity.getPath()));
|
||||
} else {
|
||||
// 弹出卸载提示框
|
||||
EventBus.getDefault().post(new EBShowDialog("plugin", downloadEntity.getPath()));
|
||||
}
|
||||
// 弹出卸载提示框
|
||||
EventBus.getDefault().post(new EBShowDialog("plugin", downloadEntity.getPath()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -242,7 +215,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
params.put("platform", platform);
|
||||
JSONObject jsonObject = new JSONObject(params);
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(Method.POST,
|
||||
Config.HOST + "v2/stat/download", jsonObject.toString(), null, null);
|
||||
Config.HOST + "stat/download", jsonObject.toString(), null, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
@ -289,6 +262,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
map.put("status", "完成");
|
||||
map.put("entrance", downloadEntity.getEntrance());
|
||||
map.put("location", downloadEntity.getLocation());
|
||||
map.put("installed", downloadEntity.getInstalled());
|
||||
map.put("network", NetworkUtils.getConnectedType(MainActivity.this));
|
||||
DataCollectionManager.onEvent(MainActivity.this, "download", map);
|
||||
}
|
||||
@ -367,6 +341,50 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
|
||||
DownloadEntity downloadEntity = null;
|
||||
for (DownloadEntity entity : DownloadManager.getInstance(getApplicationContext()).getAll()) {
|
||||
if (entity.getStatus().equals(DownloadStatus.done)) {
|
||||
if (PackageUtils.isInstalled(getApplicationContext(), entity.getPackageName())
|
||||
&& (!entity.isPlugin()
|
||||
|| PackageUtils.isSignature(getApplicationContext(), entity.getPackageName()))) {
|
||||
continue;
|
||||
}
|
||||
if (downloadEntity == null) {
|
||||
downloadEntity = entity;
|
||||
} else if (entity.getEnd() > downloadEntity.getEnd()) {
|
||||
downloadEntity = entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (downloadEntity != null) {
|
||||
String msg;
|
||||
if (downloadEntity.isPlugin()) {
|
||||
msg = "《" + downloadEntity.getName() + "-"
|
||||
+ PlatformUtils.getInstance(getApplicationContext()).getPlatformName(downloadEntity.getPlatform())
|
||||
+ "》已下载完但还未安装,是否立即安装?";
|
||||
} else {
|
||||
msg = "《" + downloadEntity.getName() + "》已下载完但还未安装,是否立即安装?";
|
||||
}
|
||||
final String path = downloadEntity.getPath();
|
||||
DialogUtils.showWarningDialog(this, "提示", msg, "直接退出", "立即安装",
|
||||
new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PackageUtils.launchSetup(MainActivity.this, path);
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
}, new DialogUtils.CancelListener() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
|
||||
mHits[mHits.length - 1] = SystemClock.uptimeMillis();
|
||||
if (mHits[0] >= (SystemClock.uptimeMillis() - 1000)) {
|
||||
@ -412,14 +430,15 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
|
||||
getSearchHints();
|
||||
|
||||
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunch", true);
|
||||
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersion(getApplicationContext()), true);
|
||||
if (!isNewFirstLaunch && sp.getBoolean("autoupdate", true)) {
|
||||
// 检查助手更新
|
||||
checkUpdate();
|
||||
}
|
||||
if (isNewFirstLaunch) {
|
||||
getPluginUpdate();
|
||||
sp.edit().putBoolean("isNewFirstLaunch", false).apply();
|
||||
initConcern(); // 初始化关注
|
||||
sp.edit().putBoolean("isNewFirstLaunchV" + PackageUtils.getVersion(getApplicationContext()), false).apply();
|
||||
}
|
||||
|
||||
// 获取免责声明
|
||||
@ -428,9 +447,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
// 初始化PlatformUtils
|
||||
PlatformUtils.getInstance(getApplicationContext());
|
||||
|
||||
// 解决助手奔溃后导致的下载状态保留问题
|
||||
DownloadManager.getInstance(this).checkAll();
|
||||
|
||||
// 添加观察者
|
||||
DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
|
||||
@ -456,6 +472,80 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
Log.e("TD_CHANNEL_ID", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"));
|
||||
}
|
||||
|
||||
//初始化关注
|
||||
private void initConcern() {
|
||||
final List<String> arrGameId = new ArrayList<>();
|
||||
final String getConcernUrl = Config.HOST + "device/" + TokenUtils.getDeviceId(MainActivity.this) + "/concern";
|
||||
ConcernUtils.loadConcernData(getConcernUrl, new ConcernUtils.DownJsonListener() {
|
||||
@Override
|
||||
public void downSucced(String str) {
|
||||
try {
|
||||
JSONArray jsonArray = new JSONArray(str);
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
String gameId = (String) jsonArray.get(i);
|
||||
arrGameId.add(gameId);
|
||||
}
|
||||
|
||||
getConcernDigest(arrGameId);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downFailed() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private int initConcernCount;
|
||||
|
||||
private void addInitConcernCount() {
|
||||
synchronized (MainActivity.class) {
|
||||
initConcernCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private void getConcernDigest(final List<String> arrGameId) {
|
||||
final ArrayList<GameEntity> concernDigest = new ArrayList<>();
|
||||
|
||||
final int size = arrGameId.size();
|
||||
initConcernCount = 0;
|
||||
for (String gameId : arrGameId) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "game/" + gameId + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
concernDigest.add(gameEntity);
|
||||
}
|
||||
|
||||
addInitConcernCount();
|
||||
if (size == initConcernCount && concernDigest.size() != 0) {
|
||||
concernManager.addByList(concernDigest);
|
||||
Utils.log("初始化关注成功==");
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addInitConcernCount();
|
||||
if (size == initConcernCount && concernDigest.size() != 0) {
|
||||
concernManager.addByList(concernDigest);
|
||||
Utils.log("初始化关注--有一个以上的游戏无法添加");
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
home1Layout = (LinearLayout) findViewById(R.id.main_ll_game);
|
||||
home2Layout = (LinearLayout) findViewById(R.id.main_ll_news);
|
||||
@ -509,26 +599,28 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
return;
|
||||
}
|
||||
|
||||
PackageManager manager = new PackageManager(getApplicationContext());
|
||||
manager.initInstalledMap(list);
|
||||
PackageManager.init(list);
|
||||
|
||||
final int size = list.size();
|
||||
iCount = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
final String packageName = list.get(i);
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v1d45/support/package/" + packageName + "/game/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "support/package/" + packageName + "/game/digest",
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
public void onResponse(JSONArray response) {
|
||||
if (response.length() != 0) {
|
||||
Type listType = new TypeToken<ArrayList<GameDigestEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
GameDigestEntity gameDigestEntity = gson.fromJson(
|
||||
response.toString(), GameDigestEntity.class);
|
||||
GameInfo gameInfo = new GameInfo();
|
||||
gameInfo.setId(gameDigestEntity.getId());
|
||||
gameInfo.setPackageName(packageName);
|
||||
concernManager.updateByEntity(gameInfo);
|
||||
List<GameDigestEntity> list = gson.fromJson(response.toString(), listType);
|
||||
for (GameDigestEntity gameDigestEntity : list) {
|
||||
GameInfo gameInfo = new GameInfo();
|
||||
gameInfo.setId(gameDigestEntity.getId());
|
||||
gameInfo.setPackageName(packageName);
|
||||
gameInfo.setGameName(gameDigestEntity.getName());
|
||||
concernManager.updateByEntity(gameInfo);
|
||||
}
|
||||
}
|
||||
addInstalledCount();
|
||||
if (iCount == size) {
|
||||
@ -557,10 +649,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
|
||||
private void updateConcern() {
|
||||
// 移除疑似游戏数据库中所有数据
|
||||
SuspectedGameManager suspectedGameManager = new SuspectedGameManager(getApplicationContext());
|
||||
suspectedGameManager.deleteAll();
|
||||
|
||||
ArrayList<String> concernIdList = new ArrayList<>();
|
||||
for (ConcernInfo entity : concernManager.getAllConcern()) {
|
||||
concernIdList.add(entity.getId());
|
||||
@ -572,34 +660,37 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
cCount = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/game/" + concernIdList.get(i) + "/digest",
|
||||
Config.HOST + "game/" + concernIdList.get(i) + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
ConcernInfo concernInfo = concernManager.findConcernById(gameEntity.getId());
|
||||
if (concernInfo != null && gameEntity.getApk() != null
|
||||
&& gameEntity.getApk().size() != 0) {
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
String packageName;
|
||||
for (int i = 0, size = gameEntity.getApk().size(); i < size; i++) {
|
||||
packageName = gameEntity.getApk().get(i).getPackageName();
|
||||
if (PackageManager.isInstalled(packageName)) {
|
||||
packageNames.put(packageName, true);
|
||||
} else {
|
||||
packageNames.put(packageName, false);
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
ConcernInfo concernInfo = concernManager.findConcernById(gameEntity.getId());
|
||||
if (concernInfo != null && gameEntity.getApk() != null
|
||||
&& gameEntity.getApk().size() != 0) {
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
String packageName;
|
||||
for (int i = 0, size = gameEntity.getApk().size(); i < size; i++) {
|
||||
packageName = gameEntity.getApk().get(i).getPackageName();
|
||||
if (PackageManager.isInstalled(packageName)) {
|
||||
packageNames.put(packageName, true);
|
||||
} else {
|
||||
packageNames.put(packageName, false);
|
||||
}
|
||||
}
|
||||
concernInfo.setTime(System.currentTimeMillis());
|
||||
concernInfo.setPackageNames(packageNames);
|
||||
concernManager.updateByConcern(concernInfo);
|
||||
}
|
||||
concernInfo.setTime(System.currentTimeMillis());
|
||||
concernInfo.setPackageNames(packageNames);
|
||||
concernManager.updateByConcern(concernInfo);
|
||||
}
|
||||
if (isNewFirstLaunch) {
|
||||
//默认安装即为关注
|
||||
if (!concernManager.isConcern(gameEntity.getId())) {
|
||||
concernManager.addByEntity(gameEntity);
|
||||
}
|
||||
//无需默认关注
|
||||
// if (isNewFirstLaunch) {
|
||||
// //默认安装即为关注
|
||||
// if (!concernManager.isConcern(gameEntity.getId())) {
|
||||
// concernManager.addByEntity(gameEntity);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
addConcernCount();
|
||||
if (cCount == size) {
|
||||
@ -713,78 +804,41 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
|
||||
private void checkGameUpdate() {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
List<ConcernInfo> infos = concernManager.getInstalledGame();
|
||||
for (ConcernInfo info : infos) {
|
||||
for (String packageName : info.getPackageNames().keySet()) {
|
||||
if (info.getPackageNames().get(packageName)) {
|
||||
list.add(packageName);
|
||||
if (info.getPackageNames().get(packageName)
|
||||
&& PackageUtils.getMetaData(this, packageName, "gh_version") != null) {
|
||||
checkGameUpdate(packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Comparator<String> comparator = new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String lhs, String rhs) {
|
||||
return lhs.compareTo(rhs);
|
||||
}
|
||||
};
|
||||
Collections.sort(list, comparator);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String packages;
|
||||
PackageManager.clearUpdateList();
|
||||
for (int i = 0, sizei = (list.size() / 10) + 1; i < sizei; i++) {
|
||||
builder.delete(0, builder.length());
|
||||
for (int j = i * 10, sizej = (i + 1) * 10 > list.size() ? list
|
||||
.size() : (i + 1) * 10; j < sizej; j++) {
|
||||
builder.append(list.get(j));
|
||||
builder.append("-");
|
||||
}
|
||||
if (builder.length() != 0) {
|
||||
packages = builder.substring(0, builder.length() - 1);
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "v1d45/support/package/update?package=" + packages,
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<ArrayList<GameUpdateEntity>>() {}.getType();
|
||||
ArrayList<GameUpdateEntity> games = gson.fromJson(response.toString(), listType);
|
||||
GameUpdateEntity gameUpdateEntity;
|
||||
for (int i = 0; i < games.size(); i++) {
|
||||
gameUpdateEntity = games.get(i);
|
||||
// 判断是否gh_version是否相同
|
||||
String gh_version = (String) PackageUtils.getMetaData(
|
||||
MainActivity.this, 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(
|
||||
MainActivity.this, gameUpdateEntity.getPackageName());
|
||||
if (version != null && version.equals(gameUpdateEntity.getVersion())) {
|
||||
// 版本相同,无需显示插件更新,继续查看是否有可更新的游戏包
|
||||
games.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
games.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
PackageManager.addUpdateList(games);
|
||||
|
||||
private void checkGameUpdate(String packageName) {
|
||||
Object gh_id = PackageUtils.getMetaData(this, packageName, "gh_id");
|
||||
String url;
|
||||
if (gh_id == null) {
|
||||
url = Config.HOST + "update/package/" + packageName;
|
||||
} else {
|
||||
url = Config.HOST + "update/game/" + gh_id + "/package/" + packageName;
|
||||
}
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(url,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
GameUpdateEntity gameUpdateEntity = gson.fromJson(
|
||||
response.toString(), GameUpdateEntity.class);
|
||||
if (PackageUtils.isCanUpdate(MainActivity.this, gameUpdateEntity)) {
|
||||
PackageManager.addUpdate(gameUpdateEntity);
|
||||
EventBus.getDefault().post(new EBDownloadStatus("update"));
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
private int count;
|
||||
@ -802,13 +856,15 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
count = 0;
|
||||
for (ConcernInfo info : infos) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/game/" + info.getId() + "/digest",
|
||||
Config.HOST + "game/" + info.getId() + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
list.add(gameEntity);
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
list.add(gameEntity);
|
||||
}
|
||||
addCount();
|
||||
if (count == size) {
|
||||
processPluginData(list);
|
||||
@ -842,25 +898,12 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
&& gameEntity.getApk() != null) {
|
||||
map = info.getPackageNames();
|
||||
for (String key : map.keySet()) {
|
||||
if (map.get(key) && !PackageUtils.isSignature(this, key)) {
|
||||
if (map.get(key)) {
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(key)) {
|
||||
GameUpdateEntity gameUpdateEntity = new GameUpdateEntity();
|
||||
gameUpdateEntity.setId(gameEntity.getId());
|
||||
gameUpdateEntity.setIcon(gameEntity.getIcon());
|
||||
gameUpdateEntity.setName(gameEntity.getName());
|
||||
gameUpdateEntity.setPackageName(apkEntity.getPackageName());
|
||||
gameUpdateEntity.setSize(apkEntity.getSize());
|
||||
gameUpdateEntity.setVersion(apkEntity.getVersion());
|
||||
gameUpdateEntity.setGhVersion(apkEntity.getGhVersion());
|
||||
gameUpdateEntity.setUrl(apkEntity.getUrl());
|
||||
gameUpdateEntity.setPlatform(apkEntity.getPlatform());
|
||||
gameUpdateEntity.setEtag(apkEntity.getEtag());
|
||||
gameUpdateEntity.setPluggable(true);
|
||||
gameUpdateEntity.setTag(gameEntity.getTag());
|
||||
gameUpdateEntity.setBrief(gameEntity.getBrief());
|
||||
|
||||
PackageManager.addUpdate(gameUpdateEntity);
|
||||
if (apkEntity.getPackageName().equals(key)
|
||||
&& !TextUtils.isEmpty(apkEntity.getGhVersion())
|
||||
&& !PackageUtils.isSignature(this, apkEntity.getPackageName())) {
|
||||
PackageManager.addUpdate(getGameUpdateEntity(gameEntity, apkEntity));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -875,6 +918,24 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
EventBus.getDefault().post(new EBDownloadStatus("plugin"));
|
||||
}
|
||||
|
||||
private GameUpdateEntity getGameUpdateEntity(GameEntity gameEntity, ApkEntity apkEntity) {
|
||||
GameUpdateEntity gameUpdateEntity = new GameUpdateEntity();
|
||||
gameUpdateEntity.setId(gameEntity.getId());
|
||||
gameUpdateEntity.setIcon(gameEntity.getIcon());
|
||||
gameUpdateEntity.setName(gameEntity.getName());
|
||||
gameUpdateEntity.setPackageName(apkEntity.getPackageName());
|
||||
gameUpdateEntity.setSize(apkEntity.getSize());
|
||||
gameUpdateEntity.setVersion(apkEntity.getVersion());
|
||||
gameUpdateEntity.setGhVersion(apkEntity.getGhVersion());
|
||||
gameUpdateEntity.setUrl(apkEntity.getUrl());
|
||||
gameUpdateEntity.setPlatform(apkEntity.getPlatform());
|
||||
gameUpdateEntity.setEtag(apkEntity.getEtag());
|
||||
gameUpdateEntity.setPluggable(true);
|
||||
gameUpdateEntity.setTag(gameEntity.getTag());
|
||||
gameUpdateEntity.setBrief(gameEntity.getBrief());
|
||||
return gameUpdateEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
@ -936,22 +997,24 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
// 获取免责声明
|
||||
private void getDisclaimer(final boolean isFirst) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2/disclaimer",
|
||||
Config.HOST + "disclaimer",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
try {
|
||||
boolean isShow = response.getBoolean("isShow");
|
||||
sp.edit().putBoolean("isShowDisclaimer", isShow).apply();
|
||||
if (isShow) {
|
||||
String content = response.getString("content");
|
||||
sp.edit().putString("disclaimer", content).apply();
|
||||
if (isFirst) {
|
||||
DialogUtils.showDisclaimerDialog(MainActivity.this, content);
|
||||
if (response.length() != 0) {
|
||||
try {
|
||||
boolean isShow = response.getBoolean("isShow");
|
||||
sp.edit().putBoolean("isShowDisclaimer", isShow).apply();
|
||||
if (isShow) {
|
||||
String content = response.getString("content");
|
||||
sp.edit().putString("disclaimer", content).apply();
|
||||
if (isFirst) {
|
||||
DialogUtils.showDisclaimerDialog(MainActivity.this, content);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
@ -983,13 +1046,16 @@ 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", getIntent().getExtras().getString("entrance"));
|
||||
toIntent.putExtra("entrance", "(插件跳转)");
|
||||
} else if("DownloadManagerActivity".equals(to)) {
|
||||
toIntent.putExtra("packageName" , getIntent().getExtras().getString("packageName"));
|
||||
toIntent.putExtra("currentItem" , 1);
|
||||
String packageName = getIntent().getExtras().getString("packageName");
|
||||
if (packageName != null) {
|
||||
toIntent.putExtra("packageName" , getIntent().getExtras().getString("packageName"));
|
||||
toIntent.putExtra("currentItem" , 1);
|
||||
}
|
||||
} else if ("GameDetailsActivity".equals(to) || "GameDetailActivity".equals(to)) {
|
||||
toIntent.putExtra("gameId", getIntent().getExtras().getString("gameId"));
|
||||
toIntent.putExtra("entrance", getIntent().getExtras().getString("entrance"));
|
||||
toIntent.putExtra("entrance", "(插件跳转)");
|
||||
} else if ("SubjectActivity".equals(to)) {
|
||||
toIntent.putExtra("id", getIntent().getExtras().getString("id"));
|
||||
toIntent.putExtra("name", getIntent().getExtras().getString("name"));
|
||||
@ -1011,12 +1077,12 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
startActivity(intent);
|
||||
} else if (from.equals("mipush_news")) {
|
||||
Intent intent = new Intent(MainActivity.this, NewsDetailActivity.class);
|
||||
intent.putExtra("entrance", "小米推送");
|
||||
intent.putExtra("entrance", "(小米推送)");
|
||||
intent.putExtra("newsId", getIntent().getStringExtra("newsId"));
|
||||
startActivity(intent);
|
||||
} else if (from.equals("mipush_new_game")) {
|
||||
Intent intent = new Intent(MainActivity.this, GameDetailActivity.class);
|
||||
intent.putExtra("entrance", "小米推送");
|
||||
intent.putExtra("entrance", "(小米推送)");
|
||||
startActivity(intent);
|
||||
} else if (from.equals("mipush_plugin")) {
|
||||
Intent intent = new Intent(MainActivity.this, DownloadManagerActivity.class);
|
||||
@ -1037,7 +1103,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
|
||||
private void getSearchHints() {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "v1d45/search/game/default",
|
||||
Config.HOST + "search/game/default",
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
@ -1061,7 +1127,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
|
||||
private void checkUpdate() {
|
||||
String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID");
|
||||
String url = Config.HOST + "v2d0/support/upgrade?version=" + PackageUtils.getVersion(getApplicationContext())
|
||||
String url = Config.HOST + "support/upgrade?version=" + PackageUtils.getVersion(getApplicationContext())
|
||||
+ "&channel=" + TD_CHANNEL_ID;
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(url,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@ -1082,6 +1148,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
game.setVersion(appEntity.getVersion());
|
||||
game.setUrl(appEntity.getUrl());
|
||||
game.setPlatform("官方版");
|
||||
game.setId("5618b86e8ab49e17088b4575");
|
||||
PackageManager.addUpdate(0, game);
|
||||
|
||||
String updateMD5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent());
|
||||
@ -1113,6 +1180,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
|
||||
private void showUpdateDialog(final String md5) {
|
||||
uploadUpgradeLog("notice"); //上传更新通知弹窗数据
|
||||
final Dialog updateDialog = new Dialog(this);
|
||||
View view = View.inflate(this, R.layout.app_update_hint_dialog, null);
|
||||
|
||||
@ -1120,7 +1188,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
content.setText(Html.fromHtml(appEntity.getContent()));
|
||||
|
||||
TextView versison = (TextView) view.findViewById(R.id.update_app_version);
|
||||
versison.setText(String.format("光环助手V%s更新内容:",appEntity.getVersion()));
|
||||
versison.setText(String.format("光环助手V%s更新内容:", appEntity.getVersion()));
|
||||
|
||||
TextView size = (TextView) view.findViewById(R.id.update_app_size);
|
||||
size.setText(String.format("大小:%s", appEntity.getSize()));
|
||||
@ -1146,6 +1214,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
"光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk");
|
||||
File file = new File(path);
|
||||
if (file.exists() && file.length() > 0) {
|
||||
uploadUpgradeLog("install");//上传更新安装数据
|
||||
startActivity(PackageUtils.getInstallIntent(path));
|
||||
} else {
|
||||
DataUtils.onEvent(MainActivity.this, "软件更新", "下载开始");
|
||||
@ -1163,14 +1232,14 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
updateDialog.show();
|
||||
}
|
||||
|
||||
private Dialog dialog;
|
||||
private Dialog downloadDialog;
|
||||
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) {
|
||||
dialog = new Dialog(this);
|
||||
downloadDialog = new Dialog(this);
|
||||
|
||||
View view = View.inflate(this, R.layout.app_updating_dialog, null);
|
||||
|
||||
@ -1186,18 +1255,18 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
if (appEntity.isForce()) {
|
||||
finish();
|
||||
} else {
|
||||
dialog.dismiss();
|
||||
downloadDialog.dismiss();
|
||||
isShowDownload = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.setCancelable(false);
|
||||
dialog.closeOptionsMenu();
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
downloadDialog.setCanceledOnTouchOutside(false);
|
||||
downloadDialog.setCancelable(false);
|
||||
downloadDialog.closeOptionsMenu();
|
||||
downloadDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
downloadDialog.setContentView(view);
|
||||
downloadDialog.show();
|
||||
|
||||
isShowDownload = true;
|
||||
|
||||
@ -1227,11 +1296,37 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
app_tv_percent.setText(downloadEntity.getPercent() + "%");
|
||||
if (DownloadStatus.done.equals(downloadEntity.getStatus())) {
|
||||
DownloadManager.getInstance(getApplicationContext()).cancel(downloadEntity.getUrl(), false);
|
||||
dialog.dismiss();
|
||||
if (downloadDialog != null) {
|
||||
downloadDialog.dismiss();
|
||||
}
|
||||
isShowDownload = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void uploadUpgradeLog(String step) {
|
||||
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");
|
||||
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";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("topic", "upgrade");
|
||||
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(Method.POST, url, null, null);
|
||||
request.setParams(params);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
Utils.log("提交更新数据" + new JSONObject(params).toString());
|
||||
}
|
||||
|
||||
// 获取META-INF中的plugin_update 文件,判断是否从游戏插件中下载的app,是则获取游戏id,启动游戏更新,下载该游戏
|
||||
private void getPluginUpdate() {
|
||||
ApplicationInfo appinfo = getApplicationInfo();
|
||||
@ -1402,7 +1497,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String packageName = busFour.getPackageName();
|
||||
final String packageName = busFour.getPackageName();
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
// 添加进已安装map中
|
||||
PackageManager.addInstalled(packageName);
|
||||
@ -1430,7 +1525,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
DownloadManager.getInstance(getApplicationContext()).cancel(
|
||||
mDownloadEntity.getUrl(), sp.getBoolean("autodelete", true));
|
||||
}
|
||||
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
Map<String, Object> kv6 = new HashMap<>();
|
||||
kv6.put("安装或卸载", "卸载完成");
|
||||
@ -1441,57 +1535,42 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameManager gameManager = new GameManager(getApplicationContext());
|
||||
GameInfo gameEntity = gameManager.findGame(packageName);
|
||||
if (gameEntity != null) {
|
||||
concernManager.updateByEntity(gameEntity);
|
||||
} else {
|
||||
FilterManager filterManager = new FilterManager(getApplicationContext());
|
||||
if (!filterManager.isFilter(packageName)) {
|
||||
SuspectedGameManager suspectedGameManager = new SuspectedGameManager(getApplicationContext());
|
||||
suspectedGameManager.addGame(new SuspectedGameInfo(
|
||||
packageName, System.currentTimeMillis()));
|
||||
}
|
||||
GameInfo gameInfo = gameManager.findGame(packageName);
|
||||
if (gameInfo != null) {
|
||||
concernManager.updateByEntity(gameInfo);
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
FilterManager filterManager = new FilterManager(getApplicationContext());
|
||||
if (!filterManager.isFilter(packageName)) {
|
||||
SuspectedGameManager suspectedGameManager = new SuspectedGameManager(getApplicationContext());
|
||||
suspectedGameManager.deleteSuspectedGame(packageName);
|
||||
|
||||
concernManager.updateByPackageName(packageName);
|
||||
}
|
||||
}
|
||||
if ("卸载".equals(busFour.getType())) {
|
||||
ArrayList<GameUpdateEntity> list = PackageManager.getUpdateList();
|
||||
GameUpdateEntity game;
|
||||
int index = -1;
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
game = list.get(i);
|
||||
if (!game.isPluggable()) {
|
||||
continue;
|
||||
}
|
||||
if (game.getPackageName().equals(packageName)) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index != -1) {
|
||||
PackageManager.removeUpdateList(packageName);
|
||||
}
|
||||
if ("卸载".equals(busFour.getType()) || "安装".equals(busFour.getType())) {
|
||||
PackageManager.removeUpdate(packageName);
|
||||
}
|
||||
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
// 安装后关注游戏
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v1d45/support/package/" + packageName + "/game/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "support/package/" + packageName + "/game/digest",
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
public void onResponse(JSONArray response) {
|
||||
if (response.length() != 0) {
|
||||
Type listType = new TypeToken<ArrayList<GameDigestEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
GameDigestEntity gameDigestEntity = gson.fromJson(
|
||||
response.toString(), GameDigestEntity.class);
|
||||
concernGame(gameDigestEntity.getId());
|
||||
List<GameDigestEntity> list = gson.fromJson(response.toString(), listType);
|
||||
for (GameDigestEntity gameDigestEntity : list) {
|
||||
GameInfo gameInfo = new GameInfo();
|
||||
gameInfo.setId(gameDigestEntity.getId());
|
||||
gameInfo.setPackageName(packageName);
|
||||
gameInfo.setGameName(gameDigestEntity.getName());
|
||||
concernManager.updateByEntity(gameInfo);
|
||||
concernGame(gameDigestEntity.getId(), packageName);
|
||||
if (PackageUtils.getMetaData(getApplicationContext(),
|
||||
packageName, "gh_version") != null) {
|
||||
checkGameUpdate(packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
@ -1504,20 +1583,37 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
DataCollectionManager.onEvent(this, "inorunstall", map);
|
||||
}
|
||||
|
||||
private void concernGame(String id) {
|
||||
if (!concernManager.isConcern(id)) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/game/" + id + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
private void concernGame(final String id, final String packageName) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "game/" + id + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
concernManager.addByEntity(gameEntity);
|
||||
GameManager manager = new GameManager(getApplicationContext());
|
||||
manager.addOrUpdate(gameEntity.getApk(), gameEntity.getId(), gameEntity.getName());
|
||||
if (!concernManager.isConcern(id)) {
|
||||
concernManager.addByEntity(gameEntity);
|
||||
}
|
||||
// 检查是否能插件化
|
||||
if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& gameEntity.getApk() != null) {
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(packageName)
|
||||
&& !TextUtils.isEmpty(apkEntity.getGhVersion())
|
||||
&& !PackageUtils.isSignature(getApplicationContext(), apkEntity.getPackageName())) {
|
||||
PackageManager.addUpdate(getGameUpdateEntity(gameEntity, apkEntity));
|
||||
EventBus.getDefault().post(new EBDownloadStatus("plugin"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -220,24 +220,32 @@ public class NewsDetailActivity extends DetailActivity implements OnClickListene
|
||||
|
||||
private void getNewsDigest(final String news_id) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v1d45/news/" + news_id + "/digest",
|
||||
Config.HOST + "news/" + news_id + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Gson gson = new Gson();
|
||||
NewsEntity newsEntity = gson.fromJson(response.toString(), NewsEntity.class);
|
||||
if (newsEntity.getType() != null) {
|
||||
actionbar_tv_title.setText(newsEntity.getType());
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
NewsEntity newsEntity = gson.fromJson(response.toString(), NewsEntity.class);
|
||||
if (newsEntity.getType() != null) {
|
||||
actionbar_tv_title.setText(newsEntity.getType());
|
||||
}
|
||||
|
||||
adapter.setId(news_id);
|
||||
adapter.setType(newsEntity.getType());
|
||||
adapter.setTitle(newsEntity.getTitle());
|
||||
adapter.getNewsDetail();
|
||||
|
||||
title = newsEntity.getTitle();
|
||||
|
||||
iv_share.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
detail_rv_show.setVisibility(View.GONE);
|
||||
reuse_ll_loading.setVisibility(View.GONE);
|
||||
detail_ll_bottom.setVisibility(View.GONE);
|
||||
detail_rv_show.setPadding(0, 0, 0, 0);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
adapter.setId(news_id);
|
||||
adapter.setType(newsEntity.getType());
|
||||
adapter.setTitle(newsEntity.getTitle());
|
||||
adapter.getNewsDetail();
|
||||
|
||||
title = newsEntity.getTitle();
|
||||
|
||||
iv_share.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
@ -321,16 +329,19 @@ public class NewsDetailActivity extends DetailActivity implements OnClickListene
|
||||
return;
|
||||
}
|
||||
JsonObjectExtendedRequest gameRequest = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/game/" + gameId + "/news_digest",
|
||||
Config.HOST + "game/" + gameId + "/news_digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Gson gson = new Gson();
|
||||
gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
adapter.setGameEntity(gameEntity); //出现空指针 找不到原因
|
||||
adapter.notifyItemInserted(1);
|
||||
downloadAddWord = gameEntity.getDownloadAddWord();
|
||||
initDownload(true);
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
adapter.setGameEntity(gameEntity);
|
||||
adapter.notifyItemInserted(1);
|
||||
downloadAddWord = gameEntity.getDownloadAddWord();
|
||||
downloadOffText = gameEntity.getDownloadOffText();
|
||||
initDownload(true);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(gameRequest, TAG);
|
||||
@ -338,7 +349,7 @@ public class NewsDetailActivity extends DetailActivity implements OnClickListene
|
||||
|
||||
// 关注事件
|
||||
public void onEventMainThread(EBConcernChanged changed) {
|
||||
if (gameEntity != null && changed.getGameId().equals(gameEntity.getId())) {
|
||||
if (gameEntity != null && changed.isSingle() && changed.getGameId().equals(gameEntity.getId())) {
|
||||
adapter.notifyItemChanged(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
map.put("from", "游戏新闻搜索");
|
||||
DataCollectionManager.onEvent(this, "search", map);
|
||||
|
||||
String url = Config.HOST + "v1d45/search/news?game_id=" + gameId
|
||||
String url = Config.HOST + "search/news?game_id=" + gameId
|
||||
+ "&keyword=" + Uri.encode(searchKey) + "&page="+ page + "&limit=20";
|
||||
final JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(url,
|
||||
new Response.Listener<JSONArray>() {
|
||||
|
||||
@ -3,7 +3,6 @@ package com.gh.gamecenter;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
@ -20,6 +19,7 @@ import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -43,13 +43,15 @@ public class PluginActivity extends BaseActivity {
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
//特殊 插件化update
|
||||
if (downloadEntity.isPluggable()) {
|
||||
Integer location = adapter.getLocationMap().get(
|
||||
downloadEntity.getName() + " - " + downloadEntity.getPlatform());
|
||||
if (location != null) {
|
||||
GameEntity detailedEntity = adapter.getPluginList().get(location);
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(PluginActivity.this, detailedEntity,
|
||||
downloadEntity, adapter, location);
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(downloadEntity.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
gameEntity = adapter.getPluginList().get(location);
|
||||
if (gameEntity != null) {
|
||||
DownloadItemUtils.processDate(PluginActivity.this, gameEntity,
|
||||
downloadEntity, adapter, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -95,17 +97,17 @@ public class PluginActivity extends BaseActivity {
|
||||
public void onEventMainThread(EBDownloadStatus status) {
|
||||
if ("delete".equals(status.getStatus())) {
|
||||
DownloadManager.getInstance(this).removePlatform(status.getName(), status.getPlatform());
|
||||
Integer location = adapter.getLocationMap().get(status.getName() + " - " + status.getPlatform());
|
||||
if (location != null) {
|
||||
GameEntity gameEntity = adapter.getPluginList().get(location);
|
||||
if (gameEntity != null && gameEntity.getEntryMap() != null) {
|
||||
if (TextUtils.isEmpty(status.getPlatform())) {
|
||||
gameEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(status.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
gameEntity = adapter.getPluginList().get(location);
|
||||
if (gameEntity != null && gameEntity.getEntryMap() != null) {
|
||||
gameEntity.getEntryMap().remove(status.getPlatform());
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -125,16 +127,13 @@ public class PluginActivity extends BaseActivity {
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
//特殊 插件化
|
||||
String name = adapter.getNameMap().get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
Integer location = adapter.getLocationMap().get(name);
|
||||
if (location != null) {
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(busFour.getPackageName());
|
||||
if (locationList != null) {
|
||||
for (int location : locationList) {
|
||||
if ("安装".equals(busFour.getType()) || "卸载".equals(busFour.getType())) {
|
||||
List<GameEntity> list = adapter.getPluginList();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
if (list.get(i).getApk().get(0).getPackageName()
|
||||
.equals(busFour.getPackageName())) {
|
||||
if (list.get(i).getApk().get(0).getPackageName().equals(busFour.getPackageName())) {
|
||||
list.remove(i);
|
||||
adapter.notifyItemRemoved(location);
|
||||
break;
|
||||
@ -142,6 +141,7 @@ public class PluginActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
}
|
||||
adapter.initLocationMap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -19,17 +20,20 @@ import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DeviceUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.MD5Utils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.SpeedUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntity;
|
||||
@ -40,12 +44,15 @@ import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.StringExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.kyleduo.switchbutton.SwitchButton;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
@ -67,7 +74,8 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
private Dialog dialog = null;
|
||||
private Dialog loadingDialog = null;
|
||||
private Dialog downloadDialog = null;
|
||||
|
||||
private AppEntity appEntity;
|
||||
|
||||
@ -96,8 +104,8 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
if (appEntity != null && appEntity.isForce()) {
|
||||
AppController.getInstance().finishActivity();
|
||||
} else {
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
if (downloadDialog != null) {
|
||||
downloadDialog.dismiss();
|
||||
}
|
||||
isShowDownload = false;
|
||||
}
|
||||
@ -230,7 +238,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
setting_sb_autoupdate.performClick();
|
||||
break;
|
||||
case R.id.setting_rl_update:
|
||||
dialog = DialogUtils.showWaitDialog(this, "检查更新中...");
|
||||
loadingDialog = DialogUtils.showWaitDialog(this, "检查更新中...");
|
||||
if (isChecking)
|
||||
break;
|
||||
isChecking = true;
|
||||
@ -241,7 +249,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
dialog = DialogUtils.showWaitDialog(context, "清除缓存中...");
|
||||
loadingDialog = DialogUtils.showWaitDialog(context, "清除缓存中...");
|
||||
claerCache();
|
||||
}
|
||||
});
|
||||
@ -330,8 +338,8 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
if (loadingDialog != null) {
|
||||
loadingDialog.dismiss();
|
||||
}
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
@ -362,7 +370,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
private void checkUpdate() {
|
||||
String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this,
|
||||
getPackageName(), "TD_CHANNEL_ID");
|
||||
String url = Config.HOST + "v2d0/support/upgrade?version=" + PackageUtils.getVersion(getApplicationContext())
|
||||
String url = Config.HOST + "support/upgrade?version=" + PackageUtils.getVersion(getApplicationContext())
|
||||
+ "&channel=" + TD_CHANNEL_ID;
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(url,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@ -370,8 +378,8 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
public void onResponse(JSONObject response) {
|
||||
|
||||
isChecking = false;
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
if (loadingDialog != null) {
|
||||
loadingDialog.dismiss();
|
||||
}
|
||||
|
||||
if (response.length() == 0) {
|
||||
@ -394,6 +402,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
game.setVersion(appEntity.getVersion());
|
||||
game.setUrl(appEntity.getUrl());
|
||||
game.setPlatform("官方版");
|
||||
game.setId("5618b86e8ab49e17088b4575");
|
||||
PackageManager.addUpdate(0, game);
|
||||
|
||||
String updateMD5 = MD5Utils.getUpdateMD5(
|
||||
@ -412,8 +421,8 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
isChecking = false;
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
if (loadingDialog != null) {
|
||||
loadingDialog.dismiss();
|
||||
}
|
||||
|
||||
Utils.log("error = " + error.toString());
|
||||
@ -425,23 +434,19 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
}
|
||||
|
||||
private void showUpdateDialog(final String md5) {
|
||||
dialog = new Dialog(this);
|
||||
View view = View.inflate(this, R.layout.app_update_hint_dialog,
|
||||
null);
|
||||
TextView content = (TextView) view
|
||||
.findViewById(R.id.updeta_content);
|
||||
TextView size = (TextView) view
|
||||
.findViewById(R.id.update_app_size);
|
||||
uploadUpgradeLog("notice"); //上传更新通知弹窗数据
|
||||
final Dialog updateDialog = new Dialog(this);
|
||||
View view = View.inflate(this, R.layout.app_update_hint_dialog, null);
|
||||
|
||||
TextView content = (TextView) view.findViewById(R.id.updeta_content);
|
||||
content.setText(Html.fromHtml(appEntity.getContent()));
|
||||
|
||||
TextView versison = (TextView) view.findViewById(R.id.update_app_version);
|
||||
versison.setText(String.format("光环助手V%s更新内容:", appEntity.getVersion()));
|
||||
|
||||
versison.setText("光环助手V"+appEntity.getVersion()+"更新内容:");
|
||||
size.setText("大小:"+appEntity.getSize());
|
||||
content.setText(appEntity.getContent()+"");
|
||||
TextView size = (TextView) view.findViewById(R.id.update_app_size);
|
||||
size.setText(String.format("大小:%s", appEntity.getSize()));
|
||||
|
||||
if (appEntity.isForce()) {
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.setCancelable(false);
|
||||
}
|
||||
view.findViewById(R.id.update_cannel).setOnClickListener(
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
@ -452,9 +457,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
} else {
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
updateDialog.dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -462,15 +465,12 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
String path = FileUtils.getDownloadPath(
|
||||
SettingActivity.this,
|
||||
"光环助手V" + appEntity.getVersion() + "_" + md5
|
||||
+ ".apk");
|
||||
updateDialog.dismiss();
|
||||
String path = FileUtils.getDownloadPath(SettingActivity.this,
|
||||
"光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk");
|
||||
File file = new File(path);
|
||||
if (file.exists() && file.length() > 0) {
|
||||
uploadUpgradeLog("install");//上传更新安装数据
|
||||
startActivity(PackageUtils.getInstallIntent(path));
|
||||
} else {
|
||||
DataUtils.onEvent(SettingActivity.this, "软件更新", "下载开始");
|
||||
@ -478,16 +478,20 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
if (appEntity.isForce()) {
|
||||
updateDialog.setCanceledOnTouchOutside(false);
|
||||
updateDialog.setCancelable(false);
|
||||
}
|
||||
updateDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
updateDialog.setContentView(view);
|
||||
updateDialog.show();
|
||||
}
|
||||
|
||||
private void showDownloadDialog(String md5) {
|
||||
dialog = new Dialog(SettingActivity.this);
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.setCancelable(false);
|
||||
dialog.closeOptionsMenu();
|
||||
final Dialog downloadDialog = new Dialog(SettingActivity.this);
|
||||
downloadDialog.setCanceledOnTouchOutside(false);
|
||||
downloadDialog.setCancelable(false);
|
||||
downloadDialog.closeOptionsMenu();
|
||||
View view = View.inflate(this, R.layout.app_updating_dialog, null);
|
||||
|
||||
app_pb_progress = (ProgressBar) view.findViewById(R.id.app_pb_progress);
|
||||
@ -506,17 +510,15 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
} else {
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
downloadDialog.dismiss();
|
||||
isShowDownload = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
downloadDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
downloadDialog.setContentView(view);
|
||||
downloadDialog.show();
|
||||
|
||||
isShowDownload = true;
|
||||
|
||||
@ -544,6 +546,30 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
DownloadManager.getInstance(getApplicationContext()).add(downloadEntity);
|
||||
}
|
||||
|
||||
private void uploadUpgradeLog(String step) {
|
||||
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");
|
||||
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";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("topic", "upgrade");
|
||||
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, TAG);
|
||||
Utils.log("提交更新数据" + new JSONObject(params).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
@ -10,6 +10,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
@ -25,7 +26,9 @@ import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadService;
|
||||
import com.gh.gamecenter.db.info.FilterInfo;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
@ -69,6 +72,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
private long start;
|
||||
|
||||
private boolean isFirst;
|
||||
private boolean isNewFirstLaunch;
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
@ -78,14 +82,16 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
TimestampUtils.initMap();
|
||||
|
||||
isFirst = true;
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersion(getApplicationContext()), true);
|
||||
|
||||
from = getIntent().getStringExtra("from");
|
||||
|
||||
if (sp.getBoolean("isNewFirstLaunch", true)
|
||||
|| sp.getInt("actionbar_height", 0) != 0) {
|
||||
if (isNewFirstLaunch || sp.getInt("actionbar_height", 0) != 0) {
|
||||
setTheme(R.style.AppTheme_Guide);
|
||||
} else {
|
||||
setTheme(R.style.AppTheme_Fullscreen);
|
||||
@ -101,7 +107,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
if (sp.getBoolean("isNewFirstLaunch", true)) {
|
||||
if (isNewFirstLaunch) {
|
||||
setContentView(R.layout.activity_splash_intro);
|
||||
ViewPager splash_viewPager = (ViewPager) findViewById(R.id.splash_viewPager);
|
||||
splash_viewPager.setAdapter(new ViewPagerAdapter());
|
||||
@ -112,8 +118,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
private class ViewPagerAdapter extends PagerAdapter {
|
||||
|
||||
private int[] pics = { R.drawable.splash_01, R.drawable.splash_02,
|
||||
R.drawable.splash_03, R.drawable.splash_04 };
|
||||
private int[] pics = { R.drawable.splash_01 };
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
@ -164,7 +169,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
|
||||
if (sp.getBoolean("isNewFirstLaunch", true)) {
|
||||
if (isNewFirstLaunch) {
|
||||
launch();
|
||||
} else {
|
||||
return true;
|
||||
@ -226,8 +231,14 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
*/
|
||||
DataCollectionManager.getInstance(getApplicationContext()).upload();
|
||||
|
||||
// 解决助手奔溃后导致的下载状态保留问题
|
||||
DownloadManager.getInstance(this).checkAll();
|
||||
|
||||
// 开启下载服务
|
||||
startService(new Intent(this, DownloadService.class));
|
||||
|
||||
// 不是第一次启动
|
||||
if (!sp.getBoolean("isNewFirstLaunch", true)) {
|
||||
if (!isNewFirstLaunch) {
|
||||
int height = sp.getInt("actionbar_height", 0);
|
||||
if (height == 0) {
|
||||
final ActionBar actionBar = getActionBar();
|
||||
@ -255,7 +266,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
*/
|
||||
private void getTime() {
|
||||
StringExtendedRequest request = new StringExtendedRequest(
|
||||
Request.Method.GET, Config.HOST + "v2d0/support/time/current",
|
||||
Request.Method.GET, Config.HOST + "support/time/current",
|
||||
new Response.Listener<String>() {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
@ -280,22 +291,23 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
*/
|
||||
private void getUISetting() {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v1d45/support/setting/ui",
|
||||
Config.HOST + "support/setting/ui",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Utils.log(response.toString());
|
||||
try {
|
||||
Editor editor = sp.edit();
|
||||
editor.putInt("download_box_row",
|
||||
response.getJSONObject("download_box").getInt("row"));
|
||||
editor.putInt("download_box_column",
|
||||
response.getJSONObject("download_box").getInt("column"));
|
||||
editor.putInt("game_detail_news_type_tab_column",
|
||||
response.getJSONObject("game_detail_news_type_tab").getInt("column"));
|
||||
editor.apply();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
if (response.length() != 0) {
|
||||
try {
|
||||
Editor editor = sp.edit();
|
||||
editor.putInt("download_box_row",
|
||||
response.getJSONObject("download_box").getInt("row"));
|
||||
editor.putInt("download_box_column",
|
||||
response.getJSONObject("download_box").getInt("column"));
|
||||
editor.putInt("game_detail_news_type_tab_column",
|
||||
response.getJSONObject("game_detail_news_type_tab").getInt("column"));
|
||||
editor.apply();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
@ -309,21 +321,23 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this,
|
||||
getPackageName(), "TD_CHANNEL_ID");
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/support/download_status?version=" + PackageUtils.getVersion(getApplicationContext())
|
||||
Config.HOST + "support/download_status?version=" + PackageUtils.getVersion(getApplicationContext())
|
||||
+ "&channel=" + TD_CHANNEL_ID,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
try {
|
||||
String status = response.getString("status");
|
||||
if ("on".equals(status)) {
|
||||
sp.edit().putBoolean("isShow", true).apply();
|
||||
} else {
|
||||
sp.edit().putBoolean("isShow", false).apply();
|
||||
if (response.length() != 0) {
|
||||
try {
|
||||
String status = response.getString("status");
|
||||
if ("on".equals(status)) {
|
||||
sp.edit().putBoolean("isShow", true).apply();
|
||||
} else {
|
||||
sp.edit().putBoolean("isShow", false).apply();
|
||||
}
|
||||
EventBus.getDefault().post(new EBReuse("Refresh"));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
EventBus.getDefault().post(new EBReuse("Refresh"));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
@ -355,7 +369,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
private void getPlatform() {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "v1d45/support/setting/platform",
|
||||
Config.HOST + "support/setting/platform",
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
@ -393,14 +407,16 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
intentControl(bundle, intent);
|
||||
} else {
|
||||
intent.putExtra("from", from);
|
||||
if ("plugin".equals(from)) {
|
||||
intent.putExtra("packageName", getIntent().getStringExtra("packageName"));
|
||||
} else if ("mipush_news".equals(from)) {
|
||||
intent.putExtra("newsId", getIntent().getStringExtra("newsId"));
|
||||
} else if ("mipush_plugin".equals(from)) {
|
||||
intent.putExtra("data", getIntent().getStringExtra("data"));
|
||||
} else if ("plugin_install".equals(from)) {
|
||||
intent.putExtra("path", getIntent().getStringExtra("path"));
|
||||
if (!TextUtils.isEmpty(from)) {
|
||||
if ("plugin".equals(from)) {
|
||||
intent.putExtra("packageName", getIntent().getStringExtra("packageName"));
|
||||
} else if ("mipush_news".equals(from)) {
|
||||
intent.putExtra("newsId", getIntent().getStringExtra("newsId"));
|
||||
} else if ("mipush_plugin".equals(from)) {
|
||||
intent.putExtra("data", getIntent().getStringExtra("data"));
|
||||
} else if ("plugin_install".equals(from)) {
|
||||
intent.putExtra("path", getIntent().getStringExtra("path"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@ package com.gh.gamecenter;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
@ -21,6 +20,8 @@ import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SubjectActivity extends BaseActivity {
|
||||
|
||||
public static final String TAG = SubjectActivity.class.getSimpleName();
|
||||
@ -31,25 +32,23 @@ public class SubjectActivity extends BaseActivity {
|
||||
private LinearLayout reuse_no_connection;
|
||||
private LinearLayoutManager layoutManager;
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String entrance;
|
||||
|
||||
private int page = 1;
|
||||
|
||||
private boolean order;
|
||||
private boolean isEverpause = false;
|
||||
|
||||
// 黄壮华 添加观察者 修改2015/8/15
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
Integer location = adapter.getLocationMap().get(downloadEntity.getName());
|
||||
if (location != null) {
|
||||
GameEntity detailedEntity = adapter.getList().get(location);
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(SubjectActivity.this, detailedEntity, downloadEntity,
|
||||
adapter, location);
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(downloadEntity.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
gameEntity = adapter.getSubjectList().get(location);
|
||||
if (gameEntity != null) {
|
||||
DownloadItemUtils.processDate(SubjectActivity.this, gameEntity, downloadEntity,
|
||||
adapter, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,14 +58,8 @@ public class SubjectActivity extends BaseActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
entrance = getIntent().getStringExtra("entrance");
|
||||
|
||||
id = getIntent().getStringExtra("id");
|
||||
name = getIntent().getStringExtra("name");
|
||||
order = getIntent().getBooleanExtra("order",false);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_subject, null);
|
||||
init(contentView, name);
|
||||
init(contentView, getIntent().getStringExtra("name"));
|
||||
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -74,7 +67,7 @@ public class SubjectActivity extends BaseActivity {
|
||||
subject_pb_loading.setVisibility(View.VISIBLE);
|
||||
subject_list.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new SubjectAdapter(SubjectActivity.this, id, name, order, entrance);
|
||||
adapter = new SubjectAdapter(SubjectActivity.this);
|
||||
subject_list.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
@ -83,7 +76,7 @@ public class SubjectActivity extends BaseActivity {
|
||||
|
||||
subject_list.setHasFixedSize(true);
|
||||
subject_list.setLayoutManager(layoutManager);
|
||||
adapter = new SubjectAdapter(this, id, name, order, entrance);
|
||||
adapter = new SubjectAdapter(this);
|
||||
subject_list.setAdapter(adapter);
|
||||
|
||||
subject_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@ -121,37 +114,40 @@ public class SubjectActivity extends BaseActivity {
|
||||
public void onEventMainThread(EBDownloadStatus status) {
|
||||
if ("delete".equals(status.getStatus())) {
|
||||
DownloadManager.getInstance(this).removePlatform(status.getName(), status.getPlatform());
|
||||
Integer location = adapter.getLocationMap().get(status.getName());
|
||||
if (location != null) {
|
||||
GameEntity gameEntity = adapter.getList().get(location);
|
||||
if (gameEntity != null && gameEntity.getEntryMap() != null) {
|
||||
if (TextUtils.isEmpty(status.getPlatform())) {
|
||||
gameEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(status.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
gameEntity = adapter.getSubjectList().get(location);
|
||||
if (gameEntity != null && gameEntity.getEntryMap() != null) {
|
||||
gameEntity.getEntryMap().remove(status.getPlatform());
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = adapter.getNameMap().get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
int location = adapter.getLocationMap().get(name);
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity entity = adapter.getList().get(location);
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
entity.getEntryMap().remove(apkEntity.getPlatform());
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(busFour.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
gameEntity = adapter.getSubjectList().get(location);
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(busFour.getPackageName())) {
|
||||
if (gameEntity.getEntryMap() != null) {
|
||||
gameEntity.getEntryMap().remove(apkEntity.getPlatform());
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -163,7 +159,7 @@ public class SubjectActivity extends BaseActivity {
|
||||
subject_list.setVisibility(View.VISIBLE);
|
||||
subject_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new SubjectAdapter(SubjectActivity.this, id, name, order, entrance);
|
||||
adapter = new SubjectAdapter(SubjectActivity.this);
|
||||
subject_list.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
@ -173,7 +169,7 @@ public class SubjectActivity extends BaseActivity {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
for (GameEntity entity : adapter.getList()) {
|
||||
for (GameEntity entity : adapter.getSubjectList()) {
|
||||
entity.setEntryMap(DownloadManager.getInstance(this).getEntryMap(entity.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package com.gh.gamecenter;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.telephony.TelephonyManager;
|
||||
@ -109,15 +108,16 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (isShowing) {
|
||||
AppController.canclePendingRequests(TAG);
|
||||
toast("取消发送");
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.setCancelable(false);
|
||||
// dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
// @Override
|
||||
// public void onDismiss(DialogInterface dialog) {
|
||||
// if (isShowing) {
|
||||
// AppController.canclePendingRequests(TAG);
|
||||
// toast("取消发送");
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
dialog.show();
|
||||
sendSuggestion(dialog, email);
|
||||
} else {
|
||||
@ -164,15 +164,16 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (isShowing) {
|
||||
AppController.canclePendingRequests(TAG);
|
||||
toast("取消发送");
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.setCancelable(false);
|
||||
// dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
// @Override
|
||||
// public void onDismiss(DialogInterface dialog) {
|
||||
// if (isShowing) {
|
||||
// AppController.canclePendingRequests(TAG);
|
||||
// toast("取消发送");
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
dialog.show();
|
||||
sendSuggestion(dialog, email);
|
||||
}
|
||||
@ -190,22 +191,26 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener
|
||||
map.put("version", android.os.Build.VERSION.RELEASE);
|
||||
map.put("imei", ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId());
|
||||
JsonObjectRequest request = new JsonObjectRequest(Method.POST,
|
||||
Config.HOST + "v1d46/support/suggestion", new JSONObject(map),
|
||||
Config.HOST + "support/suggestion", new JSONObject(map),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject object) {
|
||||
public void onResponse(JSONObject response) {
|
||||
isShowing = false;
|
||||
dialog.dismiss();
|
||||
|
||||
try {
|
||||
if ("ok".equals(object.getString("status"))) {
|
||||
toast("提交成功,感谢您的反馈!");
|
||||
finish();
|
||||
} else {
|
||||
toast("提交失败,请稍后尝试!");
|
||||
if (response.length() != 0) {
|
||||
try {
|
||||
if ("ok".equals(response.getString("status"))) {
|
||||
toast("提交成功,感谢您的反馈!");
|
||||
finish();
|
||||
} else {
|
||||
toast("提交失败,请稍后尝试!");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
} else {
|
||||
toast("提交失败,请稍后尝试!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,35 +2,38 @@ package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
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.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.view.Gh_RelativeLayout;
|
||||
import com.gh.common.view.Gh_RelativeLayout.OnSingleTapListener;
|
||||
import com.gh.common.view.Gh_ViewPager;
|
||||
import com.gh.common.view.ZoomSimpleDraweeView;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import pl.droidsonroids.gif.GifDrawable;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
@ -41,19 +44,21 @@ import pl.droidsonroids.gif.GifImageView;
|
||||
public class ViewImageActivity extends BaseActivity implements
|
||||
OnPageChangeListener {
|
||||
|
||||
private ViewPager viewimage_vp_show;
|
||||
private Gh_ViewPager viewimage_vp_show;
|
||||
private ViewImageAdapter adapter;
|
||||
private View viewimage_slide_line;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
|
||||
private ArrayList<String> urls;
|
||||
private Map<Integer, String> newUrls;
|
||||
|
||||
private String scaleType;
|
||||
|
||||
private int width;
|
||||
|
||||
private boolean isOrientation;
|
||||
private boolean isLoading = false;
|
||||
|
||||
private ImagePipeline imagePipeline;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
@ -66,27 +71,25 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
Object object = viewimage_vp_show.findViewWithTag(position);
|
||||
if (object != null) {
|
||||
RelativeLayout view = (RelativeLayout) object;
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
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);
|
||||
if (scaleType != null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, ScaleType.FIT_CENTER,
|
||||
new ImageUtils.OnLoadingCompleteListener() {
|
||||
@Override
|
||||
public void onLoadingComplete() {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, new ImageUtils.OnLoadingCompleteListener() {
|
||||
@Override
|
||||
public void onLoadingComplete() {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
ImageUtils.getInstance(getApplicationContext()).display(newUrls.get(position), urls.get(position), imageView
|
||||
, new BaseControllerListener(){
|
||||
@Override
|
||||
public void onFinalImageSet(String id, Object imageInfo, Animatable animatable) {
|
||||
super.onFinalImageSet(id, imageInfo, animatable);
|
||||
progressBar.setVisibility(View.GONE);
|
||||
// if (imageInfo == null){
|
||||
// return;
|
||||
// }
|
||||
// ImageInfo imageInfo1 = (ImageInfo) imageInfo;
|
||||
// int height = imageInfo1.getHeight();
|
||||
// int width = imageInfo1.getWidth();
|
||||
// float index = (float) height / (float) width;
|
||||
// imageView.setImagePro(index);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,6 +109,8 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
|
||||
setContentView(R.layout.activity_viewimage);
|
||||
|
||||
imagePipeline = Fresco.getImagePipeline();
|
||||
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
width = outMetrics.widthPixels / urls.size();
|
||||
@ -117,7 +122,7 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
viewimage_slide_line = findViewById(R.id.viewimage_slide_line);
|
||||
viewimage_slide_line.setLayoutParams(rparams);
|
||||
|
||||
viewimage_vp_show = (ViewPager) findViewById(R.id.viewimage_vp_show);
|
||||
viewimage_vp_show = (Gh_ViewPager) findViewById(R.id.viewimage_vp_show);
|
||||
adapter = new ViewImageAdapter();
|
||||
viewimage_vp_show.setAdapter(adapter);
|
||||
viewimage_vp_show.setCurrentItem(current);
|
||||
@ -151,79 +156,38 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
String url = urls.get(position);
|
||||
Gh_RelativeLayout view;
|
||||
if (url.contains(".gif")) {
|
||||
view = (Gh_RelativeLayout) View.inflate(container.getContext(),
|
||||
R.layout.viewimage_gif_item, null);
|
||||
GifImageView gifImageView = (GifImageView) view.findViewById(R.id.viewimage_iv_gif);
|
||||
if (!isLoading) {
|
||||
loadGifData(gifImageView, urls.get(position));
|
||||
}
|
||||
|
||||
} else {
|
||||
view = (Gh_RelativeLayout) View.inflate(container.getContext(),
|
||||
R.layout.viewimage_normal_item, null);
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
if (scaleType != null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, ScaleType.FIT_CENTER);
|
||||
} else if (isOrientation && imageView.getDrawable() == null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, 270, isOrientation);
|
||||
} else if (imageView.getDrawable() == null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView);
|
||||
}
|
||||
if (!urls.get(position).startsWith("http://image.ghzhushou.com/pic/hq/")) {
|
||||
checkUrl(urls.get(position));
|
||||
}
|
||||
Gh_RelativeLayout view = (Gh_RelativeLayout) View.inflate(container.getContext(),
|
||||
R.layout.viewimage_normal_item, null);
|
||||
ZoomSimpleDraweeView imageView = (ZoomSimpleDraweeView) view.findViewById(R.id.viewimage_iv_show);
|
||||
|
||||
if (scaleType != null || isOrientation) {
|
||||
imageView.getHierarchy().setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER);
|
||||
}
|
||||
view.setOnSingleTapListener(this);
|
||||
if (!url.startsWith("http://image.ghzhushou.com/pic/hq/") && url.startsWith("http://image.ghzhushou.com/pic/")) {
|
||||
String hqUrl = "http://image.ghzhushou.com/pic/hq" + url.substring(url.lastIndexOf("/"));
|
||||
if (imagePipeline.isInBitmapMemoryCache(Uri.parse(hqUrl))){ // 检查高清图是否被缓存
|
||||
loadImage(hqUrl, imageView);
|
||||
}else {
|
||||
checkUrl(url, imageView);
|
||||
}
|
||||
}else {
|
||||
loadImage(url, imageView);
|
||||
}
|
||||
|
||||
//单点退出
|
||||
imageView.setOnSingleClickListener(new ZoomSimpleDraweeView.setOnSingleClickListener() {
|
||||
@Override
|
||||
public void onClick() {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
view.setTag(position);
|
||||
container.addView(view);
|
||||
return view;
|
||||
}
|
||||
|
||||
private void loadGifData(final GifImageView gifImageView, final String gifUrl) {
|
||||
isLoading = true;
|
||||
gifImageView.setImageResource(R.drawable.ocupy);
|
||||
gifImageView.setScaleType(ScaleType.CENTER);
|
||||
final GifDrawable[] gifDrawable = {null};
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
URL url = new URL(gifUrl);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setConnectTimeout(5 * 1000);
|
||||
conn.setReadTimeout(5 * 1000);
|
||||
conn.connect();
|
||||
if (conn.getResponseCode() == 200) {
|
||||
InputStream inputStream = conn.getInputStream();
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
byte[] data = new byte[1024 * 5];
|
||||
int count = -1;
|
||||
while ((count = inputStream.read(data, 0, 1024 * 5)) != -1) {
|
||||
output.write(data, 0, count);
|
||||
}
|
||||
byte[] bytes = output.toByteArray();
|
||||
gifDrawable[0] = new GifDrawable(bytes);
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
gifImageView.setImageDrawable(gifDrawable[0]);
|
||||
gifImageView.setScaleType(ScaleType.FIT_CENTER);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view == object;
|
||||
@ -231,8 +195,8 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
// container.removeView((View) object);
|
||||
// object = null;
|
||||
container.removeView((View) object);
|
||||
object = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -258,13 +222,52 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
Gh_RelativeLayout ghRelativeLayout;
|
||||
for (int i = 0; i < viewimage_vp_show.getChildCount(); i++){
|
||||
if (viewimage_vp_show.getChildAt(i).getTag() != null){
|
||||
ghRelativeLayout = (Gh_RelativeLayout) viewimage_vp_show.getChildAt(i);
|
||||
if (ghRelativeLayout == null){
|
||||
return;
|
||||
}
|
||||
ZoomSimpleDraweeView zoomDraweeView = (ZoomSimpleDraweeView) ghRelativeLayout.findViewById(R.id.viewimage_iv_show);
|
||||
zoomDraweeView.reset(); // 重置矩阵,还原图片
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadImage(String url, final ZoomSimpleDraweeView imageView){
|
||||
|
||||
|
||||
if (url.contains(".gif")) {
|
||||
DraweeController controller = Fresco.newDraweeControllerBuilder()
|
||||
.setUri(url)
|
||||
.setAutoPlayAnimations(true)
|
||||
.build();
|
||||
imageView.setController(controller);
|
||||
}else {
|
||||
imageView.setImageURI(url);
|
||||
// ImageUtils.getInstance(getApplicationContext()).display(url, imageView, 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;
|
||||
// imageView.setImagePro(index);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkUrl(final String url) {
|
||||
if (!url.startsWith("http://image.ghzhushou.com/pic/")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
private void checkUrl(final String url, final ZoomSimpleDraweeView imageView) {
|
||||
newUrls = new HashMap<>();
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -276,21 +279,24 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
connection.setReadTimeout(5 * 1000);
|
||||
connection.connect();
|
||||
int code = connection.getResponseCode();
|
||||
if (code == 200) {
|
||||
//图片存在
|
||||
if (urls == null) {
|
||||
return;
|
||||
}
|
||||
//urls出现空指针
|
||||
if (code == 200 && urls != null) {
|
||||
for (int i = 0, size = urls.size(); i < size; i++) {
|
||||
if (urls.get(i).equals(url)) {
|
||||
urls.set(i, newUrl);
|
||||
newUrls.put(i, newUrl);
|
||||
Message msg = new Message();
|
||||
msg.arg1 = i;
|
||||
handler.sendMessage(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//没有高清图时
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadImage(url, imageView);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -302,6 +308,6 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
System.gc();
|
||||
viewimage_vp_show.onDestory(); // 注销EventBus
|
||||
}
|
||||
}
|
||||
|
||||
72
app/src/main/java/com/gh/gamecenter/WebActivity.java
Normal file
72
app/src/main/java/com/gh/gamecenter/WebActivity.java
Normal file
@ -0,0 +1,72 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/10/18.
|
||||
*/
|
||||
public class WebActivity extends BaseActivity {
|
||||
|
||||
private WebView news_webview;
|
||||
private ProgressBar web_progressbar;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
String webUrl = getIntent().getStringExtra("url");
|
||||
String webTitle = getIntent().getStringExtra("gameName");
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_web, null);
|
||||
init(contentView, webTitle);
|
||||
|
||||
news_webview.loadUrl(webUrl);
|
||||
|
||||
WebSettings settings = news_webview.getSettings();
|
||||
settings.setJavaScriptEnabled(true);
|
||||
|
||||
//用webview打开url
|
||||
news_webview.setWebViewClient(new WebViewClient(){
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
view.loadUrl(url);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
//设置加载进度条
|
||||
news_webview.setWebChromeClient(new WebChromeClient(){
|
||||
@Override
|
||||
public void onProgressChanged(WebView view, int newProgress) {
|
||||
web_progressbar.setProgress(newProgress);
|
||||
if (newProgress == 100){
|
||||
web_progressbar.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (web_progressbar.getVisibility() == View.GONE) {
|
||||
web_progressbar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && news_webview.canGoBack()) {
|
||||
news_webview.goBack();// 返回前一个页面
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
}
|
||||
@ -14,7 +14,6 @@ import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.gamecenter.ConcernActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.ConcernViewHolder;
|
||||
@ -72,12 +71,14 @@ public class ConcernAdapter extends RecyclerView.Adapter<ConcernViewHolder> {
|
||||
cCount = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
JsonObjectExtendedRequest concernObjectRequest = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/game/" + concernList.get(i).getId() + "/digest",
|
||||
Config.HOST + "game/" + concernList.get(i).getId() + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
result.add(response);
|
||||
}
|
||||
addConcernCount();
|
||||
result.add(response);
|
||||
if (cCount == count) {
|
||||
processingConcernGame(result);
|
||||
}
|
||||
@ -123,7 +124,8 @@ public class ConcernAdapter extends RecyclerView.Adapter<ConcernViewHolder> {
|
||||
@Override
|
||||
public void onBindViewHolder(final ConcernViewHolder holder, int position) {
|
||||
ConcernInfo concernInfo = concernList.get(position);
|
||||
ImageUtils.getInstance(context).display(concernInfo.getIcon(), holder.concern_item_icon);
|
||||
// ImageUtils.getInstance(context).display(concernInfo.getIcon(), holder.concern_item_icon);
|
||||
holder.concern_item_icon.setImageURI(concernInfo.getIcon());
|
||||
holder.concern_item_name.setText(concernInfo.getGameName());
|
||||
holder.concern_item_concern.setText("取消关注");
|
||||
holder.concern_item_concern.setBackgroundResource(R.drawable.textview_cancel_style);
|
||||
|
||||
@ -8,23 +8,26 @@ import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.gamecenter.ConcernActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.ConcernViewHolder;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.listener.OnCallBackListener;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
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.JSONObject;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
@ -49,29 +52,84 @@ public class ConcernRecommendAdapter extends RecyclerView.Adapter<ConcernViewHol
|
||||
this.context = activity;
|
||||
this.listener = activity;
|
||||
|
||||
gameList = new ArrayList<>();
|
||||
concernManager = new ConcernManager(context);
|
||||
|
||||
initRecommendGame();
|
||||
init();
|
||||
}
|
||||
|
||||
private int count;
|
||||
|
||||
private void addCount() {
|
||||
synchronized (ConcernRecommendAdapter.class) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
// 获取已安装游戏的digest
|
||||
List<ConcernInfo> installedList = concernManager.getInstalledGame();
|
||||
final int size = installedList.size();
|
||||
count = 0;
|
||||
for (ConcernInfo concernInfo : installedList) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "game/" + concernInfo.getId() + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
if (gameEntity.isNewsExists()) {
|
||||
gameList.add(gameEntity);
|
||||
}
|
||||
}
|
||||
addCount();
|
||||
if (count == size) {
|
||||
initRecommendGame();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addCount();
|
||||
if (count == size) {
|
||||
initRecommendGame();
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, ConcernActivity.TAG);
|
||||
}
|
||||
}
|
||||
|
||||
private void initRecommendGame() {
|
||||
JsonArrayExtendedRequest recommendRequest = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "v1d45/game/remenkapai",
|
||||
Config.HOST + "game/remenkapai",
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
Type listType = new TypeToken<ArrayList<GameEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
gameList = gson.fromJson(response.toString(), listType);
|
||||
if (gameList != null && gameList.size() != 0) {
|
||||
recommendGameList = new ArrayList<>();
|
||||
ArrayList<GameEntity> list = gson.fromJson(response.toString(), listType);
|
||||
for (GameEntity gameEntity : list) {
|
||||
for (int i = 0, size = gameList.size(); i < size; i++) {
|
||||
if (gameEntity.getId().equals(gameList.get(i).getId())) {
|
||||
break;
|
||||
} else if (i + 1 == size) {
|
||||
gameList.add(gameEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gameList.size() != 0) {
|
||||
recommendGameList = new ArrayList<>();
|
||||
for (int i = 0, sizei = gameList.size(); i < sizei; i++) {
|
||||
if (!concernManager.isConcern(gameList.get(i).getId())) {
|
||||
recommendGameList.add(gameList.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (recommendGameList.size() != 0) {
|
||||
if (recommendGameList != null && recommendGameList.size() != 0) {
|
||||
listener.loadDone();
|
||||
}
|
||||
}
|
||||
@ -89,8 +147,9 @@ public class ConcernRecommendAdapter extends RecyclerView.Adapter<ConcernViewHol
|
||||
@Override
|
||||
public void onBindViewHolder(final ConcernViewHolder holder, int position) {
|
||||
GameEntity gameEntity = recommendGameList.get(position);
|
||||
ImageUtils.getInstance(context).display(
|
||||
gameEntity.getIcon(), holder.concern_item_icon);
|
||||
// ImageUtils.getInstance(context).display(
|
||||
// gameEntity.getIcon(), holder.concern_item_icon);
|
||||
holder.concern_item_icon.setImageURI(gameEntity.getIcon());
|
||||
holder.concern_item_name.setText(gameEntity.getName());
|
||||
holder.concern_item_concern.setText("关注");
|
||||
holder.concern_item_concern.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
|
||||
@ -93,9 +93,9 @@ public class GameNewsAdapter extends RecyclerView.Adapter {
|
||||
|
||||
String url;
|
||||
if ("全部".equals(newsType)) {
|
||||
url = Config.HOST + "v1d45/game/" + gameId + "/news?limit=20&offset=" + offset;
|
||||
url = Config.HOST + "game/" + gameId + "/news?limit=20&offset=" + offset;
|
||||
} else {
|
||||
url = Config.HOST + "v1d45/game/" + gameId + "/news?limit=20&offset="
|
||||
url = Config.HOST + "game/" + gameId + "/news?limit=20&offset="
|
||||
+ offset + "&type=" + Uri.encode(newsType);
|
||||
}
|
||||
|
||||
|
||||
@ -9,8 +9,8 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
@ -73,7 +73,7 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
ViewHolder holder;
|
||||
if (view == null) {
|
||||
holder = new ViewHolder();
|
||||
view = holder.imageView = new ImageView(context);
|
||||
view = holder.imageView = new SimpleDraweeView(context);
|
||||
view.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) view.getTag();
|
||||
@ -81,9 +81,8 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
|
||||
final SlideEntity slideEntity = slideList.get(getPosition(position));
|
||||
|
||||
ImageUtils.getInstance(context).display(slideEntity.getImage(),
|
||||
holder.imageView, R.drawable.preload);
|
||||
// indicator.setPosition(slideList.size(), getPosition(position));
|
||||
ImageUtils.getInstance(context).display(slideEntity.getImage(), holder.imageView, R.drawable.preload, context);
|
||||
// indicator.setPosition(slideList.size(), getPosition(position));
|
||||
|
||||
holder.imageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -95,14 +94,14 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
DataUtils.onEvent(context, "点击", "游戏-插件-滚动图", kv);
|
||||
|
||||
if ("game".equals(slideEntity.getType())) {
|
||||
GameUtils.startGameDetailActivity(context, slideEntity.getLink(), "游戏-插件-滚动图");
|
||||
GameUtils.startGameDetailActivity(context, slideEntity.getLink(), "(游戏-插件:滚动图)");
|
||||
} 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", "(游戏-插件:滚动图)");
|
||||
context.startActivity(intent);
|
||||
} else if ("column".equals(slideEntity.getType())) {
|
||||
Intent intent = new Intent(context, SubjectActivity.class);
|
||||
@ -118,7 +117,7 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
}
|
||||
|
||||
private static class ViewHolder {
|
||||
ImageView imageView;
|
||||
SimpleDraweeView imageView;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -9,6 +9,7 @@ import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.net.Uri;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
@ -25,7 +26,6 @@ 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.ImageUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
@ -42,6 +42,7 @@ import com.gh.gamecenter.listener.OnCollectionCallBackListener;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -116,7 +117,70 @@ public class PlatformAdapter extends RecyclerView.Adapter<PlatformViewHolder> {
|
||||
|
||||
if (apkEntity.getApkCollection() == null) {
|
||||
// 非合集
|
||||
if (PackageManager.isInstalled(apkEntity.getPackageName())) {
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (viewHolder.download_item_tv_status.getVisibility() == View.GONE) {
|
||||
//下载游戏
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
download(apkEntity, viewHolder.download_item_tv_status, "下载");
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
download(apkEntity, viewHolder.download_item_tv_status, "下载");
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
String status = viewHolder.download_item_tv_status.getText().toString();
|
||||
if ("下载中".equals(status)
|
||||
|| "插件化下载中".equals(status)
|
||||
|| "更新下载中".equals(status)) {
|
||||
// 打开下载管理界面
|
||||
Intent intent = new Intent(context, DownloadManagerActivity.class);
|
||||
intent.putExtra("url", apkEntity.getUrl());
|
||||
context.startActivity(intent);
|
||||
} else if ("启动".equals(status)) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
DataUtils.onEvent(context, "游戏启动", gameEntity.getName(), kv);
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(context, apkEntity.getPackageName());
|
||||
} else if ("安装".equals(status) || "安装更新".equals(status)) {
|
||||
install(apkEntity, viewHolder.getPosition());
|
||||
} else if ("插件化".equals(status)) {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
download(apkEntity, viewHolder.download_item_tv_status, "插件化");
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
download(apkEntity, viewHolder.download_item_tv_status, "插件化");
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if ("安装插件".equals(status)) {
|
||||
showPluginDialog(apkEntity, PlatformAdapter.this, viewHolder.getPosition());
|
||||
} else if ("更新".equals(status)) {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
update(apkEntity);
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
update(apkEntity);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Object gh_id = PackageUtils.getMetaData(context, apkEntity.getPackageName(), "gh_id");
|
||||
if (PackageManager.isInstalled(apkEntity.getPackageName())
|
||||
&& (gh_id == null || gh_id.equals(gameEntity.getId()))) {
|
||||
// 已安装
|
||||
viewHolder.download_item_iv_pic.setVisibility(View.GONE);
|
||||
viewHolder.download_item_tv_hint.setVisibility(View.GONE);
|
||||
@ -137,12 +201,23 @@ public class PlatformAdapter extends RecyclerView.Adapter<PlatformViewHolder> {
|
||||
DownloadEntity downloadEntity = entryMap.get(apkEntity.getUrl());
|
||||
if (downloadEntity == null) {
|
||||
viewHolder.download_item_progressbar.setProgress(1000);
|
||||
viewHolder.download_item_tv_status.setText("启动");
|
||||
if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& !TextUtils.isEmpty(apkEntity.getGhVersion())
|
||||
&& !PackageUtils.isSignature(context, apkEntity.getPackageName())) {
|
||||
viewHolder.download_item_tv_status.setText("插件化");
|
||||
} else if (PackageManager.isCanUpdate(apkEntity.getPackageName())) {
|
||||
downloadEntity = DownloadManager.getInstance(context).getByPackage(apkEntity.getPackageName());
|
||||
if (downloadEntity == null
|
||||
|| downloadEntity.getUrl().equals(apkEntity.getUrl())) {
|
||||
viewHolder.itemView.setClickable(true);
|
||||
viewHolder.download_item_progressbar.setProgress(1000);
|
||||
} else {
|
||||
viewHolder.itemView.setClickable(false);
|
||||
viewHolder.download_item_progressbar.setProgress(0);
|
||||
}
|
||||
} else if (PackageManager.isCanUpdate(gameEntity.getId(), apkEntity.getPackageName())) {
|
||||
viewHolder.download_item_tv_status.setText("更新");
|
||||
} else {
|
||||
viewHolder.download_item_tv_status.setText("启动");
|
||||
}
|
||||
} else {
|
||||
viewHolder.download_item_progressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
@ -165,7 +240,8 @@ public class PlatformAdapter extends RecyclerView.Adapter<PlatformViewHolder> {
|
||||
DownloadEntity downloadEntity = entryMap.get(apkEntity.getUrl());
|
||||
if (downloadEntity == null
|
||||
|| downloadEntity.getStatus().equals(DownloadStatus.cancel)
|
||||
|| downloadEntity.getStatus().equals(DownloadStatus.hijack)) {
|
||||
|| downloadEntity.getStatus().equals(DownloadStatus.hijack)
|
||||
|| downloadEntity.getStatus().equals(DownloadStatus.notfound)) {
|
||||
int id = PlatformUtils.getInstance(context).getPlatformPic(
|
||||
apkEntity.getPlatform());
|
||||
if (id != 0) {
|
||||
@ -181,8 +257,9 @@ public class PlatformAdapter extends RecyclerView.Adapter<PlatformViewHolder> {
|
||||
.getPlatformPicPath(apkEntity.getPlatform());
|
||||
if (path != null) {
|
||||
viewHolder.download_item_iv_pic.setVisibility(View.VISIBLE);
|
||||
ImageUtils.getInstance(context).display(
|
||||
"file://" + path, viewHolder.download_item_iv_pic);
|
||||
// ImageUtils.getInstance(context).display(
|
||||
// "file://" + path, viewHolder.download_item_iv_pic);
|
||||
viewHolder.download_item_iv_pic.setImageURI(Uri.fromFile(new File(path)));
|
||||
viewHolder.download_item_tv_hint.setVisibility(View.GONE);
|
||||
viewHolder.download_item_progressbar.setVisibility(View.GONE);
|
||||
viewHolder.download_item_tv_name.setVisibility(View.GONE);
|
||||
@ -229,64 +306,6 @@ public class PlatformAdapter extends RecyclerView.Adapter<PlatformViewHolder> {
|
||||
}
|
||||
}
|
||||
}
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (viewHolder.download_item_tv_status.getVisibility() == View.GONE) {
|
||||
//下载游戏
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
download(apkEntity, viewHolder.download_item_tv_status, "下载");
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
download(apkEntity, viewHolder.download_item_tv_status, "下载");
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
String status = viewHolder.download_item_tv_status.getText().toString();
|
||||
if ("下载中".equals(status)
|
||||
|| "插件化下载中".equals(status)
|
||||
|| "更新下载中".equals(status)) {
|
||||
// 打开下载管理界面
|
||||
context.startActivity(new Intent(context, DownloadManagerActivity.class));
|
||||
} else if ("启动".equals(status)) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
DataUtils.onEvent(context, "游戏启动", gameEntity.getName(), kv);
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(context, apkEntity.getPackageName());
|
||||
} else if ("安装".equals(status) || "安装更新".equals(status)) {
|
||||
install(apkEntity, viewHolder.getPosition());
|
||||
} else if ("插件化".equals(status)) {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
download(apkEntity, viewHolder.download_item_tv_status, "插件化");
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
download(apkEntity, viewHolder.download_item_tv_status, "插件化");
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if ("安装插件".equals(status)) {
|
||||
showPluginDialog(apkEntity, PlatformAdapter.this, viewHolder.getPosition());
|
||||
} else if ("更新".equals(status)) {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
update(apkEntity);
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
update(apkEntity);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 合集
|
||||
viewHolder.download_item_iv_pic.setVisibility(View.VISIBLE);
|
||||
@ -296,9 +315,9 @@ public class PlatformAdapter extends RecyclerView.Adapter<PlatformViewHolder> {
|
||||
viewHolder.download_item_tv_status.setVisibility(View.GONE);
|
||||
viewHolder.itemView.setBackgroundColor(0x00ffffff);
|
||||
|
||||
ImageUtils.getInstance(context).display(
|
||||
apkEntity.getApkCollection().getIcon(), viewHolder.download_item_iv_pic);
|
||||
|
||||
// ImageUtils.getInstance(context).display(
|
||||
// apkEntity.getApkCollection().getIcon(), viewHolder.download_item_iv_pic);
|
||||
viewHolder.download_item_iv_pic.setImageURI(apkEntity.getApkCollection().getIcon());
|
||||
if (closeEntity.getPosition() == position && adapterPosition == closeEntity.getAdapterPosition()) {
|
||||
viewHolder.download_item_open_collection.setVisibility(View.GONE);
|
||||
viewHolder.download_item_colse_collection.setVisibility(View.VISIBLE);
|
||||
@ -366,7 +385,7 @@ public class PlatformAdapter extends RecyclerView.Adapter<PlatformViewHolder> {
|
||||
|
||||
// 下载游戏
|
||||
public void download(ApkEntity apkEntity, TextView download_item_tv_status, String method) {
|
||||
String msg = FileUtils.isCanDownload(apkEntity.getSize());
|
||||
String msg = FileUtils.isCanDownload(context, apkEntity.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
|
||||
@ -12,7 +12,6 @@ import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.view.CardLinearLayout;
|
||||
import com.gh.download.DownloadManager;
|
||||
@ -41,8 +40,7 @@ public class PluginAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
private OnCallBackListener listener;
|
||||
|
||||
private List<GameEntity> pluginList;
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private ArrayMap<String, ArrayList<Integer>> locationMap;
|
||||
|
||||
private String entrance;
|
||||
|
||||
@ -55,7 +53,6 @@ public class PluginAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
pluginList = new ArrayList<>();
|
||||
|
||||
locationMap = new ArrayMap<>();
|
||||
nameMap = new ArrayMap<>();
|
||||
|
||||
init();
|
||||
}
|
||||
@ -110,12 +107,20 @@ public class PluginAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
}
|
||||
}
|
||||
|
||||
private void initLocationMap() {
|
||||
public void initLocationMap() {
|
||||
ArrayList<Integer> list;
|
||||
GameEntity gameEntity;
|
||||
for (int i = 0; i < pluginList.size(); i++) {
|
||||
GameEntity gameEntity = pluginList.get(i);
|
||||
locationMap.put(gameEntity.getName() + " - " + gameEntity.getApk().get(0).getPlatform(), i);
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
nameMap.put(apkEntity.getPackageName(), gameEntity.getName() + " - " + gameEntity.getApk().get(0).getPlatform());
|
||||
gameEntity = pluginList.get(i);
|
||||
if (gameEntity.getApk() != null && gameEntity.getApk().size() != 0) {
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
list = locationMap.get(apkEntity.getPackageName());
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
locationMap.put(apkEntity.getPackageName(), list);
|
||||
}
|
||||
list.add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -150,7 +155,8 @@ public class PluginAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
|
||||
viewHolder.home1_game_order.setVisibility(View.GONE);
|
||||
|
||||
ImageUtils.getInstance(context).display(gameEntity.getIcon(), viewHolder.gameThumb);
|
||||
// ImageUtils.getInstance(context).display(gameEntity.getIcon(), viewHolder.gameThumb);
|
||||
viewHolder.gameThumb.setImageURI(gameEntity.getIcon());
|
||||
if (gameEntity.isPluggable()) {
|
||||
viewHolder.gameNameAndSize.setText(gameEntity.getName() + " - " +
|
||||
PlatformUtils.getInstance(context).getPlatformName(gameEntity.getApk().get(0).getPlatform()));
|
||||
@ -201,12 +207,8 @@ public class PluginAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
return pluginList;
|
||||
}
|
||||
|
||||
public ArrayMap<String, Integer> getLocationMap() {
|
||||
public ArrayMap<String, ArrayList<Integer>> getLocationMap() {
|
||||
return locationMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getNameMap() {
|
||||
return nameMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -14,12 +14,12 @@ import com.android.volley.TimeoutError;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.ItemViewType;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.view.CardLinearLayout;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.R;
|
||||
@ -58,14 +58,11 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
private Context context;
|
||||
private OnCallBackListener listener;
|
||||
|
||||
private List<GameEntity> list;
|
||||
private List<GameEntity> subjectList;
|
||||
private boolean order;
|
||||
private static final int FOOTER_ITEM = 101;
|
||||
private boolean isLoaded;
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private ArrayMap<String, ArrayList<Integer>> locationMap;
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
@ -74,20 +71,19 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
private boolean isRemove;
|
||||
private boolean isNetworkError;
|
||||
|
||||
public SubjectAdapter(SubjectActivity activity, String id, String name, boolean order, String entrance) {
|
||||
public SubjectAdapter(SubjectActivity activity) {
|
||||
|
||||
this.context = activity;
|
||||
this.listener = activity;
|
||||
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.order = order;
|
||||
this.entrance = entrance;
|
||||
this.id = activity.getIntent().getStringExtra("id");
|
||||
this.name = activity.getIntent().getStringExtra("name");
|
||||
this.order = activity.getIntent().getBooleanExtra("order", false);
|
||||
this.entrance = activity.getIntent().getStringExtra("entrance");
|
||||
|
||||
locationMap = new ArrayMap<>();
|
||||
nameMap = new ArrayMap<>();
|
||||
|
||||
list = new ArrayList<>();
|
||||
subjectList = new ArrayList<>();
|
||||
isLoaded = false;
|
||||
isNetworkError = false;
|
||||
|
||||
@ -97,7 +93,7 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
public void initList(final int page) {
|
||||
isLoaded = false;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "v1d50/game/column/" + id + "?page=" + page,
|
||||
Config.HOST + "game/column/" + id + "?page=" + page,
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
@ -142,18 +138,11 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
entity.setEntryMap(DownloadManager.getInstance(context).getEntryMap(entity.getName()));
|
||||
manager.addOrUpdate(entity.getApk(), entity.getId(), entity.getName());
|
||||
}
|
||||
list.addAll(gameList);
|
||||
notifyItemRangeInserted(list.size() - gameList.size(), gameList.size());
|
||||
subjectList.addAll(gameList);
|
||||
notifyItemRangeInserted(subjectList.size() - gameList.size(), gameList.size());
|
||||
}
|
||||
|
||||
// 黄壮华 获取游戏位置信息 修改2015/8/15
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
GameEntity entity = list.get(i);
|
||||
locationMap.put(entity.getName(), i);
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
nameMap.put(apkEntity.getPackageName(), entity.getName());
|
||||
}
|
||||
}
|
||||
initLocationMap();
|
||||
|
||||
if (listener != null) {
|
||||
listener.loadDone();
|
||||
@ -166,14 +155,32 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
isLoaded = true;
|
||||
}
|
||||
|
||||
private void initLocationMap() {
|
||||
ArrayList<Integer> list;
|
||||
GameEntity gameEntity;
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
gameEntity = subjectList.get(i);
|
||||
if (gameEntity.getApk() != null && gameEntity.getApk().size() != 0) {
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
list = locationMap.get(apkEntity.getPackageName());
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
locationMap.put(apkEntity.getPackageName(), list);
|
||||
}
|
||||
list.add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeDuplicateData(List<GameEntity> gameList) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
if (subjectList == null || subjectList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String id;
|
||||
for (int i = 0; i < gameList.size(); i++) {
|
||||
id = gameList.get(i).getId();
|
||||
for (GameEntity gameEntity : list) {
|
||||
for (GameEntity gameEntity : subjectList) {
|
||||
if (id.equals(gameEntity.getId())) {
|
||||
gameList.remove(i);
|
||||
i--;
|
||||
@ -185,36 +192,40 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (list.size()<1){
|
||||
if (subjectList.size() < 1) {
|
||||
return 0;
|
||||
}
|
||||
return list.size()+1;
|
||||
return subjectList.size() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (list.size() == position) {
|
||||
return FOOTER_ITEM;
|
||||
if (position == subjectList.size()) {
|
||||
return ItemViewType.LOADING;
|
||||
}
|
||||
if (subjectList.get(position).getTest() != null) {
|
||||
return ItemViewType.GAME_TEST;
|
||||
} else {
|
||||
return ItemViewType.GAME_NORMAL;
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
if (i == FOOTER_ITEM){
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||
if (viewType == ItemViewType.LOADING){
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.refresh_footerview, viewGroup, false);
|
||||
return new FooterViewHolder(view);
|
||||
}
|
||||
if (list.get(i).getTest() != null) {
|
||||
} else if (viewType == ItemViewType.GAME_TEST) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.game_test_item, viewGroup, false);
|
||||
return new GameTestViewHolder(view);
|
||||
} else {
|
||||
} else if (viewType == ItemViewType.GAME_NORMAL) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.game_normal_item, viewGroup, false);
|
||||
return new GameNormalViewHolder(view);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -238,7 +249,7 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
public void onClick(View v) {
|
||||
isNetworkError = false;
|
||||
notifyDataSetChanged();
|
||||
initList(list.size() / 21);
|
||||
initList(subjectList.size() / 21);
|
||||
}
|
||||
});
|
||||
} else if (isRemove) {
|
||||
@ -262,7 +273,7 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
}
|
||||
|
||||
// 最后一个
|
||||
if (position == list.size() - 1) {
|
||||
if (position == subjectList.size() - 1) {
|
||||
((CardLinearLayout) holder.itemView).setBottom(true);
|
||||
} else {
|
||||
((CardLinearLayout) holder.itemView).setBottom(false);
|
||||
@ -275,9 +286,10 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
holder.home2_game_order.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
final GameEntity gameEntity = list.get(position);
|
||||
final GameEntity gameEntity = subjectList.get(position);
|
||||
|
||||
ImageUtils.getInstance(context).display(gameEntity.getIcon(), holder.gameThumb);
|
||||
// ImageUtils.getInstance(context).display(gameEntity.getIcon(), holder.gameThumb);
|
||||
holder.gameThumb.setImageURI(gameEntity.getIcon());
|
||||
holder.gameNameAndSize.setText(gameEntity.getName());
|
||||
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(gameEntity.getBrief());
|
||||
@ -306,7 +318,7 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
map.put("game_id", gameEntity.getId());
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
GameUtils.startGameDetailActivity(context, gameEntity, entrance + "(" + name + ")");
|
||||
GameUtils.startGameDetailActivity(context, gameEntity, entrance + "+(" + name + ")");
|
||||
}
|
||||
});
|
||||
|
||||
@ -317,7 +329,7 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
holder.downloadBtn.setVisibility(View.VISIBLE);
|
||||
DownloadItemUtils.setOnClickListener(context,
|
||||
holder.downloadBtn, gameEntity, position,
|
||||
SubjectAdapter.this, entrance + "(" + name + ")", name + ":" + gameEntity.getName());
|
||||
SubjectAdapter.this, entrance + "+(" + name + ")", name + ":" + gameEntity.getName());
|
||||
} else {
|
||||
long endTime = Long.valueOf(gameEntity.getTest().getEnd()
|
||||
+ "000");
|
||||
@ -330,7 +342,7 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
holder.downloadBtn.setVisibility(View.VISIBLE);
|
||||
DownloadItemUtils.setOnClickListener(context,
|
||||
holder.downloadBtn, gameEntity, position,
|
||||
SubjectAdapter.this, entrance + "(" + name + ")", name + ":" + gameEntity.getName());
|
||||
SubjectAdapter.this, entrance + "+(" + name + ")", name + ":" + gameEntity.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -350,7 +362,7 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
}
|
||||
|
||||
// 最后一个
|
||||
if (position == list.size() - 1) {
|
||||
if (position == subjectList.size() - 1) {
|
||||
((CardLinearLayout) holder.itemView).setBottom(true);
|
||||
} else {
|
||||
((CardLinearLayout) holder.itemView).setBottom(false);
|
||||
@ -363,9 +375,10 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
holder.home1_game_order.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
final GameEntity gameEntity = list.get(position);
|
||||
final GameEntity gameEntity = subjectList.get(position);
|
||||
|
||||
ImageUtils.getInstance(context).display(gameEntity.getIcon(), holder.gameThumb);
|
||||
// ImageUtils.getInstance(context).display(gameEntity.getIcon(), holder.gameThumb);
|
||||
holder.gameThumb.setImageURI(gameEntity.getIcon());
|
||||
holder.gameNameAndSize.setText(gameEntity.getName());
|
||||
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(gameEntity.getBrief());
|
||||
@ -390,12 +403,12 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
map.put("game_id", gameEntity.getId());
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
GameUtils.startGameDetailActivity(context, gameEntity, entrance + "(" + name + ")");
|
||||
GameUtils.startGameDetailActivity(context, gameEntity, entrance + "+(" + name + ")");
|
||||
}
|
||||
});
|
||||
|
||||
DownloadItemUtils.setOnClickListener(context, holder.downloadBtn,
|
||||
gameEntity, position, this, entrance + "(" + name + ")", name + ":" + gameEntity.getName());
|
||||
gameEntity, position, this, entrance + "+(" + name + ")", name + ":" + gameEntity.getName());
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.gameDes,
|
||||
holder.game_progressbar, holder.game_ll_info,
|
||||
@ -403,18 +416,14 @@ public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
holder.downloadBtn, gameEntity);
|
||||
}
|
||||
|
||||
public List<GameEntity> getList() {
|
||||
return list;
|
||||
public List<GameEntity> getSubjectList() {
|
||||
return subjectList;
|
||||
}
|
||||
|
||||
public ArrayMap<String, Integer> getLocationMap() {
|
||||
public ArrayMap<String, ArrayList<Integer>> getLocationMap() {
|
||||
return locationMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getNameMap() {
|
||||
return nameMap;
|
||||
}
|
||||
|
||||
public boolean isLoaded(){
|
||||
return isLoaded;
|
||||
}
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/8/17.
|
||||
*/
|
||||
public class CardListViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public RecyclerView card_list_show;
|
||||
|
||||
public CardListViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
card_list_show = (RecyclerView) itemView.findViewById(R.id.card_list_show);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,9 +2,9 @@ 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;
|
||||
|
||||
/**
|
||||
@ -12,14 +12,14 @@ import com.gh.gamecenter.R;
|
||||
*/
|
||||
public class ConcernViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ImageView concern_item_icon;
|
||||
public SimpleDraweeView concern_item_icon;
|
||||
public TextView concern_item_name;
|
||||
public TextView concern_item_concern;
|
||||
|
||||
public ConcernViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
concern_item_icon = (ImageView) itemView.findViewById(R.id.concern_item_icon);
|
||||
concern_item_icon = (SimpleDraweeView) itemView.findViewById(R.id.concern_item_icon);
|
||||
concern_item_name = (TextView) itemView.findViewById(R.id.concern_item_name);
|
||||
concern_item_concern = (TextView) itemView.findViewById(R.id.concern_item_concern);
|
||||
}
|
||||
|
||||
@ -2,8 +2,8 @@ package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
@ -11,12 +11,12 @@ import com.gh.gamecenter.R;
|
||||
*/
|
||||
public class GameImageViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ImageView image;
|
||||
public SimpleDraweeView image;
|
||||
|
||||
public GameImageViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
image = (ImageView) itemView.findViewById(R.id.home_game_iv_image);
|
||||
image = (SimpleDraweeView) itemView.findViewById(R.id.home_game_iv_image);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,11 +2,11 @@ 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.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
@ -15,7 +15,7 @@ import com.gh.gamecenter.R;
|
||||
public class GameNormalViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView home1_game_order;
|
||||
public ImageView gameThumb;
|
||||
public SimpleDraweeView gameThumb;
|
||||
public TextView gameNameAndSize;
|
||||
public TextView downloadBtn;
|
||||
public TextView gameDes;
|
||||
@ -29,7 +29,7 @@ public class GameNormalViewHolder extends RecyclerView.ViewHolder {
|
||||
super(itemView);
|
||||
|
||||
home1_game_order = (TextView) itemView.findViewById(R.id.home1_game_order);
|
||||
gameThumb = (ImageView) itemView.findViewById(R.id.home1_game_thumb);
|
||||
gameThumb = (SimpleDraweeView) itemView.findViewById(R.id.home1_game_thumb);
|
||||
gameNameAndSize = (TextView) itemView.findViewById(R.id.home1_game_nameAndsize);
|
||||
downloadBtn = (TextView) itemView.findViewById(R.id.home1_download_btn);
|
||||
gameDes = (TextView) itemView.findViewById(R.id.home1_game_des);
|
||||
|
||||
@ -2,11 +2,11 @@ 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.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
@ -15,7 +15,7 @@ import com.gh.gamecenter.R;
|
||||
public class GameTestViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView home2_game_order;
|
||||
public ImageView gameThumb;
|
||||
public SimpleDraweeView gameThumb;
|
||||
public TextView gameNameAndSize;
|
||||
public TextView downloadBtn;
|
||||
public TextView gameDes;
|
||||
@ -31,7 +31,7 @@ public class GameTestViewHolder extends RecyclerView.ViewHolder {
|
||||
super(itemView);
|
||||
|
||||
home2_game_order = (TextView) itemView.findViewById(R.id.home2_game_order);
|
||||
gameThumb = (ImageView) itemView.findViewById(R.id.home2_game_thumb);
|
||||
gameThumb = (SimpleDraweeView) itemView.findViewById(R.id.home2_game_thumb);
|
||||
gameNameAndSize = (TextView) itemView.findViewById(R.id.home2_game_nameAndsize);
|
||||
downloadBtn = (TextView) itemView.findViewById(R.id.home2_download_btn);
|
||||
gameDes = (TextView) itemView.findViewById(R.id.home2_game_des);
|
||||
|
||||
@ -2,9 +2,9 @@ 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;
|
||||
|
||||
/**
|
||||
@ -12,7 +12,7 @@ import com.gh.gamecenter.R;
|
||||
*/
|
||||
public class NewsImage1ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ImageView fm_read_iv_thumb;
|
||||
public SimpleDraweeView fm_read_iv_thumb;
|
||||
public TextView fm_read_tv_title;
|
||||
public TextView fm_read_tv_read;
|
||||
public TextView fm_read_tv_type;
|
||||
@ -20,7 +20,7 @@ public class NewsImage1ViewHolder extends RecyclerView.ViewHolder {
|
||||
public NewsImage1ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
fm_read_iv_thumb = (ImageView) itemView.findViewById(R.id.fm_read_iv_thumb);
|
||||
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);
|
||||
|
||||
@ -2,9 +2,9 @@ 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;
|
||||
|
||||
/**
|
||||
@ -13,9 +13,9 @@ import com.gh.gamecenter.R;
|
||||
public class NewsImage2ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView fm_read2_special2_title;
|
||||
public ImageView fm_read2_special2_thumb1;
|
||||
public ImageView fm_read2_special2_thumb2;
|
||||
public ImageView fm_read2_special2_thumb3;
|
||||
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;
|
||||
|
||||
@ -23,9 +23,9 @@ public class NewsImage2ViewHolder extends RecyclerView.ViewHolder {
|
||||
super(itemView);
|
||||
|
||||
fm_read2_special2_title = (TextView) itemView.findViewById(R.id.fm_read2_special2_title);
|
||||
fm_read2_special2_thumb1 = (ImageView) itemView.findViewById(R.id.fm_read2_special2_thumb1);
|
||||
fm_read2_special2_thumb2 = (ImageView) itemView.findViewById(R.id.fm_read2_special2_thumb2);
|
||||
fm_read2_special2_thumb3 = (ImageView) itemView.findViewById(R.id.fm_read2_special2_thumb3);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -2,9 +2,9 @@ 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;
|
||||
|
||||
/**
|
||||
@ -13,7 +13,7 @@ import com.gh.gamecenter.R;
|
||||
public class NewsImage3ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView fm_read2_special1_title;
|
||||
public ImageView fm_read2_special1_thumb;
|
||||
public SimpleDraweeView fm_read2_special1_thumb;
|
||||
public TextView fm_read2_special1_tv_read;
|
||||
public TextView fm_read2_special1_tv_type;
|
||||
|
||||
@ -21,7 +21,7 @@ public class NewsImage3ViewHolder extends RecyclerView.ViewHolder {
|
||||
super(itemView);
|
||||
|
||||
fm_read2_special1_title = (TextView) itemView.findViewById(R.id.fm_read2_special1_title);
|
||||
fm_read2_special1_thumb = (ImageView) itemView.findViewById(R.id.fm_read2_special1_thumb);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -2,9 +2,9 @@ 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;
|
||||
|
||||
/**
|
||||
@ -12,14 +12,14 @@ import com.gh.gamecenter.R;
|
||||
*/
|
||||
public class NewsImageViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ImageView newsThumb;
|
||||
public SimpleDraweeView newsThumb;
|
||||
public TextView newsMainTitle;
|
||||
public TextView newsSubTitle;
|
||||
|
||||
public NewsImageViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
newsThumb = (ImageView) itemView.findViewById(R.id.news_thumb);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
@ -18,7 +19,7 @@ public class PlatformViewHolder extends RecyclerView.ViewHolder {
|
||||
public TextView download_item_tv_hint;
|
||||
public ImageView download_item_open_collection;
|
||||
public ImageView download_item_colse_collection;
|
||||
public ImageView download_item_iv_pic;
|
||||
public SimpleDraweeView download_item_iv_pic;
|
||||
public ProgressBar download_item_progressbar;
|
||||
|
||||
public PlatformViewHolder(View itemView) {
|
||||
@ -30,7 +31,7 @@ public class PlatformViewHolder extends RecyclerView.ViewHolder {
|
||||
.findViewById(R.id.download_item_tv_status);
|
||||
download_item_progressbar = (ProgressBar) itemView
|
||||
.findViewById(R.id.download_item_progressbar);
|
||||
download_item_iv_pic = (ImageView) itemView
|
||||
download_item_iv_pic = (SimpleDraweeView) itemView
|
||||
.findViewById(R.id.download_item_iv_pic);
|
||||
download_item_tv_hint = (TextView) itemView
|
||||
.findViewById(R.id.download_item_tv_hint);
|
||||
|
||||
@ -116,6 +116,18 @@ public class ConcernDao {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加多个关注
|
||||
*/
|
||||
public void add(List<ConcernInfo> list) {
|
||||
try {
|
||||
dao.create(list);
|
||||
} catch (SQLException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个关注
|
||||
*/
|
||||
@ -128,6 +140,18 @@ public class ConcernDao {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除多个关注
|
||||
*/
|
||||
public void delete(List<String> ids) {
|
||||
try {
|
||||
dao.deleteIds(ids);
|
||||
} catch (SQLException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id获取某一个关注
|
||||
*/
|
||||
|
||||
@ -29,7 +29,6 @@ public class DataCollectionDao {
|
||||
try {
|
||||
return dao.queryForEq("type", type);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
@ -10,7 +10,6 @@ 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.SuspectedGameInfo;
|
||||
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
@ -57,7 +56,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||
TableUtils.createTable(connectionSource, ConcernInfo.class);
|
||||
TableUtils.createTable(connectionSource, SearchHistoryInfo.class);
|
||||
TableUtils.createTable(connectionSource, GameInfo.class);
|
||||
TableUtils.createTable(connectionSource, SuspectedGameInfo.class);
|
||||
TableUtils.createTable(connectionSource, FilterInfo.class);
|
||||
TableUtils.createTable(connectionSource, DataCollectionInfo.class);
|
||||
} catch (SQLException e) {
|
||||
@ -75,7 +73,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||
TableUtils.dropTable(connectionSource, ConcernInfo.class, true);
|
||||
TableUtils.dropTable(connectionSource, SearchHistoryInfo.class, true);
|
||||
TableUtils.dropTable(connectionSource, GameInfo.class, true);
|
||||
TableUtils.dropTable(connectionSource, SuspectedGameInfo.class, true);
|
||||
TableUtils.dropTable(connectionSource, FilterInfo.class, true);
|
||||
TableUtils.dropTable(connectionSource, DataCollectionInfo.class, true);
|
||||
onCreate(database, connectionSource);
|
||||
|
||||
@ -1,99 +0,0 @@
|
||||
package com.gh.gamecenter.db;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.gh.gamecenter.db.info.SuspectedGameInfo;
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class SuspectedGameDao {
|
||||
|
||||
private DatabaseHelper helper;
|
||||
private Dao<SuspectedGameInfo, String> dao;
|
||||
|
||||
public SuspectedGameDao(Context context) {
|
||||
try {
|
||||
helper = DatabaseHelper.getHelper(context);
|
||||
dao = helper.getDao(SuspectedGameInfo.class);
|
||||
} catch (SQLException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一个疑似游戏
|
||||
*/
|
||||
public void add(SuspectedGameInfo entity) {
|
||||
try {
|
||||
dao.create(entity);
|
||||
} catch (SQLException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个疑似游戏
|
||||
*/
|
||||
public void delete(String packageName) {
|
||||
try {
|
||||
dao.deleteById(packageName);
|
||||
} catch (SQLException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据包名获取某一个疑似游戏
|
||||
*/
|
||||
public SuspectedGameInfo find(String packageName) {
|
||||
try {
|
||||
return dao.queryForId(packageName);
|
||||
} catch (SQLException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的疑似游戏
|
||||
*/
|
||||
public List<SuspectedGameInfo> getAll() {
|
||||
try {
|
||||
return dao.queryForAll();
|
||||
} catch (SQLException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新疑似游戏
|
||||
*/
|
||||
public void update(SuspectedGameInfo entity) {
|
||||
try {
|
||||
dao.update(entity);
|
||||
} catch (SQLException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
try {
|
||||
List<SuspectedGameInfo> list = dao.queryForAll();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
dao.deleteById(list.get(i).getPackageName());
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
package com.gh.gamecenter.db.info;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@DatabaseTable(tableName = "tb_suspectedgame")
|
||||
public class SuspectedGameInfo implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5623387326449838895L;
|
||||
|
||||
@DatabaseField(id = true, columnName = "packageName")
|
||||
private String packageName;
|
||||
|
||||
@DatabaseField(columnName = "time")
|
||||
private long time;
|
||||
|
||||
public SuspectedGameInfo() {
|
||||
|
||||
}
|
||||
|
||||
public SuspectedGameInfo(String packageName, long time) {
|
||||
super();
|
||||
this.packageName = packageName;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SuspectedGameEntity [packageName=" + packageName + ", time="
|
||||
+ time + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@ -8,6 +8,7 @@ import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
@ -18,6 +19,7 @@ import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.view.RecyclerViewExtended;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
@ -42,7 +44,7 @@ import de.greenrobot.event.EventBus;
|
||||
public class GameDownLoadFragment extends Fragment implements View.OnClickListener {
|
||||
|
||||
private View view;
|
||||
private RecyclerView downloadmanager_rv_show;
|
||||
private RecyclerViewExtended downloadmanager_rv_show;
|
||||
private GameDownloadAdapter adapter;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private LinearLayout reuse_nodata_skip;
|
||||
@ -51,7 +53,9 @@ public class GameDownLoadFragment extends Fragment implements View.OnClickListen
|
||||
private TextView downloadmanager_tv_allstart;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
|
||||
private String path;
|
||||
private String url;
|
||||
|
||||
private boolean isScroll;
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
@ -79,12 +83,14 @@ public class GameDownLoadFragment extends Fragment implements View.OnClickListen
|
||||
location = adapter.getLocation(downloadEntity.getUrl());
|
||||
if (location != null) {
|
||||
adapter.getDownloadingList().remove(location.intValue());
|
||||
adapter.initLocationMap();
|
||||
adapter.notifyItemRangeRemoved(adapter.getBase(), 2);
|
||||
}
|
||||
} else {
|
||||
location = adapter.getLocation(downloadEntity.getUrl());
|
||||
if (location != null) {
|
||||
adapter.getDownloadingList().remove(location.intValue());
|
||||
adapter.initLocationMap();
|
||||
adapter.notifyItemRemoved(adapter.getBase() + location + 1);
|
||||
adapter.notifyItemChanged(adapter.getBase() + 1);
|
||||
}
|
||||
@ -92,11 +98,13 @@ public class GameDownLoadFragment extends Fragment implements View.OnClickListen
|
||||
|
||||
// 添加进已完成列表
|
||||
if (adapter.getDoneList().isEmpty()) {
|
||||
adapter.getDoneList().add(downloadEntity);
|
||||
adapter.getDoneList().add(0, downloadEntity);
|
||||
adapter.initLocationMap();
|
||||
adapter.notifyItemRangeInserted(0, 2);
|
||||
} else {
|
||||
adapter.getDoneList().add(downloadEntity);
|
||||
adapter.notifyItemInserted(adapter.getDoneList().size());
|
||||
adapter.getDoneList().add(0, downloadEntity);
|
||||
adapter.initLocationMap();
|
||||
adapter.notifyItemInserted(1);
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -125,7 +133,8 @@ public class GameDownLoadFragment extends Fragment implements View.OnClickListen
|
||||
if (status.equals(DownloadStatus.downloading)
|
||||
|| status.equals(DownloadStatus.waiting)) {
|
||||
if (adapter.getDownloadingList().isEmpty()) {
|
||||
adapter.getDownloadingList().add(downloadEntity);
|
||||
adapter.getDownloadingList().add(0, downloadEntity);
|
||||
adapter.initLocationMap();
|
||||
adapter.notifyItemRangeInserted(adapter.getBase(), 2);
|
||||
if (reuse_nodata_skip.getVisibility() == View.VISIBLE) {
|
||||
reuse_nodata_skip.setVisibility(View.GONE);
|
||||
@ -133,13 +142,13 @@ public class GameDownLoadFragment extends Fragment implements View.OnClickListen
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download",
|
||||
View.VISIBLE, 1));
|
||||
} else {
|
||||
adapter.getDownloadingList().add(downloadEntity);
|
||||
adapter.notifyItemInserted(adapter.getBase() + adapter.getDownloadingList().size());
|
||||
adapter.getDownloadingList().add(0, downloadEntity);
|
||||
adapter.initLocationMap();
|
||||
adapter.notifyItemInserted(adapter.getBase() + 1);
|
||||
adapter.notifyItemChanged(adapter.getBase());
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download",
|
||||
View.VISIBLE, adapter.getDoneList().size() + adapter.getDownloadingList().size()));
|
||||
}
|
||||
adapter.putLocation(downloadEntity.getUrl(), adapter.getDownloadingList().size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -151,6 +160,11 @@ public class GameDownLoadFragment extends Fragment implements View.OnClickListen
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
String path = getActivity().getIntent().getStringExtra("path");
|
||||
url = getActivity().getIntent().getStringExtra("url");
|
||||
|
||||
isScroll = false;
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.downloadmanager, null);
|
||||
|
||||
downloadmanager_rl_head = (RelativeLayout) view.findViewById(R.id.downloadmanager_rl_head);
|
||||
@ -187,9 +201,9 @@ public class GameDownLoadFragment extends Fragment implements View.OnClickListen
|
||||
}
|
||||
});
|
||||
|
||||
downloadmanager_rv_show = (RecyclerView) view.findViewById(R.id.downloadmanager_rv_show);
|
||||
downloadmanager_rv_show = (RecyclerViewExtended) view.findViewById(R.id.downloadmanager_rv_show);
|
||||
downloadmanager_rv_show.setHasFixedSize(true);
|
||||
adapter = new GameDownloadAdapter(getActivity(), reuse_nodata_skip);
|
||||
adapter = new GameDownloadAdapter(getActivity(), reuse_nodata_skip, url);
|
||||
downloadmanager_rv_show.setAdapter(adapter);
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
downloadmanager_rv_show.setLayoutManager(layoutManager);
|
||||
@ -237,6 +251,15 @@ public class GameDownLoadFragment extends Fragment implements View.OnClickListen
|
||||
}
|
||||
}
|
||||
});
|
||||
downloadmanager_rv_show.setOnDispatchTouchListener(new RecyclerViewExtended.OnDispatchTouchListener() {
|
||||
@Override
|
||||
public void onDispatch(View v, MotionEvent event) {
|
||||
if (url != null && event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
url = null;
|
||||
adapter.setUrl(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (path != null) {
|
||||
adapter.showPluginDialog(path);
|
||||
@ -269,24 +292,31 @@ public class GameDownLoadFragment extends Fragment implements View.OnClickListen
|
||||
Integer location = adapter.getLocation(url);
|
||||
if (location != null) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
if (adapter.getDownloadingList().isEmpty() && adapter.getDoneList().size() == 1) {
|
||||
adapter.getDoneList().remove(location.intValue());
|
||||
adapter.notifyDataSetChanged();
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.GONE, 0));
|
||||
adapter.getLocationMap().clear();
|
||||
if (reuse_nodata_skip.getVisibility() == View.GONE) {
|
||||
reuse_nodata_skip.setVisibility(View.VISIBLE);
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(getActivity()).get(url);
|
||||
if (downloadEntity == null
|
||||
|| !downloadEntity.isPlugin() // 不是插件游戏,自己删除数据库数据和安装包
|
||||
|| PackageUtils.isSignature(getActivity(), packageName)) {// 是插件游戏,判断签名是否相同,是才删除数据库数据和安装包
|
||||
if (adapter.getDownloadingList().isEmpty() && adapter.getDoneList().size() == 1) {
|
||||
adapter.getDoneList().remove(location.intValue());
|
||||
adapter.getLocationMap().clear();
|
||||
adapter.notifyDataSetChanged();
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.GONE, 0));
|
||||
if (reuse_nodata_skip.getVisibility() == View.GONE) {
|
||||
reuse_nodata_skip.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else if (adapter.getDoneList().size() == 1) {
|
||||
adapter.getDoneList().remove(location.intValue());
|
||||
adapter.initLocationMap();
|
||||
adapter.notifyItemRangeRemoved(0, 2);
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.VISIBLE,
|
||||
adapter.getDoneList().size() + adapter.getDownloadingList().size()));
|
||||
} else {
|
||||
adapter.getDoneList().remove(location.intValue());
|
||||
adapter.initLocationMap();
|
||||
adapter.notifyItemRemoved(location + 1);
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.VISIBLE,
|
||||
adapter.getDoneList().size() + adapter.getDownloadingList().size()));
|
||||
}
|
||||
} else if (adapter.getDoneList().size() == 1) {
|
||||
adapter.getDoneList().remove(location.intValue());
|
||||
adapter.notifyItemRangeRemoved(0, 2);
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.VISIBLE,
|
||||
adapter.getDoneList().size() + adapter.getDownloadingList().size()));
|
||||
} else {
|
||||
adapter.getDoneList().remove(location.intValue());
|
||||
adapter.notifyItemRemoved(location + 1);
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.VISIBLE,
|
||||
adapter.getDoneList().size() + adapter.getDownloadingList().size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -307,10 +337,6 @@ public class GameDownLoadFragment extends Fragment implements View.OnClickListen
|
||||
}
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
@ -323,6 +349,22 @@ public class GameDownLoadFragment extends Fragment implements View.OnClickListen
|
||||
} else {
|
||||
reuse_nodata_skip.setVisibility(View.GONE);
|
||||
}
|
||||
if (url != null && !isScroll) {
|
||||
for (int i = 0, size = adapter.getDoneList().size(); i < size; i++) {
|
||||
if (adapter.getDoneList().get(i).getUrl().equals(url)) {
|
||||
downloadmanager_rv_show.scrollToPosition(i + 1);
|
||||
isScroll = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (int i = 0, size = adapter.getDownloadingList().size(); i < size; i++) {
|
||||
if (adapter.getDownloadingList().get(i).getUrl().equals(url)) {
|
||||
downloadmanager_rv_show.scrollToPosition(adapter.getBase() + i + 1);
|
||||
isScroll = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -17,7 +17,6 @@ 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.ImageUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
@ -32,6 +31,8 @@ import com.gh.gamecenter.eventbus.EBDownloadChanged;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -55,9 +56,12 @@ public class GameDownloadAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
private ArrayMap<String, String> urlMap;
|
||||
private ArrayList<String> deleteList;
|
||||
|
||||
public GameDownloadAdapter(Context context, LinearLayout textView) {
|
||||
private String url;
|
||||
|
||||
public GameDownloadAdapter(Context context, LinearLayout textView, String url) {
|
||||
|
||||
this.context = context;
|
||||
this.url = url;
|
||||
|
||||
downloadmanager_tv_none = textView;
|
||||
|
||||
@ -144,25 +148,21 @@ public class GameDownloadAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
|
||||
String icon = downloadEntity.getIcon();
|
||||
if (!TextUtils.isEmpty(icon)) {
|
||||
ImageUtils.getInstance(context).display(icon, viewHolder.dm_item_iv_icon);
|
||||
viewHolder.dm_item_iv_icon.setImageURI(icon);
|
||||
} else {
|
||||
viewHolder.dm_item_iv_icon.setImageResource(R.drawable.logo);
|
||||
viewHolder.dm_item_iv_icon.setImageURI("res:///" + R.drawable.logo);
|
||||
}
|
||||
|
||||
if (downloadEntity.getName().contains("光环助手")
|
||||
|| "local_plugin".equals(downloadEntity.getPlatform())) {
|
||||
|| !downloadEntity.isPlugin()) {
|
||||
viewHolder.dm_item_tv_title.setText(downloadEntity.getName());
|
||||
} else {
|
||||
String platform = downloadEntity.getPlatform();
|
||||
if ("local_plugin".equals(platform)) {
|
||||
platform = PlatformUtils.getInstance(context).getPlatformName(platform);
|
||||
if (platform == null) {
|
||||
viewHolder.dm_item_tv_title.setText(downloadEntity.getName());
|
||||
} else {
|
||||
platform = PlatformUtils.getInstance(context).getPlatformName(platform);
|
||||
if (platform == null) {
|
||||
viewHolder.dm_item_tv_title.setText(downloadEntity.getName());
|
||||
} else {
|
||||
viewHolder.dm_item_tv_title.setText(downloadEntity.getName() + " - " + platform);
|
||||
}
|
||||
viewHolder.dm_item_tv_title.setText(downloadEntity.getName() + " - " + platform);
|
||||
}
|
||||
}
|
||||
|
||||
@ -290,7 +290,7 @@ public class GameDownloadAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
} else {
|
||||
if (FileUtils.isEmptyFile(path)) {
|
||||
Toast.makeText(context, "解析包出错(可能被误删了),请重新下载", Toast.LENGTH_SHORT).show();
|
||||
removeDownload(downloadEntity, viewHolder.getPosition());
|
||||
removeDownload(downloadEntity);
|
||||
} else {
|
||||
if (downloadEntity.getName().contains("光环助手")) {
|
||||
context.startActivity(PackageUtils.getInstallIntent(path));
|
||||
@ -344,6 +344,11 @@ public class GameDownloadAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
}
|
||||
});
|
||||
|
||||
if (downloadEntity.getUrl().equals(url)) {
|
||||
viewHolder.itemView.setBackgroundColor(context.getResources().getColor(R.color.select));
|
||||
} else {
|
||||
viewHolder.itemView.setBackgroundResource(R.drawable.reuse_listview_item_style);
|
||||
}
|
||||
viewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
@ -500,50 +505,64 @@ public class GameDownloadAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
DialogUtils.showWarningDialog(context, "删除下载", msg, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
removeDownload(entry, position);
|
||||
removeDownload(entry);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void removeDownload(DownloadEntity entry, int position) {
|
||||
if (doneList.size() != 0 && position > 0 && position <= doneList.size()) {
|
||||
private void removeDownload(DownloadEntity entry) {
|
||||
Integer location = locationMap.get(entry.getUrl());
|
||||
if (location == null) {
|
||||
return;
|
||||
}
|
||||
boolean isDone = false;
|
||||
for (int i = 0, size = doneList.size(); i < size; i++) {
|
||||
if (entry.getUrl().equals(doneList.get(i).getUrl())) {
|
||||
isDone = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isDone) {
|
||||
if (downloadingList.isEmpty() && doneList.size() == 1) {
|
||||
doneList.remove(position - 1);
|
||||
doneList.remove(location.intValue());
|
||||
locationMap.clear();
|
||||
notifyDataSetChanged();
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.GONE, 0));
|
||||
locationMap.clear();
|
||||
if (downloadmanager_tv_none.getVisibility() == View.GONE) {
|
||||
downloadmanager_tv_none.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else if (doneList.size() == 1) {
|
||||
doneList.remove(position - 1);
|
||||
doneList.remove(location.intValue());
|
||||
initLocationMap();
|
||||
notifyItemRangeRemoved(0, 2);
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.VISIBLE,
|
||||
doneList.size() + downloadingList.size()));
|
||||
} else {
|
||||
doneList.remove(position - 1);
|
||||
notifyItemRemoved(position);
|
||||
doneList.remove(location.intValue());
|
||||
initLocationMap();
|
||||
notifyItemRemoved(location + 1);
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.VISIBLE,
|
||||
doneList.size() + downloadingList.size()));
|
||||
}
|
||||
} else {
|
||||
if (doneList.isEmpty() && downloadingList.size() == 1) {
|
||||
downloadingList.remove(position - 1 - getBase());
|
||||
downloadingList.remove(location.intValue());
|
||||
locationMap.clear();
|
||||
notifyDataSetChanged();
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.GONE, 0));
|
||||
locationMap.clear();
|
||||
if (downloadmanager_tv_none.getVisibility() == View.GONE) {
|
||||
downloadmanager_tv_none.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else if (downloadingList.size() == 1) {
|
||||
downloadingList.remove(position - 1 - getBase());
|
||||
downloadingList.remove(location.intValue());
|
||||
initLocationMap();
|
||||
notifyItemRangeRemoved(getBase(), 2);
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.VISIBLE,
|
||||
doneList.size() + downloadingList.size()));
|
||||
} else {
|
||||
downloadingList.remove(position - 1 - getBase());
|
||||
notifyItemRemoved(position);
|
||||
downloadingList.remove(location.intValue());
|
||||
initLocationMap();
|
||||
notifyItemRemoved(location + getBase() + 1);
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.VISIBLE,
|
||||
doneList.size() + downloadingList.size()));
|
||||
}
|
||||
@ -551,15 +570,14 @@ public class GameDownloadAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
|
||||
deleteList.add(entry.getUrl());
|
||||
statusMap.remove(entry.getUrl());
|
||||
locationMap.remove(entry.getUrl());
|
||||
initLocationMap();
|
||||
|
||||
notifyItemChanged(doneList.isEmpty() ? 0 : 1 + doneList.size());
|
||||
|
||||
DownloadManager.getInstance(context).cancel(entry.getUrl());
|
||||
}
|
||||
|
||||
private void initLocationMap() {
|
||||
public void initLocationMap() {
|
||||
locationMap.clear();
|
||||
for (int i = 0; i < doneList.size(); i++) {
|
||||
locationMap.put(doneList.get(i).getUrl(), i);
|
||||
}
|
||||
@ -584,10 +602,6 @@ public class GameDownloadAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
return locationMap.get(url);
|
||||
}
|
||||
|
||||
public void putLocation(String url, int location) {
|
||||
locationMap.put(url, location);
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getStatusMap() {
|
||||
return statusMap;
|
||||
}
|
||||
@ -607,7 +621,6 @@ public class GameDownloadAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
public void initMap() {
|
||||
downloadingList.clear();
|
||||
doneList.clear();
|
||||
locationMap.clear();
|
||||
statusMap.clear();
|
||||
urlMap.clear();
|
||||
for (DownloadEntity downloadEntity : DownloadManager.getInstance(context).getAll()) {
|
||||
@ -616,16 +629,48 @@ public class GameDownloadAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
urlMap.put(PackageUtils.getPackageNameByPath(context,
|
||||
downloadEntity.getPath()), downloadEntity.getUrl());
|
||||
doneList.add(downloadEntity);
|
||||
locationMap.put(downloadEntity.getUrl(), doneList.size() - 1);
|
||||
} else {
|
||||
downloadingList.add(downloadEntity);
|
||||
locationMap.put(downloadEntity.getUrl(), downloadingList.size() - 1);
|
||||
}
|
||||
}
|
||||
// 排序
|
||||
Comparator<DownloadEntity> comparator = new Comparator<DownloadEntity>() {
|
||||
@Override
|
||||
public int compare(DownloadEntity lhs, DownloadEntity rhs) {
|
||||
if (rhs.getStart() > lhs.getStart()) {
|
||||
return 1;
|
||||
} else if (rhs.getStart() < lhs.getStart()) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
Collections.sort(downloadingList, comparator);
|
||||
|
||||
comparator = new Comparator<DownloadEntity>() {
|
||||
@Override
|
||||
public int compare(DownloadEntity lhs, DownloadEntity rhs) {
|
||||
if (rhs.getEnd() > lhs.getEnd()) {
|
||||
return 1;
|
||||
} else if (rhs.getEnd() < lhs.getEnd()) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
Collections.sort(doneList, comparator);
|
||||
|
||||
initLocationMap();
|
||||
}
|
||||
|
||||
public int getBase() {
|
||||
return doneList.isEmpty() ? 0 : 1 + doneList.size();
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
notifyItemRangeChanged(0, getItemCount());
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
@ -13,7 +14,7 @@ import com.gh.gamecenter.R;
|
||||
*/
|
||||
public class GameDownloadViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ImageView dm_item_iv_icon;
|
||||
public SimpleDraweeView dm_item_iv_icon;
|
||||
public TextView dm_item_tv_title;
|
||||
public TextView dm_item_tv_downloads;
|
||||
public ImageView dm_item_iv_delete;
|
||||
@ -24,7 +25,7 @@ public class GameDownloadViewHolder extends RecyclerView.ViewHolder {
|
||||
public GameDownloadViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
dm_item_iv_icon = (ImageView) itemView.findViewById(R.id.dm_item_iv_icon);
|
||||
dm_item_iv_icon = (SimpleDraweeView) itemView.findViewById(R.id.dm_item_iv_icon);
|
||||
dm_item_tv_title = (TextView) itemView.findViewById(R.id.dm_item_tv_title);
|
||||
dm_item_tv_downloads = (TextView) itemView.findViewById(R.id.dm_item_tv_downloads);
|
||||
dm_item_iv_delete = (ImageView) itemView.findViewById(R.id.dm_item_iv_delete);
|
||||
|
||||
@ -2,12 +2,9 @@ package com.gh.gamecenter.download;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.SparseArray;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -21,7 +18,6 @@ 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.ImageUtils;
|
||||
import com.gh.common.util.MD5Utils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
@ -30,21 +26,20 @@ import com.gh.common.view.CardLinearLayout;
|
||||
import com.gh.common.view.CardRelativeLayout;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadStatus;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadChanged;
|
||||
import com.gh.gamecenter.eventbus.EBPerformClick;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
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.JSONObject;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@ -64,17 +59,12 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
private LinearLayout gameupdate_ll_loading;
|
||||
private LinearLayout gameupdate_tv_none;
|
||||
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, String> packageNameMap;
|
||||
private SparseBooleanArray successMap;
|
||||
private SparseArray<DownloadEntity> entryMap;
|
||||
private ArrayMap<String, ArrayList<Integer>> locationMap;
|
||||
|
||||
private List<GameUpdateEntity> updateList;
|
||||
|
||||
private String packageName;
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
public GameUpdateAdapter(Context context,
|
||||
LinearLayout loading,
|
||||
LinearLayout none,
|
||||
@ -87,9 +77,6 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
this.packageName = packageName;
|
||||
|
||||
locationMap = new ArrayMap<>();
|
||||
packageNameMap = new ArrayMap<>();
|
||||
successMap = new SparseBooleanArray();
|
||||
entryMap = new SparseArray<>();
|
||||
|
||||
updateList = new ArrayList<>();
|
||||
if (packageName != null) {
|
||||
@ -97,52 +84,70 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
} else if (isUpdate) {
|
||||
getUpdateListFromServer();
|
||||
} else {
|
||||
for (GameUpdateEntity updateEntity : PackageManager.getUpdateList()) {
|
||||
updateList.add(updateEntity);
|
||||
}
|
||||
sortUpdateList(updateList);
|
||||
|
||||
initMap();
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
updateList.clear();
|
||||
for (GameUpdateEntity updateEntity : PackageManager.getUpdateList()) {
|
||||
updateList.add(updateEntity);
|
||||
}
|
||||
sortUpdateList(updateList);
|
||||
|
||||
initLocationMap();
|
||||
|
||||
if (updateList.isEmpty()) {
|
||||
gameupdate_tv_none.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
gameupdate_tv_none.setVisibility(View.GONE);
|
||||
EventBus.getDefault().post(
|
||||
new EBDownloadChanged("update", View.VISIBLE, updateList.size()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 根据包名获取更新(单个)
|
||||
private void getUpdateByPackageName(String packageName) {
|
||||
gameupdate_ll_loading.setVisibility(View.VISIBLE);
|
||||
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "v1d45/support/package/update?package=" + packageName,
|
||||
new Response.Listener<JSONArray>() {
|
||||
if (PackageUtils.getMetaData(context, packageName, "gh_version") == null) {
|
||||
gameupdate_ll_loading.setVisibility(View.GONE);
|
||||
if (updateList.isEmpty()) {
|
||||
gameupdate_tv_none.setVisibility(View.VISIBLE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Object gh_id = PackageUtils.getMetaData(context, packageName, "gh_id");
|
||||
String url;
|
||||
if (gh_id == null) {
|
||||
url = Config.HOST + "update/package/" + packageName;
|
||||
} else {
|
||||
url = Config.HOST + "update/game/" + gh_id + "/package/" + packageName;
|
||||
}
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(url,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<ArrayList<GameUpdateEntity>>() {}.getType();
|
||||
ArrayList<GameUpdateEntity> games = gson.fromJson(response.toString(), listType);
|
||||
GameUpdateEntity gameUpdateEntity = gson.fromJson(
|
||||
response.toString(), GameUpdateEntity.class);
|
||||
|
||||
if (!isCanUpdate(games.get(0))) {
|
||||
games.remove(0);
|
||||
}
|
||||
|
||||
if (games.size() != 0) {
|
||||
updateList.add(games.get(0));
|
||||
if (PackageUtils.isCanUpdate(context, gameUpdateEntity)) {
|
||||
updateList.add(gameUpdateEntity);
|
||||
notifyItemRangeInserted(0, 2);
|
||||
PackageManager.addUpdateList(updateList);
|
||||
PackageManager.addUpdate(gameUpdateEntity);
|
||||
EventBus.getDefault().post(new EBDownloadChanged("update",
|
||||
View.VISIBLE, updateList.size()));
|
||||
initMap();
|
||||
initLocationMap();
|
||||
}
|
||||
|
||||
if (!updateList.isEmpty() && gameupdate_tv_none.getVisibility() == View.VISIBLE) {
|
||||
if (updateList.isEmpty()) {
|
||||
gameupdate_tv_none.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
gameupdate_tv_none.setVisibility(View.GONE);
|
||||
}
|
||||
gameupdate_ll_loading.setVisibility(View.GONE);
|
||||
}
|
||||
gameupdate_ll_loading.setVisibility(View.GONE);
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
@ -155,57 +160,52 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
|
||||
private int mCount;
|
||||
|
||||
private void addCount() {
|
||||
synchronized (GameUpdateAdapter.class) {
|
||||
mCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// 从服务器中获取更新(多个)
|
||||
public void getUpdateListFromServer() {
|
||||
gameupdate_ll_loading.setVisibility(View.VISIBLE);
|
||||
|
||||
List<String> packages = getInstalledList();
|
||||
if (packages.size() != 0) {
|
||||
sortPackageList(packages);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String params;
|
||||
PackageManager.clearUpdateList();
|
||||
final int count = (packages.size() / 10) + 1;
|
||||
final List<GameUpdateEntity> list = new ArrayList<>();
|
||||
final int count = packages.size();
|
||||
mCount = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
builder.delete(0, builder.length());
|
||||
for (int j = i * 10, size = (i + 1) * 10 > packages.size() ? packages
|
||||
.size() : (i + 1) * 10; j < size; j++) {
|
||||
builder.append(packages.get(j));
|
||||
builder.append("-");
|
||||
Object gh_id;
|
||||
for (String packageName : packages) {
|
||||
gh_id = PackageUtils.getMetaData(context, packageName, "gh_id");
|
||||
String url;
|
||||
if (gh_id == null) {
|
||||
url = Config.HOST + "update/package/" + packageName;
|
||||
} else {
|
||||
url = Config.HOST + "update/game/" + gh_id + "/package/" + packageName;
|
||||
}
|
||||
params = builder.substring(0, builder.length() - 1);
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "v1d45/support/package/update?package=" + params,
|
||||
new Response.Listener<JSONArray>() {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(url,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<ArrayList<GameUpdateEntity>>() {}.getType();
|
||||
ArrayList<GameUpdateEntity> games = gson.fromJson(response.toString(), listType);
|
||||
for (int i = 0; i < games.size(); i++) {
|
||||
if (!isCanUpdate(games.get(i))) {
|
||||
games.remove(i);
|
||||
i--;
|
||||
}
|
||||
GameUpdateEntity gameUpdateEntity = gson.fromJson(
|
||||
response.toString(), GameUpdateEntity.class);
|
||||
if (PackageUtils.isCanUpdate(context, gameUpdateEntity)) {
|
||||
PackageManager.addUpdate(gameUpdateEntity);
|
||||
}
|
||||
list.addAll(games);
|
||||
}
|
||||
mCount++;
|
||||
addCount();
|
||||
if (mCount == count) {
|
||||
processingData(list);
|
||||
processingData();
|
||||
}
|
||||
}
|
||||
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
mCount++;
|
||||
addCount();
|
||||
if (mCount == count) {
|
||||
processingData(list);
|
||||
processingData();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -216,36 +216,39 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
}
|
||||
}
|
||||
|
||||
private void processingData(List<GameUpdateEntity> list) {
|
||||
sortUpdateList(list);
|
||||
private void processingData() {
|
||||
for (GameUpdateEntity updateEntity : PackageManager.getUpdateList()) {
|
||||
updateList.add(updateEntity);
|
||||
}
|
||||
sortUpdateList(updateList);
|
||||
|
||||
updateList = list;
|
||||
notifyItemRangeInserted(0, 1 + updateList.size());
|
||||
|
||||
PackageManager.addUpdateList(updateList);
|
||||
EventBus.getDefault().post(
|
||||
new EBDownloadChanged("update", View.VISIBLE, updateList.size()));
|
||||
initMap();
|
||||
EventBus.getDefault().post(new EBDownloadChanged("update", View.VISIBLE, updateList.size()));
|
||||
initLocationMap();
|
||||
|
||||
if (!updateList.isEmpty() && gameupdate_tv_none.getVisibility() == View.VISIBLE) {
|
||||
if (updateList.isEmpty()) {
|
||||
gameupdate_tv_none.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
gameupdate_tv_none.setVisibility(View.GONE);
|
||||
}
|
||||
gameupdate_ll_loading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// 初始化map等变量
|
||||
private void initMap() {
|
||||
List<DownloadEntity> entries = DownloadManager.getInstance(context).getAll();
|
||||
// 初始化map
|
||||
public void initLocationMap() {
|
||||
locationMap.clear();
|
||||
|
||||
String packageName;
|
||||
ArrayList<Integer> list;
|
||||
for (int i = 0, size = updateList.size(); i < size; i++) {
|
||||
locationMap.put(updateList.get(i).getPackageName(), i);
|
||||
packageNameMap.put(updateList.get(i).getUrl(), updateList.get(i).getPackageName());
|
||||
successMap.put(i, false);
|
||||
for (DownloadEntity downloadEntity : entries) {
|
||||
if (updateList.get(i).getUrl().equals(downloadEntity.getUrl())) {
|
||||
entryMap.put(i, downloadEntity);
|
||||
break;
|
||||
}
|
||||
packageName = updateList.get(i).getPackageName();
|
||||
list = locationMap.get(packageName);
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
locationMap.put(packageName, list);
|
||||
}
|
||||
list.add(i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -255,7 +258,8 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
ConcernManager concernManager = new ConcernManager(context);
|
||||
for (ConcernInfo info : concernManager.getInstalledGame()) {
|
||||
for (String key : info.getPackageNames().keySet()) {
|
||||
if (info.getPackageNames().get(key)) {
|
||||
if (info.getPackageNames().get(key)
|
||||
&& PackageUtils.getMetaData(context, key, "gh_version") != null) {
|
||||
packages.add(key);
|
||||
}
|
||||
}
|
||||
@ -263,62 +267,6 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
return packages;
|
||||
}
|
||||
|
||||
private boolean isCanUpdate(GameUpdateEntity updateEntity) {
|
||||
// 判断是否gh_version是否相同
|
||||
String gh_version = (String) PackageUtils
|
||||
.getMetaData(context, updateEntity.getPackageName(), "gh_version");
|
||||
if (gh_version != null) {
|
||||
gh_version = gh_version.substring(2);
|
||||
// 判断gh_version是否相同
|
||||
if (gh_version.equals(updateEntity.getGhVersion())) {
|
||||
// 判断version是否相同
|
||||
String version = PackageUtils
|
||||
.getVersionByPackage(context, updateEntity.getPackageName());
|
||||
if (version != null && version.equals(updateEntity.getVersion())) {
|
||||
// 版本相同,无需显示插件更新,继续查看是否有可更新的游戏包
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 对包名进行排序
|
||||
private void sortPackageList(List<String> list) {
|
||||
Comparator<String> comparator = new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String lhs, String rhs) {
|
||||
char[] clhs = lhs.toCharArray();
|
||||
char[] crhs = rhs.toCharArray();
|
||||
int length;
|
||||
if (clhs.length < crhs.length) {
|
||||
length = clhs.length;
|
||||
} else if (clhs.length > crhs.length) {
|
||||
length = crhs.length;
|
||||
} else {
|
||||
length = clhs.length;
|
||||
}
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (clhs[i] > crhs[i]) {
|
||||
return 1;
|
||||
} else if (clhs[i] < crhs[i]) {
|
||||
return -1;
|
||||
} else if (i == length - 1) {
|
||||
if (clhs.length < crhs.length) {
|
||||
return -1;
|
||||
} else if (clhs.length > crhs.length) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
Collections.sort(list, comparator);
|
||||
}
|
||||
|
||||
// 对更新列表进行排序
|
||||
private void sortUpdateList(List<GameUpdateEntity> list) {
|
||||
Comparator<GameUpdateEntity> comparator = new Comparator<GameUpdateEntity>() {
|
||||
@ -366,11 +314,12 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
String str = updateList.get(i).getSize();
|
||||
str = str.substring(0, str.lastIndexOf("M"));
|
||||
size += Float.valueOf(str);
|
||||
if (entryMap.get(i) != null) {
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(context).get(updateList.get(i).getUrl());
|
||||
if (downloadEntity != null) {
|
||||
count++;
|
||||
}
|
||||
if (successMap.get(i)) {
|
||||
done++;
|
||||
if (downloadEntity.getStatus().equals(DownloadStatus.done)) {
|
||||
done++;
|
||||
}
|
||||
}
|
||||
}
|
||||
CardRelativeLayout cardRelativeLayout = (CardRelativeLayout) viewHolder.itemView;
|
||||
@ -396,7 +345,7 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
viewHolder.dm_item_head_tv_allstart.setText("更新中");
|
||||
for (int i = 0; i < updateList.size(); i++) {
|
||||
if (entryMap.get(i) == null) {
|
||||
if (DownloadManager.getInstance(context).get(updateList.get(i).getUrl()) == null) {
|
||||
addUpdateDownload(i);
|
||||
notifyItemChanged(i + 1);
|
||||
}
|
||||
@ -407,7 +356,7 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
public void onConfirem() {
|
||||
viewHolder.dm_item_head_tv_allstart.setText("更新中");
|
||||
for (int i = 0; i < updateList.size(); i++) {
|
||||
if (entryMap.get(i) == null) {
|
||||
if (DownloadManager.getInstance(context).get(updateList.get(i).getUrl()) == null) {
|
||||
addUpdateDownload(i);
|
||||
notifyItemChanged(i + 1);
|
||||
}
|
||||
@ -441,8 +390,9 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
if (updateEntity.getName().contains("光环助手")) {
|
||||
viewHolder.gu_item_iv_icon.setImageResource(R.drawable.logo);
|
||||
} else {
|
||||
ImageUtils.getInstance(context).display(
|
||||
updateEntity.getIcon(), viewHolder.gu_item_iv_icon);
|
||||
// ImageUtils.getInstance(context).display(
|
||||
// updateEntity.getIcon(), viewHolder.gu_item_iv_icon);
|
||||
viewHolder.gu_item_iv_icon.setImageURI(updateEntity.getIcon());
|
||||
}
|
||||
|
||||
final String platform = PlatformUtils.getInstance(context)
|
||||
@ -463,35 +413,6 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
|
||||
viewHolder.gu_item_tv_new.setText("新版:V" + updateEntity.getVersion() + " | " + updateEntity.getSize());
|
||||
|
||||
if (successMap.get(position - 1)) {
|
||||
viewHolder.gu_item_btv_update.setText("启动");
|
||||
viewHolder.gu_item_btv_update.setTextColor(Color.WHITE);
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
} else {
|
||||
DownloadEntity entry = entryMap.get(position - 1);
|
||||
if (entry != null) {
|
||||
if (updateEntity.isPluggable()) {
|
||||
viewHolder.gu_item_btv_update.setText("插件化中");
|
||||
viewHolder.gu_item_btv_update.setTextColor(context.getResources().getColorStateList(R.color.text_plugining_style));
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_plugining_style);
|
||||
} else {
|
||||
viewHolder.gu_item_btv_update.setText("更新中");
|
||||
viewHolder.gu_item_btv_update.setTextColor(context.getResources().getColorStateList(R.color.text_downloading_style));
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
}
|
||||
} else {
|
||||
if (updateEntity.isPluggable()) {
|
||||
viewHolder.gu_item_btv_update.setText("插件化");
|
||||
viewHolder.gu_item_btv_update.setTextColor(Color.WHITE);
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else {
|
||||
viewHolder.gu_item_btv_update.setText("更新");
|
||||
viewHolder.gu_item_btv_update.setTextColor(Color.WHITE);
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
viewHolder.gu_item_btv_update.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -539,15 +460,55 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
PackageUtils.launchApplicationByPackageName(context,
|
||||
updateEntity.getPackageName());
|
||||
} else if ("更新中".equals(str) || "插件化中".equals(str)) {
|
||||
handler.postDelayed(runnable, 300);
|
||||
notifyItemChanged(0);
|
||||
EventBus.getDefault().post(new EBSkip("DownloadManagerActivity", 0));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(context).get(updateEntity.getUrl());
|
||||
if (downloadEntity == null) {
|
||||
if (updateEntity.isPluggable()) {
|
||||
viewHolder.gu_item_btv_update.setText("插件化");
|
||||
viewHolder.gu_item_btv_update.setTextColor(Color.WHITE);
|
||||
downloadEntity = DownloadManager.getInstance(context).getByPackage(
|
||||
updateEntity.getPackageName());
|
||||
if (downloadEntity == null
|
||||
|| downloadEntity.getUrl().equals(updateEntity.getUrl())) {
|
||||
viewHolder.gu_item_btv_update.setClickable(true);
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else {
|
||||
viewHolder.gu_item_btv_update.setClickable(false);
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_pause_up);
|
||||
}
|
||||
} else {
|
||||
viewHolder.gu_item_btv_update.setText("更新");
|
||||
viewHolder.gu_item_btv_update.setTextColor(Color.WHITE);
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
}
|
||||
} else {
|
||||
if (PackageManager.isCanUpdate(updateEntity.getId(), updateEntity.getPackageName())) {
|
||||
viewHolder.gu_item_btv_update.setText("启动");
|
||||
viewHolder.gu_item_btv_update.setTextColor(Color.WHITE);
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
} else {
|
||||
if (updateEntity.isPluggable()) {
|
||||
viewHolder.gu_item_btv_update.setText("插件化中");
|
||||
viewHolder.gu_item_btv_update.setTextColor(
|
||||
context.getResources().getColorStateList(R.color.text_plugining_style));
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_plugining_style);
|
||||
} else {
|
||||
viewHolder.gu_item_btv_update.setText("更新中");
|
||||
viewHolder.gu_item_btv_update.setTextColor(
|
||||
context.getResources().getColorStateList(R.color.text_downloading_style));
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (packageName != null) {
|
||||
viewHolder.gu_item_btv_update.performClick();
|
||||
packageName = null;
|
||||
handler.postDelayed(runnable, 800);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -605,7 +566,7 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
}
|
||||
map.put("platform", PlatformUtils.getInstance(context)
|
||||
.getPlatformName(updateEntity.getPlatform()));
|
||||
map.put("location", "游戏更新");
|
||||
map.put("location", "游戏更新:列表");
|
||||
map.put("entrance", "(下载管理:游戏更新)");
|
||||
map.put("network", NetworkUtils.getConnectedType(context));
|
||||
DataCollectionManager.onEvent(context, "download", map);
|
||||
@ -631,37 +592,32 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
DownloadManager.getInstance(context).pauseAll();
|
||||
}
|
||||
DownloadManager.getInstance(context).add(downloadEntity);
|
||||
entryMap.put(position, downloadEntity);
|
||||
|
||||
handler.postDelayed(runnable, 300);
|
||||
notifyItemChanged(0);
|
||||
EventBus.getDefault().post(new EBSkip("DownloadManagerActivity", 0));
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
notifyItemChanged(0);
|
||||
EventBus.getDefault().post(new EBPerformClick("update"));
|
||||
}
|
||||
};
|
||||
|
||||
public List<GameUpdateEntity> getUpdateList() {
|
||||
return updateList;
|
||||
}
|
||||
|
||||
public ArrayMap<String, Integer> getLocationMap() {
|
||||
public ArrayMap<String, ArrayList<Integer>> getLocationMap() {
|
||||
return locationMap;
|
||||
}
|
||||
|
||||
public SparseBooleanArray getSuccessMap() {
|
||||
return successMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getPackageNameMap() {
|
||||
return packageNameMap;
|
||||
}
|
||||
|
||||
public SparseArray<DownloadEntity> getEntryMap() {
|
||||
return entryMap;
|
||||
public void removeUpdate(String packageName) {
|
||||
for (int i = 0; i < updateList.size(); i++) {
|
||||
if (updateList.get(i).getPackageName().equals(packageName)) {
|
||||
updateList.remove(i);
|
||||
if (updateList.isEmpty()) {
|
||||
notifyItemRangeRemoved(0, 2);
|
||||
break;
|
||||
}
|
||||
notifyItemRemoved(i + 1);
|
||||
notifyItemChanged(0);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -20,7 +20,8 @@ import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBMiPush;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
@ -43,30 +44,12 @@ public class GameUpdateFragment extends Fragment {
|
||||
private String packageName;
|
||||
private boolean isUpdate;
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString("packageName", packageName);
|
||||
outState.putBoolean("isUpdate", isUpdate);
|
||||
}
|
||||
|
||||
public void setParams(String str, boolean flag) {
|
||||
packageName = str;
|
||||
isUpdate = flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
if (savedInstanceState.containsKey("packageName")) {
|
||||
packageName = savedInstanceState.getString("packageName");
|
||||
}
|
||||
if (savedInstanceState.containsKey("isUpdate")) {
|
||||
isUpdate = savedInstanceState.getBoolean("isUpdate");
|
||||
}
|
||||
}
|
||||
packageName = getActivity().getIntent().getStringExtra("packageName");
|
||||
isUpdate = getActivity().getIntent().getBooleanExtra("isPushIntent", false);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.gameupdate, null);
|
||||
|
||||
@ -120,46 +103,36 @@ public class GameUpdateFragment extends Fragment {
|
||||
|
||||
public void onEventMainThread(EBDownloadStatus status) {
|
||||
if ("delete".equals(status.getStatus())) {
|
||||
String packageName = adapter.getPackageNameMap().get(status.getUrl());
|
||||
if (packageName != null) {
|
||||
Integer location = adapter.getLocationMap().get(packageName);
|
||||
adapter.getEntryMap().remove(location);
|
||||
gameupdate_rv_show.getAdapter().notifyItemChanged(location + 1);
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(status.getPackageName());
|
||||
if (locationList != null) {
|
||||
for (int location : locationList) {
|
||||
gameupdate_rv_show.getAdapter().notifyItemChanged(location);
|
||||
}
|
||||
gameupdate_rv_show.getAdapter().notifyItemChanged(0);
|
||||
}
|
||||
} else if ("update".equals(status.getStatus()) || "plugin".equals(status.getStatus())) {
|
||||
adapter.init();
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
Integer location = adapter.getLocationMap().get(busFour.getPackageName());
|
||||
if (location != null) {
|
||||
adapter.getSuccessMap().put(location, true);
|
||||
EventBus.getDefault().post(
|
||||
new EBDownloadChanged("update", View.VISIBLE, -1));
|
||||
gameupdate_rv_show.getAdapter().notifyItemChanged(location + 1);
|
||||
gameupdate_rv_show.getAdapter().notifyItemChanged(0);
|
||||
PackageManager.removeUpdateList(busFour.getPackageName());
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
Integer location = adapter.getLocationMap().get(busFour.getPackageName());
|
||||
if (location != null && adapter.getUpdateList().size() != 0) {
|
||||
if (adapter.getUpdateList().get(location).isPluggable()) {
|
||||
EventBus.getDefault().post(
|
||||
new EBDownloadChanged("update", View.VISIBLE, -1));
|
||||
if (adapter.getUpdateList().size() == 1) {
|
||||
adapter.getUpdateList().remove(location.intValue());
|
||||
adapter.notifyItemRangeRemoved(0, 2);
|
||||
if (reuse_nodata_skip.getVisibility() == View.GONE) {
|
||||
reuse_nodata_skip.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
adapter.getUpdateList().remove(location.intValue());
|
||||
adapter.notifyItemRemoved(location + 1);
|
||||
adapter.notifyItemChanged(0);
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(busFour.getPackageName());
|
||||
if (locationList != null) {
|
||||
for (int location : locationList) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
gameupdate_rv_show.getAdapter().notifyItemChanged(location + 1);
|
||||
gameupdate_rv_show.getAdapter().notifyItemChanged(0);
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.removeUpdate(busFour.getPackageName());
|
||||
if (adapter.getUpdateList().isEmpty()) {
|
||||
reuse_nodata_skip.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
EventBus.getDefault().post(
|
||||
new EBDownloadChanged("update", View.VISIBLE, -1));
|
||||
}
|
||||
adapter.initLocationMap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,9 +2,9 @@ package com.gh.gamecenter.download;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -12,7 +12,7 @@ import com.gh.gamecenter.R;
|
||||
*/
|
||||
public class GameUpdateViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ImageView gu_item_iv_icon;
|
||||
public SimpleDraweeView gu_item_iv_icon;
|
||||
public TextView gu_item_tv_name;
|
||||
public TextView gu_item_tv_current;
|
||||
public TextView gu_item_tv_new;
|
||||
@ -21,7 +21,7 @@ public class GameUpdateViewHolder extends RecyclerView.ViewHolder {
|
||||
public GameUpdateViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
gu_item_iv_icon = (ImageView) itemView.findViewById(R.id.gu_item_iv_icon);
|
||||
gu_item_iv_icon = (SimpleDraweeView) itemView.findViewById(R.id.gu_item_iv_icon);
|
||||
gu_item_tv_name = (TextView) itemView.findViewById(R.id.gu_item_tv_name);
|
||||
gu_item_tv_current = (TextView) itemView.findViewById(R.id.gu_item_tv_current);
|
||||
gu_item_tv_new = (TextView) itemView.findViewById(R.id.gu_item_tv_new);
|
||||
|
||||
@ -18,6 +18,23 @@ public class ConcernEntity {
|
||||
private String content;
|
||||
private int time;
|
||||
private List<String> img;
|
||||
private String link;
|
||||
private String brief;
|
||||
|
||||
public String getBrief() {
|
||||
return brief;
|
||||
}
|
||||
public void setBrief(String brief) {
|
||||
this.brief = brief;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
public void setLink(String link) {
|
||||
this.link = link;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@ -18,6 +18,16 @@ public class GameDetailEntity {
|
||||
private ArrayList<String> articleTypes;
|
||||
@SerializedName("share_code")
|
||||
private String shareCode;
|
||||
@SerializedName("download_off_text")
|
||||
private String downloadOffText;
|
||||
|
||||
public void setDownloadOffText(String downloadOffText) {
|
||||
this.downloadOffText = downloadOffText;
|
||||
}
|
||||
|
||||
public String getDownloadOffText() {
|
||||
return downloadOffText;
|
||||
}
|
||||
|
||||
public ArrayList<String> getArticleTypes() {
|
||||
return articleTypes;
|
||||
|
||||
@ -41,6 +41,28 @@ public class GameEntity {
|
||||
|
||||
private String link;
|
||||
|
||||
@SerializedName("concern_article_exists")
|
||||
private boolean newsExists = true;
|
||||
|
||||
@SerializedName("download_off_text")
|
||||
private String downloadOffText;
|
||||
|
||||
public void setDownloadOffText(String downloadOffText) {
|
||||
this.downloadOffText = downloadOffText;
|
||||
}
|
||||
|
||||
public String getDownloadOffText() {
|
||||
return downloadOffText;
|
||||
}
|
||||
|
||||
public boolean isNewsExists() {
|
||||
return newsExists;
|
||||
}
|
||||
|
||||
public void setNewsExists(boolean newsExists) {
|
||||
this.newsExists = newsExists;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
@ -170,36 +192,28 @@ public class GameEntity {
|
||||
gameEntity.setIcon(icon);
|
||||
gameEntity.setName(name);
|
||||
gameEntity.setBrief(brief);
|
||||
gameEntity.setTag(new ArrayList<>(tag));
|
||||
gameEntity.setApk(new ArrayList<>(apk));
|
||||
if (tag != null) {
|
||||
gameEntity.setTag(new ArrayList<>(tag));
|
||||
}
|
||||
if (apk != null) {
|
||||
gameEntity.setApk(new ArrayList<>(apk));
|
||||
}
|
||||
if (collection != null) {
|
||||
gameEntity.setCollection(new ArrayList<>(collection));
|
||||
}
|
||||
gameEntity.setSlide(slide);
|
||||
gameEntity.setTest(test);
|
||||
gameEntity.setDownloadAddWord(downloadAddWord);
|
||||
gameEntity.setEntryMap(new ArrayMap<String, DownloadEntity>(entryMap));
|
||||
if (entryMap != null) {
|
||||
gameEntity.setEntryMap(new ArrayMap<String, DownloadEntity>(entryMap));
|
||||
}
|
||||
gameEntity.setImage(image);
|
||||
gameEntity.setType(type);
|
||||
gameEntity.setPluggable(isPluggable);
|
||||
gameEntity.setLink(link);
|
||||
gameEntity.setNewsExists(newsExists);
|
||||
gameEntity.setDownloadOffText(downloadOffText);
|
||||
return gameEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GameEntity{" +
|
||||
"id='" + id + '\'' +
|
||||
", icon='" + icon + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", brief='" + brief + '\'' +
|
||||
", tag=" + tag +
|
||||
", apk=" + apk +
|
||||
", collection=" + collection +
|
||||
", slide='" + slide + '\'' +
|
||||
", test=" + test +
|
||||
", downloadAddWord='" + downloadAddWord + '\'' +
|
||||
", entryMap=" + entryMap +
|
||||
", image='" + image + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
", isPluggable=" + isPluggable +
|
||||
", link='" + link + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,23 +163,4 @@ public class GameUpdateEntity {
|
||||
this.apk = apk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GameUpdateEntity{" +
|
||||
"id='" + id + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", icon='" + icon + '\'' +
|
||||
", packageName='" + packageName + '\'' +
|
||||
", size='" + size + '\'' +
|
||||
", version='" + version + '\'' +
|
||||
", ghVersion='" + ghVersion + '\'' +
|
||||
", url='" + url + '\'' +
|
||||
", platform='" + platform + '\'' +
|
||||
", isPluggable=" + isPluggable +
|
||||
", apk=" + apk +
|
||||
", etag='" + etag + '\'' +
|
||||
", brief='" + brief + '\'' +
|
||||
", tag=" + tag +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,10 +4,16 @@ public class EBConcernChanged {
|
||||
|
||||
private String gameId;
|
||||
private boolean isConcern;
|
||||
private boolean isSingle;
|
||||
|
||||
public EBConcernChanged(String gameId, boolean isConcern) {
|
||||
this.gameId = gameId;
|
||||
this.isConcern = isConcern;
|
||||
this.isSingle = true;
|
||||
}
|
||||
|
||||
public EBConcernChanged() {
|
||||
this.isSingle = false;
|
||||
}
|
||||
|
||||
public String getGameId() {
|
||||
@ -18,4 +24,7 @@ public class EBConcernChanged {
|
||||
return isConcern;
|
||||
}
|
||||
|
||||
public boolean isSingle() {
|
||||
return isSingle;
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,17 +9,19 @@ public class EBDownloadStatus {
|
||||
private String name;
|
||||
private String platform;
|
||||
private String url;
|
||||
private String packageName;
|
||||
private boolean isPluggable;
|
||||
|
||||
public EBDownloadStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public EBDownloadStatus(String status, String name, String platform, String url) {
|
||||
public EBDownloadStatus(String status, String name, String platform, String url, String packageName) {
|
||||
this.status = status;
|
||||
this.name = name;
|
||||
this.platform = platform;
|
||||
this.url = url;
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
@ -38,6 +40,10 @@ public class EBDownloadStatus {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public boolean isPluggable() {
|
||||
return isPluggable;
|
||||
}
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
package com.gh.gamecenter.eventbus;
|
||||
|
||||
public class EBPerformClick {
|
||||
|
||||
private String from;
|
||||
|
||||
public EBPerformClick(String from) {
|
||||
super();
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
public String getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public void setFrom(String from) {
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
}
|
||||
@ -6,10 +6,10 @@ import android.support.annotation.Nullable;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseFragment;
|
||||
@ -26,7 +26,6 @@ import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -54,31 +53,17 @@ public class Game1Fragment extends BaseFragment implements SwipeRefreshLayout.On
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
if (!fm_game_swipe_refresh.isRefreshing()) {
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(downloadEntity.getName());
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(downloadEntity.getPackageName());
|
||||
if (locationList != null && locationList.size() != 0) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
GameEntity detailedEntity = getEntityByLocation(location);
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(getActivity(), detailedEntity,
|
||||
gameEntity = adapter.getGameEntityByLocation(location);
|
||||
if (gameEntity != null) {
|
||||
DownloadItemUtils.processDate(getActivity(), gameEntity,
|
||||
downloadEntity, adapter, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//特殊 插件化update
|
||||
if (downloadEntity.isPluggable()) {
|
||||
locationList = adapter.getLocationMap().get(downloadEntity.getName()
|
||||
+ " - " + downloadEntity.getPlatform());
|
||||
if (locationList != null && locationList.size() != 0) {
|
||||
for (int location : locationList) {
|
||||
GameEntity detailedEntity = getEntityByLocation(location);
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(getActivity(), detailedEntity,
|
||||
downloadEntity, adapter, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -111,6 +96,18 @@ public class Game1Fragment extends BaseFragment implements SwipeRefreshLayout.On
|
||||
fm_game_rv_list.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
adapter = new Game1FragmentAdapter(Game1Fragment.this, fm_game_swipe_refresh, false);
|
||||
fm_game_rv_list.setAdapter(adapter);
|
||||
|
||||
fm_game_rv_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE){
|
||||
Fresco.getImagePipeline().resume();
|
||||
}else {
|
||||
Fresco.getImagePipeline().pause();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -135,34 +132,17 @@ public class Game1Fragment extends BaseFragment implements SwipeRefreshLayout.On
|
||||
if ("delete".equals(status.getStatus())) {
|
||||
DownloadManager.getInstance(getActivity()).removePlatform(status.getName(), status.getPlatform());
|
||||
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(status.getName());
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(status.getPackageName());
|
||||
GameEntity gameEntity;
|
||||
if (locationList != null && locationList.size() != 0) {
|
||||
for (int location : locationList) {
|
||||
gameEntity = getEntityByLocation(location);
|
||||
gameEntity = adapter.getGameEntityByLocation(location);
|
||||
if (gameEntity != null && gameEntity.getEntryMap() != null) {
|
||||
if (TextUtils.isEmpty(status.getPlatform())) {
|
||||
gameEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
gameEntity.getEntryMap().remove(status.getPlatform());
|
||||
}
|
||||
gameEntity.getEntryMap().remove(status.getPlatform());
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
//特殊 插件化update
|
||||
if (status.isPluggable()) {
|
||||
locationList = adapter.getLocationMap().get(status.getName() + " - " + status.getPlatform());
|
||||
if (locationList != null && locationList.size() != 0) {
|
||||
for (int location : locationList) {
|
||||
gameEntity = getEntityByLocation(location);
|
||||
if (gameEntity != null) {
|
||||
gameEntity.setEntryMap(null);
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ("plugin".equals(status.getStatus())) {
|
||||
handler.postDelayed(initPluginRunnable, 100);
|
||||
}
|
||||
@ -171,68 +151,65 @@ public class Game1Fragment extends BaseFragment implements SwipeRefreshLayout.On
|
||||
Runnable initPluginRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (PackageManager.getPluggableSize() != 0
|
||||
&& adapter.getPluginList().isEmpty()) {
|
||||
if (adapter.isInitPlugin()) {
|
||||
adapter.initPlugin();
|
||||
} else {
|
||||
handler.postDelayed(initPluginRunnable, 100);
|
||||
}
|
||||
if (adapter.isInitPlugin()) {
|
||||
handler.postDelayed(initPluginRunnable, 100);
|
||||
} else {
|
||||
adapter.initPlugin();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = adapter.getNameMap().get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(name);
|
||||
if (locationList != null && locationList.size() != 0) {
|
||||
for (int location : locationList) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity detailedEntity = getEntityByLocation(location);
|
||||
if (detailedEntity != null) {
|
||||
for (ApkEntity apkEntity : detailedEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
detailedEntity.getEntryMap().remove(
|
||||
apkEntity.getPlatform());
|
||||
adapter.notifyItemChanged(location);
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(busFour.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
gameEntity = adapter.getGameEntityByLocation(location);
|
||||
if (gameEntity != null) {
|
||||
if (gameEntity.isPluggable()) {
|
||||
// 插件化列表
|
||||
if ("安装".equals(busFour.getType()) || "卸载".equals(busFour.getType())) {
|
||||
List<GameEntity> list = adapter.getPluginList();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (list.get(i).getApk().get(0).getPackageName().equals(busFour.getPackageName())) {
|
||||
if ("卸载".equals(busFour.getType())
|
||||
&& DownloadManager.getInstance(getActivity()).get(
|
||||
list.get(i).getApk().get(0).getUrl()) != null) {
|
||||
adapter.notifyItemChanged(2 + i);
|
||||
} else {
|
||||
list.remove(i);
|
||||
if (list.isEmpty()) {
|
||||
adapter.initItemCount();
|
||||
adapter.notifyItemRangeRemoved(1, 2);
|
||||
} else {
|
||||
adapter.initItemCount();
|
||||
adapter.notifyItemRemoved(location);
|
||||
adapter.notifyItemChanged(1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//特殊 插件化
|
||||
name = adapter.getPluginNameMap().get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(name);
|
||||
if (locationList != null && locationList.size() != 0) {
|
||||
int location;
|
||||
for (int i = 0; i < locationList.size(); i++) {
|
||||
location = locationList.get(i);
|
||||
if ("安装".equals(busFour.getType()) || "卸载".equals(busFour.getType())) {
|
||||
List<GameEntity> list = adapter.getPluginList();
|
||||
for (int j = 0; j < list.size(); j++) {
|
||||
if (list.get(j).getApk().get(0).getPackageName()
|
||||
.equals(busFour.getPackageName())) {
|
||||
list.remove(j);
|
||||
adapter.notifyItemRemoved(location);
|
||||
locationList.remove(i);
|
||||
break;
|
||||
} else {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(busFour.getPackageName())) {
|
||||
if (gameEntity.getEntryMap() != null) {
|
||||
gameEntity.getEntryMap().remove(apkEntity.getPlatform());
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (locationList.isEmpty()) {
|
||||
adapter.getLocationMap().remove(name);
|
||||
}
|
||||
}
|
||||
adapter.initLocationMap();
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,28 +258,6 @@ public class Game1Fragment extends BaseFragment implements SwipeRefreshLayout.On
|
||||
}
|
||||
}
|
||||
|
||||
private GameEntity getEntityByLocation(int position) {
|
||||
List<GameEntity> pluginList = adapter.getPluginList();
|
||||
List<SubjectEntity> subjectList = adapter.getSubjectList();
|
||||
|
||||
if (!pluginList.isEmpty() && position > 1 && position <= 1 + pluginList.size()) {
|
||||
return pluginList.get(position - 2);
|
||||
}
|
||||
|
||||
int offset = 1;
|
||||
if (!pluginList.isEmpty()) {
|
||||
offset += 1 + pluginList.size();
|
||||
}
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
return subjectList.get(i).getData().get(position - offset - 1);
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
@ -23,6 +23,7 @@ import com.android.volley.TimeoutError;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.ItemViewType;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
@ -71,15 +72,6 @@ import java.util.Map;
|
||||
*/
|
||||
public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private class ITEM_TYPE {
|
||||
public static final int slide = 0; // 滚动图
|
||||
public static final int head = 1; // 专题头部
|
||||
public static final int game_normal_type = 2; // 游戏布局1
|
||||
public static final int game_test_type = 3; // 游戏布局2
|
||||
public static final int image = 4; // 大图布局
|
||||
public static final int footer_view = 5; // 加载布局
|
||||
}
|
||||
|
||||
private Game1Fragment fragment;
|
||||
private Context context;
|
||||
private OnCallBackListener listener;
|
||||
@ -90,10 +82,10 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
private List<GameEntity> pluginList;
|
||||
private List<SubjectEntity> subjectList;
|
||||
|
||||
// 包名对应游戏位置
|
||||
private ArrayMap<String, ArrayList<Integer>> locationMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private ArrayMap<String, String> pluginNameMap;
|
||||
|
||||
private int itemCount;
|
||||
private int pluginSize;
|
||||
|
||||
private boolean isNetworkError;
|
||||
@ -117,9 +109,8 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
subjectList = new ArrayList<>();
|
||||
|
||||
locationMap = new ArrayMap<>();
|
||||
nameMap = new ArrayMap<>();
|
||||
pluginNameMap = new ArrayMap<>();
|
||||
|
||||
itemCount = 0;
|
||||
pluginSize = 0;
|
||||
|
||||
isNetworkError = false;
|
||||
@ -137,17 +128,29 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
return locationMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getNameMap() {
|
||||
return nameMap;
|
||||
}
|
||||
public GameEntity getGameEntityByLocation(int location) {
|
||||
|
||||
public ArrayMap<String, String> getPluginNameMap() {
|
||||
return pluginNameMap;
|
||||
if (!pluginList.isEmpty() && location > 1 && location <= 1 + pluginList.size()) {
|
||||
return pluginList.get(location - 2);
|
||||
}
|
||||
|
||||
int offset = 1;
|
||||
if (!pluginList.isEmpty()) {
|
||||
offset += 1 + pluginList.size();
|
||||
}
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
if (location > offset && location <= subjectList.get(i).getData().size() + offset) {
|
||||
return subjectList.get(i).getData().get(location - offset - 1);
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void initSlide(final boolean isFirst) {
|
||||
JsonArrayExtendedRequest slideRequest = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "v1d50/index/slides",
|
||||
Config.HOST + "index/slides",
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
@ -180,7 +183,7 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
|
||||
private void initSubjectList() {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "v1d50/game/chajian",
|
||||
Config.HOST + "game/chajian",
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
@ -196,6 +199,7 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
if (subjectEntity.getData().size() == 1
|
||||
&& !TextUtils.isEmpty(subjectEntity.getData().get(0).getImage())){
|
||||
list.remove(j);
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < subjectEntity.getData().size(); i++) {
|
||||
@ -219,14 +223,17 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
if (!fragment.isHidden() && !fragment.isEverpause()) {
|
||||
if (pluginList.isEmpty()) {
|
||||
subjectList = list;
|
||||
initItemCount();
|
||||
notifyItemRangeInserted(1, getItemCount() - 2);
|
||||
} else {
|
||||
int start = 2 + pluginList.size();
|
||||
subjectList = list;
|
||||
initItemCount();
|
||||
notifyItemRangeInserted(start, getItemCount() - start - 1);
|
||||
}
|
||||
} else {
|
||||
subjectList = list;
|
||||
initItemCount();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
initLocationMap();
|
||||
@ -258,20 +265,23 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
}
|
||||
|
||||
public void initPlugin() {
|
||||
if (isInitPlugin) {
|
||||
return;
|
||||
}
|
||||
isInitPlugin = true;
|
||||
ArrayList<GameUpdateEntity> updateList = PackageManager.getUpdateList();
|
||||
if (updateList.isEmpty()) {
|
||||
if (!isInitPlugin) {
|
||||
isInitPlugin = true;
|
||||
}
|
||||
isInitPlugin = false;
|
||||
return;
|
||||
}
|
||||
List<GameEntity> list = new ArrayList<>();
|
||||
GameUpdateEntity gameUpdateEntity;
|
||||
pluginSize = 0;
|
||||
for (int i = 0, size= updateList.size(); i < size; i++) {
|
||||
gameUpdateEntity = updateList.get(i);
|
||||
if (gameUpdateEntity.isPluggable()) {
|
||||
pluginSize++;
|
||||
if (pluginList.size() < 3) {
|
||||
if (list.size() < 3) {
|
||||
GameEntity gameEntity = new GameEntity();
|
||||
gameEntity.setId(gameUpdateEntity.getId());
|
||||
gameEntity.setName(gameUpdateEntity.getName());
|
||||
@ -302,16 +312,20 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
gEntity.setEntryMap(DownloadManager.getInstance(context).
|
||||
getEntryMap(gEntity.getName()));
|
||||
}
|
||||
pluginList = list;
|
||||
notifyItemRangeInserted(1, pluginList.size() + 1);
|
||||
if (getItemCount() > pluginList.size() + 2) {
|
||||
notifyItemChanged(pluginList.size() + 2);
|
||||
if (pluginList.isEmpty()) {
|
||||
pluginList = list;
|
||||
initItemCount();
|
||||
notifyItemRangeInserted(1, pluginList.size() + 1);
|
||||
if (getItemCount() > pluginList.size() + 2) {
|
||||
notifyItemChanged(pluginList.size() + 2);
|
||||
}
|
||||
} else {
|
||||
pluginList = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
initLocationMap();
|
||||
}
|
||||
if (!isInitPlugin) {
|
||||
isInitPlugin = true;
|
||||
}
|
||||
isInitPlugin = false;
|
||||
}
|
||||
|
||||
private void showView() {
|
||||
@ -327,27 +341,23 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
}
|
||||
}
|
||||
|
||||
private void initLocationMap() {
|
||||
public void initLocationMap() {
|
||||
locationMap.clear();
|
||||
|
||||
int count = getItemCount();
|
||||
if (!pluginList.isEmpty()) {
|
||||
GameEntity gameEntity;
|
||||
String name;
|
||||
ArrayList<Integer> list;
|
||||
for (int position = 0; position < count; position++) {
|
||||
if (position > 1 && position <= 1 + pluginList.size()) {
|
||||
gameEntity = pluginList.get(position - 2);
|
||||
name = gameEntity.getName() + " - " + gameEntity.getApk().get(0).getPlatform();
|
||||
list = locationMap.get(name);
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
locationMap.put(name, list);
|
||||
}
|
||||
list.add(position);
|
||||
for (int position = 0, size = pluginList.size(); position < size; position++) {
|
||||
gameEntity = pluginList.get(position);
|
||||
if (gameEntity.getApk() != null && gameEntity.getApk().size() != 0) {
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
pluginNameMap.put(apkEntity.getPackageName(),
|
||||
gameEntity.getName() + " - " + apkEntity.getPlatform());
|
||||
list = locationMap.get(apkEntity.getPackageName());
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
locationMap.put(apkEntity.getPackageName(), list);
|
||||
}
|
||||
list.add(position + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -356,8 +366,7 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
if (!subjectList.isEmpty()) {
|
||||
int offset;
|
||||
GameEntity gameEntity;
|
||||
String name;
|
||||
ArrayList<Integer> locationList;
|
||||
ArrayList<Integer> list;
|
||||
for (int position = 0; position < count; position++) {
|
||||
offset = 1;
|
||||
if (!pluginList.isEmpty()) {
|
||||
@ -367,15 +376,13 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
gameEntity = subjectList.get(i).getData().get(position - offset - 1);
|
||||
if (gameEntity.getApk() != null && !gameEntity.getApk().isEmpty()) {
|
||||
name = gameEntity.getName();
|
||||
locationList = locationMap.get(name);
|
||||
if (locationList == null) {
|
||||
locationList = new ArrayList<>();
|
||||
locationMap.put(name, locationList);
|
||||
}
|
||||
locationList.add(position);
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
nameMap.put(apkEntity.getPackageName(), name);
|
||||
list = locationMap.get(apkEntity.getPackageName());
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
locationMap.put(apkEntity.getPackageName(), list);
|
||||
}
|
||||
list.add(position);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -386,8 +393,7 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
public void initItemCount() {
|
||||
int pluginSize = 0;
|
||||
if (!pluginList.isEmpty()) {
|
||||
pluginSize += 1 + pluginList.size();
|
||||
@ -400,22 +406,27 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
subjectSize += 1 + subjectEntity.getData().size();
|
||||
}
|
||||
}
|
||||
return 1 + pluginSize + subjectSize + 1;
|
||||
itemCount = pluginSize + subjectSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 1 + itemCount + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
|
||||
if (position == 0) {
|
||||
return ITEM_TYPE.slide;
|
||||
return ItemViewType.GAME_SLIDE;
|
||||
}
|
||||
|
||||
if (!pluginList.isEmpty()) {
|
||||
if (position == 1) {
|
||||
return ITEM_TYPE.head;
|
||||
return ItemViewType.COLUMN_HEADER;
|
||||
}
|
||||
if (position > 1 && position <= 1 + pluginList.size()) {
|
||||
return ITEM_TYPE.game_normal_type;
|
||||
return ItemViewType.GAME_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -432,29 +443,29 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
}
|
||||
gameEntity = subjectList.get(i).getData().get(index);
|
||||
if (position == offset && !TextUtils.isEmpty(gameEntity.getImage())){
|
||||
return ITEM_TYPE.image;
|
||||
return ItemViewType.GAME_IMAGE;
|
||||
}else if (position == offset){
|
||||
return ITEM_TYPE.head;
|
||||
return ItemViewType.COLUMN_HEADER;
|
||||
}
|
||||
if (position == offset+1&&!TextUtils.isEmpty(subjectList.get(i).getData().get(0).getImage())){
|
||||
return ITEM_TYPE.head;
|
||||
return ItemViewType.COLUMN_HEADER;
|
||||
}
|
||||
if (!TextUtils.isEmpty(gameEntity.getImage())) {
|
||||
return ITEM_TYPE.image;
|
||||
return ItemViewType.GAME_IMAGE;
|
||||
}
|
||||
if (gameEntity.getTest() != null) {
|
||||
return ITEM_TYPE.game_test_type;
|
||||
return ItemViewType.GAME_TEST;
|
||||
}
|
||||
return ITEM_TYPE.game_normal_type;
|
||||
return ItemViewType.GAME_NORMAL;
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
return ITEM_TYPE.footer_view;
|
||||
return ItemViewType.LOADING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == ITEM_TYPE.slide) {
|
||||
if (viewType == ItemViewType.GAME_SLIDE) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.plugin1_autoscrollviewpager_viewholder, parent, false);
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
@ -463,19 +474,19 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
LinearLayout.LayoutParams.MATCH_PARENT, (int) (outMetrics.widthPixels / 16f * 7f));
|
||||
view.setLayoutParams(params);
|
||||
return new AutoScrollViewpagerViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.head) {
|
||||
} else if (viewType == ItemViewType.COLUMN_HEADER) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.home_game_head_item, parent, false);
|
||||
return new GameHeadViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.game_normal_type) {
|
||||
} else if (viewType == ItemViewType.GAME_NORMAL) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.game_normal_item, parent, false);
|
||||
return new GameNormalViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.game_test_type) {
|
||||
} else if (viewType == ItemViewType.GAME_TEST) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.game_test_item, parent, false);
|
||||
return new GameTestViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.image) {
|
||||
} else if (viewType == ItemViewType.GAME_IMAGE) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.home_game_image_item, parent, false);
|
||||
return new GameImageViewHolder(view);
|
||||
@ -587,7 +598,7 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
} else {
|
||||
holder.home2_game_order.setVisibility(View.GONE);
|
||||
}
|
||||
ImageUtils.getInstance(context).display(gameEntity.getIcon(), holder.gameThumb);
|
||||
holder.gameThumb.setImageURI(gameEntity.getImage());
|
||||
holder.gameNameAndSize.setText(gameEntity.getName());
|
||||
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(gameEntity.getBrief());
|
||||
@ -715,7 +726,7 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
} else {
|
||||
holder.home1_game_order.setVisibility(View.GONE);
|
||||
}
|
||||
ImageUtils.getInstance(context).display(gameEntity.getIcon(), holder.gameThumb);
|
||||
holder.gameThumb.setImageURI(gameEntity.getIcon());
|
||||
if (gameEntity.isPluggable()) {
|
||||
holder.gameNameAndSize.setText(String.format("%s - %s", gameEntity.getName(),
|
||||
PlatformUtils.getInstance(context).getPlatformName(
|
||||
@ -787,7 +798,7 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
final String name = subjectList.get(i).getName();
|
||||
String tag = entity.getImage();
|
||||
holder.image.setTag(tag);
|
||||
ImageUtils.getInstance(context).display(entity.getImage(), holder.image, R.drawable.preload, context, 16);//默认应该设置占位符,防止图片混乱
|
||||
ImageUtils.getInstance(context).display(entity.getImage(), holder.image, context, 16);
|
||||
holder.image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -862,7 +873,8 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
index = 0;
|
||||
}
|
||||
gameEntity = subjectList.get(i).getData().get(index);
|
||||
if (position == offset && TextUtils.isEmpty(gameEntity.getImage()) || position == offset+1&&!TextUtils.isEmpty(subjectList.get(i).getData().get(0).getImage())) {
|
||||
if (position == offset && TextUtils.isEmpty(gameEntity.getImage()) || position == offset + 1
|
||||
&& !TextUtils.isEmpty(subjectList.get(i).getData().get(0).getImage())) {
|
||||
if (TextUtils.isEmpty(subjectList.get(i).getData().get(0).getImage())
|
||||
&& pluginList.isEmpty() && i == 0) {
|
||||
((CardLinearLayout) holder.itemView).setmTop(DisplayUtils.dip2px(context, 8));
|
||||
@ -921,8 +933,7 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
for (int i = 0, size = viewpager_ll_hint
|
||||
.getChildCount(); i < size; i++) {
|
||||
for (int i = 0, size = viewpager_ll_hint.getChildCount(); i < size; i++) {
|
||||
if (i == position % size) {
|
||||
((ImageView) viewpager_ll_hint.getChildAt(i))
|
||||
.setImageResource(R.drawable.oval_hint_up);
|
||||
|
||||
@ -6,7 +6,6 @@ import android.support.annotation.Nullable;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
@ -29,7 +28,6 @@ import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/6/28.
|
||||
@ -52,12 +50,13 @@ public class Game2Fragment extends BaseFragment implements SwipeRefreshLayout.On
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
if (!fm_game_swipe_refresh.isRefreshing()) {
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(downloadEntity.getName());
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(downloadEntity.getPackageName());
|
||||
if (locationList != null && locationList.size() != 0) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
GameEntity detailedEntity = getEntityByLocation(location);
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(getActivity(), detailedEntity,
|
||||
gameEntity = adapter.getGameEntityByLocation(location);
|
||||
if (gameEntity != null) {
|
||||
DownloadItemUtils.processDate(getActivity(), gameEntity,
|
||||
downloadEntity, adapter, location);
|
||||
}
|
||||
}
|
||||
@ -122,16 +121,13 @@ public class Game2Fragment extends BaseFragment implements SwipeRefreshLayout.On
|
||||
if ("delete".equals(status.getStatus())) {
|
||||
DownloadManager.getInstance(getActivity()).removePlatform(status.getName(), status.getPlatform());
|
||||
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(status.getName());
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(status.getPackageName());
|
||||
if (locationList != null && locationList.size() != 0) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
GameEntity gameEntity = getEntityByLocation(location);
|
||||
gameEntity = adapter.getGameEntityByLocation(location);
|
||||
if (gameEntity != null && gameEntity.getEntryMap() != null) {
|
||||
if (TextUtils.isEmpty(status.getPlatform())) {
|
||||
gameEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
gameEntity.getEntryMap().remove(status.getPlatform());
|
||||
}
|
||||
gameEntity.getEntryMap().remove(status.getPlatform());
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
@ -148,22 +144,20 @@ public class Game2Fragment extends BaseFragment implements SwipeRefreshLayout.On
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = adapter.getNameMap().get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(name);
|
||||
if (locationList != null && locationList.size() != 0) {
|
||||
for (int location : locationList) {
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(busFour.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
gameEntity = adapter.getGameEntityByLocation(location);
|
||||
if (gameEntity != null) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity detailedEntity = getEntityByLocation(location);
|
||||
if (detailedEntity != null) {
|
||||
for (ApkEntity apkEntity : detailedEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
detailedEntity.getEntryMap().remove(
|
||||
apkEntity.getPlatform());
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(busFour.getPackageName())) {
|
||||
if (gameEntity.getEntryMap() != null) {
|
||||
gameEntity.getEntryMap().remove(apkEntity.getPlatform());
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
@ -198,17 +192,7 @@ public class Game2Fragment extends BaseFragment implements SwipeRefreshLayout.On
|
||||
}
|
||||
}
|
||||
|
||||
private GameEntity getEntityByLocation(int position) {
|
||||
List<SubjectEntity> list = adapter.getSubectList();
|
||||
int offset = 0;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (position > offset && position <= list.get(i).getData().size() + offset) {
|
||||
return list.get(i).getData().get(position - offset - 1);
|
||||
}
|
||||
offset = list.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
@ -15,6 +15,7 @@ import com.android.volley.TimeoutError;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.ItemViewType;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
@ -56,21 +57,12 @@ import java.util.Map;
|
||||
*/
|
||||
public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private class ITEM_TYPE {
|
||||
public final static int HEAD = 100;// 专题头部
|
||||
public final static int GAME_NORMAL = 101;// 游戏布局1
|
||||
public final static int GAME_TEST = 102;// 游戏布局2
|
||||
public final static int IMAGE = 103;// 大图布局
|
||||
public final static int FOOTER = 104;// 加载布局
|
||||
}
|
||||
|
||||
private Game2Fragment fragment;
|
||||
private Context context;
|
||||
private OnCallBackListener listener;
|
||||
|
||||
private ArrayMap<String, ArrayList<Integer>> locationMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private List<SubjectEntity> subjectList;
|
||||
private ArrayMap<String, ArrayList<Integer>> locationMap;
|
||||
|
||||
public Game2FragmentAdapter(Game2Fragment fragment, boolean isLoad) {
|
||||
|
||||
@ -81,7 +73,6 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
subjectList = new ArrayList<>();
|
||||
|
||||
locationMap = new ArrayMap<>();
|
||||
nameMap = new ArrayMap<>();
|
||||
|
||||
if (isLoad) {
|
||||
initSubjectList();
|
||||
@ -92,17 +83,12 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
return locationMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getNameMap() {
|
||||
return nameMap;
|
||||
}
|
||||
|
||||
public void initSubjectList() {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "v1d50/game/tuijian",
|
||||
Config.HOST + "game/tuijian",
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
|
||||
Type listType = new TypeToken<ArrayList<SubjectEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<SubjectEntity> list = gson.fromJson(response.toString(), listType);
|
||||
@ -115,6 +101,7 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
if (subjectEntity.getData().size() == 1
|
||||
&& !TextUtils.isEmpty(subjectEntity.getData().get(0).getImage())){
|
||||
list.remove(j);
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < subjectEntity.getData().size(); i++) {
|
||||
@ -164,29 +151,25 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
|
||||
private void initLocationMap() {
|
||||
locationMap.clear();
|
||||
nameMap.clear();
|
||||
|
||||
if (!subjectList.isEmpty()) {
|
||||
int count = getItemCount() - 1;
|
||||
GameEntity gameEntity;
|
||||
int offset;
|
||||
String name;
|
||||
ArrayList<Integer> locationList;
|
||||
ArrayList<Integer> list;
|
||||
GameEntity gameEntity;
|
||||
for (int position = 0; position < count; position++) {
|
||||
offset = 0;
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
gameEntity = subjectList.get(i).getData().get(position - offset - 1);
|
||||
if (gameEntity.getApk() != null && !gameEntity.getApk().isEmpty()) {
|
||||
name = gameEntity.getName();
|
||||
locationList = locationMap.get(name);
|
||||
if (locationList == null) {
|
||||
locationList = new ArrayList<>();
|
||||
locationMap.put(name, locationList);
|
||||
}
|
||||
locationList.add(position);
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
nameMap.put(apkEntity.getPackageName(), name);
|
||||
list = locationMap.get(apkEntity.getPackageName());
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
locationMap.put(apkEntity.getPackageName(), list);
|
||||
}
|
||||
list.add(position);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -197,6 +180,17 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
}
|
||||
}
|
||||
|
||||
public GameEntity getGameEntityByLocation(int position) {
|
||||
int offset = 0;
|
||||
for (int i = 0; i < subjectList.size(); i++) {
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
return subjectList.get(i).getData().get(position - offset - 1);
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int subjectSize = 0;
|
||||
@ -217,53 +211,54 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
GameEntity gameEntity;
|
||||
for (int i = 0; i < subjectList.size(); i++) {
|
||||
if (position >= offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
int index = position -offset-1;
|
||||
int index = position - offset - 1;
|
||||
if (index < 0) {
|
||||
index = 0;
|
||||
}
|
||||
gameEntity = subjectList.get(i).getData().get(index);
|
||||
if (position == offset && !TextUtils.isEmpty(gameEntity.getImage())){
|
||||
return ITEM_TYPE.IMAGE;
|
||||
}else if (position == offset){
|
||||
return ITEM_TYPE.HEAD;
|
||||
if (position == offset && !TextUtils.isEmpty(gameEntity.getImage())) {
|
||||
return ItemViewType.GAME_IMAGE;
|
||||
} else if (position == offset) {
|
||||
return ItemViewType.COLUMN_HEADER;
|
||||
}
|
||||
if (position == offset+1 && !TextUtils.isEmpty(subjectList.get(i).getData().get(0).getImage())) {
|
||||
return ITEM_TYPE.HEAD;
|
||||
if (position == offset + 1 && !TextUtils.isEmpty(subjectList.get(i).getData().get(0).getImage())) {
|
||||
return ItemViewType.COLUMN_HEADER;
|
||||
}
|
||||
if (gameEntity.getTest() != null) {
|
||||
return ITEM_TYPE.GAME_TEST;
|
||||
return ItemViewType.GAME_TEST;
|
||||
}
|
||||
return ITEM_TYPE.GAME_NORMAL;
|
||||
return ItemViewType.GAME_NORMAL;
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
}
|
||||
return ITEM_TYPE.FOOTER;
|
||||
return ItemViewType.LOADING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == ITEM_TYPE.HEAD) {
|
||||
if (viewType == ItemViewType.COLUMN_HEADER) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.home_game_head_item, parent, false);
|
||||
return new GameHeadViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.IMAGE) {
|
||||
} else if (viewType == ItemViewType.GAME_IMAGE) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.home_game_image_item, parent, false);
|
||||
return new GameImageViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.GAME_TEST) {
|
||||
} else if (viewType == ItemViewType.GAME_TEST) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.game_test_item, parent, false);
|
||||
return new GameTestViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.GAME_NORMAL) {
|
||||
} else if (viewType == ItemViewType.GAME_NORMAL) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.game_normal_item, parent, false);
|
||||
return new GameNormalViewHolder(view);
|
||||
} else {
|
||||
} else if (viewType == ItemViewType.LOADING) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.refresh_footerview, parent, false);
|
||||
return new FooterViewHolder(view);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -340,7 +335,7 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
GameEntity gameEntity;
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
int index = position -offset-1;
|
||||
int index = position - offset - 1;
|
||||
if (index<0){
|
||||
index = 0;
|
||||
}
|
||||
@ -381,7 +376,7 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
} else {
|
||||
holder.home1_game_order.setVisibility(View.GONE);
|
||||
}
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(), holder.gameThumb);
|
||||
holder.gameThumb.setImageURI(entity.getIcon());
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
@ -468,7 +463,7 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
} else {
|
||||
holder.home2_game_order.setVisibility(View.GONE);
|
||||
}
|
||||
ImageUtils.getInstance(context).display(gameEntity.getIcon(), holder.gameThumb);
|
||||
holder.gameThumb.setImageURI(gameEntity.getIcon());
|
||||
holder.gameNameAndSize.setText(gameEntity.getName());
|
||||
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(gameEntity.getBrief());
|
||||
@ -550,7 +545,8 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
}
|
||||
final GameEntity entity = gameEntity;
|
||||
final String name = subjectList.get(i).getName();
|
||||
ImageUtils.getInstance(context).display(entity.getImage(), holder.image, R.drawable.preload, context, 16);//默认应该设置占位符,防止图片混乱
|
||||
ImageUtils.getInstance(context).display(entity.getImage(), holder.image, context, 16);
|
||||
holder.image.setImageURI(entity.getImage());
|
||||
holder.image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
@ -7,7 +7,6 @@ import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
@ -27,6 +26,8 @@ import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
@ -55,12 +56,15 @@ public class Game3Fragment extends BaseFragment implements OnRefreshListener {
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
if (!fm_game_swipe_refresh.isRefreshing()) {
|
||||
Integer location = adapter.getLocationMap().get(downloadEntity.getName());
|
||||
if (location != null) {
|
||||
GameEntity detailedEntity = adapter.getList().get(location);
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(getActivity(), detailedEntity,
|
||||
downloadEntity, adapter, location);
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(downloadEntity.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
gameEntity = adapter.getGameList().get(location);
|
||||
if (gameEntity != null) {
|
||||
DownloadItemUtils.processDate(getActivity(), gameEntity,
|
||||
downloadEntity, adapter, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,9 +105,9 @@ public class Game3Fragment extends BaseFragment implements OnRefreshListener {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& layoutManager.findLastVisibleItemPosition() == adapter
|
||||
.getList().size()) {
|
||||
.getGameList().size()) {
|
||||
if (!adapter.isRemove() && !adapter.isLoading()) {
|
||||
adapter.addList(adapter.getList().size());
|
||||
adapter.addList(adapter.getGameList().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -138,17 +142,16 @@ public class Game3Fragment extends BaseFragment implements OnRefreshListener {
|
||||
if ("delete".equals(status.getStatus())) {
|
||||
DownloadManager.getInstance(getActivity()).removePlatform(status.getName(), status.getPlatform());
|
||||
|
||||
Integer location = adapter.getLocationMap().get(status.getName());
|
||||
if (location != null) {
|
||||
GameEntity gameEntity = adapter.getList().get(location);
|
||||
if (gameEntity != null && gameEntity.getEntryMap() != null) {
|
||||
if (TextUtils.isEmpty(status.getPlatform())) {
|
||||
gameEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(status.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
gameEntity = adapter.getGameList().get(location);
|
||||
if (gameEntity != null && gameEntity.getEntryMap() != null) {
|
||||
gameEntity.getEntryMap().remove(status.getPlatform());
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -162,20 +165,26 @@ public class Game3Fragment extends BaseFragment implements OnRefreshListener {
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = adapter.getNameMap().get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
int location = adapter.getLocationMap().get(name);
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity detailedEntity = adapter.getList().get(location);
|
||||
for (ApkEntity apkEntity : detailedEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(busFour.getPackageName())) {
|
||||
detailedEntity.getEntryMap().remove(apkEntity.getPlatform());
|
||||
ArrayList<Integer> locationList = adapter.getLocationMap().get(busFour.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
gameEntity = adapter.getGameList().get(location);
|
||||
if (gameEntity != null) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(busFour.getPackageName())) {
|
||||
if (gameEntity.getEntryMap() != null) {
|
||||
gameEntity.getEntryMap().remove(apkEntity.getPlatform());
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -192,7 +201,7 @@ public class Game3Fragment extends BaseFragment implements OnRefreshListener {
|
||||
} else if (adapter.isNetworkError()) {
|
||||
adapter.setNetworkError(false);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1);
|
||||
adapter.addList(adapter.getList().size());
|
||||
adapter.addList(adapter.getGameList().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -215,7 +224,7 @@ public class Game3Fragment extends BaseFragment implements OnRefreshListener {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
for (GameEntity entity : adapter.getList()) {
|
||||
for (GameEntity entity : adapter.getGameList()) {
|
||||
entity.setEntryMap(DownloadManager.getInstance(getActivity()).getEntryMap(entity.getName()));
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user