diff options
author | Scott Jackson <daneren2005@gmail.com> | 2012-12-26 20:21:17 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2012-12-26 20:21:17 -0800 |
commit | f0ba1fb562de8dbb16f7f207914e8582c256b417 (patch) | |
tree | 8b7a6e0205e06bea193fde16206267940eb22ab6 /subsonic-android | |
parent | 9e1f4837185787d16ac4bbe92d7ee80421a0ffad (diff) | |
download | dsub-f0ba1fb562de8dbb16f7f207914e8582c256b417.tar.gz dsub-f0ba1fb562de8dbb16f7f207914e8582c256b417.tar.bz2 dsub-f0ba1fb562de8dbb16f7f207914e8582c256b417.zip |
closes #82 Added basic about dialog
Diffstat (limited to 'subsonic-android')
5 files changed, 68 insertions, 0 deletions
diff --git a/subsonic-android/res/menu/main.xml b/subsonic-android/res/menu/main.xml index 8edf5304..449df3a8 100644 --- a/subsonic-android/res/menu/main.xml +++ b/subsonic-android/res/menu/main.xml @@ -16,6 +16,11 @@ android:id="@+id/menu_help" android:icon="@drawable/action_help" android:title="@string/menu.help"/> + + <item + android:id="@+id/menu_about" + android:icon="@drawable/action_help" + android:title="@string/menu.about"/> <item android:id="@+id/menu_settings" diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml index d814651d..949c9c4b 100644 --- a/subsonic-android/res/values/strings.xml +++ b/subsonic-android/res/values/strings.xml @@ -30,6 +30,12 @@ <string name="main.welcome_title">Welcome!</string>
<string name="main.welcome_text">Welcome to DSub! The app is currently configured to use the Subsonic demo server. After you\'ve
set up your personal server (available from <b>subsonic.org</b>), please go to <b>Settings</b> and change the configuration to connect to it.</string>
+ <string name="main.about_title">About DSub</string>
+ <string name="main.about_text">Author: Scott Jackson
+ \nEmail: daneren2005@gmail.com
+ \nVersion: %1$s
+ \nUsed Space: %2$s of %3$s
+ \nAvailable Space: %4$s of %5$s</string>
<string name="main.select_server">Select server</string>
<string name="main.shuffle">Shuffle play</string>
<string name="main.offline">Go Offline</string>
@@ -52,6 +58,7 @@ <string name="menu.exit">Exit</string>
<string name="menu.settings">Settings</string>
<string name="menu.help">Help</string>
+ <string name="menu.about">About</string>
<string name="menu.add_playlist">Add To Playlist</string>
<string name="menu.remove_playlist">Remove From Playlist</string>
<string name="menu.deleted_playlist">Deleted playlist %s</string>
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) { |