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
//implement custom column
@Composable
fun MyOwnColumn(
modifier: Modifier = Modifier,
content: @Composable () -> Unit
) {
Layout(
modifier = modifier,
content = content
) { measurables, constraints ->
@Preview(showSystemUi = true)
@Composable
fun ConstraintLayoutContentPreview() {
ComposeTheme {
ConstraintLayoutContent()
}
}
//(1)----------------------------------Basic------------------------------------
@Composable
fun ConstraintLayoutContent() {
values/themes.xml
<resources>
<style name="Theme.ComposeTheming" parent="Theme.Material.DayNight.NoActionBar">
<item name="android:statusBarColor">@color/status_bar</item>
</style>
<style name="Theme.Material.DayNight.NoActionBar" parent="@android:style/Theme.Material.Light.NoActionBar" />
</resources>
--------------------------------------------------------------------------------------------------------------------------
*********************************************************************************************************************************
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 / interview programs
Last active March 11, 2024 13:34
kotlin code example
**************************************************************************************************************************************
Sort without sort function
**************************************************************************************************************************************
val numbers = mutableListOf(4, 8, 32, 2, 5, 8)
var temp: Int
for (i in 0 until numbers.size) {
for (j in i + 1 until numbers.size) {
if (numbers[i] > numbers[j]) {
temp = numbers[i]
@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()
@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()