Last active
July 28, 2017 12:23
-
-
Save oianmol/b03e3deba3bda80f8cd5d8eb5e180970 to your computer and use it in GitHub Desktop.
Save Uri form gBoard keyboard with uri like gif/png/jpeg's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UriInfoLoader { | |
fun loadUriInfo(inputContentInfo: InputContentInfoCompat, context: Context): Single<File>? { | |
return Single.create<File> { emitter -> | |
val likUri = inputContentInfo.linkUri | |
val count = inputContentInfo.description.mimeTypeCount | |
var ext: String? = null | |
for (i in 0..count - 1) { | |
val mimetype = inputContentInfo.description.getMimeType(i) | |
if (!TextUtils.isEmpty(mimetype)) { | |
ext = MimeTypeMap.getSingleton().getExtensionFromMimeType(mimetype) | |
if (!TextUtils.isEmpty(ext)) break | |
} | |
} | |
if (TextUtils.isEmpty(ext)) { | |
emitter.onError(Exception("Empty")) | |
} | |
val contentUri = inputContentInfo.contentUri | |
try { | |
val file = Glide.with(context) | |
.load(contentUri).downloadOnly(com.bumptech.glide.request.target.Target.SIZE_ORIGINAL, com.bumptech.glide.request.target.Target.SIZE_ORIGINAL).get() | |
var file1 = FileUtils.buildImageKeyboardSupportUri(ext) | |
var newFilepath = file1.absolutePath | |
FileUtils.copyFile(file.absolutePath, newFilepath) | |
emitter.onSuccess(File(newFilepath)) | |
} catch (e: InterruptedException) { | |
emitter.onError(e) | |
} catch (e: ExecutionException) { | |
emitter.onError(e) | |
} catch (e: Exception) { | |
emitter.onError(e) | |
} | |
}.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment