Skip to content

Instantly share code, notes, and snippets.

View AfzalivE's full-sized avatar
🌴
On vacation

Afzal Najam AfzalivE

🌴
On vacation
View GitHub Profile
@AfzalivE
AfzalivE / BottomSheetScrollView.kt
Last active November 8, 2022 02:52
BottomSheetScrollView for when you have a ViewPager with RecyclerViews in your BottomSheet
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 February 4, 2021 17:58
Coroutines cancellation
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 September 2, 2022 14:10
ExplodingFab Jetpack Compose
// Using Jetpack Compose Transition v1
enum class FabState {
Initial,
Normal,
Exploded,
}
val fabSizeKey = DpPropKey()
val fabColorKey = ColorPropKey()
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 October 29, 2020 23:02 — forked from benigumocom/debug_from_qr.py
Connect Wireless Debug from Terminal on Android11
#!/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 October 14, 2020 22:47
fake() for all the unit tests
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 September 7, 2021 17:33
jetpack compose navigation
@Composable
fun VeryBasicNav() {
NavHost(startDestination = "Profile") { // this: NavGraphBuilder
composable("Profile") {
Profile()
}
composable("Dashboard") {
Dashboard()
}
composable("Scrollable") {
@AfzalivE
AfzalivE / DatabaseSyncer.kt
Last active August 18, 2020 04:39
Syncing two local and remote db tables
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 July 29, 2019 18:29
ViewModelFactory for Dagger2
/**
* 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]
@AfzalivE
AfzalivE / LocaleChanger.java
Last active April 7, 2019 16:32
Class to change android OS locale (works till API 24, M)
public class LocaleChanger {
public static void setLocale(ArrayList<Locale> arrayList) {
try {
Class cls = Class.forName("android.app.ActivityManagerNative");
Method method = cls.getMethod("getDefault", new Class[0]);
method.setAccessible(true);
Object invoke = method.invoke(cls, new Object[0]);
method = cls.getMethod("getConfiguration", new Class[0]);
method.setAccessible(true);