Skip to content

Instantly share code, notes, and snippets.

View wangerekaharun's full-sized avatar

Harun Wangereka wangerekaharun

View GitHub Profile
package farmdrive.ripe.utils
import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.location.Location
import androidx.core.app.ActivityCompat
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import com.google.android.gms.location.*
@marlonlom
marlonlom / activity-results-api-firebase-auth.medium.md
Last active June 3, 2021 07:14
Gist for medium post related to androidx activity result api, moving the firebase auth to the new results api

Adapting FirebaseAuth for the new Activity Result API

Activity Result API is a new set of classes that enhances the way we use the recently deprecated methods startActivityForResult and onActivityResult, thats a usual way for interact with another apps using intents and a response code for checking the result data.

In this short post, i'm sharing to you how adapt the firebase auth flow using the Activity Result APIs

Activity Result APIs are available since AndroidX Activity 1.2.0-alpha02 and Fragment 1.3.0-alpha02. Remember to use -ktx artifacts to get additional extensions that helps you write cleaner Kotlin code.

(app/build.gradle)

@ed-george
ed-george / Ext.kt
Last active October 15, 2021 07:02
A RecyclerView that can display a 'masked' selection
package com.himumsaiddad.example.util
import android.content.res.Resources
val Int.dp: Int
get() = (this * Resources.getSystem().displayMetrics.density).toInt()
@ologe
ologe / PreferenceExtensions.kt
Last active November 13, 2024 21:10
Android shared preference observer using kotlin coroutines (1.3.0)
inline fun <reified T> SharedPreferences.observeKey(key: String, default: T): Flow<T> = channelFlow {
send(getItem(key, default))
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, k ->
if (key == k) {
trySend(getItem(key, default))
}
}
registerOnSharedPreferenceChangeListener(listener)
@tatianamac
tatianamac / tatiana-mac-speaker-rider.md
Last active November 6, 2024 15:21
Tatiana Mac's Speaker Rider

Speaker Rider

by Tatiana Mac

Last updated 14 April 2021

What is a speaker rider?

As speaking comes with immense privilege, I have crafted a speaker rider to set expectations and boundaries around my engagement. I am grateful to all the conference organisers who have brilliantly hosted me. I would love to continue to exercise this privilege to speak at conferences, and use this privilege to make the landscape more accessible and beneficial to tech's most historically excluded and marginalised communities.

Considerations

😫 I provide a lot of explanations for those of you who never had to consider these things. Most thoughtful conferences I've attended check most of these boxes intrinsically, particularly when conference runners are experienced speakers. They get it.

@sockeqwe
sockeqwe / AdapterDelegateDslExample.kt
Created July 22, 2019 08:19
AdapterDelegates Kotlin DSL
/**
* Let's say we want to display a list of Animals in a RecyclerView.
* The list can contain items of type Dog, Cat and Snake.
*/
// AdapterDelegate for Dog.
fun dogAdapterDelegate(picasso : Picasso) = adapterDelegate<Dog, Animal>(R.layout.item_dog){ // Generics Types means this AdapterDelegate is used if item is instanceof Dog (whole list is List<Anmial>)
// this block is run once in onCreateViewHolder. Think of it as an intializer for a ViewHolder.
val name = findViewById(R.id.name)
val image = findViewById(R.id.image)
@SteveKamau72
SteveKamau72 / androidx-artifact-mapping.csv
Created May 15, 2019 07:18
Migrate Android Support libraries to AndroidX. You will need the csv file androidx-artifact-mapping.csv and run python3 migrateAndroidX.py
Old build artifact AndroidX build artifact
android.arch.core:common androidx.arch.core:core-common:2.0.0-rc01
android.arch.core:core androidx.arch.core:core:2.0.0-rc01
android.arch.core:core-testing androidx.arch.core:core-testing:2.0.0-rc01
android.arch.core:runtime androidx.arch.core:core-runtime:2.0.0-rc01
android.arch.lifecycle:common androidx.lifecycle:lifecycle-common:2.0.0-rc01
android.arch.lifecycle:common-java8 androidx.lifecycle:lifecycle-common-java8:2.0.0-rc01
android.arch.lifecycle:compiler androidx.lifecycle:lifecycle-compiler:2.0.0-rc01
android.arch.lifecycle:extensions androidx.lifecycle:lifecycle-extensions:2.0.0-rc01
android.arch.lifecycle:livedata androidx.lifecycle:lifecycle-livedata:2.0.0-rc01
@Nimrodda
Nimrodda / glide_v3_to_v4_cheatsheet.md
Last active February 5, 2021 15:34
Glide migration from v3 to v4 cheatsheet

Glide v3 Migration to v4 Cheatsheet

Description V3 V4
Entry point - optional unless you have a custom GlideModule Glide GlideApp
Bitmap transformations bitmapTransform() transform()
Release bitmap Glide.clear() GlideApp.with(context).clear()
Custom animations animate(android.R.anim.fade_in) transition(GenericTransitionOptions.with(android.R.anim.fade_in))
Request builder DrawableRequestBuilder<CustomModel> RequestBuilder<Drawable>
Request builder DrawableRequestBuilder<String> RequestBuilder<Drawable>
@davidvavra
davidvavra / NonNullAssertionDetector.kt
Created March 22, 2019 17:06
Lint check for detecting non-null assertion (!!) in your code
import com.android.tools.lint.client.api.UElementHandler
import com.android.tools.lint.detector.api.*
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UPostfixExpression
class NonNullAssertionDetector : Detector(), Detector.UastScanner {
override fun getApplicableUastTypes(): List<Class<out UElement>>? {
return listOf(UPostfixExpression::class.java)
}
@filipkowicz
filipkowicz / HeaderItemDecoration.kt
Last active September 2, 2024 15:51
Item Decorator for sticky headers in Kotlin
package com.filipkowicz.headeritemdecorator
/*
solution based on - based on Sevastyan answer on StackOverflow
changes:
- take to account views offsets
- transformed to Kotlin
- now works on viewHolders