Skip to content

Instantly share code, notes, and snippets.

View muhammadawaisshan's full-sized avatar
😁
Focusing

Muhammad Awais muhammadawaisshan

😁
Focusing
View GitHub Profile
@muhammadawaisshan
muhammadawaisshan / GalleryMain.kt
Created September 3, 2025 21:09
LazyVerticalGrid too laggy Android 11 on fast scroll
@Composable
private fun SharedTransitionScope.GalleryScreen(
state: PhotosUiState,
onAction: (PhotosAction) -> Unit,
onBackPress: () -> Unit,
onNavigateToDetails: (String, List<String?>) -> Unit,
onTopBarScrollOffsetChanged: (Float) -> Unit
) {
val cellsList = remember(state.gridItemCount) {
listOf(
package com.iobits.tech.roomtemperature.utilities
import android.content.Context
import android.content.Context.MODE_PRIVATE
import android.content.SharedPreferences
import com.iobits.tech.roomtemperature.di.App
object SavePref{
val sharedPref: SharedPreferences? by lazy {
App.mInstance?.applicationContext?.getSharedPreferences("myprefrences", MODE_PRIVATE)
@muhammadawaisshan
muhammadawaisshan / OneTimeEvents
Created October 3, 2024 12:48
OneTimeEventsCompose
-> generic fun to collect in a lifecycle aware manner
@Composable
fun <T : Any> SingleEventEffect(
sideEffectFlow: Flow<T>,
lifeCycleState: Lifecycle.State = Lifecycle.State.STARTED,
collector: (T) -> Unit
) {
val lifecycleOwner = LocalLifecycleOwner.current
LaunchedEffect(sideEffectFlow) {
@muhammadawaisshan
muhammadawaisshan / TypeTokensR8Rules
Created October 3, 2024 10:38
Keeping TypeTokens After R8
-keep class com.google.gson.internal.** { *; }
-keep class com.google.gson.reflect.** { *; }
-keep class com.google.gson.TypeAdapterFactory { *; }
-keep class com.google.gson.TypeAdapter { *; }
-keep class com.google.gson.reflect.TypeToken { *; }
@muhammadawaisshan
muhammadawaisshan / flowCollection
Last active September 24, 2024 13:36
Flows Collection
------------------------------- for collecting multiple flows in a lifecycle aware manner use repeatOnLifeCycle as it will cancel the collection when the app is in the STOP state and when i resume or start again it starts emition
------------------------
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
launch {
flow1.collect { /* Process the value. */ }
}
launch {
flow2.collect { /* Process the value. */ }
}
@muhammadawaisshan
muhammadawaisshan / errors
Last active January 14, 2025 12:51
just remembering quick solution to errors which comes commonly in often projects 😂😂😂😂
1.switch statemnt java constant expression required fix -> android.nonFinalResIds=false
2.materialcard etc material require material theme :-> instead of change whole apps theme only add this to that material component ->android:theme="@style/Theme.MaterialComponents.Light"
3.ndk interfaces not resolved? -> buildFeatures.aidl = true
4.kaptExecutionFailed -> just update kapt deps like in hilt or room
5.Use dropUnlessResumed{ //navigate etc } in compose to avoid multi-opening screens
6.Cannot find a Java installation on your machine matching this tasks requirements:-> comment kotlin{jvmToolChain()}
// Extension function to convert SDP dimension to pixels
fun Context.sdpToPx(sdpResourceId: Int): Float {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_PX,
resources.getDimension(sdpResourceId),
resources.displayMetrics
)
}
fun Context.sdpToDp(sdpResourceId: Int): Float {