This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.compose.ui.text.input.OffsetMapping | |
class CurrencyOffsetMapping(originalText: String, formattedText: String) : OffsetMapping { | |
private val originalLength: Int = originalText.length | |
private val indexes = findDigitIndexes(originalText, formattedText) | |
private fun findDigitIndexes(firstString: String, secondString: String): List<Int> { | |
val digitIndexes = mutableListOf<Int>() | |
var currentIndex = 0 | |
for (digit in firstString) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val snackBarState = remember { SnackbarHostState() } | |
Scaffold( | |
modifier = Modifier.fillMaxSize(), | |
snackbarHost = { | |
SnackbarHost(hostState = snackBarState) { | |
Snackbar { | |
Text(text = it.visuals.message) | |
} | |
} | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : ComponentActivity() { | |
private val viewModel by viewModels<MainViewModel>() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
ComposeStateTestTheme { | |
val state: MainState by viewModel.state.collectAsState() | |
MainScaffold( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExperimentalCoroutinesApi | |
@Composable | |
fun LatestNewsFeed(viewModel: NewsViewModel) { | |
val state = viewModel.newsState.collectAsState() | |
val lastIndex = state.value.articles.lastIndex | |
LazyColumnForIndexed(items = state.value.articles) { i, newsItem -> | |
if (lastIndex == i) { | |
onActive { | |
viewModel.getMoreNews() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun LazyExampleWithIndex() { | |
val items = listOf("Cat", "Dog", "Monkey")//1000 of these | |
val lastIndex = items.lastIndex | |
LazyColumnForIndexed(items = items) { index, item -> | |
if (lastIndex == index) { | |
onActive { | |
//fetch more items from API | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun LazyList() { | |
val items = listOf("Dog", "Cat", "Monkey")//1000 of these | |
LazyColumnFor(items = items) { item -> | |
Text(text = item) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun SimpleList() { | |
Column { | |
Text("First item") | |
Text("Second item") | |
for (i in 0..10) { | |
Text("Next $i item") | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"articles": [], | |
"links": { | |
"next": "/articles?sort=latest&offset=15&articleOffset=10&limit=10", | |
"self": "/articles?sort=latest" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AdItemHolder(item: View) : BaseHolder(item) { | |
private val adLabel = item.findViewById<View>(R.id.adlabel) | |
private val adContent = item.findViewById<View>(R.id.adcontent) | |
private val labelElevation = item.resources.getDimension(R.dimen.cardview_default_elevation) | |
init { | |
item.viewTreeObserver.addOnScrollChangedListener { | |
val offset = -item.top.toFloat() | |
adLabel.translationY = Math.max(offset, 0f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.Canvas | |
import android.graphics.Color | |
import android.graphics.Paint | |
import android.graphics.Rect | |
import android.graphics.drawable.GradientDrawable | |
import android.text.Layout | |
import android.text.style.LeadingMarginSpan | |
class FadeLineSpan(val fadingLine: Int, color: Int) : LeadingMarginSpan.LeadingMarginSpan2 { |
NewerOlder