Refactor AppsListFragment

This commit is contained in:
Dominik Schürmann 2015-02-23 21:55:44 +01:00
parent 2064d81aef
commit 29628e54ec

View File

@ -48,7 +48,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
public class AppsListFragment extends ListFragment implements public class AppsListFragment extends ListFragment implements
LoaderManager.LoaderCallbacks<Cursor> { LoaderManager.LoaderCallbacks<Cursor>, OnItemClickListener {
AppsAdapter mAdapter; AppsAdapter mAdapter;
@ -56,9 +56,33 @@ public class AppsListFragment extends ListFragment implements
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
getListView().setOnItemClickListener(new OnItemClickListener() { getListView().setOnItemClickListener(this);
// NOTE: No setEmptyText(), we always have the default entries
// We have a menu item to show in action bar.
setHasOptionsMenu(true);
// Create an empty adapter we will use to display the loaded data.
mAdapter = new AppsAdapter(getActivity(), null, 0);
setListAdapter(mAdapter);
// NOTE: Loader is started in onResume!
}
@Override @Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { public void onResume() {
super.onResume();
// Start out with a progress indicator.
setListShown(false);
// After coming back from Google Play -> reload
getLoaderManager().restartLoader(0, null, this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedPackageName = mAdapter.getItemPackageName(position); String selectedPackageName = mAdapter.getItemPackageName(position);
boolean installed = mAdapter.getItemIsInstalled(position); boolean installed = mAdapter.getItemIsInstalled(position);
boolean registered = mAdapter.getItemIsRegistered(position); boolean registered = mAdapter.getItemIsRegistered(position);
@ -95,30 +119,6 @@ public class AppsListFragment extends ListFragment implements
} }
} }
} }
});
// NOTE: No setEmptyText(), we always have the default entries
// We have a menu item to show in action bar.
setHasOptionsMenu(true);
// Create an empty adapter we will use to display the loaded data.
mAdapter = new AppsAdapter(getActivity(), null, 0);
setListAdapter(mAdapter);
// NOTE: Loader is started in onResume!
}
@Override
public void onResume() {
super.onResume();
// Start out with a progress indicator.
setListShown(false);
// After coming back from Google Play -> reload
getLoaderManager().restartLoader(0, null, this);
}
private static final String TEMP_COLUMN_NAME = "NAME"; private static final String TEMP_COLUMN_NAME = "NAME";
private static final String TEMP_COLUMN_INSTALLED = "INSTALLED"; private static final String TEMP_COLUMN_INSTALLED = "INSTALLED";