aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src/github/daneren2005
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-12-26 20:21:17 -0800
committerScott Jackson <daneren2005@gmail.com>2012-12-26 20:21:17 -0800
commitf0ba1fb562de8dbb16f7f207914e8582c256b417 (patch)
tree8b7a6e0205e06bea193fde16206267940eb22ab6 /subsonic-android/src/github/daneren2005
parent9e1f4837185787d16ac4bbe92d7ee80421a0ffad (diff)
downloaddsub-f0ba1fb562de8dbb16f7f207914e8582c256b417.tar.gz
dsub-f0ba1fb562de8dbb16f7f207914e8582c256b417.tar.bz2
dsub-f0ba1fb562de8dbb16f7f207914e8582c256b417.zip
closes #82 Added basic about dialog
Diffstat (limited to 'subsonic-android/src/github/daneren2005')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java27
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java13
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java16
3 files changed, 56 insertions, 0 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java
index 39653e1c..0be15eca 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java
@@ -34,7 +34,10 @@ import com.actionbarsherlock.view.MenuInflater;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
import android.os.Bundle;
+import android.os.StatFs;
import android.preference.PreferenceManager;
import android.view.ContextMenu;
import android.view.LayoutInflater;
@@ -44,6 +47,7 @@ import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.PopupWindow;
+import java.io.File;
public class MainActivity extends SubsonicTabActivity {
@@ -159,6 +163,9 @@ public class MainActivity extends SubsonicTabActivity {
case R.id.menu_help:
startActivity(new Intent(this, HelpActivity.class));
return true;
+ case R.id.menu_about:
+ showAboutDialog();
+ return true;
}
return false;
@@ -253,6 +260,26 @@ public class MainActivity extends SubsonicTabActivity {
}
}
}
+
+ private void showAboutDialog() {
+ try {
+ File rootFolder = FileUtil.getMusicDirectory(MainActivity.this);
+ 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,
+ getPackageManager().getPackageInfo(getPackageName(), 0).versionName,
+ Util.formatBytes(FileUtil.getUsedSize(MainActivity.this, rootFolder)),
+ Util.formatBytes(Util.getCacheSizeMB(MainActivity.this) * 1024L * 1024L),
+ Util.formatBytes(bytesAvailableFs),
+ Util.formatBytes(bytesTotalFs));
+ Util.info(this, R.string.main_about_title, msg);
+ } catch(Exception e) {
+ Util.toast(MainActivity.this, "Failed to open dialog");
+ }
+ // Util.toast(MainActivity.this, "Size: " + Util.formatBytes(FileUtil.getUsedSize(MainActivity.this, FileUtil.getMusicDirectory(MainActivity.this))));
+ }
private void showAlbumList(String type) {
Intent intent = new Intent(this, SelectAlbumActivity.class);
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java b/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java
index 890420fc..3762d346 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java
@@ -292,6 +292,19 @@ public class FileUtil {
int index = name.lastIndexOf('.');
return index == -1 ? name : name.substring(0, index);
}
+
+ public static long getUsedSize(Context context, File file) {
+ long size = 0L;
+
+ if(file.isFile()) {
+ return file.length();
+ } else {
+ for (File child : FileUtil.listFiles(file)) {
+ size += getUsedSize(context, child);
+ }
+ return size;
+ }
+ }
public static <T extends Serializable> boolean serialize(Context context, T obj, String fileName) {
File file = new File(context.getCacheDir(), fileName);
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
index e6055b93..762a3db7 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
@@ -582,6 +582,9 @@ public final class Util {
public static void info(Context context, int titleId, int messageId) {
showDialog(context, android.R.drawable.ic_dialog_info, titleId, messageId);
}
+ public static void info(Context context, int titleId, String message) {
+ showDialog(context, android.R.drawable.ic_dialog_info, titleId, message);
+ }
private static void showDialog(Context context, int icon, int titleId, int messageId) {
new AlertDialog.Builder(context)
@@ -596,6 +599,19 @@ public final class Util {
})
.show();
}
+ private static void showDialog(Context context, int icon, int titleId, String message) {
+ new AlertDialog.Builder(context)
+ .setIcon(icon)
+ .setTitle(titleId)
+ .setMessage(message)
+ .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int i) {
+ dialog.dismiss();
+ }
+ })
+ .show();
+ }
public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song) {