<commit_before>package lib.morkim.mfw.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.WindowManager;
import android.widget.Toast;

import java.util.UUID;

import lib.morkim.mfw.R;
import lib.morkim.mfw.app.MorkimApp;

/**
 * Created by Kammar on 2/16/2016.
 */
public abstract class ToolbarScreen<C extends Controller, P extends Presenter> extends AppCompatActivity implements Viewable<MorkimApp, C,P> {

    public static final String KEY_SCREEN_TRANSITION = "screen.transition";

    private UUID id;

    protected C controller;
    protected P presenter;

    protected abstract int toolbarId();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        id = (savedInstanceState == null) ? UUID.randomUUID() : UUID.fromString(savedInstanceState.getString(VIEWABLE_ID));

        setCustomTilteBar();

        int layoutId = layoutId();
        if (layoutId > 0)
            setContentView(layoutId);

        presenter = (P) getMorkimContext().acquirePresenter(this);
        controller = (C) getMorkimContext().acquireController(this);

        int transitionOrdinal = getIntent().getIntExtra(KEY_SCREEN_TRANSITION, Transition.NONE.ordinal());
        Transition transition = Transition.values()[transitionOrdinal];
        animateTransition(transition);

        Toolbar toolbar = (Toolbar) findViewById(toolbarId());
        setSupportActionBar(toolbar);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);

        outState.putString(VIEWABLE_ID, id.toString());
    }

    protected int layoutId() {
        return 0;
    }

    private void animateTransition(Transition transition) {
        switch (transition) {
            case RIGHT:
                overridePendingTransition(R.anim.pull_in_left, R.anim.push_out_right);
                break;
            case LEFT:
                overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
                break;
            default:
                break;
        }
    }

    @Override
    protected void onStart() {
        super.onStart();

        controller.addObserver(this);
    }

    @Override
    protected void onPause() {
        super.onPause();

        keepScreenOn(false);
    }

    @Override
    protected void onStop() {
        super.onStop();

        controller.deleteObserver(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (isFinishing()) {
            ((MorkimApp) getApplication()).destroyController(this);
            ((MorkimApp) getApplication()).destroyPresenter(this);
        }
    }

    protected void setCustomTilteBar() {

    }

    @Override
    public void keepScreenOn(boolean keepOn) {

        if (keepOn)
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        else
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }

    @Override
    public MorkimApp getMorkimContext() {
        return (MorkimApp) getApplication();
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    public Screen<C, P> getScreen() {
        return null;
    }

    @Override
    public C getController() {
        return controller;
    }

    @Override
    public P getPresenter() {
        return presenter;
    }

    @Override
    public void showShortMessage(String message) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }

    @Override
    public UUID getInstanceId() {
        return id;
    }
}
<commit_msg>Fix issue with toolbar screen controller registration<commit_after>package lib.morkim.mfw.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.WindowManager;
import android.widget.Toast;

import java.util.UUID;

import lib.morkim.mfw.R;
import lib.morkim.mfw.app.MorkimApp;

/**
 * Created by Kammar on 2/16/2016.
 */
public abstract class ToolbarScreen<C extends Controller, P extends Presenter> extends AppCompatActivity implements Viewable<MorkimApp, C,P> {

    public static final String KEY_SCREEN_TRANSITION = "screen.transition";

    private UUID id;

    protected C controller;
    protected P presenter;

    protected abstract int toolbarId();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        id = (savedInstanceState == null) ? UUID.randomUUID() : UUID.fromString(savedInstanceState.getString(VIEWABLE_ID));

        setCustomTilteBar();

        int layoutId = layoutId();
        if (layoutId > 0)
            setContentView(layoutId);

        presenter = (P) getMorkimContext().acquirePresenter(this);
        controller = (C) getMorkimContext().acquireController(this);

        int transitionOrdinal = getIntent().getIntExtra(KEY_SCREEN_TRANSITION, Transition.NONE.ordinal());
        Transition transition = Transition.values()[transitionOrdinal];
        animateTransition(transition);

        Toolbar toolbar = (Toolbar) findViewById(toolbarId());
        setSupportActionBar(toolbar);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);

        outState.putString(VIEWABLE_ID, id.toString());
    }

    protected int layoutId() {
        return 0;
    }

    private void animateTransition(Transition transition) {
        switch (transition) {
            case RIGHT:
                overridePendingTransition(R.anim.pull_in_left, R.anim.push_out_right);
                break;
            case LEFT:
                overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
                break;
            default:
                break;
        }
    }

    @Override
    protected void onStart() {
        super.onStart();

        controller.registerForUpdates(this);
    }

    @Override
    protected void onPause() {
        super.onPause();

        keepScreenOn(false);
    }

    @Override
    protected void onStop() {
        super.onStop();

        controller.unregisterFromUpdates(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (isFinishing()) {
            ((MorkimApp) getApplication()).destroyController(this);
            ((MorkimApp) getApplication()).destroyPresenter(this);
        }
    }

    protected void setCustomTilteBar() {

    }

    @Override
    public void keepScreenOn(boolean keepOn) {

        if (keepOn)
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        else
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }

    @Override
    public MorkimApp getMorkimContext() {
        return (MorkimApp) getApplication();
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    public Screen<C, P> getScreen() {
        return null;
    }

    @Override
    public C getController() {
        return controller;
    }

    @Override
    public P getPresenter() {
        return presenter;
    }

    @Override
    public void showShortMessage(String message) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }

    @Override
    public UUID getInstanceId() {
        return id;
    }
}

{'fraction_non_alphanumeric': 0.097317201472909, 'fraction_numerical': 0.0028932140978432403, 'mean_word_length': 2.6093972472710014, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '1688240', 'n_tokens_mistral': 2214, 'n_tokens_neox': 2111, 'n_words': 436}