Move wiki image cards to plugin

This commit is contained in:
Vitaliy 2021-02-03 15:41:31 +02:00
parent 78c2dbbc1a
commit b30f651415
4 changed files with 50 additions and 24 deletions

View file

@ -69,6 +69,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
public abstract class OsmandPlugin { public abstract class OsmandPlugin {
@ -211,7 +212,9 @@ public abstract class OsmandPlugin {
return Collections.emptyList(); return Collections.emptyList();
} }
protected List<ImageCard> getImageCards(@Nullable GetImageCardsListener listener) { protected List<ImageCard> getImageCards(@NonNull Map<String, String> params,
@Nullable Map<String, String> additionalParams,
@Nullable GetImageCardsListener listener) {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -273,9 +276,9 @@ public abstract class OsmandPlugin {
allPlugins.clear(); allPlugins.clear();
allPlugins.add(new MapillaryPlugin(app));
enableHiddenPlugin(app, enabledPlugins, new WikipediaPlugin(app)); enableHiddenPlugin(app, enabledPlugins, new WikipediaPlugin(app));
allPlugins.add(new MapillaryPlugin(app));
allPlugins.add(new OsmandRasterMapsPlugin(app)); allPlugins.add(new OsmandRasterMapsPlugin(app));
allPlugins.add(new OsmandMonitoringPlugin(app)); allPlugins.add(new OsmandMonitoringPlugin(app));
checkMarketPlugin(app, enabledPlugins, new SRTMPlugin(app)); checkMarketPlugin(app, enabledPlugins, new SRTMPlugin(app));
@ -875,9 +878,10 @@ public abstract class OsmandPlugin {
return collection; return collection;
} }
public static void populateImageCards(@NonNull List<ImageCard> imageCards, @Nullable GetImageCardsListener listener) { public static void populateImageCards(@NonNull List<ImageCard> imageCards, @NonNull Map<String, String> params,
@Nullable Map<String, String> additionalParams, @Nullable GetImageCardsListener listener) {
for (OsmandPlugin p : getEnabledPlugins()) { for (OsmandPlugin p : getEnabledPlugins()) {
imageCards.addAll(p.getImageCards(listener)); imageCards.addAll(p.getImageCards(params, additionalParams, listener));
} }
} }

View file

@ -19,7 +19,6 @@ import net.osmand.AndroidNetworkUtils;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
@ -29,7 +28,6 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapillary.MapillaryContributeCard; import net.osmand.plus.mapillary.MapillaryContributeCard;
import net.osmand.plus.mapillary.MapillaryImageCard; import net.osmand.plus.mapillary.MapillaryImageCard;
import net.osmand.plus.wikimedia.WikiImageHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -427,7 +425,7 @@ public abstract class ImageCard extends AbstractCard {
} }
public GetImageCardsTask(@NonNull MapActivity mapActivity, LatLon latLon, public GetImageCardsTask(@NonNull MapActivity mapActivity, LatLon latLon,
@Nullable Map<String, String> params, GetImageCardsListener listener) { @Nullable Map<String, String> params, GetImageCardsListener listener) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
this.app = mapActivity.getMyApplication(); this.app = mapActivity.getMyApplication();
this.latLon = latLon; this.latLon = latLon;
@ -436,10 +434,9 @@ public abstract class ImageCard extends AbstractCard {
} }
@Override @Override
protected List<ImageCard> doInBackground(Void... params) { protected List<ImageCard> doInBackground(Void... voids) {
TrafficStats.setThreadStatsTag(GET_IMAGE_CARD_THREAD_ID); TrafficStats.setThreadStatsTag(GET_IMAGE_CARD_THREAD_ID);
List<ImageCard> result = new ArrayList<>(); List<ImageCard> result = new ArrayList<>();
OsmandPlugin.populateImageCards(result, listener);
try { try {
final Map<String, String> pms = new LinkedHashMap<>(); final Map<String, String> pms = new LinkedHashMap<>();
pms.put("lat", "" + (float) latLon.getLatitude()); pms.put("lat", "" + (float) latLon.getLatitude());
@ -456,19 +453,8 @@ public abstract class ImageCard extends AbstractCard {
if (!Algorithms.isEmpty(preferredLang)) { if (!Algorithms.isEmpty(preferredLang)) {
pms.put("lang", preferredLang); pms.put("lang", preferredLang);
} }
if (this.params != null) { OsmandPlugin.populateImageCards(result, pms, params, listener);
String wikidataId = this.params.get(Amenity.WIKIDATA);
if (wikidataId != null) {
this.params.remove(Amenity.WIKIDATA);
WikiImageHelper.addWikidataImageCards(mapActivity, wikidataId, result);
}
String wikimediaContent = this.params.get(Amenity.WIKIMEDIA_COMMONS);
if (wikimediaContent != null) {
this.params.remove(Amenity.WIKIMEDIA_COMMONS);
WikiImageHelper.addWikimediaImageCards(mapActivity, wikimediaContent, result);
}
pms.putAll(this.params);
}
String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms, String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms,
"Requesting location images...", false, false); "Requesting location images...", false, false);

View file

@ -2,6 +2,9 @@ package net.osmand.plus.openplacereviews;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.AndroidNetworkUtils; import net.osmand.AndroidNetworkUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
@ -84,7 +87,9 @@ public class OpenPlaceReviewsPlugin extends OsmandPlugin {
} }
@Override @Override
protected List<ImageCard> getImageCards(Map<String, String> params, Map<String, String> additionalParams, GetImageCardsListener listener) { protected List<ImageCard> getImageCards(@NonNull Map<String, String> params,
@Nullable Map<String, String> additionalParams,
@Nullable GetImageCardsListener listener) {
List<ImageCard> imageCards = new ArrayList<>(); List<ImageCard> imageCards = new ArrayList<>();
if (mapActivity != null) { if (mapActivity != null) {
Object object = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObject(); Object object = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObject();

View file

@ -5,6 +5,7 @@ import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
@ -24,6 +25,8 @@ import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener;
import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.search.QuickSearchDialogFragment;
@ -32,8 +35,9 @@ import net.osmand.plus.search.listitems.QuickSearchBannerListItem;
import net.osmand.plus.search.listitems.QuickSearchFreeBannerListItem; import net.osmand.plus.search.listitems.QuickSearchFreeBannerListItem;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.views.layers.DownloadedRegionsLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.layers.DownloadedRegionsLayer;
import net.osmand.plus.wikimedia.WikiImageHelper;
import net.osmand.search.core.ObjectType; import net.osmand.search.core.ObjectType;
import net.osmand.search.core.SearchPhrase; import net.osmand.search.core.SearchPhrase;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -42,6 +46,7 @@ import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.WIKIPEDIA_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.WIKIPEDIA_ID;
@ -91,6 +96,11 @@ public class WikipediaPlugin extends OsmandPlugin {
this.mapActivity = activity; this.mapActivity = activity;
} }
@Override
public void mapActivityResumeOnTop(MapActivity activity) {
this.mapActivity = activity;
}
@Override @Override
public void mapActivityPause(MapActivity activity) { public void mapActivityPause(MapActivity activity) {
this.mapActivity = null; this.mapActivity = null;
@ -435,4 +445,25 @@ public class WikipediaPlugin extends OsmandPlugin {
} }
return false; return false;
} }
@Override
protected List<ImageCard> getImageCards(@NonNull Map<String, String> params, @Nullable Map<String, String> additionalParams, @Nullable GetImageCardsListener listener) {
List<ImageCard> imageCards = new ArrayList<>();
if (mapActivity != null) {
if (additionalParams != null) {
String wikidataId = additionalParams.get(Amenity.WIKIDATA);
if (wikidataId != null) {
additionalParams.remove(Amenity.WIKIDATA);
WikiImageHelper.addWikidataImageCards(mapActivity, wikidataId, imageCards);
}
String wikimediaContent = additionalParams.get(Amenity.WIKIMEDIA_COMMONS);
if (wikimediaContent != null) {
additionalParams.remove(Amenity.WIKIMEDIA_COMMONS);
WikiImageHelper.addWikimediaImageCards(mapActivity, wikimediaContent, imageCards);
}
params.putAll(additionalParams);
}
}
return imageCards;
}
} }