<commit_before>package org.stepic.droid.adaptive.ui.activities

import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatDelegate
import androidx.viewpager.widget.ViewPager
import kotlinx.android.synthetic.main.activity_adaptive_stats.*
import org.stepic.droid.R
import org.stepic.droid.adaptive.ui.adapters.AdaptiveStatsViewPagerAdapter
import org.stepic.droid.adaptive.ui.fragments.AdaptiveRatingFragment
import org.stepic.droid.analytic.AmplitudeAnalytic
import org.stepic.droid.base.FragmentActivityBase
import org.stepic.droid.ui.util.initCenteredToolbar
import org.stepic.droid.util.AppConstants

class AdaptiveStatsActivity : FragmentActivityBase() {
    companion object {
        init {
            AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
        }
    }

    private var courseId: Long = 0
    private var hasSavedInstanceState: Boolean = false
    private lateinit var adapter: AdaptiveStatsViewPagerAdapter
    private val onPageChangeListener = object : ViewPager.SimpleOnPageChangeListener() {
        override fun onPageSelected(page: Int) {
            if (adapter.getItem(page) is AdaptiveRatingFragment) {
                analytic
                    .reportAmplitudeEvent(
                        AmplitudeAnalytic.Adaptive.RATING_OPENED,
                        mapOf(AmplitudeAnalytic.Adaptive.Params.COURSE to courseId.toString())
                    )
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_adaptive_stats)
        initCenteredToolbar(R.string.adaptive_stats_title, true)

        courseId = intent.getLongExtra(AppConstants.KEY_COURSE_LONG_ID, 0)
        hasSavedInstanceState = savedInstanceState != null

        adapter = AdaptiveStatsViewPagerAdapter(supportFragmentManager, this, courseId)
        pager.adapter = adapter
        pager.offscreenPageLimit = adapter.count
        tabLayout.setupWithViewPager(pager)
    }

    override fun onResume() {
        super.onResume()
        courseId = intent.getLongExtra(AppConstants.KEY_COURSE_LONG_ID, 0)
        pager.addOnPageChangeListener(onPageChangeListener)
        if (!hasSavedInstanceState && pager.currentItem == 0) {
            onPageChangeListener.onPageSelected(0)
        }
    }

    override fun onPause() {
        pager.removeOnPageChangeListener(onPageChangeListener)
        super.onPause()
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        if (item?.itemId == android.R.id.home) {
            onBackPressed()<commit_msg>redundant init in onResume<commit_after>package org.stepic.droid.adaptive.ui.activities

import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatDelegate
import androidx.viewpager.widget.ViewPager
import kotlinx.android.synthetic.main.activity_adaptive_stats.*
import org.stepic.droid.R
import org.stepic.droid.adaptive.ui.adapters.AdaptiveStatsViewPagerAdapter
import org.stepic.droid.adaptive.ui.fragments.AdaptiveRatingFragment
import org.stepic.droid.analytic.AmplitudeAnalytic
import org.stepic.droid.base.FragmentActivityBase
import org.stepic.droid.ui.util.initCenteredToolbar
import org.stepic.droid.util.AppConstants

class AdaptiveStatsActivity : FragmentActivityBase() {
    companion object {
        init {
            AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
        }
    }

    private var courseId: Long = 0
    private var hasSavedInstanceState: Boolean = false
    private lateinit var adapter: AdaptiveStatsViewPagerAdapter
    private val onPageChangeListener = object : ViewPager.SimpleOnPageChangeListener() {
        override fun onPageSelected(page: Int) {
            if (adapter.getItem(page) is AdaptiveRatingFragment) {
                analytic
                    .reportAmplitudeEvent(
                        AmplitudeAnalytic.Adaptive.RATING_OPENED,
                        mapOf(AmplitudeAnalytic.Adaptive.Params.COURSE to courseId.toString())
                    )
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_adaptive_stats)
        initCenteredToolbar(R.string.adaptive_stats_title, true)

        courseId = intent.getLongExtra(AppConstants.KEY_COURSE_LONG_ID, 0)
        hasSavedInstanceState = savedInstanceState != null

        adapter = AdaptiveStatsViewPagerAdapter(supportFragmentManager, this, courseId)
        pager.adapter = adapter
        pager.offscreenPageLimit = adapter.count
        tabLayout.setupWithViewPager(pager)
    }

    override fun onResume() {
        super.onResume()
        pager.addOnPageChangeListener(onPageChangeListener)
        if (!hasSavedInstanceState && pager.currentItem == 0) {
            onPageChangeListener.onPageSelected(0)
        }
    }

    override fun onPause() {
        pager.removeOnPageChangeListener(onPageChangeListener)
        super.onPause()
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        if (item?.itemId == android.R.id.home) {
            onBackPressed()
{'fraction_non_alphanumeric': 0.07627443464929091, 'fraction_numerical': 0.0017247987734764277, 'mean_word_length': 3.142063492063492, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6892839', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1461, 'n_words': 233}