<commit_before>package com.sakebook.android.sample.bottomnavigationviewsample

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.design.widget.BottomNavigationView
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentTransaction
import android.support.v7.widget.Toolbar
import android.view.View


class MainActivity : AppCompatActivity() {

    private val toolbar by lazy { findViewById(R.id.toolbar) as Toolbar }
    private val bottomNavigation by lazy { findViewById(R.id.bottom_navigation) as BottomNavigationView }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        findViewById(android.R.id.content).systemUiVisibility =
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        setContentView(R.layout.activity_main)
        initToolbar()
        initBottomNavigation()
    }

    private fun initToolbar() {
        toolbar.title = resources.getString(R.string.app_name)
    }

    private fun initBottomNavigation() {
        val tabCount = 3
        val fragments = (0 until tabCount).mapIndexed { i, value ->
            MainFragment.newInstance(i)
        }
        updateBottomNavigation(fragments, 0, "0")
        bottomNavigation.setOnNavigationItemSelectedListener {
            when(it.itemId) {
                R.id.navigation_recents -> {
                    updateBottomNavigation(fragments, 0, "0")
                }
                R.id.navigation_favorites -> {
                    updateBottomNavigation(fragments, 1, "1")
                }
                R.id.navigation_nearby -> {
                    updateBottomNavigation(fragments, 2, "2")
                }
                else -> return@setOnNavigationItemSelectedListener false
            }
        }
    }

    private fun updateBottomNavigation(fragments: List<Fragment>, position: Int, tag: String): Boolean {
        val fragment = supportFragmentManager.findFragmentByTag(tag)
        when(fragment) {
            null -> supportFragmentManager
                    .beginTransaction()
                    .replace(R.id.layout_container, fragments[position], tag)
                    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                    .commit()
            else -> {
                if (fragment is BottomNavigationInterface) {
                    fragment.scrollToTop()<commit_msg>Refresh fragment state<commit_after>package com.sakebook.android.sample.bottomnavigationviewsample

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.design.widget.BottomNavigationView
import android.support.v4.app.FragmentTransaction
import android.support.v7.widget.Toolbar
import android.view.View


class MainActivity : AppCompatActivity() {

    private val toolbar by lazy { findViewById(R.id.toolbar) as Toolbar }
    private val bottomNavigation by lazy { findViewById(R.id.bottom_navigation) as BottomNavigationView }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        findViewById(android.R.id.content).systemUiVisibility =
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        setContentView(R.layout.activity_main)
        initToolbar()
        initBottomNavigation()
    }

    private fun initToolbar() {
        toolbar.title = resources.getString(R.string.app_name)
    }

    private fun initBottomNavigation() {
        updateBottomNavigation(0, "0")
        bottomNavigation.setOnNavigationItemSelectedListener {
            when(it.itemId) {
                R.id.navigation_recents -> {
                    updateBottomNavigation(0, "0")
                }
                R.id.navigation_favorites -> {
                    updateBottomNavigation(1, "1")
                }
                R.id.navigation_nearby -> {
                    updateBottomNavigation(2, "2")
                }
                else -> return@setOnNavigationItemSelectedListener false
            }
        }
    }

    private fun updateBottomNavigation(position: Int, tag: String): Boolean {
        val fragment = supportFragmentManager.findFragmentByTag(tag)
        when(fragment) {
            null -> {
                supportFragmentManager
                        .beginTransaction()
                        .replace(R.id.layout_container, MainFragment.newInstance(position), tag)
                        .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                        .commit()
            }
            else -> {
                if (fragment is BottomNavigationInterface) {
                    fragment.scrollToTop()
{'fraction_non_alphanumeric': 0.07819181429444105, 'fraction_numerical': 0.005090612909794339, 'mean_word_length': 2.1916829109811564, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 17, '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': '4674310', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1206, 'n_words': 212}