<commit_before>package jp.hitting.firebasesampleforandroid

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.ImageView
import com.google.firebase.storage.FirebaseStorage
import com.google.firebase.storage.StorageReference
import java.io.ByteArrayOutputStream


class StorageActivity : AppCompatActivity() {

    private var storageRef: StorageReference? = null

    private var imageView1: ImageView? = null
    private var imageView2: ImageView? = null

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

        this.initLayout()
        this.initFirebase()
        this.loadImage1()
        this.loadImage2()
    }

    private fun initLayout() {
        this.setContentView(R.layout.activity_storage)
        this.imageView1 = this.findViewById(R.id.image1) as ImageView
        this.imageView2 = this.findViewById(R.id.image2) as ImageView
    }

    private fun initFirebase() {
        this.storageRef = FirebaseStorage.getInstance().reference
    }

    private fun loadImage1() {
        this.loadImage("1", {
            this.imageView1?.setImageBitmap(it)
        })
    }

    private fun loadImage2() {
        this.loadImage("2", {
            this.imageView2?.setImageBitmap(it)
        })
    }

    private fun loadImage(name: String, completion: (Bitmap) -> Unit) {
        this.storageRef?.child("${name}.png")?.getBytes(1 * 1024 * 1024 /* 1MB */)
                ?.addOnSuccessListener {
                    val image = BitmapFactory.decodeByteArray(it, 0, it.size)
                    completion(image)
                }
    }

    private fun uploadImage(name: String, completion: () -> Unit) {
        val resourceId = this.resources.getIdentifier(name, "drawable", this.packageName)
        val image = BitmapFactory.decodeResource(this.resources, resourceId)
        ByteArrayOutputStream().use {
            image.compress(Bitmap.CompressFormat.PNG, 100, it)
            this.storageRef?.child("${name}.png")?.putBytes(it.toByteArray())
                    ?.addOnSuccessListener {
                        completion()
                    }
        }
    }

}<commit_msg>refactoring<commit_after>package jp.hitting.firebasesampleforandroid

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.ImageView
import com.google.firebase.storage.FirebaseStorage
import com.google.firebase.storage.StorageReference
import java.io.ByteArrayOutputStream


class StorageActivity : AppCompatActivity() {

    private var storageRef: StorageReference? = null

    private var imageView1: ImageView? = null
    private var imageView2: ImageView? = null

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

        this.initLayout()
        this.initFirebase()
        this.loadImageA()
        this.loadImageB()
    }

    private fun initLayout() {
        this.setContentView(R.layout.activity_storage)
        this.imageView1 = this.findViewById(R.id.image1) as ImageView
        this.imageView2 = this.findViewById(R.id.image2) as ImageView
    }

    private fun initFirebase() {
        this.storageRef = FirebaseStorage.getInstance().reference
    }

    private fun loadImageA() {
        this.loadImage("a", {
            this.imageView1?.setImageBitmap(it)
        })
    }

    private fun loadImageB() {
        this.loadImage("b", {
            this.imageView2?.setImageBitmap(it)
        })
    }

    private fun loadImage(name: String, completion: (Bitmap) -> Unit) {
        this.storageRef?.child("${name}.png")?.getBytes(1 * 1024 * 1024 /* 1MB */)
                ?.addOnSuccessListener {
                    val image = BitmapFactory.decodeByteArray(it, 0, it.size)
                    completion(image)
                }
    }

    private fun uploadImage(name: String, completion: () -> Unit) {
        val resourceId = this.resources.getIdentifier(name, "drawable", this.packageName)
        val image = BitmapFactory.decodeResource(this.resources, resourceId)
        ByteArrayOutputStream().use {
            image.compress(Bitmap.CompressFormat.PNG, 100, it)
            this.storageRef?.child("${name}.png")?.putBytes(it.toByteArray())
                    ?.addOnSuccessListener {
                        completion()
                    }
        }
    }

}
{'fraction_non_alphanumeric': 0.10482087571870853, 'fraction_numerical': 0.011499336576735958, 'mean_word_length': 2.53635652853792, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3442074', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1207, 'n_words': 224}