aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDaniel Bowman <daniel@danielbowman.co.uk>2018-10-20 18:38:26 +0100
committerDaniel Bowman <daniel@danielbowman.co.uk>2018-10-20 18:38:26 +0100
commit361f73ffa001fb6477683eee7f4c23932a234f74 (patch)
tree46fbe98524c56b45d184c38372082af6ccab1684 /app
parent19895fc4b760793c739dd056d1de1b20df92d820 (diff)
downloaddsub-361f73ffa001fb6477683eee7f4c23932a234f74.tar.gz
dsub-361f73ffa001fb6477683eee7f4c23932a234f74.tar.bz2
dsub-361f73ffa001fb6477683eee7f4c23932a234f74.zip
Fix a crash on getRecentDownloads if playlist is empty
Diffstat (limited to 'app')
-rw-r--r--app/src/androidTest/java/github/daneren2005/dsub/service/DownloadServiceTest.java14
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java2
2 files changed, 15 insertions, 1 deletions
diff --git a/app/src/androidTest/java/github/daneren2005/dsub/service/DownloadServiceTest.java b/app/src/androidTest/java/github/daneren2005/dsub/service/DownloadServiceTest.java
index 44b77b84..37e91642 100644
--- a/app/src/androidTest/java/github/daneren2005/dsub/service/DownloadServiceTest.java
+++ b/app/src/androidTest/java/github/daneren2005/dsub/service/DownloadServiceTest.java
@@ -49,6 +49,20 @@ public class DownloadServiceTest extends
assertEquals(0, position);
}
+ public void testGetRecentDownloadsWithoutPlaylist() {
+ int output_length = downloadService.getRecentDownloads().size();
+ assertEquals(0, output_length);
+ }
+
+ public void testGetRecentDownloadsWithPlaylist() {
+ downloadService.getDownloads().clear();
+ downloadService.download(this.createMusicSongs(2), false, false, false,
+ false, 0, 0);
+
+ int output_length = downloadService.getRecentDownloads().size();
+ assertEquals(1, output_length);
+ }
+
public void testGetCurrentPlayingIndexWithoutPlayList() {
int currentPlayingIndex = activity.getDownloadService()
.getCurrentPlayingIndex();
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
index 6c3cfbd7..fc2bc7fc 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
@@ -1060,7 +1060,7 @@ public class DownloadService extends Service {
public synchronized List<DownloadFile> getRecentDownloads() {
int from = Math.max(currentPlayingIndex - 10, 0);
int songsToKeep = Math.max(Util.getPreloadCount(this), 20);
- int to = Math.min(currentPlayingIndex + songsToKeep, downloadList.size() - 1);
+ int to = Math.min(currentPlayingIndex + songsToKeep, Math.max(downloadList.size() - 1, 0));
List<DownloadFile> temp = downloadList.subList(from, to);
temp.addAll(backgroundDownloadList);
return temp;