Skip to content

Commit

Permalink
Some additional impacts on #568: Improve Olympus messages activity to…
Browse files Browse the repository at this point in the history
… use CursorAdapter to load messages instead of SimpleAdapter
  • Loading branch information
Antonis committed May 11, 2017
1 parent bda6e0c commit 266d05c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 27 deletions.
Expand Up @@ -24,7 +24,6 @@
package org.restcomm.android.olympus;

import android.app.AlertDialog;
import android.app.DialogFragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
Expand All @@ -33,7 +32,6 @@
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
Expand All @@ -42,17 +40,15 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import org.restcomm.android.sdk.RCClient;
import org.restcomm.android.sdk.RCConnection;
import org.restcomm.android.sdk.RCDevice;
import org.restcomm.android.sdk.RCDeviceListener;
import org.restcomm.android.sdk.RCPresenceEvent;
import org.restcomm.android.sdk.util.RCException;

import java.util.HashMap;

Expand Down Expand Up @@ -263,15 +259,15 @@ public void onClick(View view)
HashMap<String, String> sendParams = new HashMap<String, String>();
String connectionPeer = (String) params.get(RCConnection.ParameterKeys.CONNECTION_PEER);
sendParams.put(RCConnection.ParameterKeys.CONNECTION_PEER, connectionPeer);
RCDevice.MessageStatus messageStatus = device.sendMessage(txtMessage.getText().toString(), sendParams);
if (messageStatus.status) {
try {
String jobId = device.sendMessage(txtMessage.getText().toString(), sendParams);
// also output the message in the wall
int index = listFragment.addLocalMessage(txtMessage.getText().toString(), connectionPeer.replaceAll("^sip:", "").replaceAll("@.*$", ""),
messageStatus.jobId);
listFragment.addLocalMessage(txtMessage.getText().toString(), connectionPeer.replaceAll("^sip:", "").replaceAll("@.*$", ""),
jobId);
//indexes.put(messageStatus.jobId, index);
txtMessage.setText("");
//txtWall.append("Me: " + txtMessage.getText().toString() + "\n\n");
} else {
} catch (RCException e) {
showOkAlert("RCDevice Error", "No Wifi connectivity");
}
}
Expand Down
Expand Up @@ -87,6 +87,7 @@ public enum ErrorCodes {
ERROR_MESSAGE_PEER_NOT_FOUND,
ERROR_MESSAGE_SERVICE_UNAVAILABLE,
ERROR_MESSAGE_UNTRUSTED_SERVER,
ERROR_MESSAGE_SEND_FAILED_DEVICE_OFFLINE,
}

/**
Expand Down Expand Up @@ -238,6 +239,9 @@ else if (errorCode == ErrorCodes.ERROR_MESSAGE_PEER_NOT_FOUND) {
else if (errorCode == ErrorCodes.ERROR_MESSAGE_SERVICE_UNAVAILABLE) {
return "Failed to send message; service is unavailable";
}
else if (errorCode == ErrorCodes.ERROR_MESSAGE_SEND_FAILED_DEVICE_OFFLINE) {
return "Failed to send message; RCDevice is offline";
}

return "Unmapped Restcomm Client error";
}
Expand Down
Expand Up @@ -40,6 +40,7 @@
import org.restcomm.android.sdk.SignalingClient.JainSipClient.JainSipConfiguration;
import org.restcomm.android.sdk.SignalingClient.SignalingClient;
import org.restcomm.android.sdk.util.ErrorStruct;
import org.restcomm.android.sdk.util.RCException;
import org.restcomm.android.sdk.util.RCLogger;
import org.restcomm.android.sdk.util.RCUtils;

Expand Down Expand Up @@ -155,15 +156,6 @@ public enum DeviceCapability {
CLIENT_NAME,
}

public class MessageStatus {
public String jobId;
public boolean status;

MessageStatus(String jobId, boolean status) {
this.jobId = jobId;
this.status = status;
}
}
/**
* Parameter keys for RCClient.createDevice() and RCDevice.updateParams()
*/
Expand Down Expand Up @@ -700,20 +692,21 @@ public RCConnection connect(Map<String, Object> parameters, RCConnectionListener
* @param parameters Parameters used for the message, such as 'username' that holds the recepient for the message
* @return status for the send action
*/
public MessageStatus sendMessage(String message, Map<String, String> parameters)
public String sendMessage(String message, Map<String, String> parameters) throws RCException
{
RCLogger.i(TAG, "sendMessage(): message:" + message + "\nparameters: " + parameters.toString());


if (state == DeviceState.READY) {
if (state != DeviceState.OFFLINE) {
HashMap<String, Object> messageParameters = new HashMap<>();
messageParameters.put(RCConnection.ParameterKeys.CONNECTION_PEER, parameters.get(RCConnection.ParameterKeys.CONNECTION_PEER));
messageParameters.put("text-message", message);
String jobId = signalingClient.sendMessage(messageParameters);
return new MessageStatus(jobId, true);
return signalingClient.sendMessage(messageParameters);
}
else {
return new MessageStatus(null, false);
//return new MessageStatus(null, false);
throw new RCException(RCClient.ErrorCodes.ERROR_MESSAGE_SEND_FAILED_DEVICE_OFFLINE,
RCClient.errorText(RCClient.ErrorCodes.ERROR_MESSAGE_SEND_FAILED_DEVICE_OFFLINE));
}
}

Expand Down
Expand Up @@ -25,8 +25,8 @@
import org.restcomm.android.sdk.RCClient;

class JainSipException extends Exception {
RCClient.ErrorCodes errorCode;
String errorText;
public RCClient.ErrorCodes errorCode;
public String errorText;

JainSipException(RCClient.ErrorCodes errorCode, String errorText)
{
Expand All @@ -43,5 +43,4 @@ class JainSipException extends Exception {
this.initCause(throwable);
}


}
@@ -0,0 +1,46 @@
/*
* TeleStax, Open Source Cloud Communications
* Copyright 2011-2015, Telestax Inc and individual contributors
* by the @authors tag.
*
* This program is free software: you can redistribute it and/or modify
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* For questions related to commercial use licensing, please contact sales@telestax.com.
*
*/

package org.restcomm.android.sdk.util;

import org.restcomm.android.sdk.RCClient;

public class RCException extends Exception {
public RCClient.ErrorCodes errorCode;
public String errorText;

public RCException(RCClient.ErrorCodes errorCode, String errorText)
{
this.errorCode = errorCode;
this.errorText = errorText;
}

// initialize an exception, but also chain another exception to it
public RCException(RCClient.ErrorCodes errorCode, String errorText, Throwable throwable)
{
this.errorCode = errorCode;
this.errorText = errorText;

this.initCause(throwable);
}

}

0 comments on commit 266d05c

Please sign in to comment.