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

    setContentView(R.layout.activity_commit_file_view);

    setSupportActionBar((android.support.v7.widget.Toolbar) findViewById(R.id.toolbar));

    repo = getIntent().getParcelableExtra(EXTRA_REPOSITORY);
    commit = getStringExtra(EXTRA_HEAD);
    sha = getStringExtra(EXTRA_BASE);
    path = getStringExtra(EXTRA_PATH);

    loadingBar = finder.find(R.id.pb_loading);
    codeView = finder.find(R.id.wv_code);

    file = CommitUtils.getName(path);
    isMarkdownFile = MarkdownUtils.isMarkdown(file);

    editor = new SourceEditor(codeView);
    editor.setWrap(PreferenceUtils.getCodePreferences(this).getBoolean(WRAP, false));

    ActionBar actionBar = getSupportActionBar();
    int lastSlash = path.lastIndexOf('/');
    if (lastSlash != -1) actionBar.setTitle(path.substring(lastSlash + 1));
    else actionBar.setTitle(path);
    actionBar.setSubtitle(getString(R.string.commit_prefix) + CommitUtils.abbreviate(commit));
    avatars.bind(actionBar, repo.owner);

    loadContent();
  }
  @Override
  public void onLoadFinished(Loader<CharSequence> loader, CharSequence rendered) {
    if (rendered == null) ToastUtils.show(this, R.string.error_rendering_markdown);

    ViewUtils.setGone(loadingBar, true);
    ViewUtils.setGone(codeView, false);

    if (!TextUtils.isEmpty(rendered)) {
      renderedMarkdown = rendered.toString();
      if (markdownItem != null) markdownItem.setEnabled(true);
      editor.setMarkdown(true).setSource(file, renderedMarkdown, false);
    }
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.m_wrap:
        if (editor.getWrap()) item.setTitle(R.string.enable_wrapping);
        else item.setTitle(R.string.disable_wrapping);
        editor.toggleWrap();
        PreferenceUtils.save(
            PreferenceUtils.getCodePreferences(this).edit().putBoolean(WRAP, editor.getWrap()));
        return true;

      case R.id.m_share:
        shareFile();
        return true;

      case R.id.m_render_markdown:
        if (editor.isMarkdown()) {
          item.setTitle(R.string.render_markdown);
          editor.toggleMarkdown();
          editor.setSource(file, blob);
        } else {
          item.setTitle(R.string.show_raw_markdown);
          editor.toggleMarkdown();
          if (renderedMarkdown != null) editor.setSource(file, renderedMarkdown, false);
          else loadMarkdown();
        }
        PreferenceUtils.save(
            PreferenceUtils.getCodePreferences(this)
                .edit()
                .putBoolean(RENDER_MARKDOWN, editor.isMarkdown()));
        return true;

      default:
        return super.onOptionsItemSelected(item);
    }
  }