Skip to content

Instantly share code, notes, and snippets.

View cse-ariful's full-sized avatar
💭
Working Remotely

Ariful Jannat Arif cse-ariful

💭
Working Remotely
View GitHub Profile
@cse-ariful
cse-ariful / SwiftSheetState
Created November 30, 2023 17:50
A helper file to show swiftui sheet that depends on some other nullable complex variable other than boolean
//
// SheetState.swift
//
// Created by Ariful Jannat Arif on 11/30/23.
//
import SwiftUI
/// A generic type representing a boolean value that can also hold associated data of type `T`.
struct SheetState<T: Equatable>: DynamicProperty, Equatable {
@cse-ariful
cse-ariful / BaseObservableFragment.kt
Created November 14, 2022 03:18
A Extension of baseFragment which support register and unregister and notifying the listener from context.
import androidx.viewbinding.ViewBinding
abstract class BaseObservableFragment<V : ViewBinding, ListenerType>(inflater: Inflate<V>) :
BaseFragment<V>(inflater) {
private val listeners = hashSetOf<ListenerType>()
fun notify(data: (ListenerType) -> Unit) {
@cse-ariful
cse-ariful / AnimateView.kt
Created November 14, 2022 03:16
Extension Function to animate a views x,y and alpha. And get a callback after the animation completed
fun View.animateView(xTranslate: Float = 0f, yTranslate: Float = 0f, endAlpha: Float = 0f, duration: Long = 300, onEnd: (() -> Unit)? = null) =
try {
val listener = object : Animator.AnimatorListener {
override fun onAnimationStart(p0: Animator?) {
}
override fun onAnimationEnd(p0: Animator?) {
onEnd?.invoke()
@cse-ariful
cse-ariful / BaseFragment.kt
Last active November 17, 2022 06:56
A Base Implementation of Fragment and is Very easy to work with fragments. Implemented most of the things you need on regular.
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
typealias Inflate<T> = (LayoutInflater, ViewGroup?, Boolean) -> T
@cse-ariful
cse-ariful / RemoteConfigUtil.kt
Created November 14, 2022 03:06
A Complete helper class for firebase remote config. And very easy to use and type safe.
import android.util.Log
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import kotlin.math.max
object RcConfig {
private val remoteConfig: FirebaseRemoteConfig = FirebaseRemoteConfig.getInstance()
init {
remoteConfig.setDefaultsAsync(getRemoteDefaults())
@cse-ariful
cse-ariful / SharedPreferenceUtil.kt
Last active November 14, 2022 03:06
An Utility class for kotlin to make use of shared preference easy and robust. Very convenient for access shared pref values like how we access other class variables.
import android.content.Context
import android.content.SharedPreferences
object SharedPreferenceUtil {
private const val NAME = "__arif"
private const val MODE = Context.MODE_PRIVATE
private lateinit var preferences: SharedPreferences
@cse-ariful
cse-ariful / ResultData.kt
Created November 14, 2022 02:57
Sealed class to pass different states from a repository implementation or saving different state of a variable. Very useful when working with network calls or any other data source or single source of truth principle.
sealed class ResultData<out T> {
object Loading : ResultData<Nothing>()
data class Success<out T>(val data: T) : ResultData<T>()
data class Error(val throwable: Exception? = null, val message: String? = null) :
ResultData<Nothing>()
fun isLoading() = this is Loading
fun isSuccess() = this is Success
fun isError() = this is Error
}
@cse-ariful
cse-ariful / ModelPersistHelper.kt
Created November 14, 2022 02:53
We often need to track our model class over the application lifecycle. We can do this easily using below class. No extra code needed. It's save the data in memory and retrieve from there.
import android.content.Context
import android.util.Log
import com.google.gson.Gson
import java.io.File
class ModelPersistHelper<T>(
private val context: Context,
private val gson: Gson,
private val clazz: Class<T>