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
@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 / 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 / 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 / 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 / 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
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 / firestore.rules
Created October 25, 2019 05:21
Some sample firebase rules.
rules_version = '2';
function isAuthenticated(request){
return request.auth != null && request.auth.uid != null
}
function isDocUidSameAsUserUid(request){
return request.auth.uid == request.resource.data.uid
}
@AniketSK
AniketSK / GoalListRepository.kt
Created October 25, 2019 18:56
A way to combine data from two collections when you can't use a collectionGroup because you're not supposed to be able to access all the data from one of the lists!
package com.aniketkadam.dogether.goals
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import com.aniketkadam.dogether.auth.FIREBASE_USER_ID
import com.aniketkadam.dogether.di.data.PRIVATE_GOALS_LOCATION_NAME
import com.aniketkadam.dogether.di.data.PUBLIC_GOALS_LOCATION_NAME
import com.aniketkadam.dogether.goals.data.GoalsListLiveData
import com.google.firebase.firestore.CollectionReference
import com.google.firebase.firestore.QueryDocumentSnapshot
@AniketSK
AniketSK / AttributeExtensions.kt
Created February 1, 2020 13:32
Used to make when clauses exhaustive
package com.aniketkadam.dogether.extensions
val <T> T.exhaustive: T
get() = this