<commit_before>package com.popalay.cardme.presentation.base.navigation

import android.content.Intent
import android.support.v4.app.Fragment
import android.widget.Toast
import com.popalay.cardme.business.exception.AppException
import com.popalay.cardme.presentation.base.BaseActivity
import ru.terrakok.cicerone.android.SupportAppNavigator
import ru.terrakok.cicerone.commands.Command

abstract class CustomNavigator(
        val activity: BaseActivity,
        container: Int = 0
) : SupportAppNavigator(activity, container) {

    override fun applyCommand(command: Command?) {
        if (command is Error) {
            showError(command.exception)
            return
        }
        if (command is ForwardForResult) {
            val activityIntent = createActivityIntent(command.screenKey, command.transitionData)

            // Start activity
            if (activityIntent != null) {
                activity.startActivityForResult(activityIntent, command.requestCode)
                return
            }
        }

        super.applyCommand(command)
    }

    override fun createFragment(screenKey: String, data: Any?): Fragment? {
        return null
    }

    override fun createActivityIntent(screenKey: String, data: Any?): Intent? {
        return null
    }

    open fun showError(exception: AppException) {
        Toast.makeText(activity, exception.messageRes, Toast.LENGTH_LONG).show()
    }
}<commit_msg>Add animation to fragment transactions<commit_after>package com.popalay.cardme.presentation.base.navigation

import android.content.Intent
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.widget.Toast
import com.popalay.cardme.R
import com.popalay.cardme.business.exception.AppException
import com.popalay.cardme.presentation.base.BaseActivity
import ru.terrakok.cicerone.android.SupportAppNavigator
import ru.terrakok.cicerone.commands.Back
import ru.terrakok.cicerone.commands.Command
import ru.terrakok.cicerone.commands.Forward
import ru.terrakok.cicerone.commands.Replace

abstract class CustomNavigator(
        val activity: BaseActivity,
        val containerId: Int = 0
) : SupportAppNavigator(activity, containerId) {

    val fragmentManager: FragmentManager = activity.supportFragmentManager

    override fun applyCommand(command: Command?) {
        if (command is Error) {
            showError(command.exception)
            return
        }
        if (command is ForwardForResult) {
            val activityIntent = createActivityIntent(command.screenKey, command.transitionData)

            // Start activity
            if (activityIntent != null) {
                activity.startActivityForResult(activityIntent, command.requestCode)
                return
            }
        }

        if (command is Forward) {
            val forward = command
            val activityIntent = createActivityIntent(forward.screenKey, forward.transitionData)

            // Start activity
            if (activityIntent != null) {
                activity.startActivity(activityIntent)
                return
            }
        } else if (command is Replace) {
            val replace = command
            val activityIntent = createActivityIntent(replace.screenKey, replace.transitionData)

            // Replace activity
            if (activityIntent != null) {
                activity.startActivity(activityIntent)
                activity.finish()
                return
            }
        }

        if (command is Forward) {
            val forward = command
            val fragment = createFragment(forward.screenKey, forward.transitionData)
            if (fragment == null) {
                unknownScreen(command)
                return
            }
            fragmentManager
                    .beginTransaction()
                    .setCustomAnimations(R.anim.fade_in, R.anim.fade_out)
                    .replace(containerId, fragment)
                    .addToBackStack(forward.screenKey)
                    .commit()
            return
        } else if (command is Back) {
            if (fragmentManager.backStackEntryCount > 0) {
                fragmentManager.popBackStackImmediate()
                return
            } else {
                exit()
                return
            }
        } else if (command is Replace) {
            val replace = command
            val fragment = createFragment(replace.screenKey, replace.transitionData)
            if (fragment == null) {
                unknownScreen(command)
                return
            }
            if (fragmentManager.backStackEntryCount > 0) {
                fragmentManager.popBackStackImmediate()
                fragmentManager
                        .beginTransaction()
                        .setCustomAnimations(R.anim.fade_in, R.anim.fade_out)
                        .replace(containerId, fragment)
                        .addToBackStack(replace.screenKey)
                        .commit()
                return
            } else {
                fragmentManager
                        .beginTransaction()
                        .setCustomAnimations(R.anim.fade_in, R.anim.fade_out)
                        .replace(containerId, fragment)
                        .commit()
                return
            }
        }

        super.applyCommand(command)
    }

    override fun createFragment(screenKey: String, data: Any?): Fragment? = null

    override fun createActivityIntent(screenKey: String, data: Any?): Intent? = null

    open fun showError(exception: AppException) {
        Toast.makeText(activity, exception.messageRes, Toast.LENGTH_LONG).show()
    }
}
{'fraction_non_alphanumeric': 0.07638279192273925, 'fraction_numerical': 0.0012291483757682178, 'mean_word_length': 1.94824016563147, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3024624', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1347, 'n_words': 290}