Sized of live updates are now showing size of updates
This commit is contained in:
parent
71af2ccddd
commit
6f18610082
2 changed files with 34 additions and 12 deletions
|
@ -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<Boolean> 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(),
|
||||
|
|
|
@ -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<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) {
|
||||
RegionUpdateFiles ruf = regions.get(fileName.toLowerCase());
|
||||
return getTimestamp(ruf);
|
||||
|
@ -350,6 +364,4 @@ public class IncrementalChangesManager {
|
|||
}
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue