<commit_before>package com.maxiee.heartbeat.ui;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;

import com.maxiee.heartbeat.R;
import com.maxiee.heartbeat.database.api.AddEventApi;
import com.maxiee.heartbeat.database.api.AddEventLabelRelationApi;
import com.maxiee.heartbeat.database.api.AddLabelsApi;
import com.maxiee.heartbeat.database.api.AddThoughtApi;
import com.maxiee.heartbeat.database.api.GetAllEventApi;
import com.maxiee.heartbeat.model.Thoughts;

import java.util.ArrayList;

/**
 * Created by maxiee on 15-7-29.
 */
public class EntryActivity extends Activity {

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

        // 首次使用添加引导教程
        boolean newUser = new GetAllEventApi(this).exec().isEmpty();
        if (newUser) {
            Log.d("maxiee", "捕捉到一只新用户!生成引导教程...");
            addTutorial();
        }

        // 手势解锁
        SharedPreferences sp = getSharedPreferences("hb", Context.MODE_PRIVATE);
        String pattern = sp.getString("pattern", "");
        if (pattern.isEmpty()) {
            Intent i = new Intent(this, MainActivity.class);
            startActivity(i);
            finish();
        } else {
            Intent i = new Intent(this, PatternActivity.class);
            i.putExtra(PatternActivity.ACTION, PatternActivity.VERIFY);
            startActivity(i);
            finish();
        }
    }

    void addTutorial() {
        ArrayList<String> labels = new ArrayList<>();
        labels.add(getString(R.string.app_name));
        int labelKey = new AddLabelsApi(this, labels).exec().get(0);
        int eventKey;

        // Tut4
        eventKey = (int) new AddEventApi(this, getString(R.string.tut_4_event)).exec();
        new AddEventLabelRelationApi(this, eventKey, labelKey).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_4_thought_1),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_4_thought_2),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_4_thought_3),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_4_thought_4),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();

        // Tut3
        eventKey = (int) new AddEventApi(this, getString(R.string.tut_3_event)).exec();
        new AddEventLabelRelationApi(this, eventKey, labelKey).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_3_thought_1),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_3_thought_2),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();

        // Tut2
        eventKey = (int) new AddEventApi(this, getString(R.string.tut_2_event)).exec();
        new AddEventLabelRelationApi(this, eventKey, labelKey).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_2_thought_1),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_2_thought_2),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_2_thought_3),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();

        // Tut1
        eventKey = (int) new AddEventApi(this, getString(R.string.tut_1_event)).exec();
        new AddEventLabelRelationApi(this, eventKey, labelKey).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_1_thought_1),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_1_thought_2),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_1_thought_3),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
    }
}<commit_msg>EntryActivity.java: DataManager reload when tutorial created.<commit_after>package com.maxiee.heartbeat.ui;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;

import com.maxiee.heartbeat.R;
import com.maxiee.heartbeat.data.DataManager;
import com.maxiee.heartbeat.database.api.AddEventApi;
import com.maxiee.heartbeat.database.api.AddEventLabelRelationApi;
import com.maxiee.heartbeat.database.api.AddLabelsApi;
import com.maxiee.heartbeat.database.api.AddThoughtApi;
import com.maxiee.heartbeat.database.api.GetAllEventApi;
import com.maxiee.heartbeat.model.Thoughts;

import java.util.ArrayList;

/**
 * Created by maxiee on 15-7-29.
 */
public class EntryActivity extends Activity {

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

        // 首次使用添加引导教程
        boolean newUser = new GetAllEventApi(this).exec().isEmpty();
        if (newUser) {
            Log.d("maxiee", "捕捉到一只新用户!生成引导教程...");
            addTutorial();
        }

        // 手势解锁
        SharedPreferences sp = getSharedPreferences("hb", Context.MODE_PRIVATE);
        String pattern = sp.getString("pattern", "");
        if (pattern.isEmpty()) {
            Intent i = new Intent(this, MainActivity.class);
            startActivity(i);
            finish();
        } else {
            Intent i = new Intent(this, PatternActivity.class);
            i.putExtra(PatternActivity.ACTION, PatternActivity.VERIFY);
            startActivity(i);
            finish();
        }
    }

    void addTutorial() {
        DataManager dataManager = DataManager.getInstance(this);
        ArrayList<String> labels = new ArrayList<>();
        labels.add(getString(R.string.app_name));
        int labelKey = new AddLabelsApi(this, labels).exec().get(0);
        int eventKey;

        // Tut4
        eventKey = (int) new AddEventApi(this, getString(R.string.tut_4_event)).exec();
        new AddEventLabelRelationApi(this, eventKey, labelKey).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_4_thought_1),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_4_thought_2),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_4_thought_3),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_4_thought_4),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();

        // Tut3
        eventKey = (int) new AddEventApi(this, getString(R.string.tut_3_event)).exec();
        new AddEventLabelRelationApi(this, eventKey, labelKey).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_3_thought_1),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_3_thought_2),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();

        // Tut2
        eventKey = (int) new AddEventApi(this, getString(R.string.tut_2_event)).exec();
        new AddEventLabelRelationApi(this, eventKey, labelKey).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_2_thought_1),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_2_thought_2),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_2_thought_3),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();

        // Tut1
        eventKey = (int) new AddEventApi(this, getString(R.string.tut_1_event)).exec();
        new AddEventLabelRelationApi(this, eventKey, labelKey).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_1_thought_1),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_1_thought_2),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        new AddThoughtApi(
                this, eventKey,
                getString(R.string.tut_1_thought_3),
                Thoughts.Thought.HAS_NO_RES,
                Thoughts.Thought.HAS_NO_PATH
        ).exec();
        dataManager.reload();
        dataManager.logInfo();
    }
}
{'fraction_non_alphanumeric': 0.1016577743902439, 'fraction_numerical': 0.007240853658536586, 'mean_word_length': 1.9280334728033472, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1562396', 'n_tokens_mistral': 3299, 'n_tokens_neox': 3172, 'n_words': 478}