aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectArtistFragment.java8
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java23
-rw-r--r--src/github/daneren2005/dsub/service/CachedMusicService.java11
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java5
-rw-r--r--src/github/daneren2005/dsub/util/BackgroundTask.java10
-rw-r--r--src/github/daneren2005/dsub/util/ImageLoader.java85
6 files changed, 132 insertions, 10 deletions
diff --git a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java
index d0ea96b3..6477f6cc 100644
--- a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java
@@ -174,6 +174,12 @@ public class SelectArtistFragment extends SelectListFragment<Artist> {
public List<Artist> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception {
if(!Util.isOffline(context) && !Util.isTagBrowsing(context)) {
musicFolders = musicService.getMusicFolders(refresh, context, listener);
+
+ // Hide folders option if there is only one
+ if(musicFolders.size() == 1) {
+ musicFolders = null;
+ Util.setSelectedMusicFolderId(context, null);
+ }
}
String musicFolderId = Util.getSelectedMusicFolderId(context);
@@ -199,7 +205,7 @@ public class SelectArtistFragment extends SelectListFragment<Artist> {
folderButton = folderButtonParent.findViewById(R.id.select_artist_folder);
}
- if (Util.isOffline(context) || Util.isTagBrowsing(context)) {
+ if (Util.isOffline(context) || Util.isTagBrowsing(context) || musicFolders == null) {
folderButton.setVisibility(View.GONE);
} else {
folderButton.setVisibility(View.VISIBLE);
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
index 805c0de0..6d94327c 100644
--- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
@@ -27,6 +27,8 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
+import android.widget.BaseAdapter;
+import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
@@ -688,7 +690,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
}
// If artist, we want to load the artist info to use later
- if(artist && ServerInfo.checkServerVersion(context, "1.11")) {
+ if(artist && ServerInfo.checkServerVersion(context, "1.11") && !Util.isOffline(context)) {
artistInfo = musicService.getArtistInfo(id, refresh, context, this);
}
@@ -1383,7 +1385,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
}
artistView.setText(spanned);
artistView.setSingleLine(false);
- artistView.setLines(5);
+ final int minLines = context.getResources().getInteger(R.integer.TextDescriptionLength);
+ artistView.setLines(minLines);
artistView.setTextAppearance(context, android.R.style.TextAppearance_Small);
final Spanned spannedText = spanned;
@@ -1391,7 +1394,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onClick(View v) {
- if(artistView.getMaxLines() == 5) {
+ if(artistView.getMaxLines() == minLines) {
// Use LeadingMarginSpan2 to try to make text flow around image
Display display = context.getWindowManager().getDefaultDisplay();
View coverArtView = header.findViewById(R.id.select_album_art);
@@ -1414,10 +1417,20 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
artistView.setText(ss);
artistView.setMaxLines(100);
+ if(albumList instanceof HeaderGridView) {
+ HeaderGridView headerGridView = (HeaderGridView) albumList;
+ ((BaseAdapter) headerGridView.getAdapter()).notifyDataSetChanged();
+ }
+
vlp = (ViewGroup.MarginLayoutParams) titleView.getLayoutParams();
vlp.leftMargin = width;
} else {
- artistView.setMaxLines(5);
+ artistView.setMaxLines(minLines);
+
+ if(albumList instanceof HeaderGridView) {
+ HeaderGridView headerGridView = (HeaderGridView) albumList;
+ ((BaseAdapter) headerGridView.getAdapter()).notifyDataSetChanged();
+ }
}
}
});
@@ -1452,7 +1465,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
}
private void setupButtonEvents(View header) {
ImageView shareButton = (ImageView) header.findViewById(R.id.select_album_share);
- if(share != null || podcastId != null || !Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_SHARED, true) || Util.isOffline(context) || !UserUtil.canShare()) {
+ if(share != null || podcastId != null || !Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_SHARED, true) || Util.isOffline(context) || !UserUtil.canShare() || artistInfo != null) {
shareButton.setVisibility(View.GONE);
} else {
shareButton.setOnClickListener(new View.OnClickListener() {
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java
index 232d0acf..38508e42 100644
--- a/src/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/src/github/daneren2005/dsub/service/CachedMusicService.java
@@ -30,6 +30,7 @@ import org.apache.http.HttpResponse;
import android.content.Context;
import android.graphics.Bitmap;
+import android.util.Log;
import github.daneren2005.dsub.domain.Artist;
import github.daneren2005.dsub.domain.ArtistInfo;
@@ -72,6 +73,7 @@ public class CachedMusicService implements MusicService {
private final TimeLimitedCache<List<MusicFolder>> cachedMusicFolders = new TimeLimitedCache<List<MusicFolder>>(10 * 3600, TimeUnit.SECONDS);
private final TimeLimitedCache<List<PodcastChannel>> cachedPodcastChannels = new TimeLimitedCache<List<PodcastChannel>>(10 * 3600, TimeUnit.SECONDS);
private String restUrl;
+ private String musicFolderId;
private boolean isTagBrowsing = false;
public CachedMusicService(RESTMusicService musicService) {
@@ -1300,8 +1302,9 @@ public class CachedMusicService implements MusicService {
}
private void checkSettingsChanged(Context context) {
+ int instance = musicService.getInstance(context);
String newUrl = musicService.getRestUrl(context, null, false);
- boolean newIsTagBrowsing = Util.isTagBrowsing(context);
+ boolean newIsTagBrowsing = Util.isTagBrowsing(context, instance);
if (!Util.equals(newUrl, restUrl) || isTagBrowsing != newIsTagBrowsing) {
cachedMusicFolders.clear();
cachedLicenseValid.clear();
@@ -1311,5 +1314,11 @@ public class CachedMusicService implements MusicService {
restUrl = newUrl;
isTagBrowsing = newIsTagBrowsing;
}
+
+ String newMusicFolderId = Util.getSelectedMusicFolderId(context, instance);
+ if(!Util.equals(newMusicFolderId, musicFolderId)) {
+ cachedIndexes.clear();
+ musicFolderId = newMusicFolderId;
+ }
}
}
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index 37741b92..ef69c9d3 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -905,6 +905,11 @@ public class DownloadService extends Service {
if (remoteState != LOCAL) {
remoteController.changePosition(position / 1000);
} else {
+ if(proxy != null && currentPlaying.isCompleteFileAvailable()) {
+ doPlay(currentPlaying, position, playerState == STARTED);
+ return;
+ }
+
mediaPlayer.seekTo(position);
cachedPosition = position;
subtractPosition = 0;
diff --git a/src/github/daneren2005/dsub/util/BackgroundTask.java b/src/github/daneren2005/dsub/util/BackgroundTask.java
index fda881c9..9b39ac82 100644
--- a/src/github/daneren2005/dsub/util/BackgroundTask.java
+++ b/src/github/daneren2005/dsub/util/BackgroundTask.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -46,6 +47,7 @@ public abstract class BackgroundTask<T> implements ProgressListener {
private final Context context;
protected AtomicBoolean cancelled = new AtomicBoolean(false);
protected OnCancelListener cancelListener;
+ protected Runnable onCompletionListener = null;
protected Task task;
private static final int DEFAULT_CONCURRENCY = 8;
@@ -170,6 +172,10 @@ public abstract class BackgroundTask<T> implements ProgressListener {
updateProgress(context.getResources().getString(messageId));
}
+ public void setOnCompletionListener(Runnable onCompletionListener) {
+ this.onCompletionListener = onCompletionListener;
+ }
+
protected class Task {
private Thread thread;
private AtomicBoolean taskStart = new AtomicBoolean(false);
@@ -256,6 +262,10 @@ public abstract class BackgroundTask<T> implements ProgressListener {
}
public void onDone(T result) {
done(result);
+
+ if(onCompletionListener != null) {
+ onCompletionListener.run();
+ }
}
public void onError(Throwable t) {
error(t);
diff --git a/src/github/daneren2005/dsub/util/ImageLoader.java b/src/github/daneren2005/dsub/util/ImageLoader.java
index 5adf5e34..97c7f626 100644
--- a/src/github/daneren2005/dsub/util/ImageLoader.java
+++ b/src/github/daneren2005/dsub/util/ImageLoader.java
@@ -41,7 +41,9 @@ import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.ArtistInfo;
import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
@@ -181,8 +183,14 @@ public class ImageLoader {
return bitmap;
}
- public ImageTask loadImage(View view, MusicDirectory.Entry entry, boolean large, boolean crossfade) {
- if(entry != null && entry.getCoverArt() == null && entry.isDirectory() && !Util.isOffline(context)) {
+ public SilentBackgroundTask loadImage(View view, MusicDirectory.Entry entry, boolean large, boolean crossfade) {
+ // TODO: If we know this a artist, try to load artist info instead
+ int size = large ? imageSizeLarge : imageSizeDefault;
+ if(entry != null && !entry.isAlbum() && ServerInfo.checkServerVersion(context, "1.11") && !Util.isOffline(context)) {
+ SilentBackgroundTask task = new ArtistImageTask(view.getContext(), entry, size, imageSizeLarge, large, view, crossfade);
+ task.execute();
+ return task;
+ } else if(entry != null && entry.getCoverArt() == null && entry.isDirectory() && !Util.isOffline(context)) {
// Try to lookup child cover art
MusicDirectory.Entry firstChild = FileUtil.lookupChild(context, entry, true);
if(firstChild != null) {
@@ -191,7 +199,6 @@ public class ImageLoader {
}
Bitmap bitmap;
- int size = large ? imageSizeLarge : imageSizeDefault;
if (entry == null || entry.getCoverArt() == null) {
bitmap = getUnknownImage(entry, size);
setImage(view, Util.createDrawableFromBitmap(context, bitmap), crossfade);
@@ -411,6 +418,72 @@ public class ImageLoader {
}
}
+ private class ArtistImageTask extends SilentBackgroundTask<Void> {
+ private final Context mContext;
+ private final MusicDirectory.Entry mEntry;
+ private final int mSize;
+ private final int mSaveSize;
+ private final boolean mIsNowPlaying;
+ private Drawable mDrawable;
+ private boolean mCrossfade;
+ private View mView;
+
+ private SilentBackgroundTask subTask;
+
+ public ArtistImageTask(Context context, MusicDirectory.Entry entry, int size, int saveSize, boolean isNowPlaying, View view, boolean crossfade) {
+ super(context);
+ mContext = context;
+ mEntry = entry;
+ mSize = size;
+ mSaveSize = saveSize;
+ mIsNowPlaying = isNowPlaying;
+ mView = view;
+ mCrossfade = crossfade;
+ }
+
+ @Override
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(mContext);
+ ArtistInfo artistInfo = musicService.getArtistInfo(mEntry.getId(), false, mContext, null);
+ String url = artistInfo.getImageUrl();
+
+ // Figure out whether we are going to get a artist image or the standard image
+ if(url != null) {
+ // If getting the artist image fails for any reason, retry for the standard version
+ subTask = new ViewUrlTask(mContext, mView, url, mSize) {
+ @Override
+ protected void failedToDownload() {
+ // Call loadImage so we can take advantage of all of it's logic checks
+ loadImage(mView, mEntry, mSize == imageSizeLarge, mCrossfade);
+
+ // Delete subTask so it doesn't get called in done
+ subTask = null;
+ }
+ };
+ } else if(mEntry != null && mEntry.getCoverArt() != null) {
+ subTask = new ViewImageTask(mContext, mEntry, mSize, mSaveSize, mIsNowPlaying, mView, mCrossfade);
+ } else {
+ // If entry is null as well, we need to just set as a blank image
+ Bitmap bitmap = getUnknownImage(mEntry, mSize);
+ mDrawable = Util.createDrawableFromBitmap(mContext, bitmap);
+ return null;
+ }
+
+ // Execute whichever way we decided to go
+ subTask.doInBackground();
+ return null;
+ }
+
+ @Override
+ public void done(Void result) {
+ if(subTask != null) {
+ subTask.done(result);
+ } else if(mDrawable != null) {
+ setImage(mView, mDrawable, mCrossfade);
+ }
+ }
+ }
+
private class ViewUrlTask extends SilentBackgroundTask<Void> {
private final Context mContext;
private final String mUrl;
@@ -451,8 +524,14 @@ public class ImageLoader {
protected void done(Void result) {
if(mDrawable != null) {
mView.setImageDrawable(mDrawable);
+ } else {
+ failedToDownload();
}
}
+
+ protected void failedToDownload() {
+
+ }
}
private class AvatarTask extends SilentBackgroundTask<Void> {