diff --git a/.idea/modules.xml b/.idea/modules.xml index b8e6af6e8c..665f4582d7 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index d50324fb1b..c18dd3a469 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "com.gh.gamecenter" minSdkVersion 14 targetSdkVersion 21 - versionCode 17 - versionName "2.2" + versionCode 18 + versionName "2.3" // 默认的渠道 // manifestPlaceholders = [CHANNEL_VALUE: "GH_TEST"] @@ -93,7 +93,7 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:21.0.0' - compile 'com.android.support:cardview-v7:21.0.0' +// compile 'com.android.support:cardview-v7:21.0.0' // fresco图片框架 compile 'com.facebook.fresco:fresco:0.12.0' compile 'com.facebook.fresco:animated-gif:0.12.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6f69dd5bfb..1e17c80425 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -55,7 +55,7 @@ android:name="com.gh.base.AppController" android:icon="@drawable/logo" android:label="@string/app_name" - android:theme="@style/AppThemeNormal" > + android:theme="@style/AppNormalTheme" > diff --git a/app/src/main/java/com/gh/base/AppUncaHandler.java b/app/src/main/java/com/gh/base/AppUncaHandler.java index 0fddcd21e0..59cbcf35cc 100644 --- a/app/src/main/java/com/gh/base/AppUncaHandler.java +++ b/app/src/main/java/com/gh/base/AppUncaHandler.java @@ -10,10 +10,9 @@ import android.util.Log; import android.widget.Toast; import com.gh.common.constant.Config; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.FileUtils; -import com.gh.common.util.NetworkUtils; import com.gh.gamecenter.SplashScreenActivity; -import com.gh.gamecenter.manager.DataCollectionManager; import com.tencent.stat.StatService; import java.io.File; @@ -22,9 +21,7 @@ import java.io.IOException; import java.lang.Thread.UncaughtExceptionHandler; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.HashMap; import java.util.Locale; -import java.util.Map; public class AppUncaHandler implements UncaughtExceptionHandler { @@ -88,13 +85,8 @@ public class AppUncaHandler implements UncaughtExceptionHandler { // MTA主动上传错误 StatService.reportError(appController.getApplicationContext(), errorMsg); - // WIFI实时上传错误数据 - Map map = new HashMap<>(); - map.put("content", errorMsg); - map.put("type", android.os.Build.MODEL); - map.put("system", android.os.Build.VERSION.SDK_INT + "=" + android.os.Build.VERSION.RELEASE); - DataCollectionManager.onEvent(appController.getApplicationContext(), "error", map, - NetworkUtils.isWifiConnected(appController.getApplicationContext())); + // 上传错误数据 + DataCollectionUtils.uploadError(appController.getApplicationContext(), errorMsg); // 保存到本地 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.getDefault()); diff --git a/app/src/main/java/com/gh/base/BaseActivity.java b/app/src/main/java/com/gh/base/BaseActivity.java index f6ab4f5a16..d5405a3360 100644 --- a/app/src/main/java/com/gh/base/BaseActivity.java +++ b/app/src/main/java/com/gh/base/BaseActivity.java @@ -139,7 +139,7 @@ public class BaseActivity extends Activity implements OnCallBackListener { } //如果是游戏分享,newsTitle默认为空 - public void showShare(String url, String gameName, String icon, String newsTitle, ArrayList tag, String entrance, String type) { + public void showShare(String url, String gameName, String icon, String newsTitle, ArrayList tag) { //判断是否是官方版 boolean isPlugin = false; @@ -153,9 +153,9 @@ public class BaseActivity extends Activity implements OnCallBackListener { ShareUtils.getInstance(this).showShareWindows(new View(this), url, gameName, icon, newsTitle, isPlugin); - if (newsTitle == null){ + if (newsTitle == null) { DataUtils.onEvent(this, "内容分享", gameName); - }else { + } else { DataUtils.onEvent(this, "内容分享", newsTitle); } } diff --git a/app/src/main/java/com/gh/base/BaseDetailActivity.java b/app/src/main/java/com/gh/base/BaseDetailActivity.java index 1236cb5d8e..d57dd29b0e 100644 --- a/app/src/main/java/com/gh/base/BaseDetailActivity.java +++ b/app/src/main/java/com/gh/base/BaseDetailActivity.java @@ -19,7 +19,6 @@ import com.gh.common.util.DisplayUtils; import com.gh.common.util.FileUtils; import com.gh.common.util.NetworkUtils; import com.gh.common.util.PackageUtils; -import com.gh.common.util.PlatformUtils; import com.gh.common.util.ShareUtils; import com.gh.common.view.DownloadDialog; import com.gh.download.DataWatcher; @@ -32,13 +31,9 @@ import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.eventbus.EBDownloadStatus; import com.gh.gamecenter.eventbus.EBPackage; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.PackageManager; import com.tencent.tauth.Tencent; -import java.util.HashMap; -import java.util.Map; - /** * Created by Administrator on 2016/9/19. * 游戏详情、新闻详情基类(控制底部下载栏) @@ -89,6 +84,9 @@ public abstract class BaseDetailActivity extends BaseActivity implements View.On super.onCreate(savedInstanceState); entrance = getIntent().getStringExtra("entrance"); + if (getIntent().getBundleExtra("data") != null) { + entrance = getIntent().getBundleExtra("data").getString("entrance"); + } View contentView = View.inflate(this, R.layout.activity_detail, null); @@ -395,10 +393,7 @@ public abstract class BaseDetailActivity extends BaseActivity implements View.On private void download() { String str = detail_tv_download.getText().toString(); if (str.contains("启动")) { - Map kv = new HashMap<>(); - kv.put("版本", gameEntity.getApk().get(0).getPlatform()); - kv.put("页面", name); - DataUtils.onEvent(BaseDetailActivity.this, "游戏启动", gameEntity.getName(), kv); + DataUtils.onGameLaunchEvent(this, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), name); PackageUtils.launchApplicationByPackageName(this, gameEntity.getApk().get(0).getPackageName()); } else { @@ -413,35 +408,7 @@ public abstract class BaseDetailActivity extends BaseActivity implements View.On ApkEntity apkEntity = gameEntity.getApk().get(0); String msg = FileUtils.isCanDownload(this, apkEntity.getSize()); if (TextUtils.isEmpty(msg)) { - Map kv = new HashMap<>(); - kv.put("版本", apkEntity.getPlatform()); - kv.put("状态", "下载开始"); - DataUtils.onEvent(BaseDetailActivity.this, "游戏下载", gameEntity.getName(), kv); - - Map kv2 = new HashMap<>(); - kv2.put("版本", apkEntity.getPlatform()); - kv2.put("状态", "下载开始"); - kv2.put("页面", name); - kv2.put("位置", entrance); - DataUtils.onEvent(BaseDetailActivity.this, "游戏下载位置", gameEntity.getName(), kv2); - - Map kv3 = new HashMap<>(); - kv3.put(entrance, "下载数"); - kv3.put(entrance, "下载开始"); - DataUtils.onEvent(BaseDetailActivity.this, "应用数据", gameEntity.getName(), kv3); - - Map map = new HashMap<>(); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - map.put("method", method.equals("下载") ? "正常" : method); - map.put("platform", PlatformUtils.getInstance(getApplicationContext()) - .getPlatformName(gameEntity.getApk().get(0).getPlatform())); - map.put("status", "开始"); - map.put("location", name + ":" + title); - map.put("entrance", entrance); - map.put("btn_status", method); - map.put("network", NetworkUtils.getConnectedType(this)); - DataCollectionManager.onEvent(this, "download", map); + DataUtils.onGameDownloadEvent(this, gameEntity.getName(), apkEntity.getPlatform(), entrance, "下载开始"); DownloadManager.createDownload(this, apkEntity, gameEntity, method, entrance, name + ":" + title); diff --git a/app/src/main/java/com/gh/base/BaseFragmentActivity.java b/app/src/main/java/com/gh/base/BaseFragmentActivity.java index ae57e14869..412a810f0e 100644 --- a/app/src/main/java/com/gh/base/BaseFragmentActivity.java +++ b/app/src/main/java/com/gh/base/BaseFragmentActivity.java @@ -131,7 +131,7 @@ public class BaseFragmentActivity extends FragmentActivity { } //如果是游戏分享,newsTitle默认为空 - public void showShare(String url, String gameName, String icon, String newsTitle, ArrayList tag, String entrance, String type) { + public void showShare(String url, String gameName, String icon, String newsTitle, ArrayList tag) { //判断是否是官方版 boolean isPlugin = false; diff --git a/app/src/main/java/com/gh/base/GHPushMessageReceiver.java b/app/src/main/java/com/gh/base/GHPushMessageReceiver.java index e3438e1e46..ed0bf2ddf0 100644 --- a/app/src/main/java/com/gh/base/GHPushMessageReceiver.java +++ b/app/src/main/java/com/gh/base/GHPushMessageReceiver.java @@ -233,8 +233,7 @@ public class GHPushMessageReceiver extends PushMessageReceiver { ArrayList list = new ArrayList<>(); List packageInfos = context.getPackageManager() .getInstalledPackages(0); - for (int i = 0, size = packageInfos.size(); i < size; i++) { - PackageInfo packageInfo = packageInfos.get(i); + for (PackageInfo packageInfo : packageInfos) { if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { list.add(packageInfo.packageName); } diff --git a/app/src/main/java/com/gh/base/HomeFragment.java b/app/src/main/java/com/gh/base/HomeFragment.java index 8b8a70eaaf..d8d934c695 100644 --- a/app/src/main/java/com/gh/base/HomeFragment.java +++ b/app/src/main/java/com/gh/base/HomeFragment.java @@ -8,8 +8,6 @@ import android.os.Bundle; import android.os.Handler; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentTransaction; -import android.support.v4.view.ViewPager; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -18,6 +16,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import com.gh.common.constant.Config; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.download.DownloadManager; @@ -27,13 +26,8 @@ import com.gh.gamecenter.R; import com.gh.gamecenter.SearchActivity; import com.gh.gamecenter.eventbus.EBDownloadStatus; import com.gh.gamecenter.eventbus.EBReuse; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.PackageManager; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import de.greenrobot.event.EventBus; /** @@ -43,11 +37,6 @@ import de.greenrobot.event.EventBus; public class HomeFragment extends Fragment implements View.OnClickListener { protected View view; - protected LinearLayout home_ll_top; - protected View home_slide_line; - protected ViewPager home_vp_content; - - protected LinearLayout.LayoutParams lparams; protected Handler handler = new Handler(); @@ -90,10 +79,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener { initActionBar(); - home_ll_top = (LinearLayout) view.findViewById(R.id.home_ll_top); - home_slide_line = view.findViewById(R.id.home_slide_line); - home_vp_content = (ViewPager) view.findViewById(R.id.home_vp_content); - EventBus.getDefault().register(this); } @@ -143,29 +128,17 @@ public class HomeFragment extends Fragment implements View.OnClickListener { final int id = v.getId(); if (id == R.id.actionbar_notification) { DataUtils.onEvent(getActivity(), "主页", "关注图标"); - - Map map = new HashMap<>(); - map.put("location", "关注图标"); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); + DataCollectionUtils.uploadClick(getActivity(), "关注图标", "主页"); startActivity(new Intent(getActivity(), ConcernActivity.class)); } else if (id == R.id.actionbar_rl_download) { DataUtils.onEvent(getActivity(), "主页", "下载图标"); - - Map map = new HashMap<>(); - map.put("location", "下载图标"); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); + DataCollectionUtils.uploadClick(getActivity(), "下载图标", "主页"); startActivity(new Intent(getActivity(), DownloadManagerActivity.class)); } else if (id == R.id.actionbar_search_input) { DataUtils.onEvent(getActivity(), "主页", "搜索框"); - - Map map = new HashMap<>(); - map.put("location", "搜索框"); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); + DataCollectionUtils.uploadClick(getActivity(), "搜索框", "主页"); Intent goSearch = new Intent(getActivity(), SearchActivity.class); goSearch.putExtra("clicked", false); @@ -173,11 +146,7 @@ public class HomeFragment extends Fragment implements View.OnClickListener { startActivity(goSearch); } else if (id == R.id.actionbar_iv_search) { DataUtils.onEvent(getActivity(), "主页", "搜索图标"); - - Map map = new HashMap<>(); - map.put("location", "搜索图标"); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); + DataCollectionUtils.uploadClick(getActivity(), "搜索图标", "主页"); Intent searchIntent = new Intent(getActivity(), SearchActivity.class); searchIntent.putExtra("clicked", true); @@ -220,28 +189,10 @@ public class HomeFragment extends Fragment implements View.OnClickListener { } } - @Override - public void onHiddenChanged(boolean hidden) { - super.onHiddenChanged(hidden); - FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); - List list = getChildFragmentManager().getFragments(); - if (list != null) { - if (hidden) { - for (Fragment fragment : getChildFragmentManager().getFragments()) { - transaction.hide(fragment); - } - } else { - for (Fragment fragment : getChildFragmentManager().getFragments()) { - transaction.show(fragment); - } - } - } - transaction.commit(); - } - @Override public void onDestroy() { super.onDestroy(); EventBus.getDefault().unregister(this); } + } diff --git a/app/src/main/java/com/gh/common/constant/Config.java b/app/src/main/java/com/gh/common/constant/Config.java index 1975de799f..250af1b2a7 100644 --- a/app/src/main/java/com/gh/common/constant/Config.java +++ b/app/src/main/java/com/gh/common/constant/Config.java @@ -7,7 +7,7 @@ import android.content.SharedPreferences; public class Config { public static final String HOST = "http://api.ghzhushou.com/v2d3/"; - public static final String USER_HOST = "http://user.ghzhushou.com/v1d0/"; + public static final String USER_HOST = "http://user.ghzhushou.com/v1d1/"; public static final String COMMENT_HOST = "http://comment.ghzhushou.com/v1d1/"; public static final String DATA_HOST = "http://data.ghzhushou.com/"; public static final String PREFERENCE = "ghzhushou"; diff --git a/app/src/main/java/com/gh/common/util/ConcernUtils.java b/app/src/main/java/com/gh/common/util/ConcernUtils.java index 3f24bb7e9d..749f1db610 100644 --- a/app/src/main/java/com/gh/common/util/ConcernUtils.java +++ b/app/src/main/java/com/gh/common/util/ConcernUtils.java @@ -1,5 +1,7 @@ package com.gh.common.util; +import android.content.Context; + import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -17,16 +19,15 @@ import rx.schedulers.Schedulers; */ public class ConcernUtils { - public static void postConcernGameId(final String deviceId, final String gameId) { + public static void postConcernGameId(final Context context, final String gameId) { new Thread(new Runnable() { @Override public void run() { JSONArray params = new JSONArray(); params.put(gameId); - RequestBody body = RequestBody.create(MediaType.parse("application/json"), - params.toString()); - RetrofitManager.getApi().postConcern(deviceId, body) + RequestBody body = RequestBody.create(MediaType.parse("application/json"), params.toString()); + RetrofitManager.getUser().postConcern(TokenUtils.getToken(context), body) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Response()); @@ -34,11 +35,11 @@ public class ConcernUtils { }).start(); } - public static void deleteConcernData(final String deviceId, final String gameId) { + public static void deleteConcernData(final Context context, final String gameId) { new Thread(new Runnable() { @Override public void run() { - RetrofitManager.getApi().deleteConcern(deviceId, gameId) + RetrofitManager.getUser().deleteConcern(TokenUtils.getToken(context), gameId) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Response()); @@ -46,13 +47,13 @@ public class ConcernUtils { }).start(); } - public static void updateConcernData(final String deviceId, final JSONArray data) { + public static void updateConcernData(final Context context, final JSONArray data) { new Thread(new Runnable() { @Override public void run() { RequestBody body = RequestBody.create(MediaType.parse("application/json"), data.toString()); - RetrofitManager.getApi().putConcern(deviceId, body) + RetrofitManager.getUser().putConcern(TokenUtils.getToken(context), body) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Response()); diff --git a/app/src/main/java/com/gh/common/util/DataCollectionUtils.java b/app/src/main/java/com/gh/common/util/DataCollectionUtils.java new file mode 100644 index 0000000000..f47fb0602c --- /dev/null +++ b/app/src/main/java/com/gh/common/util/DataCollectionUtils.java @@ -0,0 +1,160 @@ +package com.gh.common.util; + +import android.content.Context; +import android.os.Build; + +import com.gh.download.DownloadEntity; +import com.gh.gamecenter.db.info.ConcernInfo; +import com.gh.gamecenter.entity.GameEntity; +import com.gh.gamecenter.entity.NewsDetailEntity; +import com.gh.gamecenter.manager.ConcernManager; +import com.gh.gamecenter.manager.DataCollectionManager; +import com.gh.gamecenter.manager.PackageManager; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by LGT on 2016/12/9. + * 数据收集 工具类(data.ghzhushou.com) + */ +public class DataCollectionUtils { + + // 上传助手奔溃数据 + public static void uploadError(Context context, String msg) { + Map map = new HashMap<>(); + map.put("content", msg); + map.put("type", android.os.Build.MODEL); + map.put("system", android.os.Build.VERSION.SDK_INT + "=" + android.os.Build.VERSION.RELEASE); + // WIFI实时 + DataCollectionManager.onEvent(context, "error", map, NetworkUtils.isWifiConnected(context)); + } + + // 上传下载数据(开始、完成) + public static void uploadDownload(Context context, DownloadEntity downloadEntity, String status) { + Map map = new HashMap<>(); + map.put("game", downloadEntity.getName()); + map.put("game_id", downloadEntity.getGameId()); + if (downloadEntity.isPluggable()) { + map.put("method", "插件化"); + map.put("btn_status", "插件化"); + } else if (downloadEntity.isUpdate()) { + map.put("method", "更新"); + map.put("btn_status", "更新"); + } else { + map.put("method", "正常"); + map.put("btn_status", "下载"); + } + map.put("platform", PlatformUtils.getInstance(context).getPlatformName(downloadEntity.getPlatform())); + map.put("status", status); + map.put("location", downloadEntity.getLocation()); + map.put("entrance", downloadEntity.getEntrance()); + map.put("installed", downloadEntity.getInstalled()); + map.put("network", NetworkUtils.getConnectedType(context)); + DataCollectionManager.onEvent(context, "download", map); + } + + // 上传点击数据 + public static void uploadClick(Context context, String... args) { + if (args.length < 2) { + return; + } + Map map = new HashMap<>(); + map.put("location", args[0]); + map.put("page", args[1]); + if (args.length == 3) { + map.put("title", args[2]); + } + DataCollectionManager.onEvent(context, "click-item", map); + } + + // 上传游戏数据 + public static void uploadGame(Context context, GameEntity gameEntity, int seconds, String from) { + Map map = new HashMap<>(); + map.put("game", gameEntity.getName()); + map.put("game_id", gameEntity.getId()); + map.put("time", seconds); + map.put("from", from); + DataCollectionManager.onEvent(context, "game", map); + } + + // 上传新闻数据 + public static void uploadNews(Context context, NewsDetailEntity newsDetailEntity, + GameEntity gameEntity, int seconds, String from) { + Map map = new HashMap<>(); + map.put("title", newsDetailEntity.getTitle()); + map.put("type", newsDetailEntity.getType()); + map.put("author", newsDetailEntity.getAuthor()); + if (gameEntity != null) { + map.put("game", gameEntity.getName()); + map.put("game_id", gameEntity.getId()); + } + map.put("time", seconds); + map.put("from", from); + DataCollectionManager.onEvent(context, "news", map); + } + + // 上传安装或卸载数据 + public static void uploadInorunstall(Context context, String type, String packageName) { + Map map = new HashMap<>(); + map.put("type", type); + map.put("packageName", packageName); + DataCollectionManager.onEvent(context, "inorunstall", map); + } + + // 上传劫持数据 + public static void uploadHijack(Context context, DownloadEntity downloadEntity) { + Map map = new HashMap<>(); + map.put("url", downloadEntity.getUrl()); + map.put("game", downloadEntity.getName()); + map.put("game_id", downloadEntity.getGameId()); + map.put("platform", downloadEntity.getPlatform()); + map.put("hijack_url", downloadEntity.getError()); + DataCollectionManager.onEvent(context, "hijack", map); + } + + // 上传用户数据 + public static void uploadUser(Context context) { + ConcernManager concernManager = new ConcernManager(context); + ArrayList concernList = new ArrayList<>(); + for (ConcernInfo entity : concernManager.getAllConcern()) { + if (entity.isConcern()) { + concernList.add(entity.getGameName()); + } + } + Map map = new HashMap<>(); + map.put("type", Build.MODEL); + map.put("system", Build.VERSION.SDK_INT + "=" + Build.VERSION.RELEASE); + map.put("install", PackageManager.getInstalledList()); + map.put("concern", concernList); + DataCollectionManager.upsert(context, "user", map); + } + + // 上传搜索数据 + public static void uploadSearch(Context context, String... args) { + if (args.length < 2) { + return; + } + Map map = new HashMap<>(); + map.put("key", args[0]); + map.put("from", args[1]); + if (args.length == 3) { + map.put("click", args[2]); + } + DataCollectionManager.onEvent(context, "search", map); + } + + // 上传关注数据 + public static void uploadConcern(Context context, String... args) { + if (args.length < 3) { + return; + } + Map map = new HashMap<>(); + map.put("game", args[0]); + map.put("game_id", args[1]); + map.put("type", args[2]); + DataCollectionManager.onEvent(context, "concern", map); + } + +} diff --git a/app/src/main/java/com/gh/common/util/DataLogUtils.java b/app/src/main/java/com/gh/common/util/DataLogUtils.java new file mode 100644 index 0000000000..94355e7ec0 --- /dev/null +++ b/app/src/main/java/com/gh/common/util/DataLogUtils.java @@ -0,0 +1,91 @@ +package com.gh.common.util; + +import android.content.Context; + +import com.gh.download.DownloadEntity; +import com.gh.gamecenter.retrofit.Response; +import com.gh.gamecenter.retrofit.RetrofitManager; + +import org.json.JSONObject; + +import java.util.HashMap; +import java.util.Map; + +import okhttp3.MediaType; +import okhttp3.RequestBody; +import okhttp3.ResponseBody; +import rx.android.schedulers.AndroidSchedulers; +import rx.schedulers.Schedulers; + +/** + * Created by LGT on 2016/12/8. + * 日志上传工具类 + */ +public class DataLogUtils { + + /** + * 上传日志 + */ + public static void uploadLog(Context context, String topic, Map map) { + String version = PackageUtils.getVersionName(context); + String user = DeviceUtils.getDeviceID(context); + String channel = (String) PackageUtils.getMetaData(context, context.getPackageName(), "TD_CHANNEL_ID"); + map.put("version", version); + map.put("user", user); + map.put("device_id", TokenUtils.getDeviceId(context)); + map.put("channel", channel); + + Map params = new HashMap<>(); + params.put("topic", topic); + params.put("source", "GH-ASSIST-Client"); + params.put("time", String.valueOf(Utils.getTime(context))); + params.put("content", new JSONObject(map).toString()); + + RequestBody body = RequestBody.create(MediaType.parse("application/json"), + new JSONObject(params).toString()); + RetrofitManager.getData().postLog(body) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response()); + } + + // 轮播图 + public static void uploadLunbotuLog(Context context, String type, String title, String location) { + Map map = new HashMap<>(); + map.put("location", location); + map.put("type", type); + map.put("title", title); + map.put("form", "click"); + uploadLog(context, "lunbotu", map); + } + + // 网络错误 + public static void uploadNeterrorLog(Context context, DownloadEntity downloadEntity) { + Map map = new HashMap<>(); + map.put("url", downloadEntity.getUrl()); + map.put("game", downloadEntity.getName()); + map.put("game_id", downloadEntity.getGameId()); + map.put("platform", downloadEntity.getPlatform()); + map.put("error", downloadEntity.getError()); + uploadLog(context, "neterror", map); + } + + // 助手更新 + public static void uploadUpgradeLog(Context context, String step) { + Map map = new HashMap<>(); + map.put("step", step); + uploadLog(context, "upgrade", map); + } + + // 链接劫持 + public static void uploadHijack(Context context, DownloadEntity downloadEntity) { + Map map = new HashMap<>(); + map.put("url", downloadEntity.getUrl()); + map.put("game", downloadEntity.getName()); + map.put("game_id", downloadEntity.getGameId()); + map.put("platform", downloadEntity.getPlatform()); + map.put("hijack_url", downloadEntity.getError()); + uploadLog(context, "hijack", map); + } + +} diff --git a/app/src/main/java/com/gh/common/util/DataUtils.java b/app/src/main/java/com/gh/common/util/DataUtils.java index ebf4f776b4..b10e4e3c26 100644 --- a/app/src/main/java/com/gh/common/util/DataUtils.java +++ b/app/src/main/java/com/gh/common/util/DataUtils.java @@ -10,11 +10,13 @@ import com.tencent.stat.StatReportStrategy; import com.tencent.stat.StatService; import com.tendcloud.tenddata.TCAgent; +import java.util.HashMap; import java.util.Map; import java.util.Properties; /** * Created by LGT on 2016/6/15. + * 数据收集 工具类 (TalkingData、MTA) */ public class DataUtils { @@ -68,4 +70,39 @@ public class DataUtils { StatService.onResume(var0); } + // 游戏启动 + public static void onGameLaunchEvent(Context context, String gameName, String platform, String page) { + Map kv = new HashMap<>(); + kv.put("版本", platform); + kv.put("页面", page); + onEvent(context, "游戏启动", gameName, kv); + } + + // 游戏下载 + public static void onGameDownloadEvent(Context context, String gameName, String platform, String entrance, String status) { + Map kv = new HashMap<>(); + kv.put("版本", platform); + kv.put("状态", status); + DataUtils.onEvent(context, "游戏下载", gameName, kv); + + Map kv2 = new HashMap<>(); + kv2.put("版本", platform); + kv2.put("状态", status); + kv2.put("位置", entrance); + DataUtils.onEvent(context, "游戏下载位置", gameName, kv2); + + Map kv3 = new HashMap<>(); + kv3.put(entrance, "下载数"); + kv3.put(entrance, status); + DataUtils.onEvent(context, "应用数据", gameName, kv3); + } + + // 游戏更新 + public static void onGameUpdateEvent(Context context, String gameName, String paltform, String status) { + Map kv = new HashMap<>(); + kv.put("版本", paltform); + kv.put("状态", status); + DataUtils.onEvent(context, "游戏更新", gameName, kv); + } + } diff --git a/app/src/main/java/com/gh/common/util/DownloadItemUtils.java b/app/src/main/java/com/gh/common/util/DownloadItemUtils.java index 7401ba6753..90baf9a5b6 100644 --- a/app/src/main/java/com/gh/common/util/DownloadItemUtils.java +++ b/app/src/main/java/com/gh/common/util/DownloadItemUtils.java @@ -23,11 +23,8 @@ import com.gh.gamecenter.DownloadManagerActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.PackageManager; -import java.util.HashMap; -import java.util.Map; import java.util.concurrent.LinkedBlockingQueue; public class DownloadItemUtils { @@ -417,9 +414,7 @@ public class DownloadItemUtils { } else if ("安装".equals(str)) { install(context, gameEntity, position, adapter); } else if ("启动".equals(str)) { - Map kv = new HashMap<>(); - kv.put("版本", gameEntity.getApk().get(0).getPlatform()); - DataUtils.onEvent(context, "游戏启动", gameEntity.getName(), kv); + DataUtils.onGameLaunchEvent(context, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), location); PackageUtils.launchApplicationByPackageName(context, gameEntity.getApk().get(0).getPackageName()); } else if ("下载中".equals(str)) { @@ -476,26 +471,7 @@ public class DownloadItemUtils { GameEntity gameEntity, String entrance, String location) { - ApkEntity apkEntity = gameEntity.getApk().get(0); - //下载可更新游戏 - Map kv = new HashMap<>(); - kv.put("版本", apkEntity.getPlatform()); - kv.put("状态", "下载开始"); - DataUtils.onEvent(context, "游戏更新", gameEntity.getName(), kv); - - Map map = new HashMap<>(); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - map.put("method", "更新"); - map.put("platform", PlatformUtils.getInstance(context) - .getPlatformName(gameEntity.getApk().get(0).getPlatform())); - map.put("status", "开始"); - map.put("location", location); - map.put("entrance", entrance); - map.put("btn_status", "更新"); - map.put("network", NetworkUtils.getConnectedType(context)); - DataCollectionManager.onEvent(context, "download", map); - + DataUtils.onGameUpdateEvent(context, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), "下载开始"); DownloadManager.createDownload(context, gameEntity, "更新", entrance, location); } @@ -507,34 +483,7 @@ public class DownloadItemUtils { String location) { String msg = FileUtils.isCanDownload(context, gameEntity.getApk().get(0).getSize()); if (TextUtils.isEmpty(msg)) { - Map kv = new HashMap<>(); - kv.put("版本", gameEntity.getApk().get(0).getPlatform()); - kv.put("状态", "下载开始"); - DataUtils.onEvent(context, "游戏下载", gameEntity.getName(), kv); - - Map kv2 = new HashMap<>(); - kv2.put("版本", gameEntity.getApk().get(0).getPlatform()); - kv2.put("状态", "下载开始"); - kv2.put("位置", entrance + "-开始"); - DataUtils.onEvent(context, "游戏下载位置", gameEntity.getName(), kv2); - - Map kv3 = new HashMap<>(); - kv3.put(entrance, "下载数"); - kv3.put(entrance, "下载开始"); - DataUtils.onEvent(context, "应用数据", gameEntity.getName(), kv3); - - Map map = new HashMap<>(); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - map.put("method", "正常"); - map.put("platform", PlatformUtils.getInstance(context) - .getPlatformName(gameEntity.getApk().get(0).getPlatform())); - map.put("status", "开始"); - map.put("location", location); - map.put("entrance", entrance); - map.put("btn_status", "下载"); - map.put("network", NetworkUtils.getConnectedType(context)); - DataCollectionManager.onEvent(context, "download", map); + DataUtils.onGameDownloadEvent(context, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), entrance, "下载开始"); DownloadManager.createDownload(context, gameEntity, "下载", entrance, location); Toast.makeText(context, gameEntity.getName() + "已加入下载队列", Toast.LENGTH_SHORT).show(); @@ -557,34 +506,7 @@ public class DownloadItemUtils { String location) { String msg = FileUtils.isCanDownload(context, gameEntity.getApk().get(0).getSize()); if (TextUtils.isEmpty(msg)) { - Map kv = new HashMap<>(); - kv.put("版本", gameEntity.getApk().get(0).getPlatform()); - kv.put("状态", "下载开始"); - DataUtils.onEvent(context, "游戏下载", gameEntity.getName(), kv); - - Map kv2 = new HashMap<>(); - kv2.put("版本", gameEntity.getApk().get(0).getPlatform()); - kv2.put("状态", "下载开始"); - kv2.put("位置", entrance + "-开始"); - DataUtils.onEvent(context, "游戏下载位置", gameEntity.getName(), kv2); - - Map kv3 = new HashMap<>(); - kv3.put(entrance, "下载数"); - kv3.put(entrance, "下载开始"); - DataUtils.onEvent(context, "应用数据", gameEntity.getName(), kv3); - - Map map = new HashMap<>(); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - map.put("method", "插件化"); - map.put("platform", PlatformUtils.getInstance(context) - .getPlatformName(gameEntity.getApk().get(0).getPlatform())); - map.put("status", "开始"); - map.put("location", location); - map.put("entrance", entrance); - map.put("btn_status", "插件化"); - map.put("network", NetworkUtils.getConnectedType(context)); - DataCollectionManager.onEvent(context, "download", map); + DataUtils.onGameDownloadEvent(context, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), entrance, "下载开始"); DownloadManager.createDownload(context, gameEntity, "插件化", entrance, location); Toast.makeText(context, gameEntity.getName() + "已加入下载队列", Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/com/gh/common/util/FileUtils.java b/app/src/main/java/com/gh/common/util/FileUtils.java index 7ac9ba50cf..2efd2c3928 100644 --- a/app/src/main/java/com/gh/common/util/FileUtils.java +++ b/app/src/main/java/com/gh/common/util/FileUtils.java @@ -102,6 +102,21 @@ public class FileUtils { } } + public static void deleteFolder(File folder) { + if (folder != null) { + if (folder.isDirectory()) { + for (File file : folder.listFiles()) { + if (file.isDirectory()) { + deleteFolder(file); + } else { + file.delete(); + } + } + } + folder.delete(); + } + } + public static boolean isEmptyFile(String path) { File file = new File(path); if (file.exists() && file.length() != 0) { diff --git a/app/src/main/java/com/gh/common/util/GameUtils.java b/app/src/main/java/com/gh/common/util/GameUtils.java index 12b1c22078..f1db8316fb 100644 --- a/app/src/main/java/com/gh/common/util/GameUtils.java +++ b/app/src/main/java/com/gh/common/util/GameUtils.java @@ -5,11 +5,11 @@ import android.content.Intent; import com.gh.base.AppController; import com.gh.gamecenter.GameDetailActivity; +import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; +import com.gh.gamecenter.entity.GameUpdateEntity; + -/** - * Created by LGT on 2016/9/29. - */ public class GameUtils { /** @@ -34,4 +34,25 @@ public class GameUtils { context.startActivity(intent); } + /** + * 获取GameUpdateEntity + */ + public static GameUpdateEntity getGameUpdateEntity(GameEntity gameEntity, ApkEntity apkEntity) { + GameUpdateEntity gameUpdateEntity = new GameUpdateEntity(); + gameUpdateEntity.setId(gameEntity.getId()); + gameUpdateEntity.setIcon(gameEntity.getIcon()); + gameUpdateEntity.setName(gameEntity.getName()); + gameUpdateEntity.setPackageName(apkEntity.getPackageName()); + gameUpdateEntity.setSize(apkEntity.getSize()); + gameUpdateEntity.setVersion(apkEntity.getVersion()); + gameUpdateEntity.setGhVersion(apkEntity.getGhVersion()); + gameUpdateEntity.setUrl(apkEntity.getUrl()); + gameUpdateEntity.setPlatform(apkEntity.getPlatform()); + gameUpdateEntity.setEtag(apkEntity.getEtag()); + gameUpdateEntity.setPluggable(true); + gameUpdateEntity.setTag(gameEntity.getTag()); + gameUpdateEntity.setBrief(gameEntity.getBrief()); + return gameUpdateEntity; + } + } diff --git a/app/src/main/java/com/gh/common/util/GiftUtils.java b/app/src/main/java/com/gh/common/util/GiftUtils.java index fecf308f80..8dc19fa8eb 100644 --- a/app/src/main/java/com/gh/common/util/GiftUtils.java +++ b/app/src/main/java/com/gh/common/util/GiftUtils.java @@ -33,6 +33,7 @@ import rx.schedulers.Schedulers; /** * Created by khy on 2016/12/16. + * */ public class GiftUtils { @@ -57,11 +58,11 @@ public class GiftUtils { } //初始化存号箱 获取存号箱所有礼包 - public static void getCunHaoXiang(final Context context, final GiftDao giftDao) { - getCunHaoXiang(context, true, giftDao); + public static void getCunHaoXiang(Context context) { + getCunHaoXiang(context, true); } - private static void getCunHaoXiang(final Context context, final boolean isCheck, final GiftDao giftDao) { + private static void getCunHaoXiang(final Context context, final boolean isCheck) { new Thread(new Runnable() { @Override @@ -72,7 +73,7 @@ public class GiftUtils { .subscribe(new Response>(){ @Override public void onResponse(List response) { - super.onResponse(response); + GiftDao giftDao = new GiftDao(context); for (GiftEntity giftEntity : response) { giftDao.add(new GiftInfo(giftEntity.getGiftId(), giftEntity.getContent(), giftEntity.getIcon() , giftEntity.getName(),giftEntity.getPlatform(), giftEntity.getGiftStatus() @@ -85,11 +86,10 @@ public class GiftUtils { @Override public void onFailure(Throwable e) { - super.onFailure(e); if (e instanceof HttpException) { HttpException exception = (HttpException) e; if (exception.code() == 401) { - getCunHaoXiang(context, false, giftDao); + getCunHaoXiang(context, false); return; } } @@ -308,7 +308,7 @@ public class GiftUtils { Utils.toast(giftBtn.getContext(), "礼包领取时间已结束"); } else if ("fetched".equals(detail)) { Utils.toast(giftBtn.getContext(), "你已领过这个礼包了"); - getCunHaoXiang(giftBtn.getContext(), giftDao); + getCunHaoXiang(giftBtn.getContext()); giftBtn.setText("查看"); giftBtn.setBackgroundResource(R.drawable.textview_blue_style); } else if ("try tao".equals(detail) || "used up".equals(detail)) { @@ -380,7 +380,7 @@ public class GiftUtils { Utils.toast(giftBtn.getContext(), "礼包领取时间已结束"); } else if ("fetched".equals(detail)) { Utils.toast(giftBtn.getContext(), "你已领过这个礼包了"); - getCunHaoXiang(giftBtn.getContext(), giftDao); + getCunHaoXiang(giftBtn.getContext()); giftBtn.setText("查看"); giftBtn.setBackgroundResource(R.drawable.textview_blue_style); } else if ("try tao".equals(detail) || "used up".equals(detail)) { diff --git a/app/src/main/java/com/gh/common/util/PackageUtils.java b/app/src/main/java/com/gh/common/util/PackageUtils.java index 443dff2c61..3040fbc33d 100644 --- a/app/src/main/java/com/gh/common/util/PackageUtils.java +++ b/app/src/main/java/com/gh/common/util/PackageUtils.java @@ -170,7 +170,7 @@ public class PackageUtils { /* * 返回光环助手的版本信息 */ - public static String getVersion(Context context) { + public static String getVersionName(Context context) { try { PackageInfo pkgInfo = context.getPackageManager().getPackageInfo( context.getPackageName(), 0); @@ -181,6 +181,20 @@ public class PackageUtils { return null; } + /* + * 返回光环助手的版本code + */ + public static String getVersionCode(Context context) { + try { + PackageInfo pkgInfo = context.getPackageManager().getPackageInfo( + context.getPackageName(), 0); + return String.valueOf(pkgInfo.versionCode); + } catch (NameNotFoundException e) { + e.printStackTrace(); + } + return null; + } + /* * 获取apk的版本 */ @@ -201,8 +215,7 @@ public class PackageUtils { FilterManager filterManager = new FilterManager(context); ArrayList list = new ArrayList<>(); List packageInfos = context.getPackageManager().getInstalledPackages(0); - for (int i = 0, size = packageInfos.size(); i < size; i++) { - PackageInfo packageInfo = packageInfos.get(i); + for (PackageInfo packageInfo : packageInfos) { if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { if (!context.getPackageName().equals(packageInfo.packageName)) { if (!filterManager.isFilter(packageInfo.packageName)) { @@ -271,8 +284,7 @@ public class PackageUtils { Uri uri = Uri.fromFile(new File(path)); Intent installIntent = new Intent(Intent.ACTION_VIEW); installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - installIntent.setDataAndType(uri, - "application/vnd.android.package-archive"); + installIntent.setDataAndType(uri, "application/vnd.android.package-archive"); return installIntent; } diff --git a/app/src/main/java/com/gh/common/util/TokenUtils.java b/app/src/main/java/com/gh/common/util/TokenUtils.java index d62014fa63..74389de811 100644 --- a/app/src/main/java/com/gh/common/util/TokenUtils.java +++ b/app/src/main/java/com/gh/common/util/TokenUtils.java @@ -4,12 +4,14 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.net.wifi.WifiManager; +import android.os.Build; import android.os.Environment; import android.provider.Settings; import android.telephony.TelephonyManager; import android.text.TextUtils; import com.gh.common.constant.Config; +import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; import com.gh.gamecenter.retrofit.StringResponse; import com.tencent.stat.StatConfig; @@ -30,6 +32,9 @@ import java.net.URL; import java.util.HashMap; import java.util.Map; +import okhttp3.MediaType; +import okhttp3.RequestBody; +import okhttp3.ResponseBody; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -38,6 +43,10 @@ public class TokenUtils { // 注册设备 public static synchronized String register(final Context context) { HashMap params = new HashMap<>(); + params.put("MANUFACTURER", Build.MANUFACTURER); + params.put("MODEL", Build.MODEL); + params.put("ANDROID_SDK", String.valueOf(Build.VERSION.SDK_INT)); + params.put("ANDROID_VERSION", Build.VERSION.RELEASE); String android_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); if (!TextUtils.isEmpty(android_id)) { params.put("ANDROID_ID", android_id); @@ -113,7 +122,6 @@ public class TokenUtils { // 获取用户token public static synchronized String getToken(Context context, boolean isCheck) { - SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); String token = sp.getString("token", null); if (isCheck) { @@ -183,6 +191,54 @@ public class TokenUtils { return null; } + // 检查设备信息是否已经上传完整 + public static synchronized void checkDeviceInfo(final Context context) { + final SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); + final HashMap params = new HashMap<>(); + if (!sp.getBoolean("isUploadExtra", false)) { + params.put("MANUFACTURER", Build.MANUFACTURER); + params.put("MODEL", Build.MODEL); + params.put("ANDROID_SDK", String.valueOf(Build.VERSION.SDK_INT)); + params.put("ANDROID_VERSION", Build.VERSION.RELEASE); + } + if (!sp.getBoolean("isUploadMac", true)) { + WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + String mac = wm.getConnectionInfo().getMacAddress(); + if (!TextUtils.isEmpty(mac) || !":::::".equals(mac)) { + params.put("MAC", mac); + } + } + if (!sp.getBoolean("isUploadMid", true)) { + String mid = StatConfig.getMid(context); + if (!TextUtils.isEmpty(mid) || !"0".equals(mid)) { + params.put("MTA_ID", mid); + } + } + if (params.size() != 0) { + new Thread(){ + @Override + public void run() { + RequestBody body = RequestBody.create(MediaType.parse("application/json"), + new JSONObject(params).toString()); + RetrofitManager.getUser().postDevice(TokenUtils.getToken(context), body, + TokenUtils.getDeviceId(context)) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onResponse(ResponseBody response) { + SharedPreferences.Editor editor = sp.edit(); + editor.putBoolean("isUploadExtra", true); + editor.putBoolean("isUploadMac", true); + editor.putBoolean("isUploadMid", true); + editor.apply(); + } + }); + } + }.start(); + } + } + // 获取服务器时间 public static synchronized void getTime(Context context) { final SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); @@ -268,29 +324,6 @@ public class TokenUtils { } - // 启动助手时,检查uuid - public static void checkDeviceID(Context context) { - String uuid = loadSharedPreferences(context, false); - if (uuid == null) { - // 重新获取uuid,保存 - return; - } - // 检查 - if (loadSharedPreferences(context, true) == null){ - saveSharedPreferences(context, uuid); - } - if (loadDataFile(context ,true) == null){ - saveDataFile(context, uuid); - } - String[] dirName = {"/gh-uuid", "/system", "/data"}; - for (int i = 0; i< 3; i++) { - String s = loadSDCard(dirName[i]); - if (s == null) { - svaeSDCard(uuid, dirName[i]); - } - } - } - public static synchronized String getDeviceId(Context context) { return loadSharedPreferences(context, false); } diff --git a/app/src/main/java/com/gh/common/view/CardLinearLayout.java b/app/src/main/java/com/gh/common/view/CardLinearLayout.java index 0fa329f57e..8a5b94ae7e 100644 --- a/app/src/main/java/com/gh/common/view/CardLinearLayout.java +++ b/app/src/main/java/com/gh/common/view/CardLinearLayout.java @@ -7,11 +7,10 @@ import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.widget.LinearLayout; +import com.gh.common.util.Utils; import com.gh.gamecenter.R; -/** - * Created by LGT on 2016/8/31. - */ + public class CardLinearLayout extends LinearLayout { private Drawable mLeftDrawable, mTopDrawable, mRightDrawable, mBottomDrawable, mCenterDrawable; @@ -19,7 +18,7 @@ public class CardLinearLayout extends LinearLayout { private int mLeft, mTop, mRight, mBottom; - private boolean isBottom; + private boolean isBottom, isTran; public CardLinearLayout(Context context) { this(context, null); @@ -38,32 +37,45 @@ public class CardLinearLayout extends LinearLayout { setWillNotDraw(false); isBottom = true; - mLeftDrawable = getContext().getResources().getDrawable(R.drawable.frame_left); - mTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_top); - mRightDrawable = getContext().getResources().getDrawable(R.drawable.frame_right); - mBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_bottom); - mCenterDrawable = getContext().getResources().getDrawable(R.drawable.frame_center); - - mLeftTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_top_square); - mRightTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_top_square); - mLeftBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_bottom_square); - mRightBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_bottom_square); - if (attrs != null) { TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CardLayout); mLeft = ta.getDimensionPixelSize(R.styleable.CardLayout_left, 0); mTop = ta.getDimensionPixelSize(R.styleable.CardLayout_top, 0); mRight = ta.getDimensionPixelSize(R.styleable.CardLayout_right, 0); mBottom = ta.getDimensionPixelSize(R.styleable.CardLayout_bottom, 0); + isTran = ta.getBoolean(R.styleable.CardLayout_tran, false); ta.recycle(); } setPadding(getPaddingLeft() + mLeft, getPaddingTop() + mTop, getPaddingRight() + mRight, getPaddingBottom() + mBottom); + + if (isTran) { + mLeftDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_left); + mTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_top); + mRightDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_right); + mBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_bottom); + mCenterDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_center); + + mLeftTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_left_top_square); + mRightTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_right_top_square); + mLeftBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_left_bottom_square); + mRightBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_right_bottom_square); + } else { + mLeftDrawable = getContext().getResources().getDrawable(R.drawable.frame_left); + mTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_top); + mRightDrawable = getContext().getResources().getDrawable(R.drawable.frame_right); + mBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_bottom); + mCenterDrawable = getContext().getResources().getDrawable(R.drawable.frame_center); + + mLeftTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_top_square); + mRightTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_top_square); + mLeftBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_bottom_square); + mRightBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_bottom_square); + } } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); - if (mLeft != 0 && mTop != 0 && mRight != 0 && mBottom != 0) { // 左、上、右、下 if (mLeftTopDrawable != null) { diff --git a/app/src/main/java/com/gh/common/view/CardRelativeLayout.java b/app/src/main/java/com/gh/common/view/CardRelativeLayout.java index 8bbab939fa..2815d8a321 100644 --- a/app/src/main/java/com/gh/common/view/CardRelativeLayout.java +++ b/app/src/main/java/com/gh/common/view/CardRelativeLayout.java @@ -9,16 +9,16 @@ import android.widget.RelativeLayout; import com.gh.gamecenter.R; -/** - * Created by LGT on 2016/9/9. - */ + public class CardRelativeLayout extends RelativeLayout { - private Drawable topDrawable, bottomDrawable; + private Drawable mLeftDrawable, mRightDrawable, topDrawable, bottomDrawable; private Drawable leftTopDrawable, rightTopDrawable, leftBottomDrawable, rightBottomDrawable; private int mLeft, mTop, mRight, mBottom; + private boolean isTran; + public CardRelativeLayout(Context context) { this(context, null); } @@ -34,13 +34,6 @@ public class CardRelativeLayout extends RelativeLayout { private void init(Context context, AttributeSet attrs) { setWillNotDraw(false); - topDrawable = getContext().getResources().getDrawable(R.drawable.frame_top); - bottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_bottom); - - leftTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_top_square); - rightTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_top_square); - leftBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_bottom_square); - rightBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_bottom_square); if (attrs != null) { TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CardLayout); @@ -48,13 +41,48 @@ public class CardRelativeLayout extends RelativeLayout { mTop = ta.getDimensionPixelSize(R.styleable.CardLayout_top, 0); mRight = ta.getDimensionPixelSize(R.styleable.CardLayout_right, 0); mBottom = ta.getDimensionPixelSize(R.styleable.CardLayout_bottom, 0); + isTran = ta.getBoolean(R.styleable.CardLayout_tran, false); ta.recycle(); } + + if (isTran) { + mLeftDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_left); + mRightDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_right); + topDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_top); + bottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_bottom); + + leftTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_left_top_square); + rightTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_right_top_square); + leftBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_left_bottom_square); + rightBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_right_bottom_square); + } else { + mLeftDrawable = getContext().getResources().getDrawable(R.drawable.frame_left); + mRightDrawable = getContext().getResources().getDrawable(R.drawable.frame_right); + topDrawable = getContext().getResources().getDrawable(R.drawable.frame_top); + bottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_bottom); + + leftTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_top_square); + rightTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_top_square); + leftBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_bottom_square); + rightBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_bottom_square); + } } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); + if (mLeft != 0) { + if (mLeftDrawable != null) { + mLeftDrawable.setBounds(0, mTop, mLeft, getHeight() - mBottom); + mLeftDrawable.draw(canvas); + } + } + if (mRight != 0) { + if (mRightDrawable != null) { + mRightDrawable.setBounds(getWidth() - mRight, mTop, getWidth(), getHeight() - mBottom); + mRightDrawable.draw(canvas); + } + } if (mTop != 0) { if (leftBottomDrawable != null) { leftBottomDrawable.setBounds(0, 0, mLeft, mTop); diff --git a/app/src/main/java/com/gh/common/view/DownloadDialog.java b/app/src/main/java/com/gh/common/view/DownloadDialog.java index 25e51ea562..a081cd8492 100644 --- a/app/src/main/java/com/gh/common/view/DownloadDialog.java +++ b/app/src/main/java/com/gh/common/view/DownloadDialog.java @@ -198,26 +198,26 @@ public class DownloadDialog implements OnCollectionCallBackListener { ConcurrentHashMap hashMap = new ConcurrentHashMap<>(); boolean isCollection; - for (int i = 0, size = gameApk.size(); i < size; i++) { + for (ApkEntity apkEntity : gameApk) { isCollection = false; for (GameCollectionEntity gameCollectionEntity : gameEntity.getCollection()) { for (String packageName : gameCollectionEntity.getPackage()) { - if (packageName.equals(gameApk.get(i).getPackageName())){ + if (packageName.equals(apkEntity.getPackageName())){ isCollection = true; if (hashMap.get(gameCollectionEntity.getName()) != null) { gameCollectionApk.get(hashMap.get(gameCollectionEntity.getName())) - .getApkCollection().getSaveApkEntity().add(gameApk.get(i)); + .getApkCollection().getSaveApkEntity().add(apkEntity); } else { - ApkEntity apkEntity = new ApkEntity(); + ApkEntity newApkEntity = new ApkEntity(); GameCollectionEntity collectionEntity = new GameCollectionEntity(); List saveApkList = new ArrayList<>(); - saveApkList.add(gameApk.get(i)); + saveApkList.add(apkEntity); collectionEntity.setSaveApkEntity(saveApkList); collectionEntity.setName(gameCollectionEntity.getName()); collectionEntity.setIcon(gameCollectionEntity.getIcon()); collectionEntity.setColor(gameCollectionEntity.getColor()); - apkEntity.setApkCollection(collectionEntity); - gameCollectionApk.add(apkEntity); + newApkEntity.setApkCollection(collectionEntity); + gameCollectionApk.add(newApkEntity); hashMap.put(gameCollectionEntity.getName(), gameCollectionApk.size() - 1); } @@ -225,7 +225,7 @@ public class DownloadDialog implements OnCollectionCallBackListener { } } if (!isCollection) { - gameCollectionApk.add(gameApk.get(i)); + gameCollectionApk.add(apkEntity); } } diff --git a/app/src/main/java/com/gh/download/DownloadManager.java b/app/src/main/java/com/gh/download/DownloadManager.java index 23ca427881..27aa895c1d 100644 --- a/app/src/main/java/com/gh/download/DownloadManager.java +++ b/app/src/main/java/com/gh/download/DownloadManager.java @@ -8,6 +8,7 @@ import android.support.v4.util.ArrayMap; import android.widget.Toast; import com.gh.common.constant.Constants; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.FileUtils; import com.gh.common.util.MD5Utils; import com.gh.common.util.Utils; @@ -241,6 +242,8 @@ public class DownloadManager { } downloadEntity.setPlugin(gameEntity.getTag() != null && gameEntity.getTag().size() != 0); DownloadManager.getInstance(context.getApplicationContext()).add(downloadEntity); + // 收集下载数据 + DataCollectionUtils.uploadDownload(context, downloadEntity, "开始"); } /** diff --git a/app/src/main/java/com/gh/gamecenter/ConcernActivity.java b/app/src/main/java/com/gh/gamecenter/ConcernActivity.java index f7b9ffd4af..c63f36c145 100644 --- a/app/src/main/java/com/gh/gamecenter/ConcernActivity.java +++ b/app/src/main/java/com/gh/gamecenter/ConcernActivity.java @@ -144,9 +144,9 @@ public class ConcernActivity extends BaseActivity implements OnClickListener { } } else { concernRecommendAdapter.getRecommendGameList().clear(); - for (int i = 0, size = concernRecommendAdapter.getGameList().size(); i < size; i++) { - if (!concernManager.isConcern(concernRecommendAdapter.getGameList().get(i).getId())) { - concernRecommendAdapter.getRecommendGameList().add(concernRecommendAdapter.getGameList().get(i)); + for (GameEntity gameEntity : concernRecommendAdapter.getGameList()) { + if (!concernManager.isConcern(gameEntity.getId())) { + concernRecommendAdapter.getRecommendGameList().add(gameEntity); } } concernRecommendAdapter.notifyDataSetChanged(); @@ -206,11 +206,10 @@ public class ConcernActivity extends BaseActivity implements OnClickListener { @Override protected void onDestroy() { super.onDestroy(); - String uuid = TokenUtils.getDeviceId(this); JSONArray data = new JSONArray(); for (ConcernInfo concernInfo : concernManager.getConcernGame()) { data.put(concernInfo.getId()); } - ConcernUtils.updateConcernData(uuid, data); + ConcernUtils.updateConcernData(this, data); } } diff --git a/app/src/main/java/com/gh/gamecenter/DownloadManagerActivity.java b/app/src/main/java/com/gh/gamecenter/DownloadManagerActivity.java index d465a580c3..4f5d2b3bdb 100644 --- a/app/src/main/java/com/gh/gamecenter/DownloadManagerActivity.java +++ b/app/src/main/java/com/gh/gamecenter/DownloadManagerActivity.java @@ -88,6 +88,9 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements currentItem = savedInstanceState.getInt("CurrentItem"); } else { currentItem = getIntent().getIntExtra("currentItem", -1); + if (getIntent().getBundleExtra("data") != null) { + currentItem = getIntent().getBundleExtra("data").getInt("currentItem", -1); + } } if (currentItem == -1) { if (updateSize != 0 && downloadSize == 0) { diff --git a/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java b/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java index 13af42504e..a4a379d52b 100644 --- a/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java @@ -9,13 +9,13 @@ import android.widget.RelativeLayout; import com.gh.base.AppController; import com.gh.base.BaseDetailActivity; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DialogUtils; import com.gh.gamecenter.changeskin.ChangeSkinUtils; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.eventbus.EBConcernChanged; import com.gh.gamecenter.gamedetail.GameDetailAdapter; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -57,6 +57,9 @@ public class GameDetailActivity extends BaseDetailActivity implements View.OnCli isSentReport = false; gameId = getIntent().getStringExtra("gameId"); + if (getIntent().getBundleExtra("data") != null) { + gameId = getIntent().getBundleExtra("data").getString("gameId"); + } if (gameId == null) { gameEntity = (GameEntity) AppController.get("GameEntity", true); if (gameEntity != null) { @@ -129,14 +132,10 @@ public class GameDetailActivity extends BaseDetailActivity implements View.OnCli kv.put("点击", "分享"); DataUtils.onEvent(this, "插件数据", gameEntity.getName(), kv); - Map map = new HashMap<>(); - map.put("location", "分享"); - map.put("news", gameEntity.getName()); - map.put("page", "游戏详情"); - DataCollectionManager.onEvent(this, "click-item", map); + DataCollectionUtils.uploadClick(this, "分享", "游戏详情", gameEntity.getName()); String url = "http://www.ghzhushou.com/game/" + adapter.getGameDetailEntity().getShareCode(); - showShare(url, gameEntity.getName(), gameEntity.getIcon(), null, gameEntity.getTag(), entrance, "游戏"); + showShare(url, gameEntity.getName(), gameEntity.getIcon(), null, gameEntity.getTag()); } else if (v == actionbar_rl_back) { if (ChangeSkinUtils.isChecking) { DialogUtils.showWarningDialog(GameDetailActivity.this, "退出提示", @@ -209,12 +208,7 @@ public class GameDetailActivity extends BaseDetailActivity implements View.OnCli DataUtils.onEvent(this, "插件数据", gameEntity.getName(), kv); if (seconds > 0) { - Map map = new HashMap<>(); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - map.put("time", seconds); - map.put("from", entrance); - DataCollectionManager.onEvent(this, "game", map); + DataCollectionUtils.uploadGame(this, gameEntity, seconds, entrance); } } diff --git a/app/src/main/java/com/gh/gamecenter/MainActivity.java b/app/src/main/java/com/gh/gamecenter/MainActivity.java index 99fc99dc48..8cc85c2973 100644 --- a/app/src/main/java/com/gh/gamecenter/MainActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MainActivity.java @@ -1,6 +1,5 @@ package com.gh.gamecenter; -import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -14,6 +13,7 @@ import android.os.SystemClock; import android.provider.Settings; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; +import android.support.v4.util.ArrayMap; import android.text.Html; import android.text.Spanned; import android.text.TextUtils; @@ -21,29 +21,24 @@ import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; -import android.view.Window; import android.widget.FrameLayout; import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.ProgressBar; import android.widget.TextView; import com.gh.base.BaseFragmentActivity; import com.gh.common.constant.Config; +import com.gh.common.util.DataCollectionUtils; +import com.gh.common.util.DataLogUtils; import com.gh.common.util.DataUtils; -import com.gh.common.util.DeviceUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.FileUtils; +import com.gh.common.util.GameUtils; import com.gh.common.util.GiftUtils; -import com.gh.common.util.MD5Utils; -import com.gh.common.util.NetworkUtils; import com.gh.common.util.PackageUtils; import com.gh.common.util.PlatformUtils; import com.gh.common.util.RandomUtils; -import com.gh.common.util.SpeedUtils; import com.gh.common.util.TokenUtils; import com.gh.common.util.TrafficUtils; -import com.gh.common.util.Utils; import com.gh.download.DataWatcher; import com.gh.download.DownloadEntity; import com.gh.download.DownloadManager; @@ -52,7 +47,6 @@ import com.gh.gamecenter.db.GiftDao; import com.gh.gamecenter.db.info.ConcernInfo; import com.gh.gamecenter.db.info.GameInfo; import com.gh.gamecenter.entity.ApkEntity; -import com.gh.gamecenter.entity.AppEntity; import com.gh.gamecenter.entity.GameDigestEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.GameUpdateEntity; @@ -62,31 +56,30 @@ import com.gh.gamecenter.eventbus.EBShowDialog; import com.gh.gamecenter.eventbus.EBSkip; import com.gh.gamecenter.eventbus.EBUISwitch; import com.gh.gamecenter.game.GameFragment; -import com.gh.gamecenter.game.NewGameFragment; 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.UpdateManager; import com.gh.gamecenter.news.NewsFragment; import com.gh.gamecenter.personal.PersonalFragment; import com.gh.gamecenter.retrofit.JSONObjectResponse; +import com.gh.gamecenter.retrofit.ObservableUtil; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.io.File; import java.io.IOException; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map; +import java.util.concurrent.CountDownLatch; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -96,32 +89,24 @@ import okhttp3.RequestBody; import okhttp3.ResponseBody; import rx.Observable; import rx.android.schedulers.AndroidSchedulers; +import rx.functions.Action1; import rx.schedulers.Schedulers; /** - * - * @author 温冠超 - * @email 294299195@qq.com - * @update 2015-8-11 - * @des 项目的主Activity,3个Fragment都嵌入在这里。 + * 项目的主Activity,3个Fragment都嵌入在这里。 */ public class MainActivity extends BaseFragmentActivity implements OnClickListener { - private GameFragment gameFragment; private NewsFragment newsFragment; private PersonalFragment personalFragment; - private NewGameFragment newGameFragment; - private LinearLayout home1Layout; - private LinearLayout home2Layout; - private LinearLayout home3Layout; - private ImageView home1Image; - private ImageView home2Image; - private ImageView home3Image; - private TextView home1Title; - private TextView home2Title; - private TextView home3Title; + private GameFragment gameFragment; + private ImageView ivGame; + private ImageView ivNews; + private ImageView ivPersonal; + private TextView tvGame; + private TextView tvNews; + private TextView tvPersonal; - private AppEntity appEntity; private SharedPreferences sp; private ConcernManager concernManager; @@ -129,7 +114,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene private int currentTab; - private boolean isShowDownload = false; private boolean isNewFirstLaunch; private boolean isSkipped; @@ -153,19 +137,13 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene } else if (DownloadStatus.neterror.equals(downloadEntity.getStatus()) || DownloadStatus.timeout.equals(downloadEntity.getStatus())) { toast("网络不稳定,下载任务已暂停"); - uploadNeterrorLog(downloadEntity); - } - if (downloadEntity.getName().contains("光环助手") && isShowDownload) { - processGhAssistDownload(downloadEntity); + DataLogUtils.uploadNeterrorLog(MainActivity.this, downloadEntity); } if (DownloadStatus.done.equals(downloadEntity.getStatus())) { if (downloadEntity.getName().contains("光环助手")) { DataUtils.onEvent(MainActivity.this, "软件更新", "下载完成"); startActivity(PackageUtils.getInstallIntent(downloadEntity.getPath())); - uploadUpgradeLog("install");//上传更新安装数据 - if (appEntity != null && appEntity.isForce()) { - finish(); - } + DataLogUtils.uploadUpgradeLog(MainActivity.this, "install"); //上传更新安装数据 } else { statDoneEvent(downloadEntity); @@ -245,27 +223,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene DataUtils.onEvent(MainActivity.this, "插件化", downloadEntity.getName(), kv3); } - Map map = new HashMap<>(); - map.put("game", downloadEntity.getName()); - map.put("game_id", downloadEntity.getGameId()); - if (downloadEntity.isPluggable()) { - map.put("method", "插件化"); - map.put("btn_status", "插件化"); - } else if (downloadEntity.isUpdate()) { - map.put("method", "更新"); - map.put("btn_status", "更新"); - } else { - map.put("method", "正常"); - map.put("btn_status", "下载"); - } - map.put("platform", PlatformUtils.getInstance(getApplicationContext()) - .getPlatformName(downloadEntity.getPlatform())); - map.put("status", "完成"); - map.put("entrance", downloadEntity.getEntrance()); - map.put("location", downloadEntity.getLocation()); - map.put("installed", downloadEntity.getInstalled()); - map.put("network", NetworkUtils.getConnectedType(MainActivity.this)); - DataCollectionManager.onEvent(MainActivity.this, "download", map); + DataCollectionUtils.uploadDownload(this, downloadEntity, "完成"); if (downloadEntity.getEntrance().matches("^" + "\\(游戏\\-插件:滚动图\\[.+\\]\\)" + "$")) { // 首页轮播图数据统计 @@ -281,31 +239,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene entrance = entrance.substring(start + 1, end); String[] values = entrance.split("="); if (values.length == 3) { - Map map = new HashMap<>(); - map.put("location", values[2]); - map.put("type", values[1]); - map.put("title", values[0]); - map.put("form", "download"); - - String version = PackageUtils.getVersion(this); - String user = DeviceUtils.getDeviceID(this); - String channel = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"); - map.put("version", version); - map.put("user", user); - map.put("device_id", TokenUtils.getDeviceId(this)); - map.put("channel", channel); - Map params = new HashMap<>(); - params.put("topic", "lunbotu"); - params.put("source", "GH-ASSIST-Client"); - params.put("time", String.valueOf(Utils.getTime(this))); - params.put("content", new JSONObject(map).toString()); - - RequestBody body = RequestBody.create(MediaType.parse("application/json"), - new JSONObject(params).toString()); - RetrofitManager.getData().postLog(body) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response()); + DataLogUtils.uploadLunbotuLog(this, values[1], values[0], values[2]); } } } @@ -317,68 +251,9 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene // 弹出提示框 EventBus.getDefault().post(new EBShowDialog("hijack")); // 记录链接被劫持 - Map map = new HashMap<>(); - map.put("url", downloadEntity.getUrl()); - map.put("game", downloadEntity.getName()); - map.put("game_id", downloadEntity.getGameId()); - map.put("platform", downloadEntity.getPlatform()); - map.put("hijack_url", downloadEntity.getError()); - DataCollectionManager.onEvent(MainActivity.this, "hijack", map); + DataCollectionUtils.uploadHijack(this, downloadEntity); // 上传劫持log - uploadHijackLog(new HashMap<>(map)); - } - - private void uploadHijackLog(Map map) { - String version = PackageUtils.getVersion(this); - String user = DeviceUtils.getDeviceID(this); - String channel = (String) PackageUtils.getMetaData(this, - getPackageName(), "TD_CHANNEL_ID"); - map.put("version", version); - map.put("user", user); - map.put("device_id", TokenUtils.getDeviceId(this)); - map.put("channel", channel); - Map params = new HashMap<>(); - params.put("topic", "hijack"); - params.put("source", "GH-ASSIST-Client"); - params.put("time", String.valueOf(Utils.getTime(this))); - params.put("content", new JSONObject(map).toString()); - - RequestBody body = RequestBody.create(MediaType.parse("application/json"), - new JSONObject(params).toString()); - RetrofitManager.getData().postLog(body) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response()); - } - - // 上传网络错误log - private void uploadNeterrorLog(DownloadEntity downloadEntity) { - String version = PackageUtils.getVersion(this); - String user = DeviceUtils.getDeviceID(this); - String channel = (String) PackageUtils.getMetaData(this, - getPackageName(), "TD_CHANNEL_ID"); - Map map = new HashMap<>(); - map.put("url", downloadEntity.getUrl()); - map.put("game", downloadEntity.getName()); - map.put("game_id", downloadEntity.getGameId()); - map.put("platform", downloadEntity.getPlatform()); - map.put("version", version); - map.put("user", user); - map.put("device_id", TokenUtils.getDeviceId(this)); - map.put("channel", channel); - map.put("error", downloadEntity.getError()); - Map params = new HashMap<>(); - params.put("topic", "neterror"); - params.put("source", "GH-ASSIST-Client"); - params.put("time", String.valueOf(Utils.getTime(this))); - params.put("content", new JSONObject(map).toString()); - - RequestBody body = RequestBody.create(MediaType.parse("application/json"), - new JSONObject(params).toString()); - RetrofitManager.getData().postLog(body) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response()); + DataLogUtils.uploadHijack(this, downloadEntity); } /* @@ -467,7 +342,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene setContentView(contentView); sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); - isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersion(getApplicationContext()), true); + isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(getApplicationContext()), true); isSkipped = false; @@ -488,12 +363,11 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene if (!isNewFirstLaunch && sp.getBoolean("autoupdate", true)) { // 检查助手更新 - checkUpdate(); + UpdateManager.getInstance(this).checkUpdate(true); } if (isNewFirstLaunch) { - initCunHaoXiang(); getPluginUpdate(); -// sp.edit().putBoolean("isNewFirstLaunchV" + PackageUtils.getVersion(getApplicationContext()), false).apply(); +// sp.edit().putBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(getApplicationContext()), false).apply(); } // 获取免责声明 @@ -514,94 +388,139 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene public void run() { // 注册设备 TokenUtils.register(MainActivity.this); + TokenUtils.getToken(MainActivity.this, false); + TokenUtils.checkDeviceInfo(MainActivity.this); initConcern(); // 初始化关注 + GiftUtils.getCunHaoXiang(MainActivity.this); } }.start(); } + // 更新用户使用的助手信息 + updateUserGhzs(); + // 执行跳转事件 - handler.postDelayed(runnable, 500); + handler.postDelayed(skipRun, 500); Log.e("TD_CHANNEL_ID", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID")); } - private void initCunHaoXiang() { - GiftDao giftDao = new GiftDao(this); - GiftUtils.getCunHaoXiang(this, giftDao); + private void updateUserGhzs() { + String version_code = sp.getString("version_code", null); + String version_name = sp.getString("version_name", null); + String channel = sp.getString("channel", null); + + final String versionCode = PackageUtils.getVersionCode(MainActivity.this); + final String versionName = PackageUtils.getVersionName(MainActivity.this); + final String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(MainActivity.this, getPackageName(), "TD_CHANNEL_ID"); + if ((TextUtils.isEmpty(version_code) || TextUtils.isEmpty(version_name) || TextUtils.isEmpty(channel)) + || (!version_code.equals(versionCode) || !version_name.equals(versionName) || !channel.equals(TD_CHANNEL_ID))) { + new Thread(){ + @Override + public void run() { + Map params = new ArrayMap<>(); + params.put("version_code", versionCode); + params.put("version_name", versionName); + params.put("channel", TD_CHANNEL_ID); + + RequestBody body = RequestBody.create(MediaType.parse("application/json"), + new JSONObject(params).toString()); + RetrofitManager.getUser().postGhzs(TokenUtils.getToken(MainActivity.this), body) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onResponse(ResponseBody response) { + SharedPreferences.Editor editor = sp.edit(); + editor.putString("version_code", versionCode); + editor.putString("version_name", versionName); + editor.putString("channel", TD_CHANNEL_ID); + editor.apply(); + } + }); + } + }.start(); + } } // 初始化关注 private void initConcern() { - RetrofitManager.getApi().getConcern(TokenUtils.getDeviceId(MainActivity.this)) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response>() { - @Override - public void onResponse(List response) { - getConcernDigest(response); - } - }); - } - - private int initConcernCount; - - private void addInitConcernCount() { - synchronized (MainActivity.class) { - initConcernCount++; + String versionName = PackageUtils.getVersionName(MainActivity.this); + if ("2.3".equals(versionName) && !sp.getBoolean("isSwitchConcern", false)) { + // 针对助手2.3版本关注数据的迁移 + RetrofitManager.getApi().getConcern(TokenUtils.getDeviceId(MainActivity.this)) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response>() { + @Override + public void onResponse(List response) { + if (response.size() != 0) { + RequestBody body = RequestBody.create(MediaType.parse("application/json"), + new JSONArray(response).toString()); + RetrofitManager.getUser().putConcern(TokenUtils.getToken(MainActivity.this), body) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response()); + } + sp.edit().putBoolean("isSwitchConcern", true).apply(); + getConcernDigest(response); + } + }); + } else { + new Thread(){ + @Override + public void run() { + RetrofitManager.getUser().getConcern(TokenUtils.getToken(MainActivity.this)) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response>() { + @Override + public void onResponse(List response) { + getConcernDigest(response); + } + }); + } + }.start(); } } private void getConcernDigest(final List arrGameId) { final ArrayList concernDigest = new ArrayList<>(); - final int size = arrGameId.size(); - - if (size == 0) { + if (arrGameId.size() == 0) { EventBus.getDefault().post(new EBUISwitch("NewsFragment", -2)); // 没有关注 } - initConcernCount = 0; + List> list = new ArrayList<>(); for (String gameId : arrGameId) { - RetrofitManager.getApi().getGameDigest(gameId) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(GameEntity response) { - concernDigest.add(response); - addInitConcernCount(); - if (size == initConcernCount && concernDigest.size() != 0) { - concernManager.addByList(concernDigest); - Utils.log("初始化关注成功=="); - } - } - - @Override - public void onFailure(Throwable e) { - addInitConcernCount(); - if (size == initConcernCount && concernDigest.size() != 0) { - concernManager.addByList(concernDigest); - Utils.log("初始化关注--有一个以上的游戏无法添加"); - } - } - }); + list.add(RetrofitManager.getApi().getGameDigest(gameId)); } + Observable.merge(list) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onNext(GameEntity response) { + concernDigest.add(response); + } + @Override + public void onCompleted() { + concernManager.addByList(concernDigest); + } + }); } private void initViews() { - home1Layout = (LinearLayout) findViewById(R.id.main_ll_game); - home2Layout = (LinearLayout) findViewById(R.id.main_ll_news); - home3Layout = (LinearLayout) findViewById(R.id.main_ll_personal); - home1Image = (ImageView) findViewById(R.id.main_iv_game); - home2Image = (ImageView) findViewById(R.id.main_iv_news); - home3Image = (ImageView) findViewById(R.id.main_iv_personal); - home1Title = (TextView) findViewById(R.id.main_tv_game); - home2Title = (TextView) findViewById(R.id.main_tv_news); - home3Title = (TextView) findViewById(R.id.main_tv_personal); - home1Layout.setOnClickListener(this); - home2Layout.setOnClickListener(this); - home3Layout.setOnClickListener(this); + findViewById(R.id.main_ll_game).setOnClickListener(this); + findViewById(R.id.main_ll_news).setOnClickListener(this); + findViewById(R.id.main_ll_personal).setOnClickListener(this); + ivGame = (ImageView) findViewById(R.id.main_iv_game); + ivNews = (ImageView) findViewById(R.id.main_iv_news); + ivPersonal = (ImageView) findViewById(R.id.main_iv_personal); + tvGame = (TextView) findViewById(R.id.main_tv_game); + tvNews = (TextView) findViewById(R.id.main_tv_news); + tvPersonal = (TextView) findViewById(R.id.main_tv_personal); } private void checkPermission() { @@ -627,14 +546,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene } } - private int iCount; - - private void addInstalledCount() { - synchronized (MainActivity.class) { - iCount++; - } - } - // 获取已安装游戏 private void getInstalledListFromServer() { ArrayList list = PackageUtils.getAllPackageName(getApplicationContext()); @@ -652,9 +563,14 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene PackageManager.init(list); - final int size = list.size(); - iCount = 0; - for (int i = 0; i < size; i++) { + final CountDownLatch latch = ObservableUtil.latch(list.size(), new Action1() { + @Override + public void call(Object o) { + updateConcern(); + } + }); + + for (int i = 0, size = list.size(); i < size; i++) { final String packageName = list.get(i); RetrofitManager.getApi().getGameDigestByPackageName(packageName) .subscribeOn(Schedulers.io()) @@ -670,31 +586,17 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene concernManager.updateByEntity(gameInfo); } - addInstalledCount(); - if (iCount == size) { - updateConcern(); - } + latch.countDown(); } @Override public void onFailure(Throwable e) { - addInstalledCount(); - if (iCount == size) { - updateConcern(); - } + latch.countDown(); } }); } } - private int cCount; - - private void addConcernCount() { - synchronized (MainActivity.class) { - cCount++; - } - } - private void updateConcern() { ArrayList concernIdList = new ArrayList<>(); for (ConcernInfo entity : concernManager.getAllConcern()) { @@ -703,48 +605,37 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene if (concernIdList.isEmpty()) { update(); } else { - final int size = concernIdList.size(); - cCount = 0; - for (int i = 0; i < size; i++) { - RetrofitManager.getApi().getGameDigest(concernIdList.get(i)) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(GameEntity response) { - ConcernInfo concernInfo = concernManager.findConcernById(response.getId()); - if (concernInfo != null && response.getApk() != null - && response.getApk().size() != 0) { - HashMap packageNames = new HashMap<>(); - String packageName; - for (int i = 0, size = response.getApk().size(); i < size; i++) { - packageName = response.getApk().get(i).getPackageName(); - if (PackageManager.isInstalled(packageName)) { - packageNames.put(packageName, true); - } else { - packageNames.put(packageName, false); - } - } - concernInfo.setTime(System.currentTimeMillis()); - concernInfo.setPackageNames(packageNames); - concernManager.updateByConcern(concernInfo); - } - - addConcernCount(); - if (cCount == size) { - update(); - } - } - - @Override - public void onFailure(Throwable e) { - addConcernCount(); - if (cCount == size) { - update(); - } - } - }); + List> sequences = new ArrayList<>(); + for (String id : concernIdList) { + sequences.add(RetrofitManager.getApi().getGameDigest(id)); } + Observable.merge(sequences) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onNext(GameEntity response) { + ConcernInfo concernInfo = concernManager.findConcernById(response.getId()); + if (concernInfo != null && response.getApk() != null && response.getApk().size() != 0) { + HashMap packageNames = new HashMap<>(); + for (ApkEntity apkEntity : response.getApk()) { + if (PackageManager.isInstalled(apkEntity.getPackageName())) { + packageNames.put(apkEntity.getPackageName(), true); + } else { + packageNames.put(apkEntity.getPackageName(), false); + } + } + concernInfo.setTime(System.currentTimeMillis()); + concernInfo.setPackageNames(packageNames); + concernManager.updateByConcern(concernInfo); + } + } + + @Override + public void onCompleted() { + update(); + } + }); } } @@ -758,6 +649,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene new Thread(){ @Override public void run() { + final List installed = new ArrayList<>(); TrafficUtils spy = TrafficUtils.getInstance(getApplicationContext(), true); List concernList = concernManager.getAllConcern(); for (ConcernInfo concernEntity : concernList) { @@ -768,6 +660,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene if (PackageManager.isInstalled(packageName)) { quantity++; packageNames.put(packageName, true); + installed.add(packageName); } else { packageNames.put(packageName, false); } @@ -803,21 +696,23 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene } } + // 更新用户已安装游戏 + new Thread(){ + @Override + public void run() { + RequestBody body = RequestBody.create(MediaType.parse("application/json"), + new JSONArray(installed).toString()); + RetrofitManager.getUser().putPackage(TokenUtils.getToken(MainActivity.this), body) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response()); + } + }.start(); + handler.postDelayed(new Runnable() { @Override public void run() { - ArrayList concernList = new ArrayList<>(); - for (ConcernInfo entity : concernManager.getAllConcern()) { - if (entity.isConcern()) { - concernList.add(entity.getGameName()); - } - } - Map map = new HashMap<>(); - map.put("type", Build.MODEL); - map.put("system", Build.VERSION.SDK_INT + "=" + Build.VERSION.RELEASE); - map.put("install", PackageManager.getInstalledList()); - map.put("concern", concernList); - DataCollectionManager.upsert(MainActivity.this, "user", map); + DataCollectionUtils.uploadUser(MainActivity.this); } }, 1000); @@ -876,43 +771,26 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene }); } - private int count; - - private void addCount() { - synchronized (MainActivity.class) { - count++; - } - } - private void checkGamePlugin() { - List infos = concernManager.getInstalledGame(); - final int size = infos.size(); final List list = new ArrayList<>(); - count = 0; - for (ConcernInfo info : infos) { - RetrofitManager.getApi().getGameDigest(info.getId()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(GameEntity response) { - list.add(response); - - addCount(); - if (count == size) { - processPluginData(list); - } - } - - @Override - public void onFailure(Throwable e) { - addCount(); - if (count == size) { - processPluginData(list); - } - } - }); + List> sequences = new ArrayList<>(); + for (ConcernInfo info : concernManager.getInstalledGame()) { + sequences.add(RetrofitManager.getApi().getGameDigest(info.getId())); } + Observable.merge(sequences) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onNext(GameEntity response) { + list.add(response); + } + + @Override + public void onCompleted() { + processPluginData(list); + } + }); } private void processPluginData(List list) { @@ -921,10 +799,8 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene } List infos = concernManager.getInstalledGame(); HashMap map; - GameEntity gameEntity; for (ConcernInfo info : infos) { - for (int i = 0, size = list.size(); i < size; i++) { - gameEntity = list.get(i); + for (GameEntity gameEntity : list) { if (gameEntity.getId().equals(info.getId()) && gameEntity.getTag() != null && gameEntity.getTag().size() != 0 && gameEntity.getApk() != null) { @@ -935,7 +811,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene if (apkEntity.getPackageName().equals(key) && !TextUtils.isEmpty(apkEntity.getGhVersion()) && !PackageUtils.isSignature(this, apkEntity.getPackageName())) { - PackageManager.addUpdate(getGameUpdateEntity(gameEntity, apkEntity)); + PackageManager.addUpdate(GameUtils.getGameUpdateEntity(gameEntity, apkEntity)); break; } } @@ -950,24 +826,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene EventBus.getDefault().post(new EBDownloadStatus("plugin")); } - private GameUpdateEntity getGameUpdateEntity(GameEntity gameEntity, ApkEntity apkEntity) { - GameUpdateEntity gameUpdateEntity = new GameUpdateEntity(); - gameUpdateEntity.setId(gameEntity.getId()); - gameUpdateEntity.setIcon(gameEntity.getIcon()); - gameUpdateEntity.setName(gameEntity.getName()); - gameUpdateEntity.setPackageName(apkEntity.getPackageName()); - gameUpdateEntity.setSize(apkEntity.getSize()); - gameUpdateEntity.setVersion(apkEntity.getVersion()); - gameUpdateEntity.setGhVersion(apkEntity.getGhVersion()); - gameUpdateEntity.setUrl(apkEntity.getUrl()); - gameUpdateEntity.setPlatform(apkEntity.getPlatform()); - gameUpdateEntity.setEtag(apkEntity.getEtag()); - gameUpdateEntity.setPluggable(true); - gameUpdateEntity.setTag(gameEntity.getTag()); - gameUpdateEntity.setBrief(gameEntity.getBrief()); - return gameUpdateEntity; - } - @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); @@ -1006,6 +864,37 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene }); } + Runnable skipRun = new Runnable() { + @Override + public void run() { + if (getIntent() != null && getIntent().getExtras() != null && !isSkipped) { + isSkipped = true; + String to = getIntent().getStringExtra("to"); + if(!TextUtils.isEmpty(to)){ + Class clazz = intentClass(to); + if (clazz != null) { + Intent skipIntent = new Intent(MainActivity.this, clazz); + + Bundle bundle = getIntent().getBundleExtra("data"); + if (bundle != null) { + String entrance = bundle.getString("entrance"); + if (TextUtils.isEmpty(entrance) || !entrance.startsWith("(") || !entrance.endsWith(")")) { + bundle.putString("entrance", "(插件跳转)"); + } + String packageName = bundle.getString("packageName"); + if (packageName != null) { + bundle.putInt("currentItem", 1); + } + } + + skipIntent.putExtra("data", bundle); + startActivity(skipIntent); + } + } + } + } + }; + private Class intentClass(String to) { if ("NewsActivity".equals(to)) { to = "NewsDetailActivity"; @@ -1020,87 +909,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene return null; } - Runnable runnable = new Runnable() { - @Override - public void run() { - if (getIntent() != null && getIntent().getExtras() != null - && !isSkipped) { - isSkipped = true; - String to = getIntent().getExtras().getString("to"); - if(!TextUtils.isEmpty(to)){ - Class clazz = intentClass(to); - if (clazz != null) { - Intent toIntent = new Intent(MainActivity.this, clazz); - if ("NewsActivity".equals(to) || "NewsDetailActivity".equals(to)) { - toIntent.putExtra("newsId", getIntent().getExtras().getString("newsId")); - String entrance = getIntent().getExtras().getString("entrance"); - if (TextUtils.isEmpty(entrance) || !entrance.startsWith("(") || !entrance.endsWith(")")) { - entrance = "(插件跳转)"; - } - toIntent.putExtra("entrance", entrance); - } else if("DownloadManagerActivity".equals(to)) { - String packageName = getIntent().getExtras().getString("packageName"); - if (packageName != null) { - toIntent.putExtra("packageName" , getIntent().getExtras().getString("packageName")); - toIntent.putExtra("currentItem" , 1); - } - } else if ("GameDetailsActivity".equals(to) || "GameDetailActivity".equals(to)) { - toIntent.putExtra("gameId", getIntent().getExtras().getString("gameId")); - String entrance = getIntent().getExtras().getString("entrance"); - if (TextUtils.isEmpty(entrance) || !entrance.startsWith("(") || !entrance.endsWith(")")) { - entrance = "(插件跳转)"; - } - toIntent.putExtra("entrance", entrance); - } else if ("SubjectActivity".equals(to)) { - toIntent.putExtra("id", getIntent().getExtras().getString("id")); - toIntent.putExtra("name", getIntent().getExtras().getString("name")); - toIntent.putExtra("order", getIntent().getExtras().getBoolean("order")); - } else if ("ViewImageActivity".equals(to)) { - toIntent.putExtra("urls" , getIntent().getExtras().getStringArrayList("urls")); - toIntent.putExtra("current" , getIntent().getExtras().getInt("current",0)); - toIntent.putExtra("ScaleType" , getIntent().getExtras().getString("ScaleType")); - } else if ("SubjectActivity".equals(to)) { - toIntent.putExtra("id", getIntent().getExtras().getString("id")); - toIntent.putExtra("name", getIntent().getExtras().getString("name")); - } else if ("SuggestionActivity".equals(to)) { - toIntent.putExtra("content", getIntent().getExtras().getString("content")); - } - startActivity(toIntent); - } - } else { - String from = getIntent().getStringExtra("from"); - if (!TextUtils.isEmpty(from)) { - if (from.equals("plugin")) { - Intent intent = new Intent(MainActivity.this, DownloadManagerActivity.class); - intent.putExtra("currentItem", 1); - intent.putExtra("packageName", getIntent().getStringExtra("packageName")); - startActivity(intent); - } else if (from.equals("mipush_news")) { - Intent intent = new Intent(MainActivity.this, NewsDetailActivity.class); - intent.putExtra("entrance", "(小米推送)"); - intent.putExtra("newsId", getIntent().getStringExtra("newsId")); - startActivity(intent); - } else if (from.equals("mipush_new_game")) { - Intent intent = new Intent(MainActivity.this, GameDetailActivity.class); - intent.putExtra("entrance", "(小米推送)"); - startActivity(intent); - } else if (from.equals("mipush_plugin")) { - Intent intent = new Intent(MainActivity.this, DownloadManagerActivity.class); - intent.putExtra("currentItem", 1); - intent.putExtra("isPushIntent", true); - startActivity(intent); - } else if (from.equals("plugin_install")) { - Intent intent = new Intent(MainActivity.this, DownloadManagerActivity.class); - intent.putExtra("currentItem", 0); - intent.putExtra("path", getIntent().getStringExtra("path")); - startActivity(intent); - } - } - } - } - } - }; - private void getSearchHints() { RetrofitManager.getApi().getSearchHints() .subscribeOn(Schedulers.io()) @@ -1114,8 +922,8 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene } else { searchHint = response.get(RandomUtils.nextInt(response.size())); } - if (newGameFragment != null) { - newGameFragment.setHint(searchHint); + if (gameFragment != null) { + gameFragment.setHint(searchHint); } if (newsFragment != null) { newsFragment.setHint(searchHint); @@ -1125,202 +933,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene }); } - private void checkUpdate() { - String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"); - RetrofitManager.getApi().getUpdate(PackageUtils.getVersion(getApplicationContext()), TD_CHANNEL_ID) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(AppEntity response) { - appEntity = response; - - float version = Float.valueOf(response.getVersion()); - float currentVersion = Float.valueOf(PackageUtils.getVersion(getApplicationContext())); - if (version > currentVersion) { - // 光环助手 有更新 - GameUpdateEntity game = new GameUpdateEntity(); - game.setName("光环助手V" + response.getVersion()); - game.setPackageName(getPackageName()); - game.setSize(response.getSize()); - game.setVersion(response.getVersion()); - game.setUrl(response.getUrl()); - game.setPlatform("官方版"); - game.setId("5618b86e8ab49e17088b4575"); - PackageManager.addUpdate(0, game); - - String updateMD5 = MD5Utils.getUpdateMD5(response.getUrl(), response.getContent()); - if (response.isForce()) { - // 强制更新 - showUpdateDialog(updateMD5); - } else { - // 非强制更新 - if ("EVERY_TIME_OPEN".equals(response.getAlert())) { - // 每次都提示 - showUpdateDialog(updateMD5); - } else if (!"NEVER".equals(response.getAlert())){ - // 一天提示一次 - String showUpdateTime = sp.getString("show_update_tiem", null); - SimpleDateFormat format = new SimpleDateFormat( - "yyyy-MM-dd", Locale.getDefault()); - String today = format.format(new Date()); - if (!today.equals(showUpdateTime)) { - sp.edit().putString("show_update_tiem", today).apply(); - showUpdateDialog(updateMD5); - } - } - } - } - } - }); - } - - private void showUpdateDialog(final String md5) { - uploadUpgradeLog("notice"); //上传更新通知弹窗数据 - final Dialog updateDialog = new Dialog(this); - View view = View.inflate(this, R.layout.app_update_hint_dialog, null); - - TextView content = (TextView) view.findViewById(R.id.updeta_content); - content.setText(Html.fromHtml(appEntity.getContent())); - - TextView versison = (TextView) view.findViewById(R.id.update_app_version); - versison.setText(String.format("光环助手V%s更新内容:", appEntity.getVersion())); - - TextView size = (TextView) view.findViewById(R.id.update_app_size); - size.setText(String.format("大小:%s", appEntity.getSize())); - - view.findViewById(R.id.update_cannel).setOnClickListener( - new OnClickListener() { - @Override - public void onClick(View v) { - if (appEntity.isForce()) { - finish(); - } else { - updateDialog.dismiss(); - } - } - }); - - view.findViewById(R.id.updeta_confirm).setOnClickListener( - new OnClickListener() { - @Override - public void onClick(View v) { - updateDialog.dismiss(); - String path = FileUtils.getDownloadPath(MainActivity.this, - "光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk"); - File file = new File(path); - if (file.exists() && file.length() > 0) { - uploadUpgradeLog("install");//上传更新安装数据 - startActivity(PackageUtils.getInstallIntent(path)); - } else { - DataUtils.onEvent(MainActivity.this, "软件更新", "下载开始"); - showDownloadDialog(md5); - } - } - }); - - if (appEntity.isForce()) { - updateDialog.setCanceledOnTouchOutside(false); - updateDialog.setCancelable(false); - } - updateDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); - updateDialog.setContentView(view); - updateDialog.show(); - } - - private Dialog downloadDialog; - private ProgressBar app_pb_progress; - private TextView app_tv_speed; - private TextView app_tv_percent; - - private void showDownloadDialog(String md5) { - downloadDialog = new Dialog(this); - - View view = View.inflate(this, R.layout.app_updating_dialog, null); - - app_pb_progress = (ProgressBar) view.findViewById(R.id.app_pb_progress); - app_tv_speed = (TextView) view.findViewById(R.id.app_tv_speed); - app_tv_percent = (TextView) view.findViewById(R.id.app_tv_percent); - - view.findViewById(R.id.app_tv_cancel).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - DownloadManager.getInstance(getApplicationContext()).cancel(appEntity.getUrl()); - if (appEntity.isForce()) { - finish(); - } else { - downloadDialog.dismiss(); - isShowDownload = false; - } - } - }); - - downloadDialog.setCanceledOnTouchOutside(false); - downloadDialog.setCancelable(false); - downloadDialog.closeOptionsMenu(); - downloadDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); - downloadDialog.setContentView(view); - downloadDialog.show(); - - isShowDownload = true; - - String path = FileUtils.getDownloadPath(MainActivity.this, - "光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk"); - File file = new File(path); - if (file.exists()) { - file.delete(); - } - - DownloadEntity downloadEntity = new DownloadEntity(); - downloadEntity.setUrl(appEntity.getUrl()); - downloadEntity.setName("光环助手V" + appEntity.getVersion()); - downloadEntity.setPath(path); - downloadEntity.setPlatform("官方版"); - downloadEntity.setPackageName(getPackageName()); - DownloadManager.getInstance(getApplicationContext()).cancel(downloadEntity.getUrl(), false); - DownloadManager.getInstance(getApplicationContext()).pauseAll(); - DownloadManager.getInstance(getApplicationContext()).add(downloadEntity); - } - - private void processGhAssistDownload(DownloadEntity downloadEntity) { - app_tv_speed.setText(String.format("%s(剩%s)", SpeedUtils.getSpeed(downloadEntity.getSpeed()), - SpeedUtils.getRemainTime(downloadEntity.getSize(), - downloadEntity.getProgress(), downloadEntity.getSpeed() * 1024))); - app_pb_progress.setProgress((int) (downloadEntity.getPercent() * 10)); - app_tv_percent.setText(downloadEntity.getPercent() + "%"); - if (DownloadStatus.done.equals(downloadEntity.getStatus())) { - DownloadManager.getInstance(getApplicationContext()).cancel(downloadEntity.getUrl(), false); - if (downloadDialog != null) { - downloadDialog.dismiss(); - } - isShowDownload = false; - } - } - - private void uploadUpgradeLog(String step) { - Map map = new HashMap<>(); - String version = PackageUtils.getVersion(this); - String user = DeviceUtils.getDeviceID(this); - String channel = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"); - map.put("step", step); - map.put("version", version); - map.put("user", user); - map.put("device_id", TokenUtils.getDeviceId(this)); - map.put("channel", channel); - Map params = new HashMap<>(); - params.put("topic", "upgrade"); - params.put("source", "GH-ASSIST-Client"); - params.put("time", String.valueOf(Utils.getTime(this))); - params.put("content", new JSONObject(map).toString()); - - RequestBody body = RequestBody.create(MediaType.parse("application/json"), - new JSONObject(params).toString()); - RetrofitManager.getData().postLog(body) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response()); - } - // 获取META-INF中的plugin_update 文件,判断是否从游戏插件中下载的app,是则获取游戏id,启动游戏更新,下载该游戏 private void getPluginUpdate() { ApplicationInfo appinfo = getApplicationInfo(); @@ -1375,34 +987,34 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene hideFragments(transaction); switch (index) { case 0: - home1Image.setImageResource(R.drawable.home1_selected); - home1Title.setTextColor(getResources().getColor(R.color.theme)); - if (newGameFragment == null) { + ivGame.setImageResource(R.drawable.home1_selected); + tvGame.setTextColor(getResources().getColor(R.color.theme)); + if (gameFragment == null) { List list = getSupportFragmentManager().getFragments(); if (list != null) { for (Fragment fragment : list) { - if (fragment.getClass().equals(NewGameFragment.class)) { - newGameFragment = (NewGameFragment) fragment; - transaction.show(newGameFragment); + if (fragment.getClass().equals(GameFragment.class)) { + gameFragment = (GameFragment) fragment; + transaction.show(gameFragment); break; } } } - if (newGameFragment == null) { - newGameFragment = new NewGameFragment(); + if (gameFragment == null) { + gameFragment = new GameFragment(); if (!TextUtils.isEmpty(searchHint)) { - newGameFragment.setHint(searchHint); + gameFragment.setHint(searchHint); } - transaction.add(R.id.main_content, newGameFragment); + transaction.add(R.id.main_content, gameFragment); } } else { - transaction.show(newGameFragment); + transaction.show(gameFragment); } currentTab = 0; break; case 1: - home2Image.setImageResource(R.drawable.home2_selected); - home2Title.setTextColor(getResources().getColor(R.color.theme)); + ivNews.setImageResource(R.drawable.home2_selected); + tvNews.setTextColor(getResources().getColor(R.color.theme)); if (newsFragment == null) { List list = getSupportFragmentManager().getFragments(); if (list != null) { @@ -1427,8 +1039,8 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene currentTab = 1; break; case 2: - home3Image.setImageResource(R.drawable.home3_selected); - home3Title.setTextColor(getResources().getColor(R.color.theme)); + ivPersonal.setImageResource(R.drawable.home3_selected); + tvPersonal.setTextColor(getResources().getColor(R.color.theme)); if (personalFragment == null) { List list = getSupportFragmentManager().getFragments(); if (list != null) { @@ -1455,27 +1067,23 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene transaction.commit(); } - /** - * 清除掉所有的选中状态。 - */ + // 清除掉所有的选中状态。 private void clearSelection() { - home1Image.setImageResource(R.drawable.home1_unselected); - home2Image.setImageResource(R.drawable.home2_unselected); - home3Image.setImageResource(R.drawable.home3_unselected); - home1Title.setTextColor(getResources().getColor(R.color.title)); - home2Title.setTextColor(getResources().getColor(R.color.title)); - home3Title.setTextColor(getResources().getColor(R.color.title)); + ivGame.setImageResource(R.drawable.home1_unselected); + ivNews.setImageResource(R.drawable.home2_unselected); + ivPersonal.setImageResource(R.drawable.home3_unselected); + tvGame.setTextColor(getResources().getColor(R.color.title)); + tvNews.setTextColor(getResources().getColor(R.color.title)); + tvPersonal.setTextColor(getResources().getColor(R.color.title)); } - /** - * 将所有的Fragment都置为隐藏状态。 - */ + // 将所有的Fragment都置为隐藏状态。 private void hideFragments(FragmentTransaction transaction) { if (personalFragment != null) { transaction.hide(personalFragment); } - if (newGameFragment != null) { - transaction.hide(newGameFragment); + if (gameFragment != null) { + transaction.hide(gameFragment); } if (newsFragment != null) { transaction.hide(newsFragment); @@ -1490,8 +1098,9 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene } public void onEventMainThread(EBSkip skip) { - if ("NewGameFragment".equals(skip.getType())) { - home1Layout.performClick(); + if ("GameFragment".equals(skip.getType())) { + EventBus.getDefault().post(new EBUISwitch("MainActivity", 0)); + setTabSelection(0); EventBus.getDefault().post(new EBSkip("MainActivity", skip.getCurrentItem())); } } @@ -1568,14 +1177,37 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene checkGameUpdate(packageName); } } + // 更新已安装游戏 + new Thread(){ + @Override + public void run() { + JSONArray params = new JSONArray(); + params.put(packageName); + RequestBody body = RequestBody.create(MediaType.parse("application/json"), params.toString()); + RetrofitManager.getUser().postPackage(TokenUtils.getToken(MainActivity.this), body) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response()); + } + }.start(); } }); } - Map map = new HashMap<>(); - map.put("type", busFour.getType()); - map.put("packageName", busFour.getPackageName()); - DataCollectionManager.onEvent(this, "inorunstall", map); + if ("卸载".equals(busFour.getType())) { + // 更新已安装游戏 + new Thread(){ + @Override + public void run() { + RetrofitManager.getUser().deletePackage(TokenUtils.getToken(MainActivity.this), packageName) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response()); + } + }.start(); + } + + DataCollectionUtils.uploadInorunstall(this, busFour.getType(), busFour.getPackageName()); } private void concernGame(final String id, final String packageName) { @@ -1597,7 +1229,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene if (apkEntity.getPackageName().equals(packageName) && !TextUtils.isEmpty(apkEntity.getGhVersion()) && !PackageUtils.isSignature(getApplicationContext(), apkEntity.getPackageName())) { - PackageManager.addUpdate(getGameUpdateEntity(response, apkEntity)); + PackageManager.addUpdate(GameUtils.getGameUpdateEntity(response, apkEntity)); EventBus.getDefault().post(new EBDownloadStatus("plugin")); break; } @@ -1619,4 +1251,5 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene super.onDestroy(); DownloadManager.getInstance(this).removeObserver(dataWatcher); } + } diff --git a/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java b/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java index ec51e4c167..b409832fe2 100644 --- a/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java @@ -17,13 +17,13 @@ import android.widget.Toast; import com.gh.base.BaseDetailActivity; import com.gh.common.constant.Config; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.NewsEntity; import com.gh.gamecenter.eventbus.EBConcernChanged; import com.gh.gamecenter.eventbus.EBNetworkState; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.newsdetail.NewsDetailAdapter; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -72,6 +72,9 @@ public class NewsDetailActivity extends BaseDetailActivity implements OnClickLis detail_rv_show.setAdapter(adapter); newsId = getIntent().getStringExtra("newsId"); + if (getIntent().getBundleExtra("data") != null) { + newsId = getIntent().getBundleExtra("data").getString("newsId"); + } if (newsId == null) { String id = getIntent().getStringExtra("id"); String type = getIntent().getStringExtra("type"); @@ -265,22 +268,17 @@ public class NewsDetailActivity extends BaseDetailActivity implements OnClickLis kv.put("位置", "分享"); DataUtils.onEvent(this, "点击", "新闻详情", kv); - Map map = new HashMap<>(); - map.put("location", "分享"); - map.put("news", adapter.getNewsDetailEntity().getTitle()); - map.put("page", "新闻详情"); - DataCollectionManager.onEvent(this, "click-item", map); + DataCollectionUtils.uploadClick(this, "分享", "新闻详情", adapter.getNewsDetailEntity().getTitle()); String url = "http://www.ghzhushou.com/article/" + adapter.getNewsDetailEntity().getId() + ".html"; if (gameEntity == null){ showShare(url, adapter.getNewsDetailEntity().getTitle(), "http://image.ghzhushou.com/pic/57d604808ab49e467d8b4568.png", - adapter.getNewsDetailEntity().getTitle(), null, entrance, "新闻"); + adapter.getNewsDetailEntity().getTitle(), null); }else { showShare(url, gameEntity.getName(), gameEntity.getIcon(), - adapter.getNewsDetailEntity().getTitle(), gameEntity.getTag(), - entrance, "新闻"); + adapter.getNewsDetailEntity().getTitle(), gameEntity.getTag()); } } } else if (v == reuse_no_connection) { @@ -385,17 +383,7 @@ public class NewsDetailActivity extends BaseDetailActivity implements OnClickLis DataUtils.onEvent(NewsDetailActivity.this, "文章数据", adapter.getNewsDetailEntity().getTitle(), kv1); if (seconds > 0) { - Map map = new HashMap<>(); - map.put("title", adapter.getNewsDetailEntity().getTitle()); - map.put("type", adapter.getNewsDetailEntity().getType()); - map.put("author", adapter.getNewsDetailEntity().getAuthor()); - if (gameEntity != null) { - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - } - map.put("time", seconds); - map.put("from", entrance); - DataCollectionManager.onEvent(this, "news", map); + DataCollectionUtils.uploadNews(this, adapter.getNewsDetailEntity(), gameEntity, seconds, entrance); } } diff --git a/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java b/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java index 72afc92891..498c3fa0c3 100644 --- a/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java +++ b/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java @@ -5,8 +5,8 @@ import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; -import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; +import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -17,14 +17,16 @@ import android.widget.TextView; import android.widget.Toast; import com.gh.base.BaseActivity; +import com.gh.common.constant.Config; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.MeasureHeightLayoutManager; import com.gh.common.util.NewsUtils; +import com.gh.common.view.CardLinearLayout; import com.gh.common.view.VerticalItemDecoration; import com.gh.gamecenter.adapter.viewholder.FooterViewHolder; import com.gh.gamecenter.entity.NewsEntity; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -51,7 +53,7 @@ public class NewsSearchActivity extends BaseActivity { private EditText et_search; private LinearLayout gamedetail_news_ll_loading; private LinearLayout reuse_no_connection; - private CardView gamedetail_news_cardView; + private CardLinearLayout gamedetail_news_cardView; private MeasureHeightLayoutManager layoutManager; @@ -81,12 +83,20 @@ public class NewsSearchActivity extends BaseActivity { View view = View.inflate(this, R.layout.activity_gamedetail_news, null); init(view, gameName); + DisplayMetrics outMetrics = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(outMetrics); + + ViewGroup.LayoutParams params = gamedetail_news_cardView.getLayoutParams(); + params.height = outMetrics.heightPixels + - DisplayUtils.dip2px(this, 38 + 16 + 8 + 8) + - getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE).getInt("actionbar_height", + DisplayUtils.dip2px(getApplicationContext(), 48)) + - DisplayUtils.getInternalDimensionSize(getResources(), "status_bar_height"); + gamedetail_news_cardView.setLayoutParams(params); + newsEntities = new ArrayList<>(); searchAdapter = new NewsSearchAdapter(); - findViewById(R.id.gamedetail_news_type_ll).setVisibility(View.GONE); - findViewById(R.id.ll_search).setVisibility(View.VISIBLE); - layoutManager = new MeasureHeightLayoutManager(this); gamedetail_news_rv.setLayoutManager(layoutManager); @@ -161,11 +171,7 @@ public class NewsSearchActivity extends BaseActivity { private void loadNewsData(final int page) { DataUtils.onEvent(this, "游戏新闻搜索", searchKey); - - Map map = new HashMap<>(); - map.put("key", searchKey); - map.put("from", "游戏新闻搜索"); - DataCollectionManager.onEvent(this, "search", map); + DataCollectionUtils.uploadSearch(this, searchKey, "游戏新闻搜索"); RetrofitManager.getApi().getSearchNews(gameId, searchKey, page, 20) .map(new Func1, List>() { @@ -189,8 +195,10 @@ public class NewsSearchActivity extends BaseActivity { newsEntities.addAll(response); searchAdapter.notifyDataSetChanged(); } else { - gamedetail_news_cardView.setVisibility(View.GONE); - reuse_none_data.setVisibility(View.VISIBLE); + if (page == 1) { + gamedetail_news_cardView.setVisibility(View.GONE); + reuse_none_data.setVisibility(View.VISIBLE); + } isRemove = true; searchAdapter.notifyItemChanged(searchAdapter.getItemCount() - 1); @@ -262,12 +270,8 @@ public class NewsSearchActivity extends BaseActivity { kv.put("位置", String.valueOf(holder.getPosition() + 1)); DataUtils.onEvent(NewsSearchActivity.this, "点击", "游戏新闻搜索", kv); - Map map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", "游戏新闻搜索"); - map.put("news", newsEntity.getTitle()); - map.put("news_id", newsEntity.getId()); - DataCollectionManager.onEvent(NewsSearchActivity.this, "click-item", map); + DataCollectionUtils.uploadClick(NewsSearchActivity.this, + "列表", "游戏新闻搜索", newsEntity.getTitle()); // 统计阅读量 NewsUtils.statNewsViews(newsEntity.getId()); diff --git a/app/src/main/java/com/gh/gamecenter/SearchActivity.java b/app/src/main/java/com/gh/gamecenter/SearchActivity.java index 443a8e455f..b44939a816 100644 --- a/app/src/main/java/com/gh/gamecenter/SearchActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SearchActivity.java @@ -23,20 +23,17 @@ import android.widget.TextView.OnEditorActionListener; import com.gh.base.BaseFragmentActivity; import com.gh.common.constant.Config; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.gamecenter.db.SearchHistoryDao; import com.gh.gamecenter.eventbus.EBSearch; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.SystemBarTintManager; import com.gh.gamecenter.manager.SystemBarTintManager.SystemBarConfig; import com.gh.gamecenter.search.SearchGameDetailFragment; import com.gh.gamecenter.search.SearchGameListFragment; import com.gh.gamecenter.search.SearchHistoryFragment; -import java.util.HashMap; -import java.util.Map; - public class SearchActivity extends BaseFragmentActivity { @@ -261,11 +258,7 @@ public class SearchActivity extends BaseFragmentActivity { break; case 2: DataUtils.onEvent(SearchActivity.this, "搜索页面", searchKey); - - Map map = new HashMap<>(); - map.put("key", searchKey); - map.put("from", "搜索页面"); - DataCollectionManager.onEvent(this, "search", map); + DataCollectionUtils.uploadSearch(this, searchKey, "搜索页面"); game_detail_fragment = new SearchGameDetailFragment(); game_detail_fragment.setKey(searchKey); @@ -294,11 +287,7 @@ public class SearchActivity extends BaseFragmentActivity { public void finish() { super.finish(); DataUtils.onEvent(this, "搜索页面", searchKey); - - Map map = new HashMap<>(); - map.put("key", searchKey); - map.put("from", "搜索页面"); - DataCollectionManager.onEvent(this, "search", map); + DataCollectionUtils.uploadSearch(this, searchKey, "搜索页面"); } } diff --git a/app/src/main/java/com/gh/gamecenter/SettingActivity.java b/app/src/main/java/com/gh/gamecenter/SettingActivity.java index 92f76f4089..fcf2ede8dc 100644 --- a/app/src/main/java/com/gh/gamecenter/SettingActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SettingActivity.java @@ -8,56 +8,28 @@ import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.os.Bundle; import android.os.Handler; -import android.text.Html; import android.text.TextUtils; -import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; -import android.widget.ProgressBar; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; import android.widget.Toast; -import com.gh.base.AppController; import com.gh.base.BaseActivity; import com.gh.common.constant.Config; -import com.gh.common.util.DataUtils; -import com.gh.common.util.DeviceUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.FileUtils; -import com.gh.common.util.MD5Utils; import com.gh.common.util.PackageUtils; -import com.gh.common.util.SpeedUtils; -import com.gh.common.util.TokenUtils; -import com.gh.common.util.Utils; -import com.gh.download.DataWatcher; -import com.gh.download.DownloadEntity; -import com.gh.download.DownloadManager; -import com.gh.download.DownloadStatus; -import com.gh.gamecenter.entity.AppEntity; -import com.gh.gamecenter.entity.GameUpdateEntity; import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.eventbus.EBSkip; -import com.gh.gamecenter.manager.PackageManager; -import com.gh.gamecenter.retrofit.Response; -import com.gh.gamecenter.retrofit.RetrofitManager; +import com.gh.gamecenter.manager.UpdateManager; import com.kyleduo.switchbutton.SwitchButton; -import org.json.JSONObject; - import java.io.File; -import java.util.HashMap; -import java.util.Map; import de.greenrobot.event.EventBus; -import okhttp3.MediaType; -import okhttp3.RequestBody; -import okhttp3.ResponseBody; -import retrofit2.adapter.rxjava.HttpException; -import rx.android.schedulers.AndroidSchedulers; -import rx.schedulers.Schedulers; /** * 游戏设置页面 @@ -69,19 +41,11 @@ public class SettingActivity extends BaseActivity implements OnClickListener { private SwitchButton setting_sb_autoinstall, setting_sb_autodelete, setting_sb_deletedata, setting_sb_autoupdate, setting_sb_concerngame; - private TextView setting_tv_version, app_tv_speed, app_tv_percent, - app_btn_cancel, setting_tv_cache,setting_tv_size; - private ProgressBar app_pb_progress; + private TextView setting_tv_version, setting_tv_cache,setting_tv_size; private SharedPreferences sp; private Dialog loadingDialog = null; - private Dialog downloadDialog = null; - - private AppEntity appEntity; - - private boolean isChecking = false; - private boolean isShowDownload = false; private Handler handler = new Handler(); @@ -89,32 +53,6 @@ public class SettingActivity extends BaseActivity implements OnClickListener { private Context context = this; - private DataWatcher dataWatcher = new DataWatcher() { - @Override - public void onDataChanged(DownloadEntity downloadEntity) { - if (downloadEntity.getName().contains("光环助手") && isShowDownload) { - app_tv_speed.setText(String.format("%s(剩%s)", - SpeedUtils.getSpeed(downloadEntity.getSpeed()), - SpeedUtils.getRemainTime(downloadEntity.getSize(), downloadEntity.getProgress(), - downloadEntity.getSpeed() * 1024))); - app_pb_progress.setProgress((int) (downloadEntity.getPercent() * 10)); - app_tv_percent.setText(downloadEntity.getPercent() + "%"); - if (DownloadStatus.done.equals(downloadEntity.getStatus())) { - DownloadManager.getInstance(getApplicationContext()) - .cancel(downloadEntity.getUrl(), false); - if (appEntity != null && appEntity.isForce()) { - AppController.getInstance().finishActivity(); - } else { - if (downloadDialog != null) { - downloadDialog.dismiss(); - } - isShowDownload = false; - } - } - } - } - }; - @Override public void finish() { saveCurrentSetting(); @@ -139,8 +77,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener { findViewById(R.id.setting_cv_font_size).setOnClickListener(this); findViewById(R.id.setting_rl_concerngame).setOnClickListener(this); - setting_tv_version.setText("当前版本:V" - + PackageUtils.getVersion(getApplicationContext())); + setting_tv_version.setText(String.format("当前版本:V%s", PackageUtils.getVersionName(getApplicationContext()))); setting_tv_cache.setText(getCacheSize()); @@ -257,11 +194,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener { setting_sb_autoupdate.performClick(); break; case R.id.setting_rl_update: - loadingDialog = DialogUtils.showWaitDialog(this, "检查更新中..."); - if (!isChecking) { - isChecking = true; - checkUpdate(); - } + UpdateManager.getInstance(this).checkUpdate(false); break; case R.id.setting_rl_cache: DialogUtils.showWarningDialog(this, "清除缓存", "清空缓存后未安装的游戏可能需要重新下载,确定清空?", @@ -311,7 +244,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener { //设置正文字号 private void fontSize() { final Dialog dialog = new Dialog(this); - View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_font_size, null); + View inflate = View.inflate(this, R.layout.dialog_font_size, null); TextView tv_negative = (TextView) inflate.findViewById(R.id.font_size_negative); TextView tv_positive = (TextView) inflate.findViewById(R.id.font_size_positive); final RadioGroup radioGroup = (RadioGroup) inflate.findViewById(R.id.font_size_radiogroup); @@ -347,8 +280,8 @@ public class SettingActivity extends BaseActivity implements OnClickListener { @Override public void run() { long start = System.currentTimeMillis(); - deleteFolder(getCacheDir()); - deleteFolder(getExternalCacheDir()); + FileUtils.deleteFolder(getCacheDir()); + FileUtils.deleteFolder(getExternalCacheDir()); long time = System.currentTimeMillis() - start; if (time < 1000) { try { @@ -372,232 +305,10 @@ public class SettingActivity extends BaseActivity implements OnClickListener { }.start(); } - private void deleteFolder(File folder) { - if (folder != null) { - if (folder.isDirectory()) { - for (File file : folder.listFiles()) { - if (file.isDirectory()) { - deleteFolder(file); - } else { - file.delete(); - } - } - } - folder.delete(); - } - } - - private void checkUpdate() { - String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this, - getPackageName(), "TD_CHANNEL_ID"); - RetrofitManager.getApi().getUpdate(PackageUtils.getVersion(getApplicationContext()), TD_CHANNEL_ID) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(AppEntity response) { - isChecking = false; - if (loadingDialog != null) { - loadingDialog.dismiss(); - } - - appEntity = response; - - float version = Float.valueOf(appEntity.getVersion()); - float currentVersion = Float.valueOf(PackageUtils.getVersion(getApplicationContext())); - - if (version > currentVersion) { - // 光环助手 有更新 - GameUpdateEntity game = new GameUpdateEntity(); - game.setName("光环助手V" + appEntity.getVersion()); - game.setPackageName(getPackageName()); - game.setSize(appEntity.getSize()); - game.setVersion(appEntity.getVersion()); - game.setUrl(appEntity.getUrl()); - game.setPlatform("官方版"); - game.setId("5618b86e8ab49e17088b4575"); - PackageManager.addUpdate(0, game); - - String updateMD5 = MD5Utils.getUpdateMD5( - appEntity.getUrl(), - appEntity.getContent()); - - showUpdateDialog(updateMD5); - } else { - toast("已是最新版本"); - } - } - - @Override - public void onFailure(Throwable e) { - isChecking = false; - if (loadingDialog != null) { - loadingDialog.dismiss(); - } - - if (e instanceof HttpException) { - HttpException exception = (HttpException) e; - if (exception.code() == 304) { - toast("您的光环助手已是最新版本"); - return; - } - } - - toast("检查更新失败"); - } - }); - } - - private void showUpdateDialog(final String md5) { - uploadUpgradeLog("notice"); //上传更新通知弹窗数据 - final Dialog updateDialog = new Dialog(this); - View view = View.inflate(this, R.layout.app_update_hint_dialog, null); - - TextView content = (TextView) view.findViewById(R.id.updeta_content); - content.setText(Html.fromHtml(appEntity.getContent())); - - TextView versison = (TextView) view.findViewById(R.id.update_app_version); - versison.setText(String.format("光环助手V%s更新内容:", appEntity.getVersion())); - - TextView size = (TextView) view.findViewById(R.id.update_app_size); - size.setText(String.format("大小:%s", appEntity.getSize())); - - view.findViewById(R.id.update_cannel).setOnClickListener( - new OnClickListener() { - @Override - public void onClick(View v) { - if (appEntity.isForce()) { - AppController.getInstance().finishActivity(); - } else { - updateDialog.dismiss(); - } - } - }); - view.findViewById(R.id.updeta_confirm).setOnClickListener( - new OnClickListener() { - @Override - public void onClick(View v) { - updateDialog.dismiss(); - String path = FileUtils.getDownloadPath(SettingActivity.this, - "光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk"); - File file = new File(path); - if (file.exists() && file.length() > 0) { - uploadUpgradeLog("install");//上传更新安装数据 - startActivity(PackageUtils.getInstallIntent(path)); - } else { - DataUtils.onEvent(SettingActivity.this, "软件更新", "下载开始"); - showDownloadDialog(md5); - } - } - }); - if (appEntity.isForce()) { - updateDialog.setCanceledOnTouchOutside(false); - updateDialog.setCancelable(false); - } - updateDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); - updateDialog.setContentView(view); - updateDialog.show(); - } - - private void showDownloadDialog(String md5) { - final Dialog downloadDialog = new Dialog(SettingActivity.this); - downloadDialog.setCanceledOnTouchOutside(false); - downloadDialog.setCancelable(false); - downloadDialog.closeOptionsMenu(); - View view = View.inflate(this, R.layout.app_updating_dialog, null); - - app_pb_progress = (ProgressBar) view.findViewById(R.id.app_pb_progress); - app_tv_speed = (TextView) view.findViewById(R.id.app_tv_speed); - app_tv_percent = (TextView) view.findViewById(R.id.app_tv_percent); - app_btn_cancel = (TextView) view.findViewById(R.id.app_tv_cancel); - - app_btn_cancel.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - DownloadManager.getInstance(getApplicationContext()).cancel( - appEntity.getUrl()); - if (appEntity.isForce()) { - AppController.getInstance().finishActivity(); - } else { - downloadDialog.dismiss(); - isShowDownload = false; - } - } - }); - - downloadDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); - downloadDialog.setContentView(view); - downloadDialog.show(); - - isShowDownload = true; - - String path = FileUtils.getDownloadPath(SettingActivity.this, "光环助手V" - + appEntity.getVersion() + "_" + md5 + ".apk"); - - File file = new File(path); - - if (file.exists()) { - file.delete(); - } - - DownloadEntity downloadEntity = new DownloadEntity(); - downloadEntity.setUrl(appEntity.getUrl()); - downloadEntity.setName("光环助手V" + appEntity.getVersion()); - downloadEntity.setPath(path); - downloadEntity.setPlatform("官方版"); - downloadEntity.setPackageName(getPackageName()); - - DownloadManager.getInstance(getApplicationContext()).cancel( - downloadEntity.getUrl(), false); - - DownloadManager.getInstance(getApplicationContext()).pauseAll(); - - DownloadManager.getInstance(getApplicationContext()).add(downloadEntity); - } - - private void uploadUpgradeLog(String step) { - Map map = new HashMap<>(); - String version = PackageUtils.getVersion(this); - String user = DeviceUtils.getDeviceID(this); - String channel = (String) PackageUtils.getMetaData(this, - getPackageName(), "TD_CHANNEL_ID"); - map.put("step", step); - map.put("version", version); - map.put("user", user); - map.put("device_id", TokenUtils.getDeviceId(this)); - map.put("channel", channel); - Map params = new HashMap<>(); - params.put("topic", "upgrade"); - params.put("source", "GH-ASSIST-Client"); - params.put("time", String.valueOf(Utils.getTime(this))); - params.put("content", new JSONObject(map).toString()); - - RequestBody body = RequestBody.create(MediaType.parse("application/json"), - new JSONObject(params).toString()); - RetrofitManager.getData().postLog(body) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response()); - } - - @Override - public void onResume() { - super.onResume(); - DownloadManager.getInstance(SettingActivity.this).addObserver( - dataWatcher); - } - @Override public void onPause() { - saveCurrentSetting(); super.onPause(); - DownloadManager.getInstance(SettingActivity.this).removeObserver( - dataWatcher); + saveCurrentSetting(); } - @Override - protected void onDestroy() { - saveCurrentSetting(); - super.onDestroy(); - } } diff --git a/app/src/main/java/com/gh/gamecenter/ShareCardPicActivity.java b/app/src/main/java/com/gh/gamecenter/ShareCardPicActivity.java index 780e93000e..437069760a 100644 --- a/app/src/main/java/com/gh/gamecenter/ShareCardPicActivity.java +++ b/app/src/main/java/com/gh/gamecenter/ShareCardPicActivity.java @@ -23,6 +23,7 @@ import com.facebook.imagepipeline.image.ImageInfo; import com.gh.base.BaseActivity; import com.gh.common.util.MessageShareUtils; import com.gh.gamecenter.manager.SystemBarTintManager; +import com.gh.gamecenter.retrofit.ObservableUtil; import com.tencent.tauth.Tencent; import java.io.File; @@ -31,10 +32,12 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.List; import java.util.Vector; +import java.util.concurrent.CountDownLatch; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; +import rx.functions.Action1; /** * Created by khy on 2016/11/7. @@ -64,6 +67,8 @@ public class ShareCardPicActivity extends BaseActivity { private Bitmap shareBm; + private CountDownLatch latch; + //接收QQ或者QQ空间分享回调 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { @@ -101,6 +106,19 @@ public class ShareCardPicActivity extends BaseActivity { tintManager.setStatusBarTintResource(R.color.back); } + latch = ObservableUtil.latch(shareArrImg.size(), new Action1() { + @Override + public void call(Object o) { + ShareCardPicActivity.this.runOnUiThread(new Runnable() { + @Override + public void run() { + setContentImage(shareArrImg.get(0)); + currentImgPosition++; + } + }); + } + }); + for (int i = 0; i < shareArrImg.size(); i++) { checkUrl(shareArrImg.get(i), shareArrImg.size(), i); } @@ -185,7 +203,7 @@ public class ShareCardPicActivity extends BaseActivity { @OnClick(R.id.sharecard_chang_img) public void OnChangPicListener() { - if (currentImgPosition > shareArrImg.size() -1){ + if (currentImgPosition > shareArrImg.size() - 1) { currentImgPosition = 0; } @@ -206,29 +224,12 @@ public class ShareCardPicActivity extends BaseActivity { connection.connect(); int code = connection.getResponseCode(); if (code == 200) { - addCount(); shareArrImg.remove(position); shareArrImg.add(position, newUrl); - if (count == size) { - ShareCardPicActivity.this.runOnUiThread(new Runnable() { - @Override - public void run() { - setContentImage(shareArrImg.get(0)); - currentImgPosition++; - } - }); - } + + latch.countDown(); } else { - addCount(); - if (count == size) { - ShareCardPicActivity.this.runOnUiThread(new Runnable() { - @Override - public void run() { - setContentImage(shareArrImg.get(0)); - currentImgPosition++; - } - }); - } + latch.countDown(); } } catch (IOException e) { e.printStackTrace(); @@ -237,14 +238,6 @@ public class ShareCardPicActivity extends BaseActivity { }.start(); } - private int count; - - private void addCount() { - synchronized (ShareCardPicActivity.class) { - count++; - } - } - public static Bitmap getBitmapByView(ScrollView scrollView) { int h = 0; Bitmap bitmap = null; diff --git a/app/src/main/java/com/gh/gamecenter/SkipActivity.java b/app/src/main/java/com/gh/gamecenter/SkipActivity.java index b9a0fcb438..9bee74d002 100644 --- a/app/src/main/java/com/gh/gamecenter/SkipActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SkipActivity.java @@ -41,7 +41,11 @@ public class SkipActivity extends BaseActivity { intent.putExtra("id", id); intent.putExtra("name", getIntent().getData().getQueryParameter("name")); } else if ("suggestion".equals(host)) { - intent.putExtra("content", getIntent().getData().getQueryParameter("content")); + Uri uri = getIntent().getData(); + String content = "【" + uri.getQueryParameter("game_name") + + "-" + PlatformUtils.getInstance(this).getPlatformName(uri.getQueryParameter("platform")) + + "-V" + uri.getQueryParameter("version") + "】"; + intent.putExtra("content", content); intent.setClass(this, SuggestionActivity.class); } } else { diff --git a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java index bf7b44e0be..fe88fad53c 100644 --- a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java @@ -10,7 +10,6 @@ import android.os.Bundle; import android.os.Handler; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; -import android.text.TextUtils; import android.util.DisplayMetrics; import android.view.KeyEvent; import android.view.View; @@ -23,18 +22,16 @@ import com.gh.base.BaseActivity; import com.gh.common.constant.Config; import com.gh.common.util.FileUtils; import com.gh.common.util.PackageUtils; +import com.gh.common.util.PlatformUtils; import com.gh.common.util.TimestampUtils; import com.gh.common.util.TokenUtils; import com.gh.common.util.Utils; import com.gh.download.DownloadManager; import com.gh.download.DownloadService; -import com.gh.gamecenter.db.info.FilterInfo; -import com.gh.gamecenter.entity.PlatformEntity; import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.FilterManager; import com.gh.gamecenter.retrofit.JSONObjectResponse; -import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; import com.xiaomi.mipush.sdk.MiPushMessage; import com.xiaomi.mipush.sdk.PushMessageHelper; @@ -42,17 +39,10 @@ import com.xiaomi.mipush.sdk.PushMessageHelper; import org.json.JSONException; import org.json.JSONObject; -import java.io.BufferedReader; import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Date; -import java.util.HashSet; -import java.util.List; import java.util.Locale; -import java.util.Set; import de.greenrobot.event.EventBus; import rx.android.schedulers.AndroidSchedulers; @@ -60,16 +50,11 @@ import rx.schedulers.Schedulers; /** * 引导页面 - * - * @author 黄壮华 - * */ public class SplashScreenActivity extends BaseActivity { private SharedPreferences sp; - private String from; - private long start; private boolean isFirst; @@ -100,14 +85,12 @@ public class SplashScreenActivity extends BaseActivity { isFirst = true; sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); - isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersion(getApplicationContext()), true); - - from = getIntent().getStringExtra("from"); + isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(getApplicationContext()), true); if (isNewFirstLaunch || sp.getInt("actionbar_height", 0) != 0) { - setTheme(R.style.AppTheme_Guide); + setTheme(R.style.AppGuideTheme); } else { - setTheme(R.style.AppTheme_Fullscreen); + setTheme(R.style.AppFullScreenTheme); // 自定义ActionBar ActionBar mActionBar = getActionBar(); if (mActionBar != null) { @@ -122,20 +105,14 @@ public class SplashScreenActivity extends BaseActivity { if (isNewFirstLaunch) { setContentView(R.layout.activity_splash_intro); - ViewPager splash_viewPager = (ViewPager) findViewById(R.id.splash_viewPager); - splash_viewPager.setAdapter(new ViewPagerAdapter()); + ViewPager guideLayout = (ViewPager) findViewById(R.id.splash_intro_vp_guide); + guideLayout.setAdapter(new GuidePagerAdapter()); } else { setContentView(R.layout.activity_splash_normal); } } - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - Utils.log("flags---------------onNewIntent"); - } - - private class ViewPagerAdapter extends PagerAdapter { + private class GuidePagerAdapter extends PagerAdapter { private int[] pics = { R.drawable.splash_01 }; @@ -147,23 +124,28 @@ public class SplashScreenActivity extends BaseActivity { @Override public Object instantiateItem(ViewGroup container, int position) { if (position == pics.length - 1) { - View view = View.inflate(SplashScreenActivity.this, R.layout.splash_viewpage_item, null); - TextView textView = (TextView) view.findViewById(R.id.splash_viewPager_item_btn); + View view = View.inflate(container.getContext(), R.layout.splash_guide_item, null); + + ImageView ivImage = (ImageView) view.findViewById(R.id.splsh_guide_iv_image); + ivImage.setImageResource(pics[position]); + + TextView tvSkip = (TextView) view.findViewById(R.id.splsh_guide_tv_skip); DisplayMetrics outMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(outMetrics); - RelativeLayout.LayoutParams rparams = (RelativeLayout.LayoutParams) textView.getLayoutParams(); + RelativeLayout.LayoutParams rparams = (RelativeLayout.LayoutParams) tvSkip.getLayoutParams(); rparams.height = outMetrics.heightPixels / 4; - textView.setLayoutParams(rparams); - textView.setOnClickListener(new View.OnClickListener() { + tvSkip.setLayoutParams(rparams); + tvSkip.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { launch(); } }); + container.addView(view); return view; } else { - ImageView imageView = new ImageView(SplashScreenActivity.this); + ImageView imageView = new ImageView(container.getContext()); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setImageResource(pics[position]); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( @@ -204,38 +186,28 @@ public class SplashScreenActivity extends BaseActivity { isFirst = false; // 第一次启动,把package.txt文件内容加载进数据库 + FilterManager filterManager = null; if (!sp.getBoolean("isLoadFilter", false)) { - try { - List list = new ArrayList<>(); - BufferedReader reader = new BufferedReader( - new InputStreamReader(getAssets().open("package.txt"))); - String line; - while ((line = reader.readLine()) != null) { - list.add(new FilterInfo(line)); - } - reader.close(); - FilterManager filterManager = new FilterManager(getApplicationContext()); - filterManager.addAllFilter(list); - sp.edit().putBoolean("isLoadFilter", true).apply(); - } catch (IOException e) { - e.printStackTrace(); - } + filterManager = new FilterManager(getApplicationContext()); + filterManager.loadFilter(); } - checkGhFile(); + // 检查是否存在旧版本光环助手包 + checkOldGhFile(); - /* - * 更新过滤表,获取自动刷新的cd,获取版本对应表 - */ + // 更新过滤表,获取自动刷新的cd,获取版本对应表 String time = sp.getString("filter_time", null); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); String today = format.format(new Date()); if (!today.equals(time)) { - FilterManager manager = new FilterManager(getApplicationContext()); - manager.getFilterFromServer(today); + // 获取过滤包 + if (filterManager == null) { + filterManager = new FilterManager(getApplicationContext()); + } + filterManager.getFilterFromServer(today); // 获取版本代码、名称 - getPlatform(); + PlatformUtils.getInstance(getApplicationContext()).getPlatform(); } // 获取下载按钮状态、开启or关闭 @@ -243,14 +215,13 @@ public class SplashScreenActivity extends BaseActivity { getDownloadStatus(); } + // 获取界面设置 getUISetting(); // 更新本地时间 TokenUtils.getTime(this); - /* - * 上传数据 - */ + // 上传数据 DataCollectionManager.getInstance(getApplicationContext()).upload(); // 解决助手奔溃后导致的下载状态保留问题 @@ -283,9 +254,27 @@ public class SplashScreenActivity extends BaseActivity { } } - /* - * 获取界面设置 - */ + // 检查下载文件夹下是否有旧版本的光环助手的包,有则删除 + private void checkOldGhFile() { + File folder = new File(FileUtils.getDownloadDir(this) + File.separator); + if (folder.isDirectory()) { + for (File file : folder.listFiles()) { + if (!file.isDirectory() && file.getName().startsWith("光环助手V")) { + String name = file.getName(); + int index = name.indexOf("_"); + if (index != -1) { + float version = Float.valueOf(name.substring(name.indexOf("V") + 1, index)); + float currentVersion = Float.valueOf(PackageUtils.getVersionName(getApplicationContext())); + if (version <= currentVersion && file.delete()) { + Utils.log(file.getName() + " file delete success."); + } + } + } + } + } + } + + // 获取界面设置 private void getUISetting() { RetrofitManager.getApi().getUISetting() .subscribeOn(Schedulers.io()) @@ -311,13 +300,10 @@ public class SplashScreenActivity extends BaseActivity { }); } - /* - * 获取下载按钮显示状态 - */ + // 获取下载按钮显示状态 private void getDownloadStatus() { - String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this, - getPackageName(), "TD_CHANNEL_ID"); - RetrofitManager.getApi().getDownloadStatus(PackageUtils.getVersion(getApplicationContext()), TD_CHANNEL_ID) + String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"); + RetrofitManager.getApi().getDownloadStatus(PackageUtils.getVersionName(getApplicationContext()), TD_CHANNEL_ID) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new JSONObjectResponse() { @@ -343,103 +329,18 @@ public class SplashScreenActivity extends BaseActivity { }); } - /* - * 检查下载文件夹下是否有旧版本的光环助手的包,有则删除 - */ - private void checkGhFile() { - File folder = new File(FileUtils.getDownloadDir(this) + File.separator); - if (folder.isDirectory()) { - for (File file : folder.listFiles()) { - if (!file.isDirectory() && file.getName().startsWith("光环助手V")) { - String name = file.getName(); - int index = name.indexOf("_"); - if (index != -1) { - float version = Float.valueOf(name.substring( - name.indexOf("V") + 1, index)); - float currentVersion = Float.valueOf(PackageUtils.getVersion(getApplicationContext())); - if (version <= currentVersion) { - file.delete(); - } - } - } - } - } - } - - private void getPlatform() { - RetrofitManager.getApi().getGamePlatform() - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response>(){ - @Override - public void onResponse(List response) { - Set platformSet = new HashSet<>(); - for (PlatformEntity platformEntity : response) { - platformSet.add(platformEntity.toString()); - } - SharedPreferences sharedPreferences = getSharedPreferences("gh_platform", Context.MODE_PRIVATE); - sharedPreferences.edit().putStringSet("platform", platformSet).apply(); - } - }); - } - // 跳转到主界面 private void launch() { Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class); - Bundle bundle = getIntent().getExtras(); - if (bundle != null && bundle.getString("to") != null) { - intentControl(bundle, intent); - } else { - intent.putExtra("from", from); - if (!TextUtils.isEmpty(from)) { - if ("plugin".equals(from)) { - intent.putExtra("packageName", getIntent().getStringExtra("packageName")); - } else if ("mipush_news".equals(from)) { - intent.putExtra("newsId", getIntent().getStringExtra("newsId")); - } else if ("mipush_plugin".equals(from)) { - intent.putExtra("data", getIntent().getStringExtra("data")); - } else if ("plugin_install".equals(from)) { - intent.putExtra("path", getIntent().getStringExtra("path")); - } - } + Bundle bundle = intent.getExtras(); + if (intent.getBundleExtra("data") != null) { + bundle = intent.getBundleExtra("data"); } + intent.putExtra("data", bundle); startActivity(intent); finish(); } - private void intentControl(Bundle bundle, Intent intent) { - String to = bundle.getString("to"); - if ("NewsActivity".equals(to) || "NewsDetailActivity".equals(to)) { - intent.putExtra("newsId", bundle.getString("newsId")); - intent.putExtra("entrance", bundle.getString("entrance")); - } else if("DownloadManagerActivity".equals(to)) { - intent.putExtra("packageName", bundle.getString("packageName")); - } else if ("GameDetailsActivity".equals(to) || "GameDetailActivity".equals(to)) { - intent.putExtra("gameId", bundle.getString("gameId")); - intent.putExtra("entrance", bundle.getString("entrance")); - } else if ("SubjectActivity".equals(to)) { - intent.putExtra("id", bundle.getString("id")); - intent.putExtra("name", bundle.getString("name")); - intent.putExtra("order", bundle.getBoolean("order")); - } else if ("ViewImageActivity".equals(to)) { - intent.putExtra("urls", bundle.getStringArrayList("urls")); - intent.putExtra("current", bundle.getInt("current",0)); - intent.putExtra("ScaleType", bundle.getString("ScaleType")); - } else if ("SubjectActivity".equals(to)) { - intent.putExtra("id", bundle.getString("id")); - intent.putExtra("name", bundle.getString("name")); - } else if ("SuggestionActivity".equals(to)) { - intent.putExtra("content", bundle.getString("content")); - } - if ("NewsActivity".equals(to)) { - intent.putExtra("to", "NewsDetailActivity"); - } else if ("GameDetailsActivity".equals(to)) { - intent.putExtra("to", "GameDetailActivity"); - } else { - intent.putExtra("to", to); - } - } - } diff --git a/app/src/main/java/com/gh/gamecenter/SubjectActivity.java b/app/src/main/java/com/gh/gamecenter/SubjectActivity.java index fa744797c0..b2e23d83ef 100644 --- a/app/src/main/java/com/gh/gamecenter/SubjectActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SubjectActivity.java @@ -56,7 +56,11 @@ public class SubjectActivity extends BaseActivity { super.onCreate(savedInstanceState); View contentView = View.inflate(this, R.layout.activity_subject, null); - init(contentView, getIntent().getStringExtra("name")); + String name = getIntent().getStringExtra("name"); + if (getIntent().getBundleExtra("data") != null) { + name = getIntent().getBundleExtra("data").getString("name"); + } + init(contentView, name); reuse_no_connection.setOnClickListener(new View.OnClickListener() { @Override diff --git a/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java b/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java index a2cf2a3c59..4228f27627 100644 --- a/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java @@ -3,7 +3,6 @@ package com.gh.gamecenter; import android.app.Dialog; import android.content.Context; import android.os.Bundle; -import android.support.v7.widget.CardView; import android.telephony.TelephonyManager; import android.text.Editable; import android.text.TextUtils; @@ -18,6 +17,7 @@ import android.widget.TextView; import com.gh.base.BaseActivity; import com.gh.common.util.DialogUtils; import com.gh.common.util.PackageUtils; +import com.gh.common.view.CardLinearLayout; import com.gh.gamecenter.retrofit.JSONObjectResponse; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -44,7 +44,7 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener private TextView tv_suggest_connectway; private EditText et_suggest_content, et_suggest_connectway; - private CardView btn_suggest_post; + private CardLinearLayout btn_suggest_post; private boolean isShowing = false; @@ -87,6 +87,9 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener }); String content = getIntent().getStringExtra("content"); + if (getIntent().getBundleExtra("data") != null) { + content = getIntent().getBundleExtra("data").getString("content"); + } if (!TextUtils.isEmpty(content)) { et_suggest_content.setText(content); et_suggest_content.setSelection(et_suggest_content.getText().length()); @@ -189,7 +192,7 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener Map params = new HashMap<>(); params.put("message", et_suggest_content.getText().toString().trim()); params.put("from", email); - params.put("ghversion", PackageUtils.getVersion(this)); + params.put("ghversion", PackageUtils.getVersionName(this)); params.put("channel", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID")); params.put("type", android.os.Build.MODEL); params.put("sdk", String.valueOf(android.os.Build.VERSION.SDK_INT)); diff --git a/app/src/main/java/com/gh/gamecenter/ViewImageActivity.java b/app/src/main/java/com/gh/gamecenter/ViewImageActivity.java index 08cc354484..a669390ccc 100644 --- a/app/src/main/java/com/gh/gamecenter/ViewImageActivity.java +++ b/app/src/main/java/com/gh/gamecenter/ViewImageActivity.java @@ -1,6 +1,5 @@ package com.gh.gamecenter; -import android.content.Intent; import android.content.res.Configuration; import android.graphics.drawable.Animatable; import android.net.Uri; @@ -97,10 +96,14 @@ public class ViewImageActivity extends BaseActivity implements protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Intent intent = getIntent(); - urls = intent.getStringArrayListExtra("urls"); - int current = intent.getIntExtra("current", 0); - scaleType = intent.getStringExtra("ScaleType"); + urls = getIntent().getStringArrayListExtra("urls"); + int current = getIntent().getIntExtra("current", 0); + scaleType = getIntent().getStringExtra("ScaleType"); + if (getIntent().getBundleExtra("data") != null) { + urls = getIntent().getBundleExtra("data").getStringArrayList("urls"); + current = getIntent().getBundleExtra("data").getInt("current", 0); + scaleType = getIntent().getBundleExtra("data").getString("ScaleType"); + } if (savedInstanceState != null) { current = savedInstanceState.getInt("currentItem", 0); diff --git a/app/src/main/java/com/gh/gamecenter/adapter/ConcernAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/ConcernAdapter.java index e992764d32..8996687748 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/ConcernAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/ConcernAdapter.java @@ -7,6 +7,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Toast; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.GameUtils; @@ -17,7 +18,6 @@ import com.gh.gamecenter.db.info.ConcernInfo; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.listener.OnCallBackListener; import com.gh.gamecenter.manager.ConcernManager; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import rx.Observable; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -55,42 +56,26 @@ public class ConcernAdapter extends RecyclerView.Adapter { } } - private int cCount; - - private void addConcernCount() { - synchronized (ConcernActivity.class) { - cCount++; - } - } - private void initConcernGame() { final List result = new ArrayList<>(); - final int count = concernList.size(); - cCount = 0; - for (int i = 0; i < count; i++) { - RetrofitManager.getApi().getGameDigest(concernList.get(i).getId()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(GameEntity response) { - result.add(response); - - addConcernCount(); - if (cCount == count) { - processingConcernGame(result); - } - } - - @Override - public void onFailure(Throwable e) { - addConcernCount(); - if (cCount == count) { - processingConcernGame(result); - } - } - }); + List> sequences = new ArrayList<>(); + for (ConcernInfo concernInfo : concernList) { + sequences.add(RetrofitManager.getApi().getGameDigest(concernInfo.getId())); } + Observable.merge(sequences) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onNext(GameEntity response) { + result.add(response); + } + + @Override + public void onCompleted() { + processingConcernGame(result); + } + }); } private void processingConcernGame(List gameList) { @@ -134,11 +119,8 @@ public class ConcernAdapter extends RecyclerView.Adapter { kv.put("状态", "取消关注"); DataUtils.onEvent(context, "游戏关注", concernInfo.getGameName(), kv); - Map map = new HashMap<>(); - map.put("game", concernInfo.getGameName()); - map.put("game_id", concernInfo.getId()); - map.put("type", "取消关注"); - DataCollectionManager.onEvent(context, "concern", map); + DataCollectionUtils.uploadConcern(context, + concernInfo.getGameName(), concernInfo.getId(), "取消关注"); concernList.remove(holder.getPosition()); notifyItemRemoved(holder.getPosition()); @@ -172,12 +154,7 @@ public class ConcernAdapter extends RecyclerView.Adapter { kv.put("位置", String.valueOf(holder.getPosition() + 1)); DataUtils.onEvent(context, "点击", "我的关注-列表", kv); - Map map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", "我的关注"); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "列表", "我的关注", gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity, "(我的关注-列表)"); } diff --git a/app/src/main/java/com/gh/gamecenter/adapter/ConcernRecommendAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/ConcernRecommendAdapter.java index fb9a5aafe9..f1969ad494 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/ConcernRecommendAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/ConcernRecommendAdapter.java @@ -7,6 +7,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Toast; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.GameUtils; import com.gh.gamecenter.ConcernActivity; @@ -16,7 +17,6 @@ import com.gh.gamecenter.db.info.ConcernInfo; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.listener.OnCallBackListener; import com.gh.gamecenter.manager.ConcernManager; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import rx.Observable; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -52,45 +53,28 @@ public class ConcernRecommendAdapter extends RecyclerView.Adapter installedList = concernManager.getInstalledGame(); - final int size = installedList.size(); - count = 0; - for (ConcernInfo concernInfo : installedList) { - RetrofitManager.getApi().getGameDigest(concernInfo.getId()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(GameEntity response) { - if (response.isNewsExists()) { - gameList.add(response); - } - - addCount(); - if (count == size) { - initRecommendGame(); - } - } - - @Override - public void onFailure(Throwable e) { - addCount(); - if (count == size) { - initRecommendGame(); - } - } - }); + List> sequences = new ArrayList<>(); + for (ConcernInfo concernInfo : concernManager.getInstalledGame()) { + sequences.add(RetrofitManager.getApi().getGameDigest(concernInfo.getId())); } + Observable.merge(sequences) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onNext(GameEntity response) { + if (response.isNewsExists()) { + gameList.add(response); + } + } + + @Override + public void onCompleted() { + initRecommendGame(); + } + }); } private void initRecommendGame() { @@ -156,11 +140,8 @@ public class ConcernRecommendAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - map.put("type", "关注"); - DataCollectionManager.onEvent(context, "concern", map); + DataCollectionUtils.uploadConcern(context, + gameEntity.getName(), gameEntity.getId(), "关注"); concernManager.addByEntity(gameEntity); @@ -179,12 +160,7 @@ public class ConcernRecommendAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "推荐"); - map.put("page", "我的关注"); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "推荐", "我的关注", gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity, "(我的关注-推荐)"); } diff --git a/app/src/main/java/com/gh/gamecenter/adapter/GameNewsAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/GameNewsAdapter.java index 271646081a..f18cbe4443 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/GameNewsAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/GameNewsAdapter.java @@ -10,6 +10,7 @@ import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; import android.widget.Toast; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.NewsUtils; @@ -21,7 +22,6 @@ import com.gh.gamecenter.adapter.viewholder.GameNewsTypeListViewHolder; import com.gh.gamecenter.adapter.viewholder.NewsFooterViewHolder; import com.gh.gamecenter.adapter.viewholder.NewsTextViewHolder; import com.gh.gamecenter.entity.NewsEntity; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -206,12 +206,7 @@ public class GameNewsAdapter extends RecyclerView.Adapter { kv.put("位置", String.valueOf(viewHolder.getPosition() + 1)); DataUtils.onEvent(context, "点击", "游戏新闻详情", kv); - Map map = new HashMap<>(); - map.put("location", newsType); - map.put("page", "游戏新闻详情"); - map.put("news", newsEntity.getTitle()); - map.put("news_id", newsEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, newsType, "游戏新闻详情", newsEntity.getTitle()); // 统计阅读量 NewsUtils.statNewsViews(newsEntity.getId()); diff --git a/app/src/main/java/com/gh/gamecenter/adapter/ImagePagerAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/ImagePagerAdapter.java index 36a6d90563..f7e99f48b0 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/ImagePagerAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/ImagePagerAdapter.java @@ -11,33 +11,20 @@ import android.view.View; import android.view.ViewGroup; import com.facebook.drawee.view.SimpleDraweeView; +import com.gh.common.util.DataLogUtils; import com.gh.common.util.DataUtils; -import com.gh.common.util.DeviceUtils; import com.gh.common.util.GameUtils; import com.gh.common.util.ImageUtils; import com.gh.common.util.NewsUtils; -import com.gh.common.util.PackageUtils; -import com.gh.common.util.TokenUtils; -import com.gh.common.util.Utils; import com.gh.gamecenter.NewsDetailActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.SubjectActivity; import com.gh.gamecenter.entity.SlideEntity; -import com.gh.gamecenter.retrofit.Response; -import com.gh.gamecenter.retrofit.RetrofitManager; - -import org.json.JSONObject; import java.util.HashMap; import java.util.List; import java.util.Map; -import okhttp3.MediaType; -import okhttp3.RequestBody; -import okhttp3.ResponseBody; -import rx.android.schedulers.AndroidSchedulers; -import rx.schedulers.Schedulers; - /** * ImagePagerAdapter * @@ -104,7 +91,8 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter { DataUtils.onEvent(context, "点击", "游戏-插件-滚动图", kv); // 首页轮播图数据统计 - statLunbotuData(getPosition(position)); + DataLogUtils.uploadLunbotuLog(context, slideEntity.getType(), + slideEntity.getName(), String.valueOf(getPosition(position) + 1)); if ("game".equals(slideEntity.getType())) { String entrance = "(游戏-插件:滚动图[" @@ -138,37 +126,6 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter { return view; } - // 首页轮播图数据统计 - public void statLunbotuData(int position) { - SlideEntity slideEntity = slideList.get(position); - - Map map = new HashMap<>(); - map.put("location", String.valueOf(position + 1)); - map.put("type", slideEntity.getType()); - map.put("title", slideEntity.getName()); - map.put("form", "click"); - - String version = PackageUtils.getVersion(context); - String user = DeviceUtils.getDeviceID(context); - String channel = (String) PackageUtils.getMetaData(context, context.getPackageName(), "TD_CHANNEL_ID"); - map.put("version", version); - map.put("user", user); - map.put("device_id", TokenUtils.getDeviceId(context)); - map.put("channel", channel); - Map params = new HashMap<>(); - params.put("topic", "lunbotu"); - params.put("source", "GH-ASSIST-Client"); - params.put("time", String.valueOf(Utils.getTime(context))); - params.put("content", new JSONObject(map).toString()); - - RequestBody body = RequestBody.create(MediaType.parse("application/json"), - new JSONObject(params).toString()); - RetrofitManager.getData().postLog(body) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response()); - } - /** * @return the isInfiniteLoop */ diff --git a/app/src/main/java/com/gh/gamecenter/adapter/MessageDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/MessageDetailAdapter.java index 6c613061cb..2b018edd4c 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/MessageDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/MessageDetailAdapter.java @@ -18,6 +18,7 @@ import android.widget.TextView; import com.gh.common.constant.Config; import com.gh.common.util.ConcernContentUtils; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.NewsUtils; @@ -40,7 +41,6 @@ import com.gh.gamecenter.db.VoteDao; import com.gh.gamecenter.db.info.VoteInfo; import com.gh.gamecenter.entity.CommentEntity; import com.gh.gamecenter.entity.ConcernEntity; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.VisitManager; import com.gh.gamecenter.retrofit.JSONObjectResponse; import com.gh.gamecenter.retrofit.OkHttpCache; @@ -407,11 +407,7 @@ public class MessageDetailAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("page", "消息详情"); - map.put("news", mConcernEntity.getTitle()); - map.put("news_id", mConcernEntity.getId()); - DataCollectionManager.onEvent(mContext, "click-item", map); + DataCollectionUtils.uploadClick(mContext, "详情", "消息详情", mConcernEntity.getTitle()); // 统计阅读量 statNewsViews(mConcernEntity.getId()); @@ -717,7 +713,6 @@ public class MessageDetailAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - if ("下载".equals(method)) { - map.put("method", "正常"); - } else { - map.put("method", method); - } - map.put("platform", PlatformUtils.getInstance(context) - .getPlatformName(apkEntity.getPlatform())); - map.put("status", "开始"); - map.put("location", location); - map.put("entrance", entrance); - map.put("btn_status", method); - map.put("network", NetworkUtils.getConnectedType(context)); - DataCollectionManager.onEvent(context, "download", map); - DownloadManager.createDownload(context, apkEntity, gameEntity, method, entrance, location); DownloadManager.getInstance(context).putStatus(apkEntity.getUrl(), "downloading"); @@ -448,19 +430,6 @@ public class PlatformAdapter extends RecyclerView.Adapter { kv.put("状态", "下载开始"); DataUtils.onEvent(context, "游戏更新", gameEntity.getName(), kv); - Map map = new HashMap<>(); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - map.put("method", "更新"); - map.put("platform", PlatformUtils.getInstance(context) - .getPlatformName(apkEntity.getPlatform())); - map.put("status", "开始"); - map.put("location", location); - map.put("entrance", entrance); - map.put("btn_status", "更新"); - map.put("network", NetworkUtils.getConnectedType(context)); - DataCollectionManager.onEvent(context, "download", map); - DownloadManager.createDownload(context, apkEntity, gameEntity, "更新", entrance, location); } diff --git a/app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java index da38657fa9..f11e79f47f 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/PluginAdapter.java @@ -7,6 +7,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.DownloadItemUtils; @@ -22,7 +23,6 @@ import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.GameUpdateEntity; import com.gh.gamecenter.listener.OnCallBackListener; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.GameManager; import com.gh.gamecenter.manager.PackageManager; @@ -177,12 +177,7 @@ public class PluginAdapter extends RecyclerView.Adapter kv.put("位置", String.valueOf(viewHolder.getPosition() + 1)); DataUtils.onEvent(context, "点击", "可以插件化的游戏", kv); - Map map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", "可以插件化的游戏"); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "列表", "可以插件化的游戏", gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity.getId(), entrance + "+(可以插件化的游戏)"); } diff --git a/app/src/main/java/com/gh/gamecenter/adapter/SubjectAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/SubjectAdapter.java index 5feff61ca5..0943cd0dcc 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/SubjectAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/SubjectAdapter.java @@ -10,6 +10,7 @@ import android.view.ViewGroup; import android.widget.Toast; import com.gh.common.constant.ItemViewType; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.DownloadItemUtils; @@ -26,7 +27,6 @@ import com.gh.gamecenter.adapter.viewholder.GameTestViewHolder; import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.listener.OnCallBackListener; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.GameManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -69,6 +69,12 @@ public class SubjectAdapter extends RecyclerView.Adapter(); @@ -251,7 +257,7 @@ public class SubjectAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", name); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "列表", name, gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity, entrance + "+(" + name + ")"); } }); - if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) { - holder.downloadBtn.setVisibility(View.GONE); - } else { - if (gameEntity.getTest().getEnd() == 0) { - DownloadItemUtils.setOnClickListener(context, - holder.downloadBtn, gameEntity, position, - SubjectAdapter.this, entrance + "+(" + name + ")", name + ":" + gameEntity.getName()); - - DownloadItemUtils.updateItem(context, holder.gameDes, - holder.game_progressbar, holder.game_ll_info, holder.download_speed, - holder.download_percentage, holder.downloadBtn, gameEntity); - } else { - long endTime = Long.valueOf(gameEntity.getTest().getEnd() - + "000"); - long todayTime = new Date().getTime(); - if (todayTime > endTime) { - // 测试时间已过 - holder.downloadBtn.setVisibility(View.GONE); - } else { - // 测试时间未过 - DownloadItemUtils.setOnClickListener(context, - holder.downloadBtn, gameEntity, position, - SubjectAdapter.this, entrance + "+(" + name + ")", name + ":" + gameEntity.getName()); - - DownloadItemUtils.updateItem(context, holder.gameDes, - holder.game_progressbar, holder.game_ll_info, holder.download_speed, - holder.download_percentage, holder.downloadBtn, gameEntity); - } + if (gameEntity.getTest().getEnd() != 0) { + long endTime = Long.valueOf(gameEntity.getTest().getEnd() + "000"); + long todayTime = new Date().getTime(); + if (todayTime > endTime) { + // 测试时间已过 + gameEntity.setApk(null); } } + + DownloadItemUtils.setOnClickListener(context, + holder.downloadBtn, gameEntity, position, + SubjectAdapter.this, entrance + "+(" + name + ")", name + ":" + gameEntity.getName()); + + DownloadItemUtils.updateItem(context, holder.gameDes, + holder.game_progressbar, holder.game_ll_info, holder.download_speed, + holder.download_percentage, holder.downloadBtn, gameEntity); } private void initGameNormalViewHolder(final GameNormalViewHolder holder, int position) { @@ -404,12 +390,7 @@ public class SubjectAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", name); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "列表", name, gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity, entrance + "+(" + name + ")"); } diff --git a/app/src/main/java/com/gh/gamecenter/download/GameDownLoadFragment.java b/app/src/main/java/com/gh/gamecenter/download/GameDownLoadFragment.java index 91c1282f63..fe9e7ef272 100644 --- a/app/src/main/java/com/gh/gamecenter/download/GameDownLoadFragment.java +++ b/app/src/main/java/com/gh/gamecenter/download/GameDownLoadFragment.java @@ -161,6 +161,10 @@ public class GameDownLoadFragment extends Fragment implements View.OnClickListen String path = getActivity().getIntent().getStringExtra("path"); url = getActivity().getIntent().getStringExtra("url"); + if (getActivity().getIntent().getBundleExtra("data") != null) { + path = getActivity().getIntent().getBundleExtra("data").getString("path"); + url = getActivity().getIntent().getBundleExtra("data").getString("url"); + } isScroll = false; @@ -388,12 +392,12 @@ public class GameDownLoadFragment extends Fragment implements View.OnClickListen }); } } else { - for (int i = 0, size = adapter.getDownloadingList().size(); i < size; i++) { - DownloadManager.getInstance(getActivity()).put(adapter.getDownloadingList().get(i).getUrl(), + for (DownloadEntity downloadEntity : adapter.getDownloadingList()) { + DownloadManager.getInstance(getActivity()).put(downloadEntity.getUrl(), System.currentTimeMillis()); Message msg = Message.obtain(); msg.what = Constants.PAUSE_DOWNLOAD_TASK; - msg.obj = adapter.getDownloadingList().get(i).getUrl(); + msg.obj = downloadEntity.getUrl(); DownloadManager.getInstance(getActivity()).sendMessageDelayed(msg, 1000); } downloadmanager_tv_allstart.setText("全部开始"); @@ -404,14 +408,14 @@ public class GameDownLoadFragment extends Fragment implements View.OnClickListen } private void allStart() { - for (int i = 0, size = adapter.getDownloadingList().size(); i < size; i++) { - DownloadManager.getInstance(getActivity()).put(adapter.getDownloadingList().get(i).getUrl(), + for (DownloadEntity downloadEntity : adapter.getDownloadingList()) { + DownloadManager.getInstance(getActivity()).put(downloadEntity.getUrl(), System.currentTimeMillis()); Message msg = Message.obtain(); msg.what = Constants.CONTINUE_DOWNLOAD_TASK; - msg.obj = adapter.getDownloadingList().get(i).getUrl(); + msg.obj = downloadEntity.getUrl(); DownloadManager.getInstance(getActivity()).sendMessageDelayed(msg, 1000); - adapter.getStatusMap().put(adapter.getDownloadingList().get(i).getUrl(), "downloading"); + adapter.getStatusMap().put(downloadEntity.getUrl(), "downloading"); } downloadmanager_tv_allstart.setText("全部暂停"); downloadmanager_tv_allstart.setTextColor(getActivity().getResources().getColor(R.color.btn_gray)); diff --git a/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragmentAdapter.java index 7b9c0d2887..79b03baf53 100644 --- a/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/download/GameDownloadFragmentAdapter.java @@ -384,10 +384,10 @@ public class GameDownloadFragmentAdapter extends RecyclerView.Adapter packages = getInstalledList(); if (packages.size() != 0) { - final int count = packages.size(); - mCount = 0; + List> sequences = new ArrayList<>(); Object gh_id; for (String packageName : packages) { gh_id = PackageUtils.getMetaData(context, packageName, "gh_id"); - Observable observable; if (gh_id == null) { - observable = RetrofitManager.getApi().getGameUpdate(packageName); + sequences.add(RetrofitManager.getApi().getGameUpdate(packageName)); } else { - observable = RetrofitManager.getApi().getGameUpdate((String) gh_id, packageName); + sequences.add(RetrofitManager.getApi().getGameUpdate((String) gh_id, packageName)); } - observable.subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(GameUpdateEntity response) { - if (PackageUtils.isCanUpdate(context, response)) { - PackageManager.addUpdate(response); - } - - addCount(); - if (mCount == count) { - processingData(); - } - } - - @Override - public void onFailure(Throwable e) { - addCount(); - if (mCount == count) { - processingData(); - } - } - }); } + Observable.merge(sequences) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onNext(GameUpdateEntity response) { + if (PackageUtils.isCanUpdate(context, response)) { + PackageManager.addUpdate(response); + } + } + + @Override + public void onCompleted() { + processingData(); + } + }); } else { gameupdate_ll_loading.setVisibility(View.GONE); } @@ -548,24 +531,6 @@ public class GameUpdateFragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("game", updateEntity.getName()); - map.put("game_id", updateEntity.getId()); - map.put("status", "开始"); - if (updateEntity.isPluggable()) { - map.put("method", "插件化"); - map.put("btn_status", "插件化"); - } else { - map.put("method", "更新"); - map.put("btn_status", "更新"); - } - map.put("platform", PlatformUtils.getInstance(context) - .getPlatformName(updateEntity.getPlatform())); - map.put("location", "游戏更新:列表"); - map.put("entrance", "(下载管理:游戏更新)"); - map.put("network", NetworkUtils.getConnectedType(context)); - DataCollectionManager.onEvent(context, "download", map); - DownloadEntity downloadEntity = new DownloadEntity(); downloadEntity.setUrl(updateEntity.getUrl()); downloadEntity.setName(updateEntity.getName()); @@ -582,12 +547,15 @@ public class GameUpdateFragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", subjectEntity.getName() + "-列表"); - map.put("page", "游戏-插件"); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, + subjectEntity.getName() + "-列表", "游戏-插件", gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity, "(游戏-插件:" + subjectEntity.getName() + "-列表)"); } }); - if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) { - holder.downloadBtn.setVisibility(View.GONE); - } else { - if (gameEntity.getTest().getEnd() == 0) { - DownloadItemUtils.setOnClickListener(context, - holder.downloadBtn, gameEntity, i, - Game1FragmentAdapter.this, "(游戏-插件:" + subjectEntity.getName() + "-列表)", - "游戏-插件-" + subjectEntity.getName() + ":" + gameEntity.getName()); - - DownloadItemUtils.updateItem(context, holder.gameDes, - holder.game_progressbar, holder.game_ll_info, holder.download_speed, - holder.download_percentage, holder.downloadBtn, gameEntity); - } else { - long endTime = Long.valueOf(gameEntity.getTest().getEnd() - + "000"); - long todayTime = new Date().getTime(); - if (todayTime > endTime) { - // 测试时间已过 - holder.downloadBtn.setVisibility(View.GONE); - } else { - // 测试时间未过 - DownloadItemUtils.setOnClickListener(context, - holder.downloadBtn, gameEntity, i, - Game1FragmentAdapter.this, - "(游戏-插件:" + subjectEntity.getName() + "-列表)", - "游戏-插件-" + subjectEntity.getName() + ":" + gameEntity.getName()); - - DownloadItemUtils.updateItem(context, holder.gameDes, - holder.game_progressbar, holder.game_ll_info, holder.download_speed, - holder.download_percentage, holder.downloadBtn, gameEntity); - } + if (gameEntity.getTest().getEnd() != 0) { + long endTime = Long.valueOf(gameEntity.getTest().getEnd() + "000"); + long todayTime = new Date().getTime(); + if (todayTime > endTime) { + // 测试时间已过 + gameEntity.setApk(null); } } + DownloadItemUtils.setOnClickListener(context, + holder.downloadBtn, gameEntity, i, + Game1FragmentAdapter.this, "(游戏-插件:" + subjectEntity.getName() + "-列表)", + "游戏-插件-" + subjectEntity.getName() + ":" + gameEntity.getName()); + + DownloadItemUtils.updateItem(context, holder.gameDes, + holder.game_progressbar, holder.game_ll_info, holder.download_speed, + holder.download_percentage, holder.downloadBtn, gameEntity); } private void initGameNormalViewHolder(GameNormalViewHolder holder, int position) { @@ -752,7 +731,7 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", subjectEntity.getName() + "-列表"); - map.put("page", "游戏-插件"); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, + subjectEntity.getName() + "-列表", "游戏-插件", gameEntity.getName()); if (gameEntity.isPluggable()) { GameUtils.startGameDetailActivity(context, gameEntity.getId(), "(游戏-插件:" + subjectEntity.getName() + "-列表)"); @@ -840,10 +815,7 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", name + "-大图"); - map.put("page", "游戏-插件"); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, name + "-大图", "游戏-插件"); if ("game".equals(entity.getType())) { GameUtils.startGameDetailActivity(context, entity.getLink(), "(游戏-插件:" + name + "-大图)"); @@ -930,7 +902,7 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", subjectEntity.getName() + "-列表"); - map.put("page", "游戏-推荐"); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, + subjectEntity.getName() + "-列表", "游戏-推荐", gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity, "(游戏-推荐:" + subjectEntity.getName() + "-列表)"); } @@ -455,7 +451,7 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", subjectEntity.getName() + "-列表"); - map.put("page", "游戏-推荐"); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, + subjectEntity.getName() + "-列表", "游戏-推荐", gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity, "(游戏-推荐:" + subjectEntity.getName() + "-列表)"); } }); - if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) { - holder.downloadBtn.setVisibility(View.GONE); - } else { - if (gameEntity.getTest().getEnd() == 0) { - DownloadItemUtils.setOnClickListener(context, - holder.downloadBtn, gameEntity, i, - Game2FragmentAdapter.this, "(游戏-推荐:" + subjectEntity.getName() + "-列表)", - "游戏-推荐-" + subjectEntity.getName() + ":" + gameEntity.getName()); - - DownloadItemUtils.updateItem(context, holder.gameDes, - holder.game_progressbar, holder.game_ll_info, holder.download_speed, - holder.download_percentage, holder.downloadBtn, gameEntity); - } else { - long endTime = Long.valueOf(gameEntity.getTest().getEnd() + "000"); - long todayTime = new Date().getTime(); - if (todayTime > endTime) { - // 测试时间已过 - holder.downloadBtn.setVisibility(View.GONE); - } else { - // 测试时间未过 - DownloadItemUtils.setOnClickListener(context, - holder.downloadBtn, gameEntity, i, - Game2FragmentAdapter.this, "(游戏-推荐:" + subjectEntity.getName() + "-列表)", - "游戏-推荐-" + subjectEntity.getName() + ":" + gameEntity.getName()); - - DownloadItemUtils.updateItem(context, holder.gameDes, - holder.game_progressbar, holder.game_ll_info, holder.download_speed, - holder.download_percentage, holder.downloadBtn, gameEntity); - } + if (gameEntity.getTest().getEnd() != 0) { + long endTime = Long.valueOf(gameEntity.getTest().getEnd() + "000"); + long todayTime = new Date().getTime(); + if (todayTime > endTime) { + // 测试时间已过 + gameEntity.setApk(null); } } + DownloadItemUtils.setOnClickListener(context, + holder.downloadBtn, gameEntity, i, + Game2FragmentAdapter.this, "(游戏-推荐:" + subjectEntity.getName() + "-列表)", + "游戏-推荐-" + subjectEntity.getName() + ":" + gameEntity.getName()); + + DownloadItemUtils.updateItem(context, holder.gameDes, + holder.game_progressbar, holder.game_ll_info, holder.download_speed, + holder.download_percentage, holder.downloadBtn, gameEntity); } private void initGameImageViewHolder(GameImageViewHolder holder, int position) { @@ -558,10 +535,7 @@ public class Game2FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", name + "-大图"); - map.put("page", "游戏-推荐"); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, name + "-大图", "游戏-推荐"); if ("game".equals(entity.getType())) { GameUtils.startGameDetailActivity(context, entity.getLink(), "(游戏-推荐:" + name + "-大图)"); diff --git a/app/src/main/java/com/gh/gamecenter/game/Game3FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/game/Game3FragmentAdapter.java index 70a14ef49f..13d4a4265e 100644 --- a/app/src/main/java/com/gh/gamecenter/game/Game3FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/game/Game3FragmentAdapter.java @@ -9,6 +9,7 @@ import android.view.ViewGroup; import android.widget.Toast; import com.gh.common.constant.ItemViewType; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DownloadItemUtils; import com.gh.common.util.GameUtils; @@ -21,7 +22,6 @@ import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder; import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.listener.OnCallBackListener; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.GameManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -255,12 +255,7 @@ public class Game3FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", "游戏-单机"); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "列表", "游戏-单机", gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity, "(游戏-单机)"); } diff --git a/app/src/main/java/com/gh/gamecenter/game/GameFragment.java b/app/src/main/java/com/gh/gamecenter/game/GameFragment.java index 955810f997..e22bbba4cc 100644 --- a/app/src/main/java/com/gh/gamecenter/game/GameFragment.java +++ b/app/src/main/java/com/gh/gamecenter/game/GameFragment.java @@ -2,185 +2,302 @@ package com.gh.gamecenter.game; import android.os.Bundle; import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v4.view.ViewPager.OnPageChangeListener; -import android.util.DisplayMetrics; -import android.view.Gravity; +import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.LinearLayout; -import android.widget.TextView; +import com.facebook.drawee.backends.pipeline.Fresco; +import com.gc.materialdesign.views.ProgressBarCircularIndeterminate; import com.gh.base.HomeFragment; -import com.gh.common.util.DisplayUtils; +import com.gh.common.util.DownloadItemUtils; +import com.gh.download.DataWatcher; +import com.gh.download.DownloadEntity; +import com.gh.download.DownloadManager; import com.gh.gamecenter.R; -import com.gh.gamecenter.adapter.FragmentAdapter; -import com.gh.gamecenter.eventbus.EBSkip; +import com.gh.gamecenter.entity.ApkEntity; +import com.gh.gamecenter.entity.GameEntity; +import com.gh.gamecenter.entity.SubjectEntity; +import com.gh.gamecenter.eventbus.EBDownloadStatus; +import com.gh.gamecenter.eventbus.EBNetworkState; +import com.gh.gamecenter.eventbus.EBPackage; +import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.eventbus.EBUISwitch; +import com.gh.gamecenter.listener.OnCallBackListener; import java.util.ArrayList; import java.util.List; -import de.greenrobot.event.EventBus; - /** - * - * @author 温冠超 - * @email 294299195@qq.com - * @date 2015-8-8 主页fragment3页面 + * Created by khy on 2016/12/6. + * 新主界面 */ -public class GameFragment extends HomeFragment implements OnPageChangeListener { +public class GameFragment extends HomeFragment implements SwipeRefreshLayout.OnRefreshListener + , OnCallBackListener { - private TextView tv_chajian; - private TextView tv_tuijian; - private TextView tv_danji; + private SwipeRefreshLayout fm_game_swipe_refresh; + private RecyclerView fm_game_rv_list; + private GameFragmentAdapter adapter; + private LinearLayout reuse_no_connection; + private ProgressBarCircularIndeterminate fm_game_pb_loading; - private int width; - private int currentItem; + private boolean isEverpause; - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - outState.putInt("currentItem", currentItem); - } + private DataWatcher dataWatcher = new DataWatcher() { + @Override + public void onDataChanged(DownloadEntity downloadEntity) { + if (!fm_game_swipe_refresh.isRefreshing()) { + ArrayList locationList = adapter.getLocationMap().get(downloadEntity.getPackageName()); + if (locationList != null && locationList.size() != 0) { + GameEntity gameEntity; + for (int location : locationList) { + gameEntity = adapter.getGameEntityByLocation(location); + if (gameEntity != null) { + DownloadItemUtils.processDate(getActivity(), gameEntity, + downloadEntity, adapter, location); + } + } + } + } + } + }; - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); - List list = new ArrayList<>(); - list.add(new Game1Fragment()); - list.add(new Game2Fragment()); - list.add(new Game3Fragment()); - home_vp_content.setAdapter(new FragmentAdapter(getChildFragmentManager(), list)); - home_vp_content.addOnPageChangeListener(this); + ((LinearLayout) view).addView(View.inflate(getActivity(), R.layout.fragment_game, null)); - currentItem = 0; - if (savedInstanceState != null) { - currentItem = savedInstanceState.getInt("currentItem"); - } - initTextView(); - home_vp_content.setCurrentItem(currentItem); + reuse_no_connection = (LinearLayout) view.findViewById(R.id.reuse_no_connection); + fm_game_swipe_refresh = (SwipeRefreshLayout) view.findViewById(R.id.fm_game_swipe_refresh); + fm_game_rv_list = (RecyclerView) view.findViewById(R.id.fm_game_rv_list); + fm_game_pb_loading = (ProgressBarCircularIndeterminate) view.findViewById(R.id.fm_game_pb_loading); - DisplayMetrics outMetrics = new DisplayMetrics(); - getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics); - width = outMetrics.widthPixels / 3; - lparams = new LinearLayout.LayoutParams(width / 2, - DisplayUtils.dip2px(getActivity(), 2)); - lparams.leftMargin = (int) (width * (currentItem + 0.25f)); - home_slide_line.setLayoutParams(lparams); + reuse_no_connection.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + fm_game_swipe_refresh.setRefreshing(true); + fm_game_rv_list.setVisibility(View.VISIBLE); + fm_game_pb_loading.setVisibility(View.VISIBLE); + reuse_no_connection.setVisibility(View.GONE); + handler.postDelayed(runnable, 1000); + } + }); - handler.postDelayed(new Runnable() { - @Override - public void run() { - EventBus.getDefault().post(new EBUISwitch("GameFragment", home_vp_content.getCurrentItem())); - } - }, 100); - } + fm_game_swipe_refresh.setColorSchemeResources(R.color.theme); + fm_game_swipe_refresh.setOnRefreshListener(this); - private void initTextView() { - tv_chajian = new TextView(getActivity()); - tv_chajian.setText("插件"); - if (currentItem == 0) { - tv_chajian.setTextColor(getResources().getColor(R.color.theme)); - } else { - tv_chajian.setTextColor(getResources().getColor(R.color.title)); - } - tv_chajian.setGravity(Gravity.CENTER); - tv_chajian.setOnClickListener(this); - LinearLayout.LayoutParams lparams1 = new LinearLayout.LayoutParams( - 0, DisplayUtils.dip2px(getActivity(), 35)); - lparams1.weight = 1; - home_ll_top.addView(tv_chajian, lparams1); + fm_game_rv_list.setHasFixedSize(true); + fm_game_rv_list.setLayoutManager(new LinearLayoutManager(getActivity())); + adapter = new GameFragmentAdapter(GameFragment.this, fm_game_swipe_refresh); + fm_game_rv_list.setAdapter(adapter); - tv_tuijian = new TextView(getActivity()); - tv_tuijian.setText("推荐"); - if (currentItem == 1) { - tv_tuijian.setTextColor(getResources().getColor(R.color.theme)); - } else { - tv_tuijian.setTextColor(getResources().getColor(R.color.title)); - } - tv_tuijian.setGravity(Gravity.CENTER); - tv_tuijian.setOnClickListener(this); - LinearLayout.LayoutParams lparams2 = new LinearLayout.LayoutParams( - 0, DisplayUtils.dip2px(getActivity(), 35)); - lparams2.weight = 1; - home_ll_top.addView(tv_tuijian, lparams2); + fm_game_rv_list.setOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(RecyclerView recyclerView, int newState) { + super.onScrollStateChanged(recyclerView, newState); + if (newState == RecyclerView.SCROLL_STATE_IDLE){ + Fresco.getImagePipeline().resume(); + }else { + Fresco.getImagePipeline().pause(); + } + } + }); + } - tv_danji = new TextView(getActivity()); - tv_danji.setText("单机"); - if (currentItem == 2) { - tv_danji.setTextColor(getResources().getColor(R.color.theme)); - } else { - tv_danji.setTextColor(getResources().getColor(R.color.title)); - } - tv_danji.setGravity(Gravity.CENTER); - tv_danji.setOnClickListener(this); - LinearLayout.LayoutParams lparams3 = new LinearLayout.LayoutParams( - 0, DisplayUtils.dip2px(getActivity(), 35)); - lparams3.weight = 1; - home_ll_top.addView(tv_danji, lparams3); - } + @Override + public void loadDone() { + if (fm_game_swipe_refresh != null && fm_game_swipe_refresh.isRefreshing()) { + fm_game_swipe_refresh.setRefreshing(false); + } + if (fm_game_pb_loading != null && fm_game_pb_loading.getVisibility() == View.VISIBLE) { + fm_game_pb_loading.setVisibility(View.GONE); + } + } - @Override - public void onClick(View v) { - super.onClick(v); - if (v == tv_chajian) { - home_vp_content.setCurrentItem(0); - } else if (v == tv_tuijian) { - home_vp_content.setCurrentItem(1); - } else if (v == tv_danji) { - home_vp_content.setCurrentItem(2); - } - } + @Override + public void loadDone(Object obj) { - @Override - public void onPageSelected(int position) { - if (position == 0) { - tv_chajian.setTextColor(getResources().getColor(R.color.theme)); - tv_tuijian.setTextColor(getResources().getColor(R.color.title)); - tv_danji.setTextColor(getResources().getColor(R.color.title)); - } else if (position == 1) { - tv_chajian.setTextColor(getResources().getColor(R.color.title)); - tv_tuijian.setTextColor(getResources().getColor(R.color.theme)); - tv_danji.setTextColor(getResources().getColor(R.color.title)); - } else if (position == 2) { - tv_chajian.setTextColor(getResources().getColor(R.color.title)); - tv_tuijian.setTextColor(getResources().getColor(R.color.title)); - tv_danji.setTextColor(getResources().getColor(R.color.theme)); - } - } + } - @Override - public void onPageScrolled(int position, float positionOffset, - int positionOffsetPixels) { - if (positionOffset != 0) { - lparams.leftMargin = (int) (width * (position + positionOffset + 0.25f)); - home_slide_line.setLayoutParams(lparams); - } else { - if (currentItem != home_vp_content.getCurrentItem()) { - currentItem = home_vp_content.getCurrentItem(); - EventBus.getDefault().post(new EBUISwitch("GameFragment", currentItem)); - } - } - } + @Override + public void loadError() { + fm_game_rv_list.setVisibility(View.GONE); + fm_game_pb_loading.setVisibility(View.GONE); + reuse_no_connection.setVisibility(View.VISIBLE); + } - @Override - public void onPageScrollStateChanged(int state) { - - } + @Override + public void loadEmpty() { - public void onEventMainThread(EBUISwitch busNine) { - if ("MainActivity".equals(busNine.getFrom())) { - if (busNine.getPosition() == 0) { - EventBus.getDefault().post(new EBUISwitch("GameFragment", home_vp_content.getCurrentItem())); - } - } - } + } - public void onEventMainThread(EBSkip skip) { - if ("MainActivity".equals(skip.getType())) { - home_vp_content.setCurrentItem(skip.getCurrentItem()); - } - } + //下载被删除事件 + public void onEventMainThread(EBDownloadStatus status) { + super.onEventMainThread(status); + if ("delete".equals(status.getStatus())) { + DownloadManager.getInstance(getActivity()).removePlatform(status.getName(), status.getPlatform()); + + ArrayList locationList = adapter.getLocationMap().get(status.getPackageName()); + GameEntity gameEntity; + if (locationList != null && locationList.size() != 0) { + for (int location : locationList) { + gameEntity = adapter.getGameEntityByLocation(location); + if (gameEntity != null && gameEntity.getEntryMap() != null) { + gameEntity.getEntryMap().remove(status.getPlatform()); + } + adapter.notifyItemChanged(location); + } + } + } else if ("plugin".equals(status.getStatus())) { + handler.postDelayed(initPluginRunnable, 100); + } + } + + Runnable initPluginRunnable = new Runnable() { + @Override + public void run() { + if (adapter.isInitPlugin()) { + handler.postDelayed(initPluginRunnable, 100); + } else { + adapter.initPlugin(); + } + } + }; + + //安装、卸载事件 + public void onEventMainThread(EBPackage busFour) { + ArrayList locationList = adapter.getLocationMap().get(busFour.getPackageName()); + if (locationList != null) { + GameEntity gameEntity; + for (int location : locationList) { + gameEntity = adapter.getGameEntityByLocation(location); + if (gameEntity != null) { + if (gameEntity.isPluggable()) { + // 插件化列表 + if ("安装".equals(busFour.getType()) || "卸载".equals(busFour.getType())) { + List list = adapter.getPluginList(); + for (int i = 0; i < list.size(); i++) { + if (list.get(i).getApk().get(0).getPackageName().equals(busFour.getPackageName())) { + if ("卸载".equals(busFour.getType()) + && DownloadManager.getInstance(getActivity()).get( + list.get(i).getApk().get(0).getUrl()) != null) { + adapter.notifyItemChanged(2 + i); + } else { + list.remove(i); + if (list.isEmpty()) { + adapter.initItemCount(); + adapter.notifyItemRangeRemoved(1, 2); +// adapter.notifyItemChanged(1); // 如果position是1为图片时 需要刷新卡片高度 + } else { + adapter.initItemCount(); + adapter.notifyItemRemoved(location); + adapter.notifyItemChanged(1); + } + } + break; + } + } + } + } else { + if ("安装".equals(busFour.getType())) { + for (ApkEntity apkEntity : gameEntity.getApk()) { + if (apkEntity.getPackageName().equals(busFour.getPackageName())) { + if (gameEntity.getEntryMap() != null) { + gameEntity.getEntryMap().remove(apkEntity.getPlatform()); + } + adapter.notifyItemChanged(location); + break; + } + } + } else if ("卸载".equals(busFour.getType())) { + adapter.notifyItemChanged(location); + } + } + } + } + adapter.initLocationMap(); + } + } + + //连接上网络事件 + public void onEventMainThread(EBNetworkState busNetworkState) { + if (busNetworkState.isNetworkConnected()) { + if (reuse_no_connection.getVisibility() == View.VISIBLE) { + fm_game_swipe_refresh.setRefreshing(true); + fm_game_rv_list.setVisibility(View.VISIBLE); + fm_game_pb_loading.setVisibility(View.GONE); + reuse_no_connection.setVisibility(View.GONE); + handler.postDelayed(runnable, 1000); + } else if (adapter.isNetworkError()) { + adapter.setNetworkError(false); + adapter.notifyItemChanged(adapter.getItemCount() - 1); + adapter.initSubjectDigest(true); + } + } + } + + // 打开下载按钮事件 + public void onEventMainThread(EBReuse reuse) { + if (("Refresh".equals(reuse.getType()) || "PlatformChanged".equals(reuse.getType())) + && adapter != null) { + adapter.notifyItemRangeChanged(0, adapter.getItemCount()); + } + } + + //Fragment界面切换事件 + public void onEventMainThread(EBUISwitch busNine) { + if ("MainActivity".equals(busNine.getFrom())) { + if (busNine.getPosition() == 0) { + adapter.startAutoScroll(); + } else { + adapter.stopAutoScroll(); + } + } + } + + @Override + public void onResume() { + super.onResume(); + isEverpause = false; + for (SubjectEntity subjectEntity : adapter.getSubjectList()) { + for (GameEntity entity :subjectEntity.getData()) { + entity.setEntryMap(DownloadManager.getInstance(getActivity()).getEntryMap(entity.getName())); + } + } + for (GameEntity entity : adapter.getPluginList()) { + entity.setEntryMap(DownloadManager.getInstance(getActivity()).getEntryMap(entity.getName())); + } + adapter.notifyDataSetChanged(); + DownloadManager.getInstance(getActivity()).addObserver(dataWatcher); + adapter.startAutoScroll(); + } + + @Override + public void onPause() { + super.onPause(); + isEverpause = true; + DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher); + adapter.stopAutoScroll(); + } + + Runnable runnable = new Runnable() { + @Override + public void run() { + adapter = new GameFragmentAdapter(GameFragment.this, fm_game_swipe_refresh); + fm_game_rv_list.setAdapter(adapter); +// adapter.initSlide(true); + } + }; + + public boolean isEverpause() { + return isEverpause; + } + + @Override + public void onRefresh() { + handler.postDelayed(runnable, 1000); + } } diff --git a/app/src/main/java/com/gh/gamecenter/game/NewGameFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/game/GameFragmentAdapter.java similarity index 93% rename from app/src/main/java/com/gh/gamecenter/game/NewGameFragmentAdapter.java rename to app/src/main/java/com/gh/gamecenter/game/GameFragmentAdapter.java index 1e5ee9f81c..e7fb2e9e47 100644 --- a/app/src/main/java/com/gh/gamecenter/game/NewGameFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/game/GameFragmentAdapter.java @@ -20,6 +20,7 @@ import android.widget.Toast; import com.facebook.drawee.view.SimpleDraweeView; import com.gh.common.constant.ItemViewType; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.DownloadItemUtils; @@ -53,7 +54,6 @@ import com.gh.gamecenter.entity.SlideEntity; import com.gh.gamecenter.entity.SubjectDigestEntity; import com.gh.gamecenter.entity.SubjectEntity; import com.gh.gamecenter.listener.OnCallBackListener; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.GameManager; import com.gh.gamecenter.manager.PackageManager; import com.gh.gamecenter.retrofit.Response; @@ -73,9 +73,9 @@ import rx.schedulers.Schedulers; /** * Created by khy on 2016/12/6. */ -public class NewGameFragmentAdapter extends RecyclerView.Adapter { +public class GameFragmentAdapter extends RecyclerView.Adapter { - private NewGameFragment fragment; + private GameFragment fragment; private Context context; private OnCallBackListener listener; @@ -103,8 +103,8 @@ public class NewGameFragmentAdapter extends RecyclerView.Adapter>(){ @Override public void onResponse(List response) { - super.onResponse(response); if (response.size() == 3) { subjectDigestList = response; } else { @@ -179,12 +178,10 @@ public class NewGameFragmentAdapter extends RecyclerView.Adapter response) { if (response.size() != 0) { - if (!fragment.isHidden()&& !fragment.isEverpause()) { + if (!fragment.isHidden() && !fragment.isEverpause()) { if (pluginList.isEmpty()) { subjectList = response; initItemCount(); @@ -716,7 +713,7 @@ public class NewGameFragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", subjectEntity.getName() + "-列表"); - map.put("page", "游戏-插件"); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, + subjectEntity.getName() + "-列表", "游戏-插件", gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity, "(游戏-插件:" + subjectEntity.getName() + "-列表)"); } }); - if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) { - holder.downloadBtn.setVisibility(View.GONE); - } else { - if (gameEntity.getTest().getEnd() == 0) { - DownloadItemUtils.setOnClickListener(context, - holder.downloadBtn, gameEntity, i, - NewGameFragmentAdapter.this, "(游戏-插件:" + subjectEntity.getName() + "-列表)", - "游戏-插件-" + subjectEntity.getName() + ":" + gameEntity.getName()); - - DownloadItemUtils.updateItem(context, holder.gameDes, - holder.game_progressbar, holder.game_ll_info, holder.download_speed, - holder.download_percentage, holder.downloadBtn, gameEntity); - } else { - long endTime = Long.valueOf(gameEntity.getTest().getEnd() - + "000"); - long todayTime = new Date().getTime(); - if (todayTime > endTime) { - // 测试时间已过 - holder.downloadBtn.setVisibility(View.GONE); - } else { - // 测试时间未过 - DownloadItemUtils.setOnClickListener(context, - holder.downloadBtn, gameEntity, i, - NewGameFragmentAdapter.this, - "(游戏-插件:" + subjectEntity.getName() + "-列表)", - "游戏-插件-" + subjectEntity.getName() + ":" + gameEntity.getName()); - - DownloadItemUtils.updateItem(context, holder.gameDes, - holder.game_progressbar, holder.game_ll_info, holder.download_speed, - holder.download_percentage, holder.downloadBtn, gameEntity); - } + if (gameEntity.getTest().getEnd() != 0) { + long endTime = Long.valueOf(gameEntity.getTest().getEnd() + "000"); + long todayTime = new Date().getTime(); + if (todayTime > endTime) { + // 测试时间已过 + gameEntity.setApk(null); } } + DownloadItemUtils.setOnClickListener(context, + holder.downloadBtn, gameEntity, i, + GameFragmentAdapter.this, "(游戏-插件:" + subjectEntity.getName() + "-列表)", + "游戏-插件-" + subjectEntity.getName() + ":" + gameEntity.getName()); + + DownloadItemUtils.updateItem(context, holder.gameDes, + holder.game_progressbar, holder.game_ll_info, holder.download_speed, + holder.download_percentage, holder.downloadBtn, gameEntity); } private void initGameNormalViewHolder(GameNormalViewHolder holder, int position) { @@ -848,7 +824,7 @@ public class NewGameFragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", subjectEntity.getName() + "-列表"); - map.put("page", "游戏-插件"); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, + subjectEntity.getName() + "-列表", "游戏-插件", gameEntity.getName()); if (gameEntity.isPluggable()) { GameUtils.startGameDetailActivity(context, gameEntity.getId(), "(游戏-插件:" + subjectEntity.getName() + "-列表)"); @@ -893,7 +865,7 @@ public class NewGameFragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", name + "-大图"); - map.put("page", "游戏-插件"); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, name + "-大图", "游戏-插件"); if ("game".equals(entity.getType())) { GameUtils.startGameDetailActivity(context, entity.getLink(), "(游戏-插件:" + name + "-大图)"); @@ -1039,7 +1008,7 @@ public class NewGameFragmentAdapter extends RecyclerView.Adapter list = new ArrayList<>(); + list.add(new Game1Fragment()); + list.add(new Game2Fragment()); + list.add(new Game3Fragment()); + page_vp_content.setAdapter(new FragmentAdapter(getChildFragmentManager(), list)); + page_vp_content.addOnPageChangeListener(this); + + currentItem = 0; + if (savedInstanceState != null) { + currentItem = savedInstanceState.getInt("currentItem"); + } + initTextView(); + page_vp_content.setCurrentItem(currentItem); + + DisplayMetrics outMetrics = new DisplayMetrics(); + getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics); + width = outMetrics.widthPixels / 3; + lparams = new LinearLayout.LayoutParams(width / 2, + DisplayUtils.dip2px(getActivity(), 2)); + lparams.leftMargin = (int) (width * (currentItem + 0.25f)); + slidebar_line.setLayoutParams(lparams); + + handler.postDelayed(new Runnable() { + @Override + public void run() { + EventBus.getDefault().post(new EBUISwitch("GameFragment", page_vp_content.getCurrentItem())); + } + }, 100); + } + + private void initTextView() { + tv_chajian = new TextView(getActivity()); + tv_chajian.setText("插件"); + if (currentItem == 0) { + tv_chajian.setTextColor(getResources().getColor(R.color.theme)); + } else { + tv_chajian.setTextColor(getResources().getColor(R.color.title)); + } + tv_chajian.setGravity(Gravity.CENTER); + tv_chajian.setOnClickListener(this); + LinearLayout.LayoutParams lparams1 = new LinearLayout.LayoutParams( + 0, DisplayUtils.dip2px(getActivity(), 35)); + lparams1.weight = 1; + slidebar_ll_top.addView(tv_chajian, lparams1); + + tv_tuijian = new TextView(getActivity()); + tv_tuijian.setText("推荐"); + if (currentItem == 1) { + tv_tuijian.setTextColor(getResources().getColor(R.color.theme)); + } else { + tv_tuijian.setTextColor(getResources().getColor(R.color.title)); + } + tv_tuijian.setGravity(Gravity.CENTER); + tv_tuijian.setOnClickListener(this); + LinearLayout.LayoutParams lparams2 = new LinearLayout.LayoutParams( + 0, DisplayUtils.dip2px(getActivity(), 35)); + lparams2.weight = 1; + slidebar_ll_top.addView(tv_tuijian, lparams2); + + tv_danji = new TextView(getActivity()); + tv_danji.setText("单机"); + if (currentItem == 2) { + tv_danji.setTextColor(getResources().getColor(R.color.theme)); + } else { + tv_danji.setTextColor(getResources().getColor(R.color.title)); + } + tv_danji.setGravity(Gravity.CENTER); + tv_danji.setOnClickListener(this); + LinearLayout.LayoutParams lparams3 = new LinearLayout.LayoutParams( + 0, DisplayUtils.dip2px(getActivity(), 35)); + lparams3.weight = 1; + slidebar_ll_top.addView(tv_danji, lparams3); + } + + @Override + public void onClick(View v) { + super.onClick(v); + if (v == tv_chajian) { + page_vp_content.setCurrentItem(0); + } else if (v == tv_tuijian) { + page_vp_content.setCurrentItem(1); + } else if (v == tv_danji) { + page_vp_content.setCurrentItem(2); + } + } + + @Override + public void onPageSelected(int position) { + if (position == 0) { + tv_chajian.setTextColor(getResources().getColor(R.color.theme)); + tv_tuijian.setTextColor(getResources().getColor(R.color.title)); + tv_danji.setTextColor(getResources().getColor(R.color.title)); + } else if (position == 1) { + tv_chajian.setTextColor(getResources().getColor(R.color.title)); + tv_tuijian.setTextColor(getResources().getColor(R.color.theme)); + tv_danji.setTextColor(getResources().getColor(R.color.title)); + } else if (position == 2) { + tv_chajian.setTextColor(getResources().getColor(R.color.title)); + tv_tuijian.setTextColor(getResources().getColor(R.color.title)); + tv_danji.setTextColor(getResources().getColor(R.color.theme)); + } + } + + @Override + public void onPageScrolled(int position, float positionOffset, + int positionOffsetPixels) { + if (positionOffset != 0) { + lparams.leftMargin = (int) (width * (position + positionOffset + 0.25f)); + slidebar_line.setLayoutParams(lparams); + } else { + if (currentItem != page_vp_content.getCurrentItem()) { + currentItem = page_vp_content.getCurrentItem(); + EventBus.getDefault().post(new EBUISwitch("GameFragment", currentItem)); + } + } + } + + @Override + public void onPageScrollStateChanged(int state) { + + } + + public void onEventMainThread(EBUISwitch busNine) { + if ("MainActivity".equals(busNine.getFrom())) { + if (busNine.getPosition() == 0) { + EventBus.getDefault().post(new EBUISwitch("GameFragment", page_vp_content.getCurrentItem())); + } + } + } + + public void onEventMainThread(EBSkip skip) { + if ("MainActivity".equals(skip.getType())) { + page_vp_content.setCurrentItem(skip.getCurrentItem()); + } + } + + @Override + public void onHiddenChanged(boolean hidden) { + super.onHiddenChanged(hidden); + FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + List list = getChildFragmentManager().getFragments(); + if (list != null) { + if (hidden) { + for (Fragment fragment : getChildFragmentManager().getFragments()) { + transaction.hide(fragment); + } + } else { + for (Fragment fragment : getChildFragmentManager().getFragments()) { + transaction.show(fragment); + } + } + } + transaction.commit(); + } + +} diff --git a/app/src/main/java/com/gh/gamecenter/game/NewGameFragment.java b/app/src/main/java/com/gh/gamecenter/game/NewGameFragment.java deleted file mode 100644 index e94a640fa2..0000000000 --- a/app/src/main/java/com/gh/gamecenter/game/NewGameFragment.java +++ /dev/null @@ -1,323 +0,0 @@ -package com.gh.gamecenter.game; - -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.widget.SwipeRefreshLayout; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.view.View; -import android.widget.LinearLayout; - -import com.facebook.drawee.backends.pipeline.Fresco; -import com.gc.materialdesign.views.ProgressBarCircularIndeterminate; -import com.gh.common.util.DownloadItemUtils; -import com.gh.download.DataWatcher; -import com.gh.download.DownloadEntity; -import com.gh.download.DownloadManager; -import com.gh.gamecenter.R; -import com.gh.gamecenter.entity.ApkEntity; -import com.gh.gamecenter.entity.GameEntity; -import com.gh.gamecenter.entity.SubjectEntity; -import com.gh.gamecenter.eventbus.EBDownloadStatus; -import com.gh.gamecenter.eventbus.EBNetworkState; -import com.gh.gamecenter.eventbus.EBPackage; -import com.gh.gamecenter.eventbus.EBReuse; -import com.gh.gamecenter.eventbus.EBUISwitch; -import com.gh.gamecenter.listener.OnCallBackListener; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created by khy on 2016/12/6. - */ -public class NewGameFragment extends NewHomeFragment implements SwipeRefreshLayout.OnRefreshListener - , OnCallBackListener { - private SwipeRefreshLayout fm_game_swipe_refresh; - private RecyclerView fm_game_rv_list; - private NewGameFragmentAdapter adapter; - private LinearLayout reuse_no_connection; - private ProgressBarCircularIndeterminate fm_game_pb_loading; - - private View gameView; - - private int currentItem; - - private boolean isEverpause; - - private DataWatcher dataWatcher = new DataWatcher() { - @Override - public void onDataChanged(DownloadEntity downloadEntity) { - if (!fm_game_swipe_refresh.isRefreshing()) { - ArrayList locationList = adapter.getLocationMap().get(downloadEntity.getPackageName()); - if (locationList != null && locationList.size() != 0) { - GameEntity gameEntity; - for (int location : locationList) { - gameEntity = adapter.getGameEntityByLocation(location); - if (gameEntity != null) { - DownloadItemUtils.processDate(getActivity(), gameEntity, - downloadEntity, adapter, location); - } - } - } - } - } - }; - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - gameView = View.inflate(getActivity(), R.layout.fragment_game, null); - homeContent.addView(gameView); - currentItem = 0; - - isEverpause = false; - - reuse_no_connection = (LinearLayout) gameView.findViewById(R.id.reuse_no_connection); - fm_game_swipe_refresh = (SwipeRefreshLayout) gameView.findViewById(R.id.fm_game_swipe_refresh); - fm_game_rv_list = (RecyclerView) gameView.findViewById(R.id.fm_game_rv_list); - fm_game_pb_loading = (ProgressBarCircularIndeterminate) gameView.findViewById(R.id.fm_game_pb_loading); - - reuse_no_connection.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - fm_game_swipe_refresh.setRefreshing(true); - fm_game_rv_list.setVisibility(View.VISIBLE); - fm_game_pb_loading.setVisibility(View.VISIBLE); - reuse_no_connection.setVisibility(View.GONE); - handler.postDelayed(runnable, 1000); - } - }); - - fm_game_swipe_refresh.setColorSchemeResources(R.color.theme); - fm_game_swipe_refresh.setOnRefreshListener(this); - - fm_game_rv_list.setHasFixedSize(true); - fm_game_rv_list.setLayoutManager(new LinearLayoutManager(getActivity())); - adapter = new NewGameFragmentAdapter(NewGameFragment.this, fm_game_swipe_refresh); - fm_game_rv_list.setAdapter(adapter); - - fm_game_rv_list.setOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrollStateChanged(RecyclerView recyclerView, int newState) { - super.onScrollStateChanged(recyclerView, newState); - if (newState == RecyclerView.SCROLL_STATE_IDLE){ - Fresco.getImagePipeline().resume(); - }else { - Fresco.getImagePipeline().pause(); - } - } - }); - } - - @Override - public void loadDone() { - if (fm_game_swipe_refresh != null && fm_game_swipe_refresh.isRefreshing()) { - fm_game_swipe_refresh.setRefreshing(false); - } - if (fm_game_pb_loading != null && fm_game_pb_loading.getVisibility() == View.VISIBLE) { - fm_game_pb_loading.setVisibility(View.GONE); - } - } - - @Override - public void loadDone(Object obj) { - - } - - @Override - public void loadError() { - fm_game_rv_list.setVisibility(View.GONE); - fm_game_pb_loading.setVisibility(View.GONE); - reuse_no_connection.setVisibility(View.VISIBLE); - } - - @Override - public void loadEmpty() { - - } - - //下载被删除事件 - public void onEventMainThread(EBDownloadStatus status) { - if ("delete".equals(status.getStatus())) { - DownloadManager.getInstance(getActivity()).removePlatform(status.getName(), status.getPlatform()); - - ArrayList locationList = adapter.getLocationMap().get(status.getPackageName()); - GameEntity gameEntity; - if (locationList != null && locationList.size() != 0) { - for (int location : locationList) { - gameEntity = adapter.getGameEntityByLocation(location); - if (gameEntity != null && gameEntity.getEntryMap() != null) { - gameEntity.getEntryMap().remove(status.getPlatform()); - } - adapter.notifyItemChanged(location); - } - } - } else if ("plugin".equals(status.getStatus())) { - handler.postDelayed(initPluginRunnable, 100); - } - } - - Runnable initPluginRunnable = new Runnable() { - @Override - public void run() { - if (adapter.isInitPlugin()) { - handler.postDelayed(initPluginRunnable, 100); - } else { - adapter.initPlugin(); - } - } - }; - - //安装、卸载事件 - public void onEventMainThread(EBPackage busFour) { - ArrayList locationList = adapter.getLocationMap().get(busFour.getPackageName()); - if (locationList != null) { - GameEntity gameEntity; - for (int location : locationList) { - gameEntity = adapter.getGameEntityByLocation(location); - if (gameEntity != null) { - if (gameEntity.isPluggable()) { - // 插件化列表 - if ("安装".equals(busFour.getType()) || "卸载".equals(busFour.getType())) { - List list = adapter.getPluginList(); - for (int i = 0; i < list.size(); i++) { - if (list.get(i).getApk().get(0).getPackageName().equals(busFour.getPackageName())) { - if ("卸载".equals(busFour.getType()) - && DownloadManager.getInstance(getActivity()).get( - list.get(i).getApk().get(0).getUrl()) != null) { - adapter.notifyItemChanged(2 + i); - } else { - list.remove(i); - if (list.isEmpty()) { - adapter.initItemCount(); - adapter.notifyItemRangeRemoved(1, 2); -// adapter.notifyItemChanged(1); // 如果position是1为图片时 需要刷新卡片高度 - } else { - adapter.initItemCount(); - adapter.notifyItemRemoved(location); - adapter.notifyItemChanged(1); - } - } - break; - } - } - } - } else { - if ("安装".equals(busFour.getType())) { - for (ApkEntity apkEntity : gameEntity.getApk()) { - if (apkEntity.getPackageName().equals(busFour.getPackageName())) { - if (gameEntity.getEntryMap() != null) { - gameEntity.getEntryMap().remove(apkEntity.getPlatform()); - } - adapter.notifyItemChanged(location); - break; - } - } - } else if ("卸载".equals(busFour.getType())) { - adapter.notifyItemChanged(location); - } - } - } - } - adapter.initLocationMap(); - } - } - - //连接上网络事件 - public void onEventMainThread(EBNetworkState busNetworkState) { - if (busNetworkState.isNetworkConnected()) { - if (reuse_no_connection.getVisibility() == View.VISIBLE) { - fm_game_swipe_refresh.setRefreshing(true); - fm_game_rv_list.setVisibility(View.VISIBLE); - fm_game_pb_loading.setVisibility(View.GONE); - reuse_no_connection.setVisibility(View.GONE); - handler.postDelayed(runnable, 1000); - } else if (adapter.isNetworkError()) { - adapter.setNetworkError(false); - adapter.notifyItemChanged(adapter.getItemCount() - 1); - adapter.initSubjectDigest(true); - } - } - } - - // 打开下载按钮事件 - public void onEventMainThread(EBReuse reuse) { - if (("Refresh".equals(reuse.getType()) || "PlatformChanged".equals(reuse.getType())) - && adapter != null) { - adapter.notifyItemRangeChanged(0, adapter.getItemCount()); - } - } - - //Fragment界面切换事件 - public void onEventMainThread(EBUISwitch busNine) { - if ("MainActivity".equals(busNine.getFrom())) { - if (busNine.getPosition() == 0) { - adapter.startAutoScroll(); - } else { - adapter.stopAutoScroll(); - } - } else if ("GameFragment".equals(busNine.getFrom())) { - currentItem = busNine.getPosition(); - if (busNine.getPosition() == 0) { - adapter.startAutoScroll(); - if (fm_game_pb_loading.getVisibility() == View.VISIBLE) { - adapter.initSubjectDigest(true); - } - } else { - adapter.stopAutoScroll(); - } - } - } - - @Override - public void onResume() { - isEverpause = false; - - if (isEverpause) { - for (SubjectEntity subjectEntity : adapter.getSubjectList()) { - for (GameEntity entity :subjectEntity.getData()) { - entity.setEntryMap(DownloadManager.getInstance(getActivity()).getEntryMap(entity.getName())); - } - } - for (GameEntity entity : adapter.getPluginList()) { - entity.setEntryMap(DownloadManager.getInstance(getActivity()).getEntryMap(entity.getName())); - } - adapter.notifyDataSetChanged(); - } - super.onResume(); - DownloadManager.getInstance(getActivity()).addObserver(dataWatcher); - if (currentItem == 0) { - adapter.startAutoScroll(); - } - } - - @Override - public void onPause() { - super.onPause(); - isEverpause = true; - DownloadManager.getInstance(getActivity()).removeObserver(dataWatcher); - if (currentItem == 0) { - adapter.stopAutoScroll(); - } - } - - Runnable runnable = new Runnable() { - @Override - public void run() { - adapter = new NewGameFragmentAdapter(NewGameFragment.this, fm_game_swipe_refresh); - fm_game_rv_list.setAdapter(adapter); -// adapter.initSlide(true); - } - }; - - public boolean isEverpause() { - return isEverpause; - } - - @Override - public void onRefresh() { - handler.postDelayed(runnable, 1000); - } -} diff --git a/app/src/main/java/com/gh/gamecenter/game/NewHomeFragment.java b/app/src/main/java/com/gh/gamecenter/game/NewHomeFragment.java deleted file mode 100644 index 8badfc4353..0000000000 --- a/app/src/main/java/com/gh/gamecenter/game/NewHomeFragment.java +++ /dev/null @@ -1,241 +0,0 @@ -package com.gh.gamecenter.game; - -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Build; -import android.os.Bundle; -import android.os.Handler; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentTransaction; -import android.text.TextUtils; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.LinearLayout; -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.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.eventbus.EBDownloadStatus; -import com.gh.gamecenter.eventbus.EBReuse; -import com.gh.gamecenter.manager.DataCollectionManager; -import com.gh.gamecenter.manager.PackageManager; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import de.greenrobot.event.EventBus; - -/** - * Created by LGT on 2016/9/9. - * 工具栏 搜索控制 - */ -public class NewHomeFragment extends Fragment implements View.OnClickListener { - - protected View view; - - protected RelativeLayout homeContent; - - protected Handler handler = new Handler(); - - private TextView downloadHint; - private TextView searchHint; - - private String hint; - - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - if (!TextUtils.isEmpty(hint)) { - outState.putString("hint", hint); - } - } - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - if (savedInstanceState != null) { - hint = savedInstanceState.getString("hint"); - } - - view = View.inflate(getActivity(), R.layout.fragment_newhome, null); - homeContent = (RelativeLayout) view.findViewById(R.id.home_content); - - 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(); - - 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; - } - - private void initActionBar() { - view.findViewById(R.id.actionbar_rl_download).setOnClickListener(this); - view.findViewById(R.id.actionbar_iv_search).setOnClickListener(this); - view.findViewById(R.id.actionbar_notification).setOnClickListener(this); - - if (Config.isShow(getActivity())) { - 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(String.valueOf(downloadSize)); - } else if (updateSize != 0) { - downloadHint.setVisibility(View.VISIBLE); - downloadHint.setText(String.valueOf(updateSize)); - } else { - downloadHint.setVisibility(View.GONE); - } - - searchHint = (TextView) view.findViewById(R.id.actionbar_search_input); - searchHint.setOnClickListener(this); - if (!TextUtils.isEmpty(hint)) { - searchHint.setHint(hint); - } - } - - @Override - public void onClick(View v) { - final int id = v.getId(); - if (id == R.id.actionbar_notification) { - DataUtils.onEvent(getActivity(), "主页", "关注图标"); - - Map map = new HashMap<>(); - map.put("location", "关注图标"); - 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 map = new HashMap<>(); - map.put("location", "下载图标"); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); - - startActivity(new Intent(getActivity(), DownloadManagerActivity.class)); - } else if (id == R.id.actionbar_search_input) { - DataUtils.onEvent(getActivity(), "主页", "搜索框"); - - Map map = new HashMap<>(); - map.put("location", "搜索框"); - 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 map = new HashMap<>(); - map.put("location", "搜索图标"); - 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); - } - } - - // 打开下载按钮事件 - public void onEventMainThread(EBReuse reuse) { - if ("Refresh".equals(reuse.getType())) { - if (Config.isShow(getActivity())) { - view.findViewById(R.id.actionbar_rl_download).setVisibility(View.VISIBLE); - } else { - view.findViewById(R.id.actionbar_rl_download).setVisibility(View.GONE); - } - } - } - - public void setHint(String hint) { - if (!TextUtils.isEmpty(hint)) { - this.hint = hint; - if (searchHint != null) { - searchHint.setHint(hint); - } - } - } - - public void onEventMainThread(EBDownloadStatus status) { - int updateSize = PackageManager.getUpdateListSize(); - int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size(); - if (downloadSize != 0) { - downloadHint.setVisibility(View.VISIBLE); - downloadHint.setText(String.valueOf(downloadSize)); - } else if (updateSize != 0) { - downloadHint.setVisibility(View.VISIBLE); - downloadHint.setText(String.valueOf(updateSize)); - } else { - downloadHint.setVisibility(View.GONE); - } - } - - @Override - public void onHiddenChanged(boolean hidden) { - super.onHiddenChanged(hidden); - FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); - List list = getChildFragmentManager().getFragments(); - if (list != null) { - if (hidden) { - for (Fragment fragment : getChildFragmentManager().getFragments()) { - transaction.hide(fragment); - } - } else { - for (Fragment fragment : getChildFragmentManager().getFragments()) { - transaction.show(fragment); - } - } - } - transaction.commit(); - } - - @Override - public void onDestroy() { - super.onDestroy(); - EventBus.getDefault().unregister(this); - } -} diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java index 74917bee9d..a86b1174a6 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailAdapter.java @@ -17,6 +17,7 @@ import android.widget.Toast; import com.facebook.drawee.view.SimpleDraweeView; import com.gh.common.util.ConcernUtils; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.DisplayUtils; @@ -36,7 +37,6 @@ import com.gh.gamecenter.entity.ServerEntity; import com.gh.gamecenter.entity.TagEntity; import com.gh.gamecenter.listener.OnCallBackListener; import com.gh.gamecenter.manager.ConcernManager; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.retrofit.JSONObjectResponse; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -443,12 +443,7 @@ public class GameDetailAdapter extends RecyclerView.Adapter { kv.put("位置", "资讯攻略-全部"); DataUtils.onEvent(context, "点击", "游戏详情", kv); - Map map = new HashMap<>(); - map.put("location", "资讯攻略-全部"); - map.put("page", "游戏详情"); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "资讯攻略-全部", "游戏详情", gameEntity.getName()); Intent intent = new Intent(context, GameNewsActivity.class); intent.putExtra("articleTypes", gameDetailEntity.getArticleTypes()); @@ -489,12 +484,7 @@ public class GameDetailAdapter extends RecyclerView.Adapter { kv.put("位置", String.valueOf(ii + 1)); DataUtils.onEvent(context, "点击", "游戏详情-资讯攻略", kv); - Map map = new HashMap<>(); - map.put("location", "资讯攻略"); - map.put("page", "游戏详情"); - map.put("news", newsEntity.getTitle()); - map.put("news_id", newsEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "资讯攻略", "游戏详情", newsEntity.getTitle()); // 统计阅读量 NewsUtils.statNewsViews(newsEntity.getId()); @@ -684,11 +674,7 @@ public class GameDetailAdapter extends RecyclerView.Adapter { kv2.put("点击", "关注"); DataUtils.onEvent(context, "插件数据", gameEntity.getName(), kv2); - Map map = new HashMap<>(); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - map.put("type", "关注"); - DataCollectionManager.onEvent(context, "concern", map); + DataCollectionUtils.uploadConcern(context, gameEntity.getName(), gameEntity.getId(), "关注"); concernManager.addByEntity(gameEntity); concern.setText("取消关注"); @@ -698,8 +684,7 @@ public class GameDetailAdapter extends RecyclerView.Adapter { Toast.makeText(context, "关注成功", Toast.LENGTH_SHORT).show(); // 添加关注 - String uuid = TokenUtils.getDeviceId(context); - ConcernUtils.postConcernGameId(uuid, gameEntity.getId()); + ConcernUtils.postConcernGameId(context, gameEntity.getId()); } else { Map kv2 = new HashMap<>(); kv2.put("点击", "取消关注"); @@ -712,11 +697,8 @@ public class GameDetailAdapter extends RecyclerView.Adapter { kv.put("状态", "取消关注"); DataUtils.onEvent(context, "游戏关注", gameEntity.getName(), kv); - Map map = new HashMap<>(); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - map.put("type", "关注"); - DataCollectionManager.onEvent(context, "concern", map); + DataCollectionUtils.uploadConcern(context, + gameEntity.getName(), gameEntity.getId(), "取消关注"); concernManager.deleteConcern(gameEntity.getId()); concern.setText("关注"); @@ -724,8 +706,7 @@ public class GameDetailAdapter extends RecyclerView.Adapter { concern.setTextColor(0xffffffff); // 取消关注 - String uuid = TokenUtils.getDeviceId(context); - ConcernUtils.deleteConcernData(uuid, gameEntity.getId()); + ConcernUtils.deleteConcernData(context, gameEntity.getId()); } }); } diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailNewsServerAdapter.java b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailNewsServerAdapter.java index 004898cf03..c2d8312f2e 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailNewsServerAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailNewsServerAdapter.java @@ -12,7 +12,6 @@ import com.gh.gamecenter.R; import com.gh.gamecenter.entity.ServerEntity; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.List; import java.util.Locale; diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/GameGalleryAdapter.java b/app/src/main/java/com/gh/gamecenter/gamedetail/GameGalleryAdapter.java index aff9d83fd7..b701113e11 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/GameGalleryAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameGalleryAdapter.java @@ -7,10 +7,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.gamecenter.R; import com.gh.gamecenter.ViewImageActivity; -import com.gh.gamecenter.manager.DataCollectionManager; import java.util.ArrayList; import java.util.HashMap; @@ -18,6 +18,7 @@ import java.util.Map; /** * Created by LGT on 2016/9/8. + * */ public class GameGalleryAdapter extends RecyclerView.Adapter { @@ -47,10 +48,7 @@ public class GameGalleryAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "游戏介绍"); - map.put("page", "游戏详情"); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "游戏介绍", "游戏详情"); Intent intent = new Intent(context, ViewImageActivity.class); intent.putExtra("urls", gallery); diff --git a/app/src/main/java/com/gh/gamecenter/gift/Gift2FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/gift/Gift2FragmentAdapter.java index 806aaefff1..1d9975d2d8 100644 --- a/app/src/main/java/com/gh/gamecenter/gift/Gift2FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/gift/Gift2FragmentAdapter.java @@ -194,8 +194,7 @@ public class Gift2FragmentAdapter extends RecyclerView.Adapter map) { - String version = PackageUtils.getVersion(mContext); + String version = PackageUtils.getVersionName(mContext); String user = DeviceUtils.getDeviceID(mContext); String channel = (String) PackageUtils.getMetaData(mContext, mContext.getPackageName(), "TD_CHANNEL_ID"); @@ -203,7 +203,7 @@ public class DataCollectionManager { final List ids = new ArrayList<>(); - String version = PackageUtils.getVersion(mContext); + String version = PackageUtils.getVersionName(mContext); String user = DeviceUtils.getDeviceID(mContext); String channel = (String) PackageUtils.getMetaData(mContext, mContext.getPackageName(), "TD_CHANNEL_ID"); diff --git a/app/src/main/java/com/gh/gamecenter/manager/FilterManager.java b/app/src/main/java/com/gh/gamecenter/manager/FilterManager.java index 3b025983e5..0d38eb3b6c 100644 --- a/app/src/main/java/com/gh/gamecenter/manager/FilterManager.java +++ b/app/src/main/java/com/gh/gamecenter/manager/FilterManager.java @@ -9,6 +9,9 @@ import com.gh.gamecenter.db.info.FilterInfo; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; @@ -18,34 +21,38 @@ import rx.schedulers.Schedulers; public class FilterManager { private FilterDao dao; - private SharedPreferences sp; + private Context context; public FilterManager(Context context) { + this.context = context; dao = new FilterDao(context); - sp = context.getSharedPreferences(Config.PREFERENCE, - Context.MODE_PRIVATE); - } - - public void addFilter(String packageName) { - dao.add(new FilterInfo(packageName)); } public void addAllFilter(List list) { dao.addAll(list); } - public void deleteGame(String packageName) { - dao.delete(packageName); - } - - public List getAllGame() { - return dao.getAll(); - } - public boolean isFilter(String packageName) { return dao.isFilter(packageName); } + public void loadFilter() { + try { + List list = new ArrayList<>(); + BufferedReader reader = new BufferedReader(new InputStreamReader(context.getAssets().open("package.txt"))); + String line; + while ((line = reader.readLine()) != null) { + list.add(new FilterInfo(line)); + } + reader.close(); + addAllFilter(list); + SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); + sp.edit().putBoolean("isLoadFilter", true).apply(); + } catch (IOException e) { + e.printStackTrace(); + } + } + public void getFilterFromServer(final String today) { RetrofitManager.getApi().getPackageUnused(dao.getCount()) .subscribeOn(Schedulers.io()) @@ -57,12 +64,15 @@ public class FilterManager { for (String packageName : response) { list.add(new FilterInfo(packageName)); } - dao.addAll(list); - sp.edit().putString("filter_time", today).apply(); - if (list.size() == 500){ + addAllFilter(list); + if (list.size() == 500) { getFilterFromServer(today); + } else { + SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); + sp.edit().putString("filter_time", today).apply(); } } }); } + } diff --git a/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java b/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java new file mode 100644 index 0000000000..4b0a39d792 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java @@ -0,0 +1,313 @@ +package com.gh.gamecenter.manager; + +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.text.Html; +import android.view.View; +import android.view.Window; +import android.widget.ProgressBar; +import android.widget.TextView; +import android.widget.Toast; + +import com.gh.base.AppController; +import com.gh.common.constant.Config; +import com.gh.common.util.DataLogUtils; +import com.gh.common.util.DataUtils; +import com.gh.common.util.DialogUtils; +import com.gh.common.util.FileUtils; +import com.gh.common.util.MD5Utils; +import com.gh.common.util.PackageUtils; +import com.gh.common.util.SpeedUtils; +import com.gh.common.util.Utils; +import com.gh.download.DataWatcher; +import com.gh.download.DownloadEntity; +import com.gh.download.DownloadManager; +import com.gh.download.DownloadStatus; +import com.gh.gamecenter.R; +import com.gh.gamecenter.entity.AppEntity; +import com.gh.gamecenter.entity.GameUpdateEntity; +import com.gh.gamecenter.retrofit.Response; +import com.gh.gamecenter.retrofit.RetrofitManager; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +import retrofit2.adapter.rxjava.HttpException; +import rx.android.schedulers.AndroidSchedulers; +import rx.functions.Func1; +import rx.schedulers.Schedulers; + +/** + * Created by LGT on 2016/12/8. + * 助手更新 工具类 + */ +public class UpdateManager { + + private Context context; + + private AppEntity appEntity; + + private Dialog downloadDialog; + private ProgressBar app_pb_progress; + private TextView app_tv_speed; + private TextView app_tv_percent; + + private Dialog loadingDialog; + + private boolean isShowDownload; + private boolean isChecking; + + private UpdateManager(Context context) { + this.context = context; + this.isShowDownload = false; + this.isChecking = false; + this.loadingDialog = null; + } + + public static UpdateManager getInstance(Context context) { + return new UpdateManager(context); + } + + // 检查更新 + public void checkUpdate(final boolean isCheck) { + if (isChecking) { + return; + } + isChecking = true; + if (!isCheck) { + loadingDialog = DialogUtils.showWaitDialog(context, "检查更新中..."); + } + String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(context, context.getPackageName(), "TD_CHANNEL_ID"); + RetrofitManager.getApi().getUpdate(PackageUtils.getVersionName(context), TD_CHANNEL_ID) + .map(new Func1() { + @Override + public String call(AppEntity appEntity) { + String md5 = null; + + float version = Float.valueOf(appEntity.getVersion()); + float currentVersion = Float.valueOf(PackageUtils.getVersionName(context)); + if (version > currentVersion) { + // 助手有更新 + UpdateManager.this.appEntity = appEntity; + + // 添加到更新列表 + GameUpdateEntity gameUpdateEntity = new GameUpdateEntity(); + gameUpdateEntity.setName("光环助手V" + appEntity.getVersion()); + gameUpdateEntity.setPackageName(context.getPackageName()); + gameUpdateEntity.setSize(appEntity.getSize()); + gameUpdateEntity.setVersion(appEntity.getVersion()); + gameUpdateEntity.setUrl(appEntity.getUrl()); + gameUpdateEntity.setPlatform("官方版"); + gameUpdateEntity.setId("5618b86e8ab49e17088b4575"); + PackageManager.addUpdate(0, gameUpdateEntity); + + if (isCheck) { + if (appEntity.isForce()) { + // 强制更新 + md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent()); + } else { + // 非强制更新 + if ("EVERY_TIME_OPEN".equals(appEntity.getAlert())) { + // 每次都提示 + md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent()); + } else if (!"NEVER".equals(appEntity.getAlert())){ + // 一天提示一次 + SharedPreferences sp = context.getSharedPreferences( + Config.PREFERENCE, Context.MODE_PRIVATE); + String showUpdateTime = sp.getString("show_update_tiem", null); + SimpleDateFormat format = new SimpleDateFormat( + "yyyy-MM-dd", Locale.getDefault()); + String today = format.format(new Date()); + if (!today.equals(showUpdateTime)) { + sp.edit().putString("show_update_tiem", today).apply(); + md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent()); + } + } + } + } else { + md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent()); + } + } + + return md5; + } + }) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onResponse(String response) { + isChecking = false; + if (loadingDialog != null) { + loadingDialog.dismiss(); + } + if (response != null) { + showUpdateDialog(response); + } else if (!isCheck) { + Toast.makeText(context, "已是最新版本", Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onFailure(Throwable e) { + isChecking = false; + if (loadingDialog != null) { + loadingDialog.dismiss(); + } + if (!isCheck) { + if (e instanceof HttpException) { + HttpException exception = (HttpException) e; + if (exception.code() == 304) { + Toast.makeText(context, "您的光环助手已是最新版本", Toast.LENGTH_SHORT).show(); + return; + } + } + + Toast.makeText(context, "检查更新失败", Toast.LENGTH_SHORT).show(); + } + } + }); + } + + // 显示助手有更新提示框 + private void showUpdateDialog(final String md5) { + final Dialog updateDialog = new Dialog(context); + + View view = View.inflate(context, R.layout.app_update_hint_dialog, null); + + TextView content = (TextView) view.findViewById(R.id.updeta_content); + content.setText(Html.fromHtml(appEntity.getContent())); + + TextView versison = (TextView) view.findViewById(R.id.update_app_version); + versison.setText(String.format("光环助手V%s更新内容:", appEntity.getVersion())); + + TextView size = (TextView) view.findViewById(R.id.update_app_size); + size.setText(String.format("大小:%s", appEntity.getSize())); + + view.findViewById(R.id.update_cannel).setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + if (appEntity.isForce()) { + AppController.getInstance().finishActivity(); + } else { + updateDialog.dismiss(); + } + } + }); + + view.findViewById(R.id.updeta_confirm).setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + updateDialog.dismiss(); + String path = FileUtils.getDownloadPath(context, + "光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk"); + File file = new File(path); + if (file.exists() && file.length() > 0) { + DataLogUtils.uploadUpgradeLog(context, "install"); //上传更新安装数据 + context.startActivity(PackageUtils.getInstallIntent(path)); + } else { + DataUtils.onEvent(context, "软件更新", "下载开始"); + showDownloadDialog(md5); + } + } + }); + + if (appEntity.isForce()) { + updateDialog.setCanceledOnTouchOutside(false); + updateDialog.setCancelable(false); + } + updateDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + updateDialog.setContentView(view); + updateDialog.show(); + + DataLogUtils.uploadUpgradeLog(context, "notice"); //上传更新通知弹窗数据 + } + + private DataWatcher dataWatcher = new DataWatcher() { + @Override + public void onDataChanged(DownloadEntity downloadEntity) { + if (downloadEntity.getName().contains("光环助手") && isShowDownload) { + app_tv_speed.setText(String.format("%s(剩%s)", SpeedUtils.getSpeed(downloadEntity.getSpeed()), + SpeedUtils.getRemainTime(downloadEntity.getSize(), + downloadEntity.getProgress(), downloadEntity.getSpeed() * 1024))); + app_pb_progress.setProgress((int) (downloadEntity.getPercent() * 10)); + app_tv_percent.setText(String.format( + Locale.getDefault(), "%s%%", String.valueOf(downloadEntity.getPercent()))); + if (DownloadStatus.done.equals(downloadEntity.getStatus())) { + DownloadManager.getInstance(context).cancel(downloadEntity.getUrl(), false); + if (downloadDialog != null) { + downloadDialog.dismiss(); + } + if (appEntity != null && appEntity.isForce()) { + AppController.getInstance().finishActivity(); + } + } + } + } + }; + + private void showDownloadDialog(String md5) { + downloadDialog = new Dialog(context); + + View view = View.inflate(context, R.layout.app_updating_dialog, null); + + app_pb_progress = (ProgressBar) view.findViewById(R.id.app_pb_progress); + app_tv_speed = (TextView) view.findViewById(R.id.app_tv_speed); + app_tv_percent = (TextView) view.findViewById(R.id.app_tv_percent); + + view.findViewById(R.id.app_tv_cancel).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + DownloadManager.getInstance(context).cancel(appEntity.getUrl()); + if (appEntity.isForce()) { + AppController.getInstance().finishActivity(); + } else { + downloadDialog.dismiss(); + } + } + }); + + downloadDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + DownloadManager.getInstance(context).removeObserver(dataWatcher); + isShowDownload = false; + } + }); + + downloadDialog.setCanceledOnTouchOutside(false); + downloadDialog.setCancelable(false); + downloadDialog.closeOptionsMenu(); + downloadDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + downloadDialog.setContentView(view); + downloadDialog.show(); + + isShowDownload = true; + + DownloadManager.getInstance(context).addObserver(dataWatcher); + + // 添加到下载列表 + String path = FileUtils.getDownloadPath(context, "光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk"); + File file = new File(path); + if (file.exists() && file.delete()) { + Utils.log(file.getName() + " file delete success."); + } + + DownloadEntity downloadEntity = new DownloadEntity(); + downloadEntity.setUrl(appEntity.getUrl()); + downloadEntity.setName("光环助手V" + appEntity.getVersion()); + downloadEntity.setPath(path); + downloadEntity.setPlatform("官方版"); + downloadEntity.setPackageName(context.getPackageName()); + DownloadManager.getInstance(context).cancel(downloadEntity.getUrl(), false); + DownloadManager.getInstance(context).pauseAll(); + DownloadManager.getInstance(context).add(downloadEntity); + } + +} diff --git a/app/src/main/java/com/gh/gamecenter/news/News1Fragment.java b/app/src/main/java/com/gh/gamecenter/news/News1Fragment.java index 6d0ab87fc0..124c804f77 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News1Fragment.java +++ b/app/src/main/java/com/gh/gamecenter/news/News1Fragment.java @@ -98,10 +98,10 @@ public class News1Fragment extends BaseFragment implements SwipeRefreshLayout.On SharedPreferences sp = getActivity().getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); - isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersion(getActivity()), true); + isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(getActivity()), true); if (isNewFirstLaunch) { - sp.edit().putBoolean("isNewFirstLaunchV" + PackageUtils.getVersion(getActivity()), false).apply(); + sp.edit().putBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(getActivity()), false).apply(); } refreshLayout.setColorSchemeResources(R.color.theme); @@ -252,14 +252,6 @@ public class News1Fragment extends BaseFragment implements SwipeRefreshLayout.On handler.postDelayed(runnable, 1000); } - private int count; - - private void addCount() { - synchronized (News1Fragment.class) { - count++; - } - } - // 推荐关注改为手机安装的游戏+光环助手 private void initInstallGame() { recommendGameList.clear();//清除上一次记录 @@ -297,44 +289,34 @@ public class News1Fragment extends BaseFragment implements SwipeRefreshLayout.On }, new Action1>() { @Override public void call(final List installedList) { - count = 0; - final List gameList = new ArrayList<>(); - final int size = installedList.size() + 1; - String gameId; - for (int i = 0; i < size; i++) { + List> sequences = new ArrayList<>(); + for (int i = 0, size = installedList.size() + 1; i < size; i++) { if (i == size - 1) { - gameId = "5618b86e8ab49e17088b4575"; // 光环助手ID + sequences.add(RetrofitManager.getApi().getGameDigest("5618b86e8ab49e17088b4575"));// 光环助手ID } else { - gameId = installedList.get(i).getId(); + sequences.add(RetrofitManager.getApi().getGameDigest(installedList.get(i).getId())); } - RetrofitManager.getApi().getGameDigest(gameId) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(GameEntity response) { - if (response.getId().equals("5618b86e8ab49e17088b4575")) { - recommendGameList.add(response); - } else { - gameList.add(response); - } - addCount(); - if (count == size) { - initRecommendConcern(installedList, gameList); - } - } - - @Override - public void onFailure(Throwable e) { - addCount(); - if (count == size) { - initRecommendConcern(installedList, gameList); - } - } - }); } + Observable.merge(sequences) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onNext(GameEntity response) { + if (response.getId().equals("5618b86e8ab49e17088b4575")) { + recommendGameList.add(response); + } else { + gameList.add(response); + } + } + + @Override + public void onCompleted() { + initRecommendConcern(installedList, gameList); + } + }); } }); } diff --git a/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java index 95c6a398ef..52b056be20 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java @@ -15,6 +15,7 @@ import com.gh.base.AppController; import com.gh.common.constant.ItemViewType; import com.gh.common.util.ConcernContentUtils; import com.gh.common.util.ConcernUtils; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.GiftUtils; @@ -22,7 +23,6 @@ import com.gh.common.util.MD5Utils; import com.gh.common.util.NewsUtils; import com.gh.common.util.PlatformUtils; import com.gh.common.util.TokenUtils; -import com.gh.common.util.Utils; import com.gh.common.view.CardLinearLayout; import com.gh.gamecenter.GiftDetailActivity; import com.gh.gamecenter.MessageDetailActivity; @@ -45,7 +45,6 @@ import com.gh.gamecenter.entity.ViewsEntity; import com.gh.gamecenter.listener.OnCallBackListener; import com.gh.gamecenter.manager.CommentManager; import com.gh.gamecenter.manager.ConcernManager; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.VisitManager; import com.gh.gamecenter.retrofit.JSONObjectResponse; import com.gh.gamecenter.retrofit.ObservableUtil; @@ -231,8 +230,7 @@ public class News1FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", "资讯-关注"); - map.put("news", concernEntity.getTitle()); - map.put("news_id", concernEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "列表", "资讯-关注", concernEntity.getTitle()); //统计阅读量 statNewsViews(concernEntity, viewHolder.getPosition()); diff --git a/app/src/main/java/com/gh/gamecenter/news/News2FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/news/News2FragmentAdapter.java index d6f6055c15..555fb400b6 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News2FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/news/News2FragmentAdapter.java @@ -10,6 +10,7 @@ import android.widget.LinearLayout; import android.widget.Toast; import com.gh.common.constant.ItemViewType; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.ImageUtils; @@ -23,7 +24,6 @@ import com.gh.gamecenter.adapter.viewholder.NewsImage3ViewHolder; import com.gh.gamecenter.entity.NewsEntity; import com.gh.gamecenter.entity.ViewsEntity; import com.gh.gamecenter.listener.OnCallBackListener; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.VisitManager; import com.gh.gamecenter.retrofit.JSONObjectResponse; import com.gh.gamecenter.retrofit.ObservableUtil; @@ -253,12 +253,7 @@ public class News2FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", "资讯-资讯"); - map.put("news", newsEntity.getTitle()); - map.put("news_id", newsEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "列表", "资讯-资讯", newsEntity.getTitle()); //统计阅读量 statNewsViews(newsEntity, viewHolder.getPosition()); @@ -319,12 +314,7 @@ public class News2FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", "资讯-资讯"); - map.put("news", newsEntity.getTitle()); - map.put("news_id", newsEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "列表", "资讯-资讯", newsEntity.getTitle()); //统计阅读量 statNewsViews(newsEntity, viewHolder.getPosition()); @@ -371,12 +361,7 @@ public class News2FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", "资讯-资讯"); - map.put("news", newsEntity.getTitle()); - map.put("news_id", newsEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "列表", "资讯-资讯", newsEntity.getTitle()); //统计阅读量 statNewsViews(newsEntity, viewHolder.getPosition()); diff --git a/app/src/main/java/com/gh/gamecenter/news/News3FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/news/News3FragmentAdapter.java index 9d020df094..8cd26e1ef4 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News3FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/news/News3FragmentAdapter.java @@ -10,6 +10,7 @@ import android.widget.LinearLayout; import android.widget.Toast; import com.gh.common.constant.ItemViewType; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.ImageUtils; @@ -23,7 +24,6 @@ import com.gh.gamecenter.adapter.viewholder.NewsImage3ViewHolder; import com.gh.gamecenter.entity.NewsEntity; import com.gh.gamecenter.entity.ViewsEntity; import com.gh.gamecenter.listener.OnCallBackListener; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.VisitManager; import com.gh.gamecenter.retrofit.JSONObjectResponse; import com.gh.gamecenter.retrofit.ObservableUtil; @@ -251,12 +251,7 @@ public class News3FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", "资讯-原创"); - map.put("news", newsEntity.getTitle()); - map.put("news_id", newsEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "列表", "资讯-原创", newsEntity.getTitle()); //统计阅读量 statNewsViews(newsEntity, viewHolder.getPosition()); @@ -317,12 +312,7 @@ public class News3FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", "资讯-原创"); - map.put("news", newsEntity.getTitle()); - map.put("news_id", newsEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "列表", "资讯-原创", newsEntity.getTitle()); //统计阅读量 statNewsViews(newsEntity, viewHolder.getPosition()); @@ -369,12 +359,7 @@ public class News3FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", "资讯-原创"); - map.put("news", newsEntity.getTitle()); - map.put("news_id", newsEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "列表", "资讯-原创", newsEntity.getTitle()); //统计阅读量 statNewsViews(newsEntity, viewHolder.getPosition()); diff --git a/app/src/main/java/com/gh/gamecenter/news/News4FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/news/News4FragmentAdapter.java index 418e95c268..5cbd3f583e 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News4FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/news/News4FragmentAdapter.java @@ -10,6 +10,7 @@ import android.view.ViewGroup; import android.widget.Toast; import com.gh.common.constant.ItemViewType; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.NewsUtils; @@ -22,7 +23,6 @@ import com.gh.gamecenter.adapter.viewholder.NewsImageViewHolder; import com.gh.gamecenter.adapter.viewholder.NewsTextViewHolder; import com.gh.gamecenter.entity.NewsEntity; import com.gh.gamecenter.listener.OnCallBackListener; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -296,12 +296,7 @@ public class News4FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "今天-大图"); - map.put("page", "资讯-攻略"); - map.put("news", newsEntity.getTitle()); - map.put("news_id", newsEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "今天-大图", "资讯-攻略", newsEntity.getTitle()); // 统计阅读量 NewsUtils.statNewsViews(newsEntity.getId()); @@ -377,12 +372,7 @@ public class News4FragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", entrance); - map.put("page", "资讯-攻略"); - map.put("news", newsEntity.getTitle()); - map.put("news_id", newsEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, entrance, "资讯-攻略", newsEntity.getTitle()); // 统计阅读量 NewsUtils.statNewsViews(newsEntity.getId()); diff --git a/app/src/main/java/com/gh/gamecenter/news/NewsFragment.java b/app/src/main/java/com/gh/gamecenter/news/NewsFragment.java index 9ce0fc9440..eb2a5152d0 100644 --- a/app/src/main/java/com/gh/gamecenter/news/NewsFragment.java +++ b/app/src/main/java/com/gh/gamecenter/news/NewsFragment.java @@ -3,6 +3,7 @@ package com.gh.gamecenter.news; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewPager; import android.util.DisplayMetrics; import android.view.Gravity; @@ -27,6 +28,12 @@ import de.greenrobot.event.EventBus; */ public class NewsFragment extends HomeFragment implements View.OnClickListener, ViewPager.OnPageChangeListener { + private LinearLayout slidebar_ll_top; + private View slidebar_line; + private ViewPager page_vp_content; + + private LinearLayout.LayoutParams lparams; + private TextView tv_guanzhu; private TextView tv_zixun; private TextView tv_yuanchuang; @@ -44,19 +51,26 @@ public class NewsFragment extends HomeFragment implements View.OnClickListener, public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + ((LinearLayout) view).addView(View.inflate(getActivity(), R.layout.fragment_slidebar, null)); + ((LinearLayout) view).addView(View.inflate(getActivity(), R.layout.fragment_page, null)); + + slidebar_ll_top = (LinearLayout) view.findViewById(R.id.slidebar_ll_top); + slidebar_line = view.findViewById(R.id.slidebar_line); + page_vp_content = (ViewPager) view.findViewById(R.id.page_vp_content); + List list = new ArrayList<>(); list.add(new News1Fragment()); list.add(new News2Fragment()); list.add(new News3Fragment()); - home_vp_content.setAdapter(new FragmentAdapter(getChildFragmentManager(), list)); - home_vp_content.addOnPageChangeListener(this); + page_vp_content.setAdapter(new FragmentAdapter(getChildFragmentManager(), list)); + page_vp_content.addOnPageChangeListener(this); currentItem = 0; if (savedInstanceState != null) { currentItem = savedInstanceState.getInt("currentItem"); } initTextView(); - home_vp_content.setCurrentItem(currentItem); + page_vp_content.setCurrentItem(currentItem); DisplayMetrics outMetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics); @@ -64,12 +78,12 @@ public class NewsFragment extends HomeFragment implements View.OnClickListener, lparams = new LinearLayout.LayoutParams(width / 2, DisplayUtils.dip2px(getActivity(), 2)); lparams.leftMargin = (int) (width * (currentItem + 0.25f)); - home_slide_line.setLayoutParams(lparams); + slidebar_line.setLayoutParams(lparams); handler.postDelayed(new Runnable() { @Override public void run() { - EventBus.getDefault().post(new EBUISwitch("NewsFragment", home_vp_content.getCurrentItem())); + EventBus.getDefault().post(new EBUISwitch("NewsFragment", page_vp_content.getCurrentItem())); } }, 100); } @@ -87,7 +101,7 @@ public class NewsFragment extends HomeFragment implements View.OnClickListener, LinearLayout.LayoutParams lparams4 = new LinearLayout.LayoutParams( 0, DisplayUtils.dip2px(getActivity(), 35)); lparams4.weight = 1; - home_ll_top.addView(tv_guanzhu, lparams4); + slidebar_ll_top.addView(tv_guanzhu, lparams4); tv_zixun = new TextView(getActivity()); tv_zixun.setText("资讯"); @@ -101,7 +115,7 @@ public class NewsFragment extends HomeFragment implements View.OnClickListener, LinearLayout.LayoutParams lparams1 = new LinearLayout.LayoutParams( 0, DisplayUtils.dip2px(getActivity(), 35)); lparams1.weight = 1; - home_ll_top.addView(tv_zixun, lparams1); + slidebar_ll_top.addView(tv_zixun, lparams1); tv_yuanchuang = new TextView(getActivity()); tv_yuanchuang.setText("原创"); @@ -115,18 +129,18 @@ public class NewsFragment extends HomeFragment implements View.OnClickListener, LinearLayout.LayoutParams lparams2 = new LinearLayout.LayoutParams( 0, DisplayUtils.dip2px(getActivity(), 35)); lparams2.weight = 1; - home_ll_top.addView(tv_yuanchuang, lparams2); + slidebar_ll_top.addView(tv_yuanchuang, lparams2); } @Override public void onClick(View v) { super.onClick(v); if (v == tv_zixun) { - home_vp_content.setCurrentItem(1); + page_vp_content.setCurrentItem(1); } else if (v == tv_yuanchuang) { - home_vp_content.setCurrentItem(2); + page_vp_content.setCurrentItem(2); } else if (v == tv_guanzhu) { - home_vp_content.setCurrentItem(0); + page_vp_content.setCurrentItem(0); } } @@ -134,10 +148,10 @@ public class NewsFragment extends HomeFragment implements View.OnClickListener, public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (positionOffset != 0) { lparams.leftMargin = (int) (width * (position + positionOffset + 0.25f)); - home_slide_line.setLayoutParams(lparams); + slidebar_line.setLayoutParams(lparams); } else { - if (currentItem != home_vp_content.getCurrentItem()) { - currentItem = home_vp_content.getCurrentItem(); + if (currentItem != page_vp_content.getCurrentItem()) { + currentItem = page_vp_content.getCurrentItem(); EventBus.getDefault().post(new EBUISwitch("NewsFragment", currentItem)); } } @@ -168,10 +182,29 @@ public class NewsFragment extends HomeFragment implements View.OnClickListener, public void onEventMainThread(EBUISwitch busNine) { if ("MainActivity".equals(busNine.getFrom())) { if (busNine.getPosition() == 1) { - EventBus.getDefault().post(new EBUISwitch("NewsFragment", home_vp_content.getCurrentItem())); + EventBus.getDefault().post(new EBUISwitch("NewsFragment", page_vp_content.getCurrentItem())); } } } + @Override + public void onHiddenChanged(boolean hidden) { + super.onHiddenChanged(hidden); + FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + List list = getChildFragmentManager().getFragments(); + if (list != null) { + if (hidden) { + for (Fragment fragment : getChildFragmentManager().getFragments()) { + transaction.hide(fragment); + } + } else { + for (Fragment fragment : getChildFragmentManager().getFragments()) { + transaction.show(fragment); + } + } + } + transaction.commit(); + } + } diff --git a/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailAdapter.java index 8dc7389ef8..ff4de0c6ae 100644 --- a/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailAdapter.java @@ -19,6 +19,7 @@ import android.widget.Toast; import com.gh.common.constant.Config; import com.gh.common.util.ConcernUtils; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.GameUtils; @@ -37,7 +38,6 @@ import com.gh.gamecenter.entity.NewsEntity; import com.gh.gamecenter.gamedetail.GameDetailTopViewHolder; import com.gh.gamecenter.listener.OnCallBackListener; import com.gh.gamecenter.manager.ConcernManager; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -261,12 +261,7 @@ public class NewsDetailAdapter extends RecyclerView.Adapter { kv.put("位置", String.valueOf(viewHolder.getPosition() + 1)); DataUtils.onEvent(context, "点击", "新闻详情-相关推荐", kv); - Map map = new HashMap<>(); - map.put("location", "相关推荐"); - map.put("page", "新闻详情"); - map.put("news", newsEntity.getTitle()); - map.put("news_id", newsEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "相关推荐", "新闻详情", newsEntity.getTitle()); // 统计阅读量 NewsUtils.statNewsViews(newsEntity.getId()); @@ -318,11 +313,7 @@ public class NewsDetailAdapter extends RecyclerView.Adapter { kv2.put("点击", "关注"); DataUtils.onEvent(context, "插件数据", gameEntity.getName(), kv2); - Map map = new HashMap<>(); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - map.put("type", "关注"); - DataCollectionManager.onEvent(context, "concern", map); + DataCollectionUtils.uploadConcern(context, gameEntity.getName(), gameEntity.getId(), "关注"); concernManager.addByEntity(gameEntity); concern.setText("取消关注"); @@ -332,8 +323,7 @@ public class NewsDetailAdapter extends RecyclerView.Adapter { Toast.makeText(context, "关注成功", Toast.LENGTH_SHORT).show(); // 添加关注 - String uuid = TokenUtils.getDeviceId(context); - ConcernUtils.postConcernGameId(uuid, gameEntity.getId()); + ConcernUtils.postConcernGameId(context, gameEntity.getId()); } else { Map kv = new HashMap<>(); kv.put("状态", "取消关注"); @@ -343,11 +333,6 @@ public class NewsDetailAdapter extends RecyclerView.Adapter { kv2.put("点击", "取消关注"); DataUtils.onEvent(context, "插件数据", gameEntity.getName(), kv2); - Map map = new HashMap<>(); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - map.put("type", "取消关注"); - DataCollectionManager.onEvent(context, "concern", map); DialogUtils.showCancelDialog(context, new DialogUtils.ConfiremListener() { @Override public void onConfirem() { @@ -355,11 +340,8 @@ public class NewsDetailAdapter extends RecyclerView.Adapter { kv.put("状态", "取消关注"); DataUtils.onEvent(context, "游戏关注", gameEntity.getName(), kv); - Map map = new HashMap<>(); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - map.put("type", "关注"); - DataCollectionManager.onEvent(context, "concern", map); + DataCollectionUtils.uploadConcern(context, + gameEntity.getName(), gameEntity.getId(), "取消关注"); concernManager.deleteConcern(gameEntity.getId()); concern.setText("关注"); @@ -367,8 +349,7 @@ public class NewsDetailAdapter extends RecyclerView.Adapter { concern.setTextColor(Color.WHITE); //取消关注 - String uuid = TokenUtils.getDeviceId(context); - ConcernUtils.deleteConcernData(uuid, gameEntity.getId()); + ConcernUtils.deleteConcernData(context, gameEntity.getId()); } }); } @@ -382,14 +363,7 @@ public class NewsDetailAdapter extends RecyclerView.Adapter { kv.put("位置", "游戏信息"); DataUtils.onEvent(context, "点击", "新闻详情", kv); - Map map = new HashMap<>(); - map.put("location", "游戏信息"); - map.put("page", "新闻详情"); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - map.put("news", newsDetailEntity.getTitle()); - map.put("news_id", newsDetailEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "游戏信息", "新闻详情", newsDetailEntity.getTitle()); GameUtils.startGameDetailActivity(context, gameEntity.getId(), entrance + "+(新闻详情)"); } diff --git a/app/src/main/java/com/gh/gamecenter/personal/ConcernFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/personal/ConcernFragmentAdapter.java index 2487b48b38..ee43a0c44a 100644 --- a/app/src/main/java/com/gh/gamecenter/personal/ConcernFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/personal/ConcernFragmentAdapter.java @@ -8,6 +8,7 @@ import android.view.View; import android.view.ViewGroup; import com.gh.common.constant.ItemViewType; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DownloadItemUtils; import com.gh.common.util.GameUtils; @@ -22,7 +23,6 @@ import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.listener.OnCallBackListener; import com.gh.gamecenter.manager.ConcernManager; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.GameManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -32,6 +32,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import rx.Observable; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -76,42 +77,27 @@ public class ConcernFragmentAdapter extends RecyclerView.Adapter result = new ArrayList<>(); - final int size = concernList.size(); - count = 0; - for (int i = 0; i < concernList.size(); i++) { - RetrofitManager.getApi().getGameDigest(concernList.get(i).getId()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(GameEntity response) { - result.add(response); - addCount(); - if (count == size) { - processingConcernGame(result); - } - } - - @Override - public void onFailure(Throwable e) { - addCount(); - if (count == size) { - processingConcernGame(result); - } - } - }); + List> sequences = new ArrayList<>(); + for (ConcernInfo concernInfo : concernList) { + sequences.add(RetrofitManager.getApi().getGameDigest(concernInfo.getId())); } + Observable.merge(sequences) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onNext(GameEntity response) { + result.add(response); + } + + @Override + public void onCompleted() { + processingConcernGame(result); + } + }); } private void processingConcernGame(List list) { @@ -229,12 +215,7 @@ public class ConcernFragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", "我的光环-已关注"); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "列表", "我的光环-已关注", gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity, "(我的光环-已关注)"); } diff --git a/app/src/main/java/com/gh/gamecenter/personal/InstallFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/personal/InstallFragmentAdapter.java index 3553676563..e08ea98297 100644 --- a/app/src/main/java/com/gh/gamecenter/personal/InstallFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/personal/InstallFragmentAdapter.java @@ -8,6 +8,7 @@ import android.view.View; import android.view.ViewGroup; import com.gh.common.constant.ItemViewType; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DownloadItemUtils; import com.gh.common.util.GameUtils; @@ -25,7 +26,6 @@ import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.GameInfoEntity; import com.gh.gamecenter.manager.ConcernManager; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.manager.GameManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -37,6 +37,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import rx.Observable; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -204,43 +205,28 @@ public class InstallFragmentAdapter extends RecyclerView.Adapter ids) { final List result = new ArrayList<>(); - final int size = ids.size(); - count = 0; - for (int i = 0; i < ids.size(); i++) { - RetrofitManager.getApi().getGameDigest(ids.get(i)) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(GameEntity response) { - result.add(response); - addCount(); - if (count == size) { - processingData(result); - } - } - - @Override - public void onFailure(Throwable e) { - addCount(); - if (count == size) { - processingData(result); - } - } - }); + List> sequences = new ArrayList<>(); + for (String id : ids) { + sequences.add(RetrofitManager.getApi().getGameDigest(id)); } + Observable.merge(sequences) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onNext(GameEntity response) { + result.add(response); + } + + @Override + public void onCompleted() { + processingData(result); + } + }); } private void processingData(List gameList) { @@ -391,12 +377,7 @@ public class InstallFragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("location", "列表"); - map.put("page", "我的光环-已安装"); - map.put("game", gameEntity.getName()); - map.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map); + DataCollectionUtils.uploadClick(context, "列表", "我的光环-已安装", gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity.getId(), "(我的光环-已安装)"); } diff --git a/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java b/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java index 4ad3bbb760..1603075e15 100644 --- a/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java +++ b/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java @@ -10,8 +10,6 @@ import android.net.Uri; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Bundle; -import android.os.Handler; -import android.os.Message; import android.provider.MediaStore; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; @@ -34,6 +32,7 @@ import android.widget.Toast; import com.facebook.drawee.view.SimpleDraweeView; import com.gh.common.constant.Config; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.DisplayUtils; @@ -43,7 +42,6 @@ import com.gh.gamecenter.CropImageActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.SettingActivity; import com.gh.gamecenter.adapter.FragmentAdapter; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; import com.tencent.stat.StatConfig; @@ -86,26 +84,6 @@ public class PersonalFragment extends Fragment implements View.OnClickListener, private boolean isLogin; - private Handler handler = new Handler() { - @Override - public void handleMessage(Message msg) { - if (getActivity() != null) { - SharedPreferences sp = getActivity().getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); - String name = sp.getString("user_name", null); - if (!TextUtils.isEmpty(name)) { - me_tv_top_name.setText(name); - } - String icon = sp.getString("user_icon", null); - if (!TextUtils.isEmpty(icon)) { - // ImageUtils.getInstance(getActivity()).display(icon, me_iv_top_icon, R.drawable.user_default_icon); - me_iv_top_icon.setImageURI(icon); - } - isLogin = true; - checkDeviceInfo(); - } - } - }; - @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); @@ -188,7 +166,26 @@ public class PersonalFragment extends Fragment implements View.OnClickListener, @Override public void run() { TokenUtils.getToken(getActivity()); - handler.sendEmptyMessage(0); + TokenUtils.checkDeviceInfo(getActivity()); + if (getActivity() != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + if (getActivity() != null) { + SharedPreferences sp = getActivity().getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); + String name = sp.getString("user_name", null); + if (!TextUtils.isEmpty(name)) { + me_tv_top_name.setText(name); + } + String icon = sp.getString("user_icon", null); + if (!TextUtils.isEmpty(icon)) { + me_iv_top_icon.setImageURI(icon); + } + isLogin = true; + } + } + }); + } } }.start(); } @@ -230,12 +227,8 @@ public class PersonalFragment extends Fragment implements View.OnClickListener, public void onClick(View v) { final int id = v.getId(); if (id == R.id.me_iv_top_setting) { - DataUtils.onEvent(getActivity(), "主页", "设置图标"); - - Map map = new HashMap<>(); - map.put("location", "设置图标"); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); + DataUtils.onEvent(getActivity(), "我的光环", "设置图标"); + DataCollectionUtils.uploadClick(getActivity(), "设置图标", "我的光环"); startActivity(new Intent(getActivity(), SettingActivity.class)); } else if (id == R.id.me_tv_top_install @@ -245,23 +238,15 @@ public class PersonalFragment extends Fragment implements View.OnClickListener, || v.getId() == R.id.me_tv_topbar_concern) { me_vp_show.setCurrentItem(1); } else if (id == R.id.me_tv_top_name) { - DataUtils.onEvent(getActivity(), "主页", "用户昵称"); - - Map map = new HashMap<>(); - map.put("location", "用户昵称"); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); + DataUtils.onEvent(getActivity(), "我的光环", "用户昵称"); + DataCollectionUtils.uploadClick(getActivity(), "用户昵称", "我的光环"); if (isLogin) { showModifyNicknameDialog(me_tv_top_name.getText().toString()); } } else if (id == R.id.me_iv_top_icon) { - DataUtils.onEvent(getActivity(), "主页", "用户头像"); - - Map map = new HashMap<>(); - map.put("location", "用户头像"); - map.put("page", "主页"); - DataCollectionManager.onEvent(getActivity(), "click-item", map); + DataUtils.onEvent(getActivity(), "我的光环", "用户头像"); + DataCollectionUtils.uploadClick(getActivity(), "用户头像", "我的光环"); if (isLogin) { Intent intent = new Intent(Intent.ACTION_PICK, @@ -449,39 +434,4 @@ public class PersonalFragment extends Fragment implements View.OnClickListener, }.start(); } - /* - * 检查设备信息是否已经上传完整 - */ - private void checkDeviceInfo() { - SharedPreferences sp = getActivity().getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); - final HashMap params = new HashMap<>(); - if (!sp.getBoolean("isUploadMac", true)) { - WifiManager wm = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); - String mac = wm.getConnectionInfo().getMacAddress(); - if (!TextUtils.isEmpty(mac) || !":::::".equals(mac)) { - params.put("MAC", mac); - } - } - if (!sp.getBoolean("isUploadMid", true)) { - String mid = StatConfig.getMid(getActivity()); - if (!TextUtils.isEmpty(mid) || !"0".equals(mid)) { - params.put("MTA_ID", mid); - } - } - if (params.size() != 0) { - new Thread(){ - @Override - public void run() { - RequestBody body = RequestBody.create(MediaType.parse("application/json"), - new JSONObject(params).toString()); - RetrofitManager.getUser().postDevice(TokenUtils.getToken(getActivity()), body, - TokenUtils.getDeviceId(getActivity())) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response()); - } - }.start(); - } - } - } diff --git a/app/src/main/java/com/gh/gamecenter/receiver/ActivitySkipReceiver.java b/app/src/main/java/com/gh/gamecenter/receiver/ActivitySkipReceiver.java index da1551c2b6..d815074edd 100644 --- a/app/src/main/java/com/gh/gamecenter/receiver/ActivitySkipReceiver.java +++ b/app/src/main/java/com/gh/gamecenter/receiver/ActivitySkipReceiver.java @@ -27,7 +27,7 @@ public class ActivitySkipReceiver extends BroadcastReceiver { if (clazz != null) { Intent intent1 = new Intent(context, clazz); intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intentControl(intent1, bundle); + intent1.putExtra("data", bundle); context.startActivity(intent1); } } @@ -37,7 +37,7 @@ public class ActivitySkipReceiver extends BroadcastReceiver { intent1.setAction(Intent.ACTION_MAIN); intent1.addCategory(Intent.CATEGORY_LAUNCHER); intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intentControl(intent1, bundle); + intent1.putExtra("data", bundle); context.startActivity(intent1); } } @@ -57,32 +57,4 @@ public class ActivitySkipReceiver extends BroadcastReceiver { return null; } - private void intentControl(Intent intent, Bundle bundle) { - String to = bundle.getString("to"); - if ("NewsActivity".equals(to) || "NewsDetailActivity".equals(to)) { - intent.putExtra("newsId", bundle.getString("newsId")); - intent.putExtra("entrance", bundle.getString("entrance")); - } else if("DownloadManagerActivity".equals(to)) { - intent.putExtra("packageName", bundle.getString("packageName")); - } else if ("GameDetailsActivity".equals(to) || "GameDetailActivity".equals(to)) { - intent.putExtra("gameId", bundle.getString("gameId")); - intent.putExtra("entrance", bundle.getString("entrance")); - } else if ("SubjectActivity".equals(to)) { - intent.putExtra("id", bundle.getString("id")); - intent.putExtra("name", bundle.getString("name")); - intent.putExtra("order", bundle.getBoolean("order")); - } else if ("ViewImageActivity".equals(to)) { - intent.putExtra("urls", bundle.getStringArrayList("urls")); - intent.putExtra("current", bundle.getInt("current",0)); - intent.putExtra("ScaleType", bundle.getString("ScaleType")); - } - if ("NewsActivity".equals(to)) { - intent.putExtra("to", "NewsDetailActivity"); - } else if ("GameDetailsActivity".equals(to)) { - intent.putExtra("to", "GameDetailActivity"); - } else { - intent.putExtra("to", to); - } - } - } diff --git a/app/src/main/java/com/gh/gamecenter/receiver/InstallReceiver.java b/app/src/main/java/com/gh/gamecenter/receiver/InstallReceiver.java index 28d7965bb6..12ed9e598c 100644 --- a/app/src/main/java/com/gh/gamecenter/receiver/InstallReceiver.java +++ b/app/src/main/java/com/gh/gamecenter/receiver/InstallReceiver.java @@ -36,10 +36,10 @@ public class InstallReceiver extends BroadcastReceiver { | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); context.startActivity(intent2); + EventBus.getDefault().post(new EBMiPush("plugin_install", path)); } else { - Intent intent2 = new Intent(context, - DownloadManagerActivity.class); + Intent intent2 = new Intent(context, DownloadManagerActivity.class); intent2.putExtra("currentItem", 0); intent2.putExtra("path", path); intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @@ -50,7 +50,8 @@ public class InstallReceiver extends BroadcastReceiver { Intent intent2 = new Intent(context, SplashScreenActivity.class); intent2.setAction(Intent.ACTION_MAIN); intent2.addCategory(Intent.CATEGORY_LAUNCHER); - intent2.putExtra("from", "plugin_install"); + intent2.putExtra("to", "DownloadManagerActivity"); + intent2.putExtra("currentItem", 0); intent2.putExtra("path", path); intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent2); diff --git a/app/src/main/java/com/gh/gamecenter/receiver/NotificationReceiver.java b/app/src/main/java/com/gh/gamecenter/receiver/NotificationReceiver.java index b702c11c74..37a2819410 100644 --- a/app/src/main/java/com/gh/gamecenter/receiver/NotificationReceiver.java +++ b/app/src/main/java/com/gh/gamecenter/receiver/NotificationReceiver.java @@ -46,7 +46,7 @@ public class NotificationReceiver extends BroadcastReceiver { // 应用正在运行,前台或后台 Intent intent1 = new Intent(context, NewsDetailActivity.class); intent1.putExtra("newsId", jsonObject.get("_id").toString()); - intent1.putExtra("entrance", "小米推送"); + intent1.putExtra("entrance", "(小米推送)"); intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent1); } else { @@ -54,8 +54,9 @@ public class NotificationReceiver extends BroadcastReceiver { Intent intent1 = new Intent(context, SplashScreenActivity.class); intent1.setAction(Intent.ACTION_MAIN); intent1.addCategory(Intent.CATEGORY_LAUNCHER); - intent1.putExtra("from", "mipush_news"); + intent1.putExtra("to", "NewsDetailActivity"); intent1.putExtra("newsId", jsonObject.get("_id").toString()); + intent1.putExtra("entrance", "(小米推送)"); intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent1); } @@ -107,8 +108,9 @@ public class NotificationReceiver extends BroadcastReceiver { Intent intent2 = new Intent(context, SplashScreenActivity.class); intent2.setAction(Intent.ACTION_MAIN); intent2.addCategory(Intent.CATEGORY_LAUNCHER); - intent2.putExtra("from", "mipush_plugin"); - intent2.putExtra("data", jsonObject.toString()); + intent2.putExtra("to", "DownloadManagerActivity"); + intent2.putExtra("currentItem", 1); + intent2.putExtra("isPushIntent", true); intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent2); } @@ -125,15 +127,16 @@ public class NotificationReceiver extends BroadcastReceiver { // 应用正在运行,前台或后台 Gson gson = new Gson(); GameEntity gameEntity = gson.fromJson(jsonObject.toString(), GameEntity.class); - GameUtils.startGameDetailActivity(context, gameEntity, "小米推送"); + GameUtils.startGameDetailActivity(context, gameEntity, "(小米推送)"); } else { // 应用未在运行 Intent intent3 = new Intent(context, SplashScreenActivity.class); intent3.setAction(Intent.ACTION_MAIN); intent3.addCategory(Intent.CATEGORY_LAUNCHER); + intent3.putExtra("to", "GameDetailActivity"); + intent3.putExtra("entrance", "(小米推送)"); Gson gson = new Gson(); GameEntity gameEntity = gson.fromJson(jsonObject.toString(), GameEntity.class); - intent3.putExtra("from", "mipush_new_game"); AppController.put("GameEntity", gameEntity); intent3.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent3); @@ -143,7 +146,6 @@ public class NotificationReceiver extends BroadcastReceiver { break; } } catch (JSONException e) { - e.printStackTrace(); } } @@ -159,10 +161,8 @@ public class NotificationReceiver extends BroadcastReceiver { private ArrayList getAllPackageName(Context context) { ArrayList list = new ArrayList<>(); - List packageInfos = context.getPackageManager() - .getInstalledPackages(0); - for (int i = 0, size = packageInfos.size(); i < size; i++) { - PackageInfo packageInfo = packageInfos.get(i); + List packageInfos = context.getPackageManager().getInstalledPackages(0); + for (PackageInfo packageInfo : packageInfos) { if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { list.add(packageInfo.packageName); } diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/ApiService.java b/app/src/main/java/com/gh/gamecenter/retrofit/ApiService.java index 0f3c85f1bb..11ebeee1b7 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/ApiService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/ApiService.java @@ -25,7 +25,6 @@ import retrofit2.http.GET; import retrofit2.http.Header; import retrofit2.http.Headers; import retrofit2.http.POST; -import retrofit2.http.PUT; import retrofit2.http.Path; import retrofit2.http.Query; import rx.Observable; @@ -67,19 +66,6 @@ public interface ApiService { @GET("support/time/current") Observable getTime();// 获取服务器时间 - @Headers({"Content-Type: application/json", "Accept: application/json"}) - @PUT("device/{device_id}/concern") // 更新设备关注 - Observable putConcern(@Path("device_id") String device_id, @Body RequestBody body); - - @POST("device/{device_id}/concern") // 添加关注 - Observable postConcern(@Path("device_id") String device_id, @Body RequestBody body); - - @POST("device/{device_id}/concern/{game_id}") // 删除关注 - Observable deleteConcern(@Path("device_id") String device_id, @Path("game_id") String game_id); - - @GET("device/{device_id}/concern") // 获取设备关注数据 - Observable> getConcern(@Path("device_id") String device_id); - @Headers({"Content-Type: application/json", "Accept: application/json"}) @POST("stat/download") // 统计下载量 Observable postDownload(@Body RequestBody body); @@ -92,7 +78,7 @@ public interface ApiService { @GET("update/game/{gh_id}/package{package_name}") Observable getGameUpdate(@Path("gh_id") String gh_id, - @Path("package_name") String package_name);// 获取游戏更新 + @Path("package_name") String package_name);// 获取游戏更新 @GET("disclaimer") Observable getDisclaimer(); // 获取免责声明 @@ -204,4 +190,7 @@ public interface ApiService { @GET("support/package/unused") Observable> getPackageUnused(@Query("skip") long skip); // 获取过滤包名 + @GET("device/{device_id}/concern") // 获取设备关注数据 + Observable> getConcern(@Path("device_id") String device_id); + } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/CommentService.java b/app/src/main/java/com/gh/gamecenter/retrofit/CommentService.java index c4d84d5334..04fd430980 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/CommentService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/CommentService.java @@ -10,8 +10,6 @@ import okhttp3.ResponseBody; import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; -import retrofit2.http.POST; -import retrofit2.http.Header; import retrofit2.http.Headers; import retrofit2.http.POST; import retrofit2.http.Path; diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/ObservableUtil.java b/app/src/main/java/com/gh/gamecenter/retrofit/ObservableUtil.java index 9bf3a0d600..0e16e23921 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/ObservableUtil.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/ObservableUtil.java @@ -1,6 +1,9 @@ package com.gh.gamecenter.retrofit; +import java.util.concurrent.CountDownLatch; + import rx.Observable; +import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1; import rx.schedulers.Schedulers; @@ -43,4 +46,23 @@ public class ObservableUtil { .subscribe(action1); } + public static CountDownLatch latch(int size, Action1 action1) { + final CountDownLatch latch = new CountDownLatch(size); + Observable.create(new Observable.OnSubscribe() { + @Override + public void call(Subscriber subscriber) { + try { + latch.await(); + subscriber.onNext(null); + } catch (InterruptedException e) { + e.printStackTrace(); + } + subscriber.onCompleted(); + } + }).subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(action1); + return latch; + } + } diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpInterceptor.java b/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpInterceptor.java index 4705d4c269..6357dd8a41 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpInterceptor.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpInterceptor.java @@ -4,7 +4,6 @@ import com.gh.base.AppController; import com.gh.common.util.GzipUtils; import com.gh.common.util.NetworkUtils; import com.gh.common.util.TimestampUtils; -import com.gh.common.util.Utils; import java.io.IOException; @@ -40,8 +39,8 @@ public class OkHttpInterceptor implements Interceptor { } // log 打印 - Utils.log(String.format("Interceptor Sending request %s on %s%n%s", - request.url(), chain.connection(), request.headers())); +// Utils.log(String.format("Interceptor Sending request %s on %s%n%s", +// request.url(), chain.connection(), request.headers())); Response response = chain.proceed(request); @@ -60,8 +59,8 @@ public class OkHttpInterceptor implements Interceptor { } // log 打印 - Utils.log(String.format("Interceptor Received response for %s in %n%s", - response.request().url(), response.headers())); +// Utils.log(String.format("Interceptor Received response for %s in %n%s", +// response.request().url(), response.headers())); return response; } diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpNetworkInterceptor.java b/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpNetworkInterceptor.java index d5c4e832b2..3eb04a791e 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpNetworkInterceptor.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpNetworkInterceptor.java @@ -4,7 +4,6 @@ import com.gh.base.AppController; import com.gh.common.util.GzipUtils; import com.gh.common.util.NetworkUtils; import com.gh.common.util.TimestampUtils; -import com.gh.common.util.Utils; import java.io.IOException; @@ -34,8 +33,8 @@ public class OkHttpNetworkInterceptor implements Interceptor { // .build(); // log 打印 - Utils.log(String.format("Interceptor Network Sending request %s on %s%n%s", - request.url(), chain.connection(), request.headers())); +// Utils.log(String.format("Interceptor Network Sending request %s on %s%n%s", +// request.url(), chain.connection(), request.headers())); Response response = chain.proceed(request); @@ -71,8 +70,8 @@ public class OkHttpNetworkInterceptor implements Interceptor { } // log 打印 - Utils.log(String.format("Interceptor Network Received response for %s in %n%s", - response.request().url(), response.headers())); +// Utils.log(String.format("Interceptor Network Received response for %s in %n%s", +// response.request().url(), response.headers())); return response; } diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/UserService.java b/app/src/main/java/com/gh/gamecenter/retrofit/UserService.java index 0ba22430ce..b4e9d0e434 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/UserService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/UserService.java @@ -1,11 +1,16 @@ package com.gh.gamecenter.retrofit; +import java.util.List; + import okhttp3.RequestBody; import okhttp3.ResponseBody; import retrofit2.http.Body; +import retrofit2.http.DELETE; +import retrofit2.http.GET; import retrofit2.http.Header; import retrofit2.http.Headers; import retrofit2.http.POST; +import retrofit2.http.PUT; import retrofit2.http.Path; import rx.Observable; @@ -24,4 +29,37 @@ public interface UserService { Observable postDevice(@Header("TOKEN") String token, @Body RequestBody body, @Path("device_id") String device_id); // 修改设备信息 + @Headers({"Content-Type: application/json", "Accept: application/json"}) + @POST("login") + Observable postLogin(@Header("TOKEN") String token, @Body RequestBody body); // 用户登录 + + @Headers({"Content-Type: application/json", "Accept: application/json"}) + @POST("meta/concern") // 添加关注 + Observable postConcern(@Header("TOKEN") String token, @Body RequestBody body); + + @DELETE("meta/concern/{game_id}") // 删除关注 + Observable deleteConcern(@Header("TOKEN") String token, @Path("game_id") String game_id); + + @Headers({"Content-Type: application/json", "Accept: application/json"}) + @PUT("meta/concern") // 整体更新设备关注 + Observable putConcern(@Header("TOKEN") String token, @Body RequestBody body); + + @GET("meta/concern") // 获取设备关注数据 + Observable> getConcern(@Header("TOKEN") String token); + + @Headers({"Content-Type: application/json", "Accept: application/json"}) + @POST("meta/package") // 添加已安装游戏 + Observable postPackage(@Header("TOKEN") String token, @Body RequestBody body); + + @DELETE("meta/package/{package_name}") // 删除已安装游戏 + Observable deletePackage(@Header("TOKEN") String token, @Path("package_name") String package_name); + + @Headers({"Content-Type: application/json", "Accept: application/json"}) + @PUT("meta/package") // 整体更新设备已安装游戏 + Observable putPackage(@Header("TOKEN") String token, @Body RequestBody body); + + @Headers({"Content-Type: application/json", "Accept: application/json"}) + @POST("meta/ghzs") // 上传用户所使用的助手信息 + Observable postGhzs(@Header("TOKEN") String token, @Body RequestBody body); + } diff --git a/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragmentAdapter.java index d1532a0d0f..12ae30769e 100644 --- a/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragmentAdapter.java @@ -10,6 +10,7 @@ import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; import com.gh.common.constant.Config; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.GameUtils; @@ -20,7 +21,6 @@ import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.listener.OnCallBackListener; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -131,23 +131,14 @@ public class SearchGameDetailFragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("key", key); - map.put("from", "搜索页面"); - map.put("click", gameEntity.getName()); - DataCollectionManager.onEvent(context, "search", map); + DataCollectionUtils.uploadSearch(context, key, "搜索页面", gameEntity.getName()); Map kv = new HashMap<>(); kv.put("名字", gameEntity.getName()); kv.put("位置", String.valueOf(viewHolder.getPosition() + 1)); DataUtils.onEvent(context, "点击", "搜索", kv); - Map map2 = new HashMap<>(); - map2.put("location", "列表"); - map2.put("page", "搜索"); - map2.put("game", gameEntity.getName()); - map2.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map2); + DataCollectionUtils.uploadClick(context, "列表", "搜索", gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity, "(搜索)"); } @@ -170,11 +161,7 @@ public class SearchGameDetailFragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("key", key); - map.put("from", "搜索页面"); - map.put("click", gameEntity.getName()); - DataCollectionManager.onEvent(context, "search", map); + DataCollectionUtils.uploadSearch(context, key, "搜索页面", gameEntity.getName()); DownloadDialog.getInstance(context) .showPopupWindow(v, gameEntity, "(搜索)", "搜索:" + gameEntity.getName()); diff --git a/app/src/main/java/com/gh/gamecenter/search/SearchGameListFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/search/SearchGameListFragmentAdapter.java index 05bc3a8572..e88bb792fc 100644 --- a/app/src/main/java/com/gh/gamecenter/search/SearchGameListFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/search/SearchGameListFragmentAdapter.java @@ -10,6 +10,7 @@ import android.view.inputmethod.InputMethodManager; import com.gh.common.constant.Config; import com.gh.common.constant.ItemViewType; +import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.GameUtils; @@ -20,7 +21,6 @@ import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.listener.OnCallBackListener; -import com.gh.gamecenter.manager.DataCollectionManager; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -124,23 +124,14 @@ public class SearchGameListFragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("key", key); - map.put("from", "搜索页面"); - map.put("click", gameEntity.getName()); - DataCollectionManager.onEvent(context, "search", map); + DataCollectionUtils.uploadSearch(context, key, "搜索页面", gameEntity.getName()); Map kv = new HashMap<>(); kv.put("名字", gameEntity.getName()); kv.put("位置", String.valueOf(holder.getPosition() + 1)); DataUtils.onEvent(context, "点击", "搜索", kv); - Map map2 = new HashMap<>(); - map2.put("location", "列表"); - map2.put("page", "搜索"); - map2.put("game", gameEntity.getName()); - map2.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map2); + DataCollectionUtils.uploadClick(context, "列表", "搜索", gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity, "(搜索)"); } @@ -163,11 +154,7 @@ public class SearchGameListFragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("key", key); - map.put("from", "搜索页面"); - map.put("click", gameEntity.getName()); - DataCollectionManager.onEvent(context, "search", map); + DataCollectionUtils.uploadSearch(context, key, "搜索页面", gameEntity.getName()); DownloadDialog.getInstance(context) .showPopupWindow(v, gameEntity, "(搜索)", "搜索:" + gameEntity.getName()); @@ -191,23 +178,14 @@ public class SearchGameListFragmentAdapter extends RecyclerView.Adapter map = new HashMap<>(); - map.put("key", key); - map.put("from", "搜索页面"); - map.put("click", gameEntity.getName()); - DataCollectionManager.onEvent(context, "search", map); + DataCollectionUtils.uploadSearch(context, key, "搜索页面", gameEntity.getName()); Map kv = new HashMap<>(); kv.put("名字", gameEntity.getName()); kv.put("位置", String.valueOf(holder.getPosition() + 1)); DataUtils.onEvent(context, "点击", "搜索", kv); - Map map2 = new HashMap<>(); - map2.put("location", "列表"); - map2.put("page", "搜索"); - map2.put("game", gameEntity.getName()); - map2.put("game_id", gameEntity.getId()); - DataCollectionManager.onEvent(context, "click-item", map2); + DataCollectionUtils.uploadClick(context, "列表", "搜索", gameEntity.getName()); GameUtils.startGameDetailActivity(context, gameEntity, "(搜索)"); } diff --git a/app/src/main/res/drawable-xhdpi/frame_tran_bottom.png b/app/src/main/res/drawable-xhdpi/frame_tran_bottom.png new file mode 100644 index 0000000000..d26e877fa8 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/frame_tran_bottom.png differ diff --git a/app/src/main/res/drawable-xhdpi/frame_tran_center.png b/app/src/main/res/drawable-xhdpi/frame_tran_center.png new file mode 100644 index 0000000000..6dc899f907 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/frame_tran_center.png differ diff --git a/app/src/main/res/drawable-xhdpi/frame_tran_left.png b/app/src/main/res/drawable-xhdpi/frame_tran_left.png new file mode 100644 index 0000000000..e23c200bf2 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/frame_tran_left.png differ diff --git a/app/src/main/res/drawable-xhdpi/frame_tran_left_bottom_square.png b/app/src/main/res/drawable-xhdpi/frame_tran_left_bottom_square.png new file mode 100644 index 0000000000..7e2a3aeab0 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/frame_tran_left_bottom_square.png differ diff --git a/app/src/main/res/drawable-xhdpi/frame_tran_left_top_square.png b/app/src/main/res/drawable-xhdpi/frame_tran_left_top_square.png new file mode 100644 index 0000000000..a47036f973 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/frame_tran_left_top_square.png differ diff --git a/app/src/main/res/drawable-xhdpi/frame_tran_right.png b/app/src/main/res/drawable-xhdpi/frame_tran_right.png new file mode 100644 index 0000000000..2eff1cbd91 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/frame_tran_right.png differ diff --git a/app/src/main/res/drawable-xhdpi/frame_tran_right_bottom_square.png b/app/src/main/res/drawable-xhdpi/frame_tran_right_bottom_square.png new file mode 100644 index 0000000000..6cda221418 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/frame_tran_right_bottom_square.png differ diff --git a/app/src/main/res/drawable-xhdpi/frame_tran_right_top_square.png b/app/src/main/res/drawable-xhdpi/frame_tran_right_top_square.png new file mode 100644 index 0000000000..6f04738833 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/frame_tran_right_top_square.png differ diff --git a/app/src/main/res/drawable-xhdpi/frame_tran_top.png b/app/src/main/res/drawable-xhdpi/frame_tran_top.png new file mode 100644 index 0000000000..3d3802cfa1 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/frame_tran_top.png differ diff --git a/app/src/main/res/layout/activity_gamedetail_news.xml b/app/src/main/res/layout/activity_gamedetail_news.xml index 46456c5bcf..cc6fafc3d8 100644 --- a/app/src/main/res/layout/activity_gamedetail_news.xml +++ b/app/src/main/res/layout/activity_gamedetail_news.xml @@ -8,15 +8,13 @@ + android:layout_marginTop="16dp"> - - - - + android:layout_height="match_parent" + android:orientation="horizontal" + android:background="@android:color/white" + android:visibility="gone" + app:left="8dp" + app:right="8dp" + app:top="8dp" + app:bottom="8dp"> + android:layout_height="match_parent" /> - + @@ -17,384 +16,360 @@ android:layout_height="wrap_content" android:orientation="vertical"> - + app:left="8dp" + app:right="8dp" + app:top="8dp" + app:bottom="8dp"> - + - + android:layout_height="48dp" + android:orientation="horizontal" + android:gravity="center_vertical" + android:paddingLeft="10dp" + android:paddingRight="10dp" + android:background="@drawable/reuse_listview_item_style" + app:left="8dp" + app:right="8dp" + app:top="8dp" + app:bottom="5dp"> + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + android:layout_height="1dp" + android:background="#ededed"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="48dp" + android:gravity="center_vertical" + android:background="@drawable/reuse_listview_item_style" + android:padding="10dp"> - - + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_centerVertical="true" + android:text="清除缓存" + android:textColor="@color/title" + android:textSize="16sp" /> + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_splash_intro.xml b/app/src/main/res/layout/activity_splash_intro.xml index 9722d3cc22..c73a44243f 100644 --- a/app/src/main/res/layout/activity_splash_intro.xml +++ b/app/src/main/res/layout/activity_splash_intro.xml @@ -4,7 +4,7 @@ android:layout_height="match_parent" > diff --git a/app/src/main/res/layout/activity_suggest.xml b/app/src/main/res/layout/activity_suggest.xml index a057f1c915..8f1b0ed2b1 100644 --- a/app/src/main/res/layout/activity_suggest.xml +++ b/app/src/main/res/layout/activity_suggest.xml @@ -5,107 +5,87 @@ android:layout_height="match_parent" android:orientation="vertical" > - + - + android:orientation="vertical" + android:background="@android:color/white" + app:left="8dp" + app:right="8dp" + app:top="10dp" + app:bottom="8dp"> - + - - - - - - - - - - - + android:background="@null" + android:focusable="true" + android:gravity="top" + android:inputType="textMultiLine" + android:maxLines="12" + android:minLines="6" + android:padding="8dp" + android:hint="使用过程中发现的任何问题或者其他建议都欢迎提交给我们~光环助手会努力变得更好更强大!" + android:textSize="14sp" /> - + - - + - + - + + + + + android:orientation="horizontal" + android:background="@color/theme" + app:left="8dp" + app:right="8dp" + app:top="8dp" + app:bottom="8dp"> - + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 9432ea9cf9..c98a42a581 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -6,44 +6,4 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_newhome.xml b/app/src/main/res/layout/fragment_newhome.xml deleted file mode 100644 index 5f48254ab9..0000000000 --- a/app/src/main/res/layout/fragment_newhome.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_page.xml b/app/src/main/res/layout/fragment_page.xml new file mode 100644 index 0000000000..7b99faabd7 --- /dev/null +++ b/app/src/main/res/layout/fragment_page.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_slidebar.xml b/app/src/main/res/layout/fragment_slidebar.xml new file mode 100644 index 0000000000..83130c743d --- /dev/null +++ b/app/src/main/res/layout/fragment_slidebar.xml @@ -0,0 +1,22 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/game_viewpager_item.xml b/app/src/main/res/layout/game_viewpager_item.xml index 8e687b211a..bea6dcbdd6 100644 --- a/app/src/main/res/layout/game_viewpager_item.xml +++ b/app/src/main/res/layout/game_viewpager_item.xml @@ -1,5 +1,6 @@ @@ -38,14 +39,18 @@ - + android:layout_height="98dp" + android:paddingLeft="8dp" + android:paddingTop="8dp" + android:paddingRight="8dp" + android:layout_alignParentBottom="true" + app:left="8dp" + app:right="8dp" + app:top="8dp" + app:tran="true"> + android:visibility="visible"> + + + - \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_gift.xml b/app/src/main/res/layout/gamedetail_item_gift.xml index 7cc131972a..2334f550b0 100644 --- a/app/src/main/res/layout/gamedetail_item_gift.xml +++ b/app/src/main/res/layout/gamedetail_item_gift.xml @@ -1,38 +1,33 @@ - + - - + android:layout_height="60dp" + android:textSize="14sp" + android:textColor="@color/title" + android:gravity="center" + android:paddingLeft="10dp" + android:paddingRight="10dp" /> - - + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_gift_rv.xml b/app/src/main/res/layout/gamedetail_item_gift_rv.xml index a4d8492308..62671529f9 100644 --- a/app/src/main/res/layout/gamedetail_item_gift_rv.xml +++ b/app/src/main/res/layout/gamedetail_item_gift_rv.xml @@ -1,44 +1,37 @@ - + android:orientation="vertical" + android:background="@android:color/white" + android:paddingBottom="15dp" + android:paddingLeft="12dp" + android:paddingRight="12dp" + android:paddingTop="12dp" + app:left="8dp" + app:right="8dp" + app:top="4dp" + app:bottom="4dp"> - + android:layout_marginBottom="12dp" + android:text="游戏礼包" + android:textColor="#3a3a3a" + android:textSize="16dp" /> - + - + + - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_intro.xml b/app/src/main/res/layout/gamedetail_item_intro.xml index efc9c95252..25dc874111 100644 --- a/app/src/main/res/layout/gamedetail_item_intro.xml +++ b/app/src/main/res/layout/gamedetail_item_intro.xml @@ -1,54 +1,47 @@ - + android:orientation="vertical" + android:background="@android:color/white" + android:paddingBottom="15dp" + android:paddingLeft="12dp" + android:paddingRight="12dp" + android:paddingTop="12dp" + app:left="8dp" + app:right="8dp" + app:top="4dp" + app:bottom="8dp"> - + + + + + + + + android:text="游戏介绍内容" + android:textSize="14sp" + android:textColor="#3a3a3a" + android:lineSpacingMultiplier="1.2" + android:layout_marginTop="15sp"/> - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_news.xml b/app/src/main/res/layout/gamedetail_item_news.xml index 59de7ef631..6434ff1e63 100644 --- a/app/src/main/res/layout/gamedetail_item_news.xml +++ b/app/src/main/res/layout/gamedetail_item_news.xml @@ -1,28 +1,23 @@ - + android:orientation="vertical" + android:background="@android:color/white" + android:paddingBottom="3dp" + android:paddingLeft="12dp" + android:paddingRight="12dp" + android:paddingTop="12dp" + app:left="8dp" + app:right="8dp" + app:top="4dp" + app:bottom="4dp"> - - - + android:layout_marginBottom="12dp"> - + + - - - - - - - - - - - + android:text="全部" + android:textColor="@color/content" + android:textSize="14sp" /> + + + + + + + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_newsserver.xml b/app/src/main/res/layout/gamedetail_item_newsserver.xml index 8b4af29d9d..3d9793fac1 100644 --- a/app/src/main/res/layout/gamedetail_item_newsserver.xml +++ b/app/src/main/res/layout/gamedetail_item_newsserver.xml @@ -1,57 +1,48 @@ - + android:layout_height="85dp" + android:orientation="horizontal" + android:background="@android:color/white" + android:padding="8dp" + app:left="8dp" + app:right="8dp" + app:top="4dp" + app:bottom="4dp"> - + - + + - - + + - - + - + + - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_plugin.xml b/app/src/main/res/layout/gamedetail_item_plugin.xml index 814078d68a..fa51d963f9 100644 --- a/app/src/main/res/layout/gamedetail_item_plugin.xml +++ b/app/src/main/res/layout/gamedetail_item_plugin.xml @@ -1,80 +1,73 @@ - + android:orientation="vertical" + android:background="@android:color/white" + android:paddingBottom="14dp" + android:paddingLeft="12dp" + android:paddingRight="12dp" + android:paddingTop="12dp" + app:left="8dp" + app:right="8dp" + app:top="4dp" + app:bottom="4dp"> - + android:layout_marginBottom="12dp"> - + android:text="插件介绍" + android:textColor="#3a3a3a" + android:textSize="16dp" /> + + + android:text="详情" + android:textColor="@color/content" + android:textSize="14dp"/> - + - + - + - + - + - + - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_skin.xml b/app/src/main/res/layout/gamedetail_item_skin.xml index 50c1a808b1..2a1d4e8341 100644 --- a/app/src/main/res/layout/gamedetail_item_skin.xml +++ b/app/src/main/res/layout/gamedetail_item_skin.xml @@ -1,80 +1,74 @@ - + android:orientation="vertical" + android:background="@android:color/white" + android:paddingBottom="4dp" + android:paddingLeft="12dp" + android:paddingRight="12dp" + android:paddingTop="12dp" + app:left="8dp" + app:right="8dp" + app:top="4dp" + app:bottom="4dp"> - - + android:layout_centerVertical="true" + android:text="素材包" + android:textColor="#3a3a3a" + android:textSize="16dp" /> - + + + + + + android:background="@drawable/textview_blue_style" + android:gravity="center" + android:textColor="@android:color/white" /> - + android:layout_height="match_parent" + android:progressDrawable="@drawable/progressbar_normal_style" + android:visibility="gone" /> - + - + - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/gamedetail_item_top.xml b/app/src/main/res/layout/gamedetail_item_top.xml index 873ec2dc57..50c9751ec0 100644 --- a/app/src/main/res/layout/gamedetail_item_top.xml +++ b/app/src/main/res/layout/gamedetail_item_top.xml @@ -1,71 +1,64 @@ - + android:orientation="horizontal" + android:gravity="center_vertical" + android:background="@android:color/white" + android:paddingBottom="15dp" + android:paddingLeft="12dp" + android:paddingRight="12dp" + android:paddingTop="15dp" + app:left="8dp" + app:right="8dp" + app:top="8dp" + app:bottom="4dp"> + + - - - - - - - - - - + android:layout_weight="1" + android:layout_marginRight="16dp" + android:orientation="vertical"> + android:id="@+id/gamedetail_tv_name" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:ellipsize="end" + android:includeFontPadding="false" + android:lineSpacingMultiplier="0.9" + android:singleLine="true" + android:text="少年三国志" + android:textColor="@color/title" + android:textSize="16sp" /> + + - \ No newline at end of file + + + \ No newline at end of file diff --git a/app/src/main/res/layout/gift_item.xml b/app/src/main/res/layout/gift_item.xml index a3690f820d..ca49452e70 100644 --- a/app/src/main/res/layout/gift_item.xml +++ b/app/src/main/res/layout/gift_item.xml @@ -1,80 +1,73 @@ - + android:orientation="horizontal" + android:gravity="center_vertical" + android:background="@android:color/white" + android:paddingBottom="15dp" + android:paddingLeft="12dp" + android:paddingRight="12dp" + android:paddingTop="15dp" + app:left="8dp" + app:right="8dp" + app:top="4dp" + app:bottom="4dp"> + + - - - - - - - - - - - - + android:layout_weight="1" + android:gravity="center_vertical" + android:orientation="vertical"> + android:id="@+id/gift_name" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textColor="@color/title" + android:textSize="16sp" + android:singleLine="true" + android:text="暖床萌萌大礼包"/> + + + + - \ No newline at end of file + + + \ No newline at end of file diff --git a/app/src/main/res/layout/giftdetail_item_top.xml b/app/src/main/res/layout/giftdetail_item_top.xml index 16a47a3bf2..91bf63d214 100644 --- a/app/src/main/res/layout/giftdetail_item_top.xml +++ b/app/src/main/res/layout/giftdetail_item_top.xml @@ -1,18 +1,19 @@ - + android:orientation="horizontal" + android:gravity="center_vertical" + android:background="@android:color/white" + android:paddingBottom="15dp" + android:paddingLeft="12dp" + android:paddingRight="12dp" + android:paddingTop="15dp" + app:left="8dp" + app:right="8dp" + app:top="4dp" + app:bottom="4dp"> - \ No newline at end of file + diff --git a/app/src/main/res/layout/newsdetail_item_news_more.xml b/app/src/main/res/layout/newsdetail_item_news_more.xml index 229fb858d5..fda807b86f 100644 --- a/app/src/main/res/layout/newsdetail_item_news_more.xml +++ b/app/src/main/res/layout/newsdetail_item_news_more.xml @@ -1,33 +1,26 @@ - + android:orientation="vertical" + android:background="@android:color/white" + android:paddingBottom="3dp" + android:paddingLeft="12dp" + android:paddingRight="12dp" + android:paddingTop="15dp" + app:left="8dp" + app:right="8dp" + app:top="8dp" + app:bottom="8dp"> - + android:text="相关推荐" + android:textColor="@color/title" + android:textSize="16dp" + android:layout_marginBottom="15dp"/> - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/splash_viewpage_item.xml b/app/src/main/res/layout/splash_guide_item.xml similarity index 84% rename from app/src/main/res/layout/splash_viewpage_item.xml rename to app/src/main/res/layout/splash_guide_item.xml index e5ca85baec..9ca62c873f 100644 --- a/app/src/main/res/layout/splash_viewpage_item.xml +++ b/app/src/main/res/layout/splash_guide_item.xml @@ -4,13 +4,13 @@ android:layout_height="match_parent"> diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 700dea81bf..0217e62233 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -64,6 +64,7 @@ + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 1d8240b854..87c6cd4726 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -3,24 +3,12 @@ @@ -37,7 +25,7 @@ @color/background - - -