From 9396d41dccd16435b0a1e608475dd45d2471918d Mon Sep 17 00:00:00 2001 From: Anderson Mesquita Date: Thu, 25 Apr 2019 18:39:46 -0400 Subject: [PATCH] Add space usage bar to data folder dialog This displays a progress bar with the amount of used/free space in each storage location to make it easier to identify storage devices. This is particularly useful for devices that use non-standard names. Reference: #3049 --- .../antennapod/adapter/DataFolderAdapter.java | 12 ++++++++++++ .../res/layout/choose_data_folder_dialog_entry.xml | 8 ++++++++ .../danoeh/antennapod/core/util/StorageUtils.java | 14 ++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DataFolderAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DataFolderAdapter.java index f2a074b9d..f625dcc0c 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/DataFolderAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/DataFolderAdapter.java @@ -20,6 +20,7 @@ import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.StorageUtils; import de.danoeh.antennapod.dialog.ChooseDataFolderDialog; +import me.zhanghai.android.materialprogressbar.MaterialProgressBar; public class DataFolderAdapter extends RecyclerView.Adapter { @@ -47,6 +48,7 @@ public class DataFolderAdapter extends RecyclerView.Adapter selectAndDismiss(storagePath)); holder.radioButton.setOnClickListener((View v) -> selectAndDismiss(storagePath)); if (storagePath.getFullPath().equals(currentPath)) { @@ -98,6 +100,7 @@ public class DataFolderAdapter extends RecyclerView.Adapter + + diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java index 3a6bf5755..414b5c781 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java @@ -74,4 +74,18 @@ public class StorageUtils { } return availableBlocks * blockSize; } + + public static long getTotalSpaceAvailable(String path) { + StatFs stat = new StatFs(path); + long blockCount; + long blockSize; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + blockCount = stat.getBlockCountLong(); + blockSize = stat.getBlockSizeLong(); + } else { + blockCount = stat.getBlockCount(); + blockSize = stat.getBlockSize(); + } + return blockCount * blockSize; + } }