Reordering of favorites list

This commit is contained in:
Doug Keen 2013-03-24 18:38:06 -07:00
parent 0c51fe904d
commit fcc9f2ba21
9 changed files with 65 additions and 5 deletions

View File

@ -13,3 +13,4 @@ android.library.reference.1=../ActionBarSherlock/library
android.library.reference.2=../HoloEverywhere/library android.library.reference.2=../HoloEverywhere/library
android.library.reference.3=../NineOldAndroids/library android.library.reference.3=../NineOldAndroids/library
android.library.reference.4=../android-numberpicker/library android.library.reference.4=../android-numberpicker/library
android.library.reference.5=../drag-sort-listview/library

BIN
res/drawable-hdpi/drag_handle.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

BIN
res/drawable-mdpi/drag_handle.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 429 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 B

View File

@ -6,6 +6,15 @@
android:paddingLeft="5dp" android:paddingLeft="5dp"
android:paddingRight="5dp" > android:paddingRight="5dp" >
<ImageView
android:id="@+id/dragHandle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:contentDescription="Drag handle"
android:src="@drawable/drag_handle" />
<com.dougkeen.bart.controls.CountdownTextView <com.dougkeen.bart.controls.CountdownTextView
android:id="@+id/countdownText" android:id="@+id/countdownText"
style="@style/DepartureCountdownText" style="@style/DepartureCountdownText"
@ -25,15 +34,16 @@
<TextView <TextView
android:id="@+id/originText" android:id="@+id/originText"
style="@style/FavoriteListingTextView" style="@style/FavoriteListingTextView"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/countdownText" android:layout_toLeftOf="@id/countdownText"
android:layout_toRightOf="@id/dragHandle"
android:text="Origin" /> android:text="Origin" />
<TextView <TextView
android:id="@+id/to" android:id="@+id/to"
style="@style/FavoriteListingTextView" style="@style/FavoriteListingTextView"
android:layout_below="@id/originText" android:layout_below="@id/originText"
android:layout_toRightOf="@id/dragHandle"
android:paddingLeft="15dp" android:paddingLeft="15dp"
android:paddingRight="8dp" android:paddingRight="8dp"
android:text="to" /> android:text="to" />

View File

@ -1,15 +1,28 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.dougkeen.bart"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:gravity="center" android:gravity="center"
android:orientation="vertical" > android:orientation="vertical" >
<ListView <com.mobeta.android.dslv.DragSortListView
android:id="@android:id/list" android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" /> android:layout_margin="3dp"
android:layout_weight="1"
android:dividerHeight="1dp"
android:padding="3dp"
app:collapsed_height="1dp"
app:drag_enabled="true"
app:drag_handle_id="@id/dragHandle"
app:drag_scroll_start="0.33"
app:drag_start_mode="onDown"
app:float_alpha="0.6"
app:remove_enabled="true"
app:remove_mode="flingRemove"
app:slide_shuffle_speed="0.3" />
<TextView <TextView
android:id="@android:id/empty" android:id="@android:id/empty"

View File

@ -17,7 +17,6 @@ import com.WazaBe.HoloEverywhere.app.AlertDialog;
import com.WazaBe.HoloEverywhere.app.AlertDialog.Builder; import com.WazaBe.HoloEverywhere.app.AlertDialog.Builder;
import com.WazaBe.HoloEverywhere.app.DialogFragment; import com.WazaBe.HoloEverywhere.app.DialogFragment;
import com.WazaBe.HoloEverywhere.sherlock.SActivity; import com.WazaBe.HoloEverywhere.sherlock.SActivity;
import com.WazaBe.HoloEverywhere.widget.ListView;
import com.WazaBe.HoloEverywhere.widget.TextView; import com.WazaBe.HoloEverywhere.widget.TextView;
import com.actionbarsherlock.view.ActionMode; import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
@ -46,6 +45,7 @@ import com.googlecode.androidannotations.annotations.ItemLongClick;
import com.googlecode.androidannotations.annotations.UiThread; import com.googlecode.androidannotations.annotations.UiThread;
import com.googlecode.androidannotations.annotations.ViewById; import com.googlecode.androidannotations.annotations.ViewById;
import com.googlecode.androidannotations.annotations.rest.RestService; import com.googlecode.androidannotations.annotations.rest.RestService;
import com.mobeta.android.dslv.DragSortListView;
@EActivity(R.layout.main) @EActivity(R.layout.main)
public class RoutesListActivity extends SActivity implements TickSubscriber { public class RoutesListActivity extends SActivity implements TickSubscriber {
@ -74,7 +74,7 @@ public class RoutesListActivity extends SActivity implements TickSubscriber {
ElevatorClient elevatorClient; ElevatorClient elevatorClient;
@ViewById(android.R.id.list) @ViewById(android.R.id.list)
ListView listView; DragSortListView listView;
@ViewById(R.id.quickLookupButton) @ViewById(R.id.quickLookupButton)
Button quickLookupButton; Button quickLookupButton;
@ -107,6 +107,27 @@ public class RoutesListActivity extends SActivity implements TickSubscriber {
startContextualActionMode(); startContextualActionMode();
} }
private DragSortListView.DropListener onDrop = new DragSortListView.DropListener() {
@Override
public void drop(int from, int to) {
if (from == to)
return;
StationPair item = mRoutesAdapter.getItem(from);
mRoutesAdapter.move(item, to);
mRoutesAdapter.notifyDataSetChanged();
}
};
private DragSortListView.RemoveListener onRemove = new DragSortListView.RemoveListener() {
@Override
public void remove(int which) {
mRoutesAdapter.remove(mRoutesAdapter.getItem(which));
mRoutesAdapter.notifyDataSetChanged();
}
};
@AfterViews @AfterViews
void afterViews() { void afterViews() {
setTitle(R.string.favorite_routes); setTitle(R.string.favorite_routes);
@ -118,6 +139,9 @@ public class RoutesListActivity extends SActivity implements TickSubscriber {
listView.setEmptyView(findViewById(android.R.id.empty)); listView.setEmptyView(findViewById(android.R.id.empty));
listView.setDropListener(onDrop);
listView.setRemoveListener(onRemove);
if (mCurrentAlerts != null) { if (mCurrentAlerts != null) {
showAlertMessage(mCurrentAlerts); showAlertMessage(mCurrentAlerts);
} }

View File

@ -112,6 +112,11 @@ public class FavoritesArrayAdapter extends ArrayAdapter<StationPair> {
} }
} }
public void move(StationPair object, int to) {
super.remove(object);
super.insert(object, to);
}
@Override @Override
public void clear() { public void clear() {
super.clear(); super.clear();

View File

@ -43,6 +43,7 @@ public class StationPair implements Parcelable {
private Station origin; private Station origin;
private Station destination; private Station destination;
private String fare; private String fare;
private long fareLastUpdated; private long fareLastUpdated;
private int averageTripLength; private int averageTripLength;
private int averageTripSampleCount; private int averageTripSampleCount;
@ -126,6 +127,12 @@ public class StationPair implements Parcelable {
return true; return true;
} }
@Override
public String toString() {
return "StationPair [origin=" + origin + ", destination=" + destination
+ "]";
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;