Merge branch 'fix/update-notification' into 'master'
Fix/update notification In addition to making update notifications work again (fixing issue #20) I also removed an unused class, and made the update count easily accessible from the AppProvider.Helper class.
This commit is contained in:
		
						commit
						fbf9d4b409
					
				| @ -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<App> 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<App> 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); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -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<App> all(ContentResolver resolver) { | ||||
|             return all(resolver, DataColumns.ALL); | ||||
|         } | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Daniel Martí
						Daniel Martí