Fix issues

This commit is contained in:
Victor Shcherb 2015-10-20 00:41:08 +02:00
parent 5e2d159a6a
commit b9d3a71d02
4 changed files with 75 additions and 13 deletions

View file

@ -29,9 +29,12 @@ public class DownloadResourceGroup {
public enum DownloadResourceGroupType {
// headers
WORLD_MAPS(R.string.world_maps), REGION_MAPS(R.string.region_maps), VOICE_GROUP(R.string.voices), SUBREGIONS(
R.string.regions), VOICE_HEADER_REC(R.string.index_name_voice), VOICE_HEADER_TTS(
R.string.index_name_tts_voice),
WORLD_MAPS(R.string.world_maps), REGION_MAPS(R.string.region_maps),
SRTM_HEADER(R.string.download_srtm_maps), HILLSHADE_HEADER(R.string.download_hillshade_maps),
// headers with voice items
VOICE_HEADER_REC(R.string.index_name_voice), VOICE_HEADER_TTS(R.string.index_name_tts_voice),
// headers with resources
VOICE_GROUP(R.string.voices), SUBREGIONS(R.string.regions),
// screen items
VOICE_REC(R.string.index_name_voice), VOICE_TTS(R.string.index_name_tts_voice), WORLD(-1), REGION(-1);
@ -59,7 +62,7 @@ public class DownloadResourceGroup {
public boolean isHeader() {
return this == VOICE_HEADER_REC || this == VOICE_HEADER_TTS || this == SUBREGIONS || this == WORLD_MAPS
|| this == REGION_MAPS || this == VOICE_GROUP;
|| this == REGION_MAPS || this == VOICE_GROUP || this == HILLSHADE_HEADER || this == SRTM_HEADER;
}
}
@ -98,6 +101,42 @@ public class DownloadResourceGroup {
}
public void createHillshadeSRTMGroups() {
if(getType().isScreen()) {
DownloadResourceGroup regionMaps = getSubGroupById(DownloadResourceGroupType.REGION_MAPS.getDefaultId());
if(regionMaps != null && regionMaps.size() == 1 && parentGroup != null && parentGroup.getParentGroup() != null) {
IndexItem item = regionMaps.individualResources.get(0);
DownloadResourceGroup screenParent = parentGroup.getParentGroup();
if(item.getType() == DownloadActivityType.HILLSHADE_FILE) {
DownloadResourceGroup hillshades =
screenParent.getSubGroupById(DownloadResourceGroupType.HILLSHADE_HEADER.getDefaultId());
if(hillshades == null) {
hillshades = new DownloadResourceGroup(screenParent, DownloadResourceGroupType.HILLSHADE_HEADER);
screenParent.addGroup(hillshades);
}
hillshades.addItem(item);
regionMaps.individualResources.remove(0);
} else if (item.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
DownloadResourceGroup hillshades = screenParent
.getSubGroupById(DownloadResourceGroupType.SRTM_HEADER.getDefaultId());
if (hillshades == null) {
hillshades = new DownloadResourceGroup(screenParent, DownloadResourceGroupType.SRTM_HEADER);
screenParent.addGroup(hillshades);
}
hillshades.addItem(item);
regionMaps.individualResources.remove(0);
}
}
DownloadResourceGroup subregs = getSubGroupById(DownloadResourceGroupType.SUBREGIONS.getDefaultId());
if(subregs != null) {
for(DownloadResourceGroup g : subregs.getGroups()) {
g.createHillshadeSRTMGroups();
}
}
}
}
public void addGroup(DownloadResourceGroup g) {
if(type.isScreen()) {
if(!g.type.isHeader()) {

View file

@ -267,7 +267,7 @@ public class DownloadResources extends DownloadResourceGroup {
// 3. if hillshade/srtm is disabled, all maps from inner level could be combined into 1
addGroup(worldMaps);
addGroup(voiceGroup);
createHillshadeSRTMGroups();
trimEmptyGroups();
initAlreadyLoadedFiles();
return true;

View file

@ -324,6 +324,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
private List<DownloadResourceGroup> data = new ArrayList<DownloadResourceGroup>();
private DownloadActivity ctx;
private DownloadResourceGroup mainGroup;
@ -333,12 +334,8 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
ta.recycle();
}
public void clear() {
data.clear();
notifyDataSetChanged();
}
public void update(DownloadResourceGroup mainGroup) {
this.mainGroup = mainGroup;
data = mainGroup.getGroups();
notifyDataSetChanged();
}
@ -362,7 +359,9 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
View convertView, ViewGroup parent) {
final Object child = getChild(groupPosition, childPosition);
if (child instanceof IndexItem) {
IndexItem item = (IndexItem) child;
DownloadResourceGroup group = getGroupObj(groupPosition);
ItemViewHolder viewHolder;
if (convertView != null && convertView.getTag() instanceof ItemViewHolder) {
viewHolder = (ItemViewHolder) convertView.getTag();
@ -371,9 +370,19 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
R.layout.two_line_with_images_list_item, parent, false);
viewHolder = new ItemViewHolder(convertView, ctx);
viewHolder.setShowRemoteDate(true);
viewHolder.setShowTypeInDesc(true);
convertView.setTag(viewHolder);
}
if(mainGroup.getType() == DownloadResourceGroupType.REGION &&
group != null && group.getType() == DownloadResourceGroupType.REGION_MAPS) {
viewHolder.setShowTypeInName(true);
viewHolder.setShowTypeInDesc(false);
} else if(group != null && (group.getType() == DownloadResourceGroupType.SRTM_HEADER ||
group.getType() == DownloadResourceGroupType.HILLSHADE_HEADER)) {
viewHolder.setShowTypeInName(false);
viewHolder.setShowTypeInDesc(false);
} else {
viewHolder.setShowTypeInDesc(true);
}
viewHolder.bindIndexItem(item);
} else {
DownloadResourceGroup group = (DownloadResourceGroup) child;

View file

@ -46,9 +46,11 @@ public class ItemViewHolder {
private int textColorSecondary;
boolean showTypeInDesc;
boolean showTypeInName;
boolean showRemoteDate;
boolean silentCancelDownload;
boolean showProgressInDesc;
private DateFormat dateFormat;
@ -96,6 +98,10 @@ public class ItemViewHolder {
public void setShowTypeInDesc(boolean showTypeInDesc) {
this.showTypeInDesc = showTypeInDesc;
}
public void setShowTypeInName(boolean showTypeInName) {
this.showTypeInName = showTypeInName;
}
// FIXME don't initialize on every row
@ -116,7 +122,11 @@ public class ItemViewHolder {
}
boolean disabled = checkDisabledAndClickAction(indexItem);
/// name and left item
nameTextView.setText(indexItem.getVisibleName(context, context.getMyApplication().getRegions(), false));
if(showTypeInName) {
nameTextView.setText(indexItem.getType().getString(context));
} else {
nameTextView.setText(indexItem.getVisibleName(context, context.getMyApplication().getRegions(), false));
}
if(!disabled) {
nameTextView.setTextColor(textColorPrimary);
} else {
@ -143,7 +153,11 @@ public class ItemViewHolder {
descrTextView.setVisibility(View.VISIBLE);
if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE ||
indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) && srtmDisabled) {
descrTextView.setText(indexItem.getType().getString(context));
if(showTypeInName) {
descrTextView.setText("");
} else {
descrTextView.setText(indexItem.getType().getString(context));
}
} else if (showTypeInDesc) {
descrTextView.setText(indexItem.getType().getString(context) +
"" + indexItem.getSizeDescription(context) +