@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 boolean onCreateOptionsMenu(final Menu optionsMenu) {
    getMenuInflater().inflate(R.menu.activity_file_view, optionsMenu);

    MenuItem wrapItem = optionsMenu.findItem(R.id.m_wrap);
    if (PreferenceUtils.getCodePreferences(this).getBoolean(WRAP, false))
      wrapItem.setTitle(R.string.disable_wrapping);
    else wrapItem.setTitle(R.string.enable_wrapping);

    markdownItem = optionsMenu.findItem(R.id.m_render_markdown);
    if (isMarkdownFile) {
      markdownItem.setEnabled(blob != null);
      markdownItem.setVisible(true);
      if (PreferenceUtils.getCodePreferences(this).getBoolean(RENDER_MARKDOWN, true))
        markdownItem.setTitle(R.string.show_raw_markdown);
      else markdownItem.setTitle(R.string.render_markdown);
    }

    return true;
  }
  @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);
    }
  }