Add drawer_url preference

This commit is contained in:
Vitaliy 2020-04-21 19:01:03 +03:00
parent 5cdae7e469
commit 84f291fba5
4 changed files with 16 additions and 52 deletions

View file

@ -67,8 +67,6 @@ public class OsmAndAppCustomization {
private Map<String, Bitmap> navDrawerLogos = new HashMap<>();
private ArrayList<String> navDrawerParams;
private String navDrawerFooterIntent;
private String navDrawerFooterAppName;
private String navDrawerFooterPackageName;
@ -254,8 +252,8 @@ public class OsmAndAppCustomization {
}
@Nullable
public ArrayList<String> getNavDrawerLogoParams() {
return navDrawerParams;
public String getNavDrawerLogoUrl() {
return app.getSettings().NAV_DRAWER_URL.get();
}
public boolean setNavDrawerLogo(String uri, @Nullable String packageName, @Nullable String intent) {
@ -300,10 +298,8 @@ public class OsmAndAppCustomization {
} catch (IOException e) {
LOG.error("Failed to write file", e);
}
if (packageName != null && intent != null) {
navDrawerParams = new ArrayList<>();
navDrawerParams.add(packageName);
navDrawerParams.add(intent);
if (!Algorithms.isEmpty(intent)) {
app.getSettings().NAV_DRAWER_LOGO.set(intent);
}
}
return true;

View file

@ -1453,7 +1453,8 @@ public class OsmandSettings {
public final CommonPreference<String> API_NAV_DRAWER_ITEMS_JSON = new StringPreference("api_nav_drawer_items_json", "{}").makeGlobal();
public final CommonPreference<String> API_CONNECTED_APPS_JSON = new StringPreference("api_connected_apps_json", "[]").makeGlobal();
public final CommonPreference<String> NAV_DRAWER_LOGO = new StringPreference("nav_drawer_logo", "").makeProfile();
public final CommonPreference<String> NAV_DRAWER_LOGO = new StringPreference("drawer_logo", "").makeProfile();
public final CommonPreference<String> NAV_DRAWER_URL = new StringPreference("drawer_url", "").makeProfile();
public final CommonPreference<Integer> NUMBER_OF_STARTS_FIRST_XMAS_SHOWN = new IntPreference("number_of_starts_first_xmas_shown", 0).makeGlobal();

View file

@ -981,8 +981,9 @@ public class SettingsHelper {
@Override
void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException {
JSONObject prefsJson = json.optJSONObject("prefs");
try {
JSONObject drawerLogoJson = json.has("drawerLogo") ? json.getJSONObject("drawerLogo") : null;
JSONObject drawerLogoJson = prefsJson.optJSONObject("drawer_logo");
if (drawerLogoJson != null) {
for (Iterator<String> it = drawerLogoJson.keys(); it.hasNext(); ) {
String localeKey = it.next();

View file

@ -6,6 +6,7 @@ import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
@ -55,6 +56,7 @@ import net.osmand.plus.dialogs.FavoriteDialogs;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.liveupdates.OsmLiveActivity;
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment;
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener;
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.MarkersPlanRouteContext;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
@ -64,11 +66,11 @@ import net.osmand.plus.routepreparationmenu.WaypointsFragment;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener;
import net.osmand.plus.views.BaseMapLayer;
import net.osmand.plus.views.MapControlsLayer;
import net.osmand.plus.views.MapTileLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import net.osmand.plus.wikivoyage.WikivoyageWelcomeDialogFragment;
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity;
@ -1144,28 +1146,8 @@ public class MapActivityActions implements DialogProvider {
menu.show();
}
public void restoreOrReturnDialog(final String packageName) {
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
builder.setTitle("Restore OsmAnd");
builder.setMessage("Do you want to Restore OsmAnd or get back to the Client App?");
builder.setPositiveButton("Restore", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
restoreOsmand();
}
});
builder.setNeutralButton("Return", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
executeHeadersIntent(packageName);
}
});
builder.setNegativeButton("Cancel", null);
builder.show();
}
protected void updateDrawerMenu() {
boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
final boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
final ListView menuItemsListView = (ListView) mapActivity.findViewById(R.id.menuItems);
if (nightMode) {
menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.list_background_color_dark));
@ -1174,7 +1156,6 @@ public class MapActivityActions implements DialogProvider {
}
menuItemsListView.removeHeaderView(drawerLogoHeader);
Bitmap navDrawerLogo = getMyApplication().getAppCustomization().getNavDrawerLogo();
final ArrayList<String> navDrawerLogoParams = getMyApplication().getAppCustomization().getNavDrawerLogoParams();
if (navDrawerLogo != null) {
drawerLogoHeader.setImageBitmap(navDrawerLogo);
@ -1193,8 +1174,9 @@ public class MapActivityActions implements DialogProvider {
boolean hasHeader = menuItemsListView.getHeaderViewsCount() > 0;
boolean hasFooter = menuItemsListView.getFooterViewsCount() > 0;
if (hasHeader && position == 0 || (hasFooter && position == menuItemsListView.getCount() - 1)) {
if (navDrawerLogoParams != null) {
executeHeadersIntent(navDrawerLogoParams.get(0));
String drawerLogoParams = getMyApplication().getAppCustomization().getNavDrawerLogoUrl();
if (!Algorithms.isEmpty(drawerLogoParams)) {
WikipediaDialogFragment.showFullArticle(mapActivity, Uri.parse(drawerLogoParams), nightMode);
}
} else {
position -= menuItemsListView.getHeaderViewsCount();
@ -1209,20 +1191,4 @@ public class MapActivityActions implements DialogProvider {
});
}
private void executeHeadersIntent(String packageName) {
Intent launchIntent = mapActivity.getPackageManager().getLaunchIntentForPackage(packageName);
if(launchIntent!=null) mapActivity.startActivity(launchIntent);
mapActivity.closeDrawer();
}
private void showReturnConfirmationDialog(String packageName) {
restoreOrReturnDialog(packageName);
mapActivity.closeDrawer();
}
private void restoreOsmand(){
getMyApplication().getAppCustomization().restoreOsmand();
mapActivity.closeDrawer();
}
}
}