Skip to content

Instantly share code, notes, and snippets.

View webserveis's full-sized avatar

Webserveis webserveis

View GitHub Profile
@webserveis
webserveis / SingletonHolder.kt
Created October 15, 2022 18:45
SingletonHolder Kotlin Andorid
package com.kotlin.utils.singleton
/**
* What if you need pass some arguments for initialization jus like parameterized constructor?
* Since we can't use constructor with the object keyword. So, we need to find some other way of
* doing the same.
*
* We can archive this by using a SingletonHolder class.
* Also, to make it thread-safe, we need to have a way of synchronized a double check locking principle.
*/
@webserveis
webserveis / Main.swift
Created August 31, 2022 12:06
Pokemon Battle Swift
import Foundation
enum PokemonType : Int {
case Water = 0
case Fire
case Plant
case Electro
static var count: Int { return PokemonType.Electro.rawValue + 1}
@webserveis
webserveis / AuthState.kt
Last active August 30, 2022 13:50
Firebase Auth ViewModel
sealed class AuthState {
object Idle : AuthState()
object Authenticating : AuthState()
class Authenticated(val user: FirebaseUser? = null) : AuthState()
object Unauthenticated : AuthState()
class AuthError(val message: String? = null) : AuthState()
}
@webserveis
webserveis / MainActivity.kt
Created August 4, 2022 18:05
FirebaseUI para Android usando Kotlin
class MainActivity : AppCompatActivity() {
private lateinit var appBarConfiguration: AppBarConfiguration
private lateinit var binding: ActivityMainBinding
private val mViewModel by viewModels<AuthViewModel> {
AuthViewModelFactory(this.application)
}
private val auth by lazy {
FirebaseAuth.getInstance()
@webserveis
webserveis / FirstFragment.kt
Created July 7, 2022 15:59
TabLayout MVVM Kotlin
class FirstFragment : Fragment() {
private var _binding: FragmentFirstBinding? = null
private val binding get() = _binding!!
val viewModel by activityViewModels<MyViewModel>()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
@webserveis
webserveis / MainActivity.kt
Last active April 28, 2022 11:11
ActionMode Primary Android Kotlin
package com.example.testmenu
import android.os.Bundle
import android.view.ActionMode
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import android.util.Patterns
import java.util.regex.Pattern
object YoutubeUtils {
private fun extractYoutubeId(url: String): String? {
val pattern = "([/|?|&]vi?[/|=]|youtu.be/|embed/)([a-zA-Z0-9_-]+)".toRegex()
return pattern.find(url)?.groupValues?.last()
@webserveis
webserveis / ClickManager.kt
Last active April 30, 2021 10:09
Computar clicks para publicidad Admob
class ClickManager(
private val sp: SharedPreferences,
private val triggerTask: (Int) -> Unit,
private val triggerClick: Int = TRIGGER_CLICK,
private val uid: String? = null
) {
companion object {
private const val KEY_CLICKS_COUNT = "clicks_count"
private val TRIGGER_CLICK = 5
}
@webserveis
webserveis / RadioGridGroupLayout.kt
Last active January 10, 2022 23:07
RadioGridGroupLayout
package com.webserveis.app.testradiogridlayout
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import android.widget.CompoundButton
import androidx.appcompat.widget.AppCompatRadioButton
@webserveis
webserveis / KIntent.kt
Created February 12, 2021 12:28 — forked from wajahatkarim3/KIntent.kt
Kotlin extension functions to start a generic Activity
package com.pascalwelsch.extensions
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
/**
* Extensions for simpler launching of Activities