Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond. I'm on vacation.

Afzal Najam AfzalivE

💭
I may be slow to respond. I'm on vacation.
View GitHub Profile
@AfzalivE
AfzalivE / ands
Created Jul 6, 2021
Android Studio terminal launcher
View ands
#!/bin/bash
# check for where the latest version of IDEA is installed
STUDIOS=()
STUDIO_NAMES=()
while read line
do
studio=`echo $line`
STUDIOS+=("${studio}")
@AfzalivE
AfzalivE / BottomSheetScrollView.kt
Last active Sep 10, 2021
BottomSheetScrollView for when you have a ViewPager with RecyclerViews in your BottomSheet
View BottomSheetScrollView.kt
class BottomSheetScrollView(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs),
NestedScrollingParent2 {
private val TAG = "NestedScroll3"
private val childHelper = NestedScrollingChildHelper(this).apply {
isNestedScrollingEnabled = true
}
private var behavior: BottomSheetBehavior<*>? = null
var started = false
var canScroll = false
@AfzalivE
AfzalivE / LaunchCoroutines.kt
Last active Feb 4, 2021
Coroutines cancellation
View LaunchCoroutines.kt
fun main(args: Array<String>) {
val handler = CoroutineExceptionHandler { context, exception ->
println("CoroutineExceptionHandler got $exception with suppressed ${exception.suppressed.contentToString()}")
}
val parentScope = CoroutineScope(Dispatchers.Default + Job() + handler)
// val parentScope = MyScope()
parentScope.launch {
println("one job: " + this.coroutineContext[Job].toString())
println("Hello")
@AfzalivE
AfzalivE / ExplodingFab1.kt
Last active Dec 20, 2020
ExplodingFab Jetpack Compose
View ExplodingFab1.kt
// Using Jetpack Compose Transition v1
enum class FabState {
Initial,
Normal,
Exploded,
}
val fabSizeKey = DpPropKey()
val fabColorKey = ColorPropKey()
View ForegroundServiceLauncher.kt
class ForegroundServiceLauncher(private val serviceClass: Class<out Service>) {
private var isStarting = false
private var shouldStop = false
private var isCreated = false
@Synchronized
fun startService(context: Context, block: Intent.() -> Unit = {}) {
if (!isCreated) {
isStarting = true
@AfzalivE
AfzalivE / debug_from_qr.py
Created Oct 29, 2020 — forked from benigumocom/debug_from_qr.py
Connect Wireless Debug from Terminal on Android11
View debug_from_qr.py
#!/usr/bin/env python3
"""
Android11
Pair and connect devices for wireless debug on terminal
python-zeroconf: A pure python implementation of multicast DNS service discovery
https://github.com/jstasiak/python-zeroconf
"""
@AfzalivE
AfzalivE / Fake.kt
Created Oct 14, 2020
fake() for all the unit tests
View Fake.kt
val ALL_FAKES = listOf(
FakePostLoginUseCase::class,
// all fake classes go here
)
/**
* Finds and initializes an instance of
* class [T] if it exists in [ALL_FAKES].
*
* If it doesn't, a [FakeNotFoundException] is thrown
@AfzalivE
AfzalivE / BasicNav.kt
Last active Sep 7, 2021
jetpack compose navigation
View BasicNav.kt
@Composable
fun VeryBasicNav() {
NavHost(startDestination = "Profile") { // this: NavGraphBuilder
composable("Profile") {
Profile()
}
composable("Dashboard") {
Dashboard()
}
composable("Scrollable") {
@AfzalivE
AfzalivE / DatabaseSyncer.kt
Last active Aug 18, 2020
Syncing two local and remote db tables
View DatabaseSyncer.kt
package com.test
class DatabaseSyncer() {
// Updated thanks to @gildor
private fun findUpdatedNotes(
allLocalNotes: List<Note>,
allRemoteNotes: List<Note>
): List<Note> {
@AfzalivE
AfzalivE / ViewModelFactory.kt
Created Jul 29, 2019
ViewModelFactory for Dagger2
View ViewModelFactory.kt
/**
* Constructs a ViewModelFactory with dependencies
*/
@Singleton
class ViewModelFactory @Inject constructor(
private val creators: Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
var creator = creators[modelClass]