Merge remote-tracking branch 'origin/2.0' into 2.0
# Conflicts: # app/src/main/java/com/gh/gamecenter/GameDetailActivity.java
This commit is contained in:
@ -172,32 +172,46 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
isInstalled = true;
|
||||
}
|
||||
if (isInstalled) {
|
||||
PackageManager mPackageManager = new PackageManager(this);
|
||||
if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& !mPackageManager.isSignature(gameEntity.getApk().get(0).getPackageName())
|
||||
) {
|
||||
if (PackageManager.isCanUpdate(gameEntity.getApk().get(0).getPackageName())) {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_plugin_style);
|
||||
detail_tv_download.setText(String.format("插件化《%s》",
|
||||
R.drawable.game_item_btn_download_style);
|
||||
detail_tv_download.setText(String.format("更新《%s》",
|
||||
gameEntity.getName()));
|
||||
} else {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_plugin_style);
|
||||
detail_tv_download.setText(String.format("插件化《%s》%s",
|
||||
gameEntity.getName(), gameEntity.getDownloadAddWord()));
|
||||
R.drawable.game_item_btn_download_style);
|
||||
detail_tv_download.setText(String.format("更新《%s》%s",
|
||||
gameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
} else {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_launch_style);
|
||||
detail_tv_download.setText(String.format("启动《%s》",
|
||||
gameEntity.getName()));
|
||||
PackageManager mPackageManager = new PackageManager(this);
|
||||
if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& !mPackageManager.isSignature(gameEntity.getApk().get(0).getPackageName())
|
||||
) {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_plugin_style);
|
||||
detail_tv_download.setText(String.format("插件化《%s》",
|
||||
gameEntity.getName()));
|
||||
} else {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_plugin_style);
|
||||
detail_tv_download.setText(String.format("插件化《%s》%s",
|
||||
gameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
} else {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_launch_style);
|
||||
detail_tv_download.setText(String.format("启动《%s》%s",
|
||||
gameEntity.getName(), gameEntity.getDownloadAddWord()));
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_launch_style);
|
||||
detail_tv_download.setText(String.format("启动《%s》",
|
||||
gameEntity.getName()));
|
||||
} else {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_launch_style);
|
||||
detail_tv_download.setText(String.format("启动《%s》%s",
|
||||
gameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -210,7 +224,7 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_download_style);
|
||||
detail_tv_download.setText(String.format("下载《%s》%s",
|
||||
gameEntity.getName(), gameEntity.getDownloadAddWord()));
|
||||
gameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -246,13 +260,7 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
case done:
|
||||
EventBus.getDefault().post(new EBPutUrl(
|
||||
gameEntity.getApk().get(0).getPackageName(), mDownloadEntity.getUrl()));
|
||||
if (mDownloadEntity.isPluggable()) {
|
||||
detail_tv_per.setText("安装插件");
|
||||
} else if (mDownloadEntity.isUpdate()) {
|
||||
detail_tv_per.setText("安装更新");
|
||||
} else {
|
||||
detail_tv_per.setText("安装");
|
||||
}
|
||||
detail_tv_per.setText("安装");
|
||||
break;
|
||||
case cancel:
|
||||
case hijack:
|
||||
@ -315,9 +323,7 @@ public abstract class DetailActivity extends BaseActivity implements View.OnClic
|
||||
String str = detail_tv_per.getText().toString();
|
||||
if ("下载中".equals(str)) {
|
||||
startActivity(new Intent(this, DownloadManagerActivity.class));
|
||||
} else if ("安装插件".equals(str)) {
|
||||
|
||||
} else if ("安装".equals(str) || "安装更新".equals(str)) {
|
||||
} else if ("安装".equals(str)) {
|
||||
final String path = mDownloadEntity.getPath();
|
||||
PackageManager manager = new PackageManager(getApplicationContext());
|
||||
if (manager.launchSetup(path)) {
|
||||
|
||||
@ -127,16 +127,16 @@ public class DialogUtils {
|
||||
|
||||
public static void showDisclaimerDialog(Context context, String content) {
|
||||
final Dialog disclaimerDialog = new Dialog(context);
|
||||
View view = View.inflate(context, R.layout.setting_disclaimer_dialog, null);
|
||||
View view = View.inflate(context, R.layout.dialog_disclaimer, null);
|
||||
|
||||
TextView title = (TextView) view.findViewById(R.id.disclaimer_dialog_title);
|
||||
title.setText("免责声明");
|
||||
// TextView title = (TextView) view.findViewById(R.id.disclaimer_title);
|
||||
// title.setText("免责声明");
|
||||
|
||||
TextView message = (TextView) view.findViewById(R.id.disclaimer_dialog_message);
|
||||
TextView message = (TextView) view.findViewById(R.id.disclaimer_message);
|
||||
Spanned spanned = Html.fromHtml(content);
|
||||
message.setText(spanned);
|
||||
|
||||
view.findViewById(R.id.disclaimer_dialog_confirm).setOnClickListener(
|
||||
view.findViewById(R.id.disclaimer_confirm).setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
@ -645,7 +645,7 @@ public class DownloadItemUtils {
|
||||
DownloadEntity downloadEntity = entity.getEntryMap().get(entity.getEntryMap().keyAt(0));
|
||||
final String path = downloadEntity.getPath();
|
||||
if (FileUtils.isEmptyFile(path)) {
|
||||
Toast.makeText(context, "解析包错误", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(context, "解析包出错(可能被误删了),请重新下载", Toast.LENGTH_SHORT).show();
|
||||
DownloadManager.getInstance(context).cancel(
|
||||
entity.getEntryMap().get(entity.getEntryMap().keyAt(0)).getUrl());
|
||||
entity.getEntryMap().remove(entity.getEntryMap().keyAt(0));
|
||||
|
||||
@ -175,9 +175,16 @@ public class PackageUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有已安装的软件的包名、版本(非系统应用)
|
||||
*
|
||||
* @param context
|
||||
* 上下文
|
||||
* @return 已安装软件的包名的集合
|
||||
*/
|
||||
public static ArrayList<String> getAllPackageName(Context context) {
|
||||
FilterManager filterManager = new FilterManager(context);
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
List<PackageInfo> packageInfos = context.getPackageManager()
|
||||
.getInstalledPackages(0);
|
||||
for (int i = 0, size = packageInfos.size(); i < size; i++) {
|
||||
|
||||
@ -36,7 +36,7 @@ import java.util.Map;
|
||||
public class TokenUtils {
|
||||
|
||||
// 注册设备
|
||||
public static synchronized void register(final Context context) {
|
||||
public static synchronized String register(final Context context) {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
String android_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
if (!TextUtils.isEmpty(android_id)) {
|
||||
@ -50,31 +50,63 @@ public class TokenUtils {
|
||||
String mac = wm.getConnectionInfo().getMacAddress();
|
||||
if (!TextUtils.isEmpty(mac)) {
|
||||
params.put("MAC", mac);
|
||||
} else {
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
sp.edit().putBoolean("isUploadMac", false).apply();
|
||||
}
|
||||
String mid = StatConfig.getMid(context);
|
||||
if (!TextUtils.isEmpty(mid) || !"0".equals(mid)) {
|
||||
params.put("MTA_ID", mid);
|
||||
} else {
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
sp.edit().putBoolean("isUploadMid", false).apply();
|
||||
}
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(Request.Method.POST,
|
||||
"http://user.ghzhushou.com/v1d0/device/register", new JSONObject(params).toString(),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Utils.log("onResponse = " + response);
|
||||
try {
|
||||
// 保存device_id
|
||||
saveDeviceId(context, response.getString("device_id"));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
Utils.log("onErrorResponse = " + error);
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, TokenUtils.class);
|
||||
String url = "http://user.ghzhushou.com/v1d0/device/register";
|
||||
HttpURLConnection connection = null;
|
||||
try {
|
||||
JSONObject body = new JSONObject(params);
|
||||
connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.setRequestMethod("POST");
|
||||
|
||||
connection.addRequestProperty("Content-Type", "application/json; charset=utf-8");
|
||||
connection.addRequestProperty("Device", DeviceUtils.getDeviceHeader(context));
|
||||
|
||||
connection.connect();
|
||||
|
||||
OutputStreamWriter outputStream = new OutputStreamWriter(
|
||||
connection.getOutputStream(), "utf-8");
|
||||
outputStream.write(body.toString());
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
if (connection.getResponseCode() == 200) {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(connection.getInputStream()));
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
reader.close();
|
||||
|
||||
try {
|
||||
JSONObject response = new JSONObject(builder.toString());
|
||||
String device_id = response.getString("device_id");
|
||||
// 保存device_id
|
||||
saveDeviceId(context, device_id);
|
||||
Utils.log("device_id = " + device_id);
|
||||
return device_id;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取用户token
|
||||
|
||||
@ -648,7 +648,7 @@ public class DownloadDialog {
|
||||
|
||||
String path = entryMap.get(apkEntity.getUrl()).getPath();
|
||||
if (FileUtils.isEmptyFile(path)) {
|
||||
Toast.makeText(context, "解析包错误", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(context, "解析包出错(可能被误删了),请重新下载", Toast.LENGTH_SHORT).show();
|
||||
entryMap.remove(apkEntity.getUrl());
|
||||
DownloadManager.getInstance(context).cancel(apkEntity.getUrl());
|
||||
adapter.notifyItemChanged(location);
|
||||
@ -968,7 +968,7 @@ public class DownloadDialog {
|
||||
|
||||
final String path = entryMap.get(apkEntity.getUrl()).getPath();
|
||||
if (FileUtils.isEmptyFile(path)) {
|
||||
Toast.makeText(context, "解析包错误", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(context, "解析包出错(可能被误删了),请重新下载", Toast.LENGTH_SHORT).show();
|
||||
entryMap.remove(apkEntity.getUrl());
|
||||
DownloadManager.getInstance(context).cancel(apkEntity.getUrl());
|
||||
notifyItemChanged(position);
|
||||
|
||||
@ -1,61 +1,41 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.ConcernUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.Concern_LinearLayout;
|
||||
import com.gh.gamecenter.adapter.ConcernAdapter;
|
||||
import com.gh.gamecenter.adapter.ConcernRecommendAdapter;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
|
||||
private Concern_LinearLayout view;
|
||||
private RecyclerView concern_rv_show, concern_rv_recommend;
|
||||
private ConcernManager manager;
|
||||
private ConcernAdapter concernAdapter;
|
||||
private ConcernRecommendAdapter concernRecommendAdapter;
|
||||
private RelativeLayout concern_rl_title;
|
||||
private LinearLayout reuse_none_data;
|
||||
|
||||
private List<ConcernInfo> list;
|
||||
private List<GameEntity> recommendList;
|
||||
private List<GameEntity> concernList;
|
||||
private ConcernManager concernManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -64,19 +44,10 @@ public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
view = (Concern_LinearLayout) View.inflate(this, R.layout.activity_concern, null);
|
||||
init(view, "我的关注");
|
||||
|
||||
manager = new ConcernManager(getApplicationContext());
|
||||
concernManager = new ConcernManager(getApplicationContext());
|
||||
|
||||
list = manager.getConcernGame();
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
|
||||
recommendList = new ArrayList<>();
|
||||
concernList = new ArrayList<>();
|
||||
|
||||
if (!list.isEmpty()) {
|
||||
initConcernGame();
|
||||
} else {
|
||||
List<ConcernInfo> concernList = concernManager.getConcernGame();
|
||||
if (concernList == null || concernList.isEmpty()) {
|
||||
reuse_none_data.setVisibility(View.VISIBLE);
|
||||
concern_rv_show.setVisibility(View.GONE);
|
||||
}
|
||||
@ -84,14 +55,42 @@ public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
concern_rl_title.setOnClickListener(this);
|
||||
|
||||
concern_rv_show.setHasFixedSize(true);
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
|
||||
concern_rv_show.setLayoutManager(gridLayoutManager);
|
||||
concern_rv_show.setAdapter(new ConcernViewAdapter());
|
||||
concern_rv_show.setLayoutManager(new GridLayoutManager(this, 3));
|
||||
concernAdapter = new ConcernAdapter(this);
|
||||
concern_rv_show.setAdapter(concernAdapter);
|
||||
|
||||
concern_rv_recommend.setHasFixedSize(true);
|
||||
concern_rv_recommend.setLayoutManager(new GridLayoutManager(this, 4));
|
||||
concern_rv_recommend.setAdapter(new RecommendViewAdapter());
|
||||
concernRecommendAdapter = new ConcernRecommendAdapter(this);
|
||||
concern_rv_recommend.setAdapter(concernRecommendAdapter);
|
||||
}
|
||||
|
||||
initRecommendGame();
|
||||
@Override
|
||||
public void loadEmpty() {
|
||||
if (concernAdapter.getConcernList() == null
|
||||
|| concernAdapter.getConcernList().isEmpty()) {
|
||||
reuse_none_data.setVisibility(View.VISIBLE);
|
||||
concern_rv_show.setVisibility(View.GONE);
|
||||
}
|
||||
if (concernRecommendAdapter.getRecommendGameList() == null
|
||||
|| concernRecommendAdapter.getRecommendGameList().isEmpty()) {
|
||||
concern_rl_title.setVisibility(View.GONE);
|
||||
concern_rv_recommend.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (concernRecommendAdapter.getRecommendGameList().size() < 4) {
|
||||
concern_rv_recommend.setLayoutManager(new GridLayoutManager(
|
||||
ConcernActivity.this, concernRecommendAdapter.getRecommendGameList().size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone() {
|
||||
concern_rl_title.setVisibility(View.VISIBLE);
|
||||
concern_rv_recommend.setVisibility(View.VISIBLE);
|
||||
int size = concernRecommendAdapter.getRecommendGameList().size();
|
||||
concern_rv_recommend.setLayoutManager(new GridLayoutManager(this, size > 4 ? 4 : size));
|
||||
concern_rv_recommend.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -107,314 +106,32 @@ public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
|
||||
// 关注事件
|
||||
public void onEventMainThread(EBConcernChanged changed) {
|
||||
|
||||
}
|
||||
|
||||
private void initRecommendGame() {
|
||||
JsonArrayExtendedRequest recommendRequest = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST + "v1d45/game/remenkapai",
|
||||
Constants.GAME_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
processingData(response);
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(recommendRequest, ConcernActivity.class);
|
||||
}
|
||||
|
||||
private void processingData(JSONArray response) {
|
||||
Type listType = new TypeToken<ArrayList<GameEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<GameEntity> list = gson.fromJson(response.toString(), listType);
|
||||
recommendList.clear();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
if (!manager.isConcern(list.get(i).getId())) {
|
||||
recommendList.add(list.get(i));
|
||||
}
|
||||
}
|
||||
if (!recommendList.isEmpty()) {
|
||||
concern_rl_title.setVisibility(View.VISIBLE);
|
||||
concern_rv_recommend.setVisibility(View.VISIBLE);
|
||||
concern_rv_recommend.setLayoutManager(new GridLayoutManager(this,
|
||||
recommendList.size() > 4 ? 4 : recommendList.size()));
|
||||
concern_rv_recommend.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private int cCount;
|
||||
|
||||
private void addConcernCount() {
|
||||
synchronized (ConcernActivity.class) {
|
||||
cCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private void initConcernGame() {
|
||||
final List<JSONObject> result = new ArrayList<>();
|
||||
final int count = list.size();
|
||||
cCount = 0;
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
JsonObjectExtendedRequest concernObjectRequest = new JsonObjectExtendedRequest(
|
||||
TimestampUtils.addTimestamp(
|
||||
Config.HOST + "v2d0/game/" + list.get(i).getId() + "/digest",
|
||||
Constants.GAME_CD),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
addConcernCount();
|
||||
result.add(response);
|
||||
if (cCount == count) {
|
||||
processingConcernGame(result);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addConcernCount();
|
||||
if (cCount == count) {
|
||||
processingConcernGame(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(concernObjectRequest, ConcernActivity.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void processingConcernGame(List<JSONObject> data) {
|
||||
List<GameEntity> gameList = new ArrayList<>();
|
||||
Gson gson = new Gson();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
gameList.add(gson.fromJson(data.get(i).toString(), GameEntity.class));
|
||||
}
|
||||
concernList.clear();
|
||||
for (int i = 0, sizei = list.size(); i < sizei; i++) {
|
||||
for (int j = 0, sizej = gameList.size(); j < sizej; j++) {
|
||||
if (list.get(i).getId().equals(gameList.get(j).getId())) {
|
||||
concernList.add(gameList.get(j));
|
||||
break;
|
||||
Utils.log("changed = " + changed.getGameId());
|
||||
Utils.log("changed = " + changed.isConcern());
|
||||
if (changed.isConcern()) {
|
||||
for (GameEntity gameEntity : concernRecommendAdapter.getGameList()) {
|
||||
if (changed.getGameId().equals(gameEntity.getId())) {
|
||||
ConcernInfo concernInfo = new ConcernInfo();
|
||||
concernInfo.setGameName(gameEntity.getName());
|
||||
concernInfo.setConcern(true);
|
||||
concernInfo.setIcon(gameEntity.getIcon());
|
||||
concernInfo.setId(gameEntity.getId());
|
||||
concernAdapter.getConcernList().add(concernInfo);
|
||||
concernAdapter.getConcernGameList().add(gameEntity);
|
||||
concernAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
concern_rv_show.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private class ConcernViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView concern_item_icon;
|
||||
private TextView concern_item_name, concern_item_btn;
|
||||
|
||||
public ConcernViewHolder(View convertView) {
|
||||
super(convertView);
|
||||
concern_item_icon = (ImageView) convertView.findViewById(R.id.concern_item_icon);
|
||||
concern_item_name = (TextView) convertView.findViewById(R.id.concern_item_name);
|
||||
concern_item_btn = (TextView) convertView.findViewById(R.id.concern_item_btn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ConcernViewAdapter extends
|
||||
RecyclerView.Adapter<ConcernViewHolder> {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final ConcernViewHolder holder, int position) {
|
||||
ConcernInfo concernEntity = list.get(position);
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
concernEntity.getIcon(), holder.concern_item_icon);
|
||||
holder.concern_item_name.setText(concernEntity.getGameName());
|
||||
holder.concern_item_btn.setText("取消关注");
|
||||
holder.concern_item_btn.setBackgroundResource(R.drawable.textview_cancel_style);
|
||||
holder.concern_item_btn.setClickable(true);
|
||||
holder.concern_item_btn.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 删除关注表中的数据,并更新界面
|
||||
DialogUtils.showCancelDialog(ConcernActivity.this, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
if (manager.findConcernById(list.get(holder.getPosition()).getId()) != null) {
|
||||
ConcernInfo concernInfo = list.remove(holder.getPosition());
|
||||
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("状态", "取消关注");
|
||||
DataUtils.onEvent(ConcernActivity.this, "游戏关注", concernInfo.getGameName(), kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("game", concernInfo.getGameName());
|
||||
map.put("game_id", concernInfo.getId());
|
||||
map.put("type", "取消关注");
|
||||
DataCollectionManager.onEvent(ConcernActivity.this, "concern", map);
|
||||
|
||||
manager.deleteConcern(concernInfo.getId());
|
||||
concernList.remove(holder.getPosition());
|
||||
concern_rv_show.getAdapter().notifyItemRemoved(holder.getPosition());
|
||||
if (list.isEmpty()) {
|
||||
reuse_none_data.setVisibility(View.VISIBLE);
|
||||
concern_rv_show.setVisibility(View.GONE);
|
||||
}
|
||||
holder.concern_item_btn.setClickable(false);
|
||||
view.setClickable(false);
|
||||
|
||||
recommendList = new ArrayList<>();
|
||||
initRecommendGame();
|
||||
} else {
|
||||
toast("取消失败,请稍后再试");
|
||||
}
|
||||
}
|
||||
});
|
||||
} 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));
|
||||
}
|
||||
});
|
||||
holder.itemView.setClickable(true);
|
||||
holder.itemView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (concernList != null && !concernList.isEmpty()) {
|
||||
GameEntity gameEntity = concernList.get(holder.getPosition());
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("location", "关注列表");
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("game_id", gameEntity.getId());
|
||||
map.put("page", "我的关注");
|
||||
DataCollectionManager.onEvent(ConcernActivity.this, "click-item", map);
|
||||
|
||||
AppController.put("GameEntity", gameEntity);
|
||||
Intent intent = new Intent(ConcernActivity.this, GameDetailActivity.class);
|
||||
intent.putExtra("entrance", "我的关注-列表");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConcernViewHolder onCreateViewHolder(ViewGroup viewGroup,
|
||||
int type) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.concern_item, viewGroup, false);
|
||||
return new ConcernViewHolder(view);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class RecommendViewHolder extends RecyclerView.ViewHolder implements
|
||||
OnClickListener {
|
||||
|
||||
private ImageView concern_item_icon;
|
||||
private TextView concern_item_name, concern_item_btn;
|
||||
private View view;
|
||||
|
||||
public RecommendViewHolder(View convertView) {
|
||||
super(convertView);
|
||||
|
||||
concern_item_icon = (ImageView) convertView.findViewById(R.id.concern_item_icon);
|
||||
concern_item_name = (TextView) convertView.findViewById(R.id.concern_item_name);
|
||||
concern_item_btn = (TextView) convertView.findViewById(R.id.concern_item_btn);
|
||||
concern_item_btn.setOnClickListener(this);
|
||||
convertView.setOnClickListener(this);
|
||||
view = convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = getPosition();
|
||||
if (v == concern_item_btn) {
|
||||
// 添加关注到表,并更新当前界面,插入一个关注
|
||||
GameEntity gameEntity = recommendList.get(position);
|
||||
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("状态", "关注");
|
||||
DataUtils.onEvent(ConcernActivity.this, "游戏关注", gameEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("game_id", gameEntity.getId());
|
||||
map.put("type", "关注");
|
||||
DataCollectionManager.onEvent(ConcernActivity.this, "concern", map);
|
||||
|
||||
manager.addByEntity(gameEntity);
|
||||
ConcernInfo concernEntity = new ConcernInfo();
|
||||
concernEntity.setGameName(gameEntity.getName());
|
||||
concernEntity.setConcern(true);
|
||||
concernEntity.setIcon(gameEntity.getIcon());
|
||||
concernEntity.setId(gameEntity.getId());
|
||||
list.add(concernEntity);
|
||||
if (list.size() == 1) {
|
||||
reuse_none_data.setVisibility(View.GONE);
|
||||
concern_rv_show.setVisibility(View.VISIBLE);
|
||||
}
|
||||
concern_rv_show.getAdapter().notifyItemInserted(list.size() - 1);
|
||||
|
||||
concernList.add(recommendList.remove(position));
|
||||
if (recommendList.isEmpty()) {
|
||||
concern_rl_title.setVisibility(View.GONE);
|
||||
concern_rv_recommend.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (recommendList.size() < 4) {
|
||||
concern_rv_recommend.setLayoutManager(new GridLayoutManager(
|
||||
ConcernActivity.this, recommendList.size()));
|
||||
}
|
||||
concern_rv_recommend.getAdapter().notifyItemRemoved(position);
|
||||
}
|
||||
concern_item_btn.setClickable(false);
|
||||
view.setClickable(false);
|
||||
|
||||
toast("关注成功");
|
||||
} else {
|
||||
GameEntity gameEntity = recommendList.get(position);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("location", "热门游戏推荐");
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("game_id", gameEntity.getId());
|
||||
map.put("page", "我的关注");
|
||||
DataCollectionManager.onEvent(ConcernActivity.this, "click-item", map);
|
||||
|
||||
AppController.put("GameEntity", gameEntity);
|
||||
|
||||
Intent intent = new Intent(ConcernActivity.this, GameDetailActivity.class);
|
||||
intent.putExtra("entrance", "我的关注-推荐");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
}
|
||||
concernRecommendAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private class RecommendViewAdapter extends RecyclerView.Adapter<RecommendViewHolder> {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return recommendList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecommendViewHolder holder, int position) {
|
||||
GameEntity gameEntity = recommendList.get(position);
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
gameEntity.getIcon(), holder.concern_item_icon);
|
||||
holder.concern_item_name.setText(gameEntity.getName());
|
||||
holder.concern_item_btn.setText("关注");
|
||||
holder.concern_item_btn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
holder.concern_item_btn.setClickable(true);
|
||||
holder.view.setClickable(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecommendViewHolder onCreateViewHolder(ViewGroup viewGroup,
|
||||
int type) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.concern_item, viewGroup, false);
|
||||
return new RecommendViewHolder(view);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isPause = false;
|
||||
|
||||
@Override
|
||||
@ -428,35 +145,24 @@ public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
super.onResume();
|
||||
Utils.log("isPause = " + isPause);
|
||||
if (isPause) {
|
||||
List<ConcernInfo> concernList = manager.getConcernGame();
|
||||
List<ConcernInfo> concernList = concernManager.getConcernGame();
|
||||
boolean isChanged = false;
|
||||
if (concernList == null) {
|
||||
if (list.size() != 0){
|
||||
if (concernAdapter.getConcernList().size() != 0){
|
||||
isChanged = true;
|
||||
}
|
||||
} else {
|
||||
if (list.isEmpty()
|
||||
|| concernList.size() > list.size()
|
||||
|| concernList.size() < list.size()) {
|
||||
if (concernAdapter.getConcernList() == null
|
||||
|| concernAdapter.getConcernList().isEmpty()
|
||||
|| concernList.size() > concernAdapter.getConcernList().size()
|
||||
|| concernList.size() < concernAdapter.getConcernList().size()) {
|
||||
isChanged = true;
|
||||
}
|
||||
}
|
||||
Utils.log("isChanged = " + isChanged);
|
||||
if (isChanged) {
|
||||
list = concernList;
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
if (!list.isEmpty()) {
|
||||
reuse_none_data.setVisibility(View.GONE);
|
||||
concern_rv_show.setVisibility(View.VISIBLE);
|
||||
initConcernGame();
|
||||
} else {
|
||||
reuse_none_data.setVisibility(View.VISIBLE);
|
||||
concern_rv_show.setVisibility(View.GONE);
|
||||
}
|
||||
recommendList = new ArrayList<>();
|
||||
initRecommendGame();
|
||||
concernAdapter = new ConcernAdapter(this);
|
||||
concern_rv_show.setAdapter(concernAdapter);
|
||||
}
|
||||
isPause = false;
|
||||
}
|
||||
@ -465,9 +171,9 @@ public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
String uuid = ConcernUtils.uuid(this);
|
||||
String uuid = TokenUtils.getDeviceId(this);
|
||||
JSONArray data = new JSONArray();
|
||||
for (ConcernInfo concernInfo : manager.getConcernGame()) {
|
||||
for (ConcernInfo concernInfo : concernManager.getConcernGame()) {
|
||||
data.put(concernInfo.getId());
|
||||
}
|
||||
ConcernUtils.updateConcernData(Config.HOST + "v2d0/device/" + uuid + "/concern", data,
|
||||
@ -485,11 +191,7 @@ public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
view = null;
|
||||
concern_rv_show = null;
|
||||
concern_rv_recommend = null;
|
||||
manager = null;
|
||||
concern_rl_title = null;
|
||||
reuse_none_data = null;
|
||||
list = null;
|
||||
recommendList = null;
|
||||
concernList = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,98 +1,39 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.base.DetailActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.MD5Utils;
|
||||
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.util.TimestampUtils;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBPutUrl;
|
||||
import com.gh.gamecenter.gamedetail.GameDetailAdapter;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.tencent.tauth.Tencent;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/8/12.
|
||||
*/
|
||||
public class GameDetailActivity extends BaseActivity implements View.OnClickListener{
|
||||
public class GameDetailActivity extends DetailActivity implements View.OnClickListener{
|
||||
|
||||
private RecyclerView gamedetail_rv_show;
|
||||
private GameDetailAdapter adapter;
|
||||
private LinearLayout gamedetail_ll_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private LinearLayout gamedetail_ll_bottom;
|
||||
private TextView gamedetail_tv_download;
|
||||
private TextView gamedetail_tv_per;
|
||||
private TextView actionbar_tv_title;
|
||||
private ProgressBar gamedetail_progressbar;
|
||||
private ImageView iv_share;
|
||||
|
||||
private GameEntity gameEntity;
|
||||
private DownloadEntity mDownloadEntity;
|
||||
|
||||
private String entrance;
|
||||
private String gameId;
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
if (gameEntity != null && gameEntity.getApk().size() == 1) {
|
||||
String url = gameEntity.getApk().get(0).getUrl();
|
||||
if (url.equals(downloadEntity.getUrl())) {
|
||||
if (!"pause".equals(DownloadManager.getInstance(GameDetailActivity.this).
|
||||
getStatus(downloadEntity.getUrl()))) {
|
||||
mDownloadEntity = downloadEntity;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
@ -103,39 +44,25 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_gamedetail, null);
|
||||
|
||||
// 添加分享图标
|
||||
iv_share = new ImageView(this);
|
||||
iv_share.setImageResource(R.drawable.share_icon);
|
||||
iv_share.setOnClickListener(this);
|
||||
iv_share.setVisibility(View.GONE);
|
||||
iv_share.setPadding(DisplayUtils.dip2px(this, 13),DisplayUtils.dip2px(this, 11),DisplayUtils.dip2px(this, 11),DisplayUtils.dip2px(this, 13));
|
||||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
||||
DisplayUtils.dip2px(this, 48), DisplayUtils.dip2px(this, 48));
|
||||
params.addRule( RelativeLayout.CENTER_VERTICAL);
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT );
|
||||
|
||||
RelativeLayout reuse_actionbar = (RelativeLayout) contentView.findViewById(R.id.reuse_actionbar);
|
||||
reuse_actionbar.addView(iv_share, params);
|
||||
|
||||
init(contentView);
|
||||
name = "游戏详情";
|
||||
|
||||
gameId = getIntent().getStringExtra("gameId");
|
||||
entrance = getIntent().getStringExtra("entrance");
|
||||
if (gameId == null) {
|
||||
gameEntity = (GameEntity) AppController.get("GameEntity", true);
|
||||
gameId = gameEntity.getId();
|
||||
actionbar_tv_title.setText(gameEntity.getName());
|
||||
if (gameEntity != null) {
|
||||
gameId = gameEntity.getId();
|
||||
title = gameEntity.getName();
|
||||
actionbar_tv_title.setText(gameEntity.getName());
|
||||
}
|
||||
}
|
||||
|
||||
adapter = new GameDetailAdapter(this, gameId, entrance);
|
||||
gamedetail_rv_show.setLayoutManager(new LinearLayoutManager(this));
|
||||
gamedetail_rv_show.setAdapter(adapter);
|
||||
detail_rv_show.setLayoutManager(new LinearLayoutManager(this));
|
||||
detail_rv_show.setAdapter(adapter);
|
||||
|
||||
gamedetail_ll_bottom.setOnClickListener(this);
|
||||
gamedetail_tv_download.setOnClickListener(this);
|
||||
gamedetail_tv_per.setOnClickListener(this);
|
||||
detail_ll_bottom.setOnClickListener(this);
|
||||
detail_tv_download.setOnClickListener(this);
|
||||
detail_tv_per.setOnClickListener(this);
|
||||
reuse_no_connection.setOnClickListener(this);
|
||||
|
||||
if (gameEntity != null) {
|
||||
@ -146,164 +73,34 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList
|
||||
}
|
||||
}
|
||||
|
||||
//接受QQ或者QQ空间分享回调
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == com.tencent.connect.common.Constants.REQUEST_QQ_SHARE
|
||||
|| requestCode == com.tencent.connect.common.Constants.REQUEST_QZONE_SHARE) {
|
||||
Tencent.onActivityResultData(requestCode, resultCode, data, ShareUtils.getInstance(this).QqShareListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone() {
|
||||
if (!isDestroy) {
|
||||
if (gamedetail_ll_loading.getVisibility() == View.VISIBLE) {
|
||||
gamedetail_ll_loading.setVisibility(View.GONE);
|
||||
if (reuse_ll_loading.getVisibility() == View.VISIBLE) {
|
||||
reuse_ll_loading.setVisibility(View.GONE);
|
||||
}
|
||||
if (!TextUtils.isEmpty(adapter.getGameDetailEntity().getShareCode())) {
|
||||
iv_share.setVisibility(View.VISIBLE);
|
||||
}
|
||||
initDownload();
|
||||
downloadAddWord = adapter.getGameDetailEntity().getDownloadAddWord();
|
||||
initDownload(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadError() {
|
||||
if (!isDestroy) {
|
||||
gamedetail_ll_loading.setVisibility(View.GONE);
|
||||
reuse_ll_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化bottom
|
||||
private void initDownload() {
|
||||
if (Config.isShow(this)) {
|
||||
gamedetail_ll_bottom.setVisibility(View.VISIBLE);
|
||||
gamedetail_rv_show.setPadding(0, 0, 0, DisplayUtils.dip2px(this, 44));
|
||||
} else {
|
||||
gamedetail_ll_bottom.setVisibility(View.GONE);
|
||||
gamedetail_rv_show.setPadding(0, 0, 0, 0);
|
||||
}
|
||||
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
|
||||
gamedetail_tv_download.setText("暂无下载");
|
||||
gamedetail_tv_download.setBackgroundResource(R.drawable.game_item_btn_pause_style);
|
||||
gamedetail_tv_download.setTextColor(0xFF999999);
|
||||
gamedetail_tv_download.setClickable(false);
|
||||
} else {
|
||||
gamedetail_tv_download.setVisibility(View.VISIBLE);
|
||||
gamedetail_progressbar.setVisibility(View.GONE);
|
||||
gamedetail_tv_per.setVisibility(View.GONE);
|
||||
boolean isInstalled = false;
|
||||
if (gameEntity.getApk().size() == 1
|
||||
&& PackageManager.isInstalled(gameEntity.getApk().get(0).getPackageName())) {
|
||||
isInstalled = true;
|
||||
}
|
||||
if (isInstalled) {
|
||||
PackageManager mPackageManager = new PackageManager(this);
|
||||
if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& !mPackageManager.isSignature(gameEntity.getApk().get(0).getPackageName())) {
|
||||
gamedetail_tv_download.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
if (adapter.getGameDetailEntity() == null
|
||||
|| TextUtils.isEmpty(adapter.getGameDetailEntity().getDownloadAddWord())) {
|
||||
gamedetail_tv_download.setText(String.format("插件化《%s》",
|
||||
gameEntity.getName()));
|
||||
} else {
|
||||
gamedetail_tv_download.setText(String.format("插件化《%s》%s",
|
||||
gameEntity.getName(), adapter.getGameDetailEntity().getDownloadAddWord()));
|
||||
}
|
||||
} else {
|
||||
gamedetail_tv_download.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
if (adapter.getGameDetailEntity() == null
|
||||
|| TextUtils.isEmpty(adapter.getGameDetailEntity().getDownloadAddWord())) {
|
||||
gamedetail_tv_download.setText(String.format("启动《%s》",
|
||||
gameEntity.getName()));
|
||||
} else {
|
||||
gamedetail_tv_download.setText(String.format("启动《%s》%s",
|
||||
gameEntity.getName(), adapter.getGameDetailEntity().getDownloadAddWord()));
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else if (gameEntity.getApk().size() == 1) {
|
||||
String url = gameEntity.getApk().get(0).getUrl();
|
||||
for (DownloadEntity entry : DownloadManager.getInstance(getApplicationContext()).getAll()) {
|
||||
if (url.equals(entry.getUrl())) {
|
||||
mDownloadEntity = entry;
|
||||
gamedetail_tv_download.setVisibility(View.GONE);
|
||||
gamedetail_progressbar.setVisibility(View.VISIBLE);
|
||||
gamedetail_tv_per.setVisibility(View.VISIBLE);
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
gamedetail_tv_download.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
if (adapter.getGameDetailEntity() == null
|
||||
|| TextUtils.isEmpty(adapter.getGameDetailEntity().getDownloadAddWord())) {
|
||||
gamedetail_tv_download.setText(String.format("下载《%s》",
|
||||
gameEntity.getName()));
|
||||
} else {
|
||||
gamedetail_tv_download.setText(String.format("下载《%s》%s",
|
||||
gameEntity.getName(), adapter.getGameDetailEntity().getDownloadAddWord()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
int id = v.getId();
|
||||
if (id == R.id.gamedetail_tv_download) {
|
||||
Map<String, Object> kv0 = new HashMap<>();
|
||||
kv0.put("点击", "下载");
|
||||
DataUtils.onEvent(GameDetailActivity.this, "插件数据", gameEntity.getName(), kv0);
|
||||
if (gameEntity.getApk() != null && !gameEntity.getApk().isEmpty()) {
|
||||
if (gameEntity.getApk().size() == 1) {
|
||||
if (NetworkUtils.isWifiConnected(this)) {
|
||||
download();
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(this, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
download();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
DownloadDialog.getInstance(GameDetailActivity.this)
|
||||
.showPopupWindow(v, gameEntity, entrance + "-游戏详情",
|
||||
"游戏详情:" + gameEntity.getName());
|
||||
}
|
||||
} else {
|
||||
toast("稍等片刻~!游戏正在上传中...");
|
||||
}
|
||||
} else if (id == R.id.gamedetail_tv_per) {
|
||||
String str = gamedetail_tv_per.getText().toString();
|
||||
if ("下载中".equals(str)) {
|
||||
startActivity(new Intent(this, DownloadManagerActivity.class));
|
||||
} else if ("安装".equals(str)) {
|
||||
final String path = mDownloadEntity.getPath();
|
||||
PackageManager manager = new PackageManager(this);
|
||||
if (manager.launchSetup(path)) {
|
||||
EventBus.getDefault().post(new EBPutUrl(mDownloadEntity.getPackageName(), mDownloadEntity.getUrl()));
|
||||
startActivity(PackageUtils.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showPluginDialog(this, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
MainActivity.uninstallMap.put(
|
||||
PackageUtils.getPackageNameByPath(GameDetailActivity.this, path), path);
|
||||
startActivity(PackageUtils.getUninstallIntent(GameDetailActivity.this,
|
||||
path));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (id == R.id.reuse_no_connection) {
|
||||
public void onClick(View v) {
|
||||
super.onClick(v);
|
||||
if (v == reuse_no_connection) {
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
gamedetail_ll_loading.setVisibility(View.VISIBLE);
|
||||
reuse_ll_loading.setVisibility(View.VISIBLE);
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -314,7 +111,7 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
} else if (v instanceof ImageView) {
|
||||
} else if (v == iv_share) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("点击", "分享");
|
||||
DataUtils.onEvent(this, "插件数据", gameEntity.getName(), kv);
|
||||
@ -330,170 +127,6 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList
|
||||
}
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
gamedetail_progressbar.setProgress((int) (mDownloadEntity.getPercent() * 10));
|
||||
gamedetail_tv_per.setTextColor(0xFFFFFFFF);
|
||||
switch (mDownloadEntity.getStatus()) {
|
||||
case downloading:
|
||||
case pause:
|
||||
case timeout:
|
||||
case neterror:
|
||||
case waiting:
|
||||
gamedetail_tv_per.setText("下载中");
|
||||
break;
|
||||
case done:
|
||||
EventBus.getDefault().post(new EBPutUrl(
|
||||
gameEntity.getApk().get(0).getPackageName(), mDownloadEntity.getUrl()));
|
||||
gamedetail_tv_per.setText("安装");
|
||||
break;
|
||||
case cancel:
|
||||
case hijack:
|
||||
gamedetail_tv_download.setVisibility(View.VISIBLE);
|
||||
gamedetail_progressbar.setVisibility(View.GONE);
|
||||
gamedetail_tv_per.setVisibility(View.GONE);
|
||||
gamedetail_tv_download.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
if (adapter.getGameDetailEntity() == null
|
||||
|| TextUtils.isEmpty(adapter.getGameDetailEntity().getDownloadAddWord())) {
|
||||
gamedetail_tv_download.setText(String.format("下载《%s》",
|
||||
gameEntity.getName()));
|
||||
} else {
|
||||
gamedetail_tv_download.setText(String.format("下载《%s》%s",
|
||||
gameEntity.getName(), adapter.getGameDetailEntity().getDownloadAddWord()));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void download() {
|
||||
if (gamedetail_tv_download.getText().toString().contains("启动")) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", gameEntity.getApk().get(0).getPlatform());
|
||||
DataUtils.onEvent(GameDetailActivity.this, "游戏启动",
|
||||
gameEntity.getName(), kv);
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(
|
||||
this, gameEntity.getApk().get(0).getPackageName());
|
||||
} else {
|
||||
ApkEntity apkEntity = gameEntity.getApk().get(0);
|
||||
String msg = FileUtils.isCanDownload(apkEntity.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(GameDetailActivity.this,
|
||||
"游戏下载", gameEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<>();
|
||||
kv2.put("版本", apkEntity.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-游戏详情-开始");
|
||||
DataUtils.onEvent(GameDetailActivity.this,
|
||||
"游戏下载位置", gameEntity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv3 = new HashMap<>();
|
||||
kv3.put(entrance, "下载数");
|
||||
kv3.put(entrance, "下载开始");
|
||||
DataUtils.onEvent(GameDetailActivity.this,
|
||||
"应用数据", gameEntity.getName(), kv3);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("game_id", gameEntity.getId());
|
||||
map.put("method", "正常");
|
||||
map.put("platform",
|
||||
PlatformUtils.getInstance(this)
|
||||
.getPlatformName(
|
||||
gameEntity.getApk().get(0)
|
||||
.getPlatform()));
|
||||
map.put("status", "开始");
|
||||
map.put("location", "游戏详情:" + gameEntity.getName());
|
||||
map.put("from", entrance);
|
||||
map.put("network", NetworkUtils.getConnectedType(this));
|
||||
DataCollectionManager.onEvent(this, "download", map);
|
||||
|
||||
DownloadEntity downloadEntity = new DownloadEntity();
|
||||
downloadEntity.setUrl(apkEntity.getUrl());
|
||||
downloadEntity.setName(gameEntity.getName());
|
||||
downloadEntity.setPath(FileUtils.getDownloadPath(GameDetailActivity.this,
|
||||
MD5Utils.getContentMD5(gameEntity.getName() + "_"
|
||||
+ System.currentTimeMillis()) + ".apk"));
|
||||
downloadEntity.setPlatform(apkEntity.getPlatform());
|
||||
downloadEntity.setETag(apkEntity.getEtag());
|
||||
downloadEntity.setIcon(gameEntity.getIcon());
|
||||
downloadEntity.setGameId(gameEntity.getId());
|
||||
downloadEntity.setEntrance(entrance + "-游戏详情");
|
||||
downloadEntity.setLocation("游戏详情:" + gameEntity.getName());
|
||||
|
||||
DownloadManager.getInstance(this).add(downloadEntity);
|
||||
|
||||
gamedetail_tv_download.setVisibility(View.GONE);
|
||||
gamedetail_progressbar.setVisibility(View.VISIBLE);
|
||||
gamedetail_tv_per.setVisibility(View.VISIBLE);
|
||||
gamedetail_progressbar.setProgress(0);
|
||||
gamedetail_tv_per.setText("0.0%");
|
||||
|
||||
DownloadManager.getInstance(this).putStatus(downloadEntity.getUrl(), "downloading");
|
||||
|
||||
} else {
|
||||
toast(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
if (gameEntity != null && gameEntity.getApk().size() == 1) {
|
||||
String packageName = gameEntity.getApk().get(0).getPackageName();
|
||||
if (packageName.equals(busFour.getPackageName())) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
gamedetail_tv_download.setVisibility(View.VISIBLE);
|
||||
gamedetail_progressbar.setVisibility(View.GONE);
|
||||
gamedetail_tv_per.setVisibility(View.GONE);
|
||||
gamedetail_tv_download.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
gamedetail_tv_download.setText(String.format("启动《%s》", gameEntity.getName()));
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
gamedetail_tv_download.setVisibility(View.VISIBLE);
|
||||
gamedetail_progressbar.setVisibility(View.GONE);
|
||||
gamedetail_tv_per.setVisibility(View.GONE);
|
||||
gamedetail_tv_download.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
gamedetail_tv_download.setText(String.format("下载《%s》", gameEntity.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//接收下载被删除消息
|
||||
public void onEventMainThread(EBDownloadStatus status) {
|
||||
if ("delete".equals(status.getStatus())) {
|
||||
if (gameEntity != null && gameEntity.getApk().size() == 1) {
|
||||
String url = gameEntity.getApk().get(0).getUrl();
|
||||
if (url.equals(status.getUrl())) {
|
||||
gamedetail_tv_download.setVisibility(View.VISIBLE);
|
||||
gamedetail_progressbar.setVisibility(View.GONE);
|
||||
gamedetail_tv_per.setVisibility(View.GONE);
|
||||
gamedetail_tv_download.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
if (adapter.getGameDetailEntity() == null
|
||||
|| TextUtils.isEmpty(adapter.getGameDetailEntity().getDownloadAddWord())) {
|
||||
gamedetail_tv_download.setText(String.format("下载《%s》",
|
||||
gameEntity.getName()));
|
||||
} else {
|
||||
gamedetail_tv_download.setText(String.format("下载《%s》%s",
|
||||
gameEntity.getName(), adapter.getGameDetailEntity().getDownloadAddWord()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 关注事件
|
||||
public void onEventMainThread(EBConcernChanged changed) {
|
||||
if (!TextUtils.isEmpty(gameId) && changed.getGameId().equals(gameId)) {
|
||||
adapter.notifyItemChanged(0);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取游戏摘要
|
||||
private void getGameDigest() {
|
||||
String url = TimestampUtils.addTimestamp(Config.HOST + "v2d0/game/" + gameId + "/digest",
|
||||
@ -505,6 +138,7 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList
|
||||
if (!isDestroy) {
|
||||
Gson gson = new Gson();
|
||||
gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
title = gameEntity.getName();
|
||||
actionbar_tv_title.setText(gameEntity.getName());
|
||||
adapter.setGameEntity(gameEntity);
|
||||
adapter.getGameDetail();
|
||||
@ -519,56 +153,17 @@ public class GameDetailActivity extends BaseActivity implements View.OnClickList
|
||||
AppController.addToRequestQueue(request, GameDetailActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (gameEntity != null && gameEntity.getApk().size() == 1) {
|
||||
if (PackageManager.isInstalled(gameEntity.getApk().get(0)
|
||||
.getPackageName())) {
|
||||
gamedetail_tv_download.setVisibility(View.VISIBLE);
|
||||
gamedetail_progressbar.setVisibility(View.GONE);
|
||||
gamedetail_tv_per.setVisibility(View.GONE);
|
||||
gamedetail_tv_download.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
if (adapter.getGameDetailEntity() == null
|
||||
|| TextUtils.isEmpty(adapter.getGameDetailEntity().getDownloadAddWord())) {
|
||||
gamedetail_tv_download.setText(String.format("启动《%s》",
|
||||
gameEntity.getName()));
|
||||
} else {
|
||||
gamedetail_tv_download.setText(String.format("启动《%s》%s",
|
||||
gameEntity.getName(), gameEntity.getDownloadAddWord()));
|
||||
}
|
||||
} else {
|
||||
String url = gameEntity.getApk().get(0).getUrl();
|
||||
for (DownloadEntity entry : DownloadManager.getInstance(this).getAll()) {
|
||||
if (url.equals(entry.getUrl())) {
|
||||
mDownloadEntity = entry;
|
||||
gamedetail_tv_download.setVisibility(View.GONE);
|
||||
gamedetail_progressbar.setVisibility(View.VISIBLE);
|
||||
gamedetail_tv_per.setVisibility(View.VISIBLE);
|
||||
invalidate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 关注事件
|
||||
public void onEventMainThread(EBConcernChanged changed) {
|
||||
if (!TextUtils.isEmpty(gameId) && changed.getGameId().equals(gameId)) {
|
||||
adapter.notifyItemChanged(0);
|
||||
}
|
||||
DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
entrance = null;
|
||||
adapter = null;
|
||||
gamedetail_rv_show = null;
|
||||
gamedetail_ll_loading = null;
|
||||
reuse_no_connection = null;
|
||||
gameEntity = null;
|
||||
gamedetail_tv_download = null;
|
||||
gamedetail_tv_per = null;
|
||||
gamedetail_progressbar = null;
|
||||
mDownloadEntity = null;
|
||||
handler = null;
|
||||
iv_share = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -8,15 +8,19 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
@ -49,6 +53,7 @@ import com.gh.common.util.RunningUtils;
|
||||
import com.gh.common.util.SpeedUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
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;
|
||||
@ -69,7 +74,6 @@ import com.gh.gamecenter.eventbus.EBShowDialog;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.eventbus.EBTopStatus;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.game.Game1Fragment;
|
||||
import com.gh.gamecenter.game.GameFragment;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
@ -84,6 +88,7 @@ import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.StringExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.tencent.stat.StatConfig;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@ -127,6 +132,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
private TextView home1Title, home2Title, home3Title;
|
||||
|
||||
private SharedPreferences sp;
|
||||
private ConcernManager concernManager;
|
||||
|
||||
private ArrayMap<String, String> entryMap;
|
||||
|
||||
@ -134,6 +140,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
|
||||
private boolean isDestroy = false;
|
||||
private boolean isShowDownload = false;
|
||||
private boolean isNewFirstLaunch;
|
||||
|
||||
private Dialog dialog;
|
||||
private ProgressBar app_pb_progress;
|
||||
@ -410,64 +417,291 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
getSearchHints();
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
concernManager = new ConcernManager(getApplicationContext());
|
||||
|
||||
if (!sp.getBoolean("isNewFirstLaunch", true)
|
||||
&& sp.getBoolean("autoupdate", true)) {
|
||||
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunch", true);
|
||||
|
||||
if (!isNewFirstLaunch && sp.getBoolean("autoupdate", true)) {
|
||||
checkUpdate();
|
||||
}
|
||||
|
||||
if (sp.getBoolean("isNewFirstLaunch", true)) {
|
||||
if (isNewFirstLaunch) {
|
||||
getPluginUpdate();
|
||||
getDisclaimer(true);
|
||||
// 注册设备
|
||||
TokenUtils.register(this);
|
||||
sp.edit().putBoolean("isNewFirstLaunch", false).apply();
|
||||
} else {
|
||||
getDisclaimer(false);
|
||||
handler.postDelayed(runnable, 500);
|
||||
}
|
||||
|
||||
getDisclaimer(isNewFirstLaunch);
|
||||
|
||||
// 初始化PlatformUtils
|
||||
PlatformUtils.getInstance(getApplicationContext());
|
||||
|
||||
// 添加观察者
|
||||
DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ArrayList<String> concernList = new ArrayList<>();
|
||||
ConcernManager concernManager = new ConcernManager(MainActivity.this);
|
||||
for (ConcernInfo entity : concernManager.getAllConcern()) {
|
||||
if (entity.isConcern()) {
|
||||
concernList.add(entity.getGameName());
|
||||
}
|
||||
}
|
||||
Map<String, Object> 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);
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
// //检查是否存在更新的dex包
|
||||
// checkHotfix();
|
||||
|
||||
// 检查游戏更新
|
||||
checkGameUpdate();
|
||||
// 检查是否有权限读取应用列表
|
||||
checkPermission();
|
||||
|
||||
// 检查可插件化游戏
|
||||
checkGamePlugin();
|
||||
if (isNewFirstLaunch
|
||||
|| TokenUtils.getDeviceId(this) == null) {
|
||||
// 注册设备
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
TokenUtils.register(MainActivity.this);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
Log.e("TD_CHANNEL_ID", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"));
|
||||
}
|
||||
|
||||
private void checkPermission() {
|
||||
ArrayList<String> list = PackageUtils.getAllPackageName(getApplicationContext());
|
||||
if (list.isEmpty()) {
|
||||
// 无权限获取应用列表
|
||||
Spanned content = Html.fromHtml("请前往系统权限设置,把“" +
|
||||
"<font color='#ff0000'>读取应用列表</font>”选择为打开" +
|
||||
"“<font color='#ff0000'>允许</font>”,否则光环助手将无法帮您安装插件加速版的游戏");
|
||||
DialogUtils.showWarningDialog(this, "提示", content, "忽略", "去开启",
|
||||
new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
// 跳转应用信息界面
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
startActivityForResult(intent, 0x123);
|
||||
}
|
||||
}, null);
|
||||
} else {
|
||||
getInstalledListFromServer(list);
|
||||
}
|
||||
}
|
||||
|
||||
private int iCount;
|
||||
|
||||
private void addInstalledCount() {
|
||||
synchronized (MainActivity.class) {
|
||||
iCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取已安装游戏
|
||||
private void getInstalledListFromServer(ArrayList<String> list) {
|
||||
PackageManager manager = new PackageManager(getApplicationContext());
|
||||
manager.initInstalledMap(list);
|
||||
|
||||
final int size = list.size();
|
||||
iCount = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
final String packageName = list.get(i);
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v1d45/support/package/" + packageName + "/game/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
GameDigestEntity gameDigestEntity = gson.fromJson(
|
||||
response.toString(), GameDigestEntity.class);
|
||||
GameInfo gameInfo = new GameInfo();
|
||||
gameInfo.setId(gameDigestEntity.getId());
|
||||
gameInfo.setPackageName(packageName);
|
||||
concernManager.updateByEntity(gameInfo);
|
||||
}
|
||||
addInstalledCount();
|
||||
if (iCount == size) {
|
||||
updateConcern();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addInstalledCount();
|
||||
if (iCount == size) {
|
||||
updateConcern();
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, MainActivity.class);
|
||||
}
|
||||
}
|
||||
|
||||
private int cCount;
|
||||
|
||||
private void addConcernCount() {
|
||||
synchronized (MainActivity.class) {
|
||||
cCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConcern() {
|
||||
// 移除疑似游戏数据库中所有数据
|
||||
SuspectedGameManager suspectedGameManager = new SuspectedGameManager(
|
||||
getApplicationContext());
|
||||
suspectedGameManager.deleteAll();
|
||||
|
||||
ArrayList<String> concernIdList = new ArrayList<>();
|
||||
for (ConcernInfo entity : concernManager.getAllConcern()) {
|
||||
concernIdList.add(entity.getId());
|
||||
}
|
||||
if (concernIdList.isEmpty()) {
|
||||
update();
|
||||
} else {
|
||||
final int size = concernIdList.size();
|
||||
cCount = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/game/" + concernIdList.get(i) + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
ConcernInfo concernInfo = concernManager.findConcernById(gameEntity.getId());
|
||||
if (concernInfo != null
|
||||
&& gameEntity.getApk() != null
|
||||
&& gameEntity.getApk().size() != 0) {
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
String packageName;
|
||||
for (int i = 0, size = gameEntity.getApk().size(); i < size; i++) {
|
||||
packageName = gameEntity.getApk().get(i).getPackageName();
|
||||
if (PackageManager.isInstalled(packageName)) {
|
||||
packageNames.put(packageName, true);
|
||||
} else {
|
||||
packageNames.put(packageName, false);
|
||||
}
|
||||
}
|
||||
concernInfo.setTime(System.currentTimeMillis());
|
||||
concernInfo.setPackageNames(packageNames);
|
||||
concernManager.updateByConcern(concernInfo);
|
||||
}
|
||||
if (isNewFirstLaunch) {
|
||||
//默认安装即为关注
|
||||
if (!concernManager.isConcern(gameEntity.getId())) {
|
||||
concernManager.addByEntity(gameEntity);
|
||||
}
|
||||
}
|
||||
addConcernCount();
|
||||
if (cCount == size) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addConcernCount();
|
||||
if (cCount == size) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, MainActivity.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 更新关注列表数据
|
||||
*/
|
||||
private void update() {
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
TrafficUtils spy = TrafficUtils.getInstance(getApplicationContext(), true);
|
||||
List<ConcernInfo> concernList = concernManager.getAllConcern();
|
||||
for (ConcernInfo concernEntity : concernList) {
|
||||
concernEntity.setTime(System.currentTimeMillis());
|
||||
int quantity = 0;
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
for (String packageName : concernEntity.getPackageNames().keySet()) {
|
||||
if (PackageManager.isInstalled(packageName)) {
|
||||
quantity++;
|
||||
packageNames.put(packageName, true);
|
||||
} else {
|
||||
packageNames.put(packageName, false);
|
||||
}
|
||||
}
|
||||
concernEntity.setPackageNames(packageNames);
|
||||
concernEntity.setInstalled(quantity > 0);
|
||||
concernEntity.setInstalledQuantity(quantity);
|
||||
String tag = null;
|
||||
int weight = 0;
|
||||
if (concernEntity.isConcern() && concernEntity.isInstalled()) {
|
||||
tag = "已关注,已安装";
|
||||
weight = 2;
|
||||
} else if (concernEntity.isConcern()
|
||||
&& !concernEntity.isInstalled()) {
|
||||
tag = "已关注";
|
||||
weight = 1;
|
||||
} else if (!concernEntity.isConcern()
|
||||
&& concernEntity.isInstalled()) {
|
||||
tag = "已安装";
|
||||
weight = 1;
|
||||
}
|
||||
concernEntity.setTag(tag);
|
||||
long traffic = spy.getTraffic(new ArrayList<>(concernEntity
|
||||
.getPackageNames().keySet()));
|
||||
concernEntity.setTraffic(traffic);
|
||||
if (traffic > 0) {
|
||||
weight++;
|
||||
}
|
||||
concernEntity.setWeight(weight);
|
||||
if (weight == 0) {
|
||||
concernManager.deleteConcern(concernEntity.getId());
|
||||
} else {
|
||||
concernManager.updateByConcern(concernEntity);
|
||||
}
|
||||
}
|
||||
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ArrayList<String> concernList = new ArrayList<>();
|
||||
for (ConcernInfo entity : concernManager.getAllConcern()) {
|
||||
if (entity.isConcern()) {
|
||||
concernList.add(entity.getGameName());
|
||||
}
|
||||
}
|
||||
Map<String, Object> 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);
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
// 检查游戏更新
|
||||
checkGameUpdate();
|
||||
|
||||
// 检查可插件化游戏
|
||||
checkGamePlugin();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == 0x123) {
|
||||
ArrayList<String> list = PackageUtils.getAllPackageName(getApplicationContext());
|
||||
if (list.isEmpty()) {
|
||||
toast("读取应用列表失败");
|
||||
} else {
|
||||
getInstalledListFromServer(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkGameUpdate() {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
|
||||
ConcernManager concernManager = new ConcernManager(this);
|
||||
List<ConcernInfo> infos = concernManager.getInstalledGame();
|
||||
for (ConcernInfo info : infos) {
|
||||
for (String packageName : info.getPackageNames().keySet()) {
|
||||
@ -554,7 +788,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
|
||||
private void checkGamePlugin() {
|
||||
ConcernManager concernManager = new ConcernManager(this);
|
||||
List<ConcernInfo> infos = concernManager.getInstalledGame();
|
||||
final int size = infos.size();
|
||||
final List<GameEntity> list = new ArrayList<>();
|
||||
@ -584,7 +817,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, Game1Fragment.class);
|
||||
AppController.addToRequestQueue(request, MainActivity.class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -592,7 +825,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
if (list == null || list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ConcernManager concernManager = new ConcernManager(this);
|
||||
PackageManager mPackageManager = new PackageManager(this);
|
||||
List<ConcernInfo> infos = concernManager.getInstalledGame();
|
||||
HashMap<String, Boolean> map;
|
||||
@ -1313,8 +1545,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
GameManager gameManager = new GameManager(getApplicationContext());
|
||||
GameInfo gameEntity = gameManager.findGame(packageName);
|
||||
if (gameEntity != null) {
|
||||
ConcernManager concernManager = new ConcernManager(
|
||||
getApplicationContext());
|
||||
concernManager.updateByEntity(gameEntity);
|
||||
} else {
|
||||
FilterManager filterManager = new FilterManager(
|
||||
@ -1334,8 +1564,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
getApplicationContext());
|
||||
suspectedGameManager.deleteSuspectedGame(packageName);
|
||||
|
||||
ConcernManager concernManager = new ConcernManager(
|
||||
getApplicationContext());
|
||||
concernManager.updateByPackageName(packageName);
|
||||
}
|
||||
}
|
||||
@ -1383,7 +1611,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
|
||||
private void concernGame(String id) {
|
||||
final ConcernManager concernManager = new ConcernManager(getApplicationContext());
|
||||
if (!concernManager.isConcern(id)) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/game/" + id + "/digest",
|
||||
|
||||
@ -51,7 +51,6 @@ import java.util.Map;
|
||||
public class NewsDetailActivity extends DetailActivity implements OnClickListener {
|
||||
|
||||
private NewsDetailAdapter adapter;
|
||||
private LinearLayoutManager linearLayoutManager;
|
||||
|
||||
private String newsId;
|
||||
|
||||
@ -77,8 +76,7 @@ public class NewsDetailActivity extends DetailActivity implements OnClickListene
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
|
||||
detail_rv_show.setHasFixedSize(true);
|
||||
linearLayoutManager = new LinearLayoutManager(this);
|
||||
detail_rv_show.setLayoutManager(linearLayoutManager);
|
||||
detail_rv_show.setLayoutManager(new LinearLayoutManager(this));
|
||||
adapter = new NewsDetailAdapter(this, entrance);
|
||||
detail_rv_show.setAdapter(adapter);
|
||||
|
||||
@ -440,7 +438,6 @@ public class NewsDetailActivity extends DetailActivity implements OnClickListene
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(NewsDetailActivity.class);
|
||||
adapter = null;
|
||||
linearLayoutManager = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -144,13 +144,15 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
setting_sb_autodelete.setChecked(sp.getBoolean("autodelete", true));
|
||||
setting_sb_deletedata.setChecked(sp.getBoolean("deletedata", true));
|
||||
setting_sb_autoupdate.setChecked(sp.getBoolean("autoupdate", true));
|
||||
checkSizeIndex = sp.getInt("fontsize",1);
|
||||
|
||||
if (sp.getBoolean("isShowDisclaimer", false)) {
|
||||
TextView setting_tv_disclaimer = (TextView) findViewById(R.id.setting_tv_disclaimer);
|
||||
findViewById(R.id.setting_disclaimer_line).setVisibility(View.VISIBLE);
|
||||
setting_tv_disclaimer.setVisibility(View.VISIBLE);
|
||||
setting_tv_disclaimer.setOnClickListener(this);
|
||||
}
|
||||
|
||||
checkSizeIndex = sp.getInt("fontsize", 1);
|
||||
if (checkSizeIndex == 0){
|
||||
checkSizeIndex = 1;
|
||||
}
|
||||
@ -254,7 +256,6 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
break;
|
||||
case R.id.setting_cv_font_size:
|
||||
fontSize();
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@ -7,6 +7,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
@ -75,13 +76,18 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
private String from;
|
||||
|
||||
private long start;
|
||||
|
||||
private boolean isFirst;
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
isFirst = true;
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
@ -185,8 +191,8 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
FilterManager filterManager = new FilterManager(getApplicationContext());
|
||||
filterManager.addAllFilter(list);
|
||||
sp.edit().putBoolean("isLoadFilter", true).apply();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,6 +209,8 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
if (!today.equals(time)) {
|
||||
FilterManager manager = new FilterManager(getApplicationContext());
|
||||
manager.getFilterFromServer(today);
|
||||
|
||||
// 获取版本代码、名称
|
||||
getPlatform();
|
||||
}
|
||||
|
||||
@ -218,13 +226,28 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
*/
|
||||
DataCollectionManager.getInstance(getApplicationContext()).upload();
|
||||
|
||||
/*
|
||||
* 初始化已安装软件map,获取游戏更新列表和已安装列表
|
||||
*/
|
||||
PackageManager manager = new PackageManager(getApplicationContext());
|
||||
manager.getInstalledMapFromLocal();
|
||||
// 不是第一次启动
|
||||
if (!sp.getBoolean("isNewFirstLaunch", true)) {
|
||||
int height = sp.getInt("actionbar_height", 0);
|
||||
if (height == 0) {
|
||||
final ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null) {
|
||||
sp.edit().putInt("actionbar_height", actionBar.getHeight()).apply();
|
||||
}
|
||||
}
|
||||
|
||||
getInstalledListFromServer(sp.getBoolean("isNewFirstLaunch", true));
|
||||
long end = System.currentTimeMillis() - start;
|
||||
if (end < 3000) {
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
launch();
|
||||
}
|
||||
}, 3000 - end);
|
||||
} else {
|
||||
launch();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,7 +378,6 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
editor.putStringSet("platform", pset);
|
||||
editor.apply();
|
||||
} catch (JSONException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -363,217 +385,6 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
AppController.addToRequestQueue(request, SplashScreenActivity.class);
|
||||
}
|
||||
|
||||
private int iCount;
|
||||
|
||||
private void addInstalledCount() {
|
||||
synchronized (SplashScreenActivity.class) {
|
||||
iCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private void getInstalledListFromServer(final boolean isFirst) {
|
||||
List<String> list = PackageManager.getLocalPackageName(getApplicationContext());
|
||||
if (list.isEmpty()) {
|
||||
// 跳转应用信息界面
|
||||
// Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
// Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
// intent.setData(uri);
|
||||
// startActivity(intent);
|
||||
update();
|
||||
return;
|
||||
}
|
||||
final int count = list.size();
|
||||
final List<JSONObject> data = new ArrayList<>();
|
||||
final List<String> useParams = new ArrayList<>();
|
||||
iCount = 0;
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
final String packageName = list.get(i);
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v1d45/support/package/" + packageName + "/game/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
data.add(response);
|
||||
useParams.add(packageName);
|
||||
}
|
||||
addInstalledCount();
|
||||
if (iCount == count) {
|
||||
processingInstalledData(data, useParams, isFirst);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addInstalledCount();
|
||||
if (iCount == count) {
|
||||
processingInstalledData(data, useParams, isFirst);
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, SplashScreenActivity.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void processingInstalledData(List<JSONObject> data, List<String> useParams, boolean isFirst) {
|
||||
Gson gson = new Gson();
|
||||
for (int i = 0, size = data.size(); i < size; i++) {
|
||||
GameDigestEntity gameDigestEntity = gson.fromJson(data.get(i)
|
||||
.toString(), GameDigestEntity.class);
|
||||
GameInfo gameInfo = new GameInfo();
|
||||
gameInfo.setId(gameDigestEntity.getId());
|
||||
gameInfo.setPackageName(useParams.get(i));
|
||||
concernManager.updateByEntity(gameInfo);
|
||||
}
|
||||
|
||||
// 移除疑似游戏数据库中所有数据
|
||||
SuspectedGameManager suspectedGameManager = new SuspectedGameManager(
|
||||
getApplicationContext());
|
||||
suspectedGameManager.deleteAll();
|
||||
|
||||
updateConcern(isFirst);
|
||||
}
|
||||
|
||||
private int cCount;
|
||||
|
||||
private void addConcernCount() {
|
||||
synchronized (SplashScreenActivity.class) {
|
||||
cCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConcern(final boolean isFirst) {
|
||||
|
||||
ArrayList<String> concernId = new ArrayList<>();
|
||||
for (ConcernInfo entity : concernManager.getAllConcern()) {
|
||||
concernId.add(entity.getId());
|
||||
}
|
||||
|
||||
if (concernId.size() != 0) {
|
||||
cCount = 0;
|
||||
final int count = concernId.size();
|
||||
for (int i = 0, size = concernId.size(); i < size; i++) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/game/" + concernId.get(i) + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
addConcernCount();
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(
|
||||
response.toString(), GameEntity.class);
|
||||
|
||||
ArrayMap<String, ConcernInfo> map = concernManager
|
||||
.getConcernMap();
|
||||
ConcernInfo entity = map.get(gameEntity.getId());
|
||||
if (entity != null) {
|
||||
List<ApkEntity> list = gameEntity.getApk();
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
for (int j = 0, sizej = list.size(); j < sizej; j++) {
|
||||
packageNames.put(list.get(j).getPackageName(), false);
|
||||
}
|
||||
entity.setTime(System.currentTimeMillis());
|
||||
entity.setPackageNames(packageNames);
|
||||
if (isFirst) {
|
||||
//默认安装即为关注
|
||||
if (!concernManager.isConcern(entity.getId())) {
|
||||
concernManager.addByEntity(gameEntity);
|
||||
}
|
||||
}
|
||||
concernManager.updateByConcern(entity);
|
||||
}
|
||||
if (cCount == count) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addConcernCount();
|
||||
if (cCount == count) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, SplashScreenActivity.class);
|
||||
}
|
||||
} else {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
update();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
||||
private void update() {
|
||||
/*
|
||||
* 更新关注列表数据
|
||||
*/
|
||||
TrafficUtils spy = TrafficUtils.getInstance(getApplicationContext(), true);
|
||||
List<ConcernInfo> concernEntities = concernManager.getAllConcern();
|
||||
for (ConcernInfo concernEntity : concernEntities) {
|
||||
concernEntity.setTime(System.currentTimeMillis());
|
||||
int quantity = 0;
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
for (String packageName : concernEntity.getPackageNames().keySet()) {
|
||||
if (PackageManager.isInstalled(packageName)) {
|
||||
quantity++;
|
||||
packageNames.put(packageName, true);
|
||||
} else {
|
||||
packageNames.put(packageName, false);
|
||||
}
|
||||
}
|
||||
concernEntity.setPackageNames(packageNames);
|
||||
concernEntity.setInstalled(quantity > 0);
|
||||
concernEntity.setInstalledQuantity(quantity);
|
||||
String tag = null;
|
||||
int weight = 0;
|
||||
if (concernEntity.isConcern() && concernEntity.isInstalled()) {
|
||||
tag = "已关注,已安装";
|
||||
weight = 2;
|
||||
} else if (concernEntity.isConcern()
|
||||
&& !concernEntity.isInstalled()) {
|
||||
tag = "已关注";
|
||||
weight = 1;
|
||||
} else if (!concernEntity.isConcern()
|
||||
&& concernEntity.isInstalled()) {
|
||||
tag = "已安装";
|
||||
weight = 1;
|
||||
}
|
||||
concernEntity.setTag(tag);
|
||||
long traffic = spy.getTraffic(new ArrayList<>(concernEntity
|
||||
.getPackageNames().keySet()));
|
||||
concernEntity.setTraffic(traffic);
|
||||
if (traffic > 0) {
|
||||
weight++;
|
||||
}
|
||||
concernEntity.setWeight(weight);
|
||||
if (weight == 0) {
|
||||
concernManager.deleteConcern(concernEntity.getId());
|
||||
} else {
|
||||
concernManager.updateByConcern(concernEntity);
|
||||
}
|
||||
}
|
||||
// 不是第一次启动
|
||||
if (!sp.getBoolean("isNewFirstLaunch", true)) {
|
||||
int height = sp.getInt("actionbar_height", 0);
|
||||
if (height == 0) {
|
||||
final ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null) {
|
||||
sp.edit().putInt("actionbar_height", actionBar.getHeight()).apply();
|
||||
}
|
||||
}
|
||||
|
||||
launch();
|
||||
}
|
||||
}
|
||||
|
||||
// 跳转到主界面
|
||||
private void launch() {
|
||||
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
|
||||
|
||||
211
app/src/main/java/com/gh/gamecenter/adapter/ConcernAdapter.java
Normal file
211
app/src/main/java/com/gh/gamecenter/adapter/ConcernAdapter.java
Normal file
@ -0,0 +1,211 @@
|
||||
package com.gh.gamecenter.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.gamecenter.ConcernActivity;
|
||||
import com.gh.gamecenter.GameDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.ConcernViewHolder;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.listener.OnCallBackListener;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/20.
|
||||
*/
|
||||
public class ConcernAdapter extends RecyclerView.Adapter<ConcernViewHolder> {
|
||||
|
||||
private Context context;
|
||||
private OnCallBackListener listener;
|
||||
|
||||
private List<ConcernInfo> concernList;
|
||||
private List<GameEntity> concernGameList;
|
||||
|
||||
private ConcernManager concernManager;
|
||||
|
||||
public ConcernAdapter(ConcernActivity activity) {
|
||||
this.context = activity;
|
||||
this.listener = activity;
|
||||
|
||||
concernManager = new ConcernManager(context);
|
||||
|
||||
concernList = concernManager.getConcernGame();
|
||||
if (concernList != null && concernList.size() != 0) {
|
||||
initConcernGame();
|
||||
}
|
||||
}
|
||||
|
||||
private int cCount;
|
||||
|
||||
private void addConcernCount() {
|
||||
synchronized (ConcernActivity.class) {
|
||||
cCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private void initConcernGame() {
|
||||
final List<JSONObject> result = new ArrayList<>();
|
||||
final int count = concernList.size();
|
||||
cCount = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
JsonObjectExtendedRequest concernObjectRequest = new JsonObjectExtendedRequest(
|
||||
TimestampUtils.addTimestamp(
|
||||
Config.HOST + "v2d0/game/" + concernList.get(i).getId() + "/digest",
|
||||
Constants.GAME_CD),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
addConcernCount();
|
||||
result.add(response);
|
||||
if (cCount == count) {
|
||||
processingConcernGame(result);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addConcernCount();
|
||||
if (cCount == count) {
|
||||
processingConcernGame(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(concernObjectRequest, ConcernActivity.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void processingConcernGame(List<JSONObject> data) {
|
||||
List<GameEntity> gameList = new ArrayList<>();
|
||||
Gson gson = new Gson();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
gameList.add(gson.fromJson(data.get(i).toString(), GameEntity.class));
|
||||
}
|
||||
concernGameList = new ArrayList<>();
|
||||
for (int i = 0, sizei = concernList.size(); i < sizei; i++) {
|
||||
for (int j = 0, sizej = gameList.size(); j < sizej; j++) {
|
||||
if (concernList.get(i).getId().equals(gameList.get(j).getId())) {
|
||||
concernGameList.add(gameList.get(j));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConcernViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.concern_item, parent, false);
|
||||
return new ConcernViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final ConcernViewHolder holder, int position) {
|
||||
ConcernInfo concernInfo = concernList.get(position);
|
||||
ImageUtils.getInstance(context).display(concernInfo.getIcon(), holder.concern_item_icon);
|
||||
holder.concern_item_name.setText(concernInfo.getGameName());
|
||||
holder.concern_item_concern.setText("取消关注");
|
||||
holder.concern_item_concern.setBackgroundResource(R.drawable.textview_cancel_style);
|
||||
holder.concern_item_concern.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 删除关注表中的数据,并更新界面
|
||||
DialogUtils.showCancelDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
ConcernInfo concernInfo = concernList.get(holder.getPosition());
|
||||
if (concernManager.findConcernById(concernInfo.getId()) != null) {
|
||||
concernList.remove(holder.getPosition());
|
||||
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("状态", "取消关注");
|
||||
DataUtils.onEvent(context, "游戏关注", concernInfo.getGameName(), kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("game", concernInfo.getGameName());
|
||||
map.put("game_id", concernInfo.getId());
|
||||
map.put("type", "取消关注");
|
||||
DataCollectionManager.onEvent(context, "concern", map);
|
||||
|
||||
concernManager.deleteConcern(concernInfo.getId());
|
||||
if (concernGameList != null) {
|
||||
concernGameList.remove(holder.getPosition());
|
||||
}
|
||||
notifyItemRemoved(holder.getPosition());
|
||||
if (concernList.isEmpty()) {
|
||||
listener.loadEmpty();
|
||||
}
|
||||
holder.concern_item_concern.setClickable(false);
|
||||
holder.itemView.setClickable(false);
|
||||
} else {
|
||||
Toast.makeText(context, "取消失败,请稍后再试", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (concernGameList != null && concernGameList.size() != 0) {
|
||||
GameEntity gameEntity = concernGameList.get(holder.getPosition());
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("location", "关注列表");
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("game_id", gameEntity.getId());
|
||||
map.put("page", "我的关注");
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
AppController.put("GameEntity", gameEntity);
|
||||
Intent intent = new Intent(context, GameDetailActivity.class);
|
||||
intent.putExtra("entrance", "我的关注-列表");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (concernList == null) {
|
||||
return 0;
|
||||
}
|
||||
return concernList.size();
|
||||
}
|
||||
|
||||
public List<GameEntity> getConcernGameList() {
|
||||
return concernGameList;
|
||||
}
|
||||
|
||||
public List<ConcernInfo> getConcernList() {
|
||||
return concernList;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,165 @@
|
||||
package com.gh.gamecenter.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.gamecenter.ConcernActivity;
|
||||
import com.gh.gamecenter.GameDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.ConcernViewHolder;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.listener.OnCallBackListener;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/20.
|
||||
*/
|
||||
public class ConcernRecommendAdapter extends RecyclerView.Adapter<ConcernViewHolder> {
|
||||
|
||||
private Context context;
|
||||
private OnCallBackListener listener;
|
||||
|
||||
private List<GameEntity> gameList;
|
||||
private List<GameEntity> recommendGameList;
|
||||
|
||||
private ConcernManager concernManager;
|
||||
|
||||
public ConcernRecommendAdapter(ConcernActivity activity) {
|
||||
this.context = activity;
|
||||
this.listener = activity;
|
||||
|
||||
concernManager = new ConcernManager(context);
|
||||
|
||||
initRecommendGame();
|
||||
}
|
||||
|
||||
private void initRecommendGame() {
|
||||
JsonArrayExtendedRequest recommendRequest = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST + "v1d45/game/remenkapai",
|
||||
Constants.GAME_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
Type listType = new TypeToken<ArrayList<GameEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
gameList = gson.fromJson(response.toString(), listType);
|
||||
if (gameList != null && gameList.size() != 0) {
|
||||
recommendGameList = new ArrayList<>();
|
||||
for (int i = 0, size = gameList.size(); i < size; i++) {
|
||||
if (!concernManager.isConcern(gameList.get(i).getId())) {
|
||||
recommendGameList.add(gameList.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (recommendGameList.size() != 0) {
|
||||
listener.loadDone();
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(recommendRequest, ConcernActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConcernViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.concern_item, parent, false);
|
||||
return new ConcernViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final ConcernViewHolder holder, int position) {
|
||||
GameEntity gameEntity = recommendGameList.get(position);
|
||||
ImageUtils.getInstance(context).display(
|
||||
gameEntity.getIcon(), holder.concern_item_icon);
|
||||
holder.concern_item_name.setText(gameEntity.getName());
|
||||
holder.concern_item_concern.setText("关注");
|
||||
holder.concern_item_concern.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
holder.concern_item_concern.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 添加关注到表,并更新当前界面,插入一个关注
|
||||
GameEntity gameEntity = recommendGameList.remove(holder.getPosition());
|
||||
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("状态", "关注");
|
||||
DataUtils.onEvent(context, "游戏关注", gameEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("game_id", gameEntity.getId());
|
||||
map.put("type", "关注");
|
||||
DataCollectionManager.onEvent(context, "concern", map);
|
||||
|
||||
concernManager.addByEntity(gameEntity);
|
||||
|
||||
holder.concern_item_concern.setClickable(false);
|
||||
holder.itemView.setClickable(false);
|
||||
notifyItemRemoved(holder.getPosition());
|
||||
|
||||
Toast.makeText(context, "关注成功", Toast.LENGTH_SHORT).show();
|
||||
|
||||
listener.loadEmpty();
|
||||
}
|
||||
});
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
GameEntity gameEntity = recommendGameList.get(holder.getPosition());
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("location", "热门游戏推荐");
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("game_id", gameEntity.getId());
|
||||
map.put("page", "我的关注");
|
||||
DataCollectionManager.onEvent(context, "click-item", map);
|
||||
|
||||
AppController.put("GameEntity", gameEntity);
|
||||
Intent intent = new Intent(context, GameDetailActivity.class);
|
||||
intent.putExtra("entrance", "我的关注-推荐");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (recommendGameList == null) {
|
||||
return 0;
|
||||
}
|
||||
return recommendGameList.size();
|
||||
}
|
||||
|
||||
public List<GameEntity> getRecommendGameList() {
|
||||
return recommendGameList;
|
||||
}
|
||||
|
||||
public List<GameEntity> getGameList() {
|
||||
return gameList;
|
||||
}
|
||||
}
|
||||
@ -19,6 +19,7 @@ import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.view.CardLinearLayout;
|
||||
import com.gh.download.DownloadManager;
|
||||
@ -223,7 +224,8 @@ public class PluginAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
|
||||
ImageUtils.getInstance(context).display(entity.getIcon(), viewHolder.gameThumb);
|
||||
if (entity.isPluggable()) {
|
||||
viewHolder.gameNameAndSize.setText(entity.getName() + " - " + entity.getApk().get(0).getPlatform());
|
||||
viewHolder.gameNameAndSize.setText(entity.getName() + " - " +
|
||||
PlatformUtils.getInstance(context).getPlatformName(entity.getApk().get(0).getPlatform()));
|
||||
} else {
|
||||
viewHolder.gameNameAndSize.setText(entity.getName());
|
||||
}
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/20.
|
||||
*/
|
||||
public class ConcernViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ImageView concern_item_icon;
|
||||
public TextView concern_item_name;
|
||||
public TextView concern_item_concern;
|
||||
|
||||
public ConcernViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
concern_item_icon = (ImageView) itemView.findViewById(R.id.concern_item_icon);
|
||||
concern_item_name = (TextView) itemView.findViewById(R.id.concern_item_name);
|
||||
concern_item_concern = (TextView) itemView.findViewById(R.id.concern_item_concern);
|
||||
}
|
||||
|
||||
}
|
||||
@ -296,7 +296,7 @@ public class GameDownloadAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
DataUtils.onEvent(context, "插件化", entry.getName(), kv6);
|
||||
}
|
||||
if (FileUtils.isEmptyFile(path)) {
|
||||
Toast.makeText(context, "解析包错误", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(context, "解析包出错(可能被误删了),请重新下载", Toast.LENGTH_SHORT).show();
|
||||
removeDownload(entry, viewHolder.getPosition());
|
||||
} else {
|
||||
if (entry.getName().contains("光环助手")) {
|
||||
@ -502,7 +502,7 @@ public class GameDownloadAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
}
|
||||
|
||||
if (FileUtils.isEmptyFile(path)) {
|
||||
Toast.makeText(context, "解析包错误", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(context, "解析包出错(可能被误删了),请重新下载", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
MainActivity.uninstallMap.put(PackageUtils.getPackageNameByPath(context, path), path);
|
||||
context.startActivity(PackageUtils.getUninstallIntent(context, path));
|
||||
|
||||
@ -19,6 +19,7 @@ import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
@ -484,21 +485,26 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
viewHolder.gu_item_btv_update.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String str = viewHolder.gu_item_btv_update.getText().toString();
|
||||
final String str = viewHolder.gu_item_btv_update.getText().toString();
|
||||
if ("更新".equals(str) || "插件化".equals(str)) {
|
||||
if ("插件化".equals(str)) {
|
||||
viewHolder.gu_item_btv_update.setText("插件化中");
|
||||
viewHolder.gu_item_btv_update.setTextColor(0xFF06D0A8);
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_plugining_style);
|
||||
} else {
|
||||
viewHolder.gu_item_btv_update.setText("更新中");
|
||||
viewHolder.gu_item_btv_update.setTextColor(context.getResources().getColor(R.color.theme));
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
}
|
||||
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
if ("插件化".equals(str)) {
|
||||
viewHolder.gu_item_btv_update.setText("插件化中");
|
||||
viewHolder.gu_item_btv_update.setTextColor(0xFF06D0A8);
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_plugining_style);
|
||||
} else {
|
||||
viewHolder.gu_item_btv_update.setText("更新中");
|
||||
viewHolder.gu_item_btv_update.setTextColor(context.getResources().getColor(R.color.theme));
|
||||
viewHolder.gu_item_btv_update.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
}
|
||||
|
||||
addUpdateDownload(viewHolder.getPosition() - 1);
|
||||
addUpdateDownload(viewHolder.getPosition() - 1);
|
||||
|
||||
notifyItemChanged(0);
|
||||
notifyItemChanged(0);
|
||||
}
|
||||
});
|
||||
} else if ("启动".equals(str)) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", updateEntity.getPlatform());
|
||||
@ -506,6 +512,8 @@ public class GameUpdateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(context,
|
||||
updateEntity.getPackageName());
|
||||
} else if ("更新中".equals(str) || "插件化中".equals(str)) {
|
||||
handler.postDelayed(runnable, 300);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -14,6 +14,7 @@ import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseFragment;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
@ -162,14 +163,24 @@ public class Game1Fragment extends BaseFragment implements SwipeRefreshLayout.On
|
||||
}
|
||||
}
|
||||
} else if ("plugin".equals(status.getStatus())) {
|
||||
if (PackageManager.getPluggableSize() != 0
|
||||
&& adapter.getPluginList().isEmpty()
|
||||
&& adapter.isInitPlugin()) {
|
||||
adapter.initPlugin();
|
||||
}
|
||||
handler.postDelayed(initPluginRunnable, 100);
|
||||
}
|
||||
}
|
||||
|
||||
Runnable initPluginRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (PackageManager.getPluggableSize() != 0
|
||||
&& adapter.getPluginList().isEmpty()) {
|
||||
if (adapter.isInitPlugin()) {
|
||||
adapter.initPlugin();
|
||||
} else {
|
||||
handler.postDelayed(initPluginRunnable, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = adapter.getNameMap().get(busFour.getPackageName());
|
||||
|
||||
@ -31,6 +31,7 @@ import com.gh.common.util.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.AutoScrollViewPager;
|
||||
import com.gh.common.view.CardLinearLayout;
|
||||
import com.gh.download.DownloadManager;
|
||||
@ -268,6 +269,9 @@ public class Game1FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
public void initPlugin() {
|
||||
ArrayList<GameUpdateEntity> updateList = PackageManager.getUpdateList();
|
||||
if (updateList.isEmpty()) {
|
||||
if (!isInitPlugin) {
|
||||
isInitPlugin = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
GameUpdateEntity gameUpdateEntity;
|
||||
|
||||
@ -25,6 +25,7 @@ import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.HorizontalItemDecoration;
|
||||
import com.gh.gamecenter.GameDetailActivity;
|
||||
@ -589,7 +590,7 @@ public class GameDetailAdapter extends RecyclerView.Adapter {
|
||||
Toast.makeText(context, "关注成功", Toast.LENGTH_SHORT).show();
|
||||
|
||||
//添加关注
|
||||
String uuid = ConcernUtils.uuid(context);
|
||||
String uuid = TokenUtils.getDeviceId(context);
|
||||
ConcernUtils.postConcernGameId(gameId, Config.HOST + "v2d0/device/" + uuid + "/concern",
|
||||
new ConcernUtils.DownJsonListener() {
|
||||
@Override
|
||||
@ -626,7 +627,7 @@ public class GameDetailAdapter extends RecyclerView.Adapter {
|
||||
concern.setTextColor(0xffffffff);
|
||||
|
||||
//取消关注
|
||||
String uuid = ConcernUtils.uuid(context);
|
||||
String uuid = TokenUtils.getDeviceId(context);
|
||||
ConcernUtils.deleteConcernData(Config.HOST + "v2d0/device/" + uuid + "/concern/" + gameId,
|
||||
new ConcernUtils.DownJsonListener() {
|
||||
@Override
|
||||
|
||||
@ -80,6 +80,15 @@ public class PackageManager {
|
||||
installedMap.put(packageName, true);
|
||||
}
|
||||
|
||||
public void initInstalledMap(ArrayList<String> list) {
|
||||
installedMap = new ArrayMap<>();
|
||||
installedList = new ArrayList<>();
|
||||
for (String str : list) {
|
||||
installedMap.put(str, true);
|
||||
installedList.add(str);
|
||||
}
|
||||
}
|
||||
|
||||
public void getInstalledMapFromLocal() {
|
||||
installedMap = new ArrayMap<>();
|
||||
installedList = new ArrayList<>();
|
||||
@ -188,31 +197,6 @@ public class PackageManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有已安装的软件的包名、版本(非系统应用)
|
||||
*
|
||||
* @param context
|
||||
* 上下文
|
||||
* @return 已安装软件的包名的集合
|
||||
*/
|
||||
public static ArrayList<String> getLocalPackageName(Context context) {
|
||||
FilterManager filterManager = new FilterManager(context);
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
List<PackageInfo> packageInfos = context.getPackageManager()
|
||||
.getInstalledPackages(0);
|
||||
for (int i = 0, size = packageInfos.size(); i < size; i++) {
|
||||
PackageInfo packageInfo = packageInfos.get(i);
|
||||
if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
|
||||
if (!context.getPackageName().equals(packageInfo.packageName)) {
|
||||
if (!filterManager.isFilter(packageInfo.packageName)) {
|
||||
list.add(packageInfo.packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有已安装的软件的包名、版本(非系统应用)
|
||||
*
|
||||
|
||||
@ -154,12 +154,17 @@ public class News4Fragment extends BaseFragment implements SwipeRefreshLayout.On
|
||||
if (news_rv_show != null && news_rv_show.getVisibility() == View.GONE) {
|
||||
news_rv_show.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (reuse_none_data.getVisibility() == View.VISIBLE){
|
||||
if (reuse_none_data.getVisibility() == View.VISIBLE) {
|
||||
reuse_none_data.setVisibility(View.GONE);
|
||||
}
|
||||
if (news_swipe_refresh != null){
|
||||
if (news_swipe_refresh != null) {
|
||||
news_swipe_refresh.setEnabled(true);
|
||||
}
|
||||
if (adapter != null
|
||||
&& (adapter.getConcernList() == null
|
||||
|| adapter.getConcernList().isEmpty())) {
|
||||
reuse_none_data.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -25,6 +25,7 @@ import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.GzipUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.MD5Utils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.CardLinearLayout;
|
||||
import com.gh.gamecenter.NewsDetailActivity;
|
||||
@ -265,7 +266,7 @@ public class News4FragmentAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
}
|
||||
|
||||
public void updateConcern() {
|
||||
String uuid = ConcernUtils.uuid(context);
|
||||
String uuid = TokenUtils.getDeviceId(context);
|
||||
ConcernUtils.updateConcernData(Config.HOST + "v2d0/device/" + uuid + "/concern",
|
||||
new JSONArray(gameIdList),
|
||||
new ConcernUtils.DownJsonListener() {
|
||||
|
||||
@ -30,6 +30,7 @@ import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.RandomUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.GameDetailActivity;
|
||||
import com.gh.gamecenter.NewsDetailActivity;
|
||||
@ -102,9 +103,6 @@ public class NewsDetailAdapter extends RecyclerView.Adapter {
|
||||
newsDetailEntity.setTitle(title);
|
||||
|
||||
notifyDataSetChanged();
|
||||
|
||||
// 获取相关推荐
|
||||
getNewsMore();
|
||||
}
|
||||
|
||||
}, new Response.ErrorListener() {
|
||||
@ -285,7 +283,7 @@ public class NewsDetailAdapter extends RecyclerView.Adapter {
|
||||
Toast.makeText(context, "关注成功", Toast.LENGTH_SHORT).show();
|
||||
|
||||
//添加关注
|
||||
String uuid = ConcernUtils.uuid(context);
|
||||
String uuid = TokenUtils.getDeviceId(context);
|
||||
ConcernUtils.postConcernGameId(gameEntity.getId(), Config.HOST + "v2d0/device/" + uuid + "/concern",
|
||||
new ConcernUtils.DownJsonListener() {
|
||||
@Override
|
||||
@ -322,7 +320,7 @@ public class NewsDetailAdapter extends RecyclerView.Adapter {
|
||||
concern.setTextColor(Color.WHITE);
|
||||
|
||||
//取消关注
|
||||
String uuid = ConcernUtils.uuid(context);
|
||||
String uuid = TokenUtils.getDeviceId(context);
|
||||
ConcernUtils.deleteConcernData(Config.HOST + "v2d0/device/" + uuid + "/concern/" + gameEntity.getId(),
|
||||
new ConcernUtils.DownJsonListener() {
|
||||
@Override
|
||||
@ -407,6 +405,8 @@ public class NewsDetailAdapter extends RecyclerView.Adapter {
|
||||
+ "})()");
|
||||
super.onPageFinished(view, url);
|
||||
listener.loadDone(newsDetailEntity.getGameId());
|
||||
// 获取相关推荐
|
||||
getNewsMore();
|
||||
}
|
||||
});
|
||||
viewHolder.newsdetail_item_wv_content.setTag("show");
|
||||
|
||||
@ -4,26 +4,18 @@ import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.AbsListView;
|
||||
|
||||
import com.gh.base.BaseFragment;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
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.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.eventbus.EBMoveTop;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBSlide;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/8/12.
|
||||
@ -34,10 +26,6 @@ public class ConcernFragment extends BaseFragment {
|
||||
private LinearLayoutManager linearLayoutManager;
|
||||
private ConcernFragmentAdapter adapter;
|
||||
|
||||
private int topMargin;
|
||||
private int dis;
|
||||
private int distance;
|
||||
|
||||
private boolean isEverpause;
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@ -62,73 +50,11 @@ public class ConcernFragment extends BaseFragment {
|
||||
|
||||
init(R.layout.fm_concern);
|
||||
|
||||
topMargin = 0;
|
||||
dis = 0;
|
||||
distance = DisplayUtils.dip2px(getActivity(), 230)
|
||||
- DisplayUtils.getInternalDimensionSize(getActivity().getResources(), "status_bar_height");
|
||||
|
||||
fm_concern_rv_show.setHasFixedSize(true);
|
||||
linearLayoutManager = new LinearLayoutManager(getActivity());
|
||||
fm_concern_rv_show.setLayoutManager(linearLayoutManager);
|
||||
adapter = new ConcernFragmentAdapter(getActivity(), fm_concern_rv_show);
|
||||
fm_concern_rv_show.setAdapter(adapter);
|
||||
fm_concern_rv_show.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
|
||||
int visibility;
|
||||
if (linearLayoutManager.findFirstVisibleItemPosition() >= 1) {
|
||||
visibility = View.VISIBLE;
|
||||
} else {
|
||||
visibility = View.GONE;
|
||||
}
|
||||
Utils.log(linearLayoutManager.findFirstVisibleItemPosition());
|
||||
dis += dy;
|
||||
|
||||
topMargin -= dy;
|
||||
|
||||
EventBus.getDefault().post(new EBMoveTop("top", visibility, topMargin));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
|
||||
if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
|
||||
if (dis > distance) {
|
||||
EventBus.getDefault().post(new EBSlide(distance, 0, false));
|
||||
} else if (dis < -distance) {
|
||||
EventBus.getDefault().post(new EBSlide(0, 0, false));
|
||||
} else {
|
||||
EventBus.getDefault().post(new EBSlide(dis, 0, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBSlide busOne) {
|
||||
if (busOne.getPosition() == 1) {
|
||||
if (busOne.isReset()) {
|
||||
fm_concern_rv_show.scrollBy(0, distance - dis);
|
||||
} else {
|
||||
if (busOne.getDistance() == 0) {
|
||||
fm_concern_rv_show.scrollToPosition(0);
|
||||
topMargin = 0;
|
||||
dis = 0;
|
||||
} else {
|
||||
fm_concern_rv_show.scrollBy(0, busOne.getDistance() - dis);
|
||||
}
|
||||
}
|
||||
} else if (busOne.getPosition() == 0 && busOne.isReset()) {
|
||||
if (adapter.isEmpty()) {
|
||||
EventBus.getDefault().post(new EBMoveTop("top", View.GONE, -topMargin));
|
||||
EventBus.getDefault().post(new EBSlide(-topMargin, 0, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 关注事件
|
||||
@ -146,8 +72,6 @@ public class ConcernFragment extends BaseFragment {
|
||||
// }
|
||||
adapter = new ConcernFragmentAdapter(getActivity(), fm_concern_rv_show);
|
||||
fm_concern_rv_show.setAdapter(adapter);
|
||||
EventBus.getDefault().post(new EBMoveTop("top", View.GONE, -topMargin));
|
||||
EventBus.getDefault().post(new EBSlide(-topMargin, 0, false));
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
|
||||
@ -4,8 +4,6 @@ import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.AbsListView;
|
||||
|
||||
import com.gh.base.BaseFragment;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
@ -15,13 +13,9 @@ import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBMoveTop;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBSlide;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/8/12.
|
||||
@ -32,10 +26,6 @@ public class InstallFragment extends BaseFragment {
|
||||
private LinearLayoutManager linearLayoutManager;
|
||||
private InstallFragmentAdapter adapter;
|
||||
|
||||
private int topMargin;
|
||||
private int dis;
|
||||
private int distance;
|
||||
|
||||
private boolean isEverpause;
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@ -62,52 +52,11 @@ public class InstallFragment extends BaseFragment {
|
||||
|
||||
init(R.layout.fm_install);
|
||||
|
||||
topMargin = 0;
|
||||
dis = 0;
|
||||
distance = DisplayUtils.dip2px(getActivity(), 230)
|
||||
- DisplayUtils.getInternalDimensionSize(getActivity().getResources(), "status_bar_height");
|
||||
|
||||
fm_install_rv_show.setHasFixedSize(true);
|
||||
linearLayoutManager = new LinearLayoutManager(getActivity());
|
||||
fm_install_rv_show.setLayoutManager(linearLayoutManager);
|
||||
adapter = new InstallFragmentAdapter(getActivity(), fm_install_rv_show);
|
||||
fm_install_rv_show.setAdapter(adapter);
|
||||
fm_install_rv_show.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
|
||||
int visibility;
|
||||
if (linearLayoutManager.findFirstVisibleItemPosition() >= 1) {
|
||||
visibility = View.VISIBLE;
|
||||
} else {
|
||||
visibility = View.GONE;
|
||||
}
|
||||
|
||||
dis += dy;
|
||||
|
||||
topMargin -= dy;
|
||||
|
||||
EventBus.getDefault().post(new EBMoveTop("top", visibility, topMargin));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
|
||||
if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
|
||||
if (dis > distance) {
|
||||
EventBus.getDefault().post(new EBSlide(distance, 1, false));
|
||||
} else if (dis < -distance) {
|
||||
EventBus.getDefault().post(new EBSlide(0, 1, false));
|
||||
} else {
|
||||
EventBus.getDefault().post(new EBSlide(dis, 1, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
@ -139,29 +88,6 @@ public class InstallFragment extends BaseFragment {
|
||||
// }
|
||||
adapter = new InstallFragmentAdapter(getActivity(), fm_install_rv_show);
|
||||
fm_install_rv_show.setAdapter(adapter);
|
||||
EventBus.getDefault().post(new EBMoveTop("top", View.GONE, -topMargin));
|
||||
EventBus.getDefault().post(new EBSlide(-topMargin, 1, false));
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBSlide busOne) {
|
||||
if (busOne.getPosition() == 0) {
|
||||
if (busOne.isReset()) {
|
||||
fm_install_rv_show.scrollBy(0, distance - dis);
|
||||
} else {
|
||||
if (busOne.getDistance() == 0) {
|
||||
fm_install_rv_show.scrollToPosition(0);
|
||||
topMargin = 0;
|
||||
dis = 0;
|
||||
} else {
|
||||
fm_install_rv_show.scrollBy(0, busOne.getDistance() - dis);
|
||||
}
|
||||
}
|
||||
} else if (busOne.getPosition() == 0 && busOne.isReset()) {
|
||||
if (adapter.isEmpty()) {
|
||||
EventBus.getDefault().post(new EBMoveTop("top", View.GONE, -topMargin));
|
||||
EventBus.getDefault().post(new EBSlide(-topMargin, 1, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -6,7 +6,11 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
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;
|
||||
@ -40,19 +44,18 @@ import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.CropImageActivity;
|
||||
import com.gh.gamecenter.MainActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SettingActivity;
|
||||
import com.gh.gamecenter.eventbus.EBMoveTop;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.StringExtendedRequest;
|
||||
import com.tencent.stat.StatConfig;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
@ -64,7 +67,6 @@ public class PersonalFragment extends Fragment implements View.OnClickListener,
|
||||
private View view;
|
||||
private ViewPager me_vp_show;
|
||||
|
||||
private LinearLayout me_ll_top;
|
||||
private ImageView me_iv_top_setting;
|
||||
private ImageView me_iv_top_icon;
|
||||
private TextView me_tv_top_install;
|
||||
@ -78,14 +80,38 @@ public class PersonalFragment extends Fragment implements View.OnClickListener,
|
||||
private int dis;
|
||||
|
||||
private boolean isLogin;
|
||||
private boolean isDestroy;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
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);
|
||||
}
|
||||
isLogin = true;
|
||||
checkDeviceInfo();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("currentItem", me_vp_show.getCurrentItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.home3_fragment, null);
|
||||
isDestroy = false;
|
||||
|
||||
me_ll_top = (LinearLayout) view.findViewById(R.id.me_ll_top);
|
||||
view = View.inflate(getActivity(), R.layout.home3_fragment, null);
|
||||
|
||||
me_iv_top_icon = (ImageView) view.findViewById(R.id.me_iv_top_icon);
|
||||
me_iv_top_icon.setOnClickListener(this);
|
||||
@ -93,10 +119,15 @@ public class PersonalFragment extends Fragment implements View.OnClickListener,
|
||||
me_tv_top_name.setOnClickListener(this);
|
||||
|
||||
me_iv_top_setting = (ImageView) view.findViewById(R.id.me_iv_top_setting);
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) me_iv_top_setting.getLayoutParams();
|
||||
params.topMargin = DisplayUtils.getInternalDimensionSize(getResources(), "status_bar_height")
|
||||
+ DisplayUtils.dip2px(getActivity(), 15);
|
||||
me_iv_top_setting.setLayoutParams(params);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) me_iv_top_setting.getLayoutParams();
|
||||
params.topMargin = DisplayUtils.getInternalDimensionSize(getResources(), "status_bar_height")
|
||||
+ DisplayUtils.dip2px(getActivity(), 15);
|
||||
me_iv_top_setting.setLayoutParams(params);
|
||||
|
||||
LinearLayout me_ll_info = (LinearLayout) view.findViewById(R.id.me_ll_info);
|
||||
me_ll_info.setPadding(0, DisplayUtils.getInternalDimensionSize(getResources(), "status_bar_height"), 0, 0);
|
||||
}
|
||||
me_iv_top_setting.setOnClickListener(this);
|
||||
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
@ -117,30 +148,41 @@ public class PersonalFragment extends Fragment implements View.OnClickListener,
|
||||
rparams2.rightMargin = width - DisplayUtils.dip2px(getActivity(), 10);
|
||||
me_tv_top_concern.setLayoutParams(rparams2);
|
||||
|
||||
int currentItem = 0;
|
||||
if (savedInstanceState != null) {
|
||||
currentItem = savedInstanceState.getInt("currentItem");
|
||||
}
|
||||
|
||||
me_top_slide_line = view.findViewById(R.id.me_top_slide_line);
|
||||
top_line_rparams = (RelativeLayout.LayoutParams) me_top_slide_line.getLayoutParams();
|
||||
top_line_rparams.width = outMetrics.widthPixels / 6;
|
||||
leftMargin = outMetrics.widthPixels / 8 * 3 - outMetrics.widthPixels / 12 - DisplayUtils.dip2px(getActivity(), 10);
|
||||
top_line_rparams.leftMargin = leftMargin;
|
||||
dis = outMetrics.widthPixels / 4 + DisplayUtils.dip2px(getActivity(), 20);
|
||||
top_line_rparams.leftMargin = dis * currentItem + leftMargin;
|
||||
me_top_slide_line.setLayoutParams(top_line_rparams);
|
||||
|
||||
dis = outMetrics.widthPixels / 4 + DisplayUtils.dip2px(getActivity(), 20);
|
||||
|
||||
me_tv_top_install.setTextColor(getActivity().getResources().getColor(R.color.theme));
|
||||
me_tv_top_concern.setTextColor(getActivity().getResources().getColor(R.color.title));
|
||||
|
||||
me_tv_top_install.setTextColor(getActivity().getResources().getColor(R.color.theme));
|
||||
me_tv_top_concern.setTextColor(getActivity().getResources().getColor(R.color.title));
|
||||
if (currentItem == 0) {
|
||||
me_tv_top_install.setTextColor(getActivity().getResources().getColor(R.color.theme));
|
||||
me_tv_top_concern.setTextColor(getActivity().getResources().getColor(R.color.title));
|
||||
} else {
|
||||
me_tv_top_install.setTextColor(getActivity().getResources().getColor(R.color.title));
|
||||
me_tv_top_concern.setTextColor(getActivity().getResources().getColor(R.color.theme));
|
||||
}
|
||||
|
||||
me_vp_show = (ViewPager) view.findViewById(R.id.me_vp_show);
|
||||
me_vp_show.setAdapter(new FragmentAdapter(getChildFragmentManager()));
|
||||
me_vp_show.addOnPageChangeListener(this);
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
me_vp_show.setCurrentItem(currentItem);
|
||||
|
||||
isLogin = false;
|
||||
|
||||
login();
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
TokenUtils.getToken(getActivity());
|
||||
handler.sendEmptyMessage(0);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -199,20 +241,6 @@ public class PersonalFragment extends Fragment implements View.OnClickListener,
|
||||
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBMoveTop moveTop) {
|
||||
// if (moveTop.getType().equals("top")) {
|
||||
// if (moveTop.getVisibility() == View.VISIBLE) {
|
||||
// me_ll_topbar.setVisibility(View.VISIBLE);
|
||||
// } else {
|
||||
// me_ll_topbar.setVisibility(View.GONE);
|
||||
// }
|
||||
// if (top_rparams.topMargin != moveTop.getTopMargin()) {
|
||||
// top_rparams.topMargin = moveTop.getTopMargin();
|
||||
// me_ll_top.setLayoutParams(top_rparams);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final int id = v.getId();
|
||||
@ -300,6 +328,8 @@ public class PersonalFragment extends Fragment implements View.OnClickListener,
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
}
|
||||
});
|
||||
|
||||
@ -370,46 +400,43 @@ public class PersonalFragment extends Fragment implements View.OnClickListener,
|
||||
}.start();
|
||||
}
|
||||
|
||||
private void login() {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("device_id", TokenUtils.getDeviceId(getActivity()));
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(Request.Method.POST,
|
||||
"http://user.ghzhushou.com/v1d0/login", new JSONObject(params).toString(),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
try {
|
||||
me_tv_top_name.setText(response.getString("name"));
|
||||
String icon = response.getString("icon");
|
||||
if (!TextUtils.isEmpty(icon)) {
|
||||
ImageUtils.getInstance(getActivity()).display(icon, me_iv_top_icon, R.drawable.user_default_icon);
|
||||
}
|
||||
JSONObject token = response.getJSONObject("token");
|
||||
SharedPreferences sp = getActivity().getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.putString("user_name", response.getString("name"));
|
||||
editor.putString("user_icon", response.getString("icon"));
|
||||
editor.putString("token", token.getString("value"));
|
||||
editor.putLong("token_expire", token.getLong("expire"));
|
||||
editor.apply();
|
||||
isLogin = true;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
Utils.log("onErrorResponse = " + error);
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, PersonalFragment.class);
|
||||
/*
|
||||
* 检查设备信息是否已经上传完整
|
||||
*/
|
||||
private void checkDeviceInfo() {
|
||||
SharedPreferences sp = getActivity().getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
final HashMap<String, String> 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)) {
|
||||
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() {
|
||||
StringExtendedRequest request = new StringExtendedRequest(Request.Method.POST,
|
||||
"http://user.ghzhushou.com/v1d0/device/" + TokenUtils.getDeviceId(getActivity()),
|
||||
new JSONObject(params).toString(), null, null);
|
||||
request.addHeader("TOKEN", TokenUtils.getToken(getActivity()));
|
||||
AppController.addToRequestQueue(request, MainActivity.class);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().unregister(this);
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(PersonalFragment.class);
|
||||
view = null;
|
||||
}
|
||||
|
||||
@ -315,41 +315,54 @@
|
||||
app:cardElevation="2dp"
|
||||
app:cardUseCompatPadding="true">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/setting_rl_feedback"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/reuse_listview_item_style"
|
||||
android:padding="10dp">
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/setting_rl_feedback"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/reuse_listview_item_style"
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/setting_tv_feedback"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="意见反馈"
|
||||
android:textColor="@color/title"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/setting_tv_feedback"
|
||||
android:layout_marginTop="3dp"
|
||||
android:text="光环助手官方交流群:367541038"
|
||||
android:textColor="@color/theme"
|
||||
android:textSize="12sp" />
|
||||
</RelativeLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/setting_disclaimer_line"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="#ededed"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/setting_tv_feedback"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="意见反馈"
|
||||
android:textColor="@color/title"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/setting_tv_feedback"
|
||||
android:layout_marginTop="3dp"
|
||||
android:text="光环助手官方交流群:367541038"
|
||||
android:textColor="@color/theme"
|
||||
android:textSize="12sp" />
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/setting_tv_disclaimer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:background="@drawable/reuse_listview_item_style"
|
||||
android:padding="10dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="免责声明"
|
||||
android:textSize="16sp"
|
||||
android:visibility="gone" />
|
||||
android:id="@+id/setting_tv_disclaimer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:background="@drawable/reuse_listview_item_style"
|
||||
android:padding="10dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="免责声明"
|
||||
android:textSize="16sp"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/concern_item_btn"
|
||||
android:id="@+id/concern_item_concern"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
|
||||
50
app/src/main/res/layout/dialog_disclaimer.xml
Normal file
50
app/src/main/res/layout/dialog_disclaimer.xml
Normal file
@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<!--<TextView
|
||||
android:id="@+id/disclaimer_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="55dp"
|
||||
android:text="免责声明"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="20dp"
|
||||
android:textColor="#3a3a3a"/>
|
||||
|
||||
<View
|
||||
android:layout_width="321dp"
|
||||
android:layout_height="1dp"
|
||||
android:background="#E5E5E5"/>-->
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="284dp"
|
||||
android:layout_margin="16dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/disclaimer_message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/title"
|
||||
android:textSize="14sp" />
|
||||
</ScrollView>
|
||||
|
||||
<View
|
||||
android:layout_width="321dp"
|
||||
android:layout_height="1dp"
|
||||
android:background="#E5E5E5"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/disclaimer_confirm"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center"
|
||||
android:text="确定"
|
||||
android:textColor="@color/title"
|
||||
android:textSize="14sp" />
|
||||
|
||||
</LinearLayout>
|
||||
@ -31,6 +31,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#3a3a3a"
|
||||
android:textSize="16sp"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:lineSpacingMultiplier="0.9"
|
||||
android:includeFontPadding="false"/>
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
android:background="@color/theme">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/me_ll_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
@ -43,7 +44,7 @@
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginRight="22.5dp"
|
||||
android:src="@drawable/ic_setting"/>
|
||||
|
||||
|
||||
@ -1,58 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/border_dialog_bg"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/disclaimer_dialog_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="3dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:textColor="@color/theme"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<View
|
||||
android:id="@+id/disclaimer_dialog_line"
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="2px"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:background="#000000" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="234dp"
|
||||
android:layout_height="284dp"
|
||||
android:layout_margin="16dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/disclaimer_dialog_message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/title"
|
||||
android:textSize="14sp" />
|
||||
</ScrollView>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="15dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/disclaimer_dialog_confirm"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="27dp"
|
||||
android:background="@drawable/textview_blue_style"
|
||||
android:gravity="center"
|
||||
android:text="确定"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user