|
|
@@ -5,6 +5,7 @@ import static android.content.Context.POWER_SERVICE;
|
|
|
import android.content.Context;
|
|
|
import android.os.CancellationSignal;
|
|
|
import android.os.PowerManager;
|
|
|
+import android.provider.DocumentsContract;
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
import androidx.annotation.IntDef;
|
|
|
@@ -76,12 +77,9 @@ public class FileScanHelper {
|
|
|
* 需要能单扫某个文件夹(某个app)
|
|
|
*/
|
|
|
|
|
|
- @IntDef({RefreshScanType.GALLERY, RefreshScanType.WEIXIN, RefreshScanType.QQ})
|
|
|
+ @IntDef({FileType.IMAGE_GALLERY, FileType.IMAGE_WEIXIN, FileType.IMAGE_QQ})
|
|
|
@Retention(RetentionPolicy.SOURCE)
|
|
|
public @interface RefreshScanType {
|
|
|
- int GALLERY = 1;
|
|
|
- int WEIXIN = 2;
|
|
|
- int QQ = 3;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -96,12 +94,12 @@ public class FileScanHelper {
|
|
|
|
|
|
@Override
|
|
|
public boolean acceptFile(XFile file) {
|
|
|
- return isAcceptImageFile(file);
|
|
|
+ return isAcceptImageFile(scanType, file);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean acceptDirectory(XFile file) {
|
|
|
- return isAcceptImageDirectory(file);
|
|
|
+ return isAcceptImageDirectory(scanType, file);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -135,7 +133,8 @@ public class FileScanHelper {
|
|
|
switch (tag) {
|
|
|
case ImageType.IMG_MAGIC:
|
|
|
case ImageType.IMAGE_SUFFIX:
|
|
|
- return Flowable.just(new DetectFile(xFile, FileType.IMAGE_OTHER));
|
|
|
+ case ImageType.IMG_DATA:
|
|
|
+ return Flowable.just(new DetectFile(xFile, scanType));
|
|
|
case ImageType.XIAOMI_GALLERY_CACHE:
|
|
|
return Flowable.just(new DetectFile(xFile, FileType.IMAGE_GALLERY));
|
|
|
case ImageType.WECHAT_CACHE:
|
|
|
@@ -165,7 +164,7 @@ public class FileScanHelper {
|
|
|
.doOnTerminate(() -> releaseWakeLock(context));
|
|
|
}
|
|
|
|
|
|
- private static boolean isAcceptImageFile(XFile file) {
|
|
|
+ private static boolean isAcceptImageFile(int scanType, XFile file) {
|
|
|
try {
|
|
|
if (file.length() == 0) {
|
|
|
return false;
|
|
|
@@ -173,6 +172,14 @@ public class FileScanHelper {
|
|
|
} catch (Exception ignore) {
|
|
|
}
|
|
|
try {
|
|
|
+ if (file.getMineType() != null && file.getMineType().startsWith("image/")) {
|
|
|
+ file.setTag(ImageType.IMG_DATA);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } catch (Exception ignore) {
|
|
|
+
|
|
|
+ }
|
|
|
+ try {
|
|
|
String name = file.getName();
|
|
|
if (ImageCacheUtil.isImageSuffix(name)) {
|
|
|
file.setTag(ImageType.IMAGE_SUFFIX);
|
|
|
@@ -180,37 +187,40 @@ public class FileScanHelper {
|
|
|
}
|
|
|
} catch (Exception ignore) {
|
|
|
}
|
|
|
- try {
|
|
|
- String path = file.getPath();
|
|
|
- int brand = BrandUtil.getBrand();
|
|
|
- switch (brand) {
|
|
|
- case BrandUtil.Oppo:
|
|
|
- if (ImageCacheUtil.isOppoGalleryCacheFile(path)) {
|
|
|
- file.setTag(ImageType.OPPO_GALLERY_CACHE);
|
|
|
- }
|
|
|
- return true;
|
|
|
- case BrandUtil.Vivo:
|
|
|
- if (ImageCacheUtil.isVivoGalleryCacheFile(path)) {
|
|
|
- file.setTag(ImageType.VIVO_GALLERY_CACHE);
|
|
|
- }
|
|
|
- return true;
|
|
|
- case BrandUtil.XiaoMi:
|
|
|
- if (ImageCacheUtil.isXiaomiGalleryCacheFile(path)) {
|
|
|
- file.setTag(ImageType.XIAOMI_GALLERY_CACHE);
|
|
|
- }
|
|
|
- return true;
|
|
|
- case BrandUtil.Meizu:
|
|
|
- if (ImageCacheUtil.isMeizuGalleryCacheFile(path)) {
|
|
|
- file.setTag(ImageType.MEIZU_GALLERY_CACHE);
|
|
|
- }
|
|
|
- return true;
|
|
|
- case BrandUtil.HuaWei:
|
|
|
- if (ImageCacheUtil.isHuaweiGalleryCacheFile(path)) {
|
|
|
- file.setTag(ImageType.HUAWEI_GALLERY_CACHE);
|
|
|
- }
|
|
|
- return true;
|
|
|
+
|
|
|
+ if (scanType == FileType.IMAGE_GALLERY) {
|
|
|
+ try {
|
|
|
+ String path = file.getPath();
|
|
|
+ int brand = BrandUtil.getBrand();
|
|
|
+ switch (brand) {
|
|
|
+ case BrandUtil.Oppo:
|
|
|
+ if (ImageCacheUtil.isOppoGalleryCacheFile(path)) {
|
|
|
+ file.setTag(ImageType.OPPO_GALLERY_CACHE);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ case BrandUtil.Vivo:
|
|
|
+ if (ImageCacheUtil.isVivoGalleryCacheFile(path)) {
|
|
|
+ file.setTag(ImageType.VIVO_GALLERY_CACHE);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ case BrandUtil.XiaoMi:
|
|
|
+ if (ImageCacheUtil.isXiaomiGalleryCacheFile(path)) {
|
|
|
+ file.setTag(ImageType.XIAOMI_GALLERY_CACHE);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ case BrandUtil.Meizu:
|
|
|
+ if (ImageCacheUtil.isMeizuGalleryCacheFile(path)) {
|
|
|
+ file.setTag(ImageType.MEIZU_GALLERY_CACHE);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ case BrandUtil.HuaWei:
|
|
|
+ if (ImageCacheUtil.isHuaweiGalleryCacheFile(path)) {
|
|
|
+ file.setTag(ImageType.HUAWEI_GALLERY_CACHE);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } catch (Exception ignore) {
|
|
|
}
|
|
|
- } catch (Exception ignore) {
|
|
|
}
|
|
|
if (ImageCacheUtil.hasImgMagic(file)) {
|
|
|
file.setTag(ImageType.IMG_MAGIC);
|
|
|
@@ -220,14 +230,16 @@ public class FileScanHelper {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static boolean isAcceptImageDirectory(XFile file) {
|
|
|
- try {
|
|
|
- String path = file.getPath();
|
|
|
- if (isGalleryCacheDirectory(path)) {
|
|
|
- file.setTag(ImageType.GALLERY_CACHE);
|
|
|
- return true;
|
|
|
+ public static boolean isAcceptImageDirectory(int scanType, XFile file) {
|
|
|
+ if (scanType == FileType.IMAGE_GALLERY) {
|
|
|
+ try {
|
|
|
+ String path = file.getPath();
|
|
|
+ if (isGalleryCacheDirectory(path)) {
|
|
|
+ file.setTag(ImageType.GALLERY_CACHE);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } catch (Exception ignore) {
|
|
|
}
|
|
|
- } catch (Exception ignore) {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
@@ -247,7 +259,7 @@ public class FileScanHelper {
|
|
|
if (TextUtils.isEmpty(path)) {
|
|
|
return true;
|
|
|
}
|
|
|
- if (RefreshScanType.GALLERY == scanType) {
|
|
|
+ if (FileType.IMAGE_GALLERY == scanType) {
|
|
|
if (path.endsWith("Pictures/QQ") || path.endsWith("Pictures%2FQQ") ||
|
|
|
path.endsWith("DCIM/WeixinWork") || path.endsWith("DCIM%2FWeixinWork") ||
|
|
|
path.endsWith("Pictures/WeiXin") || path.endsWith("Pictures%2FWeiXin")
|
|
|
@@ -362,11 +374,11 @@ public class FileScanHelper {
|
|
|
|
|
|
private static List<String[]> getImageScanDirectory(@RefreshScanType int scanType) {
|
|
|
switch (scanType) {
|
|
|
- case RefreshScanType.GALLERY:
|
|
|
+ case FileType.IMAGE_GALLERY:
|
|
|
return getGallery();
|
|
|
- case RefreshScanType.WEIXIN:
|
|
|
+ case FileType.IMAGE_WEIXIN:
|
|
|
return getWeiXin();
|
|
|
- case RefreshScanType.QQ:
|
|
|
+ case FileType.IMAGE_QQ:
|
|
|
return getQQ();
|
|
|
}
|
|
|
return null;
|