Skip to content

Instantly share code, notes, and snippets.

View Priyansh-Kedia's full-sized avatar
🍄
Learning & Exploring

Priyansh Kedia Priyansh-Kedia

🍄
Learning & Exploring
View GitHub Profile
@Priyansh-Kedia
Priyansh-Kedia / TestActivity.kt
Created September 15, 2021 10:19
Observing file upload status RxJava
LiveSubject.FILE_UPLOAD_FILE.subscribe({
when(it) {
is UploadFileStatus.Complete -> {
Glide.with(this).load(it.s3Url).into(image)
toast("Uploaded image")
logD("complete upload")
}
is UploadFileStatus.Error -> {
logE("could not upload")
}
@Priyansh-Kedia
Priyansh-Kedia / UploadService.kt
Last active September 15, 2021 10:12
UploadService for Amazon SDK
class UploadService : JobIntentService() {
private val secrets = getSecrets()
override fun onHandleWork(intent: Intent) {
if (intent.extras?.containsKey(IMAGE_URI) == true) {
val imageUri = intent.getParcelableExtra<Uri>(IMAGE_URI)
var image: Bitmap? = null
if (imageUri != null) {
image = MediaStore.Images.Media.getBitmap(contentResolver, imageUri)
@Priyansh-Kedia
Priyansh-Kedia / UploadServiceCompanion.kt
Created September 15, 2021 09:52
Companion object in UploadService
companion object {
/**
* Unique job ID for this service.
*/
const val JOB_ID = 1000
const val IMAGE_URI = "image_uri"
const val IMAGE_URL = "image_url"
const val DOCUMENT_URI = "document_uri"
const val DOCUMENT_URL = "document_url"
@Priyansh-Kedia
Priyansh-Kedia / UploadFileStatus.kt
Created September 15, 2021 09:43
Class for UploadFileStatus
sealed class UploadFileStatus{
data class FileStatus(val status: Int): UploadFileStatus()
data class Error(val exception: Throwable): UploadFileStatus()
data class Complete(val s3Url: String): UploadFileStatus()
data class Start(val start: Boolean): UploadFileStatus()
}
@Priyansh-Kedia
Priyansh-Kedia / build.gradle
Created September 15, 2021 09:16
Build gradle for s3 upload and RxJava
// Aws SDK
implementation 'com.amazonaws:aws-android-sdk-core:2.6.+'
implementation 'com.amazonaws:aws-android-sdk-cognito:2.2.+'
implementation 'com.amazonaws:aws-android-sdk-s3:2.6.+'
implementation 'com.amazonaws:aws-android-sdk-ddb:2.2.+'
// RxJava
implementation "io.reactivex.rxjava3:rxjava:3.0.4"
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
@Priyansh-Kedia
Priyansh-Kedia / EMOJIS.kt
Created August 19, 2021 18:35
List of Emoji HTML codes
object EMOJIS {
private const val GRINNING_FACE = "&#128512;"
private const val BEAMING_FACE_WITH_SMILING_EYES = "&#128513;"
private const val GRINNING_SQUINTING_FACE = "&#128518;"
private const val GRINNING_FACE_WITH_SWEAT = "&#128517;"
const val FACE_WITH_TEARS_OF_JOY = "&#128514;"
private const val ROLLING_ON_THE_FLOOR_LAUGHING = "&#129315;"
private const val SLIGHTLY_SMILING_FACE = "&#128578;"
private const val UPSIDE_DOWN_FACE = "&#128579;"
@Priyansh-Kedia
Priyansh-Kedia / gist:a20c99d2b0ab37637ba3456576b01b65
Created August 19, 2021 04:33
Pagination in RecyclerView with GridLayoutManager
mediaRecycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
if ((gridLayoutManager.findLastVisibleItemPosition() == localDocumentsAdapter.itemCount - DOCUMENT_BUFFER) && dy > 0) {
documentViewModel.getImages(DOCUMENTS_COUNT)
}
}
})
@Priyansh-Kedia
Priyansh-Kedia / documentViewModel.kt
Created August 19, 2021 04:31
Document Viewmodel for MediaStore API
private val _imagesLiveData = MutableLiveData<MutableList<Three<Uri?, String?, Date>>>()
val imagesLiveData: LiveData<MutableList<Three<Uri?, String?, Date>>>
get() = _imagesLiveData
private var start = 0
private var areAllLoaded = false
fun getImages(count: Int) {
if (areAllLoaded)
return
@Priyansh-Kedia
Priyansh-Kedia / documentRepo.kt
Last active September 21, 2022 17:50
Document Repo for Pagination in MediaStore API
suspend fun getImages(count: Int, start: Int): Three<MutableList<Three<Uri?, String?, Date>>, Boolean, Int> {
val imagesList = mutableListOf<Three<Uri?, String?, Date>>()
var index = start
return withContext(Dispatchers.IO) {
while (imageCursor?.moveToPosition(i) == true) {
val id = imageIdColumn?.let { imageCursor.getLong(it) }
val dateModified = Date(TimeUnit.SECONDS.toMillis(imageCursor.getLong(imageDateModifiedColumn ?: 0)))
val displayName = imageDisplayNameColumn?.let { imageCursor.getString(it) }
@Priyansh-Kedia
Priyansh-Kedia / mutiny.py
Last active June 24, 2021 10:52
Code for importing mutiny dataset into Voxel51
import fiftyone as fo
import os
import xml.etree.ElementTree as ET
import cv2
name = "headsegmentation_dataset_ccncsa"
dataset_dir = "/home/priyansh-kedia/Documents/Datasets/headsegmentation_dataset_ccncsa/"
dataset = fo.Dataset()