Skip to content

Instantly share code, notes, and snippets.

View AniketSK's full-sized avatar
😀
Available for consulting on Android, maybe fulltime for the right company!

Aniket Kadam AniketSK

😀
Available for consulting on Android, maybe fulltime for the right company!
View GitHub Profile
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{uid}/goals/{document=**} {
allow read, write, create, delete: if request.auth != null && request.auth.uid != null && request.auth.uid == uid;
}
}
}
@AniketSK
AniketSK / AttributeExtensions.kt
Created October 15, 2019 06:27
Demos using a listener for a data source and also an editable field.
val <T> T.exhaustive: T
get() = this
@AniketSK
AniketSK / GoalListRepository.kt
Last active October 13, 2019 01:11
Example of how to watch a Firestore collection for a list of items inside a custom livedata.
package com.aniketkadam.dogether.goals
import androidx.lifecycle.LiveData
import com.aniketkadam.dogether.goals.data.GoalsListLiveData
import com.google.firebase.firestore.FirebaseFirestore
import javax.inject.Inject
class GoalListRepository @Inject constructor(private val firebaseFirestore: FirebaseFirestore) {
fun getOwnGoals(): LiveData<List<Goal>> =
@AniketSK
AniketSK / ClipboardObservable.kt
Created September 20, 2019 05:36
An RxBindings-like observable to inform of clipboard updates.
package com.aniketkadam.cleanlinks
import android.content.ClipData
import android.content.ClipboardManager
import io.reactivex.Observable
import io.reactivex.Observer
import io.reactivex.disposables.Disposable
import java.util.concurrent.atomic.AtomicBoolean
fun ClipboardManager.updates(): Observable<OptionalClipData> = ClipboardObservable(this)
@AniketSK
AniketSK / OnProgressSpeedListenerTest.kt
Last active September 2, 2019 11:57
A demonstration of how a speed calculation could be done from the OnProgressListener of https://github.com/MindorksOpenSource/PRDownloader Here's how it works: 1. To make an accurate estimate of the speed, you need a certain number of progress updates, you can choose what number this is. 2. If we haven't reached that number of observations, retu…
package com.downloader
import org.junit.Test
import java.util.*
import java.util.concurrent.TimeUnit
class OnProgressSpeedListenerTest {
@Test
fun `speed is not calculated until the required number of samples have been received`() {
@AniketSK
AniketSK / AndroidManifest.xml
Created August 4, 2019 13:39
A rule to disable animations and all that other stuff you're supposed to do before running integration tests on a device. You will need this import among others. androidTestImplementation "androidx.test.uiautomator:uiautomator:2.2.0" the idea of it was taken from the book Android Espresso Revealed: Writing Automated Unit Tests by Denys Zelenchuk…
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="${applicationId}">
<uses-sdk tools:overrideLibrary="android_libs.ub_uiautomator"/>
</manifest>
@AniketSK
AniketSK / Document.js
Created June 30, 2019 14:13
A higher order component to abstract away the connection to Firebase.
import React from 'react';
import firebase from 'firebase/app';
import { FormValidation } from '../../constants';
class Document extends React.Component {
constructor(props) {
super(props);
this.db = firebase.firestore();
this.db.settings({ timestampsInSnapshots: true });
this.willSubscribe = this.props.path != null;
@AniketSK
AniketSK / CoroutineTestRule.kt
Last active April 14, 2023 18:56
A test rule to allow testing coroutines that use the main dispatcher. Without this you'd run into "java.lang.IllegalStateException: Module with the Main dispatcher had failed to initialize. For tests Dispatchers.setMain from kotlinx-coroutines-test module can be used"
package com.aniketkadam.sharevideoshortcut
import org.junit.rules.TestWatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.runner.Description
¯\_(ツ)_/¯
companion object {
/**
* Creates an intent for the TaskEditor state machine.
*
* Utility function to cut down on boilerplate.
*/
inline fun <reified S : TaskEditorState> editorIntent(
crossinline block: S.() -> TaskEditorState
): Intent<TaskEditorState> {
return intent {