small fixes

This commit is contained in:
Skalii 2021-03-11 16:14:40 +02:00
parent bccfe95597
commit e2b108aefc
3 changed files with 17 additions and 17 deletions

View file

@ -52,7 +52,7 @@ import net.osmand.plus.liveupdates.LiveUpdatesHelper.TimeOfDay;
import net.osmand.plus.liveupdates.LiveUpdatesHelper.UpdateFrequency;
import net.osmand.plus.liveupdates.LiveUpdatesSettingsDialogFragmentNew.OnLiveUpdatesForLocalChange;
import net.osmand.plus.liveupdates.LoadLiveMapsTask.LocalIndexInfoAdapter;
import net.osmand.plus.liveupdates.PerformLiveUpdateAsyncTask.AsyncResponse;
import net.osmand.plus.liveupdates.PerformLiveUpdateAsyncTask.LiveUpdateListener;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.widgets.TextViewEx;
@ -309,7 +309,7 @@ public class LiveUpdatesFragmentNew extends BaseOsmAndDialogFragment implements
private void showUpdateDialog() {
startUpdateDateAsyncTask();
if (!Algorithms.isEmpty(adapter.mapsList)) {
final AsyncResponse refreshAfterUpdate = new AsyncResponse() {
final LiveUpdateListener listener = new LiveUpdateListener() {
@Override
public void processFinish() {
adapter.notifyDataSetChanged();
@ -317,7 +317,7 @@ public class LiveUpdatesFragmentNew extends BaseOsmAndDialogFragment implements
};
if (adapter.countEnabled == 1) {
LocalIndexInfo li = adapter.mapsList.get(0);
runLiveUpdate(getActivity(), li.getFileName(), false, refreshAfterUpdate);
runLiveUpdate(getActivity(), li.getFileName(), false, listener);
} else if (adapter.countEnabled > 1) {
AlertDialog.Builder bld = new AlertDialog.Builder(getMyActivity());
bld.setMessage(R.string.update_all_maps_now);
@ -328,7 +328,7 @@ public class LiveUpdatesFragmentNew extends BaseOsmAndDialogFragment implements
for (LocalIndexInfo li : adapter.mapsList) {
CommonPreference<Boolean> localUpdateOn = preferenceForLocalIndex(li.getFileName(), settings);
if (localUpdateOn.get()) {
runLiveUpdate(getActivity(), li.getFileName(), false, refreshAfterUpdate);
runLiveUpdate(getActivity(), li.getFileName(), false, listener);
}
}
}
@ -650,7 +650,7 @@ public class LiveUpdatesFragmentNew extends BaseOsmAndDialogFragment implements
final CommonPreference<Boolean> liveUpdatePreference = preferenceForLocalIndex(fileName, settings);
liveUpdatePreference.set(newValue);
if (settings.IS_LIVE_UPDATES_ON.get() && liveUpdatePreference.get()) {
runLiveUpdate(getActivity(), fileName, true, new AsyncResponse() {
runLiveUpdate(getActivity(), fileName, true, new LiveUpdateListener() {
@Override
public void processFinish() {
runSort();
@ -673,7 +673,7 @@ public class LiveUpdatesFragmentNew extends BaseOsmAndDialogFragment implements
@Override
public void forceUpdateLocal(String fileName, boolean userRequested, final Runnable callback) {
if (settings.IS_LIVE_UPDATES_ON.get()) {
runLiveUpdate(getActivity(), fileName, userRequested, new AsyncResponse() {
runLiveUpdate(getActivity(), fileName, userRequested, new LiveUpdateListener() {
@Override
public void processFinish() {
updateList();

View file

@ -11,7 +11,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.liveupdates.PerformLiveUpdateAsyncTask.AsyncResponse;
import net.osmand.plus.liveupdates.PerformLiveUpdateAsyncTask.LiveUpdateListener;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
@ -254,8 +254,8 @@ public class LiveUpdatesHelper {
}
}
public static void runLiveUpdate(Context context, final String fileName, boolean userRequested, @Nullable final AsyncResponse runOnPost) {
public static void runLiveUpdate(Context context, final String fileName, boolean userRequested, @Nullable final LiveUpdateListener listener) {
final String fnExt = Algorithms.getFileNameWithoutExtension(new File(fileName));
new PerformLiveUpdateAsyncTask(context, fileName, userRequested, runOnPost).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, fnExt);
new PerformLiveUpdateAsyncTask(context, fileName, userRequested, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, fnExt);
}
}

View file

@ -46,20 +46,20 @@ public class PerformLiveUpdateAsyncTask
@NonNull
private final String localIndexFileName;
private final boolean userRequested;
private final AsyncResponse runOnPost;
private final LiveUpdateListener listener;
public interface AsyncResponse {
public interface LiveUpdateListener {
void processFinish();
}
public PerformLiveUpdateAsyncTask(@NonNull Context context,
@NonNull String localIndexFileName,
boolean userRequested,
@Nullable AsyncResponse runOnPost) {
@Nullable LiveUpdateListener listener) {
this.context = context;
this.localIndexFileName = localIndexFileName;
this.userRequested = userRequested;
this.runOnPost = runOnPost;
this.listener = listener;
}
@Override
@ -149,8 +149,8 @@ public class PerformLiveUpdateAsyncTask
((DownloadIndexesThread.DownloadEvents) context).downloadInProgress();
}
updateLatestAvailability(application, localIndexFileName);
if (runOnPost != null) {
runOnPost.processFinish();
if (listener != null) {
listener.processFinish();
}
} else {
LOG.debug("onPostExecute: Not enough space for updates");
@ -163,8 +163,8 @@ public class PerformLiveUpdateAsyncTask
((DownloadIndexesThread.DownloadEvents) context).downloadInProgress();
if (userRequested && context instanceof DownloadActivity) {
updateLatestAvailability(application, localIndexFileName);
if (runOnPost != null) {
runOnPost.processFinish();
if (listener != null) {
listener.processFinish();
}
application.showShortToastMessage(R.string.no_updates_available);
}