Skip to content

Commit

Permalink
feat(capture-sdk): Refactoring
Browse files Browse the repository at this point in the history
   Fix review issues
PP-198
  • Loading branch information
jackkray committed Jul 11, 2024
1 parent 9003f49 commit c583579
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,28 +146,34 @@ class FileChooserFragment : BottomSheetDialogFragment() {
}

val photoPickType =
if (FeatureConfiguration.isMultiPageEnabled())
ActivityResultContracts.PickMultipleVisualMedia()
else
if (FeatureConfiguration.isMultiPageEnabled()) {
ActivityResultContracts.PickMultipleVisualMedia(maxItems = 10)
} else {
ActivityResultContracts.PickVisualMedia()

}

pickMedia = registerForActivityResult(photoPickType) { uri ->
findNavController().popBackStack()
if (uri != null) {
val listOfUri = when(uri){
is Uri -> listOf(uri)
is List<*> -> uri.filterIsInstance<Uri>().takeIf { it.size == uri.size }
?: throw IllegalArgumentException("List contains non-Uri elements")
else -> throw IllegalArgumentException("uri is neither Uri nor List<Uri>")
}
if (listOfUri.isNotEmpty()) {
setFragmentResult(REQUEST_KEY, Bundle().apply {
putParcelable(RESULT_KEY, FileChooserResult.FilesSelectedUri(listOfUri))
})
} else {
try {
val uriList = when(uri){
is Uri -> listOf(uri)
is List<*> -> uri.filterIsInstance<Uri>().takeIf { it.size == uri.size }
?: throw IllegalArgumentException("List contains non-Uri elements")
else -> throw IllegalArgumentException("uri is neither Uri nor List<Uri>")
}
if (uriList.isNotEmpty()) {
setFragmentResult(REQUEST_KEY, Bundle().apply {
putParcelable(RESULT_KEY, FileChooserResult.FilesSelectedUri(uriList))
})
} else {
setFragmentResult(REQUEST_KEY, Bundle().apply {
putParcelable(RESULT_KEY, FileChooserResult.Cancelled)
})
}
} catch (e: IllegalArgumentException) {
setFragmentResult(REQUEST_KEY, Bundle().apply {
putParcelable(RESULT_KEY, FileChooserResult.Cancelled)
putParcelable(RESULT_KEY, FileChooserResult.Error(GiniCaptureError(GiniCaptureError.ErrorCode.DOCUMENT_IMPORT, e.message)))
})
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ private void bindAppItemViewHolder(@NonNull final ProvidersAppItemViewHolder hol
holder.icon.setImageDrawable(item.getResolveInfo().loadIcon(mContext.getPackageManager()));
holder.label.setText(item.getResolveInfo().loadLabel(mContext.getPackageManager()));
holder.itemView.setOnClickListener(view -> {
final ProvidersAppItem item1 =
final ProvidersAppItem selectedItem =
(ProvidersAppItem) mItems.get(holder.getAdapterPosition());
mItemSelectedListener.onItemSelected(item1);
mItemSelectedListener.onItemSelected(selectedItem);
});
}

Expand All @@ -121,9 +121,9 @@ private void bindAppWrapperItemViewHolder(@NonNull final ProvidersAppItemViewHol
holder.icon.setImageDrawable(item.getDrawableIcon());
holder.label.setText(item.getText());
holder.itemView.setOnClickListener(view -> {
final ProvidersAppWrapperItem item1 =
final ProvidersAppWrapperItem selectedItem =
(ProvidersAppWrapperItem) mItems.get(holder.getAdapterPosition());
mItemSelectedListener.onItemSelected(item1);
mItemSelectedListener.onItemSelected(selectedItem);
});
}

Expand Down

0 comments on commit c583579

Please sign in to comment.