From: David A. Velasco Date: Mon, 23 Jul 2012 10:47:58 +0000 (+0200) Subject: Filter broadcast messages in receivers with the account, to avoid problems with servi... X-Git-Tag: oc-android-1.4.3~250 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/8ba2ca7b8556de4aea4a7a8407a204b4dcfca34c?ds=inline Filter broadcast messages in receivers with the account, to avoid problems with services ongoing after the current account is changed --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a3d120dc..c0082bfc 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -18,7 +18,7 @@ --> + android:versionName="0.1.174B" xmlns:android="http://schemas.android.com/apk/res/android"> diff --git a/src/eu/alefzero/owncloud/files/services/FileDownloader.java b/src/eu/alefzero/owncloud/files/services/FileDownloader.java index cc66e382..d08e7279 100644 --- a/src/eu/alefzero/owncloud/files/services/FileDownloader.java +++ b/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) { diff --git a/src/eu/alefzero/owncloud/files/services/FileUploader.java b/src/eu/alefzero/owncloud/files/services/FileUploader.java index 9f480fc0..93ee82ff 100644 --- a/src/eu/alefzero/owncloud/files/services/FileUploader.java +++ b/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); } diff --git a/src/eu/alefzero/owncloud/syncadapter/FileSyncService.java b/src/eu/alefzero/owncloud/syncadapter/FileSyncService.java index 42eaf6c4..5396f582 100644 --- a/src/eu/alefzero/owncloud/syncadapter/FileSyncService.java +++ b/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} diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index c8e32978..6bc0b0fc 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/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(); diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index 156e66ef..2f694f2a 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/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)) {