<commit_before>package com.bukhmastov.cdoitmo.activity.presenter.impl;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.ViewGroup;

import com.bukhmastov.cdoitmo.R;
import com.bukhmastov.cdoitmo.activity.ConnectedActivity;
import com.bukhmastov.cdoitmo.activity.FragmentActivity;
import com.bukhmastov.cdoitmo.activity.presenter.FragmentActivityPresenter;
import com.bukhmastov.cdoitmo.event.bus.EventBus;
import com.bukhmastov.cdoitmo.event.events.MainActivityEvent;
import com.bukhmastov.cdoitmo.factory.AppComponentProvider;
import com.bukhmastov.cdoitmo.firebase.FirebaseConfigProvider;
import com.bukhmastov.cdoitmo.fragment.ConnectedFragment;
import com.bukhmastov.cdoitmo.util.Log;
import com.bukhmastov.cdoitmo.util.NavigationMenu;
import com.bukhmastov.cdoitmo.util.Storage;
import com.bukhmastov.cdoitmo.util.Theme;
import com.bukhmastov.cdoitmo.util.Thread;

import javax.inject.Inject;

public class FragmentActivityPresenterImpl implements FragmentActivityPresenter, NavigationView.OnNavigationItemSelectedListener {

    private static final String TAG = "FragmentActivity";
    private FragmentActivity activity = null;

    @Inject
    Log log;
    @Inject
    Thread thread;
    @Inject
    EventBus eventBus;
    @Inject
    Storage storage;
    @Inject
    NavigationMenu navigationMenu;
    @Inject
    Theme theme;
    @Inject
    FirebaseConfigProvider firebaseConfigProvider;

    public FragmentActivityPresenterImpl() {
        AppComponentProvider.getComponent().inject(this);
    }

    @Override
    public void setActivity(@NonNull FragmentActivity activity) {
        this.activity = activity;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        thread.runOnUI(() -> {
            log.i(TAG, "Activity created");
            try {
                final Intent intent = activity.getIntent();
                if (intent == null) {
                    throw new NullPointerException("Intent cannot be null");
                }
                final Bundle extras = intent.getExtras();
                final Class fragment_class;
                final Bundle fragment_extras;
                if (extras != null) {
                    if (extras.containsKey("class")) {
                        fragment_class = (Class) extras.get("class");
                    } else {
                        throw new NullPointerException("Intent's extras should contains 'class'");
                    }
                    if (extras.containsKey("extras")) {
                        fragment_extras = (Bundle) extras.get("extras");
                    } else {
                        throw new NullPointerException("Intent's extras should contains 'extras'");
                    }
                    if (fragment_extras != null && fragment_extras.containsKey(ConnectedActivity.ACTIVITY_WITH_MENU)) {
                        activity.layout_with_menu = fragment_extras.getBoolean(ConnectedActivity.ACTIVITY_WITH_MENU);
                        fragment_extras.remove(ConnectedActivity.ACTIVITY_WITH_MENU);
                    }
                } else {
                    throw new NullPointerException("Intent's extras cannot be null");
                }
                activity.setContentView(activity.layout_with_menu ? R.layout.activity_fragment : R.layout.activity_fragment_without_menu);
                final Toolbar toolbar = activity.findViewById(R.id.toolbar_fragment);
                if (toolbar != null) {
                    theme.applyToolbarTheme(activity, toolbar);
                    activity.setSupportActionBar(toolbar);
                }
                final ActionBar actionBar = activity.getSupportActionBar();
                if (actionBar != null) {
                    actionBar.setHomeButtonEnabled(true);
                    actionBar.setDisplayHomeAsUpEnabled(true);
                }
                if (activity.layout_with_menu) {
                    ((NavigationView) activity.findViewById(R.id.nav_view)).setNavigationItemSelectedListener(this);
                }
                invoke(fragment_class, fragment_extras);
            } catch (Exception e) {
                log.exception(e);
                activity.finish();
            }
        });
    }

    @Override
    public void onResume() {
        thread.runOnUI(() -> {
            if (activity.layout_with_menu) {
                NavigationView navigationView = activity.findViewById(R.id.nav_view);
                navigationMenu.displayEnableDisableOfflineButton(navigationView);
                navigationMenu.hideIfUnauthorizedMode(navigationView);
                navigationMenu.displayUserData(activity, storage, navigationView);
                navigationMenu.displayRemoteMessage(activity, firebaseConfigProvider, storage);
            }
        });
    }

    @Override<commit_msg>Bug fix<commit_after>package com.bukhmastov.cdoitmo.activity.presenter.impl;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.ViewGroup;

import com.bukhmastov.cdoitmo.R;
import com.bukhmastov.cdoitmo.activity.ConnectedActivity;
import com.bukhmastov.cdoitmo.activity.FragmentActivity;
import com.bukhmastov.cdoitmo.activity.presenter.FragmentActivityPresenter;
import com.bukhmastov.cdoitmo.event.bus.EventBus;
import com.bukhmastov.cdoitmo.event.events.MainActivityEvent;
import com.bukhmastov.cdoitmo.factory.AppComponentProvider;
import com.bukhmastov.cdoitmo.firebase.FirebaseConfigProvider;
import com.bukhmastov.cdoitmo.fragment.ConnectedFragment;
import com.bukhmastov.cdoitmo.util.Log;
import com.bukhmastov.cdoitmo.util.NavigationMenu;
import com.bukhmastov.cdoitmo.util.Storage;
import com.bukhmastov.cdoitmo.util.Theme;
import com.bukhmastov.cdoitmo.util.Thread;

import javax.inject.Inject;

public class FragmentActivityPresenterImpl implements FragmentActivityPresenter, NavigationView.OnNavigationItemSelectedListener {

    private static final String TAG = "FragmentActivity";
    private FragmentActivity activity = null;

    @Inject
    Log log;
    @Inject
    Thread thread;
    @Inject
    EventBus eventBus;
    @Inject
    Storage storage;
    @Inject
    NavigationMenu navigationMenu;
    @Inject
    Theme theme;
    @Inject
    FirebaseConfigProvider firebaseConfigProvider;

    public FragmentActivityPresenterImpl() {
        AppComponentProvider.getComponent().inject(this);
    }

    @Override
    public void setActivity(@NonNull FragmentActivity activity) {
        this.activity = activity;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        thread.runOnUI(() -> {
            log.i(TAG, "Activity created");
            try {
                final Intent intent = activity.getIntent();
                if (intent == null) {
                    throw new NullPointerException("Intent cannot be null");
                }
                final Bundle extras = intent.getExtras();
                final Class fragment_class;
                final Bundle fragment_extras;
                if (extras != null) {
                    if (extras.containsKey("class")) {
                        fragment_class = (Class) extras.get("class");
                    } else {
                        throw new NullPointerException("Intent's extras should contains 'class'");
                    }
                    if (extras.containsKey("extras")) {
                        fragment_extras = (Bundle) extras.get("extras");
                    } else {
                        throw new NullPointerException("Intent's extras should contains 'extras'");
                    }
                    if (fragment_extras != null && fragment_extras.containsKey(ConnectedActivity.ACTIVITY_WITH_MENU)) {
                        activity.layout_with_menu = fragment_extras.getBoolean(ConnectedActivity.ACTIVITY_WITH_MENU);
                        fragment_extras.remove(ConnectedActivity.ACTIVITY_WITH_MENU);
                    }
                } else {
                    throw new NullPointerException("Intent's extras cannot be null");
                }
                activity.setContentView(activity.layout_with_menu ? R.layout.activity_fragment : R.layout.activity_fragment_without_menu);
                final Toolbar toolbar = activity.findViewById(R.id.toolbar_fragment);
                if (toolbar != null) {
                    theme.applyToolbarTheme(activity, toolbar);
                    activity.setSupportActionBar(toolbar);
                }
                final ActionBar actionBar = activity.getSupportActionBar();
                if (actionBar != null) {
                    actionBar.setHomeButtonEnabled(true);
                    actionBar.setDisplayHomeAsUpEnabled(true);
                }
                if (activity.layout_with_menu) {
                    NavigationView navigationView = activity.findViewById(R.id.nav_view);
                    if (navigationView != null) {
                        navigationView.setNavigationItemSelectedListener(this);
                    }
                }
                invoke(fragment_class, fragment_extras);
            } catch (Exception e) {
                log.exception(e);
                activity.finish();
            }
        });
    }

    @Override
    public void onResume() {
        thread.runOnUI(() -> {
            if (activity.layout_with_menu) {
                NavigationView navigationView = activity.findViewById(R.id.nav_view);
                navigationMenu.displayEnableDisableOfflineButton(navigationView);
                navigationMenu.hideIfUnauthorizedMode(navigationView);
                navigationMenu.displayUserData(activity, storage, navigationView);
                navigationMenu.displayRemoteMessage(activity, firebaseConfigProvider, storage);
            }
        });
    }

    @Override
{'fraction_non_alphanumeric': 0.08581710805573498, 'fraction_numerical': 0.0012918704438497739, 'mean_word_length': 2.3837027786450204, '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': '5457026', 'n_tokens_mistral': 2928, 'n_tokens_neox': 2716, 'n_words': 485}