diff --git a/OsmAnd/res/layout/list_group_title_with_switch.xml b/OsmAnd/res/layout/list_group_title_with_switch.xml index 0e2584e9fd..8d42ab079a 100644 --- a/OsmAnd/res/layout/list_group_title_with_switch.xml +++ b/OsmAnd/res/layout/list_group_title_with_switch.xml @@ -3,11 +3,13 @@ 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_height="64dp" android:gravity="center" android:orientation="horizontal" android:paddingLeft="16dp" - android:paddingRight="16dp"> + android:paddingRight="16dp" + android:paddingTop="16dp" + android:background="?attr/expandable_list_item_background"> + Live updates + Available maps Select voice guidance Select or download voice guidance for your language Select roads you want to avoid during navigation @@ -2128,4 +2130,5 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A Live update Update now App have no permission to use SD card + Last update: %s \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java index be4418e15f..c99113a2a5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java @@ -36,11 +36,12 @@ public class LocalIndexHelper { public String getInstalledDate(File f){ - return getInstalledDateEdition(f.lastModified(), null); + return android.text.format.DateFormat.getMediumDateFormat(app).format(getInstalationDate(f)); } - - public String getInstalledDateEdition(long t, TimeZone timeZone){ - return android.text.format.DateFormat.getMediumDateFormat(app).format(new Date(t)); + + public Date getInstalationDate(File f) { + final long t = f.lastModified(); + return new Date(t); } public String getInstalledDate(long t, TimeZone timeZone){ diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java index 2f2c36bff0..c99b214b93 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java @@ -4,7 +4,6 @@ import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.NonNull; -import net.osmand.map.WorldRegion; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType; @@ -27,8 +26,6 @@ public class LocalIndexInfo implements Parcelable { private boolean singleFile; private int kbSize = -1; - private WorldRegion worldRegion; - // UI state expanded private boolean expanded; @@ -113,10 +110,6 @@ public class LocalIndexInfo implements Parcelable { this.subfolder = subfolder; } - public WorldRegion getWorldRegion() { - return worldRegion; - } - public String getSubfolder() { return subfolder; } @@ -192,7 +185,6 @@ public class LocalIndexInfo implements Parcelable { dest.writeString(this.fileName); dest.writeByte(singleFile ? (byte) 1 : (byte) 0); dest.writeInt(this.kbSize); - dest.writeSerializable(this.worldRegion); dest.writeByte(expanded ? (byte) 1 : (byte) 0); } @@ -210,7 +202,6 @@ public class LocalIndexInfo implements Parcelable { this.fileName = in.readString(); this.singleFile = in.readByte() != 0; this.kbSize = in.readInt(); - this.worldRegion = (WorldRegion) in.readSerializable(); this.expanded = in.readByte() != 0; } diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java index 3db272e5c3..ad6f73548c 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java @@ -25,6 +25,7 @@ import net.osmand.plus.activities.LocalIndexHelper; 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; @@ -170,13 +171,6 @@ public class LiveUpdatesFragment extends Fragment { return convertView; } - private String getNameToDisplay(LocalIndexInfo child) { - String mapName = FileNameTranslationHelper.getFileName(ctx, - fragment.getMyActivity().getMyApplication().getResourceManager().getOsmandRegions(), - child.getFileName()); - return mapName; - } - @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { View v = convertView; @@ -229,9 +223,9 @@ public class LiveUpdatesFragment extends Fragment { @Override public String getGroup(int groupPosition) { if (groupPosition == SHOULD_UPDATE_GROUP_POSITION) { - return getString(R.string.live_updates_on); + return getString(R.string.live_updates); } else if (groupPosition == SHOULD_NOT_UPDATE_GROUP_POSITION) { - return getString(R.string.live_updates_off); + return getString(R.string.available_maps); } else { throw new IllegalArgumentException("unexpected group position:" + groupPosition); } @@ -279,6 +273,7 @@ public class LiveUpdatesFragment extends Fragment { 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) { @@ -293,6 +288,7 @@ public class LiveUpdatesFragment extends Fragment { private final ImageButton options; private final LiveUpdatesFragment fragment; private final View view; + private final int secondaryColor; private LocalFullMapsViewHolder(View view, LiveUpdatesFragment context) { icon = (ImageView) view.findViewById(R.id.icon); @@ -302,6 +298,11 @@ public class LiveUpdatesFragment extends Fragment { options = (ImageButton) view.findViewById(R.id.options); this.view = view; this.fragment = context; + + TypedValue typedValue = new TypedValue(); + Resources.Theme theme = context.getActivity().getTheme(); + theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true); + secondaryColor = typedValue.data; } public void bindLocalIndexInfo(final LocalIndexInfo item) { @@ -309,16 +310,34 @@ public class LiveUpdatesFragment extends Fragment { final OsmandSettings.CommonPreference shouldUpdatePreference = preferenceLiveUpdatesOn(item, fragment.getSettings()); - nameTextView.setText(item.getName()); + nameTextView.setText(getNameToDisplay(item)); if (shouldUpdatePreference.get()) { final Integer frequencyId = preferenceUpdateFrequency(item, fragment.getSettings()).get(); final UpdateFrequency frequency = UpdateFrequency.values()[frequencyId]; subheaderTextView.setText(frequency.toString()); + subheaderTextView.setTextColor(fragment.getActivity().getResources() + .getColor(R.color.dashboard_blue)); + icon.setImageDrawable(context.getIconsCache().getContentIcon(R.drawable.ic_map)); + icon.setImageDrawable(context.getIconsCache().getIcon(R.drawable.ic_map, R.color.dashboard_blue)); + options.setImageResource(R.drawable.ic_overflow_menu_white); } else { - subheaderTextView.setText(item.getSize() + ""); + String size; + if (item.getSize() > 100) { + size = DownloadActivity.formatMb.format(new Object[]{(float) item.getSize() / (1 << 10)}); + } else { + size = item.getSize() + " KB"; + } + subheaderTextView.setText(size); + subheaderTextView.setTextColor(secondaryColor); + icon.setImageDrawable(context.getIconsCache().getPaintedContentIcon(R.drawable.ic_map, secondaryColor)); + options.setImageResource(R.drawable.ic_action_plus); } - descriptionTextView.setText(item.getDescription()); - icon.setImageDrawable(context.getIconsCache().getContentIcon(R.drawable.ic_map)); + IncrementalChangesManager cm = context.getResourceManager().getChangesManager(); + final String fileNameWithoutExtension = + Algorithms.getFileNameWithoutExtension(new File(item.getFileName())); + final long timestamp = cm.getTimestamp(fileNameWithoutExtension); + String formattedDate = LiveUpdatesFragment.formatDateTime(fragment.getActivity(), timestamp); + descriptionTextView.setText(context.getString(R.string.last_update, formattedDate)); final View.OnClickListener clickListener = new View.OnClickListener() { @Override @@ -330,6 +349,13 @@ public class LiveUpdatesFragment extends Fragment { options.setOnClickListener(clickListener); view.setOnClickListener(clickListener); } + + private String getNameToDisplay(LocalIndexInfo child) { + String mapName = FileNameTranslationHelper.getFileName(fragment.getActivity(), + fragment.getMyActivity().getMyApplication().getResourceManager().getOsmandRegions(), + child.getFileName()); + return mapName; + } } public static class LoadLocalIndexTask @@ -360,7 +386,8 @@ public class LiveUpdatesFragment extends Fragment { @Override protected void onProgressUpdate(LocalIndexInfo... values) { for (LocalIndexInfo localIndexInfo : values) { - if (localIndexInfo.getType() == LocalIndexHelper.LocalIndexType.MAP_DATA) { + if (localIndexInfo.getType() == LocalIndexHelper.LocalIndexType.MAP_DATA + && localIndexInfo.getFileName().toLowerCase().contains("world")) { adapter.add(localIndexInfo); } } @@ -416,4 +443,10 @@ public class LiveUpdatesFragment extends Fragment { } } } + + 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); + } } diff --git a/OsmAnd/src/net/osmand/plus/resources/IncrementalChangesManager.java b/OsmAnd/src/net/osmand/plus/resources/IncrementalChangesManager.java index 7a6b14c5ec..ccd97331eb 100644 --- a/OsmAnd/src/net/osmand/plus/resources/IncrementalChangesManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/IncrementalChangesManager.java @@ -1,5 +1,15 @@ package net.osmand.plus.resources; +import net.osmand.IndexConstants; +import net.osmand.PlatformUtil; +import net.osmand.binary.BinaryMapIndexReader; +import net.osmand.osm.io.NetworkUtils; +import net.osmand.plus.R; +import net.osmand.util.Algorithms; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + import java.io.File; import java.io.IOException; import java.net.HttpURLConnection; @@ -13,16 +23,6 @@ import java.util.Set; import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; -import net.osmand.IndexConstants; -import net.osmand.PlatformUtil; -import net.osmand.binary.BinaryMapIndexReader; -import net.osmand.osm.io.NetworkUtils; -import net.osmand.plus.R; -import net.osmand.util.Algorithms; - -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - public class IncrementalChangesManager { private static final String URL = "http://download.osmand.net/check_live.php"; @@ -319,15 +319,7 @@ public class IncrementalChangesManager { iul.errorMessage = resourceManager.getContext().getString(R.string.no_updates_available); return iul; } - long timestamp = ruf.mainFileInit; - for (RegionUpdate ru : ruf.monthUpdates.values()) { - timestamp = Math.max(ru.obfCreated, timestamp); - } - for (List l : ruf.dayUpdates.values()) { - for (RegionUpdate ru : l) { - timestamp = Math.max(ru.obfCreated, timestamp); - } - } + long timestamp = getTimestamp(ruf); try { List lst = getIncrementalUpdates(fileName, timestamp); for(IncrementalUpdate iu : lst) { @@ -341,5 +333,23 @@ public class IncrementalChangesManager { return iul; } - + public long getTimestamp(String fileName) { + RegionUpdateFiles ruf = regions.get(fileName.toLowerCase()); + return getTimestamp(ruf); + } + + private long getTimestamp(RegionUpdateFiles ruf) { + long timestamp = ruf.mainFileInit; + for (RegionUpdate ru : ruf.monthUpdates.values()) { + timestamp = Math.max(ru.obfCreated, timestamp); + } + for (List l : ruf.dayUpdates.values()) { + for (RegionUpdate ru : l) { + timestamp = Math.max(ru.obfCreated, timestamp); + } + } + return timestamp; + } + + }