diff --git a/OsmAnd/res/layout/update_index.xml b/OsmAnd/res/layout/update_index.xml
index 8564e7877a..0ea43fe90f 100644
--- a/OsmAnd/res/layout/update_index.xml
+++ b/OsmAnd/res/layout/update_index.xml
@@ -14,6 +14,7 @@
diff --git a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java
index 82a19d4907..bd195d3524 100644
--- a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java
+++ b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java
@@ -36,28 +36,37 @@ public class UpdatesIndexFragment extends ListFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.update_index, container, false);
- CheckBox selectAll = (CheckBox) view.findViewById(R.id.select_all);
- selectAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ final CheckBox selectAll = (CheckBox) view.findViewById(R.id.select_all);
+ selectAll.setOnClickListener(new View.OnClickListener() {
@Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- for (IndexItem item : indexItems) {
- if (isChecked) {
- List download = item.createDownloadEntry(getMyApplication(), item.getType(), new ArrayList());
- if (download.size() > 0) {
- getDownloadActivity().getEntriesToDownload().put(item, download);
- getDownloadActivity().updateDownloadButton(true);
- }
- } else {
- getDownloadActivity().getEntriesToDownload().remove(item);
- getDownloadActivity().updateDownloadButton(true);
- }
- }
+ public void onClick(View v) {
+ if (selectAll.isChecked()) {
+ selectAll();
+ } else {
+ deselectAll();
+ }
+ listAdapter.notifyDataSetInvalidated();
}
});
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 (!getDownloadActivity().getEntriesToDownload().containsKey(item)){
+ selectAll.setChecked(false);
+ return;
+ }
+ }
+ selectAll.setChecked(true);
+ }
+
private void setSelectAllVisibility(boolean visible) {
View view = getView();
if (view == null) {
@@ -133,15 +142,15 @@ public class UpdatesIndexFragment extends ListFragment {
ch.setChecked(!ch.isChecked());
getDownloadActivity().getEntriesToDownload().remove(e);
getDownloadActivity().updateDownloadButton(true);
- return;
- }
-
- List download = e.createDownloadEntry(getMyApplication(), e.getType(), new ArrayList());
- if (download.size() > 0) {
- getDownloadActivity().getEntriesToDownload().put(e, download);
- getDownloadActivity().updateDownloadButton(true);
- ch.setChecked(!ch.isChecked());
+ } else {
+ List download = e.createDownloadEntry(getMyApplication(), e.getType(), new ArrayList());
+ if (download.size() > 0) {
+ getDownloadActivity().getEntriesToDownload().put(e, download);
+ getDownloadActivity().updateDownloadButton(true);
+ ch.setChecked(!ch.isChecked());
+ }
}
+ refreshSelectAll();
}
public DownloadActivity getDownloadActivity() {
@@ -158,11 +167,6 @@ public class UpdatesIndexFragment extends ListFragment {
MenuItem item = menu.add(0, DownloadIndexFragment.RELOAD_ID, 0, R.string.update_downlod_list);
item.setIcon(R.drawable.ic_action_refresh_dark);
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
- SubMenu s = menu.addSubMenu(0, DownloadIndexFragment.MORE_ID, 0, "");
- s.setIcon(R.drawable.ic_overflow_menu_white);
- s.add(0, DownloadIndexFragment.SELECT_ALL_ID, 0, R.string.select_all);
- s.add(0, DownloadIndexFragment.DESELECT_ALL_ID, 0, R.string.deselect_all);
- MenuItemCompat.setShowAsAction(s.getItem(), MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
}