From d356834b088b66c5f57c739ce0a19dfe01baf991 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 21 May 2014 19:12:57 -0700 Subject: #346 Add song count to about dialog --- .../daneren2005/dsub/fragments/MainFragment.java | 45 ++++++++++++++-------- src/github/daneren2005/dsub/util/FileUtil.java | 15 ++++++-- 2 files changed, 40 insertions(+), 20 deletions(-) (limited to 'src/github/daneren2005') diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java index 3a9370a3..c9bbf850 100644 --- a/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -24,6 +24,7 @@ import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.LoadingTask; +import github.daneren2005.dsub.util.Pair; import github.daneren2005.dsub.view.MergeAdapter; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.service.MusicService; @@ -319,22 +320,34 @@ public class MainFragment extends SubsonicFragment { } private void showAboutDialog() { - try { - File rootFolder = FileUtil.getMusicDirectory(context); - StatFs stat = new StatFs(rootFolder.getPath()); - long bytesTotalFs = (long) stat.getBlockCount() * (long) stat.getBlockSize(); - long bytesAvailableFs = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize(); - - String msg = getResources().getString(R.string.main_about_text, - context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName, - Util.formatBytes(FileUtil.getUsedSize(context, rootFolder)), - Util.formatBytes(Util.getCacheSizeMB(context) * 1024L * 1024L), - Util.formatBytes(bytesAvailableFs), - Util.formatBytes(bytesTotalFs)); - Util.info(context, R.string.main_about_title, msg); - } catch(Exception e) { - Util.toast(context, "Failed to open dialog"); - } + new LoadingTask(context) { + @Override + protected String doInBackground() throws Throwable { + File rootFolder = FileUtil.getMusicDirectory(context); + StatFs stat = new StatFs(rootFolder.getPath()); + long bytesTotalFs = (long) stat.getBlockCount() * (long) stat.getBlockSize(); + long bytesAvailableFs = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize(); + + Pair used = FileUtil.getUsedSize(context, rootFolder); + + return getResources().getString(R.string.main_about_text, + context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName, + used.getFirst(), + Util.formatBytes(used.getSecond()), + Util.formatBytes(Util.getCacheSizeMB(context) * 1024L * 1024L), + Util.formatBytes(bytesAvailableFs), + Util.formatBytes(bytesTotalFs)); + } + + @Override + protected void done(String msg) { + try { + Util.info(context, R.string.main_about_title, msg); + } catch(Exception e) { + Util.toast(context, "Failed to open dialog"); + } + } + }.execute(); } private void getLogs() { diff --git a/src/github/daneren2005/dsub/util/FileUtil.java b/src/github/daneren2005/dsub/util/FileUtil.java index 657ca50c..a68ded45 100644 --- a/src/github/daneren2005/dsub/util/FileUtil.java +++ b/src/github/daneren2005/dsub/util/FileUtil.java @@ -510,16 +510,23 @@ public class FileUtil { return index == -1 ? name : name.substring(0, index); } - public static long getUsedSize(Context context, File file) { + public static Pair getUsedSize(Context context, File file) { + long number = 0L; long size = 0L; if(file.isFile()) { - return file.length(); + if(isMediaFile(file)) { + return new Pair(1L, file.length()); + } else { + return new Pair(0L, 0L); + } } else { for (File child : FileUtil.listFiles(file)) { - size += getUsedSize(context, child); + Pair pair = getUsedSize(context, child); + number += pair.getFirst(); + size += pair.getSecond(); } - return size; + return new Pair(number, size); } } -- cgit v1.2.3