This commit is contained in:
Dmitriy Prodchenko 2018-05-07 18:12:21 +03:00
commit 9ee379e816
2 changed files with 33 additions and 2 deletions

View file

@ -52,6 +52,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
private TravelDownloadUpdateCard downloadUpdateCard;
private TravelNeededMapsCard neededMapsCard;
private DownloadValidationManager downloadManager;
private IndexItem currentDownloadingIndexItem;
private IndexItem mainIndexItem;
private List<IndexItem> neededIndexItems = new ArrayList<>();
@ -61,6 +62,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
downloadManager = new DownloadValidationManager(getMyApplication());
nightMode = !getMyApplication().getSettings().isLightContent();
final View mainView = inflater.inflate(R.layout.fragment_explore_tab, container, false);
@ -190,7 +192,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
@Override
public void onPrimaryButtonClick() {
if (mainIndexItem != null) {
new DownloadValidationManager(app).startDownload(getMyActivity(), mainIndexItem);
downloadManager.startDownload(getMyActivity(), mainIndexItem);
adapter.updateDownloadUpdateCard();
}
}
@ -227,7 +229,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
@Override
public void onPrimaryButtonClick() {
IndexItem[] items = neededIndexItems.toArray(new IndexItem[neededIndexItems.size()]);
new DownloadValidationManager(app).startDownload(getMyActivity(), items);
downloadManager.startDownload(getMyActivity(), items);
adapter.updateNeededMapsCard();
}
@ -240,6 +242,17 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
removeNeededMapsCard();
}
}
@Override
public void onIndexItemClick(IndexItem item) {
DownloadIndexesThread downloadThread = app.getDownloadThread();
if (downloadThread.isDownloading(item)) {
downloadThread.cancelDownload(item);
} else {
downloadManager.startDownload(getMyActivity(), item);
}
adapter.updateNeededMapsCard();
}
});
adapter.setNeededMapsCard(neededMapsCard);
}

View file

@ -28,6 +28,7 @@ public class TravelNeededMapsCard extends BaseTravelCard {
private Drawable cancelIcon;
private CardListener listener;
private View.OnClickListener onItemClickListener;
public void setListener(CardListener listener) {
this.listener = listener;
@ -39,6 +40,14 @@ public class TravelNeededMapsCard extends BaseTravelCard {
this.items = items;
downloadIcon = getActiveIcon(R.drawable.ic_action_import);
cancelIcon = getActiveIcon(R.drawable.ic_action_remove_dark);
onItemClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.onIndexItemClick((IndexItem) view.getTag());
}
}
};
}
@Override
@ -57,6 +66,13 @@ public class TravelNeededMapsCard extends BaseTravelCard {
boolean lastItem = i == items.size() - 1;
View view = holder.itemsContainer.getChildAt(i);
if (item.isDownloaded()) {
view.setOnClickListener(null);
} else {
view.setTag(item);
view.setOnClickListener(onItemClickListener);
}
((ImageView) view.findViewById(R.id.icon))
.setImageDrawable(getActiveIcon(item.getType().getIconResource()));
((TextView) view.findViewById(R.id.title))
@ -177,6 +193,8 @@ public class TravelNeededMapsCard extends BaseTravelCard {
void onPrimaryButtonClick();
void onSecondaryButtonClick();
void onIndexItemClick(IndexItem item);
}
public static class NeededMapsVH extends RecyclerView.ViewHolder {