Search in sources :

Example 11 with User

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();
}
Also used : Account(android.accounts.Account) User(org.eclipse.egit.github.core.User) Intent(android.content.Intent)

Example 12 with User

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;
}
Also used : User(org.eclipse.egit.github.core.User) InputStreamReader(java.io.InputStreamReader) UserService(org.eclipse.egit.github.core.service.UserService) BufferedReader(java.io.BufferedReader) File(java.io.File) Date(java.util.Date) FileInputStream(java.io.FileInputStream)

Example 13 with 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;
}
Also used : AQuery(com.androidquery.AQuery) User(org.eclipse.egit.github.core.User)

Aggregations

User (org.eclipse.egit.github.core.User)13 Intent (android.content.Intent)5 UserService (org.eclipse.egit.github.core.service.UserService)4 Account (android.accounts.Account)3 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GitHubClient (org.eclipse.egit.github.core.client.GitHubClient)2 AccountsException (android.accounts.AccountsException)1 IntentFilter (android.content.IntentFilter)1 Bundle (android.os.Bundle)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 AQuery (com.androidquery.AQuery)1 DrawerGarment (com.github.eddieringle.android.libs.undergarment.widgets.DrawerGarment)1 TypeToken (com.google.gson.reflect.TypeToken)1