<commit_before>package com.felipecosta.kotlinrxjavasample.main

import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import com.felipecosta.kotlinrxjavasample.R
import com.felipecosta.kotlinrxjavasample.detail.DetailActivity
import com.felipecosta.kotlinrxjavasample.listing.view.ListingFragment
import com.felipecosta.kotlinrxjavasample.samples.Sample2Fragment
import com.felipecosta.kotlinrxjavasample.samples.Sample3Fragment
import com.felipecosta.kotlinrxjavasample.samples.Sample4Fragment
import io.reactivex.Observable.merge
import io.reactivex.disposables.Disposable

class MainActivity : AppCompatActivity() {

    lateinit var drawer: DrawerLayout
    lateinit var toggle: ActionBarDrawerToggle

    lateinit var navigationView: NavigationView

    lateinit var fab: FloatingActionButton

    lateinit var disposable: Disposable

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.main_activity)

        setupViews()
        bind()
    }

    private fun setupViews() {
        val toolbar = findViewById(R.id.toolbar) as Toolbar
        setSupportActionBar(toolbar)

        drawer = findViewById(R.id.drawer_layout) as DrawerLayout
        toggle = ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close)
        drawer.addDrawerListener(toggle)
        toggle.syncState()

        navigationView = findViewById(R.id.nav_view) as NavigationView

        fab = findViewById(R.id.fab) as FloatingActionButton
    }

    private fun bind() {

        val itemSelectionObservable = navigationView.itemSelections().share()

        val sample1FragmentObservable = itemSelectionObservable.
                filter { it.itemId == R.id.nav_sample_1 }.
                map { ListingFragment.newInstance() }

        val sample2FragmentObservable = itemSelectionObservable.
                filter { it.itemId == R.id.nav_sample_2 }.
                map { Sample2Fragment.newInstance() }

        val sample3FragmentObservable = itemSelectionObservable.
                filter { it.itemId == R.id.nav_sample_3 }.
                map { Sample3Fragment.newInstance() }

        val sample4FragmentObservable = itemSelectionObservable.
                filter { it.itemId == R.id.nav_sample_4 }.
                map { Sample4Fragment.newInstance() }

        val contentFragmentObservable = merge(listOf(sample1FragmentObservable,
                sample2FragmentObservable,
                sample3FragmentObservable,
                sample4FragmentObservable))

        disposable = contentFragmentObservable.
                doOnNext { drawer.closeDrawer(GravityCompat.START) }.
                filter { !(supportFragmentManager.findFragmentById(R.id.main_content)?.javaClass?.equals(it.javaClass) ?: false) }.
                subscribe { supportFragmentManager.beginTransaction().replace(R.id.main_content, it).commit() }

        val fabClickObservable = fab.clicks()

        fabClickObservable.
                subscribe {
                    view ->
                    handleClick(view)
                }

    }

    private fun handleClick(view: Any?) {
        val activityIntent = Intent(this, DetailActivity::class.java)
        activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        this.startActivity(activityIntent)
    }

    override fun onDestroy() {
        super.onDestroy()
        drawer.removeDrawerListener(toggle)
        unbind()
    }

    private fun unbind() {
        disposable.dispose()
    }

    override fun onBackPressed() {
        val drawer = findViewById(R.id.drawer_layout) as DrawerLayout
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START)
        } else {
            super.onBackPressed()
        }
    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        // Inflate the menu; this adds items to the action bar if it is present.
        menuInflater.inflate(R.menu.main, menu)
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {<commit_msg>Passing to DetailActivity a bundle with mocked character<commit_after>package com.felipecosta.kotlinrxjavasample.main

import android.os.Bundle
import android.support.design.widget.FloatingActionButton
import android.support.design.widget.NavigationView
import android.support.v4.view.GravityCompat
import android.support.v4.widget.DrawerLayout
import android.support.v7.app.ActionBarDrawerToggle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.Menu
import android.view.MenuItem
import com.felipecosta.kotlinrxjavasample.R
import com.felipecosta.kotlinrxjavasample.detail.DetailActivity
import com.felipecosta.kotlinrxjavasample.listing.model.marvel.Character
import com.felipecosta.kotlinrxjavasample.listing.model.marvel.Thumbnail
import com.felipecosta.kotlinrxjavasample.listing.view.ListingFragment
import com.felipecosta.kotlinrxjavasample.rx.clicks
import com.felipecosta.kotlinrxjavasample.rx.itemSelections
import com.felipecosta.kotlinrxjavasample.samples.Sample2Fragment
import com.felipecosta.kotlinrxjavasample.samples.Sample3Fragment
import com.felipecosta.kotlinrxjavasample.samples.Sample4Fragment
import io.reactivex.Observable.merge
import io.reactivex.disposables.Disposable
import java.util.*

class MainActivity : AppCompatActivity() {

    lateinit var drawer: DrawerLayout

    lateinit var toggle: ActionBarDrawerToggle

    lateinit var navigationView: NavigationView

    lateinit var fab: FloatingActionButton

    lateinit var disposable: Disposable

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.main_activity)

        setupViews()
        bind()
    }

    private fun setupViews() {
        val toolbar = findViewById(R.id.toolbar) as Toolbar
        setSupportActionBar(toolbar)

        drawer = findViewById(R.id.drawer_layout) as DrawerLayout
        toggle = ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close)
        drawer.addDrawerListener(toggle)
        toggle.syncState()

        navigationView = findViewById(R.id.nav_view) as NavigationView

        fab = findViewById(R.id.fab) as FloatingActionButton
    }

    private fun bind() {

        val itemSelectionObservable = navigationView.itemSelections().share()

        val sample1FragmentObservable = itemSelectionObservable.
                filter { it.itemId == R.id.nav_sample_1 }.
                map { ListingFragment.newInstance() }

        val sample2FragmentObservable = itemSelectionObservable.
                filter { it.itemId == R.id.nav_sample_2 }.
                map { Sample2Fragment.newInstance() }

        val sample3FragmentObservable = itemSelectionObservable.
                filter { it.itemId == R.id.nav_sample_3 }.
                map { Sample3Fragment.newInstance() }

        val sample4FragmentObservable = itemSelectionObservable.
                filter { it.itemId == R.id.nav_sample_4 }.
                map { Sample4Fragment.newInstance() }

        val contentFragmentObservable = merge(listOf(sample1FragmentObservable,
                sample2FragmentObservable,
                sample3FragmentObservable,
                sample4FragmentObservable))

        disposable = contentFragmentObservable.
                doOnNext { drawer.closeDrawer(GravityCompat.START) }.
                filter { !(supportFragmentManager.findFragmentById(R.id.main_content)?.javaClass?.equals(it.javaClass) ?: false) }.
                subscribe { supportFragmentManager.beginTransaction().replace(R.id.main_content, it).commit() }

        val fabClickObservable = fab.clicks()

        fabClickObservable.
                subscribe {
                    view ->
                    handleClick(view)
                }

    }

    private fun handleClick(view: Any?) {
        DetailActivity.startDetail(this, getCharacter())
    }

    private fun getCharacter(): Character {
        val char = Character()
        char.id = 1011334
        char.name = "<NAME>"
        char.description = ""
        char.modified = Date() // "2014-04-29T14:18:17-0400",
        val thumbnail = Thumbnail()
        thumbnail.path = "http://i.annihil.us/u/prod/marvel/i/mg/c/e0/535fecbbb9784"
        thumbnail.extension = "jpg"
        char.thumbnail = thumbnail
        char.resourceURI = "http://gateway.marvel.com/v1/public/characters/1011334"
        return char
    }

    override fun onDestroy() {
        super.onDestroy()
        drawer.removeDrawerListener(toggle)
        unbind()
    }

    private fun unbind() {
        disposable.dispose()
    }

    override fun onBackPressed() {
        val drawer = findViewById(R.id.drawer_layout) as DrawerLayout
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START)
        } else {
            super.onBackPressed()
        }
    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        // Inflate the menu; this adds items to the action bar if it is present.
        menuInflater.inflate(R.menu.main, menu)
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
{'fraction_non_alphanumeric': 0.08219756999471738, 'fraction_numerical': 0.008663497094558902, 'mean_word_length': 2.7970316887284397, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, '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': '3405211', 'n_tokens_mistral': 2763, 'n_tokens_neox': 2583, 'n_words': 471}