Search in sources :

Example 1 with RoboAsyncTask

use of roboguice.util.RoboAsyncTask in project hubroid by EddieRingle.

the class AccountSelectActivity method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle, R.layout.account_select_activity);
    mProgress = (ProgressBar) findViewById(R.id.progress);
    mContent = (RelativeLayout) findViewById(R.id.content);
    ListView listView = (ListView) findViewById(R.id.lv_userselect_users);
    TextView msgView = (TextView) findViewById(R.id.tv_userselect_msg);
    Button noChoiceBtn = (Button) findViewById(R.id.btn_userselect_nochoice);
    mAccountManager = AccountManager.get(getContext());
    if (mCurrentAccount == null) {
        noChoiceBtn.setText(R.string.userselect_justbrowsing);
    }
    final Account[] accounts = mAccountManager.getAccountsByType(AuthConstants.GITHUB_ACCOUNT_TYPE);
    ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(getContext(), R.layout.account_select_listitem);
    for (Account a : accounts) {
        listAdapter.add(a.name);
    }
    noChoiceBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mPrefsEditor.remove(HubroidConstants.PREF_CURRENT_USER_LOGIN);
            mPrefsEditor.remove(HubroidConstants.PREF_CURRENT_USER);
            mPrefsEditor.remove(HubroidConstants.PREF_CURRENT_CONTEXT_LOGIN);
            mPrefsEditor.commit();
            final Intent intent = new Intent(AccountSelectActivity.this, HomeActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            finish();
        }
    });
    if (!listAdapter.isEmpty()) {
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
                mContent.setVisibility(GONE);
                mProgress.setVisibility(VISIBLE);
                new RoboAsyncTask<Boolean>(AccountSelectActivity.this) {

                    public Boolean call() throws Exception {
                        mCurrentAccount = accounts[position];
                        mGitHubClient = null;
                        UserService service = new UserService(getGHClient());
                        User user = service.getUser();
                        if (user != null) {
                            mPrefsEditor.putString(HubroidConstants.PREF_CURRENT_USER_LOGIN, user.getLogin());
                            mPrefsEditor.putString(HubroidConstants.PREF_CURRENT_USER, GsonUtils.toJson(user));
                            mPrefsEditor.commit();
                            return true;
                        }
                        return false;
                    }

                    @Override
                    public void onSuccess(Boolean authSuccess) {
                        final Intent intent = new Intent(AccountSelectActivity.this, HomeActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
                        finish();
                    }

                    @Override
                    protected void onFinally() throws RuntimeException {
                        mProgress.setVisibility(GONE);
                        mContent.setVisibility(VISIBLE);
                        super.onFinally();
                    }
                }.execute();
            }
        });
        listView.setAdapter(listAdapter);
    }
}
Also used : Account(android.accounts.Account) User(org.eclipse.egit.github.core.User) UserService(org.eclipse.egit.github.core.service.UserService) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ListView(android.widget.ListView) Button(android.widget.Button) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) RoboAsyncTask(roboguice.util.RoboAsyncTask) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

Account (android.accounts.Account)1 Intent (android.content.Intent)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 User (org.eclipse.egit.github.core.User)1 UserService (org.eclipse.egit.github.core.service.UserService)1 RoboAsyncTask (roboguice.util.RoboAsyncTask)1