mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 07:05:49 +03:00
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:
parent
adff9511e9
commit
15dcad229c
13 changed files with 139 additions and 151 deletions
|
@ -60,7 +60,6 @@
|
|||
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
|
||||
<uses-permission android:name="android.permission.READ_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.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
|
|
|
@ -68,6 +68,7 @@ import java.io.File;
|
|||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
|
@ -217,4 +218,9 @@ class AppModule {
|
|||
AppNotificationManager notificationsManager(Context context, NotificationManager platformNotificationsManager) {
|
||||
return new AppNotificationManagerImpl(context, context.getResources(), platformNotificationsManager);
|
||||
}
|
||||
|
||||
@Provides
|
||||
LocalBroadcastManager localBroadcastManager(Context context) {
|
||||
return LocalBroadcastManager.getInstance(context);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,6 +76,7 @@ import java.util.Vector;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import dagger.android.AndroidInjection;
|
||||
|
||||
public class FileDownloader extends Service
|
||||
|
@ -117,6 +118,7 @@ public class FileDownloader extends Service
|
|||
|
||||
@Inject UserAccountManager accountManager;
|
||||
@Inject UploadsStorageManager uploadsStorageManager;
|
||||
@Inject LocalBroadcastManager localBroadcastManager;
|
||||
|
||||
public static String getDownloadAddedMessage() {
|
||||
return FileDownloader.class.getName() + DOWNLOAD_ADDED_MESSAGE;
|
||||
|
@ -691,7 +693,7 @@ public class FileDownloader extends Service
|
|||
end.putExtra(EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath);
|
||||
}
|
||||
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_LINKED_TO_PATH, linkedToRemotePath);
|
||||
added.setPackage(getPackageName());
|
||||
sendStickyBroadcast(added);
|
||||
localBroadcastManager.sendBroadcast(added);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -90,6 +90,7 @@ import javax.inject.Inject;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import dagger.android.AndroidInjection;
|
||||
|
||||
/**
|
||||
|
@ -184,6 +185,7 @@ public class FileUploader extends Service
|
|||
@Inject UploadsStorageManager mUploadsStorageManager;
|
||||
@Inject ConnectivityService connectivityService;
|
||||
@Inject PowerManagementService powerManagementService;
|
||||
@Inject LocalBroadcastManager localBroadcastManager;
|
||||
|
||||
private IndexedForest<UploadFileOperation> mPendingUploads = new IndexedForest<>();
|
||||
|
||||
|
@ -823,7 +825,7 @@ public class FileUploader extends Service
|
|||
Intent start = new Intent(getUploadsAddedMessage());
|
||||
// nothing else needed right now
|
||||
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.setPackage(getPackageName());
|
||||
sendStickyBroadcast(start);
|
||||
localBroadcastManager.sendBroadcast(start);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -873,7 +875,7 @@ public class FileUploader extends Service
|
|||
end.putExtra(EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath);
|
||||
}
|
||||
end.setPackage(getPackageName());
|
||||
sendStickyBroadcast(end);
|
||||
localBroadcastManager.sendBroadcast(end);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -57,6 +57,7 @@ import java.util.Vector;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
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.setPackage(mContext.getPackageName());
|
||||
mContext.sendStickyBroadcast(intent);
|
||||
LocalBroadcastManager.getInstance(mContext.getApplicationContext()).sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,8 @@ import com.owncloud.android.operations.SynchronizeFolderOperation;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
/**
|
||||
* 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.EXTRA_REMOTE_PATH, remotePath);
|
||||
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_DOWNLOAD_RESULT, success);
|
||||
finished.setPackage(mService.getPackageName());
|
||||
mService.sendStickyBroadcast(finished);
|
||||
LocalBroadcastManager.getInstance(mService.getApplicationContext()).sendBroadcast(finished);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ import java.util.Map;
|
|||
|
||||
import androidx.annotation.PluralsRes;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
/**
|
||||
* Implementation of {@link AbstractThreadedSyncAdapter} responsible for synchronizing
|
||||
|
@ -379,8 +380,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
|
|||
}
|
||||
|
||||
intent.setPackage(getContext().getPackageName());
|
||||
getContext().sendStickyBroadcast(intent);
|
||||
//LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -137,6 +137,7 @@ import androidx.core.view.MenuItemCompat;
|
|||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
|
||||
|
||||
|
@ -159,6 +160,7 @@ public class FileDisplayActivity extends FileActivity
|
|||
private UploadFinishReceiver mUploadFinishReceiver;
|
||||
private DownloadFinishReceiver mDownloadFinishReceiver;
|
||||
private RemoteOperationResult mLastSslUntrustedServerResult;
|
||||
@Inject LocalBroadcastManager localBroadcastManager;
|
||||
|
||||
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_SHARES_SYNCED);
|
||||
mSyncBroadcastReceiver = new SyncBroadcastReceiver();
|
||||
registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
|
||||
localBroadcastManager.registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
|
||||
}
|
||||
|
||||
// Listen for upload messages
|
||||
IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.getUploadFinishMessage());
|
||||
mUploadFinishReceiver = new UploadFinishReceiver();
|
||||
registerReceiver(mUploadFinishReceiver, uploadIntentFilter);
|
||||
localBroadcastManager.registerReceiver(mUploadFinishReceiver, uploadIntentFilter);
|
||||
|
||||
// Listen for download messages
|
||||
IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.getDownloadAddedMessage());
|
||||
downloadIntentFilter.addAction(FileDownloader.getDownloadFinishMessage());
|
||||
mDownloadFinishReceiver = new DownloadFinishReceiver();
|
||||
registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
|
||||
localBroadcastManager.registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
|
||||
|
||||
// setup drawer
|
||||
menuItemId = getIntent().getIntExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItemId);
|
||||
|
@ -1165,16 +1167,15 @@ public class FileDisplayActivity extends FileActivity
|
|||
protected void onPause() {
|
||||
Log_OC.v(TAG, "onPause() start");
|
||||
if (mSyncBroadcastReceiver != null) {
|
||||
unregisterReceiver(mSyncBroadcastReceiver);
|
||||
//LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadcastReceiver);
|
||||
localBroadcastManager.unregisterReceiver(mSyncBroadcastReceiver);
|
||||
mSyncBroadcastReceiver = null;
|
||||
}
|
||||
if (mUploadFinishReceiver != null) {
|
||||
unregisterReceiver(mUploadFinishReceiver);
|
||||
localBroadcastManager.unregisterReceiver(mUploadFinishReceiver);
|
||||
mUploadFinishReceiver = null;
|
||||
}
|
||||
if (mDownloadFinishReceiver != null) {
|
||||
unregisterReceiver(mDownloadFinishReceiver);
|
||||
localBroadcastManager.unregisterReceiver(mDownloadFinishReceiver);
|
||||
mDownloadFinishReceiver = null;
|
||||
}
|
||||
|
||||
|
@ -1289,7 +1290,6 @@ public class FileDisplayActivity extends FileActivity
|
|||
}
|
||||
}
|
||||
}
|
||||
removeStickyBroadcast(intent);
|
||||
DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
|
||||
|
||||
Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
|
||||
|
@ -1308,7 +1308,6 @@ public class FileDisplayActivity extends FileActivity
|
|||
} catch (RuntimeException e) {
|
||||
// avoid app crashes after changing the serial id of RemoteOperationResult
|
||||
// in owncloud library with broadcast notifications pending to process
|
||||
removeStickyBroadcast(intent);
|
||||
|
||||
try {
|
||||
DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
|
||||
|
@ -1362,74 +1361,67 @@ public class FileDisplayActivity extends FileActivity
|
|||
*/
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
try {
|
||||
String uploadedRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH);
|
||||
String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
|
||||
boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
|
||||
OCFile currentDir = getCurrentDir();
|
||||
boolean isDescendant = currentDir != null && uploadedRemotePath != null &&
|
||||
uploadedRemotePath.startsWith(currentDir.getRemotePath());
|
||||
String uploadedRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH);
|
||||
String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
|
||||
boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
|
||||
OCFile currentDir = getCurrentDir();
|
||||
boolean isDescendant = currentDir != null && uploadedRemotePath != null &&
|
||||
uploadedRemotePath.startsWith(currentDir.getRemotePath());
|
||||
|
||||
if (sameAccount && isDescendant) {
|
||||
String linkedToRemotePath =
|
||||
intent.getStringExtra(FileUploader.EXTRA_LINKED_TO_PATH);
|
||||
if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
|
||||
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);
|
||||
if (sameAccount && isDescendant) {
|
||||
String linkedToRemotePath =
|
||||
intent.getStringExtra(FileUploader.EXTRA_LINKED_TO_PATH);
|
||||
if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO refactor this receiver, and maybe DownloadFinishReceiver; this method is duplicated :S
|
||||
|
@ -1450,11 +1442,10 @@ public class FileDisplayActivity extends FileActivity
|
|||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
try {
|
||||
boolean sameAccount = isSameAccount(intent);
|
||||
String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
|
||||
String downloadBehaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR);
|
||||
boolean isDescendant = isDescendant(downloadedRemotePath);
|
||||
boolean sameAccount = isSameAccount(intent);
|
||||
String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
|
||||
String downloadBehaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR);
|
||||
boolean isDescendant = isDescendant(downloadedRemotePath);
|
||||
|
||||
if (sameAccount && isDescendant) {
|
||||
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));
|
||||
}
|
||||
|
||||
if (mWaitingToSend != null) {
|
||||
// update file after downloading
|
||||
mWaitingToSend = getStorageManager().getFileByRemoteId(mWaitingToSend.getRemoteId());
|
||||
if (mWaitingToSend != null && mWaitingToSend.isDown() && downloadBehaviour != null) {
|
||||
switch (downloadBehaviour) {
|
||||
case OCFileListFragment.DOWNLOAD_SEND:
|
||||
String packageName = intent.getStringExtra(SendShareDialog.PACKAGE_NAME);
|
||||
String activityName = intent.getStringExtra(SendShareDialog.ACTIVITY_NAME);
|
||||
if (mWaitingToSend != null) {
|
||||
// update file after downloading
|
||||
mWaitingToSend = getStorageManager().getFileByRemoteId(mWaitingToSend.getRemoteId());
|
||||
if (mWaitingToSend != null && mWaitingToSend.isDown() && downloadBehaviour != null) {
|
||||
switch (downloadBehaviour) {
|
||||
case OCFileListFragment.DOWNLOAD_SEND:
|
||||
String packageName = intent.getStringExtra(SendShareDialog.PACKAGE_NAME);
|
||||
String activityName = intent.getStringExtra(SendShareDialog.ACTIVITY_NAME);
|
||||
|
||||
sendDownloadedFile(packageName, activityName);
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
sendDownloadedFile(packageName, activityName);
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (intent != null) {
|
||||
removeStickyBroadcast(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ import android.view.View.OnClickListener;
|
|||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
|
@ -67,6 +66,7 @@ import javax.inject.Inject;
|
|||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
public class FolderPickerActivity extends FileActivity implements FileFragment.ContainerActivity,
|
||||
OnClickListener,
|
||||
|
@ -96,7 +96,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
|
|||
protected MaterialButton mCancelBtn;
|
||||
protected MaterialButton mChooseBtn;
|
||||
private String caption;
|
||||
@Inject AppPreferences preferences;
|
||||
@Inject LocalBroadcastManager localBroadcastManager;
|
||||
|
||||
@Override
|
||||
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_SHARES_SYNCED);
|
||||
mSyncBroadcastReceiver = new SyncBroadcastReceiver();
|
||||
registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
|
||||
localBroadcastManager.registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
|
||||
|
||||
Log_OC.d(TAG, "onResume() end");
|
||||
}
|
||||
|
@ -287,8 +287,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
|
|||
protected void onPause() {
|
||||
Log_OC.e(TAG, "onPause() start");
|
||||
if (mSyncBroadcastReceiver != null) {
|
||||
unregisterReceiver(mSyncBroadcastReceiver);
|
||||
//LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadcastReceiver);
|
||||
localBroadcastManager.unregisterReceiver(mSyncBroadcastReceiver);
|
||||
mSyncBroadcastReceiver = null;
|
||||
}
|
||||
|
||||
|
@ -532,7 +531,6 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
|
|||
|
||||
}
|
||||
}
|
||||
removeStickyBroadcast(intent);
|
||||
DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
|
||||
Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
|
||||
|
||||
|
@ -544,7 +542,6 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
|
|||
} catch (RuntimeException e) {
|
||||
// avoid app crashes after changing the serial id of RemoteOperationResult
|
||||
// in owncloud library with broadcast notifications pending to process
|
||||
removeStickyBroadcast(intent);
|
||||
DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,6 +120,7 @@ import androidx.appcompat.widget.SearchView;
|
|||
import androidx.core.view.MenuItemCompat;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import static com.owncloud.android.utils.DisplayUtils.openSortingOrderDialogFragment;
|
||||
|
||||
|
@ -140,6 +141,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
|||
public static final int SINGLE_PARENT = 1;
|
||||
|
||||
@Inject AppPreferences preferences;
|
||||
@Inject LocalBroadcastManager localBroadcastManager;
|
||||
private AccountManager mAccountManager;
|
||||
private Stack<String> mParents = new Stack<>();
|
||||
private List<Parcelable> mStreamsToUpload;
|
||||
|
@ -189,7 +191,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
|||
EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
|
||||
syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
|
||||
mSyncBroadcastReceiver = new SyncBroadcastReceiver();
|
||||
registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
|
||||
localBroadcastManager.registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
|
||||
|
||||
// Init Fragment without UI to retain AsyncTask across configuration changes
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
|
@ -266,7 +268,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
|||
@Override
|
||||
protected void onDestroy() {
|
||||
if (mSyncBroadcastReceiver != null) {
|
||||
unregisterReceiver(mSyncBroadcastReceiver);
|
||||
localBroadcastManager.unregisterReceiver(mSyncBroadcastReceiver);
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
@ -1151,14 +1153,12 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
|||
}
|
||||
}
|
||||
}
|
||||
removeStickyBroadcast(intent);
|
||||
Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
|
||||
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
// avoid app crashes after changing the serial id of RemoteOperationResult
|
||||
// in owncloud library with broadcast notifications pending to process
|
||||
removeStickyBroadcast(intent);
|
||||
DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ import com.owncloud.android.utils.ThemeUtils;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
|
@ -95,6 +96,9 @@ public class UploadListActivity extends FileActivity {
|
|||
@Inject
|
||||
BackgroundJobManager backgroundJobManager;
|
||||
|
||||
@Inject
|
||||
LocalBroadcastManager localBroadcastManager;
|
||||
|
||||
private UploadListLayoutBinding binding;
|
||||
|
||||
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.getUploadStartMessage());
|
||||
uploadIntentFilter.addAction(FileUploader.getUploadFinishMessage());
|
||||
registerReceiver(uploadMessagesReceiver, uploadIntentFilter);
|
||||
localBroadcastManager.registerReceiver(uploadMessagesReceiver, uploadIntentFilter);
|
||||
|
||||
Log_OC.v(TAG, "onResume() end");
|
||||
|
||||
|
@ -233,7 +237,7 @@ public class UploadListActivity extends FileActivity {
|
|||
protected void onPause() {
|
||||
Log_OC.v(TAG, "onPause() start");
|
||||
if (uploadMessagesReceiver != null) {
|
||||
unregisterReceiver(uploadMessagesReceiver);
|
||||
localBroadcastManager.unregisterReceiver(uploadMessagesReceiver);
|
||||
uploadMessagesReceiver = null;
|
||||
}
|
||||
super.onPause();
|
||||
|
@ -355,14 +359,7 @@ public class UploadListActivity extends FileActivity {
|
|||
*/
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
try {
|
||||
uploadListAdapter.loadUploadItemsFromDb();
|
||||
} finally {
|
||||
if (intent != null) {
|
||||
removeStickyBroadcast(intent);
|
||||
}
|
||||
}
|
||||
|
||||
uploadListAdapter.loadUploadItemsFromDb();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,10 +58,10 @@ import com.nextcloud.client.account.User;
|
|||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
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.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.network.ClientFactory;
|
||||
import com.owncloud.android.R;
|
||||
|
|
|
@ -65,6 +65,7 @@ import javax.inject.Inject;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
|
@ -80,16 +81,9 @@ public class PreviewImageActivity extends FileActivity implements
|
|||
Injectable {
|
||||
|
||||
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_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 PreviewImagePagerAdapter mPreviewImagePagerAdapter;
|
||||
|
@ -99,6 +93,14 @@ public class PreviewImageActivity extends FileActivity implements
|
|||
private DownloadFinishReceiver mDownloadFinishReceiver;
|
||||
private View mFullScreenAnchorView;
|
||||
@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
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -107,7 +109,7 @@ public class PreviewImageActivity extends FileActivity implements
|
|||
final ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
if (savedInstanceState != null && !savedInstanceState.getBoolean(KEY_SYSTEM_VISIBLE, true) &&
|
||||
actionBar != null) {
|
||||
actionBar != null) {
|
||||
actionBar.hide();
|
||||
}
|
||||
|
||||
|
@ -320,7 +322,7 @@ public class PreviewImageActivity extends FileActivity implements
|
|||
|
||||
IntentFilter filter = new IntentFilter(FileDownloader.getDownloadFinishMessage());
|
||||
filter.addAction(FileDownloader.getDownloadAddedMessage());
|
||||
registerReceiver(mDownloadFinishReceiver, filter);
|
||||
localBroadcastManager.registerReceiver(mDownloadFinishReceiver, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -331,7 +333,7 @@ public class PreviewImageActivity extends FileActivity implements
|
|||
@Override
|
||||
public void onPause() {
|
||||
if (mDownloadFinishReceiver != null){
|
||||
unregisterReceiver(mDownloadFinishReceiver);
|
||||
localBroadcastManager.unregisterReceiver(mDownloadFinishReceiver);
|
||||
mDownloadFinishReceiver = null;
|
||||
}
|
||||
|
||||
|
@ -448,27 +450,22 @@ public class PreviewImageActivity extends FileActivity implements
|
|||
|
||||
OCFile file = getStorageManager().getFileByPath(downloadedRemotePath);
|
||||
int position = mPreviewImagePagerAdapter.getFilePosition(file);
|
||||
boolean downloadWasFine = intent.getBooleanExtra(
|
||||
FileDownloader.EXTRA_DOWNLOAD_RESULT, false);
|
||||
boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false);
|
||||
//boolean isOffscreen = Math.abs((mViewPager.getCurrentItem() - position))
|
||||
// <= mViewPager.getOffscreenPageLimit();
|
||||
|
||||
if (position >= 0 &&
|
||||
intent.getAction().equals(FileDownloader.getDownloadFinishMessage())) {
|
||||
if (position >= 0 && intent.getAction().equals(FileDownloader.getDownloadFinishMessage())) {
|
||||
if (downloadWasFine) {
|
||||
mPreviewImagePagerAdapter.updateFile(position, file);
|
||||
|
||||
} else {
|
||||
mPreviewImagePagerAdapter.updateWithDownloadError(position);
|
||||
}
|
||||
mPreviewImagePagerAdapter.notifyDataSetChanged(); // will trigger the creation
|
||||
// of new fragments
|
||||
|
||||
mPreviewImagePagerAdapter.notifyDataSetChanged(); // will trigger the creation of new fragments
|
||||
} else {
|
||||
Log_OC.d(TAG, "Download finished, but the fragment is offscreen");
|
||||
}
|
||||
}
|
||||
removeStickyBroadcast(intent);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue