Merge pull request #8730 from nextcloud/migrate-file-activity-extra-account-to-extra-user

Migrate FileActivity.EXTRA_ACCOUNT to EXTRA_USER and use User model as well
This commit is contained in:
Álvaro Brey 2021-12-13 11:37:44 +01:00 committed by GitHub
commit d9874c788c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 50 additions and 49 deletions

View file

@ -35,6 +35,7 @@ import com.owncloud.android.files.BootupBroadcastReceiver;
import com.owncloud.android.files.services.FileDownloader;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.providers.DiskLruImageCacheFileProvider;
import com.owncloud.android.providers.DocumentsStorageProvider;
import com.owncloud.android.providers.FileContentProvider;
import com.owncloud.android.providers.UsersAndGroupsSearchProvider;
import com.owncloud.android.services.AccountManagerService;
@ -203,7 +204,8 @@ abstract class ComponentsModule {
@ContributesAndroidInjector abstract FileContentProvider fileContentProvider();
@ContributesAndroidInjector abstract UsersAndGroupsSearchProvider usersAndGroupsSearchProvider();
@ContributesAndroidInjector abstract DiskLruImageCacheFileProvider diskLruImageCacheFileProvider();
@ContributesAndroidInjector abstract DocumentsStorageProvider documentsStorageProvider();
@ContributesAndroidInjector abstract AccountManagerService accountManagerService();
@ContributesAndroidInjector abstract OperationsService operationsService();
@ContributesAndroidInjector abstract PlayerService playerService();

View file

@ -23,12 +23,10 @@
package com.owncloud.android.db;
import android.accounts.Account;
import android.os.Parcel;
import android.os.Parcelable;
import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datamodel.UploadsStorageManager;
import com.owncloud.android.datamodel.UploadsStorageManager.UploadStatus;

View file

@ -575,7 +575,7 @@ public class FileDownloader extends Service
showDetailsIntent = new Intent(this, FileDisplayActivity.class);
}
showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, download.getFile());
showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, download.getAccount());
showDetailsIntent.putExtra(FileActivity.EXTRA_USER, download.getAccount());
showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this, (int) System.currentTimeMillis(),

View file

@ -721,7 +721,7 @@ public class FileUploader extends Service
/// includes a pending intent in the notification showing the details
Intent intent = UploadListActivity.createIntent(upload.getFile(),
upload.getAccount(),
upload.getUser(),
Intent.FLAG_ACTIVITY_CLEAR_TOP,
this);
mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this,
@ -833,13 +833,13 @@ public class FileUploader extends Service
Intent intent;
if (uploadResult.getCode().equals(ResultCode.SYNC_CONFLICT)) {
intent = ConflictsResolveActivity.createIntent(upload.getFile(),
upload.getAccount(),
upload.getUser(),
upload.getOCUploadId(),
Intent.FLAG_ACTIVITY_CLEAR_TOP,
this);
} else {
intent = UploadListActivity.createIntent(upload.getFile(),
upload.getAccount(),
upload.getUser(),
Intent.FLAG_ACTIVITY_CLEAR_TOP,
this);
}

View file

@ -267,6 +267,10 @@ public class UploadFileOperation extends SyncOperation {
return user.toPlatformAccount();
}
public User getUser() {
return user;
}
public String getFileName() {
return (mFile != null) ? mFile.getFileName() : null;
}

View file

@ -22,7 +22,6 @@
package com.owncloud.android.providers;
import android.accounts.Account;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.annotation.SuppressLint;
@ -46,7 +45,6 @@ import android.widget.Toast;
import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.account.UserAccountManagerImpl;
import com.nextcloud.client.files.downloader.DownloadTask;
import com.nextcloud.client.preferences.AppPreferences;
import com.nextcloud.client.preferences.AppPreferencesImpl;
@ -89,8 +87,11 @@ import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import dagger.android.AndroidInjection;
import static android.os.ParcelFileDescriptor.MODE_READ_ONLY;
import static android.os.ParcelFileDescriptor.MODE_WRITE_ONLY;
@ -104,6 +105,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
private static final long CACHE_EXPIRATION = TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES);
@Inject
UserAccountManager accountManager;
@VisibleForTesting
@ -302,7 +304,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
@Override
public boolean onCreate() {
accountManager = UserAccountManagerImpl.fromContext(getContext());
AndroidInjection.inject(this);
// initiate storage manager collection, because we need to serve document(tree)s
// with persist permissions

View file

@ -51,7 +51,7 @@ import androidx.annotation.VisibleForTesting;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import static com.owncloud.android.ui.activity.FileActivity.EXTRA_ACCOUNT;
import static com.owncloud.android.ui.activity.FileActivity.EXTRA_USER;
import static com.owncloud.android.ui.activity.FileActivity.EXTRA_FILE;
/**
@ -210,7 +210,7 @@ public class ActivitiesActivity extends DrawerActivity implements ActivityListIn
showDetailsIntent = new Intent(getBaseContext(), FileDisplayActivity.class);
}
showDetailsIntent.putExtra(EXTRA_FILE, ocFile);
showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
showDetailsIntent.putExtra(EXTRA_USER, getUser().orElseThrow(RuntimeException::new));
startActivity(showDetailsIntent);
}

View file

@ -73,7 +73,7 @@ public class ConflictsResolveActivity extends FileActivity implements OnConflict
protected OnConflictDecisionMadeListener listener;
public static Intent createIntent(OCFile file,
Account account,
User user,
long conflictUploadId,
Integer flag,
Context context) {
@ -82,7 +82,7 @@ public class ConflictsResolveActivity extends FileActivity implements OnConflict
intent.setFlags(intent.getFlags() | flag);
}
intent.putExtra(EXTRA_FILE, file);
intent.putExtra(EXTRA_ACCOUNT, account);
intent.putExtra(EXTRA_USER, user);
intent.putExtra(EXTRA_CONFLICT_UPLOAD_ID, conflictUploadId);
return intent;

View file

@ -145,7 +145,7 @@ public abstract class EditorWebView extends ExternalSiteWebView {
private void openShareDialog() {
Intent intent = new Intent(this, ShareActivity.class);
intent.putExtra(FileActivity.EXTRA_FILE, getFile());
intent.putExtra(FileActivity.EXTRA_ACCOUNT, getAccount());
intent.putExtra(FileActivity.EXTRA_USER, getUser().orElseThrow(RuntimeException::new));
startActivity(intent);
}

View file

@ -42,6 +42,7 @@ import android.text.TextUtils;
import android.widget.Toast;
import com.google.android.material.snackbar.Snackbar;
import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.jobs.BackgroundJobManager;
import com.nextcloud.client.network.ConnectivityService;
@ -120,7 +121,6 @@ public abstract class FileActivity extends DrawerActivity
LoadingVersionNumberTask.VersionDevInterface, FileDetailSharingFragment.OnEditShareListener {
public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
public static final String EXTRA_ACCOUNT = "com.owncloud.android.ui.activity.ACCOUNT";
public static final String EXTRA_USER = "com.owncloud.android.ui.activity.USER";
public static final String EXTRA_FROM_NOTIFICATION = "com.owncloud.android.ui.activity.FROM_NOTIFICATION";
public static final String APP_OPENED_COUNT = "APP_OPENED_COUNT";
@ -197,7 +197,6 @@ public abstract class FileActivity extends DrawerActivity
super.onCreate(savedInstanceState);
mHandler = new Handler();
mFileOperationsHelper = new FileOperationsHelper(this, getUserAccountManager(), connectivityService);
Account account = null;
if (savedInstanceState != null) {
mFile = savedInstanceState.getParcelable(FileActivity.EXTRA_FILE);
@ -207,13 +206,15 @@ public abstract class FileActivity extends DrawerActivity
);
ThemeToolbarUtils.setColoredTitle(getSupportActionBar(), savedInstanceState.getString(KEY_ACTION_BAR_TITLE), this);
} else {
account = getIntent().getParcelableExtra(FileActivity.EXTRA_ACCOUNT);
User user = getIntent().getParcelableExtra(FileActivity.EXTRA_USER);
mFile = getIntent().getParcelableExtra(FileActivity.EXTRA_FILE);
mFromNotification = getIntent().getBooleanExtra(FileActivity.EXTRA_FROM_NOTIFICATION,
false);
if (user != null) {
setUser(user);
}
}
setAccount(account, savedInstanceState != null);
mOperationsServiceConnection = new OperationsServiceConnection();
bindService(new Intent(this, OperationsService.class), mOperationsServiceConnection,
@ -234,13 +235,9 @@ public abstract class FileActivity extends DrawerActivity
@Override
protected void onStart() {
super.onStart();
fetchExternalLinks(false);
}
@Override
protected void onResume() {
super.onResume();
@ -259,7 +256,6 @@ public abstract class FileActivity extends DrawerActivity
super.onPause();
}
@Override
protected void onDestroy() {
if (mOperationsServiceConnection != null) {
@ -278,9 +274,6 @@ public abstract class FileActivity extends DrawerActivity
super.onDestroy();
}
/**
* {@inheritDoc}
*/
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
@ -336,7 +329,6 @@ public abstract class FileActivity extends DrawerActivity
return this;
}
public Handler getHandler() {
return mHandler;
}
@ -509,7 +501,11 @@ public abstract class FileActivity extends DrawerActivity
OCFile syncedFile = operation.getLocalFile();
if (!result.isSuccess()) {
if (result.getCode() == ResultCode.SYNC_CONFLICT) {
Intent intent = ConflictsResolveActivity.createIntent(syncedFile, getAccount(), -1, null, this);
Intent intent = ConflictsResolveActivity.createIntent(syncedFile,
getUser().orElseThrow(RuntimeException::new),
-1,
null,
this);
startActivity(intent);
}
@ -549,7 +545,6 @@ public abstract class FileActivity extends DrawerActivity
}
}
/**
* Dismiss loading dialog
*/
@ -562,7 +557,6 @@ public abstract class FileActivity extends DrawerActivity
}
}
private void doOnResumeAndBound() {
mOperationsServiceBinder.addOperationListener(this, mHandler);
long waitingForOpId = mFileOperationsHelper.getOpIdWaitingFor();
@ -575,7 +569,6 @@ public abstract class FileActivity extends DrawerActivity
}
}
/**
* Implements callback methods for service binding. Passed as a parameter to {
*/

View file

@ -230,7 +230,7 @@ public class FileDisplayActivity extends FileActivity
public static Intent openFileIntent(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());
intent.putExtra(FileActivity.EXTRA_USER, user);
return intent;
}
@ -2139,7 +2139,7 @@ public class FileDisplayActivity extends FileActivity
public void startImagePreview(OCFile file, boolean showPreview) {
Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
showDetailsIntent.putExtra(EXTRA_FILE, file);
showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
showDetailsIntent.putExtra(EXTRA_USER, getUser().orElseThrow(RuntimeException::new));
if (showPreview) {
startActivity(showDetailsIntent);
} else {
@ -2158,7 +2158,7 @@ public class FileDisplayActivity extends FileActivity
public void startImagePreview(OCFile file, VirtualFolderType type, boolean showPreview) {
Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
showDetailsIntent.putExtra(PreviewImageActivity.EXTRA_FILE, file);
showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
showDetailsIntent.putExtra(EXTRA_USER, getUser().orElseThrow(RuntimeException::new));
showDetailsIntent.putExtra(PreviewImageActivity.EXTRA_VIRTUAL_TYPE, type);
if (showPreview) {

View file

@ -264,7 +264,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
super.onSaveInstanceState(outState);
outState.putString(KEY_PARENTS, generatePath(mParents));
outState.putParcelable(KEY_FILE, mFile);
outState.putParcelable(FileActivity.EXTRA_ACCOUNT, getAccount());
outState.putParcelable(FileActivity.EXTRA_USER, getUser().orElseThrow(RuntimeException::new));
Log_OC.d(TAG, "onSaveInstanceState() end");
}

View file

@ -38,6 +38,7 @@ import android.widget.TextView;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.snackbar.Snackbar;
import com.nextcloud.client.account.User;
import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.preferences.AppPreferences;
import com.owncloud.android.R;
@ -76,7 +77,7 @@ import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import static com.owncloud.android.ui.activity.FileActivity.EXTRA_ACCOUNT;
import static com.owncloud.android.ui.activity.FileActivity.EXTRA_USER;
/**
* Displays local files and let the user choose what of them wants to upload to the current ownCloud account.
@ -121,12 +122,12 @@ public class UploadFilesActivity extends DrawerActivity implements LocalFileList
* onActivityResult() method will be called with the given requestCode.
*
* @param activity the activity which should call the upload activity for a result
* @param account the account for which the upload activity is called
* @param user the user for which the upload activity is called
* @param requestCode If >= 0, this code will be returned in onActivityResult()
*/
public static void startUploadActivityForResult(Activity activity, Account account, int requestCode) {
public static void startUploadActivityForResult(Activity activity, User user, int requestCode) {
Intent action = new Intent(activity, UploadFilesActivity.class);
action.putExtra(EXTRA_ACCOUNT, account);
action.putExtra(EXTRA_USER, user);
action.putExtra(REQUEST_CODE_KEY, requestCode);
activity.startActivityForResult(action, requestCode);
}

View file

@ -37,6 +37,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.core.Clock;
import com.nextcloud.client.device.PowerManagementService;
@ -101,13 +102,13 @@ public class UploadListActivity extends FileActivity {
private UploadListLayoutBinding binding;
public static Intent createIntent(OCFile file, Account account, Integer flag, Context context) {
public static Intent createIntent(OCFile file, User user, Integer flag, Context context) {
Intent intent = new Intent(context, UploadListActivity.class);
if (flag != null) {
intent.setFlags(intent.getFlags() | flag);
}
intent.putExtra(ConflictsResolveActivity.EXTRA_FILE, file);
intent.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, account);
intent.putExtra(ConflictsResolveActivity.EXTRA_USER, user);
return intent;
}

View file

@ -578,7 +578,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
Optional<User> user = accountManager.getUser(upload.getAccountName());
if (user.isPresent()) {
Intent intent = ConflictsResolveActivity.createIntent(file,
user.get().toPlatformAccount(),
user.get(),
upload.getUploadId(),
Intent.FLAG_ACTIVITY_NEW_TASK,
context);

View file

@ -477,7 +477,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
public void uploadFiles() {
UploadFilesActivity.startUploadActivityForResult(
getActivity(),
((FileActivity) getActivity()).getAccount(),
((FileActivity) getActivity()).getUser().orElseThrow(RuntimeException::new),
FileDisplayActivity.REQUEST_CODE__SELECT_FILES_FROM_FILE_SYSTEM
);
}

View file

@ -260,7 +260,7 @@ public class FileOperationsHelper {
// ISSUE 5: if the user is not running the app (this is a service!),
// this can be very intrusive; a notification should be preferred
Intent intent = ConflictsResolveActivity.createIntent(file,
user.toPlatformAccount(),
user,
-1,
Intent.FLAG_ACTIVITY_NEW_TASK,
fileActivity);
@ -332,7 +332,7 @@ public class FileOperationsHelper {
// ISSUE 5: if the user is not running the app (this is a service!),
// this can be very intrusive; a notification should be preferred
Intent intent = ConflictsResolveActivity.createIntent(file,
user.toPlatformAccount(),
user,
-1,
Intent.FLAG_ACTIVITY_NEW_TASK,
fileActivity);
@ -628,7 +628,7 @@ public class FileOperationsHelper {
public void showShareFile(OCFile file) {
Intent intent = new Intent(fileActivity, ShareActivity.class);
intent.putExtra(FileActivity.EXTRA_FILE, file);
intent.putExtra(FileActivity.EXTRA_ACCOUNT, fileActivity.getAccount());
intent.putExtra(FileActivity.EXTRA_USER, fileActivity.getUser().orElseThrow(RuntimeException::new));
fileActivity.startActivity(intent);
}

View file

@ -98,7 +98,7 @@ public class PreviewImageActivity extends FileActivity implements
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());
intent.putExtra(FileActivity.EXTRA_USER, user);
return intent;
}

View file

@ -598,7 +598,7 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene
private void startFullScreenVideo() {
Intent intent = new Intent(getActivity(), PreviewVideoActivity.class);
intent.putExtra(FileActivity.EXTRA_ACCOUNT, user.toPlatformAccount());
intent.putExtra(FileActivity.EXTRA_USER, user);
intent.putExtra(FileActivity.EXTRA_FILE, getFile());
intent.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, exoPlayer.isPlaying());
intent.putExtra(PreviewVideoActivity.EXTRA_STREAM_URL, videoUri);