use of com.owncloud.android.datamodel.OCFile in project android by nextcloud.
the class BackupListFragment method onCreateView.
@Override
public View onCreateView(@NonNull final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
binding = BackuplistFragmentBinding.inflate(inflater, container, false);
View view = binding.getRoot();
setHasOptionsMenu(true);
ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity();
if (contactsPreferenceActivity != null) {
ActionBar actionBar = contactsPreferenceActivity.getSupportActionBar();
if (actionBar != null) {
ThemeToolbarUtils.setColoredTitle(actionBar, R.string.actionbar_calendar_contacts_restore, getContext());
actionBar.setDisplayHomeAsUpEnabled(true);
}
contactsPreferenceActivity.setDrawerIndicatorEnabled(false);
}
if (savedInstanceState == null) {
listAdapter = new BackupListAdapter(accountManager, clientFactory, new HashSet<>(), new HashMap<>(), this, requireContext());
} else {
HashMap<String, Integer> checkedCalendarItems = new HashMap<>();
String[] checkedCalendarItemsArray = savedInstanceState.getStringArray(CHECKED_CALENDAR_ITEMS_ARRAY_KEY);
if (checkedCalendarItemsArray != null) {
for (String checkedItem : checkedCalendarItemsArray) {
checkedCalendarItems.put(checkedItem, -1);
}
}
if (checkedCalendarItems.size() > 0) {
showRestoreButton(true);
}
HashSet<Integer> checkedContactsItems = new HashSet<>();
int[] checkedContactsItemsArray = savedInstanceState.getIntArray(CHECKED_CONTACTS_ITEMS_ARRAY_KEY);
if (checkedContactsItemsArray != null) {
for (int checkedItem : checkedContactsItemsArray) {
checkedContactsItems.add(checkedItem);
}
}
if (checkedContactsItems.size() > 0) {
showRestoreButton(true);
}
listAdapter = new BackupListAdapter(accountManager, clientFactory, checkedContactsItems, checkedCalendarItems, this, requireContext());
}
binding.list.setAdapter(listAdapter);
binding.list.setLayoutManager(new LinearLayoutManager(getContext()));
Bundle arguments = getArguments();
if (arguments == null) {
return view;
}
if (arguments.getParcelable(FILE_NAME) != null) {
ocFiles.add(arguments.getParcelable(FILE_NAME));
} else if (arguments.getParcelableArray(FILE_NAMES) != null) {
for (Parcelable file : arguments.getParcelableArray(FILE_NAMES)) {
ocFiles.add((OCFile) file);
}
} else {
return view;
}
User user = getArguments().getParcelable(USER);
fileDownloader = new TransferManagerConnection(getActivity(), user);
fileDownloader.registerTransferListener(this::onDownloadUpdate);
fileDownloader.bind();
for (OCFile file : ocFiles) {
if (!file.isDown()) {
Request request = new DownloadRequest(user, file);
fileDownloader.enqueue(request);
}
if (MimeTypeUtil.isVCard(file) && file.isDown()) {
setFile(file);
loadContactsTask = new LoadContactsTask(this, file);
loadContactsTask.execute();
}
if (MimeTypeUtil.isCalendar(file) && file.isDown()) {
showLoadingMessage(false);
listAdapter.addCalendar(file);
}
}
binding.restoreSelected.setOnClickListener(v -> {
if (checkAndAskForCalendarWritePermission()) {
importCalendar();
}
if (listAdapter.getCheckedContactsIntArray().length > 0 && checkAndAskForContactsWritePermission()) {
importContacts(selectedAccount);
return;
}
Snackbar.make(binding.list, R.string.contacts_preferences_import_scheduled, Snackbar.LENGTH_LONG).show();
closeFragment();
});
binding.restoreSelected.setTextColor(ThemeColorUtils.primaryAccentColor(getContext()));
return view;
}
use of com.owncloud.android.datamodel.OCFile in project android by nextcloud.
the class FileDetailFragment method onMessageEvent.
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(FavoriteEvent event) {
try {
User user = accountManager.getUser();
OwnCloudClient client = clientFactory.create(user);
ToggleFavoriteRemoteOperation toggleFavoriteOperation = new ToggleFavoriteRemoteOperation(event.shouldFavorite, event.remotePath);
RemoteOperationResult remoteOperationResult = toggleFavoriteOperation.execute(client);
if (remoteOperationResult.isSuccess()) {
getFile().setFavorite(event.shouldFavorite);
OCFile file = storageManager.getFileByEncryptedRemotePath(event.remotePath);
file.setFavorite(event.shouldFavorite);
storageManager.saveFile(file);
}
} catch (ClientFactory.CreationException e) {
Log_OC.e(TAG, "Error processing event", e);
}
}
use of com.owncloud.android.datamodel.OCFile in project android by nextcloud.
the class BackupFragment method refreshBackupFolder.
private void refreshBackupFolder(final String backupFolderPath, final Context context, final FileDataStorageManager storageManager) {
AsyncTask<String, Integer, Boolean> task = new AsyncTask<String, Integer, Boolean>() {
@Override
protected Boolean doInBackground(String... path) {
OCFile folder = storageManager.getFileByPath(path[0]);
if (folder != null) {
RefreshFolderOperation operation = new RefreshFolderOperation(folder, System.currentTimeMillis(), false, false, storageManager, user, context);
RemoteOperationResult result = operation.execute(user.toPlatformAccount(), context);
return result.isSuccess();
} else {
return Boolean.FALSE;
}
}
@Override
protected void onPostExecute(Boolean result) {
if (result && binding != null) {
OCFile backupFolder = storageManager.getFileByPath(backupFolderPath);
List<OCFile> backupFiles = storageManager.getFolderContent(backupFolder, false);
Collections.sort(backupFiles, new AlphanumComparator<>());
if (backupFiles == null || backupFiles.isEmpty()) {
binding.contactsDatepicker.setVisibility(View.GONE);
} else {
binding.contactsDatepicker.setVisibility(View.VISIBLE);
}
}
}
};
task.execute(backupFolderPath);
}
use of com.owncloud.android.datamodel.OCFile 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.OCFile 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 (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);
}
}
}
}
Aggregations