Commit 07eb036d authored by wanglei's avatar wanglei

whatsapp管理

parent fa677fdd
...@@ -3,12 +3,9 @@ ...@@ -3,12 +3,9 @@
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" /> <!-- fcm 添加以下权限 -->
<!-- fcm 添加以下权限 -->
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
...@@ -25,7 +22,9 @@ ...@@ -25,7 +22,9 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.SmartCleaner" android:theme="@style/Theme.SmartCleaner"
tools:targetApi="31"> tools:targetApi="31">
<activity
android:name=".activity.WhatsAppMessageCleanActivity"
android:exported="false" />
<activity <activity
android:name=".activity.splash.NewSplashActivity" android:name=".activity.splash.NewSplashActivity"
android:exported="true" android:exported="true"
...@@ -51,6 +50,12 @@ ...@@ -51,6 +50,12 @@
android:launchMode="singleTop" android:launchMode="singleTop"
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".activity.WhatsAppCleanerActivity"
android:exported="false"
android:launchMode="singleTop"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity <activity
android:name=".activity.ScreenShotActivity" android:name=".activity.ScreenShotActivity"
android:exported="false" android:exported="false"
...@@ -63,7 +68,6 @@ ...@@ -63,7 +68,6 @@
android:launchMode="singleTop" android:launchMode="singleTop"
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity <activity
android:name=".activity.SettingActivity" android:name=".activity.SettingActivity"
android:exported="false" android:exported="false"
...@@ -78,7 +82,6 @@ ...@@ -78,7 +82,6 @@
android:name=".activity.PrepareScanActivity" android:name=".activity.PrepareScanActivity"
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity <activity
android:name=".activity.ScanJunkActivity" android:name=".activity.ScanJunkActivity"
android:screenOrientation="portrait" android:screenOrientation="portrait"
...@@ -102,8 +105,6 @@ ...@@ -102,8 +105,6 @@
android:launchMode="singleTop" android:launchMode="singleTop"
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity <activity
android:name=".activity.ResultActivity" android:name=".activity.ResultActivity"
android:screenOrientation="portrait" android:screenOrientation="portrait"
...@@ -129,7 +130,6 @@ ...@@ -129,7 +130,6 @@
android:name="com.google.android.gms.ads.flag.NATIVE_AD_DEBUGGER_ENABLED" android:name="com.google.android.gms.ads.flag.NATIVE_AD_DEBUGGER_ENABLED"
android:value="false" /> android:value="false" />
<activity <activity
android:name=".activity.photocompress.photo.StartCompressionPhotoActivity" android:name=".activity.photocompress.photo.StartCompressionPhotoActivity"
android:screenOrientation="portrait" android:screenOrientation="portrait"
...@@ -151,10 +151,10 @@ ...@@ -151,10 +151,10 @@
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<meta-data <meta-data
android:name="com.facebook.sdk.ApplicationId" android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" /> android:value="@string/facebook_app_id" />
<service <service
android:name=".fcm.FcmService" android:name=".fcm.FcmService"
android:exported="true"> android:exported="true">
...@@ -174,7 +174,6 @@ ...@@ -174,7 +174,6 @@
<category android:name="com.test.easy.cleanerjunk" /> <category android:name="com.test.easy.cleanerjunk" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver <receiver
android:name=".fcm.CloseNotificationReceiver" android:name=".fcm.CloseNotificationReceiver"
android:exported="false"> android:exported="false">
...@@ -182,7 +181,6 @@ ...@@ -182,7 +181,6 @@
<action android:name="CANCEL_NOTIFICATION" /> <action android:name="CANCEL_NOTIFICATION" />
</intent-filter> </intent-filter>
</receiver> </receiver>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -17,6 +17,7 @@ import com.test.easy.easycleanerjunk.view.AFunOb.JUNK_CLEANER ...@@ -17,6 +17,7 @@ import com.test.easy.easycleanerjunk.view.AFunOb.JUNK_CLEANER
import com.test.easy.easycleanerjunk.view.AFunOb.LARGE_FILE_CLEANER import com.test.easy.easycleanerjunk.view.AFunOb.LARGE_FILE_CLEANER
import com.test.easy.easycleanerjunk.view.AFunOb.PHOTO_COMPRESS import com.test.easy.easycleanerjunk.view.AFunOb.PHOTO_COMPRESS
import com.test.easy.easycleanerjunk.view.AFunOb.SIMILAR_PHOTOS import com.test.easy.easycleanerjunk.view.AFunOb.SIMILAR_PHOTOS
import com.test.easy.easycleanerjunk.view.AFunOb.WHATSAPP_CLEANER
class ResultActivity : BaseActivity<ActivityLayoutResultBinding>() { class ResultActivity : BaseActivity<ActivityLayoutResultBinding>() {
override val binding: ActivityLayoutResultBinding by lazy { override val binding: ActivityLayoutResultBinding by lazy {
...@@ -33,12 +34,15 @@ class ResultActivity : BaseActivity<ActivityLayoutResultBinding>() { ...@@ -33,12 +34,15 @@ class ResultActivity : BaseActivity<ActivityLayoutResultBinding>() {
BATTERY_INFO -> { BATTERY_INFO -> {
startActivity(Intent(this, BatteryInfoActivity::class.java)) startActivity(Intent(this, BatteryInfoActivity::class.java))
} }
JUNK_CLEANER -> { JUNK_CLEANER -> {
startActivity(Intent(this, ScanJunkActivity::class.java)) startActivity(Intent(this, ScanJunkActivity::class.java))
} }
LARGE_FILE_CLEANER -> { LARGE_FILE_CLEANER -> {
startActivity(Intent(this, LargeFileCleanActivity::class.java)) startActivity(Intent(this, LargeFileCleanActivity::class.java))
} }
SIMILAR_PHOTOS -> { SIMILAR_PHOTOS -> {
startActivity(Intent(this, RepeatPhotoActivity::class.java)) startActivity(Intent(this, RepeatPhotoActivity::class.java))
} }
...@@ -46,6 +50,7 @@ class ResultActivity : BaseActivity<ActivityLayoutResultBinding>() { ...@@ -46,6 +50,7 @@ class ResultActivity : BaseActivity<ActivityLayoutResultBinding>() {
PHOTO_COMPRESS -> { PHOTO_COMPRESS -> {
startActivity(Intent(this, StartCompressionPhotoActivity::class.java)) startActivity(Intent(this, StartCompressionPhotoActivity::class.java))
} }
} }
finish() finish()
} }
...@@ -78,9 +83,15 @@ class ResultActivity : BaseActivity<ActivityLayoutResultBinding>() { ...@@ -78,9 +83,15 @@ class ResultActivity : BaseActivity<ActivityLayoutResultBinding>() {
val size = intent.getLongExtra("size", 0L).toFormatSize(1) val size = intent.getLongExtra("size", 0L).toFormatSize(1)
binding.tvInfo.text = "Compress ${intent.getIntExtra("num", 0)} photo, $size space freed" binding.tvInfo.text = "Compress ${intent.getIntExtra("num", 0)} photo, $size space freed"
} }
BATTERY_INFO -> { BATTERY_INFO -> {
binding.tvInfo.text = "Battery scan completed." binding.tvInfo.text = "Battery scan completed."
} }
WHATSAPP_CLEANER -> {
binding.tvInfo.text = "WhatsApp clean completed."
}
else -> {} else -> {}
} }
from?.let { from?.let {
......
...@@ -134,7 +134,7 @@ class ScreenShotActivity : BaseActivity<ActivityScreenShotBinding>() { ...@@ -134,7 +134,7 @@ class ScreenShotActivity : BaseActivity<ActivityScreenShotBinding>() {
private fun getScreenshotBean(): ArrayList<ScreenshotBean> { private fun getScreenshotBean(): ArrayList<ScreenshotBean> {
val dcim = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) val dcim = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
val screenFiles = FileHelps.getDcim(dcim) val screenFiles = FileHelps.getDirFiles(dcim)
val hash = HashMap<String, HashSet<File>>() val hash = HashMap<String, HashSet<File>>()
val formatter = SimpleDateFormat("yyyy/MM", Locale.getDefault()) val formatter = SimpleDateFormat("yyyy/MM", Locale.getDefault())
......
package com.test.easy.easycleanerjunk.activity
import android.content.Intent
import android.graphics.Color
import android.os.Environment
import androidx.activity.addCallback
import com.google.gson.Gson
import com.test.easy.easycleanerjunk.R
import com.test.easy.easycleanerjunk.adapter.WhatsAppCleanerAdapter
import com.test.easy.easycleanerjunk.bean.WhatsAppCleanerBean
import com.test.easy.easycleanerjunk.databinding.ActivityWhatsAppCleanerBinding
import com.test.easy.easycleanerjunk.helps.BaseActivity
import com.test.easy.easycleanerjunk.helps.FileHelps.getDirFiles
import com.test.easy.easycleanerjunk.helps.KotlinExt.toFormatSize
import com.test.easy.easycleanerjunk.helps.LogEx
import com.test.easy.easycleanerjunk.helps.ads.AdmobUtils
import com.test.easy.easycleanerjunk.utils.BarUtils
import com.test.easy.easycleanerjunk.utils.FileHexEx.isImage
import com.test.easy.easycleanerjunk.utils.FileHexEx.isVideo
import java.io.File
class WhatsAppCleanerActivity : BaseActivity<ActivityWhatsAppCleanerBinding>() {
private val TAG = "WhatsAppCleanerActivity"
private lateinit var adapter: WhatsAppCleanerAdapter
override val binding: ActivityWhatsAppCleanerBinding by lazy {
ActivityWhatsAppCleanerBinding.inflate(layoutInflater)
}
override fun initView() {
BarUtils.setStatusBarLightMode(this, true)
BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
adapter = WhatsAppCleanerAdapter {
startActivity(Intent(this, WhatsAppMessageCleanActivity::class.java).apply {
putExtra("PathList", Gson().toJson(it.subFile.toTypedArray()))
putExtra("Tittle", it.tittle)
})
finish()
}
binding.rv.adapter = adapter
initData()
}
override fun initListener() {
binding.flBack.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
onBackPressedDispatcher.addCallback {
AdmobUtils.showInterstitialAd(this@WhatsAppCleanerActivity) {
finishToMain()
}
}
}
fun initData() {
val whatsAppRoot = File(Environment.getExternalStorageDirectory(), "Android/media/com.whatsapp/WhatsApp/Media/")
LogEx.logDebug(TAG, whatsAppRoot.absolutePath)
val list = arrayListOf<WhatsAppCleanerBean>()
list.add(WhatsAppCleanerBean(R.mipmap.videomessages, "Video Messages"))
list.add(WhatsAppCleanerBean(R.mipmap.imagemessages, "Image Messages"))
list.add(WhatsAppCleanerBean(R.mipmap.audiomessages, "Audio Messages"))
var totalSize = 0L
whatsAppRoot.listFiles()?.forEach { file ->
if (file.name == "WhatsApp Video") {
LogEx.logDebug(TAG, "whatsapp file=${file.absolutePath}")
val bean = list.find { it.tittle == "Video Messages" }
val subFile = getDirFiles(file).filter { isVideo(it) }
val size = subFile.sumOf { it.length() }
bean?.size = size
totalSize += size
bean?.subFile = subFile.map { it.absolutePath }
// subFile.forEach { path ->
// LogEx.logDebug(TAG, "path=$path")
// }
}
if (file.name == "WhatsApp Images") {
val bean = list.find { it.tittle == "Image Messages" }
val subFile = getDirFiles(file).filter { isImage(it) }
val size = subFile.sumOf { it.length() }
bean?.size = size
totalSize += size
bean?.subFile = subFile.map { it.absolutePath }
}
if (file.name == "WhatsApp Audio") {
val bean = list.find { it.tittle == "Audio Messages" }
val subFile = getDirFiles(file).filter { it.name.contains(".mp3") }
val size = subFile.sumOf { it.length() }
bean?.size = size
totalSize += size
bean?.subFile = subFile.map { it.absolutePath }
}
}
adapter.setData(list)
val split = totalSize.toFormatSize().split(" ")
binding.tvSize.text = split[0]
binding.tvUnit.text = split[1]
}
}
\ No newline at end of file
package com.test.easy.easycleanerjunk.activity
import android.content.Intent
import android.graphics.Color
import androidx.activity.addCallback
import com.google.gson.Gson
import com.test.easy.easycleanerjunk.adapter.WhatsAppMediaAdapter
import com.test.easy.easycleanerjunk.bean.ImageDataBean
import com.test.easy.easycleanerjunk.databinding.ActivityWhatsAppMessageCleanBinding
import com.test.easy.easycleanerjunk.helps.BaseActivity
import com.test.easy.easycleanerjunk.helps.ads.AdmobUtils
import com.test.easy.easycleanerjunk.utils.BarUtils
import com.test.easy.easycleanerjunk.view.AFunOb.WHATSAPP_CLEANER
import com.test.easy.easycleanerjunk.view.FileDeleteDialog.showFileDeleteDialog
import java.io.File
class WhatsAppMessageCleanActivity : BaseActivity<ActivityWhatsAppMessageCleanBinding>() {
private val pathList by lazy {
val json = intent.extras?.getString("PathList")
val list = Gson().fromJson(json, Array<String>::class.java)
list.map { ImageDataBean(it) }
}
private lateinit var adapter: WhatsAppMediaAdapter
override val binding: ActivityWhatsAppMessageCleanBinding by lazy {
ActivityWhatsAppMessageCleanBinding.inflate(layoutInflater)
}
override fun initView() {
BarUtils.setStatusBarLightMode(this, true)
BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
val tittle = intent.extras?.getString("Tittle") ?: ""
binding.tvTitle.text = tittle
adapter = WhatsAppMediaAdapter {
binding.llSelectAll.isSelected = it
binding.tvClean.isEnabled = it
}
binding.rv.adapter = adapter
adapter.setData(pathList)
}
override fun initListener() {
binding.flBack.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
onBackPressedDispatcher.addCallback {
AdmobUtils.showInterstitialAd(this@WhatsAppMessageCleanActivity) {
finishToMain()
}
}
binding.llSelectAll.setOnClickListener {
it.isSelected = !it.isSelected
adapter.toggleSelect(it.isSelected)
binding.tvClean.isEnabled = it.isSelected
}
binding.tvClean.setOnClickListener {
showFileDeleteDialog {
val list = adapter.getSelectData()
runCatching {
list.forEach { File(it).delete() }
}
startActivity(Intent(this, ResultActivity::class.java).apply {
putExtra("from", WHATSAPP_CLEANER)
})
finish()
}
}
}
}
\ No newline at end of file
...@@ -2,7 +2,6 @@ package com.test.easy.easycleanerjunk.activity.home ...@@ -2,7 +2,6 @@ package com.test.easy.easycleanerjunk.activity.home
import android.graphics.Color import android.graphics.Color
import android.graphics.Typeface import android.graphics.Typeface
import android.os.Environment
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
...@@ -11,7 +10,6 @@ import com.test.easy.easycleanerjunk.databinding.ActivityMainBinding ...@@ -11,7 +10,6 @@ import com.test.easy.easycleanerjunk.databinding.ActivityMainBinding
import com.test.easy.easycleanerjunk.fragment.HomeFragment import com.test.easy.easycleanerjunk.fragment.HomeFragment
import com.test.easy.easycleanerjunk.fragment.ToolsFragment import com.test.easy.easycleanerjunk.fragment.ToolsFragment
import com.test.easy.easycleanerjunk.helps.BaseActivity import com.test.easy.easycleanerjunk.helps.BaseActivity
import com.test.easy.easycleanerjunk.helps.MediaStoreUtils
import com.test.easy.easycleanerjunk.utils.BarUtils import com.test.easy.easycleanerjunk.utils.BarUtils
import com.test.easy.easycleanerjunk.view.RateStarPop import com.test.easy.easycleanerjunk.view.RateStarPop
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
...@@ -37,6 +35,7 @@ class NewMainActivity : BaseActivity<ActivityMainBinding>() { ...@@ -37,6 +35,7 @@ class NewMainActivity : BaseActivity<ActivityMainBinding>() {
} }
override fun initView() { override fun initView() {
BarUtils.setStatusBarLightMode(this, true)
BarUtils.setStatusBarColor(this, Color.TRANSPARENT) BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
binding.idVp.run { binding.idVp.run {
......
...@@ -3,12 +3,14 @@ package com.test.easy.easycleanerjunk.activity.splash ...@@ -3,12 +3,14 @@ package com.test.easy.easycleanerjunk.activity.splash
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.util.Log import android.util.Log
import com.test.easy.easycleanerjunk.activity.AppManagerActivity
import com.test.easy.easycleanerjunk.activity.CleanGuestActivity import com.test.easy.easycleanerjunk.activity.CleanGuestActivity
import com.test.easy.easycleanerjunk.activity.DeviceScanActivity import com.test.easy.easycleanerjunk.activity.DeviceScanActivity
import com.test.easy.easycleanerjunk.activity.LargeFileCleanActivity import com.test.easy.easycleanerjunk.activity.LargeFileCleanActivity
import com.test.easy.easycleanerjunk.activity.RepeatPhotoActivity import com.test.easy.easycleanerjunk.activity.RepeatPhotoActivity
import com.test.easy.easycleanerjunk.activity.ScanJunkActivity import com.test.easy.easycleanerjunk.activity.ScanJunkActivity
import com.test.easy.easycleanerjunk.activity.ScreenShotActivity import com.test.easy.easycleanerjunk.activity.ScreenShotActivity
import com.test.easy.easycleanerjunk.activity.WhatsAppCleanerActivity
import com.test.easy.easycleanerjunk.activity.home.NewMainActivity import com.test.easy.easycleanerjunk.activity.home.NewMainActivity
import com.test.easy.easycleanerjunk.activity.photocompress.photo.StartCompressionPhotoActivity import com.test.easy.easycleanerjunk.activity.photocompress.photo.StartCompressionPhotoActivity
import com.test.easy.easycleanerjunk.bean.ConfigBean.Companion.ID_JUNK_CLEAN_PUSH import com.test.easy.easycleanerjunk.bean.ConfigBean.Companion.ID_JUNK_CLEAN_PUSH
...@@ -16,6 +18,7 @@ import com.test.easy.easycleanerjunk.bean.ConfigBean.Companion.ID_LARGE_FILE_PUS ...@@ -16,6 +18,7 @@ import com.test.easy.easycleanerjunk.bean.ConfigBean.Companion.ID_LARGE_FILE_PUS
import com.test.easy.easycleanerjunk.bean.ConfigBean.Companion.ID_PHOTO_COMPRESS import com.test.easy.easycleanerjunk.bean.ConfigBean.Companion.ID_PHOTO_COMPRESS
import com.test.easy.easycleanerjunk.bean.ConfigBean.Companion.ID_SCREENSHOT_CLEAN import com.test.easy.easycleanerjunk.bean.ConfigBean.Companion.ID_SCREENSHOT_CLEAN
import com.test.easy.easycleanerjunk.bean.ConfigBean.Companion.ID_SIMILAR_IMAGE import com.test.easy.easycleanerjunk.bean.ConfigBean.Companion.ID_SIMILAR_IMAGE
import com.test.easy.easycleanerjunk.bean.WhatsAppCleanerBean
import com.test.easy.easycleanerjunk.helps.ConfigHelper import com.test.easy.easycleanerjunk.helps.ConfigHelper
object SplashJumpUtils { object SplashJumpUtils {
...@@ -24,7 +27,7 @@ object SplashJumpUtils { ...@@ -24,7 +27,7 @@ object SplashJumpUtils {
var jumpType = context.intent.getIntExtra("actionId", 0) var jumpType = context.intent.getIntExtra("actionId", 0)
Log.d("glc","actionId: " +jumpType) Log.d("glc", "actionId: " + jumpType)
if (jumpType == 0) { if (jumpType == 0) {
val uri = context.intent.data val uri = context.intent.data
......
package com.test.easy.easycleanerjunk.adapter
import android.annotation.SuppressLint
import android.graphics.Color
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.test.easy.easycleanerjunk.R
import com.test.easy.easycleanerjunk.bean.WhatsAppCleanerBean
import com.test.easy.easycleanerjunk.databinding.ItemWhatsappBinding
import com.test.easy.easycleanerjunk.helps.KotlinExt.toFormatSize
import com.test.easy.easycleanerjunk.utils.ScreenUtil.dpToPx
import com.test.easy.easycleanerjunk.view.XmlEx.inflate
import java.util.ArrayList
class WhatsAppCleanerAdapter(val click: (bean: WhatsAppCleanerBean) -> Unit) : RecyclerView.Adapter<WhatsAppCleanerAdapter.Whats>() {
private val beanList = arrayListOf<WhatsAppCleanerBean>()
class Whats(view: View) : ViewHolder(view) {
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Whats {
return Whats(R.layout.item_whatsapp.inflate(parent))
}
override fun getItemCount(): Int {
return beanList.size
}
override fun onBindViewHolder(holder: Whats, position: Int) {
val binding = ItemWhatsappBinding.bind(holder.itemView)
val context = holder.itemView.context
val bean = beanList[position]
binding.iv.setImageDrawable(ContextCompat.getDrawable(context, bean.icon))
if (bean.subFile.isEmpty()) {
binding.llIv.visibility = View.GONE
binding.tvSize.setTextColor(Color.parseColor("#999999"))
binding.ivArrow.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.jianotu_whatsapp))
} else {
binding.llIv.visibility = View.VISIBLE
runCatching {
val options = RequestOptions().transform(CenterCrop(), RoundedCorners(context.dpToPx(10)))
val image1 = bean.subFile[0]
Glide.with(context).load(image1).apply(options).into(binding.iv1)
val image2 = bean.subFile[1]
Glide.with(context).load(image2).apply(options).into(binding.iv2)
val image3 = bean.subFile[2]
Glide.with(context).load(image3).apply(options).into(binding.iv3)
}
binding.tvSize.setTextColor(Color.parseColor("#355BEA"))
binding.tvSize.text = bean.size.toFormatSize()
binding.ivArrow.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.jianotul_whatsapp))
}
binding.root.setOnClickListener {
if (bean.subFile.isEmpty()) {
return@setOnClickListener
}
click.invoke(bean)
}
}
@SuppressLint("NotifyDataSetChanged")
fun setData(list: List<WhatsAppCleanerBean>) {
beanList.clear()
beanList.addAll(list)
notifyDataSetChanged()
}
}
\ No newline at end of file
package com.test.easy.easycleanerjunk.adapter
import android.annotation.SuppressLint
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.test.easy.easycleanerjunk.R
import com.test.easy.easycleanerjunk.bean.ImageDataBean
import com.test.easy.easycleanerjunk.databinding.ItemMediaSelectBinding
import com.test.easy.easycleanerjunk.view.XmlEx.inflate
class WhatsAppMediaAdapter(private val click: (allSelect: Boolean) -> Unit) : RecyclerView.Adapter<WhatsAppMediaAdapter.WhatMedia>() {
private val beanList = arrayListOf<ImageDataBean>()
class WhatMedia(view: View) : RecyclerView.ViewHolder(view)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WhatMedia {
return WhatMedia(R.layout.item_media_select.inflate(parent))
}
override fun getItemCount(): Int {
return beanList.size
}
override fun onBindViewHolder(holder: WhatMedia, position: Int) {
}
override fun onBindViewHolder(holder: WhatMedia, position: Int, payloads: MutableList<Any>) {
val binding = ItemMediaSelectBinding.bind(holder.itemView)
val context = holder.itemView.context
val bean = beanList[position]
if (payloads.isEmpty()) {
Glide.with(context).load(bean.path).centerCrop().into(binding.iv)
binding.ivSelector.isSelected = bean.isSelect
binding.root.setOnClickListener {
binding.ivSelector.isSelected = !binding.ivSelector.isSelected
bean.isSelect = binding.ivSelector.isSelected
notifyItemChanged(position, "sdd")
click.invoke(beanList.all { it.isSelect })
}
} else {
binding.ivSelector.isSelected = bean.isSelect
super.onBindViewHolder(holder, position, payloads)
}
}
@SuppressLint("NotifyDataSetChanged")
fun setData(pathList: List<ImageDataBean>) {
beanList.clear()
beanList.addAll(pathList)
notifyDataSetChanged()
}
@SuppressLint("NotifyDataSetChanged")
fun toggleSelect(select: Boolean) {
beanList.forEach { it.isSelect = select }
notifyDataSetChanged()
}
fun getSelectData(): List<String> {
return beanList.filter { it.isSelect }.map { it.path }
}
}
\ No newline at end of file
...@@ -2,7 +2,7 @@ package com.test.easy.easycleanerjunk.bean ...@@ -2,7 +2,7 @@ package com.test.easy.easycleanerjunk.bean
data class ImageDataBean( data class ImageDataBean(
val path: String, val path: String,
val hashCode: String, val hashCode: String = "",
val avgPixel: Int, val avgPixel: Int = 0,
var isSelect: Boolean = false var isSelect: Boolean = false
) )
\ No newline at end of file
package com.test.easy.easycleanerjunk.bean
data class WhatsAppCleanerBean(
val icon: Int,
val tittle: String,
var size: Long=0L,
var subFile: List<String> = listOf()
)
...@@ -7,6 +7,8 @@ import kotlinx.coroutines.MainScope ...@@ -7,6 +7,8 @@ import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.io.File import java.io.File
import java.io.IOException
import java.io.RandomAccessFile
import java.util.LinkedList import java.util.LinkedList
object FileHelps { object FileHelps {
...@@ -62,7 +64,7 @@ object FileHelps { ...@@ -62,7 +64,7 @@ object FileHelps {
} }
} }
fun getDcim( fun getDirFiles(
folder: File, folder: File,
): ArrayList<File> { ): ArrayList<File> {
val result = arrayListOf<File>() val result = arrayListOf<File>()
...@@ -92,4 +94,19 @@ object FileHelps { ...@@ -92,4 +94,19 @@ object FileHelps {
return result return result
} }
fun readFileRange(filePath: String, start: Long, end: Long): ByteArray {
var data = byteArrayOf()
try {
val file = RandomAccessFile(filePath, "r")
file.seek(start)
val length = end - start
data = ByteArray(length.toInt())
file.readFully(data)
file.close()
} catch (e: IOException) {
e.printStackTrace()
}
return data
}
} }
\ No newline at end of file
package com.test.easy.easycleanerjunk.utils
import com.test.easy.easycleanerjunk.helps.FileHelps
import java.io.File
object FileHexEx {
private val TAG = "FileHexEx"
fun isImage(file: File): Boolean {
return isWebp(file) || isPngOrJpg(file)
}
fun isPngOrJpg(file: File): Boolean {
val pngHex = "89504E47"
val jpgHex1 = "FFD8FFE0"
val jpgHex2 = "FFD8FFE1"
val hex = FileHelps.readFileRange(file.absolutePath, 0, 4).byteArrayToHexString()
return (hex == pngHex || hex == jpgHex1 || hex == jpgHex2)
}
fun isWebp(file: File): Boolean {
val webpHex = "57454250"
val hex = FileHelps.readFileRange(file.absolutePath, 8, 11).byteArrayToHexString()
return hex == webpHex
}
fun isVideo(file: File): Boolean {
return isMp4(file) || isAvi(file) || isMkv(file)
}
fun isMp4(file: File): Boolean {
val mp4Hex = "6D70343269736F6D000061316D6F6F76"
val hex = FileHelps.readFileRange(file.absolutePath, 16, 32).byteArrayToHexString()
val flag = hex == mp4Hex
// LogEx.logDebug(TAG, "flag=$flag hex=${hex} ${file.absolutePath}")
return flag
}
fun isAvi(file: File): Boolean {
val aviHex = "524946461C1BA900415649204C495354"
val hex = FileHelps.readFileRange(file.absolutePath, 0, 16).byteArrayToHexString()
val flag = hex == aviHex
// LogEx.logDebug(TAG, "flag=$flag hex=${hex} ${file.absolutePath}")
return flag
}
fun isMkv(file: File): Boolean {
val mkvHex1 = "42F7810142F2810442F381084282886D"
val hex1 = FileHelps.readFileRange(file.absolutePath, 16, 32).byteArrayToHexString()
val flag1 = hex1 == mkvHex1
// LogEx.logDebug(TAG, "flag1=$flag1 hex=${hex1} ${file.absolutePath}")
return if (flag1) {
true
} else {
val mkvHex2 = "42F7810142F2810442F381084282886D6174726F736B614287"
val hex2 = FileHelps.readFileRange(file.absolutePath, 9, 34).byteArrayToHexString()
val flag2 = hex2 == mkvHex2
// LogEx.logDebug(TAG, "flag2=$flag2 hex=${hex2} ${file.absolutePath}")
flag2
}
}
}
\ No newline at end of file
package com.test.easy.easycleanerjunk.utils
/**
* Author: nxl
* Created on 2021/11/8 15:08
* Email: niexueliang@qdtgkj.com
* DESC: Hex码
*/
private const val HEXES = "0123456789ABCDEF"
/**
* ByteArray转Hex码
*/
fun ByteArray.byteArrayToHexString(): String {
val hex = StringBuilder(2 * this.size)
for (element in this) {
val high = element.toInt().and(0xFF).shr(4)
val low = element.toInt().and(0x0F)
hex.append(HEXES[high]).append(HEXES[low])
}
return hex.toString()
}
/**
* HexString转ByteArray
*/
fun String.hexStringToByteArr(): ByteArray {
val data = ByteArray(this.length / 2)
for (i in this.indices step 2) {
val character = this.substring(i, i + 2).toInt(16).toByte()
data[i / 2] = character
}
return data
}
\ No newline at end of file
package com.test.easy.easycleanerjunk.utils
import android.content.Context
object ScreenUtil {
fun Context.dpToPx(dps: Int): Int {
return Math.round(resources.displayMetrics.density * dps)
}
}
\ No newline at end of file
...@@ -7,4 +7,5 @@ object AFunOb { ...@@ -7,4 +7,5 @@ object AFunOb {
const val PHOTO_COMPRESS = "Photo Compress" const val PHOTO_COMPRESS = "Photo Compress"
const val SCREENSHOT_CLEANER = "Screenshot Cleaner" const val SCREENSHOT_CLEANER = "Screenshot Cleaner"
const val BATTERY_INFO = "Battery Info" const val BATTERY_INFO = "Battery Info"
const val WHATSAPP_CLEANER = "WhatsApp Cleaner"
} }
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F4F5F9"
android:orientation="vertical"
tools:context=".activity.WhatsAppCleanerActivity">
<View
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/white" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">
<FrameLayout
android:id="@+id/fl_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/fanhui"
android:tint="@color/black"
tools:ignore="ContentDescription,UseAppTint" />
</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="WhatsApp Cleaner"
android:textColor="@color/black"
android:textSize="19sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginVertical="25dp"
android:orientation="vertical"
tools:ignore="UselessParent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#4772FF"
android:textSize="45sp"
android:textStyle="bold"
tools:text="108.7" />
<TextView
android:id="@+id/tv_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="8dp"
android:textColor="#4772FF"
android:textSize="12sp"
android:textStyle="bold"
tools:text="KB" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="14dp"
android:text="Cleanable"
android:textColor="#666666"
android:textSize="15sp"
tools:ignore="HardcodedText" />
</LinearLayout>
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:background="@color/white"
android:paddingVertical="8dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_whatsapp" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activity.WhatsAppMessageCleanActivity">
<View
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/white" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">
<FrameLayout
android:id="@+id/fl_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/fanhui"
android:tint="@color/black"
tools:ignore="ContentDescription,UseAppTint" />
</FrameLayout>
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="@color/black"
android:textSize="19sp"
android:textStyle="bold"
tools:ignore="HardcodedText"
tools:text="Image Messages" />
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="3"
tools:listitem="@layout/item_media_select" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="80dp">
<LinearLayout
android:id="@+id/ll_select_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:minWidth="23dp"
android:minHeight="23dp"
android:src="@drawable/bg_selector_square"
tools:ignore="ContentDescription" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select All"
tools:ignore="HardcodedText" />
</LinearLayout>
<com.noober.background.view.BLTextView
android:id="@+id/tv_clean"
android:layout_width="266dp"
android:layout_height="50dp"
android:enabled="false"
android:gravity="center"
android:text="CLEAN"
android:textColor="@color/white"
android:textSize="19sp"
app:bl_corners_radius="10dp"
app:bl_enabled_solid_color="@color/theme_color"
app:bl_unEnabled_solid_color="#BEBEBE"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/ll_select_all"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="109dp"
android:layout_height="109dp"
android:layout_margin="8dp"
app:cardCornerRadius="5dp"
app:cardElevation="0dp">
<ImageView
android:id="@+id/iv"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_selector"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="end"
android:layout_margin="10dp"
android:src="@drawable/bg_select_all"
tools:ignore="ContentDescription" />
</androidx.cardview.widget.CardView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="8dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="ContentDescription"
tools:src="@mipmap/audiomessages" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Video Messages"
android:textColor="@color/black"
android:textSize="15sp"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/tv_no_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="No video messages found."
android:textColor="#999999"
android:textSize="12sp"
tools:ignore="HardcodedText" />
</LinearLayout>
<TextView
android:id="@+id/tv_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="0 KB"
android:textColor="#999999"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<ImageView
android:id="@+id/iv_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="5dp"
android:src="@mipmap/jianotu_whatsapp"
tools:ignore="ContentDescription" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="55dp"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_iv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:visibility="gone">
<ImageView
android:id="@+id/iv_1"
android:layout_width="90dp"
android:layout_height="90dp"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_2"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginStart="12dp"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_3"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginStart="12dp"
tools:ignore="ContentDescription" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="16dp"
android:background="#EEEEEE" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
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