Commit 9af7655d authored by wanglei's avatar wanglei

...

parent d5c9b460
...@@ -15,7 +15,6 @@ import com.base.browserwhite.bean.ConstObject.ID_NEWS ...@@ -15,7 +15,6 @@ import com.base.browserwhite.bean.ConstObject.ID_NEWS
import com.base.browserwhite.bean.ConstObject.ID_SCAN_CODE import com.base.browserwhite.bean.ConstObject.ID_SCAN_CODE
import com.base.browserwhite.bean.ConstObject.ifAgreePrivacy import com.base.browserwhite.bean.ConstObject.ifAgreePrivacy
import com.base.browserwhite.databinding.ActivitySplashBinding import com.base.browserwhite.databinding.ActivitySplashBinding
import com.base.browserwhite.service.StayNotificationService.Companion.startStayNotification
import com.base.browserwhite.ui.activity.cleanjunk.ScanJunkActivity import com.base.browserwhite.ui.activity.cleanjunk.ScanJunkActivity
import com.base.browserwhite.utils.BarUtils import com.base.browserwhite.utils.BarUtils
import com.base.browserwhite.utils.ConfigHelper import com.base.browserwhite.utils.ConfigHelper
......
package com.base.browserwhite.ui.fragment package com.base.browserwhite.ui.fragment
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.usage.StorageStatsManager
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build
import android.os.Environment
import android.os.StatFs
import android.os.storage.StorageManager
import android.view.View import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.base.browserwhite.BuildConfig
import com.base.browserwhite.bean.MediaBean import com.base.browserwhite.bean.MediaBean
import com.base.browserwhite.databinding.FragmentFileBinding import com.base.browserwhite.databinding.FragmentFileBinding
import com.base.browserwhite.ui.activity.MainActivity import com.base.browserwhite.ui.activity.MainActivity
...@@ -20,15 +14,16 @@ import com.base.browserwhite.ui.activity.mediabrowser.MediaBrowserActivity ...@@ -20,15 +14,16 @@ import com.base.browserwhite.ui.activity.mediabrowser.MediaBrowserActivity
import com.base.browserwhite.ui.adapter.MediaAdapter import com.base.browserwhite.ui.adapter.MediaAdapter
import com.base.browserwhite.ui.views.DialogViews.showDeleteTipDialog import com.base.browserwhite.ui.views.DialogViews.showDeleteTipDialog
import com.base.browserwhite.ui.views.DialogViews.showMediaMoreDialog import com.base.browserwhite.ui.views.DialogViews.showMediaMoreDialog
import com.base.browserwhite.ui.views.ProgressBean
import com.base.browserwhite.utils.IntentEx.shareAction import com.base.browserwhite.utils.IntentEx.shareAction
import com.base.browserwhite.utils.KotlinExt.toFormatSize import com.base.browserwhite.utils.KotlinExt.toFormatSize
import com.base.browserwhite.utils.LogEx import com.base.browserwhite.utils.LogEx
import com.base.browserwhite.utils.MediaStoreUtils.getMediaApkSize import com.base.browserwhite.utils.MediaStoreUtils.getMediaApkCountSize
import com.base.browserwhite.utils.MediaStoreUtils.getMediaAudioSize import com.base.browserwhite.utils.MediaStoreUtils.getMediaAudioCountSize
import com.base.browserwhite.utils.MediaStoreUtils.getMediaDocumentSize import com.base.browserwhite.utils.MediaStoreUtils.getMediaDocumentCountSize
import com.base.browserwhite.utils.MediaStoreUtils.getMediaPhotoSize import com.base.browserwhite.utils.MediaStoreUtils.getMediaPhotoCountSize
import com.base.browserwhite.utils.MediaStoreUtils.getMediaVideoSize import com.base.browserwhite.utils.MediaStoreUtils.getMediaVideoCountSize
import com.base.browserwhite.utils.MediaStoreUtils.getMediaZipSize import com.base.browserwhite.utils.MediaStoreUtils.getMediaZipCountSize
import com.base.browserwhite.utils.MediaStoreUtils.getMediaFile import com.base.browserwhite.utils.MediaStoreUtils.getMediaFile
import com.base.browserwhite.utils.PermissionHelp.checkStorePermission import com.base.browserwhite.utils.PermissionHelp.checkStorePermission
import com.base.browserwhite.utils.PermissionHelp.requestStorePermission import com.base.browserwhite.utils.PermissionHelp.requestStorePermission
...@@ -42,6 +37,7 @@ class FileFragment : BaseFragment<FragmentFileBinding>() { ...@@ -42,6 +37,7 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
private val TAG = "FileFragment" private val TAG = "FileFragment"
private lateinit var adapter: MediaAdapter private lateinit var adapter: MediaAdapter
private val progressList = arrayListOf<ProgressBean>()
override val binding: FragmentFileBinding by lazy { override val binding: FragmentFileBinding by lazy {
FragmentFileBinding.inflate(layoutInflater) FragmentFileBinding.inflate(layoutInflater)
...@@ -49,8 +45,10 @@ class FileFragment : BaseFragment<FragmentFileBinding>() { ...@@ -49,8 +45,10 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
@SuppressLint("QueryPermissionsNeeded", "SetTextI18n") @SuppressLint("QueryPermissionsNeeded", "SetTextI18n")
override fun setView() { override fun setView() {
binding.tvUsedStorage.text = (requireActivity() as MainActivity).usedBytes.toFormatSize() val mainActivity = (requireActivity() as MainActivity)
binding.tvTotalStorage.text = " / ${(requireActivity() as MainActivity).totalBytes.toFormatSize()}" binding.tvUsedStorage.text = mainActivity.usedBytes.toFormatSize()
binding.tvTotalStorage.text = " / ${mainActivity.totalBytes.toFormatSize()}"
binding.tvPercent.text = "${(mainActivity.usedBytes * 100f / mainActivity.totalBytes).toInt()}"
adapter = MediaAdapter(0, adapter = MediaAdapter(0,
clickAction = { clickAction = {
...@@ -60,10 +58,6 @@ class FileFragment : BaseFragment<FragmentFileBinding>() { ...@@ -60,10 +58,6 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
moreAction(requireContext(), view, bean, adapter) moreAction(requireContext(), view, bean, adapter)
}) })
binding.rvRecent.adapter = adapter binding.rvRecent.adapter = adapter
if (requireContext().checkStorePermission()) {
initData()
}
} }
companion object { companion object {
...@@ -89,7 +83,7 @@ class FileFragment : BaseFragment<FragmentFileBinding>() { ...@@ -89,7 +83,7 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
val launcher = (requireActivity() as MainActivity).launcher val launcher = (requireActivity() as MainActivity).launcher
requireContext().requestStorePermission(launcher) { requireContext().requestStorePermission(launcher) {
if (it) { if (it) {
initData() // initData()
} }
} }
} }
...@@ -136,6 +130,7 @@ class FileFragment : BaseFragment<FragmentFileBinding>() { ...@@ -136,6 +130,7 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
if (requireContext().checkStorePermission()) { if (requireContext().checkStorePermission()) {
binding.llPermission.visibility = View.GONE binding.llPermission.visibility = View.GONE
initData()
} else { } else {
binding.llPermission.visibility = View.VISIBLE binding.llPermission.visibility = View.VISIBLE
} }
...@@ -143,27 +138,65 @@ class FileFragment : BaseFragment<FragmentFileBinding>() { ...@@ -143,27 +138,65 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
private fun initData() = lifecycleScope.launch(Dispatchers.IO) { private fun initData() = lifecycleScope.launch(Dispatchers.IO) {
val pictureSize = requireContext().getMediaPhotoSize() val picturePair = requireContext().getMediaPhotoCountSize()
val videoSize = requireContext().getMediaVideoSize() val videoPair = requireContext().getMediaVideoCountSize()
val documentSize = requireContext().getMediaDocumentSize() val documentSize = requireContext().getMediaDocumentCountSize()
val apkSize = requireContext().getMediaApkSize() val apkSize = requireContext().getMediaApkCountSize()
val audioSize = requireContext().getMediaAudioSize() val audioPair = requireContext().getMediaAudioCountSize()
val zipSize = requireContext().getMediaZipSize() val zipSize = requireContext().getMediaZipCountSize()
val mainActivity = (requireActivity() as MainActivity)
val totalAngle = (mainActivity.usedBytes.toFloat() / mainActivity.totalBytes.toFloat()) * 360f
val appSize = mainActivity.usedBytes - videoPair.second - picturePair.second - audioPair.second
progressList.clear()
var appAngle = (appSize * totalAngle / mainActivity.usedBytes)
val random = (appAngle / 5).toInt()
appAngle -= random
val appBean = ProgressBean(0f, appAngle, "#FD412F")
progressList.add(appBean)
val videoAngle = (videoPair.second * totalAngle / mainActivity.usedBytes) + random / 3
val videoBean = ProgressBean(appBean.sweepAngle, appBean.sweepAngle + videoAngle, "#FDC734")
progressList.add(videoBean)
val photoAngle = (picturePair.second * totalAngle / mainActivity.usedBytes) + random / 3
val photoBean = ProgressBean(videoBean.sweepAngle, videoBean.sweepAngle + photoAngle, "#00BE78")
progressList.add(photoBean)
val audioAngle = (audioPair.second * totalAngle / mainActivity.usedBytes) + random / 3
val audioBean = ProgressBean(photoBean.sweepAngle, photoBean.sweepAngle + audioAngle, "#8238FD")
progressList.add(audioBean)
progressList.reverse()
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
binding.tvPhotoSize.text = pictureSize.toString() binding.tvPhotoSize.text = picturePair.first.toString()
binding.tvVideoSize.text = videoSize.toString() binding.tvVideoSize.text = videoPair.first.toString()
binding.tvAudioSize.text = audioPair.first.toString()
binding.tvDocument.text = documentSize.toString() binding.tvDocument.text = documentSize.toString()
binding.tvApkSize.text = apkSize.toString() binding.tvApkSize.text = apkSize.toString()
binding.tvAudioSize.text = audioSize.toString()
binding.tvZipSize.text = zipSize.toString() binding.tvZipSize.text = zipSize.toString()
binding.colorProgress.animateProgress(
// listOf(
// ProgressBean(155f, 180f, "#8238FD"),//music
// ProgressBean(108f, 155f, "#00BE78"),//photo
// ProgressBean(65f, 108f, "#FDC734"),//vide
// ProgressBean(0f, 65f, "#FD412F"),//app
// )
progressList
)
} }
val mediaList = requireContext().getMediaFile().filter { val mediaList = requireContext().getMediaFile().filter {
val file = File(it.path) val file = File(it.path)
if (BuildConfig.DEBUG) {
true
} else {
System.currentTimeMillis() - file.lastModified() <= 15L * 24 * 60 * 60 * 1000 System.currentTimeMillis() - file.lastModified() <= 15L * 24 * 60 * 60 * 1000
} }
}
LogEx.logDebug(TAG, "size=${mediaList.size}") LogEx.logDebug(TAG, "size=${mediaList.size}")
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
if (mediaList.isEmpty()) { if (mediaList.isEmpty()) {
......
package com.base.browserwhite.ui.views
import android.animation.AnimatorSet
import android.animation.ValueAnimator
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import android.util.AttributeSet
import android.view.View
import android.view.animation.LinearInterpolator
import com.base.browserwhite.R
class ColorProgress : View {
private lateinit var ringPaint: Paint//圆环笔
private var centerX = 0f
private var centerY = 0f
private var radius = 0f
private var strokeWidth = 0f // 圆环的宽度
private lateinit var ringRectF: RectF
private lateinit var progressRectF: RectF
private lateinit var progressPaint: Paint
private var listProgressBean: List<ProgressBean> = listOf()
private var currentAngle = 0f
constructor(context: Context) : super(context) {
initPaint(context)
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
initPaint(context)
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
initPaint(context)
}
private fun initPaint(context: Context) {
strokeWidth = context.resources.getDimension(R.dimen.dp_9)
ringPaint = Paint()
ringPaint.isAntiAlias = true
ringPaint.style = Paint.Style.STROKE
ringPaint.setColor(Color.parseColor("#E6E7EC"))
ringPaint.strokeWidth = strokeWidth
progressPaint = Paint()
progressPaint.isAntiAlias = true
progressPaint.style = Paint.Style.STROKE
progressPaint.strokeWidth = strokeWidth
progressPaint.strokeCap = Paint.Cap.ROUND
// 初始化圆的中心点和半径
centerX = width / 2.0f
centerY = height / 2.0f
radius = centerX.coerceAtMost(centerY) - strokeWidth / 2 // 减去一半的描边宽度以避免超出边界
}
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
centerX = w / 2.0f
centerY = h / 2.0f
radius = centerX.coerceAtMost(centerY) - strokeWidth / 2
ringRectF = RectF(centerX - radius, centerY - radius, centerX + radius, centerY + radius)
progressRectF = RectF(centerX - radius, centerY - radius, centerX + radius, centerY + radius)
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
// 绘制圆环
canvas.drawOval(ringRectF, ringPaint)
listProgressBean.forEachIndexed { index, progressBean ->
progressPaint.setColor(Color.parseColor(progressBean.color))
if (index != 0) {
val lastProgressBean: ProgressBean = listProgressBean[index - 1]
if (currentAngle <= progressBean.sweepAngle) {
canvas.drawArc(progressRectF, -90f, currentAngle, false, progressPaint)
progressBean.draw = true
} else if (lastProgressBean.draw) {
canvas.drawArc(progressRectF, -90f, progressBean.sweepAngle, false, progressPaint)
progressBean.draw = true
}
} else {
if (currentAngle >= progressBean.startAngle) {
canvas.drawArc(progressRectF, -90f, currentAngle, false, progressPaint)
progressBean.draw = true
}
}
}
}
private fun setProgress(angle: Float) {
currentAngle = angle
invalidate()
}
fun animateProgress( list: List<ProgressBean>) {
listProgressBean = list
val totalAngle = list.maxOf { it.sweepAngle }
val progressAnimator = ValueAnimator.ofFloat(0f, totalAngle)
progressAnimator.interpolator = LinearInterpolator() // 平滑插值器
progressAnimator.setDuration(1500) // 动画持续时间1000毫秒
progressAnimator.addUpdateListener { animation ->
val animatedValue = animation.getAnimatedValue() as Float
setProgress(animatedValue)
}
progressAnimator.start()
}
}
data class ProgressBean(
val startAngle: Float = 0f,
val sweepAngle: Float = 0f,
var color: String = ""
) {
var draw = false
}
\ No newline at end of file
package com.base.browserwhite.utils package com.base.browserwhite.utils
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.database.Cursor import android.database.Cursor
import android.media.MediaScannerConnection import android.media.MediaScannerConnection
...@@ -124,28 +125,31 @@ object MediaStoreUtils { ...@@ -124,28 +125,31 @@ object MediaStoreUtils {
} }
fun Context.getMediaPhotoSize(): Int { @SuppressLint("Range")
fun Context.getMediaPhotoCountSize(): Pair<Int, Long> {
var count = 0 var count = 0
var totalSize = 0L
runCatching { runCatching {
val contentResolver = this.contentResolver val contentResolver = this.contentResolver
// 定义查询的Uri和列 // 定义查询的Uri和列
val uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI val uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
val projection = arrayOf(MediaStore.Images.Media._ID) val projection = arrayOf(MediaStore.Images.Media._ID, MediaStore.Images.Media.SIZE)
// 执行查询 // 执行查询
val cursor = contentResolver.query(uri, projection, null, null, null) val cursor = contentResolver.query(uri, projection, null, null, null)
// 检查cursor是否包含数据 // 检查cursor是否包含数据
count = cursor?.count ?: 0 count = cursor?.count ?: 0
while (cursor?.moveToNext() == true) {
totalSize += cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media.SIZE))
}
// 关闭cursor // 关闭cursor
cursor?.close() cursor?.close()
} }
return count return Pair(count, totalSize)
} }
fun Context.getMediaPhoto(): List<MediaBean> { fun Context.getMediaPhoto(): List<MediaBean> {
...@@ -248,50 +252,64 @@ object MediaStoreUtils { ...@@ -248,50 +252,64 @@ object MediaStoreUtils {
} }
fun Context.getMediaVideoSize(): Int { @SuppressLint("Range")
fun Context.getMediaVideoCountSize(): Pair<Int, Long> {
var count = 0 var count = 0
var totalSize: Long = 0
runCatching { runCatching {
val contentResolver = this.contentResolver val contentResolver = this.contentResolver
// 定义查询的Uri和列 // 定义查询的Uri和列
val uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI val uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI
val projection = arrayOf(MediaStore.Video.Media._ID) val projection = arrayOf(MediaStore.Video.Media._ID, MediaStore.Video.Media.SIZE)
// 执行查询 // 执行查询
val cursor = contentResolver.query(uri, projection, null, null, null) val cursor = contentResolver.query(uri, projection, null, null, null)
// 检查cursor是否包含数据 // 检查cursor是否包含数据
count = cursor?.count ?: 0 count = cursor?.count ?: 0
while (cursor?.moveToNext() == true) {
totalSize += cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media.SIZE))
}
// 关闭cursor // 关闭cursor
cursor?.close() cursor?.close()
} }
return count return Pair(count, totalSize)
} }
fun Context.getMediaAudioSize(): Int { @SuppressLint("Range")
fun Context.getMediaAudioCountSize(): Pair<Int, Long> {
var count = 0 var count = 0
var totalSize: Long = 0
runCatching { runCatching {
val contentResolver = this.contentResolver val contentResolver = this.contentResolver
// 定义查询的Uri和列 // 定义查询的Uri和列
val uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI val uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
val projection = arrayOf(MediaStore.Audio.Media._ID) val projection = arrayOf(
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.SIZE,
)
// 执行查询 // 执行查询
val cursor = contentResolver.query(uri, projection, null, null, null) val cursor = contentResolver.query(uri, projection, null, null, null)
// 检查cursor是否包含数据 // 检查cursor是否包含数据
count = cursor?.count ?: 0 count = cursor?.count ?: 0
while (cursor?.moveToNext() == true) {
totalSize += cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.SIZE))
}
// 关闭cursor // 关闭cursor
cursor?.close() cursor?.close()
} }
return count return Pair(count, totalSize)
} }
fun Context.getMediaDocumentSize(): Int { fun Context.getMediaDocumentCountSize(): Int {
var count = 0 var count = 0
runCatching { runCatching {
val contentResolver = this.contentResolver val contentResolver = this.contentResolver
...@@ -324,7 +342,7 @@ object MediaStoreUtils { ...@@ -324,7 +342,7 @@ object MediaStoreUtils {
return count return count
} }
fun Context.getMediaApkSize(): Int { fun Context.getMediaApkCountSize(): Int {
var count = 0 var count = 0
runCatching { runCatching {
val contentResolver = this.contentResolver val contentResolver = this.contentResolver
...@@ -350,7 +368,7 @@ object MediaStoreUtils { ...@@ -350,7 +368,7 @@ object MediaStoreUtils {
return count return count
} }
fun Context.getMediaZipSize(): Int { fun Context.getMediaZipCountSize(): Int {
var count = 0 var count = 0
runCatching { runCatching {
val contentResolver = this.contentResolver val contentResolver = this.contentResolver
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
android:layout_height="105dp" android:layout_height="105dp"
android:layout_marginHorizontal="16dp" android:layout_marginHorizontal="16dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
app:cardBackgroundColor="#DEE9F4" app:cardBackgroundColor="#EEF7FF"
app:cardCornerRadius="15dp"> app:cardCornerRadius="15dp">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />
<LinearLayout <LinearLayout
android:id="@+id/linearLayout"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
...@@ -205,6 +206,43 @@ ...@@ -205,6 +206,43 @@
</LinearLayout> </LinearLayout>
<com.base.browserwhite.ui.views.ColorProgress
android:id="@+id/colorProgress"
android:layout_width="78dp"
android:layout_height="78dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/linearLayout"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="@id/colorProgress"
app:layout_constraintEnd_toEndOf="@id/colorProgress"
app:layout_constraintStart_toStartOf="@id/colorProgress"
app:layout_constraintTop_toTopOf="@id/colorProgress">
<TextView
android:id="@+id/tv_percent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="19sp"
android:textStyle="bold"
tools:text="100" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:text="%"
android:textColor="@color/black"
android:textSize="13sp"
tools:ignore="HardcodedText" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
......
...@@ -10,4 +10,6 @@ ...@@ -10,4 +10,6 @@
<dimen name="dp_30">30dp</dimen> <dimen name="dp_30">30dp</dimen>
<dimen name="fab_margin">16dp</dimen> <dimen name="fab_margin">16dp</dimen>
<dimen name="dp_335">335dp</dimen> <dimen name="dp_335">335dp</dimen>
<dimen name="dp_9">9dp</dimen>
<dimen name="dp_5">5dp</dimen>
</resources> </resources>
\ 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