<commit_before>package com.awscherb.cardkeeper.ui.card_detail

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.awscherb.cardkeeper.R
import com.awscherb.cardkeeper.data.model.ScannedCode
import com.awscherb.cardkeeper.ui.base.BaseFragment
import com.google.zxing.BarcodeFormat.*
import com.google.zxing.WriterException
import com.jakewharton.rxbinding3.widget.textChanges
import com.journeyapps.barcodescanner.BarcodeEncoder
import kotlinx.android.synthetic.main.fragment_card_detail.*
import javax.inject.Inject

class CardDetailFragment : BaseFragment(), CardDetailContract.View {

    @Inject
    internal lateinit var presenter: CardDetailContract.Presenter

    private val encoder: BarcodeEncoder = BarcodeEncoder()

    //================================================================================
    // Lifecycle methods
    //================================================================================

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

        baseActivity.viewComponent().inject(this)
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View = inflater.inflate(R.layout.fragment_card_detail, container, false)

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        presenter.attachView(this)

        cardDetailSave.setOnClickListener { presenter.saveCard() }

        val args = CardDetailFragmentArgs.fromBundle(arguments!!)
        presenter.loadCard(args.cardId)
    }

    override fun onDestroy() {
        presenter.onViewDestroyed()
        super.onDestroy()
    }

    //================================================================================
    // View methods
    //================================================================================

    override fun showCard(code: ScannedCode) {
        // Set title
        cardDetailTitle.setText(code.title)
        cardDetailText.text = code.text

        activity!!.title = code.title

        // Set image scaleType according to barcode type
        val scaleType = when (code.format) {
            QR_CODE, AZTEC, DATA_MATRIX -> ImageView.ScaleType.FIT_CENTER
            else -> ImageView.ScaleType.FIT_XY
        }
        cardDetailImage.scaleType = scaleType

        // Load image
        try {
            cardDetailImage.setImageBitmap(
                encoder.encodeBitmap(code.text, code.format, 200, 200)
            )
        } catch (e: WriterException) {
            e.printStackTrace()
        }

        addDisposable(
            cardDetailTitle.textChanges()
                .map { it.toString() }
                .compose(bindToLifecycle())
                .subscribe({ presenter.setTitle(it) },
                    { onError(it) })
        )
    }

    override fun setSaveVisible(visible: Boolean) {
        cardDetailSave.visibility = if (visible) View.VISIBLE else View.GONE
    }

    override fun onCardSaved() {
        activity!!.finish()
    }

    override fun onError(e: Throwable) {
        e.printStackTrace()
    }
}<commit_msg>Use back instead of finishing activity<commit_after>package com.awscherb.cardkeeper.ui.card_detail

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.awscherb.cardkeeper.R
import com.awscherb.cardkeeper.data.model.ScannedCode
import com.awscherb.cardkeeper.ui.base.BaseFragment
import com.google.zxing.BarcodeFormat.*
import com.google.zxing.WriterException
import com.jakewharton.rxbinding3.widget.textChanges
import com.journeyapps.barcodescanner.BarcodeEncoder
import kotlinx.android.synthetic.main.fragment_card_detail.*
import javax.inject.Inject

class CardDetailFragment : BaseFragment(), CardDetailContract.View {

    @Inject
    internal lateinit var presenter: CardDetailContract.Presenter

    private val encoder: BarcodeEncoder = BarcodeEncoder()

    //================================================================================
    // Lifecycle methods
    //================================================================================

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

        baseActivity.viewComponent().inject(this)
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View = inflater.inflate(R.layout.fragment_card_detail, container, false)

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        presenter.attachView(this)

        cardDetailSave.setOnClickListener { presenter.saveCard() }

        val args = CardDetailFragmentArgs.fromBundle(arguments!!)
        presenter.loadCard(args.cardId)
    }

    override fun onDestroy() {
        presenter.onViewDestroyed()
        super.onDestroy()
    }

    //================================================================================
    // View methods
    //================================================================================

    override fun showCard(code: ScannedCode) {
        // Set title
        cardDetailTitle.setText(code.title)
        cardDetailText.text = code.text

        activity!!.title = code.title

        // Set image scaleType according to barcode type
        val scaleType = when (code.format) {
            QR_CODE, AZTEC, DATA_MATRIX -> ImageView.ScaleType.FIT_CENTER
            else -> ImageView.ScaleType.FIT_XY
        }
        cardDetailImage.scaleType = scaleType

        // Load image
        try {
            cardDetailImage.setImageBitmap(
                encoder.encodeBitmap(code.text, code.format, 200, 200)
            )
        } catch (e: WriterException) {
            e.printStackTrace()
        }

        addDisposable(
            cardDetailTitle.textChanges()
                .map { it.toString() }
                .compose(bindToLifecycle())
                .subscribe({ presenter.setTitle(it) },
                    { onError(it) })
        )
    }

    override fun setSaveVisible(visible: Boolean) {
        cardDetailSave.visibility = if (visible) View.VISIBLE else View.GONE
    }

    override fun onCardSaved() {
        activity?.onBackPressed()
    }

    override fun onError(e: Throwable) {
        e.printStackTrace()
    }
}
{'fraction_non_alphanumeric': 0.1777610818933133, 'fraction_numerical': 0.0021036814425244178, 'mean_word_length': 2.9951980792316926, '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': '5398832', 'n_tokens_mistral': 1794, 'n_tokens_neox': 1668, 'n_words': 319}