Search in sources :

Example 1 with NotificationState

use of com.xabber.android.data.message.NotificationState in project xabber-android by redsolution.

the class ChatManager method loadChatDataFromRealm.

@Nullable
public ChatData loadChatDataFromRealm(AbstractChat chat) {
    String accountJid = chat.getAccount().toString();
    String userJid = chat.getUser().toString();
    ChatData chatData = null;
    Realm realm = RealmManager.getInstance().getNewRealm();
    ChatDataRealm realmChat = realm.where(ChatDataRealm.class).equalTo("accountJid", accountJid).equalTo("userJid", userJid).findFirst();
    if (realmChat != null) {
        NotificationState notificationState;
        if (realmChat.getNotificationState() != null) {
            notificationState = new NotificationState(realmChat.getNotificationState().getMode(), realmChat.getNotificationState().getTimestamp());
        } else
            notificationState = new NotificationState(NotificationState.NotificationMode.bydefault, 0);
        chatData = new ChatData(realmChat.getSubject(), realmChat.getAccountJid(), realmChat.getUserJid(), realmChat.getUnreadCount(), realmChat.isArchived(), notificationState);
    }
    realm.close();
    return chatData;
}
Also used : ChatData(com.xabber.android.data.message.ChatData) NotificationStateRealm(com.xabber.android.data.database.realm.NotificationStateRealm) Realm(io.realm.Realm) ChatDataRealm(com.xabber.android.data.database.realm.ChatDataRealm) ChatDataRealm(com.xabber.android.data.database.realm.ChatDataRealm) NotificationState(com.xabber.android.data.message.NotificationState) Nullable(android.support.annotation.Nullable)

Example 2 with NotificationState

use of com.xabber.android.data.message.NotificationState in project xabber-android by redsolution.

the class ChatActivity method onMenuItemClick.

@Override
public boolean onMenuItemClick(MenuItem item) {
    AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
    switch(item.getItemId()) {
        case R.id.action_start_encryption:
            if (chatFragment != null)
                chatFragment.showResourceChoiceAlert(account, user, false);
            return true;
        case R.id.action_restart_encryption:
            if (chatFragment != null)
                chatFragment.showResourceChoiceAlert(account, user, true);
            return true;
        case R.id.action_stop_encryption:
            if (chatFragment != null)
                chatFragment.stopEncryption(account, user);
            return true;
        case R.id.action_verify_with_fingerprint:
            startActivity(FingerprintActivity.createIntent(this, account, user));
            return true;
        case R.id.action_verify_with_question:
            startActivity(QuestionActivity.createIntent(this, account, user, true, false, null));
            return true;
        case R.id.action_verify_with_shared_secret:
            startActivity(QuestionActivity.createIntent(this, account, user, false, false, null));
            return true;
        case R.id.action_send_contact:
            sendContact();
            return true;
        case R.id.action_view_contact:
            if (chatFragment != null)
                chatFragment.showContactInfo();
            return true;
        case R.id.action_chat_settings:
            startActivity(ChatContactSettings.createIntent(this, account, user));
            return true;
        case R.id.action_authorization_settings:
            startActivity(ConferenceAddActivity.createIntent(this, account, user.getBareUserJid()));
            return true;
        case R.id.action_clear_history:
            if (chatFragment != null)
                chatFragment.clearHistory(account, user);
            return true;
        case R.id.action_export_chat:
            if (chatFragment != null)
                chatFragment.onExportChatClick();
            return true;
        case R.id.action_call_attention:
            if (chatFragment != null)
                chatFragment.callAttention();
            return true;
        case R.id.action_block_contact:
            BlockContactDialog.newInstance(account, user).show(getFragmentManager(), BlockContactDialog.class.getName());
            return true;
        case R.id.action_request_subscription:
            try {
                PresenceManager.getInstance().requestSubscription(account, user);
            } catch (NetworkException e) {
                Application.getInstance().onError(e);
            }
            return true;
        case R.id.action_archive_chat:
            if (abstractChat != null)
                abstractChat.setArchived(true, true);
            return true;
        case R.id.action_unarchive_chat:
            if (abstractChat != null)
                abstractChat.setArchived(false, true);
            return true;
        case R.id.action_mute_chat:
            if (abstractChat != null)
                abstractChat.setNotificationState(new NotificationState(NotificationState.NotificationMode.disabled, 0), true);
            setUpOptionsMenu(toolbar.getMenu());
            return true;
        case R.id.action_unmute_chat:
            if (abstractChat != null)
                abstractChat.setNotificationState(new NotificationState(NotificationState.NotificationMode.enabled, 0), true);
            setUpOptionsMenu(toolbar.getMenu());
            return true;
        case R.id.action_join_conference:
            onJoinConferenceClick();
            return true;
        case R.id.action_invite_to_chat:
            startActivity(ContactListActivity.createRoomInviteIntent(this, account, user.getBareUserJid()));
            return true;
        case R.id.action_leave_conference:
            if (chatFragment != null)
                chatFragment.leaveConference(account, user);
            return true;
        case R.id.action_show_archived:
            this.showArchived = !this.showArchived;
            if (recentChatFragment != null) {
                recentChatFragment.closeSnackbar();
                recentChatFragment.updateChats();
                Toast.makeText(this, this.showArchived ? R.string.toast_archived_show : R.string.toast_archived_hide, Toast.LENGTH_SHORT).show();
            }
            return true;
        case R.id.action_edit_alias:
            editAlias();
            return true;
        case R.id.action_edit_groups:
            startActivity(GroupEditActivity.createIntent(this, account, user));
            return true;
        case R.id.action_remove_contact:
            ContactDeleteDialogFragment.newInstance(account, user).show(getFragmentManager(), "CONTACT_DELETE");
            return true;
        case R.id.action_delete_conference:
            ContactDeleteDialogFragment.newInstance(account, user).show(getFragmentManager(), "CONTACT_DELETE");
            return true;
        default:
            return false;
    }
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) NetworkException(com.xabber.android.data.NetworkException) BlockContactDialog(com.xabber.android.ui.dialog.BlockContactDialog) NotificationState(com.xabber.android.data.message.NotificationState)

Example 3 with NotificationState

use of com.xabber.android.data.message.NotificationState in project xabber-android by redsolution.

the class ChatContactSettingsFragment method setValues.

@Override
protected boolean setValues(Map<String, Object> source, Map<String, Object> result) {
    AccountJid account = mListener.getAccount();
    UserJid user = mListener.getUser();
    // custom notification
    if (hasChanges(source, result, R.string.chat_notification_settings_key)) {
        AbstractChat chat = MessageManager.getInstance().getChat(account, user);
        if (chat != null) {
            boolean newValue = getBoolean(result, R.string.chat_notification_settings_key);
            if (chat.getNotificationState().getMode().equals(NotificationState.NotificationMode.bydefault)) {
                NotificationState.NotificationMode mode = newValue ? NotificationState.NotificationMode.enabled : NotificationState.NotificationMode.disabled;
                chat.setNotificationState(new NotificationState(mode, 0), true);
            } else {
                boolean defValue;
                if (MUCManager.getInstance().hasRoom(account, user.getJid().asEntityBareJidIfPossible()))
                    defValue = SettingsManager.eventsOnMuc();
                else
                    defValue = SettingsManager.eventsOnChat();
                if (!defValue && chat.getNotificationState().getMode().equals(NotificationState.NotificationMode.disabled)) {
                    chat.setNotificationState(new NotificationState(NotificationState.NotificationMode.enabled, 0), true);
                } else if (defValue && chat.getNotificationState().getMode().equals(NotificationState.NotificationMode.enabled)) {
                    chat.setNotificationState(new NotificationState(NotificationState.NotificationMode.disabled, 0), true);
                } else
                    chat.setNotificationState(new NotificationState(NotificationState.NotificationMode.bydefault, 0), true);
            }
        }
    }
    if (hasChanges(source, result, R.string.chat_save_history_key))
        ChatManager.getInstance().setSaveMessages(account, user, getBoolean(result, R.string.chat_save_history_key));
    if (hasChanges(source, result, R.string.chat_events_visible_chat_key))
        ChatManager.getInstance().setNotifyVisible(account, user, getBoolean(result, R.string.chat_events_visible_chat_key));
    if (hasChanges(source, result, R.string.chat_events_show_text_key)) {
        ChatManager.getInstance().setShowText(account, user, ShowMessageTextInNotification.fromInteger(getInt(result, R.string.chat_events_show_text_key)));
    }
    if (hasChanges(source, result, R.string.chat_events_vibro_key))
        ChatManager.getInstance().setMakeVibro(account, user, getBoolean(result, R.string.chat_events_vibro_key));
    if (hasChanges(source, result, R.string.chat_events_sound_key))
        ChatManager.getInstance().setSound(account, user, getUri(result, R.string.chat_events_sound_key));
    if (hasChanges(source, result, R.string.chat_events_suppress_100_key))
        ChatManager.getInstance().setSuppress100(account, user, getBoolean(result, R.string.chat_events_suppress_100_key));
    return true;
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) NotificationState(com.xabber.android.data.message.NotificationState)

Example 4 with NotificationState

use of com.xabber.android.data.message.NotificationState in project xabber-android by redsolution.

the class ContextMenuHelper method setContactContextMenuActions.

private static void setContactContextMenuActions(final Activity activity, final ContactListPresenter presenter, ContextMenu menu, final AccountJid account, final UserJid user) {
    // menu.findItem(R.id.action_chat).setOnMenuItemClickListener(
    // new MenuItem.OnMenuItemClickListener() {
    // 
    // @Override
    // public boolean onMenuItemClick(MenuItem item) {
    // MessageManager.getInstance().openChat(account, user);
    // activity.startActivity(ChatActivity.createSpecificChatIntent(
    // activity, account, user));
    // return true;
    // }
    // });
    menu.findItem(R.id.action_edit_conference).setIntent(ConferenceAddActivity.createIntent(activity, account, user.getBareUserJid()));
    menu.findItem(R.id.action_delete_conference).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            MUCDeleteDialogFragment.newInstance(account, user).show(activity.getFragmentManager(), "MUC_DELETE");
            return true;
        }
    });
    menu.findItem(R.id.action_join_conference).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            MUCManager.getInstance().joinRoom(account, user.getJid().asEntityBareJidIfPossible(), true);
            return true;
        }
    });
    menu.findItem(R.id.action_leave_conference).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            MUCManager.getInstance().leaveRoom(account, user.getJid().asEntityBareJidIfPossible());
            MessageManager.getInstance().closeChat(account, user);
            NotificationManager.getInstance().removeMessageNotification(account, user);
            presenter.updateContactList();
            return true;
        }
    });
    // menu.findItem(R.id.action_contact_info).setIntent(
    // ContactEditActivity.createIntent(activity, account, user));
    menu.findItem(R.id.action_edit_contact_groups).setIntent(GroupEditActivity.createIntent(activity, account, user));
    menu.findItem(R.id.action_delete_contact).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            ContactDeleteDialogFragment.newInstance(account, user).show(activity.getFragmentManager(), "CONTACT_DELETE");
            return true;
        }
    });
    menu.findItem(R.id.action_block_contact).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            BlockContactDialog.newInstance(account, user).show(activity.getFragmentManager(), BlockContactDialog.class.getName());
            return true;
        }
    });
    // menu.findItem(R.id.action_close_chat).setOnMenuItemClickListener(
    // new MenuItem.OnMenuItemClickListener() {
    // 
    // @Override
    // public boolean onMenuItemClick(MenuItem item) {
    // MessageManager.getInstance().closeChat(account,
    // user);
    // NotificationManager.getInstance()
    // .removeMessageNotification(account,
    // user);
    // adapter.onChange();
    // return true;
    // }
    // 
    // });
    // menu.findItem(R.id.action_request_subscription)
    // .setOnMenuItemClickListener(
    // new MenuItem.OnMenuItemClickListener() {
    // 
    // @Override
    // public boolean onMenuItemClick(MenuItem item) {
    // try {
    // PresenceManager.getInstance()
    // .requestSubscription(
    // account, user);
    // } catch (NetworkException e) {
    // Application.getInstance()
    // .onError(e);
    // }
    // return true;
    // }
    // 
    // });
    menu.findItem(R.id.action_accept_subscription).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            try {
                PresenceManager.getInstance().acceptSubscription(account, user);
            } catch (NetworkException e) {
                Application.getInstance().onError(e);
            }
            activity.startActivity(GroupEditActivity.createIntent(activity, account, user));
            return true;
        }
    });
    menu.findItem(R.id.action_discard_subscription).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            try {
                PresenceManager.getInstance().discardSubscription(account, user);
            } catch (NetworkException e) {
                Application.getInstance().onError(e);
            }
            return true;
        }
    });
    // menu.findItem(R.id.action_archive_chat).setOnMenuItemClickListener(
    // new MenuItem.OnMenuItemClickListener() {
    // @Override
    // public boolean onMenuItemClick(MenuItem item) {
    // AbstractChat chat = MessageManager.getInstance().getChat(account, user);
    // if (chat != null) chat.setArchived(true, true);
    // adapter.onChange();
    // return true;
    // }
    // });
    // 
    // menu.findItem(R.id.action_unarchive_chat).setOnMenuItemClickListener(
    // new MenuItem.OnMenuItemClickListener() {
    // @Override
    // public boolean onMenuItemClick(MenuItem item) {
    // AbstractChat chat = MessageManager.getInstance().getChat(account, user);
    // if (chat != null) chat.setArchived(false, true);
    // adapter.onChange();
    // return true;
    // }
    // });
    menu.findItem(R.id.action_mute_chat).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            AbstractChat chat = MessageManager.getInstance().getChat(account, user);
            if (chat != null)
                chat.setNotificationState(new NotificationState(NotificationState.NotificationMode.disabled, 0), true);
            presenter.updateContactList();
            return true;
        }
    });
    menu.findItem(R.id.action_unmute_chat).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            AbstractChat chat = MessageManager.getInstance().getChat(account, user);
            if (chat != null)
                chat.setNotificationState(new NotificationState(NotificationState.NotificationMode.enabled, 0), true);
            presenter.updateContactList();
            return true;
        }
    });
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) MenuItem(android.view.MenuItem) NetworkException(com.xabber.android.data.NetworkException) NotificationState(com.xabber.android.data.message.NotificationState)

Aggregations

NotificationState (com.xabber.android.data.message.NotificationState)4 AbstractChat (com.xabber.android.data.message.AbstractChat)3 NetworkException (com.xabber.android.data.NetworkException)2 Nullable (android.support.annotation.Nullable)1 MenuItem (android.view.MenuItem)1 ChatDataRealm (com.xabber.android.data.database.realm.ChatDataRealm)1 NotificationStateRealm (com.xabber.android.data.database.realm.NotificationStateRealm)1 AccountJid (com.xabber.android.data.entity.AccountJid)1 UserJid (com.xabber.android.data.entity.UserJid)1 ChatData (com.xabber.android.data.message.ChatData)1 BlockContactDialog (com.xabber.android.ui.dialog.BlockContactDialog)1 Realm (io.realm.Realm)1