change List<Object> items to List<BaseTravelCard> items
This commit is contained in:
parent
6d9f826d6a
commit
5b0f3461b9
2 changed files with 17 additions and 31 deletions
|
@ -8,6 +8,7 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.wikivoyage.explore.travelcards.BaseTravelCard;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard;
|
import net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard.ArticleTravelVH;
|
import net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard.ArticleTravelVH;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard;
|
import net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard;
|
||||||
|
@ -24,7 +25,7 @@ import java.util.List;
|
||||||
|
|
||||||
public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
private final List<Object> items = new ArrayList<>();
|
private final List<BaseTravelCard> items = new ArrayList<>();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,7 +61,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
Object item = getItem(position);
|
BaseTravelCard item = getItem(position);
|
||||||
if (viewHolder instanceof HeaderTravelVH && item instanceof HeaderTravelCard) {
|
if (viewHolder instanceof HeaderTravelVH && item instanceof HeaderTravelCard) {
|
||||||
HeaderTravelCard headerTravelCard = (HeaderTravelCard) item;
|
HeaderTravelCard headerTravelCard = (HeaderTravelCard) item;
|
||||||
headerTravelCard.setArticleItemCount(getArticleItemCount());
|
headerTravelCard.setArticleItemCount(getArticleItemCount());
|
||||||
|
@ -69,30 +70,14 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
ArticleTravelCard articleTravelCard = (ArticleTravelCard) item;
|
ArticleTravelCard articleTravelCard = (ArticleTravelCard) item;
|
||||||
articleTravelCard.setLastItem(position == getLastArticleItemIndex());
|
articleTravelCard.setLastItem(position == getLastArticleItemIndex());
|
||||||
articleTravelCard.bindViewHolder(viewHolder);
|
articleTravelCard.bindViewHolder(viewHolder);
|
||||||
} else if (viewHolder instanceof OpenBetaTravelVH && item instanceof OpenBetaTravelCard) {
|
} else {
|
||||||
((OpenBetaTravelCard) item).bindViewHolder(viewHolder);
|
item.bindViewHolder(viewHolder);
|
||||||
} else if (viewHolder instanceof StartEditingTravelVH && item instanceof StartEditingTravelCard) {
|
|
||||||
((StartEditingTravelCard) item).bindViewHolder(viewHolder);
|
|
||||||
} else if (viewHolder instanceof DownloadUpdateVH && item instanceof TravelDownloadUpdateCard) {
|
|
||||||
((TravelDownloadUpdateCard) item).bindViewHolder(viewHolder);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
Object object = getItem(position);
|
return getItem(position).getCardType();
|
||||||
if (object instanceof HeaderTravelCard) {
|
|
||||||
return ((HeaderTravelCard) object).getCardType();
|
|
||||||
} else if (object instanceof OpenBetaTravelCard) {
|
|
||||||
return ((OpenBetaTravelCard) object).getCardType();
|
|
||||||
} else if (object instanceof StartEditingTravelCard) {
|
|
||||||
return ((StartEditingTravelCard) object).getCardType();
|
|
||||||
} else if (object instanceof ArticleTravelCard) {
|
|
||||||
return ((ArticleTravelCard) object).getCardType();
|
|
||||||
} else if (object instanceof TravelDownloadUpdateCard) {
|
|
||||||
return ((TravelDownloadUpdateCard) object).getCardType();
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -102,7 +87,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
|
|
||||||
public int getArticleItemCount() {
|
public int getArticleItemCount() {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Object o : items) {
|
for (BaseTravelCard o : items) {
|
||||||
if (o instanceof ArticleTravelCard) {
|
if (o instanceof ArticleTravelCard) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +97,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
|
|
||||||
private int getLastArticleItemIndex() {
|
private int getLastArticleItemIndex() {
|
||||||
for (int i = items.size() - 1; i > 0; i--) {
|
for (int i = items.size() - 1; i > 0; i--) {
|
||||||
Object o = items.get(i);
|
BaseTravelCard o = items.get(i);
|
||||||
if (o instanceof ArticleTravelCard) {
|
if (o instanceof ArticleTravelCard) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -120,21 +105,21 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getItem(int position) {
|
private BaseTravelCard getItem(int position) {
|
||||||
return items.get(position);
|
return items.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public List<Object> getItems() {
|
public List<BaseTravelCard> getItems() {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItems(List<Object> items) {
|
public void setItems(List<BaseTravelCard> items) {
|
||||||
this.items.clear();
|
this.items.clear();
|
||||||
this.items.addAll(items);
|
this.items.addAll(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addItem(int position, Object item) {
|
public boolean addItem(int position, BaseTravelCard item) {
|
||||||
if (position >= 0 && position <= items.size()) {
|
if (position >= 0 && position <= items.size()) {
|
||||||
items.add(position, item);
|
items.add(position, item);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -22,6 +22,7 @@ import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
|
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard;
|
import net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard;
|
||||||
|
import net.osmand.plus.wikivoyage.explore.travelcards.BaseTravelCard;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard;
|
import net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard;
|
import net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard;
|
import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard;
|
||||||
|
@ -56,8 +57,8 @@ public class ExploreTabFragment extends BaseOsmAndFragment {
|
||||||
return mainView;
|
return mainView;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Object> generateItems() {
|
private List<BaseTravelCard> generateItems() {
|
||||||
final List<Object> items = new ArrayList<>();
|
final List<BaseTravelCard> items = new ArrayList<>();
|
||||||
final OsmandApplication app = getMyApplication();
|
final OsmandApplication app = getMyApplication();
|
||||||
|
|
||||||
addDownloadUpdateCard();
|
addDownloadUpdateCard();
|
||||||
|
@ -91,7 +92,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment {
|
||||||
popularDestinationsSearchTask.execute();
|
popularDestinationsSearchTask.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addOpenBetaTravelCard(List<Object> items, final boolean nightMode) {
|
private void addOpenBetaTravelCard(List<BaseTravelCard> items, final boolean nightMode) {
|
||||||
final OsmandApplication app = getMyApplication();
|
final OsmandApplication app = getMyApplication();
|
||||||
if ((Version.isFreeVersion(app) && !app.getSettings().LIVE_UPDATES_PURCHASED.get()
|
if ((Version.isFreeVersion(app) && !app.getSettings().LIVE_UPDATES_PURCHASED.get()
|
||||||
&& !app.getSettings().FULL_VERSION_PURCHASED.get())) {
|
&& !app.getSettings().FULL_VERSION_PURCHASED.get())) {
|
||||||
|
@ -167,7 +168,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment {
|
||||||
StartEditingTravelCard startEditingTravelCard = weakStartEditingTravelCard.get();
|
StartEditingTravelCard startEditingTravelCard = weakStartEditingTravelCard.get();
|
||||||
|
|
||||||
if (activity != null && adapter != null && startEditingTravelCard != null) {
|
if (activity != null && adapter != null && startEditingTravelCard != null) {
|
||||||
List<Object> adapterItems = adapter.getItems();
|
List<BaseTravelCard> adapterItems = adapter.getItems();
|
||||||
|
|
||||||
if (adapterItems.contains(startEditingTravelCard)) {
|
if (adapterItems.contains(startEditingTravelCard)) {
|
||||||
adapterItems.remove(startEditingTravelCard);
|
adapterItems.remove(startEditingTravelCard);
|
||||||
|
|
Loading…
Reference in a new issue