Merge pull request #9128 from osmandapp/WikipediaBottomSheet

Fix Wikipedia languages bottom sheet
This commit is contained in:
Vitaliy 2020-06-03 12:34:01 +03:00 committed by GitHub
commit c914cdb556
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 47 deletions

View file

@ -11,9 +11,9 @@ import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.os.ConfigurationCompat;
import androidx.core.os.LocaleListCompat;
import androidx.fragment.app.FragmentActivity;
import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
@ -48,7 +48,6 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
private List<BottomSheetItemWithCompoundButton> languageItems;
private ArrayList<WikiLanguageItem> languages;
private CallbackWithObject<Boolean> languageChangedCallback;
private boolean isGlobalWikiPoiEnabled = false;
@Override
@ -56,6 +55,7 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
super.onCreate(savedInstanceState);
app = requiredMyApplication();
settings = app.getSettings();
appMode = settings.getApplicationMode();
initLanguagesData();
}
@ -192,8 +192,9 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
}
settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.setStringsListForProfile(appMode, localesForSaving);
settings.GLOBAL_WIKIPEDIA_POI_ENABLED.setModeValue(appMode, isGlobalWikiPoiEnabled);
if (languageChangedCallback != null) {
languageChangedCallback.processResult(true);
MapActivity ma = getMapActivity();
if (ma != null) {
WikipediaPoiMenu.updateWikipediaState(ma);
}
dismiss();
}
@ -227,12 +228,13 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
}
}
public void setAppMode(ApplicationMode appMode) {
this.appMode = appMode;
}
public void setLanguageChangedCallback(CallbackWithObject<Boolean> languageChangedCallback) {
this.languageChangedCallback = languageChangedCallback;
@Nullable
private MapActivity getMapActivity() {
FragmentActivity activity = getActivity();
if (activity instanceof MapActivity) {
return (MapActivity) activity;
}
return null;
}
private class WikiLanguageItem implements Comparable<WikiLanguageItem> {
@ -276,13 +278,9 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
}
public static void showInstance(@NonNull MapActivity mapActivity,
@NonNull ApplicationMode appMode,
boolean usedOnMap,
CallbackWithObject<Boolean> callback) {
boolean usedOnMap) {
SelectWikiLanguagesBottomSheet fragment = new SelectWikiLanguagesBottomSheet();
fragment.setAppMode(appMode);
fragment.setUsedOnMap(usedOnMap);
fragment.setLanguageChangedCallback(callback);
fragment.show(mapActivity.getSupportFragmentManager(), SelectWikiLanguagesBottomSheet.TAG);
}
}

View file

@ -38,14 +38,12 @@ public class WikipediaPoiMenu {
private MapActivity mapActivity;
private OsmandApplication app;
private OsmandSettings settings;
private ApplicationMode appMode;
private boolean nightMode;
public WikipediaPoiMenu(MapActivity mapActivity) {
this.mapActivity = mapActivity;
this.app = mapActivity.getMyApplication();
this.settings = app.getSettings();
this.appMode = settings.getApplicationMode();
this.nightMode = app.getDaynightHelper().isNightModeForMapControls();
}
@ -59,14 +57,6 @@ public class WikipediaPoiMenu {
adapter.setProfileDependent(true);
adapter.setNightMode(nightMode);
final CallbackWithObject<Boolean> callback = new CallbackWithObject<Boolean>() {
@Override
public boolean processResult(Boolean result) {
mapActivity.getDashboard().refreshContent(true);
return true;
}
};
ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter,
@ -75,11 +65,11 @@ public class WikipediaPoiMenu {
app.runInUIThread(new Runnable() {
@Override
public void run() {
toggleWikipediaPoi(mapActivity, !enabled, callback);
toggleWikipediaPoi(mapActivity, !enabled, null);
}
});
} else if (itemId == languageActionStringId) {
showLanguagesDialog(mapActivity, appMode, true, callback);
SelectWikiLanguagesBottomSheet.showInstance(mapActivity, true);
}
return false;
}
@ -230,26 +220,15 @@ public class WikipediaPoiMenu {
return adapter;
}
private static void showLanguagesDialog(@NonNull final MapActivity mapActivity,
@NonNull final ApplicationMode appMode,
final boolean usedOnMap,
final CallbackWithObject<Boolean> callback) {
final OsmandApplication app = mapActivity.getMyApplication();
SelectWikiLanguagesBottomSheet.showInstance(mapActivity, appMode, usedOnMap,
new CallbackWithObject<Boolean>() {
@Override
public boolean processResult(Boolean result) {
if (result) {
Bundle wikiPoiSetting = getWikiPoiSettingsForProfile(app, appMode);
if (wikiPoiSetting != null) {
refreshWikipediaOnMap(mapActivity);
} else {
toggleWikipediaPoi(mapActivity, false, callback);
}
}
return true;
}
});
public static void updateWikipediaState(MapActivity ma) {
final OsmandApplication app = ma.getMyApplication();
ApplicationMode appMode = app.getSettings().getApplicationMode();
Bundle wikiPoiSetting = getWikiPoiSettingsForProfile(app, appMode);
if (wikiPoiSetting != null) {
refreshWikipediaOnMap(ma);
} else {
toggleWikipediaPoi(ma, false, null);
}
}
public static String getTranslation(OsmandApplication app, String locale) {
@ -305,6 +284,8 @@ public class WikipediaPoiMenu {
}
if (callback != null) {
callback.processResult(enable);
} else {
mapActivity.getDashboard().refreshContent(true);
}
mapActivity.refreshMap();
}