Search in sources :

Example 1 with TokenStore

use of com.meisolsson.githubsdk.core.TokenStore in project PocketHub by pockethub.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    userLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false);
    if (sp.getBoolean(PREF_FIRST_USE, true)) {
        openWelcomeScreen();
    }
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (!userLearnedDrawer) {
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
                userLearnedDrawer = true;
                Log.d(TAG, "User learned drawer");
            }
        }
    };
    drawerLayout.setDrawerListener(actionBarDrawerToggle);
    navigationView = (NavigationView) findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(this);
    getSupportLoaderManager().initLoader(0, null, this);
    TokenStore tokenStore = TokenStore.getInstance(this);
    if (tokenStore.getToken() == null) {
        AccountManager manager = AccountManager.get(this);
        Account[] accounts = manager.getAccountsByType(getString(R.string.account_type));
        if (accounts.length > 0) {
            Account account = accounts[0];
            AccountsHelper.getUserToken(this, account);
            tokenStore.saveToken(AccountsHelper.getUserToken(this, account));
        }
    }
}
Also used : Account(android.accounts.Account) SharedPreferences(android.content.SharedPreferences) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) AccountManager(android.accounts.AccountManager) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) TokenStore(com.meisolsson.githubsdk.core.TokenStore)

Aggregations

Account (android.accounts.Account)1 AccountManager (android.accounts.AccountManager)1 SharedPreferences (android.content.SharedPreferences)1 NavigationView (android.support.design.widget.NavigationView)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 SearchView (android.support.v7.widget.SearchView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 TokenStore (com.meisolsson.githubsdk.core.TokenStore)1