Search in sources :

Example 46 with FileDataStorageManager

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;
}
Also used : OCCapability(com.owncloud.android.lib.resources.status.OCCapability) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) GetCapabilitiesRemoteOperation(com.owncloud.android.lib.resources.status.GetCapabilitiesRemoteOperation)

Example 47 with FileDataStorageManager

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);
            }
        }
    }
}
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) AppScanActivity(com.owncloud.android.ui.activity.AppScanActivity) 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)

Example 48 with FileDataStorageManager

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();
}
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 49 with FileDataStorageManager

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();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Context(android.content.Context) User(com.nextcloud.client.account.User) ThumbnailsCacheManager(com.owncloud.android.datamodel.ThumbnailsCacheManager) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) NonNull(androidx.annotation.NonNull) OCFile(com.owncloud.android.datamodel.OCFile) Dialog(android.app.Dialog) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) ThemeCheckableUtils(com.owncloud.android.utils.theme.ThemeCheckableUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) LocalFileListAdapter(com.owncloud.android.ui.adapter.LocalFileListAdapter) ConflictResolveDialogBinding(com.owncloud.android.databinding.ConflictResolveDialogBinding) Toast(android.widget.Toast) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) DisplayUtils(com.owncloud.android.utils.DisplayUtils) ThemeDrawableUtils(com.owncloud.android.utils.theme.ThemeDrawableUtils) DialogInterface(android.content.DialogInterface) FragmentTransaction(androidx.fragment.app.FragmentTransaction) File(java.io.File) Log_OC(com.owncloud.android.lib.common.utils.Log_OC) List(java.util.List) ThemeColorUtils(com.owncloud.android.utils.theme.ThemeColorUtils) Nullable(androidx.annotation.Nullable) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) Injectable(com.nextcloud.client.di.Injectable) R(com.owncloud.android.R) ThemeButtonUtils(com.owncloud.android.utils.theme.ThemeButtonUtils) DialogFragment(androidx.fragment.app.DialogFragment) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File) View(android.view.View) NonNull(androidx.annotation.NonNull)

Example 50 with FileDataStorageManager

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());
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) User(com.nextcloud.client.account.User) TokenPushEvent(com.owncloud.android.ui.events.TokenPushEvent) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Aggregations

FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)91 OCFile (com.owncloud.android.datamodel.OCFile)43 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)21 Account (android.accounts.Account)19 User (com.nextcloud.client.account.User)16 Intent (android.content.Intent)12 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)12 Context (android.content.Context)9 File (java.io.File)9 ArrayList (java.util.ArrayList)9 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)8 Test (org.junit.Test)8 ScreenshotTest (com.owncloud.android.utils.ScreenshotTest)7 OCUpload (com.owncloud.android.db.OCUpload)6 AccountManager (android.accounts.AccountManager)5 OperationCancelledException (com.owncloud.android.lib.common.operations.OperationCancelledException)5 UploadFileOperation (com.owncloud.android.operations.UploadFileOperation)5 DialogFragment (androidx.fragment.app.DialogFragment)4 IOException (java.io.IOException)4 AccountsException (android.accounts.AccountsException)3