Restore OsmAnd on custom header click

This commit is contained in:
crimean 2018-11-10 15:51:21 +03:00
parent 284fd9a469
commit 1501e447d1
3 changed files with 39 additions and 7 deletions

View file

@ -108,6 +108,26 @@ public class OsmAndAppCustomization {
notifySettingsCustomized(); notifySettingsCustomized();
} }
private void restoreOsmandSetting() {
app.setOsmandSettings(osmandSettings);
notifySettingsCustomized();
}
public void restoreOsmand() {
navDrawerLogo = null;
featuresCustomized = false;
widgetsCustomized = false;
customOsmandSettings = null;
restoreOsmandSetting();
featuresEnabledIds.clear();
featuresDisabledIds.clear();
featuresEnabledPatterns.clear();
featuresDisabledPatterns.clear();
widgetsVisibilityMap.clear();
widgetsAvailabilityMap.clear();
}
// Activities // Activities
public Class<? extends Activity> getSettingsActivity() { public Class<? extends Activity> getSettingsActivity() {
return SettingsActivity.class; return SettingsActivity.class;

View file

@ -209,6 +209,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private boolean pendingPause = false; private boolean pendingPause = false;
private Timer splashScreenTimer; private Timer splashScreenTimer;
private boolean activityRestartNeeded = false; private boolean activityRestartNeeded = false;
private boolean stopped = false;
private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
@ -1221,6 +1222,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
stopped = false;
wakeLockHelper.onStart(this); wakeLockHelper.onStart(this);
getMyApplication().getNotificationHelper().showNotifications(); getMyApplication().getNotificationHelper().showNotifications();
} }
@ -1240,6 +1242,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
if(pendingPause) { if(pendingPause) {
onPauseActivity(); onPauseActivity();
} }
stopped = true;
super.onStop(); super.onStop();
} }
@ -1958,7 +1961,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
@Override @Override
public void onOsmAndSettingsCustomized() { public void onOsmAndSettingsCustomized() {
if (stopped) {
activityRestartNeeded = true; activityRestartNeeded = true;
} else {
recreate();
}
} }
public enum ShowQuickSearchMode { public enum ShowQuickSearchMode {

View file

@ -998,7 +998,7 @@ public class MapActivityActions implements DialogProvider {
menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.bg_color_light)); menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.bg_color_light));
} }
menuItemsListView.removeHeaderView(navDrawerLogoHeader); menuItemsListView.removeHeaderView(navDrawerLogoHeader);
Bitmap navDrawerLogo = getMyApplication().getAppCustomization().getNavDrawerLogo(); final Bitmap navDrawerLogo = getMyApplication().getAppCustomization().getNavDrawerLogo();
if (navDrawerLogo != null) { if (navDrawerLogo != null) {
navDrawerLogoHeader.setImageBitmap(navDrawerLogo); navDrawerLogoHeader.setImageBitmap(navDrawerLogo);
menuItemsListView.addHeaderView(navDrawerLogoHeader); menuItemsListView.addHeaderView(navDrawerLogoHeader);
@ -1013,6 +1013,10 @@ public class MapActivityActions implements DialogProvider {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mapActivity.dismissCardDialog(); mapActivity.dismissCardDialog();
if (position == 0 && navDrawerLogo != null) {
getMyApplication().getAppCustomization().restoreOsmand();
mapActivity.closeDrawer();
} else {
position -= menuItemsListView.getHeaderViewsCount(); position -= menuItemsListView.getHeaderViewsCount();
ContextMenuItem item = contextMenuAdapter.getItem(position); ContextMenuItem item = contextMenuAdapter.getItem(position);
ContextMenuAdapter.ItemClickListener click = item.getItemClickListener(); ContextMenuAdapter.ItemClickListener click = item.getItemClickListener();
@ -1021,6 +1025,7 @@ public class MapActivityActions implements DialogProvider {
mapActivity.closeDrawer(); mapActivity.closeDrawer();
} }
} }
}
}); });
} }