fix manual update process;
This commit is contained in:
parent
6ba23e6a3c
commit
7115368dd4
8 changed files with 116 additions and 172 deletions
|
@ -1,8 +1,5 @@
|
|||
package net.osmand.plus.activities;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
|
@ -10,9 +7,8 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class LocalIndexInfo implements Comparable<LocalIndexInfo>, Parcelable {
|
||||
public class LocalIndexInfo implements Comparable<LocalIndexInfo> {
|
||||
|
||||
private LocalIndexType type;
|
||||
private String description = "";
|
||||
|
@ -47,22 +43,6 @@ public class LocalIndexInfo implements Comparable<LocalIndexInfo>, Parcelable {
|
|||
this.backupedData = backuped;
|
||||
}
|
||||
|
||||
protected LocalIndexInfo(Parcel in) {
|
||||
readFromParcel(in);
|
||||
}
|
||||
|
||||
public static final Creator<LocalIndexInfo> CREATOR = new Creator<LocalIndexInfo>() {
|
||||
@Override
|
||||
public LocalIndexInfo createFromParcel(Parcel in) {
|
||||
return new LocalIndexInfo(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalIndexInfo[] newArray(int size) {
|
||||
return new LocalIndexInfo[size];
|
||||
}
|
||||
};
|
||||
|
||||
public void setAttachedObject(Object attachedObject) {
|
||||
this.attachedObject = attachedObject;
|
||||
}
|
||||
|
@ -196,46 +176,4 @@ public class LocalIndexInfo implements Comparable<LocalIndexInfo>, Parcelable {
|
|||
public int compareTo(LocalIndexInfo o) {
|
||||
return getFileName().compareTo(o.getFileName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeSerializable(type);
|
||||
dest.writeString(description);
|
||||
dest.writeString(name);
|
||||
dest.writeByte((byte) (backupedData ? 1 : 0));
|
||||
dest.writeByte((byte) (corrupted ? 1 : 0));
|
||||
dest.writeByte((byte) (notSupported ? 1 : 0));
|
||||
dest.writeByte((byte) (loaded ? 1 : 0));
|
||||
dest.writeString(subfolder);
|
||||
dest.writeString(pathToData);
|
||||
dest.writeString(fileName);
|
||||
dest.writeByte((byte) (singleFile ? 1 : 0));
|
||||
dest.writeInt(kbSize);
|
||||
dest.writeSerializable((Serializable) attachedObject);
|
||||
dest.writeByte((byte) (expanded ? 1 : 0));
|
||||
dest.writeValue(gpxFile);
|
||||
}
|
||||
|
||||
private void readFromParcel(Parcel in) {
|
||||
type = (LocalIndexType) in.readSerializable();
|
||||
description = in.readString();
|
||||
name = in.readString();
|
||||
backupedData = in.readByte() != 0;
|
||||
corrupted = in.readByte() != 0;
|
||||
notSupported = in.readByte() != 0;
|
||||
loaded = in.readByte() != 0;
|
||||
subfolder = in.readString();
|
||||
pathToData = in.readString();
|
||||
fileName = in.readString();
|
||||
singleFile = in.readByte() != 0;
|
||||
kbSize = in.readInt();
|
||||
attachedObject = in.readSerializable();
|
||||
expanded = in.readByte() != 0;
|
||||
gpxFile = (GPXFile) in.readSerializable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ import androidx.appcompat.content.res.AppCompatResources;
|
|||
import androidx.cardview.widget.CardView;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.view.MenuItemCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.Collator;
|
||||
|
@ -40,6 +41,7 @@ import net.osmand.plus.activities.LocalIndexInfo;
|
|||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.liveupdates.LiveUpdatesClearBottomSheet.RefreshLiveUpdates;
|
||||
import net.osmand.plus.liveupdates.LiveUpdatesFragment;
|
||||
import net.osmand.plus.liveupdates.LiveUpdatesHelper.LiveUpdateListener;
|
||||
import net.osmand.plus.liveupdates.LoadLiveMapsTask;
|
||||
import net.osmand.plus.liveupdates.LoadLiveMapsTask.LocalIndexInfoAdapter;
|
||||
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment.ChoosePlanDialogType;
|
||||
|
@ -52,7 +54,6 @@ import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
|||
import net.osmand.plus.download.DownloadResources;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
||||
import net.osmand.plus.widgets.TextViewEx;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -62,7 +63,7 @@ import java.util.List;
|
|||
import static net.osmand.plus.liveupdates.LiveUpdatesFragment.showUpdateDialog;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesFragment.updateCountEnabled;
|
||||
|
||||
public class UpdatesIndexFragment extends OsmAndListFragment implements DownloadEvents, RefreshLiveUpdates {
|
||||
public class UpdatesIndexFragment extends OsmAndListFragment implements DownloadEvents, RefreshLiveUpdates, LiveUpdateListener {
|
||||
private static final int RELOAD_ID = 5;
|
||||
private UpdateIndexAdapter listAdapter;
|
||||
private String errorMessage;
|
||||
|
@ -398,8 +399,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!listAdapter.isShowOsmLivePurchaseBanner()) {
|
||||
showUpdateDialog(getActivity(), getFragmentManager(),
|
||||
settings, listAdapter.mapsList, null);
|
||||
showUpdateDialog(getActivity(), getFragmentManager(), UpdatesIndexFragment.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -417,9 +417,22 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processFinish() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LocalIndexInfo> getMapsToUpdate() {
|
||||
return LiveUpdatesFragment.getMapsToUpdate(listAdapter.mapsList, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment currentFragment() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
public static int getDefaultIconColorId(boolean nightMode) {
|
||||
return nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ public class LiveUpdatesAlarmReceiver extends BroadcastReceiver {
|
|||
final OsmandSettings settings = application.getSettings();
|
||||
|
||||
if (!preferenceDownloadViaWiFi(localIndexInfoFile, settings).get() || wifi.isWifiEnabled()) {
|
||||
new PerformLiveUpdateAsyncTask(context, localIndexInfoFile, false, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, fileName);
|
||||
new PerformLiveUpdateAsyncTask(context, localIndexInfoFile, false)
|
||||
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, fileName);
|
||||
} else {
|
||||
PerformLiveUpdateAsyncTask.tryRescheduleDownload(context, settings, localIndexInfoFile);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import android.widget.TextView;
|
|||
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.appcompat.widget.AppCompatImageButton;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
|
@ -56,7 +55,7 @@ import net.osmand.plus.liveupdates.LiveUpdatesHelper.TimeOfDay;
|
|||
import net.osmand.plus.liveupdates.LiveUpdatesHelper.UpdateFrequency;
|
||||
import net.osmand.plus.liveupdates.LiveUpdatesSettingsBottomSheet.OnLiveUpdatesForLocalChange;
|
||||
import net.osmand.plus.liveupdates.LoadLiveMapsTask.LocalIndexInfoAdapter;
|
||||
import net.osmand.plus.liveupdates.PerformLiveUpdateAsyncTask.LiveUpdateListener;
|
||||
import net.osmand.plus.liveupdates.LiveUpdatesHelper.LiveUpdateListener;
|
||||
import net.osmand.plus.settings.backend.CommonPreference;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.widgets.TextViewEx;
|
||||
|
@ -92,7 +91,7 @@ import static net.osmand.plus.monitoring.TripRecordingBottomSheet.getActiveTextC
|
|||
import static net.osmand.plus.monitoring.TripRecordingBottomSheet.getOsmandIconColorId;
|
||||
import static net.osmand.plus.monitoring.TripRecordingBottomSheet.getSecondaryIconColorId;
|
||||
|
||||
public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnLiveUpdatesForLocalChange {
|
||||
public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnLiveUpdatesForLocalChange, LiveUpdateListener {
|
||||
|
||||
public static final String URL = "https://osmand.net/api/osmlive_status";
|
||||
public static final String TAG = LiveUpdatesFragment.class.getSimpleName();
|
||||
|
@ -111,13 +110,6 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
|
|||
private GetLastUpdateDateTask getLastUpdateDateTask;
|
||||
private LoadLiveMapsTask loadLiveMapsTask;
|
||||
|
||||
private final LiveUpdateListener liveUpdateListener = new LiveUpdateListener() {
|
||||
@Override
|
||||
public void processFinish() {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fragmentManager, Fragment target) {
|
||||
if (!fragmentManager.isStateSaved()) {
|
||||
LiveUpdatesFragment fragment = new LiveUpdatesFragment();
|
||||
|
@ -126,6 +118,23 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
|
|||
}
|
||||
}
|
||||
|
||||
public static void showUpdateDialog(Activity context, FragmentManager fragmentManager, final LiveUpdateListener listener) {
|
||||
List<LocalIndexInfo> mapsToUpdate = listener.getMapsToUpdate();
|
||||
if (!Algorithms.isEmpty(mapsToUpdate)) {
|
||||
int countEnabled = listener.getMapsToUpdate().size();
|
||||
if (countEnabled == 1) {
|
||||
runLiveUpdate(context, mapsToUpdate.get(0).getFileName(), false, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.processFinish();
|
||||
}
|
||||
});
|
||||
} else if (countEnabled > 1) {
|
||||
LiveUpdatesUpdateAllBottomSheet.showInstance(fragmentManager, listener.currentFragment());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -170,7 +179,7 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
|
|||
@Override
|
||||
public void onRefresh() {
|
||||
if (settings.IS_LIVE_UPDATES_ON.get()) {
|
||||
showUpdateDialog(getActivity(), getFragmentManager(), settings, adapter.mapsList, liveUpdateListener);
|
||||
showUpdateDialog(getActivity(), getFragmentManager(), LiveUpdatesFragment.this);
|
||||
startUpdateDateAsyncTask();
|
||||
}
|
||||
swipeRefresh.setRefreshing(false);
|
||||
|
@ -326,23 +335,10 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
|
|||
private void switchOnLiveUpdates() {
|
||||
settings.IS_LIVE_UPDATES_ON.set(true);
|
||||
enableLiveUpdates(true);
|
||||
showUpdateDialog(getMyActivity(), getFragmentManager(), settings, adapter.mapsList, liveUpdateListener);
|
||||
showUpdateDialog(getMyActivity(), getFragmentManager(), this);
|
||||
startUpdateDateAsyncTask();
|
||||
}
|
||||
|
||||
public static void showUpdateDialog(Activity context, FragmentManager fragmentManager, OsmandSettings settings,
|
||||
List<LocalIndexInfo> mapsList, @Nullable LiveUpdateListener listener) {
|
||||
if (!Algorithms.isEmpty(mapsList)) {
|
||||
int countEnabled = updateCountEnabled(null, mapsList, settings);
|
||||
if (countEnabled == 1) {
|
||||
LocalIndexInfo li = mapsList.get(0);
|
||||
runLiveUpdate(context, li.getFileName(), false, listener);
|
||||
} else if (countEnabled > 1) {
|
||||
LiveUpdatesUpdateAllBottomSheet.showInstance(fragmentManager, getMapsToUpdate(mapsList, settings), listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void enableLiveUpdates(boolean enable) {
|
||||
if (!Algorithms.isEmpty(adapter.mapsList)) {
|
||||
AlarmManager alarmMgr = (AlarmManager) app.getSystemService(Context.ALARM_SERVICE);
|
||||
|
@ -562,7 +558,12 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
|
|||
compoundButton.setOnCheckedChangeListener(new SwitchCompat.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
onUpdateLocalIndex(item, isChecked, null);
|
||||
onUpdateLocalIndex(item, isChecked, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runSort();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -639,6 +640,21 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
|
|||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processFinish() {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LocalIndexInfo> getMapsToUpdate() {
|
||||
return getMapsToUpdate(adapter.mapsList, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment currentFragment() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUpdateLocalIndex(String fileName, boolean newValue, final Runnable callback) {
|
||||
|
||||
|
@ -650,15 +666,7 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
|
|||
final CommonPreference<Boolean> liveUpdatePreference = preferenceForLocalIndex(fileName, settings);
|
||||
liveUpdatePreference.set(newValue);
|
||||
if (settings.IS_LIVE_UPDATES_ON.get() && liveUpdatePreference.get()) {
|
||||
runLiveUpdate(getActivity(), fileName, true, new LiveUpdateListener() {
|
||||
@Override
|
||||
public void processFinish() {
|
||||
runSort();
|
||||
if (callback != null) {
|
||||
callback.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
runLiveUpdate(getActivity(), fileName, true, callback);
|
||||
UpdateFrequency updateFrequency = UpdateFrequency.values()[frequencyId];
|
||||
TimeOfDay timeOfDayToUpdate = TimeOfDay.values()[timeOfDateToUpdateId];
|
||||
setAlarmForPendingIntent(alarmIntent, alarmManager, updateFrequency, timeOfDayToUpdate);
|
||||
|
@ -673,15 +681,7 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
|
|||
@Override
|
||||
public void forceUpdateLocal(String fileName, boolean userRequested, final Runnable callback) {
|
||||
if (settings.IS_LIVE_UPDATES_ON.get()) {
|
||||
runLiveUpdate(getActivity(), fileName, userRequested, new LiveUpdateListener() {
|
||||
@Override
|
||||
public void processFinish() {
|
||||
updateList();
|
||||
if (callback != null) {
|
||||
callback.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
runLiveUpdate(getActivity(), fileName, userRequested, callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -703,5 +703,4 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
|
|||
public static int getDefaultIconColorId(boolean nightMode) {
|
||||
return nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,9 +9,10 @@ import android.text.format.DateUtils;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.liveupdates.PerformLiveUpdateAsyncTask.LiveUpdateListener;
|
||||
import net.osmand.plus.activities.LocalIndexInfo;
|
||||
import net.osmand.plus.settings.backend.CommonPreference;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -20,6 +21,7 @@ import net.osmand.util.Algorithms;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class LiveUpdatesHelper {
|
||||
|
@ -254,8 +256,29 @@ public class LiveUpdatesHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static void runLiveUpdate(Context context, final String fileName, boolean userRequested, @Nullable final LiveUpdateListener listener) {
|
||||
public static void runLiveUpdate(Context context, final String fileName, boolean userRequested, @Nullable final Runnable runOnSuccess) {
|
||||
final String fnExt = Algorithms.getFileNameWithoutExtension(new File(fileName));
|
||||
new PerformLiveUpdateAsyncTask(context, fileName, userRequested, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, fnExt);
|
||||
PerformLiveUpdateAsyncTask task = new PerformLiveUpdateAsyncTask(context, fileName, userRequested);
|
||||
task.setRunOnSuccess(runOnSuccess);
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, fnExt);
|
||||
}
|
||||
|
||||
public static void runLiveUpdate(Context context, boolean userRequested, final LiveUpdateListener listener) {
|
||||
for (LocalIndexInfo mapToUpdate : listener.getMapsToUpdate()) {
|
||||
runLiveUpdate(context, mapToUpdate.getFileName(), userRequested, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.processFinish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public interface LiveUpdateListener {
|
||||
void processFinish();
|
||||
|
||||
List<LocalIndexInfo> getMapsToUpdate();
|
||||
|
||||
Fragment currentFragment();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -157,6 +157,10 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
|||
updateLastCheck();
|
||||
updateFrequencyHelpMessage();
|
||||
updateFileSize();
|
||||
Fragment target = getTargetFragment();
|
||||
if (target instanceof LiveUpdatesFragment) {
|
||||
((LiveUpdatesFragment) target).runSort();
|
||||
}
|
||||
}
|
||||
})) {
|
||||
item.setTitle(getStateText(!checked));
|
||||
|
@ -276,6 +280,10 @@ public class LiveUpdatesSettingsBottomSheet extends MenuBottomSheetDialogFragmen
|
|||
updateLastCheck();
|
||||
updateFrequencyHelpMessage();
|
||||
updateFileSize();
|
||||
Fragment target = getTargetFragment();
|
||||
if (target instanceof LiveUpdatesFragment) {
|
||||
((LiveUpdatesFragment) target).updateList();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package net.osmand.plus.liveupdates;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -9,24 +8,21 @@ import android.view.ViewGroup;
|
|||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities.DialogButtonType;
|
||||
import net.osmand.plus.activities.LocalIndexInfo;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
||||
import net.osmand.plus.liveupdates.PerformLiveUpdateAsyncTask.LiveUpdateListener;
|
||||
import net.osmand.plus.liveupdates.LiveUpdatesHelper.LiveUpdateListener;
|
||||
import net.osmand.plus.widgets.TextViewEx;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.AndroidUtils.getPrimaryTextColorId;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.runLiveUpdate;
|
||||
|
||||
|
@ -34,40 +30,20 @@ public class LiveUpdatesUpdateAllBottomSheet extends MenuBottomSheetDialogFragme
|
|||
|
||||
public static final String TAG = LiveUpdatesUpdateAllBottomSheet.class.getSimpleName();
|
||||
private static final Log LOG = PlatformUtil.getLog(LiveUpdatesUpdateAllBottomSheet.class);
|
||||
private static final String MAPS_TO_UPDATE = "maps_to_update";
|
||||
private static final String LIVE_UPDATE_LISTENER = "live_update_listener";
|
||||
|
||||
private BaseBottomSheetItem itemTitle;
|
||||
private BaseBottomSheetItem itemDescription;
|
||||
|
||||
private List<LocalIndexInfo> mapsList;
|
||||
private LiveUpdateListener listener;
|
||||
|
||||
public void setMapsList(List<LocalIndexInfo> mapsList) {
|
||||
this.mapsList = mapsList;
|
||||
}
|
||||
|
||||
public void setListener(LiveUpdateListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fragmentManager,
|
||||
List<LocalIndexInfo> mapsList, LiveUpdateListener listener) {
|
||||
public static void showInstance(@NonNull FragmentManager fragmentManager, Fragment target) {
|
||||
if (!fragmentManager.isStateSaved()) {
|
||||
LiveUpdatesUpdateAllBottomSheet fragment = new LiveUpdatesUpdateAllBottomSheet();
|
||||
fragment.setMapsList(mapsList);
|
||||
fragment.setListener(listener);
|
||||
fragment.setTargetFragment(target, 0);
|
||||
fragment.show(fragmentManager, TAG);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
if (savedInstanceState != null) {
|
||||
mapsList = savedInstanceState.getParcelableArrayList(MAPS_TO_UPDATE);
|
||||
listener = (LiveUpdateListener) savedInstanceState.getSerializable(LIVE_UPDATE_LISTENER);
|
||||
}
|
||||
|
||||
updateBottomButtons();
|
||||
|
||||
itemTitle = new SimpleBottomSheetItem.Builder()
|
||||
|
@ -97,17 +73,10 @@ public class LiveUpdatesUpdateAllBottomSheet extends MenuBottomSheetDialogFragme
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelableArrayList(MAPS_TO_UPDATE, (ArrayList<? extends Parcelable>) mapsList);
|
||||
outState.putSerializable(LIVE_UPDATE_LISTENER, listener);
|
||||
}
|
||||
|
||||
private void updateAll() {
|
||||
for (LocalIndexInfo li : mapsList) {
|
||||
runLiveUpdate(getActivity(), li.getFileName(), false, listener);
|
||||
Fragment target = getTargetFragment();
|
||||
if (target instanceof LiveUpdateListener) {
|
||||
runLiveUpdate(getActivity(), false, (LiveUpdateListener) target);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.content.Context;
|
|||
import android.os.AsyncTask;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.osmand.AndroidNetworkUtils;
|
||||
import net.osmand.AndroidNetworkUtils.OnRequestResultListener;
|
||||
|
@ -25,7 +24,6 @@ import net.osmand.util.Algorithms;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -47,20 +45,18 @@ public class PerformLiveUpdateAsyncTask
|
|||
@NonNull
|
||||
private final String localIndexFileName;
|
||||
private final boolean userRequested;
|
||||
private final LiveUpdateListener listener;
|
||||
|
||||
public interface LiveUpdateListener extends Serializable {
|
||||
void processFinish();
|
||||
}
|
||||
private Runnable runOnSuccess;
|
||||
|
||||
public PerformLiveUpdateAsyncTask(@NonNull Context context,
|
||||
@NonNull String localIndexFileName,
|
||||
boolean userRequested,
|
||||
@Nullable LiveUpdateListener listener) {
|
||||
boolean userRequested) {
|
||||
this.context = context;
|
||||
this.localIndexFileName = localIndexFileName;
|
||||
this.userRequested = userRequested;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void setRunOnSuccess(Runnable runOnSuccess) {
|
||||
this.runOnSuccess = runOnSuccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -150,9 +146,6 @@ public class PerformLiveUpdateAsyncTask
|
|||
((DownloadIndexesThread.DownloadEvents) context).downloadInProgress();
|
||||
}
|
||||
updateLatestAvailability(application, localIndexFileName);
|
||||
if (listener != null) {
|
||||
listener.processFinish();
|
||||
}
|
||||
} else {
|
||||
LOG.debug("onPostExecute: Not enough space for updates");
|
||||
}
|
||||
|
@ -164,9 +157,6 @@ public class PerformLiveUpdateAsyncTask
|
|||
((DownloadIndexesThread.DownloadEvents) context).downloadInProgress();
|
||||
if (userRequested && context instanceof DownloadActivity) {
|
||||
updateLatestAvailability(application, localIndexFileName);
|
||||
if (listener != null) {
|
||||
listener.processFinish();
|
||||
}
|
||||
application.showShortToastMessage(R.string.no_updates_available);
|
||||
}
|
||||
}
|
||||
|
@ -214,6 +204,9 @@ public class PerformLiveUpdateAsyncTask
|
|||
long dateTime = parsed.getTime();
|
||||
preferenceLatestUpdateAvailable(settings).set(dateTime);
|
||||
preferenceLatestUpdateAvailable(localIndexFileName, settings).set(dateTime);
|
||||
if (runOnSuccess != null) {
|
||||
runOnSuccess.run();
|
||||
}
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
long dateTime = preferenceLatestUpdateAvailable(settings).get();
|
||||
|
|
Loading…
Reference in a new issue