no sticky broadcast:

- use local broadcast system instead
- no need to remove sticky broadcasts then

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2019-10-23 08:22:50 +02:00
parent adff9511e9
commit 15dcad229c
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
13 changed files with 139 additions and 151 deletions

View file

@ -60,7 +60,6 @@
<uses-permission android:name="android.permission.READ_SYNC_STATS" /> <uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" /> <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" /> <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />

View file

@ -68,6 +68,7 @@ import java.io.File;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
@ -217,4 +218,9 @@ class AppModule {
AppNotificationManager notificationsManager(Context context, NotificationManager platformNotificationsManager) { AppNotificationManager notificationsManager(Context context, NotificationManager platformNotificationsManager) {
return new AppNotificationManagerImpl(context, context.getResources(), platformNotificationsManager); return new AppNotificationManagerImpl(context, context.getResources(), platformNotificationsManager);
} }
@Provides
LocalBroadcastManager localBroadcastManager(Context context) {
return LocalBroadcastManager.getInstance(context);
}
} }

View file

@ -76,6 +76,7 @@ import java.util.Vector;
import javax.inject.Inject; import javax.inject.Inject;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import dagger.android.AndroidInjection; import dagger.android.AndroidInjection;
public class FileDownloader extends Service public class FileDownloader extends Service
@ -117,6 +118,7 @@ public class FileDownloader extends Service
@Inject UserAccountManager accountManager; @Inject UserAccountManager accountManager;
@Inject UploadsStorageManager uploadsStorageManager; @Inject UploadsStorageManager uploadsStorageManager;
@Inject LocalBroadcastManager localBroadcastManager;
public static String getDownloadAddedMessage() { public static String getDownloadAddedMessage() {
return FileDownloader.class.getName() + DOWNLOAD_ADDED_MESSAGE; return FileDownloader.class.getName() + DOWNLOAD_ADDED_MESSAGE;
@ -691,7 +693,7 @@ public class FileDownloader extends Service
end.putExtra(EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath); end.putExtra(EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath);
} }
end.setPackage(getPackageName()); end.setPackage(getPackageName());
sendStickyBroadcast(end); localBroadcastManager.sendBroadcast(end);
} }
@ -708,7 +710,7 @@ public class FileDownloader extends Service
added.putExtra(EXTRA_REMOTE_PATH, download.getRemotePath()); added.putExtra(EXTRA_REMOTE_PATH, download.getRemotePath());
added.putExtra(EXTRA_LINKED_TO_PATH, linkedToRemotePath); added.putExtra(EXTRA_LINKED_TO_PATH, linkedToRemotePath);
added.setPackage(getPackageName()); added.setPackage(getPackageName());
sendStickyBroadcast(added); localBroadcastManager.sendBroadcast(added);
} }
/** /**

View file

@ -90,6 +90,7 @@ import javax.inject.Inject;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import dagger.android.AndroidInjection; import dagger.android.AndroidInjection;
/** /**
@ -184,6 +185,7 @@ public class FileUploader extends Service
@Inject UploadsStorageManager mUploadsStorageManager; @Inject UploadsStorageManager mUploadsStorageManager;
@Inject ConnectivityService connectivityService; @Inject ConnectivityService connectivityService;
@Inject PowerManagementService powerManagementService; @Inject PowerManagementService powerManagementService;
@Inject LocalBroadcastManager localBroadcastManager;
private IndexedForest<UploadFileOperation> mPendingUploads = new IndexedForest<>(); private IndexedForest<UploadFileOperation> mPendingUploads = new IndexedForest<>();
@ -823,7 +825,7 @@ public class FileUploader extends Service
Intent start = new Intent(getUploadsAddedMessage()); Intent start = new Intent(getUploadsAddedMessage());
// nothing else needed right now // nothing else needed right now
start.setPackage(getPackageName()); start.setPackage(getPackageName());
sendStickyBroadcast(start); localBroadcastManager.sendBroadcast(start);
} }
/** /**
@ -840,7 +842,7 @@ public class FileUploader extends Service
start.putExtra(ACCOUNT_NAME, upload.getAccount().name); start.putExtra(ACCOUNT_NAME, upload.getAccount().name);
start.setPackage(getPackageName()); start.setPackage(getPackageName());
sendStickyBroadcast(start); localBroadcastManager.sendBroadcast(start);
} }
/** /**
@ -873,7 +875,7 @@ public class FileUploader extends Service
end.putExtra(EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath); end.putExtra(EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath);
} }
end.setPackage(getPackageName()); end.setPackage(getPackageName());
sendStickyBroadcast(end); localBroadcastManager.sendBroadcast(end);
} }
/** /**

View file

@ -57,6 +57,7 @@ import java.util.Vector;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR; import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
@ -691,6 +692,6 @@ public class RefreshFolderOperation extends RemoteOperation {
intent.putExtra(FileSyncAdapter.EXTRA_RESULT, dataHolderItemId); intent.putExtra(FileSyncAdapter.EXTRA_RESULT, dataHolderItemId);
intent.setPackage(mContext.getPackageName()); intent.setPackage(mContext.getPackageName());
mContext.sendStickyBroadcast(intent); LocalBroadcastManager.getInstance(mContext.getApplicationContext()).sendBroadcast(intent);
} }
} }

View file

@ -41,6 +41,8 @@ import com.owncloud.android.operations.SynchronizeFolderOperation;
import java.io.IOException; import java.io.IOException;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
/** /**
* SyncFolder worker. Performs the pending operations in the order they were requested. * SyncFolder worker. Performs the pending operations in the order they were requested.
* *
@ -177,7 +179,7 @@ class SyncFolderHandler extends Handler {
added.putExtra(FileDownloader.ACCOUNT_NAME, account.name); added.putExtra(FileDownloader.ACCOUNT_NAME, account.name);
added.putExtra(FileDownloader.EXTRA_REMOTE_PATH, remotePath); added.putExtra(FileDownloader.EXTRA_REMOTE_PATH, remotePath);
added.setPackage(mService.getPackageName()); added.setPackage(mService.getPackageName());
mService.sendStickyBroadcast(added); LocalBroadcastManager.getInstance(mService.getApplicationContext()).sendBroadcast(added);
} }
/** /**
@ -191,6 +193,6 @@ class SyncFolderHandler extends Handler {
finished.putExtra(FileDownloader.EXTRA_REMOTE_PATH, remotePath); finished.putExtra(FileDownloader.EXTRA_REMOTE_PATH, remotePath);
finished.putExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, success); finished.putExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, success);
finished.setPackage(mService.getPackageName()); finished.setPackage(mService.getPackageName());
mService.sendStickyBroadcast(finished); LocalBroadcastManager.getInstance(mService.getApplicationContext()).sendBroadcast(finished);
} }
} }

View file

@ -59,6 +59,7 @@ import java.util.Map;
import androidx.annotation.PluralsRes; import androidx.annotation.PluralsRes;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
/** /**
* Implementation of {@link AbstractThreadedSyncAdapter} responsible for synchronizing * Implementation of {@link AbstractThreadedSyncAdapter} responsible for synchronizing
@ -379,8 +380,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
} }
intent.setPackage(getContext().getPackageName()); intent.setPackage(getContext().getPackageName());
getContext().sendStickyBroadcast(intent); LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
//LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
} }

View file

@ -137,6 +137,7 @@ import androidx.core.view.MenuItemCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR; import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
@ -159,6 +160,7 @@ public class FileDisplayActivity extends FileActivity
private UploadFinishReceiver mUploadFinishReceiver; private UploadFinishReceiver mUploadFinishReceiver;
private DownloadFinishReceiver mDownloadFinishReceiver; private DownloadFinishReceiver mDownloadFinishReceiver;
private RemoteOperationResult mLastSslUntrustedServerResult; private RemoteOperationResult mLastSslUntrustedServerResult;
@Inject LocalBroadcastManager localBroadcastManager;
private boolean mDualPane; private boolean mDualPane;
@ -1119,19 +1121,19 @@ public class FileDisplayActivity extends FileActivity
syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED); syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED); syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
mSyncBroadcastReceiver = new SyncBroadcastReceiver(); mSyncBroadcastReceiver = new SyncBroadcastReceiver();
registerReceiver(mSyncBroadcastReceiver, syncIntentFilter); localBroadcastManager.registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
} }
// Listen for upload messages // Listen for upload messages
IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.getUploadFinishMessage()); IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.getUploadFinishMessage());
mUploadFinishReceiver = new UploadFinishReceiver(); mUploadFinishReceiver = new UploadFinishReceiver();
registerReceiver(mUploadFinishReceiver, uploadIntentFilter); localBroadcastManager.registerReceiver(mUploadFinishReceiver, uploadIntentFilter);
// Listen for download messages // Listen for download messages
IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.getDownloadAddedMessage()); IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.getDownloadAddedMessage());
downloadIntentFilter.addAction(FileDownloader.getDownloadFinishMessage()); downloadIntentFilter.addAction(FileDownloader.getDownloadFinishMessage());
mDownloadFinishReceiver = new DownloadFinishReceiver(); mDownloadFinishReceiver = new DownloadFinishReceiver();
registerReceiver(mDownloadFinishReceiver, downloadIntentFilter); localBroadcastManager.registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
// setup drawer // setup drawer
menuItemId = getIntent().getIntExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItemId); menuItemId = getIntent().getIntExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItemId);
@ -1165,16 +1167,15 @@ public class FileDisplayActivity extends FileActivity
protected void onPause() { protected void onPause() {
Log_OC.v(TAG, "onPause() start"); Log_OC.v(TAG, "onPause() start");
if (mSyncBroadcastReceiver != null) { if (mSyncBroadcastReceiver != null) {
unregisterReceiver(mSyncBroadcastReceiver); localBroadcastManager.unregisterReceiver(mSyncBroadcastReceiver);
//LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadcastReceiver);
mSyncBroadcastReceiver = null; mSyncBroadcastReceiver = null;
} }
if (mUploadFinishReceiver != null) { if (mUploadFinishReceiver != null) {
unregisterReceiver(mUploadFinishReceiver); localBroadcastManager.unregisterReceiver(mUploadFinishReceiver);
mUploadFinishReceiver = null; mUploadFinishReceiver = null;
} }
if (mDownloadFinishReceiver != null) { if (mDownloadFinishReceiver != null) {
unregisterReceiver(mDownloadFinishReceiver); localBroadcastManager.unregisterReceiver(mDownloadFinishReceiver);
mDownloadFinishReceiver = null; mDownloadFinishReceiver = null;
} }
@ -1289,7 +1290,6 @@ public class FileDisplayActivity extends FileActivity
} }
} }
} }
removeStickyBroadcast(intent);
DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT)); DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress); Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
@ -1308,7 +1308,6 @@ public class FileDisplayActivity extends FileActivity
} catch (RuntimeException e) { } catch (RuntimeException e) {
// avoid app crashes after changing the serial id of RemoteOperationResult // avoid app crashes after changing the serial id of RemoteOperationResult
// in owncloud library with broadcast notifications pending to process // in owncloud library with broadcast notifications pending to process
removeStickyBroadcast(intent);
try { try {
DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT)); DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
@ -1362,74 +1361,67 @@ public class FileDisplayActivity extends FileActivity
*/ */
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
try { String uploadedRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH);
String uploadedRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH); String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME); boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name); OCFile currentDir = getCurrentDir();
OCFile currentDir = getCurrentDir(); boolean isDescendant = currentDir != null && uploadedRemotePath != null &&
boolean isDescendant = currentDir != null && uploadedRemotePath != null && uploadedRemotePath.startsWith(currentDir.getRemotePath());
uploadedRemotePath.startsWith(currentDir.getRemotePath());
if (sameAccount && isDescendant) { if (sameAccount && isDescendant) {
String linkedToRemotePath = String linkedToRemotePath =
intent.getStringExtra(FileUploader.EXTRA_LINKED_TO_PATH); intent.getStringExtra(FileUploader.EXTRA_LINKED_TO_PATH);
if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) { if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
updateListOfFilesFragment(false); updateListOfFilesFragment(false);
}
}
boolean uploadWasFine = intent.getBooleanExtra(
FileUploader.EXTRA_UPLOAD_RESULT,
false);
boolean renamedInUpload = getFile().getRemotePath().
equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
boolean sameFile = getFile().getRemotePath().equals(uploadedRemotePath) ||
renamedInUpload;
FileFragment details = getSecondFragment();
if (sameAccount && sameFile && details instanceof FileDetailFragment) {
if (uploadWasFine) {
setFile(getStorageManager().getFileByPath(uploadedRemotePath));
} else {
//TODO remove upload progress bar after upload failed.
Log_OC.d(TAG, "Remove upload progress bar after upload failed");
}
if (renamedInUpload) {
String newName = new File(uploadedRemotePath).getName();
DisplayUtils.showSnackMessage(
getActivity(),
R.string.filedetails_renamed_in_upload_msg,
newName
);
}
if (uploadWasFine || getFile().fileExists()) {
((FileDetailFragment) details).updateFileDetails(false, true);
} else {
cleanSecondFragment();
}
// Force the preview if the file is an image or text file
if (uploadWasFine) {
OCFile ocFile = getFile();
if (PreviewImageFragment.canBePreviewed(ocFile)) {
startImagePreview(getFile(), true);
} else if (PreviewTextFileFragment.canBePreviewed(ocFile)) {
startTextPreview(ocFile, true);
}
// TODO what about other kind of previews?
}
}
OCFileListFragment ocFileListFragment = getListOfFilesFragment();
if (ocFileListFragment != null) {
ocFileListFragment.setLoading(false);
}
} finally {
if (intent != null) {
removeStickyBroadcast(intent);
} }
} }
boolean uploadWasFine = intent.getBooleanExtra(
FileUploader.EXTRA_UPLOAD_RESULT,
false);
boolean renamedInUpload = getFile().getRemotePath().
equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
boolean sameFile = getFile().getRemotePath().equals(uploadedRemotePath) ||
renamedInUpload;
FileFragment details = getSecondFragment();
if (sameAccount && sameFile && details instanceof FileDetailFragment) {
if (uploadWasFine) {
setFile(getStorageManager().getFileByPath(uploadedRemotePath));
} else {
//TODO remove upload progress bar after upload failed.
Log_OC.d(TAG, "Remove upload progress bar after upload failed");
}
if (renamedInUpload) {
String newName = new File(uploadedRemotePath).getName();
DisplayUtils.showSnackMessage(
getActivity(),
R.string.filedetails_renamed_in_upload_msg,
newName
);
}
if (uploadWasFine || getFile().fileExists()) {
((FileDetailFragment) details).updateFileDetails(false, true);
} else {
cleanSecondFragment();
}
// Force the preview if the file is an image or text file
if (uploadWasFine) {
OCFile ocFile = getFile();
if (PreviewImageFragment.canBePreviewed(ocFile)) {
startImagePreview(getFile(), true);
} else if (PreviewTextFileFragment.canBePreviewed(ocFile)) {
startTextPreview(ocFile, true);
}
// TODO what about other kind of previews?
}
}
OCFileListFragment ocFileListFragment = getListOfFilesFragment();
if (ocFileListFragment != null) {
ocFileListFragment.setLoading(false);
}
} }
// TODO refactor this receiver, and maybe DownloadFinishReceiver; this method is duplicated :S // TODO refactor this receiver, and maybe DownloadFinishReceiver; this method is duplicated :S
@ -1450,11 +1442,10 @@ public class FileDisplayActivity extends FileActivity
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
try { boolean sameAccount = isSameAccount(intent);
boolean sameAccount = isSameAccount(intent); String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); String downloadBehaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR);
String downloadBehaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR); boolean isDescendant = isDescendant(downloadedRemotePath);
boolean isDescendant = isDescendant(downloadedRemotePath);
if (sameAccount && isDescendant) { if (sameAccount && isDescendant) {
String linkedToRemotePath = intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH); String linkedToRemotePath = intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH);
@ -1467,28 +1458,22 @@ public class FileDisplayActivity extends FileActivity
intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false)); intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
} }
if (mWaitingToSend != null) { if (mWaitingToSend != null) {
// update file after downloading // update file after downloading
mWaitingToSend = getStorageManager().getFileByRemoteId(mWaitingToSend.getRemoteId()); mWaitingToSend = getStorageManager().getFileByRemoteId(mWaitingToSend.getRemoteId());
if (mWaitingToSend != null && mWaitingToSend.isDown() && downloadBehaviour != null) { if (mWaitingToSend != null && mWaitingToSend.isDown() && downloadBehaviour != null) {
switch (downloadBehaviour) { switch (downloadBehaviour) {
case OCFileListFragment.DOWNLOAD_SEND: case OCFileListFragment.DOWNLOAD_SEND:
String packageName = intent.getStringExtra(SendShareDialog.PACKAGE_NAME); String packageName = intent.getStringExtra(SendShareDialog.PACKAGE_NAME);
String activityName = intent.getStringExtra(SendShareDialog.ACTIVITY_NAME); String activityName = intent.getStringExtra(SendShareDialog.ACTIVITY_NAME);
sendDownloadedFile(packageName, activityName); sendDownloadedFile(packageName, activityName);
break; break;
default: default:
// do nothing // do nothing
break; break;
}
} }
} }
} finally {
if (intent != null) {
removeStickyBroadcast(intent);
}
} }
} }

View file

@ -38,7 +38,6 @@ import android.view.View.OnClickListener;
import com.google.android.material.button.MaterialButton; import com.google.android.material.button.MaterialButton;
import com.nextcloud.client.di.Injectable; import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.preferences.AppPreferences;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.OCFile;
@ -67,6 +66,7 @@ import javax.inject.Inject;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
public class FolderPickerActivity extends FileActivity implements FileFragment.ContainerActivity, public class FolderPickerActivity extends FileActivity implements FileFragment.ContainerActivity,
OnClickListener, OnClickListener,
@ -96,7 +96,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
protected MaterialButton mCancelBtn; protected MaterialButton mCancelBtn;
protected MaterialButton mChooseBtn; protected MaterialButton mChooseBtn;
private String caption; private String caption;
@Inject AppPreferences preferences; @Inject LocalBroadcastManager localBroadcastManager;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -278,7 +278,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED); syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED); syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
mSyncBroadcastReceiver = new SyncBroadcastReceiver(); mSyncBroadcastReceiver = new SyncBroadcastReceiver();
registerReceiver(mSyncBroadcastReceiver, syncIntentFilter); localBroadcastManager.registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
Log_OC.d(TAG, "onResume() end"); Log_OC.d(TAG, "onResume() end");
} }
@ -287,8 +287,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
protected void onPause() { protected void onPause() {
Log_OC.e(TAG, "onPause() start"); Log_OC.e(TAG, "onPause() start");
if (mSyncBroadcastReceiver != null) { if (mSyncBroadcastReceiver != null) {
unregisterReceiver(mSyncBroadcastReceiver); localBroadcastManager.unregisterReceiver(mSyncBroadcastReceiver);
//LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadcastReceiver);
mSyncBroadcastReceiver = null; mSyncBroadcastReceiver = null;
} }
@ -532,7 +531,6 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
} }
} }
removeStickyBroadcast(intent);
DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT)); DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress); Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
@ -544,7 +542,6 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
} catch (RuntimeException e) { } catch (RuntimeException e) {
// avoid app crashes after changing the serial id of RemoteOperationResult // avoid app crashes after changing the serial id of RemoteOperationResult
// in owncloud library with broadcast notifications pending to process // in owncloud library with broadcast notifications pending to process
removeStickyBroadcast(intent);
DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT)); DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
} }
} }

View file

@ -120,6 +120,7 @@ import androidx.appcompat.widget.SearchView;
import androidx.core.view.MenuItemCompat; import androidx.core.view.MenuItemCompat;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import static com.owncloud.android.utils.DisplayUtils.openSortingOrderDialogFragment; import static com.owncloud.android.utils.DisplayUtils.openSortingOrderDialogFragment;
@ -140,6 +141,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
public static final int SINGLE_PARENT = 1; public static final int SINGLE_PARENT = 1;
@Inject AppPreferences preferences; @Inject AppPreferences preferences;
@Inject LocalBroadcastManager localBroadcastManager;
private AccountManager mAccountManager; private AccountManager mAccountManager;
private Stack<String> mParents = new Stack<>(); private Stack<String> mParents = new Stack<>();
private List<Parcelable> mStreamsToUpload; private List<Parcelable> mStreamsToUpload;
@ -189,7 +191,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
EVENT_SINGLE_FOLDER_CONTENTS_SYNCED); EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED); syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
mSyncBroadcastReceiver = new SyncBroadcastReceiver(); mSyncBroadcastReceiver = new SyncBroadcastReceiver();
registerReceiver(mSyncBroadcastReceiver, syncIntentFilter); localBroadcastManager.registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
// Init Fragment without UI to retain AsyncTask across configuration changes // Init Fragment without UI to retain AsyncTask across configuration changes
FragmentManager fm = getSupportFragmentManager(); FragmentManager fm = getSupportFragmentManager();
@ -266,7 +268,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
@Override @Override
protected void onDestroy() { protected void onDestroy() {
if (mSyncBroadcastReceiver != null) { if (mSyncBroadcastReceiver != null) {
unregisterReceiver(mSyncBroadcastReceiver); localBroadcastManager.unregisterReceiver(mSyncBroadcastReceiver);
} }
super.onDestroy(); super.onDestroy();
} }
@ -1151,14 +1153,12 @@ public class ReceiveExternalFilesActivity extends FileActivity
} }
} }
} }
removeStickyBroadcast(intent);
Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress); Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
// avoid app crashes after changing the serial id of RemoteOperationResult // avoid app crashes after changing the serial id of RemoteOperationResult
// in owncloud library with broadcast notifications pending to process // in owncloud library with broadcast notifications pending to process
removeStickyBroadcast(intent);
DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT)); DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
} }
} }

View file

@ -59,6 +59,7 @@ import com.owncloud.android.utils.ThemeUtils;
import javax.inject.Inject; import javax.inject.Inject;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@ -95,6 +96,9 @@ public class UploadListActivity extends FileActivity {
@Inject @Inject
BackgroundJobManager backgroundJobManager; BackgroundJobManager backgroundJobManager;
@Inject
LocalBroadcastManager localBroadcastManager;
private UploadListLayoutBinding binding; private UploadListLayoutBinding binding;
public static Intent createIntent(OCFile file, Account account, Integer flag, Context context) { public static Intent createIntent(OCFile file, Account account, Integer flag, Context context) {
@ -223,7 +227,7 @@ public class UploadListActivity extends FileActivity {
uploadIntentFilter.addAction(FileUploader.getUploadsAddedMessage()); uploadIntentFilter.addAction(FileUploader.getUploadsAddedMessage());
uploadIntentFilter.addAction(FileUploader.getUploadStartMessage()); uploadIntentFilter.addAction(FileUploader.getUploadStartMessage());
uploadIntentFilter.addAction(FileUploader.getUploadFinishMessage()); uploadIntentFilter.addAction(FileUploader.getUploadFinishMessage());
registerReceiver(uploadMessagesReceiver, uploadIntentFilter); localBroadcastManager.registerReceiver(uploadMessagesReceiver, uploadIntentFilter);
Log_OC.v(TAG, "onResume() end"); Log_OC.v(TAG, "onResume() end");
@ -233,7 +237,7 @@ public class UploadListActivity extends FileActivity {
protected void onPause() { protected void onPause() {
Log_OC.v(TAG, "onPause() start"); Log_OC.v(TAG, "onPause() start");
if (uploadMessagesReceiver != null) { if (uploadMessagesReceiver != null) {
unregisterReceiver(uploadMessagesReceiver); localBroadcastManager.unregisterReceiver(uploadMessagesReceiver);
uploadMessagesReceiver = null; uploadMessagesReceiver = null;
} }
super.onPause(); super.onPause();
@ -355,14 +359,7 @@ public class UploadListActivity extends FileActivity {
*/ */
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
try { uploadListAdapter.loadUploadItemsFromDb();
uploadListAdapter.loadUploadItemsFromDb();
} finally {
if (intent != null) {
removeStickyBroadcast(intent);
}
}
} }
} }
} }

View file

@ -58,10 +58,10 @@ import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManager; import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.di.Injectable; import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.files.downloader.Direction; import com.nextcloud.client.files.downloader.Direction;
import com.nextcloud.client.files.downloader.Transfer;
import com.nextcloud.client.files.downloader.TransferState;
import com.nextcloud.client.files.downloader.TransferManagerConnection;
import com.nextcloud.client.files.downloader.Request; import com.nextcloud.client.files.downloader.Request;
import com.nextcloud.client.files.downloader.Transfer;
import com.nextcloud.client.files.downloader.TransferManagerConnection;
import com.nextcloud.client.files.downloader.TransferState;
import com.nextcloud.client.jobs.BackgroundJobManager; import com.nextcloud.client.jobs.BackgroundJobManager;
import com.nextcloud.client.network.ClientFactory; import com.nextcloud.client.network.ClientFactory;
import com.owncloud.android.R; import com.owncloud.android.R;

View file

@ -65,6 +65,7 @@ import javax.inject.Inject;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@ -80,16 +81,9 @@ public class PreviewImageActivity extends FileActivity implements
Injectable { Injectable {
public static final String TAG = PreviewImageActivity.class.getSimpleName(); public static final String TAG = PreviewImageActivity.class.getSimpleName();
public static final String EXTRA_VIRTUAL_TYPE = "EXTRA_VIRTUAL_TYPE";
private static final String KEY_WAITING_FOR_BINDER = "WAITING_FOR_BINDER"; private static final String KEY_WAITING_FOR_BINDER = "WAITING_FOR_BINDER";
private static final String KEY_SYSTEM_VISIBLE = "TRUE"; private static final String KEY_SYSTEM_VISIBLE = "TRUE";
public static final String EXTRA_VIRTUAL_TYPE = "EXTRA_VIRTUAL_TYPE";
public static Intent previewFileIntent(Context context, User user, OCFile file) {
final Intent intent = new Intent(context, PreviewImageActivity.class);
intent.putExtra(FileActivity.EXTRA_FILE, file);
intent.putExtra(FileActivity.EXTRA_ACCOUNT, user.toPlatformAccount());
return intent;
}
private ViewPager mViewPager; private ViewPager mViewPager;
private PreviewImagePagerAdapter mPreviewImagePagerAdapter; private PreviewImagePagerAdapter mPreviewImagePagerAdapter;
@ -99,6 +93,14 @@ public class PreviewImageActivity extends FileActivity implements
private DownloadFinishReceiver mDownloadFinishReceiver; private DownloadFinishReceiver mDownloadFinishReceiver;
private View mFullScreenAnchorView; private View mFullScreenAnchorView;
@Inject AppPreferences preferences; @Inject AppPreferences preferences;
@Inject LocalBroadcastManager localBroadcastManager;
public static Intent previewFileIntent(Context context, User user, OCFile file) {
final Intent intent = new Intent(context, PreviewImageActivity.class);
intent.putExtra(FileActivity.EXTRA_FILE, file);
intent.putExtra(FileActivity.EXTRA_ACCOUNT, user.toPlatformAccount());
return intent;
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -107,7 +109,7 @@ public class PreviewImageActivity extends FileActivity implements
final ActionBar actionBar = getSupportActionBar(); final ActionBar actionBar = getSupportActionBar();
if (savedInstanceState != null && !savedInstanceState.getBoolean(KEY_SYSTEM_VISIBLE, true) && if (savedInstanceState != null && !savedInstanceState.getBoolean(KEY_SYSTEM_VISIBLE, true) &&
actionBar != null) { actionBar != null) {
actionBar.hide(); actionBar.hide();
} }
@ -320,7 +322,7 @@ public class PreviewImageActivity extends FileActivity implements
IntentFilter filter = new IntentFilter(FileDownloader.getDownloadFinishMessage()); IntentFilter filter = new IntentFilter(FileDownloader.getDownloadFinishMessage());
filter.addAction(FileDownloader.getDownloadAddedMessage()); filter.addAction(FileDownloader.getDownloadAddedMessage());
registerReceiver(mDownloadFinishReceiver, filter); localBroadcastManager.registerReceiver(mDownloadFinishReceiver, filter);
} }
@Override @Override
@ -331,7 +333,7 @@ public class PreviewImageActivity extends FileActivity implements
@Override @Override
public void onPause() { public void onPause() {
if (mDownloadFinishReceiver != null){ if (mDownloadFinishReceiver != null){
unregisterReceiver(mDownloadFinishReceiver); localBroadcastManager.unregisterReceiver(mDownloadFinishReceiver);
mDownloadFinishReceiver = null; mDownloadFinishReceiver = null;
} }
@ -448,27 +450,22 @@ public class PreviewImageActivity extends FileActivity implements
OCFile file = getStorageManager().getFileByPath(downloadedRemotePath); OCFile file = getStorageManager().getFileByPath(downloadedRemotePath);
int position = mPreviewImagePagerAdapter.getFilePosition(file); int position = mPreviewImagePagerAdapter.getFilePosition(file);
boolean downloadWasFine = intent.getBooleanExtra( boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false);
FileDownloader.EXTRA_DOWNLOAD_RESULT, false);
//boolean isOffscreen = Math.abs((mViewPager.getCurrentItem() - position)) //boolean isOffscreen = Math.abs((mViewPager.getCurrentItem() - position))
// <= mViewPager.getOffscreenPageLimit(); // <= mViewPager.getOffscreenPageLimit();
if (position >= 0 && if (position >= 0 && intent.getAction().equals(FileDownloader.getDownloadFinishMessage())) {
intent.getAction().equals(FileDownloader.getDownloadFinishMessage())) {
if (downloadWasFine) { if (downloadWasFine) {
mPreviewImagePagerAdapter.updateFile(position, file); mPreviewImagePagerAdapter.updateFile(position, file);
} else { } else {
mPreviewImagePagerAdapter.updateWithDownloadError(position); mPreviewImagePagerAdapter.updateWithDownloadError(position);
} }
mPreviewImagePagerAdapter.notifyDataSetChanged(); // will trigger the creation mPreviewImagePagerAdapter.notifyDataSetChanged(); // will trigger the creation of new fragments
// of new fragments
} else { } else {
Log_OC.d(TAG, "Download finished, but the fragment is offscreen"); Log_OC.d(TAG, "Download finished, but the fragment is offscreen");
} }
} }
removeStickyBroadcast(intent);
} }
} }