Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a4c8a01b9 | |||
| b3d6148c8c | |||
| d4dac2d681 | |||
| 02599ad7cc | |||
| bb790ad579 | |||
| 6ec976ccb6 | |||
| 84c30364fc | |||
| 8df31781e9 | |||
| 380d38073e | |||
| 78e295ce7e | |||
| 627a896ddb | |||
| 929f12fa18 | |||
| c0550746b1 | |||
| 602c30d87c | |||
| e7ff7a3083 | |||
| d86155383b | |||
| 4074ae5452 | |||
| bf87e7187d | |||
| 5c09b03d60 | |||
| b3b7641959 | |||
| b0a9a52288 | |||
| 35a915dda1 | |||
| 1210911a3a | |||
| b7bc0efe28 | |||
| b31131a00b | |||
| 228d0394c3 |
3
.gitignore
vendored
@ -1,8 +1,7 @@
|
||||
/.idea
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
|
||||
1
.idea/modules.xml
generated
@ -3,6 +3,7 @@
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/GH-ASSISTv1.45.iml" filepath="$PROJECT_DIR$/GH-ASSISTv1.45.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/GH-ASSISTv1.50.iml" filepath="$PROJECT_DIR$/GH-ASSISTv1.50.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/buildSrc/buildSrc.iml" filepath="$PROJECT_DIR$/buildSrc/buildSrc.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/hackdex/hackdex.iml" filepath="$PROJECT_DIR$/hackdex/hackdex.iml" />
|
||||
|
||||
@ -38,8 +38,8 @@ android {
|
||||
applicationId "com.gh.gamecenter"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 19
|
||||
versionCode 12
|
||||
versionName "1.46"
|
||||
versionCode 13
|
||||
versionName "1.50"
|
||||
|
||||
// 默认的渠道
|
||||
// manifestPlaceholders = [CHANNEL_VALUE: "GH_TEST"]
|
||||
@ -65,7 +65,7 @@ android {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
// signingConfig signingConfigs.release
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,20 +76,39 @@ android {
|
||||
/**
|
||||
* 渠道打包
|
||||
*/
|
||||
// productFlavors {
|
||||
// "GH_200"{
|
||||
// manifestPlaceholders = [CHANNEL_VALUE: "GH_200"]
|
||||
// }
|
||||
// }
|
||||
// productFlavors {
|
||||
// GH_200 {}
|
||||
// }
|
||||
// productFlavors.all { flavor ->
|
||||
// flavor.manifestPlaceholders = [CHANNEL_VALUE: name]//命令 gradlew assembleRelease
|
||||
// }
|
||||
productFlavors {
|
||||
GH_100 {}
|
||||
GH_101 {}
|
||||
GH_102 {}
|
||||
GH_103 {}
|
||||
GH_104 {}
|
||||
GH_109 {}
|
||||
GH_110 {}
|
||||
GH_113 {}
|
||||
GH_114 {}
|
||||
GH_115 {}
|
||||
GH_116 {}
|
||||
GH_118 {}
|
||||
GH_119 {}
|
||||
GH_120 {}
|
||||
GH_121 {}
|
||||
GH_123 {}
|
||||
GH_200 {}
|
||||
GH_201 {}
|
||||
GH_202 {}
|
||||
GH_203 {}
|
||||
GH_307 {}
|
||||
GH_127 {}
|
||||
}
|
||||
productFlavors.all { flavor ->
|
||||
flavor.manifestPlaceholders = [CHANNEL_VALUE: name]//命令 gradlew assembleRelease
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testCompile 'junit:junit:4.12'
|
||||
// compile ('com.facebook.fresco:fresco:0.9.0') {
|
||||
// exclude module: 'support-v4'
|
||||
// }
|
||||
}
|
||||
@ -38,15 +38,6 @@
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<!-- 小米推送需要的权限 -->
|
||||
<uses-permission android:name="com.gh.gamecenter.permission.MIPUSH_RECEIVE" />
|
||||
<!-- 添加权限 -->
|
||||
<!-- 允许程序发送SMS短信 -->
|
||||
<uses-permission android:name="android.permission.SEND_SMS" />
|
||||
<!-- 允许程序监控一个将收到短信息,记录或处理 -->
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
||||
<!-- 允许程序读取短信息 -->
|
||||
<uses-permission android:name="android.permission.READ_SMS" />
|
||||
<!-- 请求访问使用照相设备 -->
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<permission
|
||||
android:name="com.gh.gamecenter.permission.MIPUSH_RECEIVE"
|
||||
@ -71,7 +62,9 @@
|
||||
android:value="81DB144D555386A38A70B833537EC256" />
|
||||
<meta-data
|
||||
android:name="TD_CHANNEL_ID"
|
||||
android:value="GH_200" />
|
||||
android:value="GH_TEST"
|
||||
/>
|
||||
<!--android:value="${CHANNEL_VALUE}"-->
|
||||
|
||||
<!-- MTA -->
|
||||
<meta-data
|
||||
@ -79,7 +72,8 @@
|
||||
android:value="APV567FTBS7J"/>
|
||||
<meta-data
|
||||
android:name="InstallChannel"
|
||||
android:value="GH_127"/>
|
||||
android:value="GH_TEST"/>
|
||||
<!--android:value="${CHANNEL_VALUE}"-->
|
||||
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.SplashScreenActivity"
|
||||
@ -128,9 +122,6 @@
|
||||
android:name="com.gh.gamecenter.SearchActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateVisible" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.NewsOrRaidersActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.GameDetailsActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
@ -151,10 +142,7 @@
|
||||
android:name="com.gh.gamecenter.ConcernActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.HotCardActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.OriginalActivity"
|
||||
android:name="com.gh.gamecenter.SubjectActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
|
||||
<receiver android:name="com.gh.gamecenter.receiver.InstallAndUninstallReceiver" >
|
||||
@ -223,11 +211,6 @@
|
||||
<action android:name="com.xiaomi.push.PING_TIMER" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name="com.gh.gamecenter.receiver.SmsReceiver" >
|
||||
<intent-filter android:priority="1000" >
|
||||
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service android:name="com.gh.download.DownloadService" />
|
||||
<service
|
||||
|
||||
@ -28,6 +28,8 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
//import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
|
||||
public class AppController extends Application {
|
||||
public static final String TAG = AppController.class.getSimpleName();
|
||||
|
||||
@ -102,6 +104,7 @@ public class AppController extends Application {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
// Fresco.initialize(getApplicationContext());
|
||||
File dexPath = new File(getDir("dex", Context.MODE_PRIVATE), "hackdex_dex.jar");
|
||||
DexUtils.prepareAssetsDex(this, dexPath, "hackdex_dex.jar");
|
||||
HotFix.patch(this, dexPath.getAbsolutePath(), "dodola.hackdex.AntilazyLoad");
|
||||
|
||||
@ -20,8 +20,10 @@ import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.RunningUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.MainActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBShowDialog;
|
||||
import com.gh.gamecenter.manager.SystemBarTintManager;
|
||||
@ -193,12 +195,19 @@ public class BaseActivity extends Activity {
|
||||
|
||||
private boolean isShowShare = false;
|
||||
|
||||
public void onEventMainThread(EBShowDialog showDialog) {
|
||||
public void onEventMainThread(final EBShowDialog showDialog) {
|
||||
if (!isPause && this.getClass().getName().equals(RunningUtils.getTopActivity(this))) {
|
||||
if ("hijack".equals(showDialog.getType())) {
|
||||
DialogUtils.showHijackDialog(this);
|
||||
} else if ("delete".equals(showDialog.getType())) {
|
||||
DialogUtils.showDeleteDialog(this, showDialog.getPath());
|
||||
DialogUtils.showUninstallDialog(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()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,8 +20,10 @@ import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.RunningUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.MainActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBShowDialog;
|
||||
import com.gh.gamecenter.manager.SystemBarTintManager;
|
||||
@ -186,12 +188,19 @@ public class BaseFragmentActivity extends FragmentActivity {
|
||||
|
||||
private boolean isShowShare = false;
|
||||
|
||||
public void onEventMainThread(EBShowDialog showDialog) {
|
||||
public void onEventMainThread(final EBShowDialog showDialog) {
|
||||
if (!isPause && this.getClass().getName().equals(RunningUtils.getTopActivity(this))) {
|
||||
if ("hijack".equals(showDialog.getType())) {
|
||||
DialogUtils.showHijackDialog(this);
|
||||
} else if ("delete".equals(showDialog.getType())) {
|
||||
DialogUtils.showDeleteDialog(this, showDialog.getPath());
|
||||
DialogUtils.showUninstallDialog(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()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,14 +21,14 @@ public class DataUtils {
|
||||
public static void init(Application application) {
|
||||
//TalkingData
|
||||
//dubug true release false
|
||||
TCAgent.LOG_ON = false;
|
||||
TCAgent.LOG_ON = true;
|
||||
TCAgent.init(application);
|
||||
TCAgent.setReportUncaughtExceptions(true);
|
||||
|
||||
//MTA
|
||||
// 打开debug开关,可查看mta上报日志或错误
|
||||
// dubug true release false
|
||||
StatConfig.setDebugEnable(false);
|
||||
StatConfig.setDebugEnable(true);
|
||||
// 收集未处理的异常
|
||||
StatConfig.setAutoExceptionCaught(true);
|
||||
// 设置数据上报策略
|
||||
|
||||
@ -9,7 +9,6 @@ import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.MainActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
public class DialogUtils {
|
||||
@ -26,7 +25,65 @@ public class DialogUtils {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public static void showDialog(final Context context, final String path) {
|
||||
private static boolean isShowHijackDialog = false;
|
||||
|
||||
public static void showHijackDialog(final Context context) {
|
||||
if (isShowHijackDialog) {
|
||||
return;
|
||||
}
|
||||
isShowHijackDialog = true;
|
||||
|
||||
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);
|
||||
|
||||
content.setText("您当前网络环境异常,下载地址已被替换(网络劫持),请更换网络环境进行下载。");
|
||||
|
||||
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 confirem = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirem.setText("确定");
|
||||
confirem.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 跳转wifi管理界面
|
||||
Intent intent = new Intent("android.settings.WIFI_SETTINGS");
|
||||
context.startActivity(intent);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.setOnDismissListener(new Dialog.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
isShowHijackDialog = false;
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private static boolean isShowDeleteDialog = false;
|
||||
|
||||
public static void showUninstallDialog(final Context context, final ConfiremListener listener) {
|
||||
if (isShowDeleteDialog) {
|
||||
return;
|
||||
}
|
||||
isShowDeleteDialog = true;
|
||||
|
||||
final Dialog dialog = new Dialog(context);
|
||||
View view = View.inflate(context,
|
||||
R.layout.search_history_delete_dialog, null);
|
||||
@ -52,13 +109,16 @@ public class DialogUtils {
|
||||
confirem.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Utils.log("packageName = "
|
||||
+ PackageUtils.getPackageNameByPath(context, path));
|
||||
MainActivity.uninstallMap.put(
|
||||
PackageUtils.getPackageNameByPath(context, path), path);
|
||||
context.startActivity(PackageUtils.getUninstallIntent(context,
|
||||
path));
|
||||
dialog.dismiss();
|
||||
if (listener != null) {
|
||||
listener.onConfirem();
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.setOnDismissListener(new Dialog.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
isShowDeleteDialog = false;
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
@ -66,102 +126,44 @@ public class DialogUtils {
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private static boolean isShowHijackDialog = false;
|
||||
public static void showWarningDialog(Context context, final ConfiremListener listener) {
|
||||
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);
|
||||
|
||||
public static void showHijackDialog(final Context context) {
|
||||
if (!isShowHijackDialog) {
|
||||
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);
|
||||
content.setText("您当前的网络为2G/3G/4G,下载将会消耗移动流量,是否继续下载?");
|
||||
|
||||
content.setText("您当前网络环境异常,下载地址已被替换(网络劫持),请更换网络环境进行下载。");
|
||||
|
||||
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 cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_cancel);
|
||||
cancel.setText("取消");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
TextView confirem = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirem.setText("继续");
|
||||
confirem.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
if (listener != null) {
|
||||
listener.onConfirem();
|
||||
}
|
||||
});
|
||||
TextView confirem = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirem.setText("确定");
|
||||
confirem.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 跳转wifi管理界面
|
||||
Intent intent = new Intent("android.settings.WIFI_SETTINGS");
|
||||
context.startActivity(intent);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.setOnDismissListener(new Dialog.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
isShowHijackDialog = false;
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
isShowHijackDialog = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private static boolean isShowDeleteDialog = false;
|
||||
|
||||
public static void showDeleteDialog(final Context context, final String path) {
|
||||
if (!isShowDeleteDialog) {
|
||||
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);
|
||||
|
||||
content.setText("您已安装了官方原版,该版本与插件版本冲突,是否卸载官方原版?");
|
||||
|
||||
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 confirem = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirem.setText("卸载");
|
||||
confirem.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MainActivity.uninstallMap.put(
|
||||
PackageUtils.getPackageNameByPath(context, path), path);
|
||||
context.startActivity(PackageUtils.getUninstallIntent(context,
|
||||
path));
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.setOnDismissListener(new Dialog.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
isShowDeleteDialog = false;
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
isShowDeleteDialog = true;
|
||||
}
|
||||
public interface ConfiremListener{
|
||||
void onConfirem();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@ -9,7 +8,6 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
@ -20,6 +18,7 @@ import com.gh.common.constant.Constants;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.MainActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
@ -123,11 +122,10 @@ public class DownloadItemUtils {
|
||||
} else {
|
||||
downloadBtn.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (entity.getApk() != null
|
||||
&& entity.getApk().size() == 1
|
||||
&& PackageManager.isInstalled(entity.getApk().get(0)
|
||||
.getPackageName())) {
|
||||
&& PackageManager.isInstalled(entity.getApk().get(0).getPackageName())
|
||||
&& entity.getPluginPlatform() == null) {
|
||||
labelList.setVisibility(View.VISIBLE);
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
@ -141,8 +139,7 @@ public class DownloadItemUtils {
|
||||
|
||||
DownloadEntry downloadEntry;
|
||||
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(entity
|
||||
.getName());
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(entity.getName());
|
||||
|
||||
if (queue != null && !queue.isEmpty()) {
|
||||
downloadEntry = entryMap.get(queue.peek());
|
||||
@ -156,16 +153,14 @@ public class DownloadItemUtils {
|
||||
game_ll_info.setVisibility(View.VISIBLE);
|
||||
|
||||
String platform = PlatformUtils.getInstance(context)
|
||||
.getPlatformName(
|
||||
downloadEntry.getMeta().get("platform"));
|
||||
.getPlatformName(downloadEntry.getMeta().get("platform"));
|
||||
|
||||
switch (downloadEntry.getStatus()) {
|
||||
case downloading:
|
||||
if (!"pause".equals(statusMap.get(downloadEntry.getUrl()))) {
|
||||
if (isShowPlatform) {
|
||||
if (platform == null) {
|
||||
download_speed
|
||||
.setText(SpeedUtils
|
||||
download_speed.setText(SpeedUtils
|
||||
.getSpeed(downloadEntry
|
||||
.getSpeed())
|
||||
+ "(剩"
|
||||
@ -178,8 +173,7 @@ public class DownloadItemUtils {
|
||||
.getSpeed() * 1024)
|
||||
+ ")");
|
||||
} else {
|
||||
download_speed
|
||||
.setText(platform
|
||||
download_speed.setText(platform
|
||||
+ " - "
|
||||
+ SpeedUtils
|
||||
.getSpeed(downloadEntry
|
||||
@ -195,8 +189,7 @@ public class DownloadItemUtils {
|
||||
+ ")");
|
||||
}
|
||||
} else {
|
||||
download_speed
|
||||
.setText(SpeedUtils
|
||||
download_speed.setText(SpeedUtils
|
||||
.getSpeed(downloadEntry
|
||||
.getSpeed())
|
||||
+ "(剩"
|
||||
@ -254,23 +247,19 @@ public class DownloadItemUtils {
|
||||
download_speed.setText("下载完成");
|
||||
}
|
||||
download_percentage.setText("100%");
|
||||
if (entity.getApk() != null
|
||||
&& entity.getApk().size() == 1) {
|
||||
if (entity.getApk() != null && entity.getApk().size() == 1) {
|
||||
EventBus.getDefault().post(
|
||||
new EBPutUrl(entity.getApk().get(0)
|
||||
.getPackageName(), downloadEntry
|
||||
.getUrl()));
|
||||
.getPackageName(), downloadEntry.getUrl()));
|
||||
downloadBtn.setText("安装");
|
||||
downloadBtn
|
||||
.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setTextColor(0xFFFFFFFF);
|
||||
} else {
|
||||
labelList.setVisibility(View.VISIBLE);
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
downloadBtn.setText("下载");
|
||||
downloadBtn
|
||||
.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setTextColor(0xFFFFFFFF);
|
||||
}
|
||||
break;
|
||||
@ -302,7 +291,11 @@ public class DownloadItemUtils {
|
||||
labelList.setVisibility(View.VISIBLE);
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
downloadBtn.setText("下载");
|
||||
if (entity.getPluginPlatform() != null) {
|
||||
downloadBtn.setText("插件化");
|
||||
} else {
|
||||
downloadBtn.setText("下载");
|
||||
}
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setTextColor(0xFFFFFFFF);
|
||||
break;
|
||||
@ -317,9 +310,12 @@ public class DownloadItemUtils {
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
if (entity.getApk() != null) {
|
||||
downloadBtn.setText("下载");
|
||||
downloadBtn
|
||||
.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
if (entity.getPluginPlatform() != null) {
|
||||
downloadBtn.setText("插件化");
|
||||
} else {
|
||||
downloadBtn.setText("下载");
|
||||
}
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setTextColor(0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
@ -368,315 +364,40 @@ public class DownloadItemUtils {
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
if (entity.getApk().size() == 1) {
|
||||
String msg = FileUtils.isCanDownload(entity
|
||||
.getApk().get(0).getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", entity.getApk().get(0).getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(context, "游戏下载", entity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("版本", entity.getApk().get(0)
|
||||
.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-开始");
|
||||
DataUtils.onEvent(context, "游戏下载位置", entity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv3 = new HashMap<String, Object>();
|
||||
kv3.put(entrance, "下载数");
|
||||
kv3.put(entrance, "下载开始");
|
||||
DataUtils.onEvent(context, "应用数据", entity.getName(), kv3);
|
||||
|
||||
if ("主页-最新插件".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "最新插件", kv4);
|
||||
} else if ("主页-热门卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "热门卡牌", kv4);
|
||||
} else if ("主页-新测卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "新测卡牌", kv4);
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
map.put("method", "正常");
|
||||
map.put("platform", PlatformUtils.getInstance(context)
|
||||
.getPlatformName(entity.getApk().get(0).getPlatform()));
|
||||
map.put("status", "开始");
|
||||
map.put("location", "游戏详情:" + entity.getName());
|
||||
map.put("from", entrance);
|
||||
map.put("network", NetworkUtils.getConnectedType(context));
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(context, "download", map);
|
||||
|
||||
DownloadManager.getInstance(context).add(
|
||||
getDownloadEntry(context, entity, 0, entrance));
|
||||
Toast.makeText(context, entity.getName() + "已加入下载队列", Toast.LENGTH_SHORT).show();
|
||||
downloadBtn.setText("暂停");
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_gray_style);
|
||||
downloadBtn.setTextColor(0xFF999999);
|
||||
EventBus.getDefault().post(new EBRedDot(1));
|
||||
|
||||
statusMap.put(entity.getApk().get(0).getUrl(), "downloading");
|
||||
} else {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
if (!dismissEntity.isShow()) {
|
||||
dismissEntity.setShow(true);
|
||||
DownloadDialog.getInstance(context)
|
||||
.showPopupWindow(viewBtn, entity, entrance, statusMap,
|
||||
download_speed, download_percentage, location);
|
||||
}
|
||||
}
|
||||
download(context, entity, downloadBtn, statusMap,
|
||||
dismissEntity, download_speed, download_percentage,
|
||||
viewBtn, entrance, location);
|
||||
} else {
|
||||
|
||||
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);
|
||||
|
||||
content.setText("您当前的网络为2G/3G/4G,下载将会消耗移动流量,是否继续下载?");
|
||||
|
||||
TextView cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_cancel);
|
||||
cancel.setText("取消");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
DialogUtils.showWarningDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
public void onConfirem() {
|
||||
download(context, entity, downloadBtn, statusMap,
|
||||
dismissEntity, download_speed, download_percentage,
|
||||
viewBtn, entrance, location);
|
||||
}
|
||||
});
|
||||
TextView confirem = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirem.setText("继续");
|
||||
confirem.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
if (entity.getApk() == null
|
||||
|| entity.getApk().isEmpty()) {
|
||||
Toast.makeText(context,
|
||||
"稍等片刻~!游戏正在上传中...",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (entity.getApk().size() == 1) {
|
||||
String msg = FileUtils
|
||||
.isCanDownload(entity
|
||||
.getApk().get(0)
|
||||
.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", entity.getApk()
|
||||
.get(0).getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(context, "游戏下载", entity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("版本", entity.getApk().get(0).getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-开始");
|
||||
DataUtils.onEvent(context, "游戏下载位置", entity.getName(), kv2);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
map.put("method", "正常");
|
||||
map.put("platform", PlatformUtils.getInstance(context)
|
||||
.getPlatformName(entity.getApk().get(0).getPlatform()));
|
||||
map.put("status", "开始");
|
||||
map.put("location", "游戏详情:" + entity.getName());
|
||||
map.put("from", entrance);
|
||||
map.put("network", NetworkUtils.getConnectedType(context));
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(context, "download", map);
|
||||
|
||||
DownloadManager.getInstance(context).add(
|
||||
getDownloadEntry(context, entity, 0, entrance));
|
||||
Toast.makeText(context, entity.getName() + "已加入下载队列",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
downloadBtn.setText("暂停");
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_gray_style);
|
||||
downloadBtn.setTextColor(0xFF999999);
|
||||
EventBus.getDefault().post(new EBRedDot(1));
|
||||
|
||||
statusMap.put(entity.getApk().get(0).getUrl(), "downloading");
|
||||
} else {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
if (!dismissEntity.isShow()) {
|
||||
dismissEntity.setShow(true);
|
||||
DownloadDialog
|
||||
.getInstance(context)
|
||||
.showPopupWindow(
|
||||
viewBtn,
|
||||
entity,
|
||||
entrance,
|
||||
statusMap,
|
||||
download_speed,
|
||||
download_percentage,
|
||||
location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
} else if ("插件化".equals(str)) {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
plugin(context, entity, downloadBtn, statusMap, entrance);
|
||||
} else {
|
||||
DialogUtils.showWarningDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
plugin(context, entity, downloadBtn, statusMap, entrance);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if ("暂停".equals(str)) {
|
||||
ArrayMap<String, DownloadEntry> entryMap = entity
|
||||
.getEntryMap();
|
||||
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
|
||||
DownloadEntry downloadEntry;
|
||||
|
||||
LinkedBlockingQueue<String> queue = platformMap
|
||||
.get(entity.getName());
|
||||
|
||||
if (queue != null && !queue.isEmpty()) {
|
||||
downloadEntry = entryMap.get(queue.peek());
|
||||
} else {
|
||||
downloadEntry = entryMap.get(entryMap.keyAt(0));
|
||||
}
|
||||
|
||||
if (downloadEntry != null) {
|
||||
|
||||
String platform = PlatformUtils
|
||||
.getInstance(context).getPlatformName(
|
||||
downloadEntry.getMeta().get(
|
||||
"platform"));
|
||||
if (isShowPlatform) {
|
||||
if (platform == null) {
|
||||
download_speed.setText("暂停");
|
||||
} else {
|
||||
download_speed.setText(platform + " - 暂停");
|
||||
}
|
||||
} else {
|
||||
download_speed.setText("暂停");
|
||||
}
|
||||
download_percentage.setText(downloadEntry
|
||||
.getPercent() + "%");
|
||||
}
|
||||
}
|
||||
downloadBtn.setText("继续");
|
||||
downloadBtn
|
||||
.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setTextColor(0xFFFFFFFF);
|
||||
statusMap.put(entity.getApk().get(0).getUrl(), "pause");
|
||||
Message msg = Message.obtain();
|
||||
msg.what = Constants.PAUSE_DOWNLOAD_TASK;
|
||||
msg.obj = entity.getApk().get(0).getUrl();
|
||||
DownloadManager.getInstance(context).put(entity.getApk().get(0).getUrl(),
|
||||
System.currentTimeMillis());
|
||||
DownloadManager.getInstance(context).sendMessageDelayed(msg, 1000);
|
||||
pause(context, entity, download_speed, download_percentage,
|
||||
downloadBtn, platformMap, statusMap, isShowPlatform);
|
||||
} else if ("继续".equals(str)) {
|
||||
ArrayMap<String, DownloadEntry> entryMap = entity
|
||||
.getEntryMap();
|
||||
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
|
||||
DownloadEntry downloadEntry;
|
||||
|
||||
LinkedBlockingQueue<String> queue = platformMap
|
||||
.get(entity.getName());
|
||||
|
||||
if (queue != null && !queue.isEmpty()) {
|
||||
downloadEntry = entryMap.get(queue.peek());
|
||||
} else {
|
||||
downloadEntry = entryMap.get(entryMap.keyAt(0));
|
||||
}
|
||||
|
||||
if (downloadEntry != null) {
|
||||
|
||||
String platform = PlatformUtils
|
||||
.getInstance(context).getPlatformName(
|
||||
downloadEntry.getMeta().get(
|
||||
"platform"));
|
||||
if (isShowPlatform) {
|
||||
if (platform == null) {
|
||||
download_speed.setText(SpeedUtils
|
||||
.getSpeed(downloadEntry.getSpeed())
|
||||
+ "(剩"
|
||||
+ SpeedUtils.getRemainTime(
|
||||
downloadEntry.getSize(),
|
||||
downloadEntry.getProgress(),
|
||||
downloadEntry.getSpeed() * 1024)
|
||||
+ ")");
|
||||
} else {
|
||||
download_speed.setText(platform
|
||||
+ " - "
|
||||
+ SpeedUtils.getSpeed(downloadEntry
|
||||
.getSpeed())
|
||||
+ "(剩"
|
||||
+ SpeedUtils.getRemainTime(
|
||||
downloadEntry.getSize(),
|
||||
downloadEntry.getProgress(),
|
||||
downloadEntry.getSpeed() * 1024)
|
||||
+ ")");
|
||||
}
|
||||
} else {
|
||||
download_speed.setText(SpeedUtils
|
||||
.getSpeed(downloadEntry.getSpeed())
|
||||
+ "(剩"
|
||||
+ SpeedUtils.getRemainTime(
|
||||
downloadEntry.getSize(),
|
||||
downloadEntry.getProgress(),
|
||||
downloadEntry.getSpeed() * 1024)
|
||||
+ ")");
|
||||
}
|
||||
download_percentage.setText(downloadEntry
|
||||
.getPercent() + "%");
|
||||
}
|
||||
}
|
||||
downloadBtn.setText("暂停");
|
||||
downloadBtn
|
||||
.setBackgroundResource(R.drawable.textview_gray_style);
|
||||
downloadBtn.setTextColor(0xFF999999);
|
||||
statusMap.put(entity.getApk().get(0).getUrl(),
|
||||
"downloading");
|
||||
EventBus.getDefault().post(new EBRedDot(0));
|
||||
Message msg = Message.obtain();
|
||||
msg.what = Constants.CONTINUE_DOWNLOAD_TASK;
|
||||
msg.obj = entity.getApk().get(0).getUrl();
|
||||
DownloadManager.getInstance(context).put(entity.getApk().get(0).getUrl(),
|
||||
System.currentTimeMillis());
|
||||
DownloadManager.getInstance(context).sendMessageDelayed(msg, 1000);
|
||||
goon(context, entity, download_speed, download_percentage,
|
||||
downloadBtn, platformMap, statusMap, isShowPlatform);
|
||||
} else if ("安装".equals(str)) {
|
||||
String path = entity.getEntryMap()
|
||||
.get(entity.getEntryMap().keyAt(0)).getPath();
|
||||
if (FileUtils.isEmptyFile(path)) {
|
||||
Toast.makeText(context, "解析包错误", Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
DownloadManager.getInstance(context).cancel(
|
||||
entity.getEntryMap()
|
||||
.get(entity.getEntryMap().keyAt(0))
|
||||
.getUrl());
|
||||
entity.getEntryMap().remove(
|
||||
entity.getEntryMap().keyAt(0));
|
||||
adapter.notifyItemChanged(position);
|
||||
} else {
|
||||
PackageManager manager = new PackageManager(context);
|
||||
if (manager.launchSetup(path)) {
|
||||
context.startActivity(PackageUtils
|
||||
.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showDialog(context, path);
|
||||
}
|
||||
}
|
||||
install(context, entity, position, adapter);
|
||||
} else if ("启动".equals(str)) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", entity.getApk().get(0).getPlatform());
|
||||
DataUtils.onEvent(context, "游戏启动", entity.getName(), kv);
|
||||
@ -688,6 +409,307 @@ public class DownloadItemUtils {
|
||||
});
|
||||
}
|
||||
|
||||
//下载
|
||||
private static void download(Context context, GameEntity entity, TextView downloadBtn,
|
||||
ArrayMap<String, String> statusMap, DismissEntity dismissEntity,
|
||||
TextView download_speed, TextView download_percentage, View viewBtn,
|
||||
String entrance, String location) {
|
||||
if (entity.getApk().size() == 1) {
|
||||
String msg = FileUtils.isCanDownload(entity.getApk().get(0).getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", entity.getApk().get(0).getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(context, "游戏下载", entity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("版本", entity.getApk().get(0)
|
||||
.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-开始");
|
||||
DataUtils.onEvent(context, "游戏下载位置", entity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv3 = new HashMap<String, Object>();
|
||||
kv3.put(entrance, "下载数");
|
||||
kv3.put(entrance, "下载开始");
|
||||
DataUtils.onEvent(context, "应用数据", entity.getName(), kv3);
|
||||
|
||||
if ("主页-最新插件".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "最新插件", kv4);
|
||||
} else if ("主页-热门卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "热门卡牌", kv4);
|
||||
} else if ("主页-新测卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "新测卡牌", kv4);
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
map.put("method", "正常");
|
||||
map.put("platform", PlatformUtils.getInstance(context)
|
||||
.getPlatformName(entity.getApk().get(0).getPlatform()));
|
||||
map.put("status", "开始");
|
||||
map.put("location", "游戏详情:" + entity.getName());
|
||||
map.put("from", entrance);
|
||||
map.put("network", NetworkUtils.getConnectedType(context));
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(context, "download", map);
|
||||
|
||||
DownloadManager.getInstance(context).add(
|
||||
getDownloadEntry(context, entity, 0, entrance));
|
||||
Toast.makeText(context, entity.getName() + "已加入下载队列", Toast.LENGTH_SHORT).show();
|
||||
downloadBtn.setText("暂停");
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_gray_style);
|
||||
downloadBtn.setTextColor(0xFF999999);
|
||||
EventBus.getDefault().post(new EBRedDot(1));
|
||||
|
||||
statusMap.put(entity.getApk().get(0).getUrl(), "downloading");
|
||||
} else {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
if (!dismissEntity.isShow()) {
|
||||
dismissEntity.setShow(true);
|
||||
DownloadDialog.getInstance(context)
|
||||
.showPopupWindow(viewBtn, entity, entrance, statusMap,
|
||||
download_speed, download_percentage, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//插件化
|
||||
private static void plugin(Context context, GameEntity entity, TextView downloadBtn,
|
||||
ArrayMap<String, String> statusMap, String entrance) {
|
||||
String msg = FileUtils.isCanDownload(entity.getApk().get(0).getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", entity.getApk().get(0).getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(context, "游戏下载", entity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("版本", entity.getApk().get(0)
|
||||
.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-开始");
|
||||
DataUtils.onEvent(context, "游戏下载位置", entity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv3 = new HashMap<String, Object>();
|
||||
kv3.put(entrance, "下载数");
|
||||
kv3.put(entrance, "下载开始");
|
||||
DataUtils.onEvent(context, "应用数据", entity.getName(), kv3);
|
||||
|
||||
if ("主页-最新插件".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "最新插件", kv4);
|
||||
} else if ("主页-热门卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "热门卡牌", kv4);
|
||||
} else if ("主页-新测卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "新测卡牌", kv4);
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
map.put("method", "正常");
|
||||
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));
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(context, "download", map);
|
||||
|
||||
DownloadManager.getInstance(context).add(
|
||||
getDownloadEntry(context, entity, 0, entrance));
|
||||
Toast.makeText(context, entity.getName() + "已加入下载队列", Toast.LENGTH_SHORT).show();
|
||||
downloadBtn.setText("暂停");
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_gray_style);
|
||||
downloadBtn.setTextColor(0xFF999999);
|
||||
EventBus.getDefault().post(new EBRedDot(1));
|
||||
|
||||
statusMap.put(entity.getApk().get(0).getUrl(), "downloading");
|
||||
} else {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
//暂停
|
||||
private static void pause(Context context, GameEntity entity, TextView download_speed,
|
||||
TextView download_percentage, TextView downloadBtn,
|
||||
ArrayMap<String, LinkedBlockingQueue<String>> platformMap,
|
||||
ArrayMap<String, String> statusMap,
|
||||
boolean isShowPlatform) {
|
||||
ArrayMap<String, DownloadEntry> entryMap = entity
|
||||
.getEntryMap();
|
||||
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
|
||||
DownloadEntry downloadEntry;
|
||||
|
||||
LinkedBlockingQueue<String> queue = platformMap
|
||||
.get(entity.getName());
|
||||
|
||||
if (queue != null && !queue.isEmpty()) {
|
||||
downloadEntry = entryMap.get(queue.peek());
|
||||
} else {
|
||||
downloadEntry = entryMap.get(entryMap.keyAt(0));
|
||||
}
|
||||
|
||||
if (downloadEntry != null) {
|
||||
|
||||
String platform = PlatformUtils
|
||||
.getInstance(context).getPlatformName(
|
||||
downloadEntry.getMeta().get(
|
||||
"platform"));
|
||||
if (isShowPlatform) {
|
||||
if (platform == null) {
|
||||
download_speed.setText("暂停");
|
||||
} else {
|
||||
download_speed.setText(platform + " - 暂停");
|
||||
}
|
||||
} else {
|
||||
download_speed.setText("暂停");
|
||||
}
|
||||
download_percentage.setText(downloadEntry
|
||||
.getPercent() + "%");
|
||||
}
|
||||
}
|
||||
downloadBtn.setText("继续");
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setTextColor(0xFFFFFFFF);
|
||||
statusMap.put(entity.getApk().get(0).getUrl(), "pause");
|
||||
Message msg = Message.obtain();
|
||||
msg.what = Constants.PAUSE_DOWNLOAD_TASK;
|
||||
msg.obj = entity.getApk().get(0).getUrl();
|
||||
DownloadManager.getInstance(context).put(entity.getApk().get(0).getUrl(),
|
||||
System.currentTimeMillis());
|
||||
DownloadManager.getInstance(context).sendMessageDelayed(msg, 1000);
|
||||
}
|
||||
|
||||
//继续
|
||||
private static void goon(Context context, GameEntity entity, TextView download_speed,
|
||||
TextView download_percentage, TextView downloadBtn,
|
||||
ArrayMap<String, LinkedBlockingQueue<String>> platformMap,
|
||||
ArrayMap<String, String> statusMap,
|
||||
boolean isShowPlatform) {
|
||||
ArrayMap<String, DownloadEntry> entryMap = entity
|
||||
.getEntryMap();
|
||||
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
|
||||
DownloadEntry downloadEntry;
|
||||
|
||||
LinkedBlockingQueue<String> queue = platformMap
|
||||
.get(entity.getName());
|
||||
|
||||
if (queue != null && !queue.isEmpty()) {
|
||||
downloadEntry = entryMap.get(queue.peek());
|
||||
} else {
|
||||
downloadEntry = entryMap.get(entryMap.keyAt(0));
|
||||
}
|
||||
|
||||
if (downloadEntry != null) {
|
||||
|
||||
String platform = PlatformUtils
|
||||
.getInstance(context).getPlatformName(
|
||||
downloadEntry.getMeta().get(
|
||||
"platform"));
|
||||
if (isShowPlatform) {
|
||||
if (platform == null) {
|
||||
download_speed.setText(SpeedUtils
|
||||
.getSpeed(downloadEntry.getSpeed())
|
||||
+ "(剩"
|
||||
+ SpeedUtils.getRemainTime(
|
||||
downloadEntry.getSize(),
|
||||
downloadEntry.getProgress(),
|
||||
downloadEntry.getSpeed() * 1024)
|
||||
+ ")");
|
||||
} else {
|
||||
download_speed.setText(platform
|
||||
+ " - "
|
||||
+ SpeedUtils.getSpeed(downloadEntry
|
||||
.getSpeed())
|
||||
+ "(剩"
|
||||
+ SpeedUtils.getRemainTime(
|
||||
downloadEntry.getSize(),
|
||||
downloadEntry.getProgress(),
|
||||
downloadEntry.getSpeed() * 1024)
|
||||
+ ")");
|
||||
}
|
||||
} else {
|
||||
download_speed.setText(SpeedUtils
|
||||
.getSpeed(downloadEntry.getSpeed())
|
||||
+ "(剩"
|
||||
+ SpeedUtils.getRemainTime(
|
||||
downloadEntry.getSize(),
|
||||
downloadEntry.getProgress(),
|
||||
downloadEntry.getSpeed() * 1024)
|
||||
+ ")");
|
||||
}
|
||||
download_percentage.setText(downloadEntry
|
||||
.getPercent() + "%");
|
||||
}
|
||||
}
|
||||
downloadBtn.setText("暂停");
|
||||
downloadBtn
|
||||
.setBackgroundResource(R.drawable.textview_gray_style);
|
||||
downloadBtn.setTextColor(0xFF999999);
|
||||
statusMap.put(entity.getApk().get(0).getUrl(),
|
||||
"downloading");
|
||||
EventBus.getDefault().post(new EBRedDot(0));
|
||||
Message msg = Message.obtain();
|
||||
msg.what = Constants.CONTINUE_DOWNLOAD_TASK;
|
||||
msg.obj = entity.getApk().get(0).getUrl();
|
||||
DownloadManager.getInstance(context).put(entity.getApk().get(0).getUrl(),
|
||||
System.currentTimeMillis());
|
||||
DownloadManager.getInstance(context).sendMessageDelayed(msg, 1000);
|
||||
}
|
||||
|
||||
//安装
|
||||
private static void install(final Context context, GameEntity entity, int position,
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) {
|
||||
final String path = entity.getEntryMap()
|
||||
.get(entity.getEntryMap().keyAt(0)).getPath();
|
||||
if (FileUtils.isEmptyFile(path)) {
|
||||
Toast.makeText(context, "解析包错误", Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
DownloadManager.getInstance(context).cancel(
|
||||
entity.getEntryMap()
|
||||
.get(entity.getEntryMap().keyAt(0))
|
||||
.getUrl());
|
||||
entity.getEntryMap().remove(
|
||||
entity.getEntryMap().keyAt(0));
|
||||
adapter.notifyItemChanged(position);
|
||||
} else {
|
||||
PackageManager manager = new PackageManager(context);
|
||||
if (manager.launchSetup(path)) {
|
||||
context.startActivity(PackageUtils
|
||||
.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showUninstallDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
MainActivity.uninstallMap.put(
|
||||
PackageUtils.getPackageNameByPath(context, path), path);
|
||||
context.startActivity(PackageUtils.getUninstallIntent(context, path));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static DownloadEntry getDownloadEntry(Context context,
|
||||
GameEntity game, int position, String entrance) {
|
||||
ApkEntity apkEntity = game.getApk().get(position);
|
||||
@ -695,8 +717,7 @@ public class DownloadItemUtils {
|
||||
|
||||
entry.setUrl(apkEntity.getUrl());
|
||||
entry.setName(game.getName());
|
||||
entry.setPath(FileUtils.getDownloadPath(
|
||||
context,
|
||||
entry.setPath(FileUtils.getDownloadPath(context,
|
||||
MD5Utils.getContentMD5(game.getName() + "_"
|
||||
+ System.currentTimeMillis())
|
||||
+ ".apk"));
|
||||
@ -707,6 +728,9 @@ public class DownloadItemUtils {
|
||||
meta.put("gameId", game.getId());
|
||||
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()));
|
||||
}
|
||||
entry.setMeta(meta);
|
||||
return entry;
|
||||
}
|
||||
|
||||
@ -112,7 +112,9 @@ public class ImageUtils {
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
imageView.setScaleType(ScaleType.CENTER);
|
||||
imageView.setImageResource(drawable);
|
||||
if (drawable != -1) {
|
||||
imageView.setImageResource(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -13,7 +13,7 @@ import java.lang.reflect.Field;
|
||||
|
||||
public class Utils {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
private static final boolean DEBUG = true;
|
||||
|
||||
public static void log(String msg) {
|
||||
if (DEBUG) {
|
||||
|
||||
@ -866,7 +866,7 @@ public class DownloadDialog {
|
||||
kv6.put("操作", "点击安装完成");
|
||||
DataUtils.onEvent(context, "插件化", downloadEntry.getName(), kv6);
|
||||
}
|
||||
String path = entryMap.get(apkEntity.getUrl())
|
||||
final String path = entryMap.get(apkEntity.getUrl())
|
||||
.getPath();
|
||||
if (FileUtils.isEmptyFile(path)) {
|
||||
Toast.makeText(context, "解析包错误",
|
||||
@ -882,7 +882,15 @@ public class DownloadDialog {
|
||||
context.startActivity(PackageUtils
|
||||
.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showDialog(context, path);
|
||||
DialogUtils.showUninstallDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
MainActivity.uninstallMap.put(
|
||||
PackageUtils.getPackageNameByPath(context, path), path);
|
||||
context.startActivity(PackageUtils.getUninstallIntent(context,
|
||||
path));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if ("等待".equals(status)) {
|
||||
|
||||
@ -93,7 +93,6 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
top_tv_info, top_tv_attention, titlebar_tv_details,
|
||||
titlebar_tv_information, titlebar_tv_strategy, gamedetails_tv_per,
|
||||
actionbar_tv_title;
|
||||
// private TextView gamedetails_tv_database,titlebar_tv_database;
|
||||
private ImageView top_iv_icon, gamedetails_iv_share;
|
||||
private View gamedetails_slide_line, titlebar_slide_line;
|
||||
private LinearLayout gamedetails_ll_top, gamedetails_ll_topbar,
|
||||
@ -164,7 +163,6 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
|
||||
super.onSaveInstanceState(outState);
|
||||
Utils.log(this.getClass().getSimpleName() + " onSaveInstanceState");
|
||||
outState.putInt("CurrentItem", gamedetails_vp_show.getCurrentItem());
|
||||
@ -176,8 +174,7 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_gamedetails,
|
||||
null);
|
||||
View contentView = View.inflate(this, R.layout.activity_gamedetails, null);
|
||||
|
||||
gameId = getIntent().getStringExtra("gameId");
|
||||
entrance = getIntent().getStringExtra("entrance");
|
||||
@ -214,22 +211,18 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
gamedetails_tv_details.setOnClickListener(this);
|
||||
gamedetails_tv_information.setOnClickListener(this);
|
||||
gamedetails_tv_strategy.setOnClickListener(this);
|
||||
// gamedetails_tv_database.setOnClickListener(this);
|
||||
|
||||
titlebar_tv_details.setOnClickListener(this);
|
||||
titlebar_tv_information.setOnClickListener(this);
|
||||
titlebar_tv_strategy.setOnClickListener(this);
|
||||
// titlebar_tv_database.setOnClickListener(this);
|
||||
|
||||
titlebar_tv_details.setClickable(false);
|
||||
titlebar_tv_information.setClickable(true);
|
||||
titlebar_tv_strategy.setClickable(true);
|
||||
// titlebar_tv_database.setClickable(true);
|
||||
|
||||
gamedetails_tv_details.setClickable(false);
|
||||
gamedetails_tv_information.setClickable(true);
|
||||
gamedetails_tv_strategy.setClickable(true);
|
||||
// gamedetails_tv_database.setClickable(true);
|
||||
|
||||
top_tv_attention.setOnClickListener(this);
|
||||
|
||||
@ -385,7 +378,7 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
public void onClick(final View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.actionbar_rl_back:
|
||||
finish();
|
||||
@ -402,10 +395,6 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
case R.id.titlebar_tv_strategy:
|
||||
gamedetails_vp_show.setCurrentItem(2);
|
||||
break;
|
||||
// case R.id.gamedetails_tv_database:
|
||||
// case R.id.titlebar_tv_database:
|
||||
// gamedetails_vp_show.setCurrentItem(3);
|
||||
// break;
|
||||
case R.id.top_tv_attention:
|
||||
if ("关注".equals(top_tv_attention.getText().toString())) {
|
||||
|
||||
@ -448,259 +437,14 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
kv0);
|
||||
if (entity.getApk() != null && !entity.getApk().isEmpty()) {
|
||||
if (NetworkUtils.isWifiConnected(this)) {
|
||||
if (entity.getApk().size() == 1) {
|
||||
if (gamedetails_tv_download.getText().toString()
|
||||
.contains("启动")) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", entity.getApk().get(0).getPlatform());
|
||||
DataUtils.onEvent(GameDetailsActivity.this, "游戏启动",
|
||||
entity.getName(), kv);
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(
|
||||
getApplicationContext(), entity.getApk()
|
||||
.get(0).getPackageName());
|
||||
} else {
|
||||
ApkEntity apkEntity = entity.getApk().get(0);
|
||||
String msg = FileUtils.isCanDownload(apkEntity
|
||||
.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(GameDetailsActivity.this,
|
||||
"游戏下载", entity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("版本", apkEntity.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-游戏详情-开始");
|
||||
DataUtils.onEvent(GameDetailsActivity.this,
|
||||
"游戏下载位置", entity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv3 = new HashMap<String, Object>();
|
||||
kv3.put(entrance, "下载数");
|
||||
kv3.put(entrance, "下载开始");
|
||||
DataUtils.onEvent(GameDetailsActivity.this,
|
||||
"应用数据", entity.getName(), kv3);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
map.put("method", "正常");
|
||||
map.put("platform",
|
||||
PlatformUtils.getInstance(
|
||||
getApplicationContext())
|
||||
.getPlatformName(
|
||||
entity.getApk().get(0)
|
||||
.getPlatform()));
|
||||
map.put("status", "开始");
|
||||
map.put("location", "游戏详情:" + entity.getName());
|
||||
map.put("from", entrance);
|
||||
map.put("network",
|
||||
NetworkUtils.getConnectedType(this));
|
||||
map.put("createdOn",
|
||||
System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(this, "download", map);
|
||||
|
||||
DownloadEntry entry = new DownloadEntry();
|
||||
|
||||
entry.setUrl(apkEntity.getUrl());
|
||||
entry.setName(entity.getName());
|
||||
entry.setPath(FileUtils.getDownloadPath(
|
||||
GameDetailsActivity.this,
|
||||
MD5Utils.getContentMD5(entity.getName()
|
||||
+ "_"
|
||||
+ System.currentTimeMillis())
|
||||
+ ".apk"));
|
||||
HashMap<String, String> meta = new HashMap<String, String>();
|
||||
meta.put("ETag", apkEntity.getEtag());
|
||||
meta.put("icon", entity.getIcon());
|
||||
meta.put("platform", apkEntity.getPlatform());
|
||||
meta.put("gameId", entity.getId());
|
||||
meta.put("entrance", entrance + "-游戏详情");
|
||||
meta.put("location", "游戏详情:" + entity.getName());
|
||||
entry.setMeta(meta);
|
||||
|
||||
DownloadManager.getInstance(
|
||||
getApplicationContext()).add(entry);
|
||||
|
||||
EventBus.getDefault().post(new EBRedDot(1));
|
||||
|
||||
gamedetails_tv_download
|
||||
.setVisibility(View.GONE);
|
||||
gamedetails_progressbar
|
||||
.setVisibility(View.VISIBLE);
|
||||
gamedetails_tv_per.setVisibility(View.VISIBLE);
|
||||
gamedetails_progressbar.setProgress(0);
|
||||
gamedetails_tv_per.setText("0.0%");
|
||||
|
||||
statusMap.put(entry.getUrl(), "downloading");
|
||||
|
||||
} else {
|
||||
toast(msg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!dismissEntity.isShow()) {
|
||||
dismissEntity.setShow(true);
|
||||
DownloadDialog
|
||||
.getInstance(GameDetailsActivity.this)
|
||||
.showPopupWindow(v, entity,
|
||||
entrance + "-游戏详情", statusMap,
|
||||
"游戏详情:" + entity.getName());
|
||||
}
|
||||
}
|
||||
download(v);
|
||||
} else {
|
||||
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);
|
||||
|
||||
content.setText("您当前的网络为2G/3G/4G,下载将会消耗移动流量,是否继续下载?");
|
||||
|
||||
TextView cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_cancel);
|
||||
cancel.setText("取消");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
DialogUtils.showWarningDialog(this, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
public void onConfirem() {
|
||||
download(v);
|
||||
}
|
||||
});
|
||||
TextView confirem = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirem.setText("继续");
|
||||
confirem.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
if (entity.getApk().size() == 1) {
|
||||
if (gamedetails_tv_download.getText()
|
||||
.toString().contains("启动")) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", entity.getApk().get(0)
|
||||
.getPlatform());
|
||||
DataUtils.onEvent(GameDetailsActivity.this,
|
||||
"游戏启动", entity.getName(), kv);
|
||||
|
||||
PackageUtils
|
||||
.launchApplicationByPackageName(
|
||||
getApplicationContext(),
|
||||
entity.getApk().get(0)
|
||||
.getPackageName());
|
||||
} else {
|
||||
ApkEntity apkEntity = entity.getApk()
|
||||
.get(0);
|
||||
String msg = FileUtils
|
||||
.isCanDownload(apkEntity.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(
|
||||
GameDetailsActivity.this,
|
||||
"游戏下载", entity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("版本", apkEntity.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-游戏详情-开始");
|
||||
DataUtils.onEvent(
|
||||
GameDetailsActivity.this,
|
||||
"游戏下载位置", entity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv3 = new HashMap<String, Object>();
|
||||
kv3.put("下载", "下载量");
|
||||
kv3.put("下载", apkEntity.getPlatform());
|
||||
DataUtils.onEvent(
|
||||
GameDetailsActivity.this,
|
||||
"插件数据", entity.getName(), kv3);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
map.put("method", "正常");
|
||||
map.put("platform",
|
||||
PlatformUtils
|
||||
.getInstance(
|
||||
getApplicationContext())
|
||||
.getPlatformName(
|
||||
entity.getApk()
|
||||
.get(0)
|
||||
.getPlatform()));
|
||||
map.put("status", "开始");
|
||||
map.put("location", "游戏详情:" + entity.getName());
|
||||
map.put("from", entrance);
|
||||
map.put("network", NetworkUtils.getConnectedType(GameDetailsActivity.this));
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(GameDetailsActivity.this, "download", map);
|
||||
|
||||
DownloadEntry entry = new DownloadEntry();
|
||||
|
||||
entry.setUrl(apkEntity.getUrl());
|
||||
entry.setName(entity.getName());
|
||||
entry.setPath(FileUtils
|
||||
.getDownloadPath(
|
||||
GameDetailsActivity.this,
|
||||
MD5Utils.getContentMD5(entity
|
||||
.getName()
|
||||
+ "_"
|
||||
+ System.currentTimeMillis())
|
||||
+ ".apk"));
|
||||
HashMap<String, String> meta = new HashMap<String, String>();
|
||||
meta.put("ETag", apkEntity.getEtag());
|
||||
meta.put("icon", entity.getIcon());
|
||||
meta.put("platform",
|
||||
apkEntity.getPlatform());
|
||||
meta.put("gameId", entity.getId());
|
||||
meta.put("entrance", entrance + "-游戏详情");
|
||||
meta.put("location",
|
||||
"游戏详情:" + entity.getName());
|
||||
entry.setMeta(meta);
|
||||
|
||||
DownloadManager.getInstance(
|
||||
getApplicationContext()).add(
|
||||
entry);
|
||||
|
||||
EventBus.getDefault().post(
|
||||
new EBRedDot(1));
|
||||
|
||||
gamedetails_tv_download
|
||||
.setVisibility(View.GONE);
|
||||
gamedetails_progressbar
|
||||
.setVisibility(View.VISIBLE);
|
||||
gamedetails_tv_per
|
||||
.setVisibility(View.VISIBLE);
|
||||
gamedetails_progressbar.setProgress(0);
|
||||
gamedetails_tv_per.setText("0.0%");
|
||||
|
||||
statusMap.put(entry.getUrl(),
|
||||
"downloading");
|
||||
|
||||
} else {
|
||||
toast(msg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!dismissEntity.isShow()) {
|
||||
dismissEntity.setShow(true);
|
||||
DownloadDialog.getInstance(
|
||||
GameDetailsActivity.this)
|
||||
.showPopupWindow(v, entity,
|
||||
entrance + "-游戏详情",
|
||||
statusMap,
|
||||
"游戏详情:" + entity.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
} else {
|
||||
toast("稍等片刻~!游戏正在上传中...");
|
||||
@ -736,13 +480,21 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
System.currentTimeMillis());
|
||||
DownloadManager.getInstance(getApplicationContext()).sendMessageDelayed(msg, 1000);
|
||||
} else if ("安装".equals(str)) {
|
||||
String path = downloadEntry.getPath();
|
||||
final String path = downloadEntry.getPath();
|
||||
PackageManager manager = new PackageManager(
|
||||
getApplicationContext());
|
||||
if (manager.launchSetup(path)) {
|
||||
startActivity(PackageUtils.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showDialog(GameDetailsActivity.this, path);
|
||||
DialogUtils.showUninstallDialog(this, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
MainActivity.uninstallMap.put(
|
||||
PackageUtils.getPackageNameByPath(GameDetailsActivity.this, path), path);
|
||||
startActivity(PackageUtils.getUninstallIntent(GameDetailsActivity.this,
|
||||
path));
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if("等待".equals(str)){
|
||||
|
||||
@ -767,6 +519,111 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
private void download(View v) {
|
||||
if (entity.getApk().size() == 1) {
|
||||
if (gamedetails_tv_download.getText().toString()
|
||||
.contains("启动")) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", entity.getApk().get(0).getPlatform());
|
||||
DataUtils.onEvent(GameDetailsActivity.this, "游戏启动",
|
||||
entity.getName(), kv);
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(
|
||||
getApplicationContext(), entity.getApk()
|
||||
.get(0).getPackageName());
|
||||
} else {
|
||||
ApkEntity apkEntity = entity.getApk().get(0);
|
||||
String msg = FileUtils.isCanDownload(apkEntity
|
||||
.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(GameDetailsActivity.this,
|
||||
"游戏下载", entity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("版本", apkEntity.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-游戏详情-开始");
|
||||
DataUtils.onEvent(GameDetailsActivity.this,
|
||||
"游戏下载位置", entity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv3 = new HashMap<String, Object>();
|
||||
kv3.put(entrance, "下载数");
|
||||
kv3.put(entrance, "下载开始");
|
||||
DataUtils.onEvent(GameDetailsActivity.this,
|
||||
"应用数据", entity.getName(), kv3);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
map.put("method", "正常");
|
||||
map.put("platform",
|
||||
PlatformUtils.getInstance(
|
||||
getApplicationContext())
|
||||
.getPlatformName(
|
||||
entity.getApk().get(0)
|
||||
.getPlatform()));
|
||||
map.put("status", "开始");
|
||||
map.put("location", "游戏详情:" + entity.getName());
|
||||
map.put("from", entrance);
|
||||
map.put("network",
|
||||
NetworkUtils.getConnectedType(this));
|
||||
map.put("createdOn",
|
||||
System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(this, "download", map);
|
||||
|
||||
DownloadEntry entry = new DownloadEntry();
|
||||
|
||||
entry.setUrl(apkEntity.getUrl());
|
||||
entry.setName(entity.getName());
|
||||
entry.setPath(FileUtils.getDownloadPath(
|
||||
GameDetailsActivity.this,
|
||||
MD5Utils.getContentMD5(entity.getName()
|
||||
+ "_"
|
||||
+ System.currentTimeMillis())
|
||||
+ ".apk"));
|
||||
HashMap<String, String> meta = new HashMap<String, String>();
|
||||
meta.put("ETag", apkEntity.getEtag());
|
||||
meta.put("icon", entity.getIcon());
|
||||
meta.put("platform", apkEntity.getPlatform());
|
||||
meta.put("gameId", entity.getId());
|
||||
meta.put("entrance", entrance + "-游戏详情");
|
||||
meta.put("location", "游戏详情:" + entity.getName());
|
||||
entry.setMeta(meta);
|
||||
|
||||
DownloadManager.getInstance(
|
||||
getApplicationContext()).add(entry);
|
||||
|
||||
EventBus.getDefault().post(new EBRedDot(1));
|
||||
|
||||
gamedetails_tv_download
|
||||
.setVisibility(View.GONE);
|
||||
gamedetails_progressbar
|
||||
.setVisibility(View.VISIBLE);
|
||||
gamedetails_tv_per.setVisibility(View.VISIBLE);
|
||||
gamedetails_progressbar.setProgress(0);
|
||||
gamedetails_tv_per.setText("0.0%");
|
||||
|
||||
statusMap.put(entry.getUrl(), "downloading");
|
||||
|
||||
} else {
|
||||
toast(msg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!dismissEntity.isShow()) {
|
||||
dismissEntity.setShow(true);
|
||||
DownloadDialog
|
||||
.getInstance(GameDetailsActivity.this)
|
||||
.showPopupWindow(v, entity,
|
||||
entrance + "-游戏详情", statusMap,
|
||||
"游戏详情:" + entity.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showSuccessDialog() {
|
||||
final Dialog dialog = new Dialog(this);
|
||||
View view = View.inflate(this, R.layout.gamedetails_attention_dialog,
|
||||
@ -905,24 +762,20 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
titlebar_tv_details.setClickable(false);
|
||||
titlebar_tv_information.setClickable(true);
|
||||
titlebar_tv_strategy.setClickable(true);
|
||||
// titlebar_tv_database.setClickable(true);
|
||||
|
||||
gamedetails_tv_details.setClickable(false);
|
||||
gamedetails_tv_information.setClickable(true);
|
||||
gamedetails_tv_strategy.setClickable(true);
|
||||
// gamedetails_tv_database.setClickable(true);
|
||||
|
||||
titlebar_tv_details.setTextColor(getResources().getColor(
|
||||
R.color.theme_colors));
|
||||
titlebar_tv_information.setTextColor(0xFF333333);
|
||||
titlebar_tv_strategy.setTextColor(0xFF333333);
|
||||
// titlebar_tv_database.setTextColor(0xFF333333);
|
||||
|
||||
gamedetails_tv_details.setTextColor(getResources().getColor(
|
||||
R.color.theme_colors));
|
||||
gamedetails_tv_information.setTextColor(0xFF333333);
|
||||
gamedetails_tv_strategy.setTextColor(0xFF333333);
|
||||
// gamedetails_tv_database.setTextColor(0xFF333333);
|
||||
break;
|
||||
case 1:
|
||||
if (gamedetails_ll_topbar.getVisibility() == View.VISIBLE) {
|
||||
@ -933,24 +786,20 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
titlebar_tv_details.setClickable(true);
|
||||
titlebar_tv_information.setClickable(false);
|
||||
titlebar_tv_strategy.setClickable(true);
|
||||
// titlebar_tv_database.setClickable(true);
|
||||
|
||||
gamedetails_tv_details.setClickable(true);
|
||||
gamedetails_tv_information.setClickable(false);
|
||||
gamedetails_tv_strategy.setClickable(true);
|
||||
// gamedetails_tv_database.setClickable(true);
|
||||
|
||||
titlebar_tv_details.setTextColor(0xFF333333);
|
||||
titlebar_tv_information.setTextColor(getResources().getColor(
|
||||
R.color.theme_colors));
|
||||
titlebar_tv_strategy.setTextColor(0xFF333333);
|
||||
// titlebar_tv_database.setTextColor(0xFF333333);
|
||||
|
||||
gamedetails_tv_details.setTextColor(0xFF333333);
|
||||
gamedetails_tv_information.setTextColor(getResources().getColor(
|
||||
R.color.theme_colors));
|
||||
gamedetails_tv_strategy.setTextColor(0xFF333333);
|
||||
// gamedetails_tv_database.setTextColor(0xFF333333);
|
||||
break;
|
||||
case 2:
|
||||
if (gamedetails_ll_topbar.getVisibility() == View.VISIBLE) {
|
||||
@ -961,45 +810,20 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
titlebar_tv_details.setClickable(true);
|
||||
titlebar_tv_information.setClickable(true);
|
||||
titlebar_tv_strategy.setClickable(false);
|
||||
// titlebar_tv_database.setClickable(true);
|
||||
|
||||
gamedetails_tv_details.setClickable(true);
|
||||
gamedetails_tv_information.setClickable(true);
|
||||
gamedetails_tv_strategy.setClickable(false);
|
||||
// gamedetails_tv_database.setClickable(true);
|
||||
|
||||
titlebar_tv_details.setTextColor(0xFF333333);
|
||||
titlebar_tv_information.setTextColor(0xFF333333);
|
||||
titlebar_tv_strategy.setTextColor(getResources().getColor(
|
||||
R.color.theme_colors));
|
||||
// titlebar_tv_database.setTextColor(0xFF333333);
|
||||
|
||||
gamedetails_tv_details.setTextColor(0xFF333333);
|
||||
gamedetails_tv_information.setTextColor(0xFF333333);
|
||||
gamedetails_tv_strategy.setTextColor(getResources().getColor(
|
||||
R.color.theme_colors));
|
||||
// gamedetails_tv_database.setTextColor(0xFF333333);
|
||||
break;
|
||||
case 3:
|
||||
titlebar_tv_details.setClickable(true);
|
||||
titlebar_tv_information.setClickable(true);
|
||||
titlebar_tv_strategy.setClickable(true);
|
||||
// titlebar_tv_database.setClickable(false);
|
||||
|
||||
gamedetails_tv_details.setClickable(true);
|
||||
gamedetails_tv_information.setClickable(true);
|
||||
gamedetails_tv_strategy.setClickable(true);
|
||||
// gamedetails_tv_database.setClickable(false);
|
||||
|
||||
titlebar_tv_details.setTextColor(0xFF333333);
|
||||
titlebar_tv_information.setTextColor(0xFF333333);
|
||||
titlebar_tv_strategy.setTextColor(0xFF333333);
|
||||
// titlebar_tv_database.setTextColor(getResources().getColor(R.color.theme_colors));
|
||||
|
||||
gamedetails_tv_details.setTextColor(0xFF333333);
|
||||
gamedetails_tv_information.setTextColor(0xFF333333);
|
||||
gamedetails_tv_strategy.setTextColor(0xFF333333);
|
||||
// gamedetails_tv_database.setTextColor(getResources().getColor(R.color.theme_colors));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1007,10 +831,8 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset,
|
||||
int positionOffsetPixels) {
|
||||
|
||||
if (positionOffset != 0) {
|
||||
lparams.leftMargin = (int) (width * (positionOffset + position))
|
||||
+ width / 4;
|
||||
lparams.leftMargin = (int) (width * (positionOffset + position)) + width / 4;
|
||||
gamedetails_slide_line.setLayoutParams(lparams);
|
||||
titlebar_slide_line.setLayoutParams(lparams);
|
||||
}
|
||||
@ -1151,34 +973,36 @@ public class GameDetailsActivity extends BaseFragmentActivity implements
|
||||
cost = "大于60秒";
|
||||
}
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("停留时长", cost);
|
||||
DataUtils.onEvent(this, "插件数据", entity.getName(), kv);
|
||||
if (entity != null && !TextUtils.isEmpty(entity.getName())) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("停留时长", cost);
|
||||
DataUtils.onEvent(this, "插件数据", entity.getName(), kv);
|
||||
|
||||
if ("主页-最新插件".equals(entrance)) {
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put(entity.getName(), "阅读时长:" + cost);
|
||||
DataUtils.onEvent(this, "主页数据", "最新插件", kv2);
|
||||
} else if ("主页-热门卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put(entity.getName(), "阅读时长:" + cost);
|
||||
DataUtils.onEvent(this, "主页数据", "热门卡牌", kv2);
|
||||
} else if ("主页-新测卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put(entity.getName(), "阅读时长:" + cost);
|
||||
DataUtils.onEvent(this, "主页数据", "新测卡牌", kv2);
|
||||
if ("主页-最新插件".equals(entrance)) {
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put(entity.getName(), "阅读时长:" + cost);
|
||||
DataUtils.onEvent(this, "主页数据", "最新插件", kv2);
|
||||
} else if ("主页-热门卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put(entity.getName(), "阅读时长:" + cost);
|
||||
DataUtils.onEvent(this, "主页数据", "热门卡牌", kv2);
|
||||
} else if ("主页-新测卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put(entity.getName(), "阅读时长:" + cost);
|
||||
DataUtils.onEvent(this, "主页数据", "新测卡牌", kv2);
|
||||
}
|
||||
|
||||
if (seconds > 0) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
map.put("time", seconds);
|
||||
map.put("from", entrance);
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(this, "game", map);
|
||||
}
|
||||
|
||||
isSentReport = true;
|
||||
}
|
||||
|
||||
if (seconds > 0) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
map.put("time", seconds);
|
||||
map.put("from", entrance);
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(this, "game", map);
|
||||
}
|
||||
|
||||
isSentReport = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -56,18 +56,17 @@ import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBPutUrl;
|
||||
import com.gh.gamecenter.eventbus.EBRedDot;
|
||||
import com.gh.gamecenter.eventbus.EBShowDialog;
|
||||
import com.gh.gamecenter.eventbus.EBSkipNewPlugin;
|
||||
import com.gh.gamecenter.eventbus.EBTopState;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.home.HomeFragment;
|
||||
import com.gh.gamecenter.game.GameFragment;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.FilterManager;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.manager.SuspectedGameManager;
|
||||
import com.gh.gamecenter.news.NewsFragment;
|
||||
import com.gh.gamecenter.personal.PersonalFragment;
|
||||
import com.gh.gamecenter.plugin.PluginFragment;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
@ -94,7 +93,7 @@ import java.util.zip.ZipFile;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @update 2015-8-11
|
||||
@ -106,8 +105,10 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
public static ArrayMap<String, String> uninstallMap;
|
||||
public static String searchHint;
|
||||
|
||||
private HomeFragment home1Fragment;
|
||||
private PluginFragment pluginFragmentActivity;
|
||||
|
||||
private NewsFragment newsFragment;
|
||||
|
||||
private GameFragment pluginFragmentActivity;
|
||||
private PersonalFragment home3Fragment;
|
||||
private View home1Layout, home2Layout, home3Layout;
|
||||
private ImageView home1Image, home2Image, home3Image;
|
||||
@ -975,23 +976,23 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
home1Image.setImageResource(R.drawable.home1_selected);
|
||||
home1Title.setTextColor(getResources().getColor(
|
||||
R.color.theme_colors));
|
||||
if (home1Fragment == null) {
|
||||
if (pluginFragmentActivity == null) {
|
||||
List<Fragment> list = getSupportFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
for (Fragment fragment : list) {
|
||||
if (fragment.getClass().equals(HomeFragment.class)) {
|
||||
home1Fragment = (HomeFragment) fragment;
|
||||
transaction.show(home1Fragment);
|
||||
if (fragment.getClass().equals(GameFragment.class)) {
|
||||
pluginFragmentActivity = (GameFragment) fragment;
|
||||
transaction.show(pluginFragmentActivity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (home1Fragment == null) {
|
||||
home1Fragment = new HomeFragment();
|
||||
transaction.add(R.id.main_content, home1Fragment);
|
||||
if (pluginFragmentActivity == null) {
|
||||
pluginFragmentActivity = new GameFragment();
|
||||
transaction.add(R.id.main_content, pluginFragmentActivity);
|
||||
}
|
||||
} else {
|
||||
transaction.show(home1Fragment);
|
||||
transaction.show(pluginFragmentActivity);
|
||||
}
|
||||
currentTab = 0;
|
||||
break;
|
||||
@ -1000,23 +1001,23 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
home2Image.setImageResource(R.drawable.home2_selected);
|
||||
home2Title.setTextColor(getResources().getColor(
|
||||
R.color.theme_colors));
|
||||
if (pluginFragmentActivity == null) {
|
||||
if (newsFragment == null) {
|
||||
List<Fragment> list = getSupportFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
for (Fragment fragment : list) {
|
||||
if (fragment.getClass().equals(PluginFragment.class)) {
|
||||
pluginFragmentActivity = (PluginFragment) fragment;
|
||||
transaction.show(pluginFragmentActivity);
|
||||
if (fragment.getClass().equals(NewsFragment.class)) {
|
||||
newsFragment = (NewsFragment) fragment;
|
||||
transaction.show(newsFragment);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pluginFragmentActivity == null) {
|
||||
pluginFragmentActivity = new PluginFragment();
|
||||
transaction.add(R.id.main_content, pluginFragmentActivity);
|
||||
if (newsFragment == null) {
|
||||
newsFragment = new NewsFragment();
|
||||
transaction.add(R.id.main_content, newsFragment);
|
||||
}
|
||||
} else {
|
||||
transaction.show(pluginFragmentActivity);
|
||||
transaction.show(newsFragment);
|
||||
}
|
||||
currentTab = 1;
|
||||
break;
|
||||
@ -1076,9 +1077,10 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
if (pluginFragmentActivity != null) {
|
||||
transaction.hide(pluginFragmentActivity);
|
||||
}
|
||||
if (home1Fragment != null) {
|
||||
transaction.hide(home1Fragment);
|
||||
if (newsFragment != null) {
|
||||
transaction.hide(newsFragment);
|
||||
}
|
||||
|
||||
List<Fragment> list = getSupportFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
for (Fragment fragment : list) {
|
||||
@ -1112,16 +1114,6 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
entryMap.put(url.getPackageName(), url.getUrl());
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBSkipNewPlugin busFive) {
|
||||
if (busFive.getType() == 0) {
|
||||
if (isFirst) {
|
||||
PluginFragment.isFirst = true;
|
||||
}
|
||||
onClick(home2Layout);
|
||||
EventBus.getDefault().post(new EBSkipNewPlugin(1));
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String packageName = busFour.getPackageName();
|
||||
// 添加进已安装map中
|
||||
@ -1237,10 +1229,9 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(HomeFragment.class);
|
||||
AppController.canclePendingRequests(PluginFragment.class);
|
||||
AppController.canclePendingRequests(GameFragment.class);
|
||||
AppController.canclePendingRequests(NewsFragment.class);
|
||||
DownloadManager.getInstance(this).removeObserver(dataWatcher);
|
||||
home1Fragment = null;
|
||||
pluginFragmentActivity = null;
|
||||
home3Fragment = null;
|
||||
home1Layout = null;
|
||||
|
||||
@ -8,6 +8,7 @@ import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.SystemClock;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v4.view.MotionEventCompat;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Html;
|
||||
@ -15,6 +16,7 @@ import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
@ -126,6 +128,16 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
|
||||
private float Y11, Y12, Y21, Y22;
|
||||
private float X11, X12, X21, X22;
|
||||
private boolean isSecondDown = false;
|
||||
private double R11;
|
||||
private int mActivePointerId;
|
||||
private WebSettings webSettings;
|
||||
private int defaultTextZoom = 100;
|
||||
private int scrollSize = 300;//滑动距离超过300触发事件(放大缩小字体)
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
@ -172,6 +184,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
|
||||
WebView essaydetails_webView = (WebView) findViewById(R.id.essaydetails_webView);
|
||||
|
||||
if (NetworkUtils.isWifiConnected(this)) {
|
||||
essaydetails_webView.setVisibility(View.INVISIBLE);
|
||||
if (newsId != null) {
|
||||
@ -230,6 +243,71 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加手势监听,控制字体大小
|
||||
*
|
||||
* @author 柯皓源
|
||||
*/
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
|
||||
switch (ev.getAction() & MotionEventCompat.ACTION_MASK) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
isSecondDown = false;
|
||||
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
|
||||
int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
|
||||
Y11 = MotionEventCompat.getY(ev, pointerIndex);
|
||||
X11 = MotionEventCompat.getX(ev, pointerIndex);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
final int actionUpIndex = MotionEventCompat.getActionIndex(ev);
|
||||
mActivePointerId = MotionEventCompat.getPointerId(ev, actionUpIndex);
|
||||
int pointerIndex2 = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
|
||||
Y12 = MotionEventCompat.getY(ev, pointerIndex2);
|
||||
X12 = MotionEventCompat.getX(ev, pointerIndex2);
|
||||
float X2 = Math.abs(X12 - X22);
|
||||
float Y2 = Math.abs(Y12 - Y22);
|
||||
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) {
|
||||
defaultTextZoom += 10;
|
||||
webSettings.setTextZoom(defaultTextZoom);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (isSecondDown) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case MotionEventCompat.ACTION_POINTER_DOWN:
|
||||
isSecondDown = true;
|
||||
final int pointerIndexDown = MotionEventCompat.getActionIndex(ev);
|
||||
mActivePointerId = MotionEventCompat.getPointerId(ev, pointerIndexDown);
|
||||
int pointerIndex1 = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
|
||||
Y21 = MotionEventCompat.getY(ev, pointerIndex1);
|
||||
X21 = MotionEventCompat.getX(ev, pointerIndex1);
|
||||
float X1 = Math.abs(X11 - X21);
|
||||
float Y1 = Math.abs(Y11 - Y21);
|
||||
float R1 = (X1 * X1) + (Y1 * Y1);
|
||||
R11 = Math.sqrt(R1);
|
||||
break;
|
||||
case MotionEventCompat.ACTION_POINTER_UP:
|
||||
final int pointerIndexUp = MotionEventCompat.getActionIndex(ev);
|
||||
mActivePointerId = MotionEventCompat.getPointerId(ev, pointerIndexUp);
|
||||
int pointerIndex21 = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
|
||||
Y22 = MotionEventCompat.getY(ev, pointerIndex21);
|
||||
X22 = MotionEventCompat.getX(ev, pointerIndex21);
|
||||
break;
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
private void getNewDigest(final String news_id) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v1d45/news/" + news_id + "/digest",
|
||||
@ -271,262 +349,18 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
private long[] mHits = new long[2];
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
public void onClick(final View v) {
|
||||
if (v == essaydetails_tv_download) {
|
||||
if (gameEntity != null && !gameEntity.getApk().isEmpty()) {
|
||||
if (NetworkUtils.isWifiConnected(this)) {
|
||||
if (gameEntity.getApk().size() == 1) {
|
||||
if (essaydetails_tv_download.getText().toString()
|
||||
.contains("启动")) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", gameEntity.getApk().get(0)
|
||||
.getPlatform());
|
||||
DataUtils.onEvent(NewsActivity.this, "游戏启动",
|
||||
gameEntity.getName(), kv);
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(
|
||||
getApplicationContext(), gameEntity
|
||||
.getApk().get(0).getPackageName());
|
||||
} else {
|
||||
ApkEntity apkEntity = gameEntity.getApk().get(0);
|
||||
String msg = FileUtils.isCanDownload(apkEntity
|
||||
.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(NewsActivity.this, "游戏下载",
|
||||
gameEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("版本", apkEntity.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-文章详情-开始");
|
||||
DataUtils.onEvent(NewsActivity.this, "游戏下载位置",
|
||||
gameEntity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv3 = new HashMap<String, Object>();
|
||||
kv3.put(entrance, "下载数");
|
||||
kv3.put(entrance, "下载开始");
|
||||
DataUtils.onEvent(NewsActivity.this, "应用数据",
|
||||
gameEntity.getName(), kv3);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("method", "正常");
|
||||
map.put("platform",
|
||||
PlatformUtils.getInstance(
|
||||
getApplicationContext())
|
||||
.getPlatformName(
|
||||
gameEntity.getApk()
|
||||
.get(0)
|
||||
.getPlatform()));
|
||||
map.put("status", "开始");
|
||||
map.put("location", "新闻详情:" + entity.getTitle());
|
||||
map.put("from", entrance);
|
||||
map.put("network",
|
||||
NetworkUtils.getConnectedType(this));
|
||||
map.put("createdOn",
|
||||
System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(this, "download", map);
|
||||
|
||||
DownloadEntry entry = new DownloadEntry();
|
||||
|
||||
entry.setUrl(apkEntity.getUrl());
|
||||
entry.setName(gameEntity.getName());
|
||||
entry.setPath(FileUtils.getDownloadPath(
|
||||
NewsActivity.this,
|
||||
MD5Utils.getContentMD5(gameEntity
|
||||
.getName()
|
||||
+ "_"
|
||||
+ System.currentTimeMillis())
|
||||
+ ".apk"));
|
||||
HashMap<String, String> meta = new HashMap<String, String>();
|
||||
meta.put("ETag", apkEntity.getEtag());
|
||||
meta.put("icon", gameEntity.getIcon());
|
||||
meta.put("platform", apkEntity.getPlatform());
|
||||
meta.put("gameId", gameEntity.getId());
|
||||
meta.put("entrance", entrance + "-文章详情");
|
||||
meta.put("location",
|
||||
"新闻详情:" + entity.getTitle());
|
||||
entry.setMeta(meta);
|
||||
|
||||
DownloadManager.getInstance(
|
||||
getApplicationContext()).add(entry);
|
||||
|
||||
EventBus.getDefault().post(new EBRedDot(1));
|
||||
|
||||
essaydetails_tv_download
|
||||
.setVisibility(View.GONE);
|
||||
essaydetails_progressbar
|
||||
.setVisibility(View.VISIBLE);
|
||||
essaydetails_tv_per.setVisibility(View.VISIBLE);
|
||||
essaydetails_progressbar.setProgress(0);
|
||||
essaydetails_tv_per.setText("0.0%");
|
||||
|
||||
statusMap.put(entry.getUrl(), "downloading");
|
||||
|
||||
} else {
|
||||
toast(msg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!dismissEntity.isShow()) {
|
||||
dismissEntity.setShow(true);
|
||||
DownloadDialog.getInstance(NewsActivity.this)
|
||||
.showPopupWindow(v, gameEntity,
|
||||
entrance + "-文章详情", statusMap,
|
||||
"新闻详情:" + entity.getTitle());
|
||||
}
|
||||
}
|
||||
download(v);
|
||||
} else {
|
||||
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);
|
||||
|
||||
content.setText("您当前的网络为2G/3G/4G,下载将会消耗移动流量,是否继续下载?");
|
||||
|
||||
TextView cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_cancel);
|
||||
cancel.setText("取消");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
DialogUtils.showWarningDialog(this, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
public void onConfirem() {
|
||||
download(v);
|
||||
}
|
||||
});
|
||||
TextView confirem = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirem.setText("继续");
|
||||
confirem.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
if (gameEntity.getApk().size() == 1) {
|
||||
if (essaydetails_tv_download.getText()
|
||||
.toString().contains("启动")) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", gameEntity.getApk().get(0)
|
||||
.getPlatform());
|
||||
DataUtils.onEvent(NewsActivity.this, "游戏启动",
|
||||
gameEntity.getName(), kv);
|
||||
|
||||
PackageUtils
|
||||
.launchApplicationByPackageName(
|
||||
getApplicationContext(),
|
||||
gameEntity.getApk().get(0)
|
||||
.getPackageName());
|
||||
} else {
|
||||
ApkEntity apkEntity = gameEntity.getApk()
|
||||
.get(0);
|
||||
String msg = FileUtils
|
||||
.isCanDownload(apkEntity.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(NewsActivity.this,
|
||||
"游戏下载", gameEntity.getName(),
|
||||
kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("版本", apkEntity.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-文章详情-开始");
|
||||
DataUtils.onEvent(NewsActivity.this,
|
||||
"游戏下载位置", gameEntity.getName(),
|
||||
kv2);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("method", "正常");
|
||||
map.put("platform",
|
||||
PlatformUtils
|
||||
.getInstance(
|
||||
getApplicationContext())
|
||||
.getPlatformName(
|
||||
gameEntity
|
||||
.getApk()
|
||||
.get(0)
|
||||
.getPlatform()));
|
||||
map.put("status", "开始");
|
||||
map.put("location",
|
||||
"新闻详情:" + entity.getTitle());
|
||||
map.put("from", entrance);
|
||||
map.put("network",
|
||||
NetworkUtils
|
||||
.getConnectedType(NewsActivity.this));
|
||||
map.put("createdOn",
|
||||
System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(NewsActivity.this, "download", map);
|
||||
|
||||
DownloadEntry entry = new DownloadEntry();
|
||||
|
||||
entry.setUrl(apkEntity.getUrl());
|
||||
entry.setName(gameEntity.getName());
|
||||
entry.setPath(FileUtils
|
||||
.getDownloadPath(
|
||||
NewsActivity.this,
|
||||
MD5Utils.getContentMD5(gameEntity
|
||||
.getName()
|
||||
+ "_"
|
||||
+ System.currentTimeMillis())
|
||||
+ ".apk"));
|
||||
HashMap<String, String> meta = new HashMap<String, String>();
|
||||
meta.put("ETag", apkEntity.getEtag());
|
||||
meta.put("icon", gameEntity.getIcon());
|
||||
meta.put("platform",
|
||||
apkEntity.getPlatform());
|
||||
meta.put("gameId", gameEntity.getId());
|
||||
meta.put("entrance", entrance + "-文章详情");
|
||||
meta.put("location",
|
||||
"新闻详情:" + entity.getTitle());
|
||||
entry.setMeta(meta);
|
||||
|
||||
DownloadManager.getInstance(
|
||||
getApplicationContext()).add(
|
||||
entry);
|
||||
|
||||
EventBus.getDefault().post(
|
||||
new EBRedDot(1));
|
||||
|
||||
essaydetails_tv_download
|
||||
.setVisibility(View.GONE);
|
||||
essaydetails_progressbar
|
||||
.setVisibility(View.VISIBLE);
|
||||
essaydetails_tv_per
|
||||
.setVisibility(View.VISIBLE);
|
||||
essaydetails_progressbar.setProgress(0);
|
||||
essaydetails_tv_per.setText("0.0%");
|
||||
|
||||
statusMap.put(entry.getUrl(),
|
||||
"downloading");
|
||||
|
||||
} else {
|
||||
toast(msg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!dismissEntity.isShow()) {
|
||||
dismissEntity.setShow(true);
|
||||
DownloadDialog.getInstance(
|
||||
NewsActivity.this).showPopupWindow(
|
||||
v, gameEntity, entrance + "-文章详情",
|
||||
statusMap, "新闻详情:" + entity.getTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
} else {
|
||||
toast("稍等片刻~!游戏正在上传中...");
|
||||
@ -555,15 +389,23 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
System.currentTimeMillis());
|
||||
DownloadManager.getInstance(getApplicationContext()).sendMessageDelayed(msg, 1000);
|
||||
} else if ("安装".equals(str)) {
|
||||
String path = downloadEntry.getPath();
|
||||
final String path = downloadEntry.getPath();
|
||||
PackageManager manager = new PackageManager(
|
||||
getApplicationContext());
|
||||
if (manager.launchSetup(path)) {
|
||||
startActivity(PackageUtils.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showDialog(NewsActivity.this, path);
|
||||
DialogUtils.showUninstallDialog(this, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
MainActivity.uninstallMap.put(
|
||||
PackageUtils.getPackageNameByPath(NewsActivity.this, path), path);
|
||||
startActivity(PackageUtils.getUninstallIntent(NewsActivity.this,
|
||||
path));
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if("等待".equals(str)){
|
||||
} else if ("等待".equals(str)) {
|
||||
|
||||
} else {
|
||||
statusMap.put(downloadEntry.getUrl(), "pause");
|
||||
@ -585,6 +427,114 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void download(View v) {
|
||||
if (gameEntity.getApk().size() == 1) {
|
||||
if (essaydetails_tv_download.getText().toString()
|
||||
.contains("启动")) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", gameEntity.getApk().get(0)
|
||||
.getPlatform());
|
||||
DataUtils.onEvent(NewsActivity.this, "游戏启动",
|
||||
gameEntity.getName(), kv);
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(
|
||||
getApplicationContext(), gameEntity
|
||||
.getApk().get(0).getPackageName());
|
||||
} else {
|
||||
ApkEntity apkEntity = gameEntity.getApk().get(0);
|
||||
String msg = FileUtils.isCanDownload(apkEntity
|
||||
.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(NewsActivity.this, "游戏下载",
|
||||
gameEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("版本", apkEntity.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-文章详情-开始");
|
||||
DataUtils.onEvent(NewsActivity.this, "游戏下载位置",
|
||||
gameEntity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv3 = new HashMap<String, Object>();
|
||||
kv3.put(entrance, "下载数");
|
||||
kv3.put(entrance, "下载开始");
|
||||
DataUtils.onEvent(NewsActivity.this, "应用数据",
|
||||
gameEntity.getName(), kv3);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("method", "正常");
|
||||
map.put("platform",
|
||||
PlatformUtils.getInstance(
|
||||
getApplicationContext())
|
||||
.getPlatformName(
|
||||
gameEntity.getApk()
|
||||
.get(0)
|
||||
.getPlatform()));
|
||||
map.put("status", "开始");
|
||||
map.put("location", "新闻详情:" + entity.getTitle());
|
||||
map.put("from", entrance);
|
||||
map.put("network",
|
||||
NetworkUtils.getConnectedType(this));
|
||||
map.put("createdOn",
|
||||
System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(this, "download", map);
|
||||
|
||||
DownloadEntry entry = new DownloadEntry();
|
||||
|
||||
entry.setUrl(apkEntity.getUrl());
|
||||
entry.setName(gameEntity.getName());
|
||||
entry.setPath(FileUtils.getDownloadPath(
|
||||
NewsActivity.this,
|
||||
MD5Utils.getContentMD5(gameEntity
|
||||
.getName()
|
||||
+ "_"
|
||||
+ System.currentTimeMillis())
|
||||
+ ".apk"));
|
||||
HashMap<String, String> meta = new HashMap<String, String>();
|
||||
meta.put("ETag", apkEntity.getEtag());
|
||||
meta.put("icon", gameEntity.getIcon());
|
||||
meta.put("platform", apkEntity.getPlatform());
|
||||
meta.put("gameId", gameEntity.getId());
|
||||
meta.put("entrance", entrance + "-文章详情");
|
||||
meta.put("location",
|
||||
"新闻详情:" + entity.getTitle());
|
||||
entry.setMeta(meta);
|
||||
|
||||
DownloadManager.getInstance(
|
||||
getApplicationContext()).add(entry);
|
||||
|
||||
EventBus.getDefault().post(new EBRedDot(1));
|
||||
|
||||
essaydetails_tv_download
|
||||
.setVisibility(View.GONE);
|
||||
essaydetails_progressbar
|
||||
.setVisibility(View.VISIBLE);
|
||||
essaydetails_tv_per.setVisibility(View.VISIBLE);
|
||||
essaydetails_progressbar.setProgress(0);
|
||||
essaydetails_tv_per.setText("0.0%");
|
||||
|
||||
statusMap.put(entry.getUrl(), "downloading");
|
||||
|
||||
} else {
|
||||
toast(msg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!dismissEntity.isShow()) {
|
||||
dismissEntity.setShow(true);
|
||||
DownloadDialog.getInstance(NewsActivity.this)
|
||||
.showPopupWindow(v, gameEntity,
|
||||
entrance + "-文章详情", statusMap,
|
||||
"新闻详情:" + entity.getTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -660,7 +610,8 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
public void onResponse(JSONArray response) {
|
||||
Utils.log(response);
|
||||
if (!isDestroy) {
|
||||
Type listType = new TypeToken<ArrayList<NewsEntity>>() {}.getType();
|
||||
Type listType = new TypeToken<ArrayList<NewsEntity>>() {
|
||||
}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<NewsEntity> list = gson.fromJson(
|
||||
response.toString(), listType);
|
||||
@ -1040,7 +991,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
for (int i = 0, size = gameEntity.getApk().size(); i < size; i++) {
|
||||
ApkEntity apkEntity = gameEntity.getApk().get(i);
|
||||
if ("9u".equals(apkEntity.getPlatform())) {
|
||||
holder.essaydetails_info.setText("V" + apkEntity.getVersion() + " | " + apkEntity.getSize());
|
||||
holder.essaydetails_info.setText("V" + apkEntity.getVersion() + " | " + apkEntity.getSize());
|
||||
break;
|
||||
}
|
||||
if (i == size - 1) {
|
||||
@ -1066,7 +1017,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
holder.essaydetails_time.setText("昨天 " + format.format(day));
|
||||
} else {
|
||||
format.applyPattern("yyyy年MM月dd日 HH:mm");
|
||||
holder.essaydetails_time .setText(format.format(day));
|
||||
holder.essaydetails_time.setText(format.format(day));
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
@ -1078,7 +1029,7 @@ public class NewsActivity extends BaseActivity implements OnClickListener {
|
||||
}
|
||||
if (holder.essaydetails_wv_content.getTag() == null) {
|
||||
holder.essaydetails_wv_content.addJavascriptInterface(new JsInterface(NewsActivity.this), "imagelistener");
|
||||
WebSettings webSettings = holder.essaydetails_wv_content.getSettings();
|
||||
webSettings = holder.essaydetails_wv_content.getSettings();
|
||||
webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
holder.essaydetails_wv_content.loadDataWithBaseURL(null, entity.getContent(), "text/html", "utf-8", null);
|
||||
|
||||
@ -1,186 +0,0 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.NewsOrRaidersListAdapter;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
|
||||
/**
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-10 首页资讯或攻略板块
|
||||
*/
|
||||
public class NewsOrRaidersActivity extends BaseActivity {
|
||||
|
||||
private RecyclerView news_list;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private NewsOrRaidersListAdapter adapter;
|
||||
private LinearLayout news_ll_loading, reuse_no_connection;
|
||||
private TextView news_tv_label;
|
||||
private RelativeLayout news_rl_label;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
|
||||
private String type;
|
||||
|
||||
private boolean isDestroy;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
type = getIntent().getStringExtra("type");
|
||||
|
||||
isDestroy = false;
|
||||
|
||||
View contentView = View.inflate(this,
|
||||
R.layout.activity_news_or_raiders, null);
|
||||
|
||||
init(contentView, type);
|
||||
|
||||
reuse_no_connection.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
news_list.setVisibility(View.GONE);
|
||||
news_ll_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new NewsOrRaidersListAdapter(
|
||||
NewsOrRaidersActivity.this, news_list, news_ll_loading,
|
||||
reuse_no_connection, type, news_rl_label, news_tv_label);
|
||||
news_list.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
||||
rparams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
|
||||
LayoutParams.WRAP_CONTENT);
|
||||
|
||||
news_list.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
news_list.setLayoutManager(layoutManager);
|
||||
|
||||
adapter = new NewsOrRaidersListAdapter(this, news_list,
|
||||
news_ll_loading, reuse_no_connection, type, news_rl_label,
|
||||
news_tv_label);
|
||||
|
||||
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.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
|
||||
int position = layoutManager.findFirstVisibleItemPosition();
|
||||
|
||||
if (adapter.getPosition_today() != -1
|
||||
&& position >= adapter.getPosition_today()
|
||||
&& position <= adapter.getTodaySize()
|
||||
+ adapter.getPosition_today()) {
|
||||
news_tv_label.setText("今天");
|
||||
news_tv_label.setBackgroundResource(R.drawable.title_red);
|
||||
} else if (adapter.getPosition_before() != -1
|
||||
&& position >= adapter.getPosition_before()) {
|
||||
news_tv_label.setText("昨天/以前");
|
||||
news_tv_label.setBackgroundResource(R.drawable.title_gray);
|
||||
} else if (adapter.getPosition_mygame() != -1) {
|
||||
news_tv_label.setText("我的游戏");
|
||||
news_tv_label.setBackgroundResource(R.drawable.title_blue);
|
||||
}
|
||||
|
||||
if (position == adapter.getPosition_today() - 1
|
||||
|| position == adapter.getPosition_before() - 1) {
|
||||
int buttom = layoutManager.findViewByPosition(position)
|
||||
.getBottom();
|
||||
if (buttom <= news_rl_label.getHeight()) {
|
||||
rparams.topMargin = buttom - news_rl_label.getHeight();
|
||||
news_rl_label.setLayoutParams(rparams);
|
||||
} else {
|
||||
rparams.topMargin = 0;
|
||||
news_rl_label.setLayoutParams(rparams);
|
||||
}
|
||||
} else {
|
||||
rparams.topMargin = 0;
|
||||
news_rl_label.setLayoutParams(rparams);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
news_list.addItemDecoration(new VerticalItemDecoration(this, 1));
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBConcernChanged busSeven) {
|
||||
adapter.updateMyGameNews();
|
||||
}
|
||||
|
||||
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);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new NewsOrRaidersListAdapter(this, news_list,
|
||||
news_ll_loading, reuse_no_connection, type,
|
||||
news_rl_label, news_tv_label);
|
||||
news_list.setAdapter(adapter);
|
||||
} else if (adapter.isNetworkError()) {
|
||||
adapter.setNetworkError(false);
|
||||
adapter.notifyItemChanged(adapter.getItemCount());
|
||||
adapter.addList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(NewsOrRaidersActivity.class);
|
||||
news_list = null;
|
||||
layoutManager = null;
|
||||
adapter = null;
|
||||
news_ll_loading = null;
|
||||
reuse_no_connection = null;
|
||||
news_tv_label = null;
|
||||
news_rl_label = null;
|
||||
rparams = null;
|
||||
type = null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -23,6 +23,7 @@ import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.TrafficUtils;
|
||||
@ -73,7 +74,6 @@ import java.util.Set;
|
||||
public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
private ConcernManager concernManager;
|
||||
private PackageManager manager;
|
||||
private SharedPreferences sp;
|
||||
private boolean isFirst;
|
||||
|
||||
@ -81,11 +81,16 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
private String from;
|
||||
|
||||
private long start = 0L;
|
||||
private long end = 0L;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
isFirst = true;
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
@ -127,15 +132,14 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
|
||||
return pics.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
|
||||
ImageView iv = new ImageView(SplashScreenActivity.this);
|
||||
iv.setBackgroundResource(pics[position]);
|
||||
// iv.setBackgroundResource(pics[position]);
|
||||
ImageUtils.getInstance(SplashScreenActivity.this).display("drawable://" + pics[position], iv, -1);
|
||||
if (position == pics.length - 1) {
|
||||
iv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -153,13 +157,11 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
|
||||
return view == object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
|
||||
container.removeView((View) object);
|
||||
object = null;
|
||||
}
|
||||
@ -168,7 +170,6 @@ 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)) {
|
||||
Intent intent = new Intent(SplashScreenActivity.this,
|
||||
@ -184,7 +185,6 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
if (hasFocus && isFirst) {
|
||||
|
||||
@ -229,7 +229,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
getPlatform();
|
||||
}
|
||||
|
||||
getDownloadStatus();
|
||||
// getDownloadStatus();
|
||||
|
||||
getUISetting();
|
||||
|
||||
@ -241,7 +241,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
/*
|
||||
* 初始化已安装软件map,获取游戏更新列表和已安装列表
|
||||
*/
|
||||
manager = new PackageManager(getApplicationContext());
|
||||
PackageManager manager = new PackageManager(getApplicationContext());
|
||||
manager.getInstalledMapFromLocal();
|
||||
|
||||
getInstalledListFromServer();
|
||||
@ -320,7 +320,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
/*
|
||||
* 检查下载文件夹下是否有旧版本的光环助手的包,有这删除
|
||||
* 检查下载文件夹下是否有旧版本的光环助手的包,有则删除
|
||||
*/
|
||||
private void checkUpdateFile() {
|
||||
File file = new File(FileUtils.getDownloadDir(this) + File.separator);
|
||||
@ -384,7 +384,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
private int iCount;
|
||||
|
||||
private void getInstalledListFromServer() {
|
||||
List<String> list = manager.getLocalPackageName();
|
||||
List<String> list = PackageManager.getLocalPackageName(getApplicationContext());
|
||||
final int count = list.size();
|
||||
final List<JSONObject> data = new ArrayList<JSONObject>();
|
||||
final List<String> useParams = new ArrayList<String>();
|
||||
@ -392,8 +392,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
final String packageName = list.get(i);
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v1d45/support/package/" + list.get(i)
|
||||
+ "/game/digest",
|
||||
Config.HOST + "v1d45/support/package/" + list.get(i) + "/game/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
|
||||
@Override
|
||||
@ -454,7 +453,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
char[] clhs = lhs.toCharArray();
|
||||
char[] crhs = rhs.toCharArray();
|
||||
int length = 0;
|
||||
int length;
|
||||
if (clhs.length < crhs.length) {
|
||||
length = clhs.length;
|
||||
} else if (clhs.length > crhs.length) {
|
||||
@ -668,8 +667,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
if (height == 0) {
|
||||
final ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null) {
|
||||
sp.edit().putInt("actionbar_height", actionBar.getHeight())
|
||||
.apply();
|
||||
sp.edit().putInt("actionbar_height", actionBar.getHeight()).apply();
|
||||
}
|
||||
}
|
||||
|
||||
@ -688,6 +686,10 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
intent.putExtra("path", getIntent().getStringExtra("path"));
|
||||
}
|
||||
|
||||
end = System.currentTimeMillis();
|
||||
|
||||
Utils.log("time = " + (end - start));
|
||||
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ 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;
|
||||
|
||||
@ -30,7 +31,6 @@ import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBPWDismiss;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.plugin.Plugin2Fragment;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
@ -43,7 +43,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class HotCardActivity extends BaseActivity {
|
||||
public class SubjectActivity extends BaseActivity {
|
||||
|
||||
private RecyclerView hotcard_list;
|
||||
private HotCardAdapter adapter;
|
||||
@ -116,9 +116,15 @@ public class HotCardActivity extends BaseActivity {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
String id = getIntent().getStringExtra("id");
|
||||
String name = getIntent().getStringExtra("name");
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
name = "";
|
||||
}
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_hotcard, null);
|
||||
|
||||
init(contentView, "热门卡牌");
|
||||
init(contentView, name);
|
||||
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
@ -139,14 +145,14 @@ public class HotCardActivity extends BaseActivity {
|
||||
hotcard_list.setAdapter(adapter);
|
||||
hotcard_list.addItemDecoration(new VerticalItemDecoration(this, 1));
|
||||
|
||||
addList();
|
||||
addList(id);
|
||||
|
||||
}
|
||||
|
||||
private void addList() {
|
||||
private void addList(String id) {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d45/game/remenkapai", Constants.GAME_CD),
|
||||
+ "v1d50/game/column/" + id, Constants.GAME_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
|
||||
@Override
|
||||
@ -165,15 +171,14 @@ public class HotCardActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, Plugin2Fragment.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);
|
||||
List<GameEntity> gameList = gson.fromJson(response.toString(), listType);
|
||||
if (gameList != null && !gameList.isEmpty()) {
|
||||
for (GameEntity entity : gameList) {
|
||||
// 黄壮华 初始化游戏状态 修改2015/8/15
|
||||
@ -240,8 +245,7 @@ public class HotCardActivity extends BaseActivity {
|
||||
adapter.setList(entities);
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getApplicationContext()).addObserver(
|
||||
dataWatcher);
|
||||
DownloadManager.getInstance(getApplicationContext()).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -249,15 +253,14 @@ public class HotCardActivity extends BaseActivity {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
statusMap.clear();
|
||||
DownloadManager.getInstance(getApplicationContext()).removeObserver(
|
||||
dataWatcher);
|
||||
DownloadManager.getInstance(getApplicationContext()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(Plugin2Fragment.class);
|
||||
AppController.canclePendingRequests(SubjectActivity.class);
|
||||
hotcard_list = null;
|
||||
adapter = null;
|
||||
hotcard_ll_loading = null;
|
||||
@ -10,6 +10,7 @@ import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
import android.widget.RelativeLayout;
|
||||
@ -26,207 +27,238 @@ import java.net.HttpURLConnection;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 查看游戏截图页面
|
||||
*
|
||||
*
|
||||
* @author 黄壮华
|
||||
*
|
||||
*/
|
||||
public class ViewImageActivity extends BaseActivity implements
|
||||
OnPageChangeListener {
|
||||
OnPageChangeListener {
|
||||
|
||||
private ViewPager viewimage_vp_show;
|
||||
private ViewImageAdapter adapter;
|
||||
private View viewimage_slide_line;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
private ViewPager viewimage_vp_show;
|
||||
private ViewImageAdapter adapter;
|
||||
private View viewimage_slide_line;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
private ArrayList<String> urls;
|
||||
private int current;
|
||||
private int width;
|
||||
private String scaleType;
|
||||
|
||||
private ArrayList<String> urls;
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
notifyItemChanged(msg.arg1);
|
||||
}
|
||||
};
|
||||
|
||||
private int current;
|
||||
private int width;
|
||||
private String scaleType;
|
||||
private void notifyItemChanged(int position) {
|
||||
Object object = viewimage_vp_show.findViewWithTag(position);
|
||||
if (object != null) {
|
||||
RelativeLayout view = (RelativeLayout) object;
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
final ProgressBarCircularIndeterminate progressBar = (ProgressBarCircularIndeterminate) view.findViewById(R.id.viewimage_pb_loading);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
if (scaleType != null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, ScaleType.FIT_CENTER, new ImageUtils.OnLoadingCompleteListener() {
|
||||
@Override
|
||||
public void onLoadingComplete() {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, new ImageUtils.OnLoadingCompleteListener() {
|
||||
@Override
|
||||
public void onLoadingComplete() {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
notifyItemChanged(msg.arg1);
|
||||
}
|
||||
};
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
private void notifyItemChanged(int position) {
|
||||
Object object = viewimage_vp_show.findViewWithTag(position);
|
||||
if (object != null) {
|
||||
RelativeLayout view = (RelativeLayout) object;
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
final ProgressBarCircularIndeterminate progressBar = (ProgressBarCircularIndeterminate) view.findViewById(R.id.viewimage_pb_loading);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
if (scaleType != null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, ScaleType.FIT_CENTER, new ImageUtils.OnLoadingCompleteListener() {
|
||||
@Override
|
||||
public void onLoadingComplete() {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, new ImageUtils.OnLoadingCompleteListener() {
|
||||
@Override
|
||||
public void onLoadingComplete() {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Intent intent = getIntent();
|
||||
urls = intent.getStringArrayListExtra("urls");
|
||||
current = intent.getIntExtra("current", 0);
|
||||
scaleType = intent.getStringExtra("ScaleType");
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState != null) {
|
||||
current = savedInstanceState.getInt("currentItem", 0);
|
||||
}
|
||||
|
||||
Intent intent = getIntent();
|
||||
urls = intent.getStringArrayListExtra("urls");
|
||||
current = intent.getIntExtra("current", 0);
|
||||
scaleType = intent.getStringExtra("ScaleType");
|
||||
setContentView(R.layout.activity_viewimage);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
current = savedInstanceState.getInt("currentItem", 0);
|
||||
}
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
width = outMetrics.widthPixels / urls.size();
|
||||
|
||||
setContentView(R.layout.activity_viewimage);
|
||||
rparams = new RelativeLayout.LayoutParams(width, DisplayUtils.dip2px(
|
||||
getApplicationContext(), 1));
|
||||
rparams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
rparams.bottomMargin = DisplayUtils.dip2px(getApplicationContext(), 10);
|
||||
rparams.leftMargin = width * current;
|
||||
viewimage_slide_line = findViewById(R.id.viewimage_slide_line);
|
||||
viewimage_slide_line.setLayoutParams(rparams);
|
||||
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
width = outMetrics.widthPixels / urls.size();
|
||||
viewimage_vp_show = (ViewPager) findViewById(R.id.viewimage_vp_show);
|
||||
adapter = new ViewImageAdapter();
|
||||
viewimage_vp_show.setAdapter(adapter);
|
||||
viewimage_vp_show.setCurrentItem(current);
|
||||
viewimage_vp_show.addOnPageChangeListener(this);
|
||||
}
|
||||
|
||||
rparams = new RelativeLayout.LayoutParams(width, DisplayUtils.dip2px(
|
||||
getApplicationContext(), 1));
|
||||
rparams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
rparams.bottomMargin = DisplayUtils.dip2px(getApplicationContext(), 10);
|
||||
rparams.leftMargin = width * current;
|
||||
viewimage_slide_line = findViewById(R.id.viewimage_slide_line);
|
||||
viewimage_slide_line.setLayoutParams(rparams);
|
||||
|
||||
viewimage_vp_show = (ViewPager) findViewById(R.id.viewimage_vp_show);
|
||||
adapter = new ViewImageAdapter();
|
||||
viewimage_vp_show.setAdapter(adapter);
|
||||
viewimage_vp_show.setCurrentItem(current);
|
||||
viewimage_vp_show.addOnPageChangeListener(this);
|
||||
}
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("currentItem", viewimage_vp_show.getCurrentItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("currentItem", viewimage_vp_show.getCurrentItem());
|
||||
}
|
||||
private class ViewImageAdapter extends PagerAdapter implements
|
||||
OnSingleTapListener {
|
||||
|
||||
private class ViewImageAdapter extends PagerAdapter implements
|
||||
OnSingleTapListener {
|
||||
@Override
|
||||
public int getCount() {
|
||||
return urls.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return urls.size();
|
||||
}
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
String url = urls.get(position);
|
||||
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 (scaleType != null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, ScaleType.FIT_CENTER);
|
||||
} else {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView);
|
||||
}
|
||||
if (!urls.get(position).startsWith("http://image.ghzhushou.com/pic/hq/")) {
|
||||
checkUrl(urls.get(position));
|
||||
}
|
||||
ViewParent parent = imageView.getParent();
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
Gh_ImageLayout view = (Gh_ImageLayout) View.inflate(container.getContext(),
|
||||
R.layout.viewimage_item, null);
|
||||
view.setOnSingleTapListener(this);
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
if (scaleType != null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, ScaleType.FIT_CENTER);
|
||||
} else {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView);
|
||||
}
|
||||
if (!urls.get(position).startsWith("http://image.ghzhushou.com/pic/hq/")) {
|
||||
checkUrl(urls.get(position));
|
||||
}
|
||||
view.setTag(position);
|
||||
container.addView(view);
|
||||
return view;
|
||||
}
|
||||
if (parent != null) {
|
||||
ViewGroup parent1 = (ViewGroup) parent;
|
||||
parent1.removeView(imageView);
|
||||
}
|
||||
view.setTag(position);
|
||||
container.addView(imageView);
|
||||
return imageView;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view == object;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
container.removeView((View) object);
|
||||
object = null;
|
||||
}
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view == object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSingleTap() {
|
||||
finish();
|
||||
}
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
// container.removeView((View) object);
|
||||
// object = null;
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onSingleTap() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int newState) {
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int newState) {
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset,
|
||||
int positionOffsetPixels) {
|
||||
if (positionOffset != 0) {
|
||||
rparams.leftMargin = (int) (width * (positionOffset + position));
|
||||
viewimage_slide_line.setLayoutParams(rparams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset,
|
||||
int positionOffsetPixels) {
|
||||
if (positionOffset != 0) {
|
||||
rparams.leftMargin = (int) (width * (positionOffset + position));
|
||||
viewimage_slide_line.setLayoutParams(rparams);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
|
||||
private void checkUrl(final String url) {
|
||||
if (!url.startsWith("http://image.ghzhushou.com/pic/")){
|
||||
return;
|
||||
}
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String newUrl = "http://image.ghzhushou.com/pic/hq" + url.substring(url.lastIndexOf("/"));
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(newUrl).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(5 * 1000);
|
||||
connection.setReadTimeout(5 * 1000);
|
||||
connection.connect();
|
||||
int code = connection.getResponseCode();
|
||||
if (code == 200) {
|
||||
//图片存在
|
||||
for (int i = 0, size = urls.size(); i < size; i++) {
|
||||
if (urls.get(i).equals(url)){
|
||||
urls.set(i, newUrl);
|
||||
Message msg = new Message();
|
||||
msg.arg1 = i;
|
||||
handler.sendMessage(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
viewimage_vp_show = null;
|
||||
adapter = null;
|
||||
viewimage_slide_line = null;
|
||||
rparams = null;
|
||||
urls = null;
|
||||
}
|
||||
private void checkUrl(final String url) {
|
||||
if (!url.startsWith("http://image.ghzhushou.com/pic/")) {
|
||||
return;
|
||||
}
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String newUrl = "http://image.ghzhushou.com/pic/hq" + url.substring(url.lastIndexOf("/"));
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(newUrl).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(5 * 1000);
|
||||
connection.setReadTimeout(5 * 1000);
|
||||
connection.connect();
|
||||
int code = connection.getResponseCode();
|
||||
if (code == 200) {
|
||||
//图片存在
|
||||
for (int i = 0, size = urls.size(); i < size; i++) {
|
||||
if (urls.get(i).equals(url)) {
|
||||
urls.set(i, newUrl);
|
||||
Message msg = new Message();
|
||||
msg.arg1 = i;
|
||||
handler.sendMessage(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
viewimage_vp_show = null;
|
||||
adapter = null;
|
||||
viewimage_slide_line = null;
|
||||
rparams = null;
|
||||
urls = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,11 +15,14 @@ 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.GameViewHolder;
|
||||
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;
|
||||
@ -81,48 +84,116 @@ public class HotCardAdapter extends
|
||||
int position) {
|
||||
if (position != list.size()) {
|
||||
|
||||
GameViewHolder holder = (GameViewHolder) viewHolder;
|
||||
if (viewHolder instanceof GameNormalViewHolder) {
|
||||
GameNormalViewHolder holder = (GameNormalViewHolder) viewHolder;
|
||||
|
||||
final GameEntity entity = list.get(position);
|
||||
final GameEntity entity = list.get(position);
|
||||
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(),
|
||||
holder.gameThumb);
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(),
|
||||
holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(entity.getName());
|
||||
} else {
|
||||
holder.gameNameAndSize.setText(entity.getName() + " | "
|
||||
+ entity.getApk().get(0).getSize());
|
||||
}
|
||||
holder.gameDes.setText(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);
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
holder.gameDes.setText(entity.getBrief());
|
||||
} else {
|
||||
holder.gameDes.setText(entity.getApk().get(0).getSize() + " | " + entity.getBrief());
|
||||
}
|
||||
});
|
||||
|
||||
DownloadItemUtils.setOnClickListener(context, holder.downloadBtn,
|
||||
holder.downloadSpeed, holder.downloadPercentage,
|
||||
entity, position, this,
|
||||
statusMap, platformMap, "热门卡牌", dismissEntity, "hotcard:" + entity.getName());
|
||||
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);
|
||||
}
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.gameProgressbar, holder.gameInfo,
|
||||
holder.downloadSpeed, holder.downloadPercentage,
|
||||
holder.downloadBtn, entity, platformMap, statusMap);
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,15 +204,21 @@ public class HotCardAdapter extends
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
View view;
|
||||
if (i != list.size()) {
|
||||
view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.home_list_item_gamenormal_type, viewGroup, false);
|
||||
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 = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.refresh_footerview, viewGroup, false);
|
||||
return new FooterViewHolder(view);
|
||||
}
|
||||
return new GameViewHolder(view);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -11,122 +11,120 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.NewsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.SubjectActivity;
|
||||
import com.gh.gamecenter.entity.SlideEntity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ImagePagerAdapter
|
||||
*
|
||||
*
|
||||
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2014-2-23
|
||||
*/
|
||||
public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
|
||||
private Context context;
|
||||
// private List<Integer> imageIdList;
|
||||
private List<GameEntity> slideList = null;
|
||||
private Context context;
|
||||
// private List<Integer> imageIdList;
|
||||
private List<SlideEntity> slideList = null;
|
||||
|
||||
private int size;
|
||||
private boolean isInfiniteLoop;
|
||||
private int size;
|
||||
private boolean isInfiniteLoop;
|
||||
|
||||
// private ImageIndicator indicator;
|
||||
// private ImageIndicator indicator;
|
||||
|
||||
public ImagePagerAdapter(Context context, List<GameEntity> slideList,
|
||||
boolean isInfiniteLoop) {
|
||||
this.context = context;
|
||||
this.slideList = slideList;
|
||||
this.size = getSize(slideList);
|
||||
this.isInfiniteLoop = isInfiniteLoop;
|
||||
}
|
||||
public ImagePagerAdapter(Context context, List<SlideEntity> slideList,
|
||||
boolean isInfiniteLoop) {
|
||||
this.context = context;
|
||||
this.slideList = slideList;
|
||||
this.size = getSize(slideList);
|
||||
this.isInfiniteLoop = isInfiniteLoop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
// Infinite loop
|
||||
return isInfiniteLoop ? Integer.MAX_VALUE : getSize(slideList);
|
||||
}
|
||||
@Override
|
||||
public int getCount() {
|
||||
// Infinite loop
|
||||
return isInfiniteLoop ? Integer.MAX_VALUE : getSize(slideList);
|
||||
}
|
||||
|
||||
public int getSize(List<GameEntity> sourceList) {
|
||||
return sourceList == null ? 0 : sourceList.size();
|
||||
}
|
||||
public int getSize(List<SlideEntity> sourceList) {
|
||||
return sourceList == null ? 0 : sourceList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* get really position
|
||||
*
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
private int getPosition(int position) {
|
||||
return isInfiniteLoop ? position % size : position;
|
||||
}
|
||||
/**
|
||||
* get really position
|
||||
*
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
private int getPosition(int position) {
|
||||
return isInfiniteLoop ? position % size : position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View view, ViewGroup container) {
|
||||
ViewHolder holder;
|
||||
if (view == null) {
|
||||
holder = new ViewHolder();
|
||||
view = holder.imageView = new ImageView(context);
|
||||
view.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) view.getTag();
|
||||
}
|
||||
@Override
|
||||
public View getView(int position, View view, ViewGroup container) {
|
||||
ViewHolder holder;
|
||||
if (view == null) {
|
||||
holder = new ViewHolder();
|
||||
view = holder.imageView = new ImageView(context);
|
||||
view.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) view.getTag();
|
||||
}
|
||||
|
||||
final GameEntity gameEntity = slideList.get(getPosition(position));
|
||||
final SlideEntity slideEntity = slideList.get(getPosition(position));
|
||||
|
||||
ImageUtils.getInstance(context).display(gameEntity.getSlide(),
|
||||
holder.imageView, R.drawable.preload);
|
||||
// indicator.setPosition(slideList.size(), getPosition(position));
|
||||
ImageUtils.getInstance(context).display(slideEntity.getImage(),
|
||||
holder.imageView, R.drawable.preload);
|
||||
// indicator.setPosition(slideList.size(), getPosition(position));
|
||||
|
||||
holder.imageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
holder.imageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("入口", "插件-精品-滚动图");
|
||||
DataUtils.onEvent(context, "游戏详情", gameEntity.getName(), kv);
|
||||
if ("game".equals(slideEntity.getType())) {
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("gameId", slideEntity.getLink());
|
||||
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", "插件-滚动图");
|
||||
context.startActivity(intent);
|
||||
} else if ("column".equals(slideEntity.getType())) {
|
||||
Intent intent = new Intent(context, SubjectActivity.class);
|
||||
intent.putExtra("id", slideEntity.getLink());
|
||||
intent.putExtra("name", slideEntity.getName());
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "精品-滚动图");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("page", "插件");
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
AppController.put("GameEntity", gameEntity);
|
||||
Intent intent = new Intent(context, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "插件-精品滚动图");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
private static class ViewHolder {
|
||||
ImageView imageView;
|
||||
}
|
||||
private static class ViewHolder {
|
||||
ImageView imageView;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isInfiniteLoop
|
||||
*/
|
||||
public boolean isInfiniteLoop() {
|
||||
return isInfiniteLoop;
|
||||
}
|
||||
/**
|
||||
* @return the isInfiniteLoop
|
||||
*/
|
||||
public boolean isInfiniteLoop() {
|
||||
return isInfiniteLoop;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isInfiniteLoop
|
||||
* the isInfiniteLoop to set
|
||||
*/
|
||||
public ImagePagerAdapter setInfiniteLoop(boolean isInfiniteLoop) {
|
||||
this.isInfiniteLoop = isInfiniteLoop;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @param isInfiniteLoop
|
||||
* the isInfiniteLoop to set
|
||||
*/
|
||||
public ImagePagerAdapter setInfiniteLoop(boolean isInfiniteLoop) {
|
||||
this.isInfiniteLoop = isInfiniteLoop;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,17 +16,15 @@ import com.gh.gamecenter.R;
|
||||
* @des 下拉或上啦刷新中,进度显示控件
|
||||
*/
|
||||
public class FooterViewHolder extends ViewHolder {
|
||||
public View rootView;
|
||||
|
||||
public ContentLoadingProgressBar footerview_progressbar;
|
||||
public TextView footerview_tv_loading;
|
||||
|
||||
public FooterViewHolder(View view) {
|
||||
super(view);
|
||||
rootView = view;
|
||||
footerview_progressbar = (ContentLoadingProgressBar) view
|
||||
.findViewById(R.id.footerview_progressbar);
|
||||
footerview_tv_loading = (TextView) view
|
||||
.findViewById(R.id.footerview_tv_loading);
|
||||
|
||||
footerview_progressbar = (ContentLoadingProgressBar) view.findViewById(R.id.footerview_progressbar);
|
||||
footerview_tv_loading = (TextView) view.findViewById(R.id.footerview_tv_loading);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/5.
|
||||
*/
|
||||
public class GameHeadViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ImageView thumb;
|
||||
public TextView title;
|
||||
public LinearLayout link;
|
||||
public TextView more;
|
||||
|
||||
public GameHeadViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
this.thumb = (ImageView) itemView.findViewById(R.id.head_thumb);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/5.
|
||||
*/
|
||||
public class GameImageViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ImageView image;
|
||||
|
||||
public GameImageViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
image = (ImageView) itemView.findViewById(R.id.home_game_iv_image);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/2.
|
||||
*/
|
||||
public class GameNormalViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView home1_game_order;
|
||||
public ImageView gameThumb;
|
||||
public TextView gameNameAndSize;
|
||||
public TextView downloadBtn;
|
||||
public TextView gameDes;
|
||||
public LinearLayout labelList;
|
||||
public ProgressBar game_progressbar;
|
||||
public LinearLayout game_ll_info;
|
||||
public TextView download_speed;
|
||||
public TextView download_percentage;
|
||||
|
||||
public GameNormalViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
home1_game_order = (TextView) itemView.findViewById(R.id.home1_game_order);
|
||||
gameThumb = (ImageView) itemView.findViewById(R.id.home1_game_thumb);
|
||||
gameNameAndSize = (TextView) itemView.findViewById(R.id.home1_game_nameAndsize);
|
||||
downloadBtn = (TextView) itemView.findViewById(R.id.home1_download_btn);
|
||||
gameDes = (TextView) itemView.findViewById(R.id.home1_game_des);
|
||||
labelList = (LinearLayout) itemView.findViewById(R.id.home1_label_list);
|
||||
game_ll_info = (LinearLayout) itemView.findViewById(R.id.home1_game_ll_info);
|
||||
game_progressbar = (ProgressBar) itemView.findViewById(R.id.home1_game_progressbar);
|
||||
download_speed = (TextView) itemView.findViewById(R.id.home1_download_speed);
|
||||
download_percentage = (TextView) itemView.findViewById(R.id.home1_download_percentage);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/2.
|
||||
*/
|
||||
public class GameTestViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView home2_game_order;
|
||||
public ImageView gameThumb;
|
||||
public TextView gameNameAndSize;
|
||||
public TextView downloadBtn;
|
||||
public TextView gameDes;
|
||||
public TextView gameTestType;
|
||||
public TextView gameTestTime;
|
||||
public LinearLayout labelList;
|
||||
public ProgressBar game_progressbar;
|
||||
public LinearLayout game_ll_info;
|
||||
public TextView download_speed;
|
||||
public TextView download_percentage;
|
||||
|
||||
public GameTestViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
home2_game_order = (TextView) itemView.findViewById(R.id.home2_game_order);
|
||||
gameThumb = (ImageView) itemView.findViewById(R.id.home2_game_thumb);
|
||||
gameNameAndSize = (TextView) itemView.findViewById(R.id.home2_game_nameAndsize);
|
||||
downloadBtn = (TextView) itemView.findViewById(R.id.home2_download_btn);
|
||||
gameDes = (TextView) itemView.findViewById(R.id.home2_game_des);
|
||||
gameTestType = (TextView) itemView.findViewById(R.id.home2_test_type);
|
||||
gameTestTime = (TextView) itemView.findViewById(R.id.home2_test_time);
|
||||
labelList = (LinearLayout) itemView.findViewById(R.id.home2_label_list);
|
||||
game_ll_info = (LinearLayout) itemView.findViewById(R.id.home2_game_ll_info);
|
||||
game_progressbar = (ProgressBar) itemView.findViewById(R.id.home2_game_progressbar);
|
||||
download_speed = (TextView) itemView.findViewById(R.id.home2_download_speed);
|
||||
download_percentage = (TextView) itemView.findViewById(R.id.home2_download_percentage);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
public class GameViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public View view;
|
||||
public TextView gameNameAndSize, downloadSpeed,
|
||||
downloadPercentage, gameDes;
|
||||
public TextView downloadBtn;
|
||||
public ImageView gameThumb;
|
||||
public LinearLayout labelList, gameInfo;
|
||||
public ProgressBar gameProgressbar;
|
||||
|
||||
public GameViewHolder(View convertView) {
|
||||
super(convertView);
|
||||
|
||||
view = convertView;
|
||||
gameNameAndSize = (TextView) convertView
|
||||
.findViewById(R.id.home1_game_nameAndsize);
|
||||
downloadSpeed = (TextView) convertView
|
||||
.findViewById(R.id.home1_download_speed);
|
||||
downloadPercentage = (TextView) convertView
|
||||
.findViewById(R.id.home1_download_percentage);
|
||||
downloadBtn = (TextView) convertView
|
||||
.findViewById(R.id.home1_download_btn);
|
||||
gameDes = (TextView) convertView.findViewById(R.id.home1_game_des);
|
||||
gameThumb = (ImageView) convertView.findViewById(R.id.home1_game_thumb);
|
||||
labelList = (LinearLayout) convertView
|
||||
.findViewById(R.id.home1_label_list);
|
||||
gameInfo = (LinearLayout) convertView
|
||||
.findViewById(R.id.home1_game_ll_info);
|
||||
gameProgressbar = (ProgressBar) convertView
|
||||
.findViewById(R.id.home1_game_progressbar);
|
||||
}
|
||||
|
||||
}
|
||||
@ -11,9 +11,7 @@ import com.gh.gamecenter.R;
|
||||
/**
|
||||
* Created by LGT on 2016/6/6.
|
||||
*/
|
||||
public class OriginalViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public View view;
|
||||
public class NewsImage1ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ImageView fm_read_iv_thumb;
|
||||
public TextView fm_read_tv_title;
|
||||
@ -21,9 +19,9 @@ public class OriginalViewHolder extends RecyclerView.ViewHolder {
|
||||
public TextView fm_read_tv_read;
|
||||
public TextView fm_read_tv_type;
|
||||
|
||||
public OriginalViewHolder(View itemView) {
|
||||
public NewsImage1ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
view = itemView;
|
||||
|
||||
fm_read_iv_thumb = (ImageView) itemView.findViewById(R.id.fm_read_iv_thumb);
|
||||
fm_read_tv_title = (TextView) itemView.findViewById(R.id.fm_read_tv_title);
|
||||
fm_read_ll_read = (LinearLayout) itemView.findViewById(R.id.fm_read_ll_read);
|
||||
@ -0,0 +1,36 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/5.
|
||||
*/
|
||||
public class NewsImage2ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView fm_read2_special2_title;
|
||||
public ImageView fm_read2_special2_thumb1;
|
||||
public ImageView fm_read2_special2_thumb2;
|
||||
public ImageView fm_read2_special2_thumb3;
|
||||
public LinearLayout fm_read2_special2_ll_read;
|
||||
public TextView fm_read2_special2_tv_read;
|
||||
public TextView fm_read2_special2_tv_type;
|
||||
|
||||
public NewsImage2ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
fm_read2_special2_title = (TextView) itemView.findViewById(R.id.fm_read2_special2_title);
|
||||
fm_read2_special2_thumb1 = (ImageView) itemView.findViewById(R.id.fm_read2_special2_thumb1);
|
||||
fm_read2_special2_thumb2 = (ImageView) itemView.findViewById(R.id.fm_read2_special2_thumb2);
|
||||
fm_read2_special2_thumb3 = (ImageView) itemView.findViewById(R.id.fm_read2_special2_thumb3);
|
||||
fm_read2_special2_ll_read = (LinearLayout) itemView.findViewById(R.id.fm_read2_special2_ll_read);
|
||||
fm_read2_special2_tv_read = (TextView) itemView.findViewById(R.id.fm_read2_special2_tv_read);
|
||||
fm_read2_special2_tv_type = (TextView) itemView.findViewById(R.id.fm_read2_special2_tv_type);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/5.
|
||||
*/
|
||||
public class NewsImage3ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView fm_read2_special1_title;
|
||||
public ImageView fm_read2_special1_thumb;
|
||||
public LinearLayout fm_read2_special1_ll_read;
|
||||
public TextView fm_read2_special1_tv_read;
|
||||
public TextView fm_read2_special1_tv_type;
|
||||
|
||||
public NewsImage3ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
fm_read2_special1_title = (TextView) itemView.findViewById(R.id.fm_read2_special1_title);
|
||||
fm_read2_special1_thumb = (ImageView) itemView.findViewById(R.id.fm_read2_special1_thumb);
|
||||
fm_read2_special1_ll_read = (LinearLayout) itemView.findViewById(R.id.fm_read2_special1_ll_read);
|
||||
fm_read2_special1_tv_read = (TextView) itemView.findViewById(R.id.fm_read2_special1_tv_read);
|
||||
fm_read2_special1_tv_type = (TextView) itemView.findViewById(R.id.fm_read2_special1_tv_type);
|
||||
}
|
||||
|
||||
}
|
||||
@ -332,7 +332,7 @@ public class DownLoadManagerFragment extends Fragment {
|
||||
DownloadManager.getInstance(getActivity()).sendMessageDelayed(msg, 1000);
|
||||
} else if ("安装".equals(str)) {
|
||||
DownloadEntry downloadEntry = list.get(getPosition() - 1);
|
||||
String path = downloadEntry.getPath();
|
||||
final String path = downloadEntry.getPath();
|
||||
if (downloadEntry.getMeta().get("isPlugin") != null) {
|
||||
Map<String, Object> kv6 = new HashMap<String, Object>();
|
||||
kv6.put("操作", "点击安装完成");
|
||||
@ -354,7 +354,15 @@ public class DownLoadManagerFragment extends Fragment {
|
||||
startActivity(PackageUtils
|
||||
.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showDialog(getActivity(), path);
|
||||
DialogUtils.showUninstallDialog(getActivity(), new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
MainActivity.uninstallMap.put(
|
||||
PackageUtils.getPackageNameByPath(getActivity(), path), path);
|
||||
startActivity(PackageUtils.getUninstallIntent(getActivity(),
|
||||
path));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,64 +0,0 @@
|
||||
package com.gh.gamecenter.entity;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class CommentEntity {
|
||||
|
||||
@SerializedName("_id")
|
||||
private String id;
|
||||
|
||||
private String content;
|
||||
private String news_id;
|
||||
private UserEntity user;
|
||||
private FeedbackEntity feedback;
|
||||
private long time;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getNews_id() {
|
||||
return news_id;
|
||||
}
|
||||
|
||||
public void setNews_id(String news_id) {
|
||||
this.news_id = news_id;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public UserEntity getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(UserEntity user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public FeedbackEntity getFeedback() {
|
||||
return feedback;
|
||||
}
|
||||
|
||||
public void setFeedback(FeedbackEntity feedback) {
|
||||
this.feedback = feedback;
|
||||
}
|
||||
|
||||
}
|
||||
@ -31,6 +31,12 @@ public class GameEntity {
|
||||
|
||||
private ArrayMap<String, DownloadEntry> entryMap;
|
||||
|
||||
private String image;
|
||||
|
||||
private String type;
|
||||
|
||||
private String pluginPlatform;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@ -114,4 +120,46 @@ public class GameEntity {
|
||||
this.downloadAddWord = downloadAddWord;
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(String image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getPluginPlatform() {
|
||||
return pluginPlatform;
|
||||
}
|
||||
|
||||
public void setPluginPlatform(String pluginPlatform) {
|
||||
this.pluginPlatform = pluginPlatform;
|
||||
}
|
||||
|
||||
public GameEntity clone() {
|
||||
GameEntity gameEntity = new GameEntity();
|
||||
gameEntity.setId(id);
|
||||
gameEntity.setIcon(icon);
|
||||
gameEntity.setName(name);
|
||||
gameEntity.setBrief(brief);
|
||||
gameEntity.setTag(new ArrayList<String>(tag));
|
||||
gameEntity.setApk(new ArrayList<ApkEntity>(apk));
|
||||
gameEntity.setSlide(slide);
|
||||
gameEntity.setTest(test);
|
||||
gameEntity.setDownloadAddWord(downloadAddWord);
|
||||
gameEntity.setEntryMap(new ArrayMap<String, DownloadEntry>(entryMap));
|
||||
gameEntity.setImage(image);
|
||||
gameEntity.setType(type);
|
||||
gameEntity.setPluginPlatform(pluginPlatform);
|
||||
return gameEntity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
51
app/src/main/java/com/gh/gamecenter/entity/SlideEntity.java
Normal file
@ -0,0 +1,51 @@
|
||||
package com.gh.gamecenter.entity;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/6/29.
|
||||
*/
|
||||
public class SlideEntity {
|
||||
|
||||
private String image;
|
||||
|
||||
private String link;
|
||||
|
||||
private String type;
|
||||
|
||||
@SerializedName("text")
|
||||
private String name;
|
||||
|
||||
public void setImage(String image){
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public String getImage(){
|
||||
return this.image;
|
||||
}
|
||||
|
||||
public void setLink(String link){
|
||||
this.link = link;
|
||||
}
|
||||
|
||||
public String getLink(){
|
||||
return this.link;
|
||||
}
|
||||
|
||||
public void setType(String type){
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType(){
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package com.gh.gamecenter.entity;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/1.
|
||||
*/
|
||||
public class SubjectEntity {
|
||||
|
||||
@SerializedName("_id")
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
private boolean order;
|
||||
|
||||
private List<GameEntity> data;
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(boolean order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public List<GameEntity> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List<GameEntity> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,67 +0,0 @@
|
||||
package com.gh.gamecenter.entity;
|
||||
|
||||
public class UserEntity {
|
||||
|
||||
private String account;
|
||||
private String name;
|
||||
private String icon;
|
||||
private String sign;
|
||||
private String mobileNumber;
|
||||
private boolean isActivation;
|
||||
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public void setAccount(String account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(String icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public String getMobileNumber() {
|
||||
return mobileNumber;
|
||||
}
|
||||
|
||||
public void setMobileNumber(String mobileNumber) {
|
||||
this.mobileNumber = mobileNumber;
|
||||
}
|
||||
|
||||
public boolean isActivation() {
|
||||
return isActivation;
|
||||
}
|
||||
|
||||
public void setActivation(boolean isActivation) {
|
||||
this.isActivation = isActivation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserEntity [account=" + account + ", name=" + name + ", icon="
|
||||
+ icon + ", sign=" + sign + ", mobileNumber=" + mobileNumber
|
||||
+ ", isActivation=" + isActivation + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package com.gh.gamecenter.eventbus;
|
||||
|
||||
public class EBLogout {
|
||||
|
||||
private int type;
|
||||
|
||||
public EBLogout(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package com.gh.gamecenter.eventbus;
|
||||
|
||||
public class EBSkipNewPlugin {
|
||||
|
||||
private int type;
|
||||
|
||||
public EBSkipNewPlugin(int type) {
|
||||
super();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
package com.gh.gamecenter.eventbus;
|
||||
|
||||
public class EBSms {
|
||||
|
||||
private String type;
|
||||
private String code;
|
||||
|
||||
public EBSms(String type, String code) {
|
||||
this.type = type;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
}
|
||||
@ -7,16 +7,14 @@ 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.v4.widget.SwipeRefreshLayout.OnRefreshListener;
|
||||
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;
|
||||
@ -24,291 +22,205 @@ 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.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.entity.SubjectEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadDelete;
|
||||
import com.gh.gamecenter.eventbus.EBPWDismiss;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-10 modified 2015-8-12 新游界面
|
||||
* Created by khy on 2016/6/27.
|
||||
*/
|
||||
public class Game1Fragment extends Fragment implements OnRefreshListener {
|
||||
public class Game1Fragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
private View view;
|
||||
private RecyclerView recyclerview;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
private Game1FragmentAdapter adapter;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private ProgressBarCircularIndeterminate game_pb_loading;
|
||||
private View view;
|
||||
private RecyclerView mRecyclerView;
|
||||
private Game1FragmentAdapter adapter;
|
||||
private SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
private ProgressBarCircularIndeterminate mProgressBarCircularIndeterminate;
|
||||
|
||||
// 黄壮华 添加 记录信息的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 ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, String> statusMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
|
||||
private boolean isEverpause = false;
|
||||
private boolean isDestroy = false;
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
private ArrayMap<String, String> statusMap;
|
||||
private boolean isDestroy;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
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 (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 Handler handler = new Handler() {
|
||||
@Override
|
||||
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 DataWatcher dataWatcher = new DataWatcher() {
|
||||
|
||||
// 黄壮华 添加观察者 修改2015/8/15
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
for (Map.Entry<String, DownloadEntry> entry : downloadingEntries.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
if (!game_swipe_refresh.isRefreshing()) {
|
||||
for (java.util.Map.Entry<String, DownloadEntry> entry : downloadingEntries
|
||||
.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
String name = downloadEntry.getName();
|
||||
Integer location = locationMap.get(name);
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
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);
|
||||
|
||||
GameEntity detailedEntity = adapter.getList()
|
||||
.get(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);
|
||||
}
|
||||
private GameEntity getEntityByLocation(int position) {
|
||||
List<GameEntity> pluginList = adapter.getPluginList();
|
||||
List<SubjectEntity> subjectList = adapter.getSubjectList();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
if (!pluginList.isEmpty() && position > 1 && position <= 1 + pluginList.size()) {
|
||||
return pluginList.get(position - 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
int offset = 1;
|
||||
if (!pluginList.isEmpty()) {
|
||||
offset += 1 + pluginList.size();
|
||||
}
|
||||
for (int i = 0, size = subjectList.size(); i < size; i++) {
|
||||
if (position > offset && position <= subjectList.get(i).getData().size() + offset) {
|
||||
return subjectList.get(i).getData().get(position - offset - 1);
|
||||
}
|
||||
offset = subjectList.get(i).getData().size() + offset + 1;
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
return null;
|
||||
}
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.plugin1_fragment, null);
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
dismissEntity = new DismissEntity(false);
|
||||
view = View.inflate(getActivity(), R.layout.plugin1_fragment, null);
|
||||
|
||||
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>();
|
||||
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);
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
|
||||
recyclerview = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
recyclerview.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
recyclerview.setLayoutManager(layoutManager);
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
mRecyclerView = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
|
||||
game_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.game_pb_loading);
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
mSwipeRefreshLayout = (SwipeRefreshLayout) view
|
||||
.findViewById(R.id.game_swipe_refresh);
|
||||
mSwipeRefreshLayout.setColorSchemeResources(R.color.theme_colors);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
|
||||
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);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
});
|
||||
mProgressBarCircularIndeterminate = (ProgressBarCircularIndeterminate) view.findViewById(R.id.game_pb_loading);
|
||||
mProgressBarCircularIndeterminate.setVisibility(View.GONE);
|
||||
|
||||
// 黄壮华 传递引用 修改2015/8/15
|
||||
adapter = new Game1FragmentAdapter(Game1Fragment.this, locationMap,
|
||||
gameMap, platformMap, nameMap, recyclerview,
|
||||
game_swipe_refresh, reuse_no_connection,
|
||||
statusMap, dismissEntity);
|
||||
recyclerview.setAdapter(adapter);
|
||||
recyclerview.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
adapter = new Game1FragmentAdapter(getActivity(), locationMap, statusMap,
|
||||
platformMap, dismissEntity, mSwipeRefreshLayout);
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
mRecyclerView.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView,
|
||||
int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (!isDestroy
|
||||
&& newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& layoutManager.findLastVisibleItemPosition() == adapter
|
||||
.getList().size()) {
|
||||
if (!adapter.isRemove() && !adapter.isLoading()) {
|
||||
adapter.addList(adapter.getList().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
recyclerview.addItemDecoration(new VerticalItemDecoration(
|
||||
getActivity(), 1));
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
if (container != null) {
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (dismissEntity != null) {
|
||||
dismissEntity.setShow(false);
|
||||
}
|
||||
}
|
||||
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) {
|
||||
int location = locationMap.get(name);
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity detailedEntity = adapter.getList().get(location);
|
||||
for (ApkEntity apkEntity : detailedEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
detailedEntity.getEntryMap().remove(
|
||||
apkEntity.getPlatform());
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
game_swipe_refresh.setRefreshing(true);
|
||||
recyclerview.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
} else if (adapter.isNetworkError()) {
|
||||
adapter.setNetworkError(false);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1);
|
||||
adapter.addList(adapter.getList().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
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);
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
}
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
statusMap.clear();
|
||||
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
public boolean isEverpause() {
|
||||
return isEverpause;
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!isDestroy) {
|
||||
adapter = new Game1FragmentAdapter(Game1Fragment.this,
|
||||
locationMap, gameMap, platformMap, nameMap,
|
||||
recyclerview, game_swipe_refresh, reuse_no_connection,
|
||||
statusMap, dismissEntity);
|
||||
recyclerview.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
adapter.setDestroy(true);
|
||||
AppController.canclePendingRequests(Game1Fragment.class);
|
||||
EventBus.getDefault().unregister(this);
|
||||
view = null;
|
||||
recyclerview = null;
|
||||
game_swipe_refresh = null;
|
||||
adapter = null;
|
||||
layoutManager = null;
|
||||
reuse_no_connection = null;
|
||||
locationMap = null;
|
||||
gameMap = null;
|
||||
platformMap = null;
|
||||
nameMap = null;
|
||||
statusMap = null;
|
||||
dismissEntity = null;
|
||||
handler = null;
|
||||
dataWatcher = null;
|
||||
}
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,485 +6,137 @@ 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.v4.widget.SwipeRefreshLayout.OnRefreshListener;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
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.GameActivity;
|
||||
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.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPWDismiss;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.entity.SubjectEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
|
||||
public class Game2Fragment extends Fragment implements OnRefreshListener {
|
||||
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 View view;
|
||||
private RecyclerView recyclerview;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
private Game2FragmentAdapter adapter;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private TextView game_tv_label;
|
||||
private RelativeLayout game_rl_label;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private boolean isEverpause = false;
|
||||
DataWatcher dataWatcher = new DataWatcher() {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 黄壮华 添加 记录信息的map 修改2015/8/18
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
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;
|
||||
}
|
||||
|
||||
private boolean isEverpause = false;
|
||||
|
||||
private boolean isDestroy = false;
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
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);
|
||||
|
||||
private ArrayMap<String, String> statusMap;
|
||||
view = View.inflate(getActivity(), R.layout.plugin1_fragment, null);
|
||||
mRecyclerView = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
mSwipeRefreshLayout = (SwipeRefreshLayout) view
|
||||
.findViewById(R.id.game_swipe_refresh);
|
||||
mSwipeRefreshLayout.setColorSchemeResources(R.color.theme_colors);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
|
||||
private Handler handler = new Handler();
|
||||
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);
|
||||
|
||||
// 黄壮华 添加观察者 修改2015/8/15
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
if (!game_swipe_refresh.isRefreshing()) {
|
||||
for (java.util.Map.Entry<String, DownloadEntry> entry : downloadingEntries
|
||||
.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
Integer location = locationMap.get(downloadEntry.getName());
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
String platform = downloadEntry.getMeta().get(
|
||||
"platform");
|
||||
mRecyclerView.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
}
|
||||
|
||||
LinkedBlockingQueue<String> queue = platformMap
|
||||
.get(downloadEntry.getName());
|
||||
if (queue == null) {
|
||||
queue = new LinkedBlockingQueue<String>();
|
||||
queue.offer(platform);
|
||||
platformMap.put(downloadEntry.getName(), queue);
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
if (container != null) {
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
GameEntity detailedEntity = getEntityByLocation(index);
|
||||
private Handler handler = new Handler();
|
||||
|
||||
if (detailedEntity != null) {
|
||||
if (!"pause".equals(statusMap.get(entry.getValue()
|
||||
.getUrl()))) {
|
||||
ArrayMap<String, DownloadEntry> entryMap = detailedEntity
|
||||
.getEntryMap();
|
||||
if (entryMap == null) {
|
||||
entryMap = new ArrayMap<String, DownloadEntry>();
|
||||
detailedEntity.setEntryMap(entryMap);
|
||||
}
|
||||
entryMap.put(platform, downloadEntry);
|
||||
adapter.notifyItemChanged(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.game_new_testgame_fragment,
|
||||
null);
|
||||
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
gameMap = new ArrayMap<String, ArrayMap<String, DownloadEntry>>();
|
||||
nameMap = new ArrayMap<String, String>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
|
||||
game_rl_label = (RelativeLayout) view.findViewById(R.id.game_rl_label);
|
||||
game_tv_label = (TextView) view.findViewById(R.id.game_tv_label);
|
||||
|
||||
rparams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
|
||||
LayoutParams.WRAP_CONTENT);
|
||||
|
||||
game_swipe_refresh = (SwipeRefreshLayout) view
|
||||
.findViewById(R.id.game_swipe_refresh);
|
||||
game_swipe_refresh.setColorSchemeResources(R.color.theme_colors);
|
||||
game_swipe_refresh.setOnRefreshListener(this);
|
||||
|
||||
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);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
recyclerview = (RecyclerView) view.findViewById(R.id.game_list);
|
||||
recyclerview.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
recyclerview.setLayoutManager(layoutManager);
|
||||
adapter = new Game2FragmentAdapter(getActivity(), locationMap, gameMap,
|
||||
nameMap, platformMap, game_tv_label, recyclerview,
|
||||
game_swipe_refresh, reuse_no_connection,
|
||||
statusMap, dismissEntity);
|
||||
recyclerview.setAdapter(adapter);
|
||||
recyclerview.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
|
||||
int position = layoutManager.findFirstVisibleItemPosition();
|
||||
|
||||
if (position == 0
|
||||
&& layoutManager.findViewByPosition(position).getTop() == 0) {
|
||||
game_rl_label.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (!game_swipe_refresh.isRefreshing()) {
|
||||
game_rl_label.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
if (adapter.getPosition_tomorrow() != -1
|
||||
&& position >= adapter.getPosition_tomorrow()
|
||||
&& position <= adapter.getTomorrowList().size()
|
||||
+ adapter.getPosition_tomorrow()) {
|
||||
game_tv_label.setText("明天");
|
||||
game_tv_label.setBackgroundResource(R.drawable.title_red);
|
||||
} else if (adapter.getPosition_aftertomorrow() != -1
|
||||
&& position >= adapter.getPosition_aftertomorrow()
|
||||
&& position <= adapter.getTheDayAfterTomorrowList()
|
||||
.size() + adapter.getPosition_aftertomorrow()) {
|
||||
game_tv_label.setText("后天");
|
||||
game_tv_label
|
||||
.setBackgroundResource(R.drawable.title_orange);
|
||||
} else if (adapter.getPosition_before() != -1
|
||||
&& position >= adapter.getPosition_before()
|
||||
&& position <= adapter.getBeforeList().size()
|
||||
+ adapter.getPosition_before()) {
|
||||
game_tv_label.setText("昨天/以前");
|
||||
game_tv_label.setBackgroundResource(R.drawable.title_gray);
|
||||
} else if (adapter.getPosition_today() != -1) {
|
||||
game_tv_label.setText("今天");
|
||||
game_tv_label.setBackgroundResource(R.drawable.title_blue);
|
||||
}
|
||||
|
||||
if (position == adapter.getPosition_tomorrow() - 1
|
||||
|| position == adapter.getPosition_aftertomorrow() - 1
|
||||
|| position == adapter.getPosition_before() - 1) {
|
||||
int buttom = layoutManager.findViewByPosition(position)
|
||||
.getBottom();
|
||||
if (buttom <= game_rl_label.getHeight()) {
|
||||
rparams.topMargin = buttom - game_rl_label.getHeight();
|
||||
game_rl_label.setLayoutParams(rparams);
|
||||
} else {
|
||||
rparams.topMargin = 0;
|
||||
game_rl_label.setLayoutParams(rparams);
|
||||
}
|
||||
} else {
|
||||
rparams.topMargin = 0;
|
||||
game_rl_label.setLayoutParams(rparams);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView,
|
||||
int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (!isDestroy
|
||||
&& newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& layoutManager.findLastVisibleItemPosition() == adapter
|
||||
.getItemCount() - 1) {
|
||||
if (!adapter.isRemove() && !adapter.isLoading()) {
|
||||
adapter.addList(adapter.getTotalSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
recyclerview.addItemDecoration(new VerticalItemDecoration(
|
||||
getActivity(), 1));
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
if (container != null) {
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = nameMap.get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
int location = locationMap.get(name);
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity detailedEntity = getEntityByLocation(location);
|
||||
if (detailedEntity != null) {
|
||||
for (ApkEntity apkEntity : detailedEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
detailedEntity.getEntryMap().remove(
|
||||
apkEntity.getPlatform());
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GameEntity getEntityByLocation(int location) {
|
||||
GameEntity entity = null;
|
||||
int tdSize = adapter.getTodayList().size();
|
||||
int tmSize = adapter.getTomorrowList().size();
|
||||
int tdfSize = adapter.getTheDayAfterTomorrowList().size();
|
||||
int bfSize = adapter.getBeforeList().size();
|
||||
if (tdSize != 0 && tmSize == 0 && tdfSize == 0 && bfSize == 0) {
|
||||
entity = adapter.getTodayList().get(location - 1);
|
||||
} else if (tdSize == 0 && tmSize != 0 && tdfSize == 0 && bfSize == 0) {
|
||||
entity = adapter.getTomorrowList().get(location - 1);
|
||||
} else if (tdSize == 0 && tmSize == 0 && tdfSize != 0 && bfSize == 0) {
|
||||
entity = adapter.getTheDayAfterTomorrowList().get(location - 1);
|
||||
} else if (tdSize == 0 && tmSize == 0 && tdfSize == 0 && bfSize != 0) {
|
||||
entity = adapter.getBeforeList().get(location - 1);
|
||||
} else if (tdSize != 0 && tmSize != 0 && tdfSize == 0 && bfSize == 0) {
|
||||
if (location <= tdSize) {
|
||||
entity = adapter.getTodayList().get(location - 1);
|
||||
} else {
|
||||
entity = adapter.getTomorrowList().get(location - tdSize - 2);
|
||||
}
|
||||
} else if (tdSize != 0 && tmSize == 0 && tdfSize != 0 && bfSize == 0) {
|
||||
if (location <= tdSize) {
|
||||
entity = adapter.getTodayList().get(location - 1);
|
||||
} else {
|
||||
entity = adapter.getTheDayAfterTomorrowList().get(
|
||||
location - tdSize - 2);
|
||||
}
|
||||
} else if (tdSize != 0 && tmSize == 0 && tdfSize == 0 && bfSize != 0) {
|
||||
if (location <= tdSize) {
|
||||
entity = adapter.getTodayList().get(location - 1);
|
||||
} else {
|
||||
entity = adapter.getBeforeList().get(location - tdSize - 2);
|
||||
}
|
||||
} else if (tdSize == 0 && tmSize != 0 && tdfSize != 0 && bfSize == 0) {
|
||||
if (location <= tmSize) {
|
||||
entity = adapter.getTomorrowList().get(location - 1);
|
||||
} else {
|
||||
entity = adapter.getTheDayAfterTomorrowList().get(
|
||||
location - tmSize - 2);
|
||||
}
|
||||
} else if (tdSize == 0 && tmSize != 0 && tdfSize == 0 && bfSize != 0) {
|
||||
if (location <= tmSize) {
|
||||
entity = adapter.getTomorrowList().get(location - 1);
|
||||
} else {
|
||||
entity = adapter.getBeforeList().get(location - tmSize - 2);
|
||||
}
|
||||
} else if (tdSize == 0 && tmSize == 0 && tdfSize != 0 && bfSize != 0) {
|
||||
if (location <= tdfSize) {
|
||||
entity = adapter.getTheDayAfterTomorrowList().get(location - 1);
|
||||
} else {
|
||||
entity = adapter.getBeforeList().get(location - tdfSize - 2);
|
||||
}
|
||||
} else if (tdSize != 0 && tmSize != 0 && tdfSize != 0 && bfSize == 0) {
|
||||
if (location <= tdSize) {
|
||||
entity = adapter.getTodayList().get(location - 1);
|
||||
} else if (location > tdSize + 1 && location <= tdSize + tmSize + 1) {
|
||||
entity = adapter.getTomorrowList().get(location - tdSize - 2);
|
||||
} else {
|
||||
entity = adapter.getTheDayAfterTomorrowList().get(
|
||||
location - tdSize - tmSize - 3);
|
||||
}
|
||||
} else if (tdSize != 0 && tmSize != 0 && tdfSize == 0 && bfSize != 0) {
|
||||
if (location <= tdSize) {
|
||||
entity = adapter.getTodayList().get(location - 1);
|
||||
} else if (location > tdSize + 1 && location <= tdSize + tmSize + 1) {
|
||||
entity = adapter.getTomorrowList().get(location - tdSize - 2);
|
||||
} else {
|
||||
entity = adapter.getBeforeList().get(
|
||||
location - tdSize - tmSize - 3);
|
||||
}
|
||||
} else if (tdSize != 0 && tmSize == 0 && tdfSize != 0 && bfSize != 0) {
|
||||
if (location <= tdSize) {
|
||||
entity = adapter.getTodayList().get(location - 1);
|
||||
} else if (location > tdSize + 1
|
||||
&& location <= tdSize + tdfSize + 1) {
|
||||
entity = adapter.getTomorrowList().get(location - tdSize - 2);
|
||||
} else {
|
||||
entity = adapter.getBeforeList().get(
|
||||
location - tdSize - tdfSize - 3);
|
||||
}
|
||||
} else if (tdSize == 0 && tmSize != 0 && tdfSize != 0 && bfSize != 0) {
|
||||
if (location <= tmSize) {
|
||||
entity = adapter.getTomorrowList().get(location - 1);
|
||||
} else if (location > tmSize + 1
|
||||
&& location <= tmSize + tdfSize + 1) {
|
||||
entity = adapter.getTheDayAfterTomorrowList().get(
|
||||
location - tmSize - 2);
|
||||
} else {
|
||||
entity = adapter.getBeforeList().get(
|
||||
location - tmSize - tdfSize - 3);
|
||||
}
|
||||
} else if (tdSize != 0 && tmSize != 0 && tdfSize != 0 && bfSize != 0) {
|
||||
if (location <= tdSize) {
|
||||
entity = adapter.getTodayList().get(location - 1);
|
||||
} else if (location > tdSize + 1 && location <= tdSize + tmSize + 1) {
|
||||
entity = adapter.getTomorrowList().get(location - tdSize - 2);
|
||||
} else if (location > tdSize + tmSize + 2
|
||||
&& location <= tdSize + tmSize + tdfSize + 2) {
|
||||
entity = adapter.getTheDayAfterTomorrowList().get(
|
||||
location - tdSize - tmSize - 3);
|
||||
} else {
|
||||
entity = adapter.getBeforeList().get(
|
||||
location - tdSize - tmSize - tdfSize - 4);
|
||||
}
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (dismissEntity != null) {
|
||||
dismissEntity.setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
game_swipe_refresh.setRefreshing(true);
|
||||
recyclerview.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
} else if (adapter.isNetworkError()) {
|
||||
adapter.setNetworkError(false);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1);
|
||||
adapter.addList(adapter.getTotalSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!isDestroy) {
|
||||
adapter = new Game2FragmentAdapter(getActivity(), locationMap,
|
||||
gameMap, nameMap, platformMap, game_tv_label,
|
||||
recyclerview, game_swipe_refresh, reuse_no_connection,
|
||||
statusMap, dismissEntity);
|
||||
recyclerview.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
ArrayList<GameEntity> tdList = new ArrayList<GameEntity>();
|
||||
for (GameEntity entity : adapter.getTodayList()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
tdList.add(entity);
|
||||
}
|
||||
ArrayList<GameEntity> tmList = new ArrayList<GameEntity>();
|
||||
for (GameEntity entity : adapter.getTomorrowList()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
tmList.add(entity);
|
||||
}
|
||||
ArrayList<GameEntity> dftList = new ArrayList<GameEntity>();
|
||||
for (GameEntity entity : adapter.getTheDayAfterTomorrowList()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
dftList.add(entity);
|
||||
}
|
||||
ArrayList<GameEntity> bftList = new ArrayList<GameEntity>();
|
||||
for (GameEntity entity : adapter.getBeforeList()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
bftList.add(entity);
|
||||
}
|
||||
adapter.setGameList(tdList, tmList, dftList, bftList);
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
statusMap.clear();
|
||||
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
adapter.setDestory(true);
|
||||
AppController.canclePendingRequests(GameActivity.class);
|
||||
EventBus.getDefault().unregister(this);
|
||||
view = null;
|
||||
recyclerview = null;
|
||||
game_swipe_refresh = null;
|
||||
adapter = null;
|
||||
layoutManager = null;
|
||||
game_tv_label = null;
|
||||
game_rl_label = null;
|
||||
rparams = null;
|
||||
reuse_no_connection = null;
|
||||
locationMap = null;
|
||||
gameMap = null;
|
||||
nameMap = null;
|
||||
platformMap = null;
|
||||
statusMap = null;
|
||||
dismissEntity = null;
|
||||
handler = null;
|
||||
dataWatcher = null;
|
||||
}
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
statusMap.clear();
|
||||
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gh.gamecenter.plugin;
|
||||
package com.gh.gamecenter.game;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@ -49,12 +49,12 @@ import de.greenrobot.event.EventBus;
|
||||
* @update 2015-8-11
|
||||
* @des 主页插件fragment
|
||||
*/
|
||||
public class Plugin3Fragment extends Fragment implements OnRefreshListener {
|
||||
public class Game3Fragment extends Fragment implements OnRefreshListener {
|
||||
|
||||
private View view;
|
||||
private RecyclerView recyclerview;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
private Plugin3FragmentAdapter adapter;
|
||||
private Game3FragmentAdapter adapter;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private ProgressBarCircularIndeterminate game_pb_loading;
|
||||
@ -64,12 +64,11 @@ public class Plugin3Fragment extends Fragment implements OnRefreshListener {
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
|
||||
private boolean isEverpause = false;
|
||||
private boolean isDestroy = false;
|
||||
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private boolean isEverpause;
|
||||
private boolean isDestroy;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@ -79,8 +78,7 @@ public class Plugin3Fragment extends Fragment implements OnRefreshListener {
|
||||
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();
|
||||
@ -97,26 +95,21 @@ public class Plugin3Fragment extends Fragment implements OnRefreshListener {
|
||||
// 黄壮华 添加观察者 修改2015/8/15
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
public void onDataChanged(HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
if (!game_swipe_refresh.isRefreshing()) {
|
||||
for (java.util.Map.Entry<String, DownloadEntry> entry : downloadingEntries
|
||||
.entrySet()) {
|
||||
for (java.util.Map.Entry<String, DownloadEntry> entry : downloadingEntries.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
|
||||
Integer location = locationMap.get(downloadEntry.getName());
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
|
||||
GameEntity detailedEntity = adapter.getList()
|
||||
.get(index);
|
||||
GameEntity detailedEntity = adapter.getList().get(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, platformMap, handler,
|
||||
adapter, index, statusMap);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -130,16 +123,18 @@ public class Plugin3Fragment extends Fragment implements OnRefreshListener {
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.plugin1_fragment, null);
|
||||
|
||||
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>();
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
game_swipe_refresh = (SwipeRefreshLayout) view
|
||||
.findViewById(R.id.game_swipe_refresh);
|
||||
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);
|
||||
|
||||
@ -153,8 +148,7 @@ public class Plugin3Fragment extends Fragment implements OnRefreshListener {
|
||||
|
||||
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 = (LinearLayout) view.findViewById(R.id.reuse_no_connection);
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -167,7 +161,7 @@ public class Plugin3Fragment extends Fragment implements OnRefreshListener {
|
||||
});
|
||||
|
||||
// 黄壮华 传递引用 修改2015/8/15
|
||||
adapter = new Plugin3FragmentAdapter(Plugin3Fragment.this, locationMap,
|
||||
adapter = new Game3FragmentAdapter(Game3Fragment.this, locationMap,
|
||||
gameMap, platformMap, nameMap, recyclerview,
|
||||
game_swipe_refresh, reuse_no_connection, statusMap,
|
||||
dismissEntity,game_pb_loading, false);
|
||||
@ -209,8 +203,10 @@ public class Plugin3Fragment extends Fragment implements OnRefreshListener {
|
||||
platformMap.put(busThree.getName(), queue);
|
||||
}
|
||||
Integer location = locationMap.get(busThree.getName());
|
||||
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
|
||||
GameEntity detailedEntity = adapter.getList().get(index);
|
||||
if (TextUtils.isEmpty(busThree.getPlatform())) {
|
||||
detailedEntity.getEntryMap().remove("官方版");
|
||||
@ -234,10 +230,8 @@ public class Plugin3Fragment extends Fragment implements OnRefreshListener {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity detailedEntity = adapter.getList().get(location);
|
||||
for (ApkEntity apkEntity : detailedEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
detailedEntity.getEntryMap().remove(
|
||||
apkEntity.getPlatform());
|
||||
if (apkEntity.getPackageName().equals(busFour.getPackageName())) {
|
||||
detailedEntity.getEntryMap().remove(apkEntity.getPlatform());
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
}
|
||||
@ -269,7 +263,7 @@ public class Plugin3Fragment extends Fragment implements OnRefreshListener {
|
||||
if (busNine.getPosition() != 1) {
|
||||
statusMap.clear();
|
||||
}
|
||||
} else if ("PluginFragment".equals(busNine.getFrom()) && busNine.getPosition() == 2
|
||||
} else if ("GameFragment".equals(busNine.getFrom()) && busNine.getPosition() == 2
|
||||
&& game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
}
|
||||
@ -307,7 +301,7 @@ public class Plugin3Fragment extends Fragment implements OnRefreshListener {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter = new Plugin3FragmentAdapter(Plugin3Fragment.this,
|
||||
adapter = new Game3FragmentAdapter(Game3Fragment.this,
|
||||
locationMap, gameMap, platformMap, nameMap, recyclerview,
|
||||
game_swipe_refresh, reuse_no_connection, statusMap, dismissEntity,
|
||||
game_pb_loading, true);
|
||||
@ -323,7 +317,8 @@ public class Plugin3Fragment extends Fragment implements OnRefreshListener {
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(Plugin3Fragment.class);
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(Game3Fragment.class);
|
||||
EventBus.getDefault().unregister(this);
|
||||
view = null;
|
||||
recyclerview = null;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gh.gamecenter.plugin;
|
||||
package com.gh.gamecenter.game;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@ -28,7 +28,7 @@ import com.gh.download.DownloadEntry;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
@ -65,12 +65,12 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
* @update 2015-8-11
|
||||
* @des 首页插件fragment适配器
|
||||
*/
|
||||
public class Plugin3FragmentAdapter extends
|
||||
public class Game3FragmentAdapter extends
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context context;
|
||||
|
||||
private Plugin3Fragment fragment;
|
||||
private Game3Fragment fragment;
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
@ -94,17 +94,17 @@ public class Plugin3FragmentAdapter extends
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
public Plugin3FragmentAdapter(Plugin3Fragment fment,
|
||||
ArrayMap<String, Integer> lMap,
|
||||
ArrayMap<String, ArrayMap<String, DownloadEntry>> gMap,
|
||||
ArrayMap<String, LinkedBlockingQueue<String>> pMap,
|
||||
ArrayMap<String, String> nMap, RecyclerView rView,
|
||||
SwipeRefreshLayout swipeRefreshLayout,
|
||||
LinearLayout linearLayout,
|
||||
ArrayMap<String, String> sMap,
|
||||
DismissEntity dEntity,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
boolean isLoad) {
|
||||
public Game3FragmentAdapter(Game3Fragment fment,
|
||||
ArrayMap<String, Integer> lMap,
|
||||
ArrayMap<String, ArrayMap<String, DownloadEntry>> gMap,
|
||||
ArrayMap<String, LinkedBlockingQueue<String>> pMap,
|
||||
ArrayMap<String, String> nMap, RecyclerView rView,
|
||||
SwipeRefreshLayout swipeRefreshLayout,
|
||||
LinearLayout linearLayout,
|
||||
ArrayMap<String, String> sMap,
|
||||
DismissEntity dEntity,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
boolean isLoad) {
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
locationMap = lMap;
|
||||
@ -152,9 +152,10 @@ public class Plugin3FragmentAdapter extends
|
||||
}
|
||||
isLoading = true;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d45/plugin/danji?limit=20&offset=" + offset,
|
||||
Constants.GAME_CD), new Response.Listener<JSONArray>() {
|
||||
TimestampUtils.addTimestamp(
|
||||
Config.HOST + "v1d50/game/danjiyouxi?limit=20&offset=" + offset,
|
||||
Constants.GAME_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
@ -162,7 +163,8 @@ public class Plugin3FragmentAdapter extends
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
}, new Response.ErrorListener() {
|
||||
},
|
||||
new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
@ -178,8 +180,7 @@ public class Plugin3FragmentAdapter extends
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
Toast.makeText(context, "网络错误",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
isNetworkError = true;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
@ -187,16 +188,13 @@ public class Plugin3FragmentAdapter extends
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, Plugin3Fragment.class);
|
||||
AppController.addToRequestQueue(request, GameFragment.class);
|
||||
}
|
||||
|
||||
private void processingData(JSONArray response, int offset) {
|
||||
Type listType = new TypeToken<ArrayList<GameEntity>>() {
|
||||
}.getType();
|
||||
Type listType = new TypeToken<ArrayList<GameEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
GameManager manager = new GameManager(context);
|
||||
List<GameEntity> gameList = gson
|
||||
.fromJson(response.toString(), listType);
|
||||
List<GameEntity> gameList = gson.fromJson(response.toString(), listType);
|
||||
if (gameList != null && !gameList.isEmpty()) {
|
||||
if (!list.isEmpty()) {
|
||||
for (int i = 0; i < gameList.size(); i++) {
|
||||
@ -211,6 +209,7 @@ public class Plugin3FragmentAdapter extends
|
||||
}
|
||||
}
|
||||
}
|
||||
GameManager manager = new GameManager(context);
|
||||
for (GameEntity entity : gameList) {
|
||||
// 黄壮华 初始化游戏状态 修改2015/8/15
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
@ -237,7 +236,7 @@ public class Plugin3FragmentAdapter extends
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (gameList.isEmpty() || (offset == 0 && gameList.size() < 20)) {
|
||||
if (gameList == null || gameList.isEmpty() || (offset == 0 && gameList.size() < 20)) {
|
||||
isRemove = true;
|
||||
notifyItemRemoved(getItemCount());
|
||||
}
|
||||
@ -264,89 +263,6 @@ public class Plugin3FragmentAdapter extends
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder,
|
||||
final int position) {
|
||||
if (viewHolder instanceof GameViewHolder) {
|
||||
|
||||
GameViewHolder holder = (GameViewHolder) viewHolder;
|
||||
|
||||
final GameEntity detailedEntity = list.get(position);
|
||||
|
||||
detailedEntity.getApk().get(0).setPlatform("local_plugin");
|
||||
|
||||
ImageUtils.getInstance(context).display(detailedEntity.getIcon(),
|
||||
holder.gameThumb);
|
||||
if (detailedEntity.getApk() == null
|
||||
|| detailedEntity.getApk().isEmpty()) {
|
||||
holder.gameNameAndSize.setText(detailedEntity.getName());
|
||||
} else {
|
||||
holder.gameNameAndSize.setText(detailedEntity.getName()
|
||||
+ " | " + detailedEntity.getApk().get(0).getSize());
|
||||
}
|
||||
holder.gameDes.setText(detailedEntity.getBrief());
|
||||
|
||||
GameViewUtils.setLabelList(context, holder.labelList,
|
||||
detailedEntity.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, "游戏详情", detailedEntity.getName(),
|
||||
kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "单机");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("game", detailedEntity.getName());
|
||||
map.put("page", "插件");
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
AppController.put("GameEntity", detailedEntity);
|
||||
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.downloadSpeed, holder.downloadPercentage,
|
||||
detailedEntity, position, this,
|
||||
statusMap, platformMap, "插件-单机", false, dismissEntity,
|
||||
"单机:" + detailedEntity.getName());
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.gameProgressbar, holder.gameInfo,
|
||||
holder.downloadSpeed, holder.downloadPercentage,
|
||||
holder.downloadBtn, detailedEntity, platformMap, statusMap,
|
||||
false);
|
||||
} else if (viewHolder instanceof FooterViewHolder) {
|
||||
FooterViewHolder holder = (FooterViewHolder) viewHolder;
|
||||
if (isNetworkError) {
|
||||
holder.footerview_progressbar.setVisibility(View.GONE);
|
||||
holder.footerview_tv_loading.setText("加载失败,点击重试");
|
||||
holder.rootView.setClickable(true);
|
||||
holder.rootView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isNetworkError = false;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
addList(list.size());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
holder.footerview_progressbar.setVisibility(View.VISIBLE);
|
||||
holder.footerview_tv_loading.setText("加载中...");
|
||||
holder.rootView.setClickable(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position;
|
||||
@ -355,13 +271,92 @@ public class Plugin3FragmentAdapter extends
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
if (i == list.size()) {
|
||||
return new FooterViewHolder(LayoutInflater.from(
|
||||
viewGroup.getContext()).inflate(
|
||||
R.layout.refresh_footerview, viewGroup, false));
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.refresh_footerview, viewGroup, false);
|
||||
return new FooterViewHolder(view);
|
||||
} else {
|
||||
return new GameViewHolder(LayoutInflater.from(
|
||||
viewGroup.getContext()).inflate(
|
||||
R.layout.home_list_item_gamenormal_type, viewGroup, false));
|
||||
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, list.get(position), position);
|
||||
} else if (viewHolder instanceof FooterViewHolder) {
|
||||
initFooterViewHolder((FooterViewHolder) viewHolder);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "单机");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("game", entity.getName());
|
||||
map.put("page", "游戏");
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
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, "游戏-单机", false, 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,
|
||||
false);
|
||||
}
|
||||
|
||||
private void initFooterViewHolder(FooterViewHolder holder) {
|
||||
if (isNetworkError) {
|
||||
holder.footerview_progressbar.setVisibility(View.GONE);
|
||||
holder.footerview_tv_loading.setText("加载失败,点击重试");
|
||||
holder.itemView.setClickable(true);
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isNetworkError = false;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
addList(list.size());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
holder.footerview_progressbar.setVisibility(View.VISIBLE);
|
||||
holder.footerview_tv_loading.setText("加载中...");
|
||||
holder.itemView.setClickable(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -386,10 +381,6 @@ public class Plugin3FragmentAdapter extends
|
||||
return isLoading;
|
||||
}
|
||||
|
||||
public void setLoading(boolean isLoading) {
|
||||
this.isLoading = isLoading;
|
||||
}
|
||||
|
||||
public boolean isNetworkError() {
|
||||
return isNetworkError;
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gh.gamecenter.plugin;
|
||||
package com.gh.gamecenter.game;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@ -39,7 +39,6 @@ import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SearchActivity;
|
||||
import com.gh.gamecenter.SettingActivity;
|
||||
import com.gh.gamecenter.eventbus.EBRedDot;
|
||||
import com.gh.gamecenter.eventbus.EBSkipNewPlugin;
|
||||
import com.gh.gamecenter.eventbus.EBTopState;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
@ -57,7 +56,7 @@ import de.greenrobot.event.EventBus;
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-8 主页fragment3页面
|
||||
*/
|
||||
public class PluginFragment extends Fragment implements OnClickListener,
|
||||
public class GameFragment extends Fragment implements OnClickListener,
|
||||
OnPageChangeListener {
|
||||
|
||||
private View view, slideLine;
|
||||
@ -70,15 +69,12 @@ public class PluginFragment extends Fragment implements OnClickListener,
|
||||
|
||||
private String hint;
|
||||
|
||||
public static boolean isFirst;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.plugin_container_fragments,
|
||||
null);
|
||||
view = View.inflate(getActivity(), R.layout.plugin_container_fragments, null);
|
||||
|
||||
SharedPreferences sp = getActivity().getSharedPreferences(
|
||||
Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
@ -122,21 +118,11 @@ public class PluginFragment extends Fragment implements OnClickListener,
|
||||
viewPager.setAdapter(new FragmentAdapter(getChildFragmentManager()));
|
||||
viewPager.addOnPageChangeListener(this);
|
||||
|
||||
if (isFirst) {
|
||||
rparams.leftMargin = width + width / 4;
|
||||
slideLine.setLayoutParams(rparams);
|
||||
viewPager.setCurrentItem(1);
|
||||
isFirst = false;
|
||||
jingpinText.setClickable(true);
|
||||
zuixinText.setClickable(false);
|
||||
danjiText.setClickable(true);
|
||||
} else {
|
||||
rparams.leftMargin = width / 4;
|
||||
slideLine.setLayoutParams(rparams);
|
||||
jingpinText.setClickable(false);
|
||||
zuixinText.setClickable(true);
|
||||
danjiText.setClickable(true);
|
||||
}
|
||||
rparams.leftMargin = width / 4;
|
||||
slideLine.setLayoutParams(rparams);
|
||||
jingpinText.setClickable(false);
|
||||
zuixinText.setClickable(true);
|
||||
danjiText.setClickable(true);
|
||||
|
||||
currentItem = viewPager.getCurrentItem();
|
||||
|
||||
@ -145,7 +131,7 @@ public class PluginFragment extends Fragment implements OnClickListener,
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
EventBus.getDefault().post(new EBUISwitch("PluginFragment", viewPager.getCurrentItem()));
|
||||
EventBus.getDefault().post(new EBUISwitch("GameFragment", viewPager.getCurrentItem()));
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
@ -227,17 +213,16 @@ public class PluginFragment extends Fragment implements OnClickListener,
|
||||
public Fragment getItem(int position) {
|
||||
|
||||
if (position == 0) {
|
||||
return new Plugin1Fragment();
|
||||
return new Game1Fragment();
|
||||
} else if (position == 1) {
|
||||
return new Plugin2Fragment();
|
||||
return new Game2Fragment();
|
||||
} else {
|
||||
return new Plugin3Fragment();
|
||||
return new Game3Fragment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
@ -390,7 +375,6 @@ public class PluginFragment extends Fragment implements OnClickListener,
|
||||
jingpinText.setTextColor(getResources().getColor(R.color.theme_colors));
|
||||
zuixinText.setTextColor(0xFF333333);
|
||||
danjiText.setTextColor(0xFF333333);
|
||||
// EventBus.getDefault().post(new EBUISwitch("PluginFragment", 0));
|
||||
} else if (position == 1) {
|
||||
jingpinText.setClickable(true);
|
||||
zuixinText.setClickable(false);
|
||||
@ -398,7 +382,6 @@ public class PluginFragment extends Fragment implements OnClickListener,
|
||||
jingpinText.setTextColor(0xFF333333);
|
||||
zuixinText.setTextColor(getResources().getColor(R.color.theme_colors));
|
||||
danjiText.setTextColor(0xFF333333);
|
||||
// EventBus.getDefault().post(new EBUISwitch("PluginFragment", 1));
|
||||
} else if (position == 2) {
|
||||
jingpinText.setClickable(true);
|
||||
zuixinText.setClickable(true);
|
||||
@ -406,7 +389,6 @@ public class PluginFragment extends Fragment implements OnClickListener,
|
||||
jingpinText.setTextColor(0xFF333333);
|
||||
zuixinText.setTextColor(0xFF333333);
|
||||
danjiText.setTextColor(getResources().getColor(R.color.theme_colors));
|
||||
// EventBus.getDefault().post(new EBUISwitch("PluginFragment", 2));
|
||||
}
|
||||
}
|
||||
|
||||
@ -420,7 +402,7 @@ public class PluginFragment extends Fragment implements OnClickListener,
|
||||
if (currentItem != viewPager.getCurrentItem()) {
|
||||
currentItem = viewPager.getCurrentItem();
|
||||
Utils.log("currentItem = " + currentItem);
|
||||
EventBus.getDefault().post(new EBUISwitch("PluginFragment", currentItem));
|
||||
EventBus.getDefault().post(new EBUISwitch("GameFragment", currentItem));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -434,8 +416,7 @@ public class PluginFragment extends Fragment implements OnClickListener,
|
||||
if ("MainActivity".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() == 1) {
|
||||
EventBus.getDefault().post(
|
||||
new EBUISwitch("PluginFragment", viewPager
|
||||
.getCurrentItem()));
|
||||
new EBUISwitch("GameFragment", viewPager.getCurrentItem()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -455,15 +436,8 @@ public class PluginFragment extends Fragment implements OnClickListener,
|
||||
updateRedDot(busEight.getType());
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBSkipNewPlugin busSix) {
|
||||
if (busSix.getType() == 1) {
|
||||
viewPager.setCurrentItem(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHiddenChanged(boolean hidden) {
|
||||
|
||||
super.onHiddenChanged(hidden);
|
||||
FragmentTransaction transaction = getChildFragmentManager()
|
||||
.beginTransaction();
|
||||
@ -486,7 +460,6 @@ public class PluginFragment extends Fragment implements OnClickListener,
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().unregister(this);
|
||||
view = null;
|
||||
@ -1,30 +0,0 @@
|
||||
package com.gh.gamecenter.gamedetails;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/**
|
||||
* 数据库 fragment
|
||||
* @author 黄壮华
|
||||
*
|
||||
*/
|
||||
public class GameDatabaseFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
return super.onCreateView(inflater, container, savedInstanceState);
|
||||
}
|
||||
}
|
||||
@ -199,17 +199,15 @@ public class GameDetailsFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
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 class GameDetailsOnScrollListener extends
|
||||
RecyclerView.OnScrollListener {
|
||||
private class GameDetailsOnScrollListener extends RecyclerView.OnScrollListener {
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
|
||||
@ -226,8 +224,7 @@ public class GameDetailsFragment extends Fragment {
|
||||
|
||||
rparams.topMargin -= dy;
|
||||
|
||||
EventBus.getDefault().post(
|
||||
new EBMoveTop("top", visibility, rparams.topMargin));
|
||||
EventBus.getDefault().post(new EBMoveTop("top", visibility, rparams.topMargin));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -683,8 +680,7 @@ public class GameDetailsFragment extends Fragment {
|
||||
map);
|
||||
|
||||
fm_gamedetails_tv_primatte_details.setText("收回");
|
||||
fm_gamedetails_iv_primatte_details
|
||||
.setImageResource(R.drawable.up);
|
||||
fm_gamedetails_iv_primatte_details.setImageResource(R.drawable.up);
|
||||
adapter.notifyItemChanged(plugin_position);
|
||||
}
|
||||
}
|
||||
@ -692,8 +688,7 @@ public class GameDetailsFragment extends Fragment {
|
||||
|
||||
}
|
||||
|
||||
private class GameDetailsAdapter extends
|
||||
RecyclerView.Adapter<GameDetailsViewHolder> {
|
||||
private class GameDetailsAdapter extends RecyclerView.Adapter<GameDetailsViewHolder> {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
@ -881,7 +876,6 @@ public class GameDetailsFragment extends Fragment {
|
||||
@Override
|
||||
public GameDetailsViewHolder onCreateViewHolder(ViewGroup viewGroup,
|
||||
int type) {
|
||||
|
||||
View view;
|
||||
if (type == ITEM_TYPE.blank_top1) {
|
||||
RelativeLayout relativeLayout = new RelativeLayout(
|
||||
@ -980,7 +974,6 @@ public class GameDetailsFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
|
||||
if (position == 0) {
|
||||
return ITEM_TYPE.blank_top1;
|
||||
}
|
||||
@ -1156,7 +1149,6 @@ public class GameDetailsFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
|
||||
return entity.getServerInfo().size();
|
||||
}
|
||||
|
||||
@ -1279,7 +1271,6 @@ public class GameDetailsFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
EventBus.getDefault().unregister(this);
|
||||
|
||||
@ -107,7 +107,6 @@ public class GameInformationFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
|
||||
super.onSaveInstanceState(outState);
|
||||
Utils.log(this.getClass().getSimpleName() + " onSaveInstanceState");
|
||||
outState.putString("id", id);
|
||||
@ -665,8 +664,7 @@ public class GameInformationFragment extends Fragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(GameInformationViewHolder viewHolder,
|
||||
int position) {
|
||||
public void onBindViewHolder(GameInformationViewHolder viewHolder, int position) {
|
||||
if (!isNull && position == 2) {
|
||||
if (currentPosition == -1) {
|
||||
viewHolder.item_et_search.setText(keyword);
|
||||
|
||||
@ -1,623 +0,0 @@
|
||||
package com.gh.gamecenter.home;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.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.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
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.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.ConcernActivity;
|
||||
import com.gh.gamecenter.DownloadManagerActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SearchActivity;
|
||||
import com.gh.gamecenter.SettingActivity;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
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.EBRedDot;
|
||||
import com.gh.gamecenter.eventbus.EBTopState;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-8
|
||||
* @update 2015-8-11
|
||||
* @des 主页fragment页面
|
||||
*/
|
||||
public class HomeFragment extends Fragment implements OnClickListener {
|
||||
|
||||
private View view;
|
||||
private RecyclerView recyclerview;
|
||||
private HomeFragmentAdapter adapter;
|
||||
private TextView downloadHint, searchHint;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
// 黄壮华 添加 记录信息的map 修改2015/8/19
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
|
||||
private boolean isEverpause;
|
||||
private boolean isDestroy = false;
|
||||
|
||||
private int currentItem = 0;
|
||||
|
||||
private String hint;
|
||||
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
private PopupWindow popWindow;
|
||||
|
||||
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 (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 黄壮华 添加观察者 修改2015/8/19
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
for (Map.Entry<String, DownloadEntry> entry : downloadingEntries
|
||||
.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
|
||||
Integer location = locationMap.get(downloadEntry.getName());
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
|
||||
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.home1_fragment, null);
|
||||
|
||||
SharedPreferences sp = getActivity().getSharedPreferences(
|
||||
Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
|
||||
LinearLayout home_actionbar = (LinearLayout) view
|
||||
.findViewById(R.id.home_actionbar);
|
||||
LayoutParams lparams = 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");
|
||||
home_actionbar.setPadding(0, top, 0, 0);
|
||||
lparams.height += top;
|
||||
}
|
||||
|
||||
home_actionbar.setLayoutParams(lparams);
|
||||
|
||||
initActionBar();
|
||||
|
||||
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>();
|
||||
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
isEverpause = false;
|
||||
|
||||
recyclerview = (RecyclerView) view.findViewById(R.id.home_list);
|
||||
recyclerview.setHasFixedSize(true);
|
||||
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
|
||||
llm.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
recyclerview.setLayoutManager(llm);
|
||||
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
|
||||
reuse_no_connection = (LinearLayout) view
|
||||
.findViewById(R.id.reuse_no_connection);
|
||||
reuse_no_connection.setOnClickListener(this);
|
||||
|
||||
adapter = new HomeFragmentAdapter(getActivity(), gameMap, locationMap,
|
||||
nameMap, platformMap, reuse_no_connection, recyclerview,
|
||||
statusMap, dismissEntity);
|
||||
recyclerview.setAdapter(adapter);
|
||||
|
||||
recyclerview.addItemDecoration(new VerticalItemDecoration(
|
||||
getActivity(), 1));
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
|
||||
view.findViewById(R.id.actionbar_iv_search).setOnClickListener(this);
|
||||
|
||||
if (Config.isShow) {
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(
|
||||
View.VISIBLE);
|
||||
} else {
|
||||
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();
|
||||
if (downloadSize != 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText(downloadSize + "");
|
||||
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 (updateSize != 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
searchHint = (TextView) view.findViewById(R.id.actionbar_search_input);
|
||||
searchHint.setOnClickListener(this);
|
||||
|
||||
view.findViewById(R.id.actionbar_notification).setOnClickListener(this);
|
||||
|
||||
view.findViewById(R.id.actionbar_overflow).setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final int id = v.getId();
|
||||
if (id == R.id.actionbar_notification) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "关注图标");
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "关注图标");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("page", "主页");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
startActivity(new Intent(getActivity(), ConcernActivity.class));
|
||||
} else if (id == R.id.actionbar_rl_download) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "下载图标");
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "下载图标");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("page", "主页");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
if (downloadHint != null
|
||||
&& downloadHint.getVisibility() == View.VISIBLE) {
|
||||
downloadHint.setVisibility(View.GONE);
|
||||
EventBus.getDefault().post(new EBTopState("隐藏", null));
|
||||
}
|
||||
startActivity(new Intent(getActivity(),
|
||||
DownloadManagerActivity.class));
|
||||
} else if (id == R.id.actionbar_search_input) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "搜索框");
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "搜索框");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("page", "主页");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
Intent goSearch = new Intent(getActivity(), SearchActivity.class);
|
||||
goSearch.putExtra("clicked", false);
|
||||
goSearch.putExtra("hint", hint);
|
||||
startActivity(goSearch);
|
||||
} else if (id == R.id.actionbar_iv_search) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "搜索图标");
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "搜索图标");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("page", "主页");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
Intent searchIntent = new Intent(getActivity(),
|
||||
SearchActivity.class);
|
||||
searchIntent.putExtra("clicked", true);
|
||||
searchIntent.putExtra("hint", hint);
|
||||
startActivity(searchIntent);
|
||||
} else if (id == R.id.actionbar_overflow) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "更多图标");
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "更多图标");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("page", "主页");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
popUpOverflow(v);
|
||||
} else if (id == R.id.menu_rl_set) {
|
||||
popWindow.dismiss();
|
||||
startActivity(new Intent(getActivity(), SettingActivity.class));
|
||||
} else if (id == R.id.reuse_no_connection) {
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
recyclerview.setVisibility(View.VISIBLE);
|
||||
adapter = new HomeFragmentAdapter(getActivity(), gameMap,
|
||||
locationMap, nameMap, platformMap, reuse_no_connection,
|
||||
recyclerview, statusMap,
|
||||
dismissEntity);
|
||||
recyclerview.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
|
||||
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) + "");
|
||||
}
|
||||
}
|
||||
|
||||
private void popUpOverflow(View view) {
|
||||
|
||||
Rect frame = new Rect();
|
||||
getActivity().getWindow().getDecorView()
|
||||
.getWindowVisibleDisplayFrame(frame);
|
||||
|
||||
int xOffset = DisplayUtils.dip2px(getActivity(), 5);
|
||||
int yOffset = frame.top + DisplayUtils.dip2px(getActivity(), 48)
|
||||
+ xOffset;
|
||||
|
||||
View popView = View.inflate(getActivity(), R.layout.menu_popwindow,
|
||||
null);
|
||||
popView.findViewById(R.id.menu_rl_set).setOnClickListener(this);
|
||||
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.showAtLocation(view, Gravity.TOP | Gravity.RIGHT, xOffset,
|
||||
yOffset);
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
boolean isRemove = false;
|
||||
for (GameEntity detailedEntity : adapter.getZuixinchajianList()) {
|
||||
if (detailedEntity.getName().equals(busThree.getName())) {
|
||||
if (TextUtils.isEmpty(busThree.getPlatform())) {
|
||||
detailedEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
detailedEntity.getEntryMap().remove(busThree.getPlatform());
|
||||
}
|
||||
isRemove = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isRemove) {
|
||||
for (GameEntity detailedEntity : adapter.getRemenkapaiList()) {
|
||||
if (detailedEntity.getName().equals(busThree.getName())) {
|
||||
if (TextUtils.isEmpty(busThree.getPlatform())) {
|
||||
detailedEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
detailedEntity.getEntryMap().remove(
|
||||
busThree.getPlatform());
|
||||
}
|
||||
isRemove = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isRemove) {
|
||||
for (GameEntity detailedEntity : adapter.getXincekapaiList()) {
|
||||
if (detailedEntity.getName().equals(busThree.getName())) {
|
||||
if (TextUtils.isEmpty(busThree.getPlatform())) {
|
||||
detailedEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
detailedEntity.getEntryMap().remove(
|
||||
busThree.getPlatform());
|
||||
}
|
||||
isRemove = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Integer location = locationMap.get(busThree.getName());
|
||||
if (location != null) {
|
||||
adapter.notifyItemChanged(location.intValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBTopState busTen) {
|
||||
if ("搜索".equals(busTen.getType())) {
|
||||
hint = busTen.getSearchHint();
|
||||
searchHint.setHint(busTen.getSearchHint());
|
||||
} else if ("显示".equals(busTen.getType())) {
|
||||
if (downloadHint != null) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
if (downloadHint != null) {
|
||||
downloadHint.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBRedDot busEight) {
|
||||
updateRedDot(busEight.getType());
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()
|
||||
&& reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
recyclerview.setVisibility(View.VISIBLE);
|
||||
adapter = new HomeFragmentAdapter(getActivity(), gameMap,
|
||||
locationMap, nameMap, platformMap, reuse_no_connection,
|
||||
recyclerview, statusMap,
|
||||
dismissEntity);
|
||||
recyclerview.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("MainActivity".equals(busNine.getFrom())) {
|
||||
currentItem = busNine.getPosition();
|
||||
if (busNine.getPosition() == 0) {
|
||||
adapter.startAutoScroll();
|
||||
} else {
|
||||
adapter.stopAutoScroll();
|
||||
statusMap.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = nameMap.get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
int location = locationMap.get(name).intValue();
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity detailedEntity = getEntityByLocation(location);
|
||||
for (ApkEntity apkEntity : detailedEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
if (detailedEntity.getEntryMap() != null) {
|
||||
detailedEntity.getEntryMap().remove(
|
||||
apkEntity.getPlatform());
|
||||
adapter.notifyItemChanged(location);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GameEntity getEntityByLocation(int location) {
|
||||
GameEntity entity = null;
|
||||
if (location > adapter.getPosition_zuixinchajian()
|
||||
&& location <= adapter.getZuixinchajianListSize()
|
||||
+ adapter.getPosition_zuixinchajian()) {
|
||||
entity = adapter.getZuixinchajianList().get(
|
||||
location - adapter.getPosition_zuixinchajian() - 1);
|
||||
} else if (location > adapter.getPosition_remenkapai()
|
||||
&& location <= adapter.getRemenkapaiListSize()
|
||||
+ adapter.getPosition_remenkapai()) {
|
||||
entity = adapter.getRemenkapaiList().get(
|
||||
location - adapter.getPosition_remenkapai() - 1);
|
||||
} else if (location > adapter.getPosition_xincekapai()
|
||||
&& location <= adapter.getXincekapaiListSize()
|
||||
+ adapter.getPosition_xincekapai()) {
|
||||
entity = adapter.getXincekapaiList().get(
|
||||
location - adapter.getPosition_xincekapai() - 1);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/20
|
||||
DownloadItemUtils.initializeGameMap(getActivity(), gameMap);
|
||||
List<GameEntity> zList = new ArrayList<GameEntity>();
|
||||
if (adapter.getZuixinchajianList() != null) {
|
||||
for (GameEntity entity : adapter.getZuixinchajianList()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
zList.add(entity);
|
||||
}
|
||||
}
|
||||
List<GameEntity> rList = new ArrayList<GameEntity>();
|
||||
if (adapter.getRemenkapaiList() != null) {
|
||||
for (GameEntity entity : adapter.getRemenkapaiList()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
rList.add(entity);
|
||||
}
|
||||
}
|
||||
List<GameEntity> xList = new ArrayList<GameEntity>();
|
||||
if (adapter.getXincekapaiList() != null) {
|
||||
for (GameEntity entity : adapter.getXincekapaiList()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
xList.add(entity);
|
||||
}
|
||||
}
|
||||
adapter.setList(zList, rList, xList);
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
if (currentItem == 0) {
|
||||
adapter.startAutoScroll();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
statusMap.clear();
|
||||
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
|
||||
if (currentItem == 0) {
|
||||
adapter.stopAutoScroll();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(HomeFragment.class);
|
||||
EventBus.getDefault().unregister(this);
|
||||
view = null;
|
||||
recyclerview = null;
|
||||
adapter = null;
|
||||
downloadHint = null;
|
||||
searchHint = null;
|
||||
reuse_no_connection = null;
|
||||
locationMap = null;
|
||||
gameMap = null;
|
||||
platformMap = null;
|
||||
nameMap = null;
|
||||
hint = null;
|
||||
statusMap = null;
|
||||
dismissEntity = null;
|
||||
popWindow = null;
|
||||
handler = null;
|
||||
dataWatcher = null;
|
||||
}
|
||||
}
|
||||
@ -159,7 +159,7 @@ public class PackageManager {
|
||||
* 上下文
|
||||
* @return 已安装软件的包名的集合
|
||||
*/
|
||||
public ArrayList<String> getLocalPackageName() {
|
||||
public static ArrayList<String> getLocalPackageName(Context context) {
|
||||
FilterManager filterManager = new FilterManager(context);
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
List<PackageInfo> packageInfos = context.getPackageManager()
|
||||
|
||||
109
app/src/main/java/com/gh/gamecenter/news/News1Fragment.java
Normal file
@ -0,0 +1,109 @@
|
||||
package com.gh.gamecenter.news;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
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.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/6/29.
|
||||
*/
|
||||
public class News1Fragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
private View view;
|
||||
|
||||
private SwipeRefreshLayout original_swipe_refresh;
|
||||
private RecyclerView original_list;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private News1FragmentAdapter adapter;
|
||||
private ProgressBarCircularIndeterminate original_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private boolean isDestroy;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.fragment_original, null);
|
||||
|
||||
isDestroy = 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);
|
||||
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
original_swipe_refresh.setRefreshing(true);
|
||||
original_list.setVisibility(View.VISIBLE);
|
||||
original_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
original_list.setAdapter(adapter);
|
||||
original_list.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
original_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
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.getNewsList().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
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() {
|
||||
adapter = new News1FragmentAdapter(getActivity(), original_list, original_swipe_refresh,
|
||||
original_pb_loading, reuse_no_connection, true);
|
||||
original_list.setAdapter(adapter);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,492 @@
|
||||
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;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.NoConnectionError;
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.TimeoutError;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.android.volley.toolbox.DiskBasedCache;
|
||||
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.DisplayUtils;
|
||||
import com.gh.common.util.GzipUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.NewsUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.NewsImage1ViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.NewsImage2ViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.NewsImage3ViewHolder;
|
||||
import com.gh.gamecenter.entity.NewsEntity;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/6/30.
|
||||
*/
|
||||
public class News1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
|
||||
private Activity activity;
|
||||
private Context context;
|
||||
private RecyclerView original_list;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
private ProgressBarCircularIndeterminate game_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private List<NewsEntity> newsList;
|
||||
private ArrayMap<String, Integer> viewsMap;
|
||||
private List<String> urlList;
|
||||
|
||||
private boolean isLoading;
|
||||
private boolean isRemove;
|
||||
private boolean isNetworkError;
|
||||
// private boolean isLoaded;
|
||||
|
||||
public News1FragmentAdapter(Activity act,
|
||||
RecyclerView recyclerView,
|
||||
SwipeRefreshLayout swipeRefreshLayout,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
LinearLayout noConnection,
|
||||
boolean isLoad) {
|
||||
activity = act;
|
||||
context = activity;
|
||||
original_list = recyclerView;
|
||||
game_swipe_refresh = swipeRefreshLayout;
|
||||
game_pb_loading = pbLoading;
|
||||
reuse_no_connection = noConnection;
|
||||
|
||||
newsList = new ArrayList<NewsEntity>();
|
||||
viewsMap = new ArrayMap<String, Integer>();
|
||||
urlList = new ArrayList<String>();
|
||||
|
||||
isLoading = false;
|
||||
isRemove = false;
|
||||
isNetworkError = false;
|
||||
// isLoaded = false;
|
||||
|
||||
if (isLoad) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
new Thread(runnable){}.start();
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addList(0);
|
||||
}
|
||||
};
|
||||
|
||||
public void addList(final int offset) {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
isLoading = true;
|
||||
final String url = Config.HOST + "v1d50/news/zixun?limit=10&offset=" + offset;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(url, Constants.NEWS_CD),
|
||||
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()) {
|
||||
game_swipe_refresh.setRefreshing(false);
|
||||
}
|
||||
if (game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
if (list.isEmpty() || (offset == 0 && list.size() < 10)) {
|
||||
isRemove = true;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, NewsFragment.class);
|
||||
}
|
||||
|
||||
private void getNewsViews(final List<NewsEntity> list, final int start) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
StringBuilder ids = new StringBuilder();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
ids.append(list.get(i).getId());
|
||||
ids.append("-");
|
||||
}
|
||||
final String url = "http://data.ghzhushou.com/v1d46/news/" + ids.substring(0, ids.length() - 1) + "/visit";
|
||||
if (!urlList.contains(url)) {
|
||||
urlList.add(url);
|
||||
}
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(url,
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
Utils.log("response = " + response);
|
||||
try {
|
||||
JSONObject jsonObject;
|
||||
for (int i = 0, size = response.length(); i < size; i++) {
|
||||
jsonObject = response.getJSONObject(i);
|
||||
viewsMap.put(jsonObject.getString("id"), jsonObject.getInt("views"));
|
||||
}
|
||||
notifyItemRangeChanged(start, start + list.size() - 1);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, NewsFragment.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == ITEM_TYPE.normal) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.fm_read_item, parent, false);
|
||||
return new NewsImage1ViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.special1) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.fm_read2_special1, parent, false);
|
||||
return new NewsImage3ViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.special2) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.fm_read2_special2, parent, false);
|
||||
return new NewsImage2ViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.refresh_footerview, parent, false);
|
||||
return new FooterViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof NewsImage1ViewHolder) {
|
||||
initNewsImage1ViewHolder((NewsImage1ViewHolder) holder, newsList.get(position), position);
|
||||
} else if (holder instanceof NewsImage3ViewHolder) {
|
||||
initNewsImage3ViewHolder((NewsImage3ViewHolder) holder, newsList.get(position), position);
|
||||
} else if (holder instanceof NewsImage2ViewHolder) {
|
||||
initNewsImage2ViewHolder((NewsImage2ViewHolder) holder, newsList.get(position), position);
|
||||
} else if (holder instanceof FooterViewHolder) {
|
||||
initFooterViewHolder((FooterViewHolder) holder);
|
||||
}
|
||||
}
|
||||
|
||||
private void initNewsImage1ViewHolder(NewsImage1ViewHolder viewHolder, final NewsEntity newsEntity, final int position) {
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "原创");
|
||||
}
|
||||
});
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(0), viewHolder.fm_read_iv_thumb);
|
||||
viewHolder.fm_read_tv_title.setText(newsEntity.getTitle());
|
||||
Integer views = viewsMap.get(newsEntity.getId());
|
||||
if (views == null) {
|
||||
viewHolder.fm_read_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read_ll_read.setVisibility(View.VISIBLE);
|
||||
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);
|
||||
int width = (outMetrics.widthPixels - 4 * DisplayUtils.dip2px(context, 8)) / 3;
|
||||
int height = (int) (width * 3 / 4f);
|
||||
LinearLayout.LayoutParams lparams1 = new LinearLayout.LayoutParams(width, height);
|
||||
viewHolder.fm_read2_special2_thumb1.setLayoutParams(lparams1);
|
||||
LinearLayout.LayoutParams lparams2 = new LinearLayout.LayoutParams(width, height);
|
||||
lparams2.leftMargin = DisplayUtils.dip2px(context, 8);
|
||||
viewHolder.fm_read2_special2_thumb2.setLayoutParams(lparams2);
|
||||
viewHolder.fm_read2_special2_thumb3.setLayoutParams(lparams2);
|
||||
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "原创");
|
||||
}
|
||||
});
|
||||
viewHolder.fm_read2_special2_title.setText(newsEntity.getTitle());
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(0),
|
||||
viewHolder.fm_read2_special2_thumb1);
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(1),
|
||||
viewHolder.fm_read2_special2_thumb2);
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(2),
|
||||
viewHolder.fm_read2_special2_thumb3);
|
||||
Integer views = viewsMap.get(newsEntity.getId());
|
||||
if (views == null) {
|
||||
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 + "次浏览");
|
||||
}
|
||||
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) {
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
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);
|
||||
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 + "次浏览");
|
||||
}
|
||||
setType(viewHolder.fm_read2_special1_tv_type, newsEntity.getType());
|
||||
}
|
||||
|
||||
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;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
addList(newsList.size());
|
||||
}
|
||||
});
|
||||
} else if (isRemove) {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
|
||||
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()) {
|
||||
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(
|
||||
Request.Method.POST, url,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
try {
|
||||
if ("success".equals(response.getString("status"))) {
|
||||
Integer views = viewsMap.get(news_id);
|
||||
if (views == null) {
|
||||
views = new Integer(0);
|
||||
}
|
||||
views += 1;
|
||||
viewsMap.put(news_id, views);
|
||||
notifyItemChanged(position);
|
||||
|
||||
//修改volley缓存
|
||||
modifyVolleyCache(news_id);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
|
||||
}
|
||||
});
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request, NewsFragment.class);
|
||||
}
|
||||
|
||||
private static final String DEFAULT_CACHE_DIR = "volley";
|
||||
|
||||
private void modifyVolleyCache(String id) {
|
||||
String key = null;
|
||||
for (int i = 0, size = urlList.size(); i < size; i++) {
|
||||
if (urlList.get(i).contains(id)) {
|
||||
key = urlList.get(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (key == null) {
|
||||
return;
|
||||
}
|
||||
File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
|
||||
DiskBasedCache cache = new DiskBasedCache(cacheDir);
|
||||
byte[] data = cache.getData(key);
|
||||
if (data != null) {
|
||||
try {
|
||||
JSONArray jsonArray = new JSONArray(new String(GzipUtils.decompressBytes(data)));
|
||||
JSONObject jsonObject;
|
||||
for (int i = 0, size = jsonArray.length(); i < size; i++) {
|
||||
jsonObject = jsonArray.getJSONObject(i);
|
||||
if (jsonObject.getString("id").equals(id)) {
|
||||
jsonObject.put("views", jsonObject.getInt("views") + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Utils.log(jsonArray.toString());
|
||||
cache.modify(key, GzipUtils.compressBytes(jsonArray.toString().getBytes()));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
Utils.log("modifyVolleyCache is null");
|
||||
}
|
||||
}
|
||||
|
||||
private void setType(TextView textView, String type) {
|
||||
if ("活动".equals(type)){
|
||||
textView.setTextColor(context.getResources().getColor(R.color.type_huodong));
|
||||
} else if ("公告".equals(type)){
|
||||
textView.setTextColor(context.getResources().getColor(R.color.type_gonggao));
|
||||
} else {
|
||||
textView.setTextColor(context.getResources().getColor(R.color.type_gonglue));
|
||||
}
|
||||
textView.setText(type);
|
||||
}
|
||||
|
||||
public boolean isRemove() {
|
||||
return isRemove;
|
||||
}
|
||||
|
||||
public boolean isLoading() {
|
||||
return isLoading;
|
||||
}
|
||||
|
||||
public boolean isNetworkError() {
|
||||
return isNetworkError;
|
||||
}
|
||||
|
||||
public List<NewsEntity> getNewsList() {
|
||||
return newsList;
|
||||
}
|
||||
}
|
||||
@ -1,43 +1,50 @@
|
||||
package com.gh.gamecenter;
|
||||
package com.gh.gamecenter.news;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
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.BaseActivity;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.OriginalAdapter;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/6/12.
|
||||
* Created by khy on 2016/6/29.
|
||||
*/
|
||||
public class OriginalActivity extends BaseActivity 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;
|
||||
private OriginalAdapter adapter;
|
||||
private News2FragmentAdapter adapter;
|
||||
private ProgressBarCircularIndeterminate original_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private boolean isDestroy;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_original, null);
|
||||
|
||||
init(contentView, "原创");
|
||||
view = View.inflate(getActivity(), R.layout.fragment_original, null);
|
||||
|
||||
isDestroy = 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);
|
||||
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@ -51,12 +58,12 @@ public class OriginalActivity extends BaseActivity implements SwipeRefreshLayout
|
||||
});
|
||||
|
||||
original_list.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
original_list.setLayoutManager(layoutManager);
|
||||
adapter = new OriginalAdapter(this, original_list, original_swipe_refresh,
|
||||
adapter = new News2FragmentAdapter(getActivity(), original_list, original_swipe_refresh,
|
||||
original_pb_loading, reuse_no_connection, true);
|
||||
original_list.setAdapter(adapter);
|
||||
original_list.addItemDecoration(new VerticalItemDecoration(this, 1));
|
||||
original_list.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
original_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
@ -70,6 +77,17 @@ public class OriginalActivity extends BaseActivity implements SwipeRefreshLayout
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if (container != null){
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
private Handler handler = new Handler();
|
||||
@ -77,27 +95,15 @@ public class OriginalActivity extends BaseActivity implements SwipeRefreshLayout
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter = new OriginalAdapter(OriginalActivity.this, original_list, original_swipe_refresh,
|
||||
adapter = new News2FragmentAdapter(getActivity(), original_list, original_swipe_refresh,
|
||||
original_pb_loading, reuse_no_connection, true);
|
||||
original_list.setAdapter(adapter);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
original_swipe_refresh = null;
|
||||
original_list = null;
|
||||
layoutManager = null;
|
||||
adapter = null;
|
||||
original_pb_loading = null;
|
||||
reuse_no_connection = null;
|
||||
handler = null;
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,7 @@
|
||||
package com.gh.gamecenter.adapter;
|
||||
package com.gh.gamecenter.news;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@ -10,9 +9,7 @@ import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -32,10 +29,11 @@ import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.NewsUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.OriginalActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.OriginalViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.NewsImage1ViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.NewsImage2ViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.NewsImage3ViewHolder;
|
||||
import com.gh.gamecenter.entity.NewsEntity;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
@ -54,7 +52,14 @@ import java.util.List;
|
||||
/**
|
||||
* Created by LGT on 2016/6/3.
|
||||
*/
|
||||
public class OriginalAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
public class News2FragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
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 Activity activity;
|
||||
private Context context;
|
||||
@ -72,12 +77,12 @@ public class OriginalAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
private boolean isNetworkError;
|
||||
// private boolean isLoaded;
|
||||
|
||||
public OriginalAdapter(Activity act,
|
||||
RecyclerView recyclerView,
|
||||
SwipeRefreshLayout swipeRefreshLayout,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
LinearLayout noConnection,
|
||||
boolean isLoad) {
|
||||
public News2FragmentAdapter(Activity act,
|
||||
RecyclerView recyclerView,
|
||||
SwipeRefreshLayout swipeRefreshLayout,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
LinearLayout noConnection,
|
||||
boolean isLoad) {
|
||||
activity = act;
|
||||
context = activity;
|
||||
original_list = recyclerView;
|
||||
@ -115,7 +120,7 @@ public class OriginalAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
return;
|
||||
}
|
||||
isLoading = true;
|
||||
String url = Config.HOST + "v1d46/news?type_group=" + Uri.encode("原创") + "&limit=20&offset=" + offset;
|
||||
final String url = Config.HOST + "v1d50/news/yuanchuang?limit=10&offset=" + offset;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(url, Constants.NEWS_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
@ -134,7 +139,7 @@ public class OriginalAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
if (game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
if (list.isEmpty() || (offset == 0 && list.size() < 20)) {
|
||||
if (list.isEmpty() || (offset == 0 && list.size() < 10)) {
|
||||
isRemove = true;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
@ -167,7 +172,7 @@ public class OriginalAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, OriginalActivity.class);
|
||||
AppController.addToRequestQueue(request, NewsFragment.class);
|
||||
}
|
||||
|
||||
private void getNewsViews(final List<NewsEntity> list, final int start) {
|
||||
@ -205,54 +210,31 @@ public class OriginalAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, OriginalActivity.class);
|
||||
AppController.addToRequestQueue(request, NewsFragment.class);
|
||||
}
|
||||
|
||||
private class OriginalSpecial1ViewHolder extends RecyclerView.ViewHolder{
|
||||
|
||||
private View view;
|
||||
private TextView fm_read2_special1_title;
|
||||
private ImageView fm_read2_special1_thumb;
|
||||
private LinearLayout fm_read2_special1_ll_read;
|
||||
private TextView fm_read2_special1_tv_read;
|
||||
private TextView fm_read2_special1_tv_type;
|
||||
|
||||
public OriginalSpecial1ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
view = itemView;
|
||||
fm_read2_special1_title = (TextView) itemView.findViewById(R.id.fm_read2_special1_title);
|
||||
fm_read2_special1_thumb = (ImageView) itemView.findViewById(R.id.fm_read2_special1_thumb);
|
||||
fm_read2_special1_ll_read = (LinearLayout) itemView.findViewById(R.id.fm_read2_special1_ll_read);
|
||||
fm_read2_special1_tv_read = (TextView) itemView.findViewById(R.id.fm_read2_special1_tv_read);
|
||||
fm_read2_special1_tv_type = (TextView) itemView.findViewById(R.id.fm_read2_special1_tv_type);
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (newsList.isEmpty()){
|
||||
return 0;
|
||||
}
|
||||
return newsList.size() + 1;
|
||||
}
|
||||
|
||||
private class OriginalSpecial2ViewHolder extends RecyclerView.ViewHolder{
|
||||
|
||||
private View view;
|
||||
private TextView fm_read2_special2_title;
|
||||
private ImageView fm_read2_special2_thumb1, fm_read2_special2_thumb2,
|
||||
fm_read2_special2_thumb3;
|
||||
private LinearLayout fm_read2_special2_ll_read;
|
||||
private TextView fm_read2_special2_tv_read;
|
||||
private TextView fm_read2_special2_tv_type;
|
||||
|
||||
public OriginalSpecial2ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
view = itemView;
|
||||
fm_read2_special2_title = (TextView) itemView.findViewById(R.id.fm_read2_special2_title);
|
||||
fm_read2_special2_thumb1 = (ImageView) itemView.findViewById(R.id.fm_read2_special2_thumb1);
|
||||
fm_read2_special2_thumb2 = (ImageView) itemView.findViewById(R.id.fm_read2_special2_thumb2);
|
||||
fm_read2_special2_thumb3 = (ImageView) itemView.findViewById(R.id.fm_read2_special2_thumb3);
|
||||
fm_read2_special2_ll_read = (LinearLayout) itemView.findViewById(R.id.fm_read2_special2_ll_read);
|
||||
fm_read2_special2_tv_read = (TextView) itemView.findViewById(R.id.fm_read2_special2_tv_read);
|
||||
fm_read2_special2_tv_type = (TextView) itemView.findViewById(R.id.fm_read2_special2_tv_type);
|
||||
|
||||
@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
|
||||
@ -260,15 +242,15 @@ public class OriginalAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
if (viewType == ITEM_TYPE.normal) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.fm_read_item, parent, false);
|
||||
return new OriginalViewHolder(view);
|
||||
return new NewsImage1ViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.special1) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.fm_read2_special1, parent, false);
|
||||
return new OriginalSpecial1ViewHolder(view);
|
||||
return new NewsImage3ViewHolder(view);
|
||||
} else if (viewType == ITEM_TYPE.special2) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.fm_read2_special2, parent, false);
|
||||
return new OriginalSpecial2ViewHolder(view);
|
||||
return new NewsImage2ViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.refresh_footerview, parent, false);
|
||||
@ -277,116 +259,116 @@ public class OriginalAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
|
||||
if (holder instanceof OriginalViewHolder) {
|
||||
OriginalViewHolder viewHolder = (OriginalViewHolder) holder;
|
||||
|
||||
final NewsEntity newsEntity = newsList.get(position);
|
||||
viewHolder.view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "原创");
|
||||
}
|
||||
});
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(0), viewHolder.fm_read_iv_thumb);
|
||||
viewHolder.fm_read_tv_title.setText(newsEntity.getTitle());
|
||||
Integer views = viewsMap.get(newsEntity.getId());
|
||||
if (views == null) {
|
||||
viewHolder.fm_read_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read_ll_read.setVisibility(View.VISIBLE);
|
||||
viewHolder.fm_read_tv_read.setText(views + "次浏览");
|
||||
}
|
||||
setType(viewHolder.fm_read_tv_type, newsEntity.getType());
|
||||
} else if (holder instanceof OriginalSpecial1ViewHolder) {
|
||||
OriginalSpecial1ViewHolder viewHolder = (OriginalSpecial1ViewHolder) holder;
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
int height = (int) (outMetrics.widthPixels / 3f) - DisplayUtils.dip2px(context, 8);
|
||||
RelativeLayout.LayoutParams lparams = new RelativeLayout.LayoutParams(
|
||||
RelativeLayout.LayoutParams.MATCH_PARENT, height);
|
||||
lparams.topMargin = DisplayUtils.dip2px(context, 8);
|
||||
lparams.addRule(RelativeLayout.BELOW, R.id.fm_read2_special1_title);
|
||||
viewHolder.fm_read2_special1_thumb.setLayoutParams(lparams);
|
||||
|
||||
final NewsEntity newsEntity = newsList.get(position);
|
||||
viewHolder.view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
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);
|
||||
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 + "次浏览");
|
||||
}
|
||||
setType(viewHolder.fm_read2_special1_tv_type, newsEntity.getType());
|
||||
} else if (holder instanceof OriginalSpecial2ViewHolder) {
|
||||
OriginalSpecial2ViewHolder viewHolder = (OriginalSpecial2ViewHolder) holder;
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
activity.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);
|
||||
viewHolder.fm_read2_special2_thumb1.setLayoutParams(lparams1);
|
||||
LinearLayout.LayoutParams lparams2 = new LinearLayout.LayoutParams(width, height);
|
||||
lparams2.leftMargin = DisplayUtils.dip2px(context, 8);
|
||||
viewHolder.fm_read2_special2_thumb2.setLayoutParams(lparams2);
|
||||
viewHolder.fm_read2_special2_thumb3.setLayoutParams(lparams2);
|
||||
|
||||
final NewsEntity newsEntity = newsList.get(position);
|
||||
viewHolder.view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "原创");
|
||||
}
|
||||
});
|
||||
viewHolder.fm_read2_special2_title.setText(newsEntity.getTitle());
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(0),
|
||||
viewHolder.fm_read2_special2_thumb1);
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(1),
|
||||
viewHolder.fm_read2_special2_thumb2);
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(2),
|
||||
viewHolder.fm_read2_special2_thumb3);
|
||||
Integer views = viewsMap.get(newsEntity.getId());
|
||||
if (views == null) {
|
||||
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 + "次浏览");
|
||||
}
|
||||
setType(viewHolder.fm_read2_special2_tv_type, newsEntity.getType());
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof NewsImage1ViewHolder) {
|
||||
initNewsImage1ViewHolder((NewsImage1ViewHolder) holder, newsList.get(position), position);
|
||||
} else if (holder instanceof NewsImage3ViewHolder) {
|
||||
initNewsImage3ViewHolder((NewsImage3ViewHolder) holder, newsList.get(position), position);
|
||||
} else if (holder instanceof NewsImage2ViewHolder) {
|
||||
initNewsImage2ViewHolder((NewsImage2ViewHolder) holder, newsList.get(position), position);
|
||||
} else if (holder instanceof FooterViewHolder) {
|
||||
FooterViewHolder viewHolder = (FooterViewHolder) holder;
|
||||
if (isNetworkError) {
|
||||
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) {
|
||||
isNetworkError = false;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
addList(newsList.size());
|
||||
}
|
||||
});
|
||||
} else if (isRemove) {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.GONE);
|
||||
viewHolder.footerview_tv_loading.setText("加载完毕");
|
||||
viewHolder.rootView.setClickable(false);
|
||||
initFooterViewHolder((FooterViewHolder) holder);
|
||||
}
|
||||
}
|
||||
|
||||
private void initNewsImage1ViewHolder(NewsImage1ViewHolder viewHolder, final NewsEntity newsEntity, final int position) {
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "原创");
|
||||
}
|
||||
});
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(0), viewHolder.fm_read_iv_thumb);
|
||||
viewHolder.fm_read_tv_title.setText(newsEntity.getTitle());
|
||||
Integer views = viewsMap.get(newsEntity.getId());
|
||||
if (views == null) {
|
||||
viewHolder.fm_read_ll_read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.fm_read_ll_read.setVisibility(View.VISIBLE);
|
||||
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);
|
||||
int width = (outMetrics.widthPixels - 4 * DisplayUtils.dip2px(context, 8)) / 3;
|
||||
int height = (int) (width * 3 / 4f);
|
||||
LinearLayout.LayoutParams lparams1 = new LinearLayout.LayoutParams(width, height);
|
||||
viewHolder.fm_read2_special2_thumb1.setLayoutParams(lparams1);
|
||||
LinearLayout.LayoutParams lparams2 = new LinearLayout.LayoutParams(width, height);
|
||||
lparams2.leftMargin = DisplayUtils.dip2px(context, 8);
|
||||
viewHolder.fm_read2_special2_thumb2.setLayoutParams(lparams2);
|
||||
viewHolder.fm_read2_special2_thumb3.setLayoutParams(lparams2);
|
||||
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
NewsUtils.startNewsActivity(context, newsEntity, "原创");
|
||||
}
|
||||
});
|
||||
viewHolder.fm_read2_special2_title.setText(newsEntity.getTitle());
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(0),
|
||||
viewHolder.fm_read2_special2_thumb1);
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(1),
|
||||
viewHolder.fm_read2_special2_thumb2);
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumbnail().getUrl().get(2),
|
||||
viewHolder.fm_read2_special2_thumb3);
|
||||
Integer views = viewsMap.get(newsEntity.getId());
|
||||
if (views == null) {
|
||||
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 + "次浏览");
|
||||
}
|
||||
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) {
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity.getId(), position);
|
||||
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);
|
||||
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 + "次浏览");
|
||||
}
|
||||
setType(viewHolder.fm_read2_special1_tv_type, newsEntity.getType());
|
||||
}
|
||||
|
||||
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;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
addList(newsList.size());
|
||||
}
|
||||
});
|
||||
} else if (isRemove) {
|
||||
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("点击加载更多");
|
||||
@ -400,46 +382,13 @@ public class OriginalAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
else {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.VISIBLE);
|
||||
viewHolder.footerview_tv_loading.setText("加载中...");
|
||||
viewHolder.rootView.setClickable(false);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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()) {
|
||||
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(
|
||||
@ -471,7 +420,7 @@ public class OriginalAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
}
|
||||
});
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request, OriginalActivity.class);
|
||||
AppController.addToRequestQueue(request, NewsFragment.class);
|
||||
}
|
||||
|
||||
private static final String DEFAULT_CACHE_DIR = "volley";
|
||||
184
app/src/main/java/com/gh/gamecenter/news/News3Fragment.java
Normal file
@ -0,0 +1,184 @@
|
||||
package com.gh.gamecenter.news;
|
||||
|
||||
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.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/6/29.
|
||||
*/
|
||||
public class News3Fragment extends Fragment {
|
||||
|
||||
private View view;
|
||||
private RecyclerView news_list;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private News3FragmentAdapter adapter;
|
||||
private LinearLayout news_ll_loading, reuse_no_connection;
|
||||
private TextView news_tv_label;
|
||||
private RelativeLayout news_rl_label;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
|
||||
private boolean isDestroy;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.fragment_news_or_raiders, null);
|
||||
|
||||
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.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
news_list.setVisibility(View.GONE);
|
||||
news_ll_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);
|
||||
news_list.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
||||
rparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
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);
|
||||
|
||||
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.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
|
||||
int position = layoutManager.findFirstVisibleItemPosition();
|
||||
|
||||
if (adapter.getPosition_today() != -1
|
||||
&& position >= adapter.getPosition_today()
|
||||
&& position <= adapter.getTodaySize()
|
||||
+ adapter.getPosition_today()) {
|
||||
news_tv_label.setText("今天");
|
||||
news_tv_label.setBackgroundResource(R.drawable.title_red);
|
||||
} else if (adapter.getPosition_before() != -1
|
||||
&& position >= adapter.getPosition_before()) {
|
||||
news_tv_label.setText("昨天/以前");
|
||||
news_tv_label.setBackgroundResource(R.drawable.title_gray);
|
||||
}
|
||||
|
||||
if (position == adapter.getPosition_today() - 1
|
||||
|| position == adapter.getPosition_before() - 1) {
|
||||
int buttom = layoutManager.findViewByPosition(position)
|
||||
.getBottom();
|
||||
if (buttom <= news_rl_label.getHeight()) {
|
||||
rparams.topMargin = buttom - news_rl_label.getHeight();
|
||||
news_rl_label.setLayoutParams(rparams);
|
||||
} else {
|
||||
rparams.topMargin = 0;
|
||||
news_rl_label.setLayoutParams(rparams);
|
||||
}
|
||||
} else {
|
||||
rparams.topMargin = 0;
|
||||
news_rl_label.setLayoutParams(rparams);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
news_list.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if (container != null) {
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
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);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new News3FragmentAdapter(getActivity(), news_list,
|
||||
news_ll_loading, reuse_no_connection, "攻略",
|
||||
news_rl_label, news_tv_label);
|
||||
news_list.setAdapter(adapter);
|
||||
} else if (adapter.isNetworkError()) {
|
||||
adapter.setNetworkError(false);
|
||||
adapter.notifyItemChanged(adapter.getItemCount());
|
||||
adapter.addList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(NewsFragment.class);
|
||||
news_list = null;
|
||||
layoutManager = null;
|
||||
adapter = null;
|
||||
news_ll_loading = null;
|
||||
reuse_no_connection = null;
|
||||
news_tv_label = null;
|
||||
news_rl_label = null;
|
||||
rparams = null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,593 @@
|
||||
package com.gh.gamecenter.news;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
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.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.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;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-5 modified 2015-8-21 资讯首页模块
|
||||
*/
|
||||
public class News3FragmentAdapter extends
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
public static class ITEM_TYPE {
|
||||
public static final int head = 1;// head
|
||||
public static final int news_text = 2;// 新闻列表1类型
|
||||
public static final int news_image = 3;// 新闻列表2类型
|
||||
public static final int refresh_footer = 4;// 刷新布局类型
|
||||
}
|
||||
|
||||
private int position_today = -1;// 今天head的位置
|
||||
private int position_before = -1;// 昨天/以前head的位置
|
||||
|
||||
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 LayoutInflater layoutInflater;
|
||||
private Context context;
|
||||
|
||||
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;
|
||||
|
||||
todayNewsList = new ArrayList<NewsEntity>();
|
||||
beforeNewsList = new ArrayList<NewsEntity>();
|
||||
|
||||
this.relativeLayout = relativeLayout;
|
||||
this.textView = textView;
|
||||
|
||||
this.recyclerView = recyclerView;
|
||||
ll_loading = linearLayout1;
|
||||
ll_noconnection = linearLayout2;
|
||||
|
||||
this.layoutInflater = LayoutInflater.from(context);
|
||||
|
||||
initDatas();
|
||||
}
|
||||
|
||||
private void showRecyclerView() {
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
ll_loading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
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() {
|
||||
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>() {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, NewsFragment.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();
|
||||
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);
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index != i) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!beforeNewsList.isEmpty()) {
|
||||
for (int j = 0; j < beforeNewsList.size(); j++) {
|
||||
if (id.equals(beforeNewsList.get(j).getId())) {
|
||||
datas.remove(i);
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index != i) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshCount() {
|
||||
|
||||
position_today = -1;
|
||||
position_before = -1;
|
||||
|
||||
if (!todayNewsList.isEmpty()) {
|
||||
position_today = 0;
|
||||
}
|
||||
|
||||
if (!beforeNewsList.isEmpty()) {
|
||||
if (position_today != -1) {
|
||||
position_before = todayNewsList.size() + 1;
|
||||
} else if (position_today == -1) {
|
||||
position_before = 0;
|
||||
}
|
||||
}
|
||||
if (position_today != -1) {
|
||||
relativeLayout.setVisibility(View.VISIBLE);
|
||||
textView.setText("今天");
|
||||
textView.setBackgroundResource(R.drawable.title_red);
|
||||
} else if (position_before != -1) {
|
||||
relativeLayout.setVisibility(View.VISIBLE);
|
||||
textView.setText("昨天/以前");
|
||||
textView.setBackgroundResource(R.drawable.title_gray);
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int head = 0;
|
||||
if (position_today != -1) {
|
||||
head++;
|
||||
}
|
||||
if (position_before != -1) {
|
||||
head++;
|
||||
}
|
||||
return head + todayNewsList.size() + beforeNewsList.size() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
|
||||
if (position_today != -1) {
|
||||
if (position == position_today) {
|
||||
return ITEM_TYPE.head;
|
||||
}
|
||||
if (position == position_today + 1) {
|
||||
if (!TextUtils.isEmpty(todayNewsList.get(0).getThumb())) {
|
||||
return ITEM_TYPE.news_image;
|
||||
} else {
|
||||
return ITEM_TYPE.news_text;
|
||||
}
|
||||
}
|
||||
if (position > position_today + 1
|
||||
&& position <= todayNewsList.size() + position_today) {
|
||||
return ITEM_TYPE.news_text;
|
||||
}
|
||||
}
|
||||
|
||||
if (position_before != -1) {
|
||||
if (position == position_before) {
|
||||
return ITEM_TYPE.head;
|
||||
}
|
||||
if (position > position_before
|
||||
&& position <= beforeNewsList.size() + position_before) {
|
||||
return ITEM_TYPE.news_text;
|
||||
}
|
||||
}
|
||||
|
||||
return ITEM_TYPE.refresh_footer;
|
||||
}
|
||||
|
||||
@Override
|
||||
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));
|
||||
} else if (viewType == ITEM_TYPE.news_image) {
|
||||
return new ImageNewsTypeViewHolder(layoutInflater.inflate(
|
||||
R.layout.home_list_item_newsimage_type, parent, false));
|
||||
} else if (viewType == ITEM_TYPE.news_text) {
|
||||
return new TextNewsTypeViewHolder(layoutInflater.inflate(
|
||||
R.layout.home_list_item_newsnormal_type, parent, false),
|
||||
viewType);
|
||||
} else {
|
||||
return new FooterViewHolder(layoutInflater.inflate(
|
||||
R.layout.refresh_footerview, parent, false));
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
if (isNetworkError) {
|
||||
holder.footerview_progressbar.setVisibility(View.GONE);
|
||||
holder.footerview_tv_loading.setText("加载失败,点击重试");
|
||||
holder.itemView.setClickable(true);
|
||||
holder.itemView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isNetworkError = false;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
addList();
|
||||
}
|
||||
});
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class HeadViewHolder extends RecyclerView.ViewHolder {
|
||||
public TextView headType;
|
||||
|
||||
public HeadViewHolder(View v) {
|
||||
super(v);
|
||||
headType = (TextView) v.findViewById(R.id.tv_label);
|
||||
}
|
||||
|
||||
public void initViewHolder(int position, RecyclerView.ViewHolder viewHolder) {
|
||||
|
||||
if (position == position_today) {
|
||||
headType.setText("今天");
|
||||
headType.setBackgroundResource(R.drawable.title_red);
|
||||
}
|
||||
|
||||
if (position == position_before) {
|
||||
headType.setText("昨天/以前");
|
||||
headType.setBackgroundResource(R.drawable.title_gray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ImageNewsTypeViewHolder extends RecyclerView.ViewHolder {
|
||||
private ImageView newsThumb;
|
||||
private TextView newsMainTitle, newsSubTitle;
|
||||
private View rootItem;
|
||||
|
||||
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) {
|
||||
final NewsEntity newsEntity = todayNewsList.get(0);
|
||||
ImageUtils.getInstance(context).display(newsEntity.getThumb(), newsThumb);
|
||||
String title = newsEntity.getTitle();
|
||||
if (title.contains("》")) {
|
||||
newsMainTitle.setText(title.substring(0, title.indexOf("》") + 1));
|
||||
newsSubTitle.setVisibility(View.VISIBLE);
|
||||
newsSubTitle.setText(title.substring(title.indexOf("》") + 1));
|
||||
} else if (title.contains(" ")) {
|
||||
newsMainTitle.setText(title.substring(0, title.indexOf(" ") + 1));
|
||||
newsSubTitle.setVisibility(View.VISIBLE);
|
||||
newsSubTitle.setText(title.substring(title.indexOf(" ") + 1));
|
||||
} else {
|
||||
newsMainTitle.setText(title);
|
||||
newsSubTitle.setVisibility(View.GONE);
|
||||
}
|
||||
rootItem.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);
|
||||
|
||||
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);
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
NewsUtils.startNewsActivity(context, newsEntity, type
|
||||
+ "-今天");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class TextNewsTypeViewHolder extends RecyclerView.ViewHolder {
|
||||
public TextView newsType;
|
||||
public TextView newsTitle;
|
||||
private int column;
|
||||
private View rootItem;
|
||||
|
||||
public TextNewsTypeViewHolder(View v, int column) {
|
||||
super(v);
|
||||
rootItem = v;
|
||||
this.column = column;
|
||||
newsType = (TextView) v.findViewById(R.id.news_type);
|
||||
newsTitle = (TextView) v.findViewById(R.id.news_title);
|
||||
}
|
||||
|
||||
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 (newsEntity != null) {
|
||||
final NewsEntity entity = newsEntity;
|
||||
final String entrance = from;
|
||||
newsType.setBackgroundResource(NewsUtils
|
||||
.getDrawableIdByType(entity.getType()));
|
||||
newsType.setText(entity.getType());
|
||||
newsTitle.setText(entity.getTitle());
|
||||
rootItem.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);
|
||||
|
||||
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);
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
NewsUtils.startNewsActivity(context, entity, type + "-"
|
||||
+ entrance);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getAllListSize() {
|
||||
return todayNewsList.size() + beforeNewsList.size();
|
||||
}
|
||||
|
||||
public int getTodaySize() {
|
||||
return todayNewsList.size();
|
||||
}
|
||||
|
||||
public int getBeforeSize() {
|
||||
return beforeNewsList.size();
|
||||
}
|
||||
|
||||
public int getPosition_today() {
|
||||
return position_today;
|
||||
}
|
||||
|
||||
public int getPosition_before() {
|
||||
return position_before;
|
||||
}
|
||||
|
||||
public boolean isRemove() {
|
||||
return isRemove;
|
||||
}
|
||||
|
||||
public void setRemove(boolean isRemove) {
|
||||
this.isRemove = isRemove;
|
||||
}
|
||||
|
||||
public boolean isLoading() {
|
||||
return isLoading;
|
||||
}
|
||||
|
||||
public void setLoading(boolean isLoading) {
|
||||
this.isLoading = isLoading;
|
||||
}
|
||||
|
||||
public boolean isNetworkError() {
|
||||
return isNetworkError;
|
||||
}
|
||||
|
||||
public void setNetworkError(boolean isNetworkError) {
|
||||
this.isNetworkError = isNetworkError;
|
||||
}
|
||||
}
|
||||
118
app/src/main/java/com/gh/gamecenter/news/News4Fragment.java
Normal file
@ -0,0 +1,118 @@
|
||||
package com.gh.gamecenter.news;
|
||||
|
||||
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 com.gh.base.AppController;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/6/29.
|
||||
*/
|
||||
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;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.fragment_news_or_raiders, null);
|
||||
|
||||
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);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new News4FragmentAdapter(getActivity(), news_list,
|
||||
news_ll_loading, reuse_no_connection);
|
||||
news_list.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
||||
news_list.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager( getActivity());
|
||||
news_list.setLayoutManager(layoutManager);
|
||||
|
||||
adapter = new News4FragmentAdapter(getActivity(), news_list,
|
||||
news_ll_loading, reuse_no_connection);
|
||||
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if (container != null) {
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBConcernChanged busSeven) {
|
||||
adapter.updateMyGameNews();
|
||||
}
|
||||
|
||||
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);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new News4FragmentAdapter(getActivity(), news_list,
|
||||
news_ll_loading, reuse_no_connection);
|
||||
news_list.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(NewsFragment.class);
|
||||
news_list = null;
|
||||
layoutManager = null;
|
||||
adapter = null;
|
||||
news_ll_loading = null;
|
||||
reuse_no_connection = null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,601 @@
|
||||
package com.gh.gamecenter.news;
|
||||
|
||||
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.View.OnClickListener;
|
||||
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.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.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.NewsUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.gamecenter.ConcernActivity;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.db.info.SuspectedGameInfo;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameDigestEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.NewsEntity;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.manager.SuspectedGameManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-5 modified 2015-8-21 资讯首页模块
|
||||
*/
|
||||
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;// 刷新布局类型
|
||||
}
|
||||
|
||||
private int count_game = 0;// 游戏+游戏新闻 的数目
|
||||
|
||||
private ConcernManager concernManager;
|
||||
private List<ConcernInfo> concernList;
|
||||
private List<GameEntity> concernGameList;
|
||||
private ArrayMap<String, List<NewsEntity>> concernNewsMap;
|
||||
|
||||
private boolean isNetworkError = false;
|
||||
|
||||
private LayoutInflater layoutInflater;
|
||||
private Context context;
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private LinearLayout ll_loading, ll_noconnection;
|
||||
|
||||
public News4FragmentAdapter(Context con, RecyclerView recyclerView,
|
||||
LinearLayout linearLayout1, LinearLayout linearLayout2) {
|
||||
context = con;
|
||||
|
||||
this.recyclerView = recyclerView;
|
||||
ll_loading = linearLayout1;
|
||||
ll_noconnection = linearLayout2;
|
||||
|
||||
concernManager = new ConcernManager(context);
|
||||
this.layoutInflater = LayoutInflater.from(context);
|
||||
|
||||
// 获取关注的信息
|
||||
concernList = concernManager.getAllConcernBySort();
|
||||
|
||||
if (concernList != null && !concernList.isEmpty()) {
|
||||
sortList();
|
||||
initConcernNews();
|
||||
} else {
|
||||
refreshCount();
|
||||
showRecyclerView();
|
||||
}
|
||||
}
|
||||
|
||||
private void sortList() {
|
||||
Comparator<ConcernInfo> comparator = new Comparator<ConcernInfo>() {
|
||||
@Override
|
||||
public int compare(ConcernInfo lhs, ConcernInfo rhs) {
|
||||
|
||||
if (rhs.getWeight() == 2 && lhs.getWeight() == 2) {
|
||||
return 0;
|
||||
} else if (rhs.getWeight() == 2 && lhs.getWeight() == 1) {
|
||||
return 1;
|
||||
} else if (rhs.getWeight() == 1 && lhs.getWeight() == 2) {
|
||||
return -1;
|
||||
} else {
|
||||
if ("已关注".equals(rhs.getTag())
|
||||
&& "已安装".equals(lhs.getTag())) {
|
||||
return 1;
|
||||
} else if ("已安装".equals(rhs.getTag())
|
||||
&& "已关注".equals(lhs.getTag())) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Collections.sort(concernList, 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 void showRecyclerView() {
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
ll_loading.setVisibility(View.GONE);
|
||||
SuspectedGameManager manager = new SuspectedGameManager(context);
|
||||
List<SuspectedGameInfo> list = manager.getAllGame();
|
||||
if (list != null && !list.isEmpty()) {
|
||||
ll_loading.setVisibility(View.VISIBLE);
|
||||
List<String> params = new ArrayList<String>();
|
||||
for (SuspectedGameInfo entity : list) {
|
||||
params.add(entity.getPackageName());
|
||||
}
|
||||
initSuspectedGame(params);
|
||||
}
|
||||
}
|
||||
|
||||
private int iCount;
|
||||
|
||||
private void initSuspectedGame(final List<String> params) {
|
||||
iCount = 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++) {
|
||||
final String packageName = params.get(i);
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d45/support/package/" + packageName
|
||||
+ "/game/digest", Constants.GAME_CD),
|
||||
new Response.Listener<JSONObject>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
iCount++;
|
||||
if (response.length() != 0) {
|
||||
list.add(response);
|
||||
useParams.add(packageName);
|
||||
}
|
||||
if (params.size() == iCount) {
|
||||
processingData(list, params, useParams);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
iCount++;
|
||||
if (params.size() == iCount) {
|
||||
if (list.isEmpty()) {
|
||||
ll_loading.setVisibility(View.GONE);
|
||||
} else {
|
||||
processingData(list, params, useParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, NewsFragment.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void processingData(List<JSONObject> data, List<String> params,
|
||||
List<String> useParams) {
|
||||
Gson gson = new Gson();
|
||||
ConcernManager manager = new ConcernManager(context);
|
||||
for (int i = 0, size = data.size(); i < size; i++) {
|
||||
GameDigestEntity gameDigestEntity = gson.fromJson(data.get(i)
|
||||
.toString(), GameDigestEntity.class);
|
||||
GameInfo gameEntity = new GameInfo();
|
||||
gameEntity.setId(gameDigestEntity.getId());
|
||||
gameEntity.setPackageName(useParams.get(i));
|
||||
manager.updateByEntity(gameEntity, false);
|
||||
}
|
||||
|
||||
SuspectedGameManager suspectedGameManager = new SuspectedGameManager(
|
||||
context);
|
||||
for (String packageName : params) {
|
||||
suspectedGameManager.deleteSuspectedGame(packageName);
|
||||
}
|
||||
|
||||
if (data.size() > 0) {
|
||||
updateMyGameNews();
|
||||
} else {
|
||||
ll_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--;
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (!concernList.isEmpty()) {
|
||||
int count = 0;
|
||||
for (int i = 0, size = concernList.size(); i < size; i++) {
|
||||
count += (concernNewsMap.get(concernList.get(i).getGameName())
|
||||
.size() + 1);
|
||||
}
|
||||
count_game = count;
|
||||
}
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (count_game == 0) {
|
||||
return 0;
|
||||
}
|
||||
return count_game + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
|
||||
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) {
|
||||
return ITEM_TYPE.game_type;
|
||||
} else if (position > offset
|
||||
&& position <= concernNewsMap.get(
|
||||
concernList.get(i).getGameName()).size()
|
||||
+ offset) {
|
||||
return ITEM_TYPE.game_text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ITEM_TYPE.refresh_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);
|
||||
} else {
|
||||
return new FooterViewHolder(layoutInflater.inflate(
|
||||
R.layout.refresh_footerview, parent, false));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||
if (viewHolder instanceof GameNormalViewHolder) {
|
||||
((GameNormalViewHolder) viewHolder).initViewHolder(position);
|
||||
} else if (viewHolder instanceof TextNewsTypeViewHolder) {
|
||||
((TextNewsTypeViewHolder) viewHolder).initViewHolder(position);
|
||||
} else if (viewHolder instanceof FooterViewHolder) {
|
||||
FooterViewHolder holder = (FooterViewHolder) viewHolder;
|
||||
holder.footerview_progressbar.setVisibility(View.GONE);
|
||||
holder.footerview_tv_loading.setText("管理我的关注");
|
||||
holder.itemView.setClickable(true);
|
||||
holder.itemView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
context.startActivity(new Intent(context, ConcernActivity.class));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private class GameNormalViewHolder extends RecyclerView.ViewHolder {
|
||||
public ImageView gameThumb;
|
||||
public TextView gameName;
|
||||
public LinearLayout labelList;
|
||||
private View rootItem;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void initViewHolder(int position) {
|
||||
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) {
|
||||
if (concernGameList == null) {
|
||||
init(concernList.get(i));
|
||||
} else {
|
||||
init(concernGameList.get(i), concernList.get(i)
|
||||
.getTag());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void init(ConcernInfo concernEntity) {
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void init(final GameEntity entry, String tag) {
|
||||
ImageUtils.getInstance(context).display(entry.getIcon(), gameThumb);
|
||||
gameName.setText(entry.getName());
|
||||
if (tag != null) {
|
||||
GameViewUtils.setLabelList(context, labelList, tag);
|
||||
}
|
||||
rootItem.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("入口", "关注-我的游戏");
|
||||
DataUtils.onEvent(context, "游戏详情", entry.getName(), kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "我的游戏");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("game", entry.getName());
|
||||
map.put("page", "关注");
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
AppController.put("GameEntity", entry);
|
||||
Intent intent = new Intent(context,
|
||||
GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "关注-我的游戏");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private class TextNewsTypeViewHolder extends RecyclerView.ViewHolder {
|
||||
public TextView newsType;
|
||||
public TextView newsTitle;
|
||||
private int column;
|
||||
private View rootItem;
|
||||
|
||||
public TextNewsTypeViewHolder(View v, int column) {
|
||||
super(v);
|
||||
rootItem = v;
|
||||
this.column = column;
|
||||
newsType = (TextView) v.findViewById(R.id.news_type);
|
||||
newsTitle = (TextView) v.findViewById(R.id.news_title);
|
||||
}
|
||||
|
||||
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 (newsEntity != null) {
|
||||
final NewsEntity entity = newsEntity;
|
||||
final String entrance = from;
|
||||
newsType.setBackgroundResource(NewsUtils
|
||||
.getDrawableIdByType(entity.getType()));
|
||||
newsType.setText(entity.getType());
|
||||
newsTitle.setText(entity.getTitle());
|
||||
rootItem.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);
|
||||
|
||||
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", "关注");
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
NewsUtils.startNewsActivity(context, entity, "关注-" + entrance);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isNetworkError() {
|
||||
return isNetworkError;
|
||||
}
|
||||
|
||||
public void setNetworkError(boolean isNetworkError) {
|
||||
this.isNetworkError = isNetworkError;
|
||||
}
|
||||
}
|
||||
437
app/src/main/java/com/gh/gamecenter/news/NewsFragment.java
Normal file
@ -0,0 +1,437 @@
|
||||
package com.gh.gamecenter.news;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.RelativeLayout;
|
||||
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;
|
||||
import com.gh.gamecenter.MainActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SearchActivity;
|
||||
import com.gh.gamecenter.SettingActivity;
|
||||
import com.gh.gamecenter.eventbus.EBRedDot;
|
||||
import com.gh.gamecenter.eventbus.EBTopState;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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 RelativeLayout.LayoutParams rparams;
|
||||
|
||||
private String hint;
|
||||
|
||||
private int width;
|
||||
private int currentItem;
|
||||
|
||||
private PopupWindow popWindow;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.fragment_news, null);
|
||||
|
||||
SharedPreferences sp = getActivity().getSharedPreferences(
|
||||
Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
LinearLayout home_actionbar = (LinearLayout) view
|
||||
.findViewById(R.id.home_actionbar);
|
||||
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
||||
LinearLayout.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");
|
||||
home_actionbar.setPadding(0, top, 0, 0);
|
||||
lparams.height += top;
|
||||
}
|
||||
home_actionbar.setLayoutParams(lparams);
|
||||
|
||||
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);
|
||||
|
||||
slideLine = view.findViewById(R.id.slide_line);
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay()
|
||||
.getMetrics(outMetrics);
|
||||
width = outMetrics.widthPixels / 4;
|
||||
rparams = new RelativeLayout.LayoutParams(width / 2,
|
||||
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);
|
||||
|
||||
mViewPager = (ViewPager) view.findViewById(R.id.news_vp);
|
||||
mViewPager.setAdapter(new MyFragmentPagerAdapter(getChildFragmentManager()));
|
||||
mViewPager.addOnPageChangeListener(this);
|
||||
|
||||
rparams.leftMargin = width / 4;
|
||||
slideLine.setLayoutParams(rparams);
|
||||
tvZixun.setClickable(false);
|
||||
tvYuanchuang.setClickable(true);
|
||||
tvGonglve.setClickable(true);
|
||||
tvGuanzhu.setClickable(true);
|
||||
|
||||
currentItem = mViewPager.getCurrentItem();
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
private void initActionBar() {
|
||||
view.findViewById(R.id.actionbar_rl_download).setOnClickListener(this);
|
||||
|
||||
view.findViewById(R.id.actionbar_iv_search).setOnClickListener(this);
|
||||
|
||||
if (Config.isShow) {
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(
|
||||
View.VISIBLE);
|
||||
} else {
|
||||
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();
|
||||
if (downloadSize != 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText(downloadSize + "");
|
||||
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 (updateSize != 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
searchHint = (TextView) view.findViewById(R.id.actionbar_search_input);
|
||||
searchHint.setOnClickListener(this);
|
||||
if (!TextUtils.isEmpty(MainActivity.searchHint)) {
|
||||
hint = MainActivity.searchHint;
|
||||
searchHint.setHint(hint);
|
||||
}
|
||||
|
||||
view.findViewById(R.id.actionbar_notification).setOnClickListener(this);
|
||||
|
||||
view.findViewById(R.id.actionbar_overflow).setOnClickListener(this);
|
||||
|
||||
if (downloadSize != 0 || updateSize != 0) {
|
||||
EventBus.getDefault().post(new EBTopState("显示", null));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if (container != null){
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final int id = v.getId();
|
||||
if (id == R.id.actionbar_notification) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "关注图标");
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "关注图标");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("page", "主页");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
startActivity(new Intent(getActivity(), ConcernActivity.class));
|
||||
} else if (id == R.id.actionbar_rl_download) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "下载图标");
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "下载图标");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("page", "主页");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
if (downloadHint != null
|
||||
&& downloadHint.getVisibility() == View.VISIBLE) {
|
||||
downloadHint.setVisibility(View.GONE);
|
||||
EventBus.getDefault().post(new EBTopState("隐藏", null));
|
||||
}
|
||||
startActivity(new Intent(getActivity(),
|
||||
DownloadManagerActivity.class));
|
||||
} else if (id == R.id.actionbar_search_input) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "搜索框");
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "搜索框");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("page", "主页");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
Intent goSearch = new Intent(getActivity(), SearchActivity.class);
|
||||
goSearch.putExtra("clicked", false);
|
||||
goSearch.putExtra("hint", hint);
|
||||
startActivity(goSearch);
|
||||
} else if (id == R.id.actionbar_iv_search) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "搜索图标");
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "搜索图标");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("page", "主页");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
Intent searchIntent = new Intent(getActivity(),
|
||||
SearchActivity.class);
|
||||
searchIntent.putExtra("clicked", true);
|
||||
searchIntent.putExtra("hint", hint);
|
||||
startActivity(searchIntent);
|
||||
} else if (id == R.id.actionbar_overflow) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "更多图标");
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "更多图标");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("page", "主页");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
popUpOverflow(v);
|
||||
} else if (id == R.id.menu_rl_set) {
|
||||
popWindow.dismiss();
|
||||
startActivity(new Intent(getActivity(), SettingActivity.class));
|
||||
} else if (id == R.id.zixun_text) {
|
||||
mViewPager.setCurrentItem(0);
|
||||
} else if (id == R.id.yuanchuang_text) {
|
||||
mViewPager.setCurrentItem(1);
|
||||
} else if (id == R.id.gonglue_text) {
|
||||
mViewPager.setCurrentItem(2);
|
||||
} else if (id == R.id.guanzhu_text) {
|
||||
mViewPager.setCurrentItem(3);
|
||||
}
|
||||
}
|
||||
|
||||
private void popUpOverflow(View view) {
|
||||
|
||||
Rect frame = new Rect();
|
||||
getActivity().getWindow().getDecorView()
|
||||
.getWindowVisibleDisplayFrame(frame);
|
||||
|
||||
int xOffset = DisplayUtils.dip2px(getActivity(), 5);
|
||||
int yOffset = frame.top + DisplayUtils.dip2px(getActivity(), 48)
|
||||
+ xOffset;
|
||||
|
||||
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);
|
||||
|
||||
popWindow.setOutsideTouchable(true);
|
||||
popWindow.setAnimationStyle(android.R.style.Animation_Dialog);
|
||||
popWindow.setBackgroundDrawable(getResources().getDrawable(
|
||||
R.drawable.shape));
|
||||
|
||||
popWindow.showAtLocation(view, Gravity.TOP | Gravity.RIGHT, xOffset,
|
||||
yOffset);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset,
|
||||
int positionOffsetPixels) {
|
||||
if (positionOffset != 0) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
if (position == 0) {
|
||||
tvZixun.setClickable(false);
|
||||
tvYuanchuang.setClickable(true);
|
||||
tvGonglve.setClickable(true);
|
||||
tvGuanzhu.setClickable(true);
|
||||
tvZixun.setTextColor(getResources().getColor(R.color.theme_colors));
|
||||
tvYuanchuang.setTextColor(0xFF333333);
|
||||
tvGonglve.setTextColor(0xFF333333);
|
||||
tvGuanzhu.setTextColor(0xFF333333);
|
||||
} else if (position == 1) {
|
||||
tvZixun.setClickable(true);
|
||||
tvYuanchuang.setClickable(false);
|
||||
tvGonglve.setClickable(true);
|
||||
tvGuanzhu.setClickable(true);
|
||||
tvZixun.setTextColor(0xFF333333);
|
||||
tvYuanchuang.setTextColor(getResources().getColor(R.color.theme_colors));
|
||||
tvGonglve.setTextColor(0xFF333333);
|
||||
tvGuanzhu.setTextColor(0xFF333333);
|
||||
} else if (position == 2) {
|
||||
tvZixun.setClickable(true);
|
||||
tvYuanchuang.setClickable(true);
|
||||
tvGonglve.setClickable(false);
|
||||
tvGuanzhu.setClickable(true);
|
||||
tvZixun.setTextColor(0xFF333333);
|
||||
tvYuanchuang.setTextColor(0xFF333333);
|
||||
tvGonglve.setTextColor(getResources().getColor(R.color.theme_colors));
|
||||
tvGuanzhu.setTextColor(0xFF333333);
|
||||
}else if (position == 3){
|
||||
tvZixun.setClickable(true);
|
||||
tvYuanchuang.setClickable(true);
|
||||
tvGonglve.setClickable(true);
|
||||
tvGuanzhu.setClickable(false);
|
||||
tvZixun.setTextColor(0xFF333333);
|
||||
tvYuanchuang.setTextColor(0xFF333333);
|
||||
tvGonglve.setTextColor(0xFF333333);
|
||||
tvGuanzhu.setTextColor(getResources().getColor(R.color.theme_colors));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int i) {
|
||||
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBTopState busTen) {
|
||||
if ("搜索".equals(busTen.getType())) {
|
||||
hint = busTen.getSearchHint();
|
||||
searchHint.setHint(busTen.getSearchHint());
|
||||
} else if ("显示".equals(busTen.getType())) {
|
||||
if (downloadHint != null) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
if (downloadHint != null) {
|
||||
downloadHint.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBRedDot busEight) {
|
||||
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) + "");
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
} else {
|
||||
return new News4Fragment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -15,12 +15,10 @@ import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadDelete;
|
||||
import com.gh.gamecenter.eventbus.EBLogout;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBRedDot;
|
||||
import com.gh.gamecenter.eventbus.EBShowDone;
|
||||
import com.gh.gamecenter.eventbus.EBSms;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
@ -95,20 +93,6 @@ public class PersonalFragment extends Fragment {
|
||||
adapter.notifyItemChanged(0);
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBSms sms) {
|
||||
if ("注册验证".equals(sms.getType())) {
|
||||
adapter.setCode(sms.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBLogout logout) {
|
||||
if (logout.getType() == 0) {
|
||||
adapter.logout();
|
||||
} else {
|
||||
adapter.notifyItemChanged(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBShowDone showDone) {
|
||||
if ("我的游戏".equals(showDone.getFrom()) && gameRecyclerView != null) {
|
||||
gameRecyclerView.smoothScrollToPosition(showDone.getPosition());
|
||||
@ -137,11 +121,9 @@ public class PersonalFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().unregister(this);
|
||||
AppController.canclePendingRequests(
|
||||
PersonalFragment.class);
|
||||
AppController.canclePendingRequests(PersonalFragment.class);
|
||||
view = null;
|
||||
gameRecyclerView = null;
|
||||
adapter = null;
|
||||
|
||||
@ -30,7 +30,6 @@ import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
@ -73,7 +72,6 @@ import com.gh.gamecenter.entity.GameDigestEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.entity.MyGameInfo;
|
||||
import com.gh.gamecenter.entity.UserEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadDelete;
|
||||
import com.gh.gamecenter.eventbus.EBPutUrl;
|
||||
import com.gh.gamecenter.eventbus.EBRedDot;
|
||||
@ -107,8 +105,6 @@ public class PersonalFragmentAdapter extends
|
||||
private ArrayList<MyGameInfo> sortedList;
|
||||
private SparseBooleanArray isShowMap;
|
||||
|
||||
private UserEntity user;
|
||||
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private SparseArray<RecyclerView> recyclerViewMap;
|
||||
|
||||
@ -423,21 +419,6 @@ public class PersonalFragmentAdapter extends
|
||||
holder.me_tv_update.setVisibility(View.VISIBLE);
|
||||
holder.me_tv_update.setText("" + updateSize);
|
||||
}
|
||||
if (user == null) {
|
||||
holder.me_tv_nickname.setVisibility(View.INVISIBLE);
|
||||
holder.me_tv_sign.setVisibility(View.INVISIBLE);
|
||||
holder.me_iv_icon.setImageResource(R.drawable.me_icon);
|
||||
} else {
|
||||
holder.me_tv_nickname.setVisibility(View.VISIBLE);
|
||||
holder.me_tv_sign.setVisibility(View.VISIBLE);
|
||||
holder.me_tv_nickname.setText(user.getName());
|
||||
if (user.getSign() != null) {
|
||||
holder.me_tv_sign.setText(user.getSign());
|
||||
}
|
||||
ImageUtils.getInstance(fragmentActivity).display(
|
||||
user.getIcon(), holder.me_iv_icon);
|
||||
}
|
||||
|
||||
} else if (viewHolder instanceof MultiFunctionViewHolder) {
|
||||
MultiFunctionViewHolder holder = (MultiFunctionViewHolder) viewHolder;
|
||||
if (isNetworkError) {
|
||||
@ -606,41 +587,29 @@ public class PersonalFragmentAdapter extends
|
||||
public class FunctionViewHolder extends ViewHolder implements
|
||||
OnClickListener {
|
||||
|
||||
private TextView me_tv_download, me_tv_update, me_tv_nickname,
|
||||
me_tv_sign;
|
||||
private TextView me_tv_download, me_tv_update;
|
||||
private ImageView me_iv_icon;
|
||||
|
||||
public FunctionViewHolder(View convertView) {
|
||||
super(convertView);
|
||||
|
||||
convertView.findViewById(R.id.me_ll_concern).setOnClickListener(
|
||||
this);
|
||||
convertView.findViewById(R.id.me_ll_download).setOnClickListener(
|
||||
this);
|
||||
convertView.findViewById(R.id.me_ll_setting).setOnClickListener(
|
||||
this);
|
||||
convertView.findViewById(R.id.me_ll_update)
|
||||
.setOnClickListener(this);
|
||||
me_tv_download = (TextView) convertView
|
||||
.findViewById(R.id.me_tv_download);
|
||||
me_tv_update = (TextView) convertView
|
||||
.findViewById(R.id.me_tv_update);
|
||||
convertView.findViewById(R.id.me_ll_concern).setOnClickListener(this);
|
||||
convertView.findViewById(R.id.me_ll_download).setOnClickListener(this);
|
||||
convertView.findViewById(R.id.me_ll_setting).setOnClickListener(this);
|
||||
convertView.findViewById(R.id.me_ll_update).setOnClickListener(this);
|
||||
me_tv_download = (TextView) convertView.findViewById(R.id.me_tv_download);
|
||||
me_tv_update = (TextView) convertView.findViewById(R.id.me_tv_update);
|
||||
me_iv_icon = (ImageView) convertView.findViewById(R.id.me_iv_icon);
|
||||
me_iv_icon.setOnClickListener(this);
|
||||
if (Config.isShow) {
|
||||
convertView.findViewById(R.id.me_ll_download).setVisibility(
|
||||
View.VISIBLE);
|
||||
convertView.findViewById(R.id.me_ll_update).setVisibility(
|
||||
View.VISIBLE);
|
||||
convertView.findViewById(R.id.me_ll_download).setVisibility(View.VISIBLE);
|
||||
convertView.findViewById(R.id.me_ll_update).setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
convertView.findViewById(R.id.me_ll_download).setVisibility(
|
||||
View.GONE);
|
||||
convertView.findViewById(R.id.me_ll_update).setVisibility(
|
||||
View.GONE);
|
||||
convertView.findViewById(R.id.me_ll_download).setVisibility(View.GONE);
|
||||
convertView.findViewById(R.id.me_ll_update).setVisibility(View.GONE);
|
||||
}
|
||||
me_tv_nickname = (TextView) convertView
|
||||
.findViewById(R.id.me_tv_nickname);
|
||||
me_tv_sign = (TextView) convertView.findViewById(R.id.me_tv_sign);
|
||||
// me_tv_nickname = (TextView) convertView.findViewById(R.id.me_tv_nickname);
|
||||
// me_tv_sign = (TextView) convertView.findViewById(R.id.me_tv_sign);
|
||||
// me_cutting_line = convertView.findViewById(R.id.me_cutting_line);
|
||||
}
|
||||
|
||||
@ -706,19 +675,6 @@ public class PersonalFragmentAdapter extends
|
||||
|
||||
}
|
||||
|
||||
private TextView code_tv_send_again;
|
||||
private EditText code_et_code;
|
||||
|
||||
private int countdown = 60;
|
||||
|
||||
// 设置获取到的验证码
|
||||
public void setCode(String code) {
|
||||
if (code_et_code != null) {
|
||||
code_et_code.setText(code);
|
||||
code_et_code.setSelection(code.length());
|
||||
}
|
||||
}
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
@ -1333,11 +1289,6 @@ public class PersonalFragmentAdapter extends
|
||||
statusMap.clear();
|
||||
}
|
||||
|
||||
public void logout() {
|
||||
user = null;
|
||||
notifyItemChanged(0);
|
||||
}
|
||||
|
||||
public boolean isNetworkError() {
|
||||
return isNetworkError;
|
||||
}
|
||||
|
||||
@ -1,356 +0,0 @@
|
||||
package com.gh.gamecenter.plugin;
|
||||
|
||||
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.v4.widget.SwipeRefreshLayout.OnRefreshListener;
|
||||
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.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.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-10 modified 2015-8-13 插件界面下的精品fragment
|
||||
*/
|
||||
public class Plugin1Fragment extends Fragment implements OnRefreshListener {
|
||||
|
||||
private View view;
|
||||
private RecyclerView recyclerview;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
private Plugin1FragmentAdapter adapter;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private ProgressBarCircularIndeterminate game_pb_loading;
|
||||
|
||||
// 黄壮华 添加 记录信息的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 boolean isEverpause = false;
|
||||
private boolean isDestroy = false;
|
||||
|
||||
private int currentItem = 0;
|
||||
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
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 (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 黄壮华 添加观察者 修改2015/8/15
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
if (!game_swipe_refresh.isRefreshing()) {
|
||||
for (java.util.Map.Entry<String, DownloadEntry> entry : downloadingEntries
|
||||
.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
|
||||
Integer location = locationMap.get(downloadEntry.getName());
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
|
||||
GameEntity detailedEntity = adapter.getList()
|
||||
.get(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, platformMap, handler,
|
||||
adapter, index + 1, statusMap);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.plugin1_fragment, null);
|
||||
|
||||
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>();
|
||||
|
||||
dismissEntity = new DismissEntity(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
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
// 黄壮华 传递引用 修改2015/8/15
|
||||
adapter = new Plugin1FragmentAdapter(Plugin1Fragment.this, locationMap,
|
||||
gameMap, platformMap, nameMap, game_swipe_refresh,
|
||||
reuse_no_connection, recyclerview, statusMap,
|
||||
dismissEntity, game_pb_loading, false);
|
||||
recyclerview.setAdapter(adapter);
|
||||
recyclerview.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
recyclerview.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& layoutManager.findLastVisibleItemPosition() == 1 + adapter
|
||||
.getList().size()) {
|
||||
if (!adapter.isRemove() && !adapter.isLoading()) {
|
||||
adapter.addList(adapter.getList().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
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.intValue();
|
||||
GameEntity detailedEntity = adapter.getList().get(index);
|
||||
if (TextUtils.isEmpty(busThree.getPlatform())) {
|
||||
detailedEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
detailedEntity.getEntryMap().remove(busThree.getPlatform());
|
||||
}
|
||||
adapter.notifyItemChanged(index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
} else if (adapter.isNetworkError()) {
|
||||
adapter.setNetworkError(false);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1);
|
||||
adapter.addList(adapter.getList().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (dismissEntity != null) {
|
||||
dismissEntity.setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("PluginFragment".equals(busNine.getFrom())) {
|
||||
currentItem = busNine.getPosition();
|
||||
if (busNine.getPosition() == 0) {
|
||||
adapter.startAutoScroll();
|
||||
if (game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
}
|
||||
} else {
|
||||
adapter.stopAutoScroll();
|
||||
}
|
||||
} else if ("MainActivity".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() != 1) {
|
||||
adapter.stopAutoScroll();
|
||||
statusMap.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = nameMap.get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
int location = locationMap.get(name);
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity detailedEntity = adapter.getList().get(location);
|
||||
for (ApkEntity apkEntity : detailedEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
detailedEntity.getEntryMap().remove(
|
||||
apkEntity.getPlatform());
|
||||
adapter.notifyItemChanged(location + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
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);
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
if (currentItem == 0) {
|
||||
adapter.startAutoScroll();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEverpause() {
|
||||
return isEverpause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
statusMap.clear();
|
||||
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
|
||||
if (currentItem == 0) {
|
||||
adapter.stopAutoScroll();
|
||||
}
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter = new Plugin1FragmentAdapter(Plugin1Fragment.this,
|
||||
locationMap, gameMap, platformMap, nameMap,
|
||||
game_swipe_refresh, reuse_no_connection, recyclerview,
|
||||
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(Plugin1Fragment.class);
|
||||
EventBus.getDefault().unregister(this);
|
||||
view = null;
|
||||
recyclerview = null;
|
||||
game_swipe_refresh = null;
|
||||
adapter = null;
|
||||
reuse_no_connection = null;
|
||||
locationMap = null;
|
||||
gameMap = null;
|
||||
platformMap = null;
|
||||
nameMap = null;
|
||||
statusMap = null;
|
||||
dismissEntity = null;
|
||||
handler = null;
|
||||
dataWatcher = null;
|
||||
game_pb_loading = null;
|
||||
}
|
||||
}
|
||||
@ -1,610 +0,0 @@
|
||||
package com.gh.gamecenter.plugin;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
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.DisplayUtils;
|
||||
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.view.AutoScrollViewPager;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.ImagePagerAdapter;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameViewHolder;
|
||||
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.DataCollectionManager;
|
||||
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.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-13
|
||||
* @update 2015-8-13
|
||||
* @des 插件板块下的精品栏目
|
||||
*/
|
||||
public class Plugin1FragmentAdapter extends
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context context;
|
||||
|
||||
private Plugin1Fragment fragment;
|
||||
|
||||
private RecyclerView recyclerview;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private ProgressBarCircularIndeterminate game_pb_loading;
|
||||
|
||||
private List<GameEntity> slideList;
|
||||
private List<GameEntity> list;
|
||||
|
||||
private boolean isRemove;
|
||||
private boolean isLoading;
|
||||
// private boolean isLoaded;
|
||||
private boolean isNetworkError;
|
||||
private boolean isSlideError;
|
||||
private boolean isListError;
|
||||
|
||||
// 黄壮华 获取引用 修改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 ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
public Plugin1FragmentAdapter(Plugin1Fragment fment,
|
||||
ArrayMap<String, Integer> lMap,
|
||||
ArrayMap<String, ArrayMap<String, DownloadEntry>> gMap,
|
||||
ArrayMap<String, LinkedBlockingQueue<String>> pMap,
|
||||
ArrayMap<String, String> nMap,
|
||||
SwipeRefreshLayout swipeRefreshLayout,
|
||||
LinearLayout linearLayout,
|
||||
RecyclerView rView,
|
||||
ArrayMap<String, String> sMap,
|
||||
DismissEntity dEntity,
|
||||
ProgressBarCircularIndeterminate pbLoading,
|
||||
boolean isLoad) {
|
||||
|
||||
fragment = fment;
|
||||
context = fment.getActivity();
|
||||
locationMap = lMap;
|
||||
gameMap = gMap;
|
||||
platformMap = pMap;
|
||||
nameMap = nMap;
|
||||
game_swipe_refresh = swipeRefreshLayout;
|
||||
reuse_no_connection = linearLayout;
|
||||
recyclerview = rView;
|
||||
game_pb_loading = pbLoading;
|
||||
|
||||
statusMap = sMap;
|
||||
|
||||
dismissEntity = dEntity;
|
||||
|
||||
list = new ArrayList<GameEntity>();
|
||||
slideList = new ArrayList<GameEntity>();
|
||||
|
||||
isRemove = false;
|
||||
isLoading = false;
|
||||
// isLoaded = false;
|
||||
isNetworkError = false;
|
||||
isSlideError = false;
|
||||
isListError = false;
|
||||
|
||||
if (isLoad) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
new Thread(runnable){}.start();
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
initSlide(true);
|
||||
}
|
||||
};
|
||||
|
||||
private void initSlide(final boolean isFirst) {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
JsonArrayExtendedRequest slideRequest = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST + "v1d45/plugin/slide",
|
||||
Constants.GAME_CD), new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
Type listType = new TypeToken<ArrayList<GameEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
slideList = gson.fromJson(response.toString(), listType);
|
||||
if (slideList != null && !slideList.isEmpty()) {
|
||||
GameManager manager = new GameManager(context);
|
||||
for (GameEntity entity : slideList) {
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
manager.addOrUpdate(new GameInfo(
|
||||
apkEntity.getPackageName(), entity
|
||||
.getId(), entity.getName()));
|
||||
}
|
||||
}
|
||||
notifyItemChanged(0);
|
||||
}
|
||||
if (isFirst) {
|
||||
addList(0);
|
||||
}
|
||||
}
|
||||
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
isSlideError = true;
|
||||
if (!isFirst) {
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
notifyItemChanged(0);
|
||||
} else {
|
||||
showView();
|
||||
}
|
||||
}
|
||||
|
||||
if (isFirst) {
|
||||
addList(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(slideRequest, Plugin1Fragment.class);
|
||||
}
|
||||
|
||||
public void addList(final int offset) {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
isLoading = true;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d45/plugin/jingpin?limit=20&offset=" + offset,
|
||||
Constants.GAME_CD), new Response.Listener<JSONArray>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
processingData(response, offset);
|
||||
isLoading = false;
|
||||
// isLoaded = true;
|
||||
// notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
|
||||
}, 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);
|
||||
}
|
||||
isListError = true;
|
||||
showView();
|
||||
} else {
|
||||
Toast.makeText(context, "网络错误",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
isNetworkError = true;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, Plugin1Fragment.class);
|
||||
}
|
||||
|
||||
private void showView() {
|
||||
if (isSlideError && isListError) {
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
recyclerview.setVisibility(View.GONE);
|
||||
game_pb_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
} else if (isSlideError && !isListError) {
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
notifyItemChanged(0);
|
||||
} else if (!isSlideError && isListError) {
|
||||
Toast.makeText(context, "网络错误", Toast.LENGTH_SHORT).show();
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void processingData(JSONArray response, int offset) {
|
||||
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()) {
|
||||
if (!list.isEmpty()) {
|
||||
for (int i = 0; i < gameList.size(); i++) {
|
||||
GameEntity entity = gameList.get(i);
|
||||
// 去重
|
||||
for (int j = 0; j < list.size(); j++) {
|
||||
if (list.get(j).getId().equals(entity.getId())) {
|
||||
gameList.remove(i);
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
if (!fragment.isHidden() && !fragment.isEverpause()) {
|
||||
notifyItemRangeInserted(list.size() - gameList.size() + 1, gameList.size());
|
||||
}
|
||||
}
|
||||
|
||||
if (fragment.isHidden() || fragment.isEverpause()) {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
if (offset == 0 && 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);
|
||||
}
|
||||
|
||||
if (gameList.isEmpty() || (offset == 0 && gameList.size() < 20)) {
|
||||
isRemove = true;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
|
||||
// 黄壮华 获取游戏位置信息 修改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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (list.isEmpty()) {
|
||||
if (isListError) {
|
||||
return 1 + list.size() + 1;
|
||||
} else {
|
||||
return 1 + list.size();
|
||||
}
|
||||
} else {
|
||||
return 1 + list.size() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder,
|
||||
int position) {
|
||||
if (viewHolder instanceof AutoScrollViewpagerViewHolder) {
|
||||
AutoScrollViewpagerViewHolder holder = (AutoScrollViewpagerViewHolder) viewHolder;
|
||||
if (isSlideError) {
|
||||
holder.viewpager_tv_failure.setVisibility(View.VISIBLE);
|
||||
holder.viewPager.setVisibility(View.GONE);
|
||||
holder.viewpager_ll_hint.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.viewpager_tv_failure.setVisibility(View.GONE);
|
||||
holder.viewPager.setVisibility(View.VISIBLE);
|
||||
holder.viewpager_ll_hint.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (slideList.size() > 0) {
|
||||
int currentItem = 0;
|
||||
if (holder.viewPager.getAdapter() != null) {
|
||||
currentItem = holder.viewPager.getCurrentItem();
|
||||
}
|
||||
holder.viewpager_ll_hint.removeAllViews();
|
||||
for (int i = 0, size = slideList.size(); i < size; i++) {
|
||||
ImageView imageView = new ImageView(context);
|
||||
LayoutParams lparams = new LayoutParams(
|
||||
DisplayUtils.dip2px(context, 8),
|
||||
DisplayUtils.dip2px(context, 8));
|
||||
lparams.bottomMargin = DisplayUtils.dip2px(context, 8);
|
||||
if (i == currentItem) {
|
||||
imageView.setImageResource(R.drawable.oval_hint_dn);
|
||||
} else {
|
||||
imageView.setImageResource(R.drawable.oval_hint_up);
|
||||
}
|
||||
if (i != 0) {
|
||||
lparams.leftMargin = DisplayUtils.dip2px(context, 8);
|
||||
}
|
||||
imageView.setLayoutParams(lparams);
|
||||
holder.viewpager_ll_hint.addView(imageView);
|
||||
}
|
||||
holder.viewPager.setAdapter(new ImagePagerAdapter(context,
|
||||
slideList, true));
|
||||
holder.viewPager.setCurrentItem(currentItem);
|
||||
holder.viewPager.setInterval(3000);
|
||||
holder.viewPager.startAutoScroll();
|
||||
}
|
||||
} else if (viewHolder instanceof GameViewHolder) {
|
||||
|
||||
GameViewHolder holder = (GameViewHolder) viewHolder;
|
||||
|
||||
final GameEntity detailedEntity = list.get(position - 1);
|
||||
|
||||
ImageUtils.getInstance(context).display(detailedEntity.getIcon(),
|
||||
holder.gameThumb);
|
||||
if (detailedEntity.getApk() == null
|
||||
|| detailedEntity.getApk().isEmpty()) {
|
||||
holder.gameNameAndSize.setText(detailedEntity.getName());
|
||||
} else {
|
||||
holder.gameNameAndSize.setText(detailedEntity.getName()
|
||||
+ " | " + detailedEntity.getApk().get(0).getSize());
|
||||
}
|
||||
holder.gameDes.setText(detailedEntity.getBrief());
|
||||
|
||||
// 添加tag标签
|
||||
GameViewUtils.setLabelList(context, holder.labelList,
|
||||
detailedEntity.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, "游戏详情", detailedEntity.getName(),
|
||||
kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "精品-列表");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("game", detailedEntity.getName());
|
||||
map.put("page", "插件");
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
AppController.put("GameEntity", detailedEntity);
|
||||
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.downloadSpeed, holder.downloadPercentage,
|
||||
detailedEntity, position, this,
|
||||
statusMap, platformMap, "插件-精品", dismissEntity, "精品:"
|
||||
+ detailedEntity.getName());
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.gameProgressbar, holder.gameInfo,
|
||||
holder.downloadSpeed, holder.downloadPercentage,
|
||||
holder.downloadBtn, detailedEntity, platformMap, statusMap);
|
||||
} else if (viewHolder instanceof FooterViewHolder) {
|
||||
FooterViewHolder holder = (FooterViewHolder) viewHolder;
|
||||
if (isNetworkError || isListError) {
|
||||
holder.footerview_progressbar.setVisibility(View.GONE);
|
||||
holder.footerview_tv_loading.setText("加载失败,点击重试");
|
||||
holder.rootView.setClickable(true);
|
||||
holder.rootView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isNetworkError = false;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
addList(list.size());
|
||||
}
|
||||
});
|
||||
} else if (isRemove) {
|
||||
holder.footerview_progressbar.setVisibility(View.GONE);
|
||||
holder.footerview_tv_loading.setText("加载完毕");
|
||||
holder.rootView.setClickable(false);
|
||||
}
|
||||
// else if (isLoaded) {
|
||||
// holder.footerview_progressbar.setVisibility(View.GONE);
|
||||
// holder.footerview_tv_loading.setText("点击加载更多");
|
||||
// holder.rootView.setClickable(true);
|
||||
// holder.rootView.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// isLoaded = false;
|
||||
// notifyItemChanged(getItemCount() - 1);
|
||||
// addList(list.size());
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
else {
|
||||
holder.footerview_progressbar.setVisibility(View.VISIBLE);
|
||||
holder.footerview_tv_loading.setText("加载中...");
|
||||
holder.rootView.setClickable(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
if (i == 0) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.plugin1_autoscrollviewpager_viewholder, viewGroup,
|
||||
false);
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
fragment.getActivity().getWindowManager().getDefaultDisplay()
|
||||
.getMetrics(outMetrics);
|
||||
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
|
||||
LayoutParams.MATCH_PARENT,
|
||||
(int) (outMetrics.widthPixels / 16f * 7f));
|
||||
view.setLayoutParams(params);
|
||||
return new AutoScrollViewpagerViewHolder(view);
|
||||
} else if (i > 0 && i <= list.size()) {
|
||||
return new GameViewHolder(LayoutInflater.from(
|
||||
viewGroup.getContext()).inflate(
|
||||
R.layout.home_list_item_gamenormal_type, viewGroup, false));
|
||||
} else {
|
||||
return new FooterViewHolder(LayoutInflater.from(
|
||||
viewGroup.getContext()).inflate(
|
||||
R.layout.refresh_footerview, viewGroup, false));
|
||||
}
|
||||
}
|
||||
|
||||
public class AutoScrollViewpagerViewHolder extends RecyclerView.ViewHolder {
|
||||
private AutoScrollViewPager viewPager;
|
||||
private LinearLayout viewpager_ll_hint;
|
||||
private TextView viewpager_tv_failure;
|
||||
|
||||
public AutoScrollViewpagerViewHolder(View v) {
|
||||
super(v);
|
||||
viewpager_tv_failure = (TextView) v
|
||||
.findViewById(R.id.viewpager_tv_failure);
|
||||
viewpager_tv_failure.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isSlideError = false;
|
||||
notifyItemChanged(0);
|
||||
initSlide(false);
|
||||
}
|
||||
});
|
||||
viewpager_ll_hint = (LinearLayout) v
|
||||
.findViewById(R.id.viewpager_ll_hint);
|
||||
viewPager = (AutoScrollViewPager) v.findViewById(R.id.view_pager);
|
||||
viewPager
|
||||
.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
for (int i = 0, size = viewpager_ll_hint
|
||||
.getChildCount(); i < size; i++) {
|
||||
if (i == position % size) {
|
||||
((ImageView) viewpager_ll_hint
|
||||
.getChildAt(i))
|
||||
.setImageResource(R.drawable.oval_hint_dn);
|
||||
} else {
|
||||
((ImageView) viewpager_ll_hint
|
||||
.getChildAt(i))
|
||||
.setImageResource(R.drawable.oval_hint_up);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position,
|
||||
float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
// 解决viewpager和SwipeRefreshLayout滑动冲突
|
||||
if (state == ViewPager.SCROLL_STATE_DRAGGING) {
|
||||
game_swipe_refresh.setEnabled(false);
|
||||
} else {
|
||||
game_swipe_refresh.setEnabled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
autoScrollViewPager = viewPager;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private AutoScrollViewPager autoScrollViewPager;
|
||||
|
||||
public void startAutoScroll() {
|
||||
if (autoScrollViewPager != null) {
|
||||
autoScrollViewPager.startAutoScroll();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopAutoScroll() {
|
||||
if (autoScrollViewPager != null) {
|
||||
autoScrollViewPager.stopAutoScroll();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRemove() {
|
||||
return isRemove;
|
||||
}
|
||||
|
||||
public boolean isLoading() {
|
||||
return isLoading;
|
||||
}
|
||||
|
||||
public List<GameEntity> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<GameEntity> list) {
|
||||
this.list = list;
|
||||
notifyItemRangeChanged(1, list.size());
|
||||
}
|
||||
|
||||
public boolean isNetworkError() {
|
||||
return isNetworkError;
|
||||
}
|
||||
|
||||
public void setNetworkError(boolean isNetworkError) {
|
||||
this.isNetworkError = isNetworkError;
|
||||
}
|
||||
}
|
||||
@ -1,345 +0,0 @@
|
||||
package com.gh.gamecenter.plugin;
|
||||
|
||||
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.v4.widget.SwipeRefreshLayout.OnRefreshListener;
|
||||
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.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.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-8
|
||||
* @update 2015-8-11
|
||||
* @des 主页插件fragment
|
||||
*/
|
||||
public class Plugin2Fragment extends Fragment implements OnRefreshListener {
|
||||
|
||||
private View view;
|
||||
private RecyclerView recyclerview;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
private Plugin2FragmentAdapter adapter;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private ProgressBarCircularIndeterminate game_pb_loading;
|
||||
|
||||
// 黄壮华 添加 记录信息的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 boolean isEverpause = false;
|
||||
private boolean isDestroy = false;
|
||||
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
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 (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 黄壮华 添加观察者 修改2015/8/15
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
if (!game_swipe_refresh.isRefreshing()) {
|
||||
for (java.util.Map.Entry<String, DownloadEntry> entry : downloadingEntries
|
||||
.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
|
||||
Integer location = locationMap.get(downloadEntry.getName());
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
|
||||
GameEntity detailedEntity = adapter.getList()
|
||||
.get(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);
|
||||
|
||||
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>();
|
||||
|
||||
dismissEntity = new DismissEntity(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
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
// 黄壮华 传递引用 修改2015/8/15
|
||||
adapter = new Plugin2FragmentAdapter(Plugin2Fragment.this,
|
||||
locationMap, gameMap, platformMap, nameMap, recyclerview,
|
||||
game_swipe_refresh, reuse_no_connection,
|
||||
statusMap, dismissEntity, game_pb_loading, false);
|
||||
recyclerview.setAdapter(adapter);
|
||||
recyclerview.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView,
|
||||
int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& layoutManager.findLastVisibleItemPosition() == adapter
|
||||
.getList().size()) {
|
||||
if (!adapter.isRemove() && !adapter.isLoading()) {
|
||||
adapter.addList(adapter.getList().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
recyclerview.addItemDecoration(new VerticalItemDecoration(getActivity(), 1));
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
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.intValue();
|
||||
GameEntity detailedEntity = adapter.getList().get(index);
|
||||
if (TextUtils.isEmpty(busThree.getPlatform())) {
|
||||
detailedEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
detailedEntity.getEntryMap().remove(busThree.getPlatform());
|
||||
}
|
||||
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) {
|
||||
int location = locationMap.get(name);
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity detailedEntity = adapter.getList().get(location);
|
||||
for (ApkEntity apkEntity : detailedEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
detailedEntity.getEntryMap().remove(
|
||||
apkEntity.getPlatform());
|
||||
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.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
} else if (adapter.isNetworkError()) {
|
||||
adapter.setNetworkError(false);
|
||||
adapter.notifyItemChanged(adapter.getItemCount() - 1);
|
||||
adapter.addList(adapter.getList().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBUISwitch busNine) {
|
||||
if ("MainActivity".equals(busNine.getFrom())) {
|
||||
if (busNine.getPosition() != 1) {
|
||||
statusMap.clear();
|
||||
}
|
||||
} else if ("PluginFragment".equals(busNine.getFrom()) && busNine.getPosition() == 1
|
||||
&& game_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
adapter.load();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
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);
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getActivity()).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
public boolean isEverpause() {
|
||||
return isEverpause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
statusMap.clear();
|
||||
DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter = new Plugin2FragmentAdapter(Plugin2Fragment.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(Plugin2Fragment.class);
|
||||
EventBus.getDefault().unregister(this);
|
||||
view = null;
|
||||
recyclerview = null;
|
||||
game_swipe_refresh = null;
|
||||
adapter = null;
|
||||
layoutManager = null;
|
||||
reuse_no_connection = null;
|
||||
locationMap = null;
|
||||
gameMap = null;
|
||||
platformMap = null;
|
||||
nameMap = null;
|
||||
statusMap = null;
|
||||
dismissEntity = null;
|
||||
handler = null;
|
||||
dataWatcher = null;
|
||||
game_pb_loading = null;
|
||||
}
|
||||
}
|
||||
@ -1,387 +0,0 @@
|
||||
package com.gh.gamecenter.plugin;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
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.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameViewHolder;
|
||||
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.DataCollectionManager;
|
||||
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.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-8
|
||||
* @update 2015-8-11
|
||||
* @des 首页插件fragment适配器
|
||||
*/
|
||||
public class Plugin2FragmentAdapter extends
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context context;
|
||||
|
||||
private Plugin2Fragment fragment;
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private SwipeRefreshLayout game_swipe_refresh;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private ProgressBarCircularIndeterminate game_pb_loading;
|
||||
|
||||
private boolean isRemove;
|
||||
private boolean isLoading;
|
||||
private boolean isNetworkError;
|
||||
|
||||
private List<GameEntity> list;
|
||||
|
||||
// 黄壮华 获取引用 修改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 ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
public Plugin2FragmentAdapter(Plugin2Fragment fment,
|
||||
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) {
|
||||
|
||||
// 黄壮华 获取引用 修改2015/8/15
|
||||
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;
|
||||
|
||||
fragment = fment;
|
||||
context = fment.getActivity();
|
||||
|
||||
isRemove = false;
|
||||
isLoading = false;
|
||||
isNetworkError = false;
|
||||
|
||||
list = new ArrayList<GameEntity>();
|
||||
|
||||
if (isLoad) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
new Thread(runnable){}.start();
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addList(0);
|
||||
}
|
||||
};
|
||||
|
||||
public void addList(final int offset) {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
isLoading = true;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d45/plugin/zuixin?limit=20&offset=" + offset,
|
||||
Constants.GAME_CD), new Response.Listener<JSONArray>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
processingData(response, offset);
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
}, 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);
|
||||
}
|
||||
recyclerView.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, Plugin2Fragment.class);
|
||||
}
|
||||
|
||||
private void processingData(JSONArray response, int offset) {
|
||||
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()) {
|
||||
if (!list.isEmpty()) {
|
||||
for (int i = 0; i < gameList.size(); i++) {
|
||||
GameEntity entity = gameList.get(i);
|
||||
// 去重
|
||||
for (int j = 0; j < list.size(); j++) {
|
||||
if (list.get(j).getId().equals(entity.getId())) {
|
||||
gameList.remove(i);
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
if (!fragment.isHidden() && !fragment.isEverpause()) {
|
||||
notifyItemRangeInserted(list.size() - gameList.size(), gameList.size());
|
||||
}
|
||||
}
|
||||
|
||||
if (fragment.isHidden() || fragment.isEverpause()) {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
if (offset == 0 && 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);
|
||||
}
|
||||
|
||||
if (gameList.isEmpty() || (offset == 0 && gameList.size() < 20)) {
|
||||
isRemove = true;
|
||||
notifyItemRemoved(getItemCount());
|
||||
}
|
||||
|
||||
// 黄壮华 获取游戏位置信息 修改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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (list.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
if (isRemove) {
|
||||
return list.size();
|
||||
} else {
|
||||
return list.size() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder,
|
||||
int position) {
|
||||
if (viewHolder instanceof GameViewHolder) {
|
||||
GameViewHolder holder = (GameViewHolder) viewHolder;
|
||||
final GameEntity detailedEntity = list.get(position);
|
||||
ImageUtils.getInstance(context).display(detailedEntity.getIcon(),
|
||||
holder.gameThumb);
|
||||
if (detailedEntity.getApk() == null
|
||||
|| detailedEntity.getApk().isEmpty()) {
|
||||
holder.gameNameAndSize.setText(detailedEntity.getName());
|
||||
} else {
|
||||
holder.gameNameAndSize.setText(detailedEntity.getName()
|
||||
+ " | " + detailedEntity.getApk().get(0).getSize());
|
||||
}
|
||||
holder.gameDes.setText(detailedEntity.getBrief());
|
||||
|
||||
GameViewUtils.setLabelList(context, holder.labelList,
|
||||
detailedEntity.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, "游戏详情", detailedEntity.getName(),
|
||||
kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "最新");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("game", detailedEntity.getName());
|
||||
map.put("page", "插件");
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
AppController.put("GameEntity", detailedEntity);
|
||||
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.downloadSpeed, holder.downloadPercentage,
|
||||
detailedEntity, position, this,
|
||||
statusMap, platformMap, "插件-最新", dismissEntity, "最新:"
|
||||
+ detailedEntity.getName());
|
||||
|
||||
DownloadItemUtils.updateItem(context, holder.labelList,
|
||||
holder.gameProgressbar, holder.gameInfo,
|
||||
holder.downloadSpeed, holder.downloadPercentage,
|
||||
holder.downloadBtn, detailedEntity, platformMap, statusMap);
|
||||
} else if (viewHolder instanceof FooterViewHolder) {
|
||||
FooterViewHolder holder = (FooterViewHolder) viewHolder;
|
||||
if (isNetworkError) {
|
||||
holder.footerview_progressbar.setVisibility(View.GONE);
|
||||
holder.footerview_tv_loading.setText("加载失败,点击重试");
|
||||
holder.rootView.setClickable(true);
|
||||
holder.rootView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isNetworkError = false;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
addList(list.size());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
holder.footerview_progressbar.setVisibility(View.VISIBLE);
|
||||
holder.footerview_tv_loading.setText("加载中...");
|
||||
holder.rootView.setClickable(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
if (i != list.size()) {
|
||||
return new GameViewHolder(LayoutInflater.from(
|
||||
viewGroup.getContext()).inflate(
|
||||
R.layout.home_list_item_gamenormal_type, viewGroup, false));
|
||||
} else {
|
||||
return new FooterViewHolder(LayoutInflater.from(
|
||||
viewGroup.getContext()).inflate(
|
||||
R.layout.refresh_footerview, viewGroup, false));
|
||||
}
|
||||
}
|
||||
|
||||
public List<GameEntity> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<GameEntity> list) {
|
||||
this.list = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public boolean isRemove() {
|
||||
return isRemove;
|
||||
}
|
||||
|
||||
public void setRemove(boolean isRemove) {
|
||||
this.isRemove = isRemove;
|
||||
}
|
||||
|
||||
public boolean isLoading() {
|
||||
return isLoading;
|
||||
}
|
||||
|
||||
public void setLoading(boolean isLoading) {
|
||||
this.isLoading = isLoading;
|
||||
}
|
||||
|
||||
public boolean isNetworkError() {
|
||||
return isNetworkError;
|
||||
}
|
||||
|
||||
public void setNetworkError(boolean isNetworkError) {
|
||||
this.isNetworkError = isNetworkError;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
package com.gh.gamecenter.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.telephony.SmsMessage;
|
||||
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.eventbus.EBSms;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
public class SmsReceiver extends BroadcastReceiver {
|
||||
|
||||
public static final String SMS_RECEIVED_ACTION = "android.provider.Telephony.SMS_RECEIVED";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
if (intent.getAction().equals(SMS_RECEIVED_ACTION)) {
|
||||
SmsMessage[] messages = getMessagesFromIntent(intent);
|
||||
|
||||
for (SmsMessage message : messages) {
|
||||
String msgBody = message.getDisplayMessageBody();
|
||||
Utils.log(msgBody);
|
||||
if (Pattern.matches("^【注册验证】验证码:\\d{6},您正在注册成为光环助手用户,感谢您的支持!$", msgBody)) {
|
||||
String code = msgBody.substring(10, 16);
|
||||
Utils.log(code);
|
||||
EventBus.getDefault().post(new EBSms("注册验证", code));
|
||||
} else if (Pattern.matches("^【身份验证】验证码:\\d{6},您正在进行手机号码:\\d{11}的身份验证,打死不要告诉别人哦!$", msgBody)) {
|
||||
String code = msgBody.substring(10, 16);
|
||||
Utils.log(code);
|
||||
EventBus.getDefault().post(new EBSms("身份验证", code));
|
||||
} else if (Pattern.matches("^【变更验证】验证码:\\d{6},您正在尝试变更光环号:.{6,}的手机号码这一重要信息,请妥善保管账户信息。$", msgBody)) {
|
||||
String code = msgBody.substring(10, 16);
|
||||
Utils.log(code);
|
||||
EventBus.getDefault().post(new EBSms("变更验证", code));
|
||||
} else if (Pattern.matches("^【变更验证】验证码:\\d{6},您正在尝试修改光环号:.{6,}的登录密码,请妥善保管账户信息。$", msgBody)) {
|
||||
String code = msgBody.substring(10, 16);
|
||||
Utils.log(code);
|
||||
EventBus.getDefault().post(new EBSms("变更验证", code));
|
||||
}
|
||||
}
|
||||
//【注册验证】验证码:195306,您正在注册成为光环助手用户,感谢您的支持!
|
||||
//【身份验证】验证码:716438,您正在进行手机号码:13829769945的身份验证,打死不要告诉别人哦!
|
||||
//【变更验证】验证码:293785,您正在尝试变更光环号:qqqwww的手机号码这一重要信息,请妥善保管账户信息。
|
||||
//【变更验证】验证码:901874,您正在尝试修改光环号:qqqwww的登录密码,请妥善保管账户信息。
|
||||
}
|
||||
}
|
||||
|
||||
public SmsMessage[] getMessagesFromIntent(Intent intent) {
|
||||
Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
|
||||
byte[][] pduObjs = new byte[messages.length][];
|
||||
for (int i = 0; i < messages.length; i++) {
|
||||
pduObjs[i] = (byte[]) messages[i];
|
||||
}
|
||||
byte[][] pdus = new byte[pduObjs.length][];
|
||||
int pduCount = pdus.length;
|
||||
SmsMessage[] msgs = new SmsMessage[pduCount];
|
||||
for (int i = 0; i < pduCount; i++) {
|
||||
pdus[i] = pduObjs[i];
|
||||
msgs[i] = SmsMessage.createFromPdu(pdus[i]);
|
||||
}
|
||||
return msgs;
|
||||
}
|
||||
|
||||
}
|
||||
@ -19,13 +19,15 @@ 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.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
@ -41,7 +43,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Search1DetailFragmentAdapter extends RecyclerView.Adapter<GameViewHolder> {
|
||||
public class Search1DetailFragmentAdapter extends RecyclerView.Adapter<GameNormalViewHolder> {
|
||||
|
||||
private Context context;
|
||||
|
||||
@ -123,24 +125,24 @@ public class Search1DetailFragmentAdapter extends RecyclerView.Adapter<GameViewH
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameViewHolder onCreateViewHolder(ViewGroup viewGroup,
|
||||
public GameNormalViewHolder onCreateViewHolder(ViewGroup viewGroup,
|
||||
int viewType) {
|
||||
View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.home_list_item_gamenormal_type, viewGroup, false);
|
||||
return new GameViewHolder(itemView);
|
||||
R.layout.home_game_normal_item, viewGroup, false);
|
||||
return new GameNormalViewHolder(itemView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(GameViewHolder viewHolder, int position) {
|
||||
public void onBindViewHolder(GameNormalViewHolder viewHolder, int position) {
|
||||
final GameEntity gameEntity = gameList.get(position);
|
||||
|
||||
ImageUtils.getInstance(context).display(gameEntity.getIcon(), viewHolder.gameThumb);
|
||||
viewHolder.gameNameAndSize.setText(gameEntity.getName());
|
||||
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
|
||||
viewHolder.gameNameAndSize.setText(gameEntity.getName());
|
||||
viewHolder.gameDes.setText(gameEntity.getBrief());
|
||||
} else {
|
||||
viewHolder.gameNameAndSize.setText(gameEntity.getName() + " | " + gameEntity.getApk().get(0).getSize());
|
||||
viewHolder.gameDes.setText(gameEntity.getApk().get(0).getSize() + " | " + gameEntity.getBrief());
|
||||
}
|
||||
viewHolder.gameDes.setText(gameEntity.getBrief());
|
||||
|
||||
GameViewUtils.setLabelList(context, viewHolder.labelList, gameEntity.getTag());
|
||||
|
||||
@ -172,14 +174,24 @@ public class Search1DetailFragmentAdapter extends RecyclerView.Adapter<GameViewH
|
||||
} else {
|
||||
viewHolder.downloadBtn.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
public void onClick(final View v) {
|
||||
InputMethodManager imm = (InputMethodManager) context
|
||||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
if (!dismissEntity.isShow()) {
|
||||
dismissEntity.setShow(true);
|
||||
DownloadDialog.getInstance(context)
|
||||
.showPopupWindow(v, gameEntity, "搜索", "搜索:" + gameEntity.getName());
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
DownloadDialog.getInstance(context)
|
||||
.showPopupWindow(v, gameEntity, "搜索", "搜索:" + gameEntity.getName());
|
||||
} else {
|
||||
DialogUtils.showWarningDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
DownloadDialog.getInstance(context)
|
||||
.showPopupWindow(v, gameEntity, "搜索", "搜索:" + gameEntity.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -19,13 +19,15 @@ 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.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
@ -127,16 +129,16 @@ public class Search2GameListFragmentAdapter extends
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||
final GameEntity gameEntity = gameList.get(position);
|
||||
if (viewHolder instanceof GameViewHolder && position == 0) {
|
||||
GameViewHolder holder = (GameViewHolder) viewHolder;
|
||||
if (viewHolder instanceof GameNormalViewHolder && position == 0) {
|
||||
GameNormalViewHolder holder = (GameNormalViewHolder) viewHolder;
|
||||
|
||||
ImageUtils.getInstance(context).display(gameEntity.getIcon(), holder.gameThumb);
|
||||
holder.gameNameAndSize.setText(gameEntity.getName());
|
||||
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
|
||||
holder.gameNameAndSize.setText(gameEntity.getName());
|
||||
holder.gameDes.setText(gameEntity.getBrief());
|
||||
} else {
|
||||
holder.gameNameAndSize.setText(gameEntity.getName() + " | " + gameEntity.getApk().get(0).getSize());
|
||||
holder.gameDes.setText(gameEntity.getApk().get(0).getSize() + " | " + gameEntity.getBrief());
|
||||
}
|
||||
holder.gameDes.setText(gameEntity.getBrief());
|
||||
|
||||
GameViewUtils.setLabelList(context, holder.labelList, gameEntity.getTag());
|
||||
|
||||
@ -176,14 +178,24 @@ public class Search2GameListFragmentAdapter extends
|
||||
} else {
|
||||
holder.downloadBtn.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
public void onClick(final View v) {
|
||||
InputMethodManager imm = (InputMethodManager) context
|
||||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
if (!dismissEntity.isShow()) {
|
||||
dismissEntity.setShow(true);
|
||||
DownloadDialog.getInstance(context).showPopupWindow(
|
||||
v, gameEntity, "搜索", "搜索:" + gameEntity.getName());
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
DownloadDialog.getInstance(context)
|
||||
.showPopupWindow(v, gameEntity, "搜索", "搜索:" + gameEntity.getName());
|
||||
} else {
|
||||
DialogUtils.showWarningDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
DownloadDialog.getInstance(context)
|
||||
.showPopupWindow(v, gameEntity, "搜索", "搜索:" + gameEntity.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -230,8 +242,8 @@ public class Search2GameListFragmentAdapter extends
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||
if (viewType == 0) {
|
||||
View itemView = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.home_list_item_gamenormal_type, viewGroup, false);
|
||||
return new GameViewHolder(itemView);
|
||||
.inflate(R.layout.home_game_normal_item, viewGroup, false);
|
||||
return new GameNormalViewHolder(itemView);
|
||||
} else {
|
||||
View itemView = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.search2_gamelist_fragment_item, viewGroup, false);
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_selected="true" android:color="#FFFFFF"/>
|
||||
<item android:state_focused="true" android:color="#FFFFFF"/>
|
||||
<item android:state_pressed="true" android:color="#FFFFFF"/>
|
||||
<item android:color="#EB212E"/>
|
||||
</selector>
|
||||
|
Before Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 134 B |
|
Before Width: | Height: | Size: 140 B |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 2.9 KiB |
BIN
app/src/main/res/drawable-hdpi/home_plug_upgrade.png
Normal file
|
After Width: | Height: | Size: 1008 B |
|
Before Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 3.6 KiB |