Skip to content

Refactor file handling to use URIs and ContentResolver; fix bugs.#1

Draft
rothariger wants to merge 1 commit intomasterfrom
uri-refactor-and-bugfixes
Draft

Refactor file handling to use URIs and ContentResolver; fix bugs.#1
rothariger wants to merge 1 commit intomasterfrom
uri-refactor-and-bugfixes

Conversation

@rothariger
Copy link
Owner

Major changes include:

  • MainActivity, EditorFragment, FileUtils: Overhauled file opening, saving, and URI handling. Removed reliance on getRealPathFromURI and direct file paths for URI-based resources. Operations now consistently use URIs with ContentResolver.
  • EditorFragment: Implemented onSaveInstanceState to preserve content and URI across configuration changes. Updated to use display names and URIs passed from MainActivity. Improved error feedback for JSON parsing and file save operations. Added view caching.
  • FileUtils: Removed getRealPathFromURI. Added getDisplayNameFromUri. Refactored preference saving to AddUriToPrefs, storing display names and URI strings. Improved I/O methods to use Context correctly and provide better error reporting/return values.
  • MainActivity: Updated permission requests for READ_EXTERNAL_STORAGE, aligned with modern Android (API 30+). Improved handling of permission denial and permanently denied states. Streamlined moveToEditor logic.
  • Cleanup: Removed dead code and unused variables in MainActivity and EditorFragment. Standardized Context usage.

Conceptual review for FileListFragment outlined the need to use stored URI strings (parsed to Uri objects) for re-opening files. Overall, these changes significantly improve the application's robustness, error handling, and adherence to modern Android practices for file management.

Major changes include:

- MainActivity, EditorFragment, FileUtils: Overhauled file opening, saving, and URI handling. Removed reliance on `getRealPathFromURI` and direct file paths for URI-based resources. Operations now consistently use URIs with ContentResolver.
- EditorFragment: Implemented `onSaveInstanceState` to preserve content and URI across configuration changes. Updated to use display names and URIs passed from MainActivity. Improved error feedback for JSON parsing and file save operations. Added view caching.
- FileUtils: Removed `getRealPathFromURI`. Added `getDisplayNameFromUri`. Refactored preference saving to `AddUriToPrefs`, storing display names and URI strings. Improved I/O methods to use Context correctly and provide better error reporting/return values.
- MainActivity: Updated permission requests for READ_EXTERNAL_STORAGE, aligned with modern Android (API 30+). Improved handling of permission denial and permanently denied states. Streamlined `moveToEditor` logic.
- Cleanup: Removed dead code and unused variables in MainActivity and EditorFragment. Standardized Context usage.

Conceptual review for FileListFragment outlined the need to use stored URI strings (parsed to Uri objects) for re-opening files.
Overall, these changes significantly improve the application's robustness, error handling, and adherence to modern Android practices for file management.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant