use of cx.ring.model.Account in project ring-client-android by savoirfairelinux.
the class AccountsAdapter method getView.
@Override
public View getView(final int pos, View convertView, ViewGroup parent) {
View rowView = convertView;
AccountView entryView;
if (rowView == null) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
rowView = inflater.inflate(R.layout.item_account_pref, parent, false);
entryView = new AccountView();
entryView.alias = rowView.findViewById(R.id.account_alias);
entryView.host = rowView.findViewById(R.id.account_host);
entryView.loadingIndicator = rowView.findViewById(R.id.loading_indicator);
entryView.errorIndicator = rowView.findViewById(R.id.error_indicator);
entryView.enabled = rowView.findViewById(R.id.account_checked);
entryView.errorIndicator.setColorFilter(parent.getContext().getResources().getColor(R.color.error_red));
entryView.errorIndicator.setVisibility(View.GONE);
entryView.loadingIndicator.setVisibility(View.GONE);
rowView.setTag(entryView);
} else {
entryView = (AccountView) rowView.getTag();
}
final Account item = accounts.get(pos);
entryView.alias.setText(item.getAlias());
entryView.host.setTextColor(ContextCompat.getColor(parent.getContext(), R.color.text_color_secondary));
if (item.isIP2IP()) {
entryView.host.setText(item.getRegistrationState());
} else if (item.isSip()) {
entryView.host.setText(item.getDisplayUri() + " - " + item.getRegistrationState());
} else {
entryView.host.setText(item.getDisplayUri());
}
entryView.enabled.setChecked(item.isEnabled());
entryView.enabled.setOnClickListener(v -> {
item.setEnabled(!item.isEnabled());
mListeners.onItemClicked(item.getAccountID(), item.getDetails());
});
if (item.isEnabled()) {
if (!item.isActive()) {
entryView.errorIndicator.setImageResource(R.drawable.ic_network_disconnect_black_24dp);
entryView.errorIndicator.setColorFilter(Color.BLACK);
entryView.errorIndicator.setVisibility(View.VISIBLE);
entryView.loadingIndicator.setVisibility(View.GONE);
} else if (item.isTrying()) {
entryView.errorIndicator.setVisibility(View.GONE);
entryView.loadingIndicator.setVisibility(View.VISIBLE);
} else if (item.needsMigration()) {
entryView.host.setText(R.string.account_update_needed);
entryView.host.setTextColor(Color.RED);
entryView.errorIndicator.setImageResource(R.drawable.ic_warning);
entryView.errorIndicator.setColorFilter(Color.RED);
entryView.errorIndicator.setVisibility(View.VISIBLE);
} else if (item.isInError() || !item.isRegistered()) {
entryView.errorIndicator.setImageResource(R.drawable.ic_error_white);
entryView.errorIndicator.setColorFilter(Color.RED);
entryView.errorIndicator.setVisibility(View.VISIBLE);
entryView.loadingIndicator.setVisibility(View.GONE);
} else {
entryView.errorIndicator.setVisibility(View.GONE);
entryView.loadingIndicator.setVisibility(View.GONE);
}
} else {
entryView.errorIndicator.setVisibility(View.GONE);
entryView.loadingIndicator.setVisibility(View.GONE);
}
return rowView;
}
use of cx.ring.model.Account in project ring-client-android by savoirfairelinux.
the class MainPresenter method reloadAccountInfos.
public void reloadAccountInfos() {
if (mAccountService == null) {
Log.e(TAG, "reloadAccountInfos: No account service available");
return;
}
String displayableAddress = null;
List<Account> accounts = mAccountService.getAccounts();
for (Account account : accounts) {
displayableAddress = account.getDisplayUri();
}
RingNavigationViewModel viewModel = new RingNavigationViewModel(mAccountService.getCurrentAccount(), accounts);
getView().displayAccountInfos(displayableAddress, viewModel);
}
use of cx.ring.model.Account in project ring-client-android by savoirfairelinux.
the class RingSearchPresenter method queryTextChanged.
public void queryTextChanged(String query) {
if (query.equals("")) {
getView().clearSearch();
} else {
Account currentAccount = mAccountService.getCurrentAccount();
if (currentAccount == null) {
return;
}
Uri uri = new Uri(query);
if (uri.isRingId()) {
mCallContact = CallContact.buildUnknown(uri);
getView().displayContact(mCallContact);
} else {
getView().clearSearch();
// Ring search
if (mNameLookupInputHandler == null) {
mNameLookupInputHandler = new NameLookupInputHandler(mAccountService, currentAccount.getAccountID());
}
mLastBlockchainQuery = query;
mNameLookupInputHandler.enqueueNextLookup(query);
}
}
}
use of cx.ring.model.Account in project ring-client-android by savoirfairelinux.
the class ConversationFacade method searchForRingIdInBlockchain.
private void searchForRingIdInBlockchain() {
final String currentAccountId = mAccountService.getCurrentAccount().getAccountID();
for (Conversation conversation : mConversationMap.values()) {
CallContact contact = conversation.getContact();
if (contact == null) {
continue;
}
Uri contactUri = contact.getPhones().get(0).getNumber();
if (!contactUri.isRingId() || !StringUtils.isEmpty(contact.getUsername())) {
continue;
}
boolean currentAccountChecked = false;
for (String accountId : conversation.getAccountsUsed()) {
Account account = mAccountService.getAccount(accountId);
if (account == null || !account.isRing()) {
continue;
}
if (accountId.equals(currentAccountId)) {
currentAccountChecked = true;
}
mAccountService.lookupAddress(accountId, "", contactUri.getRawRingId());
}
if (!currentAccountChecked) {
mAccountService.lookupAddress(currentAccountId, "", contactUri.getRawRingId());
}
}
}
use of cx.ring.model.Account in project ring-client-android by savoirfairelinux.
the class ConversationFacade method update.
@Override
public void update(Observable observable, ServiceEvent event) {
if (event == null) {
return;
}
ServiceEvent mEvent;
if (observable instanceof HistoryService) {
switch(event.getEventType()) {
case INCOMING_MESSAGE:
{
TextMessage txt = event.getEventInput(ServiceEvent.EventInput.MESSAGE, TextMessage.class);
if (txt == null) {
Log.d(TAG, "Received a null text message");
return;
}
parseNewMessage(txt);
updateTextNotifications();
setChanged();
mEvent = new ServiceEvent(ServiceEvent.EventType.INCOMING_MESSAGE);
notifyObservers(mEvent);
break;
}
case ACCOUNT_MESSAGE_STATUS_CHANGED:
{
TextMessage newMsg = event.getEventInput(ServiceEvent.EventInput.MESSAGE, TextMessage.class);
Conversation conv = getConversationByContact(mContactService.findContactByNumber(newMsg.getNumber()));
if (conv != null) {
conv.updateTextMessage(newMsg);
}
setChanged();
mEvent = new ServiceEvent(ServiceEvent.EventType.INCOMING_MESSAGE);
notifyObservers(mEvent);
break;
}
case HISTORY_LOADED:
Account account = mAccountService.getCurrentAccount();
if (account != null) {
boolean acceptAllMessages = account.getDetailBoolean(ConfigKey.DHT_PUBLIC_IN);
mConversationMap.clear();
addContacts(acceptAllMessages);
List<HistoryCall> historyCalls = (List<HistoryCall>) event.getEventInput(ServiceEvent.EventInput.HISTORY_CALLS, ArrayList.class);
parseHistoryCalls(historyCalls, acceptAllMessages);
List<HistoryText> historyTexts = (List<HistoryText>) event.getEventInput(ServiceEvent.EventInput.HISTORY_TEXTS, ArrayList.class);
parseHistoryTexts(historyTexts, acceptAllMessages);
List<DataTransfer> historyTransfers = (List<DataTransfer>) event.getEventInput(ServiceEvent.EventInput.HISTORY_TRANSFERS, ArrayList.class);
parseHistoryTransfers(historyTransfers, acceptAllMessages);
aggregateHistory();
searchForRingIdInBlockchain();
}
setChanged();
mEvent = new ServiceEvent(ServiceEvent.EventType.CONVERSATIONS_CHANGED);
notifyObservers(mEvent);
break;
case HISTORY_MODIFIED:
refreshConversations();
break;
}
} else if (observable instanceof CallService) {
Conversation conversation = null;
Conference conference = null;
SipCall call;
switch(event.getEventType()) {
case CALL_STATE_CHANGED:
call = event.getEventInput(ServiceEvent.EventInput.CALL, SipCall.class);
if (call == null) {
Log.w(TAG, "CALL_STATE_CHANGED : call is null");
return;
}
int newState = call.getCallState();
mHardwareService.updateAudioState(newState == SipCall.State.RINGING && call.isIncoming(), call.isOnGoing() && !call.isAudioOnly());
for (Conversation conv : mConversationMap.values()) {
conference = conv.getConference(call.getCallId());
if (conference != null) {
conversation = conv;
Log.w(TAG, "CALL_STATE_CHANGED : found conversation " + call.getCallId());
break;
}
}
if (conversation == null) {
conversation = startConversation(call.getContact());
conference = new Conference(call);
conversation.addConference(conference);
}
Log.w(TAG, "CALL_STATE_CHANGED : updating call state to " + newState);
if ((call.isRinging() || newState == SipCall.State.CURRENT) && call.getTimestampStart() == 0) {
call.setTimestampStart(System.currentTimeMillis());
}
if ((newState == SipCall.State.CURRENT && call.isIncoming()) || newState == SipCall.State.RINGING && call.isOutGoing()) {
mAccountService.sendProfile(call.getCallId(), call.getAccount());
} else if (newState == SipCall.State.HUNGUP || newState == SipCall.State.BUSY || newState == SipCall.State.FAILURE || newState == SipCall.State.OVER) {
mNotificationService.cancelCallNotification(call.getCallId().hashCode());
mHardwareService.closeAudioState();
if (newState == SipCall.State.HUNGUP) {
call.setTimestampEnd(System.currentTimeMillis());
}
if (call.getTimestampStart() == 0) {
call.setTimestampStart(System.currentTimeMillis());
}
if (call.getTimestampEnd() == 0) {
call.setTimestampEnd(System.currentTimeMillis());
}
mHistoryService.insertNewEntry(conference);
conference.removeParticipant(call);
conversation.addHistoryCall(new HistoryCall(call));
mCallService.removeCallForId(call.getCallId());
}
if (conference.getParticipants().isEmpty()) {
conversation.removeConference(conference);
}
setChanged();
mEvent = new ServiceEvent(ServiceEvent.EventType.CALL_STATE_CHANGED);
notifyObservers(mEvent);
break;
case INCOMING_CALL:
call = event.getEventInput(ServiceEvent.EventInput.CALL, SipCall.class);
conversation = startConversation(call.getContact());
conference = new Conference(call);
conversation.addConference(conference);
mNotificationService.showCallNotification(conference);
mHardwareService.setPreviewSettings();
Conference currenConf = getCurrentCallingConf();
mHardwareService.updateAudioState(currenConf.getState() == SipCall.State.RINGING && currenConf.isIncoming(), false);
setChanged();
ServiceEvent serviceEvent = new ServiceEvent(ServiceEvent.EventType.INCOMING_CALL);
notifyObservers(serviceEvent);
break;
}
} else if (observable instanceof ContactService) {
switch(event.getEventType()) {
case CONTACTS_CHANGED:
refreshConversations();
break;
}
} else if (observable instanceof AccountService) {
switch(event.getEventType()) {
case REGISTERED_NAME_FOUND:
{
int state = event.getEventInput(ServiceEvent.EventInput.STATE, Integer.class);
if (state != 0) {
break;
}
String accountId = event.getEventInput(ServiceEvent.EventInput.ACCOUNT_ID, String.class);
String name = event.getEventInput(ServiceEvent.EventInput.NAME, String.class);
Uri address = new Uri(event.getEventInput(ServiceEvent.EventInput.ADDRESS, String.class));
if (mContactService.setRingContactName(accountId, address, name)) {
setChanged();
notifyObservers(new ServiceEvent(ServiceEvent.EventType.USERNAME_CHANGED));
}
break;
}
case DATA_TRANSFER:
{
DataTransferEventCode transferEventCode = event.getEventInput(ServiceEvent.EventInput.TRANSFER_EVENT_CODE, DataTransferEventCode.class);
DataTransfer transfer = event.getEventInput(ServiceEvent.EventInput.TRANSFER_INFO, DataTransfer.class);
handleDataTransferEvent(transfer, transferEventCode);
break;
}
}
}
}
Aggregations