diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java index c88ab49a92..96cda1baaf 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java @@ -98,7 +98,7 @@ public class LocalIndexHelper { loadTilesData(app.getAppPath(IndexConstants.TILES_INDEX_DIR), result, false, loadTask); loadSrtmData(app.getAppPath(IndexConstants.SRTM_INDEX_DIR), result, loadTask); loadWikiData(app.getAppPath(IndexConstants.WIKI_INDEX_DIR), result, loadTask); - loadVoiceData(app.getAppPath(IndexConstants.TTSVOICE_INDEX_EXT_ZIP), result, true, loadTask); + //loadVoiceData(app.getAppPath(IndexConstants.TTSVOICE_INDEX_EXT_ZIP), result, true, loadTask); loadVoiceData(app.getAppPath(IndexConstants.VOICE_INDEX_DIR), result, false, loadTask); return result; @@ -213,7 +213,8 @@ public class LocalIndexHelper { SRTM_DATA(R.string.local_indexes_cat_srtm, R.drawable.ic_plugin_srtm), WIKI_DATA(R.string.local_indexes_cat_wiki, R.drawable.ic_plugin_wikipedia), TTS_VOICE_DATA(R.string.local_indexes_cat_tts, R.drawable.ic_action_volume_up), - VOICE_DATA(R.string.local_indexes_cat_voice, R.drawable.ic_action_volume_up); + VOICE_DATA(R.string.local_indexes_cat_voice, R.drawable.ic_action_volume_up), + DEACTIVATED(R.string.local_indexes_cat_backup, R.drawable.ic_type_archive); // AV_DATA(R.string.local_indexes_cat_av);; @StringRes diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java index bd94e39c8d..90b46534f5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java @@ -120,6 +120,10 @@ public class LocalIndexInfo { } public LocalIndexType getType() { + return backupedData ? LocalIndexType.DEACTIVATED : type; + } + + public LocalIndexType getOriginalType() { return type; } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index 974807988c..87bc425d11 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -60,6 +60,7 @@ public class ItemViewHolder { boolean showTypeInDesc; boolean showTypeInName; + boolean showParentRegionName; boolean showRemoteDate; boolean silentCancelDownload; boolean showProgressInDesc; @@ -99,6 +100,11 @@ public class ItemViewHolder { this.showRemoteDate = showRemoteDate; } + + public void setShowParentRegionName(boolean showParentRegionName) { + this.showParentRegionName = showParentRegionName; + } + public void setShowProgressInDescr(boolean b) { showProgressInDesc = b; } @@ -137,7 +143,7 @@ public class ItemViewHolder { if(showTypeInName) { nameTextView.setText(indexItem.getType().getString(context)); } else { - nameTextView.setText(indexItem.getVisibleName(context, context.getMyApplication().getRegions(), false)); + nameTextView.setText(indexItem.getVisibleName(context, context.getMyApplication().getRegions(), showParentRegionName)); } if(!disabled) { nameTextView.setTextColor(textColorPrimary); diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index a8ae4fe2fb..317ce4d74e 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -1,5 +1,45 @@ package net.osmand.plus.download.ui; +import java.io.File; +import java.text.Collator; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import net.osmand.IndexConstants; +import net.osmand.PlatformUtil; +import net.osmand.access.AccessibleToast; +import net.osmand.plus.ContextMenuAdapter; +import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.IconsCache; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.R; +import net.osmand.plus.activities.LocalIndexHelper; +import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType; +import net.osmand.plus.activities.LocalIndexInfo; +import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; +import net.osmand.plus.activities.OsmandExpandableListFragment; +import net.osmand.plus.dialogs.DirectionsDialogs; +import net.osmand.plus.download.DownloadActivity; +import net.osmand.plus.download.DownloadActivityType; +import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; +import net.osmand.plus.download.IndexItem; +import net.osmand.plus.helpers.FileNameTranslationHelper; +import net.osmand.plus.resources.IncrementalChangesManager; +import net.osmand.plus.resources.IncrementalChangesManager.IncrementalUpdate; +import net.osmand.plus.resources.IncrementalChangesManager.IncrementalUpdateList; +import net.osmand.util.Algorithms; + +import org.apache.commons.logging.Log; + import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; @@ -34,51 +74,10 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; -import net.osmand.IProgress; -import net.osmand.IndexConstants; -import net.osmand.PlatformUtil; -import net.osmand.access.AccessibleToast; -import net.osmand.plus.ContextMenuAdapter; -import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; -import net.osmand.plus.IconsCache; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.R; -import net.osmand.plus.activities.LocalIndexHelper; -import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType; -import net.osmand.plus.activities.LocalIndexInfo; -import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; -import net.osmand.plus.activities.OsmandExpandableListFragment; -import net.osmand.plus.dialogs.DirectionsDialogs; -import net.osmand.plus.download.DownloadActivity; -import net.osmand.plus.download.DownloadActivityType; -import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; -import net.osmand.plus.download.IndexItem; -import net.osmand.plus.helpers.FileNameTranslationHelper; -import net.osmand.plus.resources.IncrementalChangesManager; -import net.osmand.plus.resources.IncrementalChangesManager.IncrementalUpdate; -import net.osmand.plus.resources.IncrementalChangesManager.IncrementalUpdateList; -import net.osmand.util.Algorithms; - -import org.apache.commons.logging.Log; - -import java.io.File; -import java.text.Collator; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; public class LocalIndexesFragment extends OsmandExpandableListFragment implements DownloadEvents { - private static final Log LOG = PlatformUtil.getLog(LocalIndexesFragment.class); private LoadLocalIndexTask asyncLoader; private Map filesToUpdate = new HashMap(); private LocalIndexesAdapter listAdapter; @@ -94,7 +93,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement private ContextMenuAdapter optionsMenuAdapter; private ActionMode actionMode; - Drawable backup; Drawable sdcard; Drawable planet; @@ -131,11 +129,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement private void colorDrawables() { boolean light = getMyApplication().getSettings().isLightContent(); - backup = getActivity().getResources().getDrawable(R.drawable.ic_type_archive); - backup.mutate(); - if (light) { - backup.setColorFilter(getResources().getColor(R.color.icon_color), PorterDuff.Mode.MULTIPLY); - } sdcard = getActivity().getResources().getDrawable(R.drawable.ic_sdcard); sdcard.mutate(); sdcard.setColorFilter(getActivity().getResources().getColor(R.color.color_distance), PorterDuff.Mode.MULTIPLY); @@ -388,19 +381,21 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement private File getFileToRestore(LocalIndexInfo i) { if (i.isBackupedData()) { File parent = new File(i.getPathToData()).getParentFile(); - if (i.getType() == LocalIndexType.MAP_DATA) { - parent = getMyApplication().getAppPath(IndexConstants.MAPS_PATH); - } else if (i.getFileName().endsWith(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)) { - parent = getMyApplication().getAppPath(IndexConstants.ROADS_INDEX_DIR); - } else if (i.getType() == LocalIndexType.TILES_DATA) { + if (i.getOriginalType() == LocalIndexType.MAP_DATA) { + if (i.getFileName().endsWith(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)) { + parent = getMyApplication().getAppPath(IndexConstants.ROADS_INDEX_DIR); + } else { + parent = getMyApplication().getAppPath(IndexConstants.MAPS_PATH); + } + } else if (i.getOriginalType() == LocalIndexType.TILES_DATA) { parent = getMyApplication().getAppPath(IndexConstants.TILES_INDEX_DIR); - } else if (i.getType() == LocalIndexType.SRTM_DATA) { + } else if (i.getOriginalType() == LocalIndexType.SRTM_DATA) { parent = getMyApplication().getAppPath(IndexConstants.SRTM_INDEX_DIR); - } else if (i.getType() == LocalIndexType.WIKI_DATA) { + } else if (i.getOriginalType() == LocalIndexType.WIKI_DATA) { parent = getMyApplication().getAppPath(IndexConstants.WIKI_INDEX_DIR); - } else if (i.getType() == LocalIndexType.TTS_VOICE_DATA) { + } else if (i.getOriginalType() == LocalIndexType.TTS_VOICE_DATA) { parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR); - } else if (i.getType() == LocalIndexType.VOICE_DATA) { + } else if (i.getOriginalType() == LocalIndexType.VOICE_DATA) { parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR); } return new File(parent, i.getFileName()); @@ -716,7 +711,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement public void onClick(DialogInterface dialog, int which) { doAction(itemId); } - }, null, null); + }, null); } else if (itemId == R.string.local_index_mi_backup) { openSelectionMode(itemId, R.drawable.ic_type_archive, new DialogInterface.OnClickListener() { @@ -725,7 +720,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement public void onClick(DialogInterface dialog, int which) { doAction(itemId); } - }, Boolean.FALSE, LocalIndexType.MAP_DATA); + }, EnumSet.of(LocalIndexType.MAP_DATA, LocalIndexType.WIKI_DATA, LocalIndexType.SRTM_DATA)); } else if (itemId == R.string.local_index_mi_restore) { openSelectionMode(itemId, R.drawable.ic_type_archive, new DialogInterface.OnClickListener() { @@ -734,16 +729,12 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement public void onClick(DialogInterface dialog, int which) { doAction(itemId); } - }, Boolean.TRUE, LocalIndexType.MAP_DATA); - listAdapter.filterCategories(true); + }, EnumSet.of(LocalIndexType.DEACTIVATED)); } } - public void openSelectionMode(int stringRes, int darkIcon, DialogInterface.OnClickListener listener, Boolean backup, - LocalIndexType filter) { - if (backup != null) { - listAdapter.filterCategories(backup); - } + public void openSelectionMode(int stringRes, int darkIcon, DialogInterface.OnClickListener listener, + EnumSet filter) { if (filter != null) { listAdapter.filterCategories(filter); } @@ -838,14 +829,12 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement notifyDataSetChanged(); } - public void filterCategories(LocalIndexType... types) { + public void filterCategories(EnumSet types) { List filter = new ArrayList(); List source = filterCategory == null ? category : filterCategory; for (LocalIndexInfo info : source) { - for (LocalIndexType ts : types) { - if (info.getType() == ts) { - filter.add(info); - } + if(types.contains(info.getType())) { + filter.add(info); } } filterCategory = filter; @@ -934,7 +923,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement name.append(" ").append(group.getSubfolder()); } if (group.isBackupedData()) { - name.append(" - ").append(ctx.getString(R.string.local_indexes_cat_backup)); + ctx.getString(R.string.local_indexes_cat_backup); } TextView nameView = ((TextView) v.findViewById(R.id.section_name)); TextView sizeView = ((TextView) v.findViewById(R.id.section_description)); @@ -1035,12 +1024,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement openPopUpMenu(v, child); } }); - if (child.isBackupedData()) { - icon.setImageDrawable(backup); - } else { - int colorId = filesToUpdate.containsKey(child.getFileName()) ? R.color.color_distance : R.color.color_ok; - icon.setImageDrawable(getContentIcon(ctx, child.getType().getIconResource(), colorId)); - } + int colorId = filesToUpdate.containsKey(child.getFileName()) ? R.color.color_distance : R.color.color_ok; + icon.setImageDrawable(getContentIcon(ctx, child.getType().getIconResource(), colorId)); nameTextView.setText(getNameToDisplay(child)); if (child.isNotSupported()) { @@ -1120,7 +1105,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement MenuItem item; if (info.getType() == LocalIndexType.MAP_DATA) { item = optionsMenu.getMenu().add(restore ? R.string.local_index_mi_restore : R.string.local_index_mi_backup) - .setIcon(backup); + .setIcon(iconsCache.getContentIcon(R.drawable.ic_type_archive)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { diff --git a/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java index a4b78919b5..cbbcc88e74 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java @@ -11,6 +11,7 @@ import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.IndexItem; +import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.support.v4.view.MenuItemCompat; @@ -33,9 +34,9 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - invalidateListView(); setHasOptionsMenu(true); } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -47,6 +48,12 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download super.onActivityCreated(savedInstanceState); updateErrorMessage(); } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + invalidateListView(activity); + } @Override public ArrayAdapter getAdapter() { @@ -55,7 +62,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download @Override public void downloadHasFinished() { - invalidateListView(); + invalidateListView(getMyActivity()); updateUpdateAllButton(); } @@ -66,17 +73,17 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download @Override public void newDownloadIndexes() { - invalidateListView(); + invalidateListView(getMyActivity()); updateUpdateAllButton(); } - public void invalidateListView() { - DownloadResources indexes = getMyActivity().getDownloadThread().getIndexes(); + public void invalidateListView(Activity a) { + DownloadResources indexes = getMyApplication().getDownloadThread().getIndexes(); List indexItems = indexes.getItemsToUpdate(); final OsmandRegions osmandRegions = getMyApplication().getResourceManager().getOsmandRegions(); - listAdapter = new UpdateIndexAdapter(getMyActivity(), R.layout.download_index_list_item, indexItems); + listAdapter = new UpdateIndexAdapter(a, R.layout.download_index_list_item, indexItems); listAdapter.sort(new Comparator() { @Override public int compare(IndexItem indexItem, IndexItem indexItem2) { @@ -198,6 +205,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download ItemViewHolder holder = (ItemViewHolder) v.getTag(); holder.setShowRemoteDate(true); holder.setShowTypeInDesc(true); + holder.setShowParentRegionName(true); holder.bindIndexItem(items.get(position), null); return v; }