Search in sources :

Example 26 with Conversation

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

the class ConversationFragment method onBackendConnected.

@Override
public void onBackendConnected() {
    Log.d(Config.LOGTAG, "ConversationFragment.onBackendConnected()");
    String uuid = pendingConversationsUuid.pop();
    if (uuid != null) {
        Conversation conversation = activity.xmppConnectionService.findConversationByUuid(uuid);
        if (conversation == null) {
            Log.d(Config.LOGTAG, "unable to restore activity");
            clearPending();
            return;
        }
        reInit(conversation);
        ScrollState scrollState = pendingScrollState.pop();
        if (scrollState != null) {
            setScrollPosition(scrollState);
        }
    }
    ActivityResult activityResult = postponedActivityResult.pop();
    if (activityResult != null) {
        handleActivityResult(activityResult);
    }
    clearPending();
}
Also used : ScrollState(de.pixart.messenger.ui.util.ScrollState) Conversation(de.pixart.messenger.entities.Conversation) ActivityResult(de.pixart.messenger.ui.util.ActivityResult)

Example 27 with Conversation

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

the class ConversationFragment method selectPresenceToAttachFile.

protected void selectPresenceToAttachFile(final int attachmentChoice) {
    final int encryption = conversation.getNextEncryption();
    final Account account = conversation.getAccount();
    final PresenceSelector.OnPresenceSelected callback = () -> {
        final Intent intent = new Intent();
        boolean chooser = false;
        String fallbackPackageId = null;
        switch(attachmentChoice) {
            case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
                intent.setAction(Intent.ACTION_GET_CONTENT);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                }
                intent.setType("image/*");
                chooser = true;
                break;
            case ATTACHMENT_CHOICE_CHOOSE_VIDEO:
                chooser = true;
                intent.setType("video/*");
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                intent.setAction(Intent.ACTION_GET_CONTENT);
                break;
            case ATTACHMENT_CHOICE_TAKE_FROM_CAMERA:
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle(getString(R.string.attach_take_from_camera));
                builder.setNegativeButton(getString(R.string.action_take_photo), (dialog, which) -> {
                    final Uri uri = activity.xmppConnectionService.getFileBackend().getTakePhotoUri();
                    pendingTakePhotoUri.push(uri);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
                    intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(intent, attachmentChoice);
                });
                builder.setPositiveButton(getString(R.string.action_take_video), (dialog, which) -> {
                    intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
                    startActivityForResult(intent, attachmentChoice);
                });
                builder.create().show();
                break;
            case ATTACHMENT_CHOICE_CHOOSE_FILE:
                chooser = true;
                intent.setType("*/*");
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                intent.setAction(Intent.ACTION_GET_CONTENT);
                break;
            case ATTACHMENT_CHOICE_RECORD_VOICE:
                startActivityForResult(new Intent(getActivity(), RecordingActivity.class), attachmentChoice);
                break;
            case ATTACHMENT_CHOICE_LOCATION:
                startActivityForResult(new Intent(getActivity(), ShareLocationActivity.class), attachmentChoice);
                break;
        }
        if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
            Log.d(Config.LOGTAG, "Attachment: " + attachmentChoice);
            if (chooser) {
                startActivityForResult(Intent.createChooser(intent, getString(R.string.perform_action_with)), attachmentChoice);
            } else {
                startActivityForResult(intent, attachmentChoice);
            }
        } else if (fallbackPackageId != null) {
            startActivity(getInstallApkIntent(fallbackPackageId));
        }
    };
    if (account.httpUploadAvailable() || attachmentChoice == ATTACHMENT_CHOICE_LOCATION) {
        if ((account.httpUploadAvailable() || attachmentChoice == ATTACHMENT_CHOICE_LOCATION) && encryption != Message.ENCRYPTION_OTR) {
            conversation.setNextCounterpart(null);
            callback.onPresenceSelected();
        } else {
            activity.selectPresence(conversation, callback);
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Arrays(java.util.Arrays) HttpDownloadConnection(de.pixart.messenger.http.HttpDownloadConnection) Bundle(android.os.Bundle) MessageUtils(de.pixart.messenger.utils.MessageUtils) TransferablePlaceholder(de.pixart.messenger.entities.TransferablePlaceholder) Uri(android.net.Uri) ImageView(android.widget.ImageView) EXTRA_ACCOUNT(de.pixart.messenger.ui.XmppActivity.EXTRA_ACCOUNT) Account(de.pixart.messenger.entities.Account) Manifest(android.Manifest) Handler(android.os.Handler) MediaStore(android.provider.MediaStore) PopupMenu(android.widget.PopupMenu) ActivityResult(de.pixart.messenger.ui.util.ActivityResult) Log(android.util.Log) Set(java.util.Set) SendButtonTool(de.pixart.messenger.ui.util.SendButtonTool) Contact(de.pixart.messenger.entities.Contact) Transferable(de.pixart.messenger.entities.Transferable) EditMessage(de.pixart.messenger.ui.widget.EditMessage) TextWatcher(android.text.TextWatcher) UIHelper(de.pixart.messenger.utils.UIHelper) ContextMenuInfo(android.view.ContextMenu.ContextMenuInfo) SimpleDateFormat(java.text.SimpleDateFormat) BitmapFactory(android.graphics.BitmapFactory) SystemClock(android.os.SystemClock) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) Editable(android.text.Editable) SessionStatus(net.java.otr4j.session.SessionStatus) ArrayList(java.util.ArrayList) Conversation(de.pixart.messenger.entities.Conversation) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) ReadByMarker(de.pixart.messenger.entities.ReadByMarker) ENCRYPTION_EXCEPTIONS(de.pixart.messenger.xmpp.Patches.ENCRYPTION_EXCEPTIONS) Fragment(android.app.Fragment) InputContentInfoCompat(android.support.v13.view.inputmethod.InputContentInfoCompat) FingerprintStatus(de.pixart.messenger.crypto.axolotl.FingerprintStatus) IOException(java.io.IOException) ScrollState(de.pixart.messenger.ui.util.ScrollState) File(java.io.File) IdRes(android.support.annotation.IdRes) Gravity(android.view.Gravity) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) DataBindingUtil(android.databinding.DataBindingUtil) SendButtonAction(de.pixart.messenger.ui.util.SendButtonAction) ChatState(de.pixart.messenger.xmpp.chatstate.ChatState) LinearLayout(android.widget.LinearLayout) PackageManager(android.content.pm.PackageManager) PendingIntent(android.app.PendingIntent) AdapterContextMenuInfo(android.widget.AdapterView.AdapterContextMenuInfo) Jid(de.pixart.messenger.xmpp.jid.Jid) CheckBox(android.widget.CheckBox) Locale(java.util.Locale) View(android.view.View) AdapterView(android.widget.AdapterView) SendIntentException(android.content.IntentSender.SendIntentException) PreferenceManager(android.preference.PreferenceManager) Presence(de.pixart.messenger.entities.Presence) XmppConnectionService(de.pixart.messenger.services.XmppConnectionService) MessageAdapter(de.pixart.messenger.ui.adapter.MessageAdapter) ExifInterface(android.support.media.ExifInterface) FragmentConversationBinding(de.pixart.messenger.databinding.FragmentConversationBinding) UUID(java.util.UUID) ViewGroup(android.view.ViewGroup) OnScrollListener(android.widget.AbsListView.OnScrollListener) ConversationMenuConfigurator(de.pixart.messenger.ui.util.ConversationMenuConfigurator) List(java.util.List) ActivityNotFoundException(android.content.ActivityNotFoundException) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) FileUtils(de.pixart.messenger.utils.FileUtils) ListView(android.widget.ListView) AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService) XmppConnection(de.pixart.messenger.xmpp.XmppConnection) EditorInfo(android.view.inputmethod.EditorInfo) Blockable(de.pixart.messenger.entities.Blockable) Context(android.content.Context) ContextMenu(android.view.ContextMenu) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) MessageArchiveService(de.pixart.messenger.services.MessageArchiveService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Intent(android.content.Intent) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) FileBackend(de.pixart.messenger.persistance.FileBackend) OnSwipeTouchListener(de.pixart.messenger.ui.interfaces.OnSwipeTouchListener) MotionEvent(android.view.MotionEvent) R(de.pixart.messenger.R) AttachmentTool(de.pixart.messenger.ui.util.AttachmentTool) Build(android.os.Build) Config(de.pixart.messenger.Config) NickValidityChecker(de.pixart.messenger.utils.NickValidityChecker) DialogInterface(android.content.DialogInterface) Message(de.pixart.messenger.entities.Message) MucOptions(de.pixart.messenger.entities.MucOptions) Iterator(java.util.Iterator) LayoutInflater(android.view.LayoutInflater) AbsListView(android.widget.AbsListView) DownloadableFile(de.pixart.messenger.entities.DownloadableFile) StylingHelper(de.pixart.messenger.utils.StylingHelper) InputConnectionCompat(android.support.v13.view.inputmethod.InputConnectionCompat) PendingItem(de.pixart.messenger.ui.util.PendingItem) Bitmap(android.graphics.Bitmap) Activity(android.app.Activity) Collections(java.util.Collections) PresenceSelector(de.pixart.messenger.ui.util.PresenceSelector) OnClickListener(android.view.View.OnClickListener) REQUEST_INVITE_TO_CONVERSATION(de.pixart.messenger.ui.XmppActivity.REQUEST_INVITE_TO_CONVERSATION) Account(de.pixart.messenger.entities.Account) PresenceSelector(de.pixart.messenger.ui.util.PresenceSelector) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint)

Example 28 with Conversation

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

the class ConversationsOverviewFragment method onCreateView.

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d(Config.LOGTAG, "onCreateView");
    this.binding = DataBindingUtil.inflate(inflater, R.layout.fragment_conversations_overview, container, false);
    this.binding.fab.setOnClickListener((view) -> StartConversationActivity.launch(getActivity()));
    this.conversationsAdapter = new ConversationAdapter(this.activity, this.conversations);
    this.binding.list.setAdapter(this.conversationsAdapter);
    this.binding.list.setOnItemClickListener((parent, view, position, id) -> {
        Conversation conversation = this.conversations.get(position);
        if (activity instanceof OnConversationSelected) {
            ((OnConversationSelected) activity).onConversationSelected(conversation);
        } else {
            Log.w(ConversationsOverviewFragment.class.getCanonicalName(), "Activity does not implement OnConversationSelected");
        }
    });
    return binding.getRoot();
}
Also used : OnConversationSelected(de.pixart.messenger.ui.interfaces.OnConversationSelected) ConversationAdapter(de.pixart.messenger.ui.adapter.ConversationAdapter) Conversation(de.pixart.messenger.entities.Conversation)

Example 29 with Conversation

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

the class ShareViaAccountActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_manage_accounts);
    accountListView = findViewById(R.id.account_list);
    this.mAccountAdapter = new AccountAdapter(this, accountList);
    accountListView.setAdapter(this.mAccountAdapter);
    accountListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
            final Account account = accountList.get(position);
            final String body = getIntent().getStringExtra(EXTRA_BODY);
            try {
                final Jid contact = Jid.fromString(getIntent().getStringExtra(EXTRA_CONTACT));
                final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, contact, false, false);
                switchToConversation(conversation, body, false);
            } catch (InvalidJidException e) {
            // ignore error
            }
            finish();
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Conversation(de.pixart.messenger.entities.Conversation) AccountAdapter(de.pixart.messenger.ui.adapter.AccountAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 30 with Conversation

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

the class StartConversationActivity method openConversationForContact.

protected void openConversationForContact(Contact contact) {
    Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false, true);
    switchToConversation(conversation);
}
Also used : Conversation(de.pixart.messenger.entities.Conversation)

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