add the ability to save the global settings of Wikipedia Languages
This commit is contained in:
parent
7508dea7ca
commit
b5f01a1c7f
2 changed files with 76 additions and 7 deletions
|
@ -1,8 +1,12 @@
|
||||||
package net.osmand.plus.wikipedia;
|
package net.osmand.plus.wikipedia;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.SpannableString;
|
||||||
|
import android.text.style.StyleSpan;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
|
|
||||||
|
@ -12,6 +16,8 @@ import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.os.ConfigurationCompat;
|
import androidx.core.os.ConfigurationCompat;
|
||||||
import androidx.core.os.LocaleListCompat;
|
import androidx.core.os.LocaleListCompat;
|
||||||
|
|
||||||
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
|
@ -124,6 +130,12 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public MapActivity getMapActivity() {
|
||||||
|
Activity activity = getActivity();
|
||||||
|
return (MapActivity) activity;
|
||||||
|
}
|
||||||
|
|
||||||
private void initLanguagesData() {
|
private void initLanguagesData() {
|
||||||
languages = new ArrayList<>();
|
languages = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -188,10 +200,42 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
|
||||||
localesForSaving.add(language.getLocale());
|
localesForSaving.add(language.getLocale());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
applyPreferenceWithSnackBar(localesForSaving, isGlobalWikiPoiEnabled);
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void applyPreference(boolean applyToAllProfiles, List<String> localesForSaving, boolean global) {
|
||||||
|
if (applyToAllProfiles) {
|
||||||
|
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
|
||||||
|
wikiPlugin.setLanguagesToShow(mode, localesForSaving);
|
||||||
|
wikiPlugin.setShowAllLanguages(mode, global);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
wikiPlugin.setLanguagesToShow(localesForSaving);
|
wikiPlugin.setLanguagesToShow(localesForSaving);
|
||||||
wikiPlugin.setShowAllLanguages(isGlobalWikiPoiEnabled);
|
wikiPlugin.setShowAllLanguages(isGlobalWikiPoiEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
wikiPlugin.updateWikipediaState();
|
wikiPlugin.updateWikipediaState();
|
||||||
dismiss();
|
}
|
||||||
|
|
||||||
|
protected void applyPreferenceWithSnackBar(final List<String> localesForSaving, final boolean global) {
|
||||||
|
applyPreference(false, localesForSaving, global);
|
||||||
|
MapActivity mapActivity = getMapActivity();
|
||||||
|
if (mapActivity != null) {
|
||||||
|
String modeName = appMode.toHumanString();
|
||||||
|
String text = app.getString(R.string.changes_applied_to_profile, modeName);
|
||||||
|
SpannableString message = UiUtilities.createSpannableString(text, new StyleSpan(Typeface.BOLD), modeName);
|
||||||
|
Snackbar snackbar = Snackbar.make(mapActivity.getLayout(), message, Snackbar.LENGTH_LONG)
|
||||||
|
.setAction(R.string.apply_to_all_profiles, new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
applyPreference(true, localesForSaving, global);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
UiUtilities.setupSnackbarVerticalLayout(snackbar);
|
||||||
|
UiUtilities.setupSnackbar(snackbar, nightMode);
|
||||||
|
snackbar.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private View getCustomButtonView() {
|
private View getCustomButtonView() {
|
||||||
|
|
|
@ -30,6 +30,7 @@ import net.osmand.plus.search.QuickSearchDialogFragment;
|
||||||
import net.osmand.plus.search.QuickSearchListAdapter;
|
import net.osmand.plus.search.QuickSearchListAdapter;
|
||||||
import net.osmand.plus.search.listitems.QuickSearchBannerListItem;
|
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.OsmandSettings;
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
import net.osmand.plus.views.layers.DownloadedRegionsLayer;
|
import net.osmand.plus.views.layers.DownloadedRegionsLayer;
|
||||||
import net.osmand.plus.views.OsmandMapTileView;
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
|
@ -189,26 +190,50 @@ public class WikipediaPlugin extends OsmandPlugin {
|
||||||
return !isShowAllLanguages() && getLanguagesToShow() != null;
|
return !isShowAllLanguages() && getLanguagesToShow() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasCustomSettings(ApplicationMode profile) {
|
||||||
|
return !isShowAllLanguages(profile) && getLanguagesToShow(profile) != null;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasLanguagesFilter() {
|
public boolean hasLanguagesFilter() {
|
||||||
return settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.get() != null;
|
return settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.get() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasLanguagesFilter(ApplicationMode profile) {
|
||||||
|
return settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.getModeValue(profile) != null;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isShowAllLanguages() {
|
public boolean isShowAllLanguages() {
|
||||||
return settings.GLOBAL_WIKIPEDIA_POI_ENABLED.get();
|
return settings.GLOBAL_WIKIPEDIA_POI_ENABLED.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isShowAllLanguages(ApplicationMode mode) {
|
||||||
|
return settings.GLOBAL_WIKIPEDIA_POI_ENABLED.getModeValue(mode);
|
||||||
|
}
|
||||||
|
|
||||||
public void setShowAllLanguages(boolean showAllLanguages) {
|
public void setShowAllLanguages(boolean showAllLanguages) {
|
||||||
settings.GLOBAL_WIKIPEDIA_POI_ENABLED.set(showAllLanguages);
|
settings.GLOBAL_WIKIPEDIA_POI_ENABLED.set(showAllLanguages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setShowAllLanguages(ApplicationMode mode, boolean showAllLanguages) {
|
||||||
|
settings.GLOBAL_WIKIPEDIA_POI_ENABLED.setModeValue(mode, showAllLanguages);
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getLanguagesToShow() {
|
public List<String> getLanguagesToShow() {
|
||||||
return settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.getStringsList();
|
return settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.getStringsList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getLanguagesToShow(ApplicationMode mode) {
|
||||||
|
return settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.getStringsListForProfile(mode);
|
||||||
|
}
|
||||||
|
|
||||||
public void setLanguagesToShow(List<String> languagesToShow) {
|
public void setLanguagesToShow(List<String> languagesToShow) {
|
||||||
settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.setStringsList(languagesToShow);
|
settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.setStringsList(languagesToShow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLanguagesToShow(ApplicationMode mode, List<String> languagesToShow) {
|
||||||
|
settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.setStringsListForProfile(mode, languagesToShow);
|
||||||
|
}
|
||||||
|
|
||||||
public void toggleWikipediaPoi(boolean enable, CallbackWithObject<Boolean> callback) {
|
public void toggleWikipediaPoi(boolean enable, CallbackWithObject<Boolean> callback) {
|
||||||
if (enable) {
|
if (enable) {
|
||||||
showWikiOnMap();
|
showWikiOnMap();
|
||||||
|
|
Loading…
Reference in a new issue