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;
}
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;
}
}
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;
}
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;
}
});
}
Aggregations