This commit is contained in:
Nazar-Kutz 2020-06-24 15:39:15 +03:00
parent 6aa58257fe
commit 2ffb95568d
6 changed files with 58 additions and 50 deletions

View file

@ -260,7 +260,6 @@ public abstract class OsmandPlugin {
allPlugins.clear();
allPlugins.add(new MapillaryPlugin(app));
allPlugins.add(new WikipediaPlugin(app));
if (!enabledPlugins.contains(MapillaryPlugin.ID)
&& !app.getSettings().getPlugins().contains("-" + MapillaryPlugin.ID)) {
@ -268,12 +267,7 @@ public abstract class OsmandPlugin {
app.getSettings().enablePlugin(MapillaryPlugin.ID, true);
}
if (!enabledPlugins.contains(WikipediaPlugin.ID)
&& !app.getSettings().getPlugins().contains("-" + WikipediaPlugin.ID)) {
enabledPlugins.add(WikipediaPlugin.ID);
app.getSettings().enablePlugin(WikipediaPlugin.ID, true);
}
checkPaidPlugin(app, enabledPlugins, new WikipediaPlugin(app));
allPlugins.add(new OsmandRasterMapsPlugin(app));
allPlugins.add(new OsmandMonitoringPlugin(app));
checkMarketPlugin(app, enabledPlugins, new SRTMPlugin(app));
@ -377,6 +371,11 @@ public abstract class OsmandPlugin {
}
}
private static void checkPaidPlugin(@NonNull OsmandApplication app, @NonNull Set<String> enabledPlugins, @NonNull OsmandPlugin plugin) {
allPlugins.add(plugin);
plugin.setActive(Version.isPaidVersion(app));
}
private static void checkMarketPlugin(@NonNull OsmandApplication app, @NonNull Set<String> enabledPlugins, @NonNull OsmandPlugin plugin) {
if (updateMarketPlugin(app, enabledPlugins, plugin)) {
allPlugins.add(plugin);

View file

@ -196,8 +196,14 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
if (intent != null && intent.getExtras() != null) {
String region = getIntent().getStringExtra(REGION_TO_SEARCH);
if (region != null && !region.isEmpty()) {
showDialog(this, SearchDialogFragment.createInstance(region, true, true,
getIntent().getBooleanExtra(SHOW_WIKI_KEY, false)));
if (getIntent().getBooleanExtra(SHOW_WIKI_KEY, false)) {
showDialog(this, SearchDialogFragment.createInstance(
region, true, DownloadActivityType.NORMAL_FILE,
DownloadActivityType.WIKIPEDIA_FILE));
} else {
showDialog(this, SearchDialogFragment.createInstance(
region, true, DownloadActivityType.NORMAL_FILE));
}
}
filter = intent.getExtras().getString(FILTER_KEY);
filterCat = intent.getExtras().getString(FILTER_CAT);

View file

@ -405,7 +405,8 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
if (filter != null && filterCat != null
&& filterCat.equals(DownloadActivityType.WIKIPEDIA_FILE.getTag())) {
getDownloadActivity().showDialog(getActivity(),
SearchDialogFragment.createInstance(filter, false, false, true));
SearchDialogFragment.createInstance(filter, false,
DownloadActivityType.WIKIPEDIA_FILE));
} else if (filter != null) {
getDownloadActivity().showDialog(getActivity(),
SearchDialogFragment.createInstance(filter));

View file

@ -71,11 +71,10 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
public static final String TAG = "SearchDialogFragment";
private static final String SEARCH_TEXT_DLG_KEY = "search_text_dlg_key";
public static final String SHOW_GROUP_KEY = "show_group_key";
public static final String SHOW_NORMAL_KEY = "show_normal_key";
public static final String DOWNLOAD_TYPES_TO_SHOW_KEY = "download_types_to_show";
public static final String SHOW_WIKI_KEY = "show_wiki_key";
private boolean showGroup;
private boolean showNormal;
private boolean showWiki;
private ArrayList<String> downloadTypesToShow = new ArrayList<>();
private ListView listView;
private SearchListAdapter listAdapter;
private BannerAndDownloadFreeVersion banner;
@ -101,23 +100,21 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
if (savedInstanceState != null) {
searchText = savedInstanceState.getString(SEARCH_TEXT_DLG_KEY);
showGroup = savedInstanceState.getBoolean(SHOW_GROUP_KEY);
showNormal = savedInstanceState.getBoolean(SHOW_NORMAL_KEY);
showWiki = savedInstanceState.getBoolean(SHOW_WIKI_KEY);
downloadTypesToShow = savedInstanceState.getStringArrayList(DOWNLOAD_TYPES_TO_SHOW_KEY);
}
if (searchText == null) {
Bundle arguments = getArguments();
if (arguments != null) {
searchText = arguments.getString(SEARCH_TEXT_DLG_KEY);
showGroup = arguments.getBoolean(SHOW_GROUP_KEY);
showNormal = arguments.getBoolean(SHOW_NORMAL_KEY);
showWiki = arguments.getBoolean(SHOW_WIKI_KEY);
downloadTypesToShow = arguments.getStringArrayList(DOWNLOAD_TYPES_TO_SHOW_KEY);
}
}
if (searchText == null) {
searchText = "";
showGroup = true;
showNormal = true;
showWiki = false;
downloadTypesToShow = new ArrayList<>();
downloadTypesToShow.add(DownloadActivityType.NORMAL_FILE.getTag());
}
boolean isLightContent = getMyApplication().getSettings().isLightContent();
@ -238,8 +235,7 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
public void onSaveInstanceState(Bundle outState) {
outState.putString(SEARCH_TEXT_DLG_KEY, searchText);
outState.putBoolean(SHOW_GROUP_KEY, showGroup);
outState.putBoolean(SHOW_NORMAL_KEY, showNormal);
outState.putBoolean(SHOW_WIKI_KEY, showWiki);
outState.putStringArrayList(DOWNLOAD_TYPES_TO_SHOW_KEY, downloadTypesToShow);
super.onSaveInstanceState(outState);
}
@ -267,19 +263,22 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
}
public static SearchDialogFragment createInstance(String searchText, boolean showGroup,
boolean showNormal, boolean showWiki) {
DownloadActivityType ... fileTypes) {
ArrayList<String> typesList = new ArrayList<>();
for (DownloadActivityType type : fileTypes) {
typesList.add(type.getTag());
}
Bundle bundle = new Bundle();
bundle.putString(SEARCH_TEXT_DLG_KEY, searchText);
bundle.putBoolean(SHOW_GROUP_KEY, showGroup);
bundle.putBoolean(SHOW_NORMAL_KEY, showNormal);
bundle.putBoolean(SHOW_WIKI_KEY, showWiki);
bundle.putStringArrayList(DOWNLOAD_TYPES_TO_SHOW_KEY, typesList);
SearchDialogFragment fragment = new SearchDialogFragment();
fragment.setArguments(bundle);
return fragment;
}
public static SearchDialogFragment createInstance(String searchText) {
return createInstance(searchText, true, true, false);
return createInstance(searchText, true, DownloadActivityType.NORMAL_FILE);
}
@Override
@ -507,9 +506,11 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
if (g.getType() == DownloadResourceGroupType.REGION_MAPS) {
if (g.getIndividualResources() != null) {
for (IndexItem item : g.getIndividualResources()) {
if ((item.getType() == DownloadActivityType.NORMAL_FILE && showNormal)
|| (item.getType() == DownloadActivityType.WIKIPEDIA_FILE && showWiki)) {
filter.add(item);
for (String fileTypeTag : downloadTypesToShow) {
DownloadActivityType type = DownloadActivityType.getIndexType(fileTypeTag);
if (type != null && type.equals(item.getType())) {
filter.add(item);
}
}
}
}

View file

@ -852,7 +852,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
cancelPrev = false;
hidden = false;
if (interruptedSearch) {
addNotFoundButton(true);
addNotFoundButton(true, SearchMoreType.STANDARD);
interruptedSearch = false;
}
}
@ -1177,7 +1177,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
if (getResultCollection() != null) {
updateSearchResult(getResultCollection(), false);
addNotFoundButton(searchUICore.isSearchMoreAvailable(searchUICore.getPhrase()));
onNothingFound(searchUICore.getPhrase());
}
break;
}
@ -1706,16 +1706,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
if (resultListener == null || resultListener.searchFinished(object.requiredSearchPhrase)) {
hideProgressBar();
SearchPhrase phrase = object.requiredSearchPhrase;
WikipediaPlugin wikiPlugin = OsmandPlugin.getPlugin(WikipediaPlugin.class);
if (wikiPlugin != null && wikiPlugin.isSearchByWiki(phrase)) {
if (!Version.isPaidVersion(app)) {
mainSearchFragment.addListItem(new QuickSearchFreeBannerListItem(app));
} else {
addNotFoundButton(searchUICore.isSearchMoreAvailable(phrase), SearchMoreType.WIKIPEDIA);
}
} else {
addNotFoundButton(searchUICore.isSearchMoreAvailable(phrase));
}
onNothingFound(phrase);
}
}
});
@ -1983,8 +1974,17 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
}
private void addNotFoundButton(boolean searchMoreAvailable) {
addNotFoundButton(searchMoreAvailable, SearchMoreType.STANDARD);
private void onNothingFound(SearchPhrase phrase) {
WikipediaPlugin wikiPlugin = OsmandPlugin.getEnabledPlugin(WikipediaPlugin.class);
if (WikipediaPlugin.isSearchByWiki(phrase)) {
if (wikiPlugin == null) {
mainSearchFragment.addListItem(new QuickSearchFreeBannerListItem(app));
} else {
addNotFoundButton(searchUICore.isSearchMoreAvailable(phrase), SearchMoreType.WIKIPEDIA);
}
} else {
addNotFoundButton(searchUICore.isSearchMoreAvailable(phrase), SearchMoreType.STANDARD);
}
}
private void addNotFoundButton(boolean searchMoreAvailable, final SearchMoreType type) {
@ -2023,13 +2023,12 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
moreListItem.setInterruptedSearch(interruptedSearch);
moreListItem.setEmptySearch(isResultEmpty());
moreListItem.setSearchMoreAvailable(searchMoreAvailable);
boolean secondaryButtonVisible = false;
if (type == SearchMoreType.STANDARD) {
secondaryButtonVisible = isOnlineSearch();
moreListItem.setSecondaryButtonVisible(isOnlineSearch());
} else if (type == SearchMoreType.WIKIPEDIA) {
secondaryButtonVisible = wikiPlugin != null && wikiPlugin.hasMapsToDownload();
moreListItem.setSecondaryButtonVisible(
wikiPlugin != null && wikiPlugin.hasMapsToDownload());
}
moreListItem.setSecondaryButtonVisible(secondaryButtonVisible);
mainSearchFragment.addListItem(moreListItem);
updateSendEmptySearchBottomBar(isResultEmpty() && !interruptedSearch);
}

View file

@ -267,7 +267,7 @@ public class WikipediaPlugin extends OsmandPlugin {
intent.putExtra(DownloadActivity.FILTER_KEY, filter);
intent.putExtra(DownloadActivity.FILTER_CAT, DownloadActivityType.WIKIPEDIA_FILE.getTag());
intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB);
app.startActivity(intent);
mapActivity.startActivity(intent);
}
public boolean hasMapsToDownload() {
@ -275,14 +275,16 @@ public class WikipediaPlugin extends OsmandPlugin {
if (mapActivity == null) {
return false;
}
return DownloadResources.findIndexItemsAt(app, mapActivity.getMapLocation(),
DownloadActivityType.WIKIPEDIA_FILE, false, 1).size() > 0;
int mapsToDownloadCount = DownloadResources.findIndexItemsAt(app,
mapActivity.getMapLocation(), DownloadActivityType.WIKIPEDIA_FILE,
false, 1).size();
return mapsToDownloadCount > 0;
} catch (IOException e) {
return false;
}
}
public boolean isSearchByWiki(SearchPhrase phrase) {
public static boolean isSearchByWiki(SearchPhrase phrase) {
if (phrase.isLastWord(ObjectType.POI_TYPE)) {
Object obj = phrase.getLastSelectedWord().getResult().object;
if (obj instanceof PoiUIFilter) {