Updated select all button in updates

This commit is contained in:
Bars107 2015-02-17 12:29:53 +02:00
parent c916d94070
commit e72e6202f0
2 changed files with 33 additions and 28 deletions

View file

@ -14,6 +14,7 @@
<CheckBox
android:id="@+id/select_all"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

View file

@ -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<DownloadEntry> download = item.createDownloadEntry(getMyApplication(), item.getType(), new ArrayList<DownloadEntry>());
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<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), e.getType(), new ArrayList<DownloadEntry>());
if (download.size() > 0) {
getDownloadActivity().getEntriesToDownload().put(e, download);
getDownloadActivity().updateDownloadButton(true);
ch.setChecked(!ch.isChecked());
} else {
List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), e.getType(), new ArrayList<DownloadEntry>());
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);
}
}