Skip to content

Instantly share code, notes, and snippets.

View KryptKode's full-sized avatar
🎯
Focusing

Paul KryptKode

🎯
Focusing
View GitHub Profile
import androidx.annotation.MainThread
import androidx.annotation.Nullable
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import java.util.concurrent.atomic.AtomicBoolean
/**
object PositionUtil {
fun computePositionalDataSourceEquivalent(position:Int, totalCount: Int): Int {
val pageSize = DataSource.PAGE_SIZE //DataSource.PAGE_SIZE is the requested page size
val initialLoadSize = DataSource.PAGE_SIZE * 3 //Default loadSize is 3 times the requested load size
var pageStart = position / pageSize * pageSize
// maximum start pos is that which will encompass end of list
val maximumLoadPage = (totalCount - initialLoadSize + pageSize - 1) / pageSize * pageSize
import React from 'react';
import classNames from 'classnames';
import {
withStyles
} from '@material-ui/core';
import styles from './styles';
const styles = (theme)=>{
}
export default styles;
abstract class BaseViewHolder<T>(itemView: View) : RecyclerView.ViewHolder(itemView) {
abstract fun performBind(item :T?)
}
class ActivityOrFragment{
private lateinit val shimmerLayout: ShimmerFrameLayout
private fun initViews() {
val shimmerLifeCycle = ShimmerLifeCycle(shimmerLayout)
lifecycle.addObserver(shimmerLifeCycle)
}
}
@KryptKode
KryptKode / EventBus.kt
Created November 15, 2019 14:25
Kotlin coroutine-based event bus
import kotlinx.coroutines.experimental.DefaultDispatcher
import kotlinx.coroutines.experimental.channels.BroadcastChannel
import kotlinx.coroutines.experimental.channels.ReceiveChannel
import kotlinx.coroutines.experimental.channels.filter
import kotlinx.coroutines.experimental.channels.map
import kotlinx.coroutines.experimental.launch
import kotlin.coroutines.experimental.CoroutineContext
class EventBus {
@KryptKode
KryptKode / EventBus.kt
Created November 15, 2019 14:25 — forked from takahirom/EventBus.kt
EventBus by Kotlin coroutine
import kotlinx.coroutines.experimental.channels.BroadcastChannel
import kotlinx.coroutines.experimental.channels.ConflatedBroadcastChannel
import kotlinx.coroutines.experimental.channels.ReceiveChannel
import kotlinx.coroutines.experimental.channels.filter
import kotlinx.coroutines.experimental.channels.map
import kotlinx.coroutines.experimental.launch
import javax.inject.Inject
import javax.inject.Singleton
@KryptKode
KryptKode / PhonecallReceiver.java
Created May 23, 2020 15:15 — forked from ftvs/PhonecallReceiver.java
Detecting an incoming call coming to an Android device. Remember to set the appropriate permissions in AndroidManifest.xml as suggested in the Stackoverflow link. Usage example in comments. Source: http://stackoverflow.com/a/15564021/264619 Explanation: http://gabesechansoftware.com/is-the-phone-ringing/#more-8
package com.gabesechan.android.reusable.receivers;
import java.util.Date;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
public abstract class PhonecallReceiver extends BroadcastReceiver {
@KryptKode
KryptKode / PlayStoreUtils.kt
Last active May 29, 2020 06:38
Android app share helper
import android.content.ComponentName
import android.content.Intent
import android.content.pm.ActivityInfo
import android.net.Uri
import androidx.fragment.app.FragmentActivity
import com.allwishes.wishesapp.R
class PlayStoreUtils(private val context: FragmentActivity) {