mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
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:
parent
db87c22150
commit
69945d50fb
10 changed files with 26 additions and 54 deletions
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -537,7 +537,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
* @param dirRemotePath Remote path of a folder that was just synchronized (with or without success)
|
||||
*/
|
||||
private void sendStickyBroadcast(boolean inProgress, String dirRemotePath, RemoteOperationResult result) {
|
||||
Intent i = new Intent(FileSyncService.SYNC_MESSAGE);
|
||||
Intent i = new Intent(FileSyncService.getSyncMessage());
|
||||
i.putExtra(FileSyncService.IN_PROGRESS, inProgress);
|
||||
i.putExtra(FileSyncService.ACCOUNT_NAME, mAccount.name);
|
||||
if (dirRemotePath != null) {
|
||||
|
|
|
@ -337,9 +337,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) {
|
||||
|
|
|
@ -31,14 +31,14 @@ 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}
|
||||
|
|
|
@ -140,8 +140,6 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
|
|||
private Handler mHandler;
|
||||
|
||||
private boolean mSyncInProgress = false;
|
||||
private String mDownloadAddedMessage;
|
||||
private String mDownloadFinishMessage;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -152,10 +150,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();
|
||||
|
@ -425,12 +419,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) {
|
||||
|
@ -661,22 +655,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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -81,9 +81,6 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
|
|||
|
||||
private boolean mFullScreen;
|
||||
|
||||
private String mDownloadAddedMessage;
|
||||
private String mDownloadFinishMessage;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -103,9 +100,6 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
|
|||
mRequestWaitingForBinder = false;
|
||||
}
|
||||
|
||||
FileDownloader downloader = new FileDownloader();
|
||||
mDownloadAddedMessage = downloader.getDownloadAddedMessage();
|
||||
mDownloadFinishMessage= downloader.getDownloadFinishMessage();
|
||||
}
|
||||
|
||||
private void initViewPager() {
|
||||
|
@ -226,8 +220,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);
|
||||
}
|
||||
|
||||
|
@ -386,7 +380,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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue