Search in sources :

Example 1 with Request

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;
}
Also used : ContactsPreferenceActivity(com.owncloud.android.ui.activity.ContactsPreferenceActivity) User(com.nextcloud.client.account.User) HashMap(java.util.HashMap) Bundle(android.os.Bundle) Request(com.nextcloud.client.files.downloader.Request) DownloadRequest(com.nextcloud.client.files.downloader.DownloadRequest) DownloadRequest(com.nextcloud.client.files.downloader.DownloadRequest) Parcelable(android.os.Parcelable) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) OCFile(com.owncloud.android.datamodel.OCFile) LoadContactsTask(com.owncloud.android.ui.asynctasks.LoadContactsTask) TransferManagerConnection(com.nextcloud.client.files.downloader.TransferManagerConnection) ActionBar(androidx.appcompat.app.ActionBar) HashSet(java.util.HashSet)

Example 2 with Request

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);
}
Also used : TransferManagerConnection(com.nextcloud.client.files.downloader.TransferManagerConnection) UploadRequest(com.nextcloud.client.files.downloader.UploadRequest) Request(com.nextcloud.client.files.downloader.Request)

Aggregations

Request (com.nextcloud.client.files.downloader.Request)2 TransferManagerConnection (com.nextcloud.client.files.downloader.TransferManagerConnection)2 Bundle (android.os.Bundle)1 Parcelable (android.os.Parcelable)1 View (android.view.View)1 ActionBar (androidx.appcompat.app.ActionBar)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 User (com.nextcloud.client.account.User)1 DownloadRequest (com.nextcloud.client.files.downloader.DownloadRequest)1 UploadRequest (com.nextcloud.client.files.downloader.UploadRequest)1 OCFile (com.owncloud.android.datamodel.OCFile)1 ContactsPreferenceActivity (com.owncloud.android.ui.activity.ContactsPreferenceActivity)1 LoadContactsTask (com.owncloud.android.ui.asynctasks.LoadContactsTask)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1