package com.betable;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.betable.fragment.BetableLogin;
import com.betable.fragment.BetableLogin.BetableLoginListener;

public class BetableActivity extends FragmentActivity implements
        BetableLoginListener {

    Button loginButton;
    BetableLogin loginView;

    private final String clientId = "FNTRHDBp7OGwfFVJPo9OBni5p65A0cwo";
    private final String clientSecret = "y75FbTEoLBTopxlchKM2luyzaIIj5Dkf";
    private final String redirectUri = "https://caseycrites.com/betable/whack-a-malone";
    private String accessToken;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        this.loginButton = (Button) this
                .findViewById(R.id.betable_login_button);

        this.loginButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                BetableActivity.this.loginView.show(
                        BetableActivity.this.getSupportFragmentManager(),
                        "betable-login");
            }

        });

        this.loginView = new BetableLogin(this.clientId, this.clientSecret,
                this.redirectUri);
    }

    @Override
    public void onSuccessfulLogin(String accessToken) {
        Toast.makeText(this,
                "Hooray, we have an access token! It's " + accessToken,
                Toast.LENGTH_LONG).show();
        this.accessToken = accessToken;
        this.loginView.dismiss();
    }

    @Override
    public void onFailedLogin(String reason) {
        Toast.makeText(this, "Bummer, something went wrong. " + reason,
                Toast.LENGTH_LONG).show();
        if (this.loginView.isVisible()) {
            this.loginView.dismiss();
        }
    }
}
@@ -429,25 +429,22 @@
    B
-utton loginButton
+etable betable
 ;%0A  
@@ -468,16 +468,40 @@
 ginView;
+%0A    Button loginButton;
 %0A%0A    pr
@@ -535,40 +535,40 @@
  = %22
-FNTRHDBp7OGwfFVJPo9OBni5p65A0cwo
+j4lAcOwsZ8Wdh6DObWxaYzg2sHfppF6t
 %22;%0A 
@@ -611,40 +611,40 @@
  = %22
-y75FbTEoLBTopxlchKM2luyzaIIj5Dkf
+C62RUr2nTjAjdlCxowxCAr8VzMqdWSlp
 %22;%0A 
@@ -690,50 +690,34 @@
 http
-s
 ://
-caseycrites.com/betable/whack-a-malone
+127.0.0.1:8000/callback
 %22;%0A 
@@ -868,16 +868,21 @@
         
+this.
 setConte
@@ -1335,32 +1335,284 @@
    %7D);%0A%0A        
+if (savedInstanceState != null) %7B%0A            this.loginView = (BetableLogin) this.getSupportFragmentManager()%0A                    .getFragment(savedInstanceState,%0A                            BetableLogin.class.getName());%0A        %7D else %7B%0A            
 this.loginView =
@@ -1615,12 +1615,8 @@
 ew =
- new
  Bet
@@ -1624,16 +1624,28 @@
 bleLogin
+.newInstance
 (this.cl
@@ -1655,27 +1655,66 @@
 tId,
- this.clientSecret,
+%0A                    this.clientSecret, this.redirectUri);
 %0A   
@@ -1710,32 +1710,35 @@
 ctUri);%0A        
+%7D%0A%0A
         this.red
@@ -1730,35 +1730,330 @@
        this.
-redirectUri
+loginView.setListener(this);%0A    %7D%0A%0A    @Override%0A    protected void onSaveInstanceState(Bundle savedInstanceState) %7B%0A        super.onSaveInstanceState(savedInstanceState);%0A        this.getSupportFragmentManager().putFragment(savedInstanceState,%0A                BetableLogin.class.getName(), this.loginView
 );%0A    %7D%0A%0A  
@@ -2304,16 +2304,70 @@
 sToken;%0A
+        this.betable = new Betable(this.accessToken);%0A
         

Update to add handle screen orientation changes as well as adding itself to BetableLogin as a listener instead of the other way around, since the original way will cause a leak.