Search in sources :

Example 71 with OCFile

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;
}
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 72 with OCFile

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);
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ClientFactory(com.nextcloud.client.network.ClientFactory) ToggleFavoriteRemoteOperation(com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation) OwnCloudClient(com.owncloud.android.lib.common.OwnCloudClient) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 73 with OCFile

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);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) RefreshFolderOperation(com.owncloud.android.operations.RefreshFolderOperation) AsyncTask(android.os.AsyncTask)

Example 74 with OCFile

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();
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FileDownloaderBinder(com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder) FileUploaderBinder(com.owncloud.android.files.services.FileUploader.FileUploaderBinder) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 75 with OCFile

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);
            }
        }
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) UploadFilesActivity(com.owncloud.android.ui.activity.UploadFilesActivity) ToolbarActivity(com.owncloud.android.ui.activity.ToolbarActivity) FolderPickerActivity(com.owncloud.android.ui.activity.FolderPickerActivity) FileActivity(com.owncloud.android.ui.activity.FileActivity) FragmentActivity(androidx.fragment.app.FragmentActivity) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) Activity(android.app.Activity)

Aggregations

OCFile (com.owncloud.android.datamodel.OCFile)307 File (java.io.File)56 Test (org.junit.Test)44 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)43 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)40 ArrayList (java.util.ArrayList)28 Intent (android.content.Intent)27 OCFileListFragment (com.owncloud.android.ui.fragment.OCFileListFragment)22 OCUpload (com.owncloud.android.db.OCUpload)20 ScreenshotTest (com.owncloud.android.utils.ScreenshotTest)20 FileFragment (com.owncloud.android.ui.fragment.FileFragment)19 User (com.nextcloud.client.account.User)17 RemoteFile (com.owncloud.android.lib.resources.files.model.RemoteFile)16 Bundle (android.os.Bundle)13 Fragment (androidx.fragment.app.Fragment)12 RemoteFile (com.owncloud.android.lib.resources.files.RemoteFile)12 FileDetailFragment (com.owncloud.android.ui.fragment.FileDetailFragment)12 Account (android.accounts.Account)11 SuppressLint (android.annotation.SuppressLint)11 PreviewTextFragment (com.owncloud.android.ui.preview.PreviewTextFragment)11