Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasKaminsky committed Feb 17, 2022
2 parents 21d5197 + ee000f7 commit dc7c3f4
Show file tree
Hide file tree
Showing 21 changed files with 443 additions and 170 deletions.
2 changes: 1 addition & 1 deletion scripts/analysis/lint-results.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DO NOT TOUCH; GENERATED BY DRONE
<span class="mdl-layout-title">Lint Report: 103 warnings</span>
<span class="mdl-layout-title">Lint Report: 102 warnings</span>
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void screenshotTextFiles() {
newFile.setModificationTimestamp(1522019340);
newFile.setStoragePath(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt");

OCFile existingFile = new OCFile("/newFile.txt");
OCFile existingFile = new OCFile("/newFile.txt", "4546546");
existingFile.setFileLength(1024000);
existingFile.setModificationTimestamp(1582019340);

Expand Down Expand Up @@ -157,7 +157,7 @@ public void cancel() {
"/newFile.txt",
user.getAccountName());

OCFile existingFile = new OCFile("/newFile.txt");
OCFile existingFile = new OCFile("/newFile.txt", "123221");
existingFile.setFileLength(1024000);
existingFile.setModificationTimestamp(1582019340);

Expand Down Expand Up @@ -198,7 +198,7 @@ public void keepExisting() {
"/newFile.txt",
user.getAccountName());

OCFile existingFile = new OCFile("/newFile.txt");
OCFile existingFile = new OCFile("/newFile.txt", "121312");
existingFile.setFileLength(1024000);
existingFile.setModificationTimestamp(1582019340);

Expand Down Expand Up @@ -243,7 +243,7 @@ public void keepNew() {
"/newFile.txt",
user.getAccountName());

OCFile existingFile = new OCFile("/newFile.txt");
OCFile existingFile = new OCFile("/newFile.txt", "12354455");
existingFile.setFileLength(1024000);
existingFile.setModificationTimestamp(1582019340);
existingFile.setRemoteId("123abc");
Expand Down Expand Up @@ -289,7 +289,7 @@ public void keepBoth() {
"/newFile.txt",
user.getAccountName());

OCFile existingFile = new OCFile("/newFile.txt");
OCFile existingFile = new OCFile("/newFile.txt", "564564");
existingFile.setFileLength(1024000);
existingFile.setModificationTimestamp(1582019340);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
*
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2022 Tobias Kaminsky
* Copyright (C) 2022 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.owncloud.android.ui.adapter

import com.owncloud.android.AbstractIT
import com.owncloud.android.datamodel.OCFile
import org.junit.Assert.assertEquals
import org.junit.Test

@Suppress("MagicNumber")
class OCFileListAdapterIT : AbstractIT() {
@Test
fun testParseMedia() {
// empty start
storageManager.deleteAllFiles()

val startDate: Long = 0
val endDate: Long = 3642752043
assertEquals(0, storageManager.getGalleryItems(startDate, endDate).size)

// create dummy files
OCFile("/test.txt", "01").apply {
mimeType = "text/plain"
}.let {
storageManager.saveFile(it)
}

OCFile("/image.png", "02").apply {
mimeType = "image/png"
modificationTimestamp = 1000000
}.let {
storageManager.saveFile(it)
}

OCFile("/image2.png", "03").apply {
mimeType = "image/png"
modificationTimestamp = 1000050
}.let {
storageManager.saveFile(it)
}

OCFile("/video.mpg", "04").apply {
mimeType = "video/mpg"
modificationTimestamp = 1000045
}.let {
storageManager.saveFile(it)
}

OCFile("/video2.avi", "05").apply {
mimeType = "video/avi"
modificationTimestamp = endDate + 10
}.let {
storageManager.saveFile(it)
}

// list of remoteFiles
assertEquals(5, storageManager.allFiles.size)
assertEquals(3, storageManager.getGalleryItems(startDate, endDate).size)
assertEquals(4, storageManager.allGalleryItems.size)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,72 @@ public void saveVirtual(VirtualFolderType type, OCFile file) {
}
}

public List<OCFile> getAllGalleryItems() {
return getGalleryItems(0, Long.MAX_VALUE);
}

public List<OCFile> getGalleryItems(long startDate, long endDate) {
List<OCFile> files = new ArrayList<>();

Uri requestURI = ProviderTableMeta.CONTENT_URI;
Cursor cursor;

if (getContentProviderClient() != null) {
try {
cursor = getContentProviderClient().query(
requestURI,
null,
ProviderTableMeta.FILE_ACCOUNT_OWNER + AND +
ProviderTableMeta.FILE_MODIFIED + ">=? AND " +
ProviderTableMeta.FILE_MODIFIED + "<? AND (" +
ProviderTableMeta.FILE_CONTENT_TYPE + " LIKE ? OR " +
ProviderTableMeta.FILE_CONTENT_TYPE + " LIKE ? )",
new String[]{
user.getAccountName(),
String.valueOf(startDate),
String.valueOf(endDate),
"image/%",
"video/%"
},
null
);
} catch (RemoteException e) {
Log_OC.e(TAG, e.getMessage(), e);
return files;
}
} else {
cursor = getContentResolver().query(
requestURI,
null,
ProviderTableMeta.FILE_ACCOUNT_OWNER + AND +
ProviderTableMeta.FILE_MODIFIED + ">=? AND " +
ProviderTableMeta.FILE_MODIFIED + "<? AND (" +
ProviderTableMeta.FILE_CONTENT_TYPE + " LIKE ? OR " +
ProviderTableMeta.FILE_CONTENT_TYPE + " LIKE ? )",
new String[]{
user.getAccountName(),
String.valueOf(startDate),
String.valueOf(endDate),
"image/%",
"video/%"
},
null
);
}

if (cursor != null) {
if (cursor.moveToFirst()) {
do {
OCFile child = createFileInstance(cursor);
files.add(child);
} while (cursor.moveToNext());
}
cursor.close();
}

return files;
}

public List<OCFile> getVirtualFolderContent(VirtualFolderType type, boolean onlyImages) {
List<OCFile> ocFiles = new ArrayList<>();
Uri req_uri = ProviderTableMeta.CONTENT_URI_VIRTUAL;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,9 @@ public long getCreationTimestamp() {
return this.creationTimestamp;
}

/**
* @return unix timestamp in milliseconds
*/
public long getModificationTimestamp() {
return this.modificationTimestamp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ private void createVirtualTable(SQLiteDatabase db) {
+ ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
+ ProviderTableMeta.VIRTUAL_TYPE + " TEXT, " // type
+ ProviderTableMeta.VIRTUAL_OCFILE_ID + " INTEGER )" // file id
);
);
}

private void createFileSystemTable(SQLiteDatabase db) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
private boolean onlyOnDevice;
private boolean showShareAvatar = false;
private OCFile highlightedItem;
private boolean showMetadata = true;

public OCFileListAdapter(
Activity activity,
Expand Down Expand Up @@ -300,6 +301,10 @@ public int getItemCount() {
}
}

public boolean isEmpty() {
return mFiles.size() == 0;
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Expand Down Expand Up @@ -469,35 +474,37 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi

gridViewHolder.getLocalFileIndicator().setVisibility(View.INVISIBLE); // default first

OperationsService.OperationsServiceBinder operationsServiceBinder = transferServiceGetter.getOperationsServiceBinder();
FileDownloader.FileDownloaderBinder fileDownloaderBinder = transferServiceGetter.getFileDownloaderBinder();
FileUploader.FileUploaderBinder fileUploaderBinder = transferServiceGetter.getFileUploaderBinder();
if (operationsServiceBinder != null && operationsServiceBinder.isSynchronizing(user, file)) {
//synchronizing
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);

} else if (fileDownloaderBinder != null && fileDownloaderBinder.isDownloading(user, file)) {
// downloading
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);

} else if (fileUploaderBinder != null && fileUploaderBinder.isUploading(user, file)) {
//uploading
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);

} else if (file.getEtagInConflict() != null) {
// conflict
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing_error);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);

} else if (file.isDown()) {
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synced);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
}
if (showMetadata) {
OperationsService.OperationsServiceBinder operationsServiceBinder = transferServiceGetter.getOperationsServiceBinder();
FileDownloader.FileDownloaderBinder fileDownloaderBinder = transferServiceGetter.getFileDownloaderBinder();
FileUploader.FileUploaderBinder fileUploaderBinder = transferServiceGetter.getFileUploaderBinder();
if (operationsServiceBinder != null && operationsServiceBinder.isSynchronizing(user, file)) {
//synchronizing
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);

} else if (fileDownloaderBinder != null && fileDownloaderBinder.isDownloading(user, file)) {
// downloading
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);

} else if (fileUploaderBinder != null && fileUploaderBinder.isUploading(user, file)) {
//uploading
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);

} else if (file.getEtagInConflict() != null) {
// conflict
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing_error);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);

} else if (file.isDown()) {
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synced);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
}

gridViewHolder.getFavorite().setVisibility(file.isFavorite() ? View.VISIBLE : View.GONE);
gridViewHolder.getFavorite().setVisibility(file.isFavorite() ? View.VISIBLE : View.GONE);
}

if (multiSelect) {
gridViewHolder.getCheckbox().setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -753,7 +760,7 @@ public boolean shouldShowHeader() {
return false;
}

if (MainApp.isOnlyOnDevice()) {
if (MainApp.isOnlyOnDevice() || ocFileListFragmentInterface.isSearchFragment()) {
return false;
}

Expand Down Expand Up @@ -857,8 +864,6 @@ public void swapDirectory(
notifyDataSetChanged();
}



public void setData(List<Object> objects,
ExtendedListFragment.SearchType searchType,
FileDataStorageManager storageManager,
Expand Down Expand Up @@ -891,15 +896,19 @@ public void setData(List<Object> objects,
break;
}

mStorageManager.deleteVirtuals(type);
if (type != VirtualFolderType.GALLERY) {
mStorageManager.deleteVirtuals(type);
}
}

// early exit
if (objects.size() > 0 && mStorageManager != null) {
if (searchType == ExtendedListFragment.SearchType.SHARED_FILTER) {
parseShares(objects);
} else {
parseVirtuals(objects, searchType);
if (searchType != ExtendedListFragment.SearchType.GALLERY_SEARCH) {
parseVirtuals(objects, searchType);
}
}
}

Expand Down Expand Up @@ -1031,6 +1040,19 @@ private void parseVirtuals(List<Object> objects, ExtendedListFragment.SearchType
mStorageManager.saveVirtuals(contentValues);
}

public void showAllGalleryItems(FileDataStorageManager storageManager) {
if (mStorageManager == null) {
mStorageManager = storageManager;
}
mFiles = mStorageManager.getAllGalleryItems();
FileStorageUtils.sortOcFolderDescDateModifiedWithoutFavoritesFirst(mFiles);

mFilesAll.clear();
mFilesAll.addAll(mFiles);

new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged);
}

public void showVirtuals(VirtualFolderType type, boolean onlyImages, FileDataStorageManager storageManager) {
mFiles = storageManager.getVirtualFolderContent(type, onlyImages);

Expand Down Expand Up @@ -1187,6 +1209,10 @@ public void setGridView(boolean bool) {
gridView = bool;
}

public void setShowMetadata(boolean bool) {
showMetadata = bool;
}

@VisibleForTesting
public void setShowShareAvatar(boolean bool) {
showShareAvatar = bool;
Expand Down
Loading

0 comments on commit dc7c3f4

Please sign in to comment.