Skip to content

Instantly share code, notes, and snippets.

@iosandroiddev
iosandroiddev / Kotlin StickyScrollView
Created June 1, 2024 07:04
A Kotlin Scroll View with Sticky Views
import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.ScrollView
import kotlin.math.min
class StickyScrollView @JvmOverloads constructor(
@iosandroiddev
iosandroiddev / KeyBoardExt.kt
Last active June 26, 2021 08:23
Extensions for Keyboard hiding
@file:JvmName("KeyBoardExt")
import android.app.Activity
import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
fun Fragment.hideKeyboard() {
@iosandroiddev
iosandroiddev / SharedPreferencesUtlils.kt
Last active March 18, 2021 06:06
Kotlin Extension file for storing & retrieving values from SharedPreferences
@file:JvmName("SharedPreferenceExtension")
import android.content.Context
import android.content.SharedPreferences
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
/**
[
{
"alpha2Code": "AF",
"alpha3Code": "AFG",
"altSpellings": [
"AF",
"Af\u0121\u0101nist\u0101n"
],
"area": 652230,
"borders": [
[
{
"alpha2Code": "AF",
"alpha3Code": "AFG",
"altSpellings": [
"AF",
"Af\u0121\u0101nist\u0101n"
],
"area": 652230,
"borders": [
package com.redplanet.tune.ui.decorations
import android.graphics.Rect
import android.support.annotation.Px
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
class GridOffsetItemDecoration(@param:Px private val spacing: Int,
private val shouldIncludeEdge: Boolean) : RecyclerView.ItemDecoration() {
object GoogleApiAvailabilityHelper {
private const val REQUEST_CODE_GOOGLE_AVAILABILITY = 999
fun checkAvailability(activity: Activity): Boolean {
val googleApiAvailability = GoogleApiAvailability.getInstance()
val statusCode = googleApiAvailability.isGooglePlayServicesAvailable(activity)
val isResultSuccess = statusCode == ConnectionResult.SUCCESS
class LocationRequestHelper(private val context: Context,
private val locationRequest: LocationRequest,
lifecycle: Lifecycle,
private val onResult: (LocationResult) -> Unit) : LifecycleObserver {
private val locationClient by lazy { FusedLocationProviderClient(context) }
private val settingsClient by lazy { LocationServices.getSettingsClient(context) }
private val locationSettingRequest by lazy {
LocationSettingsRequest.Builder()
@iosandroiddev
iosandroiddev / DialogExtensions.kt
Created July 8, 2020 06:37 — forked from oakkub/DialogExtensions.kt
Kotlin extension functions for creating AlertDialog in a DSL way
import android.annotation.SuppressLint
import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.support.annotation.StringRes
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
import android.widget.TextView
@iosandroiddev
iosandroiddev / CoroutineLifecycleObserver.kt
Created July 8, 2020 06:36 — forked from oakkub/CoroutineLifecycleObserver.kt
LifecycleObserver which allows easy cancelling of coroutines
/*
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software