parent
1187f45913
commit
fa7c35503e
|
|
@ -4,10 +4,10 @@
|
||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
<DropdownSelection timestamp="2026-03-10T06:53:45.140671700Z">
|
<DropdownSelection timestamp="2026-03-11T06:38:33.168759600Z">
|
||||||
<Target type="DEFAULT_BOOT">
|
<Target type="DEFAULT_BOOT">
|
||||||
<handle>
|
<handle>
|
||||||
<DeviceId pluginId="PhysicalDevice" identifier="serial=d927cac5" />
|
<DeviceId pluginId="PhysicalDevice" identifier="serial=Y5DELZR46DZTCI9D" />
|
||||||
</handle>
|
</handle>
|
||||||
</Target>
|
</Target>
|
||||||
</DropdownSelection>
|
</DropdownSelection>
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@ android {
|
||||||
applicationId = "com.img.rabbit"
|
applicationId = "com.img.rabbit"
|
||||||
minSdk = 24
|
minSdk = 24
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 3
|
versionCode = 1
|
||||||
versionName = "1.0.3"
|
versionName = "1.0.0"
|
||||||
multiDexEnabled = true
|
multiDexEnabled = true
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
|
||||||
|
|
@ -338,7 +338,7 @@ class MainActivity : ComponentActivity(), LoadingCallback {
|
||||||
UpdateUtils.download(
|
UpdateUtils.download(
|
||||||
scope = coroutineScope,
|
scope = coroutineScope,
|
||||||
url = url,
|
url = url,
|
||||||
filePath = FileUtils.getInstance().cacheDownLoadDir.absolutePath,
|
filePath = FileUtils.instance?.cacheDownLoadDir?.absolutePath?:"",
|
||||||
fileName = AppUpdate.getFileNameFromUrl(url),
|
fileName = AppUpdate.getFileNameFromUrl(url),
|
||||||
onProgress = {progress->
|
onProgress = {progress->
|
||||||
progressState.floatValue = progress.toFloat()/100f
|
progressState.floatValue = progress.toFloat()/100f
|
||||||
|
|
|
||||||
|
|
@ -1,337 +1,239 @@
|
||||||
package com.img.rabbit.utils;
|
package com.img.rabbit.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Environment
|
||||||
|
import android.os.StatFs
|
||||||
|
import android.util.Log
|
||||||
|
import com.img.rabbit.provider.utils.HeadParamUtils.applicationContext
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.text.DecimalFormat
|
||||||
|
import java.util.Objects
|
||||||
|
|
||||||
import android.content.Context;
|
/**
|
||||||
import android.content.Intent;
|
* 文件工具类
|
||||||
import android.os.Environment;
|
* 注意:处理路径(android/data/xxx.xxx.xxx/files/cache/)
|
||||||
import android.os.StatFs;
|
*/
|
||||||
import android.text.TextUtils;
|
class FileUtils private constructor(context: Context) {
|
||||||
import android.util.Log;
|
// 文件缓存路径(android/data/xxx.xxx.xxx/files/)
|
||||||
|
var cacheParentDir: String?
|
||||||
import com.img.rabbit.provider.utils.HeadParamUtils;
|
private set
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@SuppressWarnings({"ResultOfMethodCallIgnored", "CallToPrintStackTrace"})
|
|
||||||
public class FileUtils {
|
|
||||||
|
|
||||||
private static FileUtils instance;
|
|
||||||
private static String packageName = "dev";
|
|
||||||
|
|
||||||
// 文件缓存路径
|
|
||||||
private String CACHE_DIR;
|
|
||||||
|
|
||||||
// 下载目录
|
|
||||||
private File downloadDir;
|
|
||||||
// 缓存目录
|
|
||||||
private File cacheDir;
|
|
||||||
// 图片缓存目录
|
|
||||||
private File cacheImageDir;
|
|
||||||
|
|
||||||
private File cacheOriginalImageDir;
|
|
||||||
|
|
||||||
private File cacheEditImageDir;
|
|
||||||
|
|
||||||
private File cachePuzzleImageDir;
|
|
||||||
// 下载Uni小程序WGTD文件存放目录
|
|
||||||
private File uniWGTDir;
|
|
||||||
|
|
||||||
public static FileUtils getInstance() {
|
|
||||||
if (instance == null) {
|
|
||||||
synchronized (FileUtils.class) {
|
|
||||||
if (instance == null) {
|
|
||||||
instance = new FileUtils(Objects.requireNonNull(HeadParamUtils.INSTANCE.getApplicationContext()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileUtils(Context context) {
|
|
||||||
CACHE_DIR = Objects.requireNonNull(context.getExternalFilesDir(null)).getAbsolutePath() + File.separator + packageName + File.separator;
|
|
||||||
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
|
||||||
cacheDir = new File(CACHE_DIR, "/cache");
|
|
||||||
} else {
|
|
||||||
cacheDir = context.getCacheDir();
|
|
||||||
}
|
|
||||||
if (!cacheDir.exists())
|
|
||||||
cacheDir.mkdirs();
|
|
||||||
cacheImageDir = new File(cacheDir, "/image/");
|
|
||||||
if (!cacheImageDir.exists())
|
|
||||||
cacheImageDir.mkdirs();
|
|
||||||
|
|
||||||
cacheOriginalImageDir = new File(cacheDir, "/originalImage/");
|
|
||||||
if (!cacheOriginalImageDir.exists())
|
|
||||||
cacheOriginalImageDir.mkdirs();
|
|
||||||
|
|
||||||
cacheEditImageDir = new File(cacheDir, "/cacheEditImage/");
|
|
||||||
if (!cacheEditImageDir.exists())
|
|
||||||
cacheEditImageDir.mkdirs();
|
|
||||||
|
|
||||||
cachePuzzleImageDir = new File(cacheDir, "/cachePuzzleImage/");
|
|
||||||
if (!cachePuzzleImageDir.exists())
|
|
||||||
cachePuzzleImageDir.mkdirs();
|
|
||||||
|
|
||||||
downloadDir = new File(cacheDir, "/download/");
|
|
||||||
if (!downloadDir.exists())
|
|
||||||
downloadDir.mkdirs();
|
|
||||||
|
|
||||||
uniWGTDir = new File(cacheDir, "/uniApp/");
|
|
||||||
if (!uniWGTDir.exists())
|
|
||||||
uniWGTDir.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCACHE_DIR() {
|
|
||||||
return CACHE_DIR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取缓存目录
|
* 缓存目录(/cache/)
|
||||||
*/
|
*/
|
||||||
public File getCacheDir() {
|
private var cacheDir: File? = null
|
||||||
return cacheDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取下载目录
|
* 下载目录(/cache/download/)
|
||||||
*/
|
*/
|
||||||
public File getCacheDownLoadDir() {
|
var cacheDownLoadDir: File
|
||||||
return downloadDir;
|
private set
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* 缓存图片目录(/cache/image/)
|
||||||
|
*/
|
||||||
|
var cacheImageDir: File
|
||||||
|
private set
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取UniApp目录
|
* 获取UniApp目录
|
||||||
|
* 下载Uni小程序wgt文件存放目录(/cache/uniApp/)
|
||||||
*/
|
*/
|
||||||
public File getCacheUniAppDir() {
|
var cacheUniAppDir: File
|
||||||
return uniWGTDir;
|
private set
|
||||||
|
|
||||||
|
init {
|
||||||
|
this.cacheParentDir = context.getExternalFilesDir(null)?.absolutePath + File.separator
|
||||||
|
cacheDir = if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
|
||||||
|
File(this.cacheParentDir, "/cache")
|
||||||
|
} else {
|
||||||
|
context.cacheDir
|
||||||
|
}
|
||||||
|
if (cacheDir?.exists() != true) cacheDir?.mkdirs()
|
||||||
|
|
||||||
|
cacheImageDir = File(cacheDir, "/image/")
|
||||||
|
if (!cacheImageDir.exists()) cacheImageDir.mkdirs()
|
||||||
|
|
||||||
|
this.cacheDownLoadDir = File(cacheDir, "/download/")
|
||||||
|
if (!cacheDownLoadDir.exists()) cacheDownLoadDir.mkdirs()
|
||||||
|
|
||||||
|
this.cacheUniAppDir = File(cacheDir, "/uniApp/")
|
||||||
|
if (!cacheUniAppDir.exists()) cacheUniAppDir.mkdirs()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取缓存图片目录
|
* 获取缓存目录(android/data/xxx.xxx.xxx/files/cache/)
|
||||||
*/
|
*/
|
||||||
public File getCacheImageDir() {
|
fun getCacheDir(): File {
|
||||||
return cacheImageDir;
|
cacheDir = if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
|
||||||
|
File(this.cacheParentDir, "/cache")
|
||||||
|
} else {
|
||||||
|
applicationContext?.cacheDir
|
||||||
|
}
|
||||||
|
return cacheDir!!
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 水印照片编辑后的路径
|
* 创建一个临时图片文件((android/data/xxx.xxx.xxx/files/cache/image/系统当前时间.jpg)
|
||||||
*/
|
*/
|
||||||
public File getCacheEditImageDir() {
|
fun newTempImageFile(): File {
|
||||||
return cacheEditImageDir;
|
return File(cacheImageDir, System.currentTimeMillis().toString() + ".jpg")
|
||||||
}
|
|
||||||
|
|
||||||
public File getCacheOriginalImageDir() {
|
|
||||||
return cacheOriginalImageDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 拼图路径
|
|
||||||
*/
|
|
||||||
public File getCachePuzzleImageDir() {
|
|
||||||
return cachePuzzleImageDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建一个临时图片文件
|
|
||||||
*/
|
|
||||||
public File newTempImageFile() {
|
|
||||||
return new File(cacheImageDir, System.currentTimeMillis() + ".jpg");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断是否安装SD卡
|
|
||||||
*/
|
|
||||||
public static boolean checkSaveLocationExists() {
|
|
||||||
String sDCardStatus = Environment.getExternalStorageState();
|
|
||||||
boolean status;
|
|
||||||
status = sDCardStatus.equals(Environment.MEDIA_MOUNTED);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除指定目录下文件及目录
|
|
||||||
*/
|
|
||||||
public static void deleteFolderFile(String filePath) {
|
|
||||||
if (!TextUtils.isEmpty(filePath)) {
|
|
||||||
try {
|
|
||||||
File file = new File(filePath);
|
|
||||||
if (file.isDirectory()) {// 处理目录
|
|
||||||
File[] files = file.listFiles();
|
|
||||||
for (int i = 0; i < Objects.requireNonNull(files).length; i++) {
|
|
||||||
deleteFolderFile(files[i].getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!file.isDirectory()) {// 如果是文件,删除
|
|
||||||
file.delete();
|
|
||||||
} else {// 目录
|
|
||||||
if (Objects.requireNonNull(file.listFiles()).length == 0) {// 目录下没有文件或者目录,删除
|
|
||||||
file.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e("FileUtils", Objects.requireNonNull(e.getMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除文件
|
* 删除文件
|
||||||
*/
|
*/
|
||||||
public boolean deleteFile(String path) {
|
fun deleteFile(path: String): Boolean = File(path).takeIf { it.isFile }?.delete() ?: false
|
||||||
boolean status;
|
|
||||||
SecurityManager checker = new SecurityManager();
|
|
||||||
|
|
||||||
if (!path.isEmpty()) {
|
|
||||||
File newPath = new File(path);
|
fun fileIsExists(file: File): Boolean = file.exists()
|
||||||
checker.checkDelete(newPath.toString());
|
|
||||||
if (newPath.isFile()) {
|
/**
|
||||||
|
* 打开图库
|
||||||
|
*/
|
||||||
|
fun openGallery(context: Context) {
|
||||||
try {
|
try {
|
||||||
|
val intent = Intent(Intent.ACTION_MAIN)
|
||||||
newPath.delete();
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
status = true;
|
intent.addCategory(Intent.CATEGORY_APP_GALLERY)
|
||||||
} catch (SecurityException se) {
|
context.startActivity(intent)
|
||||||
Log.e("FileUtils", Objects.requireNonNull(se.getMessage()));
|
} catch (e: Exception) {
|
||||||
status = false;
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
status = false;
|
|
||||||
} else
|
companion object {
|
||||||
status = false;
|
var instance: FileUtils? = null
|
||||||
return status;
|
get() {
|
||||||
|
if (field == null) {
|
||||||
|
synchronized(FileUtils::class.java) {
|
||||||
|
if (field == null) {
|
||||||
|
field = applicationContext?.let { FileUtils(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return field
|
||||||
|
}
|
||||||
|
private set
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否安装SD卡
|
||||||
|
*/
|
||||||
|
fun checkSaveLocationExists(): Boolean {
|
||||||
|
val sDCardStatus = Environment.getExternalStorageState()
|
||||||
|
val status = sDCardStatus == Environment.MEDIA_MOUNTED
|
||||||
|
return status
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除指定目录下文件及目录
|
||||||
|
*/
|
||||||
|
fun deleteFolderFile(filePath: String?) {
|
||||||
|
filePath?.let { File(filePath).deleteRecursively() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取目录文件大小
|
* 获取目录文件大小
|
||||||
*/
|
*/
|
||||||
public static long getDirSize(File dir) {
|
fun getDirSize(dir: File?): Long {
|
||||||
if (dir == null) {
|
if (dir == null) {
|
||||||
return 0;
|
return 0
|
||||||
}
|
}
|
||||||
if (!dir.isDirectory()) {
|
if (!dir.isDirectory()) {
|
||||||
return 0;
|
return 0
|
||||||
}
|
}
|
||||||
long dirSize = 0;
|
var dirSize: Long = 0
|
||||||
File[] files = dir.listFiles();
|
val files = dir.listFiles()
|
||||||
for (File file : Objects.requireNonNull(files)) {
|
for (file in Objects.requireNonNull(files)) {
|
||||||
if (file.isFile()) {
|
if (file.isFile()) {
|
||||||
dirSize += file.length();
|
dirSize += file.length()
|
||||||
} else if (file.isDirectory()) {
|
} else if (file.isDirectory()) {
|
||||||
dirSize += file.length();
|
dirSize += file.length()
|
||||||
dirSize += getDirSize(file); // 递归调用继续统计
|
dirSize += getDirSize(file) // 递归调用继续统计
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dirSize;
|
return dirSize
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定文件大小
|
* 获取指定文件大小
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("resource")
|
@Throws(Exception::class)
|
||||||
public static long getFileSize(File file) throws Exception {
|
fun getFileSize(file: File): Long {
|
||||||
long size = 0;
|
var size: Long = 0
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
FileInputStream fis = null;
|
var fis: FileInputStream? = null
|
||||||
fis = new FileInputStream(file);
|
fis = FileInputStream(file)
|
||||||
size = fis.available();
|
size = fis.available().toLong()
|
||||||
} else {
|
} else {
|
||||||
|
Log.e("获取文件大小", "文件不存在!")
|
||||||
Log.e("获取文件大小", "文件不存在!");
|
|
||||||
}
|
}
|
||||||
return size;
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定文件夹
|
* 获取指定文件夹
|
||||||
*/
|
*/
|
||||||
public static long getFileSizes(File f) throws Exception {
|
@Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
|
||||||
long size = 0;
|
@Throws(Exception::class)
|
||||||
File[] flist = f.listFiles();
|
fun getFileSizes(f: File): Long {
|
||||||
for (int i = 0; i < Objects.requireNonNull(flist).length; i++) {
|
var size: Long = 0
|
||||||
if (flist[i].isDirectory()) {
|
val fileList = f.listFiles()
|
||||||
size = size + getFileSizes(flist[i]);
|
for (i in Objects.requireNonNull(fileList).indices) {
|
||||||
|
size += if (fileList[i].isDirectory()) {
|
||||||
|
getFileSizes(fileList[i])
|
||||||
} else {
|
} else {
|
||||||
size = size + getFileSize(flist[i]);
|
getFileSize(fileList[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return size;
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换文件大小
|
* 转换文件大小
|
||||||
*/
|
*/
|
||||||
public static String toFileSize(long fileS) {
|
fun toFileSize(fileS: Long): String {
|
||||||
DecimalFormat df = new DecimalFormat("#.00");
|
val df = DecimalFormat("#.00")
|
||||||
String fileSizeString;
|
val fileSizeString: String
|
||||||
String wrongSize = "0M";
|
val wrongSize = "0M"
|
||||||
if (fileS == 0) {
|
if (fileS == 0L) {
|
||||||
return wrongSize;
|
return wrongSize
|
||||||
}
|
}
|
||||||
if (fileS < 1024) {
|
if (fileS < 1024) {
|
||||||
fileSizeString = df.format((double) fileS) + "B";
|
fileSizeString = df.format(fileS.toDouble()) + "B"
|
||||||
} else if (fileS < 1048576) {
|
} else if (fileS < 1048576) {
|
||||||
fileSizeString = df.format((double) fileS / 1024) + "K";
|
fileSizeString = df.format(fileS.toDouble() / 1024) + "K"
|
||||||
} else if (fileS < 1073741824) {
|
} else if (fileS < 1073741824) {
|
||||||
fileSizeString = df.format((double) fileS / 1048576) + "M";
|
fileSizeString = df.format(fileS.toDouble() / 1048576) + "M"
|
||||||
} else {
|
} else {
|
||||||
fileSizeString = df.format((double) fileS / 1073741824) + "G";
|
fileSizeString = df.format(fileS.toDouble() / 1073741824) + "G"
|
||||||
}
|
}
|
||||||
return fileSizeString;
|
return fileSizeString
|
||||||
}
|
|
||||||
|
|
||||||
//判断文件是否存在
|
|
||||||
public boolean fileIsExists(File strFile) {
|
|
||||||
try {
|
|
||||||
if (!strFile.exists()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
//判断文件是否存在
|
|
||||||
public boolean fileIsExists(String strFile) {
|
|
||||||
try {
|
|
||||||
File f = new File(strFile);
|
|
||||||
if (!f.exists()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val externalStorageSpace: Long
|
||||||
//外部存储空间
|
//外部存储空间
|
||||||
public static long getExternalStorageSpace() {
|
get() {
|
||||||
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
|
||||||
StatFs externalStatFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
|
val externalStatFs = StatFs(
|
||||||
long externalBlockSize = externalStatFs.getBlockSizeLong();
|
Environment.getExternalStorageDirectory().absolutePath
|
||||||
long externalTotalSize = externalStatFs.getBlockCountLong() * externalBlockSize;
|
)
|
||||||
long externalAvailableSize = externalStatFs.getAvailableBlocksLong() * externalBlockSize;
|
val externalBlockSize = externalStatFs.blockSizeLong
|
||||||
Log.d("FileUtils", "当前外部空间总大小----" + externalTotalSize);
|
val externalTotalSize =
|
||||||
Log.d("FileUtils", "当前外部空间可用大小----" + externalAvailableSize);
|
externalStatFs.blockCountLong * externalBlockSize
|
||||||
return externalAvailableSize;
|
val externalAvailableSize =
|
||||||
|
externalStatFs.availableBlocksLong * externalBlockSize
|
||||||
|
Log.d("FileUtils", "当前外部空间总大小----$externalTotalSize")
|
||||||
|
Log.d(
|
||||||
|
"FileUtils",
|
||||||
|
"当前外部空间可用大小----$externalAvailableSize"
|
||||||
|
)
|
||||||
|
return externalAvailableSize
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 打开图库
|
|
||||||
*/
|
|
||||||
public void openGallery(Context context) {
|
|
||||||
try {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
intent.addCategory(Intent.CATEGORY_APP_GALLERY);
|
|
||||||
context.startActivity(intent);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -34,13 +34,15 @@ import okhttp3.Request
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.jvm.java
|
import kotlin.jvm.java
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UniApp工具类
|
||||||
|
* 小程序运行路径:/data/user/0/com.img.rabbit/files/apps/(一般/data/data/com.img.rabbit/files/apps/)
|
||||||
|
*/
|
||||||
object UniAppUtils {
|
object UniAppUtils {
|
||||||
private const val TAG = "UniAppUtils"
|
private const val TAG = "UniAppUtils"
|
||||||
/**
|
/**
|
||||||
* 所有运行的UniMp小程序实体
|
* 所有运行的UniMp小程序实体
|
||||||
*/
|
*/
|
||||||
// val uniMpPair = mutableMapOf<String?, IUniMP?>()
|
|
||||||
private val _uniMpFlow = MutableStateFlow<Map<String?, IUniMP?>>(emptyMap())
|
private val _uniMpFlow = MutableStateFlow<Map<String?, IUniMP?>>(emptyMap())
|
||||||
val uniMpFlow = _uniMpFlow.asStateFlow()
|
val uniMpFlow = _uniMpFlow.asStateFlow()
|
||||||
fun updateUniMp(id: String?, mp: IUniMP?) {
|
fun updateUniMp(id: String?, mp: IUniMP?) {
|
||||||
|
|
@ -60,6 +62,11 @@ object UniAppUtils {
|
||||||
return String.format("%s.wgt", uniMpId)
|
return String.format("%s.wgt", uniMpId)
|
||||||
//return String.format("%s.zip", uniMpId)
|
//return String.format("%s.zip", uniMpId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getWgtFile(uniMpId: String): File{
|
||||||
|
val wgtName = getWgtName(uniMpId)
|
||||||
|
return File(FileUtils.instance?.cacheUniAppDir?.absolutePath?:"", wgtName)
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
*获取当前前台运行的UniMp小程序实体
|
*获取当前前台运行的UniMp小程序实体
|
||||||
*/
|
*/
|
||||||
|
|
@ -85,16 +92,14 @@ object UniAppUtils {
|
||||||
* 是否需要下载(强制更新或者不存在wgt文件)
|
* 是否需要下载(强制更新或者不存在wgt文件)
|
||||||
*/
|
*/
|
||||||
fun isDownloadUniMp(uniVersion: UniVersionEntity): Boolean{
|
fun isDownloadUniMp(uniVersion: UniVersionEntity): Boolean{
|
||||||
val wgtName = getWgtName(uniVersion.unimp_id)
|
val wgtFile = getWgtFile(uniVersion.unimp_id)
|
||||||
val wgtFile = File(FileUtils.getInstance().cacheUniAppDir.absolutePath, wgtName)
|
return isUpdateForce(uniVersion) || !(FileUtils.instance?.fileIsExists(wgtFile) == true && FileUtils.getFileSize(wgtFile) > 0)
|
||||||
return isUpdateForce(uniVersion) || !(FileUtils.getInstance().fileIsExists(wgtFile) && FileUtils.getFileSize(wgtFile) > 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun wgtIsExists(uniMpId: String): Boolean{
|
fun wgtIsExists(uniMpId: String): Boolean{
|
||||||
val wgtName = getWgtName(uniMpId)
|
val wgtFile = getWgtFile(uniMpId)
|
||||||
val wgtFile = File(FileUtils.getInstance().cacheUniAppDir.absolutePath, wgtName)
|
|
||||||
//判断wgt是否下载
|
//判断wgt是否下载
|
||||||
return FileUtils.getInstance().fileIsExists(wgtFile) && FileUtils.getFileSize(wgtFile) > 0
|
return FileUtils.instance?.fileIsExists(wgtFile) == true && FileUtils.getFileSize(wgtFile) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isRelease(uniMpId: String): Boolean{
|
private fun isRelease(uniMpId: String): Boolean{
|
||||||
|
|
@ -215,8 +220,7 @@ object UniAppUtils {
|
||||||
val appBasePath = DCUniMPSDK.getInstance().getAppBasePath(applicationContext)
|
val appBasePath = DCUniMPSDK.getInstance().getAppBasePath(applicationContext)
|
||||||
val deleteSuccess = File(appBasePath, uniMpId).deleteRecursively()
|
val deleteSuccess = File(appBasePath, uniMpId).deleteRecursively()
|
||||||
if(deleteSuccess){
|
if(deleteSuccess){
|
||||||
val wgtName = getWgtName(uniMpId)
|
val wgtFile = getWgtFile(uniMpId)
|
||||||
val wgtFile = File(FileUtils.getInstance().cacheUniAppDir.absolutePath, wgtName)
|
|
||||||
val uniMPReleaseConfiguration = UniMPReleaseConfiguration().apply {
|
val uniMPReleaseConfiguration = UniMPReleaseConfiguration().apply {
|
||||||
wgtPath = wgtFile.path
|
wgtPath = wgtFile.path
|
||||||
password = PreferenceUtil.getUserConfig()?.config?.wgtPassword//"6462"////没有密码可以不写
|
password = PreferenceUtil.getUserConfig()?.config?.wgtPassword//"6462"////没有密码可以不写
|
||||||
|
|
@ -251,9 +255,7 @@ object UniAppUtils {
|
||||||
* 下载wgt文件
|
* 下载wgt文件
|
||||||
*/
|
*/
|
||||||
fun downloadWGT(context: Context,scope: CoroutineScope, uniVersion: UniVersionEntity, reportViewModel: ReportViewModel = ReportViewModel(), onProgress:(state: UniMpUpdate, filePath: String?, progress: Float?) -> Unit) {
|
fun downloadWGT(context: Context,scope: CoroutineScope, uniVersion: UniVersionEntity, reportViewModel: ReportViewModel = ReportViewModel(), onProgress:(state: UniMpUpdate, filePath: String?, progress: Float?) -> Unit) {
|
||||||
val uniMpId = uniVersion.unimp_id
|
val wgtFile = getWgtFile(uniVersion.unimp_id)
|
||||||
val wgtName = getWgtName(uniMpId)
|
|
||||||
val wgtFile = File(FileUtils.getInstance().cacheUniAppDir.absolutePath, wgtName)
|
|
||||||
onProgress(UniMpUpdate.DOWNLOAD_START, wgtFile.path, 0f)
|
onProgress(UniMpUpdate.DOWNLOAD_START, wgtFile.path, 0f)
|
||||||
|
|
||||||
downloadUniMp(scope, uniVersion){uniState, filePath, progress ->
|
downloadUniMp(scope, uniVersion){uniState, filePath, progress ->
|
||||||
|
|
@ -304,7 +306,7 @@ object UniAppUtils {
|
||||||
|
|
||||||
val uniMpId = uniVersion.unimp_id
|
val uniMpId = uniVersion.unimp_id
|
||||||
val wgtName = getWgtName(uniMpId)
|
val wgtName = getWgtName(uniMpId)
|
||||||
val path = FileUtils.getInstance().cacheUniAppDir.absolutePath
|
val path = FileUtils.instance?.cacheUniAppDir?.absolutePath?:""
|
||||||
//先删除旧文件
|
//先删除旧文件
|
||||||
val oldFile = File(path, wgtName)
|
val oldFile = File(path, wgtName)
|
||||||
if(oldFile.exists()){
|
if(oldFile.exists()){
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ object UpdateUtils {
|
||||||
|
|
||||||
fun install(context: Context, apkFilePath: String) {
|
fun install(context: Context, apkFilePath: String) {
|
||||||
try {
|
try {
|
||||||
val apkFile = File(FileUtils.getInstance().cacheDownLoadDir, AppUpdate.getFileNameFromUrl(apkFilePath))
|
val apkFile = File(FileUtils.instance?.cacheDownLoadDir, AppUpdate.getFileNameFromUrl(apkFilePath))
|
||||||
if (!apkFile.exists()) {
|
if (!apkFile.exists()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ public final class ChannelReader {
|
||||||
/**
|
/**
|
||||||
* 读取注入的内容
|
* 读取注入的内容
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("CallToPrintStackTrace")
|
||||||
public static String get(@NonNull Context context) {
|
public static String get(@NonNull Context context) {
|
||||||
String apkPath = getApkPath(context);
|
String apkPath = getApkPath(context);
|
||||||
String raw = TextUtils.isEmpty(apkPath) ? null : getRaw(new File(apkPath));
|
String raw = TextUtils.isEmpty(apkPath) ? null : getRaw(new File(apkPath));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue