Skip to content

Commit

Permalink
Add Camera
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahdi authored and Mahdi committed Jan 23, 2023
1 parent 7e599cc commit 63a3d31
Show file tree
Hide file tree
Showing 19 changed files with 287 additions and 177 deletions.
1 change: 1 addition & 0 deletions FilePicker/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />

<application

Expand Down
26 changes: 19 additions & 7 deletions FilePicker/src/main/java/com/mahdiasd/filepicker/FilePicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ data class FilePicker(
private val fragmentManager: FragmentManager,
var listener: FilePickerListener? = null,

var mode: List<PickerMode> = listOf(PickerMode.Image, PickerMode.Video, PickerMode.Audio),
var mode: List<PickerMode> = listOf(PickerMode.Image, PickerMode.Image, PickerMode.Video, PickerMode.Audio),
private var defaultMode: PickerMode? = null,

var videoText: String = context.getString(R.string.mahdiasd_file_picker_video),
var audioText: String = context.getString(R.string.mahdiasd_file_picker_audio),
var fileManagerText: String = context.getString(R.string.mahdiasd_file_picker_file_manager),
var imageText: String = context.getString(R.string.mahdiasd_file_picker_image),
var cameraText: String = context.getString(R.string.mahdiasd_file_picker_camera),
var openStorageText: String = context.getString(R.string.mahdiasd_file_picker_open_storage),
var maxTotalFileSizeText: String = context.getString(R.string.mahdiasd_file_picker_max_total_size),
var maxEachFileSizeText: String = context.getString(R.string.mahdiasd_file_picker_max_each_size),
Expand All @@ -28,6 +29,8 @@ data class FilePicker(
var documentIcon: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_document),
var fileManagerIcon: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_file),
var imageIcon: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_image),
var searchIcon: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_search),
var doneIcon: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_send),

var showFileWhenClick: Boolean = false,
var maxSelection: Int = 10,
Expand All @@ -38,7 +41,9 @@ data class FilePicker(
var activeColor: Int = ContextCompat.getColor(context, R.color.colorPrimary),
var deActiveColor: Int = ContextCompat.getColor(context, R.color.gray),
var cardBackgroundColor: Int = ContextCompat.getColor(context, R.color.white),
) :


) :
BaseObservable() {
private val fragmentTag = "mahdiasd_file_picker"
private var filePickerFragment = FilePickerFragment.newInstance()
Expand All @@ -62,12 +67,17 @@ data class FilePicker(
documentIcon: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_document),
fileManagerIcon: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_file),
imageIcon: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_image),
doneIcon: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_send),
searchIcon: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_search),
): FilePicker {
this.videoIcon
this.audioIcon
this.documentIcon
this.fileManagerIcon
this.imageIcon
this.searchIcon = searchIcon
this.videoIcon = videoIcon
this.audioIcon = audioIcon
this.documentIcon = documentIcon
this.fileManagerIcon = fileManagerIcon
this.imageIcon = imageIcon
this.doneIcon = doneIcon

return this
}

Expand Down Expand Up @@ -141,6 +151,7 @@ data class FilePicker(
audioText: String = context.getString(R.string.mahdiasd_file_picker_audio),
fileManagerText: String = context.getString(R.string.mahdiasd_file_picker_file_manager),
imageText: String = context.getString(R.string.mahdiasd_file_picker_image),
cameraText: String = context.getString(R.string.mahdiasd_file_picker_camera),
openStorageText: String = context.getString(R.string.mahdiasd_file_picker_open_storage),
maxTotalFileSizeText: String = context.getString(R.string.mahdiasd_file_picker_max_total_size),
maxEachFileSizeText: String = context.getString(R.string.mahdiasd_file_picker_max_each_size),
Expand All @@ -149,6 +160,7 @@ data class FilePicker(
this.audioText = audioText
this.fileManagerText = fileManagerText
this.imageText = imageText
this.cameraText = cameraText
this.openStorageText = openStorageText
this.maxTotalFileSizeText = maxTotalFileSizeText
this.maxEachFileSizeText = maxEachFileSizeText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class FilePickerAdapter(
list: List<FileModel>?,
private var selectedFiles: MutableList<FileModel>,
private val pickerMode: PickerMode,
private val config: FilePicker
private val config: FilePicker,
private val filePickerFragment: FilePickerFragment? = null,
) : BaseRecyclerAdapter<FileModel>(context, list) {

private var stack = ArrayDeque<List<FileModel?>?>()
Expand All @@ -32,17 +33,16 @@ class FilePickerAdapter(
}

override fun getRootLayoutId(): Int {
return if (pickerMode == PickerMode.Audio || pickerMode == PickerMode.FILE)
return if (pickerMode == PickerMode.Audio || pickerMode == PickerMode.File)
R.layout.item_file_picker_manager
else
R.layout.item_file_picker
}

override fun onBind(viewHolder: BaseViewHolder, position: Int) {
val model = viewHolder.getData(position) as FileModel

when (pickerMode) {
PickerMode.Audio, PickerMode.FILE -> {
PickerMode.Audio, PickerMode.File -> {
val itemBinding = viewHolder.binding as ItemFilePickerManagerBinding
itemBinding.let {
it.item = model
Expand All @@ -61,6 +61,7 @@ class FilePickerAdapter(
it.item = model
glideSdCart(itemBinding.image, model.path)
it.presenter = this
it.containCamera = config.mode.contains(PickerMode.Camera)
it.activeColor = config.activeColor
it.deActiveColor = config.deActiveColor
it.type = config.selectedMode
Expand Down Expand Up @@ -118,7 +119,9 @@ class FilePickerAdapter(
}

fun onClick(view: View, fileModel: FileModel) {
if (config.showFileWhenClick)
if (fileModel.path == "Camera")
filePickerFragment?.openCamera()
else if (config.showFileWhenClick)
openFile(fileModel.path)
else
checkBox(null, fileModel)
Expand Down Expand Up @@ -152,9 +155,6 @@ class FilePickerAdapter(
private fun glideSdCart(view: ImageView, imageUrl: String?) {
if (imageUrl == null) return
val file = File(imageUrl)
if (!file.exists()) {
return
}
val imageUri = Uri.fromFile(file) ?: return
Glide.with(view.context)
.load(imageUri)
Expand All @@ -172,14 +172,7 @@ class FilePickerAdapter(
val ext = MimeTypeMap.getFileExtensionFromUrl(file.name)
val type = map.getMimeTypeFromExtension(ext)
val intent = Intent(Intent.ACTION_VIEW)
intent.setDataAndType(
FileProvider.getUriForFile(
context,
"com.mahdiasd.filepicker.provider",
file
),
type
)
intent.setDataAndType(FileProvider.getUriForFile(context, "${context.packageName}.provider", file), type)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
context.startActivity(intent)
Expand Down
Loading

0 comments on commit 63a3d31

Please sign in to comment.