use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class GetCapabilitiesOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
final FileDataStorageManager storageManager = getStorageManager();
OCCapability currentCapability = null;
if (!storageManager.getUser().isAnonymous()) {
currentCapability = storageManager.getCapability(storageManager.getUser().getAccountName());
}
RemoteOperationResult result = new GetCapabilitiesRemoteOperation(currentCapability).execute(client);
if (result.isSuccess() && result.getData() != null && result.getData().size() > 0) {
// Read data from the result
OCCapability capability = (OCCapability) result.getData().get(0);
// Save the capabilities into database
storageManager.saveCapabilities(capability);
// update cached entry
CapabilityUtils.updateCapability(capability);
}
return result;
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class OCFileListFragment method listDirectory.
/**
* Lists the given directory on the view. When the input parameter is null,
* it will either refresh the last known directory. list the root
* if there never was a directory.
*
* @param directory File to be listed
*/
public void listDirectory(OCFile directory, OCFile file, boolean onlyOnDevice, boolean fromSearch) {
if (!searchFragment) {
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
if (storageManager != null) {
// Check input parameters for null
if (directory == null) {
if (mFile != null) {
directory = mFile;
} else {
directory = storageManager.getFileByPath(ROOT_PATH);
if (directory == null) {
// no files, wait for sync
return;
}
}
}
// If that's not a directory -> List its parent
if (!directory.isFolder()) {
Log_OC.w(TAG, "You see, that is not a directory -> " + directory);
directory = storageManager.getFileById(directory.getParentId());
if (directory == null) {
// no files, wait for sync
return;
}
}
if (searchView != null && !searchView.isIconified() && !fromSearch) {
searchView.post(() -> {
searchView.setQuery("", false);
searchView.onActionViewCollapsed();
Activity activity;
if ((activity = getActivity()) != null && activity instanceof FileDisplayActivity) {
FileDisplayActivity fileDisplayActivity = (FileDisplayActivity) activity;
fileDisplayActivity.hideSearchView(fileDisplayActivity.getCurrentDir());
if (getCurrentFile() != null) {
fileDisplayActivity.setDrawerIndicatorEnabled(fileDisplayActivity.isRoot(getCurrentFile()));
}
}
});
}
mAdapter.swapDirectory(accountManager.getUser(), directory, storageManager, onlyOnDevice, mLimitToMimeType);
OCFile previousDirectory = mFile;
mFile = directory;
updateLayout();
if (file != null) {
mAdapter.setHighlightedItem(file);
int position = mAdapter.getItemPosition(file);
if (position != -1) {
getRecyclerView().scrollToPosition(position);
}
} else if (previousDirectory == null || !previousDirectory.equals(directory)) {
getRecyclerView().scrollToPosition(0);
}
}
}
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class FileDetailFragment method updateFileDetails.
/**
* Updates the view with all relevant details about that file.
*
* TODO Remove parameter when the transferring state of files is kept in database.
*
* @param transferring Flag signaling if the file should be considered as downloading or uploading,
* although {@link FileDownloaderBinder#isDownloading(User, OCFile)} and
* {@link FileUploaderBinder#isUploading(User, OCFile)} return false.
* @param refresh If 'true', try to refresh the whole file from the database
*/
public void updateFileDetails(boolean transferring, boolean refresh) {
if (readyToShow()) {
FileDataStorageManager storageManager = containerActivity.getStorageManager();
if (storageManager == null) {
return;
}
if (refresh) {
setFile(storageManager.getFileByPath(getFile().getRemotePath()));
}
OCFile file = getFile();
// set file details
if (MimeTypeUtil.isImage(file)) {
binding.filename.setText(file.getFileName());
} else {
binding.filename.setVisibility(View.GONE);
}
binding.size.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
boolean showDetailedTimestamp = preferences.isShowDetailedTimestampEnabled();
setFileModificationTimestamp(file, showDetailedTimestamp);
setFilePreview(file);
setFavoriteIconStatus(file.isFavorite());
// configure UI for depending upon local state of the file
FileDownloaderBinder downloaderBinder = containerActivity.getFileDownloaderBinder();
FileUploaderBinder uploaderBinder = containerActivity.getFileUploaderBinder();
if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(user, file)) || (uploaderBinder != null && uploaderBinder.isUploading(user, file))) {
setButtonsForTransferring();
} else if (file.isDown()) {
setButtonsForDown();
} else {
// TODO load default preview image; when the local file is removed, the preview
// remains there
setButtonsForRemote();
}
}
setupViewPager();
getView().invalidate();
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class ConflictsResolveDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Inflate the layout for the dialog
binding = ConflictResolveDialogBinding.inflate(requireActivity().getLayoutInflater());
themeCheckableUtils.tintCheckbox(themeColorUtils.primaryColor(getContext()), binding.newCheckbox, binding.existingCheckbox);
// Build the dialog
AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
builder.setView(binding.getRoot()).setPositiveButton(R.string.common_ok, (dialog, which) -> {
if (listener != null) {
if (binding.newCheckbox.isChecked() && binding.existingCheckbox.isChecked()) {
listener.conflictDecisionMade(Decision.KEEP_BOTH);
} else if (binding.newCheckbox.isChecked()) {
listener.conflictDecisionMade(Decision.KEEP_LOCAL);
} else if (binding.existingCheckbox.isChecked()) {
listener.conflictDecisionMade(Decision.KEEP_SERVER);
}
// else do nothing
}
}).setNeutralButton(R.string.common_cancel, (dialog, which) -> {
if (listener != null) {
listener.conflictDecisionMade(Decision.CANCEL);
}
}).setTitle(String.format(getString(R.string.conflict_file_headline), existingFile.getFileName()));
File parentFile = new File(existingFile.getRemotePath()).getParentFile();
if (parentFile != null) {
binding.in.setText(String.format(getString(R.string.in_folder), parentFile.getAbsolutePath()));
} else {
binding.in.setVisibility(View.GONE);
}
// set info for new file
binding.newSize.setText(DisplayUtils.bytesToHumanReadable(newFile.length()));
binding.newTimestamp.setText(DisplayUtils.getRelativeTimestamp(getContext(), newFile.lastModified()));
binding.newThumbnail.setTag(newFile.hashCode());
LocalFileListAdapter.setThumbnail(newFile, binding.newThumbnail, getContext(), themeColorUtils, themeDrawableUtils);
// set info for existing file
binding.existingSize.setText(DisplayUtils.bytesToHumanReadable(existingFile.getFileLength()));
binding.existingTimestamp.setText(DisplayUtils.getRelativeTimestamp(getContext(), existingFile.getModificationTimestamp()));
binding.existingThumbnail.setTag(existingFile.getFileId());
DisplayUtils.setThumbnail(existingFile, binding.existingThumbnail, user, new FileDataStorageManager(user, requireContext().getContentResolver()), asyncTasks, false, getContext(), null, null, themeColorUtils, themeDrawableUtils);
View.OnClickListener checkBoxClickListener = v -> positiveButton.setEnabled(binding.newCheckbox.isChecked() || binding.existingCheckbox.isChecked());
binding.newCheckbox.setOnClickListener(checkBoxClickListener);
binding.existingCheckbox.setOnClickListener(checkBoxClickListener);
binding.newFileContainer.setOnClickListener(v -> {
binding.newCheckbox.setChecked(!binding.newCheckbox.isChecked());
positiveButton.setEnabled(binding.newCheckbox.isChecked() || binding.existingCheckbox.isChecked());
});
binding.existingFileContainer.setOnClickListener(v -> {
binding.existingCheckbox.setChecked(!binding.existingCheckbox.isChecked());
positiveButton.setEnabled(binding.newCheckbox.isChecked() || binding.existingCheckbox.isChecked());
});
return builder.create();
}
use of com.owncloud.android.datamodel.FileDataStorageManager 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..");
initFragments();
if (file.isFolder() && TextUtils.isEmpty(searchQuery)) {
startSyncFolderOperation(file, false);
}
} else {
updateActionBarTitleAndHomeButton(file.isFolder() ? null : file);
}
}
lastDisplayedUser = optionalUser;
EventBus.getDefault().post(new TokenPushEvent());
checkForNewDevVersionNecessary(getApplicationContext());
}
Aggregations