Ver Fonte

Filter broadcast messages in receivers with the account, to avoid problems with services ongoing after the current account is changed

David A. Velasco há 13 anos atrás
pai
commit
8ba2ca7b85

+ 1 - 1
AndroidManifest.xml

@@ -18,7 +18,7 @@
  -->
 <manifest package="eu.alefzero.owncloud"
     android:versionCode="1"
-    android:versionName="0.1.173B" xmlns:android="http://schemas.android.com/apk/res/android">
+    android:versionName="0.1.174B" xmlns:android="http://schemas.android.com/apk/res/android">
 
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />

+ 3 - 0
src/eu/alefzero/owncloud/files/services/FileDownloader.java

@@ -25,6 +25,7 @@ import eu.alefzero.owncloud.R;
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
 import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
 import eu.alefzero.owncloud.files.interfaces.OnDatatransferProgressListener;
+import eu.alefzero.owncloud.syncadapter.FileSyncService;
 import eu.alefzero.webdav.WebdavClient;
 
 public class FileDownloader extends Service implements OnDatatransferProgressListener {
@@ -34,6 +35,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
     public static final String EXTRA_FILE_PATH = "FILE_PATH";
     public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
     public static final String EXTRA_FILE_SIZE = "FILE_SIZE";
+    public static final String ACCOUNT_NAME = "ACCOUNT_NAME";    
     private static final String TAG = "FileDownloader";
 
     private NotificationManager mNotificationMngr;
@@ -150,6 +152,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
         end.putExtra(EXTRA_REMOTE_PATH, mRemotePath);
         end.putExtra(EXTRA_FILE_PATH, file.getAbsolutePath());
         end.putExtra(EXTRA_DOWNLOAD_RESULT, download_result);
+        end.putExtra(ACCOUNT_NAME, mAccount.name);
         sendBroadcast(end);
 
         if (download_result) {

+ 2 - 0
src/eu/alefzero/owncloud/files/services/FileUploader.java

@@ -37,6 +37,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
     public static final String KEY_REMOTE_FILE = "REMOTE_FILE";
     public static final String KEY_ACCOUNT = "ACCOUNT";
     public static final String KEY_UPLOAD_TYPE = "UPLOAD_TYPE";
+    public static final String ACCOUNT_NAME = "ACCOUNT_NAME";    
 
     public static final int UPLOAD_SINGLE_FILE = 0;
     public static final int UPLOAD_MULTIPLE_FILES = 1;
@@ -187,6 +188,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
                 
                 Intent end = new Intent(UPLOAD_FINISH_MESSAGE);
                 end.putExtra(EXTRA_PARENT_DIR_ID, parentDirId);
+                end.putExtra(ACCOUNT_NAME, mAccount.name);
                 sendBroadcast(end);
             }
             

+ 4 - 4
src/eu/alefzero/owncloud/syncadapter/FileSyncService.java

@@ -28,10 +28,10 @@ import android.os.IBinder;
  * 
  */
 public class FileSyncService extends Service {
-    public static final String SYNC_MESSAGE = "eu.alefzero.owncloud.files.ACCOUNT_SYNC";
-    public static final String SYNC_FOLDER_REMOTE_PATH = "eu.alefzero.owncloud.files.SYNC_FOLDER_REMOTE_PATH";
-    public static final String IN_PROGRESS = "sync_in_progress";
-    public static final String ACCOUNT_NAME = "account_name";
+    public static final String SYNC_MESSAGE = "ACCOUNT_SYNC";
+    public static final String SYNC_FOLDER_REMOTE_PATH = "SYNC_FOLDER_REMOTE_PATH";
+    public static final String IN_PROGRESS = "SYNC_IN_PROGRESS";
+    public static final String ACCOUNT_NAME = "ACCOUNT_NAME";
 
     /*
      * {@inheritDoc}

+ 14 - 8
src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java

@@ -639,13 +639,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         public void onReceive(Context context, Intent intent) {
             boolean inProgress = intent.getBooleanExtra(
                     FileSyncService.IN_PROGRESS, false);
-            String account_name = intent
+            String accountName = intent
                     .getStringExtra(FileSyncService.ACCOUNT_NAME);
 
-            Log.d("FileDisplay", "sync of account " + account_name
+            Log.d("FileDisplay", "sync of account " + accountName
                     + " is in_progress: " + inProgress);
 
-            if (account_name.equals(AccountUtils.getCurrentOwnCloudAccount(context).name)) {  
+            if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name)) {  
             
                 String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH); 
                  
@@ -683,10 +683,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         public void onReceive(Context context, Intent intent) {
             long parentDirId = intent.getLongExtra(FileUploader.EXTRA_PARENT_DIR_ID, -1);
             OCFile parentDir = mStorageManager.getFileById(parentDirId);
-            
-            if (parentDir != null && (
-                    (mCurrentDir == null && parentDir.getFileName().equals("/")) ||
-                     parentDir.equals(mCurrentDir))
+            String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
+
+            if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) &&
+                    parentDir != null && 
+                    (   (mCurrentDir == null && parentDir.getFileName().equals("/")) ||
+                            parentDir.equals(mCurrentDir)
+                    )
                 ) {
                 FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
                 if (fileListFragment != null) { 
@@ -706,7 +709,10 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         public void onReceive(Context context, Intent intent) {
             boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false);
             String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
-            if (downloadWasFine && mCurrentDir != null && mCurrentDir.getFileId() == mStorageManager.getFileByPath(downloadedRemotePath).getParentId()) {
+            String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
+
+            if (accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name) &&
+                    downloadWasFine && mCurrentDir != null && mCurrentDir.getFileId() == mStorageManager.getFileByPath(downloadedRemotePath).getParentId()) {
                 FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
                 if (fileListFragment != null) { 
                     fileListFragment.listDirectory();

+ 4 - 1
src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java

@@ -79,6 +79,7 @@ import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
 import eu.alefzero.owncloud.datamodel.FileDataStorageManager;
 import eu.alefzero.owncloud.datamodel.OCFile;
 import eu.alefzero.owncloud.files.services.FileDownloader;
+import eu.alefzero.owncloud.files.services.FileUploader;
 import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;
 import eu.alefzero.owncloud.utils.OwnCloudVersion;
 import eu.alefzero.webdav.WebdavClient;
@@ -553,7 +554,9 @@ public class FileDetailFragment extends SherlockFragment implements
     private class DownloadFinishReceiver extends BroadcastReceiver {
         @Override
         public void onReceive(Context context, Intent intent) {
-            if (mFile != null) {
+            String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
+
+            if (accountName.equals(mAccount.name) && mFile != null) {
                 boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false);
                 String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
                 if (mFile.getRemotePath().equals(downloadedRemotePath)) {