From b58e509633e89920f854c062045815e18f2c128b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Wed, 6 Sep 2023 18:41:31 +0200 Subject: [PATCH 1/6] Add SD card to storage analysis This closes #678 --- .../pro/activities/MimeTypesActivity.kt | 4 +- .../filemanager/pro/extensions/Context.kt | 21 ++ .../pro/fragments/StorageFragment.kt | 216 +++++++----- .../filemanager/pro/helpers/Constants.kt | 3 + .../res/drawable/ic_arrow_down_vector.xml | 5 + .../main/res/drawable/ic_arrow_up_vector.xml | 5 + .../main/res/layout/item_storage_volume.xml | 328 ++++++++++++++++++ app/src/main/res/layout/storage_fragment.xml | 305 +--------------- 8 files changed, 504 insertions(+), 383 deletions(-) create mode 100644 app/src/main/res/drawable/ic_arrow_down_vector.xml create mode 100644 app/src/main/res/drawable/ic_arrow_up_vector.xml create mode 100644 app/src/main/res/layout/item_storage_volume.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt index 85942400..60c26b93 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt @@ -40,6 +40,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener { private var zoomListener: MyRecyclerView.MyZoomListener? = null private var storedItems = ArrayList() private var currentViewType = VIEW_TYPE_LIST + private var currentVolume = PRIMARY_VOLUME_NAME override fun onCreate(savedInstanceState: Bundle?) { isMaterialActivity = true @@ -53,6 +54,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener { } currentMimeType = intent.getStringExtra(SHOW_MIMETYPE) ?: return + currentVolume = intent.getStringExtra(VOLUME_NAME) ?: currentVolume binding.mimetypesToolbar.title = getString( when (currentMimeType) { IMAGES -> R.string.images @@ -267,7 +269,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener { private fun getProperFileDirItems(callback: (ArrayList) -> Unit) { val fileDirItems = ArrayList() val showHidden = config.shouldShowHidden() - val uri = MediaStore.Files.getContentUri("external") + val uri = MediaStore.Files.getContentUri(currentVolume) val projection = arrayOf( MediaStore.Files.FileColumns.MIME_TYPE, MediaStore.Files.FileColumns.DATA, diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt index 07b1f5f5..7ecddf06 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt @@ -1,10 +1,31 @@ package com.simplemobiletools.filemanager.pro.extensions import android.content.Context +import android.os.storage.StorageManager import com.simplemobiletools.commons.extensions.isPathOnOTG import com.simplemobiletools.commons.extensions.isPathOnSD +import com.simplemobiletools.commons.extensions.otgPath +import com.simplemobiletools.commons.extensions.updateOTGPathFromPartition +import com.simplemobiletools.commons.helpers.isNougatPlus import com.simplemobiletools.filemanager.pro.helpers.Config +import com.simplemobiletools.filemanager.pro.helpers.PRIMARY_VOLUME_NAME +import java.util.Locale val Context.config: Config get() = Config.newInstance(applicationContext) fun Context.isPathOnRoot(path: String) = !(path.startsWith(config.internalStoragePath) || isPathOnOTG(path) || (isPathOnSD(path))) + +fun Context.getAllVolumeNames(): List { + val volumeNames = mutableListOf(PRIMARY_VOLUME_NAME) + if (isNougatPlus()) { + val storageManager = getSystemService(Context.STORAGE_SERVICE) as StorageManager + getExternalFilesDirs(null) + .mapNotNull { storageManager.getStorageVolume(it) } + .filterNot { it.isPrimary } + .mapNotNull { it.uuid?.lowercase(Locale.US) } + .forEach { + volumeNames.add(it) + } + } + return volumeNames +} diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt index 6db802c8..5edf93f4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt @@ -7,12 +7,15 @@ import android.content.ContentResolver import android.content.Context import android.content.Intent import android.os.Handler +import android.os.Looper import android.os.storage.StorageManager import android.provider.MediaStore import android.provider.Settings import android.util.AttributeSet import androidx.appcompat.app.AppCompatActivity import androidx.core.os.bundleOf +import androidx.core.view.children +import androidx.core.view.isVisible import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.FileDirItem @@ -21,9 +24,11 @@ import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.activities.MimeTypesActivity import com.simplemobiletools.filemanager.pro.activities.SimpleActivity import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter +import com.simplemobiletools.filemanager.pro.databinding.ItemStorageVolumeBinding import com.simplemobiletools.filemanager.pro.databinding.StorageFragmentBinding import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.extensions.formatSizeThousand +import com.simplemobiletools.filemanager.pro.extensions.getAllVolumeNames import com.simplemobiletools.filemanager.pro.helpers.* import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener import com.simplemobiletools.filemanager.pro.models.ListItem @@ -35,6 +40,7 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage private var allDeviceListItems = ArrayList() private var lastSearchedText = "" private lateinit var binding: StorageFragmentBinding + private val volumes = mutableMapOf() override fun onFinishInflate() { super.onFinishInflate() @@ -47,88 +53,132 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage this.activity = activity } - binding.totalSpace.text = String.format(context.getString(R.string.total_storage), "…") - getSizes() + val volumeNames = activity.getAllVolumeNames() + volumeNames.forEach { volumeName -> + val volumeBinding = ItemStorageVolumeBinding.inflate(activity.layoutInflater) + volumes[volumeName] = volumeBinding + volumeBinding.apply { + if (volumeName == PRIMARY_VOLUME_NAME) { + storageName.setText(R.string.internal) + } else { + storageName.setText(R.string.sd_card) + } - binding.freeSpaceHolder.setOnClickListener { - try { - val storageSettingsIntent = Intent(Settings.ACTION_INTERNAL_STORAGE_SETTINGS) - activity.startActivity(storageSettingsIntent) - } catch (e: Exception) { - activity.showErrorToast(e) + totalSpace.text = String.format(context.getString(R.string.total_storage), "…") + getSizes(volumeName) + + if (volumeNames.size > 1) { + root.children.forEach { it.beGone() } + freeSpaceHolder.beVisible() + expandButton.applyColorFilter(context.getProperPrimaryColor()) + expandButton.setImageResource(R.drawable.ic_arrow_down_vector) + + expandButton.setOnClickListener { _ -> + if (imagesHolder.isVisible) { + root.children.filterNot { it == freeSpaceHolder }.forEach { it.beGone() } + expandButton.setImageResource(R.drawable.ic_arrow_down_vector) + } else { + root.children.filterNot { it == freeSpaceHolder }.forEach { it.beVisible() } + expandButton.setImageResource(R.drawable.ic_arrow_up_vector) + } + } + } else { + expandButton.beGone() + } + + freeSpaceHolder.setOnClickListener { + try { + val storageSettingsIntent = Intent(Settings.ACTION_INTERNAL_STORAGE_SETTINGS) + activity.startActivity(storageSettingsIntent) + } catch (e: Exception) { + activity.showErrorToast(e) + } + } + + imagesHolder.setOnClickListener { launchMimetypeActivity(IMAGES, volumeName) } + videosHolder.setOnClickListener { launchMimetypeActivity(VIDEOS, volumeName) } + audioHolder.setOnClickListener { launchMimetypeActivity(AUDIO, volumeName) } + documentsHolder.setOnClickListener { launchMimetypeActivity(DOCUMENTS, volumeName) } + archivesHolder.setOnClickListener { launchMimetypeActivity(ARCHIVES, volumeName) } + othersHolder.setOnClickListener { launchMimetypeActivity(OTHERS, volumeName) } } + binding.storageVolumesHolder.addView(volumeBinding.root) } - binding.apply { - imagesHolder.setOnClickListener { launchMimetypeActivity(IMAGES) } - videosHolder.setOnClickListener { launchMimetypeActivity(VIDEOS) } - audioHolder.setOnClickListener { launchMimetypeActivity(AUDIO) } - documentsHolder.setOnClickListener { launchMimetypeActivity(DOCUMENTS) } - archivesHolder.setOnClickListener { launchMimetypeActivity(ARCHIVES) } - othersHolder.setOnClickListener { launchMimetypeActivity(OTHERS) } + ensureBackgroundThread { + getVolumeStorageStats(context) } - Handler().postDelayed({ + Handler(Looper.getMainLooper()).postDelayed({ refreshFragment() }, 2000) } override fun onResume(textColor: Int) { - getSizes() context.updateTextColors(binding.root) + val properPrimaryColor = context.getProperPrimaryColor() + val redColor = context.resources.getColor(R.color.md_red_700) + val greenColor = context.resources.getColor(R.color.md_green_700) + val lightBlueColor = context.resources.getColor(R.color.md_light_blue_700) + val yellowColor = context.resources.getColor(R.color.md_yellow_700) + val tealColor = context.resources.getColor(R.color.md_teal_700) + val pinkColor = context.resources.getColor(R.color.md_pink_700) + + volumes.entries.forEach { (it, volumeBinding) -> + getSizes(it) + volumeBinding.apply { + mainStorageUsageProgressbar.setIndicatorColor(properPrimaryColor) + mainStorageUsageProgressbar.trackColor = properPrimaryColor.adjustAlpha(LOWER_ALPHA) + + imagesProgressbar.setIndicatorColor(redColor) + imagesProgressbar.trackColor = redColor.adjustAlpha(LOWER_ALPHA) + + videosProgressbar.setIndicatorColor(greenColor) + videosProgressbar.trackColor = greenColor.adjustAlpha(LOWER_ALPHA) + + audioProgressbar.setIndicatorColor(lightBlueColor) + audioProgressbar.trackColor = lightBlueColor.adjustAlpha(LOWER_ALPHA) + + documentsProgressbar.setIndicatorColor(yellowColor) + documentsProgressbar.trackColor = yellowColor.adjustAlpha(LOWER_ALPHA) + + archivesProgressbar.setIndicatorColor(tealColor) + archivesProgressbar.trackColor = tealColor.adjustAlpha(LOWER_ALPHA) + + othersProgressbar.setIndicatorColor(pinkColor) + othersProgressbar.trackColor = pinkColor.adjustAlpha(LOWER_ALPHA) + + expandButton.applyColorFilter(context.getProperPrimaryColor()) + } + } + binding.apply { - val properPrimaryColor = context.getProperPrimaryColor() - mainStorageUsageProgressbar.setIndicatorColor(properPrimaryColor) - mainStorageUsageProgressbar.trackColor = properPrimaryColor.adjustAlpha(LOWER_ALPHA) - - val redColor = context.resources.getColor(R.color.md_red_700) - imagesProgressbar.setIndicatorColor(redColor) - imagesProgressbar.trackColor = redColor.adjustAlpha(LOWER_ALPHA) - - val greenColor = context.resources.getColor(R.color.md_green_700) - videosProgressbar.setIndicatorColor(greenColor) - videosProgressbar.trackColor = greenColor.adjustAlpha(LOWER_ALPHA) - - val lightBlueColor = context.resources.getColor(R.color.md_light_blue_700) - audioProgressbar.setIndicatorColor(lightBlueColor) - audioProgressbar.trackColor = lightBlueColor.adjustAlpha(LOWER_ALPHA) - - val yellowColor = context.resources.getColor(R.color.md_yellow_700) - documentsProgressbar.setIndicatorColor(yellowColor) - documentsProgressbar.trackColor = yellowColor.adjustAlpha(LOWER_ALPHA) - - val tealColor = context.resources.getColor(R.color.md_teal_700) - archivesProgressbar.setIndicatorColor(tealColor) - archivesProgressbar.trackColor = tealColor.adjustAlpha(LOWER_ALPHA) - - val pinkColor = context.resources.getColor(R.color.md_pink_700) - othersProgressbar.setIndicatorColor(pinkColor) - othersProgressbar.trackColor = pinkColor.adjustAlpha(LOWER_ALPHA) - searchHolder.setBackgroundColor(context.getProperBackgroundColor()) progressBar.setIndicatorColor(properPrimaryColor) progressBar.trackColor = properPrimaryColor.adjustAlpha(LOWER_ALPHA) } + ensureBackgroundThread { + getVolumeStorageStats(context) + } } - private fun launchMimetypeActivity(mimetype: String) { + private fun launchMimetypeActivity(mimetype: String, volumeName: String) { Intent(context, MimeTypesActivity::class.java).apply { putExtra(SHOW_MIMETYPE, mimetype) + putExtra(VOLUME_NAME, volumeName) context.startActivity(this) } } - private fun getSizes() { + private fun getSizes(volumeName: String) { if (!isOreoPlus()) { return } ensureBackgroundThread { - getMainStorageStats(context) - - val filesSize = getSizesByMimeType() + val filesSize = getSizesByMimeType(volumeName) val fileSizeImages = filesSize[IMAGES]!! val fileSizeVideos = filesSize[VIDEOS]!! val fileSizeAudios = filesSize[AUDIO]!! @@ -137,7 +187,7 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage val fileSizeOthers = filesSize[OTHERS]!! post { - binding.apply { + volumes[volumeName]!!.apply { imagesSize.text = fileSizeImages.formatSize() imagesProgressbar.progress = (fileSizeImages / SIZE_DIVIDER).toInt() @@ -160,8 +210,8 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage } } - private fun getSizesByMimeType(): HashMap { - val uri = MediaStore.Files.getContentUri("external") + private fun getSizesByMimeType(volumeName: String): HashMap { + val uri = MediaStore.Files.getContentUri(volumeName) val projection = arrayOf( MediaStore.Files.FileColumns.SIZE, MediaStore.Files.FileColumns.MIME_TYPE, @@ -222,40 +272,44 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage } @SuppressLint("NewApi") - private fun getMainStorageStats(context: Context) { + private fun getVolumeStorageStats(context: Context) { val externalDirs = context.getExternalFilesDirs(null) val storageManager = context.getSystemService(AppCompatActivity.STORAGE_SERVICE) as StorageManager externalDirs.forEach { file -> + val volumeName: String + val totalStorageSpace: Long + val freeStorageSpace: Long val storageVolume = storageManager.getStorageVolume(file) ?: return if (storageVolume.isPrimary) { // internal storage + volumeName = PRIMARY_VOLUME_NAME val storageStatsManager = context.getSystemService(AppCompatActivity.STORAGE_STATS_SERVICE) as StorageStatsManager val uuid = StorageManager.UUID_DEFAULT - val totalStorageSpace = storageStatsManager.getTotalBytes(uuid) - val freeStorageSpace = storageStatsManager.getFreeBytes(uuid) - - post { - binding.apply { - arrayOf( - mainStorageUsageProgressbar, imagesProgressbar, videosProgressbar, audioProgressbar, documentsProgressbar, - archivesProgressbar, othersProgressbar - ).forEach { - it.max = (totalStorageSpace / SIZE_DIVIDER).toInt() - } - - mainStorageUsageProgressbar.progress = ((totalStorageSpace - freeStorageSpace) / SIZE_DIVIDER).toInt() - - mainStorageUsageProgressbar.beVisible() - freeSpaceValue.text = freeStorageSpace.formatSizeThousand() - totalSpace.text = String.format(context.getString(R.string.total_storage), totalStorageSpace.formatSizeThousand()) - freeSpaceLabel.beVisible() - } - } + totalStorageSpace = storageStatsManager.getTotalBytes(uuid) + freeStorageSpace = storageStatsManager.getFreeBytes(uuid) } else { - // sd card - val totalSpace = file.totalSpace - val freeSpace = file.freeSpace + volumeName = storageVolume.uuid!!.lowercase(Locale.US) + totalStorageSpace = file.totalSpace + freeStorageSpace = file.freeSpace + } + + post { + volumes[volumeName]?.apply { + arrayOf( + mainStorageUsageProgressbar, imagesProgressbar, videosProgressbar, audioProgressbar, documentsProgressbar, + archivesProgressbar, othersProgressbar + ).forEach { + it.max = (totalStorageSpace / SIZE_DIVIDER).toInt() + } + + mainStorageUsageProgressbar.progress = ((totalStorageSpace - freeStorageSpace) / SIZE_DIVIDER).toInt() + + mainStorageUsageProgressbar.beVisible() + freeSpaceValue.text = freeStorageSpace.formatSizeThousand() + totalSpace.text = String.format(context.getString(R.string.total_storage), totalStorageSpace.formatSizeThousand()) + freeSpaceLabel.beVisible() + } } } } @@ -334,10 +388,10 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage } } - private fun getAllFiles(): ArrayList { + private fun getAllFiles(volumeName: String): ArrayList { val fileDirItems = ArrayList() val showHidden = context?.config?.shouldShowHidden() ?: return fileDirItems - val uri = MediaStore.Files.getContentUri("external") + val uri = MediaStore.Files.getContentUri(volumeName) val projection = arrayOf( MediaStore.Files.FileColumns.DATA, MediaStore.Files.FileColumns.DISPLAY_NAME, @@ -396,8 +450,8 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage override fun refreshFragment() { ensureBackgroundThread { - val fileDirItems = getAllFiles() - allDeviceListItems = getListItemsFromFileDirItems(fileDirItems) + val fileDirItems = volumes.keys.map { getAllFiles(it) }.flatten() + allDeviceListItems = getListItemsFromFileDirItems(ArrayList(fileDirItems)) } setupLayoutManager() } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt index ff9cab7e..f562f74d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt @@ -41,6 +41,9 @@ const val ARCHIVES = "archives" const val OTHERS = "others" const val SHOW_MIMETYPE = "show_mimetype" +const val VOLUME_NAME = "volume_name" +const val PRIMARY_VOLUME_NAME = "external" + // what else should we count as an audio except "audio/*" mimetype val extraAudioMimeTypes = arrayListOf("application/ogg") val extraDocumentMimeTypes = arrayListOf( diff --git a/app/src/main/res/drawable/ic_arrow_down_vector.xml b/app/src/main/res/drawable/ic_arrow_down_vector.xml new file mode 100644 index 00000000..1aeaa998 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_down_vector.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_arrow_up_vector.xml b/app/src/main/res/drawable/ic_arrow_up_vector.xml new file mode 100644 index 00000000..1d112693 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_up_vector.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/item_storage_volume.xml b/app/src/main/res/layout/item_storage_volume.xml new file mode 100644 index 00000000..2f84d9cf --- /dev/null +++ b/app/src/main/res/layout/item_storage_volume.xml @@ -0,0 +1,328 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/storage_fragment.xml b/app/src/main/res/layout/storage_fragment.xml index 00ca6c97..7a52a657 100644 --- a/app/src/main/res/layout/storage_fragment.xml +++ b/app/src/main/res/layout/storage_fragment.xml @@ -11,309 +11,12 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + android:layout_height="wrap_content" + android:orientation="vertical" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Date: Thu, 7 Sep 2023 11:21:00 +0200 Subject: [PATCH 2/6] Ensure SDCard files get scanned on StorageFragment --- .../pro/fragments/StorageFragment.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt index 5edf93f4..fc4997f4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt @@ -6,6 +6,7 @@ import android.app.usage.StorageStatsManager import android.content.ContentResolver import android.content.Context import android.content.Intent +import android.media.MediaScannerConnection import android.os.Handler import android.os.Looper import android.os.storage.StorageManager @@ -32,6 +33,7 @@ import com.simplemobiletools.filemanager.pro.extensions.getAllVolumeNames import com.simplemobiletools.filemanager.pro.helpers.* import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener import com.simplemobiletools.filemanager.pro.models.ListItem +import java.io.File import java.util.* class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), @@ -292,6 +294,11 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage volumeName = storageVolume.uuid!!.lowercase(Locale.US) totalStorageSpace = file.totalSpace freeStorageSpace = file.freeSpace + post { + ensureBackgroundThread { + scanVolume(volumeName, file) + } + } } post { @@ -314,6 +321,22 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage } } + private fun scanVolume(volumeName: String, root: File) { + val paths = mutableListOf() + if (context.isPathOnSD(root.path)) { + File(context.config.sdCardPath).walkBottomUp().forEach { + paths.add(it.path) + } + } + var callbackCount = 0 + MediaScannerConnection.scanFile(context, paths.toTypedArray(), null) { _, _ -> + callbackCount++ + if (callbackCount == paths.size) { + getSizes(volumeName) + } + } + } + override fun searchQueryChanged(text: String) { lastSearchedText = text binding.apply { From a0419ed02cbe56366135c603a7792838746fac08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 7 Sep 2023 11:44:16 +0200 Subject: [PATCH 3/6] Use context access to sdCardPath --- .../filemanager/pro/fragments/StorageFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt index fc4997f4..327ac5df 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt @@ -324,7 +324,7 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage private fun scanVolume(volumeName: String, root: File) { val paths = mutableListOf() if (context.isPathOnSD(root.path)) { - File(context.config.sdCardPath).walkBottomUp().forEach { + File(context.sdCardPath).walkBottomUp().forEach { paths.add(it.path) } } From fbaacdb4129e692e0c62b1c2d64ceae105999b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 7 Sep 2023 12:32:09 +0200 Subject: [PATCH 4/6] Separate internal storage from SD storage in StorageFragment --- .../com/simplemobiletools/filemanager/pro/helpers/Constants.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt index f562f74d..28e1ae40 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt @@ -42,7 +42,7 @@ const val OTHERS = "others" const val SHOW_MIMETYPE = "show_mimetype" const val VOLUME_NAME = "volume_name" -const val PRIMARY_VOLUME_NAME = "external" +const val PRIMARY_VOLUME_NAME = "external_primary" // what else should we count as an audio except "audio/*" mimetype val extraAudioMimeTypes = arrayListOf("application/ogg") From 3919384928d87edf5114d66817be42b2e7b537c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 7 Sep 2023 12:35:24 +0200 Subject: [PATCH 5/6] Remove unused imports from Context extensions --- .../com/simplemobiletools/filemanager/pro/extensions/Context.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt index 7ecddf06..7c14deb9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt @@ -4,8 +4,6 @@ import android.content.Context import android.os.storage.StorageManager import com.simplemobiletools.commons.extensions.isPathOnOTG import com.simplemobiletools.commons.extensions.isPathOnSD -import com.simplemobiletools.commons.extensions.otgPath -import com.simplemobiletools.commons.extensions.updateOTGPathFromPartition import com.simplemobiletools.commons.helpers.isNougatPlus import com.simplemobiletools.filemanager.pro.helpers.Config import com.simplemobiletools.filemanager.pro.helpers.PRIMARY_VOLUME_NAME From 69bddaa3d7fb682cac01e7212d7a853c04a26e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 7 Sep 2023 12:57:31 +0200 Subject: [PATCH 6/6] Prevent crashes on devices before Oreo version --- .../filemanager/pro/fragments/StorageFragment.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt index 327ac5df..bd33401b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt @@ -286,10 +286,15 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage if (storageVolume.isPrimary) { // internal storage volumeName = PRIMARY_VOLUME_NAME - val storageStatsManager = context.getSystemService(AppCompatActivity.STORAGE_STATS_SERVICE) as StorageStatsManager - val uuid = StorageManager.UUID_DEFAULT - totalStorageSpace = storageStatsManager.getTotalBytes(uuid) - freeStorageSpace = storageStatsManager.getFreeBytes(uuid) + if (isOreoPlus()) { + val storageStatsManager = context.getSystemService(AppCompatActivity.STORAGE_STATS_SERVICE) as StorageStatsManager + val uuid = StorageManager.UUID_DEFAULT + totalStorageSpace = storageStatsManager.getTotalBytes(uuid) + freeStorageSpace = storageStatsManager.getFreeBytes(uuid) + } else { + totalStorageSpace = file.totalSpace + freeStorageSpace = file.freeSpace + } } else { volumeName = storageVolume.uuid!!.lowercase(Locale.US) totalStorageSpace = file.totalSpace