Search in sources :

Example 56 with AccountItem

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

the class AccountRosterListener method onRosterLoaded.

@Override
public void onRosterLoaded(Roster roster) {
    LogManager.i(getLogTag(), "onRosterLoaded");
    final AccountItem accountItem = AccountManager.getInstance().getAccount(AccountRosterListener.this.account);
    if (accountItem != null) {
        for (OnRosterReceivedListener listener : Application.getInstance().getManagers(OnRosterReceivedListener.class)) {
            listener.onRosterReceived(accountItem);
        }
    }
    AccountManager.getInstance().onAccountChanged(AccountRosterListener.this.account);
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem)

Example 57 with AccountItem

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

the class ContextMenuHelper method setUpAccountMenu.

public static void setUpAccountMenu(final FragmentActivity activity, final UpdatableAdapter adapter, final String account, Menu menu) {
    final AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    ConnectionState state = accountItem.getState();
    if (state == ConnectionState.waiting) {
        menu.findItem(R.id.action_reconnect_account).setVisible(true).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (accountItem.updateConnection(true))
                    AccountManager.getInstance().onAccountChanged(account);
                return true;
            }
        });
    }
    menu.findItem(R.id.action_edit_account_status).setIntent(StatusEditor.createIntent(activity, account));
    menu.findItem(R.id.action_edit_account).setIntent(AccountViewer.createAccountPreferencesIntent(activity, account));
    if (state.isConnected()) {
        menu.findItem(R.id.action_contact_info).setVisible(true).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                activity.startActivity(AccountViewer.createAccountInfoIntent(activity, account));
                return true;
            }
        });
        menu.findItem(R.id.action_add_contact).setVisible(true).setIntent(ContactAdd.createIntent(activity, account));
    }
    if (SettingsManager.contactsShowAccounts()) {
        menu.findItem(R.id.action_set_up_offline_contacts).setVisible(true).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                ContextMenuHelper.createOfflineContactsDialog(activity, adapter, account, GroupManager.IS_ACCOUNT).show();
                return true;
            }
        });
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) MenuItem(android.view.MenuItem) ConnectionState(com.xabber.android.data.connection.ConnectionState)

Example 58 with AccountItem

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

the class CarbonManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem)) {
        return;
    }
    if (!SettingsManager.connectionUseCarbons()) {
        return;
    }
    final String user = packet.getFrom();
    if (user == null)
        return;
    if (!(packet instanceof Message))
        return;
    final Message message = (Message) packet;
    if (!getCarbonsEnabled()) {
        return;
    }
    ExtensionElement carbonExtension = null;
    Direction dir = null;
    for (ExtensionElement packetExtension : message.getExtensions()) {
        if (packetExtension instanceof Received) {
            carbonExtension = packetExtension;
            dir = Direction.received;
        } else if (packetExtension instanceof Sent) {
            carbonExtension = packetExtension;
            dir = Direction.sent;
        }
    }
    if (carbonExtension == null) {
        return;
    }
    Forwarded forwarded;
    if (dir == Direction.sent) {
        Sent carbon = (Sent) carbonExtension;
        forwarded = carbon.getForwarded();
    } else {
        Received carbon = (Received) carbonExtension;
        forwarded = carbon.getForwarded();
    }
    if (forwarded == null) {
        return;
    }
    Message forwardedMsg = (Message) forwarded.getForwardedPacket();
    MessageManager.getInstance().displayForwardedMessage(connection, forwardedMsg, dir);
}
Also used : Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement)

Example 59 with AccountItem

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

the class StatusEditor method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (isFinishing()) {
        return;
    }
    actionWithItem = null;
    setContentView(R.layout.status_editor);
    Toolbar toolbar = (Toolbar) findViewById(R.id.top_toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_clear_white_24dp);
    setTitle(null);
    setSupportActionBar(toolbar);
    Intent intent = getIntent();
    account = StatusEditor.getAccount(intent);
    BarPainter barPainter = new BarPainter(this, toolbar);
    if (account != null) {
        barPainter.updateWithAccountName(account);
    } else {
        barPainter.setDefaultColor();
    }
    ListView listView = getListView();
    listView.setOnItemClickListener(this);
    registerForContextMenu(listView);
    adapter = new StatusEditorAdapter(this);
    View footerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.status_history_footer, null, false);
    footerView.findViewById(R.id.clear_status_history_button).setOnClickListener(this);
    listView.addFooterView(footerView);
    setListAdapter(adapter);
    statusTextView = (EditText) findViewById(R.id.status_text);
    statusModeView = (Spinner) findViewById(R.id.status_icon);
    statusModeView.setAdapter(new StatusModeAdapter(this));
    savedStatusesTextView = findViewById(R.id.saved_statuses_textview);
    StatusMode statusMode;
    String statusText;
    if (savedInstanceState == null) {
        if (account == null) {
            statusMode = SettingsManager.statusMode();
            statusText = SettingsManager.statusText();
        } else {
            AccountItem accountItem = AccountManager.getInstance().getAccount(account);
            if (accountItem == null) {
                Application.getInstance().onError(R.string.NO_SUCH_ACCOUNT);
                finish();
                return;
            }
            statusMode = accountItem.getFactualStatusMode();
            statusText = accountItem.getStatusText();
        }
    } else {
        statusMode = StatusMode.valueOf(savedInstanceState.getString(SAVED_MODE));
        statusText = savedInstanceState.getString(SAVED_TEXT);
    }
    showStatus(statusMode, statusText);
}
Also used : StatusMode(com.xabber.android.data.account.StatusMode) ListView(android.widget.ListView) AccountItem(com.xabber.android.data.account.AccountItem) LayoutInflater(android.view.LayoutInflater) StatusEditorAdapter(com.xabber.android.ui.adapter.StatusEditorAdapter) Intent(android.content.Intent) StatusModeAdapter(com.xabber.android.ui.adapter.StatusModeAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) Toolbar(android.support.v7.widget.Toolbar) BarPainter(com.xabber.android.ui.color.BarPainter)

Example 60 with AccountItem

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

the class GroupedContactAdapter method getGroupView.

private View getGroupView(int position, View convertView, ViewGroup parent) {
    final View view;
    final GroupViewHolder viewHolder;
    if (convertView == null) {
        view = layoutInflater.inflate(R.layout.base_group_item, parent, false);
        viewHolder = new GroupViewHolder(view);
        view.setTag(viewHolder);
    } else {
        view = convertView;
        viewHolder = (GroupViewHolder) view.getTag();
    }
    final GroupConfiguration configuration = (GroupConfiguration) getItem(position);
    final int level = AccountManager.getInstance().getColorLevel(configuration.getAccount());
    final String name = GroupManager.getInstance().getGroupName(configuration.getAccount(), configuration.getUser());
    viewHolder.indicator.setImageLevel(configuration.isExpanded() ? 1 : 0);
    viewHolder.groupOfflineIndicator.setImageLevel(configuration.getShowOfflineMode().ordinal());
    int color;
    viewHolder.groupOfflineIndicator.setVisibility(View.GONE);
    viewHolder.offlineShadow.setVisibility(View.GONE);
    if (configuration.getUser().equals(GroupManager.ACTIVE_CHATS)) {
        color = activeChatsColor;
        viewHolder.name.setText(name);
    } else {
        viewHolder.name.setText(String.format("%s (%d/%d)", name, configuration.getOnline(), configuration.getTotal()));
        color = accountSubgroupColors[level];
        viewHolder.groupOfflineIndicator.setVisibility(View.VISIBLE);
        AccountItem accountItem = AccountManager.getInstance().getAccount(configuration.getAccount());
        if (accountItem != null) {
            StatusMode statusMode = accountItem.getDisplayStatusMode();
            if (statusMode == StatusMode.unavailable || statusMode == StatusMode.connection) {
                viewHolder.offlineShadow.setVisibility(View.VISIBLE);
            }
        }
    }
    view.setBackgroundDrawable(new ColorDrawable(color));
    return view;
}
Also used : StatusMode(com.xabber.android.data.account.StatusMode) ColorDrawable(android.graphics.drawable.ColorDrawable) AccountItem(com.xabber.android.data.account.AccountItem) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

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