This commit is contained in:
Chumva 2018-09-17 13:43:01 +03:00
parent cf32453f66
commit c31ff92c95
2 changed files with 39 additions and 11 deletions

View file

@ -14,6 +14,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; 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 Log LOG = PlatformUtil.getLog(LiveUpdatesSettingsDialogFragment.class);
private static final String LOCAL_INDEX_FILE_NAME = "local_index_file_name"; private static final String LOCAL_INDEX_FILE_NAME = "local_index_file_name";
private TextView sizeTextView;
private String fileName;
private String fileNameWithoutExtension;
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 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; assert fileName != null;
View view = LayoutInflater.from(getActivity()) 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 updateFrequencySpinner = (Spinner) view.findViewById(R.id.updateFrequencySpinner);
final Spinner updateTimesOfDaySpinner = (Spinner) view.findViewById(R.id.updateTimesOfDaySpinner); final Spinner updateTimesOfDaySpinner = (Spinner) view.findViewById(R.id.updateTimesOfDaySpinner);
final View updateTimesOfDayLayout = view.findViewById(R.id.updateTimesOfDayLayout); 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())); regionNameTextView.setText(getNameToDisplay(fileName, getMyActivity()));
final String fileNameWithoutExtension = fileNameWithoutExtension = Algorithms.getFileNameWithoutExtension(new File(fileName));
Algorithms.getFileNameWithoutExtension(new File(fileName));
final IncrementalChangesManager changesManager = getMyApplication().getResourceManager().getChangesManager(); final IncrementalChangesManager changesManager = getMyApplication().getResourceManager().getChangesManager();
final long timestamp = changesManager.getTimestamp(fileNameWithoutExtension); final long timestamp = changesManager.getTimestamp(fileNameWithoutExtension);
String lastUpdateDate = formatDateTime(getActivity(), timestamp); String lastUpdateDate = formatDateTime(getActivity(), timestamp);
@ -171,16 +176,32 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
} }
}) })
.setNegativeButton(R.string.shared_string_cancel, null) .setNegativeButton(R.string.shared_string_cancel, null)
.setNeutralButton(R.string.update_now, new DialogInterface.OnClickListener() { .setNeutralButton(R.string.update_now, null);
@Override
public void onClick(DialogInterface dialog, int which) {
runLiveUpdate(getActivity(), fileName, true);
sizeTextView.setText(getUpdatesSize(fileNameWithoutExtension, changesManager));
}
});
return builder.create(); 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) { private void refreshTimeOfDayLayout(UpdateFrequency updateFrequency, View updateTimesOfDayLayout) {
switch (updateFrequency) { switch (updateFrequency) {
case HOURLY: case HOURLY:

View file

@ -9,6 +9,7 @@ import android.support.annotation.NonNull;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.download.AbstractDownloadActivity; import net.osmand.plus.download.AbstractDownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.download.DownloadIndexesThread;
@ -76,6 +77,9 @@ public class PerformLiveUpdateAsyncTask
final OsmandSettings settings = application.getSettings(); final OsmandSettings settings = application.getSettings();
if (result.errorMessage != null) { if (result.errorMessage != null) {
LOG.info(result.errorMessage); LOG.info(result.errorMessage);
if (forceUpdate) {
application.showShortToastMessage(result.errorMessage);
}
tryRescheduleDownload(context, settings, localIndexFileName); tryRescheduleDownload(context, settings, localIndexFileName);
} else { } else {
settings.LIVE_UPDATES_RETRIES.resetToDefault(); settings.LIVE_UPDATES_RETRIES.resetToDefault();
@ -122,6 +126,9 @@ public class PerformLiveUpdateAsyncTask
} else { } else {
if (context instanceof DownloadIndexesThread.DownloadEvents) { if (context instanceof DownloadIndexesThread.DownloadEvents) {
((DownloadIndexesThread.DownloadEvents) context).downloadInProgress(); ((DownloadIndexesThread.DownloadEvents) context).downloadInProgress();
if (forceUpdate && context instanceof OsmLiveActivity) {
application.showShortToastMessage(R.string.no_updates_available);
}
} }
} }
} }