From f0ba1fb562de8dbb16f7f207914e8582c256b417 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 26 Dec 2012 20:21:17 -0800 Subject: closes #82 Added basic about dialog --- subsonic-android/res/menu/main.xml | 5 ++++ subsonic-android/res/values/strings.xml | 7 ++++++ .../daneren2005/dsub/activity/MainActivity.java | 27 ++++++++++++++++++++++ .../src/github/daneren2005/dsub/util/FileUtil.java | 13 +++++++++++ .../src/github/daneren2005/dsub/util/Util.java | 16 +++++++++++++ 5 files changed, 68 insertions(+) (limited to 'subsonic-android') 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"/> + + Welcome! Welcome to DSub! The app is currently configured to use the Subsonic demo server. After you\'ve set up your personal server (available from subsonic.org), please go to Settings and change the configuration to connect to it. + About DSub + Author: Scott Jackson + \nEmail: daneren2005@gmail.com + \nVersion: %1$s + \nUsed Space: %2$s of %3$s + \nAvailable Space: %4$s of %5$s Select server Shuffle play Go Offline @@ -52,6 +58,7 @@ Exit Settings Help + About Add To Playlist Remove From Playlist Deleted playlist %s 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 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) { -- cgit v1.2.3