Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-03-02 10:35:13 +01:00
commit 339c248f81
7 changed files with 49 additions and 78 deletions

View file

@ -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;
}

View file

@ -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<LocalIndexInfo> CREATOR = new Creator<LocalIndexInfo>() {
public LocalIndexInfo createFromParcel(Parcel source) {
return new LocalIndexInfo(source);
}
public LocalIndexInfo[] newArray(int size) {
return new LocalIndexInfo[size];
}
};
}

View file

@ -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();

View file

@ -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<Boolean> preference = preferenceLiveUpdatesOn(info,
OsmandSettings.CommonPreference<Boolean> preference = preferenceLiveUpdatesOn(info.getFileName(),
getSettings());
if (preference.get()) {
dataShouldUpdate.add(info);
@ -284,7 +283,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppList
Set<LocalIndexInfo> changedSet = new HashSet<>();
for (LocalIndexInfo localIndexInfo : dataShouldUpdate) {
OsmandSettings.CommonPreference<Boolean> 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<Boolean> 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<Boolean> 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(),

View file

@ -32,45 +32,45 @@ public class LiveUpdatesHelper {
public static final int DEFAULT_LAST_CHECK = -1;
public static OsmandSettings.CommonPreference<Boolean> 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<Boolean> 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<Boolean> 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<Integer> 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<Integer> 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<Long> 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);
}
}

View file

@ -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;
}

View file

@ -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<Integer> 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);