Add logic for "Later" button

This commit is contained in:
Alex Sytnyk 2018-05-07 14:29:57 +03:00
parent 2949be12d7
commit e8038dddf6
2 changed files with 18 additions and 1 deletions

View file

@ -143,6 +143,14 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
} }
} }
public void removeNeededMapsCard() {
int pos = getNeededMapsCardPosition();
if (neededMapsCardExists(pos)) {
removeItem(pos);
notifyItemRemoved(pos);
}
}
private int getNeededMapsCardPosition() { private int getNeededMapsCardPosition() {
if (downloadUpdateCardExists(FIRST_POSITION)) { if (downloadUpdateCardExists(FIRST_POSITION)) {
return SECOND_POSITION; return SECOND_POSITION;
@ -150,6 +158,10 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
return FIRST_POSITION; return FIRST_POSITION;
} }
private boolean neededMapsCardExists(int position) {
return items.size() > position && items.get(position).getCardType() == TravelNeededMapsCard.TYPE;
}
public void setDownloadUpdateCard(TravelDownloadUpdateCard card) { public void setDownloadUpdateCard(TravelDownloadUpdateCard card) {
if (addItem(getDownloadUpdateCardPosition(), card)) { if (addItem(getDownloadUpdateCardPosition(), card)) {
notifyDataSetChanged(); notifyDataSetChanged();

View file

@ -231,7 +231,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
if (neededMapsCard.isDownloading()) { if (neededMapsCard.isDownloading()) {
Toast.makeText(getContext(), "Cancel", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Cancel", Toast.LENGTH_SHORT).show();
} else { } else {
Toast.makeText(getContext(), "Later", Toast.LENGTH_SHORT).show(); removeNeededMapsCard();
} }
} }
}); });
@ -250,6 +250,11 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
downloadUpdateCard = null; downloadUpdateCard = null;
} }
private void removeNeededMapsCard() {
adapter.removeNeededMapsCard();
neededMapsCard = null;
}
private static class ProcessIndexItemsTask extends AsyncTask<Void, Void, Pair<IndexItem, List<IndexItem>>> { private static class ProcessIndexItemsTask extends AsyncTask<Void, Void, Pair<IndexItem, List<IndexItem>>> {
private static DownloadActivityType[] types = new DownloadActivityType[]{ private static DownloadActivityType[] types = new DownloadActivityType[]{