use of com.nextcloud.client.account.User in project android by nextcloud.
the class FileDisplayActivity method startContactListFragment.
public void startContactListFragment(OCFile file) {
final User user = getUser().orElseThrow(RuntimeException::new);
ContactsPreferenceActivity.startActivityWithContactsFile(this, user, file);
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class FileDisplayActivity method onStart.
@Override
public void onStart() {
super.onStart();
final Optional<User> optionalUser = getUser();
final FileDataStorageManager storageManager = getStorageManager();
if (optionalUser.isPresent() && storageManager != null) {
// / Check whether the 'main' OCFile handled by the Activity is contained in the
// current Account
OCFile file = getFile();
// get parent from path
String parentPath = "";
if (file != null) {
if (file.isDown() && file.getLastSyncDateForProperties() == 0) {
// upload in progress - right now, files are not inserted in the local
// cache until the upload is successful get parent from path
parentPath = file.getRemotePath().substring(0, file.getRemotePath().lastIndexOf(file.getFileName()));
if (storageManager.getFileByPath(parentPath) == null) {
// not able to know the directory where the file is uploading
file = null;
}
} else {
file = storageManager.getFileByPath(file.getRemotePath());
// currentDir = null if not in the current Account
}
}
if (file == null) {
// fall back to root folder
// never returns null
file = storageManager.getFileByPath(OCFile.ROOT_PATH);
}
setFile(file);
User user = optionalUser.get();
setupDrawer();
mSwitchAccountButton.setTag(user.getAccountName());
DisplayUtils.setAvatar(user, this, getResources().getDimension(R.dimen.nav_drawer_menu_avatar_radius), getResources(), mSwitchAccountButton, this);
final boolean userChanged = !user.nameEquals(lastDisplayedUser.orElse(null));
if (userChanged) {
Log_OC.d(TAG, "Initializing Fragments in onAccountChanged..");
initFragmentsWithFile(user, file);
if (file.isFolder() && TextUtils.isEmpty(searchQuery)) {
startSyncFolderOperation(file, false);
}
} else {
updateActionBarTitleAndHomeButton(file.isFolder() ? null : file);
}
}
lastDisplayedUser = optionalUser;
EventBus.getDefault().post(new TokenPushEvent());
checkForNewDevVersionNecessary(getApplicationContext());
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class FileDisplayActivity method startTextPreview.
/**
* Starts the preview of a text file {@link OCFile}.
*
* @param file Text {@link OCFile} to preview.
*/
public void startTextPreview(OCFile file, boolean showPreview) {
Optional<User> optUser = getUser();
if (!optUser.isPresent()) {
// remnants of old unsafe system; do not crash, silently stop
return;
}
User user = optUser.get();
if (showPreview) {
showSortListGroup(false);
PreviewTextFileFragment fragment = PreviewTextFileFragment.create(user, file, searchOpen, searchQuery);
setLeftFragment(fragment);
binding.rightFragmentContainer.setVisibility(View.GONE);
super.updateActionBarTitleAndHomeButton(file);
} else {
Intent previewIntent = new Intent();
previewIntent.putExtra(EXTRA_FILE, file);
previewIntent.putExtra(TEXT_PREVIEW, true);
FileOperationsHelper fileOperationsHelper = new FileOperationsHelper(this, getUserAccountManager(), connectivityService);
fileOperationsHelper.startSyncForFileAndIntent(file, previewIntent);
}
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class FileDisplayActivity method startDownloadForPreview.
/**
* Requests the download of the received {@link OCFile} , updates the UI to monitor the download progress and
* prepares the activity to preview or open the file when the download finishes.
*
* @param file {@link OCFile} to download and preview.
*/
public void startDownloadForPreview(OCFile file) {
final User currentUser = getUser().orElseThrow(RuntimeException::new);
Fragment detailFragment = FileDetailFragment.newInstance(file, currentUser);
setLeftFragment(detailFragment);
mWaitingToPreview = file;
requestForDownload();
updateActionBarTitleAndHomeButton(file);
setFile(file);
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class FileActivity method onCreate.
/**
* Loads the ownCloud {@link Account} and main {@link OCFile} to be handled by the instance of
* the {@link FileActivity}.
*
* Grants that a valid ownCloud {@link Account} is associated to the instance, or that the user
* is requested to create a new one.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mHandler = new Handler();
mFileOperationsHelper = new FileOperationsHelper(this, getUserAccountManager(), connectivityService);
if (savedInstanceState != null) {
mFile = savedInstanceState.getParcelable(FileActivity.EXTRA_FILE);
mFromNotification = savedInstanceState.getBoolean(FileActivity.EXTRA_FROM_NOTIFICATION);
mFileOperationsHelper.setOpIdWaitingFor(savedInstanceState.getLong(KEY_WAITING_FOR_OP_ID, Long.MAX_VALUE));
ThemeToolbarUtils.setColoredTitle(getSupportActionBar(), savedInstanceState.getString(KEY_ACTION_BAR_TITLE), this);
} else {
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);
}
}
mOperationsServiceConnection = new OperationsServiceConnection();
bindService(new Intent(this, OperationsService.class), mOperationsServiceConnection, Context.BIND_AUTO_CREATE);
mDownloadServiceConnection = newTransferenceServiceConnection();
if (mDownloadServiceConnection != null) {
bindService(new Intent(this, FileDownloader.class), mDownloadServiceConnection, Context.BIND_AUTO_CREATE);
}
mUploadServiceConnection = newTransferenceServiceConnection();
if (mUploadServiceConnection != null) {
bindService(new Intent(this, FileUploader.class), mUploadServiceConnection, Context.BIND_AUTO_CREATE);
}
}
Aggregations