Correctly select swappable apps from list.

Previously, there was a bug with an off-by-one error, as android-11
or later was treating the headerView different to android-10 and
earlier. They now both have the same understanding about the header
view.
This commit is contained in:
Peter Serwylo 2015-04-02 16:20:23 +11:00
parent 9db556f4b7
commit d62a3c711d

View File

@ -30,7 +30,7 @@ public class SelectAppsFragment extends ThemeableListFragment
implements LoaderManager.LoaderCallbacks<Cursor>, SearchView.OnQueryTextListener { implements LoaderManager.LoaderCallbacks<Cursor>, SearchView.OnQueryTextListener {
@SuppressWarnings("UnusedDeclaration") @SuppressWarnings("UnusedDeclaration")
private static final String TAG = "org.fdroid.fdroid.views.swap.SelectAppsFragment"; private static final String TAG = "fdroid.SwapAppsList";
private String mCurrentFilterString; private String mCurrentFilterString;
@ -124,11 +124,14 @@ public class SelectAppsFragment extends ThemeableListFragment
@Override @Override
public void onListItemClick(ListView l, View v, int position, long id) { public void onListItemClick(ListView l, View v, int position, long id) {
toggleAppSelected(position); // Ignore the headerView at position 0.
if (position > 0) {
toggleAppSelected(position);
}
} }
private void toggleAppSelected(int position) { private void toggleAppSelected(int position) {
Cursor c = (Cursor) getListAdapter().getItem(position); Cursor c = (Cursor) getListAdapter().getItem(position - 1);
String packageName = c.getString(c.getColumnIndex(InstalledAppProvider.DataColumns.APP_ID)); String packageName = c.getString(c.getColumnIndex(InstalledAppProvider.DataColumns.APP_ID));
if (FDroidApp.selectedApps.contains(packageName)) { if (FDroidApp.selectedApps.contains(packageName)) {
FDroidApp.selectedApps.remove(packageName); FDroidApp.selectedApps.remove(packageName);
@ -254,7 +257,7 @@ public class SelectAppsFragment extends ThemeableListFragment
@Override @Override
public View newView(Context context, Cursor cursor, ViewGroup parent) { public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = getInflater(context).inflate(R.layout.select_local_apps_list_item, null); View view = getInflater(context).inflate(R.layout.select_local_apps_list_item, parent, false);
bindView(view, context, cursor); bindView(view, context, cursor);
return view; return view;
} }
@ -288,7 +291,6 @@ public class SelectAppsFragment extends ThemeableListFragment
CheckBox checkBox = (CheckBox)checkBoxView; CheckBox checkBox = (CheckBox)checkBoxView;
checkBox.setOnCheckedChangeListener(null); checkBox.setOnCheckedChangeListener(null);
final int cursorPosition = cursor.getPosition();
final int listPosition = cursor.getPosition() + 1; // To account for the header view. final int listPosition = cursor.getPosition() + 1; // To account for the header view.
checkBox.setChecked(listView.isItemChecked(listPosition)); checkBox.setChecked(listView.isItemChecked(listPosition));
@ -296,7 +298,7 @@ public class SelectAppsFragment extends ThemeableListFragment
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
listView.setItemChecked(listPosition, isChecked); listView.setItemChecked(listPosition, isChecked);
toggleAppSelected(cursorPosition); toggleAppSelected(listPosition);
} }
}); });
} }