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 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.ArticleTravelVH;
|
||||
import net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard;
|
||||
|
@ -24,7 +25,7 @@ import java.util.List;
|
|||
|
||||
public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private final List<Object> items = new ArrayList<>();
|
||||
private final List<BaseTravelCard> items = new ArrayList<>();
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
|
@ -60,7 +61,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
||||
Object item = getItem(position);
|
||||
BaseTravelCard item = getItem(position);
|
||||
if (viewHolder instanceof HeaderTravelVH && item instanceof HeaderTravelCard) {
|
||||
HeaderTravelCard headerTravelCard = (HeaderTravelCard) item;
|
||||
headerTravelCard.setArticleItemCount(getArticleItemCount());
|
||||
|
@ -69,30 +70,14 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
ArticleTravelCard articleTravelCard = (ArticleTravelCard) item;
|
||||
articleTravelCard.setLastItem(position == getLastArticleItemIndex());
|
||||
articleTravelCard.bindViewHolder(viewHolder);
|
||||
} else if (viewHolder instanceof OpenBetaTravelVH && item instanceof OpenBetaTravelCard) {
|
||||
((OpenBetaTravelCard) 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);
|
||||
} else {
|
||||
item.bindViewHolder(viewHolder);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
Object object = getItem(position);
|
||||
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;
|
||||
return getItem(position).getCardType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -102,7 +87,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
|
||||
public int getArticleItemCount() {
|
||||
int count = 0;
|
||||
for (Object o : items) {
|
||||
for (BaseTravelCard o : items) {
|
||||
if (o instanceof ArticleTravelCard) {
|
||||
count++;
|
||||
}
|
||||
|
@ -112,7 +97,7 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
|
||||
private int getLastArticleItemIndex() {
|
||||
for (int i = items.size() - 1; i > 0; i--) {
|
||||
Object o = items.get(i);
|
||||
BaseTravelCard o = items.get(i);
|
||||
if (o instanceof ArticleTravelCard) {
|
||||
return i;
|
||||
}
|
||||
|
@ -120,21 +105,21 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
return 0;
|
||||
}
|
||||
|
||||
private Object getItem(int position) {
|
||||
private BaseTravelCard getItem(int position) {
|
||||
return items.get(position);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<Object> getItems() {
|
||||
public List<BaseTravelCard> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Object> items) {
|
||||
public void setItems(List<BaseTravelCard> items) {
|
||||
this.items.clear();
|
||||
this.items.addAll(items);
|
||||
}
|
||||
|
||||
public boolean addItem(int position, Object item) {
|
||||
public boolean addItem(int position, BaseTravelCard item) {
|
||||
if (position >= 0 && position <= items.size()) {
|
||||
items.add(position, item);
|
||||
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.TravelDbHelper;
|
||||
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.OpenBetaTravelCard;
|
||||
import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard;
|
||||
|
@ -56,8 +57,8 @@ public class ExploreTabFragment extends BaseOsmAndFragment {
|
|||
return mainView;
|
||||
}
|
||||
|
||||
private List<Object> generateItems() {
|
||||
final List<Object> items = new ArrayList<>();
|
||||
private List<BaseTravelCard> generateItems() {
|
||||
final List<BaseTravelCard> items = new ArrayList<>();
|
||||
final OsmandApplication app = getMyApplication();
|
||||
|
||||
addDownloadUpdateCard();
|
||||
|
@ -91,7 +92,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment {
|
|||
popularDestinationsSearchTask.execute();
|
||||
}
|
||||
|
||||
private void addOpenBetaTravelCard(List<Object> items, final boolean nightMode) {
|
||||
private void addOpenBetaTravelCard(List<BaseTravelCard> items, final boolean nightMode) {
|
||||
final OsmandApplication app = getMyApplication();
|
||||
if ((Version.isFreeVersion(app) && !app.getSettings().LIVE_UPDATES_PURCHASED.get()
|
||||
&& !app.getSettings().FULL_VERSION_PURCHASED.get())) {
|
||||
|
@ -167,7 +168,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment {
|
|||
StartEditingTravelCard startEditingTravelCard = weakStartEditingTravelCard.get();
|
||||
|
||||
if (activity != null && adapter != null && startEditingTravelCard != null) {
|
||||
List<Object> adapterItems = adapter.getItems();
|
||||
List<BaseTravelCard> adapterItems = adapter.getItems();
|
||||
|
||||
if (adapterItems.contains(startEditingTravelCard)) {
|
||||
adapterItems.remove(startEditingTravelCard);
|
||||
|
|
Loading…
Reference in a new issue