Skip to content

Commit

Permalink
Fix top 30 drinks items position update.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimowner committed Feb 15, 2019
1 parent 0050ef7 commit 83db6a8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ext.versions = [

def versionMajor = 1
def versionMinor = 1
def versionPatch = 2
def versionPatch = 3

android {
compileSdkVersion versions.targetSdkVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
// && oldProduct.getCategory().equals(newProduct.getCategory())
// && oldProduct.getAlcoholic().equals(newProduct.getAlcoholic())
// && oldProduct.getGlass().equals(newProduct.getGlass())
&& oldProduct.getPosition() == newProduct.getPosition()
&& oldProduct.getHistory() == newProduct.getHistory()
&& oldProduct.isFavorite() == newProduct.isFavorite();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ListItem implements Parcelable {
/** Time stamp when last time user opened this cocktail details. */
private final long history;
private final boolean isFavorite;
private int position = 0;

public ListItem(long id, String name, String description, String category, String alcoholic,
String glass, String avatar_url, long history, boolean isFavorite) {
Expand Down Expand Up @@ -84,6 +85,14 @@ public boolean isFavorite() {
return isFavorite;
}

public int getPosition() {
return position;
}

public void setPosition(int position) {
this.position = position;
}

//----- START Parcelable implementation ----------
private ListItem(Parcel in) {
long[] longs = new long[2];
Expand All @@ -101,6 +110,7 @@ private ListItem(Parcel in) {
boolean[] bools = new boolean[1];
in.readBooleanArray(bools);
isFavorite = bools[0];
position = in.readInt();
}

public int describeContents() {
Expand All @@ -111,6 +121,7 @@ public void writeToParcel(Parcel out, int flags) {
out.writeLongArray(new long[] {id, history});
out.writeStringArray(new String[] {name, description, category, alcoholic, glass, avatar_url});
out.writeBooleanArray(new boolean[] {isFavorite});
out.writeInt(position);
}

public static final Parcelable.Creator<ListItem> CREATOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ public ListItem getItem(int pos) {
}

public void setData(List<ListItem> data) {
for (int i = 0; i < data.size(); i++) {
data.get(i).setPosition(i);
}
CocktailsDiffUtilCallback productDiffUtilCallback = new CocktailsDiffUtilCallback(mShowingData, data);
DiffUtil.DiffResult productDiffResult = DiffUtil.calculateDiff(productDiffUtilCallback);
this.mShowingData.clear();
Expand Down

0 comments on commit 83db6a8

Please sign in to comment.