Skip to content

Instantly share code, notes, and snippets.

View Devansh-Maurya's full-sized avatar
Up and up and up...

Devansh Maurya Devansh-Maurya

Up and up and up...
View GitHub Profile
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
/**
* Friendly reminder that this might not be the best place to do major changes. Or any changes at all.
* Use the [reason] arg to point your teammates and your future-self to some documentation.
*/
annotation class HereBeDragons(val reason: String)
@gmk57
gmk57 / 1 ViewBindingDelegates.kt
Last active September 6, 2024 06:45
Kotlin delegates for Android View Binding with usage examples
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.viewbinding.ViewBinding
@naman14
naman14 / ClickMonitoringView.kt
Created January 18, 2021 17:19
Handle possible child clicks in a parent viewgroup
package com.bharatpe.nativeloader
import android.content.Context
import android.graphics.Rect
import android.util.AttributeSet
import android.util.Log
import android.view.GestureDetector
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
/**
* Navigates only if this is safely possible; when this Fragment is still the current destination.
*/
fun Fragment.navigateSafe(
@IdRes resId: Int,
args: Bundle? = null,
navOptions: NavOptions? = null,
navigatorExtras: Navigator.Extras? = null
) {
if (mayNavigate()) findNavController().navigate(
/**
* Returns true if the navigation controller is still pointing at 'this' fragment, or false if it already navigated away.
*/
fun Fragment.mayNavigate(): Boolean {
val navController = findNavController()
val destinationIdInNavController = navController.currentDestination?.id
// add tag_navigation_destination_id to your ids.xml so that it's unique:
val destinationIdOfThisFragment = view?.getTag(R.id.tag_navigation_destination_id) ?: destinationIdInNavController
@gabrielemariotti
gabrielemariotti / README.MD
Last active September 24, 2024 09:22
How to use the ShapeableImageView.

The Material Components Library introduced with the 1.2.0-alpha03 the new ShapeableImageView.

In your layout you can use:

 <com.google.android.material.imageview.ShapeableImageView
      android:id="@+id/image_view"
      app:srcCompat="@drawable/..." />

Then in your code apply the ShapeAppearanceModel to define your custom corners:

@jofftiquez
jofftiquez / firebase_copy.js
Last active April 7, 2024 13:29 — forked from katowulf/firebase_copy.js
Firebase realtime database - how to copy or move data to a new path?
function copyFbRecord(oldRef, newRef) {
return Promise((resolve, reject) => {
oldRef.once('value').then(snap => {
return newRef.set(snap.val());
}).then(() => {
console.log('Done!');
resolve();
}).catch(err => {
console.log(err.message);
reject();
@robertpainsi
robertpainsi / commit-message-guidelines.md
Last active November 16, 2024 11:48
Commit message guidelines

Commit Message Guidelines

Short (72 chars or less) summary

More detailed explanatory text. Wrap it to 72 characters. The blank
line separating the summary from the body is critical (unless you omit
the body entirely).

Write your commit message in the imperative: "Fix bug" and not "Fixed
bug" or "Fixes bug." This convention matches up with commit messages