Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
5be1babcd1
9 changed files with 196 additions and 104 deletions
|
@ -4,7 +4,8 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:background="?attr/bg_color">
|
||||
|
||||
<include layout="@layout/shadow_bottom"/>
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="72dp"
|
||||
android:background="?attr/expandable_list_item_background"
|
||||
android:background="?attr/bg_color"
|
||||
android:descendantFocusability="blocksDescendants"
|
||||
android:minHeight="@dimen/list_item_height"
|
||||
android:orientation="horizontal"
|
||||
|
|
|
@ -2141,4 +2141,9 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
|
|||
<string name="update_time">Update time</string>
|
||||
<string name="updates_size_pattern">"Updates: %s"</string>
|
||||
<string name="last_map_change">"Last map change: %s"</string>
|
||||
<string name="hourly">Hourly</string>
|
||||
<string name="daily">Daily</string>
|
||||
<string name="weekly">Weekly</string>
|
||||
<string name="morning">Morning</string>
|
||||
<string name="Night">Night</string>
|
||||
</resources>
|
|
@ -2,7 +2,6 @@ package net.osmand.plus.download;
|
|||
|
||||
import android.app.Dialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
@ -39,7 +38,7 @@ public class DownloadValidationManager {
|
|||
return downloadThread;
|
||||
}
|
||||
|
||||
public void startDownload(Context context, IndexItem... items) {
|
||||
public void startDownload(FragmentActivity context, IndexItem... items) {
|
||||
downloadFilesWithAllChecks(context, items);
|
||||
}
|
||||
|
||||
|
@ -47,7 +46,7 @@ public class DownloadValidationManager {
|
|||
return app;
|
||||
}
|
||||
|
||||
public void downloadFilesCheck_3_ValidateSpace(final Context context, final IndexItem... items) {
|
||||
public void downloadFilesCheck_3_ValidateSpace(final FragmentActivity context, final IndexItem... items) {
|
||||
long szLong = 0;
|
||||
int i = 0;
|
||||
for (IndexItem es : downloadThread.getCurrentDownloadingItems()) {
|
||||
|
@ -77,7 +76,7 @@ public class DownloadValidationManager {
|
|||
}
|
||||
}
|
||||
|
||||
private void downloadFileCheck_Final_Run(Context context, IndexItem[] items) {
|
||||
private void downloadFileCheck_Final_Run(FragmentActivity context, IndexItem[] items) {
|
||||
downloadThread.runDownloadFiles(items);
|
||||
if (context instanceof DownloadEvents) {
|
||||
((DownloadEvents) context).downloadInProgress();
|
||||
|
@ -85,16 +84,16 @@ public class DownloadValidationManager {
|
|||
}
|
||||
|
||||
|
||||
protected void downloadFilesWithAllChecks(Context context, IndexItem[] items) {
|
||||
protected void downloadFilesWithAllChecks(FragmentActivity context, IndexItem[] items) {
|
||||
downloadFilesCheck_1_FreeVersion(context, items);
|
||||
}
|
||||
|
||||
protected void downloadFilesCheck_1_FreeVersion(Context context, IndexItem[] items) {
|
||||
protected void downloadFilesCheck_1_FreeVersion(FragmentActivity context, IndexItem[] items) {
|
||||
if (Version.isFreeVersion(getMyApplication())) {
|
||||
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
|
||||
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS) {
|
||||
if (context instanceof FragmentActivity) {
|
||||
FragmentActivity activity = (FragmentActivity) context;
|
||||
FragmentActivity activity = context;
|
||||
new InstallPaidVersionDialogFragment()
|
||||
.show(activity.getSupportFragmentManager(), InstallPaidVersionDialogFragment.TAG);
|
||||
}
|
||||
|
@ -106,7 +105,7 @@ public class DownloadValidationManager {
|
|||
}
|
||||
}
|
||||
|
||||
protected void downloadFilesCheck_2_Internet(final Context context, final IndexItem[] items) {
|
||||
protected void downloadFilesCheck_2_Internet(final FragmentActivity context, final IndexItem[] items) {
|
||||
if (!getMyApplication().getSettings().isWifiConnected()) {
|
||||
if (getMyApplication().getSettings().isInternetConnectionAvailable()) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
|
@ -128,7 +127,7 @@ public class DownloadValidationManager {
|
|||
}
|
||||
|
||||
|
||||
public void makeSureUserCancelDownload(Context ctx, final IndexItem item) {
|
||||
public void makeSureUserCancelDownload(FragmentActivity ctx, final IndexItem item) {
|
||||
AlertDialog.Builder bld = new AlertDialog.Builder(ctx);
|
||||
bld.setTitle(ctx.getString(R.string.shared_string_cancel));
|
||||
bld.setMessage(R.string.confirm_interrupt_download);
|
||||
|
|
|
@ -21,7 +21,7 @@ public class LiveUpdatesAlarmReceiver extends BroadcastReceiver {
|
|||
public void onReceive(Context context, Intent intent) {
|
||||
String fileName = intent.getAction();
|
||||
LocalIndexInfo localIndexInfo =
|
||||
intent.getParcelableExtra(LiveUpdatesSettingsDialogFragment.LOCAL_INDEX_INFO);
|
||||
intent.getParcelableExtra(LiveUpdatesHelper.LOCAL_INDEX_INFO);
|
||||
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
|
||||
final OsmandApplication application = (OsmandApplication) context.getApplicationContext();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package net.osmand.plus.liveupdates;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
@ -43,9 +45,11 @@ import static net.osmand.plus.liveupdates.LiveUpdatesHelper.TimeOfDay;
|
|||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.UpdateFrequency;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.formatDateTime;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getNameToDisplay;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLiveUpdatesOn;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceTimeOfDayToUpdate;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceUpdateFrequency;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.setAlarmForPendingIntent;
|
||||
|
||||
public class LiveUpdatesFragment extends Fragment {
|
||||
public static final String TITILE = "Live Updates";
|
||||
|
@ -70,8 +74,6 @@ public class LiveUpdatesFragment extends Fragment {
|
|||
listView = (ExpandableListView) view.findViewById(android.R.id.list);
|
||||
// View header = inflater.inflate(R.layout.live_updates_header, listView, false);
|
||||
|
||||
View topShadowView = inflater.inflate(R.layout.shadow_top, listView, false);
|
||||
listView.addHeaderView(topShadowView);
|
||||
View bottomShadowView = inflater.inflate(R.layout.shadow_bottom, listView, false);
|
||||
listView.addFooterView(bottomShadowView);
|
||||
adapter = new LocalIndexesAdapter(this);
|
||||
|
@ -179,24 +181,24 @@ public class LiveUpdatesFragment extends Fragment {
|
|||
|
||||
@Override
|
||||
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
View view = convertView;
|
||||
String group = getGroup(groupPosition);
|
||||
if (v == null) {
|
||||
if (view == null) {
|
||||
LayoutInflater inflater = LayoutInflater.from(ctx);
|
||||
v = inflater.inflate(R.layout.list_group_title_with_switch, parent, false);
|
||||
view = inflater.inflate(R.layout.list_group_title_with_switch, parent, false);
|
||||
}
|
||||
TextView nameView = ((TextView) v.findViewById(R.id.section_name));
|
||||
TextView nameView = ((TextView) view.findViewById(R.id.section_name));
|
||||
nameView.setText(group);
|
||||
|
||||
v.setOnClickListener(null);
|
||||
view.setOnClickListener(null);
|
||||
|
||||
TypedValue typedValue = new TypedValue();
|
||||
Resources.Theme theme = ctx.getTheme();
|
||||
theme.resolveAttribute(R.attr.ctx_menu_info_view_bg, typedValue, true);
|
||||
v.setBackgroundColor(typedValue.data);
|
||||
view.setBackgroundColor(typedValue.data);
|
||||
|
||||
SwitchCompat liveUpdatesSwitch = (SwitchCompat) v.findViewById(R.id.liveUpdatesSwitch);
|
||||
View topShadowView = v.findViewById(R.id.bottomShadowView);
|
||||
SwitchCompat liveUpdatesSwitch = (SwitchCompat) view.findViewById(R.id.liveUpdatesSwitch);
|
||||
View topShadowView = view.findViewById(R.id.bottomShadowView);
|
||||
if (groupPosition == SHOULD_UPDATE_GROUP_POSITION) {
|
||||
topShadowView.setVisibility(View.GONE);
|
||||
liveUpdatesSwitch.setVisibility(View.VISIBLE);
|
||||
|
@ -207,15 +209,30 @@ public class LiveUpdatesFragment extends Fragment {
|
|||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
settings.IS_LIVE_UPDATES_ON.set(isChecked);
|
||||
int liveUpdatesStateId = isChecked ? R.string.shared_string_on
|
||||
: R.string.shared_string_off;
|
||||
AlarmManager alarmMgr = (AlarmManager) getActivity()
|
||||
.getSystemService(Context.ALARM_SERVICE);
|
||||
for (LocalIndexInfo localIndexInfo : dataShouldUpdate) {
|
||||
PendingIntent alarmIntent = getPendingIntent(getActivity(),
|
||||
localIndexInfo);
|
||||
if(isChecked) {
|
||||
final OsmandSettings.CommonPreference<Integer> updateFrequencyPreference =
|
||||
preferenceUpdateFrequency(localIndexInfo, getSettings());
|
||||
final OsmandSettings.CommonPreference<Integer> timeOfDayPreference =
|
||||
preferenceTimeOfDayToUpdate(localIndexInfo, getSettings());
|
||||
UpdateFrequency updateFrequency = UpdateFrequency.values()[updateFrequencyPreference.get()];
|
||||
TimeOfDay timeOfDayToUpdate = TimeOfDay.values()[timeOfDayPreference.get()];
|
||||
setAlarmForPendingIntent(alarmIntent, alarmMgr, updateFrequency, timeOfDayToUpdate);
|
||||
} else {
|
||||
alarmMgr.cancel(alarmIntent);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
topShadowView.setVisibility(View.VISIBLE);
|
||||
liveUpdatesSwitch.setVisibility(View.GONE);
|
||||
}
|
||||
return v;
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -312,9 +329,9 @@ public class LiveUpdatesFragment extends Fragment {
|
|||
final UpdateFrequency frequency = UpdateFrequency.values()[frequencyId];
|
||||
final TimeOfDay timeOfDay = TimeOfDay.values()[timeOfDateToUpdateId];
|
||||
subheaderTextView.setVisibility(View.VISIBLE);
|
||||
String subheaderText = frequency.toString();
|
||||
String subheaderText = fragment.getString(frequency.getLocalizedId());
|
||||
if (frequency != UpdateFrequency.HOURLY) {
|
||||
subheaderText += " • " + timeOfDay.toString();
|
||||
subheaderText += " • " + fragment.getString(timeOfDay.getLocalizedId());
|
||||
}
|
||||
subheaderTextView.setText(subheaderText);
|
||||
subheaderTextView.setTextColor(fragment.getActivity().getResources()
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
package net.osmand.plus.liveupdates;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.LocalIndexInfo;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class LiveUpdatesHelper {
|
||||
private static final String UPDATE_TIMES_POSTFIX = "_update_times";
|
||||
|
@ -13,6 +21,13 @@ public class LiveUpdatesHelper {
|
|||
private static final String DOWNLOAD_VIA_WIFI_POSTFIX = "_download_via_wifi";
|
||||
private static final String LIVE_UPDATES_ON_POSTFIX = "_live_updates_on";
|
||||
private static final String LAST_UPDATE_ATTEMPT_ON_POSTFIX = "_last_update_attempt";
|
||||
public static final String LOCAL_INDEX_INFO = "local_index_info";
|
||||
|
||||
|
||||
private static final int MORNING_UPDATE_TIME = 8;
|
||||
private static final int NIGHT_UPDATE_TIME = 21;
|
||||
private static final int SHIFT = 1000;
|
||||
|
||||
public static final int DEFAULT_LAST_CHECK = -1;
|
||||
|
||||
public static OsmandSettings.CommonPreference<Boolean> preferenceForLocalIndex(
|
||||
|
@ -64,14 +79,83 @@ public class LiveUpdatesHelper {
|
|||
return dateFormat.format(dateTime) + " " + timeFormat.format(dateTime);
|
||||
}
|
||||
|
||||
public static enum TimeOfDay {
|
||||
MORNING,
|
||||
NIGHT
|
||||
public static PendingIntent getPendingIntent(Context context, LocalIndexInfo localIndexInfo) {
|
||||
Intent intent = new Intent(context, LiveUpdatesAlarmReceiver.class);
|
||||
final File file = new File(localIndexInfo.getFileName());
|
||||
final String fileName = Algorithms.getFileNameWithoutExtension(file);
|
||||
intent.putExtra(LOCAL_INDEX_INFO, localIndexInfo);
|
||||
intent.setAction(fileName);
|
||||
return PendingIntent.getBroadcast(context, 0, intent, 0);
|
||||
}
|
||||
|
||||
public enum UpdateFrequency {
|
||||
HOURLY,
|
||||
DAILY,
|
||||
WEEKLY
|
||||
public static void setAlarmForPendingIntent(PendingIntent alarmIntent, AlarmManager alarmMgr, UpdateFrequency updateFrequency, TimeOfDay timeOfDayToUpdate) {
|
||||
long timeOfFirstUpdate;
|
||||
long updateInterval;
|
||||
switch (updateFrequency) {
|
||||
case HOURLY:
|
||||
timeOfFirstUpdate = System.currentTimeMillis() + SHIFT;
|
||||
updateInterval = AlarmManager.INTERVAL_HOUR;
|
||||
break;
|
||||
case DAILY:
|
||||
timeOfFirstUpdate = getNextUpdateTime(timeOfDayToUpdate);
|
||||
updateInterval = AlarmManager.INTERVAL_DAY;
|
||||
break;
|
||||
case WEEKLY:
|
||||
timeOfFirstUpdate = getNextUpdateTime(timeOfDayToUpdate);
|
||||
updateInterval = AlarmManager.INTERVAL_DAY * 7;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected update frequency:"
|
||||
+ updateFrequency);
|
||||
}
|
||||
alarmMgr.setInexactRepeating(AlarmManager.RTC,
|
||||
timeOfFirstUpdate, updateInterval, alarmIntent);
|
||||
}
|
||||
|
||||
private static long getNextUpdateTime(TimeOfDay timeOfDayToUpdate) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
if (timeOfDayToUpdate == TimeOfDay.MORNING) {
|
||||
calendar.add(Calendar.DATE, 1);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, MORNING_UPDATE_TIME);
|
||||
} else if (timeOfDayToUpdate == TimeOfDay.NIGHT) {
|
||||
calendar.add(Calendar.DATE, 1);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, NIGHT_UPDATE_TIME);
|
||||
}
|
||||
return calendar.getTimeInMillis();
|
||||
}
|
||||
|
||||
public static enum TimeOfDay {
|
||||
MORNING(R.string.morning),
|
||||
NIGHT(R.string.Night);
|
||||
private final int localizedId;
|
||||
|
||||
TimeOfDay(int localizedId) {
|
||||
this.localizedId = localizedId;
|
||||
}
|
||||
|
||||
public int getLocalizedId() {
|
||||
return localizedId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static enum UpdateFrequency {
|
||||
HOURLY(R.string.hourly),
|
||||
DAILY(R.string.daily),
|
||||
WEEKLY(R.string.weekly);
|
||||
private final int localizedId;
|
||||
|
||||
UpdateFrequency(int localizedId) {
|
||||
this.localizedId = localizedId;
|
||||
}
|
||||
|
||||
public int getLocalizedId() {
|
||||
return localizedId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.app.Dialog;
|
|||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
|
@ -32,26 +31,21 @@ import net.osmand.util.Algorithms;
|
|||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Calendar;
|
||||
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.TimeOfDay;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.UpdateFrequency;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.formatDateTime;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getNameToDisplay;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceDownloadViaWiFi;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceForLocalIndex;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceTimeOfDayToUpdate;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceUpdateFrequency;
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.setAlarmForPendingIntent;
|
||||
|
||||
public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
|
||||
private static final Log LOG = PlatformUtil.getLog(LiveUpdatesAlarmReceiver.class);
|
||||
private static final String LOCAL_INDEX = "local_index";
|
||||
public static final String LOCAL_INDEX_INFO = "local_index_info";
|
||||
|
||||
|
||||
private static final int MORNING_UPDATE_TIME = 8;
|
||||
private static final int NIGHT_UPDATE_TIME = 21;
|
||||
private static final int SHIFT = 1000;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
|
@ -86,7 +80,7 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
|
|||
preferenceForLocalIndex(localIndexInfo, getSettings());
|
||||
final OsmandSettings.CommonPreference<Boolean> downloadViaWiFiPreference =
|
||||
preferenceDownloadViaWiFi(localIndexInfo, getSettings());
|
||||
final OsmandSettings.CommonPreference<Integer> updateFrequencePreference =
|
||||
final OsmandSettings.CommonPreference<Integer> updateFrequencyPreference =
|
||||
preferenceUpdateFrequency(localIndexInfo, getSettings());
|
||||
final OsmandSettings.CommonPreference<Integer> timeOfDayPreference =
|
||||
preferenceTimeOfDayToUpdate(localIndexInfo, getSettings());
|
||||
|
@ -95,7 +89,7 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
|
|||
|
||||
updateSize(fileNameWithoutExtension, changesManager, sizeTextView);
|
||||
|
||||
updateFrequencySpinner.setSelection(updateFrequencePreference.get());
|
||||
updateFrequencySpinner.setSelection(updateFrequencyPreference.get());
|
||||
updateFrequencySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
@ -131,48 +125,25 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
|
|||
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
liveUpdatePreference.set(liveUpdatesSwitch.isChecked());
|
||||
downloadViaWiFiPreference.set(downloadOverWiFiCheckBox.isChecked());
|
||||
|
||||
final int updateFrequencyInt = updateFrequencySpinner.getSelectedItemPosition();
|
||||
updateFrequencePreference.set(updateFrequencyInt);
|
||||
UpdateFrequency updateFrequency = UpdateFrequency.values()[updateFrequencyInt];
|
||||
updateFrequencyPreference.set(updateFrequencyInt);
|
||||
|
||||
AlarmManager alarmMgr = (AlarmManager) getActivity()
|
||||
.getSystemService(Context.ALARM_SERVICE);
|
||||
Intent intent = new Intent(getActivity(), LiveUpdatesAlarmReceiver.class);
|
||||
final File file = new File(localIndexInfo.getFileName());
|
||||
final String fileName = Algorithms.getFileNameWithoutExtension(file);
|
||||
intent.putExtra(LOCAL_INDEX_INFO, localIndexInfo);
|
||||
intent.setAction(fileName);
|
||||
PendingIntent alarmIntent = PendingIntent.getBroadcast(getActivity(), 0, intent, 0);
|
||||
PendingIntent alarmIntent = getPendingIntent(getActivity(), localIndexInfo);
|
||||
|
||||
final int timeOfDayInt = updateTimesOfDaySpinner.getSelectedItemPosition();
|
||||
timeOfDayPreference.set(timeOfDayInt);
|
||||
TimeOfDay timeOfDayToUpdate = TimeOfDay.values()[timeOfDayInt];
|
||||
long timeOfFirstUpdate;
|
||||
long updateInterval;
|
||||
switch (updateFrequency) {
|
||||
case HOURLY:
|
||||
timeOfFirstUpdate = System.currentTimeMillis() + SHIFT;
|
||||
updateInterval = AlarmManager.INTERVAL_HOUR;
|
||||
break;
|
||||
case DAILY:
|
||||
timeOfFirstUpdate = getNextUpdateTime(timeOfDayToUpdate);
|
||||
updateInterval = AlarmManager.INTERVAL_DAY;
|
||||
break;
|
||||
case WEEKLY:
|
||||
timeOfFirstUpdate = getNextUpdateTime(timeOfDayToUpdate);
|
||||
updateInterval = AlarmManager.INTERVAL_DAY * 7;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected update frequency:"
|
||||
+ updateFrequency);
|
||||
}
|
||||
|
||||
liveUpdatePreference.set(liveUpdatesSwitch.isChecked());
|
||||
downloadViaWiFiPreference.set(downloadOverWiFiCheckBox.isChecked());
|
||||
alarmMgr.cancel(alarmIntent);
|
||||
if (liveUpdatesSwitch.isChecked()) {
|
||||
alarmMgr.setInexactRepeating(AlarmManager.RTC,
|
||||
timeOfFirstUpdate, updateInterval, alarmIntent);
|
||||
if (liveUpdatesSwitch.isChecked() && getSettings().IS_LIVE_UPDATES_ON.get()) {
|
||||
UpdateFrequency updateFrequency = UpdateFrequency.values()[updateFrequencyInt];
|
||||
TimeOfDay timeOfDayToUpdate = TimeOfDay.values()[timeOfDayInt];
|
||||
setAlarmForPendingIntent(alarmIntent, alarmMgr, updateFrequency, timeOfDayToUpdate);
|
||||
} else {
|
||||
alarmMgr.cancel(alarmIntent);
|
||||
}
|
||||
getLiveUpdatesFragment().notifyLiveUpdatesChanged();
|
||||
}
|
||||
|
@ -207,18 +178,6 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
|
|||
sizeTextView.setText(getString(R.string.updates_size_pattern, size));
|
||||
}
|
||||
|
||||
private long getNextUpdateTime(TimeOfDay timeOfDayToUpdate) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
if (timeOfDayToUpdate == TimeOfDay.MORNING) {
|
||||
calendar.add(Calendar.DATE, 1);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, MORNING_UPDATE_TIME);
|
||||
} else if (timeOfDayToUpdate == TimeOfDay.NIGHT) {
|
||||
calendar.add(Calendar.DATE, 1);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, NIGHT_UPDATE_TIME);
|
||||
}
|
||||
return calendar.getTimeInMillis();
|
||||
}
|
||||
|
||||
private LiveUpdatesFragment getLiveUpdatesFragment() {
|
||||
return (LiveUpdatesFragment) getParentFragment();
|
||||
}
|
||||
|
|
|
@ -14,12 +14,12 @@ import net.osmand.plus.activities.LocalIndexInfo;
|
|||
import net.osmand.plus.download.AbstractDownloadActivity;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.DownloadIndexesThread;
|
||||
import net.osmand.plus.download.DownloadValidationManager;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.resources.IncrementalChangesManager;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceUpdateFrequency;
|
||||
|
@ -41,15 +41,19 @@ public class PerformLiveUpdateAsyncTask
|
|||
activity.setSupportProgressBarIndeterminateVisibility(true);
|
||||
OsmandSettings settings = activity.getMyApplication().getSettings();
|
||||
}
|
||||
final OsmandApplication myApplication = (OsmandApplication) context.getApplicationContext();
|
||||
final OsmandApplication myApplication = getMyApplication();
|
||||
OsmandSettings.CommonPreference<Long> lastCheckPreference =
|
||||
LiveUpdatesHelper.preferenceLastCheck(localIndexInfo, myApplication.getSettings());
|
||||
lastCheckPreference.set(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) context.getApplicationContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IncrementalChangesManager.IncrementalUpdateList doInBackground(String... params) {
|
||||
final OsmandApplication myApplication = (OsmandApplication) context.getApplicationContext();
|
||||
final OsmandApplication myApplication = getMyApplication();
|
||||
IncrementalChangesManager cm = myApplication.getResourceManager().getChangesManager();
|
||||
return cm.getUpdatesByMonth(params[0]);
|
||||
}
|
||||
|
@ -60,7 +64,7 @@ public class PerformLiveUpdateAsyncTask
|
|||
AbstractDownloadActivity activity = (AbstractDownloadActivity) context;
|
||||
activity.setSupportProgressBarIndeterminateVisibility(false);
|
||||
}
|
||||
final OsmandApplication application = (OsmandApplication) context.getApplicationContext();
|
||||
final OsmandApplication application = getMyApplication();
|
||||
final OsmandSettings settings = application.getSettings();
|
||||
if (result.errorMessage != null) {
|
||||
Toast.makeText(context, result.errorMessage, Toast.LENGTH_SHORT).show();
|
||||
|
@ -71,21 +75,44 @@ public class PerformLiveUpdateAsyncTask
|
|||
if (ll.isEmpty()) {
|
||||
Toast.makeText(context, R.string.no_updates_available, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
int i = 0;
|
||||
IndexItem[] is = new IndexItem[ll.size()];
|
||||
ArrayList<IndexItem> itemsToDownload = new ArrayList<>(ll.size());
|
||||
for (IncrementalChangesManager.IncrementalUpdate iu : ll) {
|
||||
IndexItem ii = new IndexItem(iu.fileName, "Incremental update",
|
||||
IndexItem indexItem = new IndexItem(iu.fileName, "Incremental update",
|
||||
iu.timestamp, iu.sizeText, iu.contentSize,
|
||||
iu.containerSize, DownloadActivityType.LIVE_UPDATES_FILE);
|
||||
is[i++] = ii;
|
||||
itemsToDownload.add(indexItem);
|
||||
}
|
||||
DownloadValidationManager downloadValidationManager =
|
||||
new DownloadValidationManager(application);
|
||||
DownloadIndexesThread downloadThread = application.getDownloadThread();
|
||||
if (context instanceof DownloadIndexesThread.DownloadEvents) {
|
||||
downloadValidationManager.getDownloadThread()
|
||||
.setUiActivity((DownloadIndexesThread.DownloadEvents) context);
|
||||
downloadThread.setUiActivity((DownloadIndexesThread.DownloadEvents) context);
|
||||
}
|
||||
boolean downloadViaWiFi =
|
||||
LiveUpdatesHelper.preferenceDownloadViaWiFi(localIndexInfo, settings).get();
|
||||
if (getMyApplication().getSettings().isInternetConnectionAvailable()) {
|
||||
if (settings.isWifiConnected() || downloadViaWiFi) {
|
||||
long szLong = 0;
|
||||
int i = 0;
|
||||
for (IndexItem es : downloadThread.getCurrentDownloadingItems()) {
|
||||
szLong += es.getContentSize();
|
||||
i++;
|
||||
}
|
||||
for (IndexItem es : itemsToDownload) {
|
||||
szLong += es.getContentSize();
|
||||
i++;
|
||||
}
|
||||
double sz = ((double) szLong) / (1 << 20);
|
||||
// get availabile space
|
||||
double asz = downloadThread.getAvailableSpace();
|
||||
if (asz == -1 || asz <= 0 || sz / asz <= 0.4) {
|
||||
IndexItem[] itemsArray = new IndexItem[itemsToDownload.size()];
|
||||
itemsArray = itemsToDownload.toArray(itemsArray);
|
||||
downloadThread.runDownloadFiles(itemsArray);
|
||||
if (context instanceof DownloadIndexesThread.DownloadEvents) {
|
||||
((DownloadIndexesThread.DownloadEvents) context).downloadInProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
downloadValidationManager.startDownload(context, is);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +131,7 @@ public class PerformLiveUpdateAsyncTask
|
|||
Intent intent = new Intent(context, LiveUpdatesAlarmReceiver.class);
|
||||
final File file = new File(localIndexInfo.getFileName());
|
||||
final String fileName = Algorithms.getFileNameWithoutExtension(file);
|
||||
intent.putExtra(LiveUpdatesSettingsDialogFragment.LOCAL_INDEX_INFO, localIndexInfo);
|
||||
intent.putExtra(LiveUpdatesHelper.LOCAL_INDEX_INFO, localIndexInfo);
|
||||
intent.setAction(fileName);
|
||||
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
|
||||
|
||||
|
|
Loading…
Reference in a new issue