Example from Android Jetpack: LiveData
MutableLiveData Example |
---|
![]() |
@Composable | |
fun ParallaxScreen(modifier: Modifier = Modifier) { | |
val context = LocalContext.current | |
val scope = rememberCoroutineScope() | |
var data by remember { mutableStateOf<SensorData?>(null) } | |
DisposableEffect(Unit) { | |
val dataManager = SensorDataManager(context) | |
dataManager.init() |
import hashlib | |
import json | |
import os | |
import requests | |
import urllib3 | |
class CafeBazaarClient: |
package com.betvictor.casino.presentation.views | |
/* | |
* Copyright 2019 The Android Open Source Project | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 |
import androidx.fragment.app.Fragment | |
import androidx.lifecycle.DefaultLifecycleObserver | |
import androidx.lifecycle.LifecycleOwner | |
import androidx.lifecycle.Observer | |
import kotlin.properties.ReadOnlyProperty | |
import kotlin.reflect.KProperty | |
fun <T> Fragment.viewLifecycleLazy(initialise: () -> T): ReadOnlyProperty<Fragment, T> = | |
object : ReadOnlyProperty<Fragment, T>, DefaultLifecycleObserver { |
package com.mrezanasirloo.ganjeh | |
import android.util.SparseArray | |
import androidx.activity.ComponentActivity | |
import androidx.annotation.MainThread | |
import androidx.fragment.app.Fragment | |
import androidx.fragment.app.createViewModelLazy | |
import androidx.lifecycle.LifecycleOwner | |
import androidx.lifecycle.ViewModel | |
import androidx.lifecycle.ViewModelLazy |
package com.filipkowicz.headeritemdecorator | |
/* | |
solution based on - based on Sevastyan answer on StackOverflow | |
changes: | |
- take to account views offsets | |
- transformed to Kotlin | |
- now works on viewHolders |
MutableLiveData Example |
---|
![]() |
//T is a type of items | |
//when inheriting, just create constructor matching super, | |
//and override viewHolder() method that will return ViewHolder for given item type | |
public abstract class BaseRecyclerAdapter<T> extends RecyclerView.Adapter<BaseRecyclerAdapter.BaseViewHolder> { | |
public interface OnItemClickListener<T> { | |
void onClick(T item); | |
} |
val spanned = spannable{ bold("some") + italic(" formatted") + color(Color.RED, " text") } | |
val nested = spannable{ bold(italic("nested ")) + url("www.google.com", "text") } | |
val noWrapping = bold("no ") + sub("wrapping ) + sup("also ") + "works" | |
text_view.text = spanned + nested + noWrapping |
public class LocaleManager { | |
private static final String LANGUAGE_KEY = "CHOOSE_LANGUAGE"; | |
public static Context setLocale(Context c) { | |
String savedLanguage = getLanguage(c); | |
return savedLanguage == null ? c : updateResources(c, savedLanguage); | |
} | |
public static Context setNewLocale(Context c, String language) { | |
persistLanguage(c, language); |