From c31ff92c95ca5bf9236a2aa267ae719a68683f64 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 17 Sep 2018 13:43:01 +0300 Subject: [PATCH] Fix #6038 --- .../LiveUpdatesSettingsDialogFragment.java | 43 ++++++++++++++----- .../PerformLiveUpdateAsyncTask.java | 7 +++ 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesSettingsDialogFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesSettingsDialogFragment.java index b5b4789767..bdb09145f6 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesSettingsDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesSettingsDialogFragment.java @@ -14,6 +14,7 @@ import android.view.LayoutInflater; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.CheckBox; import android.widget.Spinner; import android.widget.TextView; @@ -50,11 +51,16 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment { private static final Log LOG = PlatformUtil.getLog(LiveUpdatesSettingsDialogFragment.class); private static final String LOCAL_INDEX_FILE_NAME = "local_index_file_name"; + private TextView sizeTextView; + + private String fileName; + private String fileNameWithoutExtension; + @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - final String fileName = getArguments().getString(LOCAL_INDEX_FILE_NAME); + fileName = getArguments().getString(LOCAL_INDEX_FILE_NAME); assert fileName != null; View view = LayoutInflater.from(getActivity()) @@ -67,11 +73,10 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment { final Spinner updateFrequencySpinner = (Spinner) view.findViewById(R.id.updateFrequencySpinner); final Spinner updateTimesOfDaySpinner = (Spinner) view.findViewById(R.id.updateTimesOfDaySpinner); final View updateTimesOfDayLayout = view.findViewById(R.id.updateTimesOfDayLayout); - final TextView sizeTextView = (TextView) view.findViewById(R.id.sizeTextView); + sizeTextView = (TextView) view.findViewById(R.id.sizeTextView); regionNameTextView.setText(getNameToDisplay(fileName, getMyActivity())); - final String fileNameWithoutExtension = - Algorithms.getFileNameWithoutExtension(new File(fileName)); + fileNameWithoutExtension = Algorithms.getFileNameWithoutExtension(new File(fileName)); final IncrementalChangesManager changesManager = getMyApplication().getResourceManager().getChangesManager(); final long timestamp = changesManager.getTimestamp(fileNameWithoutExtension); String lastUpdateDate = formatDateTime(getActivity(), timestamp); @@ -171,16 +176,32 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment { } }) .setNegativeButton(R.string.shared_string_cancel, null) - .setNeutralButton(R.string.update_now, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - runLiveUpdate(getActivity(), fileName, true); - sizeTextView.setText(getUpdatesSize(fileNameWithoutExtension, changesManager)); - } - }); + .setNeutralButton(R.string.update_now, null); return builder.create(); } + @Override + public void onResume() { + super.onResume(); + final AlertDialog dialog = (AlertDialog) getDialog(); + if (dialog != null) { + Button neutralButton = (Button) dialog.getButton(Dialog.BUTTON_NEUTRAL); + neutralButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (!getSettings().isInternetConnectionAvailable()) { + getMyApplication().showShortToastMessage(R.string.no_internet_connection); + } else { + runLiveUpdate(getActivity(), fileName, true); + final IncrementalChangesManager changesManager = getMyApplication().getResourceManager().getChangesManager(); + sizeTextView.setText(getUpdatesSize(fileNameWithoutExtension, changesManager)); + dialog.dismiss(); + } + } + }); + } + } + private void refreshTimeOfDayLayout(UpdateFrequency updateFrequency, View updateTimesOfDayLayout) { switch (updateFrequency) { case HOURLY: diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/PerformLiveUpdateAsyncTask.java b/OsmAnd/src/net/osmand/plus/liveupdates/PerformLiveUpdateAsyncTask.java index db0a0b8efd..570ed57a14 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/PerformLiveUpdateAsyncTask.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/PerformLiveUpdateAsyncTask.java @@ -9,6 +9,7 @@ import android.support.annotation.NonNull; import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; import net.osmand.plus.download.AbstractDownloadActivity; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadIndexesThread; @@ -76,6 +77,9 @@ public class PerformLiveUpdateAsyncTask final OsmandSettings settings = application.getSettings(); if (result.errorMessage != null) { LOG.info(result.errorMessage); + if (forceUpdate) { + application.showShortToastMessage(result.errorMessage); + } tryRescheduleDownload(context, settings, localIndexFileName); } else { settings.LIVE_UPDATES_RETRIES.resetToDefault(); @@ -122,6 +126,9 @@ public class PerformLiveUpdateAsyncTask } else { if (context instanceof DownloadIndexesThread.DownloadEvents) { ((DownloadIndexesThread.DownloadEvents) context).downloadInProgress(); + if (forceUpdate && context instanceof OsmLiveActivity) { + application.showShortToastMessage(R.string.no_updates_available); + } } } }