处理一部分activity的toolbar,已经处理完毕的标记为Deprecated,为了保持MTA数据上报兼容性,暂时未删除对应的Activity
This commit is contained in:
@ -2,240 +2,23 @@ package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Html;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.CleanApkAdapter;
|
||||
import com.gh.gamecenter.entity.InstallGameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import com.halo.assistant.fragment.ApkCleanerFragment;
|
||||
import com.halo.assistant.ui.IntentFactory;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/1/24.
|
||||
*/
|
||||
public class CleanApkActivity extends BaseActivity implements CleanApkAdapter.OnScanListener {
|
||||
|
||||
@BindView(R.id.apk_count)
|
||||
TextView mApkCount;
|
||||
@BindView(R.id.apk_rv)
|
||||
RecyclerView mApkRv;
|
||||
@BindView(R.id.delete_btn)
|
||||
TextView mApkDeleteBtn;
|
||||
@BindView(R.id.select_game_all)
|
||||
CheckBox mApkSelectAll;
|
||||
@BindView(R.id.scan_pb)
|
||||
ProgressBar mScanPb;
|
||||
@BindView(R.id.reuse_nodata_skip_tv_hint)
|
||||
TextView mNodataSkipTv;
|
||||
@BindView(R.id.reuse_nodata_skip_tv_btn)
|
||||
TextView mNodataSkipBtn;
|
||||
@BindView(R.id.reuse_nodata_skip)
|
||||
LinearLayout mNodataSkipLl;
|
||||
@BindView(R.id.delete_bottom)
|
||||
LinearLayout mDeleteBottom;
|
||||
@BindView(R.id.select_game_installed_ll)
|
||||
RelativeLayout mInstallAllData;
|
||||
|
||||
private CleanApkAdapter mAdapter;
|
||||
@Deprecated
|
||||
public class CleanApkActivity extends CommonActivity {
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context) {
|
||||
Intent intent = new Intent(context, CleanApkActivity.class);
|
||||
return intent;
|
||||
// Intent intent = new Intent(context, CleanApkActivity.class);
|
||||
return new IntentFactory.Builder(context)
|
||||
.setActivity(CleanApkActivity.class)
|
||||
.setFragment(ApkCleanerFragment.class).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_clean_apk;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setNavigationTitle(getString(R.string.title_clean_apk));
|
||||
|
||||
mNodataSkipLl.setVisibility(View.GONE);
|
||||
|
||||
mAdapter = new CleanApkAdapter(this, this, mApkDeleteBtn, mApkSelectAll);
|
||||
mApkRv.setLayoutManager(new LinearLayoutManager(this));
|
||||
mApkRv.addItemDecoration(new VerticalItemDecoration(this, 8, true));
|
||||
mApkRv.setAdapter(mAdapter);
|
||||
|
||||
mApkSelectAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
ArrayMap<Integer, Boolean> selectPosition = new ArrayMap<>();
|
||||
ArrayMap<Integer, Boolean> selectPosition1 = mAdapter.getSelectPosition();
|
||||
int itemCount = mAdapter.getItemCount();
|
||||
if (isChecked) {
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
selectPosition.put(i, true);
|
||||
}
|
||||
} else {
|
||||
int selectCount = 0;
|
||||
for (Integer integer : selectPosition1.keySet()) {
|
||||
if (selectPosition1.get(integer)) {
|
||||
selectCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (selectCount != itemCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
selectPosition.put(i, false);
|
||||
}
|
||||
}
|
||||
|
||||
mAdapter.setSelectPosition(selectPosition);
|
||||
mAdapter.notifyItemRangeChanged(0, itemCount);
|
||||
mAdapter.checkBoxControl(isChecked, 0);
|
||||
}
|
||||
});
|
||||
|
||||
mNodataSkipBtn.setText("去首页看看");
|
||||
mNodataSkipTv.setText("安装包已清理干净\n快去发现更多好玩的游戏吧!");
|
||||
mNodataSkipTv.setLineSpacing(0, 1.5f);
|
||||
|
||||
}
|
||||
|
||||
@OnClick({R.id.delete_btn, R.id.reuse_nodata_skip_tv_btn})
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.delete_btn: {
|
||||
String s = mApkDeleteBtn.getText().toString();
|
||||
if ("停止扫描".equals(s)) {
|
||||
mAdapter.isStopScan();
|
||||
} else {
|
||||
if ("一键删除".equals(s)) {
|
||||
Utils.toast(CleanApkActivity.this, "请选择需要删除的安装包");
|
||||
return;
|
||||
}
|
||||
|
||||
final List<InstallGameEntity> apkList = mAdapter.getApkList();
|
||||
final ArrayMap<Integer, Boolean> selectPosition = mAdapter.getSelectPosition();
|
||||
|
||||
for (int i = 0; i < apkList.size(); i++) {
|
||||
if (selectPosition.get(i) && apkList.get(i).getInstallStatus() == 1) {
|
||||
DialogUtils.showWarningDialog(CleanApkActivity.this, "删除安装包"
|
||||
, Html.fromHtml(getString(R.string.delete_apk_hint))
|
||||
, "取消 ", "确定"
|
||||
, new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
deleteApk(apkList, selectPosition);
|
||||
}
|
||||
}, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
deleteApk(apkList, selectPosition);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case R.id.reuse_nodata_skip_tv_btn: {
|
||||
Intent intent = MainActivity.getMainIntent(this);
|
||||
startActivity(intent);
|
||||
|
||||
mNodataSkipBtn.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
EventBus.getDefault().post(new EBSkip(MainActivity.EB_SKIP_GAMEFRAGMENT, 0));
|
||||
}
|
||||
}, 300);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteApk(List<InstallGameEntity> apkList, ArrayMap<Integer, Boolean> selectPosition) {
|
||||
long size = 0;
|
||||
for (int i = 0; i < apkList.size(); i++) {
|
||||
if (selectPosition.get(i)) {
|
||||
InstallGameEntity installGameEntity = apkList.get(i);
|
||||
size = size + installGameEntity.getGameSize();
|
||||
File file = new File(installGameEntity.getGamePath());
|
||||
if (file.isFile() && file.exists()) {
|
||||
file.delete();
|
||||
mAdapter.deleteApk(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double allSize = (((float) size / 1024) / 1024);
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
String sizeName = df.format(allSize) + "MB";
|
||||
Utils.toast(CleanApkActivity.this, "删除成功,已为您节省" + sizeName + "空间");
|
||||
mApkDeleteBtn.setText("一键删除");
|
||||
mAdapter.notifyDataSetChanged(); // 刷新Adapter position
|
||||
|
||||
updateScanData();
|
||||
|
||||
if (apkList.size() == 0) { // 全部删除
|
||||
mNodataSkipLl.setVisibility(View.VISIBLE);
|
||||
mInstallAllData.setVisibility(View.GONE);
|
||||
mDeleteBottom.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateScanData() {
|
||||
long allSize = 0;
|
||||
List<InstallGameEntity> apkList = mAdapter.getApkList();
|
||||
for (InstallGameEntity installGameEntity : apkList) {
|
||||
allSize = allSize + installGameEntity.getGameSize();
|
||||
}
|
||||
|
||||
double size = (((float) allSize / 1024) / 1024);
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
String sizeName = df.format(size) + "MB";
|
||||
|
||||
mApkCount.setText(Html.fromHtml(getString(R.string.clean_apk_count, apkList.size(), sizeName)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanOver() {
|
||||
mApkDeleteBtn.setText("立即删除");
|
||||
mApkDeleteBtn.setBackgroundResource(R.drawable.game_item_btn_red_style);
|
||||
|
||||
updateScanData();
|
||||
|
||||
mScanPb.setVisibility(View.GONE);
|
||||
mApkSelectAll.setVisibility(View.VISIBLE);
|
||||
mApkSelectAll.setChecked(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noData() {
|
||||
mNodataSkipBtn.setText("去首页看看");
|
||||
mNodataSkipTv.setText("暂无安装包");
|
||||
mNodataSkipLl.setVisibility(View.VISIBLE);
|
||||
mInstallAllData.setVisibility(View.GONE);
|
||||
mDeleteBottom.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user