some fixes;

This commit is contained in:
Skalii 2021-03-29 14:03:05 +03:00
parent c5540162f4
commit 6ba23e6a3c
6 changed files with 122 additions and 56 deletions

View file

@ -12,7 +12,7 @@
-->
<string name="live_update_all_maps">Update all maps added to \"OsmAnd Live\"?</string>
<string name="update_all_maps_added">Update all maps added to %1$s?</string>
<string name="release_4_0_beta">
• OsmAnd Live updates moved to \"Downloads > Updates\"\n\n
• Tracks now could be colorizing by altitude, speed, or slope.\n\n

View file

@ -1,5 +1,8 @@
package net.osmand.plus.activities;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import net.osmand.GPXUtilities.GPXFile;
@ -7,8 +10,9 @@ 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> {
public class LocalIndexInfo implements Comparable<LocalIndexInfo>, Parcelable {
private LocalIndexType type;
private String description = "";
@ -43,6 +47,22 @@ public class LocalIndexInfo implements Comparable<LocalIndexInfo> {
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;
}
@ -176,4 +196,46 @@ public class LocalIndexInfo implements Comparable<LocalIndexInfo> {
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;
}
}

View file

@ -399,7 +399,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download
public void onClick(View v) {
if (!listAdapter.isShowOsmLivePurchaseBanner()) {
showUpdateDialog(getActivity(), getFragmentManager(),
listAdapter.mapsList, listAdapter.countEnabled, null);
settings, listAdapter.mapsList, null);
}
}
});

View file

@ -170,8 +170,7 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
@Override
public void onRefresh() {
if (settings.IS_LIVE_UPDATES_ON.get()) {
showUpdateDialog(getActivity(), getFragmentManager(), adapter.mapsList,
adapter.countEnabled, liveUpdateListener);
showUpdateDialog(getActivity(), getFragmentManager(), settings, adapter.mapsList, liveUpdateListener);
startUpdateDateAsyncTask();
}
swipeRefresh.setRefreshing(false);
@ -262,9 +261,6 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
Toolbar toolbar = (Toolbar) appBarLayout.findViewById(R.id.toolbar);
TextViewEx toolbarTitle = (TextViewEx) toolbar.findViewById(R.id.toolbar_title);
toolbarTitle.setText(R.string.osm_live);
int iconColorResId = nightMode ? R.color.active_buttons_and_links_text_dark : R.color.active_buttons_and_links_text_light;
Drawable icBack = app.getUIUtilities().getIcon(AndroidUtils.getNavigationIconResId(app), iconColorResId);
DrawableCompat.setTint(icBack, ContextCompat.getColor(app, iconColorResId));
View closeButton = toolbar.findViewById(R.id.close_button);
closeButton.setOnClickListener(new View.OnClickListener() {
@ -275,6 +271,7 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
});
FrameLayout iconHelpContainer = toolbar.findViewById(R.id.action_button);
int iconColorResId = nightMode ? R.color.active_buttons_and_links_text_dark : R.color.active_buttons_and_links_text_light;
AppCompatImageButton iconHelp = toolbar.findViewById(R.id.action_button_icon);
Drawable helpDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_help_online, iconColorResId);
iconHelp.setImageDrawable(helpDrawable);
@ -329,18 +326,19 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
private void switchOnLiveUpdates() {
settings.IS_LIVE_UPDATES_ON.set(true);
enableLiveUpdates(true);
showUpdateDialog(getMyActivity(), getFragmentManager(), adapter.mapsList, adapter.countEnabled, liveUpdateListener);
showUpdateDialog(getMyActivity(), getFragmentManager(), settings, adapter.mapsList, liveUpdateListener);
startUpdateDateAsyncTask();
}
public static void showUpdateDialog(Activity context, FragmentManager fragmentManager, List<LocalIndexInfo> mapsList,
int countEnabled, @Nullable LiveUpdateListener listener) {
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, mapsList, listener);
LiveUpdatesUpdateAllBottomSheet.showInstance(fragmentManager, getMapsToUpdate(mapsList, settings), listener);
}
}
}
@ -348,22 +346,20 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
private void enableLiveUpdates(boolean enable) {
if (!Algorithms.isEmpty(adapter.mapsList)) {
AlarmManager alarmMgr = (AlarmManager) app.getSystemService(Context.ALARM_SERVICE);
for (LocalIndexInfo li : adapter.mapsList) {
CommonPreference<Boolean> localUpdateOn = preferenceForLocalIndex(li.getFileName(), settings);
if (localUpdateOn.get()) {
String fileName = li.getFileName();
PendingIntent alarmIntent = getPendingIntent(app, fileName);
if (enable) {
final CommonPreference<Integer> updateFrequencyPreference =
preferenceUpdateFrequency(fileName, settings);
final CommonPreference<Integer> timeOfDayPreference =
preferenceTimeOfDayToUpdate(fileName, settings);
UpdateFrequency updateFrequency = UpdateFrequency.values()[updateFrequencyPreference.get()];
TimeOfDay timeOfDayToUpdate = TimeOfDay.values()[timeOfDayPreference.get()];
setAlarmForPendingIntent(alarmIntent, alarmMgr, updateFrequency, timeOfDayToUpdate);
} else {
alarmMgr.cancel(alarmIntent);
}
List<LocalIndexInfo> mapsToUpdate = getMapsToUpdate(adapter.mapsList, settings);
for (LocalIndexInfo li : mapsToUpdate) {
String fileName = li.getFileName();
PendingIntent alarmIntent = getPendingIntent(app, fileName);
if (enable) {
final CommonPreference<Integer> updateFrequencyPreference =
preferenceUpdateFrequency(fileName, settings);
final CommonPreference<Integer> timeOfDayPreference =
preferenceTimeOfDayToUpdate(fileName, settings);
UpdateFrequency updateFrequency = UpdateFrequency.values()[updateFrequencyPreference.get()];
TimeOfDay timeOfDayToUpdate = TimeOfDay.values()[timeOfDayPreference.get()];
setAlarmForPendingIntent(alarmIntent, alarmMgr, updateFrequency, timeOfDayToUpdate);
} else {
alarmMgr.cancel(alarmIntent);
}
}
}
@ -375,21 +371,26 @@ public class LiveUpdatesFragment extends BaseOsmAndDialogFragment implements OnL
}
}
public static int updateCountEnabled(TextView countView, ArrayList<LocalIndexInfo> mapsList, OsmandSettings settings) {
int countEnabled = 0;
public static int updateCountEnabled(TextView countView, List<LocalIndexInfo> mapsList, OsmandSettings settings) {
int countEnabled = getMapsToUpdate(mapsList, settings).size();
if (countView != null) {
for (LocalIndexInfo map : mapsList) {
CommonPreference<Boolean> preference = preferenceForLocalIndex(map.getFileName(), settings);
if (preference.get()) {
countEnabled++;
}
}
String countText = countEnabled + "/" + mapsList.size();
countView.setText(countText);
}
return countEnabled;
}
public static List<LocalIndexInfo> getMapsToUpdate(List<LocalIndexInfo> mapsList, OsmandSettings settings) {
List<LocalIndexInfo> listToUpdate = new ArrayList<>();
for (LocalIndexInfo mapToUpdate : mapsList) {
CommonPreference<Boolean> preference = preferenceForLocalIndex(mapToUpdate.getFileName(), settings);
if (preference.get()) {
listToUpdate.add(mapToUpdate);
}
}
return listToUpdate;
}
protected class LiveMapsAdapter extends OsmandBaseExpandableListAdapter implements LocalIndexInfoAdapter {
private final ArrayList<LocalIndexInfo> mapsList = new ArrayList<>();
private int countEnabled = 0;

View file

@ -1,6 +1,7 @@
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;
@ -11,7 +12,6 @@ import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities.DialogButtonType;
import net.osmand.plus.activities.LocalIndexInfo;
@ -20,25 +20,22 @@ 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.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
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.preferenceForLocalIndex;
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.runLiveUpdate;
public class LiveUpdatesUpdateAllBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = LiveUpdatesUpdateAllBottomSheet.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(LiveUpdatesUpdateAllBottomSheet.class);
private OsmandApplication app;
private OsmandSettings settings;
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;
@ -66,8 +63,10 @@ public class LiveUpdatesUpdateAllBottomSheet extends MenuBottomSheetDialogFragme
@Override
public void createMenuItems(Bundle savedInstanceState) {
app = getMyApplication();
settings = app.getSettings();
if (savedInstanceState != null) {
mapsList = savedInstanceState.getParcelableArrayList(MAPS_TO_UPDATE);
listener = (LiveUpdateListener) savedInstanceState.getSerializable(LIVE_UPDATE_LISTENER);
}
updateBottomButtons();
@ -78,8 +77,9 @@ public class LiveUpdatesUpdateAllBottomSheet extends MenuBottomSheetDialogFragme
.create();
items.add(itemTitle);
String osmAndLive = "\"" + getString(R.string.osm_live) + "\"";
itemDescription = new LongDescriptionItem.Builder()
.setDescription(getString(R.string.live_update_all_maps))
.setDescription(getString(R.string.update_all_maps_added, osmAndLive))
.setDescriptionMaxLines(5)
.setDescriptionColorId(getPrimaryTextColorId(nightMode))
.setLayoutId(R.layout.bottom_sheet_item_description_long)
@ -97,14 +97,17 @@ 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() {
if (settings != null) {
for (LocalIndexInfo li : mapsList) {
CommonPreference<Boolean> localUpdateOn = preferenceForLocalIndex(li.getFileName(), settings);
if (localUpdateOn.get()) {
runLiveUpdate(getActivity(), li.getFileName(), false, listener);
}
}
for (LocalIndexInfo li : mapsList) {
runLiveUpdate(getActivity(), li.getFileName(), false, listener);
}
}
@ -128,5 +131,4 @@ public class LiveUpdatesUpdateAllBottomSheet extends MenuBottomSheetDialogFragme
protected DialogButtonType getRightBottomButtonType() {
return DialogButtonType.PRIMARY;
}
}

View file

@ -25,6 +25,7 @@ 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;
@ -48,7 +49,7 @@ public class PerformLiveUpdateAsyncTask
private final boolean userRequested;
private final LiveUpdateListener listener;
public interface LiveUpdateListener {
public interface LiveUpdateListener extends Serializable {
void processFinish();
}