Fix storage selection crash

This commit is contained in:
Alexey Kulish 2016-03-26 20:42:04 +03:00
parent 28630f460b
commit f693f766c9
2 changed files with 12 additions and 6 deletions

View file

@ -118,6 +118,7 @@
</LinearLayout> </LinearLayout>
<View <View
android:id="@+id/divSharedStorage"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_gravity="fill_horizontal" android:layout_gravity="fill_horizontal"

View file

@ -90,11 +90,16 @@ public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
internalStorageDescription.setText(getFreeSpace(internalStorage)); internalStorageDescription.setText(getFreeSpace(internalStorage));
View sharedMemoryRow = view.findViewById(R.id.sharedMemoryRow); View sharedMemoryRow = view.findViewById(R.id.sharedMemoryRow);
if (hasExternalStoragePermission && sharedStorage != null) {
sharedMemoryRow.setOnClickListener(sharedMemoryOnClickListener); sharedMemoryRow.setOnClickListener(sharedMemoryOnClickListener);
ImageView sharedMemoryImageView = (ImageView) view.findViewById(R.id.sharedMemoryImageView); ImageView sharedMemoryImageView = (ImageView) view.findViewById(R.id.sharedMemoryImageView);
sharedMemoryImageView.setImageDrawable(getContentIcon(R.drawable.ic_sdcard)); sharedMemoryImageView.setImageDrawable(getContentIcon(R.drawable.ic_sdcard));
TextView sharedMemoryDescription = (TextView) view.findViewById(R.id.sharedMemoryDescription); TextView sharedMemoryDescription = (TextView) view.findViewById(R.id.sharedMemoryDescription);
sharedMemoryDescription.setText(getFreeSpace(sharedStorage)); sharedMemoryDescription.setText(getFreeSpace(sharedStorage));
} else {
view.findViewById(R.id.divSharedStorage).setVisibility(View.GONE);
sharedMemoryRow.setVisibility(View.GONE);
}
View memoryStickRow = view.findViewById(R.id.memoryStickRow); View memoryStickRow = view.findViewById(R.id.memoryStickRow);
if (hasExternalStoragePermission && externalStorage != null) { if (hasExternalStoragePermission && externalStorage != null) {
@ -138,7 +143,7 @@ public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
private String getFreeSpace(File dir) { private String getFreeSpace(File dir) {
String sz = ""; String sz = "";
if (dir.canRead()) { if (dir != null && dir.canRead()) {
StatFs fs = new StatFs(dir.getAbsolutePath()); StatFs fs = new StatFs(dir.getAbsolutePath());
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
float size = (float) fs.getAvailableBlocks() * fs.getBlockSize(); float size = (float) fs.getAvailableBlocks() * fs.getBlockSize();