Fixed bug in access to SYNC_MESSAGE identifier for building broadcast intents in SyncFolderOperation, and added static to remove unnecessary service objects

This commit is contained in:
David A. Velasco 2013-10-23 18:44:20 +02:00
parent f88f81e906
commit d0c9ad1091
10 changed files with 26 additions and 55 deletions

View file

@ -52,9 +52,6 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log_OC.d(TAG, "Received: " + intent.getAction());
FileUploader fileUploader = new FileUploader();
if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {
handleConnectivityAction(context, intent);
}else if (intent.getAction().equals(NEW_PHOTO_ACTION_UNOFFICIAL)) {
@ -63,7 +60,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
} else if (intent.getAction().equals(NEW_PHOTO_ACTION)) {
handleNewPhotoAction(context, intent);
Log_OC.d(TAG, "OFFICIAL processed: android.hardware.action.NEW_PICTURE");
} else if (intent.getAction().equals(fileUploader.getUploadFinishMessage())) {
} else if (intent.getAction().equals(FileUploader.getUploadFinishMessage())) {
handleUploadFinished(context, intent);
} else {
Log_OC.e(TAG, "Incorrect intent sent: " + intent.getAction());

View file

@ -92,12 +92,12 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
private int mLastPercent;
public String getDownloadAddedMessage() {
return getClass().getName().toString() + DOWNLOAD_ADDED_MESSAGE;
public static String getDownloadAddedMessage() {
return FileDownloader.class.getName().toString() + DOWNLOAD_ADDED_MESSAGE;
}
public String getDownloadFinishMessage() {
return getClass().getName().toString() + DOWNLOAD_FINISH_MESSAGE;
public static String getDownloadFinishMessage() {
return FileDownloader.class.getName().toString() + DOWNLOAD_FINISH_MESSAGE;
}
/**

View file

@ -57,9 +57,6 @@ public class FileObserverService extends Service {
private static DownloadCompletedReceiverBis mDownloadReceiver;
private IBinder mBinder = new LocalBinder();
private String mDownloadAddedMessage;
private String mDownloadFinishMessage;
public class LocalBinder extends Binder {
FileObserverService getService() {
return FileObserverService.this;
@ -71,13 +68,9 @@ public class FileObserverService extends Service {
super.onCreate();
mDownloadReceiver = new DownloadCompletedReceiverBis();
FileDownloader downloader = new FileDownloader();
mDownloadAddedMessage = downloader.getDownloadAddedMessage();
mDownloadFinishMessage= downloader.getDownloadFinishMessage();
IntentFilter filter = new IntentFilter();
filter.addAction(mDownloadAddedMessage);
filter.addAction(mDownloadFinishMessage);
filter.addAction(FileDownloader.getDownloadAddedMessage());
filter.addAction(FileDownloader.getDownloadFinishMessage());
registerReceiver(mDownloadReceiver, filter);
mObserversMap = new HashMap<String, OwnCloudFileObserver>();
@ -267,12 +260,12 @@ public class FileObserverService extends Service {
String downloadPath = intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH);
OwnCloudFileObserver observer = mObserversMap.get(downloadPath);
if (observer != null) {
if (intent.getAction().equals(mDownloadFinishMessage) &&
if (intent.getAction().equals(FileDownloader.getDownloadFinishMessage()) &&
new File(downloadPath).exists()) { // the download could be successful. not; in both cases, the file could be down, due to a former download or upload
observer.startWatching();
Log_OC.d(TAG, "Watching again " + downloadPath);
} else if (intent.getAction().equals(mDownloadAddedMessage)) {
} else if (intent.getAction().equals(FileDownloader.getDownloadAddedMessage())) {
observer.stopWatching();
Log_OC.d(TAG, "Disabling observance of " + downloadPath);
}

View file

@ -129,8 +129,8 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
private RemoteViews mDefaultNotificationContentView;
public String getUploadFinishMessage() {
return getClass().getName().toString() + UPLOAD_FINISH_MESSAGE;
public static String getUploadFinishMessage() {
return FileUploader.class.getName().toString() + UPLOAD_FINISH_MESSAGE;
}
/**

View file

@ -360,5 +360,4 @@ public class SynchronizeFolderOperation extends RemoteOperation {
}
}
}

View file

@ -287,9 +287,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
* @param dirRemotePath Remote path of a folder that was just synchronized (with or without success)
*/
private void sendStickyBroadcast(boolean inProgress, String dirRemotePath, RemoteOperationResult result) {
FileSyncService fileSyncService = new FileSyncService();
Intent i = new Intent(fileSyncService.getSyncMessage());
Intent i = new Intent(FileSyncService.getSyncMessage());
i.putExtra(FileSyncService.IN_PROGRESS, inProgress);
i.putExtra(FileSyncService.ACCOUNT_NAME, getAccount().name);
if (dirRemotePath != null) {

View file

@ -28,14 +28,15 @@ import android.os.IBinder;
*
*/
public class FileSyncService extends Service {
public static final String SYNC_MESSAGE = "ACCOUNT_SYNC";
private 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";
public static final String SYNC_RESULT = "SYNC_RESULT";
public String getSyncMessage(){
return getClass().getName().toString() + SYNC_MESSAGE;
public static String getSyncMessage(){
return FileSyncService.class.getName().toString() + SYNC_MESSAGE;
}
/*
* {@inheritDoc}

View file

@ -139,9 +139,6 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
private OCFile mWaitingToPreview;
private Handler mHandler;
private String mDownloadAddedMessage;
private String mDownloadFinishMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log_OC.d(TAG, "onCreate() start");
@ -151,10 +148,6 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
mHandler = new Handler();
FileDownloader downloader = new FileDownloader();
mDownloadAddedMessage = downloader.getDownloadAddedMessage();
mDownloadFinishMessage= downloader.getDownloadFinishMessage();
/// bindings to transference services
mUploadConnection = new ListServiceConnection();
mDownloadConnection = new ListServiceConnection();
@ -412,12 +405,12 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
// the user browsed to other file ; forget the automatic preview
mWaitingToPreview = null;
} else if (downloadEvent.equals(mDownloadAddedMessage)) {
} else if (downloadEvent.equals(FileDownloader.getDownloadAddedMessage())) {
// grant that the right panel updates the progress bar
detailsFragment.listenForTransferProgress();
detailsFragment.updateFileDetails(true, false);
} else if (downloadEvent.equals(mDownloadFinishMessage)) {
} else if (downloadEvent.equals(FileDownloader.getDownloadFinishMessage())) {
// update the right panel
boolean detailsFragmentChanged = false;
if (waitedPreview) {
@ -635,22 +628,19 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
super.onResume();
Log_OC.e(TAG, "onResume() start");
FileUploader fileUploader = new FileUploader();
FileSyncService fileSyncService = new FileSyncService();
// Listen for sync messages
IntentFilter syncIntentFilter = new IntentFilter(fileSyncService.getSyncMessage());
IntentFilter syncIntentFilter = new IntentFilter(FileSyncService.getSyncMessage());
mSyncBroadcastReceiver = new SyncBroadcastReceiver();
registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
// Listen for upload messages
IntentFilter uploadIntentFilter = new IntentFilter(fileUploader.getUploadFinishMessage());
IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.getUploadFinishMessage());
mUploadFinishReceiver = new UploadFinishReceiver();
registerReceiver(mUploadFinishReceiver, uploadIntentFilter);
// Listen for download messages
IntentFilter downloadIntentFilter = new IntentFilter(mDownloadAddedMessage);
downloadIntentFilter.addAction(mDownloadFinishMessage);
IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.getDownloadAddedMessage());
downloadIntentFilter.addAction(FileDownloader.getDownloadFinishMessage());
mDownloadFinishReceiver = new DownloadFinishReceiver();
registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);

View file

@ -207,8 +207,7 @@ public class FileDetailFragment extends FileFragment implements
public void onResume() {
super.onResume();
mUploadFinishReceiver = new UploadFinishReceiver();
FileUploader fileUploader = new FileUploader();
IntentFilter filter = new IntentFilter(fileUploader.getUploadFinishMessage());
IntentFilter filter = new IntentFilter(FileUploader.getUploadFinishMessage());
getActivity().registerReceiver(mUploadFinishReceiver, filter);
}

View file

@ -82,9 +82,6 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
private boolean mFullScreen;
private String mDownloadAddedMessage;
private String mDownloadFinishMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -104,9 +101,6 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
mRequestWaitingForBinder = false;
}
FileDownloader downloader = new FileDownloader();
mDownloadAddedMessage = downloader.getDownloadAddedMessage();
mDownloadFinishMessage= downloader.getDownloadFinishMessage();
}
private void initViewPager() {
@ -227,8 +221,8 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
//Log.e(TAG, "ACTIVITY, ONRESUME");
mDownloadFinishReceiver = new DownloadFinishReceiver();
IntentFilter filter = new IntentFilter(mDownloadFinishMessage);
filter.addAction(mDownloadAddedMessage);
IntentFilter filter = new IntentFilter(FileDownloader.getDownloadFinishMessage());
filter.addAction(FileDownloader.getDownloadAddedMessage());
registerReceiver(mDownloadFinishReceiver, filter);
}
@ -387,7 +381,7 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false);
//boolean isOffscreen = Math.abs((mViewPager.getCurrentItem() - position)) <= mViewPager.getOffscreenPageLimit();
if (position >= 0 && intent.getAction().equals(mDownloadFinishMessage)) {
if (position >= 0 && intent.getAction().equals(FileDownloader.getDownloadFinishMessage())) {
if (downloadWasFine) {
mPreviewImagePagerAdapter.updateFile(position, file);