mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2024-12-25 08:21:59 +01:00
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
This commit is contained in:
parent
683f7e46a2
commit
9396d41dcc
@ -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<DataFolderAdapter.ViewHolder> {
|
||||
@ -47,6 +48,7 @@ public class DataFolderAdapter extends RecyclerView.Adapter<DataFolderAdapter.Vi
|
||||
StoragePath storagePath = entries.get(position);
|
||||
holder.path.setText(storagePath.getShortPath());
|
||||
holder.size.setText(Converter.byteToString(storagePath.getAvailableSpace()));
|
||||
holder.progressBar.setProgress(storagePath.getUsagePercentage());
|
||||
holder.root.setOnClickListener((View v) -> selectAndDismiss(storagePath));
|
||||
holder.radioButton.setOnClickListener((View v) -> selectAndDismiss(storagePath));
|
||||
if (storagePath.getFullPath().equals(currentPath)) {
|
||||
@ -98,6 +100,7 @@ public class DataFolderAdapter extends RecyclerView.Adapter<DataFolderAdapter.Vi
|
||||
private TextView path;
|
||||
private TextView size;
|
||||
private RadioButton radioButton;
|
||||
private MaterialProgressBar progressBar;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
@ -105,6 +108,7 @@ public class DataFolderAdapter extends RecyclerView.Adapter<DataFolderAdapter.Vi
|
||||
path = itemView.findViewById(R.id.path);
|
||||
size = itemView.findViewById(R.id.size);
|
||||
radioButton = itemView.findViewById(R.id.radio_button);
|
||||
progressBar = itemView.findViewById(R.id.used_space);
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,5 +131,13 @@ public class DataFolderAdapter extends RecyclerView.Adapter<DataFolderAdapter.Vi
|
||||
long getAvailableSpace() {
|
||||
return StorageUtils.getFreeSpaceAvailable(path);
|
||||
}
|
||||
|
||||
long getTotalSpace() {
|
||||
return StorageUtils.getTotalSpaceAvailable(path);
|
||||
}
|
||||
|
||||
int getUsagePercentage() {
|
||||
return 100 - (int) (100 * getAvailableSpace() / (float) getTotalSpace());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout 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:id="@+id/root"
|
||||
android:layout_width="match_parent"
|
||||
@ -35,6 +36,13 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="2 GB" />
|
||||
|
||||
<me.zhanghai.android.materialprogressbar.MaterialProgressBar
|
||||
android:id="@+id/used_space"
|
||||
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:mpb_progressStyle="horizontal" />
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user