diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java index 27e916863a..e016a3e06a 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java @@ -2,8 +2,10 @@ package net.osmand.plus.liveupdates; import android.content.Context; import android.content.res.Resources; +import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Bundle; +import android.support.annotation.DrawableRes; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v7.widget.SwitchCompat; @@ -309,6 +311,9 @@ public class LiveUpdatesFragment extends Fragment { OsmandApplication context = fragment.getMyActivity().getMyApplication(); final OsmandSettings.CommonPreference shouldUpdatePreference = preferenceLiveUpdatesOn(item, fragment.getSettings()); + IncrementalChangesManager changesManager = context.getResourceManager().getChangesManager(); + final String fileNameWithoutExtension = + Algorithms.getFileNameWithoutExtension(new File(item.getFileName())); nameTextView.setText(getNameToDisplay(item)); if (shouldUpdatePreference.get()) { @@ -318,23 +323,23 @@ public class LiveUpdatesFragment extends Fragment { subheaderTextView.setTextColor(fragment.getActivity().getResources() .getColor(R.color.osmand_orange)); icon.setImageDrawable(context.getIconsCache().getIcon(R.drawable.ic_map, R.color.osmand_orange)); - options.setImageDrawable(context.getIconsCache().getPaintedContentIcon(R.drawable.ic_overflow_menu_white, secondaryColor)); + options.setImageDrawable(getSecondaryColorPaintedIcon(R.drawable.ic_overflow_menu_white)); } else { String size; - if (item.getSize() > 100) { - size = DownloadActivity.formatMb.format(new Object[]{(float) item.getSize() / (1 << 10)}); + long updatesSize = changesManager.getUpdatesSize(fileNameWithoutExtension); + updatesSize /= (1 << 10); + if (updatesSize > 100) { + size = DownloadActivity.formatMb.format(new Object[]{(float) updatesSize / (1 << 10)}); } else { - size = item.getSize() + " KB"; + size = updatesSize + " KB"; } subheaderTextView.setText(size); subheaderTextView.setTextColor(secondaryColor); - icon.setImageDrawable(context.getIconsCache().getPaintedContentIcon(R.drawable.ic_map, secondaryColor)); - options.setImageDrawable(context.getIconsCache().getPaintedContentIcon(R.drawable.ic_action_plus, secondaryColor)); + icon.setImageDrawable(getSecondaryColorPaintedIcon(R.drawable.ic_map)); + options.setImageDrawable(getSecondaryColorPaintedIcon(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); + + final long timestamp = changesManager.getTimestamp(fileNameWithoutExtension); String formattedDate = LiveUpdatesFragment.formatDateTime(fragment.getActivity(), timestamp); descriptionTextView.setText(context.getString(R.string.last_update, formattedDate)); @@ -349,6 +354,11 @@ public class LiveUpdatesFragment extends Fragment { view.setOnClickListener(clickListener); } + private Drawable getSecondaryColorPaintedIcon(@DrawableRes int drawable) { + return fragment.getMyActivity().getMyApplication().getIconsCache() + .getPaintedContentIcon(drawable, secondaryColor); + } + private String getNameToDisplay(LocalIndexInfo child) { String mapName = FileNameTranslationHelper.getFileName(fragment.getActivity(), fragment.getMyActivity().getMyApplication().getResourceManager().getOsmandRegions(), diff --git a/OsmAnd/src/net/osmand/plus/resources/IncrementalChangesManager.java b/OsmAnd/src/net/osmand/plus/resources/IncrementalChangesManager.java index ccd97331eb..296a0688dd 100644 --- a/OsmAnd/src/net/osmand/plus/resources/IncrementalChangesManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/IncrementalChangesManager.java @@ -333,6 +333,20 @@ public class IncrementalChangesManager { return iul; } + public long getUpdatesSize(String fileName){ + RegionUpdateFiles ruf = regions.get(fileName.toLowerCase()); + long size = 0; + for (List regionUpdates : ruf.dayUpdates.values()) { + for (RegionUpdate regionUpdate : regionUpdates) { + size += regionUpdate.file.length(); + } + } + for (RegionUpdate regionUpdate : ruf.monthUpdates.values()) { + size += regionUpdate.file.length(); + } + return size; + } + public long getTimestamp(String fileName) { RegionUpdateFiles ruf = regions.get(fileName.toLowerCase()); return getTimestamp(ruf); @@ -350,6 +364,4 @@ public class IncrementalChangesManager { } return timestamp; } - - }