-
Notifications
You must be signed in to change notification settings - Fork 27
feat: Implement content picker and grid layout for media #748
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
feat: Implement content picker and grid layout for media #748
Conversation
feat: add DWeb server control to SnowbirdFragment and update service …
Replaced the generic file picker with a new content picker sheet that allows users to add media from the camera, gallery, or files.
- **Content Picker:** Added a bottom sheet (`ContentPickerFragment`) to choose between Camera, Gallery, and Files.
- **Modern Media Pickers:** Implemented modern `ActivityResultContracts` for picking visual media, taking pictures, and opening documents.
- **Camera Integration:** Added logic to handle camera permissions and launch either the native camera or a custom camera activity.
- **Grid Layout:** Changed the file list from a `LinearLayoutManager` to a `GridLayoutManager` for a visual, grid-based display.
- **File Type Filtering:** The file picker now filters for supported media types (image, video, audio) and shows a warning for invalid files.
- **Open Downloaded Files:** Implemented functionality to open downloaded files using an `ACTION_VIEW` intent.
- **UI Enhancements:**
- A new `snowbird_media_grid_item.xml` layout was created for grid items.
- The adapter now displays appropriate icons based on file type (image, video, audio).
…dweb-picker-and-ui-improvements
| import java.lang.ref.WeakReference | ||
|
|
||
| class SnowbirdFileViewHolder(val binding: OneLineRowBinding) : RecyclerView.ViewHolder(binding.root) | ||
| class SnowbirdFileViewHolder(val binding: SnowbirdMediaGridItemBinding) : RecyclerView.ViewHolder(binding.root) |
Check warning
Code scanning / detekt
Library classes should not be public. Warning
|
|
||
| // Modern visual media picker for gallery (supports up to 10 items) | ||
| private val galleryLauncher = | ||
| registerForActivityResult(ActivityResultContracts.PickMultipleVisualMedia(10)) { uris: List<Uri>? -> |
Check warning
Code scanning / detekt
Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning
| val filteredUris = uris.filter { uri -> | ||
| val mimeType = requireContext().contentResolver.getType(uri) | ||
| mimeType?.startsWith("image/") == true || | ||
| mimeType?.startsWith("video/") == true || |
Check warning
Code scanning / detekt
Reports mis-indented code Warning
| val mimeType = requireContext().contentResolver.getType(uri) | ||
| mimeType?.startsWith("image/") == true || | ||
| mimeType?.startsWith("video/") == true || | ||
| mimeType?.startsWith("audio/") == true |
Check warning
Code scanning / detekt
Reports mis-indented code Warning
| dialogManager.showDialog(dialogManager.requireResourceProvider()) { | ||
| type = DialogType.Warning | ||
| title = UiText.DynamicString("Invalid File Type") | ||
| message = UiText.DynamicString("Please select only image, video, or audio files. Other file types are not supported.") |
Check warning
Code scanning / detekt
Reports lines with exceeded length Warning
| // Only allow media file types (images, videos, audio) | ||
| try { | ||
| filePickerLauncher.launch(arrayOf("image/*", "video/*", "audio/*")) | ||
| } catch (e: Exception) { |
Check warning
Code scanning / detekt
The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled. Warning
| val request = PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageAndVideo) | ||
| try { | ||
| galleryLauncher.launch(request) | ||
| } catch (e: Exception) { |
Check warning
Code scanning / detekt
The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled. Warning
| viewBinding.snowbirdMediaRecyclerView.setEmptyView(R.layout.view_empty_state) | ||
| // viewBinding.snowbirdMediaRecyclerView.layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL) | ||
| viewBinding.snowbirdMediaRecyclerView.layoutManager = LinearLayoutManager(requireContext()) | ||
| viewBinding.snowbirdMediaRecyclerView.layoutManager = GridLayoutManager(requireContext(), 3) |
Check warning
Code scanning / detekt
Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning
| } | ||
| } | ||
| } | ||
| } catch (e: Exception) { |
Check warning
Code scanning / detekt
The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled. Warning
| } | ||
| } | ||
|
|
||
| private fun getMimeType(fileName: String): String? { |
Check warning
Code scanning / detekt
Prefer splitting up complex methods into smaller, easier to test methods. Warning
Elelan
left a comment
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.
LGTM
feat: Implement content picker and grid layout for media
Replaced the generic file picker with a new content picker sheet that allows users to add media from the camera, gallery, or files.
ContentPickerFragment) to choose between Camera, Gallery, and Files.ActivityResultContractsfor picking visual media, taking pictures, and opening documents.LinearLayoutManagerto aGridLayoutManagerfor a visual, grid-based display.ACTION_VIEWintent.snowbird_media_grid_item.xmllayout was created for grid items.