Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-10-15 11:19:40 +02:00
commit e1b44d0433
2 changed files with 31 additions and 61 deletions

View file

@ -13,7 +13,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
@ -42,28 +41,6 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
private UpdateIndexAdapter listAdapter; private UpdateIndexAdapter listAdapter;
List<IndexItem> indexItems = new ArrayList<>(); List<IndexItem> indexItems = new ArrayList<>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.update_index, container, false);
return view;
}
private void refreshSelectAll() {
View view = getView();
if (view == null) {
return;
}
CheckBox selectAll = (CheckBox) view.findViewById(R.id.select_all);
for (IndexItem item : indexItems) {
if (!getMyActivity().getEntriesToDownload().containsKey(item)){
selectAll.setChecked(false);
return;
}
}
selectAll.setChecked(true);
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -74,6 +51,11 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.update_index, container, false);
}
private void createListView() { private void createListView() {
updateHeader(); updateHeader();
if (indexItems.size() == 0) { if (indexItems.size() == 0) {
@ -95,7 +77,8 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
setListAdapter(listAdapter); setListAdapter(listAdapter);
} }
private void updateHeader(){ private void updateHeader() {
osmandRegions = getMyApplication().getRegions();
View view = getView(); View view = getView();
if (getView() == null) { if (getView() == null) {
return; return;
@ -120,25 +103,8 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
@Override @Override
public void onListItemClick(ListView l, View v, int position, long id) { public void onListItemClick(ListView l, View v, int position, long id) {
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
onItemSelected(ch, position);
}
private void onItemSelected(CheckBox ch, int position) {
final IndexItem e = (IndexItem) getListAdapter().getItem(position); final IndexItem e = (IndexItem) getListAdapter().getItem(position);
if (ch.isChecked()) { getMyActivity().startDownload(e);
ch.setChecked(!ch.isChecked());
getMyActivity().getEntriesToDownload().remove(e);
getMyActivity().updateFragments();
} else {
List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), e.getType(), new ArrayList<DownloadEntry>());
if (download.size() > 0) {
getMyActivity().getEntriesToDownload().put(e, download);
getMyActivity().updateFragments();
ch.setChecked(!ch.isChecked());
}
}
refreshSelectAll();
} }
public DownloadActivity getMyActivity() { public DownloadActivity getMyActivity() {
@ -296,8 +262,8 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
context.getMyApplication().getResourceManager().getOsmandRegions(); context.getMyApplication().getResourceManager().getOsmandRegions();
String eName = indexItem.getVisibleName(context.getMyApplication(), osmandRegions); String eName = indexItem.getVisibleName(context.getMyApplication(), osmandRegions);
nameTextView.setText(eName.trim().replace('\n', ' ').replace("TTS","")); //$NON-NLS-1$ nameTextView.setText(eName.trim().replace('\n', ' ').replace("TTS", "")); //$NON-NLS-1$
String d = getMapDescription(indexItem); String d = getMapDescription(indexItem);
descrTextView.setText(d); descrTextView.setText(d);
String sfName = indexItem.getTargetFileName(); String sfName = indexItem.getTargetFileName();
@ -307,36 +273,40 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
if (dt != null) { if (dt != null) {
try { try {
Date tm = format.parse(dt); Date tm = format.parse(dt);
long days = Math.max(1, (indexItem.getTimestamp() - tm.getTime()) / (24 * 60 * 60 * 1000) + 1); long days = Math.max(1, (indexItem.getTimestamp() - tm.getTime()) / (24 * 60 * 60 * 1000) + 1);
mapDateTextView.setText(days + " " + context.getString(R.string.days_behind)); mapDateTextView.setText(days + " " + context.getString(R.string.days_behind));
} catch (ParseException e1) { } catch (ParseException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
} }
rightImageButton.setVisibility(View.VISIBLE);
rightImageButton.setImageDrawable(
context.getMyApplication().getIconsCache()
.getContentIcon(R.drawable.ic_action_import));
} }
private String getMapDescription(IndexItem item){ private String getMapDescription(IndexItem item) {
String typeName = getTypeName(item, item.getType().getStringResource()); String typeName = getTypeName(item, item.getType().getStringResource());
String date = item.getDate(format); String date = item.getDate(format);
String size = item.getSizeDescription(context); String size = item.getSizeDescription(context);
return typeName + " " + date + " " + size; return typeName + " " + date + " " + size;
} }
private String getTypeName(IndexItem item, int resId){ private String getTypeName(IndexItem item, int resId) {
Activity activity = context; Activity activity = context;
if (resId == R.string.download_regular_maps){ if (resId == R.string.download_regular_maps) {
return activity.getString(R.string.shared_string_map); return activity.getString(R.string.shared_string_map);
} else if (resId == R.string.download_wikipedia_maps){ } else if (resId == R.string.download_wikipedia_maps) {
return activity.getString(R.string.shared_string_wikipedia); return activity.getString(R.string.shared_string_wikipedia);
} else if (resId == R.string.voices) { } else if (resId == R.string.voices) {
return item.getTargetFileName().contains("tts") ? activity.getString(R.string.ttsvoice) : activity return item.getTargetFileName().contains("tts") ? activity.getString(R.string.ttsvoice) : activity
.getString(R.string.voice); .getString(R.string.voice);
} else if (resId == R.string.download_roads_only_maps){ } else if (resId == R.string.download_roads_only_maps) {
return activity.getString(R.string.roads_only); return activity.getString(R.string.roads_only);
} else if (resId == R.string.download_srtm_maps){ } else if (resId == R.string.download_srtm_maps) {
return activity.getString(R.string.download_srtm_maps); return activity.getString(R.string.download_srtm_maps);
} else if (resId == R.string.download_hillshade_maps){ } else if (resId == R.string.download_hillshade_maps) {
return activity.getString(R.string.download_hillshade_maps); return activity.getString(R.string.download_hillshade_maps);
} }
return ""; return "";

View file

@ -133,7 +133,7 @@ public class ItemViewHolder {
descrTextView.setText(indexItem.getSizeDescription(context)); descrTextView.setText(indexItem.getSizeDescription(context));
} }
rightImageButton.setVisibility(View.VISIBLE); rightImageButton.setVisibility(View.VISIBLE);
rightImageButton.setImageDrawable(getContextIcon(context, R.drawable.ic_action_import)); rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_import));
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
if (rightButtonAction != RightButtonAction.UNKNOWN) { if (rightButtonAction != RightButtonAction.UNKNOWN) {
@ -195,15 +195,15 @@ public class ItemViewHolder {
int colorId = outdated ? R.color.color_distance : R.color.color_ok; int colorId = outdated ? R.color.color_distance : R.color.color_ok;
final int color = context.getResources().getColor(colorId); final int color = context.getResources().getColor(colorId);
mapDateTextView.setTextColor(color); mapDateTextView.setTextColor(color);
leftImageView.setImageDrawable(getContextIcon(context, leftImageView.setImageDrawable(getContentIcon(context,
indexItem.getType().getIconResource(), color)); indexItem.getType().getIconResource(), color));
nameTextView.setTextColor(textColorPrimary); nameTextView.setTextColor(textColorPrimary);
} else if (disabled) { } else if (disabled) {
leftImageView.setImageDrawable(getContextIcon(context, leftImageView.setImageDrawable(getContentIcon(context,
indexItem.getType().getIconResource(), textColorSecondary)); indexItem.getType().getIconResource(), textColorSecondary));
nameTextView.setTextColor(textColorSecondary); nameTextView.setTextColor(textColorSecondary);
} else { } else {
leftImageView.setImageDrawable(getContextIcon(context, leftImageView.setImageDrawable(getContentIcon(context,
indexItem.getType().getIconResource())); indexItem.getType().getIconResource()));
nameTextView.setTextColor(textColorPrimary); nameTextView.setTextColor(textColorPrimary);
} }
@ -227,14 +227,14 @@ public class ItemViewHolder {
Drawable leftImageDrawable = null; Drawable leftImageDrawable = null;
switch (region.getMapState()) { switch (region.getMapState()) {
case NOT_DOWNLOADED: case NOT_DOWNLOADED:
leftImageDrawable = getContextIcon(context, R.drawable.ic_map); leftImageDrawable = getContentIcon(context, R.drawable.ic_map);
break; break;
case DOWNLOADED: case DOWNLOADED:
leftImageDrawable = getContextIcon(context, R.drawable.ic_map, leftImageDrawable = getContentIcon(context, R.drawable.ic_map,
context.getResources().getColor(R.color.color_ok)); context.getResources().getColor(R.color.color_ok));
break; break;
case OUTDATED: case OUTDATED:
leftImageDrawable = getContextIcon(context, R.drawable.ic_map, leftImageDrawable = getContentIcon(context, R.drawable.ic_map,
context.getResources().getColor(R.color.color_distance)); context.getResources().getColor(R.color.color_distance));
break; break;
} }
@ -244,11 +244,11 @@ public class ItemViewHolder {
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
} }
private Drawable getContextIcon(DownloadActivity context, int resourceId) { private Drawable getContentIcon(DownloadActivity context, int resourceId) {
return context.getMyApplication().getIconsCache().getContentIcon(resourceId); return context.getMyApplication().getIconsCache().getContentIcon(resourceId);
} }
private Drawable getContextIcon(DownloadActivity context, int resourceId, int color) { private Drawable getContentIcon(DownloadActivity context, int resourceId, int color) {
return context.getMyApplication().getIconsCache().getPaintedContentIcon(resourceId, color); return context.getMyApplication().getIconsCache().getPaintedContentIcon(resourceId, color);
} }