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

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.maxiee.heartbeat.R;
import com.maxiee.heartbeat.common.FileUtils;
import com.maxiee.heartbeat.common.TimeUtils;
import com.maxiee.heartbeat.common.tagview.Tag;
import com.maxiee.heartbeat.common.tagview.TagView;
import com.maxiee.heartbeat.database.utils.EventUtils;
import com.maxiee.heartbeat.database.utils.ImageUtils;
import com.maxiee.heartbeat.database.utils.LabelUtils;
import com.maxiee.heartbeat.database.utils.ThoughtUtils;
import com.maxiee.heartbeat.model.Event;
import com.maxiee.heartbeat.model.Image;
import com.maxiee.heartbeat.model.Label;
import com.maxiee.heartbeat.model.Thoughts;
import com.maxiee.heartbeat.ui.adapter.ThoughtTimeaxisAdapter;
import com.maxiee.heartbeat.ui.common.BaseActivity;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by maxiee on 15-6-13.
 */
public class EventDetailActivity extends BaseActivity {
    private final static String TAG = EventDetailActivity.class.getSimpleName();

    public static final String EXTRA_NAME = "id";
    private static final int ADD_IMAGE = 1127;
    private static final int LONG_IMAGE_IMAGE_MAX_HEIGHT = 300;

    private long mId;
    private Event mEvent;

    @Bind(R.id.tv_event)        TextView mTvEvent;
    @Bind(R.id.recyclerview)    RecyclerView mRecyclerView;
    @Bind(R.id.tagview)         TagView mTagView;
    @Bind(R.id.tv_time)         TextView mTvTime;
    @Bind(R.id.backdrop)        ImageView mImageBackDrop;
    @Bind(R.id.card_event)      View mCardEvent;
    @Bind(R.id.add_imgae)       TextView mAddImageText;
    @Bind(R.id.header)          View mHeaderView;

    private LinearLayoutManager mLayoutManager;
    private ThoughtTimeaxisAdapter mAdapter;

    private Image mImage;
    private Thoughts mThoughts;
    private String mSortingType;
    private boolean mHasImage = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_event_detail);
        ButterKnife.bind(this);

        Intent intent = getIntent();
        mId = intent.getLongExtra(EXTRA_NAME, -1);

        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        mSortingType = sp.getString("time_axis_sorting", "0");

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

        setTitle("");
        mLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(mLayoutManager);

        mEvent = EventUtils.getEvent(this, mId);

        mTagView.setOnTagClickListener(new TagView.OnTagClickListener() {
            @Override
            public void onTagClick(Tag tag, int position) {
                Intent i = new Intent();
                i.setAction(Intent.ACTION_MAIN);
                i.setClass(EventDetailActivity.this, LabelDetailActivity.class);
                i.putExtra("tag_text", tag.text);
                startActivity(i);
            }
        });

        mTvTime.setText(TimeUtils.parseTime(this, mEvent.getTimestamp()));

        mCardEvent.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Intent i = new Intent(EventDetailActivity.this, AddEventActivity.class);
                i.putExtra(AddEventActivity.ID_EVENT_MODIFY, mId);
                startActivity(i);
                return true;
            }
        });

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(EventDetailActivity.this, AddEditThoughtActivity.class);
                i.putExtra(AddEditThoughtActivity.MODE, AddEditThoughtActivity.MODE_NEW);
                i.putExtra(AddEditThoughtActivity.EVENT_KEY, mId);
                startActivity(i);
            }
        });

        mThoughts = ThoughtUtils.getThoughtsByEventId(this, mId);
        mAdapter = new ThoughtTimeaxisAdapter(mThoughts);
        mRecyclerView.setAdapter(mAdapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mEvent = EventUtils.getEvent(this, mId);
        mTvEvent.setText(mEvent.getEvent());
        mThoughts = ThoughtUtils.getThoughtsByEventId(this, mEvent.getId());
        mAdapter.setData(mThoughts);
        initImage();
        updateTagView();
    }

    private void initImage() {
        mImage = ImageUtils.getImageByEventId(this, mEvent.getId());
        if (mImage == null) {
            mAddImageText.setVisibility(View.VISIBLE);
            mAddImageText.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (Build.VERSION.SDK_INT < 19) {<commit_msg>EventDetailActivity.java: time axis data reload.<commit_after>package com.maxiee.heartbeat.ui;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.maxiee.heartbeat.R;
import com.maxiee.heartbeat.common.FileUtils;
import com.maxiee.heartbeat.common.TimeUtils;
import com.maxiee.heartbeat.common.tagview.Tag;
import com.maxiee.heartbeat.common.tagview.TagView;
import com.maxiee.heartbeat.database.utils.EventUtils;
import com.maxiee.heartbeat.database.utils.ImageUtils;
import com.maxiee.heartbeat.database.utils.LabelUtils;
import com.maxiee.heartbeat.database.utils.ThoughtUtils;
import com.maxiee.heartbeat.model.Event;
import com.maxiee.heartbeat.model.Image;
import com.maxiee.heartbeat.model.Label;
import com.maxiee.heartbeat.model.Thoughts;
import com.maxiee.heartbeat.ui.adapter.ThoughtTimeaxisAdapter;
import com.maxiee.heartbeat.ui.common.BaseActivity;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by maxiee on 15-6-13.
 */
public class EventDetailActivity extends BaseActivity {
    private final static String TAG = EventDetailActivity.class.getSimpleName();

    public static final String EXTRA_NAME = "id";
    private static final int ADD_IMAGE = 1127;
    private static final int LONG_IMAGE_IMAGE_MAX_HEIGHT = 300;

    private long mId;
    private Event mEvent;

    @Bind(R.id.tv_event)        TextView mTvEvent;
    @Bind(R.id.recyclerview)    RecyclerView mRecyclerView;
    @Bind(R.id.tagview)         TagView mTagView;
    @Bind(R.id.tv_time)         TextView mTvTime;
    @Bind(R.id.backdrop)        ImageView mImageBackDrop;
    @Bind(R.id.card_event)      View mCardEvent;
    @Bind(R.id.add_imgae)       TextView mAddImageText;
    @Bind(R.id.header)          View mHeaderView;

    private LinearLayoutManager mLayoutManager;
    private ThoughtTimeaxisAdapter mAdapter;

    private Image mImage;
    private Thoughts mThoughts;
    private String mSortingType;
    private boolean mHasImage = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_event_detail);
        ButterKnife.bind(this);

        Intent intent = getIntent();
        mId = intent.getLongExtra(EXTRA_NAME, -1);

        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        mSortingType = sp.getString("time_axis_sorting", "0");

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

        setTitle("");
        mLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(mLayoutManager);

        mEvent = EventUtils.getEvent(this, mId);

        mTagView.setOnTagClickListener(new TagView.OnTagClickListener() {
            @Override
            public void onTagClick(Tag tag, int position) {
                Intent i = new Intent();
                i.setAction(Intent.ACTION_MAIN);
                i.setClass(EventDetailActivity.this, LabelDetailActivity.class);
                i.putExtra("tag_text", tag.text);
                startActivity(i);
            }
        });

        mTvTime.setText(TimeUtils.parseTime(this, mEvent.getTimestamp()));

        mCardEvent.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Intent i = new Intent(EventDetailActivity.this, AddEventActivity.class);
                i.putExtra(AddEventActivity.ID_EVENT_MODIFY, mId);
                startActivity(i);
                return true;
            }
        });

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(EventDetailActivity.this, AddEditThoughtActivity.class);
                i.putExtra(AddEditThoughtActivity.MODE, AddEditThoughtActivity.MODE_NEW);
                i.putExtra(AddEditThoughtActivity.EVENT_KEY, mId);
                startActivity(i);
            }
        });

        mThoughts = ThoughtUtils.getThoughtsByEventId(this, mId);
        mAdapter = new ThoughtTimeaxisAdapter(mThoughts);
        mRecyclerView.setAdapter(mAdapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mEvent = EventUtils.getEvent(this, mId);
        mTvEvent.setText(mEvent.getEvent());
        mThoughts = ThoughtUtils.getThoughtsByEventId(this, mEvent.getId());
        mAdapter.setData(mThoughts);
        mAdapter.notifyDataSetChanged();
        initImage();
        updateTagView();
    }

    private void initImage() {
        mImage = ImageUtils.getImageByEventId(this, mEvent.getId());
        if (mImage == null) {
            mAddImageText.setVisibility(View.VISIBLE);
            mAddImageText.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (Build.VERSION.SDK_INT < 19) {
{'fraction_non_alphanumeric': 0.095464463840399, 'fraction_numerical': 0.003428927680798005, 'mean_word_length': 3.3165153044063236, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3750630', 'n_tokens_mistral': 3820, 'n_tokens_neox': 3683, 'n_words': 671}