Permalink
Browse files

fixed merge conflict

  • Loading branch information...
2 parents 245e900 + 272f479 commit dc0bbefbdb4f5cba3bbd847f0cb2bcb01e0092de Sam Karp committed Apr 13, 2011
@@ -1,7 +1,7 @@
package gov.nasa.arc.geocam.talk.activity.test;
import gov.nasa.arc.geocam.talk.R;
-import gov.nasa.arc.geocam.talk.activity.GeoCamTalkMessageArrayAdapter;
+import gov.nasa.arc.geocam.talk.activity.GeoCamTalkMessageAdapter;
import gov.nasa.arc.geocam.talk.bean.GeoCamTalkMessage;
import gov.nasa.arc.geocam.talk.injected.FakeGeoCamTalkMessageFactory;
import gov.nasa.arc.geocam.talk.test.GeoCamTestCase;
@@ -28,7 +28,7 @@ public void shouldProperlyDisplayGeolocaionStatus() throws Exception {
msgs.add(FakeGeoCamTalkMessageFactory.getMessage("testing", "Patrick", true));
msgs.add(FakeGeoCamTalkMessageFactory.getMessage("testing2", "Not Patrick", false));
- GeoCamTalkMessageArrayAdapter adapter = new GeoCamTalkMessageArrayAdapter(
+ GeoCamTalkMessageAdapter adapter = new GeoCamTalkMessageAdapter(
Robolectric.application.getApplicationContext());
adapter.setTalkMessages(msgs);
@@ -48,24 +48,11 @@ public void testEqualsMethodFalse() throws Exception
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy hh:mm:ss");
GeoCamTalkMessage message1 = new GeoCamTalkMessage();
- message1.setAuthorUsername("rhornsby");
- message1.setAuthorFullname("Rufus Hornsby");
- message1.setLongitude(-122.057954);
- message1.setContent("Structural engineer not allowing access to building. Fire is too out of control. Fire squad alerted.");
- message1.setContentTimestamp(sdf.parse("03/13/11 10:48:44"));
- message1.setLatitude(37.411629);
message1.setMessageId(15);
- message1.setAccuracy(60);
GeoCamTalkMessage message2 = new GeoCamTalkMessage();
- message2.setAuthorUsername("rhornsby");
- message2.setAuthorFullname("Rufus Hornsby");
- message2.setLongitude(-122.057954);
- message2.setContent("Structural engineer not allowing access to building. Fire is too out of control. Fire squad alerted. Blah"); // changed here
- message2.setContentTimestamp(sdf.parse("03/13/11 10:48:44"));
- message2.setLatitude(37.411629);
- message2.setMessageId(15);
- message2.setAccuracy(60);
+ message2.setMessageId(12);
+
// assert
assertFalse(message1.equals(message2));
@@ -1,6 +1,14 @@
package gov.nasa.arc.geocam.talk.injected;
+import com.google.inject.Scopes;
+
+import gov.nasa.arc.geocam.talk.service.AudioPlayer;
+import gov.nasa.arc.geocam.talk.service.AudioRecorder;
import gov.nasa.arc.geocam.talk.service.DatabaseHelper;
+import gov.nasa.arc.geocam.talk.service.IAudioPlayer;
+import gov.nasa.arc.geocam.talk.service.IAudioRecorder;
+import gov.nasa.arc.geocam.talk.service.ISiteAuth;
+import gov.nasa.arc.geocam.talk.service.SiteAuthCookie;
import gov.nasa.arc.geocam.talk.service.TalkJsonConverter;
import gov.nasa.arc.geocam.talk.service.GeoCamSynchronizationTimerTask;
import gov.nasa.arc.geocam.talk.service.IDatabaseHelper;
@@ -18,10 +26,13 @@
@Override
protected void configure() {
bind(ITalkServer.class).to(FakeTalkServer.class);
- bind(ITalkJsonConverter.class).to(TalkJsonConverter.class);
- bind(IMessageStore.class).to(MessageStore.class);
bind(IDatabaseHelper.class).to(DatabaseHelper.class);
+ bind(IMessageStore.class).to(MessageStore.class);
+ bind(IAudioRecorder.class).to(AudioRecorder.class);
+ bind(IAudioPlayer.class).to(AudioPlayer.class);
+ bind(ITalkJsonConverter.class).to(TalkJsonConverter.class);
+ bind(ISiteAuth.class).to(SiteAuthCookie.class).in(Scopes.SINGLETON);
bind(IIntentHelper.class).to(IntentHelper.class);
- bind(IGeoCamSynchronizationTimerTask.class).to(GeoCamSynchronizationTimerTask.class);
- }
+ bind(IGeoCamSynchronizationTimerTask.class).to(GeoCamSynchronizationTimerTask.class).in(
+ Scopes.SINGLETON); }
}
@@ -20,7 +20,7 @@ public void ensureProperParsingOfMessageListFeed() throws Exception
{
// arrange
String jsonString =
- "{\"ts\": 1, \"ms\": [{\"authorUsername\": \"rhornsby\", \"authorFullname\":\"Rufus Hornsby\", \"longitude\": null, \"content\": \"Crap, my geolocation service crashed and I am not providing geoloc with this message. This message should be the latest to make sure we gracefully fall back to the next available geolocated message.\", \"contentTimestamp\": \"03/13/11 11:23:21\",\"latitude\": null, \"messageId\": 19, \"accuracy\": null}, {\"authorUsername\": \"rhornsby\", \"longitude\": -122.057954, \"content\": \"Structural engineer not allowing access to building. Fire is too out of control. Fire squad alerted.\", \"contentTimestamp\": \"03/13/11 10:48:44\", \"latitude\": 37.411629, \"messageId\": 15, \"accuracy\":60.0, \"hasGeolocation\":true}]}";
+ "{\"ts\": 1, \"ms\": [{\"authorUsername\": \"rhornsby\", \"authorFullname\":\"Rufus Hornsby\", \"longitude\": null, \"content\": \"Crap, my geolocation service crashed and I am not providing geoloc with this message. This message should be the latest to make sure we gracefully fall back to the next available geolocated message.\", \"contentTimestamp\": 182376817,\"latitude\": null, \"messageId\": 19, \"accuracy\": null}, {\"authorUsername\": \"rhornsby\", \"longitude\": -122.057954, \"content\": \"Structural engineer not allowing access to building. Fire is too out of control. Fire squad alerted.\", \"contentTimestamp\": 182376817, \"latitude\": 37.411629, \"messageId\": 15, \"accuracy\":60.0, \"hasGeolocation\":true}]}";
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
TalkJsonConverter converter =
new TalkJsonConverter();
@@ -30,7 +30,7 @@ public void ensureProperParsingOfMessageListFeed() throws Exception
message1.setAuthorFullname("Rufus Hornsby");
// don't set longitude
message1.setContent("Crap, my geolocation service crashed and I am not providing geoloc with this message. This message should be the latest to make sure we gracefully fall back to the next available geolocated message.");
- message1.setContentTimestamp(sdf.parse("03/13/11 11:23:21"));
+ message1.setContentTimestamp(new Date(182376817));
// don't set latitude
message1.setMessageId(19);
// don't set accuracy
@@ -39,7 +39,7 @@ public void ensureProperParsingOfMessageListFeed() throws Exception
message2.setAuthorUsername("rhornsby");
message2.setLongitude(-122.057954);
message2.setContent("Structural engineer not allowing access to building. Fire is too out of control. Fire squad alerted.");
- message2.setContentTimestamp(sdf.parse("03/13/11 10:48:44"));
+ message2.setContentTimestamp(new Date(182376817));
message2.setLatitude(37.411629);
message2.setMessageId(15);
message2.setAccuracy(60);
@@ -62,13 +62,13 @@ public void ensureSingularDeserializationWorks() throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
String jsonString =
- "{\"authorUsername\": \"rhornsby\", \"longitude\": -122.057954, \"content\": \"Structural engineer not allowing access to building. Fire is too out of control. Fire squad alerted.\", \"contentTimestamp\": \"03/13/11 10:48:44\", \"latitude\": 37.411629, \"messageId\": 15, \"accuracy\":60.0}";
+ "{\"authorUsername\": \"rhornsby\", \"longitude\": -122.057954, \"content\": \"Structural engineer not allowing access to building. Fire is too out of control. Fire squad alerted.\", \"contentTimestamp\": 182376817, \"latitude\": 37.411629, \"messageId\": 15, \"accuracy\":60.0}";
GeoCamTalkMessage message = new GeoCamTalkMessage();
message.setAuthorUsername("rhornsby");
message.setLongitude(-122.057954);
message.setContent("Structural engineer not allowing access to building. Fire is too out of control. Fire squad alerted.");
- message.setContentTimestamp(sdf.parse("03/13/11 10:48:44"));
+ message.setContentTimestamp(new Date(182376817));
message.setLatitude(37.411629);
message.setMessageId(15);
message.setAccuracy(60);
@@ -88,7 +88,7 @@ public void ensureSerializeReturnsProperString() throws Exception
GeoCamTalkMessage msg = new GeoCamTalkMessage();
msg.setContent("contentTest");
- msg.setContentTimestamp(new Date());
+ msg.setContentTimestamp(new Long(182376817));
msg.setAccuracy(10);
msg.setLatitude(11);
msg.setLongitude(20.5);
@@ -99,6 +99,7 @@ public void ensureSerializeReturnsProperString() throws Exception
assertTrue(jsonString.contains("content"));
assertTrue(jsonString.contains("contentTest"));
assertTrue(jsonString.contains("contentTimestamp"));
+ assertTrue(jsonString.contains("182376817"));
assertTrue(jsonString.contains("accuracy"));
assertTrue(jsonString.contains("10"));
assertTrue(jsonString.contains("latitude"));
@@ -51,6 +51,8 @@ public void shouldEnsureGetTalkMessagesReturnsMessages() throws Exception {
IIntentHelper intentHelper = mock(IIntentHelper.class);
setHiddenField(talkImpl, "intentHelper", intentHelper);
+ setHiddenField(talkImpl, "urlMessageList", "test");
+
// act
talkImpl.getTalkMessages();
@@ -73,6 +75,12 @@ public void shouldEnsureCreateTalkMessagePostsTalkMessage() throws Exception
when(jsonConv.serialize((GeoCamTalkMessage)anyObject())).thenReturn("");
setHiddenField(talkImpl, "jsonConverter", jsonConv);
+ MessageStore ms = mock(MessageStore.class);
+ setHiddenField(talkImpl, "messageStore", ms);
+
+ IIntentHelper ih = mock(IIntentHelper.class);
+ setHiddenField(talkImpl, "intentHelper", ih);
+
// act
talkImpl.createTalkMessage(new GeoCamTalkMessage());
@@ -29,12 +29,12 @@ protected void configure() {
bind(IDatabaseHelper.class).to(DatabaseHelper.class);
bind(IMessageStore.class).to(MessageStore.class);
bind(IAudioRecorder.class).to(AudioRecorder.class);
- bind(IAudioPlayer.class).to(AudioPlayer.class);
+ bind(IAudioPlayer.class).to(AudioPlayer.class).in(Scopes.SINGLETON);
bind(ITalkJsonConverter.class).to(TalkJsonConverter.class);
bind(ISiteAuth.class).to(SiteAuthCookie.class).in(Scopes.SINGLETON);
bind(IIntentHelper.class).to(IntentHelper.class);
- bind(IGeoCamSynchronizationTimerTask.class).to(GeoCamSynchronizationTimerTask.class).in(
- Scopes.SINGLETON);
+ bind(IGeoCamSynchronizationTimerTask.class).to(
+ GeoCamSynchronizationTimerTask.class).in(Scopes.SINGLETON);
}
}
@@ -29,51 +29,53 @@
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
-import android.widget.Toast;
import com.google.inject.Inject;
public class GeoCamTalkActivity extends RoboActivity {
@Inject
ITalkServer djangoTalk;
+
@InjectView(R.id.TalkListView)
ListView talkListView;
+
@InjectResource(R.string.url_server_root)
String serverRootUrl;
+
@Inject
- GeoCamTalkMessageArrayAdapter adapter;
+ GeoCamTalkMessageAdapter adapter;
+
@Inject
IMessageStore messageStore;
+
@Inject
ISiteAuth siteAuth;
+
@Inject
IAudioPlayer player;
@Inject
SharedPreferences prefs;
@Inject
IIntentHelper intentHelper;
-
+
List<GeoCamTalkMessage> talkMessages;
private EditText username;
private BroadcastReceiver receiver = new BroadcastReceiver() {
-
+
@Override
public void onReceive(Context context, Intent intent) {
- if(intent.getAction().contentEquals(TalkServerIntent.INTENT_NEW_MESSAGES.toString()))
- {
+ if (intent.getAction().contentEquals(TalkServerIntent.INTENT_NEW_MESSAGES.toString())) {
GeoCamTalkActivity.this.newMessages();
}
}
};
-
-
- /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
setUsername();
}
@@ -85,7 +87,20 @@ private void setUsername()
username.setText(prefs.getString("webapp_username", null));
}
}
-
+
+ private void populateListView() {
+ try {
+ talkMessages = messageStore.getAllMessages();
+ } catch (Exception e) {
+ Log.i("Talk", "Error:" + e.getMessage());
+ }
+
+ if (talkMessages != null) {
+ adapter.setTalkMessages(talkMessages);
+ talkListView.setAdapter(adapter);
+ }
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
@@ -128,84 +143,48 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
public void onGoHomeClick(View v) {
- List<GeoCamTalkMessage> talkMessages = null;
-
- try {
- talkMessages = messageStore.getAllMessages();
- } catch (Exception e) {
- Log.i("Talk", "Error:" + e.getMessage());
- }
-
- if (talkMessages != null) {
- adapter.setTalkMessages(talkMessages);
- talkListView.setAdapter(adapter);
- }
+ populateListView();
}
public void onCreateTalkClick(View v) {
UIUtils.createTalkMessage(this);
}
public void newMessages() {
- try {
- talkMessages = messageStore.getAllMessages();
- } catch (Exception e) {
- Log.i("Talk", "Error:" + e.getMessage());
- }
-
- if (talkMessages != null) {
- adapter.setTalkMessages(talkMessages);
- talkListView.setAdapter(adapter);
- }
+ populateListView();
}
-
- @Override
- protected void onResume() {
- super.onResume();
- IntentFilter filter = new IntentFilter();
- filter.addAction(TalkServerIntent.INTENT_NEW_MESSAGES.toString());
- registerReceiver(receiver, filter);
+ @Override
+ protected void onResume() {
+ super.onResume();
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(TalkServerIntent.INTENT_NEW_MESSAGES.toString());
+ registerReceiver(receiver, filter);
- setContentView(R.layout.main);
+ populateListView();
setUsername();
- talkListView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
- @Override
- public void onItemClick (AdapterView<?> parentView, View childView, int position, long id) {
- GeoCamTalkMessage msg = adapter.getTalkMessage(position);
- if(msg.hasAudio())
- {
- try
- {
- UIUtils.playAudio(getApplicationContext(), msg, player, siteAuth);
- } catch (Exception e)
- {
- UIUtils.displayException(getApplicationContext(), e, "Cannot retrieve audio");
- }
- }
- }
- });
-
-
- try {
- talkMessages = messageStore.getAllMessages();
- } catch (Exception e) {
- Log.i("Talk", "Error:" + e.getMessage());
- }
+ talkListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> parentView, View childView,
+ int position, long id) {
+ GeoCamTalkMessage msg = adapter.getTalkMessage(position);
+ if (msg.hasAudio()) {
+ try {
+ UIUtils.playAudio(getApplicationContext(), msg, player,
+ siteAuth);
+ } catch (Exception e) {
+ UIUtils.displayException(getApplicationContext(), e,
+ "Cannot retrieve audio");
+ }
+ }
+ }
+ });
+ }
- if (talkMessages != null) {
- adapter.setTalkMessages(talkMessages);
- talkListView.setAdapter(adapter);
- } else {
- Toast.makeText(this.getApplicationContext(), "Communication Error with Server",
- Toast.LENGTH_SHORT).show();
- }
- }
-
- @Override
- protected void onPause() {
- unregisterReceiver(receiver);
- super.onPause();
- }
+ @Override
+ protected void onPause() {
+ unregisterReceiver(receiver);
+ super.onPause();
+ }
}
Oops, something went wrong.

0 comments on commit dc0bbef

Please sign in to comment.