Merge pull request #1994 from mfietz/issue/1859-add-tile
Subscriptions: Move add tile to end
This commit is contained in:
commit
78ae4f620b
|
@ -30,8 +30,8 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI
|
||||||
/** placeholder object that indicates item should be added */
|
/** placeholder object that indicates item should be added */
|
||||||
public static final Object ADD_ITEM_OBJ = new Object();
|
public static final Object ADD_ITEM_OBJ = new Object();
|
||||||
|
|
||||||
/** the position in the view that holds the add item */
|
/** the position in the view that holds the add item; 0 is the first, -1 is the last position */
|
||||||
private static final int ADD_POSITION = 0;
|
private static final int ADD_POSITION = -1;
|
||||||
private static final String TAG = "SubscriptionsAdapter";
|
private static final String TAG = "SubscriptionsAdapter";
|
||||||
|
|
||||||
private final WeakReference<MainActivity> mainActivityRef;
|
private final WeakReference<MainActivity> mainActivityRef;
|
||||||
|
@ -42,8 +42,16 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI
|
||||||
this.itemAccess = itemAccess;
|
this.itemAccess = itemAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getAddTilePosition() {
|
||||||
|
if(ADD_POSITION < 0) {
|
||||||
|
return ADD_POSITION + getCount();
|
||||||
|
}
|
||||||
|
return ADD_POSITION;
|
||||||
|
}
|
||||||
|
|
||||||
private int getAdjustedPosition(int origPosition) {
|
private int getAdjustedPosition(int origPosition) {
|
||||||
return origPosition - 1;
|
assert(origPosition != getAddTilePosition());
|
||||||
|
return origPosition < getAddTilePosition() ? origPosition : origPosition - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,15 +61,20 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getItem(int position) {
|
public Object getItem(int position) {
|
||||||
if (position == ADD_POSITION) {
|
if (position == getAddTilePosition()) {
|
||||||
return ADD_ITEM_OBJ;
|
return ADD_ITEM_OBJ;
|
||||||
}
|
}
|
||||||
return itemAccess.getItem(getAdjustedPosition(position));
|
return itemAccess.getItem(getAdjustedPosition(position));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasStableIds() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getItemId(int position) {
|
public long getItemId(int position) {
|
||||||
if (position == ADD_POSITION) {
|
if (position == getAddTilePosition()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return itemAccess.getItem(getAdjustedPosition(position)).getId();
|
return itemAccess.getItem(getAdjustedPosition(position)).getId();
|
||||||
|
@ -87,7 +100,7 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI
|
||||||
holder = (Holder) convertView.getTag();
|
holder = (Holder) convertView.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position == ADD_POSITION) {
|
if (position == getAddTilePosition()) {
|
||||||
holder.feedTitle.setText("{md-add 500%}\n\n" + mainActivityRef.get().getString(R.string.add_feed_label));
|
holder.feedTitle.setText("{md-add 500%}\n\n" + mainActivityRef.get().getString(R.string.add_feed_label));
|
||||||
holder.feedTitle.setVisibility(View.VISIBLE);
|
holder.feedTitle.setVisibility(View.VISIBLE);
|
||||||
// prevent any accidental re-use of old values (not sure how that would happen...)
|
// prevent any accidental re-use of old values (not sure how that would happen...)
|
||||||
|
|
Loading…
Reference in New Issue