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)
}
}
}
}
}
......
......@@ -11,7 +11,6 @@ import com.mints.cleaner.adapter.multiClean.MultiCleanAdapter
import com.mints.cleaner.databinding.ActivityMultiCleanBinding
import com.mints.cleaner.model.bean.CleanHeaderTitle
import com.mints.cleaner.model.bean.FileBean
import com.mints.cleaner.service.ScreenService
import com.mints.cleaner.util.FileUtils
import com.mints.cleaner.util.FormatUtils
import com.mints.cleaner.util.IntentUtils
......@@ -20,13 +19,17 @@ import kotlinx.android.synthetic.main.activity_album_clean.btn_clean
import kotlinx.android.synthetic.main.activity_multi_clean.*
import java.io.File
import java.util.*
import kotlin.concurrent.schedule
/**
* 视频、音频、压缩包、安装包、大文件清理
*/
class MultiCleanActivity : BaseVMActivity(), MultiCleanAdapter.OnImageSelectListener,
MultiCleanAdapter.OnItemClickListener {
private val binding by binding<ActivityMultiCleanBinding>(R.layout.activity_multi_clean)
private val dataList = mutableListOf<FileBean>()
private var dataList = mutableListOf<FileBean>()
private val multiAdapter: MultiCleanAdapter by lazy {
MultiCleanAdapter(
......@@ -35,41 +38,179 @@ class MultiCleanActivity : BaseVMActivity(), MultiCleanAdapter.OnImageSelectList
)
}
companion object {
const val MULTI_TYPE = "VIDEO"
// 视频清理
const val MULTI_TYPE_VIDEO = "VIDEO"
// 音频清理
const val MULTI_TYPE_AUDIO = "AUDIO"
// 压缩包清理
const val MULTI_TYPE_ZIP = "ZIP"
// 安装包清理
const val MULTI_TYPE_APK = "APK"
// 大文件清理
const val MULTI_TYPE_BIGFILE = "OTHERS"
}
private val mMultiType: String by lazy { intent.getStringExtra(MULTI_TYPE) }
// 是否全选
private var flag = false
private var sIsScrolling = false
override fun initView() {
binding.run {
title = CleanHeaderTitle(
getString(R.string.video_clean),
R.mipmap.ic_activity_arrow,
{
onBackPressed()
},
View.VISIBLE,
getString(R.string.full_choice),
{
if (!flag) {
multiAdapter.fullSelectImage()
title?.rightInfo = getString(R.string.cancel_full_choice)
title?.title = "已选中" + multiAdapter.getSelectImageList().size + "项"
} else {
multiAdapter.cancelFullSelectImage()
title?.rightInfo = getString(R.string.full_choice)
title?.title = getString(R.string.album_clean)
}
flag = !flag
},
R.color.theme
)
title = when (mMultiType) {
MULTI_TYPE_VIDEO -> {
CleanHeaderTitle(
getString(R.string.video_clean),
R.mipmap.ic_activity_arrow,
{
onBackPressed()
},
View.VISIBLE,
getString(R.string.full_choice),
{
if (!flag) {
multiAdapter.fullSelectImage()
title?.rightInfo = getString(R.string.cancel_full_choice)
title?.title = "已选中" + multiAdapter.getSelectImageList().size + "项"
} else {
multiAdapter.cancelFullSelectImage()
title?.rightInfo = getString(R.string.full_choice)
title?.title = getString(R.string.album_clean)
}
flag = !flag
},
R.color.theme
)
}
MULTI_TYPE_AUDIO -> {
CleanHeaderTitle(
getString(R.string.music_clean),
R.mipmap.ic_activity_arrow,
{
onBackPressed()
},
View.VISIBLE,
getString(R.string.full_choice),
{
if (!flag) {
multiAdapter.fullSelectImage()
title?.rightInfo = getString(R.string.cancel_full_choice)
title?.title = "已选中" + multiAdapter.getSelectImageList().size + "项"
} else {
multiAdapter.cancelFullSelectImage()
title?.rightInfo = getString(R.string.full_choice)
title?.title = getString(R.string.album_clean)
}
flag = !flag
},
R.color.theme
)
}
MULTI_TYPE_ZIP -> {
CleanHeaderTitle(
getString(R.string.zip_clean),
R.mipmap.ic_activity_arrow,
{
onBackPressed()
},
View.VISIBLE,
getString(R.string.full_choice),
{
if (!flag) {
multiAdapter.fullSelectImage()
title?.rightInfo = getString(R.string.cancel_full_choice)
title?.title = "已选中" + multiAdapter.getSelectImageList().size + "项"
} else {
multiAdapter.cancelFullSelectImage()
title?.rightInfo = getString(R.string.full_choice)
title?.title = getString(R.string.album_clean)
}
flag = !flag
},
R.color.theme
)
}
MULTI_TYPE_APK -> {
CleanHeaderTitle(
getString(R.string.apk_clean),
R.mipmap.ic_activity_arrow,
{
onBackPressed()
},
View.VISIBLE,
getString(R.string.full_choice),
{
if (!flag) {
multiAdapter.fullSelectImage()
title?.rightInfo = getString(R.string.cancel_full_choice)
title?.title = "已选中" + multiAdapter.getSelectImageList().size + "项"
} else {
multiAdapter.cancelFullSelectImage()
title?.rightInfo = getString(R.string.full_choice)
title?.title = getString(R.string.album_clean)
}
flag = !flag
},
R.color.theme
)
}
MULTI_TYPE_BIGFILE -> {
CleanHeaderTitle(
getString(R.string.bigFile_clean),
R.mipmap.ic_activity_arrow,
{
onBackPressed()
},
View.VISIBLE,
getString(R.string.full_choice),
{
if (!flag) {
multiAdapter.fullSelectImage()
title?.rightInfo = getString(R.string.cancel_full_choice)
title?.title = "已选中" + multiAdapter.getSelectImageList().size + "项"
} else {
multiAdapter.cancelFullSelectImage()
title?.rightInfo = getString(R.string.full_choice)
title?.title = getString(R.string.album_clean)
}
flag = !flag
},
R.color.theme
)
}
else -> {
CleanHeaderTitle(
getString(R.string.unknown),
R.mipmap.ic_activity_arrow,
{
onBackPressed()
},
View.GONE,
"",
{},
R.color.theme
)
}
}
}
clv_loading.showLoading()
initRecyclerView()
btn_clean.setOnClickListener {
val selectImageList = multiAdapter.getSelectImageList()
if (selectImageList.isEmpty()) return@setOnClickListener
......@@ -100,7 +241,7 @@ class MultiCleanActivity : BaseVMActivity(), MultiCleanAdapter.OnImageSelectList
sIsScrolling = true
Glide.with(this@MultiCleanActivity).pauseRequests()
} else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
if (sIsScrolling === true) {
if (sIsScrolling) {
Glide.with(this@MultiCleanActivity).resumeRequests()
}
sIsScrolling = false
......@@ -112,67 +253,138 @@ class MultiCleanActivity : BaseVMActivity(), MultiCleanAdapter.OnImageSelectList
}
override fun initData() {
MultiCleanModel.loadVideoForSDCard(this, object : MultiCleanModel.DataCallback {
override fun onSuccess(files: ArrayList<FileBean>?) {
files?.let {
dataList.addAll(it)
}
when (mMultiType) {
MULTI_TYPE_VIDEO -> {
MultiCleanModel.loadVideoForSDCard(this, object : MultiCleanModel.DataCallback {
override fun onSuccess(files: ArrayList<FileBean>?) {
files?.let {
dataList.addAll(it)
}
// Timer().schedule(1000) {
// runOnUiThread {
// multiAdapter.notifyDataSetChanged()
// }
// }
Timer().schedule(1000) {
runOnUiThread {
multiAdapter.notifyDataSetChanged()
}
}
runOnUiThread {
multiAdapter.notifyDataSetChanged()
}
runOnUiThread {
multiAdapter.notifyDataSetChanged()
}
}
})
}
MULTI_TYPE_AUDIO -> {
MultiCleanModel.loadMusicForSDCard(this, object : MultiCleanModel.DataCallback {
override fun onSuccess(files: ArrayList<FileBean>?) {
files?.let {
dataList.addAll(it)
}
runOnUiThread {
multiAdapter.notifyDataSetChanged()
}
}
})
}
MULTI_TYPE_APK -> {
FileScanModel.getSuffixFiles(object : FileScanModel.DataCallback {
override fun onSuccess(filePaths: ArrayList<String>?) {
filePaths?.let { it ->
it.forEach {
dataList.add(ApkUtils.getApkInfo(this@MultiCleanActivity, it))
}
dataList.sortWith(Comparator { file, t1 ->
when {
file.size < t1.size -> {
1
}
file.size > t1.size -> {
-1
}
else -> {
0
}
}
})
}
runOnUiThread {
multiAdapter.notifyDataSetChanged()
}
}
}, "apk")
}
MULTI_TYPE_ZIP -> {
// 压缩包数据
FileScanModel.getSuffixFiles(object : FileScanModel.DataCallback {
override fun onSuccess(filePaths: ArrayList<String>?) {
filePaths?.let { it ->
dataList.clear()
it.forEach {
dataList.add(ApkUtils.getZipInfo(it))
}
dataList.sortWith(Comparator { file, t1 ->
when {
file.size < t1.size -> {
1
}
file.size > t1.size -> {
-1
}
else -> {
0
}
}
})
}
runOnUiThread {
multiAdapter.notifyDataSetChanged()
}
}
}, "7z", "zip")
}
MULTI_TYPE_BIGFILE -> {
// 大文件数据
FileScanModel.getBigFiles(object : FileScanModel.DataCallback {
override fun onSuccess(filePaths: ArrayList<String>?) {
filePaths?.let { it ->
dataList.clear()
it.forEach {
dataList.add(ApkUtils.getBigFileInfo(this@MultiCleanActivity, it))
}
dataList.sortWith(Comparator { file, t1 ->
when {
file.size < t1.size -> {
1
}
file.size > t1.size -> {
-1
}
else -> {
0
}
}
})
}
runOnUiThread {
multiAdapter.notifyDataSetChanged()
}
})
// MultiCleanModel.loadMusicForSDCard(this, object : MultiCleanModel.DataCallback {
// override fun onSuccess(files: ArrayList<FileBean>?) {
// files?.let {
// dataList.addAll(it)
// }
//
// runOnUiThread {
// multiAdapter.notifyDataSetChanged()
// }
// }
//
// })
// FileScanModel.getSuffixFiles(object : FileScanModel.DataCallback {
// override fun onSuccess(filePaths: ArrayList<String>?) {
// filePaths?.let { it ->
// it.forEach {
// dataList.add(ApkUtils.getApkInfo(this@MultiCleanActivity, it))
// }
//
// dataList.sortWith(Comparator { file, t1 ->
// when {
// file.size < t1.size -> {
// 1
// }
// file.size > t1.size -> {
// -1
// }
// else -> {
// 0
// }
// }
// })
// }
//
// runOnUiThread {
// multiAdapter.notifyDataSetChanged()
// }
//
// }
// }, "apk")
}
})
}
else -> {
}
}
}
......@@ -193,11 +405,81 @@ class MultiCleanActivity : BaseVMActivity(), MultiCleanAdapter.OnImageSelectList
}
override fun onItemClick(fileBean: FileBean, position: Int) {
val videoFileIntent = IntentUtils.getVideoFileIntent(this, fileBean.path)
startActivity(videoFileIntent)
// 根据不同类型跳转系统自带的文件打开器
var multiIntent: Intent?
when (mMultiType) {
MULTI_TYPE_AUDIO -> {
multiIntent = IntentUtils.getAudioFileIntent(this, fileBean.path)
startActivity(multiIntent)
}
MULTI_TYPE_VIDEO -> {
multiIntent = IntentUtils.getVideoFileIntent(this, fileBean.path)
startActivity(multiIntent)
}
MULTI_TYPE_ZIP -> {
multiIntent = IntentUtils.getZipFileIntent(this, fileBean.path)
startActivity(multiIntent)
}
MULTI_TYPE_APK -> {
multiIntent = IntentUtils.getApkFileIntent(this, fileBean.path)
startActivity(multiIntent)
}
else -> {
when (FileUtils.getExtensionName(fileBean.path)) {
"apk" -> {
// multiIntent = IntentUtils.getApkFileIntent(this, fileBean.path)
// startActivity(multiIntent)
}
"jpg" -> {
multiIntent = IntentUtils.getImageFileIntent(this, fileBean.path)
startActivity(multiIntent)
}
"png" -> {
multiIntent = IntentUtils.getImageFileIntent(this, fileBean.path)
startActivity(multiIntent)
}
"jpeg" -> {
multiIntent = IntentUtils.getImageFileIntent(this, fileBean.path)
startActivity(multiIntent)
}
"jpg" -> {
multiIntent = IntentUtils.getImageFileIntent(this, fileBean.path)
startActivity(multiIntent)
}
"txt" -> {
multiIntent = IntentUtils.getTextFileIntent(fileBean.path, false)
startActivity(multiIntent)
}
"mp3" -> {
multiIntent = IntentUtils.getAudioFileIntent(this, fileBean.path)
startActivity(multiIntent)
}
"mp4" -> {
multiIntent = IntentUtils.getVideoFileIntent(this, fileBean.path)
startActivity(multiIntent)
}
"rar" -> {
multiIntent = IntentUtils.getZipFileIntent(this, fileBean.path)
startActivity(multiIntent)
}
"zip" -> {
multiIntent = IntentUtils.getZipFileIntent(this, fileBean.path)
startActivity(multiIntent)
}
"7z" -> {
multiIntent = IntentUtils.getZipFileIntent(this, fileBean.path)
startActivity(multiIntent)
}
else -> {
}
}
}
}
}
// 删除后更新手机
// 删除后更新手机资源文件
private fun updateFile(imgPath: String?) {
val intent = Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE)
intent.data = Uri.fromFile(File(imgPath))
......
......@@ -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