Skip to content

Instantly share code, notes, and snippets.

View ananth10's full-sized avatar
🎯
Focusing

ananth ananth10

🎯
Focusing
View GitHub Profile
@ananth10
ananth10 / RecyclerViewAdapter.kt
Created March 16, 2023 12:24
How To Use DiffUtil In RecyclerView Adapter
private val diffUtil = object : DiffUtil.ItemCallback<String>() {
override fun areItemsTheSame(oldItem: String, newItem: String): Boolean {
return oldItem == newItem
}
override fun areContentsTheSame(oldItem: String, newItem: String): Boolean {
return oldItem == newItem
}
}
@ananth10
ananth10 / Swipe Delete.kt
Created March 16, 2023 12:21
Swipe Delete In RecyclerView
private val swipeCallBack = object : ItemTouchHelper.SimpleCallback(0,ItemTouchHelper.RIGHT or ItemTouchHelper.LEFT){
override fun onMove(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder
): Boolean {
return true
}
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
@ananth10
ananth10 / KotlinExtensionFunction.kt
Last active April 28, 2023 11:48
Useful Kotlin Extension Functions
fun Activity.goToActivity(newActivity: Class<*>){
val intent= Intent(this, newActivity)
startActivity(intent)
}
fun Activity.goToActivityWithBundle(newActivity: Class<*>,bundle: Bundle){
val intent=Intent(this, newActivity)
intent.putExtra("bundle",bundle)
startActivity(intent)
}
@ananth10
ananth10 / NetworkConnectionChange.js
Last active March 3, 2021 08:24
Detect network connection changes in react native
import React, { useEffect, useState } from 'react';
import { StyleSheet, View, Text, Alert } from 'react-native';
import NetInfo from '@react-native-community/netinfo'
let cellularGeneration=''
let signalStrength=100
let connectionType=''
const NetworkConnectionChange=()=>{
@ananth10
ananth10 / CommonTextWatcher.kt
Created August 30, 2020 06:04
This is common TextWatcher for EditText component to avoid boiler plate code!!
class CommonTextWatcher(
private val beforeChanged:((CharSequence?,Int,Int,Int)->Unit)={_,_,_,_->},
private val afterChanged:((Editable?)->Unit)={},
private val onChanged:(CharSequence?,Int,Int,Int)->Unit
):TextWatcher {
override fun afterTextChanged(p0: Editable?) {
afterChanged(p0)
}
override fun beforeTextChanged(char: CharSequence?, start: Int, count: Int, after: Int) {
@ananth10
ananth10 / GridDividerDecoration.java
Created August 10, 2017 12:47
Item decoration for RecyclerViews with GridLayoutManagers.
import android.graphics.Rect;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class GridDividerDecoration extends RecyclerView.ItemDecoration {
private int space;
private int spanCount;
private int lastItemInFirstLane = -1;
@ananth10
ananth10 / gist:f9f66d8c58547b534093d951acd5f6cd
Created June 30, 2017 13:48 — forked from yqritc/gist:ccca77dc42f2364777e1
Equal column spacing for Android RecyclerView GridLayoutManager by using custom ItemDecoration

ItemOffsetDecoration

public class ItemOffsetDecoration extends RecyclerView.ItemDecoration {

    private int mItemOffset;

    public ItemOffsetDecoration(int itemOffset) {
        mItemOffset = itemOffset;
    }