<commit_before>/*
 * Copyright 2020 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
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package dev.chrisbanes.accompanist.sample.coil

import android.os.Bundle
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.Composable
import androidx.compose.Recomposer
import androidx.ui.core.Alignment
import androidx.ui.core.ContextAmbient
import androidx.ui.core.Modifier
import androidx.ui.core.setContent
import androidx.ui.foundation.Text
import androidx.ui.foundation.VerticalScroller
import androidx.ui.layout.FlowRow
import androidx.ui.layout.Stack
import androidx.ui.layout.fillMaxSize
import androidx.ui.layout.padding
import androidx.ui.layout.preferredSize
import androidx.ui.material.CircularProgressIndicator
import androidx.ui.material.Scaffold
import androidx.ui.material.TopAppBar
import androidx.ui.res.stringResource
import androidx.ui.unit.dp
import coil.request.GetRequest
import coil.transform.CircleCropTransformation
import dev.chrisbanes.accompanist.coil.CoilImage
import dev.chrisbanes.accompanist.coil.CoilImageWithCrossfade
import dev.chrisbanes.accompanist.mdctheme.MaterialThemeFromMdcTheme
import dev.chrisbanes.accompanist.sample.R

class CoilSampleActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val contentView = FrameLayout(this)
        setContentView(contentView)

        contentView.setContent(Recomposer.current()) {
            MaterialThemeFromMdcTheme {
                CoilSample()
            }
        }
    }
}

@Composable
fun CoilSample() {
    Scaffold(
        topAppBar = {
            TopAppBar(
                title = { Text(text = stringResource(R.string.coil_title)) }
            )
        }
    ) {
        VerticalScroller(modifier = Modifier.padding(16.dp)) {
            FlowRow(
                mainAxisSpacing = 4.dp,
                crossAxisSpacing = 4.dp
            ) {
                // CoilImage with data parameter
                CoilImage(
                    data = "https://loremflickr.com/300/300",
                    modifier = Modifier.preferredSize(128.dp, 128.dp)
                )

                // CoilImage with GetRequest parameter
                CoilImage(
                    request = GetRequest.Builder(ContextAmbient.current)
                        .data("https://loremflickr.com/300/300")
                        .transformations(CircleCropTransformation())
                        .build(),
                    modifier = Modifier.preferredSize(128.dp, 128.dp)
                )

                // CoilImage with loading slot
                CoilImage(
                    data = "https://loremflickr.com/300/300",
                    loading = {
                        Stack(Modifier.fillMaxSize()) {
                            CircularProgressIndicator(Modifier.gravity(Alignment.Center))
                        }
                    },
                    modifier = Modifier.preferredSize(128.dp, 128.dp)
                )

                // CoilImageWithCrossfade with data parameter
                CoilImageWithCrossfade(
                    data = "https://loremflickr.com/300/300",
                    modifier = Modifier.preferredSize(128.dp, 128.dp)
                )

                // CoilImageWithCrossfade with GetRequest parameter
                CoilImageWithCrossfade(
                    request = GetRequest.Builder(ContextAmbient.current)
                        .data("https://loremflickr.com/300/300")
                        .transformations(CircleCropTransformation())
                        .build(),
                    modifier = Modifier.preferredSize(128.dp, 128.dp)
                )

                // CoilImageWithCrossfade with loading slot
                CoilImageWithCrossfade(
                    data = "https://loremflickr.com/300/300",
                    loading = {
                        Stack(Modifier.fillMaxSize()) {
                            CircularProgressIndicator(Modifier.gravity(Alignment.Center))
                        }
                    },
                    modifier = Modifier.preferredSize(128.dp, 128.dp)
                )
            }
        }
    }
}<commit_msg>Use picsum.images rather than loremflickr.com<commit_after>/*
 * Copyright 2020 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
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package dev.chrisbanes.accompanist.sample.coil

import android.os.Bundle
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.Composable
import androidx.compose.Recomposer
import androidx.ui.core.Alignment
import androidx.ui.core.ContextAmbient
import androidx.ui.core.Modifier
import androidx.ui.core.setContent
import androidx.ui.foundation.Text
import androidx.ui.foundation.VerticalScroller
import androidx.ui.layout.FlowRow
import androidx.ui.layout.Stack
import androidx.ui.layout.fillMaxSize
import androidx.ui.layout.padding
import androidx.ui.layout.preferredSize
import androidx.ui.material.CircularProgressIndicator
import androidx.ui.material.Scaffold
import androidx.ui.material.TopAppBar
import androidx.ui.res.stringResource
import androidx.ui.unit.dp
import coil.request.GetRequest
import coil.transform.CircleCropTransformation
import dev.chrisbanes.accompanist.coil.CoilImage
import dev.chrisbanes.accompanist.coil.CoilImageWithCrossfade
import dev.chrisbanes.accompanist.mdctheme.MaterialThemeFromMdcTheme
import dev.chrisbanes.accompanist.sample.R

class CoilSampleActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val contentView = FrameLayout(this)
        setContentView(contentView)

        contentView.setContent(Recomposer.current()) {
            MaterialThemeFromMdcTheme {
                CoilSample()
            }
        }
    }
}

@Composable
fun CoilSample() {
    Scaffold(
        topAppBar = {
            TopAppBar(
                title = { Text(text = stringResource(R.string.coil_title)) }
            )
        }
    ) {
        VerticalScroller(modifier = Modifier.padding(16.dp)) {
            FlowRow(
                mainAxisSpacing = 4.dp,
                crossAxisSpacing = 4.dp
            ) {
                // CoilImage with data parameter
                CoilImage(
                    data = sampleImageUrl,
                    modifier = Modifier.preferredSize(128.dp, 128.dp)
                )

                // CoilImage with GetRequest parameter
                CoilImage(
                    request = GetRequest.Builder(ContextAmbient.current)
                        .data(sampleImageUrl)
                        .transformations(CircleCropTransformation())
                        .build(),
                    modifier = Modifier.preferredSize(128.dp, 128.dp)
                )

                // CoilImage with loading slot
                CoilImage(
                    data = sampleImageUrl,
                    loading = {
                        Stack(Modifier.fillMaxSize()) {
                            CircularProgressIndicator(Modifier.gravity(Alignment.Center))
                        }
                    },
                    modifier = Modifier.preferredSize(128.dp, 128.dp)
                )

                // CoilImageWithCrossfade with data parameter
                CoilImageWithCrossfade(
                    data = sampleImageUrl,
                    modifier = Modifier.preferredSize(128.dp, 128.dp)
                )

                // CoilImageWithCrossfade with GetRequest parameter
                CoilImageWithCrossfade(
                    request = GetRequest.Builder(ContextAmbient.current)
                        .data(sampleImageUrl)
                        .transformations(CircleCropTransformation())
                        .build(),
                    modifier = Modifier.preferredSize(128.dp, 128.dp)
                )

                // CoilImageWithCrossfade with loading slot
                CoilImageWithCrossfade(
                    data = sampleImageUrl,
                    loading = {
                        Stack(Modifier.fillMaxSize()) {
                            CircularProgressIndicator(Modifier.gravity(Alignment.Center))
                        }
                    },
                    modifier = Modifier.preferredSize(128.dp, 128.dp)
                )
            }
        }
    }
}

private const val sampleImageUrl = "https://picsum.photos/300/300"
{'fraction_non_alphanumeric': 0.07712269047124766, 'fraction_numerical': 0.014324268216732406, 'mean_word_length': 1.8786973409023007, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 9, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5047285', 'n_tokens_mistral': 2684, 'n_tokens_neox': 2425, 'n_words': 499}