Skip to content

Instantly share code, notes, and snippets.

View parthdesai1208's full-sized avatar
🏢
Working from office

Parth Desai parthdesai1208

🏢
Working from office
View GitHub Profile
*********************************************************************************************************************************
Image
*********************************************************************************************************************************
Usage:
painter = painterResource(id = OwlTheme.images.lockupLogo)
---------------------------------------------------------------------------------
data class:
@Immutable
data class Images(@DrawableRes val lockupLogo: Int)
*********************************************************************************************************************************
AnimatedVisibility - without params
*********************************************************************************************************************************
@Preview(showSystemUi = true)
@Composable
fun SimpleAnimatedVisibility() {
var visibility by remember { mutableStateOf(true) }
Column(
modifier = Modifier.fillMaxSize(),
******************************************************************************************************************************************
ex-1
statement = here, we want to test that, from 3 tabs, whatever value is set for current screen so according that same tab should selected.
******************************************************************************************************************************************
passed case)
@get:Rule
val composeTestRule = createComposeRule()
@Test
fun rallyTopAppBarTest() {
@parthdesai1208
parthdesai1208 / Client
Last active April 6, 2022 13:17
Retrofit
object NursingApiClient {
lateinit var retrofit: Retrofit
val service: ApiInterface by lazy {
val builder = Retrofit.Builder()
.baseUrl(BASE_URL) //e.g., "https://api.github.com/"
//(we can change it at runtime to deal with multiple API versions)
//like, Production, staging, developments etc.
.addConverterFactory(GsonConverterFactory.create())
@parthdesai1208
parthdesai1208 / Live Template
Last active June 2, 2022 16:53
Collections of live template for android studio
Abbreviation: fun0
Description: Function with no parameters
Template text:
fun $NAME$() : $RETURN$ {
return $RETURN$
}
*******************************************************************************************************************************************
Abbreviation: key
Description: Key for a bundle
Template text:
@parthdesai1208
parthdesai1208 / App.kt
Created October 14, 2022 16:22
shared preferences using kotlin delegation
val sharedApplicationContext: Context get() = sharedApplicationContextBackingProperty
?: throw IllegalStateException(
"Application context not initialized yet."
)
private var sharedApplicationContextBackingProperty: Context? = null
class App : Application() {
override fun onCreate() {
super.onCreate()
//implement custom column
@Composable
fun MyOwnColumn(
modifier: Modifier = Modifier,
content: @Composable () -> Unit
) {
Layout(
modifier = modifier,
content = content
) { measurables, constraints ->
@parthdesai1208
parthdesai1208 / to get foldable postures
Created November 9, 2022 14:27
Compose for every screen
//WindowStateUtils.kt
/**
* Information about the posture of the device
*/
sealed interface DevicePosture {
object NormalPosture : DevicePosture
data class BookPosture(
val hingePosition: Rect
) : DevicePosture
@parthdesai1208
parthdesai1208 / Interceptors
Created November 16, 2022 07:34
Retrofit interceptors
Gzip interceptors = for data compression
public class GzipRequestInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request originalRequest = chain.request();
if (originalRequest.body() == null || originalRequest.header("Content-Encoding") != null) {
return chain.proceed(originalRequest);
}
Request compressedRequest = originalRequest.newBuilder()
@parthdesai1208
parthdesai1208 / Flow Demo
Last active November 29, 2022 14:01
Flow APIs
*********************************************************StateFlow Demo**************************************************************
Step-1) build.gradle
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.6"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.6"
Step-2) data class
data class Resource<out T>(val status: Status, val data: T?, val message: String?) {
companion object {