Search in sources :

Example 51 with OCFile

use of com.owncloud.android.datamodel.OCFile in project android by nextcloud.

the class GallerySearchTask method parseMedia.

private boolean parseMedia(long startDate, long endDate, List<Object> remoteFiles) {
    // retrieve all between startDate and endDate
    Map<String, OCFile> localFilesMap = RefreshFolderOperation.prefillLocalFilesMap(null, storageManager.getGalleryItems(startDate * 1000L, endDate * 1000L));
    List<OCFile> filesToAdd = new ArrayList<>();
    List<OCFile> filesToUpdate = new ArrayList<>();
    OCFile localFile;
    for (Object file : remoteFiles) {
        OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) file);
        localFile = localFilesMap.remove(ocFile.getRemotePath());
        if (localFile == null) {
            // add new file
            filesToAdd.add(ocFile);
        } else if (!localFile.getEtag().equals(ocFile.getEtag())) {
            // update file
            ocFile.setLastSyncDateForData(System.currentTimeMillis());
            filesToUpdate.add(ocFile);
        }
    }
    // add new files
    for (OCFile file : filesToAdd) {
        storageManager.saveFile(file);
    }
    // update existing files
    for (OCFile file : filesToUpdate) {
        storageManager.saveFile(file);
    }
    // existing files to remove
    for (OCFile file : localFilesMap.values()) {
        storageManager.removeFile(file, true, true);
    }
    Log_OC.d(this, "Gallery search result:" + " new: " + filesToAdd.size() + " updated: " + filesToUpdate.size() + " deleted: " + localFilesMap.size());
    return didNotFindNewResults(filesToAdd, filesToUpdate, localFilesMap.values());
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) ArrayList(java.util.ArrayList)

Example 52 with OCFile

use of com.owncloud.android.datamodel.OCFile in project android by nextcloud.

the class ReceiveExternalFilesActivity method populateDirectoryList.

private void populateDirectoryList() {
    setContentView(R.layout.receive_external_files);
    setupEmptyList();
    setupToolbar();
    ActionBar actionBar = getSupportActionBar();
    setupActionBarSubtitle();
    ListView mListView = findViewById(android.R.id.list);
    findViewById(R.id.sort_list_button_group).setVisibility(View.VISIBLE);
    findViewById(R.id.switch_grid_view_button).setVisibility(View.GONE);
    String current_dir = mParents.peek();
    boolean notRoot = mParents.size() > 1;
    if (actionBar != null) {
        if (TextUtils.isEmpty(current_dir)) {
            ThemeToolbarUtils.setColoredTitle(actionBar, R.string.uploader_top_message, this);
        } else {
            ThemeToolbarUtils.setColoredTitle(actionBar, current_dir, this);
        }
        actionBar.setDisplayHomeAsUpEnabled(notRoot);
        actionBar.setHomeButtonEnabled(notRoot);
    }
    String full_path = generatePath(mParents);
    Log_OC.d(TAG, "Populating view with content of : " + full_path);
    mFile = getStorageManager().getFileByPath(full_path);
    if (mFile != null) {
        List<OCFile> files = getStorageManager().getFolderContent(mFile, false);
        if (files.isEmpty()) {
            setMessageForEmptyList(R.string.file_list_empty_headline, R.string.empty, R.drawable.uploads);
        } else {
            mEmptyListContainer.setVisibility(View.GONE);
            files = sortFileList(files);
            List<Map<String, Object>> data = new LinkedList<>();
            for (OCFile f : files) {
                Map<String, Object> h = new HashMap<>();
                h.put("dirname", f);
                data.add(h);
            }
            UploaderAdapter sa = new UploaderAdapter(this, data, R.layout.uploader_list_item_layout, new String[] { "dirname" }, new int[] { R.id.filename }, getStorageManager(), getUser().get());
            mListView.setAdapter(sa);
        }
        MaterialButton btnChooseFolder = findViewById(R.id.uploader_choose_folder);
        ThemeButtonUtils.colorPrimaryButton(btnChooseFolder, this);
        btnChooseFolder.setOnClickListener(this);
        if (mFile.canWrite()) {
            btnChooseFolder.setEnabled(true);
            ThemeButtonUtils.colorPrimaryButton(btnChooseFolder, this);
        } else {
            btnChooseFolder.setEnabled(false);
            btnChooseFolder.setBackgroundColor(Color.GRAY);
        }
        ThemeToolbarUtils.colorStatusBar(this);
        ThemeToolbarUtils.tintBackButton(actionBar, this);
        Button btnNewFolder = findViewById(R.id.uploader_cancel);
        btnNewFolder.setTextColor(ThemeColorUtils.primaryColor(this, true));
        btnNewFolder.setOnClickListener(this);
        mListView.setOnItemClickListener(this);
        sortButton = findViewById(R.id.sort_button);
        FileSortOrder sortOrder = preferences.getSortOrderByFolder(mFile);
        sortButton.setText(DisplayUtils.getSortOrderStringId(sortOrder));
        sortButton.setOnClickListener(l -> openSortingOrderDialogFragment(getSupportFragmentManager(), sortOrder));
    }
}
Also used : HashMap(java.util.HashMap) FileSortOrder(com.owncloud.android.utils.FileSortOrder) MaterialButton(com.google.android.material.button.MaterialButton) LinkedList(java.util.LinkedList) OCFile(com.owncloud.android.datamodel.OCFile) ListView(android.widget.ListView) UploaderAdapter(com.owncloud.android.ui.adapter.UploaderAdapter) Button(android.widget.Button) MaterialButton(com.google.android.material.button.MaterialButton) Map(java.util.Map) HashMap(java.util.HashMap) ActionBar(androidx.appcompat.app.ActionBar)

Example 53 with OCFile

use of com.owncloud.android.datamodel.OCFile in project android by nextcloud.

the class PreviewMediaFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    Log_OC.v(TAG, "onStart");
    OCFile file = getFile();
    if (file != null) {
        // bind to any existing player
        mediaPlayerServiceConnection.bind();
        if (exoPlayer == null) {
            exoPlayer = new ExoPlayer.Builder(requireContext()).build();
        }
        binding.exoplayerView.setPlayer(exoPlayer);
        LinearLayout linearLayout = binding.exoplayerView.findViewById(R.id.exo_center_controls);
        if (linearLayout.getChildCount() == 5) {
            AppCompatImageButton fullScreenButton = new AppCompatImageButton(requireContext());
            fullScreenButton.setImageResource(R.drawable.exo_styled_controls_fullscreen_exit);
            fullScreenButton.setLayoutParams(new LinearLayout.LayoutParams(143, 143));
            fullScreenButton.setScaleType(ImageView.ScaleType.FIT_CENTER);
            fullScreenButton.setBackgroundColor(Color.TRANSPARENT);
            fullScreenButton.setOnClickListener(l -> {
                startFullScreenVideo();
            });
            linearLayout.addView(fullScreenButton);
            linearLayout.invalidate();
        }
        if (MimeTypeUtil.isAudio(file)) {
            binding.mediaController.setMediaPlayer(mediaPlayerServiceConnection);
            binding.mediaController.setVisibility(View.VISIBLE);
            mediaPlayerServiceConnection.start(user, file, autoplay, savedPlaybackPosition);
            binding.emptyView.emptyListView.setVisibility(View.GONE);
            binding.progress.setVisibility(View.GONE);
        } else if (MimeTypeUtil.isVideo(file)) {
            if (mediaPlayerServiceConnection.isConnected()) {
                // always stop player
                stopAudio();
            }
            playVideo();
        }
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) AppCompatImageButton(androidx.appcompat.widget.AppCompatImageButton) LinearLayout(android.widget.LinearLayout)

Example 54 with OCFile

use of com.owncloud.android.datamodel.OCFile in project android by nextcloud.

the class FileStorageUtils method searchForLocalFileInDefaultPath.

/**
 * Scans the default location for saving local copies of files searching for
 * a 'lost' file with the same full name as the {@link OCFile} received as
 * parameter.
 *
 * This method helps to keep linked local copies of the files when the app is uninstalled, and then
 * reinstalled in the device. OR after the cache of the app was deleted in system settings.
 *
 * The method is assuming that all the local changes in the file where synchronized in the past. This is dangerous,
 * but assuming the contrary could lead to massive unnecessary synchronizations of downloaded file after deleting
 * the app cache.
 *
 * This should be changed in the near future to avoid any chance of data loss, but we need to add some options
 * to limit hard automatic synchronizations to wifi, unless the user wants otherwise.
 *
 * @param file         File to associate a possible 'lost' local file.
 * @param accountName  File owner account name.
 */
public static void searchForLocalFileInDefaultPath(OCFile file, String accountName) {
    if ((file.getStoragePath() == null || !new File(file.getStoragePath()).exists()) && !file.isFolder()) {
        File f = new File(FileStorageUtils.getDefaultSavePathFor(accountName, file));
        if (f.exists()) {
            file.setStoragePath(f.getAbsolutePath());
            file.setLastSyncDateForData(f.lastModified());
        }
    }
}
Also used : RemoteFile(com.owncloud.android.lib.resources.files.model.RemoteFile) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File)

Example 55 with OCFile

use of com.owncloud.android.datamodel.OCFile in project android by nextcloud.

the class FileStorageUtils method fillOCFile.

/**
 * Creates and populates a new {@link OCFile} object with the data read from the server.
 *
 * @param remote    remote file read from the server (remote file or folder).
 * @return New OCFile instance representing the remote resource described by remote.
 */
public static OCFile fillOCFile(RemoteFile remote) {
    OCFile file = new OCFile(remote.getRemotePath());
    file.setDecryptedRemotePath(remote.getRemotePath());
    file.setCreationTimestamp(remote.getCreationTimestamp());
    if (MimeType.DIRECTORY.equalsIgnoreCase(remote.getMimeType())) {
        file.setFileLength(remote.getSize());
    } else {
        file.setFileLength(remote.getLength());
    }
    file.setMimeType(remote.getMimeType());
    file.setModificationTimestamp(remote.getModifiedTimestamp());
    file.setEtag(remote.getEtag());
    file.setPermissions(remote.getPermissions());
    file.setRemoteId(remote.getRemoteId());
    file.setFavorite(remote.isFavorite());
    if (file.isFolder()) {
        file.setEncrypted(remote.isEncrypted());
    }
    file.setMountType(remote.getMountType());
    file.setPreviewAvailable(remote.isHasPreview());
    file.setUnreadCommentsCount(remote.getUnreadCommentsCount());
    file.setOwnerId(remote.getOwnerId());
    file.setOwnerDisplayName(remote.getOwnerDisplayName());
    file.setNote(remote.getNote());
    file.setSharees(new ArrayList<>(Arrays.asList(remote.getSharees())));
    file.setRichWorkspace(remote.getRichWorkspace());
    return file;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile)

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