Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-12-22 17:31:32 +01:00
commit afc82fc73c
13 changed files with 318 additions and 146 deletions

View file

@ -16,6 +16,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />

View file

@ -3,48 +3,71 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:theme="@style/OsmandLightTheme">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="125dp"
android:background="@color/dashboard_blue"
android:orientation="vertical"
android:padding="16dp">
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:paddingTop="24dp">
<TextView
android:id="@+id/regionNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/color_white"
tools:text="Flevoland"/>
<TextView
android:id="@+id/countryNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:visibility="visible"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/white_80_transparent"
android:textSize="12sp"
android:visibility="gone"
tools:text="The Netherlands"/>
tools:text="The Netherlands"
tools:visibility="visible"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/color_white"/>
android:background="@color/white_50_transparent"/>
<TextView
android:id="@+id/lastUpdateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update: 4 Dec 2015, 14:41"/>
android:layout_height="40dp"
android:layout_gravity="bottom"
android:gravity="center"
android:textColor="@color/color_white"
android:textSize="12sp"
tools:text="Update: 4 Dec 2015, 14:41"/>
</LinearLayout>
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:columnCount='2'
android:padding="24dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="54dp"
android:layout_column="0"
android:layout_row="1"
android:gravity="center"
android:text="@string/live_update"/>
<android.support.v7.widget.SwitchCompat
@ -53,40 +76,79 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="54dp"
android:layout_column="0"
android:layout_row="2"
android:gravity="center"
android:text="@string/only_download_over_wifi"/>
<android.support.v7.widget.SwitchCompat
<CheckBox
android:id="@+id/downloadOverWiFiSwitch"
android:layout_gravity="right"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="54dp"
android:layout_column="0"
android:layout_row="3"
android:gravity="center"
android:text="@string/update_every"/>
<Spinner
android:id="@+id/updateFrequencySpinner"
style="@style/OsmandLightTheme.Spinner"
android:layout_width="wrap_content"
android:layout_height="54dp"
android:layout_column="1"
android:layout_gravity="right"
android:entries="@array/update_frequencies_array"/>
android:entries="@array/update_frequencies_array"
android:gravity="left"
android:paddingLeft="0dp"/>
<TextView
android:id="@+id/updateTimesOfDayLabel"
android:layout_width="wrap_content"
android:layout_height="54dp"
android:layout_column="0"
android:layout_row="4"
android:gravity="center"
android:text="@string/update_time"/>
<Spinner
android:id="@+id/updateTimesOfDaySpinner"
style="@style/OsmandLightTheme.Spinner"
android:layout_width="wrap_content"
android:layout_height="54dp"
android:layout_column="1"
android:layout_gravity="right"
android:layout_row="4"
android:entries="@array/update_times_of_day"
android:visibility="gone"/>
android:gravity="left"
android:paddingLeft="0dp"/>
<TextView
android:id="@+id/sizeTextView"
android:layout_width="wrap_content"
android:layout_height="54dp"
android:layout_column="0"
android:layout_row="5"
android:gravity="center"
tools:text="Updates: 65NB"/>
<Button
android:id="@+id/removeUpdatesButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_column="1"
android:layout_gravity="right"
android:layout_row="5"
android:gravity="right|center_vertical"
android:text="@string/shared_string_clear"/>
</GridLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/color_white"/>
android:background="?attr/divider_color"/>
</LinearLayout>

View file

@ -4,24 +4,40 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="64dp"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:background="?attr/expandable_list_item_background">
android:orientation="vertical">
<TextView
android:id="@+id/section_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:text="Live updates"/>
<include layout="@layout/shadow_bottom"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/liveUpdatesSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:visibility="visible"
android:visibility="gone"/>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<include layout="@layout/shadow_top"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<TextView
android:id="@+id/section_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:text="Live updates"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/liveUpdatesSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"/>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<View
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/bottomShadowView"
android:layout_width="match_parent"
android:layout_height="6dp"
android:background="@drawable/bg_shadow_list_bottom"
tools:showIn="@layout/list_group_title_with_switch"/>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<View
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@drawable/bg_shadow_list_top"
tools:showIn="@layout/list_group_title_with_switch"/>

View file

@ -185,4 +185,8 @@
<color name="region_updateable">#55FF8F00</color>
<color name="region_selected">#55FFFF00</color>
<color name="region_downloading">#44FF61FF</color>
<!-- Dialog Live Updates Settings -->
<color name="white_50_transparent">#8FFF</color>
<color name="white_80_transparent">#CFFF</color>
</resources>

View file

@ -2131,4 +2131,6 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="update_now">Update now</string>
<string name="missing_write_external_storage_permission">App have no permission to use SD card</string>
<string name="last_update">Last update: %s</string>
<string name="update_date_pattern">"Update: %s"</string>
<string name="update_time">Update time</string>
</resources>

View file

@ -146,6 +146,13 @@
<item name="colorAccent">@color/osmand_orange</item>
</style>
<style name="OsmandLightTheme.Spinner" parent="Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="android:background">?android:selectableItemBackground</item>
<item name="android:dropDownSelector">?android:selectableItemBackground</item>
<item name="android:divider">@null</item>
<item name="overlapAnchor">true</item>
</style>
<style name="OsmandDarkTheme.DarkActionbar">
<item name="colorAccent">@color/color_white</item>
</style>

View file

@ -18,7 +18,6 @@ import android.widget.ExpandableListView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -28,10 +27,7 @@ import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.download.AbstractDownloadActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.resources.IncrementalChangesManager;
import net.osmand.util.Algorithms;
@ -44,6 +40,8 @@ import java.util.List;
import java.util.Set;
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.preferenceLiveUpdatesOn;
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceUpdateFrequency;
@ -72,6 +70,10 @@ public class LiveUpdatesFragment extends Fragment {
adapter = new LocalIndexesAdapter(this);
listView.setAdapter(adapter);
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);
new LoadLocalIndexTask(adapter, this).execute();
return view;
}
@ -192,7 +194,9 @@ public class LiveUpdatesFragment extends Fragment {
v.setBackgroundColor(typedValue.data);
SwitchCompat liveUpdatesSwitch = (SwitchCompat) v.findViewById(R.id.liveUpdatesSwitch);
View topShadowView = v.findViewById(R.id.bottomShadowView);
if (groupPosition == SHOULD_UPDATE_GROUP_POSITION) {
topShadowView.setVisibility(View.GONE);
liveUpdatesSwitch.setVisibility(View.VISIBLE);
OsmandApplication application = (OsmandApplication) ctx.getApplicationContext();
final OsmandSettings settings = application.getSettings();
@ -206,6 +210,7 @@ public class LiveUpdatesFragment extends Fragment {
}
});
} else {
topShadowView.setVisibility(View.VISIBLE);
liveUpdatesSwitch.setVisibility(View.GONE);
}
return v;
@ -256,32 +261,12 @@ public class LiveUpdatesFragment extends Fragment {
}
private static OsmandSettings.CommonPreference<Boolean> preferenceForLocalIndex(
String idPostfix,
LocalIndexInfo item,
LiveUpdatesFragment fragment) {
final OsmandApplication myApplication = fragment.getMyActivity().getMyApplication();
final OsmandSettings settings = myApplication.getSettings();
final String settingId = item.getFileName() + idPostfix;
return settings.registerBooleanPreference(settingId, false);
}
private void expandAllGroups() {
for (int i = 0; i < adapter.getGroupCount(); i++) {
listView.expandGroup(i);
}
}
void runLiveUpdate(final LocalIndexInfo info) {
final String fnExt = Algorithms.getFileNameWithoutExtension(new File(info.getFileName()));
new PerformLiveUpdateAsyncTask(getMyActivity()).execute(new String[]{fnExt});
adapter.notifyLiveUpdatesChanged();
}
LocalIndexInfo getLocalIndexInfo(int groupPosition, int childPosition) {
return adapter.getChild(groupPosition, childPosition);
}
private static class LocalFullMapsViewHolder {
private final ImageView icon;
private final TextView nameTextView;
@ -315,7 +300,7 @@ public class LiveUpdatesFragment extends Fragment {
final String fileNameWithoutExtension =
Algorithms.getFileNameWithoutExtension(new File(item.getFileName()));
nameTextView.setText(getNameToDisplay(item));
nameTextView.setText(getNameToDisplay(item, fragment.getMyActivity()));
if (shouldUpdatePreference.get()) {
final Integer frequencyId = preferenceUpdateFrequency(item, fragment.getSettings()).get();
final UpdateFrequency frequency = UpdateFrequency.values()[frequencyId];
@ -340,7 +325,7 @@ public class LiveUpdatesFragment extends Fragment {
}
final long timestamp = changesManager.getTimestamp(fileNameWithoutExtension);
String formattedDate = LiveUpdatesFragment.formatDateTime(fragment.getActivity(), timestamp);
String formattedDate = formatDateTime(fragment.getActivity(), timestamp);
descriptionTextView.setText(context.getString(R.string.last_update, formattedDate));
final View.OnClickListener clickListener = new View.OnClickListener() {
@ -358,13 +343,6 @@ public class LiveUpdatesFragment extends Fragment {
return fragment.getMyActivity().getMyApplication().getIconsCache()
.getPaintedContentIcon(drawable, secondaryColor);
}
private String getNameToDisplay(LocalIndexInfo child) {
String mapName = FileNameTranslationHelper.getFileName(fragment.getActivity(),
fragment.getMyActivity().getMyApplication().getResourceManager().getOsmandRegions(),
child.getFileName());
return mapName;
}
}
public static class LoadLocalIndexTask
@ -410,52 +388,4 @@ public class LiveUpdatesFragment extends Fragment {
adapter.sort();
}
}
public static class PerformLiveUpdateAsyncTask
extends AsyncTask<String, Object, IncrementalChangesManager.IncrementalUpdateList> {
private final AbstractDownloadActivity activity;
public PerformLiveUpdateAsyncTask(AbstractDownloadActivity activity) {
this.activity = activity;
}
protected void onPreExecute() {
activity.setSupportProgressBarIndeterminateVisibility(true);
}
@Override
protected IncrementalChangesManager.IncrementalUpdateList doInBackground(String... params) {
final OsmandApplication myApplication = activity.getMyApplication();
IncrementalChangesManager cm = myApplication.getResourceManager().getChangesManager();
return cm.getUpdatesByMonth(params[0]);
}
protected void onPostExecute(IncrementalChangesManager.IncrementalUpdateList result) {
activity.setSupportProgressBarIndeterminateVisibility(false);
if (result.errorMessage != null) {
Toast.makeText(activity, result.errorMessage, Toast.LENGTH_SHORT).show();
} else {
List<IncrementalChangesManager.IncrementalUpdate> ll = result.getItemsForUpdate();
if (ll.isEmpty()) {
Toast.makeText(activity, R.string.no_updates_available, Toast.LENGTH_SHORT).show();
} else {
int i = 0;
IndexItem[] is = new IndexItem[ll.size()];
for (IncrementalChangesManager.IncrementalUpdate iu : ll) {
IndexItem ii = new IndexItem(iu.fileName, "Incremental update", iu.timestamp, iu.sizeText,
iu.contentSize, iu.containerSize, DownloadActivityType.LIVE_UPDATES_FILE);
is[i++] = ii;
}
activity.startDownload(is);
}
}
}
}
private static String formatDateTime(Context ctx, long dateTime) {
java.text.DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(ctx);
java.text.DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(ctx);
return dateFormat.format(dateTime) + " " + timeFormat.format(dateTime);
}
}

View file

@ -1,11 +1,12 @@
package net.osmand.plus.liveupdates;
import android.content.Context;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.helpers.FileNameTranslationHelper;
/**
* Created by GaidamakUA on 12/18/15.
*/
public class LiveUpdatesHelper {
private static final String UPDATE_TIMES_POSTFIX = "_update_times";
private static final String TIME_OF_DAY_TO_UPDATE_POSTFIX = "_time_of_day_to_update";
@ -43,6 +44,19 @@ public class LiveUpdatesHelper {
return settings.registerIntPreference(settingId, TimesOfDay.NIGHT.ordinal());
}
public static String getNameToDisplay(LocalIndexInfo child, OsmandActionBarActivity activity) {
String mapName = FileNameTranslationHelper.getFileName(activity,
activity.getMyApplication().getResourceManager().getOsmandRegions(),
child.getFileName());
return mapName;
}
public static String formatDateTime(Context ctx, long dateTime) {
java.text.DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(ctx);
java.text.DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(ctx);
return dateFormat.format(dateTime) + " " + timeFormat.format(dateTime);
}
public static enum TimesOfDay {
MORNING,
NIGHT

View file

@ -14,6 +14,8 @@ import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Spinner;
import android.widget.TextView;
@ -21,7 +23,9 @@ import net.osmand.plus.OsmandApplication;
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.download.AbstractDownloadActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.resources.IncrementalChangesManager;
import net.osmand.util.Algorithms;
import java.io.File;
@ -29,6 +33,8 @@ import java.util.Calendar;
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.TimesOfDay;
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.preferenceDownloadViaWiFi;
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceForLocalIndex;
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceTimeOfDayToUpdate;
@ -53,14 +59,22 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
.inflate(R.layout.dialog_live_updates_item_settings, null);
final TextView regionNameTextView = (TextView) view.findViewById(R.id.regionNameTextView);
final TextView countryNameTextView = (TextView) view.findViewById(R.id.countryNameTextView);
final TextView lastUpdateTextView = (TextView) view.findViewById(R.id.lastUpdateTextView);
final SwitchCompat liveUpdatesSwitch = (SwitchCompat) view.findViewById(R.id.liveUpdatesSwitch);
final SwitchCompat downloadOverWiFiSwitch = (SwitchCompat) view.findViewById(R.id.downloadOverWiFiSwitch);
final CheckBox downloadOverWiFiSwitch = (CheckBox) view.findViewById(R.id.downloadOverWiFiSwitch);
final Spinner updateFrequencySpinner = (Spinner) view.findViewById(R.id.updateFrequencySpinner);
final Spinner updateTimesOfDaySpinner = (Spinner) view.findViewById(R.id.updateTimesOfDaySpinner);
final TextView updateTimesOfDayTextView = (TextView) view.findViewById(R.id.updateTimesOfDayLabel);
final TextView sizeTextView = (TextView) view.findViewById(R.id.sizeTextView);
final Button removeUpdatesButton = (Button) view.findViewById(R.id.removeUpdatesButton);
regionNameTextView.setText(localIndexInfo.getName());
// countryNameTextView.setText(localIndexInfo.getWorldRegion().getLocaleName());
countryNameTextView.setVisibility(View.VISIBLE);
regionNameTextView.setText(getNameToDisplay(localIndexInfo, getMyActivity()));
final String fileNameWithoutExtension =
Algorithms.getFileNameWithoutExtension(new File(localIndexInfo.getFileName()));
final IncrementalChangesManager changesManager = getMyApplication().getResourceManager().getChangesManager();
final long timestamp = changesManager.getTimestamp(fileNameWithoutExtension);
String formattedDate = formatDateTime(getActivity(), timestamp);
lastUpdateTextView.setText(getString(R.string.update_date_pattern, formattedDate));
final OsmandSettings.CommonPreference<Boolean> liveUpdatePreference =
preferenceForLocalIndex(localIndexInfo, getSettings());
final OsmandSettings.CommonPreference<Boolean> downloadViaWiFiPreference =
@ -72,6 +86,40 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
liveUpdatesSwitch.setChecked(true);
downloadOverWiFiSwitch.setChecked(downloadViaWiFiPreference.get());
updateSize(fileNameWithoutExtension, changesManager, sizeTextView);
updateFrequencySpinner.setSelection(updateFrequencePreference.get());
updateFrequencySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
UpdateFrequency updateFrequency = UpdateFrequency.values()[position];
switch (updateFrequency) {
case HOURLY:
updateTimesOfDaySpinner.setVisibility(View.GONE);
updateTimesOfDayTextView.setVisibility(View.GONE);
break;
case DAILY:
case WEEKLY:
updateTimesOfDaySpinner.setVisibility(View.VISIBLE);
updateTimesOfDayTextView.setVisibility(View.VISIBLE);
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
removeUpdatesButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
changesManager.deleteUpdates(fileNameWithoutExtension);
getLiveUpdatesFragment().notifyLiveUpdatesChanged();
updateSize(fileNameWithoutExtension, changesManager, sizeTextView);
}
});
builder.setView(view)
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
@ -126,35 +174,33 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
.setNeutralButton(R.string.update_now, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getLiveUpdatesFragment().runLiveUpdate(localIndexInfo);
runLiveUpdate(localIndexInfo);
updateSize(fileNameWithoutExtension, changesManager, sizeTextView);
}
});
updateFrequencySpinner.setSelection(updateFrequencePreference.get());
updateFrequencySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
UpdateFrequency updateFrequency = UpdateFrequency.values()[position];
switch (updateFrequency) {
case HOURLY:
updateTimesOfDaySpinner.setVisibility(View.GONE);
break;
case DAILY:
case WEEKLY:
updateTimesOfDaySpinner.setVisibility(View.VISIBLE);
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
return builder.create();
}
void runLiveUpdate(final LocalIndexInfo info) {
final String fnExt = Algorithms.getFileNameWithoutExtension(new File(info.getFileName()));
new PerformLiveUpdateAsyncTask(getMyActivity()).execute(new String[]{fnExt});
getLiveUpdatesFragment().notifyLiveUpdatesChanged();
}
private void updateSize(String fileNameWithoutExtension,
IncrementalChangesManager changesManager,
TextView sizeTextView) {
String size;
long updatesSize = changesManager.getUpdatesSize(fileNameWithoutExtension);
updatesSize /= (1 << 10);
if (updatesSize > 100) {
size = DownloadActivity.formatMb.format(new Object[]{(float) updatesSize / (1 << 10)});
} else {
size = updatesSize + " KB";
}
sizeTextView.setText(size);
}
private long getNextUpdateTime(TimesOfDay timeOfDayToUpdate) {
Calendar calendar = Calendar.getInstance();
if (timeOfDayToUpdate == TimesOfDay.MORNING) {
@ -176,7 +222,11 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
}
private OsmandApplication getMyApplication() {
return ((OsmandActionBarActivity) this.getActivity()).getMyApplication();
return getMyActivity().getMyApplication();
}
private AbstractDownloadActivity getMyActivity() {
return (AbstractDownloadActivity) this.getActivity();
}
public static LiveUpdatesSettingsDialogFragment createInstance(LocalIndexInfo localIndexInfo) {

View file

@ -0,0 +1,55 @@
package net.osmand.plus.liveupdates;
import android.os.AsyncTask;
import android.widget.Toast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.download.AbstractDownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.resources.IncrementalChangesManager;
import java.util.List;
public class PerformLiveUpdateAsyncTask
extends AsyncTask<String, Object, IncrementalChangesManager.IncrementalUpdateList> {
private final AbstractDownloadActivity activity;
public PerformLiveUpdateAsyncTask(AbstractDownloadActivity activity) {
this.activity = activity;
}
protected void onPreExecute() {
activity.setSupportProgressBarIndeterminateVisibility(true);
}
@Override
protected IncrementalChangesManager.IncrementalUpdateList doInBackground(String... params) {
final OsmandApplication myApplication = activity.getMyApplication();
IncrementalChangesManager cm = myApplication.getResourceManager().getChangesManager();
return cm.getUpdatesByMonth(params[0]);
}
protected void onPostExecute(IncrementalChangesManager.IncrementalUpdateList result) {
activity.setSupportProgressBarIndeterminateVisibility(false);
if (result.errorMessage != null) {
Toast.makeText(activity, result.errorMessage, Toast.LENGTH_SHORT).show();
} else {
List<IncrementalChangesManager.IncrementalUpdate> ll = result.getItemsForUpdate();
if (ll.isEmpty()) {
Toast.makeText(activity, R.string.no_updates_available, Toast.LENGTH_SHORT).show();
} else {
int i = 0;
IndexItem[] is = new IndexItem[ll.size()];
for (IncrementalChangesManager.IncrementalUpdate iu : ll) {
IndexItem ii = new IndexItem(iu.fileName, "Incremental update", iu.timestamp, iu.sizeText,
iu.contentSize, iu.containerSize, DownloadActivityType.LIVE_UPDATES_FILE);
is[i++] = ii;
}
activity.startDownload(is);
}
}
}
}

View file

@ -119,7 +119,7 @@ public class IncrementalChangesManager {
}
protected static String formatSize(long vl) {
return (float) ((vl * 1000 / (1 << 20l)) / 1000.0f) + "";
return (vl * 1000 / (1 << 20l)) / 1000.0f + "";
}
public static long calculateSize(List<IncrementalUpdate> list) {
@ -347,6 +347,18 @@ public class IncrementalChangesManager {
return size;
}
public void deleteUpdates(String fileName){
RegionUpdateFiles ruf = regions.get(fileName.toLowerCase());
for (List<RegionUpdate> regionUpdates : ruf.dayUpdates.values()) {
for (RegionUpdate regionUpdate : regionUpdates) {
regionUpdate.file.delete();
}
}
for (RegionUpdate regionUpdate : ruf.monthUpdates.values()) {
regionUpdate.file.delete();
}
}
public long getTimestamp(String fileName) {
RegionUpdateFiles ruf = regions.get(fileName.toLowerCase());
return getTimestamp(ruf);