Skip to content

Commit

Permalink
fixed #769: Implemented, FcmConfigurationClient added finally block f…
Browse files Browse the repository at this point in the history
…or disconnet the ongoing connection
  • Loading branch information
Ognjen Manevski committed Dec 12, 2017
1 parent 26e7304 commit a503b33
Show file tree
Hide file tree
Showing 6 changed files with 270 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,26 @@
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.SwitchCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.restcomm.android.olympus.Util.Utils;
import org.restcomm.android.sdk.RCDevice;

/**
* A login screen that offers Restcomm login.
*/
public class SigninActivity extends AppCompatActivity {
public class SigninActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {

SharedPreferences prefs;
// UI references.
Expand All @@ -59,6 +63,15 @@ public class SigninActivity extends AppCompatActivity {

//SharedPreferences prefsGeneral = null;

//push notifications
private SwitchCompat switchCompat;
private EditText txtPushAccount;
private EditText txtPushPassword;
private EditText txtPushDomain;
private EditText txtHttpDomain;
private LinearLayout llPushContainer;


@Override
protected void onCreate(Bundle savedInstanceState)
{
Expand Down Expand Up @@ -127,6 +140,22 @@ public void onClick(View view)
txtUsername.setText(prefs.getString(RCDevice.ParameterKeys.SIGNALING_USERNAME, ""));
txtDomain.setText(prefs.getString(RCDevice.ParameterKeys.SIGNALING_DOMAIN, ""));
txtPassword.setText(prefs.getString(RCDevice.ParameterKeys.SIGNALING_PASSWORD, ""));

llPushContainer = (LinearLayout) findViewById(R.id.ll_push_container);
switchCompat = (SwitchCompat) findViewById(R.id.switch_enable_push);
txtPushAccount = (EditText) findViewById(R.id.push_account_email);
txtPushPassword = (EditText) findViewById(R.id.push_password);
txtPushDomain = (EditText) findViewById(R.id.push_domain);
txtHttpDomain = (EditText) findViewById(R.id.http_domain);

switchCompat.setChecked(prefs.getBoolean(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_ENABLE_PUSH_FOR_ACCOUNT, true));
txtPushAccount.setText(prefs.getString(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_ACCOUNT_EMAIL, ""));
txtPushPassword.setText(prefs.getString(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_ACCOUNT_PASSWORD, ""));
txtPushDomain.setText(prefs.getString(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_PUSH_DOMAIN, ""));
txtHttpDomain.setText(prefs.getString(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_HTTP_DOMAIN, ""));

switchCompat.setOnCheckedChangeListener(this);

}
}

Expand All @@ -139,8 +168,10 @@ private void attemptLogin()

// Store values at the time of the login attempt.
String username = txtUsername.getText().toString();
String password = txtPassword.getText().toString();
String domain = txtDomain.getText().toString();
boolean pushEnabled = switchCompat.isChecked();
String pushDomain = txtPushDomain.getText().toString();
String httpDomain = txtHttpDomain.getText().toString();

boolean cancel = false;
View focusView = null;
Expand All @@ -167,12 +198,37 @@ else if (domain.contains(" ")) {
cancel = true;
}

if (pushEnabled && !cancel){
if (!Utils.isValidEmail(txtPushAccount.getText())){
txtPushAccount.setError(getString(R.string.error_invalid_email));
focusView = txtPushAccount;
cancel = true;
} else if (TextUtils.isEmpty(pushDomain)){
txtPushDomain.setError(getString(R.string.error_field_required));
focusView = txtPushDomain;
cancel = true;
} else if (TextUtils.isEmpty(httpDomain)){
txtHttpDomain.setError(getString(R.string.error_field_required));
focusView = txtHttpDomain;
cancel = true;
} else if (pushDomain.contains(" ")) {
txtPushDomain.setError(getString(R.string.error_field_no_whitespace));
focusView = txtPushDomain;
cancel = true;
} else if (httpDomain.contains(" ")) {
txtHttpDomain.setError(getString(R.string.error_field_no_whitespace));
focusView = txtHttpDomain;
cancel = true;
}
}

if (cancel) {
// There was an error; don't attempt login and focus the first
// form field with an error.
focusView.requestFocus();
}
else {

// note down the fact that we are signed up so that
globalPreferences.setSignedUp(true);

Expand All @@ -198,17 +254,28 @@ private void updatePrefs()
//push settings
/*** IMPORTANT ***/
/** Push notifications will not work if these parameters are replaced with real values: **/
/** ACCOUNT EMAIL, ACCOUNT PASSWORD, FCM SERVER KEY **/
/** PUSH_NOTIFICATIONS_APPLICATION_NAME, PUSH_NOTIFICATIONS_FCM_SERVER_KEY **/
prefEdit.putString(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_APPLICATION_NAME, "Olympus");
prefEdit.putString(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_ACCOUNT_EMAIL, "ACCOUNT EMAIL");
prefEdit.putString(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_ACCOUNT_PASSWORD, "ACCOUNT PASSWORD");
prefEdit.putBoolean(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_ENABLE_PUSH_FOR_ACCOUNT, true);
prefEdit.putString(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_PUSH_DOMAIN, "push.restcomm.com");
prefEdit.putString(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_HTTP_DOMAIN, "cloud.restcomm.com");
prefEdit.putString(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_FCM_SERVER_KEY, "FCM SERVER KEY");

prefEdit.putString(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_ACCOUNT_EMAIL, txtPushAccount.getText().toString());
prefEdit.putString(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_ACCOUNT_PASSWORD, txtPushPassword.getText().toString());
prefEdit.putBoolean(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_ENABLE_PUSH_FOR_ACCOUNT, switchCompat.isChecked());
prefEdit.putString(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_PUSH_DOMAIN, txtPushDomain.getText().toString());
prefEdit.putString(RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_HTTP_DOMAIN, txtHttpDomain.getText().toString());



prefEdit.apply();
}

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
llPushContainer.setVisibility(View.VISIBLE);
} else {
llPushContainer.setVisibility(View.GONE);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.olympus.Util;

public class Utils {

public final static boolean isValidEmail(CharSequence target) {
if (target == null) {
return false;
}

return android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,10 @@
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="org.restcomm.android.olympus.SigninActivity">

<!-- Login progress -->
<!--
<ProgressBar
android:id="@+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone"/>
-->

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to \nRestcomm Olympus"
android:text="@string/welcome_to_olympus"
android:id="@+id/label_call"
android:layout_marginTop="0dp"
android:layout_marginBottom="15dp"
Expand All @@ -50,7 +39,7 @@
android:id="@+id/signin_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username, like 'bob'"
android:hint="@string/username"
android:inputType="text"
android:maxLines="1"
android:singleLine="true"/>
Expand All @@ -65,7 +54,7 @@
android:id="@+id/signin_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:hint="@string/password"
android:imeActionId="@+id/login"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
Expand All @@ -83,20 +72,95 @@
android:id="@+id/signin_domain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Domain, like 'cloud.restcomm.com'"
android:hint="@string/domain"
android:inputType="text"
android:maxLines="1"
android:singleLine="true"/>

</android.support.design.widget.TextInputLayout>

<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_enable_push"
android:layout_marginStart="4dp"
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/enable_push_notifications"/>

<LinearLayout
android:id="@+id/ll_push_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/push_account_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/push_account_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true"/>

</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/push_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/push_account_password"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true"/>

</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/push_domain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/push_domain"
android:inputType="text"
android:maxLines="1"
android:singleLine="true"/>

</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/http_domain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/http_domain"
android:inputType="text"
android:maxLines="1"
android:singleLine="true"/>

</android.support.design.widget.TextInputLayout>

</LinearLayout>
<Button
android:id="@+id/signin_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Sign in"
android:text="@string/sign_in"
android:textStyle="bold"
android:textColor="@color/colorButtonWhite"
android:backgroundTint="@color/colorPrimary" />
Expand Down
13 changes: 13 additions & 0 deletions Examples/restcomm-olympus/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,17 @@
<string name="pref_displayhud_default" translatable="false">false</string>
-->

<!-- sign in activity -->
<string name="welcome_to_olympus">Welcome to \nRestcomm Olympus</string>
<string name="username">"Username, like \'bob\'</string>
<string name="password">Password</string>
<string name="domain">Domain, like \'cloud.restcomm.com\'</string>
<string name="sign_in">Sign in</string>
<string name="enable_push_notifications">Enable push notifications</string>
<string name="push_account_email">Restcomm-Connect account email</string>
<string name="push_account_password">Password for Restcomm-Connect account</string>
<string name="push_domain">Push domain, like: \'push.restcomm.com\'</string>
<string name="http_domain">Http domain, like: \'cloud.restcomm.com\'</string>


</resources>

0 comments on commit a503b33

Please sign in to comment.