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.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
@ -42,28 +41,6 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
private UpdateIndexAdapter listAdapter;
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
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -74,6 +51,11 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.update_index, container, false);
}
private void createListView() {
updateHeader();
if (indexItems.size() == 0) {
@ -95,7 +77,8 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
setListAdapter(listAdapter);
}
private void updateHeader(){
private void updateHeader() {
osmandRegions = getMyApplication().getRegions();
View view = getView();
if (getView() == null) {
return;
@ -120,25 +103,8 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
@Override
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);
if (ch.isChecked()) {
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();
getMyActivity().startDownload(e);
}
public DownloadActivity getMyActivity() {
@ -296,8 +262,8 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
context.getMyApplication().getResourceManager().getOsmandRegions();
String eName = indexItem.getVisibleName(context.getMyApplication(), osmandRegions);
nameTextView.setText(eName.trim().replace('\n', ' ').replace("TTS","")); //$NON-NLS-1$
String d = getMapDescription(indexItem);
nameTextView.setText(eName.trim().replace('\n', ' ').replace("TTS", "")); //$NON-NLS-1$
String d = getMapDescription(indexItem);
descrTextView.setText(d);
String sfName = indexItem.getTargetFileName();
@ -307,36 +273,40 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
if (dt != null) {
try {
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));
} catch (ParseException e1) {
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 date = item.getDate(format);
String size = item.getSizeDescription(context);
return typeName + " " + date + " " + size;
}
private String getTypeName(IndexItem item, int resId){
private String getTypeName(IndexItem item, int resId) {
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);
} else if (resId == R.string.download_wikipedia_maps){
} else if (resId == R.string.download_wikipedia_maps) {
return activity.getString(R.string.shared_string_wikipedia);
} else if (resId == R.string.voices) {
return item.getTargetFileName().contains("tts") ? activity.getString(R.string.ttsvoice) : activity
.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);
} else if (resId == R.string.download_srtm_maps){
} else if (resId == 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 "";

View file

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