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

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.util.Log;
import android.util.TypedValue;
import android.view.MenuItem;
import android.widget.TextView;

import com.maxiee.heartbeat.R;
import com.maxiee.heartbeat.common.TimeUtils;
import com.maxiee.heartbeat.database.api.GetEventsByLabelKeyApi;
import com.maxiee.heartbeat.database.api.HasLabelApi;
import com.maxiee.heartbeat.model.Event;
import com.maxiee.heartbeat.ui.adapter.EventListAdapter;

import java.util.ArrayList;

/**
 * Created by maxiee on 15-6-27.
 */
public class LabelDetailActivity extends AppCompatActivity{

    private Toolbar mToolbar;
    private RecyclerView mRecyclerView;
    private TextView mLabelHint;
    private String mLabel;
    private ArrayList<Event> mEventList;
    private int mAccentColor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_label_detail);

        Intent i = getIntent();

        mLabel = i.getStringExtra("tag_text");

        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mLabelHint = (TextView) findViewById(R.id.label_hint);
        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mRecyclerView.getContext()));

        TypedValue accentValue = new TypedValue();
        getTheme().resolveAttribute(R.attr.colorAccent, accentValue, true);
        mAccentColor = accentValue.data;

        if (mLabel != null) {
            int labelKey = new HasLabelApi(this, mLabel).exec();
            updateEventList(labelKey);
            showHintText();
        }
    }

    public void updateEventList(int labelKey) {
        mEventList = new GetEventsByLabelKeyApi(this, labelKey).exec();
        mRecyclerView.setAdapter(new EventListAdapter(mEventList));
    }

    public void showHintText() {
        if (mEventList.size() < 1) return;
        long earlistEventTime = mEventList.get(mEventList.size() - 1).getTimestamp();
        long latestEventTime = mEventList.get(0).getTimestamp();
        ArrayList<String> hint = new ArrayList<>();
        hint.add(mLabel + "\n");
        hint.add(getString(R.string.label_hint_001));
        hint.add(TimeUtils.parseTime(this, earlistEventTime));
        hint.add(getString(R.string.label_hint_002));
        hint.add(String.valueOf(mEventList.size()));
        hint.add(getString(R.string.label_hint_003));
        hint.add(String.valueOf(
                TimeUtils.countDaysBetween(
                        earlistEventTime,
                        latestEventTime)));
        hint.add(getString(R.string.label_hint_004));
        String textToSpan = "";
        for (int i=0; i<hint.size(); i++) {
            textToSpan += hint.get(i);
        }
        Spannable spannable = new SpannableString(textToSpan);
        int offset = 0;
        for (int i=0; i<hint.size(); i++) {
            if (i == 0) {
                spannable.setSpan(
                        new RelativeSizeSpan(1.5f),
                        0,
                        mLabel.length(),
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                );
                spannable.setSpan(
                        new StyleSpan(Typeface.BOLD),
                        0,
                        mLabel.length(),<commit_msg>LabelDetailActivity.java: fix wrong latest time.<commit_after>package com.maxiee.heartbeat.ui;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.util.Log;
import android.util.TypedValue;
import android.view.MenuItem;
import android.widget.TextView;

import com.maxiee.heartbeat.R;
import com.maxiee.heartbeat.common.TimeUtils;
import com.maxiee.heartbeat.database.api.GetEventsByLabelKeyApi;
import com.maxiee.heartbeat.database.api.HasLabelApi;
import com.maxiee.heartbeat.model.Event;
import com.maxiee.heartbeat.ui.adapter.EventListAdapter;

import java.util.ArrayList;

/**
 * Created by maxiee on 15-6-27.
 */
public class LabelDetailActivity extends AppCompatActivity{

    private Toolbar mToolbar;
    private RecyclerView mRecyclerView;
    private TextView mLabelHint;
    private String mLabel;
    private ArrayList<Event> mEventList;
    private int mAccentColor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_label_detail);

        Intent i = getIntent();

        mLabel = i.getStringExtra("tag_text");

        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mLabelHint = (TextView) findViewById(R.id.label_hint);
        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mRecyclerView.getContext()));

        TypedValue accentValue = new TypedValue();
        getTheme().resolveAttribute(R.attr.colorAccent, accentValue, true);
        mAccentColor = accentValue.data;

        if (mLabel != null) {
            int labelKey = new HasLabelApi(this, mLabel).exec();
            updateEventList(labelKey);
            showHintText();
        }
    }

    public void updateEventList(int labelKey) {
        mEventList = new GetEventsByLabelKeyApi(this, labelKey).exec();
        mRecyclerView.setAdapter(new EventListAdapter(mEventList));
    }

    public void showHintText() {
        if (mEventList.size() < 1) return;
        long earlistEventTime = mEventList.get(mEventList.size() - 1).getTimestamp();
        long latestEventTime = System.currentTimeMillis();
        ArrayList<String> hint = new ArrayList<>();
        hint.add(mLabel + "\n");
        hint.add(getString(R.string.label_hint_001));
        hint.add(TimeUtils.parseTime(this, earlistEventTime));
        hint.add(getString(R.string.label_hint_002));
        hint.add(String.valueOf(mEventList.size()));
        hint.add(getString(R.string.label_hint_003));
        hint.add(String.valueOf(
                TimeUtils.countDaysBetween(
                        earlistEventTime,
                        latestEventTime)));
        hint.add(getString(R.string.label_hint_004));
        String textToSpan = "";
        for (int i=0; i<hint.size(); i++) {
            textToSpan += hint.get(i);
        }
        Spannable spannable = new SpannableString(textToSpan);
        int offset = 0;
        for (int i=0; i<hint.size(); i++) {
            if (i == 0) {
                spannable.setSpan(
                        new RelativeSizeSpan(1.5f),
                        0,
                        mLabel.length(),
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                );
                spannable.setSpan(
                        new StyleSpan(Typeface.BOLD),
                        0,
                        mLabel.length(),
{'fraction_non_alphanumeric': 0.10525027536409252, 'fraction_numerical': 0.007710194590625383, 'mean_word_length': 2.8151260504201683, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, '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': '2404375', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2323, 'n_words': 407}