Sized of live updates are now showing size of updates

This commit is contained in:
GaidamakUA 2015-12-21 13:11:52 +02:00
parent 71af2ccddd
commit 6f18610082
2 changed files with 34 additions and 12 deletions

View file

@ -2,8 +2,10 @@ package net.osmand.plus.liveupdates;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.SwitchCompat;
@ -309,6 +311,9 @@ public class LiveUpdatesFragment extends Fragment {
OsmandApplication context = fragment.getMyActivity().getMyApplication(); OsmandApplication context = fragment.getMyActivity().getMyApplication();
final OsmandSettings.CommonPreference<Boolean> shouldUpdatePreference = final OsmandSettings.CommonPreference<Boolean> shouldUpdatePreference =
preferenceLiveUpdatesOn(item, fragment.getSettings()); preferenceLiveUpdatesOn(item, fragment.getSettings());
IncrementalChangesManager changesManager = context.getResourceManager().getChangesManager();
final String fileNameWithoutExtension =
Algorithms.getFileNameWithoutExtension(new File(item.getFileName()));
nameTextView.setText(getNameToDisplay(item)); nameTextView.setText(getNameToDisplay(item));
if (shouldUpdatePreference.get()) { if (shouldUpdatePreference.get()) {
@ -318,23 +323,23 @@ public class LiveUpdatesFragment extends Fragment {
subheaderTextView.setTextColor(fragment.getActivity().getResources() subheaderTextView.setTextColor(fragment.getActivity().getResources()
.getColor(R.color.osmand_orange)); .getColor(R.color.osmand_orange));
icon.setImageDrawable(context.getIconsCache().getIcon(R.drawable.ic_map, 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 { } else {
String size; String size;
if (item.getSize() > 100) { long updatesSize = changesManager.getUpdatesSize(fileNameWithoutExtension);
size = DownloadActivity.formatMb.format(new Object[]{(float) item.getSize() / (1 << 10)}); updatesSize /= (1 << 10);
if (updatesSize > 100) {
size = DownloadActivity.formatMb.format(new Object[]{(float) updatesSize / (1 << 10)});
} else { } else {
size = item.getSize() + " KB"; size = updatesSize + " KB";
} }
subheaderTextView.setText(size); subheaderTextView.setText(size);
subheaderTextView.setTextColor(secondaryColor); subheaderTextView.setTextColor(secondaryColor);
icon.setImageDrawable(context.getIconsCache().getPaintedContentIcon(R.drawable.ic_map, secondaryColor)); icon.setImageDrawable(getSecondaryColorPaintedIcon(R.drawable.ic_map));
options.setImageDrawable(context.getIconsCache().getPaintedContentIcon(R.drawable.ic_action_plus, secondaryColor)); options.setImageDrawable(getSecondaryColorPaintedIcon(R.drawable.ic_action_plus));
} }
IncrementalChangesManager cm = context.getResourceManager().getChangesManager();
final String fileNameWithoutExtension = final long timestamp = changesManager.getTimestamp(fileNameWithoutExtension);
Algorithms.getFileNameWithoutExtension(new File(item.getFileName()));
final long timestamp = cm.getTimestamp(fileNameWithoutExtension);
String formattedDate = LiveUpdatesFragment.formatDateTime(fragment.getActivity(), timestamp); String formattedDate = LiveUpdatesFragment.formatDateTime(fragment.getActivity(), timestamp);
descriptionTextView.setText(context.getString(R.string.last_update, formattedDate)); descriptionTextView.setText(context.getString(R.string.last_update, formattedDate));
@ -349,6 +354,11 @@ public class LiveUpdatesFragment extends Fragment {
view.setOnClickListener(clickListener); view.setOnClickListener(clickListener);
} }
private Drawable getSecondaryColorPaintedIcon(@DrawableRes int drawable) {
return fragment.getMyActivity().getMyApplication().getIconsCache()
.getPaintedContentIcon(drawable, secondaryColor);
}
private String getNameToDisplay(LocalIndexInfo child) { private String getNameToDisplay(LocalIndexInfo child) {
String mapName = FileNameTranslationHelper.getFileName(fragment.getActivity(), String mapName = FileNameTranslationHelper.getFileName(fragment.getActivity(),
fragment.getMyActivity().getMyApplication().getResourceManager().getOsmandRegions(), fragment.getMyActivity().getMyApplication().getResourceManager().getOsmandRegions(),

View file

@ -333,6 +333,20 @@ public class IncrementalChangesManager {
return iul; return iul;
} }
public long getUpdatesSize(String fileName){
RegionUpdateFiles ruf = regions.get(fileName.toLowerCase());
long size = 0;
for (List<RegionUpdate> 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) { public long getTimestamp(String fileName) {
RegionUpdateFiles ruf = regions.get(fileName.toLowerCase()); RegionUpdateFiles ruf = regions.get(fileName.toLowerCase());
return getTimestamp(ruf); return getTimestamp(ruf);
@ -350,6 +364,4 @@ public class IncrementalChangesManager {
} }
return timestamp; return timestamp;
} }
} }