Skip to content

Instantly share code, notes, and snippets.

View deepakkumardk's full-sized avatar

Deepak Kumar deepakkumardk

View GitHub Profile
@deepakkumardk
deepakkumardk / cloudSettings
Last active February 18, 2021 06:09
Retrofit API call extension
{"lastUpload":"2021-02-18T06:09:40.064Z","extensionVersion":"v3.4.3"}
@deepakkumardk
deepakkumardk / HandleImage.kt
Last active June 14, 2019 12:02
Identifying the source of image and handling it
private fun handleSendImage(intent: Intent) {
val imageUri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
if (imageUri.toString().contains("com.google.android.apps.docs")) { //From Google Drive
// show the progress bar until the you get the file
this.createTempFile(imageUri, DriveTempFileCallback {
// hide the progress bar
// file -- handle the file as you want
})
} else { //From gallery intent
// handle signle image from gallary intent
@deepakkumardk
deepakkumardk / HandleIntent.kt
Last active June 14, 2019 11:53
Handle the incoming intent
val action = intent.action
val type = intent.type
if (Intent.ACTION_SEND == action && type != null) {
if (type.startsWith("image/")) {
handleSendImage(intent)
}
} else if (Intent.ACTION_SEND_MULTIPLE == action && type != null) {
if (type.startsWith("image/")) {
handleSendMultipleImages(intent)
@deepakkumardk
deepakkumardk / DriveTempFileCallback.kt
Created June 8, 2019 09:56
DriveTempFileCallback interface to handle single image from drive
public interface DriveTempFileCallback {
fun onFileCreated(file: File)
}
@deepakkumardk
deepakkumardk / DriveImageCallback.kt
Created June 8, 2019 09:56
DriveImageCallback Interface to handle multiple images from drive
public interface DriveImageCallback {
fun onSuccess(list: ArrayList<Uri>)
}
@deepakkumardk
deepakkumardk / DriveEx.kt
Created June 8, 2019 09:55
Extension file to handle images from Google Drive
fun Activity?.createTempFile(uri: Uri, callback: DriveTempFileCallback) {
val startTime = System.currentTimeMillis() // Just for debugging purpose
this.doAsyncResult { // Here I have used the Anko library to simplify things
var stream: InputStream? = null
try {
stream = this@createTempFile?.contentResolver?.openInputStream(uri)
} catch (e: FileNotFoundException) {
e.printStackTrace()
}