use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class OCFileListFragment method updateLayout.
private void updateLayout() {
if (!isShowingJustFolders()) {
int filesCount = 0, foldersCount = 0;
int count = mAdapter.getCount();
OCFile file;
for (int i = 0; i < count; i++) {
file = (OCFile) mAdapter.getItem(i);
if (file.isFolder()) {
foldersCount++;
} else {
if (!file.isHidden()) {
filesCount++;
}
}
}
// set footer text
setFooterText(generateFooterText(filesCount, foldersCount));
// decide grid vs list view
OwnCloudVersion version = AccountUtils.getServerVersion(((FileActivity) mContainerActivity).getAccount());
if (version != null && version.supportsRemoteThumbnails() && isGridViewPreferred(mFile)) {
switchToGridView();
} else {
switchToListView();
}
}
invalidateActionMode();
}
use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class OCFileListFragment method isGridViewPreferred.
/**
* Determines if user set folder to grid or list view. If folder is not set itself,
* it finds a parent that is set (at least root is set).
* @param file Folder to check.
* @return 'true' is folder should be shown in grid mode, 'false' if list mode is preferred.
*/
public boolean isGridViewPreferred(OCFile file) {
if (file != null) {
OCFile fileToTest = file;
OCFile parentDir;
String parentPath = null;
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
SharedPreferences setting = getActivity().getSharedPreferences(GRID_IS_PREFERED_PREFERENCE, Context.MODE_PRIVATE);
if (setting.contains(String.valueOf(fileToTest.getFileId()))) {
return setting.getBoolean(String.valueOf(fileToTest.getFileId()), false);
} else {
do {
if (fileToTest.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
parentPath = new File(fileToTest.getRemotePath()).getParent();
parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR;
parentDir = storageManager.getFileByPath(parentPath);
} else {
parentDir = storageManager.getFileByPath(OCFile.ROOT_PATH);
}
while (parentDir == null) {
parentPath = new File(parentPath).getParent();
parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR;
parentDir = storageManager.getFileByPath(parentPath);
}
fileToTest = parentDir;
} while (endWhile(parentDir, setting));
return setting.getBoolean(String.valueOf(fileToTest.getFileId()), false);
}
} else {
return false;
}
}
use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class PreviewVideoActivity method onAccountSet.
@Override
protected void onAccountSet(boolean stateWasRecovered) {
super.onAccountSet(stateWasRecovered);
if (getAccount() != null) {
OCFile file = getFile();
/// Validate handled file (first image to preview)
if (file == null) {
throw new IllegalStateException("Instanced with a NULL OCFile");
}
if (!file.isVideo()) {
throw new IllegalArgumentException("Non-video file passed as argument");
}
file = getStorageManager().getFileById(file.getFileId());
if (file != null) {
if (file.isDown()) {
mVideoPlayer.setVideoURI(file.getStorageUri());
} else {
// not working yet
String url;
try {
url = AccountUtils.constructFullURLForAccount(this, getAccount()) + file.getRemotePath();
mVideoPlayer.setVideoURI(Uri.parse(url));
} catch (AccountNotFoundException e) {
onError(null, MediaService.OC_MEDIA_ERROR, R.string.media_err_no_account);
}
}
// create and prepare control panel for the user
mMediaController = new MediaController(this);
mMediaController.setMediaPlayer(mVideoPlayer);
mMediaController.setAnchorView(mVideoPlayer);
mVideoPlayer.setMediaController(mMediaController);
} else {
finish();
}
} else {
finish();
}
}
use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class FileStorageUtils method sortByName.
/**
* Sorts list by Name
* @param files files to sort
*/
public static Vector<OCFile> sortByName(Vector<OCFile> files) {
final Integer val;
if (mSortAscending) {
val = 1;
} else {
val = -1;
}
Collections.sort(files, new Comparator<OCFile>() {
public int compare(OCFile o1, OCFile o2) {
if (o1.isFolder() && o2.isFolder()) {
return val * new AlphanumComparator().compare(o1, o2);
} else if (o1.isFolder()) {
return -1;
} else if (o2.isFolder()) {
return 1;
}
return val * new AlphanumComparator().compare(o1, o2);
}
});
return files;
}
use of com.owncloud.android.datamodel.OCFile in project android by owncloud.
the class FileStorageUtils method createOCFileFrom.
/**
* 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 createOCFileFrom(RemoteFile remote) {
OCFile file = new OCFile(remote.getRemotePath());
file.setCreationTimestamp(remote.getCreationTimestamp());
if (remote.getMimeType().equalsIgnoreCase("DIR")) {
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());
return file;
}
Aggregations