From 0da37b0d7e82307384e1978ea4cf6cbf3cb6fcdc Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 2 Mar 2016 10:34:43 +0100 Subject: [PATCH] Remove local index info --- .../src/net/osmand/plus/AppInitializer.java | 3 +- .../plus/activities/LocalIndexInfo.java | 41 +++---------------- .../liveupdates/LiveUpdatesAlarmReceiver.java | 4 +- .../plus/liveupdates/LiveUpdatesFragment.java | 17 ++++---- .../plus/liveupdates/LiveUpdatesHelper.java | 36 ++++++++-------- .../LiveUpdatesSettingsDialogFragment.java | 18 ++++---- .../PerformLiveUpdateAsyncTask.java | 8 ++-- 7 files changed, 49 insertions(+), 78 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 7c6b2c5a28..d947807d8d 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -509,7 +509,8 @@ public class AppInitializer implements IProgress { } }); AlarmManager alarmMgr = (AlarmManager) app.getSystemService(Context.ALARM_SERVICE); - for (LocalIndexInfo fullMap : fullMaps) { + for (LocalIndexInfo fm : fullMaps) { + String fullMap = fm.getFileName(); if (!preferenceLiveUpdatesOn(fullMap, settings).get()) { continue; } diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java index c99b214b93..a07d4bb8cd 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java @@ -1,16 +1,14 @@ package net.osmand.plus.activities; -import android.os.Parcel; -import android.os.Parcelable; -import android.support.annotation.NonNull; +import java.io.File; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType; +import android.os.Parcel; +import android.support.annotation.NonNull; -import java.io.File; - -public class LocalIndexInfo implements Parcelable { +public class LocalIndexInfo { private LocalIndexType type; private String description = ""; @@ -166,27 +164,6 @@ public class LocalIndexInfo implements Parcelable { return type.getBasename(this); } - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(this.type == null ? -1 : this.type.ordinal()); - dest.writeString(this.description); - dest.writeString(this.name); - dest.writeByte(backupedData ? (byte) 1 : (byte) 0); - dest.writeByte(corrupted ? (byte) 1 : (byte) 0); - dest.writeByte(notSupported ? (byte) 1 : (byte) 0); - dest.writeByte(loaded ? (byte) 1 : (byte) 0); - dest.writeString(this.subfolder); - dest.writeString(this.pathToData); - dest.writeString(this.fileName); - dest.writeByte(singleFile ? (byte) 1 : (byte) 0); - dest.writeInt(this.kbSize); - dest.writeByte(expanded ? (byte) 1 : (byte) 0); - } protected LocalIndexInfo(Parcel in) { int tmpType = in.readInt(); @@ -205,13 +182,5 @@ public class LocalIndexInfo implements Parcelable { this.expanded = in.readByte() != 0; } - public static final Creator CREATOR = new Creator() { - public LocalIndexInfo createFromParcel(Parcel source) { - return new LocalIndexInfo(source); - } - - public LocalIndexInfo[] newArray(int size) { - return new LocalIndexInfo[size]; - } - }; + } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesAlarmReceiver.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesAlarmReceiver.java index faeb839be5..d54baa5bf4 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesAlarmReceiver.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesAlarmReceiver.java @@ -20,8 +20,8 @@ public class LiveUpdatesAlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String fileName = intent.getAction(); - LocalIndexInfo localIndexInfo = - intent.getParcelableExtra(LiveUpdatesHelper.LOCAL_INDEX_INFO); + String localIndexInfo = + intent.getStringExtra(LiveUpdatesHelper.LOCAL_INDEX_INFO); WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); final OsmandApplication application = (OsmandApplication) context.getApplicationContext(); diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java index 6d9d453e5c..f86b984747 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java @@ -32,7 +32,6 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; - import net.osmand.map.WorldRegion; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; @@ -120,7 +119,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppList if (!processing && InAppHelper.isSubscribedToLiveUpdates()) { final FragmentManager fragmentManager = getChildFragmentManager(); LiveUpdatesSettingsDialogFragment - .createInstance(adapter.getChild(groupPosition, childPosition)) + .createInstance(adapter.getChild(groupPosition, childPosition).getFileName()) .show(fragmentManager, "settings"); return true; } else { @@ -271,7 +270,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppList } public void add(LocalIndexInfo info) { - OsmandSettings.CommonPreference preference = preferenceLiveUpdatesOn(info, + OsmandSettings.CommonPreference preference = preferenceLiveUpdatesOn(info.getFileName(), getSettings()); if (preference.get()) { dataShouldUpdate.add(info); @@ -284,7 +283,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppList Set changedSet = new HashSet<>(); for (LocalIndexInfo localIndexInfo : dataShouldUpdate) { OsmandSettings.CommonPreference preference = - preferenceLiveUpdatesOn(localIndexInfo, getSettings()); + preferenceLiveUpdatesOn(localIndexInfo.getFileName(), getSettings()); if (!preference.get()) { changedSet.add(localIndexInfo); } @@ -294,7 +293,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppList changedSet.clear(); for (LocalIndexInfo localIndexInfo : dataShouldNotUpdate) { OsmandSettings.CommonPreference preference = - preferenceLiveUpdatesOn(localIndexInfo, getSettings()); + preferenceLiveUpdatesOn(localIndexInfo.getFileName(), getSettings()); if (preference.get()) { changedSet.add(localIndexInfo); } @@ -392,7 +391,8 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppList private void enableLiveUpdates(boolean enable) { AlarmManager alarmMgr = (AlarmManager) getActivity() .getSystemService(Context.ALARM_SERVICE); - for (LocalIndexInfo localIndexInfo : dataShouldUpdate) { + for (LocalIndexInfo li : dataShouldUpdate) { + String localIndexInfo = li.getFileName(); PendingIntent alarmIntent = getPendingIntent(getActivity(), localIndexInfo); if (enable) { @@ -490,7 +490,8 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppList } @SuppressWarnings("deprecation") - public void bindLocalIndexInfo(final LocalIndexInfo item, boolean isLastChild) { + public void bindLocalIndexInfo(final LocalIndexInfo it, boolean isLastChild) { + final String item = it.getFileName(); OsmandApplication context = fragment.getMyActivity().getMyApplication(); final OsmandSettings.CommonPreference shouldUpdatePreference = preferenceLiveUpdatesOn(item, fragment.getSettings()); @@ -523,7 +524,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppList view.setLayoutParams(layoutParams); final String fileNameWithoutExtension = - Algorithms.getFileNameWithoutExtension(new File(item.getFileName())); + Algorithms.getFileNameWithoutExtension(new File(item)); final long timestamp = changesManager.getTimestamp(fileNameWithoutExtension); final long lastCheck = preferenceLastCheck(item, fragment.getSettings()).get(); String lastCheckString = formatDateTime(fragment.getActivity(), diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesHelper.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesHelper.java index 6de28b1732..d2861427a6 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesHelper.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesHelper.java @@ -32,45 +32,45 @@ public class LiveUpdatesHelper { public static final int DEFAULT_LAST_CHECK = -1; public static OsmandSettings.CommonPreference preferenceForLocalIndex( - LocalIndexInfo item, OsmandSettings settings) { - final String settingId = item.getFileName() + LIVE_UPDATES_ON_POSTFIX; + String item, OsmandSettings settings) { + final String settingId = item + LIVE_UPDATES_ON_POSTFIX; return settings.registerBooleanPreference(settingId, false); } public static OsmandSettings.CommonPreference preferenceLiveUpdatesOn( - LocalIndexInfo item, OsmandSettings settings) { - final String settingId = item.getFileName() + LIVE_UPDATES_ON_POSTFIX; + String item, OsmandSettings settings) { + final String settingId = item + LIVE_UPDATES_ON_POSTFIX; return settings.registerBooleanPreference(settingId, false); } public static OsmandSettings.CommonPreference preferenceDownloadViaWiFi( - LocalIndexInfo item, OsmandSettings settings) { - final String settingId = item.getFileName() + DOWNLOAD_VIA_WIFI_POSTFIX; + String item, OsmandSettings settings) { + final String settingId = item + DOWNLOAD_VIA_WIFI_POSTFIX; return settings.registerBooleanPreference(settingId, false); } public static OsmandSettings.CommonPreference preferenceUpdateFrequency( - LocalIndexInfo item, OsmandSettings settings) { - final String settingId = item.getFileName() + UPDATE_TIMES_POSTFIX; + String item, OsmandSettings settings) { + final String settingId = item + UPDATE_TIMES_POSTFIX; return settings.registerIntPreference(settingId, UpdateFrequency.HOURLY.ordinal()); } public static OsmandSettings.CommonPreference preferenceTimeOfDayToUpdate( - LocalIndexInfo item, OsmandSettings settings) { - final String settingId = item.getFileName() + TIME_OF_DAY_TO_UPDATE_POSTFIX; + String item, OsmandSettings settings) { + final String settingId = item + TIME_OF_DAY_TO_UPDATE_POSTFIX; return settings.registerIntPreference(settingId, TimeOfDay.NIGHT.ordinal()); } public static OsmandSettings.CommonPreference preferenceLastCheck( - LocalIndexInfo item, OsmandSettings settings) { - final String settingId = item.getFileName() + LAST_UPDATE_ATTEMPT_ON_POSTFIX; + String item, OsmandSettings settings) { + final String settingId = item + LAST_UPDATE_ATTEMPT_ON_POSTFIX; return settings.registerLongPreference(settingId, DEFAULT_LAST_CHECK); } - public static String getNameToDisplay(LocalIndexInfo child, OsmandActionBarActivity activity) { + public static String getNameToDisplay(String child, OsmandActionBarActivity activity) { return FileNameTranslationHelper.getFileName(activity, activity.getMyApplication().getResourceManager().getOsmandRegions(), - child.getFileName()); + child); } public static String formatDateTime(Context ctx, long dateTime) { @@ -80,9 +80,9 @@ public class LiveUpdatesHelper { } public static PendingIntent getPendingIntent(@NonNull Context context, - @NonNull LocalIndexInfo localIndexInfo) { + @NonNull String localIndexInfo) { Intent intent = new Intent(context, LiveUpdatesAlarmReceiver.class); - final File file = new File(localIndexInfo.getFileName()); + final File file = new File(localIndexInfo); final String fileName = Algorithms.getFileNameWithoutExtension(file); intent.putExtra(LOCAL_INDEX_INFO, localIndexInfo); intent.setAction(fileName); @@ -159,8 +159,8 @@ public class LiveUpdatesHelper { } } - public static void runLiveUpdate(Context context, final LocalIndexInfo info, boolean forceUpdate) { - final String fnExt = Algorithms.getFileNameWithoutExtension(new File(info.getFileName())); + public static void runLiveUpdate(Context context, final String info, boolean forceUpdate) { + final String fnExt = Algorithms.getFileNameWithoutExtension(new File(info)); new PerformLiveUpdateAsyncTask(context, info, forceUpdate).execute(fnExt); } } diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesSettingsDialogFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesSettingsDialogFragment.java index 32fa16bea7..b1720730ae 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesSettingsDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesSettingsDialogFragment.java @@ -54,7 +54,7 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - final LocalIndexInfo localIndexInfo = getArguments().getParcelable(LOCAL_INDEX); + final String localIndexInfo = getArguments().getString(LOCAL_INDEX); View view = LayoutInflater.from(getActivity()) .inflate(R.layout.dialog_live_updates_item_settings, null); @@ -70,7 +70,7 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment { regionNameTextView.setText(getNameToDisplay(localIndexInfo, getMyActivity())); final String fileNameWithoutExtension = - Algorithms.getFileNameWithoutExtension(new File(localIndexInfo.getFileName())); + Algorithms.getFileNameWithoutExtension(new File(localIndexInfo)); final IncrementalChangesManager changesManager = getMyApplication().getResourceManager().getChangesManager(); final long timestamp = changesManager.getTimestamp(fileNameWithoutExtension); String lastUpdateDate = formatDateTime(getActivity(), timestamp); @@ -209,10 +209,10 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment { return (AbstractDownloadActivity) this.getActivity(); } - public static LiveUpdatesSettingsDialogFragment createInstance(LocalIndexInfo localIndexInfo) { + public static LiveUpdatesSettingsDialogFragment createInstance(String localIndexInfo) { LiveUpdatesSettingsDialogFragment fragment = new LiveUpdatesSettingsDialogFragment(); Bundle args = new Bundle(); - args.putParcelable(LOCAL_INDEX, localIndexInfo); + args.putString(LOCAL_INDEX, localIndexInfo); fragment.setArguments(args); return fragment; } @@ -221,14 +221,14 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment { @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - final LocalIndexInfo localIndexInfo = getArguments().getParcelable(LOCAL_INDEX); + final String localIndexInfo = getArguments().getString(LOCAL_INDEX); final IncrementalChangesManager changesManager = getMyApplication().getResourceManager().getChangesManager(); final String fileNameWithoutExtension = - Algorithms.getFileNameWithoutExtension(new File(localIndexInfo.getFileName())); + Algorithms.getFileNameWithoutExtension(new File(localIndexInfo)); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage(getString(R.string.clear_updates_proposition_message) - + getUpdatesSize(fileNameWithoutExtension, changesManager)) + + " " + getUpdatesSize(fileNameWithoutExtension, changesManager)) .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -244,10 +244,10 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment { return (OsmandApplication) getActivity().getApplication(); } - public static ClearUpdatesDialogFragment createInstance(LocalIndexInfo localIndexInfo) { + public static ClearUpdatesDialogFragment createInstance(String localIndexInfo) { ClearUpdatesDialogFragment fragment = new ClearUpdatesDialogFragment(); Bundle args = new Bundle(); - args.putParcelable(LOCAL_INDEX, localIndexInfo); + args.putString(LOCAL_INDEX, localIndexInfo); fragment.setArguments(args); return fragment; } diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/PerformLiveUpdateAsyncTask.java b/OsmAnd/src/net/osmand/plus/liveupdates/PerformLiveUpdateAsyncTask.java index eab8a6b078..f7264b11c6 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/PerformLiveUpdateAsyncTask.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/PerformLiveUpdateAsyncTask.java @@ -33,11 +33,11 @@ public class PerformLiveUpdateAsyncTask @NonNull private final Context context; @NonNull - private final LocalIndexInfo localIndexInfo; + private final String localIndexInfo; private final boolean forceUpdate; public PerformLiveUpdateAsyncTask(@NonNull Context context, - @NonNull LocalIndexInfo localIndexInfo, + @NonNull String localIndexInfo, boolean forceUpdate) { this.context = context; this.localIndexInfo = localIndexInfo; @@ -133,7 +133,7 @@ public class PerformLiveUpdateAsyncTask public static void tryRescheduleDownload(@NonNull Context context, @NonNull OsmandSettings settings, - @NonNull LocalIndexInfo localIndexInfo) { + @NonNull String localIndexInfo) { final OsmandSettings.CommonPreference updateFrequencyPreference = preferenceUpdateFrequency(localIndexInfo, settings); final Integer frequencyOrdinal = updateFrequencyPreference.get(); @@ -144,7 +144,7 @@ public class PerformLiveUpdateAsyncTask final Integer retriesLeft = settings.LIVE_UPDATES_RETRIES.get(); if (retriesLeft > 0) { Intent intent = new Intent(context, LiveUpdatesAlarmReceiver.class); - final File file = new File(localIndexInfo.getFileName()); + final File file = new File(localIndexInfo); final String fileName = Algorithms.getFileNameWithoutExtension(file); intent.putExtra(LiveUpdatesHelper.LOCAL_INDEX_INFO, localIndexInfo); intent.setAction(fileName);