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);
}
}
Aggregations