From 826854592f48451aab8ba3ad103b8702bb9d4c1f Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Wed, 30 Apr 2014 21:17:16 +0930 Subject: [PATCH] Made app update notifications work again. The update service now queries the app provider for installed apps which can and want to be updated. --- src/org/fdroid/fdroid/UpdateService.java | 36 ++++-------------- src/org/fdroid/fdroid/data/AppProvider.java | 12 ++++++ .../views/AppListFragmentPageAdapter.java | 17 ++------- src/org/fdroid/fdroid/views/AppListView.java | 37 ------------------- 4 files changed, 23 insertions(+), 79 deletions(-) delete mode 100644 src/org/fdroid/fdroid/views/AppListView.java diff --git a/src/org/fdroid/fdroid/UpdateService.java b/src/org/fdroid/fdroid/UpdateService.java index 7992264aa..6817936f8 100644 --- a/src/org/fdroid/fdroid/UpdateService.java +++ b/src/org/fdroid/fdroid/UpdateService.java @@ -18,8 +18,6 @@ package org.fdroid.fdroid; -import java.util.*; - import android.app.*; import android.content.*; import android.content.SharedPreferences.Editor; @@ -29,14 +27,15 @@ import android.net.NetworkInfo; import android.net.Uri; import android.os.*; import android.preference.PreferenceManager; +import android.support.v4.app.NotificationCompat; +import android.support.v4.app.TaskStackBuilder; import android.text.TextUtils; import android.util.Log; +import android.widget.Toast; import org.fdroid.fdroid.data.*; import org.fdroid.fdroid.updater.RepoUpdater; -import android.support.v4.app.NotificationCompat; -import android.support.v4.app.TaskStackBuilder; -import android.widget.Toast; +import java.util.*; public class UpdateService extends IntentService implements ProgressListener { @@ -388,30 +387,9 @@ public class UpdateService extends IntentService implements ProgressListener { } private void performUpdateNotification(Collection apps) { - int updateCount = 0; - - // This may be somewhat strange, because we usually would just trust - // App.canAndWantToUpdate(). The only problem is that the "appsToUpdate" - // list only contains data from the repo index, not our database. - // As such, it doesn't know if we want to ignore the apps or not. For that, we - // need to query the database manually and identify those which are to be ignored. - String[] projection = { AppProvider.DataColumns.APP_ID }; - List appsToIgnore = AppProvider.Helper.findIgnored(this, projection); - for (App app : apps) { - boolean ignored = false; - for (App appIgnored : appsToIgnore) { - if (appIgnored.id.equals(app.id)) { - ignored = true; - break; - } - } - if (!ignored && app.hasUpdates()) { - updateCount++; - } - } - - if (updateCount > 0) { - showAppUpdatesNotification(updateCount); + int count = AppProvider.Helper.count(this, AppProvider.getCanUpdateUri()); + if (count > 0) { + showAppUpdatesNotification(count); } } diff --git a/src/org/fdroid/fdroid/data/AppProvider.java b/src/org/fdroid/fdroid/data/AppProvider.java index e7a0398a7..1b0fbaa76 100644 --- a/src/org/fdroid/fdroid/data/AppProvider.java +++ b/src/org/fdroid/fdroid/data/AppProvider.java @@ -18,6 +18,18 @@ public class AppProvider extends FDroidProvider { private Helper() {} + public static int count(Context context, Uri uri) { + String[] projection = new String[] { AppProvider.DataColumns._COUNT }; + Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); + int count = 0; + if (cursor != null && cursor.getCount() == 1) { + cursor.moveToFirst(); + count = cursor.getInt(0); + cursor.close(); + } + return count; + } + public static List all(ContentResolver resolver) { return all(resolver, DataColumns.ALL); } diff --git a/src/org/fdroid/fdroid/views/AppListFragmentPageAdapter.java b/src/org/fdroid/fdroid/views/AppListFragmentPageAdapter.java index b05c0e940..4313dec77 100644 --- a/src/org/fdroid/fdroid/views/AppListFragmentPageAdapter.java +++ b/src/org/fdroid/fdroid/views/AppListFragmentPageAdapter.java @@ -1,10 +1,7 @@ package org.fdroid.fdroid.views; -import android.database.Cursor; -import android.net.Uri; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentPagerAdapter; - import org.fdroid.fdroid.FDroid; import org.fdroid.fdroid.R; import org.fdroid.fdroid.data.AppProvider; @@ -26,16 +23,10 @@ public class AppListFragmentPageAdapter extends FragmentPagerAdapter { } private String getUpdateTabTitle() { - Uri uri = AppProvider.getCanUpdateUri(); - String[] projection = new String[] { AppProvider.DataColumns._COUNT }; - Cursor cursor = parent.getContentResolver().query(uri, projection, null, null, null); - String suffix = ""; - if (cursor != null && cursor.getCount() == 1) { - cursor.moveToFirst(); - int count = cursor.getInt(0); - suffix = " (" + count + ")"; - } - return parent.getString(R.string.tab_updates) + suffix; + int updateCount = AppProvider.Helper.count(parent, AppProvider.getCanUpdateUri()); + + // TODO: Make RTL friendly, probably by having a different string for both tab_updates_none and tab_updates + return parent.getString(R.string.tab_updates) + " (" + updateCount + ")"; } @Override diff --git a/src/org/fdroid/fdroid/views/AppListView.java b/src/org/fdroid/fdroid/views/AppListView.java deleted file mode 100644 index b65f50cc3..000000000 --- a/src/org/fdroid/fdroid/views/AppListView.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.fdroid.fdroid.views; - -import android.content.Context; -import android.util.AttributeSet; -import android.widget.LinearLayout; -import android.widget.ListView; - -/** - * There are three main app-lists in the UI: - * - Available - * - Installed - * - Apps which can be updated - * This class provides a View which knows about these app lists, but can have - * different contents (e.g. a drop down list of categories). It allows us to - * get a reference to the selected item in the FDroid Activity, without having - * to know which list we are actually looking at. - */ -public class AppListView extends LinearLayout { - - private ListView appList; - - public AppListView(Context context) { - super(context); - } - - public AppListView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public void setAppList(ListView appList) { - this.appList = appList; - } - - public ListView getAppList() { - return appList; - } -}