use of androidx.annotation.StringRes in project Conversations by siacs.
the class ChooseContactActivity method getTitleFromIntent.
@StringRes
public int getTitleFromIntent() {
final Intent intent = getIntent();
boolean multiple = intent != null && intent.getBooleanExtra(EXTRA_SELECT_MULTIPLE, false);
@StringRes int fallback = multiple ? R.string.title_activity_choose_contacts : R.string.title_activity_choose_contact;
return intent != null ? intent.getIntExtra(EXTRA_TITLE_RES_ID, fallback) : fallback;
}
use of androidx.annotation.StringRes in project Conversations by siacs.
the class PgpEngine method encrypt.
public void encrypt(final Message message, final UiCallback<Message> callback) {
Intent params = new Intent();
params.setAction(OpenPgpApi.ACTION_ENCRYPT);
final Conversation conversation = (Conversation) message.getConversation();
if (conversation.getMode() == Conversation.MODE_SINGLE) {
long[] keys = { conversation.getContact().getPgpKeyId(), conversation.getAccount().getPgpId() };
params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, keys);
} else {
params.putExtra(OpenPgpApi.EXTRA_KEY_IDS, conversation.getMucOptions().getPgpKeyIds());
}
if (!message.needsUploading()) {
params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
String body;
if (message.hasFileOnRemoteHost()) {
body = message.getFileParams().url;
} else {
body = message.getBody();
}
InputStream is = new ByteArrayInputStream(body.getBytes());
final OutputStream os = new ByteArrayOutputStream();
api.executeApiAsync(params, is, os, result -> {
switch(result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS:
try {
os.flush();
final ArrayList<String> encryptedMessageBody = new ArrayList<>();
final String[] lines = os.toString().split("\n");
for (int i = 2; i < lines.length - 1; ++i) {
if (!lines[i].contains("Version")) {
encryptedMessageBody.add(lines[i].trim());
}
}
message.setEncryptedBody(Joiner.on('\n').join(encryptedMessageBody));
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
mXmppConnectionService.sendMessage(message);
callback.success(message);
} catch (IOException e) {
callback.error(R.string.openpgp_error, message);
}
break;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
callback.userInputRequired(result.getParcelableExtra(OpenPgpApi.RESULT_INTENT), message);
break;
case OpenPgpApi.RESULT_CODE_ERROR:
OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
String errorMessage = error != null ? error.getMessage() : null;
@StringRes final int res;
if (errorMessage != null && errorMessage.startsWith("Bad key for encryption")) {
res = R.string.bad_key_for_encryption;
} else {
res = R.string.openpgp_error;
}
logError(conversation.getAccount(), error);
callback.error(res, message);
break;
}
});
} else {
try {
DownloadableFile inputFile = this.mXmppConnectionService.getFileBackend().getFile(message, true);
DownloadableFile outputFile = this.mXmppConnectionService.getFileBackend().getFile(message, false);
outputFile.getParentFile().mkdirs();
outputFile.createNewFile();
final InputStream is = new FileInputStream(inputFile);
final OutputStream os = new FileOutputStream(outputFile);
api.executeApiAsync(params, is, os, result -> {
switch(result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS:
try {
os.flush();
} catch (IOException ignored) {
// ignored
}
FileBackend.close(os);
mXmppConnectionService.sendMessage(message);
callback.success(message);
break;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
callback.userInputRequired(result.getParcelableExtra(OpenPgpApi.RESULT_INTENT), message);
break;
case OpenPgpApi.RESULT_CODE_ERROR:
logError(conversation.getAccount(), result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
callback.error(R.string.openpgp_error, message);
break;
}
});
} catch (final IOException e) {
callback.error(R.string.openpgp_error, message);
}
}
}
use of androidx.annotation.StringRes in project Conversations by siacs.
the class XmppActivity method quickEdit.
@SuppressLint("InflateParams")
private void quickEdit(final String previousValue, final OnValueEdited callback, @StringRes final int hint, boolean password, boolean permitEmpty) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
DialogQuickeditBinding binding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.dialog_quickedit, null, false);
if (password) {
binding.inputEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
builder.setPositiveButton(R.string.accept, null);
if (hint != 0) {
binding.inputLayout.setHint(getString(hint));
}
binding.inputEditText.requestFocus();
if (previousValue != null) {
binding.inputEditText.getText().append(previousValue);
}
builder.setView(binding.getRoot());
builder.setNegativeButton(R.string.cancel, null);
final AlertDialog dialog = builder.create();
dialog.setOnShowListener(d -> SoftKeyboardUtils.showKeyboard(binding.inputEditText));
dialog.show();
View.OnClickListener clickListener = v -> {
String value = binding.inputEditText.getText().toString();
if (!value.equals(previousValue) && (!value.trim().isEmpty() || permitEmpty)) {
String error = callback.onValueEdited(value);
if (error != null) {
binding.inputLayout.setError(error);
return;
}
}
SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
dialog.dismiss();
};
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(clickListener);
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener((v -> {
SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
dialog.dismiss();
}));
dialog.setCanceledOnTouchOutside(false);
dialog.setOnDismissListener(dialog1 -> {
SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
});
}
Aggregations