aboutsummaryrefslogtreecommitdiff
path: root/src/github/daneren2005
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-02-11 14:56:07 -0800
committerScott Jackson <daneren2005@gmail.com>2014-02-11 14:56:07 -0800
commite4b23a8076f1b420b439744fc05b646f3ce19c1a (patch)
treeb762eef1b56987a7db92720646b73dfe81d0d027 /src/github/daneren2005
parent48885e5d506a4434b52c7f053e1edf540e573df0 (diff)
parent68cf8918365fa41bc12dfde1b7e39ec5a4279e9e (diff)
downloaddsub-e4b23a8076f1b420b439744fc05b646f3ce19c1a.tar.gz
dsub-e4b23a8076f1b420b439744fc05b646f3ce19c1a.tar.bz2
dsub-e4b23a8076f1b420b439744fc05b646f3ce19c1a.zip
Merge branch 'master' of github.com:daneren2005/Subsonic
Diffstat (limited to 'src/github/daneren2005')
-rw-r--r--src/github/daneren2005/dsub/activity/SettingsActivity.java3
-rw-r--r--src/github/daneren2005/dsub/service/DownloadFile.java12
-rw-r--r--src/github/daneren2005/dsub/service/DownloadServiceImpl.java27
-rw-r--r--src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java33
-rw-r--r--src/github/daneren2005/dsub/util/Constants.java8
-rw-r--r--src/github/daneren2005/dsub/util/Util.java39
6 files changed, 69 insertions, 53 deletions
diff --git a/src/github/daneren2005/dsub/activity/SettingsActivity.java b/src/github/daneren2005/dsub/activity/SettingsActivity.java
index 7cebdbdd..40ca5570 100644
--- a/src/github/daneren2005/dsub/activity/SettingsActivity.java
+++ b/src/github/daneren2005/dsub/activity/SettingsActivity.java
@@ -77,7 +77,6 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
private EditTextPreference randomSize;
private ListPreference tempLoss;
private ListPreference pauseDisconnect;
- private EditTextPreference bufferLength;
private Preference addServerPreference;
private PreferenceCategory serversCategory;
private EditTextPreference chatRefreshRate;
@@ -119,7 +118,6 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
randomSize = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_RANDOM_SIZE);
tempLoss = (ListPreference) findPreference(Constants.PREFERENCES_KEY_TEMP_LOSS);
pauseDisconnect = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PAUSE_DISCONNECT);
- bufferLength = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_BUFFER_LENGTH);
serversCategory = (PreferenceCategory) findPreference(Constants.PREFERENCES_KEY_SERVER_KEY);
addServerPreference = (Preference) findPreference(Constants.PREFERENCES_KEY_SERVER_ADD);
chatRefreshRate = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_CHAT_REFRESH);
@@ -303,7 +301,6 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
randomSize.setSummary(randomSize.getText());
tempLoss.setSummary(tempLoss.getEntry());
pauseDisconnect.setSummary(pauseDisconnect.getEntry());
- bufferLength.setSummary(bufferLength.getText() + " seconds");
chatRefreshRate.setSummary(chatRefreshRate.getText());
videoPlayer.setSummary(videoPlayer.getEntry());
syncInterval.setSummary(syncInterval.getEntry());
diff --git a/src/github/daneren2005/dsub/service/DownloadFile.java b/src/github/daneren2005/dsub/service/DownloadFile.java
index cfadced5..9ecfe0ad 100644
--- a/src/github/daneren2005/dsub/service/DownloadFile.java
+++ b/src/github/daneren2005/dsub/service/DownloadFile.java
@@ -63,7 +63,7 @@ public class DownloadFile {
private boolean saveWhenDone = false;
private boolean completeWhenDone = false;
private Integer contentLength = null;
- private int currentSpeed = 0;
+ private long currentSpeed = 0;
public DownloadFile(Context context, MusicDirectory.Entry song, boolean save) {
this.context = context;
@@ -111,7 +111,7 @@ public class DownloadFile {
return contentLength;
}
- public int getCurrentSize() {
+ public long getCurrentSize() {
if(partialFile.exists()) {
return partialFile.length();
} else {
@@ -119,12 +119,12 @@ public class DownloadFile {
if(file.exists()) {
return file.length();
} else {
- return 0;
+ return 0L;
}
}
}
- public int getEstimatedSize() {
+ public long getEstimatedSize() {
if(contentLength != null) {
return contentLength;
}
@@ -135,13 +135,13 @@ public class DownloadFile {
} else if(song.getDuration() == null) {
return 0;
} else {
- int br = getBitrate();
+ int br = (getBitRate() * 1024) / 8;
int duration = song.getDuration();
return br * duration;
}
}
- public int getBytesPerSecond() {
+ public long getBytesPerSecond() {
return currentSpeed;
}
diff --git a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index d67d53bf..9f1e5ee9 100644
--- a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -121,6 +121,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
private int cachedPosition = 0;
private long downloadRevision;
private boolean downloadOngoing = false;
+ private DownloadFile lastDownloaded = null;
private static boolean equalizerAvailable;
private static boolean visualizerAvailable;
@@ -1526,13 +1527,26 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
}
- if(!backgroundDownloadList.isEmpty() && downloadRevision != revision) {
- Util.showDownloadingNotification(this, currentDownloading, backgroundDownloadList.size());
+ if(!backgroundDownloadList.isEmpty()) {
+ DownloadFile speedFile = null;
+ // Updating existing notification
+ if(downloadOngoing) {
+ // Changing download, use speed of last DownloadFile
+ if(revision != downloadRevision && lastDownloaded != null) {
+ speedFile = lastDownloaded;
+ } else {
+ // Updated mid-download
+ speedFile = currentDownloading;
+ }
+ }
+ Util.showDownloadingNotification(this, currentDownloading, backgroundDownloadList.size(), speedFile);
downloadRevision = revision;
+ lastDownloaded = currentDownloading;
downloadOngoing = true;
} else if(backgroundDownloadList.isEmpty() && downloadOngoing) {
Util.hideDownloadingNotification(this);
downloadOngoing = false;
+ lastDownloaded = null;
}
// Delete obsolete .partial and .complete files.
@@ -1608,16 +1622,9 @@ public class DownloadServiceImpl extends Service implements DownloadService {
this.position = position;
partialFile = downloadFile.getPartialFile();
- SharedPreferences prefs = Util.getPreferences(DownloadServiceImpl.this);
- long bufferLength = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_BUFFER_LENGTH, "5"));
- if(bufferLength == 0) {
- // Set to seconds in a day, basically infinity
- bufferLength = 86400L;
- }
-
// Calculate roughly how many bytes BUFFER_LENGTH_SECONDS corresponds to.
int bitRate = downloadFile.getBitRate();
- long byteCount = Math.max(100000, bitRate * 1024L / 8L * bufferLength);
+ long byteCount = Math.max(100000, bitRate * 1024L / 8L * 5L);
// Find out how large the file should grow before resuming playback.
Log.i(TAG, "Buffering from position " + position + " and bitrate " + bitRate);
diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
index 65320f84..cd876621 100644
--- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
+++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
@@ -92,8 +92,6 @@ public class DownloadServiceLifecycleSupport {
} else if (DownloadServiceImpl.CMD_STOP.equals(action)) {
downloadService.pause();
downloadService.seekTo(0);
- } else if(DownloadServiceImpl.CANCEL_DOWNLOADS.equals(action)) {
- downloadService.clearBackground();
}
}
});
@@ -204,19 +202,26 @@ public class DownloadServiceLifecycleSupport {
}
public void onStart(Intent intent) {
- if (intent != null && intent.getExtras() != null) {
- final KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
- if (event != null) {
- eventHandler.post(new Runnable() {
- @Override
- public void run() {
- if(!setup.get()) {
- lock.lock();
- lock.unlock();
+ if (intent != null) {
+ if(intent.getExtras() != null) {
+ final KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
+ if (event != null) {
+ eventHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ if(!setup.get()) {
+ lock.lock();
+ lock.unlock();
+ }
+ handleKeyEvent(event);
}
- handleKeyEvent(event);
- }
- });
+ });
+ }
+ } else {
+ String action = intent.getAction();
+ if(DownloadServiceImpl.CANCEL_DOWNLOADS.equals(action)) {
+ downloadService.clearBackground();
+ }
}
}
}
diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java
index c6dd49f2..5d80a961 100644
--- a/src/github/daneren2005/dsub/util/Constants.java
+++ b/src/github/daneren2005/dsub/util/Constants.java
@@ -41,7 +41,6 @@ public final class Constants {
public static final String INTENT_EXTRA_NAME_ARTIST = "subsonic.artist";
public static final String INTENT_EXTRA_NAME_TITLE = "subsonic.title";
public static final String INTENT_EXTRA_NAME_AUTOPLAY = "subsonic.playall";
- public static final String INTENT_EXTRA_NAME_ERROR = "subsonic.error";
public static final String INTENT_EXTRA_NAME_QUERY = "subsonic.query";
public static final String INTENT_EXTRA_NAME_PLAYLIST_ID = "subsonic.playlist.id";
public static final String INTENT_EXTRA_NAME_PLAYLIST_NAME = "subsonic.playlist.name";
@@ -50,7 +49,6 @@ public final class Constants {
public static final String INTENT_EXTRA_NAME_ALBUM_LIST_SIZE = "subsonic.albumlistsize";
public static final String INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET = "subsonic.albumlistoffset";
public static final String INTENT_EXTRA_NAME_SHUFFLE = "subsonic.shuffle";
- public static final String INTENT_EXTRA_NAME_REFRESH = "subsonic.refresh";
public static final String INTENT_EXTRA_REQUEST_SEARCH = "subsonic.requestsearch";
public static final String INTENT_EXTRA_NAME_EXIT = "subsonic.exit" ;
public static final String INTENT_EXTRA_NAME_DOWNLOAD = "subsonic.download";
@@ -65,7 +63,6 @@ public final class Constants {
// Notification IDs.
public static final int NOTIFICATION_ID_PLAYING = 100;
- public static final int NOTIFICATION_ID_ERROR = 101;
public static final int NOTIFICATION_ID_DOWNLOADING = 102;
// Preferences keys.
@@ -104,7 +101,6 @@ public final class Constants {
public static final String PREFERENCES_KEY_REPEAT_MODE = "repeatMode";
public static final String PREFERENCES_KEY_WIFI_REQUIRED_FOR_DOWNLOAD = "wifiRequiredForDownload";
public static final String PREFERENCES_KEY_RANDOM_SIZE = "randomSize";
- public static final String PREFERENCES_KEY_SLEEP_TIMER = "sleepTimer";
public static final String PREFERENCES_KEY_SLEEP_TIMER_DURATION = "sleepTimerDuration";
public static final String PREFERENCES_KEY_OFFLINE = "offline";
public static final String PREFERENCES_KEY_TEMP_LOSS = "tempLoss";
@@ -112,7 +108,6 @@ public final class Constants {
public static final String PREFERENCES_KEY_SHUFFLE_END_YEAR = "endYear";
public static final String PREFERENCES_KEY_SHUFFLE_GENRE = "genre";
public static final String PREFERENCES_KEY_KEEP_SCREEN_ON = "keepScreenOn";
- public static final String PREFERENCES_KEY_BUFFER_LENGTH = "bufferLength";
public static final String PREFERENCES_EQUALIZER_ON = "equalizerOn";
public static final String PREFERENCES_VISUALIZER_ON = "visualizerOn";
public static final String PREFERENCES_EQUALIZER_SETTINGS = "equalizerSettings";
@@ -154,9 +149,6 @@ public final class Constants {
public static final String MAIN_BACK_STACK = "backStackIds";
public static final String MAIN_BACK_STACK_SIZE = "backStackIdsSize";
- public static final String MAIN_BACK_STACK_TABS = "backStackTabs";
- public static final String MAIN_BACK_STACK_POSITION = "backStackPosition";
- public static final String FRAGMENT_ID = "fragmentId";
public static final String FRAGMENT_LIST = "fragmentList";
public static final String FRAGMENT_LIST2 = "fragmentList2";
public static final String FRAGMENT_DOWNLOAD_FLIPPER = "fragmentDownloadFlipper";
diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java
index fe8b6eae..e2f2d02f 100644
--- a/src/github/daneren2005/dsub/util/Util.java
+++ b/src/github/daneren2005/dsub/util/Util.java
@@ -606,14 +606,17 @@ public final class Util {
}
public static boolean recursiveDelete(File dir) {
if (dir != null && dir.exists()) {
- for(File file: dir.listFiles()) {
- if(file.isDirectory()) {
- if(!recursiveDelete(file)) {
- return false;
- }
- } else if(file.exists()) {
- if(!file.delete()) {
- return false;
+ File[] list = dir.listFiles();
+ if(list != null) {
+ for(File file: list) {
+ if(file.isDirectory()) {
+ if(!recursiveDelete(file)) {
+ return false;
+ }
+ } else if(file.exists()) {
+ if(!file.delete()) {
+ return false;
+ }
}
}
}
@@ -1105,12 +1108,24 @@ public final class Util {
DSubWidgetProvider.notifyInstances(context, downloadService, false);
}
- public static void showDownloadingNotification(final Context context, DownloadFile file, int size) {
+ public static void showDownloadingNotification(final Context context, DownloadFile file, int size, DownloadFile speedFile) {
Intent cancelIntent = new Intent(context, DownloadServiceImpl.class);
cancelIntent.setAction(DownloadServiceImpl.CANCEL_DOWNLOADS);
PendingIntent cancelPI = PendingIntent.getService(context, 0, cancelIntent, 0);
- String currentDownloading = (file != null) ? file.getSong().getTitle() : "none";
+ String currentDownloading, currentSize, speed;
+ if(file != null) {
+ currentDownloading = file.getSong().getTitle();
+ currentSize = Util.formatBytes(file.getEstimatedSize());
+ } else {
+ currentDownloading = "none";
+ currentSize = "0";
+ }
+ if(speedFile != null) {
+ speed = Long.toString(speedFile.getBytesPerSecond() / 1024);
+ } else {
+ speed = "0";
+ }
NotificationCompat.Builder builder;
builder = new NotificationCompat.Builder(context)
@@ -1118,11 +1133,11 @@ public final class Util {
.setContentTitle(context.getResources().getString(R.string.download_downloading_title, size))
.setContentText(context.getResources().getString(R.string.download_downloading_summary, currentDownloading))
.setStyle(new NotificationCompat.BigTextStyle()
- .bigText(context.getResources().getString(R.string.download_downloading_summary, currentDownloading)))
+ .bigText(context.getResources().getString(R.string.download_downloading_summary_expanded, currentDownloading, currentSize, speed)))
.setProgress(10, 5, true)
.setOngoing(true)
.addAction(R.drawable.notification_close,
- context.getResources().getString(R.string.common_cancel,
+ context.getResources().getString(R.string.common_cancel),
cancelPI);
Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);