aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github/daneren2005
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/github/daneren2005')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/EntryInfiniteGridAdapter.java57
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java2
2 files changed, 55 insertions, 4 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/EntryInfiniteGridAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/EntryInfiniteGridAdapter.java
index 3bc3f6aa..288c38a6 100644
--- a/app/src/main/java/github/daneren2005/dsub/adapter/EntryInfiniteGridAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/EntryInfiniteGridAdapter.java
@@ -16,9 +16,13 @@
package github.daneren2005.dsub.adapter;
import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
import java.util.List;
+import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.MusicDirectory.Entry;
import github.daneren2005.dsub.domain.ServerInfo;
@@ -26,8 +30,11 @@ import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.util.ImageLoader;
import github.daneren2005.dsub.util.SilentBackgroundTask;
+import github.daneren2005.dsub.view.UpdateView;
public class EntryInfiniteGridAdapter extends EntryGridAdapter {
+ public static int VIEW_TYPE_LOADING = 4;
+
private String type;
private String extra;
private int size;
@@ -39,6 +46,44 @@ public class EntryInfiniteGridAdapter extends EntryGridAdapter {
super(context, entries, imageLoader, largeCell);
}
+ @Override
+ public UpdateView.UpdateViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ if(viewType == VIEW_TYPE_LOADING) {
+ View progress = LayoutInflater.from(context).inflate(R.layout.tab_progress, null);
+ progress.setVisibility(View.VISIBLE);
+ return new UpdateView.UpdateViewHolder(progress, false);
+ }
+
+ return super.onCreateViewHolder(parent, viewType);
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ if(isLoadingView(position)) {
+ return VIEW_TYPE_LOADING;
+ }
+
+ return super.getItemViewType(position);
+ }
+
+ @Override
+ public void onBindViewHolder(UpdateView.UpdateViewHolder holder, int position) {
+ if(!isLoadingView(position)) {
+ super.onBindViewHolder(holder, position);
+ }
+ }
+
+ @Override
+ public int getItemCount() {
+ int size = super.getItemCount();
+
+ if(!allLoaded) {
+ size++;
+ }
+
+ return size;
+ }
+
public void setData(String type, String extra, int size) {
this.type = type;
this.extra = extra;
@@ -57,9 +102,6 @@ public class EntryInfiniteGridAdapter extends EntryGridAdapter {
@Override
protected Void doInBackground() throws Throwable {
newData = cacheInBackground();
- if(newData.isEmpty()) {
- allLoaded = true;
- }
return null;
}
@@ -67,6 +109,11 @@ public class EntryInfiniteGridAdapter extends EntryGridAdapter {
protected void done(Void result) {
appendCachedData(newData);
loading = false;
+
+ if(newData.isEmpty()) {
+ allLoaded = true;
+ notifyDataSetChanged();
+ }
}
}.execute();
}
@@ -92,4 +139,8 @@ public class EntryInfiniteGridAdapter extends EntryGridAdapter {
this.notifyItemRangeInserted(start, newData.size());
}
}
+
+ protected boolean isLoadingView(int position) {
+ return !allLoaded && position >= entries.size();
+ }
}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
index 7ab419cf..d427a26d 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
@@ -182,7 +182,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements EntryGr
@Override
public int getSpanSize(int position) {
int viewType = entryGridAdapter.getItemViewType(position);
- if(viewType == EntryGridAdapter.VIEW_TYPE_SONG || viewType == EntryGridAdapter.VIEW_TYPE_HEADER) {
+ if(viewType == EntryGridAdapter.VIEW_TYPE_SONG || viewType == EntryGridAdapter.VIEW_TYPE_HEADER || viewType == EntryInfiniteGridAdapter.VIEW_TYPE_LOADING) {
return columns;
} else {
return 1;