public class GitHubApiService extends IntentService {

    public static final String ACTION_GET_URI = "action_get_uri";

    public static final String ACTION_EVENTS_LIST_USER_PUBLIC = "action_events_list_user_public";

    public static final String ACTION_EVENTS_LIST_USER_RECEIVED = "action_events_list_user_received";

    public static final String ACTION_EVENTS_LIST_TIMELINE = "action_events_list_timeline";

    public static final String ACTION_ISSUES_LIST_SELF = "action_issues_list_self";

    public static final String ACTION_ORGS_LIST_MEMBERS = "action_orgs_list_members";

    public static final String ACTION_ORGS_SELF_MEMBERSHIPS = "action_orgs_self_memberships";

    public static final String ACTION_ORGS_USER_MEMBERSHIPS = "action_orgs_user_memberships";

    public static final String ACTION_REPOS_GET_REPO = "action_repos_get_repo";

    public static final String ACTION_REPOS_LIST_ORG_OWNED = "action_repos_list_org_owned";

    public static final String ACTION_REPOS_LIST_SELF_OWNED = "action_repos_list_self_owned";

    public static final String ACTION_REPOS_LIST_USER_OWNED = "action_repos_list_user_owned";

    public static final String ACTION_REPOS_LIST_USER_WATCHED = "action_repos_list_user_watched";

    public static final String ACTION_USERS_GET_USER = "action_users_get_user";

    public static final String ACTION_USERS_LIST_FOLLOWERS = "action_users_list_followers";

    public static final String ACTION_USERS_LIST_FOLLOWING = "action_users_list_following";

    public static final String ARG_ACCOUNT = "arg_account";

    public static final String ARG_ANONYMOUS = "arg_anonymous";

    public static final String ARG_BASIC_USERNAME = "arg_basic_username";

    public static final String ARG_BASIC_PASSWORD = "arg_basic_password";

    public static final String ARG_FORCE_REFRESH = "arg_force_refresh";

    public static final String ARG_OAUTH_TOKEN = "arg_oauth_token";

    public static final String ARG_START_PAGE = "arg_start_page";

    public static final String EXTRA_ERROR = "extra_error";

    public static final String EXTRA_HAS_NEXT = "extra_has_next";

    public static final String EXTRA_NEXT_PAGE = "extra_next_page";

    public static final String EXTRA_RESULT_JSON = "extra_result_json";

    public static final String PARAM_DIRECTION = "param_direction";

    public static final String PARAM_FILTER = "param_filter";

    public static final String PARAM_LABELS = "param_labels";

    public static final String PARAM_LOGIN = "param_login";

    public static final String PARAM_REPO_OWNER = "param_repo_owner";

    public static final String PARAM_REPO_NAME = "param_repo_name";

    public static final String PARAM_SINCE = "param_since";

    public static final String PARAM_SORT = "param_sort";

    public static final String PARAM_STATE = "param_state";

    public static final String USER_AGENT = "Hubroid/GitHubJava";

    private static String sApiHostname = HOST_API;

    private static int sApiPort = -1;

    private static String sApiScheme = PROTOCOL_HTTPS;

    private GitHubClient mGitHubClient;

    /**
     * Sets the Api hostname to connect to.
     *
     * Default is {@link IGitHubConstants#HOST_API}.
     */
    public static void setApiHostname(final String hostname) {
        sApiHostname = hostname;
    }

    /**
     * Sets the port to connect to the host with. Default is -1.
     */
    public static void setApiPort(final int port) {
        sApiPort = port;
    }

    /**
     * Sets the scheme to connect to the host with.
     *
     * Default is {@link IGitHubConstants#PROTOCOL_HTTPS}.
     */
    public static void setApiScheme(final String scheme) {
        sApiScheme = scheme;
    }

    public GitHubApiService() {
        super("GitHubApiService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        if (intent == null) {
            return;
        }

        mGitHubClient = new GitHubClient(sApiHostname, sApiPort, sApiScheme);
        mGitHubClient.setUserAgent(USER_AGENT);

        if (!intent.getBooleanExtra(ARG_ANONYMOUS, false)) {
            if (intent.hasExtra(ARG_OAUTH_TOKEN)) {
                mGitHubClient.setOAuth2Token(intent.getStringExtra(ARG_OAUTH_TOKEN));
            } else if (intent.hasExtra(ARG_BASIC_USERNAME) && intent.hasExtra(ARG_BASIC_PASSWORD)) {
                mGitHubClient.setCredentials(intent.getStringExtra(ARG_BASIC_USERNAME),
                        intent.getStringExtra(ARG_BASIC_PASSWORD));
            } else if (intent.hasExtra(ARG_ACCOUNT) &&
                    intent.getParcelableExtra(ARG_ACCOUNT) != null) {
                final Account account = intent.getParcelableExtra(ARG_ACCOUNT);
                try {
                    final String oauthToken =
                            new OAuthUserProvider().getOAuthResponse(this, account).access_token;
                    if (oauthToken != null) {
                        mGitHubClient.setOAuth2Token(oauthToken);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (AccountsException e) {
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                }
            }
        }

        if (intent.getAction().equals(ACTION_GET_URI)) {
            final GitHubRequest request = new GitHubRequest();
            request.setUri(intent.getData().toString());

            GitHubResponse response;
            try {
                response = mGitHubClient.get(request);
            } catch (IOException e) {
                response = null;
                e.printStackTrace();
            }

            final Intent resultIntent = new Intent(ACTION_GET_URI, intent.getData());
            if (response != null) {
                resultIntent.putExtra(EXTRA_HAS_NEXT, response.getNext() != null);
                resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(response.getBody()));
            } else {
                resultIntent.putExtra(EXTRA_ERROR, true);
            }
            sendBroadcast(resultIntent);
        } else if (intent.getAction().equals(ACTION_EVENTS_LIST_USER_PUBLIC)) {
            final EventService es = new EventService(mGitHubClient);
            ArrayList<Event> result = null;
            PageIterator<Event> iterator = null;
            final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);

            if (intent.hasExtra(PARAM_LOGIN)) {
                iterator = es.pageUserEvents(intent.getStringExtra(PARAM_LOGIN), true, startPage,
                        REQUEST_PAGE_SIZE);
            }

            if (iterator != null && iterator.hasNext()) {
                result = new ArrayList<Event>();
                result.addAll(iterator.next());
            }

            final Intent resultIntent = new Intent(ACTION_EVENTS_LIST_USER_PUBLIC);
            if (result != null) {
                resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
                resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
                resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
            } else {
                resultIntent.putExtra(EXTRA_ERROR, true);
            }
            sendBroadcast(resultIntent);
        } else if (intent.getAction().equals(ACTION_EVENTS_LIST_USER_RECEIVED)) {
            final EventService es = new EventService(mGitHubClient);
            ArrayList<Event> result = null;
            PageIterator<Event> iterator = null;
            final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);

            if (intent.hasExtra(PARAM_LOGIN)) {
                iterator = es.pageUserReceivedEvents(intent.getStringExtra(PARAM_LOGIN), false,
                        startPage, REQUEST_PAGE_SIZE);
            }

            if (iterator != null && iterator.hasNext()) {
                result = new ArrayList<Event>();
                result.addAll(iterator.next());
            }

            final Intent resultIntent = new Intent(ACTION_EVENTS_LIST_USER_RECEIVED);
            if (result != null) {
                resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
                resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
                resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
            } else {
                resultIntent.putExtra(EXTRA_ERROR, true);
            }
            sendBroadcast(resultIntent);
        } else if (intent.getAction().equals(ACTION_EVENTS_LIST_TIMELINE)) {
            final EventService es = new EventService(mGitHubClient);
            ArrayList<Event> result = null;
            PageIterator<Event> iterator;
            final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);

            iterator = es.pagePublicEvents(startPage, REQUEST_PAGE_SIZE);

            if (iterator != null && iterator.hasNext()) {
                result = new ArrayList<Event>();
                result.addAll(iterator.next());
            }

            final Intent resultIntent = new Intent(ACTION_EVENTS_LIST_TIMELINE);
            if (result != null) {
                resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
                resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
                resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
            } else {
                resultIntent.putExtra(EXTRA_ERROR, true);
            }
            sendBroadcast(resultIntent);
        } else if (intent.getAction().equals(ACTION_ISSUES_LIST_SELF)) {
            final IssueService is = new IssueService(mGitHubClient);
            final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
            ArrayList<RepositoryIssue> result = null;
            PageIterator<RepositoryIssue> iterator;
            HashMap<String, String> params = new HashMap<String, String>();

            if (intent.hasExtra(PARAM_FILTER)) {
                params.put("filter", intent.getStringExtra(PARAM_FILTER));
            }
            if (intent.hasExtra(PARAM_STATE)) {
                params.put("state", intent.getStringExtra(PARAM_STATE));
            }
            if (intent.hasExtra(PARAM_LABELS)) {
                params.put("labels", intent.getStringExtra(PARAM_LABELS));
            }
            if (intent.hasExtra(PARAM_SORT)) {
                params.put("sort", intent.getStringExtra(PARAM_SORT));
            }
            if (intent.hasExtra(PARAM_DIRECTION)) {
                params.put("direction", intent.getStringExtra(PARAM_DIRECTION));
            }
            if (intent.hasExtra(PARAM_SINCE)) {
                params.put("since", intent.getStringExtra(PARAM_SINCE));
            }

            iterator = is.pageIssues(params, startPage, REQUEST_PAGE_SIZE);

            if (iterator != null && iterator.hasNext()) {
                result = new ArrayList<RepositoryIssue>();
                result.addAll(iterator.next());
            }

            final Intent resultIntent = new Intent(ACTION_ISSUES_LIST_SELF);
            if (result != null) {
                resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
                resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
                resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
            } else {
                resultIntent.putExtra(EXTRA_ERROR, true);
            }
            sendBroadcast(resultIntent);
        } else if (intent.getAction().equals(ACTION_ORGS_SELF_MEMBERSHIPS)) {
            final OrganizationService os = new OrganizationService(mGitHubClient);
            List<User> result;
            try {
                result = os.getOrganizations();
            } catch (IOException e) {
                result = null;
                e.printStackTrace();
            }

            final Intent resultIntent = new Intent(ACTION_ORGS_SELF_MEMBERSHIPS);
            if (result != null) {
                resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
            } else {
                resultIntent.putExtra(EXTRA_ERROR, true);
            }
            sendBroadcast(resultIntent);
        } else if (intent.getAction().equals(ACTION_REPOS_GET_REPO)) {
            final RepositoryService rs = new RepositoryService(mGitHubClient);
            Repository result;
            try {
                result = rs.getRepository(intent.getStringExtra(PARAM_REPO_OWNER),
                        intent.getStringExtra(PARAM_REPO_NAME));
            } catch (IOException e) {
                result = null;
                e.printStackTrace();
            }

            final Intent resultIntent = new Intent(ACTION_REPOS_GET_REPO);
            if (result != null) {
                resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
            } else {
                resultIntent.putExtra(EXTRA_ERROR, true);
            }
            sendBroadcast(resultIntent);
        } else if (intent.getAction().equals(ACTION_REPOS_LIST_ORG_OWNED)) {
            final RepositoryService rs = new RepositoryService(mGitHubClient);
            ArrayList<Repository> result = null;
            PageIterator<Repository> iterator;
            final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);

            iterator = rs.pageOrgRepositories(intent.getStringExtra(PARAM_LOGIN),
                    startPage, REQUEST_PAGE_SIZE);

            if (iterator != null && iterator.hasNext()) {
                result = new ArrayList<Repository>();
                result.addAll(iterator.next());
            }

            final Intent resultIntent = new Intent(ACTION_REPOS_LIST_ORG_OWNED);
            if (result != null) {
                resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
                resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
                resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
            } else {
                resultIntent.putExtra(EXTRA_ERROR, true);
            }
            sendBroadcast(resultIntent);
        } else if (intent.getAction().equals(ACTION_REPOS_LIST_SELF_OWNED)) {
            final RepositoryService rs = new RepositoryService(mGitHubClient);
            ArrayList<Repository> result = null;
            PageIterator<Repository> iterator;
            final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);

            Map<String, String> filter = new HashMap<String, String>();
            filter.put("type", "owner");
            filter.put("sort", "pushed");

            iterator = rs.pageRepositories(filter, startPage, REQUEST_PAGE_SIZE);

            if (iterator != null && iterator.hasNext()) {
                result = new ArrayList<Repository>();
                result.addAll(iterator.next());
            }

            final Intent resultIntent = new Intent(ACTION_REPOS_LIST_SELF_OWNED);
            if (result != null) {
                resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
                resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
                resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
            } else {
                resultIntent.putExtra(EXTRA_ERROR, true);
            }
            sendBroadcast(resultIntent);
        } else if (intent.getAction().equals(ACTION_REPOS_LIST_USER_OWNED)) {
            final RepositoryService rs = new RepositoryService(mGitHubClient);
            ArrayList<Repository> result = null;
            PageIterator<Repository> iterator;
            final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);

            iterator = rs.pageRepositories(intent.getStringExtra(PARAM_LOGIN),
                    startPage, REQUEST_PAGE_SIZE);

            if (iterator != null && iterator.hasNext()) {
                result = new ArrayList<Repository>();
                result.addAll(iterator.next());
            }

            final Intent resultIntent = new Intent(ACTION_REPOS_LIST_USER_OWNED);
            if (result != null) {
                resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
                resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
                resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
            } else {
                resultIntent.putExtra(EXTRA_ERROR, true);
            }
            sendBroadcast(resultIntent);
        } else if (intent.getAction().equals(ACTION_REPOS_LIST_USER_WATCHED)) {
            final WatcherService ws = new WatcherService(mGitHubClient);
            ArrayList<Repository> result = null;
            PageIterator<Repository> iterator;
            final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);

            try {
                iterator = ws.pageWatched(intent.getStringExtra(PARAM_LOGIN),
                        startPage, REQUEST_PAGE_SIZE);
            } catch (IOException e) {
                iterator = null;
            }

            if (iterator != null && iterator.hasNext()) {
                result = new ArrayList<Repository>();
                result.addAll(iterator.next());
            }

            final Intent resultIntent = new Intent(ACTION_REPOS_LIST_USER_WATCHED);
            if (result != null) {
                resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
                resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
                resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
            } else {
                resultIntent.putExtra(EXTRA_ERROR, true);
            }
            sendBroadcast(resultIntent);
        } else if (intent.getAction().equals(ACTION_USERS_GET_USER)) {
            final UserService us = new UserService(mGitHubClient);
            User result;
            try {
                result = us.getUser(intent.getStringExtra(PARAM_LOGIN));
            } catch (IOException e) {
                result = null;
                e.printStackTrace();
            }

            final Intent resultIntent = new Intent(ACTION_USERS_GET_USER);
            if (result != null) {
                resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
            } else {
                resultIntent.putExtra(EXTRA_ERROR, true);
            }
            sendBroadcast(resultIntent);
        } else if (intent.getAction().equals(ACTION_USERS_LIST_FOLLOWERS)) {
            final UserService us = new UserService(mGitHubClient);
            ArrayList<User> result = null;
            PageIterator<User> iterator;
            final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);

            iterator = us.pageFollowers(intent.getStringExtra(PARAM_LOGIN),
                    startPage, REQUEST_PAGE_SIZE);

            if (iterator != null && iterator.hasNext()) {
                result = new ArrayList<User>();
                result.addAll(iterator.next());
            }

            final Intent resultIntent = new Intent(ACTION_USERS_LIST_FOLLOWERS);
            if (result != null) {
                resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
                resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
                resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
            } else {
                resultIntent.putExtra(EXTRA_ERROR, true);
            }
            sendBroadcast(resultIntent);
        } else if (intent.getAction().equals(ACTION_USERS_LIST_FOLLOWING)) {
            final UserService us = new UserService(mGitHubClient);
            ArrayList<User> result = null;
            PageIterator<User> iterator;
            final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);

            iterator = us.pageFollowing(intent.getStringExtra(PARAM_LOGIN),
                    startPage, REQUEST_PAGE_SIZE);

            if (iterator != null && iterator.hasNext()) {
                result = new ArrayList<User>();
                result.addAll(iterator.next());
            }

            final Intent resultIntent = new Intent(ACTION_USERS_LIST_FOLLOWING);
            if (result != null) {
                resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
                resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
                resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
            } else {
                resultIntent.putExtra(EXTRA_ERROR, true);
            }
            sendBroadcast(resultIntent);
        }
    }
} public class RepositoriesActivity extends BaseDashboardActivity {

    @Override
    protected void onCreate(Bundle icicle, int layout) {
        super.onCreate(icicle, R.layout.main);

        final FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentByTag(RepositoryListFragment.class.getName());

        if (fragment == null) {
            fragment = new RepositoryListFragment();
            fragment.setArguments(getIntent().getExtras());

            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(R.id.container_main, fragment, RepositoryListFragment.class.getName())
                    .commit();
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home && !isFromDashboard()) {
            final String userJson = getIntent().getStringExtra(ARG_TARGET_USER);
            if (userJson != null) {
                final Intent toUser = new Intent(this, ProfileActivity.class);
                toUser.putExtra(ARG_TARGET_USER, userJson);
                startActivity(toUser);
                finish();
                return true;
            }
        }
        return super.onOptionsItemSelected(item);
    }
} public class InfoListAdapter extends BaseListAdapter<InfoListAdapter.InfoHolder> {

    public static class InfoHolder {

        public
        String primary;

        public
        String secondary;

        public
        AdapterView.OnItemClickListener onClick;

        public
        AdapterView.OnItemLongClickListener onLongClick;
    }

    public static class ViewHolder {

        TextView primary;

        TextView secondary;
    }

    public InfoListAdapter(BaseActivity context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.info_list_item, null);
            viewHolder = new ViewHolder();
            viewHolder.primary = (TextView) convertView.findViewById(R.id.tv_info_primary);
            viewHolder.secondary = (TextView) convertView.findViewById(R.id.tv_info_secondary);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        final InfoHolder holder = getItem(position);

        viewHolder.primary.setText(holder.primary);
        viewHolder.secondary.setText(holder.secondary);

        return convertView;
    }

} public class BaseFragment extends SherlockFragment {

    protected Configuration mConfiguration;

    private boolean mCreateActionBarCalled = false;

    protected HashMap<String, Object> mArgumentMap = new HashMap<String, Object>();

    public BaseFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mConfiguration = getResources().getConfiguration();

		/*
         * Process arguments Bundle into a HashMap of different objects
		 */
        final Bundle arguments = getArguments();
        if (arguments != null) {
            if (arguments.getString(ARG_TARGET_USER) != null) {
                mArgumentMap.put(ARG_TARGET_USER,
                        GsonUtils.fromJson(arguments.getString(ARG_TARGET_USER),
                                User.class));
            }
            if (arguments.getString(ARG_TARGET_ISSUE) != null) {
                mArgumentMap.put(ARG_TARGET_ISSUE,
                        GsonUtils.fromJson(arguments.getString(ARG_TARGET_ISSUE),
                                Issue.class));
            }
            if (arguments.getString(ARG_TARGET_REPO) != null) {
                mArgumentMap.put(ARG_TARGET_ISSUE,
                        GsonUtils.fromJson(arguments.getString(ARG_TARGET_ISSUE),
                                Repository.class));
            }
        }
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        /* Let the system know this fragment can provide an options menu */
        setHasOptionsMenu(true);
    }

    public BaseActivity getBaseActivity() {
        return (BaseActivity) getActivity();
    }

    public Context getContext() {
        return getBaseActivity().getContext();
    }

    protected View getFragmentContainer() {
        return getBaseActivity().findViewById(R.id.container_main);
    }

    protected boolean isMultiPane() {
        return getBaseActivity().isMultiPane();
    }

    public void onCreateActionBar(ActionBar bar, Menu menu, MenuInflater inflater) {
        mCreateActionBarCalled = true;

        bar.setHomeButtonEnabled(true);

        bar.setDisplayShowHomeEnabled(true);
        bar.setDisplayShowTitleEnabled(true);
    }

    @Override
    public final void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);

        if (getBaseActivity() instanceof BaseDashboardActivity &&
                ((BaseDashboardActivity)getBaseActivity()).isDrawerOpened()) {
            return;
        } else {
            mCreateActionBarCalled = false;
            onCreateActionBar(getBaseActivity().getSupportActionBar(), menu, inflater);
            if (!mCreateActionBarCalled) {
                throw new IllegalStateException("You must call super() in onCreateActionBar()");
            }
        }
    }

    /**
     * @return The target user sent to this DataFragment as an argument, or null if none exists.
     */
    public User getTargetUser() {
        return (User) mArgumentMap.get(ARG_TARGET_USER);
    }

    /**
     * @return The target issue sent to this DataFragment as an argument, or null if none exists.
     */
    public Issue getTargetIssue() {
        return (Issue) mArgumentMap.get(ARG_TARGET_ISSUE);
    }

    /**
     * @return The target repository sent to this DataFragment as an argument, or null if none
     *         exists.
     */
    public Repository getTargetRepo() {
        return (Repository) mArgumentMap.get(ARG_TARGET_REPO);
    }
} public class IdleList<T> extends ListView {

    static final int INTERNAL_EMPTY_ID = 0x00ff0001;

    static final int INTERNAL_PROGRESS_ID = 0x00ff0002;

    static final int INTERNAL_FOOTER_ID = 0x00ff0003;

    LinearLayout mFooterView;

    TextView mStandardEmptyView;

    ProgressBar mProgress;

    CharSequence mEmptyText;

    CharSequence mTitle;

    boolean mListShown;

    public IdleList(Context context) {
        super(context);
        setupIdleList();
    }

    public IdleList(Context context, AttributeSet attrs) {
        super(context, attrs);
        setupIdleList();
    }

    public IdleList(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setupIdleList();
    }

    private void setupIdleList() {
        Context context = getContext();

        mFooterView = new LinearLayout(context);
        mFooterView.setId(INTERNAL_FOOTER_ID);
        mFooterView.setGravity(Gravity.CENTER);
        mFooterView.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT));

        mProgress = new ProgressBar(context, null, android.R.attr.progressBarStyle);
        mProgress.setId(INTERNAL_PROGRESS_ID);
        mProgress.setIndeterminate(true);
        mProgress.setVisibility(View.GONE);
        final LayoutParams progressLayoutParams = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
        mProgress.setLayoutParams(progressLayoutParams);

        mFooterView.addView(mProgress);

        mStandardEmptyView = new TextView(context);
        mStandardEmptyView.setId(INTERNAL_EMPTY_ID);
        mStandardEmptyView.setGravity(Gravity.CENTER);
        mStandardEmptyView.setVisibility(View.GONE);
        mStandardEmptyView.setPadding(10, 15, 10, 15);
        mStandardEmptyView.setText("That's all, folks!");

        mFooterView.addView(mStandardEmptyView, new LayoutParams(MATCH_PARENT, MATCH_PARENT));

        setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT));

        setFooterDividersEnabled(true);
        addFooterView(mFooterView, null, false);

        setItemsCanFocus(true);
        setDrawSelectorOnTop(true);

		/* A tiny hack to get the ProgressBar to show */
        mListShown = true;
        setListShown(true);
        setFooterShown(true);
    }

    public BaseListAdapter<T> getListAdapter() {
        final ListAdapter adapter = getAdapter();

        if (adapter instanceof HeaderViewListAdapter) {
            return (BaseListAdapter<T>) ((HeaderViewListAdapter) adapter).getWrappedAdapter();
        } else {
            return (BaseListAdapter<T>) getAdapter();
        }
    }

    @Override
    public void setAdapter(ListAdapter adapter) {
        if (!(adapter instanceof BaseListAdapter)) {
            throw new IllegalArgumentException("IdleList must use a BaseListAdapter.");
        }

        boolean hadAdapter = getListAdapter() != null;

        super.setAdapter(adapter);

        if (!(mListShown || hadAdapter)) {
            setListShown(true, getWindowToken() != null);
        }
    }

    public CharSequence getTitle() {
        return mTitle;
    }

    public void setTitle(CharSequence title) {
        mTitle = title;
    }

    public void setEmptyText(CharSequence text) {
        if (mStandardEmptyView == null) {
            throw new IllegalStateException("Can't be used with a custom content view");
        }
        mStandardEmptyView.setText(text);
        if (mEmptyText == null) {
            setEmptyView(mStandardEmptyView);
        }
        mEmptyText = text;
    }

    public void setListShown(boolean shown) {
        setListShown(shown, true);
    }

    public void setListShownNoAnimation(boolean shown) {
        setListShown(shown, false);
    }

    private void setListShown(boolean shown, boolean animate) {
        if (mListShown == shown) {
            return;
        }
        mListShown = shown;
        final Context context = getContext();
        if (shown) {
            if (animate) {
                startAnimation(AnimationUtils.loadAnimation(context, android.R.anim.fade_in));
            } else {
                clearAnimation();
            }
            setVisibility(View.VISIBLE);
        } else {
            if (animate) {
                startAnimation(AnimationUtils.loadAnimation(context, android.R.anim.fade_out));
            } else {
                clearAnimation();
            }
            setVisibility(View.GONE);
        }
    }

    public void setFooterShown(boolean shown) {
        if (shown) {
            mFooterView.setVisibility(View.VISIBLE);
        } else {
            mFooterView.setVisibility(View.GONE);
        }
    }

    public ProgressBar getProgressBar() {
        return mProgress;
    }

    public LinearLayout getFooterView() {
        return mFooterView;
    }

    public TextView getStandardEmptyView() {
        return mStandardEmptyView;
    }
} public final static String ARG_TARGET_USER = "target_user"; public static final String ACTION_USERS_GET_USER = "action_users_get_user"; public static final String ARG_ACCOUNT = "arg_account"; public static final String EXTRA_ERROR = "extra_error"; public static final String EXTRA_RESULT_JSON = "extra_result_json"; public static final String PARAM_LOGIN = "param_login"; public static final String ARG_LIST_TYPE = "list_type"; public static final int LIST_USER = 1; public static boolean isStringEmpty(final String str) {
    return str == null || str.equals("");
}
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.androidquery.AQuery;
import net.idlesoft.android.apps.github.R;
import net.idlesoft.android.apps.github.services.GitHubApiService;
import net.idlesoft.android.apps.github.ui.activities.app.RepositoriesActivity;
import net.idlesoft.android.apps.github.ui.adapters.InfoListAdapter;
import net.idlesoft.android.apps.github.ui.fragments.BaseFragment;
import net.idlesoft.android.apps.github.ui.widgets.IdleList;
import org.eclipse.egit.github.core.User;
import org.eclipse.egit.github.core.client.GsonUtils;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.util.ArrayList;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static net.idlesoft.android.apps.github.HubroidConstants.ARG_TARGET_USER;
import static net.idlesoft.android.apps.github.services.GitHubApiService.ACTION_USERS_GET_USER;
import static net.idlesoft.android.apps.github.services.GitHubApiService.ARG_ACCOUNT;
import static net.idlesoft.android.apps.github.services.GitHubApiService.EXTRA_ERROR;
import static net.idlesoft.android.apps.github.services.GitHubApiService.EXTRA_RESULT_JSON;
import static net.idlesoft.android.apps.github.services.GitHubApiService.PARAM_LOGIN;
import static net.idlesoft.android.apps.github.ui.fragments.app.RepositoryListFragment.ARG_LIST_TYPE;
import static net.idlesoft.android.apps.github.ui.fragments.app.RepositoryListFragment.LIST_USER;
import static net.idlesoft.android.apps.github.utils.StringUtils.isStringEmpty;
/*
 * Copyright (c) 2012 Eddie Ringle
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted
 * provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this list of conditions
 * and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
 * and the following disclaimer in the documentation and/or other materials provided with the
 * distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package net.idlesoft.android.apps.github.ui.fragments.app;







public class ProfileFragment extends BaseFragment {

    private static final String EXTRA_USER = "extra_user";

    private boolean mRefreshing;

    private ArrayList<InfoListAdapter.InfoHolder> mHolders;

    private ProgressBar mProgress;

    private ImageView mGravatarView;

    private LinearLayout mContent;

    private IdleList<InfoListAdapter.InfoHolder> mListView;

    private User mUser;

    private BroadcastReceiver mProfileReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (context == null || intent == null) {
                return;
            }

            if (intent.getBooleanExtra(EXTRA_ERROR, false)) {
                getBaseActivity().popShortToast("An error occurred.");
            } else {
                if (intent.getAction().equals(ACTION_USERS_GET_USER)) {
                    final String userJson = intent.getStringExtra(EXTRA_RESULT_JSON);
                    if (userJson != null) {
                        mUser = GsonUtils.fromJson(userJson, User.class);
                        buildHolders(mUser);
                        buildUI(mUser);

                        mProgress.setVisibility(GONE);
                        mContent.setVisibility(VISIBLE);
                    }
                }
            }
        }
    };

    public void buildHolders(final User user) {
        if (user == null) {
            return;
        }

        mHolders = new ArrayList<InfoListAdapter.InfoHolder>();

        InfoListAdapter.InfoHolder holder;

		/* Email */
        if (!isStringEmpty(user.getEmail())) {
            holder = new InfoListAdapter.InfoHolder();
            holder.primary = "Email";
            holder.secondary = user.getEmail();
            holder.onClick = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    final Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("message/rfc822");
                    intent.putExtra(Intent.EXTRA_EMAIL,
                            new String[]{mHolders.get(position).secondary});
                    getBaseActivity().startActivity(
                            Intent.createChooser(intent, "Send mail..."));
                }
            };
            mHolders.add(holder);
        }

		/* Blog/Website */
        if (!isStringEmpty(user.getBlog())) {
            holder = new InfoListAdapter.InfoHolder();
            holder.primary = "Blog";
            holder.secondary = user.getBlog();
            holder.onClick = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    final Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(mHolders.get(position).secondary));
                    getBaseActivity().startActivity(intent);
                }
            };
            mHolders.add(holder);
        }

		/* Company */
        if (!isStringEmpty(user.getCompany())) {
            holder = new InfoListAdapter.InfoHolder();
            holder.primary = "Company";
            holder.secondary = user.getCompany();
            mHolders.add(holder);
        }

		/* Followers/Following */
        holder = new InfoListAdapter.InfoHolder();
        holder.primary = "Followers/Following";
        holder.secondary = Integer.toString(user.getFollowing());
        holder.onClick = new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                final Bundle args = new Bundle();
                args.putString(ARG_TARGET_USER, GsonUtils.toJson(user));