|
@@ -12,9 +12,11 @@ import android.view.View;
|
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
+import com.sheep.gamegroup.absBase.AbsObserver;
|
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
import com.sheep.gamegroup.model.entity.ApkInfo;
|
|
import com.sheep.gamegroup.model.entity.ApkInfo;
|
|
|
import com.sheep.gamegroup.model.entity.AppInfo;
|
|
import com.sheep.gamegroup.model.entity.AppInfo;
|
|
|
|
|
+import com.sheep.gamegroup.util.FileUtil;
|
|
|
import com.sheep.gamegroup.util.ListUtil;
|
|
import com.sheep.gamegroup.util.ListUtil;
|
|
|
import com.sheep.gamegroup.util.StringUtils;
|
|
import com.sheep.gamegroup.util.StringUtils;
|
|
|
import com.sheep.gamegroup.util.SysAppUtil;
|
|
import com.sheep.gamegroup.util.SysAppUtil;
|
|
@@ -31,11 +33,15 @@ import java.io.File;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.security.MessageDigest;
|
|
import java.security.MessageDigest;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
import butterknife.BindView;
|
|
import butterknife.BindView;
|
|
|
import butterknife.OnClick;
|
|
import butterknife.OnClick;
|
|
|
|
|
+import io.reactivex.Observable;
|
|
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
|
|
+import io.reactivex.schedulers.Schedulers;
|
|
|
|
|
|
|
|
import static com.sheep.jiuyan.samllsheep.utils.ClassFileHelper.DIR;
|
|
import static com.sheep.jiuyan.samllsheep.utils.ClassFileHelper.DIR;
|
|
|
|
|
|
|
@@ -60,6 +66,7 @@ public class ActSheepApkList extends BaseActivity {
|
|
|
public void initView() {
|
|
public void initView() {
|
|
|
TitleBarUtils
|
|
TitleBarUtils
|
|
|
.getInstance()
|
|
.getInstance()
|
|
|
|
|
+ .setShowOrHide(this, true)
|
|
|
.setTitle(this, "Sheep目录Apk渠道测试")
|
|
.setTitle(this, "Sheep目录Apk渠道测试")
|
|
|
.setTitleFinish(this);
|
|
.setTitleFinish(this);
|
|
|
user_label_commit_tv.setVisibility(View.GONE);
|
|
user_label_commit_tv.setVisibility(View.GONE);
|
|
@@ -70,54 +77,45 @@ public class ActSheepApkList extends BaseActivity {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private List<ApkInfo> list = new ArrayList<>();
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void initData() {
|
|
public void initData() {
|
|
|
- loadData(getList());
|
|
|
|
|
|
|
+ loadData(list);
|
|
|
|
|
+ Observable.just(1).map(integer -> getList())
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
+ .subscribe(new AbsObserver<List<ApkInfo>>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(List<ApkInfo> appInfoList) {
|
|
|
|
|
+ list.addAll(appInfoList);
|
|
|
|
|
+ ViewUtil.notifyDataSetChanged(user_label_list);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private List<ApkInfo> getList() {
|
|
private List<ApkInfo> getList() {
|
|
|
List<ApkInfo> apkInfoList = ListUtil.emptyList();
|
|
List<ApkInfo> apkInfoList = ListUtil.emptyList();
|
|
|
|
|
|
|
|
File dir = new File(DIR);
|
|
File dir = new File(DIR);
|
|
|
- File[] files = dir.listFiles();
|
|
|
|
|
- if(files != null)
|
|
|
|
|
|
|
+ File[] files = dir.listFiles(file -> TextUtils.equals(FileUtil.getExtensionName(file.getName()), "apk"));
|
|
|
|
|
+ if (files != null)
|
|
|
for (File file : files) {
|
|
for (File file : files) {
|
|
|
apkInfoList.add(getAppInfo(getApplicationContext(), file));
|
|
apkInfoList.add(getAppInfo(getApplicationContext(), file));
|
|
|
}
|
|
}
|
|
|
return apkInfoList;
|
|
return apkInfoList;
|
|
|
}
|
|
}
|
|
|
- public static boolean onlyZip = true;
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
public static ApkInfo getAppInfo(Context context, File file) {
|
|
public static ApkInfo getAppInfo(Context context, File file) {
|
|
|
ApkInfo apkInfo = new ApkInfo();
|
|
ApkInfo apkInfo = new ApkInfo();
|
|
|
|
|
+ String extensionName = FileUtil.getExtensionName(file.getName());
|
|
|
|
|
+ if (TextUtils.isEmpty(extensionName)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
PackageManager packageManager = context.getPackageManager();
|
|
PackageManager packageManager = context.getPackageManager();
|
|
|
String absolutePath = file.getAbsolutePath();
|
|
String absolutePath = file.getAbsolutePath();
|
|
|
- AppInfo appInfo = new AppInfo();
|
|
|
|
|
- if(!onlyZip){
|
|
|
|
|
- PackageInfo pkgInfo = getPackageInfo(context, absolutePath);
|
|
|
|
|
- if (pkgInfo == null) {
|
|
|
|
|
- return apkInfo;
|
|
|
|
|
- }
|
|
|
|
|
- pkgInfo.applicationInfo.sourceDir = absolutePath;
|
|
|
|
|
- pkgInfo.applicationInfo.publicSourceDir = absolutePath;
|
|
|
|
|
-
|
|
|
|
|
- //程序包名
|
|
|
|
|
- String packageName = pkgInfo.packageName;
|
|
|
|
|
- appInfo.setPackageName(packageName);
|
|
|
|
|
- //获取到图标
|
|
|
|
|
- Drawable icon = pkgInfo.applicationInfo.loadIcon(packageManager);
|
|
|
|
|
- appInfo.setIcon(icon);
|
|
|
|
|
- //获取到应用的名字
|
|
|
|
|
- String appName = pkgInfo.applicationInfo.loadLabel(packageManager).toString();
|
|
|
|
|
- appInfo.setAppName(appName);
|
|
|
|
|
- appInfo.setSha1(SysAppUtil.getSHA1(pkgInfo));
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- //获取到安装包的路径
|
|
|
|
|
- appInfo.setSourceDir(absolutePath);
|
|
|
|
|
- //获取到安装apk的大小
|
|
|
|
|
- long apkSize = file.length();
|
|
|
|
|
- //格式化apk的大小
|
|
|
|
|
- appInfo.setApkSize(Formatter.formatFileSize(SheepApp.getInstance(), apkSize));
|
|
|
|
|
|
|
+ AppInfo appInfo = SysAppUtil.getAppInfo(packageManager, getPackageInfo(context, absolutePath));
|
|
|
apkInfo.setAppInfo(appInfo);
|
|
apkInfo.setAppInfo(appInfo);
|
|
|
apkInfo.setFile(file);
|
|
apkInfo.setFile(file);
|
|
|
try {
|
|
try {
|
|
@@ -128,6 +126,7 @@ public class ActSheepApkList extends BaseActivity {
|
|
|
}
|
|
}
|
|
|
return apkInfo;
|
|
return apkInfo;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
//得到PackageInfo对象
|
|
//得到PackageInfo对象
|
|
|
public static PackageInfo getPackageInfo(Context context, String apkFilepath) {
|
|
public static PackageInfo getPackageInfo(Context context, String apkFilepath) {
|
|
|
PackageManager pm = context.getPackageManager();
|
|
PackageManager pm = context.getPackageManager();
|
|
@@ -140,9 +139,10 @@ public class ActSheepApkList extends BaseActivity {
|
|
|
}
|
|
}
|
|
|
return pkgInfo;
|
|
return pkgInfo;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
private void loadData(List<ApkInfo> list) {
|
|
private void loadData(List<ApkInfo> list) {
|
|
|
user_label_list.setLayoutManager(new LinearLayoutManager(SheepApp.getInstance()));
|
|
user_label_list.setLayoutManager(new LinearLayoutManager(SheepApp.getInstance()));
|
|
|
- user_label_list.setAdapter(new AdbCommonRecycler<ApkInfo>(SheepApp.getInstance(), list){
|
|
|
|
|
|
|
+ user_label_list.setAdapter(new AdbCommonRecycler<ApkInfo>(SheepApp.getInstance(), list) {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public int getViewIdByType(int type) {
|
|
public int getViewIdByType(int type) {
|
|
@@ -152,41 +152,31 @@ public class ActSheepApkList extends BaseActivity {
|
|
|
@Override
|
|
@Override
|
|
|
public void convert(ViewHolder holder, final ApkInfo item) {
|
|
public void convert(ViewHolder holder, final ApkInfo item) {
|
|
|
ImageView app_info_iv = holder.itemView.findViewById(R.id.app_info_iv);
|
|
ImageView app_info_iv = holder.itemView.findViewById(R.id.app_info_iv);
|
|
|
- TextView app_info_name_tv = holder.itemView.findViewById(R.id.app_info_name_tv);
|
|
|
|
|
- TextView app_info_package_name_tv = holder.itemView.findViewById(R.id.app_info_package_name_tv);
|
|
|
|
|
- TextView app_info_size_tv = holder.itemView.findViewById(R.id.app_info_size_tv);
|
|
|
|
|
- TextView app_info_path_tv = holder.itemView.findViewById(R.id.app_info_path_tv);
|
|
|
|
|
|
|
+ TextView app_info_tv = holder.itemView.findViewById(R.id.app_info_tv);
|
|
|
|
|
+ TextView app_info_tv2 = holder.itemView.findViewById(R.id.app_info_tv2);
|
|
|
|
|
|
|
|
final AppInfo appInfo = item.getAppInfo();
|
|
final AppInfo appInfo = item.getAppInfo();
|
|
|
- if(appInfo == null){
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if(appInfo.getIcon() != null)
|
|
|
|
|
|
|
+ if (appInfo != null && appInfo.getIcon() != null)
|
|
|
app_info_iv.setImageDrawable(appInfo.getIcon());
|
|
app_info_iv.setImageDrawable(appInfo.getIcon());
|
|
|
- ViewUtil.setText(app_info_name_tv, appInfo.getAppName());
|
|
|
|
|
- app_info_name_tv.append(item.getComment());//CommonUtil.getFileMD5(item.getFile())
|
|
|
|
|
- ViewUtil.setText(app_info_package_name_tv, appInfo.getPackageName());
|
|
|
|
|
- ViewUtil.setText(app_info_size_tv, appInfo.getApkSize());
|
|
|
|
|
- ViewUtil.setText(app_info_path_tv, appInfo.getSourceDir()+"\n"+appInfo.getSha1());
|
|
|
|
|
|
|
|
|
|
- holder.itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onClick(View view) {
|
|
|
|
|
- try {
|
|
|
|
|
- onClickItem(item);
|
|
|
|
|
- } catch (IOException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- G.showToast(e.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ViewUtil.setText(app_info_tv, appInfo != null ? appInfo.getAppInfo() : "");
|
|
|
|
|
+ ViewUtil.setText(app_info_tv2, appInfo != null ? appInfo.getAppInfo2() : "");
|
|
|
|
|
+ app_info_tv2.append("\n渠道:" + item.getComment());
|
|
|
|
|
+
|
|
|
|
|
+ holder.itemView.setOnClickListener(view -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ onClickItem(item);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ G.showToast(e.getMessage());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public boolean onLongClick(View view) {
|
|
|
|
|
|
|
+ holder.itemView.setOnLongClickListener(view -> {
|
|
|
|
|
+ if (appInfo != null) {
|
|
|
StringUtils.CopyText(appInfo.getSha1());
|
|
StringUtils.CopyText(appInfo.getSha1());
|
|
|
- G.showToast("复制sha1成功:"+appInfo.getSha1());
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ G.showToast("复制sha1成功:" + appInfo.getSha1());
|
|
|
}
|
|
}
|
|
|
|
|
+ return true;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -194,7 +184,7 @@ public class ActSheepApkList extends BaseActivity {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void onClickItem(final ApkInfo apkInfo) throws IOException {
|
|
private void onClickItem(final ApkInfo apkInfo) throws IOException {
|
|
|
- if(TextUtils.isEmpty(apkInfo.getComment())){
|
|
|
|
|
|
|
+ if (TextUtils.isEmpty(apkInfo.getComment())) {
|
|
|
String comment = "976873";
|
|
String comment = "976873";
|
|
|
ZipChannelUtil.writeQUA(apkInfo.getFile(), comment);
|
|
ZipChannelUtil.writeQUA(apkInfo.getFile(), comment);
|
|
|
apkInfo.setComment(comment);
|
|
apkInfo.setComment(comment);
|
|
@@ -202,7 +192,7 @@ public class ActSheepApkList extends BaseActivity {
|
|
|
G.showToast("给apk添加zip注释作为渠道成功");
|
|
G.showToast("给apk添加zip注释作为渠道成功");
|
|
|
} else {
|
|
} else {
|
|
|
ZipChannelUtil.delQUA(apkInfo.getFile());
|
|
ZipChannelUtil.delQUA(apkInfo.getFile());
|
|
|
- G.showToast("成功删除渠道:"+apkInfo.getComment());
|
|
|
|
|
|
|
+ G.showToast("成功删除渠道:" + apkInfo.getComment());
|
|
|
apkInfo.setComment("");
|
|
apkInfo.setComment("");
|
|
|
user_label_list.getAdapter().notifyDataSetChanged();
|
|
user_label_list.getAdapter().notifyDataSetChanged();
|
|
|
}
|
|
}
|