diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-05-21 19:12:57 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-05-21 19:12:57 -0700 |
commit | d356834b088b66c5f57c739ce0a19dfe01baf991 (patch) | |
tree | 0c9b7bda61e7319d986eb39c2ac26733fd92a8bb /src/github/daneren2005 | |
parent | c6129022d37658ccb5c1989efaececf098f84c12 (diff) | |
download | dsub-d356834b088b66c5f57c739ce0a19dfe01baf991.tar.gz dsub-d356834b088b66c5f57c739ce0a19dfe01baf991.tar.bz2 dsub-d356834b088b66c5f57c739ce0a19dfe01baf991.zip |
#346 Add song count to about dialog
Diffstat (limited to 'src/github/daneren2005')
-rw-r--r-- | src/github/daneren2005/dsub/fragments/MainFragment.java | 45 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/util/FileUtil.java | 15 |
2 files changed, 40 insertions, 20 deletions
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<String>(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<Long, Long> 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<Long, Long> getUsedSize(Context context, File file) { + long number = 0L; long size = 0L; if(file.isFile()) { - return file.length(); + if(isMediaFile(file)) { + return new Pair<Long, Long>(1L, file.length()); + } else { + return new Pair<Long, Long>(0L, 0L); + } } else { for (File child : FileUtil.listFiles(file)) { - size += getUsedSize(context, child); + Pair<Long, Long> pair = getUsedSize(context, child); + number += pair.getFirst(); + size += pair.getSecond(); } - return size; + return new Pair<Long, Long>(number, size); } } |