Add documentation.
This commit is contained in:
parent
727d86236b
commit
d20b1cb64a
|
@ -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<MultiPickerAudioType>(requestCode) {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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<MultiPickerContactType>(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<MultiPickerContactType> {
|
||||
if (requestCode != this.requestCode && resultCode != Activity.RESULT_OK) {
|
||||
return emptyList()
|
||||
|
|
|
@ -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<MultiPickerFileType>(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<MultiPickerFileType> {
|
||||
if (requestCode != this.requestCode && resultCode != Activity.RESULT_OK) {
|
||||
return emptyList()
|
||||
|
|
|
@ -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<MultiPickerImageType>(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<MultiPickerImageType> {
|
||||
if (requestCode != this.requestCode && resultCode != Activity.RESULT_OK) {
|
||||
return emptyList()
|
||||
|
|
|
@ -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<T>(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<T>
|
||||
|
||||
/**
|
||||
* 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<T> {
|
||||
return getSelectedFiles(context, requestCode, Activity.RESULT_OK, data)
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this function to disable multiple selection of files.
|
||||
*/
|
||||
fun single(): Picker<T> {
|
||||
single = true
|
||||
return this
|
||||
|
@ -43,10 +55,18 @@ abstract class Picker<T>(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)
|
||||
}
|
||||
|
|
|
@ -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<MultiPickerVideoType>(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<MultiPickerVideoType> {
|
||||
if (requestCode != this.requestCode && resultCode != Activity.RESULT_OK) {
|
||||
return emptyList()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue