Commit cf359084 authored by wanglei's avatar wanglei

...

parent b37d8503
...@@ -52,6 +52,7 @@ dependencies { ...@@ -52,6 +52,7 @@ dependencies {
implementation("com.github.bumptech.glide:glide:4.16.0") implementation("com.github.bumptech.glide:glide:4.16.0")
implementation("com.github.angcyo.DslTablayout:TabLayout:3.5.5") implementation("com.github.angcyo.DslTablayout:TabLayout:3.5.5")
implementation("de.hdodenhof:circleimageview:3.1.0") implementation("de.hdodenhof:circleimageview:3.1.0")
implementation("com.github.pokercc:ExpandableRecyclerView:0.9.3")
//相机 //相机
val cameraxVersion = "1.2.2" val cameraxVersion = "1.2.2"
......
...@@ -6,18 +6,20 @@ import android.graphics.drawable.Drawable ...@@ -6,18 +6,20 @@ import android.graphics.drawable.Drawable
data class ParentBean( data class ParentBean(
val icon: Int = 0, val icon: Int = 0,
val tittle: String = "", val tittle: String = "",
val childItem: List<ChildBean> = arrayListOf(),
) { ) {
var playAnimation: Boolean = true var playAnimation: Boolean = true
var isExpand: Boolean = false var isExpand: Boolean = true
var isSelect: Boolean = false var isSelect: Boolean = true
var finished: Boolean = false var finished: Boolean = false
var rotateValueAnimator: ValueAnimator? = null var rotateValueAnimator: ValueAnimator? = null
} }
data class ChildBean( data class ChildBean(
val icon: Drawable? = null, val icon: Int = 0,
val name: String = "",
val path: String = "", val path: String = "",
) { ) {
var isSelect: Boolean = false var playAnimation: Boolean = true
var apkIcon: Drawable? = null
var isSelect: Boolean = true
} }
\ No newline at end of file
package com.base.browserwhite.ui.activity.cleanjunk package com.base.browserwhite.ui.activity.cleanjunk
import android.annotation.SuppressLint
import android.content.pm.PackageManager
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.Drawable
import android.os.Environment import android.os.Environment
import android.view.View import android.view.View
import androidx.activity.addCallback import androidx.activity.addCallback
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.base.browserwhite.R import com.base.browserwhite.R
import com.base.browserwhite.bean.ChildBean
import com.base.browserwhite.bean.ParentBean import com.base.browserwhite.bean.ParentBean
import com.base.browserwhite.databinding.ActivityScanJunkBinding import com.base.browserwhite.databinding.ActivityScanJunkBinding
import com.base.browserwhite.ui.activity.BaseActivity import com.base.browserwhite.ui.activity.BaseActivity
import com.base.browserwhite.ui.adapter.JunkExpandAdapter
import com.base.browserwhite.ui.adapter.JunkScanAdapter import com.base.browserwhite.ui.adapter.JunkScanAdapter
import com.base.browserwhite.utils.BarUtils import com.base.browserwhite.utils.BarUtils
import com.base.browserwhite.utils.FileHelp.getFileFolder import com.base.browserwhite.utils.FileHelp.getFileFolder
...@@ -22,10 +28,12 @@ import kotlinx.coroutines.flow.SharedFlow ...@@ -22,10 +28,12 @@ import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.io.File import java.io.File
import kotlin.random.Random
class ScanJunkActivity : BaseActivity<ActivityScanJunkBinding>() { class ScanJunkActivity : BaseActivity<ActivityScanJunkBinding>() {
private lateinit var junkScanAdapter: JunkScanAdapter private lateinit var junkScanAdapter: JunkScanAdapter
private lateinit var junkExpandAdapter: JunkExpandAdapter
override val binding: ActivityScanJunkBinding by lazy { override val binding: ActivityScanJunkBinding by lazy {
ActivityScanJunkBinding.inflate(layoutInflater) ActivityScanJunkBinding.inflate(layoutInflater)
...@@ -46,6 +54,8 @@ class ScanJunkActivity : BaseActivity<ActivityScanJunkBinding>() { ...@@ -46,6 +54,8 @@ class ScanJunkActivity : BaseActivity<ActivityScanJunkBinding>() {
junkScanAdapter = JunkScanAdapter() junkScanAdapter = JunkScanAdapter()
binding.rv.adapter = junkScanAdapter binding.rv.adapter = junkScanAdapter
junkExpandAdapter = JunkExpandAdapter()
binding.rvEx.adapter = junkExpandAdapter
lifecycleScope.launch(Dispatchers.Main) { lifecycleScope.launch(Dispatchers.Main) {
pathFlow.collectLatest { pathFlow.collectLatest {
...@@ -67,6 +77,7 @@ class ScanJunkActivity : BaseActivity<ActivityScanJunkBinding>() { ...@@ -67,6 +77,7 @@ class ScanJunkActivity : BaseActivity<ActivityScanJunkBinding>() {
} }
@SuppressLint("SetTextI18n")
private fun beginScan() = lifecycleScope.launch(Dispatchers.Main) { private fun beginScan() = lifecycleScope.launch(Dispatchers.Main) {
var size = 0L var size = 0L
junkScanAdapter.addData(ParentBean(R.mipmap.x_residual, "Residual File"), 0) junkScanAdapter.addData(ParentBean(R.mipmap.x_residual, "Residual File"), 0)
...@@ -108,8 +119,46 @@ class ScanJunkActivity : BaseActivity<ActivityScanJunkBinding>() { ...@@ -108,8 +119,46 @@ class ScanJunkActivity : BaseActivity<ActivityScanJunkBinding>() {
setSize(size) setSize(size)
junkScanAdapter.setFinishScan(3) junkScanAdapter.setFinishScan(3)
delay(Random.nextLong(500, 1000))
binding.rv.visibility = View.GONE
binding.rvEx.visibility = View.VISIBLE
// if (emptyFolder.isNotEmpty()) {
val childList1 = emptyFolder.map { ChildBean(R.mipmap.d_reseiual, it.absolutePath) }
val emptyParent = ParentBean(tittle = "Residual File", childItem = childList1)
junkExpandAdapter.addData(listOf(emptyParent), false)
junkExpandAdapter.expandAllGroup()
// }
if (apkList.isNotEmpty()) {
val childList2 = apkList.map {
ChildBean(R.mipmap.d_useless, it.absolutePath).apply { apkIcon = getApkDrawable(it.absolutePath) }
}
val apkParent = ParentBean(tittle = "Useless installation package", childItem = childList2)
junkExpandAdapter.addData(listOf(apkParent), false)
junkExpandAdapter.expandAllGroup()
}
if (tempList.isNotEmpty()) {
val childList3 = tempList.map { ChildBean(R.mipmap.d_temp, it.absolutePath) }
val tempParent = ParentBean(tittle = "Temp Files", childItem = childList3)
junkExpandAdapter.addData(listOf(tempParent), false)
junkExpandAdapter.expandAllGroup()
}
if (logList.isNotEmpty()) {
val childList4 = logList.map { ChildBean(R.mipmap.d_log, it.absolutePath) }
val logParent = ParentBean(tittle = "Log Files", childItem = childList4)
junkExpandAdapter.addData(listOf(logParent), false)
junkExpandAdapter.expandAllGroup()
}
binding.clTop.setBackgroundResource(R.mipmap.hong_bg)
binding.tvPath.visibility = View.GONE binding.tvPath.visibility = View.GONE
binding.tvBtn.isEnabled=true binding.tvBtn.isEnabled = true
binding.tvBtn.setTextColor(ContextCompat.getColor(this@ScanJunkActivity, R.color.white))
binding.tvBtn.text = "Clean up ${size.toFormatSize()}"
} }
private fun setSize(size: Long) { private fun setSize(size: Long) {
...@@ -118,5 +167,13 @@ class ScanJunkActivity : BaseActivity<ActivityScanJunkBinding>() { ...@@ -118,5 +167,13 @@ class ScanJunkActivity : BaseActivity<ActivityScanJunkBinding>() {
binding.tvUnit.text = split[1] binding.tvUnit.text = split[1]
} }
private fun getApkDrawable(apkPath: String): Drawable? {
val packageInfo = packageManager.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES)
if (packageInfo != null) {
val applicationInfo = packageInfo.applicationInfo
return packageManager.getApplicationIcon(applicationInfo)
}
return null
}
} }
\ No newline at end of file
package com.base.browserwhite.ui.adapter
import android.annotation.SuppressLint
import android.view.ViewGroup
import android.view.animation.AnimationUtils
import com.base.browserwhite.R
import com.base.browserwhite.bean.ParentBean
import com.base.browserwhite.databinding.ItemJunkChildBinding
import com.base.browserwhite.databinding.ItemJunkParentBinding
import com.base.browserwhite.utils.KotlinExt.toFormatSize
import com.base.browserwhite.utils.XmlEx.inflate
import pokercc.android.expandablerecyclerview.ExpandableAdapter
import java.io.File
class JunkExpandAdapter : ExpandableAdapter<ExpandableAdapter.ViewHolder>() {
private val beanList = arrayListOf<ParentBean>()
override fun getChildCount(groupPosition: Int): Int {
return beanList[groupPosition].childItem.size
}
override fun getGroupCount(): Int {
return beanList.size
}
override fun onCreateChildViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(R.layout.item_junk_child.inflate(viewGroup))
}
override fun onCreateGroupViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(R.layout.item_junk_parent.inflate(viewGroup))
}
override fun onBindChildViewHolder(holder: ViewHolder, groupPosition: Int, childPosition: Int, payloads: List<Any>) {
val binding = ItemJunkChildBinding.bind(holder.itemView)
val parentBean = beanList[groupPosition]
val childBeanList = parentBean.childItem
val childBean = childBeanList[childPosition]
if (payloads.isEmpty()) {
if (childBean.apkIcon == null) binding.iv.setImageResource(childBean.icon) else binding.iv.setImageDrawable(childBean.apkIcon)
val file = File(childBean.path)
binding.tvName.text = file.name
binding.tvSize.text = file.length().toFormatSize()
binding.ivSelector.isSelected = childBean.isSelect
binding.root.setOnClickListener {
childBean.isSelect = !childBean.isSelect
notifyChildChange(groupPosition, childPosition, "aaa")
val allSelect = childBeanList.all { it.isSelect }
if (parentBean.isSelect != allSelect) {
parentBean.isSelect = allSelect
notifyGroupChange(groupPosition, "aa")
}
}
if (childBean.playAnimation) {
val slideInFromRight = AnimationUtils.loadAnimation(holder.itemView.context, R.anim.slide_in_from_right)
binding.root.startAnimation(slideInFromRight)
childBean.playAnimation = false
}
} else {
binding.ivSelector.isSelected = childBean.isSelect
}
}
@SuppressLint("NotifyDataSetChanged")
override fun onBindGroupViewHolder(holder: ViewHolder, groupPosition: Int, expand: Boolean, payloads: List<Any>) {
val binding = ItemJunkParentBinding.bind(holder.itemView)
val bean = beanList[groupPosition]
bean.isExpand = expand
if (bean.isExpand) {
binding.ivExpand.setImageResource(R.mipmap.zhankai)
} else {
binding.ivExpand.setImageResource(R.mipmap.shouqi)
}
if (payloads.isEmpty()) {
binding.tvName.text = bean.tittle
val size = bean.childItem.sumOf { File(it.path).length() }
binding.tvSize.text = size.toFormatSize()
binding.flExpand.setOnClickListener {
bean.isExpand = !bean.isExpand
notifyGroupChange(groupPosition, "aa")
if (bean.isExpand) {
expandGroup(groupPosition, true)
} else {
collapseGroup(groupPosition, true)
}
}
binding.ivSelector.isSelected = bean.isSelect
binding.flSelector.setOnClickListener {
bean.isSelect = !bean.isSelect
bean.childItem.forEach { it.isSelect = bean.isSelect }
notifyDataSetChanged()
}
if (bean.playAnimation) {
val slideInFromRight = AnimationUtils.loadAnimation(holder.itemView.context, R.anim.slide_in_from_right)
binding.root.startAnimation(slideInFromRight)
bean.playAnimation = false
}
} else {
binding.ivSelector.isSelected = bean.isSelect
}
}
override fun onGroupViewHolderExpandChange(holder: ViewHolder, groupPosition: Int, animDuration: Long, expand: Boolean) {}
@SuppressLint("NotifyDataSetChanged")
fun addData(list: List<ParentBean>, clear: Boolean = true) {
if (clear) {
beanList.clear()
}
beanList.addAll(list)
notifyDataSetChanged()
}
}
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/xuan" android:state_selected="true" />
<item android:drawable="@mipmap/weixuan" android:state_selected="false" />
</selector>
\ No newline at end of file
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:includeFontPadding="false" android:includeFontPadding="false"
android:text="0"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="54sp" android:textSize="54sp"
android:textStyle="bold" android:textStyle="bold"
...@@ -63,7 +64,7 @@ ...@@ -63,7 +64,7 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ll" app:layout_constraintTop_toBottomOf="@id/ll"
app:layout_constraintVertical_bias="0.3" app:layout_constraintVertical_bias="0.3"
tools:text="108.7" /> tools:ignore="HardcodedText" />
<TextView <TextView
android:id="@+id/tv_unit" android:id="@+id/tv_unit"
...@@ -74,8 +75,7 @@ ...@@ -74,8 +75,7 @@
android:textSize="14sp" android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_size" app:layout_constraintTop_toBottomOf="@id/tv_size" />
tools:text="KB" />
<TextView <TextView
android:id="@+id/tv_path" android:id="@+id/tv_path"
...@@ -106,6 +106,12 @@ ...@@ -106,6 +106,12 @@
android:layout_height="match_parent" android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" /> app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<pokercc.android.expandablerecyclerview.ExpandableRecyclerView
android:id="@+id/rv_ex"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</FrameLayout> </FrameLayout>
<TextView <TextView
...@@ -117,9 +123,8 @@ ...@@ -117,9 +123,8 @@
android:enabled="false" android:enabled="false"
android:gravity="center" android:gravity="center"
android:text="Scan in progress" android:text="Scan in progress"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#AEAEB0" android:textColor="#AEAEB0"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
......
<?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="15dp"
android:layout_marginVertical="10dp">
<ImageView
android:id="@+id/iv"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginVertical="6dp"
tools:ignore="ContentDescription"
tools:src="@mipmap/d_reseiual" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="8dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/tv_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:singleLine="true"
android:textColor="@color/black"
android:textSize="14sp"
tools:text="Ali Webpage ads" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="Suggestion: Clean up"
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:textColor="#FF8523"
android:textSize="14sp"
tools:text="12.72 MB" />
<ImageView
android:id="@+id/iv_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="16dp"
android:src="@drawable/bg_circle_selector"
tools:ignore="ContentDescription" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<FrameLayout
android:id="@+id/fl_expand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="10dp"
android:padding="10dp">
<ImageView
android:id="@+id/iv_expand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@mipmap/zhankai"
tools:ignore="ContentDescription" />
</FrameLayout>
<TextView
android:id="@+id/tv_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="8dp"
android:layout_weight="1"
android:textColor="@color/black"
android:textSize="15sp"
tools:text="Residual File" />
<TextView
android:id="@+id/tv_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#FF8523"
android:textSize="14sp"
tools:text="12.72 MB" />
<FrameLayout
android:id="@+id/fl_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="6dp"
android:padding="10dp">
<ImageView
android:id="@+id/iv_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bg_circle_selector"
tools:ignore="ContentDescription" />
</FrameLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#E5E6EB"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ 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