Implemented drag & drop reordering
This commit is contained in:
parent
89d4bdc9c6
commit
ef50c412c9
|
@ -0,0 +1,35 @@
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:dslv="http://schemas.android.com/apk/res/de.danoeh.antennapod"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<com.mobeta.android.dslv.DragSortListView
|
||||||
|
android:id="@android:id/list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
dslv:collapsed_height="2dp"
|
||||||
|
dslv:drag_enabled="true"
|
||||||
|
dslv:drag_handle_id="@id/drag_handle"
|
||||||
|
dslv:drag_scroll_start="0.33"
|
||||||
|
dslv:drag_start_mode="onDown"
|
||||||
|
dslv:float_alpha="0.6"
|
||||||
|
dslv:max_drag_scroll_speed="0.5"
|
||||||
|
dslv:remove_enabled="true"
|
||||||
|
dslv:remove_mode="flingRemove"
|
||||||
|
dslv:slide_shuffle_speed="0.3"
|
||||||
|
dslv:sort_enabled="true"
|
||||||
|
dslv:track_drag_sort="false"
|
||||||
|
dslv:use_default_controller="true" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@id/android:empty"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/no_feeds_label" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -11,7 +11,7 @@
|
||||||
android:scaleType="centerCrop" />
|
android:scaleType="centerCrop" />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:id="@+id/dragHandle"
|
android:id="@id/drag_handle"
|
||||||
android:layout_width="@dimen/dragview_length"
|
android:layout_width="@dimen/dragview_length"
|
||||||
android:layout_height="@dimen/dragview_length"
|
android:layout_height="@dimen/dragview_length"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
android:layout_marginLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_toLeftOf="@id/dragHandle"
|
android:layout_toLeftOf="@id/drag_handle"
|
||||||
android:layout_toRightOf="@id/imgvFeedimage"
|
android:layout_toRightOf="@id/imgvFeedimage"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:lines="2"
|
android:lines="2"
|
||||||
|
@ -46,7 +46,7 @@
|
||||||
android:layout_below="@id/txtvTitle"
|
android:layout_below="@id/txtvTitle"
|
||||||
android:layout_marginLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
android:layout_marginRight="8dp"
|
android:layout_marginRight="8dp"
|
||||||
android:layout_toLeftOf="@id/dragHandle"
|
android:layout_toLeftOf="@id/drag_handle"
|
||||||
android:layout_toRightOf="@id/imgvFeedimage"
|
android:layout_toRightOf="@id/imgvFeedimage"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
|
|
|
@ -10,5 +10,5 @@
|
||||||
<item name="download_all_item" type="id"/>
|
<item name="download_all_item" type="id"/>
|
||||||
<item name="clear_history_item" type="id"/>
|
<item name="clear_history_item" type="id"/>
|
||||||
<item name="organize_queue_item" type="id"/>
|
<item name="organize_queue_item" type="id"/>
|
||||||
|
<item name="drag_handle" type="id" />
|
||||||
</resources>
|
</resources>
|
|
@ -2,7 +2,10 @@ package de.danoeh.antennapod.activity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -15,6 +18,7 @@ import android.widget.TextView;
|
||||||
import com.actionbarsherlock.app.SherlockListActivity;
|
import com.actionbarsherlock.app.SherlockListActivity;
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import com.actionbarsherlock.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
import com.mobeta.android.dslv.DragSortListView;
|
||||||
|
|
||||||
import de.danoeh.antennapod.PodcastApp;
|
import de.danoeh.antennapod.PodcastApp;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
|
@ -33,12 +37,66 @@ public class OrganizeQueueActivity extends SherlockListActivity {
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
setTheme(PodcastApp.getThemeResourceId());
|
setTheme(PodcastApp.getThemeResourceId());
|
||||||
super.onCreate(savedInstanceState);
|
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()
|
adapter = new OrganizeAdapter(this, 0, FeedManager.getInstance()
|
||||||
.getQueue());
|
.getQueue());
|
||||||
setListAdapter(adapter);
|
setListAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
super.onCreateOptionsMenu(menu);
|
super.onCreateOptionsMenu(menu);
|
||||||
|
@ -112,7 +170,6 @@ public class OrganizeQueueActivity extends SherlockListActivity {
|
||||||
TextView title;
|
TextView title;
|
||||||
TextView feedTitle;
|
TextView feedTitle;
|
||||||
ImageView feedImage;
|
ImageView feedImage;
|
||||||
View dragHandle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Moving queue item");
|
Log.d(TAG, "Moving queue item from index " + from + " to index "
|
||||||
int itemIndex = queue.indexOf(item);
|
+ to);
|
||||||
int newIndex = itemIndex + delta;
|
if (from >= 0 && from < queue.size() && to >= 0 && to < queue.size()) {
|
||||||
if (newIndex >= 0 && newIndex < queue.size()) {
|
FeedItem item = queue.remove(from);
|
||||||
FeedItem oldItem = queue.set(newIndex, item);
|
queue.add(to, item);
|
||||||
queue.set(itemIndex, oldItem);
|
|
||||||
dbExec.execute(new Runnable() {
|
dbExec.execute(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
|
@ -783,10 +796,11 @@ public class FeedManager {
|
||||||
adapter.close();
|
adapter.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (broadcastUpdate) {
|
||||||
}
|
|
||||||
sendQueueUpdateBroadcast(context, item);
|
sendQueueUpdateBroadcast(context, item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isInQueue(FeedItem item) {
|
public boolean isInQueue(FeedItem item) {
|
||||||
return queue.contains(item);
|
return queue.contains(item);
|
||||||
|
|
|
@ -63,6 +63,9 @@ public class EpisodesFragment extends SherlockFragment {
|
||||||
filter.addAction(FeedManager.ACTION_FEED_LIST_UPDATE);
|
filter.addAction(FeedManager.ACTION_FEED_LIST_UPDATE);
|
||||||
|
|
||||||
getActivity().registerReceiver(contentUpdate, filter);
|
getActivity().registerReceiver(contentUpdate, filter);
|
||||||
|
if (adapter != null) {
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue