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();
}
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
public Class<? extends Activity> getSettingsActivity() {
return SettingsActivity.class;

View file

@ -209,6 +209,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private boolean pendingPause = false;
private Timer splashScreenTimer;
private boolean activityRestartNeeded = false;
private boolean stopped = false;
private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
@ -1221,6 +1222,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
@Override
protected void onStart() {
super.onStart();
stopped = false;
wakeLockHelper.onStart(this);
getMyApplication().getNotificationHelper().showNotifications();
}
@ -1240,6 +1242,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
if(pendingPause) {
onPauseActivity();
}
stopped = true;
super.onStop();
}
@ -1958,7 +1961,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
@Override
public void onOsmAndSettingsCustomized() {
activityRestartNeeded = true;
if (stopped) {
activityRestartNeeded = true;
} else {
recreate();
}
}
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.removeHeaderView(navDrawerLogoHeader);
Bitmap navDrawerLogo = getMyApplication().getAppCustomization().getNavDrawerLogo();
final Bitmap navDrawerLogo = getMyApplication().getAppCustomization().getNavDrawerLogo();
if (navDrawerLogo != null) {
navDrawerLogoHeader.setImageBitmap(navDrawerLogo);
menuItemsListView.addHeaderView(navDrawerLogoHeader);
@ -1013,12 +1013,17 @@ public class MapActivityActions implements DialogProvider {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mapActivity.dismissCardDialog();
position -= menuItemsListView.getHeaderViewsCount();
ContextMenuItem item = contextMenuAdapter.getItem(position);
ContextMenuAdapter.ItemClickListener click = item.getItemClickListener();
if (click != null && click.onContextMenuClick(simpleListAdapter, item.getTitleId(),
position, false, AndroidUtils.getCenterViewCoordinates(view))) {
if (position == 0 && navDrawerLogo != null) {
getMyApplication().getAppCustomization().restoreOsmand();
mapActivity.closeDrawer();
} else {
position -= menuItemsListView.getHeaderViewsCount();
ContextMenuItem item = contextMenuAdapter.getItem(position);
ContextMenuAdapter.ItemClickListener click = item.getItemClickListener();
if (click != null && click.onContextMenuClick(simpleListAdapter, item.getTitleId(),
position, false, AndroidUtils.getCenterViewCoordinates(view))) {
mapActivity.closeDrawer();
}
}
}
});