Commit fb388135 authored by LIly's avatar LIly
Browse files

fix recoverable user error

parent 29bc9fa8
......@@ -22,6 +22,7 @@ import com.google.android.gms.auth.GoogleAuthException;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException;
import com.google.api.client.util.ExponentialBackOff;
import com.google.api.services.calendar.CalendarScopes;
......@@ -48,9 +49,9 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
private static final String TAG = "EbCMessageApp";
public static GoogleAccountCredential mCredential;
private static EncounterBasedCommunication ebc = null;
public static EncounterBasedCommunication ebc = null;
public static EncounterBasedCommunication getEbC(Context context){
public EncounterBasedCommunication getEbC(Context context){
if (ebc == null) {
ebc = EncounterBasedCommunication.getInstance();
ebc.initialize(context, R.raw.ebc_config);
......@@ -58,6 +59,8 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
ebc.getUserAccountClient().loginAccountWithGoogle(mCredential.getToken());
ebc.getSDDRClient().startFormingEncounters();
ebc.getSDDRClient().confirmAndCommunicateUsingNetwork();
} catch (UserRecoverableAuthIOException e) {
startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
} catch (IOException | GoogleAuthException e) {
Log.d("EBC ERROR", e.getMessage());
e.printStackTrace();
......@@ -148,6 +151,7 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
REQUEST_PERMISSION_GET_ACCOUNTS,
Manifest.permission.GET_ACCOUNTS);
}
}
public void getLocationPermissions() {
......
......@@ -29,7 +29,7 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import static org.mpisws.ebcmessageapp.MainActivity.getEbC;
import static org.mpisws.ebcmessageapp.MainActivity.ebc;
import static org.mpisws.ebcmessageapp.recving.MessageView.HIDDEN_TEXT_ID;
import static org.mpisws.ebcmessageapp.recving.MessageView.MSG_TEXT_ID;
import static org.mpisws.helpers.Utils.objFromString;
......@@ -72,12 +72,12 @@ public class GetMessagesFragment extends Fragment {
String msgTxt = ((TextView) layout.findViewById(R.id.subject)).getText().toString()
+ ": " + ((TextView) layout.findViewById(R.id.message)).getText().toString();
Log.d("SENDING REPLY", msgTxt + " to " + finalRmw.getEncounterID());
getEbC(getContext()).getCommunicationClient().replyToMessage(msgTxt, finalRmw);
ebc.getCommunicationClient().replyToMessage(msgTxt, finalRmw);
});
if (rmw.getMsgType() == ReceivedMessageWrapper.MsgTyp.PRIVATE_MESSAGE) {
builder.setNegativeButton("GET CHANNEL MSGS", (dialog12, whichButton) -> {
Log.d("GETTING MESSAGES from ", finalRmw.getEncounterID());
getEbC(getContext()).getCommunicationClient().getConversationOnPrivateChannel(finalRmw.getEncounterID(),
ebc.getCommunicationClient().getConversationOnPrivateChannel(finalRmw.getEncounterID(),
new ESClient.GetReceivedMessagesCallback() {
@Override
public void processReceivedMessages(List<ReceivedMessageWrapper> msgs) {
......@@ -174,7 +174,7 @@ public class GetMessagesFragment extends Fragment {
}
}
};
getEbC(getContext()).getCommunicationClient().getUnreadMsgs(callback);
ebc.getCommunicationClient().getUnreadMsgs(callback);
synchronized(notifyObject) {
if (!done[0]) notifyObject.wait();
}
......
......@@ -19,7 +19,7 @@ import java.io.IOException;
import java.util.List;
import java.util.Locale;
import static org.mpisws.ebcmessageapp.MainActivity.getEbC;
import static org.mpisws.ebcmessageapp.MainActivity.ebc;
import static org.mpisws.helpers.Utils.objToString;
class MessageView extends LinearLayout {
......@@ -52,7 +52,7 @@ class MessageView extends LinearLayout {
switch(message.getMsgType()) {
case ENCOUNTER_FORWARDING_MESSAGE:
Pair<List<MLocation>, TimeInterval> encInfo = getEbC(getContext()).getSDDRClient().getEncounterInfoFromEID(message.getEncounterID());
Pair<List<MLocation>, TimeInterval> encInfo = ebc.getSDDRClient().getEncounterInfoFromEID(message.getEncounterID());
// try and get location
if (encInfo.getLeft().size() != 0) {
Geocoder geocoder = new Geocoder(getContext(), Locale.getDefault());
......
......@@ -30,6 +30,7 @@ import com.google.api.services.calendar.model.Event;
import com.google.api.services.calendar.model.Events;
import org.mpisws.ebcmessageapp.R;
import org.mpisws.messaging.constraints.AllEncountersConstraint;
import org.mpisws.messaging.constraints.EncounterQueryConstraint;
import org.mpisws.messaging.constraints.SpaceTimeIntersectConstraint;
......@@ -39,9 +40,9 @@ import java.time.ZoneOffset;
import java.util.List;
import java.util.regex.Pattern;
import static org.mpisws.ebcmessageapp.MainActivity.ebc;
import static org.mpisws.ebcmessageapp.sending.CalEventView.HIDDEN_TEXT_ID;
import static org.mpisws.ebcmessageapp.MainActivity.REQUEST_AUTHORIZATION;
import static org.mpisws.ebcmessageapp.MainActivity.getEbC;
import static org.mpisws.ebcmessageapp.MainActivity.mCredential;
import static org.mpisws.ebcmessageapp.MainActivity.showGooglePlayServicesAvailabilityErrorDialog;
......@@ -93,9 +94,10 @@ public class SendMessagesFragment extends Fragment {
Log.d("Message", msgTxt);
// TODO
//AllEncountersConstraint allconstraint = new AllEncountersConstraint();
AllEncountersConstraint allconstraint = new AllEncountersConstraint();
// enabling replies
getEbC(getContext()).getCommunicationClient().sendDirectMessageToEncounters(msgTxt, constraint, true);
ebc.getSDDRClient().updateDatabaseOnAgent();
ebc.getCommunicationClient().sendDirectMessageToEncounters(msgTxt, allconstraint, true);
})
.setNegativeButton("Cancel", (dialog12, whichButton) -> {
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment