Commit afaef8d1 authored by wanglei's avatar wanglei

Merge remote-tracking branch 'origin/master'

parents 817b40e3 34704608
...@@ -73,7 +73,7 @@ object ActivityJumpHelps { ...@@ -73,7 +73,7 @@ object ActivityJumpHelps {
fun requestPermission( fun requestPermission(
context: Context, context: Context,
launcher: ActivityLauncher, launcher: ActivityLauncher,
block: (() -> Unit?)? = null block: (() -> Unit)? = null
) { ) {
if (PermissionHelps.checkFilesAccessPermission(context)) { if (PermissionHelps.checkFilesAccessPermission(context)) {
block?.invoke() block?.invoke()
......
...@@ -124,47 +124,49 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(FragmentHomeBinding::infl ...@@ -124,47 +124,49 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(FragmentHomeBinding::infl
} }
private fun initData() { private fun initData() {
lifecycleScope.launch(Dispatchers.IO) { ActivityJumpHelps.requestPermission(requireContext(), launcher) {
val totalStorage = async { AppHelps.getTotalExternalSize() } lifecycleScope.launch(Dispatchers.IO) {
val availableStorage = async { AppHelps.getAvailableExternalSize() } val totalStorage = async { AppHelps.getTotalExternalSize() }
val totalStorageSize = totalStorage.await() val availableStorage = async { AppHelps.getAvailableExternalSize() }
val availableStorageSize = availableStorage.await() val totalStorageSize = totalStorage.await()
val usedMemoryStorageSize = totalStorageSize - availableStorageSize val availableStorageSize = availableStorage.await()
val usedMemoryStorageScale = usedMemoryStorageSize * 100 / totalStorageSize val usedMemoryStorageSize = totalStorageSize - availableStorageSize
val usedMemoryStorageScale = usedMemoryStorageSize * 100 / totalStorageSize
val totalMemoryUsed = async { AppHelps.getMemTotal(requireContext()) } val totalMemoryUsed = async { AppHelps.getMemTotal(requireContext()) }
val availableMemoryUsed = async { AppHelps.getMemAvailable(requireContext()) } val availableMemoryUsed = async { AppHelps.getMemAvailable(requireContext()) }
val totalMemoryUsedSize = totalMemoryUsed.await() val totalMemoryUsedSize = totalMemoryUsed.await()
val availableMemoryUsedSize = availableMemoryUsed.await() val availableMemoryUsedSize = availableMemoryUsed.await()
val usedMemoryUsedSize = totalMemoryUsedSize - availableMemoryUsedSize val usedMemoryUsedSize = totalMemoryUsedSize - availableMemoryUsedSize
val usedMemoryUsedScale: Long = usedMemoryUsedSize * 100 / totalMemoryUsedSize val usedMemoryUsedScale: Long = usedMemoryUsedSize * 100 / totalMemoryUsedSize
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
binding.tvStorageUsed.text = "${usedMemoryStorageScale.toInt()}%" binding.tvStorageUsed.text = "${usedMemoryStorageScale.toInt()}%"
binding.tvMemoryUsed.text = "${usedMemoryUsedScale.toInt()}%" binding.tvMemoryUsed.text = "${usedMemoryUsedScale.toInt()}%"
binding.llStorageUsed.visibility = View.VISIBLE binding.llStorageUsed.visibility = View.VISIBLE
binding.llMemoryUsed.visibility = View.VISIBLE binding.llMemoryUsed.visibility = View.VISIBLE
AnimationHelps.progress(binding.pbStorageUsed, usedMemoryStorageScale.toInt()) AnimationHelps.progress(binding.pbStorageUsed, usedMemoryStorageScale.toInt())
AnimationHelps.progress(binding.pbMemoryUsed, usedMemoryUsedScale.toInt()) AnimationHelps.progress(binding.pbMemoryUsed, usedMemoryUsedScale.toInt())
}
} }
} lifecycleScope.launch(Dispatchers.IO) {
lifecycleScope.launch(Dispatchers.IO) { val emptyFoldersDeferred = async { FileHelps.findEmptyFolders(lifecycleScope) }
val emptyFoldersDeferred = async { FileHelps.findEmptyFolders(lifecycleScope) } val filesDeferred = async { MediaHelps.findSpecifiedFiles(requireContext()) }
val filesDeferred = async { MediaHelps.findSpecifiedFiles(requireContext()) } val emptyFolder = emptyFoldersDeferred.await()
val emptyFolder = emptyFoldersDeferred.await() val files = filesDeferred.await()
val files = filesDeferred.await() val emptyLength = emptyFolder.sumOf { it.length }
val emptyLength = emptyFolder.sumOf { it.length } val filesLength = files.sumOf { it.length }
val filesLength = files.sumOf { it.length } val totalLength = emptyLength + filesLength
val totalLength = emptyLength + filesLength val totalSize = Utils.getSize(totalLength)
val totalSize = Utils.getSize(totalLength) withContext(Dispatchers.Main) {
withContext(Dispatchers.Main) { val sp = SpannableString("$totalSize\n${getString(R.string.junk_files)}")
val sp = SpannableString("$totalSize\n${getString(R.string.junk_files)}") sp.setSpan(
sp.setSpan( AbsoluteSizeSpan(16, true),
AbsoluteSizeSpan(16, true), sp.indexOf("\n"),
sp.indexOf("\n"), sp.length,
sp.length, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE )
) binding.tvJunkFiles.text = sp
binding.tvJunkFiles.text = sp }
} }
} }
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
android:id="@+id/iv_icon" android:id="@+id/iv_icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="15dp" android:layout_marginTop="10dp"
android:src="@mipmap/icon_junk_scan" android:src="@mipmap/icon_junk_scan"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
......
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