From 010014fe68806e83944b9e8dab328e368526c4ac Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Thu, 15 Oct 2015 12:18:45 +0300 Subject: [PATCH] UpdatesIndexFragment fixed updates --- .../plus/download/UpdatesIndexFragment.java | 74 ++++++------------- .../plus/download/items/ItemViewHolder.java | 18 ++--- 2 files changed, 31 insertions(+), 61 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java index c231c1bdd5..566e3bf76d 100644 --- a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java @@ -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; @@ -43,28 +42,6 @@ public class UpdatesIndexFragment extends OsmAndListFragment { private UpdateIndexAdapter listAdapter; List 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); @@ -75,6 +52,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) { @@ -94,7 +76,8 @@ public class UpdatesIndexFragment extends OsmAndListFragment { setListAdapter(listAdapter); } - private void updateHeader(){ + private void updateHeader() { + osmandRegions = getMyApplication().getRegions(); View view = getView(); if (getView() == null) { return; @@ -119,25 +102,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 download = e.createDownloadEntry(getMyApplication(), e.getType(), new ArrayList()); - if (download.size() > 0) { - getMyActivity().getEntriesToDownload().put(e, download); - getMyActivity().updateFragments(); - ch.setChecked(!ch.isChecked()); - } - } - refreshSelectAll(); + getMyActivity().startDownload(e); } public DownloadActivity getMyActivity() { @@ -293,8 +259,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(); @@ -304,36 +270,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 ""; diff --git a/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java index 47591e2135..908576a13c 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java @@ -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); }