Переглянути джерело

测试时,可以直接分享apk文件

zengjiebin 7 роки тому
батько
коміт
7cbd230300

+ 8 - 4
app/src/main/java/com/kfzs/duanduan/utils/ApkUtils.java

@@ -175,12 +175,10 @@ public class ApkUtils {
         try {
             PackageInfo packageInfo = SheepApp.getInstance().getPackageManager().getPackageInfo(
                     packageName, PackageManager.GET_ACTIVITIES | PackageManager.GET_SIGNATURES);
-            Signature[] signs = packageInfo.signatures;
-            Signature sign = signs[0];
-            String signStr = encryptionMD5(sign.toByteArray());
+            String signMd5 = getSignMd5(packageInfo);
             if (action1 != null)
                 action1.call(packageInfo);
-            return signStr;
+            return signMd5;
         } catch (PackageManager.NameNotFoundException e) {
             e.printStackTrace();
         } catch (Exception e2) {
@@ -189,6 +187,12 @@ public class ApkUtils {
         return "";
     }
 
+    public static String getSignMd5(PackageInfo packageInfo) {
+        Signature[] signs = packageInfo.signatures;
+        Signature sign = signs[0];
+       return encryptionMD5(sign.toByteArray());
+    }
+
     /**
      * 获取未安装app签名md5值
      */

+ 35 - 0
app/src/main/java/com/sheep/gamegroup/model/entity/AppInfo.java

@@ -2,6 +2,11 @@ package com.sheep.gamegroup.model.entity;
 
 import android.graphics.drawable.Drawable;
 
+import com.sheep.gamegroup.util.Md5Util;
+import com.sheep.gamegroup.util.string.SpannableSb;
+
+import java.io.File;
+
 /**
  * Created by realicing on 2018/6/19.
  * realicing@sina.com
@@ -81,6 +86,7 @@ public class AppInfo {
 
     public void setSourceDir(String sourceDir) {
         this.sourceDir = sourceDir;
+        sourceDirMd5 = Md5Util.getFileMD5(new File(sourceDir));
     }
 
     public String getSha1() {
@@ -90,4 +96,33 @@ public class AppInfo {
     public void setSha1(String sha1) {
         this.sha1 = sha1;
     }
+
+    private String signMd5;
+
+    public String getSignMd5() {
+        return signMd5;
+    }
+
+    public void setSignMd5(String signMd5) {
+        this.signMd5 = signMd5;
+    }
+
+    public CharSequence getAppInfo() {
+        return new SpannableSb().append("名称:").append(appName).br()
+                .append(isUserApp ?  "用户app" : "系统app").kgz().append(isSD ? "SD卡" : "内置").kgz().append("大小:").append(apkSize).br()
+                .append("包名:").append(packageName).br()
+                .getSsb();
+    }
+    public CharSequence getAppInfo2() {
+        return new SpannableSb()
+                .append("路径:").append(sourceDir).br()
+                .append("文件md5:").br().append(sourceDirMd5).br()
+                .append("签名md5:").br().append(signMd5).br()
+                .append("sha1:").append(sha1)
+                .getSsb();
+    }
+    private String sourceDirMd5;
+    public String getSourceDirMd5() {
+        return sourceDirMd5;
+    }
 }

+ 49 - 40
app/src/main/java/com/sheep/gamegroup/util/SysAppUtil.java

@@ -295,49 +295,58 @@ public class SysAppUtil {
         //获取到所有的安装包
         List<PackageInfo> installedPackages = packageManager.getInstalledPackages(PackageManager.GET_ACTIVITIES | PackageManager.GET_SIGNATURES);
         ArrayList<AppInfo> appInfos = new ArrayList<>();
-        for (PackageInfo installedPackage : installedPackages) {
-            AppInfo appInfo = new AppInfo();
-            //程序包名
-            String packageName = installedPackage.packageName;
-            appInfo.setPackageName(packageName);
-            //获取到图标
-            Drawable icon = installedPackage.applicationInfo.loadIcon(packageManager);
-            appInfo.setIcon(icon);
-            //获取到应用的名字
-            String appName = installedPackage.applicationInfo.loadLabel(packageManager).toString();
-            appInfo.setAppName(appName);
-            //获取到安装包的路径
-            String sourceDir = installedPackage.applicationInfo.sourceDir;
-            appInfo.setSourceDir(sourceDir);
-            File file = new File(sourceDir);
-            //获取到安装apk的大小
-            long apkSize = file.length();
-            //格式化apk的大小
-            appInfo.setApkSize(Formatter.formatFileSize(SheepApp.getInstance(),apkSize));
-            appInfo.setSha1(getSHA1(installedPackage));
-
-            int flags = installedPackage.applicationInfo.flags;
-            //判断当前是否是系统app
-            if((flags & ApplicationInfo.FLAG_SYSTEM) !=0){
-                //那么就是系统app
-                appInfo.setUserApp(false);
-            }else{
-                //那么就是用户app
-                appInfo.setUserApp(true);
-            }
-
-            if((flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE)!=0){
-                //那么当前安装的就是sd卡
-                appInfo.setSD(true);
-
-            }else{
-                //那么就是手机内存
-                appInfo.setSD(false);
-            }
-            appInfos.add(appInfo);
+        for (PackageInfo item : installedPackages) {
+            appInfos.add(getAppInfo(packageManager, item));
         }
         return appInfos;
     }
+
+    public static AppInfo getAppInfo(PackageManager packageManager, PackageInfo item) {
+        if(item == null){
+            return null;
+        }
+        AppInfo appInfo = new AppInfo();
+        //程序包名
+        String packageName = item.packageName;
+        appInfo.setPackageName(packageName);
+        //获取到图标
+        Drawable icon = item.applicationInfo.loadIcon(packageManager);
+        appInfo.setIcon(icon);
+        //获取到应用的名字
+        String appName = item.applicationInfo.loadLabel(packageManager).toString();
+        appInfo.setAppName(appName);
+        //获取到安装包的路径
+        String sourceDir = item.applicationInfo.sourceDir;
+        appInfo.setSourceDir(sourceDir);
+        File file = new File(sourceDir);
+        //获取到安装apk的大小
+        long apkSize = file.length();
+        //格式化apk的大小
+        appInfo.setApkSize(Formatter.formatFileSize(SheepApp.getInstance(),apkSize));
+        appInfo.setSha1(getSHA1(item));
+
+        int flags = item.applicationInfo.flags;
+        //判断当前是否是系统app
+        if((flags & ApplicationInfo.FLAG_SYSTEM) !=0){
+            //那么就是系统app
+            appInfo.setUserApp(false);
+        }else{
+            //那么就是用户app
+            appInfo.setUserApp(true);
+        }
+
+        if((flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE)!=0){
+            //那么当前安装的就是sd卡
+            appInfo.setSD(true);
+
+        }else{
+            //那么就是手机内存
+            appInfo.setSD(false);
+        }
+        appInfo.setSignMd5(ApkUtils.getSignMd5(item));
+        return appInfo;
+    }
+
     public static String getSHA1(PackageInfo packageInfo) {
         try {
             byte[] cert = packageInfo.signatures[0].toByteArray();

+ 18 - 1
app/src/main/java/com/sheep/gamegroup/util/TestUtil.java

@@ -49,6 +49,7 @@ import com.sheep.gamegroup.module.skin.util.SkinUtil;
 import com.sheep.gamegroup.module.yf_shop.model.ReceiveCouponsCheckResq;
 import com.sheep.gamegroup.usage.AppUsageManager;
 import com.sheep.gamegroup.util.js.BaseActWeb;
+import com.sheep.gamegroup.util.share.ShareLinkConfig;
 import com.sheep.gamegroup.view.activity.ActInstallApkList;
 import com.sheep.gamegroup.view.activity.ActMain;
 import com.sheep.gamegroup.view.activity.ActSheepApkList;
@@ -261,7 +262,7 @@ public class TestUtil {
      */
     public static void test(final Activity activity) {
         final String[] items = {"复制token", "添加token", "复制打点数据", "从jenkins下载小绵羊安装包", "测试表情包",
-                "跳转QQ", "跳转QQ群",
+                "跳转QQ", "跳转QQ群", "分享我的签名的小绵羊apk", "分享当前小绵羊apk",
                 "测试升级对话框","少数民族姓名", "开启皮肤", "不开启皮肤", "我的游戏", "优惠券弹窗", "填写收件地址弹窗",
                 "朗读文字", "游戏搜索", "测试插件","测试bitmap", "剪切视频", "我的关注", "足迹",
                 "测试联通卡", "测试联通卡2", "测试签名1", "测试签名2", "测试孔剑秋faq正式服",
@@ -286,6 +287,22 @@ public class TestUtil {
             return;
         }
         switch (item) {
+            case "分享当前小绵羊apk":
+                PackageInfo packageInfo = ApkUtils.getPackageInfo(SheepApp.getInstance().getPackageName());
+                if (packageInfo != null && packageInfo.applicationInfo != null && !TextUtils.isEmpty(packageInfo.applicationInfo.sourceDir)) {
+                    new ShareLinkConfig().setTitle("分享").setDes("分享小绵羊apk")
+                            .setShareFile(new File(packageInfo.applicationInfo.sourceDir))
+                            .setShareType(ShareLinkConfig.SYS_SEND).setType(ShareLinkConfig.FILE)
+                            .toShare(activity);
+                } else {
+                    G.showToast("无法获取到apk,重启试试");
+                }
+                break;
+            case "分享我的签名的小绵羊apk":
+                new ShareLinkConfig().setTitle("分享").setDes("分享小绵羊apk")
+                        .setShareType(ShareLinkConfig.SYS_SEND).setType(ShareLinkConfig.FILE)
+                        .toShare(activity);
+                break;
             case "测试升级对话框":
                 testUpgradeDialog();
                 break;

+ 43 - 21
app/src/main/java/com/sheep/gamegroup/util/share/ShareLinkConfig.java

@@ -61,7 +61,8 @@ public class ShareLinkConfig {
     private String des;
     private String iconUrl;
     private int iconResId;
-    private File file;
+    private File iconFile;//图标
+    private File shareFile;//要分享的文件
     private int type = WEB;//分享类型:对应TYPE
     private Action1<View> action1;
     private String shareType = ALL;//分享方式:对应 SHARE_TYPE
@@ -120,12 +121,20 @@ public class ShareLinkConfig {
         return this;
     }
 
-    public File getFile() {
-        return file;
+    public File getShareFile() {
+        return shareFile;
     }
 
-    public ShareLinkConfig setFile(File file) {
-        this.file = file;
+    public ShareLinkConfig setShareFile(File shareFile) {
+        this.shareFile = shareFile;
+        return this;
+    }
+    public File getIconFile() {
+        return iconFile;
+    }
+
+    public ShareLinkConfig setIconFile(File file) {
+        this.iconFile = file;
         return this;
     }
 
@@ -160,7 +169,7 @@ public class ShareLinkConfig {
         if (activity == null) {
             return;
         }
-        if(TextUtils.isEmpty(link)){
+        if(needLink() && TextUtils.isEmpty(link)){
             CommonUtil.getInstance().callActionWithUserInfo(new Action1<UserEntity>() {
                 @Override
                 public void call(UserEntity userEntity) {
@@ -201,13 +210,13 @@ public class ShareLinkConfig {
                         if (file == null) {
                             setIconUrl(null).toShare(activity, umShareListener);
                         } else {
-                            setIconUrl(null).setFile(file).toShare(activity, umShareListener);
+                            setIconUrl(null).setIconFile(file).toShare(activity, umShareListener);
                         }
                     }
                 });
                 return;
             } else {
-                setFile(new File(path));
+                setIconFile(new File(path));
             }
         }
         final String realUrl = jointString(link, shareType);
@@ -218,7 +227,10 @@ public class ShareLinkConfig {
                 return;
             case ShareLinkConfig.SYS_SEND:
                 SHARE_SYS_SEND.onEvent();
-                shareBySysSend(activity);
+                if(shareFile == null)
+                    shareBySysSend(activity);
+                else
+                    shareFile(activity, shareFile);
                 return;
             case ShareLinkConfig.FACE_TO_FACE:
                 ViewUtil.showQR(activity, realUrl);
@@ -259,8 +271,8 @@ public class ShareLinkConfig {
         UMImage umImage;
         UMWeb umWeb;
         if (type == WEB) {
-            if(file != null && file.exists()){
-                umImage = new UMImage(SheepApp.getInstance(), file);
+            if(iconFile != null && iconFile.exists()){
+                umImage = new UMImage(SheepApp.getInstance(), iconFile);
             } else if(iconResId > 0){
                 umImage = new UMImage(SheepApp.getInstance(), iconResId);
             } else {
@@ -281,9 +293,11 @@ public class ShareLinkConfig {
                             .share();
                     break;
             }
+        } else if(type == FILE){
+            G.showToast("暂不支持直接分享文件,可以通过系统方式进行分享");
         } else {
-            if(file != null && file.exists()){
-                umImage = new UMImage(SheepApp.getInstance(), file);
+            if(iconFile != null && iconFile.exists()){
+                umImage = new UMImage(SheepApp.getInstance(), iconFile);
             } else if(iconResId > 0){
                 umImage = new UMImage(SheepApp.getInstance(), iconResId);
             } else {
@@ -302,6 +316,10 @@ public class ShareLinkConfig {
         }
     }
 
+    //需要链接,web分享才需要链接
+    private boolean needLink() {
+        return type == WEB;
+    }
 
 
     public static void shareBySysSend(Activity activity) {
@@ -309,17 +327,17 @@ public class ShareLinkConfig {
         if (packageInfo != null && packageInfo.applicationInfo != null && !TextUtils.isEmpty(packageInfo.applicationInfo.sourceDir)) {
             String dir = DIR;
             //File dir = SheepApp.getInstance().getDir("apk", Context.MODE_PRIVATE);
-            File file = new File(dir, String.format(Locale.CHINA, "sheep_release_v%s_%d-%s.apk", packageInfo.versionName, packageInfo.versionCode, DataUtil.getInstance().getInvitationCode()));
-            if (!file.exists()) {
+            File shareApkFile = new File(dir, String.format(Locale.CHINA, "sheep_release_v%s_%d-%s.apk", packageInfo.versionName, packageInfo.versionCode, DataUtil.getInstance().getInvitationCode()));
+            if (!shareApkFile.exists()) {
                 try {
-                    FileUtil.copyFile(new File(packageInfo.applicationInfo.sourceDir), file);
-                    ZipChannelUtil.writeQUA(file, DataUtil.getInstance().getInvitationCode());
+                    FileUtil.copyFile(new File(packageInfo.applicationInfo.sourceDir), shareApkFile);
+                    ZipChannelUtil.writeQUA(shareApkFile, DataUtil.getInstance().getInvitationCode());
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
             }
-            if (file.exists())
-                shareFile(activity, file);
+            if (shareApkFile.exists())
+                shareFile(activity, shareApkFile);
             else
                 G.showToast("暂不支持,或未打开权限");
         } else {
@@ -364,6 +382,9 @@ public class ShareLinkConfig {
      * 1:微信 2:QQ 3:短信 4:二维码 5:其他
      */
     public static String jointString(String url, @ShareLinkConfig.SHARE_TYPE String type) {
+        if(url == null){
+            return null;
+        }
         if (url.contains("&type="))
             return url;
         switch (type) {
@@ -396,8 +417,9 @@ public class ShareLinkConfig {
 
 
     public final static int WEB = 1;//分享网页,
-    public final static int IMG = 2;//分享图片,图片对应的是一个文件:file
-    @IntDef({WEB, IMG})
+    public final static int IMG = 2;//分享图片
+    public final static int FILE = 3;//分享文件,分享文件暂时只支持系统分享的方式
+    @IntDef({WEB, FILE, IMG})
     @Retention(RetentionPolicy.SOURCE)
     public @interface TYPE {
     }

+ 3 - 0
app/src/main/java/com/sheep/gamegroup/util/string/SpannableSb.java

@@ -44,6 +44,9 @@ public class SpannableSb {
     }
 
     public SpannableSb append(Object object) {
+        if(object == null){
+            return this;
+        }
         String text = object.toString();
         if(TextUtils.isEmpty(text)){
             appendText = null;

+ 78 - 31
app/src/main/java/com/sheep/gamegroup/view/activity/ActInstallApkList.java

@@ -1,19 +1,21 @@
 package com.sheep.gamegroup.view.activity;
 
+import android.support.v7.app.AlertDialog;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.TextView;
 
+import com.sheep.gamegroup.absBase.AbsObserver;
 import com.sheep.gamegroup.absBase.BaseActivity;
 import com.sheep.gamegroup.model.entity.AppInfo;
 import com.sheep.gamegroup.util.LogUtil;
-import com.sheep.gamegroup.util.Md5Util;
 import com.sheep.gamegroup.util.StringUtils;
 import com.sheep.gamegroup.util.SysAppUtil;
 import com.sheep.gamegroup.util.ViewHolder;
 import com.sheep.gamegroup.util.ViewUtil;
+import com.sheep.gamegroup.util.share.ShareLinkConfig;
 import com.sheep.gamegroup.view.adapter.AdbCommonRecycler;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
@@ -22,6 +24,7 @@ import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.zip.ZipEntry;
@@ -29,6 +32,9 @@ import java.util.zip.ZipFile;
 
 import butterknife.BindView;
 import butterknife.OnClick;
+import io.reactivex.Observable;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.schedulers.Schedulers;
 
 /**
  * Created by realicing on 2018/6/19.
@@ -49,8 +55,8 @@ public class ActInstallApkList extends BaseActivity {
 
     @Override
     public void initView() {
-        TitleBarUtils
-                .getInstance()
+        TitleBarUtils.getInstance()
+                .setShowOrHide(this, true)
                 .setTitle(this, "已经安装的应用列表")
                 .setTitleFinish(this);
         user_label_commit_tv.setVisibility(View.GONE);
@@ -61,13 +67,26 @@ public class ActInstallApkList extends BaseActivity {
 
     }
 
+    private List<AppInfo> list = new ArrayList<>();
+
     @Override
     public void initData() {
-        loadData(SysAppUtil.getAppInfos());
+        loadData(list);
+        Observable.just(1).map(integer -> SysAppUtil.getAppInfos())
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new AbsObserver<List<AppInfo>>() {
+                    @Override
+                    public void onNext(List<AppInfo> appInfoList) {
+                        list.addAll(appInfoList);
+                        ViewUtil.notifyDataSetChanged(user_label_list);
+                    }
+                });
     }
+
     private void loadData(List<AppInfo> appInfoList) {
         user_label_list.setLayoutManager(new LinearLayoutManager(SheepApp.getInstance()));
-        user_label_list.setAdapter(new AdbCommonRecycler<AppInfo>(SheepApp.getInstance(), appInfoList){
+        user_label_list.setAdapter(new AdbCommonRecycler<AppInfo>(SheepApp.getInstance(), appInfoList) {
 
             @Override
             public int getViewIdByType(int type) {
@@ -77,32 +96,18 @@ public class ActInstallApkList extends BaseActivity {
             @Override
             public void convert(ViewHolder holder, final AppInfo appInfo) {
                 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);
 
                 app_info_iv.setImageDrawable(appInfo.getIcon());
-                ViewUtil.setText(app_info_name_tv, appInfo.getAppName());
-                app_info_name_tv.append(Md5Util.getFileMD5(new File(appInfo.getSourceDir())));
-                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());
-                app_info_path_tv.append("\n"+ (appInfo.isUserApp() ? "用户app":"系统app")  +"\u3000"+ (appInfo.isSD() ? "SD卡" : "手机内存"));
-
-                holder.itemView.setOnClickListener(new View.OnClickListener() {
-                    @Override
-                    public void onClick(View view) {
-                        onClickItem(view, appInfo);
-                    }
-                });
-                holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
-                    @Override
-                    public boolean onLongClick(View view) {
-                        StringUtils.CopyText(appInfo.getSha1());
-                        G.showToast("复制sha1成功:"+appInfo.getSha1());
-                        return true;
-                    }
+                ViewUtil.setText(app_info_tv, appInfo.getAppInfo());
+                ViewUtil.setText(app_info_tv2, appInfo.getAppInfo2());
+
+                holder.itemView.setOnClickListener(view -> onClickItem(view, appInfo));
+                holder.itemView.setOnLongClickListener(view -> {
+                    StringUtils.CopyText(appInfo.getSha1());
+                    G.showToast("复制sha1成功:" + appInfo.getSha1());
+                    return true;
                 });
             }
         });
@@ -110,8 +115,49 @@ public class ActInstallApkList extends BaseActivity {
     }
 
     private void onClickItem(View view, final AppInfo appInfo) {
-        StringUtils.CopyText(appInfo.getPackageName());
-        readApp(appInfo);
+        final String[] items = {
+                "系统分享",
+                "复制包名", "打印apk内容文件列表", "复制名字", "复制sha1", "复制文件路径", "复制md5", "复制签名md5",
+        };
+        AlertDialog dialog = new AlertDialog.Builder(this).setTitle("请选择测试项目")
+                .setItems(items, (dialog1, which) -> onChooseItem(appInfo, items[which])).create();
+        dialog.show();
+    }
+
+    private void onChooseItem(AppInfo appInfo, String item) {
+        switch (item){
+            case "系统分享":
+                tryShareFile(appInfo, ShareLinkConfig.SYS_SEND);
+                break;
+            case "复制包名":
+                StringUtils.CopyText(appInfo.getPackageName());
+                break;
+            case "复制名字":
+                StringUtils.CopyText(appInfo.getAppName());
+                break;
+            case "复制sha1":
+                StringUtils.CopyText(appInfo.getSha1());
+                break;
+            case "复制文件路径":
+                StringUtils.CopyText(appInfo.getSourceDir());
+                break;
+            case "复制md5":
+                StringUtils.CopyText(appInfo.getSourceDirMd5());
+                break;
+            case "复制签名md5":
+                StringUtils.CopyText(appInfo.getSignMd5());
+                break;
+            case "打印apk内容文件列表":
+                readApp(appInfo);
+                break;
+        }
+    }
+
+    private void tryShareFile(AppInfo appInfo, @ShareLinkConfig.SHARE_TYPE String shareType) {
+        new ShareLinkConfig().setTitle("分享:" +appInfo.getAppName()).setDes(appInfo.getAppInfo().toString())
+                .setShareFile(new File(appInfo.getSourceDir()))
+                .setShareType(shareType).setType(ShareLinkConfig.FILE)
+                .toShare(SheepApp.getInstance().getCurrentActivity());
     }
 
 
@@ -141,6 +187,7 @@ public class ActInstallApkList extends BaseActivity {
             }
         }
     }
+
     @OnClick({R.id.user_label_commit_tv})
     public void onViewClicked(View view) {
         switch (view.getId()) {

+ 1 - 5
app/src/main/java/com/sheep/gamegroup/view/activity/ActInvitation.java

@@ -30,7 +30,6 @@ import com.bumptech.glide.request.RequestListener;
 import com.bumptech.glide.request.RequestOptions;
 import com.bumptech.glide.request.target.Target;
 import com.kfzs.duanduan.utils.StatusBarUtils;
-import com.sheep.gamegroup.absBase.BaseActivity;
 import com.sheep.gamegroup.absBase.BaseUMActivity;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.FriendAndAwardEntity;
@@ -65,13 +64,10 @@ import java.util.List;
 import java.util.Locale;
 
 import butterknife.BindView;
-import butterknife.OnClick;
 import io.reactivex.android.schedulers.AndroidSchedulers;
 import io.reactivex.schedulers.Schedulers;
 import rx.functions.Action1;
 
-import static com.sheep.gamegroup.util.ViewUtil.getNetImgByName;
-
 /**
  * Created by realicing on 2018/9/7.
  * realicing@sina.com
@@ -446,7 +442,7 @@ public class ActInvitation extends BaseUMActivity {
                                 .setLink(url)
                                 .setShareType(item)
                                 .setDes(description)
-                                .setFile(file)
+                                .setIconFile(file)
                                 .setType(ShareLinkConfig.IMG)
                                 .toShare(ActInvitation.this, new UMShareListener() {
 

+ 51 - 61
app/src/main/java/com/sheep/gamegroup/view/activity/ActSheepApkList.java

@@ -12,9 +12,11 @@ import android.view.View;
 import android.widget.ImageView;
 import android.widget.TextView;
 
+import com.sheep.gamegroup.absBase.AbsObserver;
 import com.sheep.gamegroup.absBase.BaseActivity;
 import com.sheep.gamegroup.model.entity.ApkInfo;
 import com.sheep.gamegroup.model.entity.AppInfo;
+import com.sheep.gamegroup.util.FileUtil;
 import com.sheep.gamegroup.util.ListUtil;
 import com.sheep.gamegroup.util.StringUtils;
 import com.sheep.gamegroup.util.SysAppUtil;
@@ -31,11 +33,15 @@ import java.io.File;
 import java.io.IOException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
 
 import butterknife.BindView;
 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;
 
@@ -60,6 +66,7 @@ public class ActSheepApkList extends BaseActivity {
     public void initView() {
         TitleBarUtils
                 .getInstance()
+                .setShowOrHide(this, true)
                 .setTitle(this, "Sheep目录Apk渠道测试")
                 .setTitleFinish(this);
         user_label_commit_tv.setVisibility(View.GONE);
@@ -70,54 +77,45 @@ public class ActSheepApkList extends BaseActivity {
 
     }
 
+    private List<ApkInfo> list = new ArrayList<>();
+
     @Override
     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() {
         List<ApkInfo> apkInfoList = ListUtil.emptyList();
 
         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) {
                 apkInfoList.add(getAppInfo(getApplicationContext(), file));
             }
         return apkInfoList;
     }
-    public static boolean onlyZip = true;
+
+
     public static ApkInfo getAppInfo(Context context, File file) {
         ApkInfo apkInfo = new ApkInfo();
+        String extensionName = FileUtil.getExtensionName(file.getName());
+        if (TextUtils.isEmpty(extensionName)) {
+            return null;
+        }
         PackageManager packageManager = context.getPackageManager();
         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.setFile(file);
         try {
@@ -128,6 +126,7 @@ public class ActSheepApkList extends BaseActivity {
         }
         return apkInfo;
     }
+
     //得到PackageInfo对象
     public static PackageInfo getPackageInfo(Context context, String apkFilepath) {
         PackageManager pm = context.getPackageManager();
@@ -140,9 +139,10 @@ public class ActSheepApkList extends BaseActivity {
         }
         return pkgInfo;
     }
+
     private void loadData(List<ApkInfo> list) {
         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
             public int getViewIdByType(int type) {
@@ -152,41 +152,31 @@ public class ActSheepApkList extends BaseActivity {
             @Override
             public void convert(ViewHolder holder, final ApkInfo item) {
                 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();
-                if(appInfo == null){
-                    return;
-                }
-                if(appInfo.getIcon() != null)
+                if (appInfo != null && appInfo.getIcon() != null)
                     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());
-                        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 {
-        if(TextUtils.isEmpty(apkInfo.getComment())){
+        if (TextUtils.isEmpty(apkInfo.getComment())) {
             String comment = "976873";
             ZipChannelUtil.writeQUA(apkInfo.getFile(), comment);
             apkInfo.setComment(comment);
@@ -202,7 +192,7 @@ public class ActSheepApkList extends BaseActivity {
             G.showToast("给apk添加zip注释作为渠道成功");
         } else {
             ZipChannelUtil.delQUA(apkInfo.getFile());
-            G.showToast("成功删除渠道:"+apkInfo.getComment());
+            G.showToast("成功删除渠道:" + apkInfo.getComment());
             apkInfo.setComment("");
             user_label_list.getAdapter().notifyDataSetChanged();
         }

+ 3 - 10
app/src/main/java/com/sheep/gamegroup/view/activity/ActSheepPngList.java

@@ -49,6 +49,7 @@ public class ActSheepPngList extends BaseActivity {
     public void initView() {
         TitleBarUtils
                 .getInstance()
+                .setShowOrHide(this, true)
                 .setTitle(this, "Sheep目录png测试")
                 .setTitleFinish(this);
         user_label_commit_tv.setVisibility(View.GONE);
@@ -66,12 +67,7 @@ public class ActSheepPngList extends BaseActivity {
 
     private List<File> getList() {
         File dir = new File(DIR);
-        File[] files = dir.listFiles(new FileFilter() {
-            @Override
-            public boolean accept(File file) {
-                return TextUtils.equals(FileUtil.getExtensionName(file.getName()), "png");
-            }
-        });
+        File[] files = dir.listFiles(file -> TextUtils.equals(FileUtil.getExtensionName(file.getName()), "png"));
         return ListUtil.asList(files);
     }
     private void loadData(List<File> list) {
@@ -86,10 +82,7 @@ public class ActSheepPngList extends BaseActivity {
             @Override
             public void convert(ViewHolder holder, final File item) {
                 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_name_tv = holder.itemView.findViewById(R.id.app_info_tv);
 
                 Glide.with(SheepApp.getInstance())
                         .load(item)

+ 29 - 26
app/src/main/java/com/sheep/gamegroup/view/activity/ActUserLabelList.java

@@ -50,10 +50,10 @@ public class ActUserLabelList extends BaseActivity {
 
     @Override
     public void initView() {
-        TitleBarUtils
-                .getInstance()
+        TitleBarUtils.getInstance()
+                .setShowOrHide(this, true)
                 .setTitle(this, "请选择您喜欢的标签")
-                .setTitleListen(this, -2,null);
+                .setTitleListen(this, -2, null);
     }
 
     @Override
@@ -81,11 +81,13 @@ public class ActUserLabelList extends BaseActivity {
                     }
                 });
     }
+
     private List<UserLabelList> checkLabelList;
+
     private void loadData(List<UserLabelList> checkLabelList) {
         this.checkLabelList = checkLabelList;
         user_label_list.setLayoutManager(new LinearLayoutManager(SheepApp.getInstance()));
-        user_label_list.setAdapter(new AdbCommonRecycler<UserLabelList>(SheepApp.getInstance(), checkLabelList){
+        user_label_list.setAdapter(new AdbCommonRecycler<UserLabelList>(SheepApp.getInstance(), checkLabelList) {
 
             @Override
             public int getViewIdByType(int type) {
@@ -99,7 +101,7 @@ public class ActUserLabelList extends BaseActivity {
                 ViewUtil.setText(user_label_tv, userLabelList.getLabel_type_name());
 
                 TagFlowLayout tagList = rootConvertView.findViewById(R.id.user_label_tagflow_layout);
-                if(tagList != null) {
+                if (tagList != null) {
                     TagAdapter adapter = new TagAdapter<UserLabel>(userLabelList.getLabels()) {
                         @Override
                         public View getView(FlowLayout parent, int position, UserLabel userLabel) {
@@ -115,7 +117,7 @@ public class ActUserLabelList extends BaseActivity {
                         @Override
                         public boolean onTagClick(View view, int position, FlowLayout parent) {
                             UserLabel userLabel = ListUtil.getItem(userLabelList.getLabels(), position);
-                            if(userLabel != null) {
+                            if (userLabel != null) {
                                 userLabel.setChecked(!userLabel.isChecked());
                                 return true;
                             }
@@ -127,6 +129,7 @@ public class ActUserLabelList extends BaseActivity {
         });
 
     }
+
     @OnClick({R.id.user_label_commit_tv})
     public void onViewClicked(View view) {
         switch (view.getId()) {
@@ -137,40 +140,40 @@ public class ActUserLabelList extends BaseActivity {
     }
 
     private void toCommit() {
-        if(ListUtil.isEmpty(checkLabelList)){
+        if (ListUtil.isEmpty(checkLabelList)) {
             G.showToast(R.string.loading_data);
             return;
         }
         List<Integer> list = ListUtil.emptyList();
         for (UserLabelList userLabelList : checkLabelList) {
             for (UserLabel userLabel : userLabelList.getLabels()) {
-                if(userLabel.isChecked()) {
+                if (userLabel.isChecked()) {
                     list.add(userLabel.getLabel_id());
                 }
             }
         }
-        LogUtil.println("用户标签:"+list.size());
+        LogUtil.println("用户标签:" + list.size());
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("label_ids", list);
         SheepApp.getInstance().getNetComponent().getApiService().postLabelList(jsonObject)
-                        .subscribeOn(Schedulers.io())
-                        .observeOn(AndroidSchedulers.mainThread())
-                        .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
-                            @Override
-                            public void onNext(BaseMessage baseMessage) {
-                                Jump2View.getInstance().checkCommendApp(ActUserLabelList.this, null);
-                                finish();
-                            }
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                    @Override
+                    public void onNext(BaseMessage baseMessage) {
+                        Jump2View.getInstance().checkCommendApp(ActUserLabelList.this, null);
+                        finish();
+                    }
 
-                            @Override
-                            public void onError(BaseMessage baseMessage) {
-                                G.showToast(baseMessage);
-                                if(BuildConfig.DEBUG){
-                                    Jump2View.getInstance().checkCommendApp(ActUserLabelList.this, null);
-                                    finish();
-                                }
-                            }
-                        });
+                    @Override
+                    public void onError(BaseMessage baseMessage) {
+                        G.showToast(baseMessage);
+                        if (BuildConfig.DEBUG) {
+                            Jump2View.getInstance().checkCommendApp(ActUserLabelList.this, null);
+                            finish();
+                        }
+                    }
+                });
     }
 
 }

+ 1 - 2
app/src/main/res/layout/act_user_label_list.xml

@@ -2,10 +2,9 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:fitsSystemWindows="true"
     android:orientation="vertical">
 
-    <include layout="@layout/title" />
-
     <android.support.v7.widget.RecyclerView
         android:id="@+id/user_label_list"
         android:layout_width="match_parent"

+ 25 - 43
app/src/main/res/layout/app_info_item.xml

@@ -5,65 +5,47 @@
     android:layout_height="wrap_content"
     android:layout_marginTop="@dimen/dp_10"
     android:background="@drawable/x_shap_shadow_bg_rectgangle_white"
-    android:paddingBottom="@dimen/dp_10"
-    android:paddingEnd="@dimen/content_padding_20"
     android:paddingStart="@dimen/dp_10"
-    android:paddingTop="@dimen/dp_10">
+    android:paddingTop="@dimen/dp_10"
+    android:paddingEnd="10dp"
+    android:paddingBottom="@dimen/dp_10">
 
     <ImageView
         android:id="@+id/app_info_iv"
-        android:layout_width="80dp"
-        android:layout_height="80dp"
+        android:layout_width="50dp"
+        android:layout_height="50dp"
         android:src="@mipmap/icon"
-        app:layout_constraintStart_toStartOf="parent" />
+        app:layout_constraintBottom_toTopOf="@id/app_info_tv2"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toStartOf="@id/app_info_tv"
+        app:layout_constraintTop_toTopOf="parent" />
 
     <TextView
-        android:id="@+id/app_info_name_tv"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
+        android:id="@+id/app_info_tv"
+        android:layout_width="0dp"
+        android:layout_height="0dp"
         android:layout_gravity="center_vertical"
-        android:layout_marginStart="@dimen/dp_10"
+        android:layout_marginStart="6dp"
         android:text="名称"
         android:textColor="@color/black_6_3"
         android:textSize="12sp"
-        app:layout_constraintBottom_toTopOf="@+id/app_info_size_tv"
+        app:layout_constraintBottom_toBottomOf="@id/app_info_iv"
+        app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toEndOf="@id/app_info_iv"
-        app:layout_constraintTop_toTopOf="@+id/app_info_iv" />
+        app:layout_constraintTop_toTopOf="@id/app_info_iv" />
 
     <TextView
-        android:id="@+id/app_info_package_name_tv"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_gravity="center_vertical"
-        android:text="包名"
-        android:textColor="@color/black_191919"
-        android:textSize="12sp"
-        app:layout_constraintBottom_toTopOf="@+id/app_info_path_tv"
-        app:layout_constraintStart_toStartOf="@+id/app_info_name_tv"
-        app:layout_constraintTop_toBottomOf="@+id/app_info_name_tv" />
-    <TextView
-        android:id="@+id/app_info_size_tv"
-        android:layout_width="wrap_content"
+        android:id="@+id/app_info_tv2"
+        android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_gravity="center_vertical"
-        android:text="大小"
-        android:textColor="@color/black_191919"
-        android:textSize="12sp"
-        android:layout_marginStart="@dimen/dp_10"
-        app:layout_constraintBottom_toTopOf="@+id/app_info_path_tv"
-        app:layout_constraintStart_toEndOf="@+id/app_info_package_name_tv"
-        app:layout_constraintTop_toBottomOf="@+id/app_info_name_tv" />
-
-    <TextView
-        android:id="@+id/app_info_path_tv"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_gravity="center_vertical"
-        android:text="路径"
-        android:textColor="@color/black_deep"
+        android:text="详细"
+        android:textColor="@color/black_6_3"
         android:textSize="12sp"
-        app:layout_constraintBottom_toBottomOf="@+id/app_info_iv"
-        app:layout_constraintStart_toStartOf="@+id/app_info_name_tv"
-        app:layout_constraintTop_toBottomOf="@+id/app_info_size_tv" />
+        android:layout_marginTop="6dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@id/app_info_iv" />
 
 </android.support.constraint.ConstraintLayout>