Search in sources :

Example 6 with Conversation

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

the class DatabaseBackend method getConversations.

public CopyOnWriteArrayList<Conversation> getConversations(int status) {
    CopyOnWriteArrayList<Conversation> list = new CopyOnWriteArrayList<>();
    SQLiteDatabase db = this.getReadableDatabase();
    String[] selectionArgs = { Integer.toString(status) };
    Cursor cursor = db.rawQuery("select * from " + Conversation.TABLENAME + " where " + Conversation.STATUS + " = ? order by " + Conversation.CREATED + " desc", selectionArgs);
    while (cursor.moveToNext()) {
        list.add(Conversation.fromCursor(cursor));
    }
    cursor.close();
    return list;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Conversation(de.pixart.messenger.entities.Conversation) Cursor(android.database.Cursor) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 7 with Conversation

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

the class ConferenceDetailsActivity method startConversation.

protected void startConversation(User user) {
    if (user.getRealJid() != null) {
        Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(), user.getRealJid().toBareJid(), false, true);
        switchToConversation(conversation);
    }
}
Also used : Conversation(de.pixart.messenger.entities.Conversation)

Example 8 with Conversation

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

the class ConversationActivity method invalidateActionBarTitle.

private void invalidateActionBarTitle() {
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
        if (mainFragment != null && mainFragment instanceof ConversationFragment) {
            final Conversation conversation = ((ConversationFragment) mainFragment).getConversation();
            if (conversation != null) {
                actionBar.setDisplayHomeAsUpEnabled(true);
                View view = getLayoutInflater().inflate(R.layout.ab_title, null);
                getSupportActionBar().setCustomView(view);
                actionBar.setDisplayShowTitleEnabled(false);
                actionBar.setDisplayShowCustomEnabled(true);
                TextView abtitle = findViewById(android.R.id.text1);
                TextView absubtitle = findViewById(android.R.id.text2);
                abtitle.setText(conversation.getName());
                abtitle.setOnClickListener(view1 -> {
                    if (conversation.getMode() == Conversation.MODE_SINGLE) {
                        switchToContactDetails(conversation.getContact());
                    } else if (conversation.getMode() == Conversation.MODE_MULTI) {
                        Intent intent = new Intent(ConversationActivity.this, ConferenceDetailsActivity.class);
                        intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
                        intent.putExtra("uuid", conversation.getUuid());
                        startActivity(intent);
                    }
                });
                abtitle.setSelected(true);
                if (conversation.getMode() == Conversation.MODE_SINGLE && !conversation.withSelf()) {
                    ChatState state = conversation.getIncomingChatState();
                    if (conversation.getContact().getShownStatus() == Presence.Status.OFFLINE) {
                        absubtitle.setText(getString(R.string.account_status_offline));
                        absubtitle.setSelected(true);
                        absubtitle.setOnClickListener(view12 -> {
                            if (conversation.getMode() == Conversation.MODE_SINGLE) {
                                switchToContactDetails(conversation.getContact());
                            } else if (conversation.getMode() == Conversation.MODE_MULTI) {
                                Intent intent = new Intent(ConversationActivity.this, ConferenceDetailsActivity.class);
                                intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
                                intent.putExtra("uuid", conversation.getUuid());
                                startActivity(intent);
                            }
                        });
                    } else {
                        if (state == ChatState.COMPOSING) {
                            absubtitle.setText(getString(R.string.is_typing));
                            absubtitle.setTypeface(null, Typeface.BOLD_ITALIC);
                            absubtitle.setSelected(true);
                            absubtitle.setOnClickListener(view13 -> {
                                if (conversation.getMode() == Conversation.MODE_SINGLE) {
                                    switchToContactDetails(conversation.getContact());
                                } else if (conversation.getMode() == Conversation.MODE_MULTI) {
                                    Intent intent = new Intent(ConversationActivity.this, ConferenceDetailsActivity.class);
                                    intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
                                    intent.putExtra("uuid", conversation.getUuid());
                                    startActivity(intent);
                                }
                            });
                        } else {
                            if (showLastSeen && conversation.getContact().getLastseen() > 0) {
                                absubtitle.setText(UIHelper.lastseen(getApplicationContext(), conversation.getContact().isActive(), conversation.getContact().getLastseen()));
                            } else {
                                absubtitle.setText(getString(R.string.account_status_online));
                            }
                            absubtitle.setSelected(true);
                            absubtitle.setOnClickListener(view14 -> {
                                if (conversation.getMode() == Conversation.MODE_SINGLE) {
                                    switchToContactDetails(conversation.getContact());
                                } else if (conversation.getMode() == Conversation.MODE_MULTI) {
                                    Intent intent = new Intent(ConversationActivity.this, ConferenceDetailsActivity.class);
                                    intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
                                    intent.putExtra("uuid", conversation.getUuid());
                                    startActivity(intent);
                                }
                            });
                        }
                    }
                } else {
                    if (conversation.getParticipants() != null) {
                        ChatState state = ChatState.COMPOSING;
                        List<MucOptions.User> userWithChatStates = conversation.getMucOptions().getUsersWithChatState(state, 5);
                        if (userWithChatStates.size() == 0) {
                            state = ChatState.PAUSED;
                            userWithChatStates = conversation.getMucOptions().getUsersWithChatState(state, 5);
                        }
                        List<MucOptions.User> users = conversation.getMucOptions().getUsers(true);
                        if (state == ChatState.COMPOSING) {
                            if (userWithChatStates.size() > 0) {
                                if (userWithChatStates.size() == 1) {
                                    MucOptions.User user = userWithChatStates.get(0);
                                    absubtitle.setText(getString(R.string.contact_is_typing, UIHelper.getDisplayName(user)));
                                } else {
                                    StringBuilder builder = new StringBuilder();
                                    for (MucOptions.User user : userWithChatStates) {
                                        if (builder.length() != 0) {
                                            builder.append(", ");
                                        }
                                        builder.append(UIHelper.getDisplayName(user));
                                    }
                                    absubtitle.setText(getString(R.string.contacts_are_typing, builder.toString()));
                                }
                            }
                        } else {
                            if (users.size() == 1) {
                                absubtitle.setText(getString(R.string.one_participant));
                            } else {
                                absubtitle.setText(getString(R.string.more_participants, users.size()));
                            }
                        }
                        absubtitle.setSelected(true);
                        absubtitle.setOnClickListener(view15 -> {
                            if (conversation.getMode() == Conversation.MODE_SINGLE) {
                                switchToContactDetails(conversation.getContact());
                            } else if (conversation.getMode() == Conversation.MODE_MULTI) {
                                Intent intent = new Intent(ConversationActivity.this, ConferenceDetailsActivity.class);
                                intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
                                intent.putExtra("uuid", conversation.getUuid());
                                startActivity(intent);
                            }
                        });
                    } else {
                        absubtitle.setText(R.string.no_participants);
                        abtitle.setSelected(true);
                        absubtitle.setOnClickListener(view16 -> {
                            if (conversation.getMode() == Conversation.MODE_SINGLE) {
                                switchToContactDetails(conversation.getContact());
                            } else if (conversation.getMode() == Conversation.MODE_MULTI) {
                                Intent intent = new Intent(ConversationActivity.this, ConferenceDetailsActivity.class);
                                intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
                                intent.putExtra("uuid", conversation.getUuid());
                                startActivity(intent);
                            }
                        });
                    }
                }
                return;
            }
        }
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayShowCustomEnabled(false);
        actionBar.setTitle(R.string.app_name);
        actionBar.setSubtitle(null);
        actionBar.setDisplayHomeAsUpEnabled(false);
    }
}
Also used : ChatState(de.pixart.messenger.xmpp.chatstate.ChatState) Conversation(de.pixart.messenger.entities.Conversation) Intent(android.content.Intent) Fragment(android.app.Fragment) View(android.view.View) TextView(android.widget.TextView) MucOptions(de.pixart.messenger.entities.MucOptions) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar)

Example 9 with Conversation

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

the class ConversationActivity method onBackendConnected.

@Override
void onBackendConnected() {
    if (performRedirectIfNecessary(true)) {
        return;
    }
    xmppConnectionService.getNotificationService().setIsInForeground(true);
    final Intent FirstStartIntent = getIntent();
    final Bundle extras = FirstStartIntent.getExtras();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (extras != null && extras.containsKey(PREF_FIRST_START)) {
            FirstStartTime = extras.getLong(PREF_FIRST_START);
            Log.d(Config.LOGTAG, "Get first start time from StartUI: " + FirstStartTime);
        }
    } else {
        FirstStartTime = System.currentTimeMillis();
        Log.d(Config.LOGTAG, "Device is running Android < SDK 23, no restart required: " + FirstStartTime);
    }
    Intent intent = pendingViewIntent.pop();
    if (intent != null) {
        if (processViewIntent(intent)) {
            if (binding.secondaryFragment != null) {
                notifyFragmentOfBackendConnected(R.id.main_fragment);
            }
            invalidateActionBarTitle();
            return;
        }
    }
    if (FirstStartTime == 0) {
        Log.d(Config.LOGTAG, "First start time: " + FirstStartTime + ", restarting App");
        // write first start timestamp to file
        FirstStartTime = System.currentTimeMillis();
        SharedPreferences FirstStart = getApplicationContext().getSharedPreferences(PREF_FIRST_START, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = FirstStart.edit();
        editor.putLong(PREF_FIRST_START, FirstStartTime);
        editor.commit();
        // restart
        Intent restartintent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
        restartintent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        restartintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(restartintent);
        System.exit(0);
    }
    if (xmppConnectionService.getAccounts().size() != 0) {
        if (xmppConnectionService.hasInternetConnection()) {
            if (xmppConnectionService.isWIFI() || (xmppConnectionService.isMobile() && !xmppConnectionService.isMobileRoaming())) {
                if (!xmppConnectionService.installedFromFDroid()) {
                    AppUpdate(xmppConnectionService.installedFromPlayStore());
                }
            }
        }
    }
    for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
        notifyFragmentOfBackendConnected(id);
    }
    ActivityResult activityResult = postponedActivityResult.pop();
    if (activityResult != null) {
        handleActivityResult(activityResult);
    }
    invalidateActionBarTitle();
    if (binding.secondaryFragment != null && ConversationFragment.getConversation(this) == null) {
        Conversation conversation = ConversationsOverviewFragment.getSuggestion(this);
        if (conversation != null) {
            openConversation(conversation, null);
        }
    }
    showDialogsIfMainIsOverview();
}
Also used : SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) IdRes(android.support.annotation.IdRes) Intent(android.content.Intent) Conversation(de.pixart.messenger.entities.Conversation) ActivityResult(de.pixart.messenger.ui.util.ActivityResult) SuppressLint(android.annotation.SuppressLint)

Example 10 with Conversation

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

the class ConversationActivity method onConversationArchived.

@Override
public void onConversationArchived(Conversation conversation) {
    if (performRedirectIfNecessary(conversation, false)) {
        return;
    }
    Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
    if (mainFragment != null && mainFragment instanceof ConversationFragment) {
        getFragmentManager().popBackStack();
        return;
    }
    Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
    if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) {
        if (((ConversationFragment) secondaryFragment).getConversation() == conversation) {
            Conversation suggestion = ConversationsOverviewFragment.getSuggestion(this, conversation);
            if (suggestion != null) {
                openConversation(suggestion, null);
            }
        }
    }
}
Also used : Conversation(de.pixart.messenger.entities.Conversation) Fragment(android.app.Fragment)

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