@Override public void onNextClicked() { // TODO: login user as anonymous Account account = mCurrentUser.getAccount(); if (account == null) { // if there is no previously existing user mCurrentUser.createAnonymousUser( new ListUser.AnonymousUserCallback() { @Override public void onSuccess() { Log.v(TAG, "> createAnonymousUser > onSuccess"); Account account = mCurrentUser.getAccount(); String userID = am.getUserData(account, AccountGeneral.USER_ID); Log.v(TAG, "USER ID: " + userID); Intent intent = new Intent(StartActivity.this, CategoryListActivity.class); startActivity(intent); } @Override public void onAccountFail(Boolean bol) { Log.v(TAG, "> createAnonymousUser > onAccountFail: " + bol.toString()); // TODO: if account fails to be created in } @Override public void onFail(VolleyError error) { Log.v(TAG, "> createAnonymousUser > onFail: " + error.getMessage()); if (error instanceof NoConnectionError || error instanceof NetworkError) { // TODO: need an working internet connection } else if (error instanceof ServerError) { // TODO: we’re experiencing some problems dialog } } }); } else { // TODO: what happens if you already have an account on the phone: account picker? Intent intent = new Intent(StartActivity.this, CategoryListActivity.class); startActivity(intent); } } // onNextClicked
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_start); mContext = this; am = AccountManager.get(getBaseContext()); mCurrentUser = new ListUser(StartActivity.this); mMessageHelper = new MessageHelper(mContext); mSharedPref = new SharedPreferencesMethods(mContext); if (!mCurrentUser.isAnonymousUser() || mSharedPref.getAnalyticsViewed() && mCurrentUser.isAnonymousUser()) { // Redirect to MainActivity Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } // Google Analytics Tracker ((ListApplication) getApplication()).getTracker(ListApplication.TrackerName.GLOBAL_TRACKER); // UI Elements mFrameLayout = (FrameLayout) findViewById(R.id.fragment_container); mStartButton = (Button) findViewById(R.id.startButton); mAccountButton = (Button) findViewById(R.id.accountButton); mTermsLink = (TextView) findViewById(R.id.cc_logo_label); // “I’m new to the list” mStartButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { getSupportFragmentManager() .beginTransaction() .add(R.id.fragment_container, explainerFragment) .commit(); mFrameLayout.setClickable(true); } }); // StartButton ClickListener // “I already have an account” mAccountButton.setOnClickListener( new View.OnClickListener() { // If you have accounts > show picker; if not, show login @Override public void onClick(View v) { mCurrentUser.getAvailableFullAccounts( new ListUser.AvailableAccountCallback() { @Override public void onResult(Account[] availableAccounts) { if (availableAccounts.length > 1) { mCurrentUser.showAccountPicker( availableAccounts, new ListUser.AuthCallback() { @Override public void onAuthed(String authtoken) { Log.d(TAG, "I have an account > Got an authtoken"); // TODO: is this actually needed? Intent intent = new Intent(StartActivity.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } }); } else { mCurrentUser.addNewFullAccount( AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, new ListUser.AuthCallback() { @Override public void onAuthed(String authtoken) { Log.v(TAG, "> addNewFullAccount token: " + authtoken); Intent intent = new Intent(StartActivity.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } }); } } // onResult }); // getAvailableFullAccounts } }); // accountButton // Enable links if (mTermsLink != null) { mTermsLink.setMovementMethod(LinkMovementMethod.getInstance()); } } // OnCreate