package com.rollbar.example.android;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import com.rollbar.android.Rollbar;

public class MainActivity extends AppCompatActivity {

  private Rollbar rollbar;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    rollbar = Rollbar.init(this);

    final MainActivity self = this;
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
            .setAction("Action", new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                self.clickAction();
              }
            }).show();
      }
    });
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
      return true;
    }

    return super.onOptionsItemSelected(item);
  }

  private void clickAction() {
    rollbar.error("this should exist");
    rollbar.setPersonData("42", "andy", null);
    Log.d("yo", "hey");
    rollbar.log(new Error("this is an error"), "another thing to exist");
  }
}

@@ -457,36 +457,8 @@
  %7B%0A%0A
-  private Rollbar rollbar;%0A%0A
   @O
@@ -706,18 +706,8 @@
 %0A   
- rollbar =
  Rol
@@ -1954,24 +1954,176 @@
 kAction() %7B%0A
+    Rollbar rollbar = Rollbar.instance();%0A    if (rollbar == null) %7B%0A      Log.d(%22yo%22, %22Rollbar is null, initialize before using%22);%0A      return;%0A    %7D%0A
     rollbar.

use the instance getter rather than storing the result of init