Skip to content

Commit

Permalink
Add support for lists of Events
Browse files Browse the repository at this point in the history
Signed-off-by: Eddie Ringle <eddie@eringle.net>
  • Loading branch information
EddieRingle committed Aug 27, 2012
1 parent 3a3090c commit 35cfa02
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 0 deletions.
1 change: 1 addition & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
android:host="oauth"></data>
</intent-filter>
</activity>
<activity android:name=".ui.activities.app.EventsActivity" />
<activity android:name=".ui.activities.app.RepositoriesActivity" />
<activity android:name=".ui.activities.app.ProfileActivity" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.eclipse.egit.github.core.client.GsonUtils;
import org.eclipse.egit.github.core.client.IGitHubConstants;
import org.eclipse.egit.github.core.client.PageIterator;
import org.eclipse.egit.github.core.event.Event;
import org.eclipse.egit.github.core.service.EventService;
import org.eclipse.egit.github.core.service.OrganizationService;
import org.eclipse.egit.github.core.service.RepositoryService;
import org.eclipse.egit.github.core.service.UserService;
Expand All @@ -57,6 +59,8 @@ public class GitHubApiService extends IntentService {

public static final String ACTION_GET_URI = "action_get_uri";

public static final String ACTION_EVENTS_LIST_TIMELINE = "action_events_list_timeline";

public static final String ACTION_ORGS_LIST_MEMBERS = "action_orgs_list_members";

public static final String ACTION_ORGS_SELF_MEMBERSHIPS = "action_orgs_self_memberships";
Expand Down Expand Up @@ -185,6 +189,28 @@ protected void onHandleIntent(Intent intent) {
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_ORGS_SELF_MEMBERSHIPS)) {
final OrganizationService os = new OrganizationService(mGitHubClient);
List<User> result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@

import net.idlesoft.android.apps.github.R;
import net.idlesoft.android.apps.github.services.GitHubApiService;
import net.idlesoft.android.apps.github.ui.activities.app.EventsActivity;
import net.idlesoft.android.apps.github.ui.activities.app.HomeActivity;
import net.idlesoft.android.apps.github.ui.activities.app.ProfileActivity;
import net.idlesoft.android.apps.github.ui.activities.app.RepositoriesActivity;
import net.idlesoft.android.apps.github.ui.adapters.ContextListAdapter;
import net.idlesoft.android.apps.github.ui.adapters.DashboardListAdapter;
import net.idlesoft.android.apps.github.ui.fragments.app.EventListFragment;
import net.idlesoft.android.apps.github.ui.widgets.OcticonView;

import org.eclipse.egit.github.core.User;
Expand Down Expand Up @@ -63,6 +65,8 @@
import static net.idlesoft.android.apps.github.services.GitHubApiService.ACTION_ORGS_SELF_MEMBERSHIPS;
import static net.idlesoft.android.apps.github.services.GitHubApiService.ARG_ACCOUNT;
import static net.idlesoft.android.apps.github.services.GitHubApiService.EXTRA_RESULT_JSON;
import static net.idlesoft.android.apps.github.ui.fragments.app.EventListFragment.ARG_EVENT_LIST_TYPE;
import static net.idlesoft.android.apps.github.ui.fragments.app.EventListFragment.LIST_TIMELINE;
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.ui.fragments.app.RepositoryListFragment.LIST_WATCHED;
Expand Down Expand Up @@ -205,6 +209,20 @@ public void onDrawerClosed() {
.setGlyphSize(72.0f)
.toDrawable();
entry.selected = false;
entry.onEntryClickListener = new DashboardListAdapter.DashboardEntry.OnEntryClickListener() {
@Override
public void onClick(DashboardListAdapter.DashboardEntry entry, int i) {
final Intent eventsIntent = new Intent(BaseDashboardActivity.this,
EventsActivity.class);
eventsIntent.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_NEW_TASK);
eventsIntent.putExtra(ARG_DASHBOARD_ITEM, i);
eventsIntent.putExtra(ARG_FROM_DASHBOARD, true);
eventsIntent.putExtra(ARG_TARGET_USER,
GsonUtils.toJson(new User().setLogin(getCurrentContextLogin())));
eventsIntent.putExtra(ARG_EVENT_LIST_TYPE, LIST_TIMELINE);
startActivity(eventsIntent);
}
};
dashboardEntries.add(entry);

entry = new DashboardListAdapter.DashboardEntry();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.activities.app;

import com.actionbarsherlock.view.MenuItem;

import net.idlesoft.android.apps.github.R;
import net.idlesoft.android.apps.github.ui.activities.BaseDashboardActivity;
import net.idlesoft.android.apps.github.ui.fragments.app.EventListFragment;
import net.idlesoft.android.apps.github.ui.fragments.app.RepositoryListFragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

import static net.idlesoft.android.apps.github.HubroidConstants.ARG_TARGET_USER;

public class EventsActivity extends BaseDashboardActivity {

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

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

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

getSupportFragmentManager()
.beginTransaction()
.replace(R.id.container_main, fragment, EventListFragment.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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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.adapters;

import com.androidquery.AQuery;

import net.idlesoft.android.apps.github.R;
import net.idlesoft.android.apps.github.ui.activities.BaseActivity;

import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.event.Event;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class EventListAdapter extends BaseListAdapter<Event> {

public static class ViewHolder {

TextView title;

ImageView gravatar;

TextView extra;
}

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.event_list_item, null);
holder = new ViewHolder();

holder.title = (TextView) convertView.findViewById(R.id.tv_event_title);
holder.gravatar = (ImageView) convertView.findViewById(R.id.iv_event_gravatar);
holder.extra = (TextView) convertView.findViewById(R.id.tv_event_extra);

convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

final Event e = getItem(position);

holder.title.setText(e.getActor().getLogin() + " did a(n) " + e.getType());
holder.extra.setText(e.getCreatedAt().toString());

final AQuery aq = new AQuery(getContext());

aq.id(holder.gravatar).image(e.getActor().getAvatarUrl(), true, true, 140, R.drawable.gravatar, null, AQuery.FADE_IN_NETWORK);

return convertView;
}
}
Loading

0 comments on commit 35cfa02

Please sign in to comment.