Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 39fecb09a7 | |||
| 42cbb4f6ec | |||
| 335dac3481 | |||
| 24014feef0 | |||
| f74ae2a8cf | |||
| 8eca878a8b | |||
| 33ce47b438 | |||
| d2702c9d4a | |||
| cbc7a144a4 | |||
| a9f078865e | |||
| 18330df2f0 | |||
| b0e401bbbd | |||
| 1b03e434a7 | |||
| 87c5c5a0d8 | |||
| b915ea01be | |||
| f0f12cf8ff | |||
| 303f5b8f58 | |||
| bff4d80c27 | |||
| 7cbdf69188 | |||
| 58c6a9a5d5 | |||
| e0c08e94f3 | |||
| 15ad3e7d39 | |||
| 4ce8d1ea95 | |||
| 37af534904 | |||
| 8de6a6a789 | |||
| e033e20dbf | |||
| 42d0d9c60b | |||
| 5559a47f80 | |||
| c37c50d0c1 | |||
| 5b5341f9e1 | |||
| 848b4e44d5 | |||
| fa6cc8dfaf | |||
| 3c83b4ad5c | |||
| 6c3e042edc | |||
| 4feff1600e | |||
| e7f510941f |
3
.gitignore
vendored
@ -1,7 +1,8 @@
|
||||
/.idea
|
||||
.idea/misc.xml
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
/captures
|
||||
@ -38,8 +38,8 @@ android {
|
||||
applicationId "com.gh.gamecenter"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 19
|
||||
versionCode 13
|
||||
versionName "1.50"
|
||||
versionCode 14
|
||||
versionName "1.51"
|
||||
|
||||
// 默认的渠道
|
||||
// manifestPlaceholders = [CHANNEL_VALUE: "GH_TEST"]
|
||||
@ -82,6 +82,7 @@ android {
|
||||
GH_102 {}
|
||||
GH_103 {}
|
||||
GH_104 {}
|
||||
GH_106 {}
|
||||
GH_109 {}
|
||||
GH_110 {}
|
||||
GH_113 {}
|
||||
@ -108,7 +109,5 @@ android {
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testCompile 'junit:junit:4.12'
|
||||
// compile ('com.facebook.fresco:fresco:0.9.0') {
|
||||
// exclude module: 'support-v4'
|
||||
// }
|
||||
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.16'
|
||||
}
|
||||
BIN
app/libs/alicloud-android-sdk-httpdns-1.0.6.jar
Normal file
BIN
app/libs/utdid4all-1.0.4.jar
Normal file
@ -38,6 +38,8 @@
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<!-- 小米推送需要的权限 -->
|
||||
<uses-permission android:name="com.gh.gamecenter.permission.MIPUSH_RECEIVE" />
|
||||
<!-- 获取网路状态 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
|
||||
<permission
|
||||
android:name="com.gh.gamecenter.permission.MIPUSH_RECEIVE"
|
||||
@ -144,6 +146,9 @@
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.SubjectActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.PluginActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
|
||||
<receiver android:name="com.gh.gamecenter.receiver.InstallAndUninstallReceiver" >
|
||||
<intent-filter>
|
||||
|
||||
@ -208,6 +208,16 @@ public class BaseActivity extends Activity {
|
||||
startActivity(PackageUtils.getUninstallIntent(BaseActivity.this, showDialog.getPath()));
|
||||
}
|
||||
});
|
||||
} else if ("plugin".equals(showDialog.getType())) {
|
||||
DialogUtils.showPluginDialog(this, new DialogUtils.ConfiremListener(){
|
||||
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
MainActivity.uninstallMap.put(
|
||||
PackageUtils.getPackageNameByPath(BaseActivity.this, showDialog.getPath()), showDialog.getPath());
|
||||
startActivity(PackageUtils.getUninstallIntent(BaseActivity.this, showDialog.getPath()));
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,6 +201,16 @@ public class BaseFragmentActivity extends FragmentActivity {
|
||||
startActivity(PackageUtils.getUninstallIntent(BaseFragmentActivity.this, showDialog.getPath()));
|
||||
}
|
||||
});
|
||||
} else if ("plugin".equals(showDialog.getType())) {
|
||||
DialogUtils.showPluginDialog(this, new DialogUtils.ConfiremListener(){
|
||||
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
MainActivity.uninstallMap.put(
|
||||
PackageUtils.getPackageNameByPath(BaseFragmentActivity.this, showDialog.getPath()), showDialog.getPath());
|
||||
startActivity(PackageUtils.getUninstallIntent(BaseFragmentActivity.this, showDialog.getPath()));
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,14 +21,14 @@ public class DataUtils {
|
||||
public static void init(Application application) {
|
||||
//TalkingData
|
||||
//dubug true release false
|
||||
TCAgent.LOG_ON = true;
|
||||
TCAgent.LOG_ON = false;
|
||||
TCAgent.init(application);
|
||||
TCAgent.setReportUncaughtExceptions(true);
|
||||
|
||||
//MTA
|
||||
// 打开debug开关,可查看mta上报日志或错误
|
||||
// dubug true release false
|
||||
StatConfig.setDebugEnable(true);
|
||||
StatConfig.setDebugEnable(false);
|
||||
// 收集未处理的异常
|
||||
StatConfig.setAutoExceptionCaught(true);
|
||||
// 设置数据上报策略
|
||||
@ -55,7 +55,7 @@ public class DataUtils {
|
||||
for (String key : var3.keySet()) {
|
||||
prop.setProperty(key, var3.get(key) + "");
|
||||
}
|
||||
StatService.trackCustomBeginKVEvent(var0, var1, prop);
|
||||
StatService.trackCustomKVEvent(var0, var1, prop);
|
||||
}
|
||||
|
||||
public static void onPause(Activity var0) {
|
||||
|
||||
@ -4,6 +4,8 @@ import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
@ -162,8 +164,139 @@ public class DialogUtils {
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public static void showSuccessDialog(Context context) {
|
||||
final Dialog dialog = new Dialog(context);
|
||||
View view = View.inflate(context, R.layout.gamedetails_attention_dialog, null);
|
||||
TextView title = (TextView) view.findViewById(R.id.dialog_title);
|
||||
title.setText("关注成功");
|
||||
TextView confirm = (TextView) view.findViewById(R.id.dialog_confirm);
|
||||
confirm.setText("我知道了");
|
||||
confirm.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
TextView message = (TextView) view.findViewById(R.id.dialog_message);
|
||||
message.setText("游戏的最新动态消息会优先提醒您,包括攻略、资讯、开服信息、开测信息以及最新的插件。");
|
||||
view.findViewById(R.id.dialog_rl_cancel).setVisibility(View.GONE);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public static void showCancelDialog(Context context, final ConfiremListener listener) {
|
||||
final Dialog dialog = new Dialog(context);
|
||||
View view = View.inflate(context, R.layout.gamedetails_attention_dialog, null);
|
||||
TextView title = (TextView) view.findViewById(R.id.dialog_title);
|
||||
title.setText("取消关注");
|
||||
TextView cancel = (TextView) view.findViewById(R.id.dialog_cancel);
|
||||
cancel.setText("取消");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
TextView message = (TextView) view.findViewById(R.id.dialog_message);
|
||||
|
||||
Spanned content = Html
|
||||
.fromHtml("取消关注游戏后,您将无法及时收到游戏的<font color='#ff0000'>攻略</font>、<font color='#ff0000'>资讯</font>等最新动态提醒,您确定取消吗?");
|
||||
message.setText(content);
|
||||
|
||||
view.findViewById(R.id.dialog_rl_confirm).setVisibility(View.VISIBLE);
|
||||
view.findViewById(R.id.dialog_confirm).setOnClickListener(
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
if (listener != null) {
|
||||
listener.onConfirem();
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public static void showPluginDialog(Context context, final ConfiremListener cListener,
|
||||
final DismissListener dListener) {
|
||||
final Dialog dialog = new Dialog(context);
|
||||
View view = View.inflate(context, R.layout.search_history_delete_dialog, null);
|
||||
TextView title = (TextView) view.findViewById(R.id.delete_dialog_title);
|
||||
title.setText("插件化安装");
|
||||
TextView content = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_message);
|
||||
Spanned spanned = Html.fromHtml("您将进行插件化安装以实现插件功能,此过程将"
|
||||
+ "<font color=\"#ff0000\">卸载</font>" + "当前使用的版本并"
|
||||
+ "<font color=\"#ff0000\">安装插件版本</font>" + "。");
|
||||
content.setText(spanned);
|
||||
|
||||
TextView cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_cancel);
|
||||
cancel.setText("取消");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
TextView confirm = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirm.setText("确定");
|
||||
confirm.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
if (cListener != null) {
|
||||
cListener.onConfirem();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (dListener != null) {
|
||||
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
dListener.onDismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public static void showDisclaimerDialog(Context context, String content) {
|
||||
final Dialog disclaimerDialog = new Dialog(context);
|
||||
View view = View.inflate(context, R.layout.setting_disclaimer_dialog, null);
|
||||
TextView title = (TextView) view
|
||||
.findViewById(R.id.disclaimer_dialog_title);
|
||||
title.setText("免责声明");
|
||||
TextView message = (TextView) view
|
||||
.findViewById(R.id.disclaimer_dialog_message);
|
||||
Spanned spanned = Html.fromHtml(content);
|
||||
message.setText(spanned);
|
||||
view.findViewById(R.id.disclaimer_dialog_confirm).setOnClickListener(
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
disclaimerDialog.dismiss();
|
||||
}
|
||||
});
|
||||
disclaimerDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
disclaimerDialog.setContentView(view);
|
||||
disclaimerDialog.show();
|
||||
}
|
||||
|
||||
public interface ConfiremListener{
|
||||
void onConfirem();
|
||||
}
|
||||
|
||||
public interface DismissListener{
|
||||
void onDismiss();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -40,11 +40,9 @@ public class DownloadItemUtils {
|
||||
public static void initializeGameMap(Context context,
|
||||
ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap) {
|
||||
gameMap.clear();
|
||||
List<DownloadEntry> list = DownloadManager.getInstance(context)
|
||||
.getAll();
|
||||
List<DownloadEntry> list = DownloadManager.getInstance(context).getAll();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
ArrayMap<String, DownloadEntry> map = gameMap.get(list.get(i)
|
||||
.getName());
|
||||
ArrayMap<String, DownloadEntry> map = gameMap.get(list.get(i).getName());
|
||||
if (map == null) {
|
||||
map = new ArrayMap<String, DownloadEntry>();
|
||||
}
|
||||
@ -147,7 +145,12 @@ public class DownloadItemUtils {
|
||||
downloadEntry = entryMap.get(entryMap.keyAt(0));
|
||||
}
|
||||
|
||||
if (downloadEntry != null) {
|
||||
String pluginPlatform = entity.getPluginPlatform();
|
||||
|
||||
if (downloadEntry != null && (pluginPlatform == null
|
||||
|| pluginPlatform.equals(PlatformUtils.getInstance(context)
|
||||
.getPlatformName(downloadEntry.getMeta().get("platform"))))) {
|
||||
|
||||
labelList.setVisibility(View.GONE);
|
||||
game_progressbar.setVisibility(View.VISIBLE);
|
||||
game_ll_info.setVisibility(View.VISIBLE);
|
||||
@ -304,6 +307,19 @@ public class DownloadItemUtils {
|
||||
}
|
||||
game_progressbar.setProgress((int) (downloadEntry
|
||||
.getPercent() * 10));
|
||||
} else {
|
||||
labelList.setVisibility(View.VISIBLE);
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
if (entity.getApk() != null) {
|
||||
if (entity.getPluginPlatform() != null) {
|
||||
downloadBtn.setText("插件化");
|
||||
} else {
|
||||
downloadBtn.setText("下载");
|
||||
}
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setTextColor(0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
labelList.setVisibility(View.VISIBLE);
|
||||
@ -524,7 +540,6 @@ public class DownloadItemUtils {
|
||||
map.put("platform", PlatformUtils.getInstance(context)
|
||||
.getPlatformName(entity.getApk().get(0).getPlatform()));
|
||||
map.put("status", "开始");
|
||||
map.put("isPlugin", "true");
|
||||
map.put("location", "游戏详情:" + entity.getName());
|
||||
map.put("from", entrance);
|
||||
map.put("network", NetworkUtils.getConnectedType(context));
|
||||
@ -698,14 +713,14 @@ public class DownloadItemUtils {
|
||||
context.startActivity(PackageUtils
|
||||
.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showUninstallDialog(context, new DialogUtils.ConfiremListener() {
|
||||
DialogUtils.showPluginDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
MainActivity.uninstallMap.put(
|
||||
PackageUtils.getPackageNameByPath(context, path), path);
|
||||
context.startActivity(PackageUtils.getUninstallIntent(context, path));
|
||||
}
|
||||
});
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -729,7 +744,8 @@ public class DownloadItemUtils {
|
||||
meta.put("entrance", entrance);
|
||||
meta.put("location", "游戏详情:" + game.getName());
|
||||
if (game.getPluginPlatform() != null) {
|
||||
meta.put("PluginPlatform", PlatformUtils.getInstance(context).getPlatformName(game.getApk().get(0).getPlatform()));
|
||||
meta.put("PluginPlatform", game.getPluginPlatform());
|
||||
meta.put("isPlugin", "true");
|
||||
}
|
||||
entry.setMeta(meta);
|
||||
return entry;
|
||||
|
||||
35
app/src/main/java/com/gh/common/util/HttpdnsUtils.java
Normal file
@ -0,0 +1,35 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.alibaba.sdk.android.httpdns.HttpDns;
|
||||
import com.alibaba.sdk.android.httpdns.HttpDnsService;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/7/11.
|
||||
*/
|
||||
public class HttpdnsUtils {
|
||||
private static HttpDnsService httpdns;
|
||||
private static String accountID = "180813";
|
||||
|
||||
public static String getUrls(Context context,String url){
|
||||
httpdns = HttpDns.getService(context,accountID);
|
||||
try {
|
||||
URL oldUrl = new URL(url);
|
||||
HttpURLConnection connection = (HttpURLConnection) oldUrl.openConnection();
|
||||
String ip = httpdns.getIpByHost(oldUrl.getHost());
|
||||
if (ip!= null){
|
||||
String newUrl = url.replaceFirst(oldUrl.getHost(), ip);
|
||||
return newUrl;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,7 +2,10 @@ 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.view.ViewGroup;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
@ -13,15 +16,18 @@ 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 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);
|
||||
|
||||
@ -39,18 +45,21 @@ public class ImageUtils {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
private ImageUtils(Context context, int size) {
|
||||
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)
|
||||
.build();
|
||||
|
||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
|
||||
context).writeDebugLogs().build();
|
||||
context).writeDebugLogs()
|
||||
.memoryCacheExtraOptions(480, 800)
|
||||
.build();
|
||||
|
||||
ImageLoader.getInstance().init(config);
|
||||
imageLoader = ImageLoader.getInstance();
|
||||
@ -86,7 +95,10 @@ public class ImageUtils {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
//增加一个上下文环境,图片宽度设最大,高度自适应
|
||||
public void display(String url, ImageView imageView, int drawable,Context context) {
|
||||
display(url, imageView, drawable, ScaleType.FIT_XY, null,context);
|
||||
}
|
||||
public void display(String url, ImageView imageView, int drawable) {
|
||||
display(url, imageView, drawable, ScaleType.FIT_XY, null);
|
||||
}
|
||||
@ -130,17 +142,131 @@ public class ImageUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, ScaleType scaleType) {
|
||||
display(url, imageView, R.drawable.ocupy, scaleType, null);
|
||||
public void display(final String url, final ImageView imageView,
|
||||
final int drawable, final ScaleType scaleType,
|
||||
final OnLoadingCompleteListener listener,final Context context) {
|
||||
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;
|
||||
float index = (float) height/(float) width;
|
||||
int newHeight = (int)(index*widthPixels);
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
|
||||
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) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView) {
|
||||
display(url, imageView, R.drawable.ocupy, ScaleType.FIT_XY, null);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, ScaleType scaleType, OnLoadingCompleteListener listener) {
|
||||
display(url, imageView, R.drawable.ocupy, scaleType, listener);
|
||||
}
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
@ -3,10 +3,17 @@ package com.gh.common.util;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.gamecenter.NewsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.NewsDetailsEntity;
|
||||
import com.gh.gamecenter.entity.NewsEntity;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class NewsUtils {
|
||||
|
||||
@ -50,4 +57,27 @@ public class NewsUtils {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计阅读量
|
||||
* @param news_id
|
||||
*/
|
||||
public static void statNewsViews(String news_id) {
|
||||
String url = "http://data.ghzhushou.com/news/stat?news_id=" + news_id;
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Request.Method.POST, url,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
|
||||
}
|
||||
});
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request, NewsUtils.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ import java.lang.reflect.Field;
|
||||
|
||||
public class Utils {
|
||||
|
||||
private static final boolean DEBUG = true;
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
public static void log(String msg) {
|
||||
if (DEBUG) {
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
@ -16,8 +15,6 @@ import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.util.SparseArray;
|
||||
import android.view.Gravity;
|
||||
@ -26,7 +23,6 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
@ -177,7 +173,7 @@ public class DownloadDialog {
|
||||
|
||||
gameName = game.getName();
|
||||
gameIcon = game.getIcon();
|
||||
gameId = game.getIcon();
|
||||
gameId = game.getId();
|
||||
if (game.getTag() == null || game.getTag().isEmpty()) {
|
||||
gameType = "normal";
|
||||
} else {
|
||||
@ -354,7 +350,7 @@ public class DownloadDialog {
|
||||
}
|
||||
|
||||
private ArrayList<ApkEntity> sortApk(String gameId, List<ApkEntity> apkList) {
|
||||
DownloadEntry downloadEntry = null;
|
||||
DownloadEntry downloadEntry;
|
||||
ArrayList<ApkEntity> list = new ArrayList<ApkEntity>();
|
||||
List<ApkEntity> installedList = new ArrayList<ApkEntity>();
|
||||
List<ApkEntity> doneList = new ArrayList<ApkEntity>();
|
||||
@ -513,35 +509,9 @@ public class DownloadDialog {
|
||||
// 显示插件化
|
||||
private void showPluginDialog(final ApkEntity apkEntity,
|
||||
final RecyclerViewAdapter adapter, final int location) {
|
||||
final Dialog dialog = new Dialog(context);
|
||||
View view = View.inflate(context,
|
||||
R.layout.search_history_delete_dialog, null);
|
||||
TextView title = (TextView) view.findViewById(R.id.delete_dialog_title);
|
||||
title.setText("插件化安装");
|
||||
TextView content = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_message);
|
||||
Spanned spanned = Html.fromHtml("您将进行插件化安装以实现插件功能,此过程将"
|
||||
+ "<font color=\"#ff0000\">卸载</font>" + "当前使用的版本并"
|
||||
+ "<font color=\"#ff0000\">安装插件版本</font>" + "。");
|
||||
content.setText(spanned);
|
||||
|
||||
TextView cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_cancel);
|
||||
cancel.setText("取消");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
DialogUtils.showPluginDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
TextView confirm = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirm.setText("确定");
|
||||
confirm.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
|
||||
public void onConfirem() {
|
||||
Map<String, Object> kv6 = new HashMap<String, Object>();
|
||||
kv6.put("操作", "点击插件化安装完成");
|
||||
DataUtils.onEvent(context, "插件化", gameName, kv6);
|
||||
@ -557,11 +527,7 @@ public class DownloadDialog {
|
||||
context.startActivity(PackageUtils.getUninstallIntent(context, path));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}, null);
|
||||
}
|
||||
|
||||
private class RecyclerViewAdapter extends
|
||||
@ -820,8 +786,7 @@ public class DownloadDialog {
|
||||
HashMap<String, String> meta = new HashMap<String, String>();
|
||||
meta.put("ETag", apkEntity.getEtag());
|
||||
meta.put("icon", gameIcon);
|
||||
meta.put(
|
||||
"platform", apkEntity.getPlatform());
|
||||
meta.put("platform", apkEntity.getPlatform());
|
||||
meta.put("gameId", gameId);
|
||||
meta.put("entrance", entrance);
|
||||
meta.put("location", mlocation);
|
||||
@ -882,7 +847,7 @@ public class DownloadDialog {
|
||||
context.startActivity(PackageUtils
|
||||
.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showUninstallDialog(context, new DialogUtils.ConfiremListener() {
|
||||
DialogUtils.showPluginDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
MainActivity.uninstallMap.put(
|
||||
@ -890,7 +855,7 @@ public class DownloadDialog {
|
||||
context.startActivity(PackageUtils.getUninstallIntent(context,
|
||||
path));
|
||||
}
|
||||
});
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
} else if ("等待".equals(status)) {
|
||||
@ -978,6 +943,10 @@ public class DownloadDialog {
|
||||
|| "pause".equals(statusMap.get(downloadEntry
|
||||
.getUrl()))) {
|
||||
viewHolder.download_item_tv_status.setText("继续");
|
||||
} else if (downloadEntry.getStatus().equals(
|
||||
DownloadStatus.timeout) || downloadEntry.getStatus().equals(
|
||||
DownloadStatus.neterror)) {
|
||||
viewHolder.download_item_tv_status.setText("继续");
|
||||
} else {
|
||||
viewHolder.download_item_tv_status.setText("插件下载中");
|
||||
}
|
||||
@ -988,6 +957,10 @@ public class DownloadDialog {
|
||||
} else if (downloadEntry.getStatus().equals(
|
||||
DownloadStatus.pause)) {
|
||||
viewHolder.download_item_tv_status.setText("继续");
|
||||
} else if (downloadEntry.getStatus().equals(
|
||||
DownloadStatus.timeout) || downloadEntry.getStatus().equals(
|
||||
DownloadStatus.neterror)) {
|
||||
viewHolder.download_item_tv_status.setText("继续");
|
||||
} else {
|
||||
viewHolder.download_item_tv_status.setText("更新中");
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ public class Gh_ViewPager extends ViewPager {
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||
|
||||
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
getChildAt(i).dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
@ -10,7 +10,8 @@ public interface DownloadListener {
|
||||
* 更新每一次下载的大小
|
||||
* @param downloadedSize
|
||||
*/
|
||||
void onProgressChanged(int downloadedSize);
|
||||
// void onProgressChanged(int downloadedSize);
|
||||
void onProgressChanged(long length, int downloadedSize);
|
||||
|
||||
/**
|
||||
* 更新任务下载状态
|
||||
|
||||
@ -75,8 +75,9 @@ public class DownloadTask implements DownloadListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onProgressChanged(int len) {
|
||||
currSize += len;
|
||||
// public synchronized void onProgressChanged(int len) {
|
||||
public synchronized void onProgressChanged(long length, int len) {
|
||||
currSize = length;
|
||||
double percent = 0;
|
||||
if (entry.getSize() != 0) {
|
||||
percent = currSize * 100.0 / entry.getSize();
|
||||
|
||||
@ -24,6 +24,7 @@ public class DownloadThread extends Thread {
|
||||
private DownloadListener listener;
|
||||
private DownloadStatus status;
|
||||
private Context context;
|
||||
// private boolean getNewurlSuccess = false;
|
||||
|
||||
public DownloadThread(Context context, DownloadEntry entry,
|
||||
DownloadListener listener) {
|
||||
@ -52,14 +53,33 @@ public class DownloadThread extends Thread {
|
||||
fileOutputStream = new FileOutputStream(entry.getPath());
|
||||
}
|
||||
|
||||
//Httpdns替换地址
|
||||
// String newUrl = HttpdnsUtils.getUrls(context, entry.getUrl());
|
||||
// if (newUrl == null) {
|
||||
// newUrl = entry.getUrl();
|
||||
// getNewurlSuccess = false;
|
||||
// Utils.log("HttpDnsService::获取新地址失败,用原地址进行下载,原地址为::"+newUrl);
|
||||
// } else {
|
||||
// getNewurlSuccess = true;
|
||||
// Utils.log("HttpDnsService::获取新地址成功,目标地址为::"+newUrl);
|
||||
// }
|
||||
|
||||
URL url = new URL(entry.getUrl());
|
||||
HttpURLConnection connection = (HttpURLConnection) url
|
||||
.openConnection();
|
||||
// HttpURLConnection connection = (HttpURLConnection) new URL(newUrl).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(CONNECT_TIME);
|
||||
connection.setReadTimeout(READ_TIME);
|
||||
connection.setRequestProperty("RANGE",
|
||||
"bytes=" + targetFile.length() + "-");
|
||||
|
||||
//获取新地址成功,设置HTTP请求头Host域
|
||||
// if (getNewurlSuccess && newUrl.endsWith(".apk") ){
|
||||
// //非.apk,结尾的下载地址不需要加请求头Host域
|
||||
// connection.setRequestProperty("Host", url.getHost());
|
||||
// }
|
||||
|
||||
//设置自动重定向
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
Trace.getInstance().debug(DownloadThread.class.getSimpleName(),
|
||||
@ -79,6 +99,10 @@ public class DownloadThread extends Thread {
|
||||
connection.setReadTimeout(READ_TIME);
|
||||
connection.setRequestProperty("RANGE",
|
||||
"bytes=" + targetFile.length() + "-");
|
||||
// if (getNewurlSuccess && newUrl.endsWith(".apk") ){
|
||||
// //非.apk,结尾的下载地址不需要加请求头Host域
|
||||
// connection.setRequestProperty("Host", url.getHost());
|
||||
// }
|
||||
//设置自动重定向
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
}
|
||||
@ -117,7 +141,8 @@ public class DownloadThread extends Thread {
|
||||
int len;
|
||||
while ((len = bis.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, len);
|
||||
listener.onProgressChanged(len);
|
||||
// listener.onProgressChanged(len);
|
||||
listener.onProgressChanged(targetFile.length(), len);
|
||||
if (status == DownloadStatus.pause
|
||||
|| status == DownloadStatus.cancel) {
|
||||
listener.onStatusChanged(status);
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@ -11,14 +9,11 @@ import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.view.Window;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
@ -42,14 +37,12 @@ import com.gh.common.util.MD5Utils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.RunningUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadStatus;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
@ -109,13 +102,13 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
private int currentItem = -1;
|
||||
private int previous = 0;
|
||||
private int width;
|
||||
private boolean isDestory;
|
||||
private String gameId;
|
||||
private String entrance;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
private long start = 0L;
|
||||
private boolean isShowPluginDialog = false;
|
||||
private boolean isSentReport = false;
|
||||
|
||||
private ArrayMap<String, String> statusMap;
|
||||
@ -140,24 +133,6 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Entry<String, DownloadEntry> entry : downloadingEntries
|
||||
.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
if (DownloadStatus.done.equals(downloadEntry.getStatus())
|
||||
&& downloadEntry.getMeta().get("isPlugin") != null) {
|
||||
if (!RunningUtils
|
||||
.isApplicationBroughtToBackground(getApplicationContext())
|
||||
&& RunningUtils.isEqualsTop(
|
||||
getApplicationContext(),
|
||||
GameDetailsActivity.class.getName())) {
|
||||
if (!isShowPluginDialog) {
|
||||
isShowPluginDialog = true;
|
||||
showPluginDialog(downloadEntry.getPath(),
|
||||
downloadEntry.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -174,6 +149,8 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
isDestory = false;
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_gamedetails, null);
|
||||
|
||||
gameId = getIntent().getStringExtra("gameId");
|
||||
@ -259,29 +236,33 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Gson gson = new Gson();
|
||||
entity = gson.fromJson(response.toString(),
|
||||
GameEntity.class);
|
||||
gamedetails_ll_loading.setVisibility(View.GONE);
|
||||
gamedetails_vp_show.setVisibility(View.VISIBLE);
|
||||
gamedetails_ll_top.setVisibility(View.VISIBLE);
|
||||
if (Config.isShow) {
|
||||
gamedetails_ll_bottom.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
gamedetails_ll_bottom.setVisibility(View.GONE);
|
||||
if (!isDestory) {
|
||||
Gson gson = new Gson();
|
||||
entity = gson.fromJson(response.toString(),
|
||||
GameEntity.class);
|
||||
gamedetails_ll_loading.setVisibility(View.GONE);
|
||||
gamedetails_vp_show.setVisibility(View.VISIBLE);
|
||||
gamedetails_ll_top.setVisibility(View.VISIBLE);
|
||||
if (Config.isShow) {
|
||||
gamedetails_ll_bottom.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
gamedetails_ll_bottom.setVisibility(View.GONE);
|
||||
}
|
||||
init();
|
||||
}
|
||||
init();
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接和访问超时
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
toast("网络错误");
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
gamedetails_ll_loading.setVisibility(View.GONE);
|
||||
if (!isDestory) {
|
||||
// 无网络连接和访问超时
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
toast("网络错误");
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
gamedetails_ll_loading.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -420,14 +401,33 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
top_tv_attention
|
||||
.setBackgroundResource(R.drawable.border_red_bg);
|
||||
top_tv_attention.setTextColor(0xffbc2132);
|
||||
showSuccessDialog();
|
||||
|
||||
DialogUtils.showSuccessDialog(this);
|
||||
} else {
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("点击", "取消关注");
|
||||
DataUtils.onEvent(GameDetailsActivity.this, "插件数据",
|
||||
entity.getName(), kv2);
|
||||
DataUtils.onEvent(GameDetailsActivity.this, "插件数据", entity.getName(), kv2);
|
||||
|
||||
showCancelDialog();
|
||||
DialogUtils.showCancelDialog(this, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("状态", "取消关注");
|
||||
DataUtils.onEvent(GameDetailsActivity.this, "游戏关注", entity.getName(), kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
map.put("type", "关注");
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(GameDetailsActivity.this, "concern", map);
|
||||
|
||||
concernManager.deleteConcern(entity.getId());
|
||||
|
||||
top_tv_attention.setText("关注");
|
||||
top_tv_attention.setBackgroundResource(R.drawable.textview_red_style);
|
||||
top_tv_attention.setTextColor(0xffffffff);
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
case R.id.gamedetails_tv_download:
|
||||
@ -486,7 +486,7 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
if (manager.launchSetup(path)) {
|
||||
startActivity(PackageUtils.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showUninstallDialog(this, new DialogUtils.ConfiremListener() {
|
||||
DialogUtils.showPluginDialog(this, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
MainActivity.uninstallMap.put(
|
||||
@ -494,7 +494,7 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
startActivity(PackageUtils.getUninstallIntent(GameDetailsActivity.this,
|
||||
path));
|
||||
}
|
||||
});
|
||||
}, null);
|
||||
}
|
||||
} else if("等待".equals(str)){
|
||||
|
||||
@ -624,132 +624,6 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
private void showSuccessDialog() {
|
||||
final Dialog dialog = new Dialog(this);
|
||||
View view = View.inflate(this, R.layout.gamedetails_attention_dialog,
|
||||
null);
|
||||
TextView title = (TextView) view.findViewById(R.id.dialog_title);
|
||||
title.setText("关注成功");
|
||||
TextView confirm = (TextView) view.findViewById(R.id.dialog_confirm);
|
||||
confirm.setText("我知道了");
|
||||
confirm.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
TextView message = (TextView) view.findViewById(R.id.dialog_message);
|
||||
message.setText("游戏的最新动态消息会优先提醒您,包括攻略、资讯、开服信息、开测信息以及最新的插件。");
|
||||
view.findViewById(R.id.dialog_rl_cancel).setVisibility(View.GONE);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void showCancelDialog() {
|
||||
final Dialog dialog = new Dialog(this);
|
||||
View view = View.inflate(this, R.layout.gamedetails_attention_dialog,
|
||||
null);
|
||||
TextView title = (TextView) view.findViewById(R.id.dialog_title);
|
||||
title.setText("取消关注");
|
||||
TextView cancel = (TextView) view.findViewById(R.id.dialog_cancel);
|
||||
cancel.setText("取消");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
TextView message = (TextView) view.findViewById(R.id.dialog_message);
|
||||
|
||||
Spanned content = Html
|
||||
.fromHtml("取消关注游戏后,您将无法及时收到游戏的<font color='#ff0000'>攻略</font>、<font color='#ff0000'>资讯</font>等最新动态提醒,您确定取消吗?");
|
||||
message.setText(content);
|
||||
|
||||
view.findViewById(R.id.dialog_rl_confirm).setVisibility(View.VISIBLE);
|
||||
view.findViewById(R.id.dialog_confirm).setOnClickListener(
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("状态", "取消关注");
|
||||
DataUtils.onEvent(GameDetailsActivity.this, "游戏关注",
|
||||
entity.getName(), kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
map.put("type", "关注");
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(GameDetailsActivity.this,
|
||||
"concern", map);
|
||||
|
||||
concernManager.deleteConcern(entity.getId());
|
||||
dialog.dismiss();
|
||||
top_tv_attention.setText("关注");
|
||||
top_tv_attention
|
||||
.setBackgroundResource(R.drawable.textview_red_style);
|
||||
top_tv_attention.setTextColor(0xffffffff);
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void showPluginDialog(final String path, final String gameName) {
|
||||
final Dialog dialog = new Dialog(this);
|
||||
View view = View.inflate(this, R.layout.search_history_delete_dialog,
|
||||
null);
|
||||
TextView title = (TextView) view.findViewById(R.id.delete_dialog_title);
|
||||
title.setText("插件化安装");
|
||||
TextView content = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_message);
|
||||
Spanned spanned = Html.fromHtml("您将进行插件化安装以实现插件功能,此过程将"
|
||||
+ "<font color=\"#ff0000\">卸载</font>" + "当前使用的版本并"
|
||||
+ "<font color=\"#ff0000\">安装插件版本</font>" + "。");
|
||||
content.setText(spanned);
|
||||
|
||||
TextView cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_cancel);
|
||||
cancel.setText("取消");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
TextView confirm = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirm.setText("确定");
|
||||
confirm.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
Map<String, Object> kv6 = new HashMap<String, Object>();
|
||||
kv6.put("操作", "一次性完成");
|
||||
DataUtils.onEvent(GameDetailsActivity.this, "插件化", gameName, kv6);
|
||||
if (FileUtils.isEmptyFile(path)) {
|
||||
toast("解析包错误");
|
||||
} else {
|
||||
MainActivity.uninstallMap.put(PackageUtils.getPackageNameByPath(getApplicationContext(), path), path);
|
||||
startActivity(PackageUtils.getUninstallIntent(getApplicationContext(), path));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
isShowPluginDialog = false;
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
switch (position) {
|
||||
@ -1070,6 +944,7 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestory = true;
|
||||
gamedetails_tv_details = null;
|
||||
gamedetails_tv_information = null;
|
||||
gamedetails_tv_strategy = null;
|
||||
|
||||
@ -34,6 +34,7 @@ import com.gh.base.AppController;
|
||||
import com.gh.base.BaseFragmentActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.MD5Utils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
@ -121,7 +122,6 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
|
||||
private int currentTab;
|
||||
|
||||
private boolean isFirst;
|
||||
private boolean isDestroy = false;
|
||||
private boolean isShowDownload = false;
|
||||
|
||||
@ -293,14 +293,13 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
downloadEntry.getMeta().get(
|
||||
"platform"));
|
||||
if (platform != null) {
|
||||
String msg = downloadEntry.getName()
|
||||
+ " - " + platform;
|
||||
if (downloadEntry.getMeta().get("isPlugin") != null) {
|
||||
msg = msg + " - 插件化安装包下载完成";
|
||||
EventBus.getDefault().post(new EBShowDialog("plugin", downloadEntry
|
||||
.getPath()));
|
||||
} else {
|
||||
msg = msg + " - 下载完成";
|
||||
toast(downloadEntry.getName()
|
||||
+ " - " + platform + " - 下载完成");
|
||||
}
|
||||
toast(msg);
|
||||
} else {
|
||||
toast(downloadEntry.getName() + " - 下载完成");
|
||||
}
|
||||
@ -406,21 +405,19 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
doneMap = new ArrayMap<String, String>();
|
||||
uninstallMap = new ArrayMap<String, String>();
|
||||
|
||||
isFirst = true;
|
||||
|
||||
getSearchHints();
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
|
||||
if (!sp.getBoolean("isFirstLaunch", true)
|
||||
if (!sp.getBoolean("isNewsFirstLaunch", true)
|
||||
&& sp.getBoolean("autoupdate", true)) {
|
||||
checkUpdate();
|
||||
}
|
||||
|
||||
if (sp.getBoolean("isFirstLaunch", true)) {
|
||||
if (sp.getBoolean("isNewsFirstLaunch", true)) {
|
||||
getPluginUpdate();
|
||||
getDisclaimer(true);
|
||||
sp.edit().putBoolean("isFirstLaunch", false).apply();
|
||||
sp.edit().putBoolean("isNewsFirstLaunch", false).apply();
|
||||
} else {
|
||||
getDisclaimer(false);
|
||||
handler.postDelayed(runnable, 500);
|
||||
@ -532,7 +529,7 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
sp.edit().putString("disclaimer", content)
|
||||
.apply();
|
||||
if (isFirst) {
|
||||
showDisclaimerDialog(content);
|
||||
DialogUtils.showDisclaimerDialog(MainActivity.this, content);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
@ -553,30 +550,6 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
AppController.addToRequestQueue(request, MainActivity.class);
|
||||
}
|
||||
|
||||
// 弹出免责声明的窗口
|
||||
private void showDisclaimerDialog(String content) {
|
||||
final Dialog disclaimerDialog = new Dialog(this);
|
||||
View view = View
|
||||
.inflate(this, R.layout.setting_disclaimer_dialog, null);
|
||||
TextView title = (TextView) view
|
||||
.findViewById(R.id.disclaimer_dialog_title);
|
||||
title.setText("免责声明");
|
||||
TextView message = (TextView) view
|
||||
.findViewById(R.id.disclaimer_dialog_message);
|
||||
Spanned spanned = Html.fromHtml(content);
|
||||
message.setText(spanned);
|
||||
view.findViewById(R.id.disclaimer_dialog_confirm).setOnClickListener(
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
disclaimerDialog.dismiss();
|
||||
}
|
||||
});
|
||||
disclaimerDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
disclaimerDialog.setContentView(view);
|
||||
disclaimerDialog.show();
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -952,9 +925,6 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
break;
|
||||
case R.id.home2_layout:
|
||||
EventBus.getDefault().post(new EBUISwitch("MainActivity", 1));
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
}
|
||||
setTabSelection(1);
|
||||
break;
|
||||
case R.id.home3_layout:
|
||||
@ -1099,12 +1069,15 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
jsonObject.toString(), new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
|
||||
Utils.log("download = " + response);
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
|
||||
Utils.log("download = " + error);
|
||||
if (error.networkResponse != null) {
|
||||
Utils.log("download = " + new String(error.networkResponse.data));
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, MainActivity.class);
|
||||
@ -1115,6 +1088,7 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
|
||||
String packageName = busFour.getPackageName();
|
||||
// 添加进已安装map中
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
@ -1142,19 +1116,24 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
url, sp.getBoolean("autodelete", true));
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
for (DownloadEntry downloadEntry : DownloadManager.getInstance(
|
||||
getApplicationContext()).getAll()) {
|
||||
if (downloadEntry.getMeta().get("isPlugin") != null
|
||||
&& downloadEntry.getMeta().get("package_name")
|
||||
.equals(packageName)) {
|
||||
Map<String, Object> kv6 = new HashMap<String, Object>();
|
||||
kv6.put("安装或卸载", "卸载完成");
|
||||
DataUtils.onEvent(this, "插件化", downloadEntry.getName(), kv6);
|
||||
break;
|
||||
try {
|
||||
for (DownloadEntry downloadEntry : DownloadManager.getInstance(
|
||||
getApplicationContext()).getAll()) {
|
||||
if (downloadEntry.getMeta().get("isPlugin") != null
|
||||
&& downloadEntry.getMeta().get("package_name")
|
||||
.equals(packageName)) {
|
||||
Map<String, Object> kv6 = new HashMap<String, Object>();
|
||||
kv6.put("安装或卸载", "卸载完成");
|
||||
DataUtils.onEvent(this, "插件化", downloadEntry.getName(), kv6);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String path = uninstallMap.get(packageName);
|
||||
|
||||
if (path != null) {
|
||||
uninstallMap.remove(packageName);
|
||||
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@ -32,6 +34,7 @@ import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.NoConnectionError;
|
||||
import com.android.volley.Response;
|
||||
@ -135,8 +138,10 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
private double R11;
|
||||
private int mActivePointerId;
|
||||
private WebSettings webSettings;
|
||||
private int defaultTextZoom = 100;
|
||||
private int defaultTextZoom = 85;
|
||||
private int scrollSize = 300;//滑动距离超过300触发事件(放大缩小字体)
|
||||
private SharedPreferences sp;
|
||||
private int fontsize;
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
@ -241,6 +246,31 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
}
|
||||
});
|
||||
}
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Activity.MODE_PRIVATE);
|
||||
fontsize = sp.getInt("fontsize",1);
|
||||
if (fontsize == 0){
|
||||
fontsize = 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void saveFontSize(int size){
|
||||
SharedPreferences.Editor edit = sp.edit();
|
||||
edit.putInt("fontsize",size);
|
||||
edit.apply();
|
||||
}
|
||||
private String getFontSize(int i){
|
||||
switch (i){
|
||||
case 1:
|
||||
return "小字号";
|
||||
case 2:
|
||||
return "中字号";
|
||||
case 3:
|
||||
return "大字号";
|
||||
case 4:
|
||||
return "特大字号";
|
||||
default:
|
||||
return "未知字号";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -270,13 +300,19 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
float R2 = (X2 * X2) + (Y2 * Y2);
|
||||
double R12 = Math.sqrt(R2);
|
||||
if (isSecondDown && webSettings != null) {
|
||||
if ((R11 - R12) > scrollSize) {
|
||||
defaultTextZoom -= 10;
|
||||
webSettings.setTextZoom(defaultTextZoom);
|
||||
if ((R11 - R12) > scrollSize&&fontsize>1) {
|
||||
fontsize --;
|
||||
webSettings.setTextZoom(defaultTextZoom+15*fontsize);
|
||||
saveFontSize(fontsize);
|
||||
String fontSizeText = getFontSize(fontsize);
|
||||
Toast.makeText(this,fontSizeText,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
if ((R11 - R12) < -scrollSize) {
|
||||
defaultTextZoom += 10;
|
||||
webSettings.setTextZoom(defaultTextZoom);
|
||||
if ((R11 - R12) < -scrollSize&&fontsize<4) {
|
||||
fontsize ++;
|
||||
webSettings.setTextZoom(defaultTextZoom+15*fontsize);
|
||||
saveFontSize(fontsize);
|
||||
String fontSizeText = getFontSize(fontsize);
|
||||
Toast.makeText(this,fontSizeText,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -395,7 +431,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
if (manager.launchSetup(path)) {
|
||||
startActivity(PackageUtils.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showUninstallDialog(this, new DialogUtils.ConfiremListener() {
|
||||
DialogUtils.showPluginDialog(this, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
MainActivity.uninstallMap.put(
|
||||
@ -403,7 +439,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
startActivity(PackageUtils.getUninstallIntent(NewsActivity.this,
|
||||
path));
|
||||
}
|
||||
});
|
||||
}, null);
|
||||
}
|
||||
} else if ("等待".equals(str)) {
|
||||
|
||||
@ -1032,6 +1068,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
webSettings = holder.essaydetails_wv_content.getSettings();
|
||||
webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
webSettings.setTextZoom(defaultTextZoom+fontsize*15);
|
||||
holder.essaydetails_wv_content.loadDataWithBaseURL(null, entity.getContent(), "text/html", "utf-8", null);
|
||||
holder.essaydetails_wv_content.setWebViewClient(new WebViewClient() {
|
||||
@Override
|
||||
@ -1235,7 +1272,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
super.onPause();
|
||||
statusMap.clear();
|
||||
DownloadManager.getInstance(this).removeObserver(dataWatcher);
|
||||
if (!isSentReport) {
|
||||
if (!isSentReport && entity != null) {
|
||||
long end = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
int seconds = (int) ((end - start) / 1000);
|
||||
|
||||
198
app/src/main/java/com/gh/gamecenter/PluginActivity.java
Normal file
@ -0,0 +1,198 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.PluginAdapter;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPWDismiss;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/6.
|
||||
*/
|
||||
public class PluginActivity extends BaseActivity {
|
||||
|
||||
private RecyclerView plugin_list;
|
||||
private PluginAdapter adapter;
|
||||
private ProgressBarCircularIndeterminate plugin_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private boolean isEverpause = false;
|
||||
private boolean isDestroy = false;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (!isDestroy) {
|
||||
if (msg.what == Constants.DOWNLOAD_ROLL) {
|
||||
String name = (String) msg.obj;
|
||||
if (adapter != null) {
|
||||
LinkedBlockingQueue<String> queue = adapter.getPlatformMap().get(name);
|
||||
if (queue.size() > 1) {
|
||||
queue.offer(queue.poll());
|
||||
Message msg2 = Message.obtain();
|
||||
msg2.obj = name;
|
||||
msg2.what = Constants.DOWNLOAD_ROLL;
|
||||
sendMessageDelayed(msg2, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
for (java.util.Map.Entry<String, DownloadEntry> entry : downloadingEntries
|
||||
.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
|
||||
//特殊 插件化update
|
||||
if (downloadEntry.getMeta().get("PluginPlatform") != null) {
|
||||
Integer location = adapter.getLocationMap().get(
|
||||
downloadEntry.getName() + " - " + downloadEntry.getMeta().get("PluginPlatform"));
|
||||
if (location != null) {
|
||||
int index = location;
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, adapter.getPlatformMap(), handler, adapter, index, adapter.getStatusMap());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_plugin, null);
|
||||
|
||||
init(contentView, "可以插件化的游戏");
|
||||
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
plugin_pb_loading.setVisibility(View.VISIBLE);
|
||||
plugin_list.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new PluginAdapter(PluginActivity.this, plugin_list,
|
||||
plugin_pb_loading, reuse_no_connection);
|
||||
plugin_list.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
||||
plugin_list.setHasFixedSize(true);
|
||||
plugin_list.setLayoutManager(new LinearLayoutManager(this));
|
||||
adapter = new PluginAdapter(this, plugin_list, plugin_pb_loading, reuse_no_connection);
|
||||
plugin_list.setAdapter(adapter);
|
||||
plugin_list.addItemDecoration(new VerticalItemDecoration(this, 1));
|
||||
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (adapter != null) {
|
||||
adapter.getDismissEntity().setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
plugin_list.setVisibility(View.VISIBLE);
|
||||
plugin_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new PluginAdapter(this, plugin_list, plugin_pb_loading, reuse_no_connection);
|
||||
plugin_list.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
//特殊 插件化
|
||||
String name = adapter.getNameMap().get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
Integer location = adapter.getLocationMap().get(name);
|
||||
if (location != null) {
|
||||
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())) {
|
||||
list.remove(i);
|
||||
adapter.notifyItemRemoved(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GameEntity getEntityByLocation(int position) {
|
||||
return adapter.getPluginList().get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
adapter.getStatusMap().clear();
|
||||
DownloadManager.getInstance(this).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
//修改游戏下载状态
|
||||
DownloadItemUtils.initializeGameMap(this, adapter.getGameMap());
|
||||
for (GameEntity entity : adapter.getPluginList()) {
|
||||
entity.setEntryMap(adapter.getGameMap().get(entity.getName()));
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(PluginActivity.class);
|
||||
plugin_list = null;
|
||||
adapter = null;
|
||||
plugin_pb_loading = null;
|
||||
reuse_no_connection = null;
|
||||
handler = null;
|
||||
dataWatcher = null;
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,8 @@ import android.app.ActionBar.LayoutParams;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.text.Editable;
|
||||
@ -56,6 +58,17 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
private String searchKey;
|
||||
private int currentTab;
|
||||
|
||||
private boolean isHistorySearch;
|
||||
private Handler handler = new Handler(){
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
if (msg.what == 1){
|
||||
setResultPresentModel(1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
@ -179,6 +192,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
if (!TextUtils.isEmpty(searchKey)) {
|
||||
setResultPresentModel(2);
|
||||
dao.add(searchKey);
|
||||
isHistorySearch = false;
|
||||
} else {
|
||||
toast("请输入搜索内容");
|
||||
}
|
||||
@ -214,11 +228,12 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
public void afterTextChanged(Editable s) {
|
||||
String newSearchKey = s.toString().trim();
|
||||
if (!newSearchKey.equals(searchKey)) {
|
||||
handler.removeMessages(1);
|
||||
searchKey = newSearchKey;
|
||||
if (searchKey.length() < 1) {
|
||||
setResultPresentModel(0);
|
||||
} else {
|
||||
setResultPresentModel(1);
|
||||
} else if (!isHistorySearch){
|
||||
handler.sendEmptyMessageDelayed(1,300);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -326,6 +341,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
}
|
||||
|
||||
public void onEvent(EBSearch search) {
|
||||
isHistorySearch = true;
|
||||
String str = search.getKey();
|
||||
searchInput.setText(str);
|
||||
searchInput.setFocusable(true);
|
||||
|
||||
@ -15,9 +15,9 @@ import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
@ -59,7 +59,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
private SwitchButton setting_sb_autoinstall, setting_sb_autodelete,
|
||||
setting_sb_deletedata, setting_sb_autoupdate;
|
||||
private TextView setting_tv_version, app_tv_speed, app_tv_percent,
|
||||
app_btn_cancel, setting_tv_cache;
|
||||
app_btn_cancel, setting_tv_cache,setting_tv_size;
|
||||
private ProgressBar app_pb_progress;
|
||||
|
||||
private SharedPreferences sp;
|
||||
@ -73,6 +73,8 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
private int checkSizeIndex;
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
|
||||
@Override
|
||||
@ -147,12 +149,17 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
setting_sb_autodelete.setChecked(sp.getBoolean("autodelete", true));
|
||||
setting_sb_deletedata.setChecked(sp.getBoolean("deletedata", true));
|
||||
setting_sb_autoupdate.setChecked(sp.getBoolean("autoupdate", true));
|
||||
checkSizeIndex = sp.getInt("fontsize",1);
|
||||
|
||||
if (sp.getBoolean("isShowDisclaimer", false)) {
|
||||
TextView setting_tv_disclaimer = (TextView) findViewById(R.id.setting_tv_disclaimer);
|
||||
setting_tv_disclaimer.setVisibility(View.VISIBLE);
|
||||
setting_tv_disclaimer.setOnClickListener(this);
|
||||
}
|
||||
if (checkSizeIndex == 0){
|
||||
checkSizeIndex = 1;
|
||||
}
|
||||
fontTextSize(checkSizeIndex);
|
||||
}
|
||||
|
||||
// 获取缓存大小
|
||||
@ -196,6 +203,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
mEditor.putBoolean("autodelete", setting_sb_autodelete.isChecked());
|
||||
mEditor.putBoolean("deletedata", setting_sb_deletedata.isChecked());
|
||||
mEditor.putBoolean("autoupdate", setting_sb_autoupdate.isChecked());
|
||||
mEditor.putInt("fontsize",checkSizeIndex);
|
||||
mEditor.apply();
|
||||
}
|
||||
|
||||
@ -235,42 +243,66 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
case R.id.setting_tv_disclaimer:
|
||||
String content = sp.getString("disclaimer", null);
|
||||
if (!TextUtils.isEmpty(content)) {
|
||||
showDisclaimerDialog(content);
|
||||
DialogUtils.showDisclaimerDialog(this, content);
|
||||
}
|
||||
break;
|
||||
case R.id.setting_rl_font_size:
|
||||
final Dialog dialog = new Dialog(this);
|
||||
View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_font_size, null);
|
||||
TextView tv_negative = (TextView) inflate.findViewById(R.id.font_size_negative);
|
||||
TextView tv_positive = (TextView) inflate.findViewById(R.id.font_size_positive);
|
||||
final RadioGroup radioGroup = (RadioGroup) inflate.findViewById(R.id.font_size_radiogroup);
|
||||
tv_negative.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
tv_positive.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId();
|
||||
int index = checkedRadioButtonId % 4;
|
||||
if (index == 0) {
|
||||
index = 4;
|
||||
}
|
||||
Toast.makeText(getApplicationContext(), "" +index, Toast.LENGTH_SHORT).show();
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(inflate);
|
||||
dialog.show();
|
||||
fontSize();
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void fontTextSize(int i){
|
||||
switch (i){
|
||||
case 1:
|
||||
setting_tv_size.setText("小字号");
|
||||
break;
|
||||
case 2:
|
||||
setting_tv_size.setText("中字号");
|
||||
break;
|
||||
case 3:
|
||||
setting_tv_size.setText("大字号");
|
||||
break;
|
||||
case 4:
|
||||
setting_tv_size.setText("特大字号");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//设置正文字号
|
||||
private void fontSize() {
|
||||
final Dialog dialog = new Dialog(this);
|
||||
View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_font_size, null);
|
||||
TextView tv_negative = (TextView) inflate.findViewById(R.id.font_size_negative);
|
||||
TextView tv_positive = (TextView) inflate.findViewById(R.id.font_size_positive);
|
||||
final RadioGroup radioGroup = (RadioGroup) inflate.findViewById(R.id.font_size_radiogroup);
|
||||
((RadioButton)(radioGroup.getChildAt(checkSizeIndex-1))).setChecked(true);
|
||||
|
||||
tv_negative.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
tv_positive.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
checkSizeIndex = radioGroup.getCheckedRadioButtonId() % 4;
|
||||
|
||||
if (checkSizeIndex == 0){
|
||||
checkSizeIndex = 4;
|
||||
}
|
||||
dialog.cancel();
|
||||
saveCurrentSetting();
|
||||
fontTextSize(checkSizeIndex);
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(inflate);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
// 清除缓存
|
||||
private void claerCache() {
|
||||
@ -317,30 +349,6 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
// 弹出免责声明的窗口
|
||||
private void showDisclaimerDialog(String content) {
|
||||
final Dialog disclaimerDialog = new Dialog(this);
|
||||
View view = View
|
||||
.inflate(this, R.layout.setting_disclaimer_dialog, null);
|
||||
TextView title = (TextView) view
|
||||
.findViewById(R.id.disclaimer_dialog_title);
|
||||
title.setText("免责声明");
|
||||
TextView message = (TextView) view
|
||||
.findViewById(R.id.disclaimer_dialog_message);
|
||||
Spanned spanned = Html.fromHtml(content);
|
||||
message.setText(spanned);
|
||||
view.findViewById(R.id.disclaimer_dialog_confirm).setOnClickListener(
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
disclaimerDialog.dismiss();
|
||||
}
|
||||
});
|
||||
disclaimerDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
disclaimerDialog.setContentView(view);
|
||||
disclaimerDialog.show();
|
||||
}
|
||||
|
||||
private void checkUpdate() {
|
||||
String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this,
|
||||
getPackageName(), "TD_CHANNEL_ID");
|
||||
@ -386,7 +394,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
|
||||
showUpdateDialog(updateMD5);
|
||||
} else {
|
||||
showCancelDialog();
|
||||
toast("已是最新版本");
|
||||
}
|
||||
|
||||
}
|
||||
@ -540,39 +548,6 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
DownloadManager.getInstance(getApplicationContext()).add(downloadEntry);
|
||||
}
|
||||
|
||||
private void showCancelDialog() {
|
||||
|
||||
final Dialog dialog = new Dialog(SettingActivity.this);
|
||||
View view = View.inflate(SettingActivity.this,
|
||||
R.layout.search_history_delete_dialog, null);
|
||||
TextView title = (TextView) view.findViewById(R.id.delete_dialog_title);
|
||||
title.setText("更新提示");
|
||||
TextView content = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_message);
|
||||
|
||||
content.setText("已经是最新版本!");
|
||||
|
||||
view.findViewById(R.id.delete_dialog_rl_cancel)
|
||||
.setVisibility(View.GONE);
|
||||
view.findViewById(R.id.delete_dialog_rl_confirm).setVisibility(
|
||||
View.VISIBLE);
|
||||
|
||||
TextView cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
|
||||
cancel.setVisibility(View.VISIBLE);
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
@ -97,7 +97,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
from = getIntent().getStringExtra("from");
|
||||
|
||||
if (sp.getBoolean("isFirstLaunch", true)
|
||||
if (sp.getBoolean("isNewsFirstLaunch", true)
|
||||
|| sp.getInt("actionbar_height", 0) != 0) {
|
||||
setTheme(R.style.AppTheme_Guide);
|
||||
} else {
|
||||
@ -116,7 +116,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
setContentView(R.layout.activity_splash);
|
||||
|
||||
if (sp.getBoolean("isFirstLaunch", true)) {
|
||||
if (sp.getBoolean("isNewsFirstLaunch", true)) {
|
||||
findViewById(R.id.splash_ll_normal).setVisibility(View.GONE);
|
||||
|
||||
ViewPager splash_viewPager = (ViewPager) findViewById(R.id.splash_viewPager);
|
||||
@ -171,7 +171,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("isFirstLaunch", true)) {
|
||||
if (sp.getBoolean("isNewsFirstLaunch", true)) {
|
||||
Intent intent = new Intent(SplashScreenActivity.this,
|
||||
MainActivity.class);
|
||||
startActivity(intent);
|
||||
@ -229,7 +229,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
getPlatform();
|
||||
}
|
||||
|
||||
// getDownloadStatus();
|
||||
getDownloadStatus();
|
||||
|
||||
getUISetting();
|
||||
|
||||
@ -576,11 +576,14 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
List<ApkEntity> list = gameEntity.getApk();
|
||||
HashMap<String, Boolean> packageNames = new HashMap<String, Boolean>();
|
||||
for (int j = 0, sizej = list.size(); j < sizej; j++) {
|
||||
packageNames.put(
|
||||
list.get(j).getPackageName(), false);
|
||||
packageNames.put(list.get(j).getPackageName(), false);
|
||||
}
|
||||
entity.setTime(System.currentTimeMillis());
|
||||
entity.setPackageNames(packageNames);
|
||||
//默认安装即为关注
|
||||
if (!concernManager.isConcern(entity.getId())) {
|
||||
concernManager.addByEntity(gameEntity);
|
||||
}
|
||||
concernManager.updateByConcern(entity);
|
||||
}
|
||||
if (cCount == count) {
|
||||
@ -661,7 +664,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
concernManager.updateByConcern(concernEntity);
|
||||
}
|
||||
}
|
||||
if (!sp.getBoolean("isFirstLaunch", true)) {
|
||||
if (!sp.getBoolean("isNewsFirstLaunch", true)) {
|
||||
|
||||
int height = sp.getInt("actionbar_height", 0);
|
||||
if (height == 0) {
|
||||
|
||||
@ -3,64 +3,46 @@ package com.gh.gamecenter;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
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.android.volley.NoConnectionError;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.HotCardAdapter;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.adapter.SubjectAdapter;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPWDismiss;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class SubjectActivity extends BaseActivity {
|
||||
|
||||
private RecyclerView hotcard_list;
|
||||
private HotCardAdapter adapter;
|
||||
private LinearLayout hotcard_ll_loading;
|
||||
private RecyclerView subject_list;
|
||||
private SubjectAdapter adapter;
|
||||
private ProgressBarCircularIndeterminate subject_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
// 黄壮华 添加 记录信息的map 修改2015/8/15
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private String id;
|
||||
private boolean order;
|
||||
|
||||
private boolean isEverpause = false;
|
||||
private boolean isDestroy = false;
|
||||
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private int page = 1;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
@ -68,9 +50,8 @@ public class SubjectActivity extends BaseActivity {
|
||||
if (!isDestroy) {
|
||||
if (msg.what == Constants.DOWNLOAD_ROLL) {
|
||||
String name = (String) msg.obj;
|
||||
if (platformMap != null) {
|
||||
LinkedBlockingQueue<String> queue = platformMap
|
||||
.get(name);
|
||||
if (adapter != null) {
|
||||
LinkedBlockingQueue<String> queue = adapter.getPlatformMap().get(name);
|
||||
if (queue.size() > 1) {
|
||||
queue.offer(queue.poll());
|
||||
Message msg2 = Message.obtain();
|
||||
@ -86,7 +67,6 @@ public class SubjectActivity extends BaseActivity {
|
||||
|
||||
// 黄壮华 添加观察者 修改2015/8/15
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
@ -94,16 +74,16 @@ public class SubjectActivity extends BaseActivity {
|
||||
.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
|
||||
Integer location = locationMap.get(downloadEntry.getName());
|
||||
Integer location = adapter.getLocationMap().get(downloadEntry.getName());
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
int index = location;
|
||||
|
||||
GameEntity detailedEntity = adapter.getList().get(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, platformMap, handler, adapter,
|
||||
index, statusMap);
|
||||
downloadEntry, adapter.getPlatformMap(), handler, adapter,
|
||||
index, adapter.getStatusMap());
|
||||
}
|
||||
|
||||
}
|
||||
@ -113,108 +93,63 @@ public class SubjectActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
String id = getIntent().getStringExtra("id");
|
||||
id = getIntent().getStringExtra("id");
|
||||
String name = getIntent().getStringExtra("name");
|
||||
order = getIntent().getBooleanExtra("order",false);
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
name = "";
|
||||
}
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_hotcard, null);
|
||||
View contentView = View.inflate(this, R.layout.activity_subject, null);
|
||||
|
||||
init(contentView, name);
|
||||
|
||||
dismissEntity = new DismissEntity(false);
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
subject_pb_loading.setVisibility(View.VISIBLE);
|
||||
subject_list.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new SubjectAdapter(SubjectActivity.this, subject_list,
|
||||
subject_pb_loading, reuse_no_connection, id , order);
|
||||
subject_list.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
gameMap = new ArrayMap<String, ArrayMap<String, DownloadEntry>>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
nameMap = new ArrayMap<String, String>();
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
|
||||
hotcard_list.setHasFixedSize(true);
|
||||
hotcard_list.setLayoutManager(new LinearLayoutManager(this));
|
||||
subject_list.setHasFixedSize(true);
|
||||
subject_list.setLayoutManager(layoutManager);
|
||||
adapter = new SubjectAdapter(this, subject_list, subject_pb_loading, reuse_no_connection, id,order);
|
||||
subject_list.setAdapter(adapter);
|
||||
subject_list.addItemDecoration(new VerticalItemDecoration(this, 1));
|
||||
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(this, gameMap);
|
||||
subject_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (!isDestroy && newState == RecyclerView.SCROLL_STATE_IDLE && adapter.getItemCount() == layoutManager.findLastVisibleItemPosition()+1&&adapter.isLoaded()){
|
||||
page++;
|
||||
adapter.initList(page);
|
||||
|
||||
// 黄壮华 传递引用 修改2015/8/15
|
||||
adapter = new HotCardAdapter(this, platformMap, statusMap, dismissEntity);
|
||||
hotcard_list.setAdapter(adapter);
|
||||
hotcard_list.addItemDecoration(new VerticalItemDecoration(this, 1));
|
||||
|
||||
addList(id);
|
||||
|
||||
}
|
||||
|
||||
private void addList(String id) {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d50/game/column/" + id, Constants.GAME_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
processingData(response);
|
||||
}
|
||||
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接
|
||||
if (error.getClass().equals(NoConnectionError.class)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, SubjectActivity.class);
|
||||
}
|
||||
|
||||
private void processingData(JSONArray response) {
|
||||
Type listType = new TypeToken<ArrayList<GameEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
GameManager manager = new GameManager(getApplicationContext());
|
||||
List<GameEntity> gameList = gson.fromJson(response.toString(), listType);
|
||||
if (gameList != null && !gameList.isEmpty()) {
|
||||
for (GameEntity entity : gameList) {
|
||||
// 黄壮华 初始化游戏状态 修改2015/8/15
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
manager.addOrUpdate(new GameInfo(apkEntity.getPackageName(),
|
||||
entity.getId(), entity.getName()));
|
||||
}
|
||||
}
|
||||
adapter.getList().addAll(gameList);
|
||||
adapter.notifyItemRangeInserted(adapter.getList().size() - gameList.size(), gameList.size());
|
||||
}
|
||||
});
|
||||
|
||||
// 黄壮华 获取游戏位置信息 修改2015/8/15
|
||||
for (int i = 0, size = adapter.getList().size(); i < size; i++) {
|
||||
GameEntity entity = adapter.getList().get(i);
|
||||
locationMap.put(entity.getName(), i);
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
nameMap.put(apkEntity.getPackageName(), entity.getName());
|
||||
}
|
||||
}
|
||||
|
||||
hotcard_list.setVisibility(View.VISIBLE);
|
||||
hotcard_ll_loading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (dismissEntity != null) {
|
||||
dismissEntity.setShow(false);
|
||||
if (adapter != null) {
|
||||
adapter.getDismissEntity().setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = nameMap.get(busFour.getPackageName());
|
||||
String name = adapter.getNameMap().get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
int location = locationMap.get(name);
|
||||
int location = adapter.getLocationMap().get(name);
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity entity = adapter.getList().get(location);
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
@ -231,18 +166,29 @@ public class SubjectActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
subject_list.setVisibility(View.VISIBLE);
|
||||
subject_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new SubjectAdapter(SubjectActivity.this, subject_list,
|
||||
subject_pb_loading, reuse_no_connection, id, order);
|
||||
subject_list.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(this, gameMap);
|
||||
List<GameEntity> entities = new ArrayList<GameEntity>();
|
||||
DownloadItemUtils.initializeGameMap(this, adapter.getGameMap());
|
||||
for (GameEntity entity : adapter.getList()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
entities.add(entity);
|
||||
entity.setEntryMap(adapter.getGameMap().get(entity.getName()));
|
||||
}
|
||||
adapter.setList(entities);
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getApplicationContext()).addObserver(dataWatcher);
|
||||
@ -252,7 +198,7 @@ public class SubjectActivity extends BaseActivity {
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
statusMap.clear();
|
||||
adapter.getStatusMap().clear();
|
||||
DownloadManager.getInstance(getApplicationContext()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@ -261,15 +207,10 @@ public class SubjectActivity extends BaseActivity {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(SubjectActivity.class);
|
||||
hotcard_list = null;
|
||||
subject_list = null;
|
||||
adapter = null;
|
||||
hotcard_ll_loading = null;
|
||||
locationMap = null;
|
||||
gameMap = null;
|
||||
platformMap = null;
|
||||
nameMap = null;
|
||||
statusMap = null;
|
||||
dismissEntity = null;
|
||||
subject_pb_loading = null;
|
||||
reuse_no_connection = null;
|
||||
handler = null;
|
||||
dataWatcher = null;
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@ -22,16 +23,17 @@ import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.view.Gh_ImageLayout;
|
||||
import com.gh.common.view.Gh_ImageLayout.OnSingleTapListener;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
//import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
//import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder;
|
||||
//import com.facebook.drawee.view.SimpleDraweeView;
|
||||
//import com.facebook.imagepipeline.request.ImageRequest;
|
||||
//import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
||||
import pl.droidsonroids.gif.GifDrawable;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
|
||||
|
||||
/**
|
||||
* 查看游戏截图页面
|
||||
@ -49,7 +51,9 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
private int current;
|
||||
private int width;
|
||||
private String scaleType;
|
||||
|
||||
private ImageView imageView;
|
||||
private boolean isOrientation;
|
||||
private boolean isLoading = false;
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
@ -95,6 +99,7 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
current = savedInstanceState.getInt("currentItem", 0);
|
||||
isOrientation = savedInstanceState.getBoolean("isOrientation");
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_viewimage);
|
||||
@ -116,12 +121,25 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
viewimage_vp_show.setAdapter(adapter);
|
||||
viewimage_vp_show.setCurrentItem(current);
|
||||
viewimage_vp_show.addOnPageChangeListener(this);
|
||||
|
||||
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
|
||||
|
||||
{
|
||||
isOrientation = true; // 横屏
|
||||
|
||||
} else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
|
||||
|
||||
{
|
||||
isOrientation = false;// 竖屏
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("currentItem", viewimage_vp_show.getCurrentItem());
|
||||
outState.putBoolean("isOrientation", isOrientation);
|
||||
}
|
||||
|
||||
private class ViewImageAdapter extends PagerAdapter implements
|
||||
@ -129,6 +147,9 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (urls == null) {
|
||||
return 0;
|
||||
}
|
||||
return urls.size();
|
||||
}
|
||||
|
||||
@ -138,30 +159,29 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
Gh_ImageLayout view = (Gh_ImageLayout) View.inflate(container.getContext(),
|
||||
R.layout.viewimage_item, null);
|
||||
view.setOnSingleTapListener(this);
|
||||
// if (url.contains(".gif")) {
|
||||
// SimpleDraweeView simpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.test_gif);
|
||||
// ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
|
||||
// .build();
|
||||
// PipelineDraweeControllerBuilder controllerBuilder = Fresco.newDraweeControllerBuilder()
|
||||
// .setAutoPlayAnimations(true)
|
||||
// .setTapToRetryEnabled(true)
|
||||
// .setImageRequest(imageRequest);
|
||||
// simpleDraweeView.setController(controllerBuilder.build());
|
||||
// ViewParent parent = simpleDraweeView.getParent();
|
||||
//
|
||||
// if (parent != null) {
|
||||
// ViewGroup parent1 = (ViewGroup) parent;
|
||||
// parent1.removeView(simpleDraweeView);
|
||||
// }
|
||||
// container.addView(simpleDraweeView);
|
||||
// return simpleDraweeView;
|
||||
//
|
||||
// } else {
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
if (url.contains(".gif")) {
|
||||
GifImageView gifImageView = (GifImageView) view.findViewById(R.id.gifView);
|
||||
ViewParent parent = gifImageView.getParent();
|
||||
if (!isLoading) {
|
||||
LoadGifData(gifImageView, urls.get(position));
|
||||
}
|
||||
|
||||
if (parent != null) {
|
||||
ViewGroup parent1 = (ViewGroup) parent;
|
||||
parent1.removeView(gifImageView);
|
||||
}
|
||||
container.addView(gifImageView);
|
||||
return gifImageView;
|
||||
|
||||
} else {
|
||||
imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
if (scaleType != null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, ScaleType.FIT_CENTER);
|
||||
} else {
|
||||
} 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);
|
||||
}
|
||||
@ -177,10 +197,52 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
view.setTag(position);
|
||||
container.addView(imageView);
|
||||
return imageView;
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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 (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view == object;
|
||||
@ -235,6 +297,10 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
int code = connection.getResponseCode();
|
||||
if (code == 200) {
|
||||
//图片存在
|
||||
if (urls == null) {
|
||||
return;
|
||||
}
|
||||
//urls出现空指针
|
||||
for (int i = 0, size = urls.size(); i < size; i++) {
|
||||
if (urls.get(i).equals(url)) {
|
||||
urls.set(i, newUrl);
|
||||
@ -260,5 +326,7 @@ public class ViewImageActivity extends BaseActivity implements
|
||||
viewimage_slide_line = null;
|
||||
rparams = null;
|
||||
urls = null;
|
||||
imageView = null;
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,224 +0,0 @@
|
||||
package com.gh.gamecenter.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameTestViewHolder;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-8
|
||||
* @update 2015-8-11
|
||||
* @des 首页插件fragment适配器
|
||||
*/
|
||||
public class HotCardAdapter extends
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context context;
|
||||
|
||||
private List<GameEntity> list;
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
public HotCardAdapter(Context context,
|
||||
ArrayMap<String, LinkedBlockingQueue<String>> pMap,
|
||||
ArrayMap<String, String> sMap, DismissEntity dEntity) {
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
platformMap = pMap;
|
||||
statusMap = sMap;
|
||||
dismissEntity = dEntity;
|
||||
|
||||
this.context = context;
|
||||
|
||||
list = new ArrayList<GameEntity>();
|
||||
}
|
||||
|
||||
public List<GameEntity> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<GameEntity> list) {
|
||||
this.list = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder,
|
||||
int position) {
|
||||
if (position != list.size()) {
|
||||
|
||||
if (viewHolder instanceof GameNormalViewHolder) {
|
||||
GameNormalViewHolder holder = (GameNormalViewHolder) viewHolder;
|
||||
|
||||
final GameEntity entity = list.get(position);
|
||||
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(),
|
||||
holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
|
||||
GameViewUtils.setLabelList(context, holder.labelList, entity.getTag());
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("入口", "热门卡牌");
|
||||
DataUtils.onEvent(context, "游戏详情", entity.getName(), kv);
|
||||
|
||||
AppController.put("GameEntity", entity);
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "热门卡牌");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
DownloadItemUtils.setOnClickListener(context, holder.downloadBtn,
|
||||
holder.download_speed, holder.download_percentage,
|
||||
entity, position, this,
|
||||
statusMap, platformMap, "热门卡牌", dismissEntity, "hotcard:" + entity.getName());
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.game_progressbar, holder.game_ll_info,
|
||||
holder.download_speed, holder.download_percentage,
|
||||
holder.downloadBtn, entity, platformMap, statusMap);
|
||||
} else if (viewHolder instanceof GameTestViewHolder) {
|
||||
GameTestViewHolder holder = (GameTestViewHolder) viewHolder;
|
||||
|
||||
final GameEntity entity = list.get(position);
|
||||
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(),
|
||||
holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
holder.gameTestType.setText(entity.getTest().getType());
|
||||
if (entity.getTest().getStart() == 0) {
|
||||
holder.gameTestTime.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.gameTestTime.setText(GameViewUtils.getGameTestDate(entity.getTest().getStart()));
|
||||
}
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AppController.put("GameEntity", entity);
|
||||
Intent intent = new Intent(context,
|
||||
GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "主页-新测卡牌");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.downloadBtn.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (entity.getTest().getEnd() == 0) {
|
||||
holder.downloadBtn.setVisibility(View.VISIBLE);
|
||||
DownloadItemUtils.setOnClickListener(context,
|
||||
holder.downloadBtn, holder.download_speed,
|
||||
holder.download_percentage, entity, position,
|
||||
HotCardAdapter.this,
|
||||
statusMap, platformMap, "主页-新测卡牌",
|
||||
dismissEntity, "主页:" + entity.getName());
|
||||
} else {
|
||||
long endTime = Long.valueOf(entity.getTest().getEnd()
|
||||
+ "000");
|
||||
long todayTime = new Date().getTime();
|
||||
if (todayTime > endTime) {
|
||||
// 测试时间已过
|
||||
holder.downloadBtn.setVisibility(View.GONE);
|
||||
} else {
|
||||
// 测试时间未过
|
||||
holder.downloadBtn.setVisibility(View.VISIBLE);
|
||||
DownloadItemUtils.setOnClickListener(context,
|
||||
holder.downloadBtn, holder.download_speed,
|
||||
holder.download_percentage, entity, position,
|
||||
HotCardAdapter.this, statusMap, platformMap,
|
||||
"主页-新测卡牌", dismissEntity,
|
||||
"主页:" + entity.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.game_progressbar, holder.game_ll_info, holder.download_speed,
|
||||
holder.download_percentage, holder.downloadBtn, entity, platformMap,
|
||||
statusMap);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
if (i != list.size()) {
|
||||
if (list.get(i).getTest() != null) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.home_game_test_item, viewGroup, false);
|
||||
return new GameTestViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.home_game_normal_item, viewGroup, false);
|
||||
return new GameNormalViewHolder(view);
|
||||
}
|
||||
} else {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.refresh_footerview, viewGroup, false);
|
||||
return new FooterViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -11,6 +11,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.NewsActivity;
|
||||
@ -18,7 +19,9 @@ import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SubjectActivity;
|
||||
import com.gh.gamecenter.entity.SlideEntity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ImagePagerAdapter
|
||||
@ -65,7 +68,7 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View view, ViewGroup container) {
|
||||
public View getView(final int position, View view, ViewGroup container) {
|
||||
ViewHolder holder;
|
||||
if (view == null) {
|
||||
holder = new ViewHolder();
|
||||
@ -85,15 +88,20 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("名字", slideEntity.getName());
|
||||
kv.put("位置", getPosition(position) + 1);
|
||||
DataUtils.onEvent(context, "点击", "游戏-插件-滚动图", kv);
|
||||
|
||||
if ("game".equals(slideEntity.getType())) {
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("gameId", slideEntity.getLink());
|
||||
intent.putExtra("entrance", "插件-滚动图");
|
||||
intent.putExtra("entrance", "游戏-插件-滚动图");
|
||||
context.startActivity(intent);
|
||||
} else if ("news".equals(slideEntity.getType())) {
|
||||
Intent intent = new Intent(context, NewsActivity.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);
|
||||
|
||||
290
app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java
Normal file
@ -0,0 +1,290 @@
|
||||
package com.gh.gamecenter.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.game.GameFragment;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/6.
|
||||
*/
|
||||
public class PluginAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context context;
|
||||
|
||||
private RecyclerView plugin_list;
|
||||
private ProgressBarCircularIndeterminate plugin_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private List<GameEntity> pluginList;
|
||||
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private ArrayMap<String, String> statusMap;
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
public PluginAdapter(Context context,
|
||||
RecyclerView recyclerView,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
LinearLayout linearLayout) {
|
||||
|
||||
this.context = context;
|
||||
plugin_list = recyclerView;
|
||||
plugin_pb_loading = pbLoading;
|
||||
reuse_no_connection = linearLayout;
|
||||
|
||||
pluginList = new ArrayList<GameEntity>();
|
||||
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
gameMap = new ArrayMap<String, ArrayMap<String, DownloadEntry>>();
|
||||
nameMap = new ArrayMap<String, String>();
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(context, gameMap);
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private int count;
|
||||
|
||||
//检查可以插件化的游戏
|
||||
private void init() {
|
||||
ConcernManager concernManager = new ConcernManager(context);
|
||||
List<ConcernInfo> infos = concernManager.getInstalledGame();
|
||||
final int size = infos.size();
|
||||
final List<GameEntity> list = new ArrayList<GameEntity>();
|
||||
count = 0;
|
||||
for (ConcernInfo info : infos) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST + "v1d45/game/" + info.getId() + "/digest", Constants.GAME_CD),
|
||||
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);
|
||||
count++;
|
||||
if (count == size) {
|
||||
processingData(list);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
count++;
|
||||
if (count == size) {
|
||||
if (list.isEmpty()) {
|
||||
plugin_list.setVisibility(View.GONE);
|
||||
plugin_pb_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
processingData(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, GameFragment.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void processingData(List<GameEntity> list) {
|
||||
if (plugin_pb_loading != null && plugin_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
plugin_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
if (list == null || list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ConcernManager concernManager = new ConcernManager(context);
|
||||
PackageManager mPackageManager = new PackageManager(context);
|
||||
List<ConcernInfo> infos = concernManager.getInstalledGame();
|
||||
HashMap<String, Boolean> map;
|
||||
GameEntity gameEntity;
|
||||
for (ConcernInfo info : infos) {
|
||||
map = info.getPackageNames();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
gameEntity = list.get(i);
|
||||
if (gameEntity.getId().equals(info.getId())
|
||||
&& gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& gameEntity.getApk() != null) {
|
||||
for (String key : map.keySet()) {
|
||||
if (map.get(key)) {
|
||||
if (!mPackageManager.isSignature(key)) {
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(key)) {
|
||||
GameEntity entity = gameEntity.clone();
|
||||
entity.setPluginPlatform(
|
||||
PlatformUtils.getInstance(context).getPlatformName(apkEntity.getPlatform()));
|
||||
ArrayList<ApkEntity> apkList = new ArrayList<ApkEntity>();
|
||||
apkList.add(apkEntity);
|
||||
entity.setApk(apkList);
|
||||
pluginList.add(entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!pluginList.isEmpty()) {
|
||||
GameManager manager = new GameManager(context);
|
||||
for (GameEntity gEntity : pluginList) {
|
||||
gEntity.setEntryMap(gameMap.get(gEntity.getName()));
|
||||
for (ApkEntity aEntity : gEntity.getApk()) {
|
||||
manager.addOrUpdate(new GameInfo(aEntity.getPackageName(),
|
||||
gEntity.getId(), gEntity.getName()));
|
||||
}
|
||||
}
|
||||
notifyItemRangeInserted(0, pluginList.size());
|
||||
initLocationMap();
|
||||
}
|
||||
}
|
||||
|
||||
private void initLocationMap() {
|
||||
for (int i = 0; i < pluginList.size(); i++) {
|
||||
GameEntity gameEntity = pluginList.get(i);
|
||||
locationMap.put(gameEntity.getName() + " - " + gameEntity.getPluginPlatform(), i);
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
nameMap.put(apkEntity.getPackageName(), gameEntity.getName() + " - " + gameEntity.getPluginPlatform());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.home_game_normal_item, parent, false);
|
||||
return new GameNormalViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof GameNormalViewHolder) {
|
||||
GameNormalViewHolder viewHolder = (GameNormalViewHolder) holder;
|
||||
|
||||
final GameEntity entity = pluginList.get(position);
|
||||
|
||||
viewHolder.home1_game_order.setVisibility(View.GONE);
|
||||
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(), viewHolder.gameThumb);
|
||||
if (entity.getPluginPlatform() != null) {
|
||||
viewHolder.gameNameAndSize.setText(entity.getName() + " - " + entity.getPluginPlatform());
|
||||
} else {
|
||||
viewHolder.gameNameAndSize.setText(entity.getName());
|
||||
}
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
viewHolder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
viewHolder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
GameViewUtils.setLabelList(context, viewHolder.labelList, entity.getTag());
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("gameId", entity.getId());
|
||||
intent.putExtra("entrance", "游戏-插件");
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
final int i = position;
|
||||
|
||||
DownloadItemUtils.setOnClickListener(context, viewHolder.downloadBtn,
|
||||
viewHolder.download_speed, viewHolder.download_percentage, entity, i,
|
||||
PluginAdapter.this,
|
||||
statusMap, platformMap, "游戏-插件",
|
||||
dismissEntity, "主页:" + entity.getName());
|
||||
|
||||
DownloadItemUtils.updateItem(context, viewHolder.labelList,
|
||||
viewHolder.game_progressbar, viewHolder.game_ll_info, viewHolder.download_speed,
|
||||
viewHolder.download_percentage, viewHolder.downloadBtn, entity, platformMap,
|
||||
statusMap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return pluginList.size();
|
||||
}
|
||||
|
||||
public List<GameEntity> getPluginList() {
|
||||
return pluginList;
|
||||
}
|
||||
|
||||
public ArrayMap<String, Integer> getLocationMap() {
|
||||
return locationMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, LinkedBlockingQueue<String>> getPlatformMap() {
|
||||
return platformMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, ArrayMap<String, DownloadEntry>> getGameMap() {
|
||||
return gameMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getNameMap() {
|
||||
return nameMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getStatusMap() {
|
||||
return statusMap;
|
||||
}
|
||||
|
||||
public DismissEntity getDismissEntity() {
|
||||
return dismissEntity;
|
||||
}
|
||||
|
||||
}
|
||||
416
app/src/main/java/com/gh/gamecenter/adapter/SubjectAdapter.java
Normal file
@ -0,0 +1,416 @@
|
||||
package com.gh.gamecenter.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.NoConnectionError;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.TimeoutError;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SubjectActivity;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameTestViewHolder;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-8
|
||||
* @update 2015-8-11
|
||||
* @des 首页插件fragment适配器
|
||||
*/
|
||||
public class SubjectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context context;
|
||||
|
||||
private RecyclerView subject_list;
|
||||
private ProgressBarCircularIndeterminate subject_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private List<GameEntity> list;
|
||||
private boolean order;
|
||||
private static final int FOOTER_ITEM = 101;
|
||||
private boolean isLoaded;
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
private int page = 1;
|
||||
private boolean isRemove;
|
||||
private boolean isNetworkError;
|
||||
private int per_page = 20;
|
||||
private String id;
|
||||
|
||||
public SubjectAdapter(Context context,
|
||||
RecyclerView recyclerView,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
LinearLayout linearLayout,
|
||||
String id,boolean order) {
|
||||
this.order = order;
|
||||
|
||||
this.context = context;
|
||||
subject_list = recyclerView;
|
||||
subject_pb_loading = pbLoading;
|
||||
reuse_no_connection = linearLayout;
|
||||
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
gameMap = new ArrayMap<String, ArrayMap<String, DownloadEntry>>();
|
||||
nameMap = new ArrayMap<String, String>();
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(context, gameMap);
|
||||
|
||||
list = new ArrayList<GameEntity>();
|
||||
isLoaded = false;
|
||||
isNetworkError = false;
|
||||
this.id = id;
|
||||
|
||||
initList(page);
|
||||
}
|
||||
|
||||
public void initList(final int page) {
|
||||
isLoaded =false;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d50/game/column/" + id +"?page="+ page, Constants.GAME_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
processingData(response);
|
||||
}
|
||||
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
if (page == 1){
|
||||
if (subject_pb_loading != null && subject_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
subject_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
subject_list.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
isNetworkError = true;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, SubjectActivity.class);
|
||||
}
|
||||
|
||||
private void processingData(JSONArray response) {
|
||||
Type listType = new TypeToken<ArrayList<GameEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
GameManager manager = new GameManager(context);
|
||||
List<GameEntity> gameList = gson.fromJson(response.toString(), listType);
|
||||
if (gameList != null && !gameList.isEmpty()) {
|
||||
for (GameEntity entity : gameList) {
|
||||
// 黄壮华 初始化游戏状态 修改2015/8/15
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
manager.addOrUpdate(new GameInfo(apkEntity.getPackageName(),
|
||||
entity.getId(), entity.getName()));
|
||||
}
|
||||
}
|
||||
list.addAll(gameList);
|
||||
|
||||
notifyItemRangeInserted(list.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());
|
||||
}
|
||||
}
|
||||
|
||||
if (subject_pb_loading != null && subject_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
subject_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
if (list.isEmpty() || gameList.size() < 20) {
|
||||
isRemove = true;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
isLoaded = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (list.size()<1){
|
||||
return 0;
|
||||
}
|
||||
return list.size()+1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (list.size() == position) {
|
||||
return FOOTER_ITEM;
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
if (i == FOOTER_ITEM){
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.refresh_footerview, viewGroup, false);
|
||||
return new FooterViewHolder(view);
|
||||
}
|
||||
if (list.get(i).getTest() != null) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.home_game_test_item, viewGroup, false);
|
||||
return new GameTestViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.home_game_normal_item, viewGroup, false);
|
||||
return new GameNormalViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||
if (viewHolder instanceof GameNormalViewHolder) {
|
||||
initGameNormalViewHolder((GameNormalViewHolder) viewHolder, position);
|
||||
} else if (viewHolder instanceof GameTestViewHolder) {
|
||||
initGameTestViewHolder((GameTestViewHolder) viewHolder, position);
|
||||
} else if (viewHolder instanceof FooterViewHolder){
|
||||
initFooterViewHolder((FooterViewHolder) viewHolder);
|
||||
}
|
||||
}
|
||||
|
||||
private void initFooterViewHolder(FooterViewHolder viewHolder) {
|
||||
if (isNetworkError) {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.GONE);
|
||||
viewHolder.footerview_tv_loading.setText("加载失败,点击重试");
|
||||
viewHolder.itemView.setClickable(true);
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isNetworkError = false;
|
||||
notifyDataSetChanged();
|
||||
initList(list.size()/per_page+1);
|
||||
}
|
||||
});
|
||||
} else if (isRemove) {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.GONE);
|
||||
viewHolder.footerview_tv_loading.setText("加载完毕");
|
||||
viewHolder.itemView.setClickable(false);
|
||||
} else {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.VISIBLE);
|
||||
viewHolder.footerview_tv_loading.setText("加载中...");
|
||||
viewHolder.itemView.setClickable(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void initGameTestViewHolder(GameTestViewHolder holder, int position) {
|
||||
if (order) {
|
||||
holder.home2_game_order.setVisibility(View.VISIBLE);
|
||||
holder.home2_game_order.setText((position + 1) + "");
|
||||
} else {
|
||||
holder.home2_game_order.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
final GameEntity entity = list.get(position);
|
||||
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(), holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
holder.gameTestType.setText(entity.getTest().getType());
|
||||
if (entity.getTest().getStart() == 0) {
|
||||
holder.gameTestTime.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.gameTestTime.setText(GameViewUtils.getGameTestDate(entity.getTest().getStart()));
|
||||
}
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AppController.put("GameEntity", entity);
|
||||
Intent intent = new Intent(context,
|
||||
GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "主页-新测卡牌");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.downloadBtn.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (entity.getTest().getEnd() == 0) {
|
||||
holder.downloadBtn.setVisibility(View.VISIBLE);
|
||||
DownloadItemUtils.setOnClickListener(context,
|
||||
holder.downloadBtn, holder.download_speed,
|
||||
holder.download_percentage, entity, position,
|
||||
SubjectAdapter.this,
|
||||
statusMap, platformMap, "主页-新测卡牌",
|
||||
dismissEntity, "主页:" + entity.getName());
|
||||
} else {
|
||||
long endTime = Long.valueOf(entity.getTest().getEnd()
|
||||
+ "000");
|
||||
long todayTime = new Date().getTime();
|
||||
if (todayTime > endTime) {
|
||||
// 测试时间已过
|
||||
holder.downloadBtn.setVisibility(View.GONE);
|
||||
} else {
|
||||
// 测试时间未过
|
||||
holder.downloadBtn.setVisibility(View.VISIBLE);
|
||||
DownloadItemUtils.setOnClickListener(context,
|
||||
holder.downloadBtn, holder.download_speed,
|
||||
holder.download_percentage, entity, position,
|
||||
SubjectAdapter.this, statusMap, platformMap,
|
||||
"主页-新测卡牌", dismissEntity,
|
||||
"主页:" + entity.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.game_progressbar, holder.game_ll_info, holder.download_speed,
|
||||
holder.download_percentage, holder.downloadBtn, entity, platformMap,
|
||||
statusMap);
|
||||
}
|
||||
|
||||
private void initGameNormalViewHolder(GameNormalViewHolder holder, int position) {
|
||||
if (order) {
|
||||
holder.home1_game_order.setVisibility(View.VISIBLE);
|
||||
holder.home1_game_order.setText((position + 1) + "");
|
||||
} else {
|
||||
holder.home1_game_order.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
final GameEntity entity = list.get(position);
|
||||
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(), holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
|
||||
GameViewUtils.setLabelList(context, holder.labelList, entity.getTag());
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("入口", "热门卡牌");
|
||||
DataUtils.onEvent(context, "游戏详情", entity.getName(), kv);
|
||||
|
||||
AppController.put("GameEntity", entity);
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "热门卡牌");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
DownloadItemUtils.setOnClickListener(context, holder.downloadBtn,
|
||||
holder.download_speed, holder.download_percentage,
|
||||
entity, position, this,
|
||||
statusMap, platformMap, "热门卡牌", dismissEntity, "hotcard:" + entity.getName());
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.game_progressbar, holder.game_ll_info,
|
||||
holder.download_speed, holder.download_percentage,
|
||||
holder.downloadBtn, entity, platformMap, statusMap);
|
||||
}
|
||||
|
||||
public List<GameEntity> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayMap<String, Integer> getLocationMap() {
|
||||
return locationMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, LinkedBlockingQueue<String>> getPlatformMap() {
|
||||
return platformMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, ArrayMap<String, DownloadEntry>> getGameMap() {
|
||||
return gameMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getNameMap() {
|
||||
return nameMap;
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getStatusMap() {
|
||||
return statusMap;
|
||||
}
|
||||
|
||||
public DismissEntity getDismissEntity() {
|
||||
return dismissEntity;
|
||||
}
|
||||
|
||||
public boolean isLoaded(){
|
||||
return isLoaded;
|
||||
}
|
||||
|
||||
}
|
||||
@ -17,6 +17,7 @@ public class GameHeadViewHolder extends RecyclerView.ViewHolder {
|
||||
public TextView title;
|
||||
public LinearLayout link;
|
||||
public TextView more;
|
||||
public View headTop;
|
||||
|
||||
public GameHeadViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
@ -25,6 +26,7 @@ public class GameHeadViewHolder extends RecyclerView.ViewHolder {
|
||||
this.title = (TextView) itemView.findViewById(R.id.head_title);
|
||||
this.link = (LinearLayout) itemView.findViewById(R.id.head_link);
|
||||
this.more = (TextView) itemView.findViewById(R.id.head_more);
|
||||
this.headTop = itemView.findViewById(R.id.head_top);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -12,11 +12,13 @@ import com.gh.gamecenter.R;
|
||||
public class GameImageViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ImageView image;
|
||||
public View top;
|
||||
|
||||
public GameImageViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
image = (ImageView) itemView.findViewById(R.id.home_game_iv_image);
|
||||
top = itemView.findViewById(R.id.home_game_iv_image_top);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.gh.gamecenter.download;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.Nullable;
|
||||
@ -8,15 +7,12 @@ import android.support.v4.app.Fragment;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnLongClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
@ -200,7 +196,6 @@ public class DownLoadManagerFragment extends Fragment {
|
||||
@Nullable
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
if (container != null) {
|
||||
container.removeView(view);
|
||||
}
|
||||
@ -354,7 +349,7 @@ public class DownLoadManagerFragment extends Fragment {
|
||||
startActivity(PackageUtils
|
||||
.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showUninstallDialog(getActivity(), new DialogUtils.ConfiremListener() {
|
||||
DialogUtils.showPluginDialog(getActivity(), new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
MainActivity.uninstallMap.put(
|
||||
@ -362,7 +357,7 @@ public class DownLoadManagerFragment extends Fragment {
|
||||
startActivity(PackageUtils.getUninstallIntent(getActivity(),
|
||||
path));
|
||||
}
|
||||
});
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -491,11 +486,14 @@ public class DownLoadManagerFragment extends Fragment {
|
||||
downloadmanager_rv_show.getAdapter().notifyItemRemoved(
|
||||
position);
|
||||
}
|
||||
|
||||
EventBus.getDefault().post(
|
||||
new EBDownloadDelete(entry.getName(), entry.getMeta()
|
||||
.get("platform"), entry.getUrl()));
|
||||
|
||||
EBDownloadDelete delete = new EBDownloadDelete(entry.getName(),
|
||||
entry.getMeta().get("platform"), entry.getUrl());
|
||||
String PluginPlatform = entry.getMeta().get("PluginPlatform");
|
||||
if (PluginPlatform != null) {
|
||||
delete.setPluginPlatform(PluginPlatform);
|
||||
}
|
||||
EventBus.getDefault().post(delete);
|
||||
|
||||
DownloadManager.getInstance(getActivity()).cancel(
|
||||
entry.getUrl());
|
||||
}
|
||||
@ -505,35 +503,9 @@ public class DownLoadManagerFragment extends Fragment {
|
||||
|
||||
// 显示插件化
|
||||
private void showPluginDialog(final String path) {
|
||||
final Dialog dialog = new Dialog(getActivity());
|
||||
View view = View.inflate(getActivity(),
|
||||
R.layout.search_history_delete_dialog, null);
|
||||
TextView title = (TextView) view.findViewById(R.id.delete_dialog_title);
|
||||
title.setText("插件化安装");
|
||||
TextView content = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_message);
|
||||
Spanned spanned = Html.fromHtml("您将进行插件化安装以实现插件功能,此过程将"
|
||||
+ "<font color=\"#ff0000\">卸载</font>" + "当前使用的版本并"
|
||||
+ "<font color=\"#ff0000\">安装插件版本</font>" + "。");
|
||||
content.setText(spanned);
|
||||
|
||||
TextView cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_cancel);
|
||||
cancel.setText("取消");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
DialogUtils.showPluginDialog(getActivity(), new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
TextView confirm = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirm.setText("确定");
|
||||
confirm.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
|
||||
public void onConfirem() {
|
||||
for (DownloadEntry downloadEntry : DownloadManager.getInstance(
|
||||
getActivity()).getAll()) {
|
||||
if (downloadEntry.getMeta().get("isPlugin") != null
|
||||
@ -552,11 +524,7 @@ public class DownLoadManagerFragment extends Fragment {
|
||||
startActivity(PackageUtils.getUninstallIntent(getActivity(), path));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}, null);
|
||||
}
|
||||
|
||||
private class DownLoadListAdapter extends
|
||||
|
||||
@ -37,6 +37,16 @@ public class GameEntity {
|
||||
|
||||
private String pluginPlatform;
|
||||
|
||||
private String link;
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
|
||||
public void setLink(String link) {
|
||||
this.link = link;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@ -14,6 +14,8 @@ public class SubjectEntity {
|
||||
|
||||
private String name;
|
||||
|
||||
private String more;
|
||||
|
||||
private boolean order;
|
||||
|
||||
private List<GameEntity> data;
|
||||
@ -34,6 +36,14 @@ public class SubjectEntity {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getMore() {
|
||||
return more;
|
||||
}
|
||||
|
||||
public void setMore(String more) {
|
||||
this.more = more;
|
||||
}
|
||||
|
||||
public boolean getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ public class EBDownloadDelete {
|
||||
private String name;
|
||||
private String platform;
|
||||
private String url;
|
||||
private String PluginPlatform;
|
||||
|
||||
public EBDownloadDelete(String name, String platform, String url) {
|
||||
super();
|
||||
@ -37,4 +38,12 @@ public class EBDownloadDelete {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getPluginPlatform() {
|
||||
return PluginPlatform;
|
||||
}
|
||||
|
||||
public void setPluginPlatform(String pluginPlatform) {
|
||||
PluginPlatform = pluginPlatform;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -13,20 +13,27 @@ import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.SubjectEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadDelete;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPWDismiss;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -41,17 +48,25 @@ import de.greenrobot.event.EventBus;
|
||||
public class Game1Fragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
private View view;
|
||||
private RecyclerView mRecyclerView;
|
||||
private RecyclerView recyclerview;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
private Game1FragmentAdapter adapter;
|
||||
private SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
private ProgressBarCircularIndeterminate mProgressBarCircularIndeterminate;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private ProgressBarCircularIndeterminate game_pb_loading;
|
||||
|
||||
//下载用到的map
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, String> statusMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private ArrayMap<String, String> pluginNameMap;
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
private int currentItem;
|
||||
|
||||
private boolean isEverpause;
|
||||
private boolean isDestroy;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@ -61,8 +76,7 @@ public class Game1Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
if (msg.what == Constants.DOWNLOAD_ROLL) {
|
||||
String name = (String) msg.obj;
|
||||
if (platformMap != null) {
|
||||
LinkedBlockingQueue<String> queue = platformMap
|
||||
.get(name);
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(name);
|
||||
if (queue.size() > 1) {
|
||||
queue.offer(queue.poll());
|
||||
Message msg2 = Message.obtain();
|
||||
@ -81,29 +95,223 @@ public class Game1Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
for (Map.Entry<String, DownloadEntry> entry : downloadingEntries.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
if (!game_swipe_refresh.isRefreshing()) {
|
||||
for (Map.Entry<String, DownloadEntry> entry : downloadingEntries.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
|
||||
Integer location;
|
||||
String PluginPlatform = downloadEntry.getMeta().get("PluginPlatform");
|
||||
if (PluginPlatform != null) {
|
||||
location = locationMap.get(downloadEntry.getName() + " - " + PluginPlatform);
|
||||
} else {
|
||||
location = locationMap.get(downloadEntry.getName());
|
||||
}
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
Integer location = locationMap.get(downloadEntry.getName());
|
||||
if (location != null) {
|
||||
int index = location;
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, platformMap, handler, adapter, index, statusMap);
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, platformMap, handler, adapter, index, statusMap);
|
||||
}
|
||||
}
|
||||
|
||||
//特殊 插件化update
|
||||
if (downloadEntry.getMeta().get("PluginPlatform") != null) {
|
||||
location = locationMap.get(downloadEntry.getName() + " - " + downloadEntry.getMeta().get("PluginPlatform"));
|
||||
if (location != null) {
|
||||
int index = location;
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, platformMap, handler, adapter, index, statusMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.plugin1_fragment, null);
|
||||
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
gameMap = new ArrayMap<String, ArrayMap<String, DownloadEntry>>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
nameMap = new ArrayMap<String, String>();
|
||||
pluginNameMap = new ArrayMap<String, String>();
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
currentItem = 0;
|
||||
|
||||
isEverpause = false;
|
||||
isDestroy = false;
|
||||
|
||||
//初始化gamemap
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
|
||||
reuse_no_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
game_swipe_refresh.setRefreshing(true);
|
||||
recyclerview.setVisibility(View.VISIBLE);
|
||||
game_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
game_swipe_refresh = (SwipeRefreshLayout) view.findViewById(R.id.game_swipe_refresh);
|
||||
game_swipe_refresh.setColorSchemeResources(R.color.theme_colors);
|
||||
game_swipe_refresh.setOnRefreshListener(this);
|
||||
|
||||
game_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.game_pb_loading);
|
||||
|
||||
recyclerview = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
recyclerview.setHasFixedSize(true);
|
||||
recyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
adapter = new Game1FragmentAdapter(Game1Fragment.this, locationMap, gameMap,
|
||||
platformMap, nameMap, pluginNameMap, recyclerview, game_swipe_refresh, reuse_no_connection,
|
||||
statusMap, dismissEntity, game_pb_loading, false);
|
||||
recyclerview.setAdapter(adapter);
|
||||
recyclerview.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if(container != null){
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
//下载被删除事件
|
||||
public void onEventMainThread(EBDownloadDelete busThree) {
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(busThree.getName());
|
||||
if (queue != null) {
|
||||
queue.remove(busThree.getPlatform());
|
||||
platformMap.put(busThree.getName(), queue);
|
||||
}
|
||||
Integer location = locationMap.get(busThree.getName());
|
||||
if (location != null) {
|
||||
int index = location;
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
if (detailedEntity != null) {
|
||||
if (TextUtils.isEmpty(busThree.getPlatform())) {
|
||||
detailedEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
detailedEntity.getEntryMap().remove(busThree.getPlatform());
|
||||
}
|
||||
}
|
||||
adapter.notifyItemChanged(index);
|
||||
}
|
||||
//特殊 插件化update
|
||||
if (busThree.getPluginPlatform() != null) {
|
||||
location = locationMap.get(busThree.getName() + " - " + busThree.getPluginPlatform());
|
||||
int index = location;
|
||||
Utils.log(location);
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
if (detailedEntity != null) {
|
||||
detailedEntity.setEntryMap(null);
|
||||
}
|
||||
adapter.notifyItemChanged(index);
|
||||
}
|
||||
}
|
||||
|
||||
//版本选择框消失事件
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (dismissEntity != null) {
|
||||
dismissEntity.setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = nameMap.get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
Integer location = locationMap.get(name);
|
||||
if (location != null) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity detailedEntity = getEntityByLocation(location);
|
||||
for (ApkEntity apkEntity : detailedEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
detailedEntity.getEntryMap().remove(
|
||||
apkEntity.getPlatform());
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
//特殊 插件化
|
||||
name = pluginNameMap.get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
Integer location = locationMap.get(name);
|
||||
if (location != null) {
|
||||
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())) {
|
||||
list.remove(i);
|
||||
adapter.notifyItemRemoved(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
game_swipe_refresh.setRefreshing(true);
|
||||
recyclerview.setVisibility(View.VISIBLE);
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
} else if (adapter.isNetworkError()) {
|
||||
adapter.setNetworkError(false);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1);
|
||||
adapter.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Fragment界面切换事件
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("MainActivity".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() == 0) {
|
||||
adapter.startAutoScroll();
|
||||
} else {
|
||||
adapter.stopAutoScroll();
|
||||
statusMap.clear();
|
||||
}
|
||||
} else if ("GameFragment".equals(busNine.getFrom())) {
|
||||
currentItem = busNine.getPosition();
|
||||
if (busNine.getPosition() == 0) {
|
||||
adapter.startAutoScroll();
|
||||
if (game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
}
|
||||
} else {
|
||||
adapter.stopAutoScroll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GameEntity getEntityByLocation(int position) {
|
||||
List<GameEntity> pluginList = adapter.getPluginList();
|
||||
List<SubjectEntity> subjectList = adapter.getSubjectList();
|
||||
@ -127,52 +335,52 @@ public class Game1Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.plugin1_fragment, null);
|
||||
|
||||
isDestroy = false;
|
||||
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
mRecyclerView = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
|
||||
mSwipeRefreshLayout = (SwipeRefreshLayout) view
|
||||
.findViewById(R.id.game_swipe_refresh);
|
||||
mSwipeRefreshLayout.setColorSchemeResources(R.color.theme_colors);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
|
||||
mProgressBarCircularIndeterminate = (ProgressBarCircularIndeterminate) view.findViewById(R.id.game_pb_loading);
|
||||
mProgressBarCircularIndeterminate.setVisibility(View.GONE);
|
||||
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
adapter = new Game1FragmentAdapter(getActivity(), locationMap, statusMap,
|
||||
platformMap, dismissEntity, mSwipeRefreshLayout);
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
mRecyclerView.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
//修改游戏下载状态
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
for (SubjectEntity subjectEntity : adapter.getSubjectList()) {
|
||||
for (GameEntity entity :subjectEntity.getData()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
}
|
||||
}
|
||||
for (GameEntity entity : adapter.getPluginList()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
if (currentItem == 0) {
|
||||
adapter.startAutoScroll();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if(container != null){
|
||||
container.removeView(view);
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
statusMap.clear();
|
||||
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
|
||||
if (currentItem == 0) {
|
||||
adapter.stopAutoScroll();
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
public boolean isEverpause() {
|
||||
return isEverpause;
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
if (!isDestroy) {
|
||||
adapter = new Game1FragmentAdapter(Game1Fragment.this, locationMap, gameMap,
|
||||
platformMap, nameMap, pluginNameMap, recyclerview, game_swipe_refresh, reuse_no_connection,
|
||||
statusMap, dismissEntity, game_pb_loading, true);
|
||||
recyclerview.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -181,46 +389,26 @@ public class Game1Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (dismissEntity != null) {
|
||||
dismissEntity.setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBDownloadDelete busThree) {
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(busThree.getName());
|
||||
if (queue != null) {
|
||||
queue.remove(busThree.getPlatform());
|
||||
platformMap.put(busThree.getName(), queue);
|
||||
}
|
||||
Integer location = locationMap.get(busThree.getName());
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
if (TextUtils.isEmpty(busThree.getPlatform())) {
|
||||
detailedEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
detailedEntity.getEntryMap().remove(busThree.getPlatform());
|
||||
}
|
||||
adapter.notifyItemChanged(index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(Game1Fragment.class);
|
||||
EventBus.getDefault().unregister(this);
|
||||
view = null;
|
||||
recyclerview = null;
|
||||
adapter = null;
|
||||
reuse_no_connection = null;
|
||||
game_swipe_refresh = null;
|
||||
game_pb_loading = null;
|
||||
locationMap = null;
|
||||
gameMap = null;
|
||||
platformMap = null;
|
||||
nameMap = null;
|
||||
pluginNameMap = null;
|
||||
statusMap = null;
|
||||
dismissEntity = null;
|
||||
handler = null;
|
||||
dataWatcher = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,133 +2,279 @@ package com.gh.gamecenter.game;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
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.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.SubjectEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadDelete;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPWDismiss;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/6/28.
|
||||
*/
|
||||
public class Game2Fragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
private View view;
|
||||
private RecyclerView mRecyclerView;
|
||||
private Game2FragmentAdapter game2FragmentAdapter;
|
||||
private SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
private ProgressBarCircularIndeterminate mProgressBarCircularIndeterminate;
|
||||
|
||||
private View view;
|
||||
private RecyclerView recyclerview;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
private Game2FragmentAdapter adapter;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private ProgressBarCircularIndeterminate game_pb_loading;
|
||||
|
||||
//下载用到的map
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
private boolean isEverpause = false;
|
||||
DataWatcher dataWatcher = new DataWatcher() {
|
||||
private boolean isEverpause;
|
||||
private boolean isDestroy;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void onDataChanged(HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
for (Map.Entry<String, DownloadEntry> stringDownloadEntryEntry : downloadingEntries.entrySet()) {
|
||||
DownloadEntry value = stringDownloadEntryEntry.getValue();
|
||||
Integer integer = locationMap.get(value.getName());
|
||||
if (integer!=null){
|
||||
int i = integer.intValue();
|
||||
GameEntity gameEntity = initListPosition(i);
|
||||
if (gameEntity != null) {
|
||||
DownloadItemUtils.processDate(gameEntity, value, platformMap, handler, game2FragmentAdapter, i, statusMap);
|
||||
public void handleMessage(Message msg) {
|
||||
if (!isDestroy) {
|
||||
if (msg.what == Constants.DOWNLOAD_ROLL) {
|
||||
String name = (String) msg.obj;
|
||||
if (platformMap != null) {
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(name);
|
||||
if (queue.size() > 1) {
|
||||
queue.offer(queue.poll());
|
||||
Message msg2 = Message.obtain();
|
||||
msg2.obj = name;
|
||||
msg2.what = Constants.DOWNLOAD_ROLL;
|
||||
sendMessageDelayed(msg2, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private GameEntity initListPosition(int position) {
|
||||
List<SubjectEntity> list = game2FragmentAdapter.getList();
|
||||
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 = offset + list.get(i).getData().size();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
if (!game_swipe_refresh.isRefreshing()) {
|
||||
for (Map.Entry<String, DownloadEntry> stringDownloadEntryEntry : downloadingEntries.entrySet()) {
|
||||
DownloadEntry downloadEntry = stringDownloadEntryEntry.getValue();
|
||||
|
||||
Integer location = locationMap.get(downloadEntry.getName());
|
||||
if (location != null) {
|
||||
int index = location;
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, platformMap, handler, adapter, index, statusMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.plugin1_fragment, null);
|
||||
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
gameMap = new ArrayMap<String, ArrayMap<String, DownloadEntry>>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
nameMap = new ArrayMap<String, String>();
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.plugin1_fragment, null);
|
||||
mRecyclerView = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
isEverpause = false;
|
||||
isDestroy = false;
|
||||
|
||||
mSwipeRefreshLayout = (SwipeRefreshLayout) view
|
||||
.findViewById(R.id.game_swipe_refresh);
|
||||
mSwipeRefreshLayout.setColorSchemeResources(R.color.theme_colors);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
//初始化gamemap
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
|
||||
mProgressBarCircularIndeterminate = (ProgressBarCircularIndeterminate) view.findViewById(R.id.game_pb_loading);
|
||||
mProgressBarCircularIndeterminate.setVisibility(View.GONE);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
game2FragmentAdapter = new Game2FragmentAdapter(getActivity(), this,locationMap,gameMap,platformMap,nameMap,statusMap,true,dismissEntity);
|
||||
mRecyclerView.setAdapter(game2FragmentAdapter);
|
||||
reuse_no_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
game_swipe_refresh.setRefreshing(true);
|
||||
recyclerview.setVisibility(View.VISIBLE);
|
||||
game_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
mRecyclerView.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
game_swipe_refresh = (SwipeRefreshLayout) view.findViewById(R.id.game_swipe_refresh);
|
||||
game_swipe_refresh.setColorSchemeResources(R.color.theme_colors);
|
||||
game_swipe_refresh.setOnRefreshListener(this);
|
||||
|
||||
game_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.game_pb_loading);
|
||||
|
||||
recyclerview = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
recyclerview.setHasFixedSize(true);
|
||||
recyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
adapter = new Game2FragmentAdapter(Game2Fragment.this, locationMap, gameMap,
|
||||
platformMap, nameMap, recyclerview, game_swipe_refresh, reuse_no_connection,
|
||||
statusMap, dismissEntity, game_pb_loading, false);
|
||||
recyclerview.setAdapter(adapter);
|
||||
recyclerview.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if (container != null) {
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
//下载被删除事件
|
||||
public void onEventMainThread(EBDownloadDelete busThree) {
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(busThree.getName());
|
||||
if (queue != null) {
|
||||
queue.remove(busThree.getPlatform());
|
||||
platformMap.put(busThree.getName(), queue);
|
||||
}
|
||||
};
|
||||
Integer location = locationMap.get(busThree.getName());
|
||||
if (location != null) {
|
||||
int index = location;
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
if (detailedEntity != null) {
|
||||
if (TextUtils.isEmpty(busThree.getPlatform())) {
|
||||
detailedEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
detailedEntity.getEntryMap().remove(busThree.getPlatform());
|
||||
}
|
||||
}
|
||||
adapter.notifyItemChanged(index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
handler.postDelayed(runnable, 1000);
|
||||
//版本选择框消失事件
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (dismissEntity != null) {
|
||||
dismissEntity.setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = nameMap.get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
Integer location = locationMap.get(name);
|
||||
if (location != null) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity detailedEntity = getEntityByLocation(location);
|
||||
for (ApkEntity apkEntity : detailedEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
detailedEntity.getEntryMap().remove(
|
||||
apkEntity.getPlatform());
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
game_swipe_refresh.setRefreshing(true);
|
||||
recyclerview.setVisibility(View.VISIBLE);
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Fragment界面切换事件
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("MainActivity".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() != 0) {
|
||||
statusMap.clear();
|
||||
}
|
||||
} else if ("GameFragment".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() == 1) {
|
||||
if (game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
//修改游戏下载状态
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
for (SubjectEntity subjectEntity : adapter.getSubectList()) {
|
||||
for (GameEntity entity :subjectEntity.getData()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
}
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@ -139,4 +285,47 @@ public class Game2Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
statusMap.clear();
|
||||
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
public boolean isEverpause() {
|
||||
return isEverpause;
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!isDestroy) {
|
||||
adapter = new Game2FragmentAdapter(Game2Fragment.this, locationMap, gameMap,
|
||||
platformMap, nameMap, recyclerview, game_swipe_refresh, reuse_no_connection,
|
||||
statusMap, dismissEntity, game_pb_loading, true);
|
||||
recyclerview.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(Game2Fragment.class);
|
||||
EventBus.getDefault().unregister(this);
|
||||
view = null;
|
||||
recyclerview = null;
|
||||
adapter = null;
|
||||
reuse_no_connection = null;
|
||||
game_swipe_refresh = null;
|
||||
game_pb_loading = null;
|
||||
locationMap = null;
|
||||
gameMap = null;
|
||||
platformMap = null;
|
||||
nameMap = null;
|
||||
statusMap = null;
|
||||
dismissEntity = null;
|
||||
handler = null;
|
||||
dataWatcher = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,37 +2,45 @@ package com.gh.gamecenter.game;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.NoConnectionError;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.TimeoutError;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.NewsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SubjectActivity;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameHeadViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameImageViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameTestViewHolder;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.SubjectEntity;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
@ -42,112 +50,245 @@ import org.json.JSONArray;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/6/28.
|
||||
*/
|
||||
public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private final static int ITEM_XINCE = 100;//游戏布局2
|
||||
private final static int ITEM = 101;//游戏布局1
|
||||
private final static int ITEM_HEAD = 102;//专题头部
|
||||
private final static int ITEM_PIC = 103;//大图布局
|
||||
private List<SubjectEntity> subjectList = new ArrayList<SubjectEntity>();
|
||||
private Context mContext;
|
||||
|
||||
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;// 大图布局
|
||||
}
|
||||
|
||||
private Game2Fragment fragment;
|
||||
private Context context;
|
||||
|
||||
private RecyclerView recyclerview;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private ProgressBarCircularIndeterminate game_pb_loading;
|
||||
|
||||
private List<SubjectEntity> subjectList;
|
||||
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
public Game2FragmentAdapter(FragmentActivity activity, Game2Fragment game2Fragment, ArrayMap<String, Integer> locationMap
|
||||
, ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap, ArrayMap<String, LinkedBlockingQueue<String>> platformMap
|
||||
, ArrayMap<String, String> nameMap, ArrayMap<String, String> statusMap, boolean b, DismissEntity dismissEntity) {
|
||||
this.mContext = activity;
|
||||
this.locationMap = locationMap;
|
||||
this.gameMap = gameMap;
|
||||
this.platformMap = platformMap;
|
||||
this.nameMap = nameMap;
|
||||
this.statusMap = statusMap;
|
||||
this.dismissEntity = dismissEntity;
|
||||
LoadData2();
|
||||
public Game2FragmentAdapter(Game2Fragment fragment,
|
||||
ArrayMap<String, Integer> lMap,
|
||||
ArrayMap<String, ArrayMap<String, DownloadEntry>> gMap,
|
||||
ArrayMap<String, LinkedBlockingQueue<String>> pMap,
|
||||
ArrayMap<String, String> nMap,
|
||||
RecyclerView rView,
|
||||
SwipeRefreshLayout refreshLayout,
|
||||
LinearLayout linearLayout,
|
||||
ArrayMap<String, String> sMap,
|
||||
DismissEntity dEntity,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
boolean isLoad) {
|
||||
|
||||
this.fragment = fragment;
|
||||
this.context = fragment.getActivity();
|
||||
locationMap = lMap;
|
||||
gameMap = gMap;
|
||||
platformMap = pMap;
|
||||
nameMap = nMap;
|
||||
recyclerview = rView;
|
||||
game_swipe_refresh = refreshLayout;
|
||||
reuse_no_connection = linearLayout;
|
||||
game_pb_loading = pbLoading;
|
||||
statusMap = sMap;
|
||||
dismissEntity = dEntity;
|
||||
|
||||
subjectList = new ArrayList<SubjectEntity>();
|
||||
|
||||
if (isLoad) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData2() {
|
||||
public void load() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
initSubjectList();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void initSubjectList() {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST + "v1d50/game/tuijian",
|
||||
Constants.GAME_CD), new Response.Listener<JSONArray>() {
|
||||
Constants.GAME_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
Type listType = new TypeToken<ArrayList<SubjectEntity>>() {
|
||||
}.getType();
|
||||
Gson gson = new Gson();
|
||||
subjectList = gson.fromJson(response.toString(), listType);
|
||||
notifyDataSetChanged();
|
||||
initLocationMap();
|
||||
}
|
||||
Type listType = new TypeToken<ArrayList<SubjectEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<SubjectEntity> list = gson.fromJson(response.toString(), listType);
|
||||
if (list != null && !list.isEmpty()) {
|
||||
subjectList = list;
|
||||
GameManager manager = new GameManager(context);
|
||||
SubjectEntity subjectEntity;
|
||||
GameEntity gameEntity;
|
||||
for (int j = 0; j < subjectList.size(); j++) {
|
||||
subjectEntity = subjectList.get(j);
|
||||
if (subjectEntity.getData().size() == 1
|
||||
&& !TextUtils.isEmpty(subjectEntity.getData().get(0).getImage())){
|
||||
subjectList.remove(j);
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < subjectEntity.getData().size(); i++) {
|
||||
gameEntity = subjectEntity.getData().get(i);
|
||||
if (gameEntity.getApk() != null && !gameEntity.getApk().isEmpty()) {
|
||||
gameEntity.setEntryMap(gameMap.get(gameEntity.getName()));
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
manager.addOrUpdate(new GameInfo(apkEntity.getPackageName(),
|
||||
gameEntity.getId(), gameEntity.getName()));
|
||||
}
|
||||
} else if (TextUtils.isEmpty(gameEntity.getId())) {
|
||||
if (TextUtils.isEmpty(gameEntity.getType())
|
||||
|| TextUtils.isEmpty(gameEntity.getLink())
|
||||
|| TextUtils.isEmpty(gameEntity.getName())
|
||||
|| TextUtils.isEmpty(gameEntity.getImage())) {
|
||||
subjectEntity.getData().remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
if (!fragment.isHidden() && !fragment.isEverpause()) {
|
||||
notifyItemRangeInserted(0, getItemCount());
|
||||
} else {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
}
|
||||
initLocationMap();
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, GameFragment.class);
|
||||
if (game_swipe_refresh != null && game_swipe_refresh.isRefreshing()) {
|
||||
game_swipe_refresh.setRefreshing(false);
|
||||
}
|
||||
|
||||
if (game_pb_loading != null && game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接和访问超时
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
if (game_swipe_refresh != null && game_swipe_refresh.isRefreshing()) {
|
||||
game_swipe_refresh.setRefreshing(false);
|
||||
}
|
||||
if (game_pb_loading != null && game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
recyclerview.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, Game1Fragment.class);
|
||||
}
|
||||
|
||||
private void initLocationMap() {
|
||||
locationMap.clear();
|
||||
|
||||
int count = 0;
|
||||
if (!subjectList.isEmpty()) {
|
||||
SubjectEntity subjectEntity;
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
subjectEntity = subjectList.get(i);
|
||||
count += 1 + subjectEntity.getData().size();
|
||||
}
|
||||
int count = getItemCount();
|
||||
GameEntity gameEntity;
|
||||
int offset;
|
||||
for (int position = 0; position < count; position++) {
|
||||
int offset = 0;
|
||||
GameEntity gameEntity;
|
||||
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);
|
||||
locationMap.put(gameEntity.getName(), position);
|
||||
if (gameEntity.getApk() != null && !gameEntity.getApk().isEmpty()) {
|
||||
locationMap.put(gameEntity.getName(), position);
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
nameMap.put(apkEntity.getPackageName(), gameEntity.getName());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Utils.log(locationMap.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int subjectSize = 0;
|
||||
if (!subjectList.isEmpty()) {
|
||||
for (int i = 0; i < subjectList.size(); i++) {
|
||||
SubjectEntity subjectEntity = subjectList.get(i);
|
||||
subjectSize += subjectEntity.getData().size() + 1;
|
||||
}
|
||||
}
|
||||
return subjectSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
GameEntity gameEntity;
|
||||
if (!subjectList.isEmpty()) {
|
||||
int offset = 0;
|
||||
GameEntity gameEntity;
|
||||
for (int i = 0; i < subjectList.size(); i++) {
|
||||
if (position == offset) {
|
||||
return ITEM_HEAD;
|
||||
}
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
gameEntity = subjectList.get(i).getData().get(position - offset - 1);
|
||||
if (!TextUtils.isEmpty(gameEntity.getImage())) {
|
||||
return ITEM_PIC;
|
||||
// if (position == offset) {
|
||||
// return ITEM_TYPE.IMAGE;
|
||||
// }
|
||||
// if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
// gameEntity = subjectList.get(i).getData().get(position - offset - 1);
|
||||
// if (position == offset+1&&!TextUtils.isEmpty(gameEntity.getImage())) {
|
||||
// return ITEM_TYPE.HEAD;
|
||||
// }
|
||||
// if (gameEntity.getTest() != null) {
|
||||
// return ITEM_TYPE.GAME_TEST;
|
||||
// }
|
||||
// return ITEM_TYPE.GAME_NORMAL;
|
||||
// }
|
||||
// offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
if (position>=offset && position <= subjectList.get(i).getData().size() + offset){
|
||||
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+1&&!TextUtils.isEmpty(subjectList.get(i).getData().get(0).getImage())){
|
||||
return ITEM_TYPE.HEAD;
|
||||
}
|
||||
if (gameEntity.getTest() != null) {
|
||||
return ITEM_XINCE;
|
||||
return ITEM_TYPE.GAME_TEST;
|
||||
}
|
||||
return ITEM;
|
||||
return ITEM_TYPE.GAME_NORMAL;
|
||||
}
|
||||
offset = offset + subjectList.get(i).getData().size() + 1;
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
@ -155,118 +296,189 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view;
|
||||
switch (viewType) {
|
||||
case ITEM_HEAD:
|
||||
view = LayoutInflater.from(mContext).inflate(R.layout.home_game_head_item, parent, false);
|
||||
return new GameHeadViewHolder(view);
|
||||
case ITEM_PIC:
|
||||
view = LayoutInflater.from(mContext).inflate(R.layout.home_game_image_item, parent, false);
|
||||
return new GameImageViewHolder(view);
|
||||
case ITEM:
|
||||
view = LayoutInflater.from(mContext).inflate(R.layout.home_game_normal_item, parent, false);
|
||||
return new GameNormalViewHolder(view);
|
||||
case ITEM_XINCE:
|
||||
view = LayoutInflater.from(mContext).inflate(R.layout.home_game_test_item, parent, false);
|
||||
return new GameTestViewHolder(view);
|
||||
default:
|
||||
return null;
|
||||
|
||||
|
||||
if (viewType == ITEM_TYPE.HEAD) {
|
||||
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) {
|
||||
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) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.home_game_test_item, parent, false);
|
||||
return new GameTestViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.home_game_normal_item, parent, false);
|
||||
return new GameNormalViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
|
||||
if (holder instanceof GameHeadViewHolder) {
|
||||
GameHeadViewHolder viewHolder = (GameHeadViewHolder) holder;
|
||||
viewHolder.thumb.setVisibility(View.GONE);
|
||||
int offset = 0;
|
||||
for (int i = 0; i < subjectList.size(); i++) {
|
||||
if (position == offset) {
|
||||
viewHolder.title.setText(subjectList.get(i).getName());
|
||||
}
|
||||
offset = offset + subjectList.get(i).getData().size();
|
||||
}
|
||||
initGameHeadViewHolder((GameHeadViewHolder) holder, position);
|
||||
} else if (holder instanceof GameNormalViewHolder) {
|
||||
GameNormalViewHolder viewHolder = (GameNormalViewHolder) holder;
|
||||
int offset = 0;
|
||||
GameEntity gameEntity;
|
||||
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 (TextUtils.isEmpty(gameEntity.getImage()) && gameEntity.getTest() == null) {
|
||||
initGameNormal(viewHolder, gameEntity, position - offset - 1, subjectList.get(i).getOrder());
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
|
||||
initGameNormalViewHolder((GameNormalViewHolder) holder, position);
|
||||
} else if (holder instanceof GameTestViewHolder) {
|
||||
GameTestViewHolder viewHolder = (GameTestViewHolder) holder;
|
||||
int offset = 0;
|
||||
GameEntity gameEntity;
|
||||
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.getTest() != null) {
|
||||
initGameTest(viewHolder, gameEntity, position - offset - 1, subjectList.get(i).getOrder());
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
initGameTestViewHolder((GameTestViewHolder) holder, position);
|
||||
} else if (holder instanceof GameImageViewHolder) {
|
||||
GameImageViewHolder viewHolder = (GameImageViewHolder) holder;
|
||||
int offset = 0;
|
||||
GameEntity gameEntity;
|
||||
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 (!TextUtils.isEmpty(gameEntity.getImage())) {
|
||||
final GameEntity entity = gameEntity;
|
||||
ImageUtils.getInstance(mContext).display(entity.getImage(), viewHolder.image, -1);
|
||||
viewHolder.image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if ("game".equals(entity.getType())) {
|
||||
Intent intent = new Intent(mContext, GameDetailsActivity.class);
|
||||
intent.putExtra("gameId", entity.getId());
|
||||
intent.putExtra("entrance", "插件-大图");
|
||||
mContext.startActivity(intent);
|
||||
} else if ("news".equals(entity.getType())) {
|
||||
Intent intent = new Intent(mContext, NewsActivity.class);
|
||||
intent.putExtra("newsId", entity.getId());
|
||||
intent.putExtra("entrance", "插件-大图");
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
initGameImageViewHolder((GameImageViewHolder) holder, position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initGameTest(GameTestViewHolder holder, GameEntity gameEntity, int i, boolean order) {
|
||||
private void initGameHeadViewHolder(GameHeadViewHolder holder, int position) {
|
||||
int offset = 0;
|
||||
GameEntity gameEntity;
|
||||
for (int i = 0; i < subjectList.size(); i++) {
|
||||
if (position >= offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
int index = position - offset;
|
||||
if (index < 0){
|
||||
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())) {
|
||||
holder.thumb.setVisibility(View.GONE);
|
||||
holder.title.setText(subjectList.get(i).getName());
|
||||
if (TextUtils.isEmpty(subjectList.get(i).getData().get(0).getImage())&&position!=0){
|
||||
holder.headTop.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
holder.headTop.setVisibility(View.GONE);
|
||||
}
|
||||
if (subjectList.get(i).getData().size()>=Integer.parseInt(subjectList.get(i).getMore())){
|
||||
holder.link.setVisibility(View.GONE);
|
||||
}else {
|
||||
holder.link.setVisibility(View.VISIBLE);
|
||||
}
|
||||
final int ii = i;
|
||||
holder.link.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(context, SubjectActivity.class);
|
||||
intent.putExtra("id", subjectList.get(ii).getId());
|
||||
intent.putExtra("name", subjectList.get(ii).getName());
|
||||
intent.putExtra("order",subjectList.get(ii).getOrder());
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void initGameNormalViewHolder(GameNormalViewHolder holder, int position) {
|
||||
int offset = 0;
|
||||
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;
|
||||
if (index<0){
|
||||
index = 0;
|
||||
}
|
||||
gameEntity = subjectList.get(i).getData().get(index);
|
||||
if (TextUtils.isEmpty(gameEntity.getImage()) && gameEntity.getTest() == null) {
|
||||
int order = position - offset - 1;
|
||||
if (subjectList.get(i).getData().get(0).getImage() != null) {
|
||||
order--;
|
||||
}
|
||||
initGameNormal(holder, gameEntity, order, subjectList.get(i).getOrder(), subjectList.get(i).getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void initGameNormal(GameNormalViewHolder holder, GameEntity entity,
|
||||
final int i, boolean order, final String name) {
|
||||
if (order) {
|
||||
holder.home1_game_order.setVisibility(View.VISIBLE);
|
||||
holder.home1_game_order.setText((i + 1) + "");
|
||||
} else {
|
||||
holder.home1_game_order.setVisibility(View.GONE);
|
||||
}
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(), holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
GameViewUtils.setLabelList(context, holder.labelList, entity.getTag());
|
||||
|
||||
final GameEntity gameInfoEntity = entity;
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("名字", gameInfoEntity.getName());
|
||||
kv.put("位置", i + 1);
|
||||
DataUtils.onEvent(context, "点击", "游戏-推荐-" + name, kv);
|
||||
|
||||
AppController.put("GameEntity", gameInfoEntity);
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "游戏-推荐-" + name);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
DownloadItemUtils.setOnClickListener(context, holder.downloadBtn,
|
||||
holder.download_speed, holder.download_percentage, entity, i,
|
||||
Game2FragmentAdapter.this,
|
||||
statusMap, platformMap, "游戏-推荐-" + name,
|
||||
dismissEntity, "游戏-推荐-" + name + ":" + entity.getName());
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.game_progressbar, holder.game_ll_info, holder.download_speed,
|
||||
holder.download_percentage, holder.downloadBtn, entity, platformMap,
|
||||
statusMap);
|
||||
}
|
||||
|
||||
private void initGameTestViewHolder(GameTestViewHolder holder, int position) {
|
||||
int offset = 0;
|
||||
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;
|
||||
if (index < 0){
|
||||
index = 0;
|
||||
}
|
||||
gameEntity = subjectList.get(i).getData().get(index);
|
||||
if (gameEntity.getTest() != null) {
|
||||
int order = position - offset - 1;
|
||||
if (subjectList.get(i).getData().get(0).getImage() != null) {
|
||||
order--;
|
||||
}
|
||||
initGameTest(holder, gameEntity, order, subjectList.get(i).getOrder(), subjectList.get(i).getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void initGameTest(GameTestViewHolder holder, final GameEntity gameEntity,
|
||||
final int i, boolean order, final String name) {
|
||||
if (order) {
|
||||
holder.home2_game_order.setVisibility(View.VISIBLE);
|
||||
holder.home2_game_order.setText(i + "");
|
||||
holder.home2_game_order.setText((i + 1) + "");
|
||||
} else {
|
||||
holder.home2_game_order.setVisibility(View.GONE);
|
||||
}
|
||||
ImageUtils.getInstance(mContext).display(gameEntity.getIcon(),
|
||||
holder.gameThumb);
|
||||
ImageUtils.getInstance(context).display(gameEntity.getIcon(), holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(gameEntity.getName());
|
||||
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(gameEntity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(gameEntity.getApk().get(0).getSize() + " | " + gameEntity.getBrief());
|
||||
holder.gameDes.setText(gameEntity.getApk().get(0).getSize() + " | " + gameEntity.getBrief());
|
||||
}
|
||||
holder.gameTestType.setText(gameEntity.getTest().getType());
|
||||
if (gameEntity.getTest().getStart() == 0) {
|
||||
@ -275,28 +487,36 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
holder.gameTestTime.setText(GameViewUtils.getGameTestDate(gameEntity.getTest().getStart()));
|
||||
}
|
||||
|
||||
final GameEntity entity = gameEntity;
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AppController.put("GameEntity", entity);
|
||||
Intent intent = new Intent(mContext,
|
||||
GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "主页-新测卡牌");
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("名字", gameEntity.getName());
|
||||
kv.put("位置", i + 1);
|
||||
DataUtils.onEvent(context, "点击", "游戏-推荐-" + name, kv);
|
||||
|
||||
AppController.put("GameEntity", gameEntity);
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "游戏-推荐-" + name);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.startActivity(intent);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
|
||||
holder.downloadBtn.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (entity.getTest().getEnd() == 0) {
|
||||
if (gameEntity.getTest().getEnd() == 0) {
|
||||
holder.downloadBtn.setVisibility(View.VISIBLE);
|
||||
|
||||
DownloadItemUtils.setOnClickListener(context,
|
||||
holder.downloadBtn, holder.download_speed,
|
||||
holder.download_percentage, gameEntity, i,
|
||||
Game2FragmentAdapter.this,
|
||||
statusMap, platformMap, "游戏-推荐-" + name,
|
||||
dismissEntity, "游戏-推荐-" + name + ":" + gameEntity.getName());
|
||||
} else {
|
||||
long endTime = Long.valueOf(entity.getTest().getEnd()
|
||||
long endTime = Long.valueOf(gameEntity.getTest().getEnd()
|
||||
+ "000");
|
||||
long todayTime = new Date().getTime();
|
||||
if (todayTime > endTime) {
|
||||
@ -305,69 +525,82 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
} else {
|
||||
// 测试时间未过
|
||||
holder.downloadBtn.setVisibility(View.VISIBLE);
|
||||
|
||||
DownloadItemUtils.setOnClickListener(context,
|
||||
holder.downloadBtn, holder.download_speed,
|
||||
holder.download_percentage, gameEntity, i,
|
||||
Game2FragmentAdapter.this, statusMap, platformMap,
|
||||
"游戏-推荐-" + name, dismissEntity,
|
||||
"游戏-推荐-" + name + ":" + gameEntity.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void initGameNormal(GameNormalViewHolder holder, GameEntity entity, int i, boolean order) {
|
||||
if (order) {
|
||||
holder.home1_game_order.setVisibility(View.VISIBLE);
|
||||
holder.home1_game_order.setText(i + "");
|
||||
} else {
|
||||
holder.home1_game_order.setVisibility(View.GONE);
|
||||
}
|
||||
ImageUtils.getInstance(mContext).display(entity.getIcon(),
|
||||
holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
GameViewUtils.setLabelList(mContext, holder.labelList, entity.getTag());
|
||||
|
||||
final GameEntity gameInfoEntity = entity;
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AppController.put("GameEntity", gameInfoEntity);
|
||||
Intent intent = new Intent(mContext, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "游戏-推荐");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
});
|
||||
DownloadItemUtils.setOnClickListener(mContext, holder.downloadBtn,
|
||||
holder.download_speed, holder.download_percentage, entity, i,
|
||||
Game2FragmentAdapter.this,
|
||||
statusMap, platformMap, "游戏-推荐",
|
||||
dismissEntity, "主页:" + entity.getName());
|
||||
|
||||
DownloadItemUtils.updateItem(mContext, holder.labelList,
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.game_progressbar, holder.game_ll_info, holder.download_speed,
|
||||
holder.download_percentage, holder.downloadBtn, entity, platformMap,
|
||||
holder.download_percentage, holder.downloadBtn, gameEntity, platformMap,
|
||||
statusMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int dataSize = 0;
|
||||
if (!subjectList.isEmpty()) {
|
||||
for (int i = 0; i < subjectList.size(); i++) {
|
||||
SubjectEntity subjectEntity = subjectList.get(i);
|
||||
dataSize += subjectEntity.getData().size() + 1;
|
||||
private void initGameImageViewHolder(GameImageViewHolder holder, int position) {
|
||||
int offset = 0;
|
||||
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;
|
||||
if (index<0){
|
||||
index = 0;
|
||||
}
|
||||
gameEntity = subjectList.get(i).getData().get(index);
|
||||
if (position == offset && !TextUtils.isEmpty(gameEntity.getImage())) {
|
||||
final GameEntity entity = gameEntity;
|
||||
final String name = subjectList.get(i).getName();
|
||||
final int ii = index;
|
||||
if (position == 0){
|
||||
holder.top.setVisibility(View.GONE);
|
||||
}else {
|
||||
holder.top.setVisibility(View.VISIBLE);
|
||||
}
|
||||
ImageUtils.getInstance(context).display(entity.getImage(), holder.image, 1,context);//默认应该设置占位符,防止图片混乱
|
||||
holder.image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("名字", entity.getName());
|
||||
kv.put("位置", ii + 1);
|
||||
DataUtils.onEvent(context, "点击", "游戏-推荐-" + name, kv);
|
||||
|
||||
if (TextUtils.isEmpty(entity.getLink())){
|
||||
Toast.makeText(context, "数据缺失", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if ("game".equals(entity.getType())) {
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("gameId", entity.getLink());
|
||||
intent.putExtra("entrance", "游戏-推荐-" + name);
|
||||
context.startActivity(intent);
|
||||
} else if ("news".equals(entity.getType())) {
|
||||
Intent intent = new Intent(context, NewsActivity.class);
|
||||
intent.putExtra("newsId", entity.getLink());
|
||||
intent.putExtra("entrance", "游戏-推荐-" + name);
|
||||
context.startActivity(intent);
|
||||
} else if ("column".equals(entity.getType())) {
|
||||
Intent intent = new Intent(context, SubjectActivity.class);
|
||||
intent.putExtra("id", entity.getLink());
|
||||
intent.putExtra("name", entity.getName());
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
return dataSize;
|
||||
}
|
||||
|
||||
|
||||
public List<SubjectEntity> getList() {
|
||||
public List<SubjectEntity> getSubectList() {
|
||||
return subjectList;
|
||||
}
|
||||
|
||||
|
||||
@ -34,9 +34,7 @@ import com.gh.gamecenter.eventbus.EBPWDismiss;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
@ -102,7 +100,7 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
|
||||
Integer location = locationMap.get(downloadEntry.getName());
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
int index = location;
|
||||
GameEntity detailedEntity = adapter.getList().get(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
@ -134,20 +132,9 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
isEverpause = false;
|
||||
isDestroy = false;
|
||||
|
||||
game_swipe_refresh = (SwipeRefreshLayout) view.findViewById(R.id.game_swipe_refresh);
|
||||
game_swipe_refresh.setColorSchemeResources(R.color.theme_colors);
|
||||
game_swipe_refresh.setOnRefreshListener(this);
|
||||
|
||||
recyclerview = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
recyclerview.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
recyclerview.setLayoutManager(layoutManager);
|
||||
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
|
||||
game_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.game_pb_loading);
|
||||
|
||||
reuse_no_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -160,6 +147,16 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
}
|
||||
});
|
||||
|
||||
game_swipe_refresh = (SwipeRefreshLayout) view.findViewById(R.id.game_swipe_refresh);
|
||||
game_swipe_refresh.setColorSchemeResources(R.color.theme_colors);
|
||||
game_swipe_refresh.setOnRefreshListener(this);
|
||||
|
||||
game_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.game_pb_loading);
|
||||
|
||||
recyclerview = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
recyclerview.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
recyclerview.setLayoutManager(layoutManager);
|
||||
// 黄壮华 传递引用 修改2015/8/15
|
||||
adapter = new Game3FragmentAdapter(Game3Fragment.this, locationMap,
|
||||
gameMap, platformMap, nameMap, recyclerview,
|
||||
@ -196,6 +193,7 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
return view;
|
||||
}
|
||||
|
||||
//下载被删除事件
|
||||
public void onEventMainThread(EBDownloadDelete busThree) {
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(busThree.getName());
|
||||
if (queue != null) {
|
||||
@ -203,9 +201,8 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
platformMap.put(busThree.getName(), queue);
|
||||
}
|
||||
Integer location = locationMap.get(busThree.getName());
|
||||
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
int index = location;
|
||||
|
||||
GameEntity detailedEntity = adapter.getList().get(index);
|
||||
if (TextUtils.isEmpty(busThree.getPlatform())) {
|
||||
@ -217,12 +214,14 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
}
|
||||
}
|
||||
|
||||
//版本选择框消失事件
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (dismissEntity != null) {
|
||||
dismissEntity.setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = nameMap.get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
@ -242,12 +241,13 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
game_swipe_refresh.setRefreshing(true);
|
||||
recyclerview.setVisibility(View.VISIBLE);
|
||||
game_pb_loading.setVisibility(View.VISIBLE);
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
} else if (adapter.isNetworkError()) {
|
||||
@ -260,12 +260,15 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("MainActivity".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() != 1) {
|
||||
if (busNine.getPosition() != 0) {
|
||||
statusMap.clear();
|
||||
}
|
||||
} else if ("GameFragment".equals(busNine.getFrom()) && busNine.getPosition() == 2
|
||||
&& game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
} else if ("GameFragment".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() == 2) {
|
||||
if (game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -279,12 +282,10 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
if (isEverpause) {
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/20
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
List<GameEntity> entities = new ArrayList<GameEntity>();
|
||||
for (GameEntity entity : adapter.getList()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
entities.add(entity);
|
||||
}
|
||||
adapter.setList(entities);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
@ -301,11 +302,13 @@ public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter = new Game3FragmentAdapter(Game3Fragment.this,
|
||||
locationMap, gameMap, platformMap, nameMap, recyclerview,
|
||||
game_swipe_refresh, reuse_no_connection, statusMap, dismissEntity,
|
||||
game_pb_loading, true);
|
||||
recyclerview.setAdapter(adapter);
|
||||
if (!isDestroy) {
|
||||
adapter = new Game3FragmentAdapter(Game3Fragment.this,
|
||||
locationMap, gameMap, platformMap, nameMap, recyclerview,
|
||||
game_swipe_refresh, reuse_no_connection, statusMap, dismissEntity,
|
||||
game_pb_loading, true);
|
||||
recyclerview.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -57,20 +57,11 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
* @des 首页插件fragment适配器
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-8
|
||||
* @update 2015-8-11
|
||||
* @des 首页插件fragment适配器
|
||||
*/
|
||||
public class Game3FragmentAdapter extends
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context context;
|
||||
|
||||
private Game3Fragment fragment;
|
||||
private Context context;
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
@ -88,7 +79,6 @@ public class Game3FragmentAdapter extends
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
@ -106,14 +96,13 @@ public class Game3FragmentAdapter extends
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
boolean isLoad) {
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
this.fragment = fment;
|
||||
this.context = fment.getActivity();
|
||||
locationMap = lMap;
|
||||
gameMap = gMap;
|
||||
platformMap = pMap;
|
||||
nameMap = nMap;
|
||||
|
||||
statusMap = sMap;
|
||||
|
||||
recyclerView = rView;
|
||||
game_swipe_refresh = swipeRefreshLayout;
|
||||
reuse_no_connection = linearLayout;
|
||||
@ -121,9 +110,6 @@ public class Game3FragmentAdapter extends
|
||||
|
||||
dismissEntity = dEntity;
|
||||
|
||||
fragment = fment;
|
||||
context = fment.getActivity();
|
||||
|
||||
isRemove = false;
|
||||
isLoading = false;
|
||||
isNetworkError = false;
|
||||
@ -136,16 +122,14 @@ public class Game3FragmentAdapter extends
|
||||
}
|
||||
|
||||
public void load() {
|
||||
new Thread(runnable){}.start();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addList(0);
|
||||
}
|
||||
}){}.start();
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addList(0);
|
||||
}
|
||||
};
|
||||
|
||||
public void addList(final int offset) {
|
||||
if (isLoading) {
|
||||
return;
|
||||
@ -173,11 +157,13 @@ public class Game3FragmentAdapter extends
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
if (offset == 0) {
|
||||
if (game_swipe_refresh.isRefreshing()) {
|
||||
if (game_swipe_refresh != null && game_swipe_refresh.isRefreshing()) {
|
||||
game_swipe_refresh.setRefreshing(false);
|
||||
}
|
||||
if (game_pb_loading != null && game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
@ -188,7 +174,7 @@ public class Game3FragmentAdapter extends
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, GameFragment.class);
|
||||
AppController.addToRequestQueue(request, Game3Fragment.class);
|
||||
}
|
||||
|
||||
private void processingData(JSONArray response, int offset) {
|
||||
@ -228,7 +214,7 @@ public class Game3FragmentAdapter extends
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
if (offset == 0 && game_swipe_refresh.isRefreshing()) {
|
||||
if (game_swipe_refresh != null && game_swipe_refresh.isRefreshing()) {
|
||||
game_swipe_refresh.setRefreshing(false);
|
||||
}
|
||||
|
||||
@ -291,14 +277,13 @@ public class Game3FragmentAdapter extends
|
||||
}
|
||||
|
||||
private void initGameNormalViewHolder(GameNormalViewHolder holder, final GameEntity entity, int position) {
|
||||
entity.getApk().get(0).setPlatform("local_plugin");
|
||||
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(),
|
||||
holder.gameThumb);
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(), holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
entity.getApk().get(0).setPlatform("local_plugin");
|
||||
holder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
|
||||
@ -364,11 +349,6 @@ public class Game3FragmentAdapter extends
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<GameEntity> list) {
|
||||
this.list = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public boolean isRemove() {
|
||||
return isRemove;
|
||||
}
|
||||
|
||||
@ -30,7 +30,6 @@ import android.widget.TextView;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.ConcernActivity;
|
||||
import com.gh.gamecenter.DownloadManagerActivity;
|
||||
@ -59,15 +58,31 @@ import de.greenrobot.event.EventBus;
|
||||
public class GameFragment extends Fragment implements OnClickListener,
|
||||
OnPageChangeListener {
|
||||
|
||||
private View view, slideLine;
|
||||
private View view;
|
||||
private View slideLine;
|
||||
private ViewPager viewPager;
|
||||
private TextView jingpinText, zuixinText, danjiText, downloadHint, searchHint;
|
||||
private TextView jingpinText;
|
||||
private TextView zuixinText;
|
||||
private TextView danjiText;
|
||||
private TextView downloadHint;
|
||||
private TextView searchHint;
|
||||
|
||||
private PopupWindow popWindow;
|
||||
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
|
||||
private String hint;
|
||||
|
||||
private int width;
|
||||
private int currentItem;
|
||||
|
||||
private String hint;
|
||||
private Handler handler = new Handler();
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("currentItem", currentItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -79,15 +94,12 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
SharedPreferences sp = getActivity().getSharedPreferences(
|
||||
Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
|
||||
LinearLayout home_actionbar = (LinearLayout) view
|
||||
.findViewById(R.id.home_actionbar);
|
||||
LayoutParams params = new LayoutParams(
|
||||
LayoutParams.MATCH_PARENT, sp.getInt("actionbar_height",
|
||||
DisplayUtils.dip2px(getActivity(), 48)));
|
||||
LinearLayout home_actionbar = (LinearLayout) view.findViewById(R.id.home_actionbar);
|
||||
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
|
||||
sp.getInt("actionbar_height", DisplayUtils.dip2px(getActivity(), 48)));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
int top = DisplayUtils.getInternalDimensionSize(getResources(),
|
||||
"status_bar_height");
|
||||
int top = DisplayUtils.getInternalDimensionSize(getResources(), "status_bar_height");
|
||||
home_actionbar.setPadding(0, top, 0, 0);
|
||||
params.height += top;
|
||||
}
|
||||
@ -96,9 +108,6 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
|
||||
initActionBar();
|
||||
|
||||
viewPager = (ViewPager) view.findViewById(R.id.pager);
|
||||
|
||||
slideLine = view.findViewById(R.id.slide_line);
|
||||
jingpinText = (TextView) view.findViewById(R.id.jingpin_text);
|
||||
zuixinText = (TextView) view.findViewById(R.id.zuixin_text);
|
||||
danjiText = (TextView) view.findViewById(R.id.danji_text);
|
||||
@ -107,24 +116,39 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
zuixinText.setOnClickListener(this);
|
||||
danjiText.setOnClickListener(this);
|
||||
|
||||
slideLine = view.findViewById(R.id.slide_line);
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay()
|
||||
.getMetrics(outMetrics);
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
width = outMetrics.widthPixels / 3;
|
||||
rparams = new RelativeLayout.LayoutParams(width / 2,
|
||||
DisplayUtils.dip2px(getActivity(), 2));
|
||||
rparams.addRule(RelativeLayout.BELOW, R.id.plugin_ll_top);
|
||||
|
||||
viewPager = (ViewPager) view.findViewById(R.id.pager);
|
||||
viewPager.setAdapter(new FragmentAdapter(getChildFragmentManager()));
|
||||
viewPager.addOnPageChangeListener(this);
|
||||
|
||||
rparams.leftMargin = width / 4;
|
||||
slideLine.setLayoutParams(rparams);
|
||||
jingpinText.setClickable(false);
|
||||
zuixinText.setClickable(true);
|
||||
danjiText.setClickable(true);
|
||||
currentItem = 0;
|
||||
if (savedInstanceState != null) {
|
||||
currentItem = savedInstanceState.getInt("currentItem");
|
||||
}
|
||||
viewPager.setCurrentItem(currentItem);
|
||||
|
||||
currentItem = viewPager.getCurrentItem();
|
||||
rparams.leftMargin = width * currentItem + width / 4;
|
||||
slideLine.setLayoutParams(rparams);
|
||||
if (currentItem == 0) {
|
||||
jingpinText.setClickable(false);
|
||||
zuixinText.setClickable(true);
|
||||
danjiText.setClickable(true);
|
||||
} else if (currentItem == 1) {
|
||||
jingpinText.setClickable(true);
|
||||
zuixinText.setClickable(false);
|
||||
danjiText.setClickable(true);
|
||||
} else {
|
||||
jingpinText.setClickable(true);
|
||||
zuixinText.setClickable(true);
|
||||
danjiText.setClickable(false);
|
||||
}
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
@ -136,7 +160,13 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
}, 100);
|
||||
}
|
||||
|
||||
private Handler handler = new Handler();
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
if (container != null) {
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
private void initActionBar() {
|
||||
view.findViewById(R.id.actionbar_rl_download).setOnClickListener(this);
|
||||
@ -144,17 +174,14 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
view.findViewById(R.id.actionbar_iv_search).setOnClickListener(this);
|
||||
|
||||
if (Config.isShow) {
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(
|
||||
View.VISIBLE);
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(
|
||||
View.GONE);
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
downloadHint = (TextView) view.findViewById(R.id.action_tip);
|
||||
int updateSize = PackageManager.getUpdateListSize();
|
||||
int downloadSize = DownloadManager.getInstance(getActivity()).getAll()
|
||||
.size();
|
||||
int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size();
|
||||
if (downloadSize != 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText(downloadSize + "");
|
||||
@ -194,24 +221,14 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
}
|
||||
}
|
||||
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
if (container != null) {
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
private class FragmentAdapter extends FragmentPagerAdapter {
|
||||
|
||||
public FragmentAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
|
||||
if (position == 0) {
|
||||
return new Game1Fragment();
|
||||
} else if (position == 1) {
|
||||
@ -231,13 +248,7 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final int id = v.getId();
|
||||
if (id == R.id.jingpin_text) {
|
||||
viewPager.setCurrentItem(0);
|
||||
} else if (id == R.id.zuixin_text) {
|
||||
viewPager.setCurrentItem(1);
|
||||
} else if (id == R.id.danji_text) {
|
||||
viewPager.setCurrentItem(2);
|
||||
} else if (id == R.id.actionbar_notification) {
|
||||
if (id == R.id.actionbar_notification) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "关注图标");
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
@ -301,68 +312,34 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
|
||||
popUpOverflow(v);
|
||||
} else if (id == R.id.menu_rl_set) {
|
||||
v.setVisibility(View.GONE);
|
||||
popWindow.dismiss();
|
||||
startActivity(new Intent(getActivity(), SettingActivity.class));
|
||||
}
|
||||
}
|
||||
|
||||
public void updateRedDot(int type) {
|
||||
int downloadSize = DownloadManager.getInstance(getActivity()).getAll()
|
||||
.size();
|
||||
if (type == 1 && downloadSize == 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText((downloadSize + type) + "");
|
||||
int width = DisplayUtils.dip2px(getActivity(), 12);
|
||||
RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams(
|
||||
width, width);
|
||||
rparams.topMargin = DisplayUtils.dip2px(getActivity(), 8);
|
||||
rparams.rightMargin = DisplayUtils.dip2px(getActivity(), 2);
|
||||
rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
downloadHint.setLayoutParams(rparams);
|
||||
} else if (type == -1 && (downloadSize == 0 || downloadSize == 1)) {
|
||||
int updateSize = PackageManager.getUpdateList().size();
|
||||
if (updateSize != 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText("");
|
||||
int width = DisplayUtils.dip2px(getActivity(), 10);
|
||||
RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams(
|
||||
width, width);
|
||||
rparams.topMargin = DisplayUtils.dip2px(getActivity(), 8);
|
||||
rparams.rightMargin = DisplayUtils.dip2px(getActivity(), 3);
|
||||
rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
downloadHint.setLayoutParams(rparams);
|
||||
} else {
|
||||
downloadHint.setVisibility(View.GONE);
|
||||
}
|
||||
} else if (downloadSize != 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText((downloadSize + type) + "");
|
||||
} else if (id == R.id.jingpin_text) {
|
||||
viewPager.setCurrentItem(0);
|
||||
} else if (id == R.id.zuixin_text) {
|
||||
viewPager.setCurrentItem(1);
|
||||
} else if (id == R.id.danji_text) {
|
||||
viewPager.setCurrentItem(2);
|
||||
}
|
||||
}
|
||||
|
||||
private void popUpOverflow(View view) {
|
||||
|
||||
Rect frame = new Rect();
|
||||
getActivity().getWindow().getDecorView()
|
||||
.getWindowVisibleDisplayFrame(frame);
|
||||
getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
|
||||
|
||||
int xOffset = DisplayUtils.dip2px(getActivity(), 5);
|
||||
int yOffset = frame.top + DisplayUtils.dip2px(getActivity(), 48)
|
||||
+ xOffset;
|
||||
int yOffset = frame.top + DisplayUtils.dip2px(getActivity(), 48) + xOffset;
|
||||
|
||||
View popView = View.inflate(getActivity(), R.layout.menu_popwindow,
|
||||
null);
|
||||
View popView = View.inflate(getActivity(), R.layout.menu_popwindow, null);
|
||||
popView.findViewById(R.id.menu_rl_set).setOnClickListener(this);
|
||||
PopupWindow popWindow = new PopupWindow(popView,
|
||||
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
|
||||
popWindow = new PopupWindow(popView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
|
||||
|
||||
popWindow.setOutsideTouchable(true);
|
||||
popWindow.setAnimationStyle(android.R.style.Animation_Dialog);
|
||||
popWindow.setBackgroundDrawable(getResources().getDrawable(
|
||||
R.drawable.shape));
|
||||
popWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape));
|
||||
|
||||
popWindow.showAtLocation(view, Gravity.TOP | Gravity.RIGHT, xOffset,
|
||||
yOffset);
|
||||
popWindow.showAtLocation(view, Gravity.TOP | Gravity.RIGHT, xOffset, yOffset);
|
||||
|
||||
}
|
||||
|
||||
@ -401,7 +378,6 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
} else {
|
||||
if (currentItem != viewPager.getCurrentItem()) {
|
||||
currentItem = viewPager.getCurrentItem();
|
||||
Utils.log("currentItem = " + currentItem);
|
||||
EventBus.getDefault().post(new EBUISwitch("GameFragment", currentItem));
|
||||
}
|
||||
}
|
||||
@ -414,7 +390,7 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("MainActivity".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() == 1) {
|
||||
if (busNine.getPosition() == 0) {
|
||||
EventBus.getDefault().post(
|
||||
new EBUISwitch("GameFragment", viewPager.getCurrentItem()));
|
||||
}
|
||||
@ -436,21 +412,49 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
updateRedDot(busEight.getType());
|
||||
}
|
||||
|
||||
public void updateRedDot(int type) {
|
||||
int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size();
|
||||
if (type == 1 && downloadSize == 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText((downloadSize + type) + "");
|
||||
int width = DisplayUtils.dip2px(getActivity(), 12);
|
||||
RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams(width, width);
|
||||
rparams.topMargin = DisplayUtils.dip2px(getActivity(), 8);
|
||||
rparams.rightMargin = DisplayUtils.dip2px(getActivity(), 2);
|
||||
rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
downloadHint.setLayoutParams(rparams);
|
||||
} else if (type == -1 && (downloadSize == 0 || downloadSize == 1)) {
|
||||
int updateSize = PackageManager.getUpdateList().size();
|
||||
if (updateSize != 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText("");
|
||||
int width = DisplayUtils.dip2px(getActivity(), 10);
|
||||
RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams(width, width);
|
||||
rparams.topMargin = DisplayUtils.dip2px(getActivity(), 8);
|
||||
rparams.rightMargin = DisplayUtils.dip2px(getActivity(), 3);
|
||||
rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
downloadHint.setLayoutParams(rparams);
|
||||
} else {
|
||||
downloadHint.setVisibility(View.GONE);
|
||||
}
|
||||
} else if (downloadSize != 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText((downloadSize + type) + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHiddenChanged(boolean hidden) {
|
||||
super.onHiddenChanged(hidden);
|
||||
FragmentTransaction transaction = getChildFragmentManager()
|
||||
.beginTransaction();
|
||||
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
|
||||
List<Fragment> list = getChildFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
if (hidden) {
|
||||
for (Fragment fragment : getChildFragmentManager()
|
||||
.getFragments()) {
|
||||
for (Fragment fragment : getChildFragmentManager().getFragments()) {
|
||||
transaction.hide(fragment);
|
||||
}
|
||||
} else {
|
||||
for (Fragment fragment : getChildFragmentManager()
|
||||
.getFragments()) {
|
||||
for (Fragment fragment : getChildFragmentManager().getFragments()) {
|
||||
transaction.show(fragment);
|
||||
}
|
||||
}
|
||||
@ -472,6 +476,7 @@ public class GameFragment extends Fragment implements OnClickListener,
|
||||
searchHint = null;
|
||||
rparams = null;
|
||||
hint = null;
|
||||
handler = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -863,6 +863,8 @@ public class GameDetailsFragment extends Fragment {
|
||||
kv.put("点击", "新闻攻略");
|
||||
DataUtils.onEvent(getActivity(), "插件数据", gameName, kv);
|
||||
|
||||
//统计阅读量
|
||||
NewsUtils.statNewsViews(newsEntity.getId());
|
||||
NewsUtils.startNewsActivity(getActivity(), newsEntity,
|
||||
entrance + "-游戏详情-详情");
|
||||
}
|
||||
|
||||
@ -457,9 +457,10 @@ public class GameInformationFragment extends Fragment {
|
||||
map.put("news", newsEntity.getTitle());
|
||||
map.put("page", "游戏详情");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
NewsUtils.startNewsActivity(getActivity(), newsEntity, entrance
|
||||
+ "-游戏详情-资讯");
|
||||
|
||||
//统计阅读量
|
||||
NewsUtils.statNewsViews(newsEntity.getId());
|
||||
NewsUtils.startNewsActivity(getActivity(), newsEntity, entrance + "-游戏详情-资讯");
|
||||
}
|
||||
if (v == item_tv_search) {
|
||||
InputMethodManager imm = (InputMethodManager) getActivity()
|
||||
|
||||
@ -465,7 +465,9 @@ public class GameStrategyFragment extends Fragment {
|
||||
map.put("news", newsEntity.getTitle());
|
||||
map.put("page", "游戏详情");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
|
||||
//统计阅读量
|
||||
NewsUtils.statNewsViews(newsEntity.getId());
|
||||
NewsUtils.startNewsActivity(getActivity(), newsEntity, entrance
|
||||
+ "-游戏详情-攻略");
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ public class DataCollectionManager {
|
||||
}
|
||||
|
||||
public static void onEvent(Context context, String type, Map<String, Object> map) {
|
||||
if ("news".equals(type) || "download".equals(type)) {
|
||||
if ("news".equals(type) || "download".equals(type) || "search".equals(type)) {
|
||||
DataCollectionManager.getInstance(context).realTimeUpload(type, map);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -15,6 +15,10 @@ import android.widget.LinearLayout;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/6/29.
|
||||
@ -22,7 +26,6 @@ import com.gh.gamecenter.R;
|
||||
public class News1Fragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
private View view;
|
||||
|
||||
private SwipeRefreshLayout original_swipe_refresh;
|
||||
private RecyclerView original_list;
|
||||
private LinearLayoutManager layoutManager;
|
||||
@ -31,6 +34,7 @@ public class News1Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private boolean isDestroy;
|
||||
private boolean isEverpause;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -39,14 +43,15 @@ public class News1Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
view = View.inflate(getActivity(), R.layout.fragment_original, null);
|
||||
|
||||
isDestroy = false;
|
||||
isEverpause = false;
|
||||
|
||||
original_swipe_refresh = (SwipeRefreshLayout) view.findViewById(R.id.original_swipe_refresh);
|
||||
original_list = (RecyclerView) view.findViewById(R.id.original_list);
|
||||
original_swipe_refresh.setColorSchemeResources(R.color.theme_colors);
|
||||
reuse_no_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
|
||||
original_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.original_pb_loading);
|
||||
original_swipe_refresh.setOnRefreshListener(this);
|
||||
|
||||
original_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.original_pb_loading);
|
||||
|
||||
reuse_no_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -54,14 +59,16 @@ public class News1Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
original_list.setVisibility(View.VISIBLE);
|
||||
original_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
original_list = (RecyclerView) view.findViewById(R.id.original_list);
|
||||
original_list.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
original_list.setLayoutManager(layoutManager);
|
||||
adapter = new News1FragmentAdapter(getActivity(), original_list, original_swipe_refresh,
|
||||
original_pb_loading, reuse_no_connection, true);
|
||||
adapter = new News1FragmentAdapter(News1Fragment.this, original_list, original_swipe_refresh,
|
||||
original_pb_loading, reuse_no_connection, false);
|
||||
original_list.setAdapter(adapter);
|
||||
original_list.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
original_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@ -78,6 +85,7 @@ public class News1Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
}
|
||||
});
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -90,20 +98,76 @@ public class News1Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
return view;
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
original_swipe_refresh.setRefreshing(true);
|
||||
original_list.setVisibility(View.VISIBLE);
|
||||
original_pb_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Fragment界面切换事件
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("NewsFragment".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() == 0) {
|
||||
if (original_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter = new News1FragmentAdapter(getActivity(), original_list, original_swipe_refresh,
|
||||
original_pb_loading, reuse_no_connection, true);
|
||||
original_list.setAdapter(adapter);
|
||||
if (!isDestroy) {
|
||||
adapter = new News1FragmentAdapter(News1Fragment.this, original_list, original_swipe_refresh,
|
||||
original_pb_loading, reuse_no_connection, true);
|
||||
original_list.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
|
||||
public boolean isEverpause() {
|
||||
return isEverpause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
isEverpause = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
EventBus.getDefault().unregister(this);
|
||||
view = null;
|
||||
original_swipe_refresh = null;
|
||||
original_list = null;
|
||||
layoutManager = null;
|
||||
adapter = null;
|
||||
original_pb_loading = null;
|
||||
reuse_no_connection = null;
|
||||
handler = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
package com.gh.gamecenter.news;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -24,6 +22,7 @@ import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.GzipUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
@ -48,13 +47,23 @@ import org.json.JSONObject;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/6/30.
|
||||
*/
|
||||
public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
|
||||
private Activity activity;
|
||||
|
||||
private class ITEM_TYPE {
|
||||
public static final int normal = 0;//正常布局
|
||||
public static final int special1 = 1;//一张1:3图
|
||||
public static final int special2 = 2;//三张4:3图
|
||||
public static final int footer = 3;//页脚
|
||||
}
|
||||
|
||||
private News1Fragment fragment;
|
||||
private Context context;
|
||||
private RecyclerView original_list;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
@ -68,16 +77,16 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
private boolean isLoading;
|
||||
private boolean isRemove;
|
||||
private boolean isNetworkError;
|
||||
// private boolean isLoaded;
|
||||
|
||||
public News1FragmentAdapter(Activity act,
|
||||
public News1FragmentAdapter(News1Fragment fragment,
|
||||
RecyclerView recyclerView,
|
||||
SwipeRefreshLayout swipeRefreshLayout,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
LinearLayout noConnection,
|
||||
boolean isLoad) {
|
||||
activity = act;
|
||||
context = activity;
|
||||
|
||||
this.fragment = fragment;
|
||||
this.context = fragment.getActivity();
|
||||
original_list = recyclerView;
|
||||
game_swipe_refresh = swipeRefreshLayout;
|
||||
game_pb_loading = pbLoading;
|
||||
@ -90,7 +99,6 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
isLoading = false;
|
||||
isRemove = false;
|
||||
isNetworkError = false;
|
||||
// isLoaded = false;
|
||||
|
||||
if (isLoad) {
|
||||
load();
|
||||
@ -98,16 +106,14 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
}
|
||||
|
||||
public void load() {
|
||||
new Thread(runnable){}.start();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addList(0);
|
||||
}
|
||||
}){}.start();
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addList(0);
|
||||
}
|
||||
};
|
||||
|
||||
public void addList(final int offset) {
|
||||
if (isLoading) {
|
||||
return;
|
||||
@ -119,18 +125,23 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
Log.e("URL",url);
|
||||
isLoading = false;
|
||||
|
||||
Type listType = new TypeToken<ArrayList<NewsEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<NewsEntity> list = gson.fromJson(response.toString(), listType);
|
||||
newsList.addAll(list);
|
||||
notifyItemRangeInserted(newsList.size() - list.size(), list.size());
|
||||
|
||||
if (offset == 0 && game_swipe_refresh.isRefreshing()) {
|
||||
if (!fragment.isHidden() && !fragment.isEverpause()) {
|
||||
notifyItemRangeInserted(newsList.size() - list.size(), list.size());
|
||||
} else {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
if (game_swipe_refresh != null && game_swipe_refresh.isRefreshing()) {
|
||||
game_swipe_refresh.setRefreshing(false);
|
||||
}
|
||||
if (game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
if (game_pb_loading != null && game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
if (list.isEmpty() || (offset == 0 && list.size() < 10)) {
|
||||
@ -138,9 +149,6 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
|
||||
// isLoaded = true;
|
||||
// notifyItemChanged(getItemCount() - 1);
|
||||
|
||||
//获取新闻阅读量
|
||||
getNewsViews(list, offset);
|
||||
}
|
||||
@ -152,11 +160,13 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
if (offset == 0) {
|
||||
if (game_swipe_refresh.isRefreshing()) {
|
||||
if (game_swipe_refresh != null && game_swipe_refresh.isRefreshing()) {
|
||||
game_swipe_refresh.setRefreshing(false);
|
||||
}
|
||||
if (game_pb_loading != null && game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
original_list.setVisibility(View.GONE);
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
@ -245,9 +255,15 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("名字", newsEntity.getTitle());
|
||||
kv.put("位置", position + 1);
|
||||
DataUtils.onEvent(context, "点击", "资讯-资讯", kv);
|
||||
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "原创");
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "资讯-资讯");
|
||||
}
|
||||
});
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(0), viewHolder.fm_read_iv_thumb);
|
||||
@ -257,14 +273,14 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.fm_read_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read_ll_read.setVisibility(View.VISIBLE);
|
||||
viewHolder.fm_read_tv_read.setText(views + "次浏览");
|
||||
viewHolder.fm_read_tv_read.setText(views + "");
|
||||
}
|
||||
setType(viewHolder.fm_read_tv_type, newsEntity.getType());
|
||||
}
|
||||
|
||||
private void initNewsImage2ViewHolder(NewsImage2ViewHolder viewHolder, final NewsEntity newsEntity, final int position) {
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
fragment.getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
int width = (outMetrics.widthPixels - 4 * DisplayUtils.dip2px(context, 8)) / 3;
|
||||
int height = (int) (width * 3 / 4f);
|
||||
LinearLayout.LayoutParams lparams1 = new LinearLayout.LayoutParams(width, height);
|
||||
@ -277,9 +293,14 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("名字", newsEntity.getTitle());
|
||||
kv.put("位置", position + 1);
|
||||
DataUtils.onEvent(context, "点击", "资讯-资讯", kv);
|
||||
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "原创");
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "资讯-资讯");
|
||||
}
|
||||
});
|
||||
viewHolder.fm_read2_special2_title.setText(newsEntity.getTitle());
|
||||
@ -294,30 +315,34 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.fm_read2_special2_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read2_special2_ll_read.setVisibility(View.VISIBLE);
|
||||
viewHolder.fm_read2_special2_tv_read.setText(views + "次浏览");
|
||||
viewHolder.fm_read2_special2_tv_read.setText(views + "");
|
||||
}
|
||||
setType(viewHolder.fm_read2_special2_tv_type, newsEntity.getType());
|
||||
}
|
||||
|
||||
private void initNewsImage3ViewHolder(NewsImage3ViewHolder viewHolder, final NewsEntity newsEntity, final int position) {
|
||||
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("名字", newsEntity.getTitle());
|
||||
kv.put("位置", position + 1);
|
||||
DataUtils.onEvent(context, "点击", "资讯-资讯", kv);
|
||||
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "原创");
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "资讯-资讯");
|
||||
}
|
||||
});
|
||||
viewHolder.fm_read2_special1_title.setText(newsEntity.getTitle());
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(0),
|
||||
viewHolder.fm_read2_special1_thumb);
|
||||
viewHolder.fm_read2_special1_thumb,1,context);
|
||||
Integer views = viewsMap.get(newsEntity.getId());
|
||||
if (views == null) {
|
||||
viewHolder.fm_read2_special1_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read2_special1_ll_read.setVisibility(View.VISIBLE);
|
||||
viewHolder.fm_read2_special1_tv_read.setText(views + "次浏览");
|
||||
viewHolder.fm_read2_special1_tv_read.setText(views + "");
|
||||
}
|
||||
setType(viewHolder.fm_read2_special1_tv_type, newsEntity.getType());
|
||||
}
|
||||
@ -339,21 +364,7 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.footerview_progressbar.setVisibility(View.GONE);
|
||||
viewHolder.footerview_tv_loading.setText("加载完毕");
|
||||
viewHolder.itemView.setClickable(false);
|
||||
}
|
||||
// else if (isLoaded) {
|
||||
// viewHolder.footerview_progressbar.setVisibility(View.GONE);
|
||||
// viewHolder.footerview_tv_loading.setText("点击加载更多");
|
||||
// viewHolder.rootView.setClickable(true);
|
||||
// viewHolder.rootView.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// isLoaded = false;
|
||||
// notifyItemChanged(getItemCount() - 1);
|
||||
// addList(newsList.size());
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
else {
|
||||
} else {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.VISIBLE);
|
||||
viewHolder.footerview_tv_loading.setText("加载中...");
|
||||
viewHolder.itemView.setClickable(false);
|
||||
@ -368,15 +379,6 @@ public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
return newsList.size() + 1;
|
||||
}
|
||||
|
||||
class ITEM_TYPE {
|
||||
|
||||
public static final int normal = 0;//正常布局
|
||||
public static final int special1 = 1;//一张1:3图
|
||||
public static final int special2 = 2;//三张4:3图
|
||||
public static final int footer = 3;//页脚
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (position == newsList.size()) {
|
||||
|
||||
@ -15,14 +15,17 @@ import android.widget.LinearLayout;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/6/29.
|
||||
*/
|
||||
public class News2Fragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener{
|
||||
public class News2Fragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
private View view;
|
||||
|
||||
private SwipeRefreshLayout original_swipe_refresh;
|
||||
private RecyclerView original_list;
|
||||
private LinearLayoutManager layoutManager;
|
||||
@ -31,6 +34,7 @@ public class News2Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private boolean isDestroy;
|
||||
private boolean isEverpause;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -39,14 +43,15 @@ public class News2Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
view = View.inflate(getActivity(), R.layout.fragment_original, null);
|
||||
|
||||
isDestroy = false;
|
||||
isEverpause = false;
|
||||
|
||||
original_swipe_refresh = (SwipeRefreshLayout) view.findViewById(R.id.original_swipe_refresh);
|
||||
original_list = (RecyclerView) view.findViewById(R.id.original_list);
|
||||
original_swipe_refresh.setColorSchemeResources(R.color.theme_colors);
|
||||
reuse_no_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
|
||||
original_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.original_pb_loading);
|
||||
original_swipe_refresh.setOnRefreshListener(this);
|
||||
|
||||
original_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.original_pb_loading);
|
||||
|
||||
reuse_no_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -54,14 +59,16 @@ public class News2Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
original_list.setVisibility(View.VISIBLE);
|
||||
original_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
original_list = (RecyclerView) view.findViewById(R.id.original_list);
|
||||
original_list.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
original_list.setLayoutManager(layoutManager);
|
||||
adapter = new News2FragmentAdapter(getActivity(), original_list, original_swipe_refresh,
|
||||
original_pb_loading, reuse_no_connection, true);
|
||||
adapter = new News2FragmentAdapter(News2Fragment.this, original_list, original_swipe_refresh,
|
||||
original_pb_loading, reuse_no_connection, false);
|
||||
original_list.setAdapter(adapter);
|
||||
original_list.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
original_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@ -78,6 +85,7 @@ public class News2Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
}
|
||||
});
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -90,20 +98,76 @@ public class News2Fragment extends Fragment implements SwipeRefreshLayout.OnRefr
|
||||
return view;
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
original_swipe_refresh.setRefreshing(true);
|
||||
original_list.setVisibility(View.VISIBLE);
|
||||
original_pb_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Fragment界面切换事件
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("NewsFragment".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() == 1) {
|
||||
if (original_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter = new News2FragmentAdapter(getActivity(), original_list, original_swipe_refresh,
|
||||
original_pb_loading, reuse_no_connection, true);
|
||||
original_list.setAdapter(adapter);
|
||||
if (!isDestroy) {
|
||||
adapter = new News2FragmentAdapter(News2Fragment.this, original_list, original_swipe_refresh,
|
||||
original_pb_loading, reuse_no_connection, true);
|
||||
original_list.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
|
||||
public boolean isEverpause() {
|
||||
return isEverpause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
isEverpause = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
EventBus.getDefault().unregister(this);
|
||||
view = null;
|
||||
original_swipe_refresh = null;
|
||||
original_list = null;
|
||||
layoutManager = null;
|
||||
adapter = null;
|
||||
original_pb_loading = null;
|
||||
reuse_no_connection = null;
|
||||
handler = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.gh.gamecenter.news;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
@ -23,6 +22,7 @@ import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.GzipUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
@ -47,12 +47,14 @@ import org.json.JSONObject;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/6/3.
|
||||
* Created by khy on 2016/6/30.
|
||||
*/
|
||||
public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
|
||||
|
||||
private class ITEM_TYPE {
|
||||
public static final int normal = 0;//正常布局
|
||||
@ -61,7 +63,7 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
public static final int footer = 3;//页脚
|
||||
}
|
||||
|
||||
private Activity activity;
|
||||
private News2Fragment fragment;
|
||||
private Context context;
|
||||
private RecyclerView original_list;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
@ -75,16 +77,16 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
private boolean isLoading;
|
||||
private boolean isRemove;
|
||||
private boolean isNetworkError;
|
||||
// private boolean isLoaded;
|
||||
|
||||
public News2FragmentAdapter(Activity act,
|
||||
public News2FragmentAdapter(News2Fragment fragment,
|
||||
RecyclerView recyclerView,
|
||||
SwipeRefreshLayout swipeRefreshLayout,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
LinearLayout noConnection,
|
||||
boolean isLoad) {
|
||||
activity = act;
|
||||
context = activity;
|
||||
|
||||
this.fragment = fragment;
|
||||
this.context = fragment.getActivity();
|
||||
original_list = recyclerView;
|
||||
game_swipe_refresh = swipeRefreshLayout;
|
||||
game_pb_loading = pbLoading;
|
||||
@ -97,7 +99,6 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
isLoading = false;
|
||||
isRemove = false;
|
||||
isNetworkError = false;
|
||||
// isLoaded = false;
|
||||
|
||||
if (isLoad) {
|
||||
load();
|
||||
@ -105,16 +106,14 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
}
|
||||
|
||||
public void load() {
|
||||
new Thread(runnable){}.start();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addList(0);
|
||||
}
|
||||
}){}.start();
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addList(0);
|
||||
}
|
||||
};
|
||||
|
||||
public void addList(final int offset) {
|
||||
if (isLoading) {
|
||||
return;
|
||||
@ -127,16 +126,22 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
isLoading = false;
|
||||
|
||||
Type listType = new TypeToken<ArrayList<NewsEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<NewsEntity> list = gson.fromJson(response.toString(), listType);
|
||||
newsList.addAll(list);
|
||||
notifyItemRangeInserted(newsList.size() - list.size(), list.size());
|
||||
|
||||
if (offset == 0 && game_swipe_refresh.isRefreshing()) {
|
||||
if (!fragment.isHidden() && !fragment.isEverpause()) {
|
||||
notifyItemRangeInserted(newsList.size() - list.size(), list.size());
|
||||
} else {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
if (game_swipe_refresh != null && game_swipe_refresh.isRefreshing()) {
|
||||
game_swipe_refresh.setRefreshing(false);
|
||||
}
|
||||
if (game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
if (game_pb_loading != null && game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
if (list.isEmpty() || (offset == 0 && list.size() < 10)) {
|
||||
@ -144,34 +149,33 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
|
||||
// isLoaded = true;
|
||||
// notifyItemChanged(getItemCount() - 1);
|
||||
|
||||
//获取新闻阅读量
|
||||
getNewsViews(list, offset);
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
isLoading = false;
|
||||
// 无网络连接和访问超时
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
if (offset == 0) {
|
||||
if (game_swipe_refresh.isRefreshing()) {
|
||||
game_swipe_refresh.setRefreshing(false);
|
||||
}
|
||||
original_list.setVisibility(View.GONE);
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
isNetworkError = true;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
isLoading = false;
|
||||
// 无网络连接和访问超时
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
if (offset == 0) {
|
||||
if (game_swipe_refresh != null && game_swipe_refresh.isRefreshing()) {
|
||||
game_swipe_refresh.setRefreshing(false);
|
||||
}
|
||||
if (game_pb_loading != null && game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
original_list.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
isNetworkError = true;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, NewsFragment.class);
|
||||
}
|
||||
|
||||
@ -205,38 +209,14 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, NewsFragment.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (newsList.isEmpty()){
|
||||
return 0;
|
||||
}
|
||||
return newsList.size() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (position == newsList.size()) {
|
||||
return ITEM_TYPE.footer;
|
||||
}
|
||||
NewsEntity newsEntity = newsList.get(position);
|
||||
if ("4x3".equals(newsEntity.getThumbnail().getType())
|
||||
&& newsEntity.getThumbnail().getUrl().size() == 3){
|
||||
return ITEM_TYPE.special2;
|
||||
}
|
||||
if ("3x1".equals(newsEntity.getThumbnail().getType())) {
|
||||
return ITEM_TYPE.special1;
|
||||
}
|
||||
return ITEM_TYPE.normal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == ITEM_TYPE.normal) {
|
||||
@ -275,9 +255,14 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("名字", newsEntity.getTitle());
|
||||
kv.put("位置", position + 1);
|
||||
DataUtils.onEvent(context, "点击", "资讯-原创", kv);
|
||||
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "原创");
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "资讯-原创");
|
||||
}
|
||||
});
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(0), viewHolder.fm_read_iv_thumb);
|
||||
@ -287,14 +272,14 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.fm_read_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read_ll_read.setVisibility(View.VISIBLE);
|
||||
viewHolder.fm_read_tv_read.setText(views + "次浏览");
|
||||
viewHolder.fm_read_tv_read.setText(views + "");
|
||||
}
|
||||
setType(viewHolder.fm_read_tv_type, newsEntity.getType());
|
||||
}
|
||||
|
||||
private void initNewsImage2ViewHolder(NewsImage2ViewHolder viewHolder, final NewsEntity newsEntity, final int position) {
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
fragment.getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
int width = (outMetrics.widthPixels - 4 * DisplayUtils.dip2px(context, 8)) / 3;
|
||||
int height = (int) (width * 3 / 4f);
|
||||
LinearLayout.LayoutParams lparams1 = new LinearLayout.LayoutParams(width, height);
|
||||
@ -307,9 +292,14 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("名字", newsEntity.getTitle());
|
||||
kv.put("位置", position + 1);
|
||||
DataUtils.onEvent(context, "点击", "资讯-原创", kv);
|
||||
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "原创");
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "资讯-原创");
|
||||
}
|
||||
});
|
||||
viewHolder.fm_read2_special2_title.setText(newsEntity.getTitle());
|
||||
@ -324,7 +314,7 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.fm_read2_special2_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read2_special2_ll_read.setVisibility(View.VISIBLE);
|
||||
viewHolder.fm_read2_special2_tv_read.setText(views + "次浏览");
|
||||
viewHolder.fm_read2_special2_tv_read.setText(views + "");
|
||||
}
|
||||
setType(viewHolder.fm_read2_special2_tv_type, newsEntity.getType());
|
||||
}
|
||||
@ -333,20 +323,25 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("名字", newsEntity.getTitle());
|
||||
kv.put("位置", position + 1);
|
||||
DataUtils.onEvent(context, "点击", "资讯-原创", kv);
|
||||
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "原创");
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "资讯-原创");
|
||||
}
|
||||
});
|
||||
viewHolder.fm_read2_special1_title.setText(newsEntity.getTitle());
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(0),
|
||||
viewHolder.fm_read2_special1_thumb);
|
||||
viewHolder.fm_read2_special1_thumb,1,context);
|
||||
Integer views = viewsMap.get(newsEntity.getId());
|
||||
if (views == null) {
|
||||
viewHolder.fm_read2_special1_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read2_special1_ll_read.setVisibility(View.VISIBLE);
|
||||
viewHolder.fm_read2_special1_tv_read.setText(views + "次浏览");
|
||||
viewHolder.fm_read2_special1_tv_read.setText(views + "");
|
||||
}
|
||||
setType(viewHolder.fm_read2_special1_tv_type, newsEntity.getType());
|
||||
}
|
||||
@ -368,27 +363,36 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
viewHolder.footerview_progressbar.setVisibility(View.GONE);
|
||||
viewHolder.footerview_tv_loading.setText("加载完毕");
|
||||
viewHolder.itemView.setClickable(false);
|
||||
}
|
||||
// else if (isLoaded) {
|
||||
// viewHolder.footerview_progressbar.setVisibility(View.GONE);
|
||||
// viewHolder.footerview_tv_loading.setText("点击加载更多");
|
||||
// viewHolder.rootView.setClickable(true);
|
||||
// viewHolder.rootView.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// isLoaded = false;
|
||||
// notifyItemChanged(getItemCount() - 1);
|
||||
// addList(newsList.size());
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
else {
|
||||
} else {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.VISIBLE);
|
||||
viewHolder.footerview_tv_loading.setText("加载中...");
|
||||
viewHolder.itemView.setClickable(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (newsList.isEmpty()){
|
||||
return 0;
|
||||
}
|
||||
return newsList.size() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (position == newsList.size()) {
|
||||
return ITEM_TYPE.footer;
|
||||
}
|
||||
NewsEntity newsEntity = newsList.get(position);
|
||||
if ("4x3".equals(newsEntity.getThumbnail().getType()) && newsEntity.getThumbnail().getUrl().size() == 3){
|
||||
return ITEM_TYPE.special2;
|
||||
}
|
||||
if ("3x1".equals(newsEntity.getThumbnail().getType())) {
|
||||
return ITEM_TYPE.special1;
|
||||
}
|
||||
return ITEM_TYPE.normal;
|
||||
}
|
||||
|
||||
private void statNewsViews(final String news_id, final int position) {
|
||||
String url = "http://data.ghzhushou.com/news/stat?news_id=" + news_id;
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
@ -488,5 +492,4 @@ public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
public List<NewsEntity> getNewsList() {
|
||||
return newsList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,17 +6,20 @@ 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;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/6/29.
|
||||
@ -27,7 +30,8 @@ public class News3Fragment extends Fragment {
|
||||
private RecyclerView news_list;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private News3FragmentAdapter adapter;
|
||||
private LinearLayout news_ll_loading, reuse_no_connection;
|
||||
private ProgressBarCircularIndeterminate news_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private TextView news_tv_label;
|
||||
private RelativeLayout news_rl_label;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
@ -38,53 +42,39 @@ public class News3Fragment extends Fragment {
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.fragment_news_or_raiders, null);
|
||||
view = View.inflate(getActivity(), R.layout.fragment_news3, null);
|
||||
|
||||
isDestroy = false;
|
||||
|
||||
news_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.news_pb_loading);
|
||||
|
||||
news_list = (RecyclerView) view.findViewById(R.id.news_list);
|
||||
news_ll_loading = (LinearLayout) view.findViewById(R.id.news_ll_loading);
|
||||
reuse_no_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
|
||||
news_rl_label = (RelativeLayout) view.findViewById(R.id.news_rl_label);
|
||||
news_tv_label = (TextView) view.findViewById(R.id.news_tv_label);
|
||||
|
||||
reuse_no_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
news_list.setVisibility(View.GONE);
|
||||
news_ll_loading.setVisibility(View.VISIBLE);
|
||||
news_list.setVisibility(View.VISIBLE);
|
||||
news_pb_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new News3FragmentAdapter(
|
||||
getActivity(), news_list, news_ll_loading,
|
||||
reuse_no_connection, "攻略", news_rl_label, news_tv_label);
|
||||
adapter = new News3FragmentAdapter(News3Fragment.this, news_list,
|
||||
news_pb_loading, reuse_no_connection, news_rl_label, news_tv_label, true);
|
||||
news_list.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
||||
news_rl_label = (RelativeLayout) view.findViewById(R.id.news_rl_label);
|
||||
rparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
news_list = (RecyclerView) view.findViewById(R.id.news_list);
|
||||
news_list.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager( getActivity());
|
||||
news_list.setLayoutManager(layoutManager);
|
||||
|
||||
adapter = new News3FragmentAdapter(getActivity(), news_list,
|
||||
news_ll_loading, reuse_no_connection, "攻略", news_rl_label,
|
||||
news_tv_label);
|
||||
|
||||
adapter = new News3FragmentAdapter(News3Fragment.this, news_list,
|
||||
news_pb_loading, reuse_no_connection, news_rl_label, news_tv_label, false);
|
||||
news_list.setAdapter(adapter);
|
||||
news_list.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
v.performClick();
|
||||
}
|
||||
if (news_ll_loading.getVisibility() == View.VISIBLE) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
news_list.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
news_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
||||
@Override
|
||||
@ -108,8 +98,7 @@ public class News3Fragment extends Fragment {
|
||||
|
||||
if (position == adapter.getPosition_today() - 1
|
||||
|| position == adapter.getPosition_before() - 1) {
|
||||
int buttom = layoutManager.findViewByPosition(position)
|
||||
.getBottom();
|
||||
int buttom = layoutManager.findViewByPosition(position).getBottom();
|
||||
if (buttom <= news_rl_label.getHeight()) {
|
||||
rparams.topMargin = buttom - news_rl_label.getHeight();
|
||||
news_rl_label.setLayoutParams(rparams);
|
||||
@ -124,19 +113,18 @@ public class News3Fragment extends Fragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView,
|
||||
int newState) {
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (!isDestroy && newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& layoutManager.findLastVisibleItemPosition() + 1 == adapter.getItemCount()) {
|
||||
if (!adapter.isRemove() && !adapter.isLoading() && !adapter.isNetworkError()) {
|
||||
adapter.addList();
|
||||
adapter.addList(adapter.getAllListSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
news_list.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -149,20 +137,31 @@ public class News3Fragment extends Fragment {
|
||||
return view;
|
||||
}
|
||||
|
||||
//Fragment界面切换事件
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("NewsFragment".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() == 2) {
|
||||
if (news_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
news_list.setVisibility(View.GONE);
|
||||
news_ll_loading.setVisibility(View.VISIBLE);
|
||||
news_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new News3FragmentAdapter(getActivity(), news_list,
|
||||
news_ll_loading, reuse_no_connection, "攻略",
|
||||
news_rl_label, news_tv_label);
|
||||
adapter = new News3FragmentAdapter(News3Fragment.this, news_list,
|
||||
news_pb_loading, reuse_no_connection, news_rl_label, news_tv_label, true);
|
||||
news_list.setAdapter(adapter);
|
||||
} else if (adapter.isNetworkError()) {
|
||||
adapter.setNetworkError(false);
|
||||
adapter.notifyItemChanged(adapter.getItemCount());
|
||||
adapter.addList();
|
||||
adapter.addList(adapter.getAllListSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -171,11 +170,12 @@ public class News3Fragment extends Fragment {
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(NewsFragment.class);
|
||||
AppController.canclePendingRequests(News3Fragment.class);
|
||||
EventBus.getDefault().unregister(this);
|
||||
news_list = null;
|
||||
layoutManager = null;
|
||||
adapter = null;
|
||||
news_ll_loading = null;
|
||||
news_pb_loading = null;
|
||||
reuse_no_connection = null;
|
||||
news_tv_label = null;
|
||||
news_rl_label = null;
|
||||
|
||||
@ -10,6 +10,7 @@ import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@ -18,6 +19,7 @@ import com.android.volley.NoConnectionError;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.TimeoutError;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
@ -26,7 +28,6 @@ import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.NewsUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.entity.NewsEntity;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
@ -63,161 +64,168 @@ public class News3FragmentAdapter extends
|
||||
private int position_today = -1;// 今天head的位置
|
||||
private int position_before = -1;// 昨天/以前head的位置
|
||||
|
||||
private News3Fragment fragment;
|
||||
private Context context;
|
||||
|
||||
private RecyclerView news_list;
|
||||
private ProgressBarCircularIndeterminate news_pb_loading;
|
||||
private LinearLayout ll_noconnection;
|
||||
private RelativeLayout news_rl_label;
|
||||
private TextView news_tv_label;
|
||||
|
||||
private List<NewsEntity> todayNewsList;
|
||||
private List<NewsEntity> beforeNewsList;
|
||||
|
||||
private boolean isRemove = false;
|
||||
private boolean isLoading = false;
|
||||
// private boolean isLoaded = false;
|
||||
private boolean isNetworkError = false;
|
||||
private boolean isRemove;
|
||||
private boolean isLoading;
|
||||
private boolean isNetworkError;
|
||||
|
||||
private LayoutInflater layoutInflater;
|
||||
private Context context;
|
||||
public News3FragmentAdapter(News3Fragment fragment,
|
||||
RecyclerView recyclerView,
|
||||
ProgressBarCircularIndeterminate loading,
|
||||
LinearLayout noconnection,
|
||||
RelativeLayout rlabel,
|
||||
TextView tlabel,
|
||||
boolean isLoad) {
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private LinearLayout ll_loading, ll_noconnection;
|
||||
|
||||
private RelativeLayout relativeLayout;
|
||||
private TextView textView;
|
||||
|
||||
private String type;
|
||||
|
||||
public News3FragmentAdapter(Context con, RecyclerView recyclerView,
|
||||
LinearLayout linearLayout1, LinearLayout linearLayout2, String str,
|
||||
RelativeLayout relativeLayout, TextView textView) {
|
||||
context = con;
|
||||
|
||||
type = str;
|
||||
this.fragment = fragment;
|
||||
context = fragment.getActivity();
|
||||
news_list = recyclerView;
|
||||
news_rl_label = rlabel;
|
||||
news_tv_label = tlabel;
|
||||
news_pb_loading = loading;
|
||||
ll_noconnection = noconnection;
|
||||
|
||||
todayNewsList = new ArrayList<NewsEntity>();
|
||||
beforeNewsList = new ArrayList<NewsEntity>();
|
||||
|
||||
this.relativeLayout = relativeLayout;
|
||||
this.textView = textView;
|
||||
isRemove = false;
|
||||
isLoading = false;
|
||||
isNetworkError = false;
|
||||
|
||||
this.recyclerView = recyclerView;
|
||||
ll_loading = linearLayout1;
|
||||
ll_noconnection = linearLayout2;
|
||||
|
||||
this.layoutInflater = LayoutInflater.from(context);
|
||||
|
||||
initDatas();
|
||||
if (isLoad) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
private void showRecyclerView() {
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
ll_loading.setVisibility(View.GONE);
|
||||
public void load() {
|
||||
addList(0);
|
||||
}
|
||||
|
||||
private void initDatas() {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d45/news?type_group=" + Uri.encode(type)
|
||||
+ "&offset=0&limit=20", Constants.NEWS_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
SimpleDateFormat format = new SimpleDateFormat("Mdd",
|
||||
Locale.getDefault());
|
||||
int today = Integer.valueOf(format.format(new Date()));
|
||||
|
||||
Type listType = new TypeToken<ArrayList<NewsEntity>>() {
|
||||
}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<NewsEntity> newsLists = gson.fromJson(
|
||||
response.toString(), listType);
|
||||
int size = newsLists.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
int day = Integer.valueOf(format.format(new Date(
|
||||
Long.valueOf(newsLists.get(i)
|
||||
.getPublishOn() + "000"))));
|
||||
if (day == today) {
|
||||
todayNewsList.add(newsLists.get(i));
|
||||
} else {
|
||||
beforeNewsList.add(newsLists.get(i));
|
||||
}
|
||||
}
|
||||
if (size < 20) {
|
||||
isRemove = true;
|
||||
}
|
||||
refreshCount();
|
||||
showRecyclerView();
|
||||
// isLoaded = true;
|
||||
// notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接和访问超时
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
Toast.makeText(context, "获取" + type + "失败",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
ll_loading.setVisibility(View.GONE);
|
||||
ll_noconnection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, NewsFragment.class);
|
||||
}
|
||||
|
||||
public void addList() {
|
||||
public void addList(final int offset) {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
isLoading = true;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d45/news?type_group=" + Uri.encode(type)
|
||||
+ "&offset=" + getAllListSize() + "&limit=20",
|
||||
Constants.NEWS_CD), new Response.Listener<JSONArray>() {
|
||||
+ "v1d45/news?type_group=" + Uri.encode("攻略")
|
||||
+ "&offset=" + offset + "&limit=20",
|
||||
Constants.NEWS_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
|
||||
Type listType = new TypeToken<ArrayList<NewsEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<NewsEntity> lists = gson.fromJson(response.toString(), listType);
|
||||
if (lists != null) {
|
||||
if (lists.isEmpty()) {
|
||||
isRemove = true;
|
||||
notifyItemRemoved(getItemCount());
|
||||
} else {
|
||||
addDatas(lists);
|
||||
List<NewsEntity> list = gson.fromJson(response.toString(), listType);
|
||||
|
||||
//去重
|
||||
list = removeDuplicate(list);
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("Mdd", Locale.getDefault());
|
||||
int today = Integer.valueOf(format.format(new Date()));
|
||||
|
||||
if (offset == 0) {
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
int day = Integer.valueOf(format.format(new Date(
|
||||
Long.valueOf(list.get(i).getPublishOn() + "000"))));
|
||||
if (day == today) {
|
||||
todayNewsList.add(list.get(i));
|
||||
} else {
|
||||
beforeNewsList.add(list.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
refreshCount();
|
||||
} else {
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
int day = Integer.valueOf(format.format(new Date(Long.valueOf(list
|
||||
.get(i).getPublishOn() + "000"))));
|
||||
if (day == today) {
|
||||
todayNewsList.add(list.get(i));
|
||||
if (todayNewsList.size() == 1) {
|
||||
position_today = 0;
|
||||
notifyItemRangeInserted(0, 2);
|
||||
} else {
|
||||
notifyItemInserted(todayNewsList.size());
|
||||
}
|
||||
} else {
|
||||
beforeNewsList.add(list.get(i));
|
||||
if (beforeNewsList.size() == 1 && position_before == -1) {
|
||||
if (position_today == -1) {
|
||||
position_before = 0;
|
||||
notifyItemRangeInserted(0, 2);
|
||||
} else if (position_today == -1) {
|
||||
position_before = todayNewsList.size() + 1;
|
||||
notifyItemRangeChanged(position_before, 2);
|
||||
}
|
||||
} else {
|
||||
notifyItemInserted(getItemCount() - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (news_pb_loading != null && news_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
news_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (list.size() < 20) {
|
||||
isRemove = true;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
// isLoaded = true;
|
||||
// notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
isLoading = false;
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
isNetworkError = true;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
// 无网络连接和访问超时
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
if (offset == 0) {
|
||||
Toast.makeText(context, "获取攻略失败", Toast.LENGTH_SHORT).show();
|
||||
if (news_pb_loading != null && news_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
news_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
news_list.setVisibility(View.GONE);
|
||||
ll_noconnection.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
isNetworkError = true;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, NewsFragment.class);
|
||||
AppController.addToRequestQueue(request, News3Fragment.class);
|
||||
}
|
||||
|
||||
private void addDatas(List<NewsEntity> datas) {
|
||||
final int dataSize = datas.size();
|
||||
// 去重
|
||||
for (int i = 0; i < datas.size(); i++) {
|
||||
String id = datas.get(i).getId();
|
||||
//去除重复数据
|
||||
private List<NewsEntity> removeDuplicate(List<NewsEntity> list) {
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
String id = list.get(i).getId();
|
||||
final int index = i;
|
||||
|
||||
if (!todayNewsList.isEmpty()) {
|
||||
for (int j = 0; j < todayNewsList.size(); j++) {
|
||||
if (id.equals(todayNewsList.get(j).getId())) {
|
||||
datas.remove(i);
|
||||
list.remove(i);
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
@ -230,7 +238,7 @@ public class News3FragmentAdapter extends
|
||||
if (!beforeNewsList.isEmpty()) {
|
||||
for (int j = 0; j < beforeNewsList.size(); j++) {
|
||||
if (id.equals(beforeNewsList.get(j).getId())) {
|
||||
datas.remove(i);
|
||||
list.remove(i);
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
@ -240,35 +248,7 @@ public class News3FragmentAdapter extends
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dataSize < 20 && datas.size() == 0) {
|
||||
isRemove = true;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("Mdd", Locale.getDefault());
|
||||
int today = Integer.valueOf(format.format(new Date()));
|
||||
|
||||
for (int i = 0, size = datas.size(); i < size; i++) {
|
||||
int day = Integer.valueOf(format.format(new Date(Long.valueOf(datas
|
||||
.get(i).getPublishOn() + "000"))));
|
||||
if (day == today) {
|
||||
todayNewsList.add(datas.get(i));
|
||||
notifyItemInserted(getItemCount() - 2);
|
||||
} else {
|
||||
beforeNewsList.add(datas.get(i));
|
||||
if (beforeNewsList.size() == 1 && position_before == -1) {
|
||||
if (position_today != -1) {
|
||||
position_before = todayNewsList.size() + 1;
|
||||
} else if (position_today == -1) {
|
||||
position_before = 0;
|
||||
}
|
||||
notifyItemRangeChanged(getItemCount() - 2, getItemCount());
|
||||
} else {
|
||||
notifyItemInserted(getItemCount() - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private void refreshCount() {
|
||||
@ -287,15 +267,17 @@ public class News3FragmentAdapter extends
|
||||
position_before = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (position_today != -1) {
|
||||
relativeLayout.setVisibility(View.VISIBLE);
|
||||
textView.setText("今天");
|
||||
textView.setBackgroundResource(R.drawable.title_red);
|
||||
news_rl_label.setVisibility(View.VISIBLE);
|
||||
news_tv_label.setText("今天");
|
||||
news_tv_label.setBackgroundResource(R.drawable.title_red);
|
||||
} else if (position_before != -1) {
|
||||
relativeLayout.setVisibility(View.VISIBLE);
|
||||
textView.setText("昨天/以前");
|
||||
textView.setBackgroundResource(R.drawable.title_gray);
|
||||
news_rl_label.setVisibility(View.VISIBLE);
|
||||
news_tv_label.setText("昨天/以前");
|
||||
news_tv_label.setBackgroundResource(R.drawable.title_gray);
|
||||
}
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@ -348,71 +330,77 @@ public class News3FragmentAdapter extends
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,
|
||||
int viewType) {
|
||||
if (viewType == ITEM_TYPE.head) {
|
||||
return new HeadViewHolder(layoutInflater.inflate(
|
||||
R.layout.news_list_item_category, parent, false));
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.news_list_item_category, parent, false);
|
||||
return new HeadViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.news_image) {
|
||||
return new ImageNewsTypeViewHolder(layoutInflater.inflate(
|
||||
R.layout.home_list_item_newsimage_type, parent, false));
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.home_list_item_newsimage_type, parent, false);
|
||||
return new ImageNewsTypeViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.news_text) {
|
||||
return new TextNewsTypeViewHolder(layoutInflater.inflate(
|
||||
R.layout.home_list_item_newsnormal_type, parent, false),
|
||||
viewType);
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.home_list_item_newsnormal_type, parent, false);
|
||||
return new TextNewsTypeViewHolder(view);
|
||||
} else {
|
||||
return new FooterViewHolder(layoutInflater.inflate(
|
||||
R.layout.refresh_footerview, parent, false));
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.gamedetails_item_loading, parent, false);
|
||||
return new FooterViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder,
|
||||
int position) {
|
||||
if (viewHolder instanceof HeadViewHolder) {
|
||||
((HeadViewHolder) viewHolder).initViewHolder(position, viewHolder);
|
||||
} else if (viewHolder instanceof ImageNewsTypeViewHolder) {
|
||||
((ImageNewsTypeViewHolder) viewHolder).initViewHolder(position);
|
||||
} else if (viewHolder instanceof TextNewsTypeViewHolder) {
|
||||
((TextNewsTypeViewHolder) viewHolder).initViewHolder(position);
|
||||
} else if (viewHolder instanceof FooterViewHolder) {
|
||||
FooterViewHolder holder = (FooterViewHolder) viewHolder;
|
||||
private class FooterViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ProgressBar item_pb_loading;
|
||||
public TextView item_tv_loading;
|
||||
|
||||
public FooterViewHolder(View view) {
|
||||
super(view);
|
||||
|
||||
item_pb_loading = (ProgressBar) view.findViewById(R.id.item_pb_loading);
|
||||
item_tv_loading = (TextView) view.findViewById(R.id.item_tv_loading);
|
||||
}
|
||||
|
||||
public void initFooterViewHolder() {
|
||||
if (isNetworkError) {
|
||||
holder.footerview_progressbar.setVisibility(View.GONE);
|
||||
holder.footerview_tv_loading.setText("加载失败,点击重试");
|
||||
holder.itemView.setClickable(true);
|
||||
holder.itemView.setOnClickListener(new OnClickListener() {
|
||||
item_pb_loading.setVisibility(View.GONE);
|
||||
item_tv_loading.setText("加载失败,点击重试");
|
||||
itemView.setClickable(true);
|
||||
itemView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isNetworkError = false;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
addList();
|
||||
addList(getAllListSize());
|
||||
}
|
||||
});
|
||||
} else if (isRemove) {
|
||||
holder.footerview_progressbar.setVisibility(View.GONE);
|
||||
holder.footerview_tv_loading.setText("加载完毕");
|
||||
holder.itemView.setClickable(false);
|
||||
}
|
||||
// else if (isLoaded) {
|
||||
// holder.footerview_progressbar.setVisibility(View.GONE);
|
||||
// holder.footerview_tv_loading.setText("点击加载更多");
|
||||
// holder.rootView.setClickable(true);
|
||||
// holder.rootView.setOnClickListener(new OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// isLoaded = false;
|
||||
// notifyItemChanged(getItemCount() - 1);
|
||||
// addList();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
else {
|
||||
holder.footerview_progressbar.setVisibility(View.VISIBLE);
|
||||
holder.footerview_tv_loading.setText("加载中...");
|
||||
holder.itemView.setClickable(false);
|
||||
item_pb_loading.setVisibility(View.GONE);
|
||||
item_tv_loading.setText("加载完毕");
|
||||
itemView.setClickable(false);
|
||||
} else {
|
||||
item_pb_loading.setVisibility(View.VISIBLE);
|
||||
item_tv_loading.setText("加载中...");
|
||||
itemView.setClickable(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||
if (viewHolder instanceof HeadViewHolder) {
|
||||
((HeadViewHolder) viewHolder).initViewHolder(position);
|
||||
} else if (viewHolder instanceof ImageNewsTypeViewHolder) {
|
||||
((ImageNewsTypeViewHolder) viewHolder).initViewHolder();
|
||||
} else if (viewHolder instanceof TextNewsTypeViewHolder) {
|
||||
((TextNewsTypeViewHolder) viewHolder).initViewHolder(position);
|
||||
} else if (viewHolder instanceof FooterViewHolder) {
|
||||
((FooterViewHolder) viewHolder).initFooterViewHolder();
|
||||
}
|
||||
}
|
||||
|
||||
private class HeadViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView headType;
|
||||
|
||||
public HeadViewHolder(View v) {
|
||||
@ -420,7 +408,7 @@ public class News3FragmentAdapter extends
|
||||
headType = (TextView) v.findViewById(R.id.tv_label);
|
||||
}
|
||||
|
||||
public void initViewHolder(int position, RecyclerView.ViewHolder viewHolder) {
|
||||
public void initViewHolder(int position) {
|
||||
|
||||
if (position == position_today) {
|
||||
headType.setText("今天");
|
||||
@ -435,19 +423,21 @@ public class News3FragmentAdapter extends
|
||||
}
|
||||
|
||||
public class ImageNewsTypeViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView newsThumb;
|
||||
private TextView newsMainTitle, newsSubTitle;
|
||||
private View rootItem;
|
||||
private TextView newsMainTitle;
|
||||
private TextView newsSubTitle;
|
||||
|
||||
public ImageNewsTypeViewHolder(View v) {
|
||||
super(v);
|
||||
rootItem = v;
|
||||
|
||||
newsThumb = (ImageView) v.findViewById(R.id.news_thumb);
|
||||
newsMainTitle = (TextView) v.findViewById(R.id.news_main_title);
|
||||
newsSubTitle = (TextView) v.findViewById(R.id.news_sub_title);
|
||||
|
||||
}
|
||||
|
||||
public void initViewHolder(int position) {
|
||||
public void initViewHolder() {
|
||||
final NewsEntity newsEntity = todayNewsList.get(0);
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumb(), newsThumb);
|
||||
String title = newsEntity.getTitle();
|
||||
@ -463,23 +453,24 @@ public class News3FragmentAdapter extends
|
||||
newsMainTitle.setText(title);
|
||||
newsSubTitle.setVisibility(View.GONE);
|
||||
}
|
||||
rootItem.setOnClickListener(new OnClickListener() {
|
||||
itemView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("文章类型", newsEntity.getType());
|
||||
kv.put("入口", type + "-今天");
|
||||
DataUtils.onEvent(context, "文章阅读-" + type, newsEntity.getTitle(), kv);
|
||||
kv.put("入口", "攻略-今天");
|
||||
DataUtils.onEvent(context, "资讯-攻略", newsEntity.getTitle(), kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "今天");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("news", newsEntity.getTitle());
|
||||
map.put("page", type);
|
||||
map.put("page", "攻略");
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
NewsUtils.startNewsActivity(context, newsEntity, type
|
||||
+ "-今天");
|
||||
|
||||
//统计阅读量
|
||||
NewsUtils.statNewsViews(newsEntity.getId());
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "资讯-攻略-今天");
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -487,15 +478,12 @@ public class News3FragmentAdapter extends
|
||||
}
|
||||
|
||||
private class TextNewsTypeViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView newsType;
|
||||
public TextView newsTitle;
|
||||
private int column;
|
||||
private View rootItem;
|
||||
|
||||
public TextNewsTypeViewHolder(View v, int column) {
|
||||
public TextNewsTypeViewHolder(View v) {
|
||||
super(v);
|
||||
rootItem = v;
|
||||
this.column = column;
|
||||
newsType = (TextView) v.findViewById(R.id.news_type);
|
||||
newsTitle = (TextView) v.findViewById(R.id.news_title);
|
||||
}
|
||||
@ -503,18 +491,14 @@ public class News3FragmentAdapter extends
|
||||
public void initViewHolder(final int position) {
|
||||
NewsEntity newsEntity = null;
|
||||
String from = null;
|
||||
if (column == ITEM_TYPE.news_text) {
|
||||
if (position > position_today
|
||||
&& position <= todayNewsList.size() + position_today) {
|
||||
newsEntity = todayNewsList.get(position - position_today
|
||||
- 1);
|
||||
from = "今天";
|
||||
} else if (position > position_before
|
||||
&& position <= beforeNewsList.size() + position_before) {
|
||||
newsEntity = beforeNewsList.get(position - position_before
|
||||
- 1);
|
||||
from = "昨天/以前";
|
||||
}
|
||||
if (position > position_today
|
||||
&& position <= todayNewsList.size() + position_today) {
|
||||
newsEntity = todayNewsList.get(position - position_today - 1);
|
||||
from = "今天";
|
||||
} else if (position > position_before
|
||||
&& position <= beforeNewsList.size() + position_before) {
|
||||
newsEntity = beforeNewsList.get(position - position_before - 1);
|
||||
from = "昨天/以前";
|
||||
}
|
||||
if (newsEntity != null) {
|
||||
final NewsEntity entity = newsEntity;
|
||||
@ -523,23 +507,24 @@ public class News3FragmentAdapter extends
|
||||
.getDrawableIdByType(entity.getType()));
|
||||
newsType.setText(entity.getType());
|
||||
newsTitle.setText(entity.getTitle());
|
||||
rootItem.setOnClickListener(new OnClickListener() {
|
||||
itemView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("文章类型", entity.getType());
|
||||
kv.put("入口", type + "-" + entrance);
|
||||
DataUtils.onEvent(context, "文章阅读-" + type, entity.getTitle(), kv);
|
||||
kv.put("入口", "攻略-" + entrance);
|
||||
DataUtils.onEvent(context, "资讯-攻略", entity.getTitle(), kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", entrance);
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("news", entity.getTitle());
|
||||
map.put("page", type);
|
||||
map.put("page", "攻略");
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
NewsUtils.startNewsActivity(context, entity, type + "-"
|
||||
+ entrance);
|
||||
|
||||
//统计阅读量
|
||||
NewsUtils.statNewsViews(entity.getId());
|
||||
NewsUtils.startNewsActivity(context, entity, "资讯-攻略-" + entrance);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -555,10 +540,6 @@ public class News3FragmentAdapter extends
|
||||
return todayNewsList.size();
|
||||
}
|
||||
|
||||
public int getBeforeSize() {
|
||||
return beforeNewsList.size();
|
||||
}
|
||||
|
||||
public int getPosition_today() {
|
||||
return position_today;
|
||||
}
|
||||
@ -579,10 +560,6 @@ public class News3FragmentAdapter extends
|
||||
return isLoading;
|
||||
}
|
||||
|
||||
public void setLoading(boolean isLoading) {
|
||||
this.isLoading = isLoading;
|
||||
}
|
||||
|
||||
public boolean isNetworkError() {
|
||||
return isNetworkError;
|
||||
}
|
||||
|
||||
@ -1,21 +1,28 @@
|
||||
package com.gh.gamecenter.news;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
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;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.ConcernActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/6/29.
|
||||
@ -24,57 +31,49 @@ public class News4Fragment extends Fragment {
|
||||
|
||||
private View view;
|
||||
private RecyclerView news_list;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private News4FragmentAdapter adapter;
|
||||
private LinearLayout news_ll_loading, reuse_no_connection;
|
||||
|
||||
private boolean isDestroy;
|
||||
private ProgressBarCircularIndeterminate news_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private TextView news_tv_none;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.fragment_news_or_raiders, null);
|
||||
view = View.inflate(getActivity(), R.layout.fragment_news3, null);
|
||||
|
||||
news_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.news_pb_loading);
|
||||
|
||||
news_tv_none = (TextView) view.findViewById(R.id.news_tv_none);
|
||||
news_tv_none.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(getActivity(), ConcernActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
news_list = (RecyclerView) view.findViewById(R.id.news_list);
|
||||
news_ll_loading = (LinearLayout) view.findViewById(R.id.news_ll_loading);
|
||||
reuse_no_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
|
||||
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
news_list.setVisibility(View.GONE);
|
||||
news_ll_loading.setVisibility(View.VISIBLE);
|
||||
news_list.setVisibility(View.VISIBLE);
|
||||
news_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new News4FragmentAdapter(getActivity(), news_list,
|
||||
news_ll_loading, reuse_no_connection);
|
||||
news_pb_loading, reuse_no_connection, news_tv_none, true);
|
||||
news_list.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
||||
news_list = (RecyclerView) view.findViewById(R.id.news_list);
|
||||
news_list.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager( getActivity());
|
||||
news_list.setLayoutManager(layoutManager);
|
||||
|
||||
news_list.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
adapter = new News4FragmentAdapter(getActivity(), news_list,
|
||||
news_ll_loading, reuse_no_connection);
|
||||
|
||||
news_pb_loading, reuse_no_connection, news_tv_none, false);
|
||||
news_list.setAdapter(adapter);
|
||||
news_list.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
v.performClick();
|
||||
}
|
||||
if (news_ll_loading.getVisibility() == View.VISIBLE) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
news_list.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -87,18 +86,36 @@ public class News4Fragment extends Fragment {
|
||||
return view;
|
||||
}
|
||||
|
||||
//关注改变事件
|
||||
public void onEventMainThread(EBConcernChanged busSeven) {
|
||||
adapter.updateMyGameNews();
|
||||
adapter.update();
|
||||
}
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
adapter.update();
|
||||
}
|
||||
|
||||
//Fragment界面切换事件
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("NewsFragment".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() == 3) {
|
||||
if (news_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
news_list.setVisibility(View.GONE);
|
||||
news_ll_loading.setVisibility(View.VISIBLE);
|
||||
news_list.setVisibility(View.VISIBLE);
|
||||
news_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new News4FragmentAdapter(getActivity(), news_list,
|
||||
news_ll_loading, reuse_no_connection);
|
||||
news_pb_loading, reuse_no_connection, news_tv_none, true);
|
||||
news_list.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
@ -107,12 +124,12 @@ public class News4Fragment extends Fragment {
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(NewsFragment.class);
|
||||
AppController.canclePendingRequests(News4Fragment.class);
|
||||
EventBus.getDefault().unregister(this);
|
||||
view = null;
|
||||
news_list = null;
|
||||
layoutManager = null;
|
||||
adapter = null;
|
||||
news_ll_loading = null;
|
||||
news_pb_loading = null;
|
||||
reuse_no_connection = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,12 +11,10 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.NoConnectionError;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.TimeoutError;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
@ -66,50 +64,65 @@ public class News4FragmentAdapter extends
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
public static class ITEM_TYPE {
|
||||
public static final int game_type = 1;// 游戏布局类型
|
||||
public static final int game_text = 2;// 游戏新闻列表类型
|
||||
public static final int refresh_footer = 3;// 刷新布局类型
|
||||
public static final int GAME = 1;// 游戏布局类型
|
||||
public static final int NEWS = 2;// 游戏新闻列表类型
|
||||
public static final int FOOTER = 3;// 刷新布局类型
|
||||
}
|
||||
|
||||
private int count_game = 0;// 游戏+游戏新闻 的数目
|
||||
private Context context;
|
||||
|
||||
private RecyclerView news_list;
|
||||
private ProgressBarCircularIndeterminate news_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private TextView news_tv_none;
|
||||
|
||||
private ConcernManager concernManager;
|
||||
private List<ConcernInfo> concernList;
|
||||
private List<GameEntity> concernGameList;
|
||||
private ArrayMap<String, List<NewsEntity>> concernNewsMap;
|
||||
|
||||
private boolean isNetworkError = false;
|
||||
private ConcernManager concernManager;
|
||||
|
||||
private LayoutInflater layoutInflater;
|
||||
private Context context;
|
||||
private int count_game;// 游戏+游戏新闻 的数目
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private LinearLayout ll_loading, ll_noconnection;
|
||||
|
||||
public News4FragmentAdapter(Context con, RecyclerView recyclerView,
|
||||
LinearLayout linearLayout1, LinearLayout linearLayout2) {
|
||||
public News4FragmentAdapter(Context con,
|
||||
RecyclerView recyclerView,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
LinearLayout linearLayout,
|
||||
TextView textView,
|
||||
boolean isLoad) {
|
||||
context = con;
|
||||
|
||||
this.recyclerView = recyclerView;
|
||||
ll_loading = linearLayout1;
|
||||
ll_noconnection = linearLayout2;
|
||||
news_list = recyclerView;
|
||||
news_pb_loading = pbLoading;
|
||||
reuse_no_connection = linearLayout;
|
||||
news_tv_none = textView;
|
||||
|
||||
concernManager = new ConcernManager(context);
|
||||
this.layoutInflater = LayoutInflater.from(context);
|
||||
concernGameList = new ArrayList<GameEntity>();
|
||||
concernNewsMap = new ArrayMap<String, List<NewsEntity>>();
|
||||
|
||||
// 获取关注的信息
|
||||
concernList = concernManager.getAllConcernBySort();
|
||||
concernList = new ArrayList<ConcernInfo>();
|
||||
|
||||
if (concernList != null && !concernList.isEmpty()) {
|
||||
sortList();
|
||||
initConcernNews();
|
||||
} else {
|
||||
refreshCount();
|
||||
showRecyclerView();
|
||||
count_game = 0;
|
||||
|
||||
if (isLoad) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
private void sortList() {
|
||||
public void load() {
|
||||
// 获取关注的信息
|
||||
concernList = concernManager.getAllConcernBySort();
|
||||
if (concernList != null && !concernList.isEmpty()) {
|
||||
sortList(concernList);
|
||||
initGameNews();
|
||||
} else {
|
||||
news_list.setVisibility(View.GONE);
|
||||
news_pb_loading.setVisibility(View.GONE);
|
||||
news_tv_none.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void sortList(List<ConcernInfo> list) {
|
||||
Comparator<ConcernInfo> comparator = new Comparator<ConcernInfo>() {
|
||||
@Override
|
||||
public int compare(ConcernInfo lhs, ConcernInfo rhs) {
|
||||
@ -131,30 +144,130 @@ public class News4FragmentAdapter extends
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
Collections.sort(concernList, comparator);
|
||||
Collections.sort(list, comparator);
|
||||
}
|
||||
|
||||
public void updateMyGameNews() {
|
||||
ll_loading.setVisibility(View.VISIBLE);
|
||||
concernList = concernManager.getAllConcernBySort();
|
||||
if (concernList != null && !concernList.isEmpty()) {
|
||||
sortList();
|
||||
initConcernNews();
|
||||
} else {
|
||||
ll_loading.setVisibility(View.GONE);
|
||||
refreshCount();
|
||||
private int count;
|
||||
|
||||
private void initGameNews() {
|
||||
final List<ConcernInfo> cList = new ArrayList<ConcernInfo>();
|
||||
count = 0;
|
||||
final int size = concernList.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
final int index = i;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(
|
||||
Config.HOST + "v1d45/game/" + concernList.get(i).getId()
|
||||
+ "/news?limit=3&offset=0", Constants.NEWS_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<ArrayList<NewsEntity>>() {}.getType();
|
||||
List<NewsEntity> list = gson.fromJson(response.toString(), listType);
|
||||
if (list != null && !list.isEmpty()) {
|
||||
cList.add(concernList.get(index));
|
||||
concernNewsMap.put(concernList.get(index).getGameName(), list);
|
||||
}
|
||||
count++;
|
||||
if (count == size) {
|
||||
refresh(cList);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
count++;
|
||||
if (count == size) {
|
||||
refresh(cList);
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, News4Fragment.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void showRecyclerView() {
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
ll_loading.setVisibility(View.GONE);
|
||||
private void refresh(List<ConcernInfo> list) {
|
||||
if (list.isEmpty()) {
|
||||
news_list.setVisibility(View.GONE);
|
||||
news_pb_loading.setVisibility(View.GONE);
|
||||
news_tv_none.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
concernList = list;
|
||||
List<String> ids = new ArrayList<String>();
|
||||
for (int i = 0; i < concernList.size(); i++) {
|
||||
ids.add(concernList.get(i).getId());
|
||||
}
|
||||
news_list.setVisibility(View.VISIBLE);
|
||||
news_pb_loading.setVisibility(View.GONE);
|
||||
refreshCount();
|
||||
initGame(ids);
|
||||
}
|
||||
}
|
||||
|
||||
private void initGame(List<String> ids) {
|
||||
count = 0;
|
||||
final int size = ids.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST + "v1d45/game/"
|
||||
+ ids.get(i) + "/digest", Constants.GAME_CD),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
if (gameEntity != null) {
|
||||
concernGameList.add(gameEntity);
|
||||
}
|
||||
count++;
|
||||
if (count == size) {
|
||||
processingGameData();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
count++;
|
||||
if (count == size) {
|
||||
processingGameData();
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, News4Fragment.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void processingGameData() {
|
||||
if (!concernGameList.isEmpty()) {
|
||||
List<GameEntity> list = new ArrayList<GameEntity>();
|
||||
for (int i = 0, size = concernList.size(); i < size; i++) {
|
||||
String id = concernList.get(i).getId();
|
||||
for (GameEntity gameEntity : concernGameList) {
|
||||
if (gameEntity.getId().equals(id)) {
|
||||
list.add(gameEntity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
concernGameList = list;
|
||||
GameManager manager = new GameManager(context);
|
||||
for (int i = 0, size = concernGameList.size(); i < size; i++) {
|
||||
for (ApkEntity apkEntity : concernGameList.get(i).getApk()) {
|
||||
manager.addOrUpdate(new GameInfo(apkEntity.getPackageName(),
|
||||
concernGameList.get(i).getId(), concernGameList.get(i).getName()));
|
||||
}
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
SuspectedGameManager manager = new SuspectedGameManager(context);
|
||||
List<SuspectedGameInfo> list = manager.getAllGame();
|
||||
if (list != null && !list.isEmpty()) {
|
||||
ll_loading.setVisibility(View.VISIBLE);
|
||||
news_pb_loading.setVisibility(View.VISIBLE);
|
||||
List<String> params = new ArrayList<String>();
|
||||
for (SuspectedGameInfo entity : list) {
|
||||
params.add(entity.getPackageName());
|
||||
@ -163,10 +276,8 @@ public class News4FragmentAdapter extends
|
||||
}
|
||||
}
|
||||
|
||||
private int iCount;
|
||||
|
||||
private void initSuspectedGame(final List<String> params) {
|
||||
iCount = 0;
|
||||
count = 0;
|
||||
final List<JSONObject> list = new ArrayList<JSONObject>();
|
||||
final List<String> useParams = new ArrayList<String>();
|
||||
for (int i = 0, size = params.size(); i < size; i++) {
|
||||
@ -179,12 +290,12 @@ public class News4FragmentAdapter extends
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
iCount++;
|
||||
count++;
|
||||
if (response.length() != 0) {
|
||||
list.add(response);
|
||||
useParams.add(packageName);
|
||||
}
|
||||
if (params.size() == iCount) {
|
||||
if (params.size() == count) {
|
||||
processingData(list, params, useParams);
|
||||
}
|
||||
}
|
||||
@ -192,10 +303,10 @@ public class News4FragmentAdapter extends
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
iCount++;
|
||||
if (params.size() == iCount) {
|
||||
count++;
|
||||
if (params.size() == count) {
|
||||
if (list.isEmpty()) {
|
||||
ll_loading.setVisibility(View.GONE);
|
||||
news_pb_loading.setVisibility(View.GONE);
|
||||
} else {
|
||||
processingData(list, params, useParams);
|
||||
}
|
||||
@ -219,146 +330,31 @@ public class News4FragmentAdapter extends
|
||||
manager.updateByEntity(gameEntity, false);
|
||||
}
|
||||
|
||||
SuspectedGameManager suspectedGameManager = new SuspectedGameManager(
|
||||
context);
|
||||
SuspectedGameManager suspectedGameManager = new SuspectedGameManager(context);
|
||||
for (String packageName : params) {
|
||||
suspectedGameManager.deleteSuspectedGame(packageName);
|
||||
}
|
||||
|
||||
if (data.size() > 0) {
|
||||
updateMyGameNews();
|
||||
update();
|
||||
} else {
|
||||
ll_loading.setVisibility(View.GONE);
|
||||
news_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private int count;
|
||||
|
||||
private void initConcernNews() {
|
||||
final List<ConcernInfo> cList = new ArrayList<ConcernInfo>();
|
||||
concernNewsMap = new ArrayMap<String, List<NewsEntity>>();
|
||||
count = concernList.size();
|
||||
for (int i = 0, size = concernList.size(); i < size; i++) {
|
||||
final int index = i;
|
||||
final int finalI = i;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(
|
||||
Config.HOST + "v1d45/game/"
|
||||
+ concernList.get(i).getId()
|
||||
+ "/news?limit=3&offset=0", Constants.NEWS_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<ArrayList<NewsEntity>>() {
|
||||
}.getType();
|
||||
List<NewsEntity> list = gson.fromJson(
|
||||
response.toString(), listType);
|
||||
if (list != null && !list.isEmpty()) {
|
||||
cList.add(concernList.get(index));
|
||||
concernNewsMap.put(concernList.get(index)
|
||||
.getGameName(), list);
|
||||
}
|
||||
refresh(cList);
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接和网络超时
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
ll_loading.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, NewsFragment.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void refresh(List<ConcernInfo> cList) {
|
||||
if (count != 1) {
|
||||
count--;
|
||||
public void update() {
|
||||
news_pb_loading.setVisibility(View.VISIBLE);
|
||||
concernList = concernManager.getAllConcernBySort();
|
||||
if (concernList != null && !concernList.isEmpty()) {
|
||||
sortList(concernList);
|
||||
initGameNews();
|
||||
} else {
|
||||
concernList = cList;
|
||||
if (!concernList.isEmpty()) {
|
||||
List<String> ids = new ArrayList<String>();
|
||||
for (int i = 0; i < concernList.size(); i++) {
|
||||
ids.add(concernList.get(i).getId());
|
||||
}
|
||||
initConcernDatas(ids);
|
||||
} else {
|
||||
refreshCount();
|
||||
showRecyclerView();
|
||||
}
|
||||
news_list.setVisibility(View.GONE);
|
||||
news_pb_loading.setVisibility(View.GONE);
|
||||
news_tv_none.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void initConcernDatas(List<String> ids) {
|
||||
final List<JSONObject> result = new ArrayList<JSONObject>();
|
||||
final int count = ids.size();
|
||||
for (int i = 0, size = ids.size(); i < size; i++) {
|
||||
JsonObjectExtendedRequest gameObjectRequest = new JsonObjectExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST + "v1d45/game/"
|
||||
+ ids.get(i) + "/digest", Constants.GAME_CD),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
result.add(response);
|
||||
if (result.size() == count) {
|
||||
processingConcernData(result);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接和网络超时
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
refreshCount();
|
||||
showRecyclerView();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(gameObjectRequest, NewsFragment.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void processingConcernData(List<JSONObject> data) {
|
||||
Gson gson = new Gson();
|
||||
concernGameList = new ArrayList<GameEntity>();
|
||||
for (int i = 0, size = data.size(); i < size; i++) {
|
||||
JSONObject response = data.get(i);
|
||||
concernGameList.add(gson.fromJson(response.toString(),
|
||||
GameEntity.class));
|
||||
}
|
||||
if (concernGameList != null && !concernGameList.isEmpty()) {
|
||||
List<GameEntity> list = new ArrayList<GameEntity>();
|
||||
for (int i = 0, size = concernList.size(); i < size; i++) {
|
||||
String id = concernList.get(i).getId();
|
||||
for (GameEntity gameEntity : concernGameList) {
|
||||
if (gameEntity.getId().equals(id)) {
|
||||
list.add(gameEntity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
concernGameList = list;
|
||||
GameManager manager = new GameManager(context);
|
||||
for (int i = 0, size = concernGameList.size(); i < size; i++) {
|
||||
for (ApkEntity apkEntity : concernGameList.get(i).getApk()) {
|
||||
manager.addOrUpdate(new GameInfo(apkEntity.getPackageName(),
|
||||
concernGameList.get(i).getId(), concernGameList
|
||||
.get(i).getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
refreshCount();
|
||||
showRecyclerView();
|
||||
}
|
||||
|
||||
private void refreshCount() {
|
||||
|
||||
count_game = 0;
|
||||
@ -394,30 +390,33 @@ public class News4FragmentAdapter extends
|
||||
concernList.get(j).getGameName()).size() + 1);
|
||||
}
|
||||
if (position == offset) {
|
||||
return ITEM_TYPE.game_type;
|
||||
return ITEM_TYPE.GAME;
|
||||
} else if (position > offset
|
||||
&& position <= concernNewsMap.get(
|
||||
concernList.get(i).getGameName()).size()
|
||||
+ offset) {
|
||||
return ITEM_TYPE.game_text;
|
||||
return ITEM_TYPE.NEWS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ITEM_TYPE.refresh_footer;
|
||||
return ITEM_TYPE.FOOTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == ITEM_TYPE.game_type) {
|
||||
return new GameNormalViewHolder(layoutInflater.inflate(
|
||||
R.layout.news_list_item_gamenormal_type, parent, false));
|
||||
} else if (viewType == ITEM_TYPE.game_text) {
|
||||
return new TextNewsTypeViewHolder(layoutInflater.inflate(
|
||||
R.layout.home_list_item_newsnormal_type, parent, false), viewType);
|
||||
if (viewType == ITEM_TYPE.GAME) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.news_list_item_gamenormal_type, parent, false);
|
||||
return new GameNormalViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.NEWS) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.home_list_item_newsnormal_type, parent, false);
|
||||
return new TextNewsTypeViewHolder(view);
|
||||
} else {
|
||||
return new FooterViewHolder(layoutInflater.inflate(
|
||||
R.layout.refresh_footerview, parent, false));
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.refresh_footerview, parent, false);
|
||||
return new FooterViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@ -431,6 +430,10 @@ public class News4FragmentAdapter extends
|
||||
FooterViewHolder holder = (FooterViewHolder) viewHolder;
|
||||
holder.footerview_progressbar.setVisibility(View.GONE);
|
||||
holder.footerview_tv_loading.setText("管理我的关注");
|
||||
holder.footerview_tv_loading.setBackgroundResource(R.drawable.border_blue_bg);
|
||||
int i = (int) (context.getResources().getDisplayMetrics().density * 5);
|
||||
holder.footerview_tv_loading.setPadding(i,i,i,i);
|
||||
holder.footerview_tv_loading.setTextColor(0xff1BA4FC);
|
||||
holder.itemView.setClickable(true);
|
||||
holder.itemView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
@ -442,17 +445,19 @@ public class News4FragmentAdapter extends
|
||||
}
|
||||
|
||||
private class GameNormalViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ImageView gameThumb;
|
||||
public TextView gameName;
|
||||
public LinearLayout labelList;
|
||||
private View rootItem;
|
||||
public ImageView gameInfo;
|
||||
|
||||
public GameNormalViewHolder(View v) {
|
||||
super(v);
|
||||
this.rootItem = v;
|
||||
|
||||
gameThumb = (ImageView) v.findViewById(R.id.news_game_thumb);
|
||||
gameName = (TextView) v.findViewById(R.id.news_game_name);
|
||||
labelList = (LinearLayout) v.findViewById(R.id.news_label_list);
|
||||
gameInfo = (ImageView) v.findViewById(R.id.gamenormal_game_info);
|
||||
}
|
||||
|
||||
public void initViewHolder(int position) {
|
||||
@ -464,11 +469,10 @@ public class News4FragmentAdapter extends
|
||||
concernList.get(j).getGameName()).size() + 1);
|
||||
}
|
||||
if (position == offset) {
|
||||
if (concernGameList == null) {
|
||||
if (concernGameList.isEmpty()) {
|
||||
init(concernList.get(i));
|
||||
} else {
|
||||
init(concernGameList.get(i), concernList.get(i)
|
||||
.getTag());
|
||||
init(concernGameList.get(i), concernList.get(i).getTag());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -476,14 +480,13 @@ public class News4FragmentAdapter extends
|
||||
}
|
||||
|
||||
private void init(ConcernInfo concernEntity) {
|
||||
ImageUtils.getInstance(context).display(concernEntity.getIcon(),
|
||||
gameThumb);
|
||||
ImageUtils.getInstance(context).display(concernEntity.getIcon(), gameThumb);
|
||||
gameName.setText(concernEntity.getGameName());
|
||||
String tag = concernEntity.getTag();
|
||||
if (tag != null) {
|
||||
GameViewUtils.setLabelList(context, labelList, tag);
|
||||
}
|
||||
rootItem.setOnClickListener(new OnClickListener() {
|
||||
itemView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
@ -497,7 +500,7 @@ public class News4FragmentAdapter extends
|
||||
if (tag != null) {
|
||||
GameViewUtils.setLabelList(context, labelList, tag);
|
||||
}
|
||||
rootItem.setOnClickListener(new OnClickListener() {
|
||||
itemView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
@ -513,9 +516,9 @@ public class News4FragmentAdapter extends
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
AppController.put("GameEntity", entry);
|
||||
Intent intent = new Intent(context,
|
||||
GameDetailsActivity.class);
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "关注-我的游戏");
|
||||
intent.putExtra("current", 1);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
@ -524,15 +527,13 @@ public class News4FragmentAdapter extends
|
||||
}
|
||||
|
||||
private class TextNewsTypeViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView newsType;
|
||||
public TextView newsTitle;
|
||||
private int column;
|
||||
private View rootItem;
|
||||
|
||||
public TextNewsTypeViewHolder(View v, int column) {
|
||||
public TextNewsTypeViewHolder(View v) {
|
||||
super(v);
|
||||
rootItem = v;
|
||||
this.column = column;
|
||||
|
||||
newsType = (TextView) v.findViewById(R.id.news_type);
|
||||
newsTitle = (TextView) v.findViewById(R.id.news_title);
|
||||
}
|
||||
@ -540,24 +541,18 @@ public class News4FragmentAdapter extends
|
||||
public void initViewHolder(final int position) {
|
||||
NewsEntity newsEntity = null;
|
||||
String from = null;
|
||||
if (column == ITEM_TYPE.game_text) {
|
||||
if (position >= 0 && position < count_game) {
|
||||
for (int i = 0, size = concernList.size(); i < size; i++) {
|
||||
int offset = 0;
|
||||
for (int j = 0; j < i; j++) {
|
||||
offset += (concernNewsMap.get(
|
||||
concernList.get(j).getGameName()).size() + 1);
|
||||
}
|
||||
if (position > offset
|
||||
&& position <= concernNewsMap.get(
|
||||
concernList.get(i).getGameName())
|
||||
.size()
|
||||
+ offset) {
|
||||
newsEntity = concernNewsMap.get(
|
||||
concernList.get(i).getGameName()).get(
|
||||
position - offset - 1);
|
||||
from = "我的游戏";
|
||||
}
|
||||
if (position >= 0 && position < count_game) {
|
||||
for (int i = 0, size = concernList.size(); i < size; i++) {
|
||||
int offset = 0;
|
||||
for (int j = 0; j < i; j++) {
|
||||
offset += (concernNewsMap.get(
|
||||
concernList.get(j).getGameName()).size() + 1);
|
||||
}
|
||||
if (position > offset && position <= concernNewsMap.get(
|
||||
concernList.get(i).getGameName()).size() + offset) {
|
||||
newsEntity = concernNewsMap.get(
|
||||
concernList.get(i).getGameName()).get(position - offset - 1);
|
||||
from = "我的游戏";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -568,13 +563,13 @@ public class News4FragmentAdapter extends
|
||||
.getDrawableIdByType(entity.getType()));
|
||||
newsType.setText(entity.getType());
|
||||
newsTitle.setText(entity.getTitle());
|
||||
rootItem.setOnClickListener(new OnClickListener() {
|
||||
itemView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("文章类型", entity.getType());
|
||||
kv.put("入口", "关注-" + entrance);
|
||||
DataUtils.onEvent(context, "文章阅读-关注", entity.getTitle(), kv);
|
||||
DataUtils.onEvent(context, "资讯-关注", entity.getTitle(), kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", entrance);
|
||||
@ -583,7 +578,9 @@ public class News4FragmentAdapter extends
|
||||
map.put("page", "关注");
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
NewsUtils.startNewsActivity(context, entity, "关注-" + entrance);
|
||||
//统计阅读量
|
||||
NewsUtils.statNewsViews(entity.getId());
|
||||
NewsUtils.startNewsActivity(context, entity, "资讯-关注-" + entrance);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -591,11 +588,4 @@ public class News4FragmentAdapter extends
|
||||
|
||||
}
|
||||
|
||||
public boolean isNetworkError() {
|
||||
return isNetworkError;
|
||||
}
|
||||
|
||||
public void setNetworkError(boolean isNetworkError) {
|
||||
this.isNetworkError = isNetworkError;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,10 +6,12 @@ import android.content.SharedPreferences;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
@ -25,7 +27,6 @@ import android.widget.TextView;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.ConcernActivity;
|
||||
import com.gh.gamecenter.DownloadManagerActivity;
|
||||
@ -40,6 +41,7 @@ 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 de.greenrobot.event.EventBus;
|
||||
@ -48,11 +50,18 @@ import de.greenrobot.event.EventBus;
|
||||
* Created by khy on 2016/6/29.
|
||||
*/
|
||||
public class NewsFragment extends Fragment implements View.OnClickListener, ViewPager.OnPageChangeListener {
|
||||
|
||||
private View view;
|
||||
private ViewPager mViewPager;
|
||||
private TextView tvZixun, tvYuanchuang, tvGonglve, tvGuanzhu;
|
||||
private TextView downloadHint, searchHint;
|
||||
private View slideLine;
|
||||
private ViewPager viewPager;
|
||||
private TextView tvZixun;
|
||||
private TextView tvYuanchuang;
|
||||
private TextView tvGonglve;
|
||||
private TextView tvGuanzhu;
|
||||
private TextView downloadHint;
|
||||
private TextView searchHint;
|
||||
|
||||
private PopupWindow popWindow;
|
||||
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
|
||||
@ -61,7 +70,13 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View
|
||||
private int width;
|
||||
private int currentItem;
|
||||
|
||||
private PopupWindow popWindow;
|
||||
private Handler handler = new Handler();
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("currentItem", currentItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -87,10 +102,15 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View
|
||||
|
||||
initActionBar();
|
||||
|
||||
tvGonglve = (TextView) view.findViewById(R.id.gonglue_text);
|
||||
tvGuanzhu = (TextView) view.findViewById(R.id.guanzhu_text);
|
||||
tvZixun = (TextView) view.findViewById(R.id.zixun_text);
|
||||
tvYuanchuang = (TextView) view.findViewById(R.id.yuanchuang_text);
|
||||
tvGonglve = (TextView) view.findViewById(R.id.gonglue_text);
|
||||
tvGuanzhu = (TextView) view.findViewById(R.id.guanzhu_text);
|
||||
|
||||
tvZixun.setOnClickListener(this);
|
||||
tvYuanchuang.setOnClickListener(this);
|
||||
tvGonglve.setOnClickListener(this);
|
||||
tvGuanzhu.setOnClickListener(this);
|
||||
|
||||
slideLine = view.findViewById(R.id.slide_line);
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
@ -101,25 +121,59 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View
|
||||
DisplayUtils.dip2px(getActivity(), 2));
|
||||
rparams.addRule(RelativeLayout.BELOW, R.id.plugin_ll_top);
|
||||
|
||||
tvZixun.setOnClickListener(this);
|
||||
tvYuanchuang.setOnClickListener(this);
|
||||
tvGonglve.setOnClickListener(this);
|
||||
tvGuanzhu.setOnClickListener(this);
|
||||
viewPager = (ViewPager) view.findViewById(R.id.news_vp);
|
||||
viewPager.setAdapter(new FragmentAdapter(getChildFragmentManager()));
|
||||
viewPager.addOnPageChangeListener(this);
|
||||
|
||||
mViewPager = (ViewPager) view.findViewById(R.id.news_vp);
|
||||
mViewPager.setAdapter(new MyFragmentPagerAdapter(getChildFragmentManager()));
|
||||
mViewPager.addOnPageChangeListener(this);
|
||||
currentItem = 0;
|
||||
if (savedInstanceState != null) {
|
||||
currentItem = savedInstanceState.getInt("currentItem");
|
||||
}
|
||||
viewPager.setCurrentItem(currentItem);
|
||||
|
||||
rparams.leftMargin = width / 4;
|
||||
rparams.leftMargin = width * currentItem + width / 4;
|
||||
slideLine.setLayoutParams(rparams);
|
||||
tvZixun.setClickable(false);
|
||||
tvYuanchuang.setClickable(true);
|
||||
tvGonglve.setClickable(true);
|
||||
tvGuanzhu.setClickable(true);
|
||||
|
||||
currentItem = mViewPager.getCurrentItem();
|
||||
if (currentItem == 0) {
|
||||
tvZixun.setClickable(false);
|
||||
tvYuanchuang.setClickable(true);
|
||||
tvGonglve.setClickable(true);
|
||||
tvGuanzhu.setClickable(true);
|
||||
} else if (currentItem == 1) {
|
||||
tvZixun.setClickable(true);
|
||||
tvYuanchuang.setClickable(false);
|
||||
tvGonglve.setClickable(true);
|
||||
tvGuanzhu.setClickable(true);
|
||||
} else if (currentItem == 2) {
|
||||
tvZixun.setClickable(true);
|
||||
tvYuanchuang.setClickable(true);
|
||||
tvGonglve.setClickable(false);
|
||||
tvGuanzhu.setClickable(true);
|
||||
} else if (currentItem == 3) {
|
||||
tvZixun.setClickable(true);
|
||||
tvYuanchuang.setClickable(true);
|
||||
tvGonglve.setClickable(true);
|
||||
tvGuanzhu.setClickable(false);
|
||||
}
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
EventBus.getDefault().post(new EBUISwitch("NewsFragment", viewPager.getCurrentItem()));
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if (container != null){
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
private void initActionBar() {
|
||||
@ -128,17 +182,14 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View
|
||||
view.findViewById(R.id.actionbar_iv_search).setOnClickListener(this);
|
||||
|
||||
if (Config.isShow) {
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(
|
||||
View.VISIBLE);
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(
|
||||
View.GONE);
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
downloadHint = (TextView) view.findViewById(R.id.action_tip);
|
||||
int updateSize = PackageManager.getUpdateListSize();
|
||||
int downloadSize = DownloadManager.getInstance(getActivity()).getAll()
|
||||
.size();
|
||||
int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size();
|
||||
if (downloadSize != 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText(downloadSize + "");
|
||||
@ -178,14 +229,29 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if (container != null){
|
||||
container.removeView(view);
|
||||
public class FragmentAdapter extends FragmentPagerAdapter{
|
||||
|
||||
public FragmentAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
if (i == 0) {
|
||||
return new News1Fragment();
|
||||
} else if (i == 1) {
|
||||
return new News2Fragment();
|
||||
} else if (i == 2) {
|
||||
return new News3Fragment();
|
||||
} else {
|
||||
return new News4Fragment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 4;
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -258,28 +324,25 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View
|
||||
popWindow.dismiss();
|
||||
startActivity(new Intent(getActivity(), SettingActivity.class));
|
||||
} else if (id == R.id.zixun_text) {
|
||||
mViewPager.setCurrentItem(0);
|
||||
viewPager.setCurrentItem(0);
|
||||
} else if (id == R.id.yuanchuang_text) {
|
||||
mViewPager.setCurrentItem(1);
|
||||
viewPager.setCurrentItem(1);
|
||||
} else if (id == R.id.gonglue_text) {
|
||||
mViewPager.setCurrentItem(2);
|
||||
viewPager.setCurrentItem(2);
|
||||
} else if (id == R.id.guanzhu_text) {
|
||||
mViewPager.setCurrentItem(3);
|
||||
viewPager.setCurrentItem(3);
|
||||
}
|
||||
}
|
||||
|
||||
private void popUpOverflow(View view) {
|
||||
|
||||
Rect frame = new Rect();
|
||||
getActivity().getWindow().getDecorView()
|
||||
.getWindowVisibleDisplayFrame(frame);
|
||||
getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
|
||||
|
||||
int xOffset = DisplayUtils.dip2px(getActivity(), 5);
|
||||
int yOffset = frame.top + DisplayUtils.dip2px(getActivity(), 48)
|
||||
+ xOffset;
|
||||
int yOffset = frame.top + DisplayUtils.dip2px(getActivity(), 48) + xOffset;
|
||||
|
||||
View popView = View.inflate(getActivity(), R.layout.menu_popwindow,
|
||||
null);
|
||||
View popView = View.inflate(getActivity(), R.layout.menu_popwindow, null);
|
||||
popView.findViewById(R.id.menu_rl_set).setOnClickListener(this);
|
||||
popWindow = new PopupWindow(popView, LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT, true);
|
||||
@ -289,8 +352,7 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View
|
||||
popWindow.setBackgroundDrawable(getResources().getDrawable(
|
||||
R.drawable.shape));
|
||||
|
||||
popWindow.showAtLocation(view, Gravity.TOP | Gravity.RIGHT, xOffset,
|
||||
yOffset);
|
||||
popWindow.showAtLocation(view, Gravity.TOP | Gravity.RIGHT, xOffset, yOffset);
|
||||
|
||||
}
|
||||
|
||||
@ -301,13 +363,13 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View
|
||||
rparams.leftMargin = (int) (width * (position + positionOffset) + width / 4);
|
||||
slideLine.setLayoutParams(rparams);
|
||||
} else {
|
||||
if (currentItem != mViewPager.getCurrentItem()) {
|
||||
currentItem = mViewPager.getCurrentItem();
|
||||
Utils.log("currentItem = " + currentItem);
|
||||
EventBus.getDefault().post(new EBUISwitch("GameFragment", currentItem));
|
||||
if (currentItem != viewPager.getCurrentItem()) {
|
||||
currentItem = viewPager.getCurrentItem();
|
||||
EventBus.getDefault().post(new EBUISwitch("NewsFragment", currentItem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
if (position == 0) {
|
||||
@ -355,6 +417,15 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View
|
||||
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("MainActivity".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() == 1) {
|
||||
EventBus.getDefault().post(
|
||||
new EBUISwitch("NewsFragment", viewPager.getCurrentItem()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBTopState busTen) {
|
||||
if ("搜索".equals(busTen.getType())) {
|
||||
hint = busTen.getSearchHint();
|
||||
@ -375,8 +446,7 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View
|
||||
}
|
||||
|
||||
public void updateRedDot(int type) {
|
||||
int downloadSize = DownloadManager.getInstance(getActivity()).getAll()
|
||||
.size();
|
||||
int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size();
|
||||
if (type == 1 && downloadSize == 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText((downloadSize + type) + "");
|
||||
@ -408,30 +478,41 @@ public class NewsFragment extends Fragment implements View.OnClickListener, View
|
||||
}
|
||||
}
|
||||
|
||||
public class MyFragmentPagerAdapter extends FragmentPagerAdapter{
|
||||
|
||||
public MyFragmentPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
if (i == 0) {
|
||||
return new News1Fragment();
|
||||
} else if (i == 1) {
|
||||
return new News2Fragment();
|
||||
} else if (i == 2) {
|
||||
return new News3Fragment();
|
||||
@Override
|
||||
public void onHiddenChanged(boolean hidden) {
|
||||
super.onHiddenChanged(hidden);
|
||||
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
|
||||
List<Fragment> list = getChildFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
if (hidden) {
|
||||
for (Fragment fragment : getChildFragmentManager().getFragments()) {
|
||||
transaction.hide(fragment);
|
||||
}
|
||||
} else {
|
||||
return new News4Fragment();
|
||||
for (Fragment fragment : getChildFragmentManager().getFragments()) {
|
||||
transaction.show(fragment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 4;
|
||||
}
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
view = null;
|
||||
slideLine = null;
|
||||
viewPager = null;
|
||||
tvZixun = null;
|
||||
tvYuanchuang = null;
|
||||
tvGonglve = null;
|
||||
tvGuanzhu = null;
|
||||
downloadHint = null;
|
||||
searchHint = null;
|
||||
popWindow = null;
|
||||
rparams = null;
|
||||
hint = null;
|
||||
handler = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.gh.gamecenter.personal;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
@ -18,8 +17,6 @@ import android.support.v4.widget.ContentLoadingProgressBar;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.SparseArray;
|
||||
@ -29,7 +26,6 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
@ -46,6 +42,7 @@ import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
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;
|
||||
@ -1216,35 +1213,9 @@ public class PersonalFragmentAdapter extends
|
||||
private void showPluginDialog(final ApkEntity apkEntity,
|
||||
final String gameName, final PlatformViewAdapter adapter,
|
||||
final int location) {
|
||||
final Dialog dialog = new Dialog(fragmentActivity);
|
||||
View view = View.inflate(fragmentActivity,
|
||||
R.layout.search_history_delete_dialog, null);
|
||||
TextView title = (TextView) view.findViewById(R.id.delete_dialog_title);
|
||||
title.setText("插件化安装");
|
||||
TextView content = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_message);
|
||||
Spanned spanned = Html.fromHtml("您将进行插件化安装以实现插件功能,此过程将"
|
||||
+ "<font color=\"#ff0000\">卸载</font>" + "当前使用的版本并"
|
||||
+ "<font color=\"#ff0000\">安装插件版本</font>" + "。");
|
||||
content.setText(spanned);
|
||||
|
||||
TextView cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_cancel);
|
||||
cancel.setText("取消");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
DialogUtils.showPluginDialog(fragmentActivity, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
TextView confirm = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirm.setText("确定");
|
||||
confirm.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
|
||||
public void onConfirem() {
|
||||
Map<String, Object> kv6 = new HashMap<String, Object>();
|
||||
kv6.put("操作", "点击插件化安装完成");
|
||||
DataUtils.onEvent(fragmentActivity, "插件化", gameName, kv6);
|
||||
@ -1266,11 +1237,7 @@ public class PersonalFragmentAdapter extends
|
||||
fragmentActivity.startActivity(PackageUtils.getUninstallIntent(fragmentActivity, path));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}, null);
|
||||
}
|
||||
|
||||
public void updateItem(EBDownloadDelete busThree) {
|
||||
|
||||
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 86 KiB After Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 54 KiB |
@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<include
|
||||
layout="@layout/resue_actionbar"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/hotcard_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/bg_color"
|
||||
android:visibility="gone" >
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/hotcard_ll_loading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<ProgressBar
|
||||
style="?android:attr/progressBarStyle"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:text="加载中..."
|
||||
android:textColor="#666666"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@ -1,36 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<include layout="@layout/resue_actionbar" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/original_swipe_refresh"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/original_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
<com.gc.materialdesign.views.ProgressBarCircularIndeterminate
|
||||
android:id="@+id/original_pb_loading"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:background="@color/theme_colors" />
|
||||
|
||||
<include layout="@layout/reuse_no_connection" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
31
app/src/main/res/layout/activity_plugin.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<include
|
||||
layout="@layout/resue_actionbar"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/plugin_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/bg_color" >
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
<com.gc.materialdesign.views.ProgressBarCircularIndeterminate
|
||||
android:id="@+id/plugin_pb_loading"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:background="@color/theme_colors" />
|
||||
|
||||
<include layout="@layout/reuse_no_connection" />
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
31
app/src/main/res/layout/activity_subject.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<include
|
||||
layout="@layout/resue_actionbar"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/subject_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/bg_color" >
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
<com.gc.materialdesign.views.ProgressBarCircularIndeterminate
|
||||
android:id="@+id/subject_pb_loading"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:background="@color/theme_colors" />
|
||||
|
||||
<include layout="@layout/reuse_no_connection" />
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@ -32,13 +32,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/reuse_radiobutton_item_style"
|
||||
android:text="特大字号" />
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/reuse_radiobutton_item_style"
|
||||
android:text="大字号" />
|
||||
android:text="小字号" />
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="match_parent"
|
||||
@ -50,8 +44,14 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/reuse_radiobutton_item_style"
|
||||
android:text="大字号" />
|
||||
|
||||
android:text="小字号" />
|
||||
<RadioButton
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/reuse_radiobutton_item_style"
|
||||
|
||||
android:text="特大字号" />
|
||||
</RadioGroup>
|
||||
|
||||
<RelativeLayout
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
@ -9,32 +10,15 @@
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/news_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone" >
|
||||
android:layout_height="match_parent" >
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/news_ll_loading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
<com.gc.materialdesign.views.ProgressBarCircularIndeterminate
|
||||
android:id="@+id/news_pb_loading"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="visible" >
|
||||
|
||||
<ProgressBar
|
||||
style="?android:attr/progressBarStyle"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:text="加载中..."
|
||||
android:textColor="#666666"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
android:background="@color/theme_colors" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/news_rl_label"
|
||||
@ -57,6 +41,19 @@
|
||||
</RelativeLayout>
|
||||
|
||||
<include layout="@layout/reuse_no_connection" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/news_tv_none"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="300dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:background="@drawable/reuse_none"
|
||||
android:gravity="center"
|
||||
android:text="暂无关注"
|
||||
android:textColor="#616161"
|
||||
android:textSize="14sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@ -5,9 +5,11 @@
|
||||
android:orientation="vertical" >
|
||||
|
||||
<View
|
||||
android:id="@+id/head_top"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:background="@color/bg_color" />
|
||||
android:background="@color/bg_color"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -47,7 +49,7 @@
|
||||
android:id="@+id/head_more"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="更多"
|
||||
android:text="全部"
|
||||
android:textColor="@color/theme_colors"
|
||||
android:textSize="13sp" />
|
||||
|
||||
|
||||
@ -3,11 +3,15 @@
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<View
|
||||
android:id="@+id/home_game_iv_image_top"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:background="@color/bg_color" />
|
||||
<ImageView
|
||||
android:id="@+id/home_game_iv_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:scaleType="fitCenter"/>
|
||||
android:scaleType="centerCrop"/>
|
||||
|
||||
</LinearLayout>
|
||||
@ -8,14 +8,16 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/home1_game_order"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="1"
|
||||
android:gravity="center"
|
||||
android:layout_centerVertical="true"
|
||||
android:textColor="#333333"
|
||||
android:layout_marginRight="8dp"
|
||||
android:visibility="gone"
|
||||
android:textSize="14sp"/>
|
||||
android:layout_marginRight="4dp"
|
||||
android:maxLength="3"
|
||||
android:textSize="14sp"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/home1_game_thumb"
|
||||
|
||||
@ -9,14 +9,16 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/home2_game_order"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="1"
|
||||
android:gravity="center"
|
||||
android:layout_centerVertical="true"
|
||||
android:textColor="#333333"
|
||||
android:layout_marginRight="8dp"
|
||||
android:visibility="gone"
|
||||
android:textSize="14sp"/>
|
||||
android:layout_marginRight="4dp"
|
||||
android:maxLength="3"
|
||||
android:textSize="14sp"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/home2_game_thumb"
|
||||
@ -155,7 +157,7 @@
|
||||
android:paddingRight="10dp"
|
||||
android:text="无数据..."
|
||||
android:textSize="13sp"
|
||||
android:maxLines="2"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
android:textColor="#666666" />
|
||||
|
||||
|
||||
@ -33,7 +33,6 @@
|
||||
android:id="@+id/news_sub_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="39dp"
|
||||
android:ellipsize="end"
|
||||
android:gravity="right"
|
||||
android:maxLines="1"
|
||||
|
||||
@ -31,5 +31,13 @@
|
||||
android:layout_toRightOf="@id/news_game_thumb"
|
||||
android:orientation="horizontal" >
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:id="@+id/gamenormal_game_info"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="45dp"
|
||||
android:padding="5dp"
|
||||
android:src="@drawable/userinfo_more"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
@ -17,7 +17,9 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:orientation="horizontal" >
|
||||
android:orientation="horizontal"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginRight="10dp">
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
<com.gh.common.view.Gh_ImageLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<!--xmlns:fresco="http://schemas.android.com/apk/res-auto"-->
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/viewimage_iv_show"
|
||||
@ -10,11 +9,11 @@
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop" />
|
||||
|
||||
<!--<com.facebook.drawee.view.SimpleDraweeView-->
|
||||
<!--android:id="@+id/test_gif"-->
|
||||
<!--android:layout_width="match_parent"-->
|
||||
<!--android:layout_height="match_parent"-->
|
||||
<!--fresco:actualImageScaleType="fitCenter"/>-->
|
||||
<pl.droidsonroids.gif.GifImageView
|
||||
android:id="@+id/gifView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="fitCenter"/>
|
||||
|
||||
<com.gc.materialdesign.views.ProgressBarCircularIndeterminate
|
||||
android:id="@+id/viewimage_pb_loading"
|
||||
|
||||