aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/github/daneren2005/dsub/view/UpdateView.java')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/view/UpdateView.java89
1 files changed, 54 insertions, 35 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java b/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java
index f9c62121..8e1029df 100644
--- a/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java
+++ b/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java
@@ -20,9 +20,9 @@ package github.daneren2005.dsub.view;
import android.content.Context;
import android.content.res.TypedArray;
-import android.graphics.Color;
import android.os.Handler;
import android.os.Looper;
+import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@@ -37,20 +37,20 @@ import java.util.List;
import java.util.WeakHashMap;
import github.daneren2005.dsub.domain.MusicDirectory;
-import github.daneren2005.dsub.util.ImageLoader;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.util.SilentBackgroundTask;
-public class UpdateView extends LinearLayout {
+public abstract class UpdateView<T> extends LinearLayout {
private static final String TAG = UpdateView.class.getSimpleName();
private static final WeakHashMap<UpdateView, ?> INSTANCES = new WeakHashMap<UpdateView, Object>();
- private static Handler backgroundHandler;
- private static Handler uiHandler;
+ protected static Handler backgroundHandler;
+ protected static Handler uiHandler;
private static Runnable updateRunnable;
private static int activeActivities = 0;
protected Context context;
+ protected T item;
protected RatingBar ratingBar;
protected ImageButton starButton;
protected ImageView moreButton;
@@ -65,6 +65,7 @@ public class UpdateView extends LinearLayout {
protected SilentBackgroundTask<Void> imageTask = null;
protected final boolean autoUpdate;
+ protected boolean checkable;
public UpdateView(Context context) {
this(context, true);
@@ -75,8 +76,8 @@ public class UpdateView extends LinearLayout {
this.autoUpdate = autoUpdate;
setLayoutParams(new AbsListView.LayoutParams(
- ViewGroup.LayoutParams.FILL_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT));
+ ViewGroup.LayoutParams.FILL_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT));
if(autoUpdate) {
INSTANCES.put(this, null);
@@ -89,37 +90,16 @@ public class UpdateView extends LinearLayout {
}
- public void setObject(Object obj) {
+ public void setObject(T obj) {
+ item = obj;
setObjectImpl(obj);
updateBackground();
update();
}
- public void setObject(Object obj1, Object obj2) {
- if(imageTask != null) {
- imageTask.cancel();
- imageTask = null;
- }
-
- setObjectImpl(obj1, obj2);
- backgroundHandler.post(new Runnable() {
- @Override
- public void run() {
- updateBackground();
- uiHandler.post(new Runnable() {
- @Override
- public void run() {
- update();
- }
- });
- }
- });
- }
- protected void setObjectImpl(Object obj) {
-
- }
- protected void setObjectImpl(Object obj1, Object obj2) {
-
+ public void setObject(T obj1, Object obj2) {
+ setObject(obj1, null);
}
+ protected abstract void setObjectImpl(T obj);
private static synchronized void startUpdater() {
if(uiHandler != null) {
@@ -224,8 +204,6 @@ public class UpdateView extends LinearLayout {
MusicDirectory.Entry check = null;
if(view instanceof SongView) {
check = ((SongView) view).getEntry();
- } else if(view instanceof AlbumCell) {
- check = ((AlbumCell) view).getEntry();
} else if(view instanceof AlbumView) {
check = ((AlbumView) view).getEntry();
}
@@ -283,4 +261,45 @@ public class UpdateView extends LinearLayout {
rating = isRated;
}
}
+
+ public boolean isCheckable() {
+ return checkable;
+ }
+
+ public void onClick() {
+
+ }
+
+ public static class UpdateViewHolder<T> extends RecyclerView.ViewHolder {
+ private UpdateView updateView;
+ private View view;
+ private T item;
+
+ public UpdateViewHolder(UpdateView itemView) {
+ super(itemView);
+
+ this.updateView = itemView;
+ this.view = itemView;
+ }
+
+ // Different is so that call is not ambiguous
+ public UpdateViewHolder(View view, boolean different) {
+ super(view);
+ this.view = view;
+ }
+
+ public UpdateView<T> getUpdateView() {
+ return updateView;
+ }
+ public View getView() {
+ return view;
+ }
+ public void setItem(T item) {
+ this.item = item;
+ }
+ public T getItem() {
+ return item;
+ }
+ }
}
+