Add drawer_url preference
This commit is contained in:
parent
5cdae7e469
commit
84f291fba5
4 changed files with 16 additions and 52 deletions
|
@ -67,8 +67,6 @@ public class OsmAndAppCustomization {
|
||||||
|
|
||||||
private Map<String, Bitmap> navDrawerLogos = new HashMap<>();
|
private Map<String, Bitmap> navDrawerLogos = new HashMap<>();
|
||||||
|
|
||||||
private ArrayList<String> navDrawerParams;
|
|
||||||
|
|
||||||
private String navDrawerFooterIntent;
|
private String navDrawerFooterIntent;
|
||||||
private String navDrawerFooterAppName;
|
private String navDrawerFooterAppName;
|
||||||
private String navDrawerFooterPackageName;
|
private String navDrawerFooterPackageName;
|
||||||
|
@ -254,8 +252,8 @@ public class OsmAndAppCustomization {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ArrayList<String> getNavDrawerLogoParams() {
|
public String getNavDrawerLogoUrl() {
|
||||||
return navDrawerParams;
|
return app.getSettings().NAV_DRAWER_URL.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setNavDrawerLogo(String uri, @Nullable String packageName, @Nullable String intent) {
|
public boolean setNavDrawerLogo(String uri, @Nullable String packageName, @Nullable String intent) {
|
||||||
|
@ -300,10 +298,8 @@ public class OsmAndAppCustomization {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.error("Failed to write file", e);
|
LOG.error("Failed to write file", e);
|
||||||
}
|
}
|
||||||
if (packageName != null && intent != null) {
|
if (!Algorithms.isEmpty(intent)) {
|
||||||
navDrawerParams = new ArrayList<>();
|
app.getSettings().NAV_DRAWER_LOGO.set(intent);
|
||||||
navDrawerParams.add(packageName);
|
|
||||||
navDrawerParams.add(intent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -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_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> 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();
|
public final CommonPreference<Integer> NUMBER_OF_STARTS_FIRST_XMAS_SHOWN = new IntPreference("number_of_starts_first_xmas_shown", 0).makeGlobal();
|
||||||
|
|
||||||
|
|
|
@ -981,8 +981,9 @@ public class SettingsHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException {
|
void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException {
|
||||||
|
JSONObject prefsJson = json.optJSONObject("prefs");
|
||||||
try {
|
try {
|
||||||
JSONObject drawerLogoJson = json.has("drawerLogo") ? json.getJSONObject("drawerLogo") : null;
|
JSONObject drawerLogoJson = prefsJson.optJSONObject("drawer_logo");
|
||||||
if (drawerLogoJson != null) {
|
if (drawerLogoJson != null) {
|
||||||
for (Iterator<String> it = drawerLogoJson.keys(); it.hasNext(); ) {
|
for (Iterator<String> it = drawerLogoJson.keys(); it.hasNext(); ) {
|
||||||
String localeKey = it.next();
|
String localeKey = it.next();
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.app.Dialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -55,6 +56,7 @@ import net.osmand.plus.dialogs.FavoriteDialogs;
|
||||||
import net.osmand.plus.download.IndexItem;
|
import net.osmand.plus.download.IndexItem;
|
||||||
import net.osmand.plus.liveupdates.OsmLiveActivity;
|
import net.osmand.plus.liveupdates.OsmLiveActivity;
|
||||||
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment;
|
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment;
|
||||||
|
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener;
|
||||||
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
|
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
|
||||||
import net.osmand.plus.mapmarkers.MarkersPlanRouteContext;
|
import net.osmand.plus.mapmarkers.MarkersPlanRouteContext;
|
||||||
import net.osmand.plus.measurementtool.MeasurementToolFragment;
|
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.RouteProvider.GPXRouteParamsBuilder;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
import net.osmand.plus.settings.BaseSettingsFragment;
|
import net.osmand.plus.settings.BaseSettingsFragment;
|
||||||
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener;
|
|
||||||
import net.osmand.plus.views.BaseMapLayer;
|
import net.osmand.plus.views.BaseMapLayer;
|
||||||
import net.osmand.plus.views.MapControlsLayer;
|
import net.osmand.plus.views.MapControlsLayer;
|
||||||
import net.osmand.plus.views.MapTileLayer;
|
import net.osmand.plus.views.MapTileLayer;
|
||||||
import net.osmand.plus.views.OsmandMapTileView;
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
|
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
|
||||||
import net.osmand.plus.wikivoyage.WikivoyageWelcomeDialogFragment;
|
import net.osmand.plus.wikivoyage.WikivoyageWelcomeDialogFragment;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
|
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
|
||||||
import net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity;
|
import net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity;
|
||||||
|
@ -1144,28 +1146,8 @@ public class MapActivityActions implements DialogProvider {
|
||||||
menu.show();
|
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() {
|
protected void updateDrawerMenu() {
|
||||||
boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
final boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||||
final ListView menuItemsListView = (ListView) mapActivity.findViewById(R.id.menuItems);
|
final ListView menuItemsListView = (ListView) mapActivity.findViewById(R.id.menuItems);
|
||||||
if (nightMode) {
|
if (nightMode) {
|
||||||
menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.list_background_color_dark));
|
menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.list_background_color_dark));
|
||||||
|
@ -1174,7 +1156,6 @@ public class MapActivityActions implements DialogProvider {
|
||||||
}
|
}
|
||||||
menuItemsListView.removeHeaderView(drawerLogoHeader);
|
menuItemsListView.removeHeaderView(drawerLogoHeader);
|
||||||
Bitmap navDrawerLogo = getMyApplication().getAppCustomization().getNavDrawerLogo();
|
Bitmap navDrawerLogo = getMyApplication().getAppCustomization().getNavDrawerLogo();
|
||||||
final ArrayList<String> navDrawerLogoParams = getMyApplication().getAppCustomization().getNavDrawerLogoParams();
|
|
||||||
|
|
||||||
if (navDrawerLogo != null) {
|
if (navDrawerLogo != null) {
|
||||||
drawerLogoHeader.setImageBitmap(navDrawerLogo);
|
drawerLogoHeader.setImageBitmap(navDrawerLogo);
|
||||||
|
@ -1193,8 +1174,9 @@ public class MapActivityActions implements DialogProvider {
|
||||||
boolean hasHeader = menuItemsListView.getHeaderViewsCount() > 0;
|
boolean hasHeader = menuItemsListView.getHeaderViewsCount() > 0;
|
||||||
boolean hasFooter = menuItemsListView.getFooterViewsCount() > 0;
|
boolean hasFooter = menuItemsListView.getFooterViewsCount() > 0;
|
||||||
if (hasHeader && position == 0 || (hasFooter && position == menuItemsListView.getCount() - 1)) {
|
if (hasHeader && position == 0 || (hasFooter && position == menuItemsListView.getCount() - 1)) {
|
||||||
if (navDrawerLogoParams != null) {
|
String drawerLogoParams = getMyApplication().getAppCustomization().getNavDrawerLogoUrl();
|
||||||
executeHeadersIntent(navDrawerLogoParams.get(0));
|
if (!Algorithms.isEmpty(drawerLogoParams)) {
|
||||||
|
WikipediaDialogFragment.showFullArticle(mapActivity, Uri.parse(drawerLogoParams), nightMode);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
position -= menuItemsListView.getHeaderViewsCount();
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue