use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method createAdhocConference.
public boolean createAdhocConference(final Account account, final String subject, final Iterable<Jid> jids, final UiCallback<Conversation> callback) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": creating adhoc conference with " + jids.toString());
if (account.getStatus() == Account.State.ONLINE) {
try {
String server = findConferenceServer(account);
if (server == null) {
if (callback != null) {
callback.error(R.string.no_conference_server_found, null);
}
return false;
}
final Jid jid = Jid.fromParts(new BigInteger(64, getRNG()).toString(Character.MAX_RADIX), server, null);
final Conversation conversation = findOrCreateConversation(account, jid, true, false, true);
joinMuc(conversation, new OnConferenceJoined() {
@Override
public void onConferenceJoined(final Conversation conversation) {
pushConferenceConfiguration(conversation, IqGenerator.defaultRoomConfiguration(), new OnConfigurationPushed() {
@Override
public void onPushSucceeded() {
if (subject != null && !subject.trim().isEmpty()) {
pushSubjectToConference(conversation, subject.trim());
}
for (Jid invite : jids) {
invite(conversation, invite);
}
if (account.countPresences() > 1) {
directInvite(conversation, account.getJid().toBareJid());
}
saveConversationAsBookmark(conversation, subject);
if (callback != null) {
callback.success(conversation);
}
}
@Override
public void onPushFailed() {
archiveConversation(conversation);
if (callback != null) {
callback.error(R.string.conference_creation_failed, conversation);
}
}
});
}
});
return true;
} catch (InvalidJidException e) {
if (callback != null) {
callback.error(R.string.conference_creation_failed, null);
}
return true;
}
} else {
if (callback != null) {
callback.error(R.string.not_connected_try_again, null);
}
return true;
}
}
use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.
the class BlockContactDialog method show.
public static void show(final XmppActivity xmppActivity, final Blockable blockable) {
final AlertDialog.Builder builder = new AlertDialog.Builder(xmppActivity);
final boolean isBlocked = blockable.isBlocked();
builder.setNegativeButton(R.string.cancel, null);
LayoutInflater inflater = (LayoutInflater) xmppActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout view = (LinearLayout) inflater.inflate(R.layout.dialog_block_contact, null);
TextView message = view.findViewById(R.id.text);
final CheckBox report = view.findViewById(R.id.report_spam);
final boolean reporting = blockable.getAccount().getXmppConnection().getFeatures().spamReporting();
report.setVisibility(!isBlocked && reporting ? View.VISIBLE : View.GONE);
builder.setView(view);
String value;
SpannableString spannable;
if (blockable.getJid().isDomainJid() || blockable.getAccount().isBlocked(blockable.getJid().toDomainJid())) {
builder.setTitle(isBlocked ? R.string.action_unblock_domain : R.string.action_block_domain);
value = blockable.getJid().toDomainJid().toString();
spannable = new SpannableString(xmppActivity.getString(isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text, value));
} else {
int resBlockAction = blockable instanceof Conversation && ((Conversation) blockable).isWithStranger() ? R.string.block_stranger : R.string.action_block_contact;
builder.setTitle(isBlocked ? R.string.action_unblock_contact : resBlockAction);
value = blockable.getJid().toBareJid().toString();
spannable = new SpannableString(xmppActivity.getString(isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text, value));
}
int start = spannable.toString().indexOf(value);
if (start >= 0) {
spannable.setSpan(new TypefaceSpan("monospace"), start, start + value.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
message.setText(spannable);
builder.setPositiveButton(isBlocked ? R.string.unblock : R.string.block, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
if (isBlocked) {
xmppActivity.xmppConnectionService.sendUnblockRequest(blockable);
} else {
boolean toastShown = false;
if (xmppActivity.xmppConnectionService.sendBlockRequest(blockable, report.isChecked())) {
Toast.makeText(xmppActivity, R.string.corresponding_conversations_closed, Toast.LENGTH_SHORT).show();
toastShown = true;
}
if (xmppActivity instanceof ContactDetailsActivity) {
if (!toastShown) {
Toast.makeText(xmppActivity, R.string.contact_blocked_past_tense, Toast.LENGTH_SHORT).show();
}
xmppActivity.finish();
}
}
}
});
builder.create().show();
}
use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.
the class ConversationAdapter method getView.
@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.conversation_list_row, parent, false);
}
ViewHolder viewHolder = ViewHolder.get(view);
Conversation conversation = getItem(position);
if (this.activity instanceof XmppActivity) {
int c = Color.get(activity, conversation == selectedConversation ? R.attr.color_background_secondary : R.attr.color_background_primary);
viewHolder.swipeableItem.setBackgroundColor(c);
}
if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) {
viewHolder.name.setText(EmojiWrapper.transform(conversation.getName()));
} else {
viewHolder.name.setText(conversation.getJid().toBareJid().toString());
}
Message message = conversation.getLatestMessage();
int unreadcount = conversation.unreadCount();
int failedcount = conversation.failedCount();
viewHolder.receivedStatus.setVisibility(View.GONE);
viewHolder.readStatus.setVisibility(View.GONE);
if (!conversation.isRead()) {
viewHolder.name.setTypeface(null, Typeface.BOLD);
} else {
viewHolder.name.setTypeface(null, Typeface.NORMAL);
}
if (unreadcount > 0) {
viewHolder.unreadCount.setVisibility(View.VISIBLE);
viewHolder.unreadCount.setText(unreadcount > 99 ? "\u221E" : String.valueOf(unreadcount));
} else {
viewHolder.unreadCount.setVisibility(View.GONE);
}
if (failedcount > 0) {
viewHolder.failedCount.setVisibility(View.VISIBLE);
viewHolder.failedCount.setText(failedcount > 99 ? "\u221E" : String.valueOf(failedcount));
} else {
viewHolder.failedCount.setVisibility(View.GONE);
}
final boolean fileAvailable = message.getTransferable() == null || message.getTransferable().getStatus() != Transferable.STATUS_DELETED;
final boolean showPreviewText;
if (fileAvailable && (message.isFileOrImage() || message.treatAsDownloadable() || message.isGeoUri())) {
final int imageResource;
if (message.isGeoUri()) {
imageResource = activity.getThemeResource(R.attr.ic_attach_location, R.drawable.ic_attach_location);
showPreviewText = false;
} else {
final String mime = message.getMimeType();
switch(mime == null ? "" : mime.split("/")[0]) {
case "image":
imageResource = activity.getThemeResource(R.attr.ic_attach_photo, R.drawable.ic_attach_photo);
showPreviewText = false;
break;
case "video":
imageResource = activity.getThemeResource(R.attr.ic_attach_video, R.drawable.ic_attach_video);
showPreviewText = false;
break;
case "audio":
imageResource = activity.getThemeResource(R.attr.ic_attach_record, R.drawable.ic_attach_record);
showPreviewText = false;
break;
default:
imageResource = activity.getThemeResource(R.attr.ic_attach_document, R.drawable.ic_attach_document);
showPreviewText = true;
break;
}
}
viewHolder.lastMessageIcon.setImageResource(imageResource);
viewHolder.lastMessageIcon.setVisibility(View.VISIBLE);
} else {
viewHolder.lastMessageIcon.setVisibility(View.GONE);
showPreviewText = true;
}
final Pair<String, Boolean> preview = UIHelper.getMessagePreview(activity, message);
if (showPreviewText) {
viewHolder.lastMessage.setText(EmojiWrapper.transform(preview.first));
} else {
viewHolder.lastMessageIcon.setContentDescription(preview.first);
}
viewHolder.lastMessage.setVisibility(showPreviewText ? View.VISIBLE : View.GONE);
if (preview.second) {
if (conversation.isRead()) {
viewHolder.lastMessage.setTypeface(null, Typeface.ITALIC);
viewHolder.sender.setTypeface(null, Typeface.NORMAL);
} else {
viewHolder.lastMessage.setTypeface(null, Typeface.BOLD_ITALIC);
viewHolder.sender.setTypeface(null, Typeface.BOLD);
}
} else {
if (conversation.isRead()) {
viewHolder.lastMessage.setTypeface(null, Typeface.NORMAL);
viewHolder.sender.setTypeface(null, Typeface.NORMAL);
} else {
viewHolder.lastMessage.setTypeface(null, Typeface.BOLD);
viewHolder.sender.setTypeface(null, Typeface.BOLD);
}
}
if (message.getStatus() == Message.STATUS_RECEIVED) {
if (conversation.getMode() == Conversation.MODE_MULTI) {
viewHolder.sender.setVisibility(View.VISIBLE);
viewHolder.sender.setText(UIHelper.getMessageDisplayName(message).split("\\s+")[0] + ':');
} else {
viewHolder.sender.setVisibility(View.GONE);
}
} else if (message.getType() != Message.TYPE_STATUS) {
viewHolder.sender.setVisibility(View.VISIBLE);
viewHolder.sender.setText(activity.getString(R.string.me) + ':');
} else {
viewHolder.sender.setVisibility(View.GONE);
}
long muted_till = conversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0);
if (muted_till == Long.MAX_VALUE) {
viewHolder.notificationIcon.setVisibility(View.VISIBLE);
viewHolder.notificationIcon.setImageResource(R.drawable.ic_notifications_off_grey600_24dp);
} else if (muted_till >= System.currentTimeMillis()) {
viewHolder.notificationIcon.setVisibility(View.VISIBLE);
viewHolder.notificationIcon.setImageResource(R.drawable.ic_notifications_paused_grey600_24dp);
} else if (conversation.alwaysNotify()) {
viewHolder.notificationIcon.setVisibility(View.GONE);
} else {
viewHolder.notificationIcon.setVisibility(View.VISIBLE);
viewHolder.notificationIcon.setImageResource(R.drawable.ic_notifications_none_grey600_24dp);
}
viewHolder.timestamp.setText(UIHelper.readableTimeDifference(activity, conversation.getLatestMessage().getTimeSent()));
loadAvatar(conversation, viewHolder.avatar);
if (conversation.getMode() == Conversation.MODE_SINGLE && ShowPresenceColoredNames()) {
switch(conversation.getContact().getPresences().getShownStatus()) {
case CHAT:
case ONLINE:
viewHolder.name.setTextColor(ContextCompat.getColor(activity, R.color.online));
break;
case AWAY:
viewHolder.name.setTextColor(ContextCompat.getColor(activity, R.color.away));
break;
case XA:
case DND:
viewHolder.name.setTextColor(ContextCompat.getColor(activity, R.color.notavailable));
break;
default:
viewHolder.name.setTextColor(ContextCompat.getColor(activity, R.color.black87));
break;
}
} else {
viewHolder.name.setTextColor(ContextCompat.getColor(activity, R.color.black87));
}
if (activity.xmppConnectionService.indicateReceived()) {
switch(message.getMergedStatus()) {
case Message.STATUS_SEND_RECEIVED:
viewHolder.receivedStatus.setVisibility(View.VISIBLE);
break;
case Message.STATUS_SEND_DISPLAYED:
viewHolder.receivedStatus.setVisibility(View.VISIBLE);
viewHolder.readStatus.setVisibility(View.VISIBLE);
break;
}
}
if (conversation.getMode() == Conversation.MODE_SINGLE) {
if (conversation.getIncomingChatState().equals(ChatState.COMPOSING)) {
viewHolder.lastMessage.setText(R.string.is_typing);
viewHolder.lastMessage.setTypeface(null, Typeface.BOLD_ITALIC);
viewHolder.sender.setVisibility(View.GONE);
}
} 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);
}
if (state == ChatState.COMPOSING) {
if (userWithChatStates.size() > 0) {
if (userWithChatStates.size() == 1) {
MucOptions.User user = userWithChatStates.get(0);
viewHolder.lastMessage.setText(activity.getString(R.string.contact_is_typing, UIHelper.getDisplayName(user)));
viewHolder.lastMessage.setTypeface(null, Typeface.BOLD_ITALIC);
viewHolder.sender.setVisibility(View.GONE);
} else {
StringBuilder builder = new StringBuilder();
for (MucOptions.User user : userWithChatStates) {
if (builder.length() != 0) {
builder.append(", ");
}
builder.append(UIHelper.getDisplayName(user));
}
viewHolder.lastMessage.setText(activity.getString(R.string.contacts_are_typing, builder.toString()));
viewHolder.lastMessage.setTypeface(null, Typeface.BOLD_ITALIC);
viewHolder.sender.setVisibility(View.GONE);
}
}
}
}
}
return view;
}
use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.
the class ExceptionHelper method checkForCrash.
public static boolean checkForCrash(XmppActivity activity) {
try {
final XmppConnectionService service = activity == null ? null : activity.xmppConnectionService;
if (service == null) {
return false;
}
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
boolean crashreport = preferences.getBoolean("crashreport", activity.getResources().getBoolean(R.bool.send_crashreport));
if (!crashreport || Config.BUG_REPORTS == null) {
return false;
}
List<Account> accounts = service.getAccounts();
Account account = null;
for (int i = 0; i < accounts.size(); ++i) {
if (accounts.get(i).isEnabled()) {
account = accounts.get(i);
break;
}
}
if (account == null) {
return false;
}
final Account finalAccount = account;
FileInputStream file = activity.openFileInput(FILENAME);
InputStreamReader inputStreamReader = new InputStreamReader(file);
BufferedReader stacktrace = new BufferedReader(inputStreamReader);
final StringBuilder report = new StringBuilder();
PackageManager pm = activity.getPackageManager();
PackageInfo packageInfo;
try {
packageInfo = pm.getPackageInfo(activity.getPackageName(), PackageManager.GET_SIGNATURES);
report.append("Version: ").append(packageInfo.versionName).append('\n');
report.append("Last Update: ").append(DATE_FORMAT.format(new Date(packageInfo.lastUpdateTime))).append('\n');
Signature[] signatures = packageInfo.signatures;
if (signatures != null && signatures.length >= 1) {
report.append("SHA-1: ").append(CryptoHelper.getFingerprintCert(packageInfo.signatures[0].toByteArray())).append('\n');
}
report.append('\n');
} catch (Exception e) {
e.printStackTrace();
return false;
}
String line;
while ((line = stacktrace.readLine()) != null) {
report.append(line);
report.append('\n');
}
file.close();
activity.deleteFile(FILENAME);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(activity.getString(R.string.crash_report_title));
builder.setMessage(activity.getText(R.string.crash_report_message));
builder.setPositiveButton(activity.getText(R.string.send_now), new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.d(Config.LOGTAG, "using account=" + finalAccount.getJid().toBareJid() + " to send in stack trace");
Conversation conversation = null;
try {
conversation = service.findOrCreateConversation(finalAccount, Jid.fromString(Config.BUG_REPORTS), false, true);
} catch (final InvalidJidException ignored) {
}
Message message = new Message(conversation, report.toString(), Message.ENCRYPTION_NONE);
service.sendMessage(message);
}
});
builder.setNegativeButton(activity.getText(R.string.send_never), new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
preferences.edit().putBoolean("crash_report", false).apply();
}
});
builder.create().show();
return true;
} catch (final IOException ignored) {
return false;
}
}
Aggregations