Search in sources :

Example 1 with AccountItem

use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.

the class AccountListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view;
    AccountManager accountManager = AccountManager.getInstance();
    if (convertView == null) {
        view = getActivity().getLayoutInflater().inflate(R.layout.account_list_item, parent, false);
    } else {
        view = convertView;
    }
    final String account = getItem(position);
    ((ImageView) view.findViewById(R.id.color)).setImageDrawable(new ColorDrawable(ColorManager.getInstance().getAccountPainter().getAccountMainColor(account)));
    ((ImageView) view.findViewById(R.id.avatar)).setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
    ((TextView) view.findViewById(R.id.name)).setText(accountManager.getVerboseName(account));
    SwitchCompat accountSwitch = (SwitchCompat) view.findViewById(R.id.account_switch);
    final AccountItem accountItem = accountManager.getAccount(account);
    accountSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            AccountManager.getInstance().setEnabled(account, isChecked);
        }
    });
    ConnectionState state;
    if (accountItem == null) {
        state = ConnectionState.offline;
        accountSwitch.setChecked(false);
    } else {
        state = accountItem.getState();
        accountSwitch.setChecked(accountItem.isEnabled());
    }
    ((TextView) view.findViewById(R.id.status)).setText(getActivity().getString(state.getStringId()));
    return view;
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ColorDrawable(android.graphics.drawable.ColorDrawable) AccountManager(com.xabber.android.data.account.AccountManager) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ConnectionState(com.xabber.android.data.connection.ConnectionState) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 2 with AccountItem

use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.

the class PresenceManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza stanza) {
    if (!(connection instanceof AccountItem)) {
        return;
    }
    if (!(stanza instanceof Presence)) {
        return;
    }
    Presence presence = (Presence) stanza;
    if (presence.getType() == Presence.Type.subscribe) {
        String account = ((AccountItem) connection).getAccount();
        // Subscription request
        HashSet<String> set = requestedSubscriptions.get(account);
        if (set != null && set.contains(bareAddress)) {
            try {
                acceptSubscription(account, bareAddress);
            } catch (NetworkException e) {
            }
            subscriptionRequestProvider.remove(account, bareAddress);
        } else {
            subscriptionRequestProvider.add(new SubscriptionRequest(account, bareAddress), null);
        }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) Presence(org.jivesoftware.smack.packet.Presence) NetworkException(com.xabber.android.data.NetworkException)

Example 3 with AccountItem

use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.

the class AccountList method onCreateContextMenu.

@Override
protected void onCreateContextMenu(ContextMenu menu, String actionWith) {
    final AccountItem accountItem = AccountManager.getInstance().getAccount(actionWith);
    menu.setHeaderTitle(AccountManager.getInstance().getVerboseName(actionWith));
    if (accountItem.isEnabled()) {
        menu.add(0, CONTEXT_MENU_STATUS_EDITOR_ID, 0, getResources().getText(R.string.status_editor));
    }
    menu.add(0, CONTEXT_MENU_VIEW_ACCOUNT_ID, 0, getString(R.string.account_editor));
    super.onCreateContextMenu(menu, actionWith);
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem)

Example 4 with AccountItem

use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.

the class GroupedContactAdapter method getAccountView.

private View getAccountView(int position, View convertView, ViewGroup parent) {
    final View view;
    final ContactListAccountItemViewHolder viewHolder;
    if (convertView == null) {
        view = layoutInflater.inflate(R.layout.contact_list_account_group_item, parent, false);
        viewHolder = new ContactListAccountItemViewHolder(view);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            view.setElevation(accountElevation);
        }
        view.setTag(viewHolder);
    } else {
        view = convertView;
        viewHolder = (ContactListAccountItemViewHolder) view.getTag();
    }
    final AccountConfiguration configuration = (AccountConfiguration) getItem(position);
    final String account = configuration.getAccount();
    viewHolder.statusIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onClickListener.onAccountMenuClick(v, account);
        }
    });
    final int level = AccountManager.getInstance().getColorLevel(account);
    view.setBackgroundDrawable(new ColorDrawable(accountGroupColors[level]));
    viewHolder.name.setText(GroupManager.getInstance().getGroupName(account, configuration.getUser()));
    viewHolder.smallRightText.setText(configuration.getOnline() + "/" + configuration.getTotal());
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    String statusText = accountItem.getStatusText().trim();
    if (statusText.isEmpty()) {
        statusText = activity.getString(accountItem.getDisplayStatusMode().getStringID());
    }
    viewHolder.secondLineMessage.setText(statusText);
    if (SettingsManager.contactsShowAvatars()) {
        viewHolder.avatar.setVisibility(View.VISIBLE);
        viewHolder.avatar.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
    } else {
        viewHolder.avatar.setVisibility(View.GONE);
    }
    viewHolder.avatar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            activity.startActivity(AccountViewer.createAccountInfoIntent(activity, account));
        }
    });
    viewHolder.statusIcon.setImageLevel(accountItem.getDisplayStatusMode().getStatusLevel());
    ShowOfflineMode showOfflineMode = configuration.getShowOfflineMode();
    if (showOfflineMode == ShowOfflineMode.normal) {
        if (SettingsManager.contactsShowOffline()) {
            showOfflineMode = ShowOfflineMode.always;
        } else {
            showOfflineMode = ShowOfflineMode.never;
        }
    }
    viewHolder.smallRightIcon.setImageLevel(showOfflineMode.ordinal());
    StatusMode statusMode = AccountManager.getInstance().getAccount(configuration.getAccount()).getDisplayStatusMode();
    if (statusMode == StatusMode.unavailable || statusMode == StatusMode.connection) {
        viewHolder.offlineShadow.setVisibility(View.VISIBLE);
    } else {
        viewHolder.offlineShadow.setVisibility(View.GONE);
    }
    return view;
}
Also used : StatusMode(com.xabber.android.data.account.StatusMode) ColorDrawable(android.graphics.drawable.ColorDrawable) AccountItem(com.xabber.android.data.account.AccountItem) ShowOfflineMode(com.xabber.android.data.roster.ShowOfflineMode) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 5 with AccountItem

use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.

the class ChatContactSettingsFragment method onInflate.

@Override
protected void onInflate(Bundle savedInstanceState) {
    addPreferencesFromResource(R.xml.preference_chat_contact);
    AccountItem accountItem = mListener.getAccountItem();
    if (accountItem.getArchiveMode() == ArchiveMode.server || accountItem.getArchiveMode() == ArchiveMode.dontStore) {
        getPreferenceScreen().removePreference(getPreferenceScreen().findPreference(getString(R.string.chat_save_history_key)));
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem)

Aggregations

AccountItem (com.xabber.android.data.account.AccountItem)96 AccountJid (com.xabber.android.data.entity.AccountJid)24 UserJid (com.xabber.android.data.entity.UserJid)14 View (android.view.View)12 NetworkException (com.xabber.android.data.NetworkException)11 ArrayList (java.util.ArrayList)11 SmackException (org.jivesoftware.smack.SmackException)11 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)11 Message (org.jivesoftware.smack.packet.Message)11 Presence (org.jivesoftware.smack.packet.Presence)10 TextView (android.widget.TextView)9 XMPPException (org.jivesoftware.smack.XMPPException)9 Jid (org.jxmpp.jid.Jid)9 ImageView (android.widget.ImageView)8 StatusMode (com.xabber.android.data.account.StatusMode)6 ConnectionState (com.xabber.android.data.connection.ConnectionState)5 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)5 Realm (io.realm.Realm)5 ColorDrawable (android.graphics.drawable.ColorDrawable)4 AccountManager (com.xabber.android.data.account.AccountManager)4