Skip to content

Commit

Permalink
MemoryUtil: prevent overloading
Browse files Browse the repository at this point in the history
  • Loading branch information
codekidX committed Dec 28, 2016
1 parent c501adf commit 2b076b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private void populateList() {
storagesList = new ArrayList<Storages>();

File storageDir = new File("/storage");
File internalStorageDir = Environment.getExternalStorageDirectory();
String internalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();

File[] volumeList = storageDir.listFiles();

Expand All @@ -154,9 +154,9 @@ private void populateList() {
} else {
storages.setStorageTitle(INTERNAL_STORAGE_TITLE);
}
storages.setStoragePath(internalStorageDir.getAbsolutePath());
storages.setMemoryTotalSize(memoryUtil.getTotalMemorySize(internalStorageDir));
storages.setMemoryAvailableSize(memoryUtil.getAvailableMemorySize(internalStorageDir));
storages.setStoragePath(internalStoragePath);
storages.setMemoryTotalSize(memoryUtil.formatSize(memoryUtil.getTotalMemorySize(internalStoragePath)));
storages.setMemoryAvailableSize(memoryUtil.formatSize(memoryUtil.getAvailableMemorySize(internalStoragePath)));
storagesList.add(storages);


Expand All @@ -166,10 +166,11 @@ private void populateList() {
&& !f.getName().equals(MemoryUtil.EMULATED_DIR_NAME)
&& !f.getName().equals(MemoryUtil.SDCARD0_DIR_NAME)) {
Storages sharedStorage = new Storages();
String fPath = f.getAbsolutePath();
sharedStorage.setStorageTitle(f.getName());
sharedStorage.setMemoryTotalSize(memoryUtil.getTotalMemorySize(f));
sharedStorage.setMemoryAvailableSize(memoryUtil.getAvailableMemorySize(f));
sharedStorage.setStoragePath(f.getAbsolutePath());
sharedStorage.setMemoryTotalSize(memoryUtil.formatSize(memoryUtil.getTotalMemorySize(fPath)));
sharedStorage.setMemoryAvailableSize(memoryUtil.formatSize(memoryUtil.getAvailableMemorySize(fPath)));
sharedStorage.setStoragePath(fPath);
storagesList.add(sharedStorage);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,9 @@ public int getStorageListSize() {

/**
* calculate available/free size of any directory
* @param file File to use it with StatFs
* @return string formatted using formatSize()
* @param path path of the storage
* @return size in bytes
*/
public String getAvailableMemorySize(File file) {
StatFs stat = new StatFs(file.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return formatSize(availableBlocks * blockSize);
}

public long getAvailableMemorySize(String path) {
File file = new File(path);
StatFs stat = new StatFs(file.getPath());
Expand All @@ -66,16 +59,9 @@ public long getAvailableMemorySize(String path) {

/**
* calculate total size of any directory
* @param file File to use it with StatFs
* @return
* @param path path of the storage
* @return size in bytes
*/
public String getTotalMemorySize(File file) {
StatFs stat = new StatFs(file.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
return formatSize(totalBlocks * blockSize);
}

public long getTotalMemorySize(String path) {
File file = new File(path);
StatFs stat = new StatFs(file.getPath());
Expand Down

0 comments on commit 2b076b5

Please sign in to comment.