Skip to content

Implemented sort order for DAV documents #1434

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

Conversation

ArnyminerZ
Copy link
Member

Purpose

See #1431, sort order is not being applied in DavDocumentsProvider.

Short description

  • Added a new function to WebDavDocumentsDao that takes a, order by argument.
  • Implemented the usage of sortOrder in DavDocumentsProvider.

Checklist

  • The PR has a proper title, description and label.
  • I have self-reviewed the PR.
  • I have added documentation to complex functions and functions that can be used by other modules.
  • I have added reasonable tests or consciously decided to not add tests.

Signed-off-by: Arnau Mora <arnyminerz@proton.me>
@ArnyminerZ ArnyminerZ added the bug Something isn't working label May 2, 2025
@ArnyminerZ ArnyminerZ self-assigned this May 2, 2025
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
@ArnyminerZ ArnyminerZ marked this pull request as ready for review May 2, 2025 09:27
@ArnyminerZ ArnyminerZ requested review from Copilot and sunkup May 2, 2025 09:27
@ArnyminerZ ArnyminerZ changed the title Implemented sort order Implemented sort order for DAV documents May 2, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses issue #1431 by implementing sort order functionality in document fetching and updating the associated UI provider. Key changes include adding a new ordered query function to WebDavDocumentsDao, integrating sort order processing in DavDocumentsProvider, and updating documentation in WebDavDocument.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
app/src/main/kotlin/at/bitfire/davdroid/webdav/DavDocumentsProvider.kt Implements sorting logic based on the sortOrder parameter
app/src/main/kotlin/at/bitfire/davdroid/db/WebDavDocumentDao.kt Introduces dynamic ordering via getChildrenOrdered
app/src/main/kotlin/at/bitfire/davdroid/db/WebDavDocument.kt Adds documentation reminder for column name changes

@sunkup sunkup removed their request for review May 5, 2025 11:52
ArnyminerZ added 2 commits May 9, 2025 15:15
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
@rfc2822 rfc2822 force-pushed the 1431-file-order-issue-when-accessing-audio-files-via-android-document-provider-saf-via-playbook branch from d7bdcb0 to 5b905dc Compare May 9, 2025 13:15
…io-files-via-android-document-provider-saf-via-playbook
…sing-audio-files-via-android-document-provider-saf-via-playbook' into 1431-file-order-issue-when-accessing-audio-files-via-android-document-provider-saf-via-playbook
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
@ArnyminerZ ArnyminerZ requested review from rfc2822 and Copilot May 10, 2025 13:55
@ArnyminerZ
Copy link
Member Author

I've created a new function for processing the order by request to make sure its format is correct

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a sort order for DAV documents by adding a new sorting method and integrating it within the document provider and DAO layer. Key changes include:

  • Adding a processOrderByQuery method with its corresponding tests.
  • Updating DavDocumentsProvider to use processOrderByQuery when fetching children.
  • Modifying the DAO query in WebDavDocumentDao to accept a dynamic orderBy parameter and updating related documentation.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
DavDocumentsProviderTest.kt Added tests for verifying the processOrderByQuery method's functionality.
DavDocumentsProvider.kt Implemented processOrderByQuery and integrated it into the children query flow.
WebDavDocumentDao.kt Updated the getChildren query to include an ORDER BY clause using a dynamic parameter.
WebDavDocument.kt Added a documentation note regarding column name changes.

@rfc2822 rfc2822 requested review from sunkup and removed request for rfc2822 May 11, 2025 11:42
sunkup
sunkup previously approved these changes May 12, 2025
Copy link
Member

@sunkup sunkup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, looks like it should be working, but this is really complex. Do we really need it to be a single method? ( @rfc2822 ) I can't help but think that we could reduce some complexity.
If not using multiple query methods, then maybe by using an enum to pass in the different combinations as arguments and hereby reduce some of the parsing and stringbuilding complexity.

Would be my preferred way since it's easier to reason about, but I think it should work like this too.

Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a test for ORDER BY in the @Query and it fails.

As I understand it, prepared statements / bind parameters don't work for identifiers / clauses. They can only replace values. Can you please double-check?

If that's true, I think we need to use @RawQuery to construct a query (ideally with some helper like SQLiteQueryBuilder.buildQuery()).

We should probably

  1. get arbitrary sorting with multiple fields working (+ test), and then
  2. write a function that parses the incoming sort order, takes the order fields and constructs a new ORDER BY with only the supported fields (will probably look very much like processOrderByQuery, maybe a bit more separated).

…io-files-via-android-document-provider-saf-via-playbook
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
…io-files-via-android-document-provider-saf-via-playbook
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
@ArnyminerZ ArnyminerZ marked this pull request as draft May 19, 2025 16:42
…io-files-via-android-document-provider-saf-via-playbook
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
…sing-audio-files-via-android-document-provider-saf-via-playbook' into 1431-file-order-issue-when-accessing-audio-files-via-android-document-provider-saf-via-playbook
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
@ArnyminerZ ArnyminerZ marked this pull request as ready for review May 20, 2025 07:46
@ArnyminerZ ArnyminerZ requested a review from rfc2822 May 20, 2025 07:46
@rfc2822 rfc2822 requested a review from Copilot May 21, 2025 08:40
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a sort order for DAV documents by integrating a new function in WebDavDocumentsDao along with a DocumentSortByMapper that validates and converts content provider sort directives into SQL clauses. Key changes include:

  • Adding a new mapping function in DocumentSortByMapper and corresponding tests in DocumentSortByMapperTest.
  • Refactoring DavDocumentsProvider to inject and use DocumentSortByMapper for preparing SQL order clauses.
  • Extending WebDavDocumentDao with a RawQuery-based getChildren method that supports dynamic order clauses and updating tests accordingly.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
DocumentSortByMapperTest.kt Added tests covering various column and direction mappings.
DocumentSortByMapper.kt Introduced logic to convert content provider order strings into validated SQL order clauses.
DavDocumentsProvider.kt Updated to use the new mapper and pass the computed SQL sort clause to the DAO.
WebDavDocumentDao.kt Extended with a new DAO method that accepts custom order clauses via a raw query.
WebDavDocument.kt Minor updates: comment update regarding column name changes.
DavDocumentsProviderTest.kt, WebDavDocumentDaoTest.kt Updated tests reflecting the new sort order logic.

@rfc2822 rfc2822 requested a review from Copilot May 21, 2025 08:45
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Implements configurable sort ordering for DAV documents by extending the DAO and wiring in a content‐provider–to–SQL mapping.

  • Introduces DocumentSortByMapper to translate provider sortOrder strings to SQL clauses.
  • Extends WebDavDocumentDao with a raw-query–based getChildren(parentId, orderBy) method and deprecates the old overload.
  • Integrates the new mapper and DAO method into DavDocumentsProvider and updates tests accordingly.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
app/src/main/kotlin/at/bitfire/davdroid/webdav/DocumentSortByMapper.kt Adds mapper for translating content-provider sort fields to SQL.
app/src/test/kotlin/at/bitfire/davdroid/webdav/DocumentSortByMapperTest.kt Unit tests covering valid/invalid sort strings for mapper.
app/src/main/kotlin/at/bitfire/davdroid/db/WebDavDocumentDao.kt Adds raw-query–based getChildren(parentId, orderBy) and default.
app/src/androidTest/kotlin/at/bitfire/davdroid/db/WebDavDocumentDaoTest.kt Integration tests for DAO sorting behavior.
app/src/main/kotlin/at/bitfire/davdroid/webdav/DavDocumentsProvider.kt Hooks in the mapper and new DAO overload to apply sortOrder.
app/src/androidTest/kotlin/at/bitfire/davdroid/webdav/DavDocumentsProviderTest.kt Adjusts expected child ordering in provider tests.
app/src/main/kotlin/at/bitfire/davdroid/db/WebDavDocument.kt Adds a comment reminder for column-name dependencies.
Comments suppressed due to low confidence (1)

app/src/main/kotlin/at/bitfire/davdroid/db/WebDavDocumentDao.kt:27

  • Room’s @RawQuery usually expects a parameter of type SupportSQLiteQuery (or RoomSQLiteQuery). Please verify that RoomRawQuery is the correct type here or switch to SupportSQLiteQuery to ensure Room can generate the implementation.
fun query(query: RoomRawQuery): List<WebDavDocument>

Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have

  • moved the complex logic out into a new class (using Hilt for the logger),
  • adapted the logic to be more understandable,
  • added a default order by name when not specified.

@rfc2822 rfc2822 requested a review from sunkup May 21, 2025 08:50
Copy link
Member

@sunkup sunkup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, minor comments only, but I did not test it. How did you guys test it? Which app did you use?

@rfc2822 rfc2822 requested a review from sunkup May 21, 2025 13:31
@rfc2822
Copy link
Member

rfc2822 commented May 21, 2025

Looks good, minor comments only, but I did not test it. How did you guys test it? Which app did you use?

AOSP Files from the emulator

Copy link
Member

@sunkup sunkup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good I think. Works as it should.

@rfc2822 rfc2822 dismissed their stale review May 22, 2025 07:48

Did major changes myself

@rfc2822 rfc2822 merged commit 19f8667 into main-ose May 22, 2025
11 checks passed
@rfc2822 rfc2822 deleted the 1431-file-order-issue-when-accessing-audio-files-via-android-document-provider-saf-via-playbook branch May 22, 2025 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File order issue when accessing audio files via Android Document Provider (SAF) via Playbook
3 participants