Search in sources :

Example 21 with Conversation

use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.

the class AvatarService method get.

public Bitmap get(Message message, int size, boolean cachedOnly) {
    final Conversation conversation = message.getConversation();
    if (message.getType() == Message.TYPE_STATUS && message.getCounterparts() != null && message.getCounterparts().size() > 1) {
        return get(message.getCounterparts(), size, cachedOnly);
    } else if (message.getStatus() == Message.STATUS_RECEIVED) {
        Contact c = message.getContact();
        if (c != null && (c.getProfilePhoto() != null || c.getAvatar() != null)) {
            return get(c, size, cachedOnly);
        } else if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
            final Jid trueCounterpart = message.getTrueCounterpart();
            MucOptions.User user;
            if (trueCounterpart != null) {
                user = conversation.getMucOptions().findUserByRealJid(trueCounterpart);
            } else {
                user = conversation.getMucOptions().findUserByFullJid(message.getCounterpart());
            }
            if (user != null) {
                return getImpl(user, size, cachedOnly);
            }
        } else if (c != null) {
            return get(c, size, cachedOnly);
        }
        Jid tcp = message.getTrueCounterpart();
        String seed = tcp != null ? tcp.toBareJid().toString() : null;
        return get(UIHelper.getMessageDisplayName(message), seed, size, cachedOnly);
    } else {
        return get(conversation.getAccount(), size, cachedOnly);
    }
}
Also used : MucOptions(de.pixart.messenger.entities.MucOptions) Jid(de.pixart.messenger.xmpp.jid.Jid) Conversation(de.pixart.messenger.entities.Conversation) Contact(de.pixart.messenger.entities.Contact)

Example 22 with Conversation

use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.

the class AvatarService method get.

private Bitmap get(MucOptions mucOptions, int size, boolean cachedOnly) {
    final String KEY = key(mucOptions, size);
    Bitmap bitmap = this.mXmppConnectionService.getBitmapCache().get(KEY);
    if (bitmap != null || cachedOnly) {
        return bitmap;
    }
    final List<MucOptions.User> users = mucOptions.getUsersRelevantForNameAndAvatar();
    if (users.size() == 0) {
        Conversation c = mucOptions.getConversation();
        bitmap = getImpl(c.getName(), c.getJid().toBareJid().toString(), size);
    } else {
        bitmap = getImpl(users, size);
    }
    this.mXmppConnectionService.getBitmapCache().put(KEY, bitmap);
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Conversation(de.pixart.messenger.entities.Conversation)

Example 23 with Conversation

use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.

the class AvatarService method key.

private String key(List<MucOptions.User> users, int size) {
    final Conversation conversation = users.get(0).getConversation();
    StringBuilder builder = new StringBuilder("TILE_");
    builder.append(conversation.getUuid());
    for (MucOptions.User user : users) {
        builder.append("\0");
        builder.append(user.getRealJid() == null ? "" : user.getRealJid().toBareJid().toPreppedString());
        builder.append("\0");
        builder.append(user.getFullJid() == null ? "" : user.getFullJid().toPreppedString());
    }
    final String key = builder.toString();
    synchronized (this.conversationDependentKeys) {
        Set<String> keys;
        if (this.conversationDependentKeys.containsKey(conversation.getUuid())) {
            keys = this.conversationDependentKeys.get(conversation.getUuid());
        } else {
            keys = new HashSet<>();
            this.conversationDependentKeys.put(conversation.getUuid(), keys);
        }
        keys.add(key);
    }
    return key;
}
Also used : MucOptions(de.pixart.messenger.entities.MucOptions) Conversation(de.pixart.messenger.entities.Conversation)

Example 24 with Conversation

use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.

the class ContactChooserTargetService method onGetChooserTargets.

@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    Intent intent = new Intent(this, XmppConnectionService.class);
    intent.setAction("contact_chooser");
    startService(intent);
    bindService(intent, this, Context.BIND_AUTO_CREATE);
    ArrayList<ChooserTarget> chooserTargets = new ArrayList<>();
    try {
        waitForService();
        final ArrayList<Conversation> conversations = new ArrayList<>();
        if (!mXmppConnectionService.areMessagesInitialized()) {
            return chooserTargets;
        }
        mXmppConnectionService.populateWithOrderedConversations(conversations, false);
        final ComponentName componentName = new ComponentName(this, ShareWithActivity.class);
        final int pixel = (int) (48 * getResources().getDisplayMetrics().density);
        for (int i = 0; i < Math.min(conversations.size(), MAX_TARGETS); ++i) {
            final Conversation conversation = conversations.get(i);
            final String name = conversation.getName();
            final Icon icon = Icon.createWithBitmap(mXmppConnectionService.getAvatarService().get(conversation, pixel));
            final float score = 1 - (1.0f / MAX_TARGETS) * i;
            final Bundle extras = new Bundle();
            extras.putString("uuid", conversation.getUuid());
            chooserTargets.add(new ChooserTarget(name, icon, score, componentName, extras));
        }
    } catch (InterruptedException e) {
    }
    unbindService(this);
    return chooserTargets;
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Intent(android.content.Intent) Conversation(de.pixart.messenger.entities.Conversation) ChooserTarget(android.service.chooser.ChooserTarget) ComponentName(android.content.ComponentName) Icon(android.graphics.drawable.Icon)

Example 25 with Conversation

use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.

the class ExportLogsService method export.

private void export() {
    wakeLock.acquire();
    List<Conversation> conversations = mDatabaseBackend.getConversations(Conversation.STATUS_AVAILABLE);
    conversations.addAll(mDatabaseBackend.getConversations(Conversation.STATUS_ARCHIVED));
    NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getBaseContext());
    mBuilder.setContentTitle(getString(R.string.app_name)).setContentText(getString(R.string.notification_export_logs_title)).setSmallIcon(R.drawable.ic_import_export_white_24dp).setProgress(0, 0, true);
    startForeground(NOTIFICATION_ID, mBuilder.build());
    mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());
    if (ReadableLogsEnabled) {
        for (Conversation conversation : conversations) {
            writeToFile(conversation);
        }
    }
    if (mAccounts.size() == 1) {
        try {
            ExportDatabase();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Conversation(de.pixart.messenger.entities.Conversation) IOException(java.io.IOException)

Aggregations

Conversation (de.pixart.messenger.entities.Conversation)69 Jid (de.pixart.messenger.xmpp.jid.Jid)20 Account (de.pixart.messenger.entities.Account)18 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)16 Message (de.pixart.messenger.entities.Message)15 Contact (de.pixart.messenger.entities.Contact)11 MucOptions (de.pixart.messenger.entities.MucOptions)9 Intent (android.content.Intent)7 SuppressLint (android.annotation.SuppressLint)6 Uri (android.net.Uri)6 SpannableString (android.text.SpannableString)6 View (android.view.View)6 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)6 DownloadableFile (de.pixart.messenger.entities.DownloadableFile)6 Element (de.pixart.messenger.xml.Element)6 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)6 IOException (java.io.IOException)6 Fragment (android.app.Fragment)5 SharedPreferences (android.content.SharedPreferences)5 Bitmap (android.graphics.Bitmap)5