summaryrefslogtreecommitdiff
path: root/src/de/danoeh
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2013-02-18 19:11:33 +0100
committerdaniel oeh <daniel.oeh@gmail.com>2013-02-18 19:11:33 +0100
commitef50c412c94bcff92ba88149d94e3e2449725cc4 (patch)
tree888869b63ddafbb10f05c9ae798f9ffbb6b6bd6d /src/de/danoeh
parent89d4bdc9c6c000632d42fe548f1dedaa4c6dbd05 (diff)
downloadAntennaPod-ef50c412c94bcff92ba88149d94e3e2449725cc4.zip
Implemented drag & drop reordering
Diffstat (limited to 'src/de/danoeh')
-rw-r--r--src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java61
-rw-r--r--src/de/danoeh/antennapod/feed/FeedManager.java34
-rw-r--r--src/de/danoeh/antennapod/fragment/EpisodesFragment.java3
3 files changed, 86 insertions, 12 deletions
diff --git a/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java b/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java
index 8c194f138..a7017d2fb 100644
--- a/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java
+++ b/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java
@@ -2,7 +2,10 @@ package de.danoeh.antennapod.activity;
import java.util.List;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -15,6 +18,7 @@ import android.widget.TextView;
import com.actionbarsherlock.app.SherlockListActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
+import com.mobeta.android.dslv.DragSortListView;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R;
@@ -26,13 +30,18 @@ public class OrganizeQueueActivity extends SherlockListActivity {
private static final String TAG = "OrganizeQueueActivity";
private static final int MENU_ID_ACCEPT = 2;
-
+
private OrganizeAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(PodcastApp.getThemeResourceId());
super.onCreate(savedInstanceState);
+ setContentView(R.layout.organize_queue);
+
+ DragSortListView listView = (DragSortListView) getListView();
+ listView.setDropListener(dropListener);
+ listView.setRemoveListener(removeListener);
adapter = new OrganizeAdapter(this, 0, FeedManager.getInstance()
.getQueue());
@@ -40,6 +49,55 @@ public class OrganizeQueueActivity extends SherlockListActivity {
}
@Override
+ protected void onPause() {
+ super.onPause();
+ try {
+ unregisterReceiver(contentUpdate);
+ } catch (IllegalArgumentException e) {
+
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ IntentFilter filter = new IntentFilter(FeedManager.ACTION_QUEUE_UPDATE);
+ filter.addAction(FeedManager.ACTION_FEED_LIST_UPDATE);
+ registerReceiver(contentUpdate, filter);
+ }
+
+ private BroadcastReceiver contentUpdate = new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (adapter != null) {
+ adapter.notifyDataSetChanged();
+ }
+ }
+
+ };
+
+ private DragSortListView.DropListener dropListener = new DragSortListView.DropListener() {
+
+ @Override
+ public void drop(int from, int to) {
+ FeedManager manager = FeedManager.getInstance();
+ manager.moveQueueItem(OrganizeQueueActivity.this, from, to, false);
+ adapter.notifyDataSetChanged();
+ }
+ };
+
+ private DragSortListView.RemoveListener removeListener = new DragSortListView.RemoveListener() {
+
+ @Override
+ public void remove(int which) {
+ FeedManager manager = FeedManager.getInstance();
+ manager.removeQueueItem(OrganizeQueueActivity.this,
+ (FeedItem) getListAdapter().getItem(which));
+ }
+ };
+
+ @Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
TypedArray drawables = obtainStyledAttributes(new int[] { R.attr.navigation_accept });
@@ -112,7 +170,6 @@ public class OrganizeQueueActivity extends SherlockListActivity {
TextView title;
TextView feedTitle;
ImageView feedImage;
- View dragHandle;
}
}
diff --git a/src/de/danoeh/antennapod/feed/FeedManager.java b/src/de/danoeh/antennapod/feed/FeedManager.java
index 3e5e838b0..6c3471e5c 100644
--- a/src/de/danoeh/antennapod/feed/FeedManager.java
+++ b/src/de/danoeh/antennapod/feed/FeedManager.java
@@ -765,16 +765,29 @@ public class FeedManager {
}
}
- public void moveQueueItem(final Context context, FeedItem item, int delta) {
+ /**
+ * Moves the queue item at the specified index to another position. If the
+ * indices are out of range, no operation will be performed.
+ *
+ * @param from
+ * index of the item that is going to be moved
+ * @param to
+ * destination index of item
+ * @param broadcastUpdate
+ * true if the method should send a queue update broadcast after
+ * the operation has been performed. This should be set to false
+ * if the order of the queue is changed through drag & drop
+ * reordering to avoid visual glitches.
+ */
+ public void moveQueueItem(final Context context, int from, int to,
+ boolean broadcastUpdate) {
if (AppConfig.DEBUG)
- Log.d(TAG, "Moving queue item");
- int itemIndex = queue.indexOf(item);
- int newIndex = itemIndex + delta;
- if (newIndex >= 0 && newIndex < queue.size()) {
- FeedItem oldItem = queue.set(newIndex, item);
- queue.set(itemIndex, oldItem);
+ Log.d(TAG, "Moving queue item from index " + from + " to index "
+ + to);
+ if (from >= 0 && from < queue.size() && to >= 0 && to < queue.size()) {
+ FeedItem item = queue.remove(from);
+ queue.add(to, item);
dbExec.execute(new Runnable() {
-
@Override
public void run() {
PodDBAdapter adapter = new PodDBAdapter(context);
@@ -783,9 +796,10 @@ public class FeedManager {
adapter.close();
}
});
-
+ if (broadcastUpdate) {
+ sendQueueUpdateBroadcast(context, item);
+ }
}
- sendQueueUpdateBroadcast(context, item);
}
public boolean isInQueue(FeedItem item) {
diff --git a/src/de/danoeh/antennapod/fragment/EpisodesFragment.java b/src/de/danoeh/antennapod/fragment/EpisodesFragment.java
index 967cfd2bc..843cf5af0 100644
--- a/src/de/danoeh/antennapod/fragment/EpisodesFragment.java
+++ b/src/de/danoeh/antennapod/fragment/EpisodesFragment.java
@@ -63,6 +63,9 @@ public class EpisodesFragment extends SherlockFragment {
filter.addAction(FeedManager.ACTION_FEED_LIST_UPDATE);
getActivity().registerReceiver(contentUpdate, filter);
+ if (adapter != null) {
+ adapter.notifyDataSetChanged();
+ }
}
@Override