// Path: app/src/main/java/party/minge/reddit/client/AuthenticationCallback.java
// public interface AuthenticationCallback {
//     void onSuccessfulAuthentication();
//     void onFailedAuthentication(Exception e);
// }
// 
// Path: app/src/main/java/party/minge/reddit/client/Manager.java
// @EBean(scope = EBean.Scope.Singleton)
// public class Manager {
//     @Bean(ResFactory.class)
//     protected UserAgentFactory userAgentFactory;
// 
//     @Bean(ResFactory.class)
//     protected CredentialFactory credentialFactory;
// 
//     @Bean(UserlessCredentialFactory.class)
//     protected CredentialFactory anonymousCredentialFactory;
// 
//     protected RedditClient redditClient;
// 
//     protected AuthenticationManager authenticationManager;
// 
//     protected AccountManager accountManager;
// 
//     @Bean(PreferenceTokenStore.class)
//     protected TokenStore tokenStore;
// 
//     @AfterInject
//     public void afterInject() {
//         this.redditClient = new RedditClient(this.userAgentFactory.getUserAgent());
//         this.authenticationManager = AuthenticationManager.get();
//         this.authenticationManager.init(this.redditClient, new RefreshTokenHandler(this.tokenStore, this.redditClient));
//         this.accountManager = new AccountManager(this.redditClient);
//     }
// 
//     /**
//      * Anonymously authenticates if required.
//      * If already authenticated, does not re-authenticate.
//      *
//      * @param authenticationCallback Methods to call on success or failure.
//      */
//     public void authenticateIfRequired(AuthenticationCallback authenticationCallback) {
//         AuthenticationState state = AuthenticationManager.get().checkAuthState();
// 
//         if (state == AuthenticationState.READY) {
//             authenticationCallback.onSuccessfulAuthentication();
//             return;
//         }
// 
//         if (state == AuthenticationState.NEED_REFRESH) {
//             try {
//                 this.authenticationManager.refreshAccessToken(this.getCredentials());
//                 authenticationCallback.onSuccessfulAuthentication();
//             } catch (Exception ex) {
//                 authenticationCallback.onFailedAuthentication(ex);
//             }
// 
//             return;
//         }
// 
//         try {
//             OAuthData authData = this.getClient().getOAuthHelper().easyAuth(this.getAnonymousCredentials());
//             this.getClient().authenticate(authData);
// 
//             authenticationCallback.onSuccessfulAuthentication();
//         } catch (Exception ex) {
//             authenticationCallback.onFailedAuthentication(ex);
//         }
//     }
// 
//     public RedditClient getClient() {
//         return this.redditClient;
//     }
// 
//     public AccountManager getAccountManager() {
//         return this.accountManager;
//     }
// 
//     public AuthenticationManager getAuthenticationManager() {
//         return this.authenticationManager;
//     }
// 
//     public Credentials getCredentials() {
//         return this.credentialFactory.getCredentials();
//     }
// 
//     public Credentials getAnonymousCredentials() {
//         return this.anonymousCredentialFactory.getCredentials();
//     }
// }
// 
// Path: app/src/main/java/party/minge/reddit/menu/SidebarMenuAdapter.java
// @EBean
// public class SidebarMenuAdapter extends BaseAdapter {
//     @Bean
//     protected SidebarMenuItemRepository repository;
// 
//     @RootContext
//     protected Context rootContext;
// 
//     @Override
//     public int getCount() {
//         return this.repository.getLength();
//     }
// 
//     @Override
//     public MenuItem getItem(int i) {
//         return this.repository.getMenuItems()[i];
//     }
// 
//     @Override
//     public long getItemId(int i) {
//         return this.repository.getMenuItems()[i].getId();
//     }
// 
//     @Override
//     public View getView(int i, View view, ViewGroup viewGroup) {
//         if (view == null) {
//             view = MenuItemView_.build(this.rootContext);
//         }
// 
//         ((MenuItemView)view).bind(this.getItem(i));
// 
//         return view;
//     }
// }


import android.app.Activity;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import net.dean.jraw.models.Submission;
import net.dean.jraw.paginators.SubredditPaginator;
import org.androidannotations.annotations.AfterInject;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import party.minge.reddit.client.AuthenticationCallback;
import party.minge.reddit.client.Manager;
import party.minge.reddit.menu.SidebarMenuAdapter;
import static android.view.View.GONE;
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                SubredditActivity.this.sidebarMenuAdapter.notifyDataSetChanged();
            }
        };

        this.layoutDrawer.setDrawerListener(this.drawerListener);

        this.grpSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                SubredditActivity.this.fetchPosts();
            }
        });
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (this.drawerListener.onOptionsItemSelected(item)) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @AfterViews
    @Background
    protected void authenticateIfRequired() {
// Path: app/src/main/java/party/minge/reddit/client/AuthenticationCallback.java
// public interface AuthenticationCallback {
//     void onSuccessfulAuthentication();
//     void onFailedAuthentication(Exception e);
// }
// 
// Path: app/src/main/java/party/minge/reddit/client/Manager.java
// @EBean(scope = EBean.Scope.Singleton)
// public class Manager {
//     @Bean(ResFactory.class)
//     protected UserAgentFactory userAgentFactory;
// 
//     @Bean(ResFactory.class)
//     protected CredentialFactory credentialFactory;
// 
//     @Bean(UserlessCredentialFactory.class)
//     protected CredentialFactory anonymousCredentialFactory;
// 
//     protected RedditClient redditClient;
// 
//     protected AuthenticationManager authenticationManager;
// 
//     protected AccountManager accountManager;
// 
//     @Bean(PreferenceTokenStore.class)
//     protected TokenStore tokenStore;
// 
//     @AfterInject
//     public void afterInject() {
//         this.redditClient = new RedditClient(this.userAgentFactory.getUserAgent());
//         this.authenticationManager = AuthenticationManager.get();
//         this.authenticationManager.init(this.redditClient, new RefreshTokenHandler(this.tokenStore, this.redditClient));
//         this.accountManager = new AccountManager(this.redditClient);
//     }
// 
//     /**
//      * Anonymously authenticates if required.
//      * If already authenticated, does not re-authenticate.
//      *
//      * @param authenticationCallback Methods to call on success or failure.
//      */
//     public void authenticateIfRequired(AuthenticationCallback authenticationCallback) {
//         AuthenticationState state = AuthenticationManager.get().checkAuthState();
// 
//         if (state == AuthenticationState.READY) {
//             authenticationCallback.onSuccessfulAuthentication();
//             return;
//         }
// 
//         if (state == AuthenticationState.NEED_REFRESH) {
//             try {
//                 this.authenticationManager.refreshAccessToken(this.getCredentials());
//                 authenticationCallback.onSuccessfulAuthentication();
//             } catch (Exception ex) {
//                 authenticationCallback.onFailedAuthentication(ex);
//             }
// 
//             return;
//         }
// 
//         try {
//             OAuthData authData = this.getClient().getOAuthHelper().easyAuth(this.getAnonymousCredentials());
//             this.getClient().authenticate(authData);
// 
//             authenticationCallback.onSuccessfulAuthentication();
//         } catch (Exception ex) {
//             authenticationCallback.onFailedAuthentication(ex);
//         }
//     }
// 
//     public RedditClient getClient() {
//         return this.redditClient;
//     }
// 
//     public AccountManager getAccountManager() {
//         return this.accountManager;
//     }
// 
//     public AuthenticationManager getAuthenticationManager() {
//         return this.authenticationManager;
//     }
// 
//     public Credentials getCredentials() {
//         return this.credentialFactory.getCredentials();
//     }
// 
//     public Credentials getAnonymousCredentials() {
//         return this.anonymousCredentialFactory.getCredentials();
//     }
// }
// 
// Path: app/src/main/java/party/minge/reddit/menu/SidebarMenuAdapter.java
// @EBean
// public class SidebarMenuAdapter extends BaseAdapter {
//     @Bean
//     protected SidebarMenuItemRepository repository;
// 
//     @RootContext
//     protected Context rootContext;
// 
//     @Override
//     public int getCount() {
//         return this.repository.getLength();
//     }
// 
//     @Override
//     public MenuItem getItem(int i) {
//         return this.repository.getMenuItems()[i];
//     }
// 
//     @Override
//     public long getItemId(int i) {
//         return this.repository.getMenuItems()[i].getId();
//     }
// 
//     @Override
//     public View getView(int i, View view, ViewGroup viewGroup) {
//         if (view == null) {
//             view = MenuItemView_.build(this.rootContext);
//         }
// 
//         ((MenuItemView)view).bind(this.getItem(i));
// 
//         return view;
//     }
// }


// Path: app/src/main/java/party/minge/reddit/SubredditActivity.java
import android.app.Activity;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import net.dean.jraw.models.Submission;
import net.dean.jraw.paginators.SubredditPaginator;
import org.androidannotations.annotations.AfterInject;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import party.minge.reddit.client.AuthenticationCallback;
import party.minge.reddit.client.Manager;
import party.minge.reddit.menu.SidebarMenuAdapter;
import static android.view.View.GONE;

            }

            @Override
            public void onDrawerClosed(View drawerView) {
                SubredditActivity.this.sidebarMenuAdapter.notifyDataSetChanged();
            }
        };

        this.layoutDrawer.setDrawerListener(this.drawerListener);

        this.grpSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                SubredditActivity.this.fetchPosts();
            }
        });
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (this.drawerListener.onOptionsItemSelected(item)) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @AfterViews
    @Background
    protected void authenticateIfRequired() {
        this.manager.authenticateIfRequired(new AuthenticationCallback() {