Skip to content

Instantly share code, notes, and snippets.

View damianpetla's full-sized avatar
🐢
Mastering Compose

Damian Petla damianpetla

🐢
Mastering Compose
View GitHub Profile
@damianpetla
damianpetla / DateUtils.kt
Last active August 29, 2015 14:10
Simple way to convert ISO8601 date/time to localised date/time
import java.util.TimeZone
import android.text.format.Time
import java.text.SimpleDateFormat
import java.text.DateFormat
/**
* Created by loop on 24/11/14.
*/
/**
@damianpetla
damianpetla / GmailAuthenticator.kt
Last active August 29, 2015 14:18
Trait's restricted class example
trait GmailAuthenticator : ActionBarActivity {
companion object {
val TAG = javaClass<GmailAuthenticator>().getName()
val PLAY_SERVICES_RESOLUTION_REQUEST = 9000
val REQUEST_CODE_PICK_ACCOUNT = 1000
val REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR = 1001
val AUDIENCE = "audience:...."
}
@damianpetla
damianpetla / someClass.kt
Created May 21, 2015 08:45
Coloring text with HTML tags
val color = getResources().getString(R.color.some_color).replace("#ff", "#")
val terms = getString(R.string.register_terms, color)
termsText.setText(Html.fromHtml(terms))
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
SwipeRefreshLayout rv = (SwipeRefreshLayout) inflater.inflate(
R.layout.fragment_cheese_list, container, false);
rv.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
}
public class MySwipeLayout : SwipeRefreshLayout {
public constructor(context: Context) : super(context)
public constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
var appBarLayout: AppBarLayout? = null
override fun onAttachedToWindow() {
super<SwipeRefreshLayout>.onAttachedToWindow()
@damianpetla
damianpetla / FadeLineSpan.kt
Last active June 27, 2018 16:14
Fading TexView line
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 {
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)
{
"articles": [],
"links": {
"next": "/articles?sort=latest&offset=15&articleOffset=10&limit=10",
"self": "/articles?sort=latest"
}
}
@Composable
fun SimpleList() {
Column {
Text("First item")
Text("Second item")
for (i in 0..10) {
Text("Next $i item")
}
}
}
@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
}
}