Add inapp purchase

Add account creator
This commit is contained in:
Margaux Clerc 2016-08-09 13:21:34 +02:00
parent 375d2eb2dd
commit 5b264a6685
20 changed files with 821 additions and 313 deletions

View file

@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.linphone"
android:versionCode="3100" android:installLocation="auto">
android:versionCode="3120" android:installLocation="auto">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23"/>
<!-- Permissions for Push Notification -->

View file

@ -1,4 +1,4 @@
source.dir=src:submodules/linphone/mediastreamer2/java/src:submodules/linphone/java/j2se:submodules/linphone/java/common:submodules/linphone/java/impl:submodules/linphone/coreapi/help/java
key.store=bc-android.keystore
key.alias=nw8000
version.name=2.5.0
version.name=3.1.2

69
res/layout/in_app.xml Normal file
View file

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/colorH"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/status"
android:name="org.linphone.StatusFragment"
android:layout_width="match_parent"
android:layout_height="40dp"
tools:layout="@layout/status"/>
<LinearLayout
android:id="@+id/topbar"
android:background="@color/colorF"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="60dp">
<ImageView
android:id="@+id/back"
android:src="@drawable/back"
android:background="@drawable/toolbar_button"
android:contentDescription="@string/content_description_back"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="18dp"/>
<TextView
android:text="@string/inapp"
style="@style/font1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:gravity="center"/>
<ImageView
android:id="@+id/cancel"
android:src="@drawable/dialer_back"
android:background="@drawable/toolbar_button"
android:contentDescription="@string/content_description_dialer_back"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="15dp"/>
</LinearLayout>
<ProgressBar
android:id="@+id/purchaseItemsFetchInProgress"
style="?android:attr/progressBarStyle"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_below="@+id/topbar"/>
</RelativeLayout>

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/inapp_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@color/colorE"
android:cacheColorHint="@color/transparent"
android:dividerHeight="1dp" />
</LinearLayout>

View file

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" >
<Button
android:id="@+id/inapp_button"
android:text="@string/assistant_create_account"
android:background="@drawable/assistant_button"
style="@style/font8"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_width="match_parent"
android:layout_height="40dp"/>
</LinearLayout>

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/inapp_purchase"
android:background="@color/colorH"
android:layout_width="match_parent"
android:layout_height="60dp">
<ImageView
android:id="@+id/inapp_icon"
android:src="@drawable/linphone_logo"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:layout_margin="5dp"
android:layout_width="40dp"
android:layout_height="40dp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/inapp_icon">
<TextView
android:id="@+id/purchase_title"
style="@style/font7"
android:textSize="15sp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:id="@+id/purchase_description"
style="@style/font11"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<TextView
android:id="@+id/purchase_price"
android:layout_margin="5dp"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>

View file

@ -6,26 +6,8 @@
android:orientation="vertical" >
<LinearLayout
android:id="@+id/topbar"
android:background="@color/colorF"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="60dp">
<TextView
android:text="@string/assistant"
style="@style/font1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:padding="30dp"
android:gravity="center"
android:orientation="vertical">
@ -90,21 +72,17 @@
android:singleLine="true"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/purchasable_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="40dp"
android:gravity="center"
android:orientation="vertical"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
<Button
android:id="@+id/inapp_button"
android:text="@string/assistant_create_account"
android:background="@drawable/assistant_button"
style="@style/font8"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
</LinearLayout>
android:paddingRight="10dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="40dp"/>
</LinearLayout>

View file

@ -37,5 +37,15 @@ max_calls=10
activation_code_length=4
[in-app-purchase]
server_url=https://www.linphone.org/xmlrpc.php
server_url=http://sip3.linphone.org/inapp.php
purchasable_items_ids=test_account_subscription
[assistant]
domain=sip.linphone.org
password_max_length=-1
password_min_length=1
username_length=-1
username_max_length=64
username_min_length=1
username_regex=^[a-z0-9_.\-]*$
xmlrpc_url=https://sip3.linphone.org:444/inapp.php

View file

@ -16,8 +16,10 @@
<bool name="replace_assistant_with_old_interface">false</bool>
<bool name="force_use_of_linphone_friends">false</bool>
<bool name="in_app_purchase_in_settings">false</bool>
<bool name="use_friendlist_subscription">true</bool>
<string name="wizard_url">https://sip3.linphone.org:444/inapp.php</string>
<string name="wizard_url">https://www.linphone.org/wizard.php</string>
<!-- Push notification settings -->
<bool name="enable_push_id">true</bool>

View file

@ -100,6 +100,26 @@
<string name="select_your_country">Select your Country</string>
<string name="country_code">(%s)</string>
<!-- Status -->
<string name="invalid_email">Invalid email</string>
<string name="account_already_exist">Account already exist</string>
<string name="invalid_username">Invalid username</string>
<string name="invalid_domain">Invalid domain</string>
<string name="invalid_route">Invalid route</string>
<string name="username_too_short">Username too short</string>
<string name="username_too_long">Username too long</string>
<string name="username_invalid_size">Username length invalid</string>
<string name="phone_number_too_long">Phone number too long</string>
<string name="phone_number_too_short">Phone number too short</string>
<string name="phone_number_invalid">Invalid phone number</string>
<string name="password_too_short">Password too short</string>
<string name="password_too_long">Password too long</string>
<string name="request_failed">Failed to query the server. Please try again later</string>
<string name="transport_unsupported">Unsupported transport</string>
<!-- In-app -->
<string name="inapp">in-app</string>
<!-- Dailer -->
<string name="address_bar_hint">Enter a number or an address</string>

View file

@ -48,7 +48,11 @@ import org.linphone.core.LinphoneCoreListenerBase;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.Reason;
import org.linphone.mediastream.Log;
import org.linphone.purchase.InAppPurchaseActivity;
import org.linphone.purchase.InAppPurchaseHelper;
import org.linphone.ui.AddressText;
import org.linphone.xmlrpc.XmlRpcHelper;
import org.linphone.xmlrpc.XmlRpcListenerBase;
import android.Manifest;
import android.annotation.SuppressLint;
@ -197,6 +201,10 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
initButtons();
initSideMenu();
//ifINAP
getTrialAccount();
getExpirationAccount();
currentFragment = FragmentsAvailable.EMPTY;
if (savedInstanceState == null) {
changeCurrentFragment(FragmentsAvailable.DIALER, getIntent().getExtras());
@ -619,6 +627,10 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
startActivity(new Intent(LinphoneActivity.this, AssistantActivity.class));
}
public void displayInapp() {
startActivity(new Intent(LinphoneActivity.this, InAppPurchaseActivity.class));
}
public int getUnreadMessageCount() {
int count = 0;
LinphoneChatRoom[] chats = LinphoneManager.getLc().getChatRooms();
@ -1438,8 +1450,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
}
public void initSideMenu() {
sideMenu = (DrawerLayout) findViewById(R.id.side_menu);
sideMenuItems = new String[]{getResources().getString(R.string.menu_assistant),getResources().getString(R.string.menu_settings),getResources().getString(R.string.menu_about)};
sideMenuItems = new String[]{getResources().getString(R.string.menu_assistant),getResources().getString(R.string.menu_settings),getResources().getString(R.string.menu_about),"Inapp"};
sideMenuContent = (RelativeLayout) findViewById(R.id.side_menu_content);
sideMenuItemList = (ListView)findViewById(R.id.item_list);
menu = (ImageView) findViewById(R.id.side_menu_button);
@ -1457,6 +1470,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
if (sideMenuItemList.getAdapter().getItem(i).toString().equals(getString(R.string.menu_assistant))) {
LinphoneActivity.instance().displayAssistant();
}
if (sideMenuItemList.getAdapter().getItem(i).toString().equals("Inapp")) {
LinphoneActivity.instance().displayInapp();
}
openOrCloseSideMenu(false);
}
});
@ -1538,6 +1554,8 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
}
}
public void refreshAccounts(){
if (LinphoneManager.getLc().getProxyConfigList().length > 1) {
accountsList.setVisibility(View.VISIBLE);
@ -1628,6 +1646,66 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
return view;
}
}
//Inapp Purchase
private void getTrialAccount() {
if(LinphoneManager.getLc().getDefaultProxyConfig() != null) {
XmlRpcHelper helper = new XmlRpcHelper();
helper.isTrialAccountAsync(new XmlRpcListenerBase() {
@Override
public void onTrialAccountFetched(boolean isTrial) {
if(isTrial){
displayInappDialog();
}
}
}, LinphonePreferences.instance().getAccountUsername(0), LinphonePreferences.instance().getAccountHa1(0));
}
}
private void getExpirationAccount() {
if(LinphoneManager.getLc().getDefaultProxyConfig() != null) {
XmlRpcHelper helper = new XmlRpcHelper();
helper.getAccountExpireAsync(new XmlRpcListenerBase() {
@Override
public void onAccountExpireFetched(String result) {
Log.w("RESULT " + result);
}
}, LinphonePreferences.instance().getAccountUsername(0), LinphonePreferences.instance().getAccountHa1(0));
}
}
public Dialog displayInappDialog(){
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.colorC));
d.setAlpha(200);
dialog.setContentView(R.layout.input_dialog);
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
dialog.getWindow().setBackgroundDrawable(d);
TextView customText = (TextView) dialog.findViewById(R.id.customText);
customText.setText(getString(R.string.error_bad_credentials));
Button retry = (Button) dialog.findViewById(R.id.retry);
Button cancel = (Button) dialog.findViewById(R.id.cancel);
retry.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
}
});
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
return dialog;
}
}
interface ContactPicked {

View file

@ -419,7 +419,6 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
friend.edit();
friend.setFamilyName(lastName);
friend.setGivenName(firstName);
friend.setName(fullName);
for (LinphoneAddress address : friend.getAddresses()) {
friend.removeAddress(address);
@ -444,10 +443,15 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
friend.addPhoneNumber(noa.getValue());
}
}
if (friend.getAddress() != null) {
friend.setName(fullName);
}
friend.done();
if (friend.getAddress() != null) {
if (lc.findFriendByAddress(friend.getAddress().asString()) == null) {
try {
LinphoneManager.getLcIfManagerNotDestroyedOrNull().addFriend(friend);
lc.addFriend(friend);
if (!ContactsManager.getInstance().hasContactsAccess()) {
// This refresh is only needed if app has no contacts permission to refresh the list of LinphoneFriends.
// Otherwise contacts will be refreshed due to changes in native contact and the handler in ContactsManager
@ -457,6 +461,8 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
Log.e(e);
}
}
}
}
public void save() {
if (isAndroidContact() && ContactsManager.getInstance().hasContactsAccess() && changesToCommit.size() > 0) {

View file

@ -26,6 +26,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.linphone.core.LinphoneAccountCreator;
import org.linphone.core.LinphoneAccountCreatorImpl;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneAddress.TransportType;
import org.linphone.core.LinphoneAuthInfo;
@ -192,6 +194,11 @@ public class LinphonePreferences {
getLc().addAuthInfo(authInfo);
}
public LinphoneAccountCreator AccountCreator(LinphoneCore lc, String server_url) {
return new LinphoneAccountCreatorImpl(lc, server_url);
}
public static class AccountBuilder {
private LinphoneCore lc;
private String tempUsername;
@ -537,6 +544,12 @@ public class LinphonePreferences {
LinphoneAuthInfo authInfo = getAuthInfo(n);
return authInfo == null ? null : authInfo.getPassword();
}
public String getAccountHa1(int n) {
LinphoneAuthInfo authInfo = getAuthInfo(n);
return authInfo == null ? null : authInfo.getHa1();
}
public void setAccountDomain(int n, String domain) {
String identity = "sip:" + getAccountUsername(n) + "@" + domain;
LinphoneAuthInfo old_info = getAuthInfo(n);

View file

@ -25,6 +25,8 @@ import org.linphone.LinphoneUtils;
import org.linphone.LinphonePreferences.AccountBuilder;
import org.linphone.R;
import org.linphone.StatusFragment;
import org.linphone.core.LinphoneAccountCreator;
import org.linphone.core.LinphoneAccountCreatorImpl;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneAddress.TransportType;
import org.linphone.core.LinphoneCore;
@ -113,8 +115,6 @@ private static AssistantActivity instance;
mPrefs = LinphonePreferences.instance();
status.enableSideMenu(false);
checkAndRequestReadPhoneState();
mListener = new LinphoneCoreListenerBase() {
@Override
public void registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, RegistrationState state, String smessage) {
@ -465,6 +465,7 @@ private static AssistantActivity instance;
.setRealm("sip.linphone.org")
.setNoDefault(false);
mPrefs.enabledFriendlistSubscription(getResources().getBoolean(R.bool.use_friendlist_subscription));
mPrefs.setStunServer(getString(R.string.default_stun));
mPrefs.setIceEnabled(true);

View file

@ -23,6 +23,8 @@ import java.util.regex.Pattern;
import org.linphone.LinphoneManager;
import org.linphone.R;
import org.linphone.core.LinphoneAccountCreator;
import org.linphone.core.LinphoneAccountCreatorImpl;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.LinphoneXmlRpcRequest;
import org.linphone.core.LinphoneXmlRpcRequest.LinphoneXmlRpcRequestListener;
@ -30,6 +32,7 @@ import org.linphone.core.LinphoneXmlRpcRequestImpl;
import org.linphone.core.LinphoneXmlRpcSession;
import org.linphone.core.LinphoneXmlRpcSessionImpl;
import org.linphone.xmlrpc.XmlRpcHelper;
import org.linphone.mediastream.Log;
import android.Manifest;
import android.accounts.Account;
@ -54,10 +57,13 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import static org.linphone.core.LinphoneAccountCreator.*;
/**
* @author Sylvain Berfini
*/
public class CreateAccountFragment extends Fragment implements CompoundButton.OnCheckedChangeListener, OnClickListener {
public class CreateAccountFragment extends Fragment implements CompoundButton.OnCheckedChangeListener, OnClickListener, LinphoneAccountCreatorListener {
private Handler mHandler = new Handler();
private EditText phoneNumberEdit, usernameEdit, passwordEdit, passwordConfirmEdit, emailEdit, dialCode;
private TextView phoneNumberError, usernameError, passwordError, passwordConfirmError, emailError, sipUri;
@ -74,6 +80,8 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
private LinphoneXmlRpcSession xmlRpcSession;
private CountryListFragment.Country country;
private LinphoneAccountCreator accountCreator;
private String getUsername() {
String username = usernameEdit.getText().toString();
return username.toLowerCase(Locale.getDefault());
@ -93,6 +101,9 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.assistant_account_creation, container, false);
accountCreator = new LinphoneAccountCreatorImpl(LinphoneManager.getLc(), getResources().getString(R.string.wizard_url));
accountCreator.setListener(this);
phoneNumberError = (TextView) view.findViewById(R.id.phone_number_error);
phoneNumberEdit = (EditText) view.findViewById(R.id.phone_number);
phoneNumberEdit.addTextChangedListener(new TextWatcher() {
@ -107,7 +118,7 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
public void afterTextChanged(Editable s) {}
});
phoneNumberLayout = (LinearLayout) view.findViewById(R.id.phone_number_layout);
addXMLRPCPhoneNumberHandler(phoneNumberEdit, null);
addPhoneNumberHandler(phoneNumberEdit, null);
selectCountry = (Button) view.findViewById(R.id.select_country);
selectCountry.setOnClickListener(this);
@ -144,7 +155,7 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
public void afterTextChanged(Editable s) {}
});
usernameLayout = (LinearLayout) view.findViewById(R.id.username_layout);
addXMLRPCUsernameHandler(usernameEdit, null);
addUsernameHandler(usernameEdit, null);
}
if(getResources().getBoolean(R.bool.isTablet)){
@ -332,60 +343,6 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
xmlRpcSession.sendRequest(xmlRpcRequest);
}
private void isPhoneNumberRegistred(final String username, final ImageView icon) {
final Runnable runOk = new Runnable() {
public void run() {
phoneNumberOk = false;
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, LinphoneManager.getInstance().getContext().getString(R.string.assistant_phone_number_unavailable));
//createAccount.setEnabled(phoneNumberOk);
}
};
final Runnable runNotOk = new Runnable() {
public void run() {
phoneNumberOk = true;
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, "");
createAccount.setEnabled(phoneNumberOk);
}
};
final Runnable runNotReachable = new Runnable() {
public void run() {
phoneNumberOk = false;
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, LinphoneManager.getInstance().getContext().getString(R.string.wizard_server_unavailable));
createAccount.setEnabled(phoneNumberOk);
}
};
LinphoneXmlRpcRequest xmlRpcRequest = new LinphoneXmlRpcRequestImpl("is_phone_number_used", LinphoneXmlRpcRequest.ArgType.String);
xmlRpcRequest.setListener(new LinphoneXmlRpcRequestListener() {
@Override
public void onXmlRpcRequestResponse(LinphoneXmlRpcRequest request) {
if (request.getStatus() == LinphoneXmlRpcRequest.Status.Ok) {
final String response = request.getStringResponse();
if (response.equals(XmlRpcHelper.SERVER_RESPONSE_OK)) {
mHandler.post(runOk);
} else {
if(response.startsWith("ERROR")){
mHandler.post(new Runnable() {
@Override
public void run() {
phoneNumberOk = false;
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, response);
//createAccount.setEnabled(phoneNumberOk);
}
});
} else {
mHandler.post(runNotOk);
}
}
} else if (request.getStatus() == LinphoneXmlRpcRequest.Status.Failed) {
mHandler.post(runNotReachable);
}
}
});
xmlRpcRequest.addStringArg(username);
xmlRpcSession.sendRequest(xmlRpcRequest);
}
private boolean isEmailCorrect(String email) {
Pattern emailPattern = Patterns.EMAIL_ADDRESS;
return emailPattern.matcher(email).matches();
@ -477,29 +434,36 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
xmlRpcSession.sendRequest(xmlRpcRequest);
}
private void addXMLRPCPhoneNumberHandler(final EditText field, final ImageView icon) {
private void addPhoneNumberHandler(final EditText field, final ImageView icon) {
field.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
if (s.length() > 0) {
phoneNumberOk = false;
String phoneNumber = getPhoneNumber();
if (LinphoneManager.getLc().createProxyConfig().isPhoneNumber(phoneNumber)) {
isPhoneNumberRegistred(phoneNumber, icon);
String countryCode = dialCode.getText().toString();
if(countryCode != null && countryCode.startsWith("+")) {
countryCode = countryCode.substring(1);
}
Status status = accountCreator.setPhoneNumber(phoneNumberEdit.getText().toString(), countryCode);
if(status.equals(Status.Ok)){
accountCreator.isAccountUsed();
} else {
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, getResources().getString(R.string.wizard_username_incorrect));
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, errorForStatus(status));
}
} else {
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, "");
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int count, int after) {
}
});
}
private void addXMLRPCUsernameHandler(final EditText field, final ImageView icon) {
private void addUsernameHandler(final EditText field, final ImageView icon) {
field.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
Matcher matcher = UPPER_CASE_REGEX.matcher(s);
@ -514,20 +478,14 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
}
public void onTextChanged(CharSequence s, int start, int count, int after) {
field.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
if(s.length() > 0){
usernameOk = false;
String username = field.getText().toString();
if (isUsernameCorrect(username)) {
if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) {
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
username = lpc.normalizePhoneNumber(username);
}
isUsernameRegistred(username, icon);
Status status = accountCreator.setUsername(field.getText().toString());
if(status.equals(Status.Ok)){
accountCreator.setPhoneNumber(null,null);
accountCreator.isAccountUsed();
} else {
displayError(usernameOk, usernameError, usernameEdit, getResources().getString(R.string.wizard_username_incorrect));
displayError(usernameOk, usernameError, usernameEdit, errorForStatus(status));
}
} else {
displayError(true, usernameError, usernameEdit, "");
@ -535,8 +493,6 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
}
});
}
});
}
private void addXMLRPCEmailHandler(final EditText field, final ImageView icon) {
field.addTextChangedListener(new TextWatcher() {
@ -631,4 +587,96 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
field1.addTextChangedListener(passwordListener);
field2.addTextChangedListener(passwordListener);
}
String errorForStatus(Status status) {
boolean isPhoneNumber = (phoneNumberEdit.getText().length() > 0);
if (status.equals(Status.EmailInvalid))
return getString(R.string.invalid_email);
if (status.equals(Status.UsernameInvalid)){
return getString(R.string.invalid_username);
}
if (status.equals(Status.UsernameTooShort)){
return getString(R.string.username_too_short);
}
if (status.equals(Status.UsernameTooLong)){
return getString(R.string.username_too_long);
}
if (status.equals(Status.UsernameInvalidSize))
return getString(R.string.username_invalid_size);
if (status.equals(Status.PhoneNumberTooShort))
return getString(R.string.phone_number_too_short);
if (status.equals(Status.PhoneNumberTooLong))
return getString(R.string.phone_number_too_long);
if (status.equals(Status.PhoneNumberInvalid))
return getString(R.string.phone_number_invalid);
if (status.equals(Status.PasswordTooShort))
return getString(R.string.username_too_short);
if (status.equals(Status.PasswordTooLong))
return getString(R.string.username_too_long);
if (status.equals(Status.DomainInvalid))
return getString(R.string.invalid_domain);
if (status.equals(Status.RouteInvalid))
return getString(R.string.invalid_route);
if (status.equals(Status.DisplayNameInvalid))
return getString(R.string.invalid_route);
if (status.equals(Status.Failed))
return getString(R.string.request_failed);
if (status.equals(Status.TransportNotSupported))
return getString(R.string.transport_unsupported);
if (status.equals(Status.AccountExist))
return getString(R.string.account_already_exist);
if (status.equals(Status.AccountCreated)
|| status.equals(Status.AccountNotCreated)
|| status.equals(Status.AccountNotExist)
|| status.equals(Status.AccountNotActivated)
|| status.equals(Status.AccountAlreadyActivated)
|| status.equals(Status.AccountActivated)
|| status.equals(Status.Ok)){
return "";
}
return null;
}
@Override
public void onAccountCreatorIsAccountUsed(LinphoneAccountCreator accountCreator, final Status status) {
if(useUsername.isChecked()){
if (status.equals(Status.AccountNotExist)) {
usernameOk = true;
displayError(usernameOk, usernameError, usernameEdit, errorForStatus(status));
} else {
usernameOk = false;
displayError(usernameOk, usernameError, usernameEdit, errorForStatus(status));
}
createAccount.setEnabled(usernameOk && phoneNumberOk);
} else {
if (status.equals(Status.AccountNotExist)) {
phoneNumberOk = true;
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, errorForStatus(status));
} else {
phoneNumberOk = true;
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, errorForStatus(status));
}
createAccount.setEnabled(phoneNumberOk);
}
}
@Override
public void onAccountCreatorAccountCreated(LinphoneAccountCreator accountCreator, Status status) {
}
@Override
public void onAccountCreatorAccountActivated(LinphoneAccountCreator accountCreator, Status status) {
}
@Override
public void onAccountCreatorAccountLinkedWithPhoneNumber(LinphoneAccountCreator accountCreator, Status status) {
}
@Override
public void onAccountCreatorPhoneNumberLinkActivated(LinphoneAccountCreator accountCreator, Status status) {
}
@Override
public void onAccountCreatorIsAccountActivated(LinphoneAccountCreator accountCreator, Status status) {
}
}

View file

@ -19,80 +19,129 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import java.util.ArrayList;
import java.util.Locale;
import java.util.List;
import org.linphone.LinphoneManager;
import org.linphone.LinphonePreferences;
import org.linphone.R;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.mediastream.Log;
import org.linphone.xmlrpc.XmlRpcHelper;
import org.linphone.xmlrpc.XmlRpcListenerBase;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ImageView;
import android.widget.Toast;
/**
* @author Sylvain Berfini
*/
public class InAppPurchaseActivity extends Activity implements InAppPurchaseListener, OnClickListener {
private static InAppPurchaseActivity instance;
private InAppPurchaseHelper inAppPurchaseHelper;
private LinearLayout purchasableItemsLayout;
private ArrayList<Purchasable> purchasedItems;
private Button buyItemButton, recoverAccountButton;
private Handler mHandler = new Handler();
private ImageView cancel, back;
private EditText username, email;
private TextView errorMessage;
private boolean usernameOk = false;
private List<Purchasable> purchasedItems;
private Fragment fragment;
private Handler mHandler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
inAppPurchaseHelper = new InAppPurchaseHelper(this, this);
setContentView(R.layout.in_app);
setContentView(R.layout.in_app_store);
purchasableItemsLayout = (LinearLayout) findViewById(R.id.purchasable_items);
back = (ImageView) findViewById(R.id.back);
back.setOnClickListener(this);
back.setVisibility(View.INVISIBLE);
cancel = (ImageView) findViewById(R.id.cancel);
cancel.setOnClickListener(this);
username = (EditText) findViewById(R.id.username);
email = (EditText) findViewById(R.id.email);
errorMessage = (TextView) findViewById(R.id.username_error);
addUsernameHandler(username, errorMessage);
instance = this;
}
private void changeFragment(Fragment newFragment) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, newFragment);
transaction.commitAllowingStateLoss();
}
public void displayInappList() {
fragment = new InAppPurchaseListFragment();
changeFragment(fragment);
}
public void displayStore(Purchasable item) {
Bundle extra = new Bundle();
extra.putString("item_id",item.getId());
fragment = new InAppPurchaseFragment();
fragment.setArguments(extra);
changeFragment(fragment);
}
public void buyInapp(String username, Purchasable item){
LinphonePreferences.instance().setInAppPurchasedItem(item);
inAppPurchaseHelper.purchaseItemAsync(item.getId(), username);
}
public String getGmailAccount() {
return inAppPurchaseHelper.getGmailAccount();
}
@Override
protected void onDestroy() {
instance = null;
inAppPurchaseHelper.destroy();
super.onDestroy();
}
public List<Purchasable> getPurchasedItems() {
if (purchasedItems == null || purchasedItems.size() == 0) {
Log.w("nul");
}
return purchasedItems;
}
public Purchasable getPurchasedItem(String id) {
for(Purchasable item : purchasedItems){
if (item.getId().equals(id)){
return item;
}
}
return null;
}
public static InAppPurchaseActivity instance() {
return instance;
}
@Override
public void onServiceAvailableForQueries() {
email.setText(inAppPurchaseHelper.getGmailAccount());
email.setEnabled(false);
//email.setText(inAppPurchaseHelper.getGmailAccount());
//email.setEnabled(false);
inAppPurchaseHelper.getPurchasedItemsAsync();
//inAppPurchaseHelper.getPurchasedItemsAsync();
inAppPurchaseHelper.getAvailableItemsForPurchaseAsync();
}
@Override
public void onAvailableItemsForPurchaseQueryFinished(ArrayList<Purchasable> items) {
purchasableItemsLayout.removeAllViews();
//purchasableItemsLayout.removeAllViews();
purchasedItems = new ArrayList<Purchasable>();
for (Purchasable item : items) {
displayBuySubscriptionButton(item);
purchasedItems.add(item);
}
displayInappList();
}
@Override
@ -104,7 +153,7 @@ public class InAppPurchaseActivity extends Activity implements InAppPurchaseList
} else {
for (Purchasable purchasedItem : purchasedItems) {
Log.d("[In-app purchase] Found already bought item, expires " + purchasedItem.getExpireDate());
displayRecoverAccountButton(purchasedItem);
//displayRecoverAccountButton(purchasedItem);
}
}
}
@ -113,28 +162,26 @@ public class InAppPurchaseActivity extends Activity implements InAppPurchaseList
public void onPurchasedItemConfirmationQueryFinished(boolean success) {
if (success) {
XmlRpcHelper xmlRpcHelper = new XmlRpcHelper();
xmlRpcHelper.createAccountAsync(new XmlRpcListenerBase() {
Purchasable item = LinphonePreferences.instance().getInAppPurchasedItem();
xmlRpcHelper.updateAccountExpireAsync(new XmlRpcListenerBase() {
@Override
public void onAccountCreated(String result) {
public void onAccountExpireUpdated(String result) {
//TODO
}
}, getUsername(), email.getText().toString(), null);
}, LinphonePreferences.instance().getAccountUsername(0), LinphonePreferences.instance().getAccountHa1(0), getString(R.string.default_domain), item.getPayload(), item.getPayloadSignature());
}
}
@Override
public void onClick(View v) {
Purchasable item = (Purchasable) v.getTag();
if (v.equals(recoverAccountButton)) {
XmlRpcHelper xmlRpcHelper = new XmlRpcHelper();
xmlRpcHelper.createAccountAsync(new XmlRpcListenerBase() {
@Override
public void onAccountCreated(String result) {
//TODO
}
}, getUsername(), email.getText().toString(), null);
} else {
inAppPurchaseHelper.purchaseItemAsync(item.getId(), getUsername());
int id = v.getId();
if (id == R.id.cancel) {
finish();
} else if (id == R.id.back) {
onBackPressed();
}
}
@ -145,12 +192,6 @@ public class InAppPurchaseActivity extends Activity implements InAppPurchaseList
@Override
public void onRecoverAccountSuccessful(boolean success) {
mHandler.post(new Runnable() {
@Override
public void run() {
recoverAccountButton.setEnabled(false);
}
});
}
@Override
@ -170,70 +211,4 @@ public class InAppPurchaseActivity extends Activity implements InAppPurchaseList
Log.d("[In-app purchase] Account activated");
}
}
private void displayBuySubscriptionButton(Purchasable item) {
View layout = LayoutInflater.from(this).inflate(R.layout.in_app_purchasable, purchasableItemsLayout);
Button button = (Button) layout.findViewById(R.id.inapp_button);
button.setText("Buy account (" + item.getPrice() + ")");
button.setTag(item);
button.setOnClickListener(this);
XmlRpcHelper xmlRpcHelper = new XmlRpcHelper();
xmlRpcHelper.createAccountAsync(new XmlRpcListenerBase() {
@Override
public void onAccountCreated(String result) {
//TODO
}
}, getUsername(), email.getText().toString(), null);
buyItemButton = button;
buyItemButton.setEnabled(usernameOk);
}
private void displayRecoverAccountButton(Purchasable item) {
View layout = LayoutInflater.from(this).inflate(R.layout.in_app_purchasable, purchasableItemsLayout);
Button button = (Button) layout.findViewById(R.id.inapp_button);
button.setText("Recover account");
button.setTag(item);
button.setOnClickListener(this);
recoverAccountButton = button;
recoverAccountButton.setEnabled(usernameOk);
}
private String getUsername() {
String username = this.username.getText().toString();
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
username = lpc.normalizePhoneNumber(username);
return username.toLowerCase(Locale.getDefault());
}
private boolean isUsernameCorrect(String username) {
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
return lpc.isPhoneNumber(username);
}
private void addUsernameHandler(final EditText field, final TextView errorMessage) {
field.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int count, int after) {
usernameOk = false;
String username = s.toString();
if (isUsernameCorrect(username)) {
usernameOk = true;
errorMessage.setText("");
} else {
errorMessage.setText(R.string.wizard_username_incorrect);
}
if (buyItemButton != null) buyItemButton.setEnabled(usernameOk);
if (recoverAccountButton != null) recoverAccountButton.setEnabled(usernameOk);
}
});
}
}

View file

@ -0,0 +1,150 @@
package org.linphone.purchase;
/*
InAppPurchaseFragment.java
Copyright (C) 2016 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import android.app.Fragment;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.linphone.LinphoneManager;
import org.linphone.LinphonePreferences;
import org.linphone.R;
import org.linphone.mediastream.Log;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.xmlrpc.XmlRpcHelper;
import org.linphone.xmlrpc.XmlRpcListenerBase;
import java.util.Locale;
public class InAppPurchaseFragment extends Fragment implements View.OnClickListener {
private EditText username, email;
private TextView errorMessage;
private boolean usernameOk = false;
private Handler mHandler = new Handler();
private Button buyItemButton, recoverAccountButton;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater mInflater = inflater;
View view = inflater.inflate(R.layout.in_app_store, container, false);
String id = getArguments().getString("item_id");
Purchasable item = InAppPurchaseActivity.instance().getPurchasedItem(id);
Log.w("Item store " + item.getDescription());
buyItemButton = (Button) view.findViewById(R.id.inapp_button);
displayBuySubscriptionButton(item);
username = (EditText) view.findViewById(R.id.username);
username.setText(LinphonePreferences.instance().getAccountUsername(0));
email = (EditText) view.findViewById(R.id.email);
email.setText(InAppPurchaseActivity.instance().getGmailAccount());
errorMessage = (TextView) view.findViewById(R.id.username_error);
addUsernameHandler(username, errorMessage);
return view;
}
private void addUsernameHandler(final EditText field, final TextView errorMessage) {
field.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int count, int after) {
usernameOk = false;
String username = s.toString();
if (isUsernameCorrect(username)) {
usernameOk = true;
errorMessage.setText("");
} else {
errorMessage.setText(R.string.wizard_username_incorrect);
}
if (buyItemButton != null) buyItemButton.setEnabled(usernameOk);
if (recoverAccountButton != null) recoverAccountButton.setEnabled(usernameOk);
}
});
}
private boolean isUsernameCorrect(String username) {
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
return lpc.isPhoneNumber(username);
}
private void displayBuySubscriptionButton(Purchasable item) {
//View layout = LayoutInflater.from(this).inflate(R.layout.in_app_purchasable, purchasableItemsLayout);
//Button button = (Button) layout.findViewById(R.id.inapp_button);
buyItemButton.setText("Buy account (" + item.getPrice() + ")");
buyItemButton.setTag(item);
buyItemButton.setOnClickListener(this);
/*XmlRpcHelper xmlRpcHelper = new XmlRpcHelper();
xmlRpcHelper.createAccountAsync(new XmlRpcListenerBase() {
@Override
public void onAccountCreated(String result) {
//TODO
}
}, getUsername(), email.getText().toString(), null);*/
buyItemButton.setEnabled(usernameOk);
}
@Override
public void onClick(View v) {
Purchasable item = (Purchasable) v.getTag();
if (v.equals(recoverAccountButton)) {
//XmlRpcHelper xmlRpcHelper = new XmlRpcHelper();
/*xmlRpcHelper.createAccountAsync(new XmlRpcListenerBase() {
@Override
public void onAccountCreated(String result) {
//TODO
}
}, getUsername(), email.getText().toString(), null);*/
} else {
InAppPurchaseActivity.instance().buyInapp(getUsername(), item);
}
}
private String getUsername() {
String username = this.username.getText().toString();
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
username = lpc.normalizePhoneNumber(username);
return username.toLowerCase(Locale.getDefault());
}
}

View file

@ -127,14 +127,19 @@ public class InAppPurchaseHelper {
mListener = listener;
mGmailAccount = getGmailAccount();
Log.d("[In-app purchase] creating InAppPurchaseHelper for context "+context.getLocalClassName());
mServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
Log.d("[In-app purchase] onServiceDisconnected!");
mService = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.d("[In-app purchase] onServiceConnected!");
mService = IInAppBillingService.Stub.asInterface(service);
String packageName = mContext.getPackageName();
try {
@ -191,6 +196,7 @@ public class InAppPurchaseHelper {
String desc = object.getString(SKU_DETAILS_DESC);
Purchasable purchasable = new Purchasable(id).setTitle(title).setDescription(desc).setPrice(price);
Log.w("Purchasable item " + purchasable.getDescription());
products.add(purchasable);
} catch (JSONException e) {
Log.e(e);
@ -277,6 +283,10 @@ public class InAppPurchaseHelper {
String payload = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
String signature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);
Purchasable item = LinphonePreferences.instance().getInAppPurchasedItem();
item.setPayloadAndSignature(payload, signature);
LinphonePreferences.instance().setInAppPurchasedItem(item);
XmlRpcHelper xmlRpcHelper = new XmlRpcHelper();
xmlRpcHelper.verifySignatureAsync(new XmlRpcListenerBase() {
@Override

View file

@ -0,0 +1,100 @@
package org.linphone.purchase;
/*
InAppPurchaseListFragment.java
Copyright (C) 2016 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import android.widget.AdapterView;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import org.linphone.R;
import org.linphone.mediastream.Log;
import java.util.List;
public class InAppPurchaseListFragment extends Fragment implements AdapterView.OnItemClickListener{
private ListView inappList;
private LayoutInflater mInflater;
private List<Purchasable> mPurchasableItems;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mInflater = inflater;
View view = inflater.inflate(R.layout.in_app_list, container, false);
mPurchasableItems = InAppPurchaseActivity.instance().getPurchasedItems();
inappList = (ListView) view.findViewById(R.id.inapp_list);
if(mPurchasableItems != null){
inappList.setAdapter(new InAppListAdapter());
inappList.setOnItemClickListener(this);
}
return view;
}
class InAppListAdapter extends BaseAdapter {
InAppListAdapter() {}
public int getCount() {
return mPurchasableItems.size();
}
public Object getItem(int position) {
return mPurchasableItems.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView != null) {
view = convertView;
} else {
view = mInflater.inflate(R.layout.in_app_purchase_item, parent, false);
}
final Purchasable item = mPurchasableItems.get(position);
TextView itemTitle = (TextView) view.findViewById(R.id.purchase_title);
TextView itemDesc = (TextView) view.findViewById(R.id.purchase_description);
TextView itemPrice = (TextView) view.findViewById(R.id.purchase_price);
itemTitle.setText(item.getTitle());
itemDesc.setText(item.getDescription());
itemPrice.setText(item.getPrice());
view.setTag(item);
return view;
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Purchasable item = (Purchasable) view.getTag();
InAppPurchaseActivity.instance().displayStore(item);
}
}

View file

@ -56,7 +56,7 @@ public class XmlRpcHelper {
}
public void getAccountExpireAsync(final XmlRpcListener listener, String username, String password) {
LinphoneXmlRpcRequest xmlRpcRequest = new LinphoneXmlRpcRequestImpl("get_expiration_for_account", LinphoneXmlRpcRequest.ArgType.String);
LinphoneXmlRpcRequest xmlRpcRequest = new LinphoneXmlRpcRequestImpl("get_account_expiration", LinphoneXmlRpcRequest.ArgType.String);
xmlRpcRequest.setListener(new LinphoneXmlRpcRequestListener() {
@Override
public void onXmlRpcRequestResponse(LinphoneXmlRpcRequest request) {
@ -79,7 +79,7 @@ public class XmlRpcHelper {
xmlRpcSession.sendRequest(xmlRpcRequest);
}
public void updateAccountExpireAsync(final XmlRpcListener listener, String username, String password, String payload, String signature) {
public void updateAccountExpireAsync(final XmlRpcListener listener, String username, String password, String domain, String payload, String signature) {
LinphoneXmlRpcRequest xmlRpcRequest = new LinphoneXmlRpcRequestImpl("update_expiration_date", LinphoneXmlRpcRequest.ArgType.String);
xmlRpcRequest.setListener(new LinphoneXmlRpcRequestListener() {
@Override
@ -100,6 +100,7 @@ public class XmlRpcHelper {
});
xmlRpcRequest.addStringArg(username);
xmlRpcRequest.addStringArg(password);
xmlRpcRequest.addStringArg(domain);
xmlRpcRequest.addStringArg(payload);
xmlRpcRequest.addStringArg(signature);
xmlRpcSession.sendRequest(xmlRpcRequest);
@ -164,7 +165,7 @@ public class XmlRpcHelper {
if (!"NOK".equals(result) && !"OK".equals(result)) {
listener.onError(result);
}
listener.onAccountFetched("OK".equals(result));
listener.onTrialAccountFetched("OK".equals(result));
} else if (request.getStatus() == LinphoneXmlRpcRequest.Status.Failed) {
Log.e(result);
listener.onError(result);
@ -352,12 +353,13 @@ public class XmlRpcHelper {
}
public void verifySignatureAsync(final XmlRpcListener listener, String payload, String signature) {
LinphoneXmlRpcRequest xmlRpcRequest = new LinphoneXmlRpcRequestImpl("verify_payload_signature", LinphoneXmlRpcRequest.ArgType.String);
LinphoneXmlRpcRequest xmlRpcRequest = new LinphoneXmlRpcRequestImpl("check_payload_signature", LinphoneXmlRpcRequest.ArgType.String);
xmlRpcRequest.setListener(new LinphoneXmlRpcRequestListener() {
@Override
public void onXmlRpcRequestResponse(LinphoneXmlRpcRequest request) {
String result = request.getStringResponse();
if (request.getStatus() == LinphoneXmlRpcRequest.Status.Ok) {
Log.w(result);
if (result.startsWith("ERROR_")) {
Log.e(result);
listener.onError(result);