Commit 622a8d13 authored by jyx's avatar jyx

压缩包、安装包清理

parent 3435ddb3
......@@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<application
android:name=".App"
......@@ -12,10 +13,11 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ui.setting.SettingActivity"></activity>
<activity android:name=".ui.albumClean.AlbumCleanActivity" />
......@@ -23,15 +25,9 @@
android:name=".ui.multiClean.MultiCleanActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:excludeFromRecents="true"
android:noHistory="true"
android:launchMode="singleTop"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
android:noHistory="true"
android:screenOrientation="portrait"></activity>
<!-- 屏幕适配 -->
<meta-data
......@@ -46,6 +42,16 @@
android:launchMode="singleTop"
android:theme="@style/CustomerTransparentTheme" />
<activity
android:name=".ui.NavigationActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
......@@ -64,6 +70,7 @@
<service
android:name=".service.keep.KeepLiveManager$GrayInnerService"
android:process=":screen" />
<activity
android:name=".service.keep.PixelActivity"
android:excludeFromRecents="true"
......
......@@ -33,7 +33,7 @@ class AlbumCleanAdapter(layoutResId: Int, data: List<Image>) :
.centerCrop()
.placeholder(drawable)
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
)
.into(this)
......
package com.mints.cleaner.adapter.home
import android.widget.GridView
import android.widget.ImageView
import android.widget.SimpleAdapter
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.mints.cleaner.R
import com.mints.cleaner.util.LogUtil
class HomeAdapter : BaseMultiItemQuickAdapter<HomeMultiItem, BaseViewHolder> {
......@@ -14,11 +17,10 @@ class HomeAdapter : BaseMultiItemQuickAdapter<HomeMultiItem, BaseViewHolder> {
addItemType(HomeMultiItem.ITEM_BOTTOM, R.layout.item_clean_bottom)
}
override fun convert(helper: BaseViewHolder, item: HomeMultiItem?) {
override fun convert(helper: BaseViewHolder, item: HomeMultiItem) {
when (helper.itemViewType) {
HomeMultiItem.ITEM_TOP -> {
helper.addOnClickListener(R.id.btn_clean)
}
HomeMultiItem.ITEM_MID -> {
val gridView = helper.getView<GridView>(R.id.gv_clean)
......@@ -37,7 +39,11 @@ class HomeAdapter : BaseMultiItemQuickAdapter<HomeMultiItem, BaseViewHolder> {
}
}
HomeMultiItem.ITEM_BOTTOM -> {
item.itemData?.let {
helper.setText(R.id.tv_title, it.title)
helper.setText(R.id.tv_info, it.info)
helper.getView<ImageView>(R.id.iv).setImageResource(it.image)
}
}
}
}
......
......@@ -5,13 +5,19 @@ import com.chad.library.adapter.base.entity.MultiItemEntity
class HomeMultiItem : MultiItemEntity {
private var itemType: Int = 0
lateinit var itemData: BottomData
var gvDataList: MutableList<Map<String, Any>> = ArrayList()
lateinit var gvDataList: MutableList<Map<String, Any>>
constructor(itemType: Int) {
this.itemType = itemType
}
constructor(itemType: Int, itemData: BottomData) {
this.itemType = itemType
this.itemData = itemData
}
constructor(itemType: Int, gvDataList: MutableList<Map<String, Any>>) {
this.itemType = itemType
this.gvDataList = gvDataList
......@@ -31,4 +37,6 @@ class HomeMultiItem : MultiItemEntity {
override fun getItemType(): Int {
return itemType
}
data class BottomData(val title: String, val info: String, val image: Int)
}
\ No newline at end of file
......@@ -4,7 +4,6 @@ data class FileBean(
val image: Any,
val path: String,
val time: String,
val modifyTime: Long,
val name: String,
val size: Long
)
\ No newline at end of file
......@@ -18,6 +18,15 @@ class MainRepository(val service: ApiService) : BaseRepository() {
R.mipmap.ic_launcher
)
private val itemBottomTitle = arrayOf("文件清理", "安装包清理", "音乐清理", "压缩包清理")
private val itemBottomInfo = arrayOf("释放更多空间", "清理无用的安装包", "清理不喜欢的音乐", "清理无用的压缩包")
private val itemBottomImage = arrayOf(
R.mipmap.ic_launcher,
R.mipmap.ic_launcher,
R.mipmap.ic_launcher,
R.mipmap.ic_launcher
)
private var multiItemList: ArrayList<HomeMultiItem> = arrayListOf()
private val gvDataList: MutableList<Map<String, Any>> = ArrayList()
......@@ -32,13 +41,22 @@ class MainRepository(val service: ApiService) : BaseRepository() {
multiItemList = arrayListOf(
HomeMultiItem(HomeMultiItem.ITEM_TOP),
HomeMultiItem(HomeMultiItem.ITEM_MID, gvDataList),
HomeMultiItem(HomeMultiItem.ITEM_BOTTOM),
HomeMultiItem(HomeMultiItem.ITEM_BOTTOM),
HomeMultiItem(HomeMultiItem.ITEM_BOTTOM),
HomeMultiItem(HomeMultiItem.ITEM_BOTTOM)
HomeMultiItem(HomeMultiItem.ITEM_MID, gvDataList)
)
for (i in itemBottomTitle.indices) {
multiItemList.add(
HomeMultiItem(
HomeMultiItem.ITEM_BOTTOM,
HomeMultiItem.BottomData(
itemBottomTitle[i],
itemBottomInfo[i],
itemBottomImage[i]
)
)
)
}
return multiItemList
}
......
......@@ -7,8 +7,12 @@ import com.mints.cleaner.R
import com.mints.cleaner.adapter.home.HomeAdapter
import com.mints.cleaner.databinding.FragmentCleanBinding
import com.mints.cleaner.model.bean.HeaderTitle
import com.mints.cleaner.ui.PreviewActivity
import com.mints.cleaner.ui.albumClean.AlbumCleanActivity
import com.mints.cleaner.ui.main.MainViewModel
import com.mints.cleaner.ui.multiClean.MultiCleanActivity
import com.mints.core.base.BaseVMFragment
import com.mints.ktx.ext.startKtxActivity
import com.mints.ktx.ext.toast
import org.koin.androidx.viewmodel.ext.android.viewModel
......@@ -53,19 +57,19 @@ class HomeFragment : BaseVMFragment<FragmentCleanBinding>(R.layout.fragment_clea
when (position) {
2 -> {
// 文件清理
activity?.let { toast(it, "文件清理", Toast.LENGTH_SHORT) }
}
3 -> {
// 音乐清理
activity?.let { toast(it, "音乐清理", Toast.LENGTH_SHORT) }
// 安装包清理
startKtxActivity<MultiCleanActivity>(value = MultiCleanActivity.MULTI_TYPE to MultiCleanActivity.MULTI_TYPE_APK)
}
4 -> {
// 安装包清理
activity?.let { toast(it, "安装包清理", Toast.LENGTH_SHORT) }
// 音乐清理
startKtxActivity<MultiCleanActivity>(value = MultiCleanActivity.MULTI_TYPE_AUDIO to MultiCleanActivity.MULTI_TYPE_AUDIO)
}
5 -> {
// 压缩包清理
activity?.let { toast(it, "压缩包清理", Toast.LENGTH_SHORT) }
startKtxActivity<MultiCleanActivity>(value = MultiCleanActivity.MULTI_TYPE_ZIP to MultiCleanActivity.MULTI_TYPE_ZIP)
}
}
}
......@@ -75,22 +79,24 @@ class HomeFragment : BaseVMFragment<FragmentCleanBinding>(R.layout.fragment_clea
override fun onGridViewItemClick(position: Int) {
when (position) {
0 -> {
activity?.let { toast(it, "0", Toast.LENGTH_SHORT) }
// 手机加速
}
1 -> {
activity?.let { toast(it, "1", Toast.LENGTH_SHORT) }
// 微信清理
}
2 -> {
activity?.let { toast(it, "2", Toast.LENGTH_SHORT) }
// QQ清理
}
3 -> {
activity?.let { toast(it, "3", Toast.LENGTH_SHORT) }
// 软件管理
}
4 -> {
activity?.let { toast(it, "4", Toast.LENGTH_SHORT) }
// 相册清理
startKtxActivity<AlbumCleanActivity>()
}
5 -> {
activity?.let { toast(it, "5", Toast.LENGTH_SHORT) }
// 视频清理
startKtxActivity<MultiCleanActivity>(value = MultiCleanActivity.MULTI_TYPE_VIDEO to MultiCleanActivity.MULTI_TYPE_VIDEO)
}
}
......
......@@ -3,16 +3,19 @@ package com.mints.cleaner.ui.multiClean
import android.content.Context
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.media.MediaPlayer
import com.mints.cleaner.R
import com.mints.cleaner.model.bean.FileBean
import com.mints.cleaner.util.FileUtils
import com.mints.cleaner.util.FormatUtils
import com.mints.cleaner.util.LogUtil
import java.io.File
object ApkUtils {
/**
* 根据apk存储路径获取apk图标
* 根据apk存储路径获取apk信息
*/
fun getApkInfo(
context: Context, apkPath: String
......@@ -41,7 +44,93 @@ object ApkUtils {
val size = apkFile.length()
val modifiedTime = FormatUtils.formatTime(apkFile.lastModified())
return FileBean(apkIcon, apkPath, modifiedTime, 0L, apkLabel, size)
return FileBean(apkIcon, apkPath, modifiedTime, apkLabel, size)
}
/**
* 获取压缩包信息
*/
fun getZipInfo(
filePath: String
): FileBean {
val file = File(filePath)
val name = file.name
val modifiedTime = FormatUtils.formatTime(file.lastModified())
val size = file.length()
return FileBean("", filePath, modifiedTime, name, size)
}
/**
* 获取大文件信息
*/
fun getBigFileInfo(context: Context, filePath: String): FileBean {
val file = File(filePath)
val name = file.name
var modifiedTime: String
val extensionName = FileUtils.getExtensionName(name)
val size = file.length()
val image: String
when (extensionName) {
"apk" -> {
return getApkInfo(context, filePath)
}
"mp3" -> {
val mediaPlayer = MediaPlayer()
mediaPlayer.setDataSource(filePath)
mediaPlayer.prepare()
modifiedTime = FormatUtils.formatDuration(mediaPlayer.duration.toLong())
image = filePath
}
"mp4" -> {
val mediaPlayer = MediaPlayer()
mediaPlayer.setDataSource(filePath)
mediaPlayer.prepare()
modifiedTime = FormatUtils.formatDuration(mediaPlayer.duration.toLong())
image = filePath
}
"txt" -> {
modifiedTime = FormatUtils.formatTime(file.lastModified())
image = filePath
}
"jpeg" -> {
modifiedTime = FormatUtils.formatTime(file.lastModified())
image = filePath
}
"jpg" -> {
modifiedTime = FormatUtils.formatTime(file.lastModified())
image = filePath
}
"png" -> {
modifiedTime = FormatUtils.formatTime(file.lastModified())
image = filePath
}
"gif" -> {
modifiedTime = FormatUtils.formatTime(file.lastModified())
image = filePath
}
"zip" -> {
modifiedTime = FormatUtils.formatTime(file.lastModified())
image = ""
}
"rar" -> {
modifiedTime = FormatUtils.formatTime(file.lastModified())
image = ""
}
"7z" -> {
modifiedTime = FormatUtils.formatTime(file.lastModified())
image = ""
}
else -> {
modifiedTime = FormatUtils.formatTime(file.lastModified())
image = ""
}
}
return FileBean(image, filePath, modifiedTime, name, size)
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import java.util.*
object FileScanModel {
private val mEligibleFiles: ArrayList<String> by lazy { arrayListOf<String>() }
private val mBigFiles: ArrayList<String> by lazy { arrayListOf<String>() }
/**
* Java文件操作 根据文件后缀获取全部文件
......@@ -29,17 +30,44 @@ object FileScanModel {
getSuffixFile(file.listFiles(), *suffixs)
} else {
val fileName = file.name
suffixs.forEach { it ->
suffixs.forEach {
if (fileName.endsWith(".$it")) {
mEligibleFiles?.let {
it.add(file.absolutePath)
}
mEligibleFiles.add(file.absolutePath)
}
}
}
}
}
}
/**
* Java文件操作 根据文件大小获取文件
*/
fun getBigFiles(callback: DataCallback) {
Thread(Runnable {
val sdDir = Environment.getExternalStorageDirectory()
val listFiles = sdDir.listFiles()
getBigFile(listFiles)
callback.onSuccess(mBigFiles)
}).start()
}
private fun getBigFile(files: Array<File>) {
files?.let {
for (file in files) {
if (file.isDirectory) {
getBigFile(file.listFiles())
} else {
// 大于10MB即视为大文件
if (file.length() > 1024 * 1024 * 10) {
mBigFiles.add(file.absolutePath)
}
}
}
}
}
......
......@@ -6,20 +6,16 @@ import android.content.pm.PackageManager
import android.database.ContentObserver
import android.database.Cursor
import android.net.Uri
import android.os.Environment
import android.provider.MediaStore
import androidx.core.content.ContextCompat
import com.mints.cleaner.model.bean.FileBean
import com.mints.cleaner.ui.albumClean.AlbumCleanModel
import com.mints.cleaner.util.FormatUtils
import com.mints.cleaner.util.UriUtils
import java.io.File
import java.lang.ref.WeakReference
import java.util.*
import kotlin.Comparator
import kotlin.collections.ArrayList
object MultiCleanModel {
/**
......@@ -203,7 +199,6 @@ object MultiCleanModel {
thumbPath,
path,
formatDuration,
modifyTime,
displayName,
size
)
......@@ -342,7 +337,6 @@ object MultiCleanModel {
thumbPath,
path,
formatDuration,
modifyTime,
displayName,
size
)
......
......@@ -6,7 +6,6 @@ import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.provider.MediaStore
import java.text.DecimalFormat
object FileUtils {
......@@ -51,4 +50,17 @@ object FileUtils {
return result
}
/*
* Java文件操作 获取文件扩展名
* */
fun getExtensionName(filename: String?): String? {
filename?.let {
val dot = filename.lastIndexOf('.')
if (dot > -1 && dot < filename.length - 1) {
return filename.substring(dot + 1)
}
}
return filename
}
}
\ No newline at end of file
......@@ -86,6 +86,28 @@ object IntentUtils {
return intent
}
//Android获取一个用于打开APK文件的intent
fun getZipFileIntent(context: Context, param: String?): Intent? {
val intent = Intent()
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.action = Intent.ACTION_VIEW
var uri: Uri?
uri = if (isAndroidN) {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
FileProvider.getUriForFile(
context,
context.packageName + ".fileprovider",
File(param)
)
} else {
Uri.fromFile(File(param))
}
intent.setDataAndType(uri, "application/x-gzip")
return intent
}
//Android获取一个用于打开VIDEO文件的intent
fun getVideoFileIntent(context: Context, param: String?): Intent? {
val intent = Intent("android.intent.action.VIEW")
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="20dp"
android:paddingTop="20dp"
android:paddingEnd="20dp">
android:layout_height="80dp">
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerVertical="true"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_toEndOf="@id/iv"
android:text="@string/file_clean"
android:textColor="@color/black"
android:textSize="18sp"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
......@@ -36,8 +36,7 @@
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/iv"
android:layout_marginTop="20dp"
android:layout_alignParentBottom="true"
android:background="@color/gray_01" />
<TextView
......@@ -45,6 +44,7 @@
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="20dp"
android:text=">"
android:textSize="30sp" />
......
......@@ -21,7 +21,9 @@
<string name="wifi">wifi</string>
<string name="my">我的</string>
<string name="unknown">未知</string>
<string name="file_clean">文件清理</string>
<string name="bigFile_clean">大文件清理</string>
<string name="music_clean">音乐清理</string>
<string name="album_clean">相册清理</string>
<string name="apk_clean">安装包清理</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment