WIP QuickConversationsService
This commit is contained in:
parent
532eed9a0a
commit
954acb377e
|
@ -225,11 +225,11 @@ public class XmppConnectionService extends Service {
|
||||||
mJingleConnectionManager.deliverPacket(account, packet);
|
mJingleConnectionManager.deliverPacket(account, packet);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private HttpConnectionManager mHttpConnectionManager = new HttpConnectionManager(
|
private HttpConnectionManager mHttpConnectionManager = new HttpConnectionManager(this);
|
||||||
this);
|
|
||||||
private AvatarService mAvatarService = new AvatarService(this);
|
private AvatarService mAvatarService = new AvatarService(this);
|
||||||
private MessageArchiveService mMessageArchiveService = new MessageArchiveService(this);
|
private MessageArchiveService mMessageArchiveService = new MessageArchiveService(this);
|
||||||
private PushManagementService mPushManagementService = new PushManagementService(this);
|
private PushManagementService mPushManagementService = new PushManagementService(this);
|
||||||
|
private QuickConversationsService mQuickConversationsService = new QuickConversationsService(this);
|
||||||
private final ConversationsFileObserver fileObserver = new ConversationsFileObserver(
|
private final ConversationsFileObserver fileObserver = new ConversationsFileObserver(
|
||||||
Environment.getExternalStorageDirectory().getAbsolutePath()
|
Environment.getExternalStorageDirectory().getAbsolutePath()
|
||||||
) {
|
) {
|
||||||
|
@ -3682,6 +3682,10 @@ public class XmppConnectionService extends Service {
|
||||||
return this.mMessageArchiveService;
|
return this.mMessageArchiveService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public QuickConversationsService getQuickConversationsService() {
|
||||||
|
return this.mQuickConversationsService;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Contact> findContacts(Jid jid, String accountJid) {
|
public List<Contact> findContacts(Jid jid, String accountJid) {
|
||||||
ArrayList<Contact> contacts = new ArrayList<>();
|
ArrayList<Contact> contacts = new ArrayList<>();
|
||||||
for (Account account : getAccounts()) {
|
for (Account account : getAccounts()) {
|
||||||
|
|
|
@ -1,12 +1,60 @@
|
||||||
package eu.siacs.conversations.services;
|
package eu.siacs.conversations.services;
|
||||||
|
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.Config;
|
||||||
|
import eu.siacs.conversations.entities.Account;
|
||||||
|
import eu.siacs.conversations.utils.PhoneNumberUtilWrapper;
|
||||||
|
import io.michaelrocks.libphonenumber.android.Phonenumber;
|
||||||
|
import rocks.xmpp.addr.Jid;
|
||||||
|
|
||||||
public class QuickConversationsService {
|
public class QuickConversationsService {
|
||||||
|
|
||||||
private final XmppConnectionService service;
|
private final XmppConnectionService service;
|
||||||
|
|
||||||
|
private final Set<OnVerificationRequested> mOnVerificationRequested = Collections.newSetFromMap(new WeakHashMap<>());
|
||||||
|
private final Set<OnVerified> mOnVerified = Collections.newSetFromMap(new WeakHashMap<>());
|
||||||
|
|
||||||
QuickConversationsService(XmppConnectionService xmppConnectionService) {
|
QuickConversationsService(XmppConnectionService xmppConnectionService) {
|
||||||
this.service = xmppConnectionService;
|
this.service = xmppConnectionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addOnVerificationRequestedListener(OnVerificationRequested onVerificationRequested) {
|
||||||
|
synchronized (mOnVerificationRequested) {
|
||||||
|
mOnVerificationRequested.add(onVerificationRequested);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeOnVerificationRequestedListener(OnVerificationRequested onVerificationRequested) {
|
||||||
|
synchronized (mOnVerificationRequested) {
|
||||||
|
mOnVerificationRequested.remove(onVerificationRequested);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestVerification(Phonenumber.PhoneNumber phoneNumber) {
|
||||||
|
String local = PhoneNumberUtilWrapper.normalize(service, phoneNumber);
|
||||||
|
Log.d(Config.LOGTAG,"requesting verification for "+PhoneNumberUtilWrapper.normalize(service,phoneNumber));
|
||||||
|
Account account = new Account(Jid.of(local,"quick.conversations.im",null),"foo");
|
||||||
|
service.createAccount(account);
|
||||||
|
synchronized (mOnVerificationRequested) {
|
||||||
|
for(OnVerificationRequested onVerificationRequested : mOnVerificationRequested) {
|
||||||
|
onVerificationRequested.onVerificationRequested();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnVerificationRequested {
|
||||||
|
void onVerificationRequestFailed(int code);
|
||||||
|
void onVerificationRequested();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnVerified {
|
||||||
|
void onVerificationFailed();
|
||||||
|
void onVerificationSucceeded();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -18,13 +18,14 @@ import android.widget.TextView;
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.databinding.ActivityEnterNumberBinding;
|
import eu.siacs.conversations.databinding.ActivityEnterNumberBinding;
|
||||||
|
import eu.siacs.conversations.services.QuickConversationsService;
|
||||||
import eu.siacs.conversations.ui.drawable.TextDrawable;
|
import eu.siacs.conversations.ui.drawable.TextDrawable;
|
||||||
import eu.siacs.conversations.utils.PhoneNumberUtilWrapper;
|
import eu.siacs.conversations.utils.PhoneNumberUtilWrapper;
|
||||||
import io.michaelrocks.libphonenumber.android.NumberParseException;
|
import io.michaelrocks.libphonenumber.android.NumberParseException;
|
||||||
import io.michaelrocks.libphonenumber.android.PhoneNumberUtil;
|
import io.michaelrocks.libphonenumber.android.PhoneNumberUtil;
|
||||||
import io.michaelrocks.libphonenumber.android.Phonenumber;
|
import io.michaelrocks.libphonenumber.android.Phonenumber;
|
||||||
|
|
||||||
public class EnterPhoneNumberActivity extends XmppActivity {
|
public class EnterPhoneNumberActivity extends XmppActivity implements QuickConversationsService.OnVerificationRequested {
|
||||||
|
|
||||||
private static final int REQUEST_CHOOSE_COUNTRY = 0x1234;
|
private static final int REQUEST_CHOOSE_COUNTRY = 0x1234;
|
||||||
|
|
||||||
|
@ -69,7 +70,7 @@ public class EnterPhoneNumberActivity extends XmppActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onBackendConnected() {
|
void onBackendConnected() {
|
||||||
|
xmppConnectionService.getQuickConversationsService().addOnVerificationRequestedListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -100,6 +101,14 @@ public class EnterPhoneNumberActivity extends XmppActivity {
|
||||||
super.onSaveInstanceState(savedInstanceState);
|
super.onSaveInstanceState(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
if (xmppConnectionService != null) {
|
||||||
|
xmppConnectionService.getQuickConversationsService().removeOnVerificationRequestedListener(this);
|
||||||
|
}
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
private void onNextClick(View v) {
|
private void onNextClick(View v) {
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
try {
|
try {
|
||||||
|
@ -133,7 +142,7 @@ public class EnterPhoneNumberActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onPhoneNumberEntered(Phonenumber.PhoneNumber phoneNumber) {
|
private void onPhoneNumberEntered(Phonenumber.PhoneNumber phoneNumber) {
|
||||||
|
xmppConnectionService.getQuickConversationsService().requestVerification(phoneNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -149,4 +158,13 @@ public class EnterPhoneNumberActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onVerificationRequestFailed(int code) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onVerificationRequested() {
|
||||||
|
Log.d(Config.LOGTAG,"requested");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,11 @@ public class PhoneNumberUtilWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String normalize(Context context, String number) throws NumberParseException {
|
public static String normalize(Context context, String number) throws NumberParseException {
|
||||||
final PhoneNumberUtil instance = getInstance(context);
|
return normalize(context, getInstance(context).parse(number, getUserCountry(context)));
|
||||||
return instance.format(instance.parse(number, getUserCountry(context)), PhoneNumberUtil.PhoneNumberFormat.E164);
|
}
|
||||||
|
|
||||||
|
public static String normalize(Context context, Phonenumber.PhoneNumber phoneNumber) {
|
||||||
|
return getInstance(context).format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PhoneNumberUtil getInstance(final Context context) {
|
public static PhoneNumberUtil getInstance(final Context context) {
|
||||||
|
|
Loading…
Reference in New Issue