diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-05-09 22:49:46 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-05-09 22:49:46 -0700 |
commit | 38b34726329b70f5abfd73a9cb9dd006d4a2a777 (patch) | |
tree | d557b4937de038cc8390a377ed5194fbad7a832e /subsonic-android | |
parent | e3e47ef3422a0fbd4c4e19837e13e881ecfe01ad (diff) | |
download | dsub-38b34726329b70f5abfd73a9cb9dd006d4a2a777.tar.gz dsub-38b34726329b70f5abfd73a9cb9dd006d4a2a777.tar.bz2 dsub-38b34726329b70f5abfd73a9cb9dd006d4a2a777.zip |
Add lazy loading for album lists
Diffstat (limited to 'subsonic-android')
-rw-r--r-- | subsonic-android/libs/CWAC-AdapterWrapper.jar | bin | 0 -> 4841 bytes | |||
-rw-r--r-- | subsonic-android/libs/CWAC-EndlessAdapter.jar | bin | 0 -> 5317 bytes | |||
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java | 37 | ||||
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/view/AlbumListAdapter.java | 74 |
4 files changed, 84 insertions, 27 deletions
diff --git a/subsonic-android/libs/CWAC-AdapterWrapper.jar b/subsonic-android/libs/CWAC-AdapterWrapper.jar Binary files differnew file mode 100644 index 00000000..692fe4d3 --- /dev/null +++ b/subsonic-android/libs/CWAC-AdapterWrapper.jar diff --git a/subsonic-android/libs/CWAC-EndlessAdapter.jar b/subsonic-android/libs/CWAC-EndlessAdapter.jar Binary files differnew file mode 100644 index 00000000..ec20d936 --- /dev/null +++ b/subsonic-android/libs/CWAC-EndlessAdapter.jar diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 8cd66f5f..209e22b2 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -37,6 +37,7 @@ import github.daneren2005.dsub.util.LoadingTask; import github.daneren2005.dsub.util.Pair;
import github.daneren2005.dsub.util.TabBackgroundTask;
import github.daneren2005.dsub.util.Util;
+import github.daneren2005.dsub.view.AlbumListAdapter;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
@@ -62,7 +63,6 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter String playlistName;
String albumListType;
int albumListSize;
- int albumListOffset;
@Override
public void onCreate(Bundle bundle) {
@@ -105,7 +105,6 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter playlistName = args.getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME);
albumListType = args.getString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE);
albumListSize = args.getInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0);
- albumListOffset = args.getInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0);
}
load(false);
@@ -246,7 +245,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter if (playlistId != null) {
getPlaylist(playlistId, playlistName);
} else if (albumListType != null) {
- getAlbumList(albumListType, albumListSize, albumListOffset);
+ getAlbumList(albumListType, albumListSize);
} else {
getMusicDirectory(id, name, refresh);
}
@@ -274,7 +273,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter }.execute();
}
- private void getAlbumList(final String albumListType, final int size, final int offset) {
+ private void getAlbumList(final String albumListType, final int size) {
showHeader = false;
if ("newest".equals(albumListType)) {
@@ -298,31 +297,10 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter if ("starred".equals(albumListType)) {
result = service.getStarredList(context, this);
} else {
- result = service.getAlbumList(albumListType, size, offset, context, this);
+ result = service.getAlbumList(albumListType, size, 0, context, this);
}
return result;
}
-
- @Override
- protected void done(Pair<MusicDirectory, Boolean> result) {
- if (!result.getFirst().getChildren().isEmpty()) {
- if (!("starred".equals(albumListType))) {
- moreButton.setVisibility(View.VISIBLE);
- if(entryList.getFooterViewsCount() == 0) {
- entryList.addFooterView(footer);
- }
- }
-
- moreButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- albumListOffset += albumListSize;
- refresh();
- }
- });
- }
- super.done(result);
- }
}.execute();
}
@@ -366,7 +344,12 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter }
emptyView.setVisibility(entries.isEmpty() ? View.VISIBLE : View.GONE);
- entryList.setAdapter(entryAdapter = new EntryAdapter(context, getImageLoader(), entries, true));
+ entryAdapter = new EntryAdapter(context, getImageLoader(), entries, true);
+ if(albumListType == null || "starred".equals(albumListType)) {
+ entryList.setAdapter(entryAdapter);
+ } else {
+ entryList.setAdapter(new AlbumListAdapter(context, entryAdapter, albumListType, albumListSize));
+ }
entryList.setVisibility(View.VISIBLE);
licenseValid = result.getSecond();
context.invalidateOptionsMenu();
diff --git a/subsonic-android/src/github/daneren2005/dsub/view/AlbumListAdapter.java b/subsonic-android/src/github/daneren2005/dsub/view/AlbumListAdapter.java new file mode 100644 index 00000000..60dc89f9 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/view/AlbumListAdapter.java @@ -0,0 +1,74 @@ +/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 (C) Sindre Mehus
+ */
+package github.daneren2005.dsub.view;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import com.commonsware.cwac.endless.EndlessAdapter;
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.service.MusicService;
+import github.daneren2005.dsub.service.MusicServiceFactory;
+import java.util.List;
+
+public class AlbumListAdapter extends EndlessAdapter {
+ Context context;
+ ArrayAdapter<MusicDirectory.Entry> adapter;
+ String type;
+ int size;
+ int offset;
+ List<MusicDirectory.Entry> entries;
+
+ public AlbumListAdapter(Context context, ArrayAdapter<MusicDirectory.Entry> adapter, String type, int size) {
+ super(adapter);
+ this.context = context;
+ this.adapter = adapter;
+ this.type = type;
+ this.size = size;
+ this.offset = size;
+ }
+
+ @Override
+ protected boolean cacheInBackground() throws Exception {
+ MusicService service = MusicServiceFactory.getMusicService(context);
+ MusicDirectory result = service.getAlbumList(type, size, offset, context, null);
+ entries = result.getChildren();
+ if(entries.size() > 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ protected void appendCachedData() {
+ for(MusicDirectory.Entry entry: entries) {
+ adapter.add(entry);
+ }
+ offset += entries.size();
+ }
+
+ @Override
+ protected View getPendingView(ViewGroup parent) {
+ return LayoutInflater.from(context).inflate(R.layout.tab_progress, null);
+ }
+}
|