use of com.nextcloud.client.files.downloader.Request 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.nextcloud.client.files.downloader.Request in project android by nextcloud.
the class SaveCalendar method upload.
private void upload(File file) {
String backupFolder = activity.getResources().getString(R.string.calendar_backup_folder) + OCFile.PATH_SEPARATOR;
Request request = new UploadRequest.Builder(user, file.getAbsolutePath(), backupFolder + file.getName()).setFileSize(file.length()).setNameConflicPolicy(NameCollisionPolicy.RENAME).setCreateRemoteFolder(true).setTrigger(UploadTrigger.USER).setPostAction(PostUploadAction.MOVE_TO_APP).setRequireWifi(false).setRequireCharging(false).build();
TransferManagerConnection connection = new TransferManagerConnection(activity, user);
connection.enqueue(request);
}
Aggregations