去掉MainActivity的entryMap、uninstallMap,使用下载是添加packageNam来进行获取DownloadEntity
This commit is contained in:
@ -17,7 +17,6 @@ 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;
|
||||
@ -68,7 +67,6 @@ import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBPutUrl;
|
||||
import com.gh.gamecenter.eventbus.EBShowDialog;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.eventbus.EBTopStatus;
|
||||
@ -121,7 +119,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
|
||||
public static final String TAG = MainActivity.class.getSimpleName();
|
||||
|
||||
public static ArrayMap<String, String> uninstallMap;
|
||||
public static String searchHint;
|
||||
|
||||
private GameFragment gameFragment;
|
||||
@ -134,8 +131,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
private SharedPreferences sp;
|
||||
private ConcernManager concernManager;
|
||||
|
||||
private ArrayMap<String, String> entryMap;
|
||||
|
||||
private int currentTab;
|
||||
|
||||
private boolean isDestroy = false;
|
||||
@ -166,7 +161,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
if (DownloadStatus.done.equals(downloadEntity.getStatus())) {
|
||||
if (downloadEntity.getName().contains("光环助手")) {
|
||||
DataUtils.onEvent(MainActivity.this, "软件更新", "下载完成");
|
||||
entryMap.put(downloadEntity.getPackageName(), downloadEntity.getUrl());
|
||||
startActivity(PackageUtils.getInstallIntent(downloadEntity.getPath()));
|
||||
if (appEntity != null && appEntity.isIs_force()) {
|
||||
finish();
|
||||
@ -216,11 +210,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
map.put("network", NetworkUtils.getConnectedType(MainActivity.this));
|
||||
DataCollectionManager.onEvent(MainActivity.this, "download", map);
|
||||
|
||||
entryMap.put(PackageUtils.getPackageNameByPath(
|
||||
getApplicationContext(),
|
||||
downloadEntity.getPath()), downloadEntity
|
||||
.getUrl());
|
||||
|
||||
if (RunningUtils.isApplicationBroughtToBackground(getApplicationContext())) {
|
||||
if (downloadEntity.isPluggable()) {
|
||||
NotificationManager nManager = (NotificationManager) getSystemService(
|
||||
@ -253,9 +242,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
nManager.notify(
|
||||
((int) System.currentTimeMillis() / 1000),
|
||||
notification);
|
||||
|
||||
uninstallMap.put(PackageUtils.getPackageNameByPath(
|
||||
getApplicationContext(), path), path);
|
||||
}
|
||||
} else {
|
||||
String platform = PlatformUtils.getInstance(
|
||||
@ -283,7 +269,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
PackageManager manager = new PackageManager(
|
||||
getApplicationContext());
|
||||
if (manager.launchSetup(downloadEntity.getPath())) {
|
||||
entryMap.put(downloadEntity.getPackageName(), downloadEntity.getUrl());
|
||||
startActivity(PackageUtils.getInstallIntent(downloadEntity.getPath()));
|
||||
} else {
|
||||
// 记录自动弹出卸载框
|
||||
@ -300,10 +285,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
// 统计下载完成
|
||||
uploadData(downloadEntity.getGameId(), downloadEntity.getPlatform());
|
||||
}
|
||||
} else {
|
||||
Utils.log("It is already done!");
|
||||
DataUtils.onEvent(MainActivity.this, "多次弹框数据",
|
||||
downloadEntity.getName() + "-" + downloadEntity.getPlatform());
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -415,9 +396,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
initViews();
|
||||
setTabSelection(currentTab);
|
||||
|
||||
uninstallMap = new ArrayMap<>();
|
||||
entryMap = new ArrayMap<>();
|
||||
|
||||
getSearchHints();
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
@ -1280,6 +1258,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
downloadEntity.setName("光环助手V" + appEntity.getVersion());
|
||||
downloadEntity.setPath(path);
|
||||
downloadEntity.setPlatform("官方版");
|
||||
downloadEntity.setPackageName(getPackageName());
|
||||
|
||||
DownloadManager.getInstance(getApplicationContext()).cancel(
|
||||
downloadEntity.getUrl(), false);
|
||||
@ -1491,12 +1470,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPutUrl url) {
|
||||
entryMap.put(url.getPackageName(), url.getUrl());
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
|
||||
String packageName = busFour.getPackageName();
|
||||
// 添加进已安装map中
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
@ -1504,45 +1478,31 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
PackageManager.removeInstalled(packageName);
|
||||
}
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
String url = entryMap.get(packageName);
|
||||
if (url != null) {
|
||||
entryMap.remove(packageName);
|
||||
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(
|
||||
getApplicationContext()).get(url);
|
||||
if (downloadEntity != null && downloadEntity.isPluggable()) {
|
||||
DownloadEntity mDownloadEntity = null;
|
||||
for (DownloadEntity downloadEntity : DownloadManager.getInstance(
|
||||
getApplicationContext()).getAll()) {
|
||||
if (packageName.equals(downloadEntity.getPackageName())) {
|
||||
mDownloadEntity = downloadEntity;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (mDownloadEntity != null) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
if (mDownloadEntity.isPluggable()) {
|
||||
Map<String, Object> kv6 = new HashMap<>();
|
||||
kv6.put("安装或卸载", "安装完成");
|
||||
DataUtils.onEvent(this, "插件化", downloadEntity.getName(), kv6);
|
||||
DataUtils.onEvent(this, "插件化", mDownloadEntity.getName(), kv6);
|
||||
}
|
||||
|
||||
// 删除数据库和文件
|
||||
DownloadManager.getInstance(getApplicationContext()).cancel(
|
||||
url, sp.getBoolean("autodelete", true));
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
try {
|
||||
for (DownloadEntity downloadEntity : DownloadManager.getInstance(
|
||||
getApplicationContext()).getAll()) {
|
||||
if (downloadEntity.isPluggable()
|
||||
&& packageName.equals(downloadEntity.getPackageName())) {
|
||||
Map<String, Object> kv6 = new HashMap<>();
|
||||
kv6.put("安装或卸载", "卸载完成");
|
||||
DataUtils.onEvent(this, "插件化", downloadEntity.getName(), kv6);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mDownloadEntity.getUrl(), sp.getBoolean("autodelete", true));
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
Map<String, Object> kv6 = new HashMap<>();
|
||||
kv6.put("安装或卸载", "卸载完成");
|
||||
DataUtils.onEvent(this, "插件化", mDownloadEntity.getName(), kv6);
|
||||
|
||||
String path = uninstallMap.get(packageName);
|
||||
|
||||
if (path != null) {
|
||||
uninstallMap.remove(packageName);
|
||||
|
||||
startActivity(PackageUtils.getInstallIntent(path));
|
||||
startActivity(PackageUtils.getInstallIntent(mDownloadEntity.getPath()));
|
||||
}
|
||||
}
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
@ -1655,7 +1615,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
home2Title = null;
|
||||
home3Title = null;
|
||||
sp = null;
|
||||
entryMap = null;
|
||||
dialog = null;
|
||||
app_pb_progress = null;
|
||||
app_tv_speed = null;
|
||||
|
||||
Reference in New Issue
Block a user