Skip to content

Commit f9f747c

Browse files
committed
feat(file-list): recent files
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 6fe8692 commit f9f747c

File tree

11 files changed

+54
-76
lines changed

11 files changed

+54
-76
lines changed

app/src/main/java/com/nextcloud/utils/extensions/OCFileExtensions.kt

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,6 @@ import com.owncloud.android.datamodel.OCFileDepth.FirstLevel
1515
import com.owncloud.android.datamodel.OCFileDepth.Root
1616
import com.owncloud.android.utils.FileStorageUtils
1717

18-
@Suppress("ReturnCount")
19-
fun List<OCFile>.hasSameContentAs(other: List<OCFile>): Boolean {
20-
if (this.size != other.size) return false
21-
22-
if (this === other) return true
23-
24-
for (i in this.indices) {
25-
val a = this[i]
26-
val b = other[i]
27-
28-
if (a != b) return false
29-
if (a.fileId != b.fileId) return false
30-
if (a.etag != b.etag) return false
31-
if (a.modificationTimestamp != b.modificationTimestamp) return false
32-
33-
if (a.fileLength != b.fileLength) return false
34-
if (a.isFavorite != b.isFavorite) return false
35-
36-
if (a.fileName != b.fileName) return false
37-
}
38-
39-
return true
40-
}
41-
4218
fun List<OCFile>.filterFilenames(): List<OCFile> = distinctBy { it.fileName }
4319

4420
fun OCFile.isTempFile(): Boolean {
@@ -47,12 +23,6 @@ fun OCFile.isTempFile(): Boolean {
4723
return storagePath?.startsWith(appTempPath) == true
4824
}
4925

50-
fun OCFile.mediaSize(defaultThumbnailSize: Float): Pair<Int, Int> {
51-
val width = (imageDimension?.width?.toInt() ?: defaultThumbnailSize.toInt())
52-
val height = (imageDimension?.height?.toInt() ?: defaultThumbnailSize.toInt())
53-
return width to height
54-
}
55-
5626
fun OCFile?.isPNG(): Boolean {
5727
if (this == null) {
5828
return false

app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ private void onNavigationItemClicked(final MenuItem menuItem) {
627627
}
628628
} else if (itemId == R.id.nav_shared) {
629629
openSharedTab();
630-
} else if (itemId == R.id.nav_recently_modified) {
630+
} else if (itemId == R.id.nav_recent_files) {
631631
resetOnlyPersonalAndOnDevice();
632632
startRecentlyModifiedSearch(menuItem);
633633
} else if (itemId == R.id.nav_assistant) {
@@ -1474,7 +1474,7 @@ public boolean isMenuItemIdBelongsToSearchType() {
14741474
return menuItemId == R.id.nav_favorites ||
14751475
menuItemId == R.id.nav_shared ||
14761476
menuItemId == R.id.nav_on_device ||
1477-
menuItemId == R.id.nav_recently_modified ||
1477+
menuItemId == R.id.nav_recent_files ||
14781478
menuItemId == R.id.nav_gallery;
14791479
}
14801480
}

app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -858,13 +858,6 @@ public void swapDirectory(
858858
}
859859

860860
public void updateAdapter(List<OCFile> newFiles, OCFile directory) {
861-
boolean hasSameContent = OCFileExtensionsKt.hasSameContentAs(mFiles, newFiles);
862-
863-
if (hasSameContent) {
864-
Log_OC.d(TAG, "same data passed skipping update");
865-
return;
866-
}
867-
868861
Log_OC.d(TAG, "updating the adapter");
869862

870863
mFiles = new ArrayList<>(newFiles);

app/src/main/java/com/owncloud/android/ui/events/SearchEvent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ data class SearchEvent(val searchQuery: String, val searchType: SearchRemoteOper
3131
fun toSearchType(): SearchType? = when (searchType) {
3232
SearchRemoteOperation.SearchType.FILE_SEARCH -> SearchType.FILE_SEARCH
3333
SearchRemoteOperation.SearchType.FAVORITE_SEARCH -> SearchType.FAVORITE_SEARCH
34-
SearchRemoteOperation.SearchType.RECENTLY_MODIFIED_SEARCH -> SearchType.RECENTLY_MODIFIED_SEARCH
34+
SearchRemoteOperation.SearchType.RECENTLY_MODIFIED_SEARCH -> SearchType.RECENT_FILES_SEARCH
3535
SearchRemoteOperation.SearchType.SHARED_FILTER -> SearchType.SHARED_FILTER
3636
SearchRemoteOperation.SearchType.PHOTO_SEARCH -> SearchType.GALLERY_SEARCH
3737
SearchRemoteOperation.SearchType.GALLERY_SEARCH -> SearchType.GALLERY_SEARCH

app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,11 @@ open class ExtendedListFragment :
626626
)
627627
}
628628

629-
SearchType.RECENTLY_MODIFIED_SEARCH -> {
629+
SearchType.RECENT_FILES_SEARCH -> {
630630
setMessageForEmptyList(
631-
R.string.file_list_empty_headline_server_search,
632-
R.string.file_list_empty_recently_modified,
633-
R.drawable.ic_list_empty_recent
631+
R.string.file_list_empty_recent_files_headline,
632+
R.string.file_list_empty_recent_files_description,
633+
R.drawable.nav_recently_outline
634634
)
635635
}
636636

app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation;
8080
import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
8181
import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation;
82+
import com.owncloud.android.lib.resources.files.model.RemoteFile;
8283
import com.owncloud.android.lib.resources.status.E2EVersion;
8384
import com.owncloud.android.lib.resources.status.OCCapability;
8485
import com.owncloud.android.lib.resources.status.Type;
@@ -152,7 +153,7 @@
152153
import static com.owncloud.android.ui.fragment.SearchType.FAVORITE_SEARCH;
153154
import static com.owncloud.android.ui.fragment.SearchType.FILE_SEARCH;
154155
import static com.owncloud.android.ui.fragment.SearchType.NO_SEARCH;
155-
import static com.owncloud.android.ui.fragment.SearchType.RECENTLY_MODIFIED_SEARCH;
156+
import static com.owncloud.android.ui.fragment.SearchType.RECENT_FILES_SEARCH;
156157
import static com.owncloud.android.ui.fragment.SearchType.SHARED_FILTER;
157158
import static com.owncloud.android.utils.DisplayUtils.openSortingOrderDialogFragment;
158159

@@ -1764,7 +1765,7 @@ protected void setEmptyView(SearchEvent event) {
17641765
break;
17651766

17661767
case RECENTLY_MODIFIED_SEARCH:
1767-
setEmptyListMessage(RECENTLY_MODIFIED_SEARCH);
1768+
setEmptyListMessage(RECENT_FILES_SEARCH);
17681769
break;
17691770

17701771
case SHARED_FILTER:
@@ -1876,10 +1877,10 @@ protected void handleSearchEvent(SearchEvent event) {
18761877

18771878
final var activity = getActivity();
18781879
if (activity != null) {
1879-
activity.runOnUiThread(() -> {{
1880+
activity.runOnUiThread(() -> {
18801881
getAdapter().removeAllFiles();
18811882
setEmptyListMessage(EmptyListState.LOADING);
1882-
}});
1883+
});
18831884
}
18841885

18851886
prepareCurrentSearch(event);
@@ -1892,7 +1893,13 @@ protected void handleSearchEvent(SearchEvent event) {
18921893
});
18931894

18941895
final User currentUser = accountManager.getUser();
1895-
final var remoteOperation = getSearchRemoteOperation(currentUser, event);
1896+
RemoteOperation remoteOperation;
1897+
if (currentSearchType == RECENT_FILES_SEARCH) {
1898+
remoteOperation = getRecentFilesSearchRemoteOperation();
1899+
} else {
1900+
remoteOperation = getSearchRemoteOperation(currentUser, event);
1901+
}
1902+
18961903
searchTask = new OCFileListSearchTask(mContainerActivity, this, remoteOperation, currentUser, event, SharedListFragment.TASK_TIMEOUT, preferences);
18971904
searchTask.execute();
18981905
}
@@ -1909,6 +1916,27 @@ protected RemoteOperation getSearchRemoteOperation(final User currentUser, final
19091916
ocCapability);
19101917
}
19111918

1919+
private RemoteOperation getRecentFilesSearchRemoteOperation() {
1920+
String accountName = accountManager.getUser().getAccountName();
1921+
OCCapability capability = mContainerActivity.getStorageManager().getCapability(accountName);
1922+
String searchQuery = "";
1923+
1924+
SearchRemoteOperation remoteOperation = new SearchRemoteOperation(
1925+
searchQuery,
1926+
SearchRemoteOperation.SearchType.RECENTLY_MODIFIED_SEARCH,
1927+
false,
1928+
capability
1929+
);
1930+
1931+
long nowSeconds = System.currentTimeMillis() / 1000L;
1932+
long last14DaysTimestamp = nowSeconds - 14L * 24 * 60 * 60;
1933+
1934+
remoteOperation.setTimestamp(last14DaysTimestamp);
1935+
remoteOperation.setLimit(100);
1936+
1937+
return remoteOperation;
1938+
}
1939+
19121940
@Subscribe(threadMode = ThreadMode.MAIN)
19131941
public void onMessageEvent(EncryptionEvent event) {
19141942
new Thread(() -> {{
@@ -2255,8 +2283,8 @@ public int getMenuItemId() {
22552283
return R.id.nav_groupfolders;
22562284
} else if (isSearchEventFavorite() || currentSearchType == FAVORITE_SEARCH) {
22572285
return R.id.nav_favorites;
2258-
} else if (currentSearchType == RECENTLY_MODIFIED_SEARCH) {
2259-
return R.id.nav_recently_modified;
2286+
} else if (currentSearchType == RECENT_FILES_SEARCH) {
2287+
return R.id.nav_recent_files;
22602288
} else {
22612289
return R.id.nav_all_files;
22622290
}

app/src/main/java/com/owncloud/android/ui/fragment/OCFileListSearchTask.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class OCFileListSearchTask(
8484
if (result?.isSuccess == true) {
8585
if (result.resultData?.isEmpty() == true) {
8686
withContext(Dispatchers.Main) {
87-
fragment.setEmptyListMessage(SearchType.NO_SEARCH)
87+
fragment.setEmptyListMessage(fragment.currentSearchType)
8888
return@withContext
8989
}
9090

@@ -171,7 +171,7 @@ class OCFileListSearchTask(
171171
var newList = list.toMutableList()
172172

173173
if (searchType == SearchType.GALLERY_SEARCH ||
174-
searchType == SearchType.RECENTLY_MODIFIED_SEARCH
174+
searchType == SearchType.RECENT_FILES_SEARCH
175175
) {
176176
return@withContext FileStorageUtils.sortOcFolderDescDateModifiedWithoutFavoritesFirst(newList)
177177
}
@@ -246,7 +246,8 @@ class OCFileListSearchTask(
246246
put(ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_ID, ocFile.fileId)
247247
}
248248
contentValuesList.add(cv)
249-
} catch (_: Exception) {
249+
} catch (e: Exception) {
250+
Log_OC.e(TAG, "parseAndSaveVirtuals():" ,e)
250251
}
251252
}
252253

app/src/main/java/com/owncloud/android/ui/fragment/SearchType.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ enum class SearchType : Parcelable {
2020
FILE_SEARCH,
2121
FAVORITE_SEARCH,
2222
GALLERY_SEARCH,
23-
RECENTLY_MODIFIED_SEARCH,
23+
RECENT_FILES_SEARCH,
2424

2525
// not a real filter, but nevertheless
2626
SHARED_FILTER,
@@ -30,7 +30,7 @@ enum class SearchType : Parcelable {
3030
fun titleId(): Int? = when (this) {
3131
FAVORITE_SEARCH -> R.string.drawer_item_favorites
3232
GALLERY_SEARCH -> R.string.drawer_item_gallery
33-
RECENTLY_MODIFIED_SEARCH -> R.string.drawer_item_recently_modified
33+
RECENT_FILES_SEARCH -> R.string.drawer_item_recent_files
3434
SHARED_FILTER -> R.string.drawer_item_shared
3535
ON_DEVICE -> R.string.drawer_item_on_device
3636
else -> null

app/src/main/res/drawable/ic_list_empty_recent.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/src/main/res/menu/partial_drawer_entries.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
android:icon="@drawable/selector_share"
4040
android:title="@string/drawer_item_shared" />
4141
<item
42-
android:id="@+id/nav_recently_modified"
42+
android:id="@+id/nav_recent_files"
4343
android:icon="@drawable/selector_recently"
4444
android:orderInCategory="0"
45-
android:title="@string/drawer_item_recently_modified"
45+
android:title="@string/drawer_item_recent_files"
4646
android:visible="true"/>
4747
<item
4848
android:id="@+id/nav_groupfolders"

0 commit comments

Comments
 (0)