-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Media Sorting Improvement #16425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Leo-Berman
wants to merge
8
commits into
nextcloud:master
Choose a base branch
from
Leo-Berman:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Media Sorting Improvement #16425
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
357c961
feat(gallery): Sort by folder date structure (YYYY/MM/DD) then timestamp
Leo-Berman 6a29bef
Resolving codacy stuff
Leo-Berman be3a035
Some more tests and date validation
Leo-Berman 0ce9dc3
Removing unecessary sorting
Leo-Berman cf998f4
Cleanup
Leo-Berman f45d152
Set it up so the categories load correctly.
Leo-Berman 189929a
Resolving codacy changes with AI
Leo-Berman 3c4861f
Spotless checks
Leo-Berman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,7 +59,8 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme | |
| private boolean photoSearchQueryRunning = false; | ||
| private AsyncTask<Void, Void, GallerySearchTask.Result> photoSearchTask; | ||
| private long endDate; | ||
| private int limit = 150; | ||
| // Use 0 for unlimited - fetch all metadata at once; thumbnails load lazily | ||
| private int limit = 0; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may introduce unforeseen side effects on slow and very large instances, as forcing @tobiasKaminsky Please share your thoughts as well. |
||
| private GalleryAdapter mAdapter; | ||
|
|
||
| private static final int SELECT_LOCATION_REQUEST_CODE = 212; | ||
|
|
||
194 changes: 194 additions & 0 deletions
194
app/src/test/java/com/owncloud/android/ui/adapter/GalleryAdapterFolderDateTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| /* | ||
| * Nextcloud - Android Client | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only | ||
| */ | ||
| package com.owncloud.android.ui.adapter | ||
|
|
||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertNotNull | ||
| import org.junit.Assert.assertNull | ||
| import org.junit.Test | ||
| import java.util.Calendar | ||
|
|
||
| class GalleryAdapterFolderDateTest { | ||
|
|
||
| @Test | ||
| fun `extractFolderDate returns null for invalid paths`() { | ||
| assertNull(GalleryAdapter.extractFolderDate(null)) | ||
| assertNull(GalleryAdapter.extractFolderDate("/Photos/vacation/image.jpg")) | ||
| assertNull(GalleryAdapter.extractFolderDate("/Documents/file.pdf")) | ||
| assertNull(GalleryAdapter.extractFolderDate("")) | ||
| assertNull(GalleryAdapter.extractFolderDate("/Photos/2025image.jpg")) | ||
| } | ||
|
|
||
| @Test | ||
| fun `extractFolderDate extracts YYYY MM pattern`() { | ||
| val result = GalleryAdapter.extractFolderDate("/Photos/2025/01/image.jpg") | ||
| assertNotNull(result) | ||
|
|
||
| val cal = Calendar.getInstance().apply { timeInMillis = result!! } | ||
| assertEquals(2025, cal.get(Calendar.YEAR)) | ||
| assertEquals(0, cal.get(Calendar.MONTH)) // January is 0 | ||
| assertEquals(1, cal.get(Calendar.DAY_OF_MONTH)) // defaults to 1 | ||
| } | ||
|
|
||
| @Test | ||
| fun `extractFolderDate extracts YYYY MM DD pattern`() { | ||
| val result = GalleryAdapter.extractFolderDate("/Photos/2025/01/15/image.jpg") | ||
| assertNotNull(result) | ||
|
|
||
| val cal = Calendar.getInstance().apply { timeInMillis = result!! } | ||
| assertEquals(2025, cal.get(Calendar.YEAR)) | ||
| assertEquals(0, cal.get(Calendar.MONTH)) // January is 0 | ||
| assertEquals(15, cal.get(Calendar.DAY_OF_MONTH)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `extractFolderDate handles single digit components as partial match`() { | ||
| // Single digit month doesn't match pattern, so only year is captured | ||
| val monthResult = GalleryAdapter.extractFolderDate("/Photos/2025/3/image.jpg") | ||
| assertNotNull(monthResult) | ||
| var cal = Calendar.getInstance().apply { timeInMillis = monthResult!! } | ||
| assertEquals(2025, cal.get(Calendar.YEAR)) | ||
| assertEquals(0, cal.get(Calendar.MONTH)) // defaults to January (0) | ||
| assertEquals(1, cal.get(Calendar.DAY_OF_MONTH)) // defaults to 1 | ||
|
|
||
| // /2025/03/5/ matches YYYY/MM only, day defaults to 1 | ||
| val dayResult = GalleryAdapter.extractFolderDate("/Photos/2025/03/5/image.jpg") | ||
| assertNotNull(dayResult) | ||
| cal = Calendar.getInstance().apply { timeInMillis = dayResult!! } | ||
| assertEquals(2025, cal.get(Calendar.YEAR)) | ||
| assertEquals(2, cal.get(Calendar.MONTH)) // March is 2 | ||
| assertEquals(1, cal.get(Calendar.DAY_OF_MONTH)) // defaults to 1 | ||
| } | ||
|
|
||
| @Test | ||
| fun `extractFolderDate works with nested paths`() { | ||
| val result = GalleryAdapter.extractFolderDate("/InstantUpload/Camera/2024/12/25/IMG_001.jpg") | ||
| assertNotNull(result) | ||
|
|
||
| val cal = Calendar.getInstance().apply { timeInMillis = result!! } | ||
| assertEquals(2024, cal.get(Calendar.YEAR)) | ||
| assertEquals(11, cal.get(Calendar.MONTH)) // December is 11 | ||
| assertEquals(25, cal.get(Calendar.DAY_OF_MONTH)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `extractFolderDate finds first match in path with multiple date patterns`() { | ||
| val result = GalleryAdapter.extractFolderDate("/2023/06/backup/2024/12/25/image.jpg") | ||
| assertNotNull(result) | ||
|
|
||
| val cal = Calendar.getInstance().apply { timeInMillis = result!! } | ||
| assertEquals(2023, cal.get(Calendar.YEAR)) | ||
| assertEquals(5, cal.get(Calendar.MONTH)) // June is 5 | ||
| } | ||
|
|
||
| @Test | ||
| fun `extractFolderDate returns midnight timestamp`() { | ||
| val result = GalleryAdapter.extractFolderDate("/Photos/2025/01/15/image.jpg") | ||
| assertNotNull(result) | ||
|
|
||
| val cal = Calendar.getInstance().apply { timeInMillis = result!! } | ||
| assertEquals(0, cal.get(Calendar.HOUR_OF_DAY)) | ||
| assertEquals(0, cal.get(Calendar.MINUTE)) | ||
| assertEquals(0, cal.get(Calendar.SECOND)) | ||
| assertEquals(0, cal.get(Calendar.MILLISECOND)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `folder date ordering - newer dates should be greater`() { | ||
| val jan15 = GalleryAdapter.extractFolderDate("/Photos/2025/01/15/a.jpg")!! | ||
| val jan20 = GalleryAdapter.extractFolderDate("/Photos/2025/01/20/b.jpg")!! | ||
| val feb01 = GalleryAdapter.extractFolderDate("/Photos/2025/02/01/c.jpg")!! | ||
| val y2020 = GalleryAdapter.extractFolderDate("/Photos/2020/06/image.jpg")!! | ||
| val y2025 = GalleryAdapter.extractFolderDate("/Photos/2025/06/image.jpg")!! | ||
|
|
||
| assert(jan20 > jan15) { "Jan 20 should be after Jan 15" } | ||
| assert(feb01 > jan20) { "Feb 1 should be after Jan 20" } | ||
| assert(feb01 > jan15) { "Feb 1 should be after Jan 15" } | ||
| assert(y2025 > y2020) { "2025 should be after 2020" } | ||
| } | ||
|
|
||
| @Test | ||
| fun `extractFolderDate handles year only path`() { | ||
| val result = GalleryAdapter.extractFolderDate("/Photos/2025/image.jpg") | ||
| assertNotNull(result) | ||
|
|
||
| val cal = Calendar.getInstance().apply { timeInMillis = result!! } | ||
| assertEquals(2025, cal.get(Calendar.YEAR)) | ||
| assertEquals(0, cal.get(Calendar.MONTH)) // defaults to January (0) | ||
| assertEquals(1, cal.get(Calendar.DAY_OF_MONTH)) // defaults to 1 | ||
| } | ||
|
|
||
| @Test | ||
| fun `extractFolderDate handles invalid month values`() { | ||
| // Month 00 is invalid, so it defaults to January | ||
| val result = GalleryAdapter.extractFolderDate("/Photos/2025/00/image.jpg") | ||
| assertNotNull(result) | ||
|
|
||
| val cal = Calendar.getInstance().apply { timeInMillis = result!! } | ||
| assertEquals(2025, cal.get(Calendar.YEAR)) | ||
| assertEquals(0, cal.get(Calendar.MONTH)) // defaults to January (0) | ||
| assertEquals(1, cal.get(Calendar.DAY_OF_MONTH)) // defaults to 1 | ||
| } | ||
|
|
||
| @Test | ||
| fun `extractFolderDate handles valid month boundaries`() { | ||
| // Month 12 (December) | ||
| val decResult = GalleryAdapter.extractFolderDate("/Photos/2025/12/image.jpg") | ||
| assertNotNull(decResult) | ||
| var cal = Calendar.getInstance().apply { timeInMillis = decResult!! } | ||
| assertEquals(2025, cal.get(Calendar.YEAR)) | ||
| assertEquals(11, cal.get(Calendar.MONTH)) // December is 11 | ||
|
|
||
| // Day 31 | ||
| val day31Result = GalleryAdapter.extractFolderDate("/Photos/2025/01/31/image.jpg") | ||
| assertNotNull(day31Result) | ||
| cal = Calendar.getInstance().apply { timeInMillis = day31Result!! } | ||
| assertEquals(31, cal.get(Calendar.DAY_OF_MONTH)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `extractFolderDate handles invalid day values`() { | ||
| // Feb 30 is invalid, so day defaults to 1 | ||
| val feb30Result = GalleryAdapter.extractFolderDate("/Photos/2025/02/30/image.jpg") | ||
| assertNotNull(feb30Result) | ||
| var cal = Calendar.getInstance().apply { timeInMillis = feb30Result!! } | ||
| assertEquals(2025, cal.get(Calendar.YEAR)) | ||
| assertEquals(1, cal.get(Calendar.MONTH)) // February is 1 | ||
| assertEquals(1, cal.get(Calendar.DAY_OF_MONTH)) // defaults to 1 | ||
|
|
||
| // Day 00 is invalid, so day defaults to 1 | ||
| val day00Result = GalleryAdapter.extractFolderDate("/Photos/2025/03/00/image.jpg") | ||
| assertNotNull(day00Result) | ||
| cal = Calendar.getInstance().apply { timeInMillis = day00Result!! } | ||
| assertEquals(2025, cal.get(Calendar.YEAR)) | ||
| assertEquals(2, cal.get(Calendar.MONTH)) // March is 2 | ||
| assertEquals(1, cal.get(Calendar.DAY_OF_MONTH)) // defaults to 1 | ||
| } | ||
|
|
||
| @Test | ||
| fun `extractFolderDate requires trailing slash after date components`() { | ||
| // No trailing slash after month, so only year is captured | ||
| val result = GalleryAdapter.extractFolderDate("/Photos/2025/03image.jpg") | ||
| assertNotNull(result) | ||
|
|
||
| val cal = Calendar.getInstance().apply { timeInMillis = result!! } | ||
| assertEquals(2025, cal.get(Calendar.YEAR)) | ||
| assertEquals(0, cal.get(Calendar.MONTH)) // defaults to January (0) | ||
| assertEquals(1, cal.get(Calendar.DAY_OF_MONTH)) // defaults to 1 | ||
| } | ||
|
|
||
| @Test | ||
| fun `extractFolderDate works at start of path`() { | ||
| val result = GalleryAdapter.extractFolderDate("/2025/06/15/image.jpg") | ||
| assertNotNull(result) | ||
|
|
||
| val cal = Calendar.getInstance().apply { timeInMillis = result!! } | ||
| assertEquals(2025, cal.get(Calendar.YEAR)) | ||
| assertEquals(5, cal.get(Calendar.MONTH)) // June is 5 | ||
| assertEquals(15, cal.get(Calendar.DAY_OF_MONTH)) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this folder date extraction logic to the
DateFormatterobject and add logs for exceptions cases.