From 4d377795b26e19a4973eda5eba292319ae00fee3 Mon Sep 17 00:00:00 2001 From: Sanjay Prajapati <82382452+sanjay-mi@users.noreply.github.com> Date: Thu, 3 Mar 2022 17:33:04 +0530 Subject: [PATCH] Develop (#55) - issues fixes and improvements. Co-authored-by: AKASH PATEL --- README.md | 25 ++++++- app/build.gradle | 2 +- .../main/java/com/lassi/app/MainActivity.kt | 32 +++++++- app/src/main/res/layout/activity_main.xml | 18 +++++ app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin .../res/mipmap-hdpi/ic_launcher_round.png | Bin app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin .../res/mipmap-mdpi/ic_launcher_round.png | Bin app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin .../res/mipmap-xhdpi/ic_launcher_round.png | Bin .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin app/src/main/res/values/strings.xml | 1 + lassi/build.gradle | 6 +- .../lassi/common/extenstions/ContextExt.kt | 24 ++++++ .../com/lassi/common/utils/FilePickerUtils.kt | 64 +++++++++++++++- .../lassi/data/media/MediaRepositoryImpl.kt | 3 + .../com/lassi/domain/media/LassiOption.kt | 1 - .../java/com/lassi/domain/media/MediaType.kt | 3 +- .../mediadirectory/FolderFragment.kt | 4 +- .../LassiMediaPickerActivity.kt | 70 ++++++++++++++---- 23 files changed, 224 insertions(+), 29 deletions(-) mode change 100644 => 100755 app/src/main/res/mipmap-hdpi/ic_launcher.png mode change 100644 => 100755 app/src/main/res/mipmap-hdpi/ic_launcher_round.png mode change 100644 => 100755 app/src/main/res/mipmap-mdpi/ic_launcher.png mode change 100644 => 100755 app/src/main/res/mipmap-mdpi/ic_launcher_round.png mode change 100644 => 100755 app/src/main/res/mipmap-xhdpi/ic_launcher.png mode change 100644 => 100755 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png mode change 100644 => 100755 app/src/main/res/mipmap-xxhdpi/ic_launcher.png mode change 100644 => 100755 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png mode change 100644 => 100755 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png mode change 100644 => 100755 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 lassi/src/main/java/com/lassi/common/extenstions/ContextExt.kt diff --git a/README.md b/README.md index 68fba16..0b65cc1 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Lassi is simplest way to pick media (either image, video, audio or doc) * Filter by particular media type * Filter videos by min and max time * Enable/disable camera from LassiOption +* You can open System Default view for file selection by using MediaType.FILE_TYPE_WITH_SYSTEM_VIEW # Usage @@ -51,18 +52,19 @@ Lassi is simplest way to pick media (either image, video, audio or doc) ```groovy dependencies { ... - implementation 'com.github.Mindinventory:Lassi:0.3.0' + implementation 'com.github.Mindinventory:Lassi:X.X.X' } ``` ### Implementation -* Step 1. Add Lassi in to your activity class: +* Step 1. + To open a app color theme view then add Lassi in to your activity class: ```kotlin val intent = Lassi(this) - .with(LassiOption.CAMERA_AND_GALLERY) // choose Option CAMERA, GALLERY or CAMERA_AND_GALLERY + .with(LassiOption.CAMERA_AND_GALLERY) // choose Option CAMERA or CAMERA_AND_GALLERY .setMaxCount(5) .setGridSize(3) .setMediaType(MediaType.VIDEO) // MediaType : VIDEO IMAGE, AUDIO OR DOC @@ -90,7 +92,18 @@ Lassi is simplest way to pick media (either image, video, audio or doc) .build() receiveData.launch(intent) ``` +`OR` To open a system default view then add Lassi in to your activity class: +```kotlin + val intent = Lassi(this) + .setMediaType(MediaType.FILE_TYPE_WITH_SYSTEM_VIEW) + .setSupportedFileTypes( + "jpg", "jpeg", "png", "webp", "gif", "mp4", "mkv", "webm", "avi", "flv", "3gp", + "pdf", "odt", "doc", "docs", "docx", "txt", "ppt", "pptx", "rtf", "xlsx", "xls" + ) // Filter by required media format (Mandatory) + .build() + receiveData.launch(intent) +``` * Step 2. Get Lassi result in ActivityResultCallback lambda function. @@ -110,6 +123,10 @@ Lassi is simplest way to pick media (either image, video, audio or doc) ### Document access permission note If Android device SDK is >= 30 and wants to access document (only for choose the non media file) then add ```android.permission.MANAGE_EXTERNAL_STORAGE``` permission in your app otherwise library won't allow to access documents. Kindly check sample app for more detail. +If you don't want to give Manage External Storage permission and wants to get files with system default view then You can use `OR` option from Step 1 and give required file type of document. + +### MediaType.FILE_TYPE_WITH_SYSTEM_VIEW (for System Default View) +Using this MediaType you can choose multiple files from system default view. You can't set max count limit for file choose. Give file type into setSupportedFileTypes and you can choose only those types of file from system view. ### Guideline for contributors Contribution towards our repository is always welcome, we request contributors to create a pull request to the **develop** branch only. @@ -125,7 +142,7 @@ It would be great for us if the reporter can share the below things to understan ### Requirements -* minSdkVersion >= 17 +* minSdkVersion >= 19 * Androidx ### Library used diff --git a/app/build.gradle b/app/build.gradle index c730e7f..833b68b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,7 +8,7 @@ android { compileSdkVersion 32 defaultConfig { applicationId "com.lassi.app" - minSdkVersion 17 + minSdkVersion 19 targetSdkVersion 32 versionCode 1 versionName "1.0" diff --git a/app/src/main/java/com/lassi/app/MainActivity.kt b/app/src/main/java/com/lassi/app/MainActivity.kt index 763d917..f5cd489 100644 --- a/app/src/main/java/com/lassi/app/MainActivity.kt +++ b/app/src/main/java/com/lassi/app/MainActivity.kt @@ -37,6 +37,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { btnVideoPicker.setOnClickListener(this) btnAudioPicker.setOnClickListener(this) btnDocPicker.setOnClickListener(this) + btnDocumentSystemIntent.setOnClickListener(this) rvSelectedMedia.adapter = selectedMediaAdapter rvSelectedMedia.addItemDecoration(GridSpacingItemDecoration(2, 10)) } @@ -108,6 +109,36 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { R.id.btnDocPicker -> { requestPermissionForDocument() } + R.id.btnDocumentSystemIntent -> { + val intent = Lassi(this) + .setMediaType(MediaType.FILE_TYPE_WITH_SYSTEM_VIEW) + .setSupportedFileTypes( + "jpg", + "jpeg", + "png", + "webp", + "gif", + "mp4", + "mkv", + "webm", + "avi", + "flv", + "3gp", + "pdf", + "odt", + "doc", + "docs", + "docx", + "txt", + "ppt", + "pptx", + "rtf", + "xlsx", + "xls" + ) + .build() + receiveData.launch(intent) + } } } @@ -206,7 +237,6 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { } } } - else -> { launchDocPicker() } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 53e6ae7..1ab7c59 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -86,6 +86,24 @@ app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/btnImagePicker" /> + +