Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Working on session list and detail screens. Moved GreenhouseTemplate …
Browse files Browse the repository at this point in the history
…code from spring social. Updated dependencies. Identified an issue with scribe, and switched to signpost for the initial oauth dance.
  • Loading branch information
royclarkson committed Nov 18, 2010
1 parent 891fde5 commit 30a157a
Show file tree
Hide file tree
Showing 26 changed files with 840 additions and 60 deletions.
5 changes: 4 additions & 1 deletion .classpath
Expand Up @@ -6,9 +6,12 @@
<classpathentry kind="lib" path="lib/slf4j-android-1.6.1-RC1.jar"/>
<classpathentry kind="lib" path="lib/jackson-core-asl-1.6.1.jar"/>
<classpathentry kind="lib" path="lib/jackson-mapper-asl-1.6.1.jar"/>
<classpathentry kind="lib" path="lib/scribe-1.0.7.jar"/>
<classpathentry kind="lib" path="lib/spring-android-commons-logging-1.0.0.BUILD-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/spring-android-rest-template-1.0.0.BUILD-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/spring-social-core-1.0.0.BUILD-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/signpost-commonshttp4-1.2.1.1.jar"/>
<classpathentry kind="lib" path="lib/signpost-core-1.2.1.1.jar"/>
<classpathentry kind="lib" path="lib/scribe-1.0.7.jar"/>
<classpathentry kind="lib" path="lib/commons-httpclient-3.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
3 changes: 1 addition & 2 deletions AndroidManifest.xml
Expand Up @@ -21,8 +21,7 @@
</activity>

<activity
android:name="com.springsource.greenhouse.activities.SignInActivity"
android:label="@string/app_name"
android:name="com.springsource.greenhouse.activities.SignInActivity"
android:theme="@android:style/Theme.NoTitleBar">
<!-- <intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Binary file added lib/commons-httpclient-3.1-sources.jar
Binary file not shown.
Binary file added lib/commons-httpclient-3.1.jar
Binary file not shown.
Binary file added lib/scribe-1.0.7-sources.jar
Binary file not shown.
Binary file added lib/signpost-commonshttp4-1.2.1.1.jar
Binary file not shown.
Binary file added lib/signpost-core-1.2.1.1.jar
Binary file not shown.
Binary file modified lib/spring-android-rest-template-1.0.0.BUILD-SNAPSHOT.jar
Binary file not shown.
Binary file modified lib/spring-social-core-1.0.0.BUILD-SNAPSHOT.jar
Binary file not shown.
2 changes: 0 additions & 2 deletions res/values/strings.xml
Expand Up @@ -30,8 +30,6 @@

<string-array name="event_session_details_options_array">
<item>Description</item>
<item>Favorite</item>
<item>Rate</item>
</string-array>

</resources>
Expand Up @@ -47,10 +47,10 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
NavigationManager.startActivity(view.getContext(), EventSessionDescriptionActivity.class);
break;
case 1:
Event event = SharedDataManager.getCurrentEvent();
EventSession session = SharedDataManager.getCurrentSession();
EventSessionsController.updateFavoriteSession(view.getContext(), event.getId(), session.getId());
break;
// Event event = SharedDataManager.getCurrentEvent();
// EventSession session = SharedDataManager.getCurrentSession();
// EventSessionsController.updateFavoriteSession(view.getContext(), event.getId(), session.getId());
// break;
case 2:
// NavigationManager.startActivity(view.getContext(), EventSessionsScheduleActivity.class);
default:
Expand Down Expand Up @@ -82,16 +82,16 @@ private void refreshEventDetails() {
final TextView textViewSessionLeaders = (TextView) findViewById(R.id.event_session_details_textview_leaders);
final TextView textViewSessionTime = (TextView) findViewById(R.id.event_session_details_textview_time);
final TextView textViewSessionRoom = (TextView) findViewById(R.id.event_session_details_textview_room);
final TextView textViewSessionRating = (TextView) findViewById(R.id.event_session_details_textview_rating);
// final TextView textViewSessionRating = (TextView) findViewById(R.id.event_session_details_textview_rating);

textViewSessionName.setText(session.getTitle());
textViewSessionLeaders.setText("leaders");
textViewSessionLeaders.setText(session.getJoinedLeaders(", "));

String startTime = new SimpleDateFormat("h:mm a").format(session.getStartTime());
String endTime = new SimpleDateFormat("h:mm a").format(session.getEndTime());
textViewSessionTime.setText(startTime + " - " + endTime);

textViewSessionRoom.setText(session.getRoom().getLabel());
textViewSessionRating.setText(session.getRating() + " Stars");
// textViewSessionRating.setText(session.getRating() + " Stars");
}
}
Expand Up @@ -8,7 +8,6 @@

import org.springframework.social.greenhouse.Event;
import org.springframework.social.greenhouse.EventSession;
import org.springframework.social.greenhouse.EventSession.Leader;

import android.app.ListActivity;
import android.os.Bundle;
Expand Down Expand Up @@ -65,6 +64,10 @@ private void refreshSessions() {

sessions = EventSessionsController.getSessionsByDay(this, event.getId(), day);

if (sessions == null) {
return;
}

List<Map<String,String>> sessionMaps = new ArrayList<Map<String,String>>();

// TODO: Is there w way to populate the table from an Event instead of a Map?
Expand Down
Expand Up @@ -7,19 +7,18 @@

import org.springframework.social.greenhouse.Event;
import org.springframework.social.greenhouse.EventSession;
import org.springframework.social.greenhouse.EventSession.Leader;

import com.springsource.greenhouse.R;
import com.springsource.greenhouse.controllers.EventSessionsController;
import com.springsource.greenhouse.controllers.NavigationManager;
import com.springsource.greenhouse.util.SharedDataManager;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.springsource.greenhouse.R;
import com.springsource.greenhouse.controllers.EventSessionsController;
import com.springsource.greenhouse.controllers.NavigationManager;
import com.springsource.greenhouse.util.SharedDataManager;

public class EventSessionsConferenceFavoritesActivity extends ListActivity {

private List<EventSession> sessions;
Expand Down Expand Up @@ -63,6 +62,10 @@ private void refreshSessions() {

sessions = EventSessionsController.getConferenceFavoriteSessions(this, event.getId());

if (sessions == null) {
return;
}

List<Map<String,String>> sessionMaps = new ArrayList<Map<String,String>>();

// TODO: Is there w way to populate the table from an Event instead of a Map?
Expand Down
Expand Up @@ -7,11 +7,9 @@

import org.springframework.social.greenhouse.Event;
import org.springframework.social.greenhouse.EventSession;
import org.springframework.social.greenhouse.EventSession.Leader;

import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.SimpleAdapter;

import com.springsource.greenhouse.R;
Expand Down Expand Up @@ -51,6 +49,10 @@ private void refreshSessions() {
}

sessions = EventSessionsController.getSessionsCurrent(this, event.getId());

if (sessions == null) {
return;
}

List<Map<String,String>> sessionMaps = new ArrayList<Map<String,String>>();

Expand Down
Expand Up @@ -7,7 +7,6 @@

import org.springframework.social.greenhouse.Event;
import org.springframework.social.greenhouse.EventSession;
import org.springframework.social.greenhouse.EventSession.Leader;

import android.app.ListActivity;
import android.os.Bundle;
Expand Down Expand Up @@ -63,6 +62,10 @@ private void refreshSessions() {

sessions = EventSessionsController.getFavoriteSessions(this, event.getId());

if (sessions == null) {
return;
}

List<Map<String,String>> sessionMaps = new ArrayList<Map<String,String>>();

// TODO: Is there w way to populate the table from an Event instead of a Map?
Expand Down
Expand Up @@ -48,12 +48,12 @@ private void refreshSessions() {
Event event = SharedDataManager.getCurrentEvent();
upcomingSessions = EventSessionsController.getSessionsUpcoming(this, event.getId());

if (upcomingSessions == null) {
if (event == null || upcomingSessions == null) {
return;
}

List<Map<String,String>> sessions = new ArrayList<Map<String,String>>();

// TODO: Is there w way to populate the table from a Session instead of a Map?
for (EventSession session : upcomingSessions) {
Map<String, String> map = new HashMap<String, String>();
Expand Down
48 changes: 39 additions & 9 deletions src/com/springsource/greenhouse/activities/OAuthActivity.java
Expand Up @@ -21,6 +21,8 @@
import com.springsource.greenhouse.util.Prefs;

public class OAuthActivity extends Activity {

private static final String TAG = "OAuthActivity";
private SharedPreferences _settings;

@Override
Expand All @@ -30,12 +32,28 @@ protected void onCreate(Bundle savedInstanceState) {
if (getIntent().getData() == null) {
try {
_settings = getSharedPreferences(Prefs.PREFS, Context.MODE_PRIVATE);

// scribe
ServiceBuilder serviceBuilder = new ServiceBuilder();
OAuthService oAuthService = serviceBuilder.apiKey(Prefs.getConsumerKey()).apiSecret(Prefs.getConsumerSecret()).provider(GreenhouseApi.class).callback(Prefs.CALLBACK_URI_STRING).build();
Token requestToken = oAuthService.getRequestToken();

Prefs.saveRequestInformation(_settings, requestToken.getToken(), requestToken.getSecret());
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Prefs.getUrlBase() + "/oauth/confirm_access?oauth_token=" + requestToken.getToken())));
String requestTokenValue = requestToken.getToken();
String requestTokenSecret = requestToken.getSecret();
// Prefs.saveRequestInformation(_settings, requestToken.getToken(), requestToken.getSecret());
Uri uri = Uri.parse(Prefs.getUrlBase() + "/oauth/confirm_access?oauth_token=" + requestToken.getToken());

// signpost
// OAuthConsumer oauthConsumer = new CommonsHttpOAuthConsumer(Prefs.getConsumerKey(), Prefs.getConsumerSecret());
// OAuthProvider oauthProvider = new CommonsHttpOAuthProvider(Prefs.getRequestTokenUrl(), Prefs.getAccessTokenUrl(), Prefs.getAuthorizeUrl());
// String authUrl = oauthProvider.retrieveRequestToken(oauthConsumer, Prefs.CALLBACK_URI_STRING);
// String requestTokenValue = oauthConsumer.getToken();
// String requestTokenSecret = oauthConsumer.getTokenSecret();
// Prefs.saveRequestInformation(_settings, oauthConsumer.getToken(), oauthConsumer.getTokenSecret());
// Uri uri = Uri.parse(authUrl);

Prefs.saveRequestInformation(_settings, requestTokenValue, requestTokenSecret);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
finish();
} catch (Exception e) {
Log.e("ErrorHandler", e.getMessage(), e);
Expand All @@ -54,6 +72,8 @@ protected void onResume() {
if (uri == null || !Prefs.getCallbackUri().getScheme().equals(uri.getScheme())) {
return;
}

Log.d(TAG, uri.toString());

_settings = getSharedPreferences(Prefs.PREFS, Context.MODE_PRIVATE);
String[] tokenAndSecret = Prefs.getRequestTokenAndSecret(_settings);
Expand All @@ -62,21 +82,31 @@ protected void onResume() {
Intent intent = new Intent(this, MainTabWidget.class);

try {
Token requestToken = new Token(requestTokenValue, requestTokenSecret);
String verifier = uri.getQueryParameter("oauth_verifier");
String verifierValue = uri.getQueryParameter("oauth_verifier");

// scribe
Token requestToken = new Token(requestTokenValue, requestTokenSecret);
ServiceBuilder serviceBuilder = new ServiceBuilder();
OAuthService oAuthService = serviceBuilder.apiKey(Prefs.getConsumerKey()).apiSecret(Prefs.getConsumerSecret()).provider(GreenhouseApi.class).callback(Prefs.CALLBACK_URI_STRING).build();

Token accessToken = oAuthService.getAccessToken(requestToken, new Verifier(verifier));

Verifier verifier = new Verifier(verifierValue);
Token accessToken = oAuthService.getAccessToken(requestToken, verifier);
Prefs.saveAuthInformation(_settings, accessToken.getToken(), accessToken.getSecret());

// signpost
// String verifier = uri.getQueryParameter("oauth_verifier");
// OAuthConsumer oauthConsumer = new CommonsHttpOAuthConsumer(Prefs.getConsumerKey(), Prefs.getConsumerSecret());
// oauthConsumer.setTokenWithSecret(requestTokenValue, requestTokenSecret);
// OAuthProvider oauthProvider = new CommonsHttpOAuthProvider(Prefs.getRequestTokenUrl(), Prefs.getAccessTokenUrl(), Prefs.getAuthorizeUrl());
// oauthProvider.retrieveAccessToken(oauthConsumer, verifier);
// Log.d(TAG, oauthConsumer.getToken());
// Log.d(TAG, oauthConsumer.getTokenSecret());
// Prefs.saveAuthInformation(_settings, oauthConsumer.getToken(), oauthConsumer.getTokenSecret());

// Clear the request stuff, now that we have the real thing
Prefs.resetRequestInformation(_settings);
}
catch (Exception e) {
Log.e("ErrorHandler", e.getMessage(), e);
Log.e(TAG, e.getMessage(), e);
Writer result = new StringWriter();
e.printStackTrace(new PrintWriter(result));
}
Expand Down
@@ -1,12 +1,13 @@
package com.springsource.greenhouse.controllers;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.social.greenhouse.EventSession;
import org.springframework.web.client.HttpClientErrorException;

import android.content.Context;
import android.util.Log;
Expand All @@ -33,10 +34,10 @@ public static List<EventSession> getSessionsCurrent(Context context, long eventI
}

return currentSessions;
} catch(HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) {
// signOut(context);
}
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
Writer result = new StringWriter();
e.printStackTrace(new PrintWriter(result));
} finally {
dismissProgressDialog();
}
Expand Down Expand Up @@ -65,10 +66,10 @@ public static List<EventSession> getSessionsUpcoming(Context context, long event
}

return upcomingSessions;
} catch(HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) {
// signOut(context);
}
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
Writer result = new StringWriter();
e.printStackTrace(new PrintWriter(result));
} finally {
dismissProgressDialog();
}
Expand All @@ -81,10 +82,10 @@ public static List<EventSession> getSessionsByDay(Context context, long eventId,
showProgressDialog(context);
try {
return getGreenhouseOperations(context).getSessionsOnDay(eventId, day);
} catch(HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) {
// signOut(context);
}
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
Writer result = new StringWriter();
e.printStackTrace(new PrintWriter(result));
} finally {
dismissProgressDialog();
}
Expand All @@ -97,10 +98,10 @@ public static List<EventSession> getFavoriteSessions(Context context, long event
showProgressDialog(context);
try {
return getGreenhouseOperations(context).getFavoriteSessions(eventId);
} catch(HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) {
// signOut(context);
}
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
Writer result = new StringWriter();
e.printStackTrace(new PrintWriter(result));
} finally {
dismissProgressDialog();
}
Expand All @@ -113,10 +114,10 @@ public static List<EventSession> getConferenceFavoriteSessions(Context context,
showProgressDialog(context);
try {
return getGreenhouseOperations(context).getConferenceFavoriteSessions(eventId);
} catch(HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) {
// signOut(context);
}
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
Writer result = new StringWriter();
e.printStackTrace(new PrintWriter(result));
} finally {
dismissProgressDialog();
}
Expand All @@ -129,8 +130,10 @@ public static boolean updateFavoriteSession(Context context, long eventId, long
showProgressDialog(context);
try {
return getGreenhouseOperations(context).updateFavoriteSession(eventId, sessionId);
} catch(Exception e) {
Log.e(TAG, e.getLocalizedMessage());
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
Writer result = new StringWriter();
e.printStackTrace(new PrintWriter(result));
} finally {
dismissProgressDialog();
}
Expand Down
@@ -1,9 +1,11 @@
package com.springsource.greenhouse.controllers;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.List;

import org.springframework.social.greenhouse.Event;
import org.springframework.web.client.ResourceAccessException;

import android.app.Activity;
import android.util.Log;
Expand All @@ -20,8 +22,12 @@ public static List<Event> getUpcomingEvents(Activity activity) {
showProgressDialog(activity);
try {
return getGreenhouseOperations(activity).getUpcomingEvents();
} catch(ResourceAccessException e) {
Log.e(TAG, e.getLocalizedMessage());
// } catch(ResourceAccessException e) {
// Log.e(TAG, e.getLocalizedMessage());
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
Writer result = new StringWriter();
e.printStackTrace(new PrintWriter(result));
} finally {
dismissProgressDialog();
}
Expand Down

0 comments on commit 30a157a

Please sign in to comment.