From d20b1cb64ab25edc4b4d28d15e88eef6d3bece8d Mon Sep 17 00:00:00 2001 From: onurays Date: Tue, 24 Mar 2020 12:15:14 +0300 Subject: [PATCH] Add documentation. --- .../vector/riotx/multipicker/AudioPicker.kt | 2 -- .../vector/riotx/multipicker/CameraPicker.kt | 23 ++++++++++++--- .../vector/riotx/multipicker/ContactPicker.kt | 10 ++++++- .../im/vector/riotx/multipicker/FilePicker.kt | 9 ++++++ .../vector/riotx/multipicker/ImagePicker.kt | 15 ++++++---- .../im/vector/riotx/multipicker/Picker.kt | 28 ++++++++++++++++--- .../vector/riotx/multipicker/VideoPicker.kt | 11 ++++++-- .../home/room/detail/RoomDetailFragment.kt | 1 - 8 files changed, 79 insertions(+), 20 deletions(-) diff --git a/multipicker/src/main/java/im/vector/riotx/multipicker/AudioPicker.kt b/multipicker/src/main/java/im/vector/riotx/multipicker/AudioPicker.kt index 752cd84e1e..a9c89a9ec0 100644 --- a/multipicker/src/main/java/im/vector/riotx/multipicker/AudioPicker.kt +++ b/multipicker/src/main/java/im/vector/riotx/multipicker/AudioPicker.kt @@ -20,9 +20,7 @@ import android.app.Activity import android.content.Context import android.content.Intent import android.media.MediaMetadataRetriever -import android.net.Uri import android.provider.MediaStore -import androidx.fragment.app.Fragment import im.vector.riotx.multipicker.entity.MultiPickerAudioType class AudioPicker(override val requestCode: Int) : Picker(requestCode) { diff --git a/multipicker/src/main/java/im/vector/riotx/multipicker/CameraPicker.kt b/multipicker/src/main/java/im/vector/riotx/multipicker/CameraPicker.kt index d8c16279cc..d7a4d55d22 100644 --- a/multipicker/src/main/java/im/vector/riotx/multipicker/CameraPicker.kt +++ b/multipicker/src/main/java/im/vector/riotx/multipicker/CameraPicker.kt @@ -19,13 +19,9 @@ package im.vector.riotx.multipicker import android.app.Activity import android.content.Context import android.content.Intent -import android.graphics.BitmapFactory -import android.graphics.ImageDecoder import android.net.Uri -import android.os.Build import android.provider.MediaStore import androidx.core.content.FileProvider -import androidx.exifinterface.media.ExifInterface import androidx.fragment.app.Fragment import im.vector.riotx.multipicker.entity.MultiPickerImageType import im.vector.riotx.multipicker.utils.ImageUtils @@ -34,8 +30,16 @@ import java.text.SimpleDateFormat import java.util.Date import java.util.Locale +/** + * Implementation of taking a photo with Camera + */ class CameraPicker(val requestCode: Int) { + /** + * Start camera by using an Activity + * @param activity Activity to handle onActivityResult(). + * @return Uri of taken photo or null if the operation is cancelled. + */ fun startWithExpectingFile(activity: Activity): Uri? { val photoUri = createPhotoUri(activity) val intent = createIntent().apply { @@ -45,6 +49,11 @@ class CameraPicker(val requestCode: Int) { return photoUri } + /** + * Start camera by using a Fragment + * @param fragment Fragment to handle onActivityResult(). + * @return Uri of taken photo or null if the operation is cancelled. + */ fun startWithExpectingFile(fragment: Fragment): Uri? { val photoUri = createPhotoUri(fragment.requireContext()) val intent = createIntent().apply { @@ -54,6 +63,12 @@ class CameraPicker(val requestCode: Int) { return photoUri } + /** + * Call this function from onActivityResult(int, int, Intent). + * @return Taken photo or null if request code is wrong + * or result code is not Activity.RESULT_OK + * or user cancelled the operation. + */ fun getTakenPhoto(context: Context, requestCode: Int, resultCode: Int, photoUri: Uri): MultiPickerImageType? { if (requestCode == this.requestCode && resultCode == Activity.RESULT_OK) { val projection = arrayOf( diff --git a/multipicker/src/main/java/im/vector/riotx/multipicker/ContactPicker.kt b/multipicker/src/main/java/im/vector/riotx/multipicker/ContactPicker.kt index 968c5623e5..b0ae0e4cda 100644 --- a/multipicker/src/main/java/im/vector/riotx/multipicker/ContactPicker.kt +++ b/multipicker/src/main/java/im/vector/riotx/multipicker/ContactPicker.kt @@ -21,11 +21,19 @@ import android.content.ContentResolver import android.content.Context import android.content.Intent import android.provider.ContactsContract -import androidx.fragment.app.Fragment import im.vector.riotx.multipicker.entity.MultiPickerContactType +/** + * Contact Picker implementation + */ class ContactPicker(override val requestCode: Int) : Picker(requestCode) { + /** + * Call this function from onActivityResult(int, int, Intent). + * Returns selected contact or empty list if request code is wrong + * or result code is not Activity.RESULT_OK + * or user did not select any files. + */ override fun getSelectedFiles(context: Context, requestCode: Int, resultCode: Int, data: Intent?): List { if (requestCode != this.requestCode && resultCode != Activity.RESULT_OK) { return emptyList() diff --git a/multipicker/src/main/java/im/vector/riotx/multipicker/FilePicker.kt b/multipicker/src/main/java/im/vector/riotx/multipicker/FilePicker.kt index 20f62faf24..e8c74fad19 100644 --- a/multipicker/src/main/java/im/vector/riotx/multipicker/FilePicker.kt +++ b/multipicker/src/main/java/im/vector/riotx/multipicker/FilePicker.kt @@ -22,8 +22,17 @@ import android.content.Intent import android.provider.OpenableColumns import im.vector.riotx.multipicker.entity.MultiPickerFileType +/** + * Implementation of selecting any type of files + */ class FilePicker(override val requestCode: Int) : Picker(requestCode) { + /** + * Call this function from onActivityResult(int, int, Intent). + * Returns selected files or empty list if request code is wrong + * or result code is not Activity.RESULT_OK + * or user did not select any files. + */ override fun getSelectedFiles(context: Context, requestCode: Int, resultCode: Int, data: Intent?): List { if (requestCode != this.requestCode && resultCode != Activity.RESULT_OK) { return emptyList() diff --git a/multipicker/src/main/java/im/vector/riotx/multipicker/ImagePicker.kt b/multipicker/src/main/java/im/vector/riotx/multipicker/ImagePicker.kt index 452724f4c7..d7bf383f03 100644 --- a/multipicker/src/main/java/im/vector/riotx/multipicker/ImagePicker.kt +++ b/multipicker/src/main/java/im/vector/riotx/multipicker/ImagePicker.kt @@ -19,18 +19,21 @@ package im.vector.riotx.multipicker import android.app.Activity import android.content.Context import android.content.Intent -import android.graphics.BitmapFactory -import android.graphics.ImageDecoder -import android.net.Uri -import android.os.Build import android.provider.MediaStore -import androidx.exifinterface.media.ExifInterface -import androidx.fragment.app.Fragment import im.vector.riotx.multipicker.entity.MultiPickerImageType import im.vector.riotx.multipicker.utils.ImageUtils +/** + * Image Picker implementation + */ class ImagePicker(override val requestCode: Int) : Picker(requestCode) { + /** + * Call this function from onActivityResult(int, int, Intent). + * Returns selected image files or empty list if request code is wrong + * or result code is not Activity.RESULT_OK + * or user did not select any files. + */ override fun getSelectedFiles(context: Context, requestCode: Int, resultCode: Int, data: Intent?): List { if (requestCode != this.requestCode && resultCode != Activity.RESULT_OK) { return emptyList() diff --git a/multipicker/src/main/java/im/vector/riotx/multipicker/Picker.kt b/multipicker/src/main/java/im/vector/riotx/multipicker/Picker.kt index c1784ee054..ff20c1303b 100644 --- a/multipicker/src/main/java/im/vector/riotx/multipicker/Picker.kt +++ b/multipicker/src/main/java/im/vector/riotx/multipicker/Picker.kt @@ -22,20 +22,32 @@ import android.content.Intent import android.net.Uri import androidx.fragment.app.Fragment +/** + * Abstract class to provide all types of Pickers + */ abstract class Picker(open val requestCode: Int) { protected var single = false - open fun startWithExpectingFile(activity: Activity): Uri? = null - - open fun startWithExpectingFile(fragment: Fragment): Uri? = null - + /** + * Call this function from onActivityResult(int, int, Intent). + * @return selected files or empty list if request code is wrong + * or result code is not Activity.RESULT_OK + * or user did not select any files. + */ abstract fun getSelectedFiles(context: Context, requestCode: Int, resultCode: Int, data: Intent?): List + /** + * Use this function to retrieve files which are shared from another application or internally + * by using android.intent.action.SEND or android.intent.action.SEND_MULTIPLE actions. + */ fun getIncomingFiles(context: Context, data: Intent?): List { return getSelectedFiles(context, requestCode, Activity.RESULT_OK, data) } + /** + * Call this function to disable multiple selection of files. + */ fun single(): Picker { single = true return this @@ -43,10 +55,18 @@ abstract class Picker(open val requestCode: Int) { abstract fun createIntent(): Intent + /** + * Start Storage Access Framework UI by using an Activity. + * @param activity Activity to handle onActivityResult(). + */ fun startWith(activity: Activity) { activity.startActivityForResult(createIntent(), requestCode) } + /** + * Start Storage Access Framework UI by using a Fragment. + * @param fragment Fragment to handle onActivityResult(). + */ fun startWith(fragment: Fragment) { fragment.startActivityForResult(createIntent(), requestCode) } diff --git a/multipicker/src/main/java/im/vector/riotx/multipicker/VideoPicker.kt b/multipicker/src/main/java/im/vector/riotx/multipicker/VideoPicker.kt index c2a441c15a..b85ffacd48 100644 --- a/multipicker/src/main/java/im/vector/riotx/multipicker/VideoPicker.kt +++ b/multipicker/src/main/java/im/vector/riotx/multipicker/VideoPicker.kt @@ -20,13 +20,20 @@ import android.app.Activity import android.content.Context import android.content.Intent import android.media.MediaMetadataRetriever -import android.net.Uri import android.provider.MediaStore -import androidx.fragment.app.Fragment import im.vector.riotx.multipicker.entity.MultiPickerVideoType +/** + * Video Picker implementation + */ class VideoPicker(override val requestCode: Int) : Picker(requestCode) { + /** + * Call this function from onActivityResult(int, int, Intent). + * Returns selected video files or empty list if request code is wrong + * or result code is not Activity.RESULT_OK + * or user did not select any files. + */ override fun getSelectedFiles(context: Context, requestCode: Int, resultCode: Int, data: Intent?): List { if (requestCode != this.requestCode && resultCode != Activity.RESULT_OK) { return emptyList() diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 779b7fb089..f58d7be718 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -156,7 +156,6 @@ import im.vector.riotx.features.reactions.EmojiReactionPickerActivity import im.vector.riotx.features.settings.VectorPreferences import im.vector.riotx.features.share.SharedData import im.vector.riotx.features.themes.ThemeUtils -import im.vector.riotx.multipicker.MultiPicker import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers import kotlinx.android.parcel.Parcelize