make ApkProvider.Helper take Context rather than ContentResolver

This makes the code a bit neater, and passing the Context around is a
common pattern.

https://dev.guardianproject.info/issues/2926
refs #2926
This commit is contained in:
Hans-Christoph Steiner 2014-02-18 16:41:28 -05:00
parent ab6166c36d
commit a4de616b7a
3 changed files with 8 additions and 6 deletions

View File

@ -92,7 +92,7 @@ public class AppDetails extends ListActivity {
public ApkListAdapter(Context context, App app) {
super(context, 0);
List<Apk> apks = ApkProvider.Helper.findByApp(context.getContentResolver(), app.id);
List<Apk> apks = ApkProvider.Helper.findByApp(context, app.id);
for (Apk apk : apks ) {
if (apk.compatible || pref_incompatibleVersions) {
add(apk);

View File

@ -545,7 +545,7 @@ public class UpdateService extends IntentService implements ProgressListener {
ApkProvider.DataColumns.VERSION,
ApkProvider.DataColumns.VERSION_CODE
};
return ApkProvider.Helper.knownApks(getContentResolver(), apks, fields);
return ApkProvider.Helper.knownApks(this, apks, fields);
}
private void updateOrInsertApps(List<App> appsToUpdate, int totalUpdateCount, int currentCount) {

View File

@ -111,12 +111,13 @@ public class ApkProvider extends FDroidProvider {
resolver.delete(uri, null, null);
}
public static List<Apk> findByApp(ContentResolver resolver, String appId) {
return findByApp(resolver, appId, ApkProvider.DataColumns.ALL);
public static List<Apk> findByApp(Context context, String appId) {
return findByApp(context, appId, ApkProvider.DataColumns.ALL);
}
public static List<Apk> findByApp(ContentResolver resolver,
public static List<Apk> findByApp(Context context,
String appId, String[] projection) {
ContentResolver resolver = context.getContentResolver();
Uri uri = getAppUri(appId);
String sort = ApkProvider.DataColumns.VERSION_CODE + " DESC";
Cursor cursor = resolver.query(uri, projection, null, null, sort);
@ -127,8 +128,9 @@ public class ApkProvider extends FDroidProvider {
* Returns apks in the database, which have the same id and version as
* one of the apks in the "apks" argument.
*/
public static List<Apk> knownApks(ContentResolver resolver,
public static List<Apk> knownApks(Context context,
List<Apk> apks, String[] fields) {
ContentResolver resolver = context.getContentResolver();
Uri uri = getContentUri(apks);
Cursor cursor = resolver.query(uri, fields, null, null, null);
return cursorToList(cursor);