Normal time, fixed some bugs of live updates.

This commit is contained in:
GaidamakUA 2015-12-19 17:30:59 +02:00
parent dfef1f20f8
commit 240bf6581e
6 changed files with 89 additions and 49 deletions

View file

@ -3,11 +3,13 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="48dp" android:layout_height="64dp"
android:gravity="center" android:gravity="center"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="16dp"> android:paddingRight="16dp"
android:paddingTop="16dp"
android:background="?attr/expandable_list_item_background">
<TextView <TextView
android:id="@+id/section_name" android:id="@+id/section_name"

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="live_updates">Live updates</string>
<string name="available_maps">Available maps</string>
<string name="select_voice_provider">Select voice guidance</string> <string name="select_voice_provider">Select voice guidance</string>
<string name="select_voice_provider_descr">Select or download voice guidance for your language</string> <string name="select_voice_provider_descr">Select or download voice guidance for your language</string>
<string name="impassable_road_desc">Select roads you want to avoid during navigation</string> <string name="impassable_road_desc">Select roads you want to avoid during navigation</string>
@ -2128,4 +2130,5 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="live_update">Live update</string> <string name="live_update">Live update</string>
<string name="update_now">Update now</string> <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="missing_write_external_storage_permission">App have no permission to use SD card</string>
<string name="last_update">Last update: %s</string>
</resources> </resources>

View file

@ -36,11 +36,12 @@ public class LocalIndexHelper {
public String getInstalledDate(File f){ 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){ public Date getInstalationDate(File f) {
return android.text.format.DateFormat.getMediumDateFormat(app).format(new Date(t)); final long t = f.lastModified();
return new Date(t);
} }
public String getInstalledDate(long t, TimeZone timeZone){ public String getInstalledDate(long t, TimeZone timeZone){

View file

@ -4,7 +4,6 @@ import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import net.osmand.map.WorldRegion;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType; import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
@ -27,8 +26,6 @@ public class LocalIndexInfo implements Parcelable {
private boolean singleFile; private boolean singleFile;
private int kbSize = -1; private int kbSize = -1;
private WorldRegion worldRegion;
// UI state expanded // UI state expanded
private boolean expanded; private boolean expanded;
@ -113,10 +110,6 @@ public class LocalIndexInfo implements Parcelable {
this.subfolder = subfolder; this.subfolder = subfolder;
} }
public WorldRegion getWorldRegion() {
return worldRegion;
}
public String getSubfolder() { public String getSubfolder() {
return subfolder; return subfolder;
} }
@ -192,7 +185,6 @@ public class LocalIndexInfo implements Parcelable {
dest.writeString(this.fileName); dest.writeString(this.fileName);
dest.writeByte(singleFile ? (byte) 1 : (byte) 0); dest.writeByte(singleFile ? (byte) 1 : (byte) 0);
dest.writeInt(this.kbSize); dest.writeInt(this.kbSize);
dest.writeSerializable(this.worldRegion);
dest.writeByte(expanded ? (byte) 1 : (byte) 0); dest.writeByte(expanded ? (byte) 1 : (byte) 0);
} }
@ -210,7 +202,6 @@ public class LocalIndexInfo implements Parcelable {
this.fileName = in.readString(); this.fileName = in.readString();
this.singleFile = in.readByte() != 0; this.singleFile = in.readByte() != 0;
this.kbSize = in.readInt(); this.kbSize = in.readInt();
this.worldRegion = (WorldRegion) in.readSerializable();
this.expanded = in.readByte() != 0; this.expanded = in.readByte() != 0;
} }

View file

@ -25,6 +25,7 @@ import net.osmand.plus.activities.LocalIndexHelper;
import net.osmand.plus.activities.LocalIndexInfo; import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.download.AbstractDownloadActivity; import net.osmand.plus.download.AbstractDownloadActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask; import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
@ -170,13 +171,6 @@ public class LiveUpdatesFragment extends Fragment {
return convertView; return convertView;
} }
private String getNameToDisplay(LocalIndexInfo child) {
String mapName = FileNameTranslationHelper.getFileName(ctx,
fragment.getMyActivity().getMyApplication().getResourceManager().getOsmandRegions(),
child.getFileName());
return mapName;
}
@Override @Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = convertView; View v = convertView;
@ -229,9 +223,9 @@ public class LiveUpdatesFragment extends Fragment {
@Override @Override
public String getGroup(int groupPosition) { public String getGroup(int groupPosition) {
if (groupPosition == SHOULD_UPDATE_GROUP_POSITION) { 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) { } else if (groupPosition == SHOULD_NOT_UPDATE_GROUP_POSITION) {
return getString(R.string.live_updates_off); return getString(R.string.available_maps);
} else { } else {
throw new IllegalArgumentException("unexpected group position:" + groupPosition); throw new IllegalArgumentException("unexpected group position:" + groupPosition);
} }
@ -279,6 +273,7 @@ public class LiveUpdatesFragment extends Fragment {
void runLiveUpdate(final LocalIndexInfo info) { void runLiveUpdate(final LocalIndexInfo info) {
final String fnExt = Algorithms.getFileNameWithoutExtension(new File(info.getFileName())); final String fnExt = Algorithms.getFileNameWithoutExtension(new File(info.getFileName()));
new PerformLiveUpdateAsyncTask(getMyActivity()).execute(new String[]{fnExt}); new PerformLiveUpdateAsyncTask(getMyActivity()).execute(new String[]{fnExt});
adapter.notifyLiveUpdatesChanged();
} }
LocalIndexInfo getLocalIndexInfo(int groupPosition, int childPosition) { LocalIndexInfo getLocalIndexInfo(int groupPosition, int childPosition) {
@ -293,6 +288,7 @@ public class LiveUpdatesFragment extends Fragment {
private final ImageButton options; private final ImageButton options;
private final LiveUpdatesFragment fragment; private final LiveUpdatesFragment fragment;
private final View view; private final View view;
private final int secondaryColor;
private LocalFullMapsViewHolder(View view, LiveUpdatesFragment context) { private LocalFullMapsViewHolder(View view, LiveUpdatesFragment context) {
icon = (ImageView) view.findViewById(R.id.icon); icon = (ImageView) view.findViewById(R.id.icon);
@ -302,6 +298,11 @@ public class LiveUpdatesFragment extends Fragment {
options = (ImageButton) view.findViewById(R.id.options); options = (ImageButton) view.findViewById(R.id.options);
this.view = view; this.view = view;
this.fragment = context; 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) { public void bindLocalIndexInfo(final LocalIndexInfo item) {
@ -309,16 +310,34 @@ public class LiveUpdatesFragment extends Fragment {
final OsmandSettings.CommonPreference<Boolean> shouldUpdatePreference = final OsmandSettings.CommonPreference<Boolean> shouldUpdatePreference =
preferenceLiveUpdatesOn(item, fragment.getSettings()); preferenceLiveUpdatesOn(item, fragment.getSettings());
nameTextView.setText(item.getName()); nameTextView.setText(getNameToDisplay(item));
if (shouldUpdatePreference.get()) { if (shouldUpdatePreference.get()) {
final Integer frequencyId = preferenceUpdateFrequency(item, fragment.getSettings()).get(); final Integer frequencyId = preferenceUpdateFrequency(item, fragment.getSettings()).get();
final UpdateFrequency frequency = UpdateFrequency.values()[frequencyId]; final UpdateFrequency frequency = UpdateFrequency.values()[frequencyId];
subheaderTextView.setText(frequency.toString()); subheaderTextView.setText(frequency.toString());
} else { subheaderTextView.setTextColor(fragment.getActivity().getResources()
subheaderTextView.setText(item.getSize() + ""); .getColor(R.color.dashboard_blue));
}
descriptionTextView.setText(item.getDescription());
icon.setImageDrawable(context.getIconsCache().getContentIcon(R.drawable.ic_map)); 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 {
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);
}
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() { final View.OnClickListener clickListener = new View.OnClickListener() {
@Override @Override
@ -330,6 +349,13 @@ public class LiveUpdatesFragment extends Fragment {
options.setOnClickListener(clickListener); options.setOnClickListener(clickListener);
view.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 public static class LoadLocalIndexTask
@ -360,7 +386,8 @@ public class LiveUpdatesFragment extends Fragment {
@Override @Override
protected void onProgressUpdate(LocalIndexInfo... values) { protected void onProgressUpdate(LocalIndexInfo... values) {
for (LocalIndexInfo 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); 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);
}
} }

View file

@ -1,5 +1,15 @@
package net.osmand.plus.resources; 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.File;
import java.io.IOException; import java.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
@ -13,16 +23,6 @@ import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap; 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 { public class IncrementalChangesManager {
private static final String URL = "http://download.osmand.net/check_live.php"; 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); iul.errorMessage = resourceManager.getContext().getString(R.string.no_updates_available);
return iul; return iul;
} }
long timestamp = ruf.mainFileInit; long timestamp = getTimestamp(ruf);
for (RegionUpdate ru : ruf.monthUpdates.values()) {
timestamp = Math.max(ru.obfCreated, timestamp);
}
for (List<RegionUpdate> l : ruf.dayUpdates.values()) {
for (RegionUpdate ru : l) {
timestamp = Math.max(ru.obfCreated, timestamp);
}
}
try { try {
List<IncrementalUpdate> lst = getIncrementalUpdates(fileName, timestamp); List<IncrementalUpdate> lst = getIncrementalUpdates(fileName, timestamp);
for(IncrementalUpdate iu : lst) { for(IncrementalUpdate iu : lst) {
@ -341,5 +333,23 @@ public class IncrementalChangesManager {
return iul; 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<RegionUpdate> l : ruf.dayUpdates.values()) {
for (RegionUpdate ru : l) {
timestamp = Math.max(ru.obfCreated, timestamp);
}
}
return timestamp;
}
} }