Skip to content

Instantly share code, notes, and snippets.

View virendersran01's full-sized avatar
💻
Working from home

Virender Srxn virendersran01

💻
Working from home
  • India
View GitHub Profile
@filipkowicz
filipkowicz / HeaderItemDecoration.kt
Last active February 26, 2025 18:20
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
class GalleryActivity : AppCompatActivity() {
private val PICK_IMAGE_REQUEST = 71
private var filePath: Uri? = null
private var firebaseStore: FirebaseStorage? = null
private var storageReference: StorageReference? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_gallery)
@alana-mullen
alana-mullen / ConnectivityExtension.kt
Created January 16, 2020 00:28
Android Kotlin extension to check network connectivity
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
val Context.isConnected: Boolean
get() {
val connectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
return when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> {
@Zhuinden
Zhuinden / FragmentViewBindingDelegate.kt
Last active February 11, 2025 09:25
Fragment view binding delegate
// https://github.com/Zhuinden/fragmentviewbindingdelegate-kt
import android.view.View
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.viewbinding.ViewBinding
import kotlin.properties.ReadOnlyProperty
class UserAdapter : RecyclerView.Adapter<UserAdapter.UserViewHolder> {
var users: List<User> = emptyList()
set(value) {
field = value
notifyDataSetChanged()
}
// This keeps track of the currently selected position
var selectedPosition by Delegates.observable(-1) { property, oldPos, newPos ->
fun Fragment.isGranted(permission: AppPermission) = run {
context?.let {
(PermissionChecker.checkSelfPermission(it, permission.permissionName
) == PermissionChecker.PERMISSION_GRANTED)
} ?: false
}
fun Fragment.shouldShowRationale(permission: AppPermission) = run {
shouldShowRequestPermissionRationale(permission.permissionName)
}
fun TextInputEditText.isNotNullOrEmpty(errorString: String): Boolean {
val textInputLayout = this.parent.parent as TextInputLayout
textInputLayout.errorIconDrawable = null
this.onChange { textInputLayout.error = null }
return if (this.text.toString().trim().isEmpty()) {
textInputLayout.error = errorString
false
} else {
true
@smartherd
smartherd / MainActivity.kt
Created November 8, 2020 13:31
Spannable String
package com.sriyank.spannablestring
import android.graphics.Color
import android.graphics.Typeface
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.Spannable
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.TextPaint
@dzolnai
dzolnai / View.kt
Last active August 2, 2023 15:12
Expandable TextView with clickable '...read more'
import android.annotation.SuppressLint
import android.content.Context
import android.text.Layout
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.StaticLayout
import android.text.TextPaint
import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan
@virendersran01
virendersran01 / TypeWriter.java
Created March 4, 2021 06:12 — forked from Antarix/TypeWriter.java
TextView animation like type writer
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.widget.TextView;
public class TypeWriter extends TextView {
private CharSequence mText;
private int mIndex;
private long mDelay = 150; //Default 150ms delay