Merge pull request #6056 from osmandapp/Fix_6038

Fix #6038
This commit is contained in:
Alexander Sytnyk 2018-09-17 14:16:00 +03:00 committed by GitHub
commit 9c996cdaa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 17 deletions

View file

@ -159,8 +159,8 @@ public class LiveUpdatesHelper {
}
}
public static void runLiveUpdate(Context context, final String fileName, boolean forceUpdate) {
public static void runLiveUpdate(Context context, final String fileName, boolean userRequested) {
final String fnExt = Algorithms.getFileNameWithoutExtension(new File(fileName));
new PerformLiveUpdateAsyncTask(context, fileName, forceUpdate).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, fnExt);
new PerformLiveUpdateAsyncTask(context, fileName, userRequested).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, fnExt);
}
}

View file

@ -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:

View file

@ -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;
@ -30,14 +31,14 @@ public class PerformLiveUpdateAsyncTask
private final Context context;
@NonNull
private final String localIndexFileName;
private final boolean forceUpdate;
private final boolean userRequested;
public PerformLiveUpdateAsyncTask(@NonNull Context context,
@NonNull String localIndexFileName,
boolean forceUpdate) {
boolean userRequested) {
this.context = context;
this.localIndexFileName = localIndexFileName;
this.forceUpdate = forceUpdate;
this.userRequested = userRequested;
}
@Override
@ -76,6 +77,9 @@ public class PerformLiveUpdateAsyncTask
final OsmandSettings settings = application.getSettings();
if (result.errorMessage != null) {
LOG.info(result.errorMessage);
if (userRequested) {
application.showShortToastMessage(result.errorMessage);
}
tryRescheduleDownload(context, settings, localIndexFileName);
} else {
settings.LIVE_UPDATES_RETRIES.resetToDefault();
@ -95,7 +99,7 @@ public class PerformLiveUpdateAsyncTask
boolean downloadViaWiFi =
LiveUpdatesHelper.preferenceDownloadViaWiFi(localIndexFileName, settings).get();
if (getMyApplication().getSettings().isInternetConnectionAvailable()) {
if (forceUpdate || settings.isWifiConnected() || !downloadViaWiFi) {
if (userRequested || settings.isWifiConnected() || !downloadViaWiFi) {
long szLong = 0;
int i = 0;
for (IndexItem es : downloadThread.getCurrentDownloadingItems()) {
@ -122,6 +126,9 @@ public class PerformLiveUpdateAsyncTask
} else {
if (context instanceof DownloadIndexesThread.DownloadEvents) {
((DownloadIndexesThread.DownloadEvents) context).downloadInProgress();
if (userRequested && context instanceof OsmLiveActivity) {
application.showShortToastMessage(R.string.no_updates_available);
}
}
}
}