use of org.eclipse.egit.github.core.User in project hubroid by EddieRingle.
the class HomeActivity method onCreate.
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle, NO_LAYOUT);
/* BugSense setup */
BugSenseHandler.setup(this, "40e35a51");
mFirstRun = mPrefs.getBoolean(HubroidConstants.PREF_FIRST_RUN, true);
if (mFirstRun) {
/*
* If this is the first time the user is using Hubroid, take them directly to the
* Account Selection screen so that they can log in if they so choose.
*/
mPrefsEditor.putBoolean(HubroidConstants.PREF_FIRST_RUN, false);
mPrefsEditor.commit();
/* Show the Account Selection screen first, then start the show */
startActivityForResult(new Intent(this, AccountSelectActivity.class), 0);
finish();
} else {
/*
* Otherwise, make sure whatever existing account Hubroid is set to use hasn't been
* deleted by the user in the system settings prior to returning to Hubroid.
*/
final String currentUserLogin = mPrefs.getString(HubroidConstants.PREF_CURRENT_USER_LOGIN, null);
final String currentUserJson = mPrefs.getString(HubroidConstants.PREF_CURRENT_USER, null);
if (currentUserLogin != null) {
if (currentUserJson == null) {
startActivityForResult(new Intent(this, AccountSelectActivity.class), 0);
finish();
} else {
mCurrentAccount = new Account(currentUserLogin, GITHUB_ACCOUNT_TYPE);
}
}
}
final Intent startIntent = new Intent(this, EventsActivity.class);
startIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startIntent.putExtra(ARG_FROM_DASHBOARD, true);
if (getCurrentContextLogin() != null && !getCurrentContextLogin().equals("")) {
startIntent.putExtra(ARG_TARGET_USER, GsonUtils.toJson(new User().setLogin(getCurrentContextLogin())));
}
if (getIntent() != null && getIntent().getBooleanExtra(EXTRA_SHOWING_DASH, false)) {
startIntent.putExtra(EXTRA_SHOWING_DASH, true);
}
startActivity(startIntent);
finish();
}
use of org.eclipse.egit.github.core.User in project hubroid by EddieRingle.
the class RequestCache method getUser.
public static User getUser(final BaseActivity context, final String login, final boolean forceUpdate) {
User user = null;
boolean shouldRefresh = false;
final File dir = new File(context.getCacheDir(), ROOT_DIR + USER_DIR);
if (!dir.exists() || !dir.isDirectory()) {
dir.mkdirs();
}
final File f = new File(dir, login + ".json");
if (!forceUpdate && f.exists()) {
/* Check if the cached JSON is really old (>1 day) */
final Date d = new Date();
final long elderCheck = d.getTime() - (KEEP_LENGTH);
if (f.lastModified() < elderCheck) {
shouldRefresh = true;
} else {
try {
final FileInputStream in = new FileInputStream(f);
user = GsonUtils.fromJson(new BufferedReader(new InputStreamReader(in)), User.class);
in.close();
return user;
} catch (Exception e) {
shouldRefresh = true;
}
}
} else {
shouldRefresh = true;
}
if (shouldRefresh || forceUpdate) {
try {
final UserService us = new UserService(context.getGHClient());
user = us.getUser(login);
if (user != null) {
putUser(context, user);
}
} catch (Exception e) {
user = null;
e.printStackTrace();
}
}
return user;
}
use of org.eclipse.egit.github.core.User in project hubroid by EddieRingle.
the class ContextListAdapter method doGetView.
public View doGetView(int position, View convertView, ViewGroup parent, boolean dropdown) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.user_list_item, null);
holder = new ViewHolder();
holder.gravatar = (ImageView) convertView.findViewById(R.id.iv_user_gravatar);
holder.login = (TextView) convertView.findViewById(R.id.tv_user_login);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final User user = getItem(position);
final String login = user.getLogin();
final String type = user.getType();
final AQuery aq = new AQuery(convertView);
aq.id(holder.gravatar).image(user.getAvatarUrl(), true, true, 200, R.drawable.gravatar, null, AQuery.FADE_IN_NETWORK, 1.0f);
holder.login.setText(login);
holder.login.setTextColor(Color.parseColor("#2c2c2c"));
return convertView;
}
Aggregations