remove functions from subclassed DcContext

the functions were part of ApplicationDcContext for no special reason,
however, now standing in the way of avoiding subclassing DcContext
(to use the DcContext objects returned from DcAccounts directly).
This commit is contained in:
B. Petersen
2021-07-22 22:59:22 +02:00
parent 4c679053b9
commit b28a62a1ea
32 changed files with 306 additions and 331 deletions
@@ -16,6 +16,7 @@ import androidx.work.WorkManager;
import org.thoughtcrime.securesms.components.emoji.EmojiProvider;
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.connect.FetchWorker;
import org.thoughtcrime.securesms.connect.ForegroundDetector;
import org.thoughtcrime.securesms.connect.KeepAliveService;
@@ -85,13 +86,13 @@ public class ApplicationContext extends MultiDexApplication {
DynamicTheme.setDefaultDayNightMode(this);
dcContext.setStockTranslations();
DcHelper.setStockTranslations(this);
IntentFilter filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
dcContext.setStockTranslations();
DcHelper.setStockTranslations(context);
}
}, filter);
@@ -469,7 +469,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
menu.findItem(R.id.menu_show_map).setVisible(false);
}
if (!dcContext.isWebrtcConfigOk() || !dcChat.canVideochat()) {
if (!DcHelper.isWebrtcConfigOk(dcContext) || !dcChat.canVideochat()) {
menu.findItem(R.id.menu_videochat_invite).setVisible(false);
}
@@ -958,7 +958,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
if(chatId == DcChat.DC_CHAT_NO_CHAT)
throw new IllegalStateException("can't display a conversation for no chat.");
dcChat = dcContext.getChat(chatId);
recipient = dcContext.getRecipient(dcChat);
recipient = new Recipient(this, dcChat);
glideRequests = GlideApp.with(this);
@@ -1050,7 +1050,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
filename = filename.substring(0, i);
}
}
String path = dcContext.getBlobdirFile(filename, ext);
String path = DcHelper.getBlobdirFile(dcContext, filename, ext);
// copy content to this file
if(path!=null) {
@@ -1518,7 +1518,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
@Override
public void handleReplyMessage(DcMsg msg) {
// If you modify these lines you may also want to modify ConversationItem.setQuote():
Recipient author = dcContext.getRecipient(dcContext.getContact(msg.getFromId()));
Recipient author = new Recipient(this, dcContext.getContact(msg.getFromId()));
SlideDeck slideDeck = new SlideDeck();
if (msg.getType() != DcMsg.DC_MSG_TEXT) {
@@ -872,7 +872,7 @@ public class ConversationFragment extends MessageSelectorFragment
handleDeleteMessages(getListAdapter().getSelectedItems());
return true;
case R.id.menu_context_share:
dcContext.openForViewOrShare(getContext(), getSelectedMessageRecord(getListAdapter().getSelectedItems()).getId(), Intent.ACTION_SEND);
DcHelper.openForViewOrShare(getContext(), getSelectedMessageRecord(getListAdapter().getSelectedItems()).getId(), Intent.ACTION_SEND);
return true;
case R.id.menu_context_details:
handleDisplayDetails(getSelectedMessageRecord(getListAdapter().getSelectedItems()));
@@ -49,6 +49,7 @@ import org.thoughtcrime.securesms.components.ConversationItemThumbnail;
import org.thoughtcrime.securesms.components.DocumentView;
import org.thoughtcrime.securesms.components.QuoteView;
import org.thoughtcrime.securesms.components.emoji.EmojiTextView;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.mms.AudioSlide;
import org.thoughtcrime.securesms.mms.DocumentSlide;
import org.thoughtcrime.securesms.mms.GlideApp;
@@ -517,7 +518,7 @@ public class ConversationItem extends BaseConversationItem
if (messageRecord.isOutgoing() || !showSender || dcContact ==null) {
contactPhoto.setVisibility(View.GONE);
} else {
contactPhoto.setAvatar(glideRequests, dcContext.getRecipient(dcContact), true);
contactPhoto.setAvatar(glideRequests, new Recipient(context, dcContact), true);
contactPhoto.setVisibility(View.VISIBLE);
}
}
@@ -542,7 +543,7 @@ public class ConversationItem extends BaseConversationItem
Recipient author = null;
SlideDeck slideDeck = new SlideDeck();
if (msg != null) {
author = dcContext.getRecipient(dcContext.getContact(msg.getFromId()));
author = new Recipient(context, dcContext.getContact(msg.getFromId()));
if (msg.getType() != DcMsg.DC_MSG_TEXT) {
Slide slide = MediaUtil.getSlideForMsg(context, msg);
if (slide != null) {
@@ -713,7 +714,7 @@ public class ConversationItem extends BaseConversationItem
context.startActivity(intent);
} else if (slide.getUri() != null) {
dcContext.openForViewOrShare(context, slide.getDcMsgId(), Intent.ACTION_VIEW);
DcHelper.openForViewOrShare(context, slide.getDcMsgId(), Intent.ACTION_VIEW);
}
}
}
@@ -33,6 +33,7 @@ import org.thoughtcrime.securesms.connect.ApplicationDcContext;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.mms.GlideRequests;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
@@ -49,6 +50,7 @@ class ConversationListAdapter extends RecyclerView.Adapter {
private static final int MESSAGE_TYPE_THREAD = 2;
private static final int MESSAGE_TYPE_INBOX_ZERO = 3;
private final WeakReference<Context> context;
private final @NonNull ApplicationDcContext dcContext;
private @NonNull DcChatlist dcChatlist;
private final @NonNull GlideRequests glideRequests;
@@ -86,6 +88,7 @@ class ConversationListAdapter extends RecyclerView.Adapter {
@Nullable ItemClickListener clickListener)
{
super();
this.context = new WeakReference<>(context);
this.glideRequests = glideRequests;
this.dcContext = DcHelper.getContext(context);
this.dcChatlist = new DcChatlist(0);
@@ -127,10 +130,15 @@ class ConversationListAdapter extends RecyclerView.Adapter {
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
Context context = this.context.get();
if (context == null) {
return;
}
ViewHolder holder = (ViewHolder)viewHolder;
DcChat chat = dcContext.getChat(dcChatlist.getChatId(i));
DcLot summary = dcChatlist.getSummary(i, chat);
holder.getItem().bind(dcContext.getThreadRecord(summary, chat), dcChatlist.getMsgId(i), summary, glideRequests, locale, batchSet, batchMode);
holder.getItem().bind(DcHelper.getThreadRecord(context, summary, chat), dcChatlist.getMsgId(i), summary, glideRequests, locale, batchSet, batchMode);
}
@Override
@@ -188,4 +196,4 @@ class ConversationListAdapter extends RecyclerView.Adapter {
dcChatlist = chatlist == null ? new DcChatlist(0) : chatlist;
notifyDataSetChanged();
}
}
}
@@ -178,7 +178,7 @@ public class ConversationListItem extends RelativeLayout
@Nullable String highlightSubstring)
{
this.selectedThreads = Collections.emptySet();
Recipient recipient = DcHelper.getContext(getContext()).getRecipient(contact);
Recipient recipient = new Recipient(getContext(), contact);
this.glideRequests = glideRequests;
fromView.setText(getHighlightedSpan(locale, contact.getDisplayName(), highlightSubstring));
@@ -202,7 +202,7 @@ public class ConversationListItem extends RelativeLayout
ApplicationDcContext dcContext = DcHelper.getContext(getContext());
DcContact sender = dcContext.getContact(messageResult.getFromId());
this.selectedThreads = Collections.emptySet();
Recipient recipient = DcHelper.getContext(getContext()).getRecipient(sender);
Recipient recipient = new Recipient(getContext(), sender);
this.glideRequests = glideRequests;
fromView.setText(recipient, true);
@@ -17,6 +17,7 @@ import com.b44t.messenger.DcContext;
import org.thoughtcrime.securesms.components.AvatarImageView;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.mms.GlideRequests;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.ViewUtil;
public class ConversationTitleView extends RelativeLayout {
@@ -98,7 +99,7 @@ public class ConversationTitleView extends RelativeLayout {
imgRight = R.drawable.ic_verified;
}
avatar.setAvatar(glideRequests, DcHelper.getContext(getContext()).getRecipient(dcChat), false);
avatar.setAvatar(glideRequests, new Recipient(getContext(), dcChat), false);
title.setCompoundDrawablesWithIntrinsicBounds(imgLeft, 0, imgRight, 0);
subtitle.setVisibility(showAddInfo? View.VISIBLE : View.GONE);
@@ -109,7 +110,7 @@ public class ConversationTitleView extends RelativeLayout {
public void setTitle(@NonNull GlideRequests glideRequests, @NonNull DcContact contact) {
// the verified state is _not_ shown in the title. this will be confusing as in the one-to-one-ChatViews, the verified
// icon is also not shown as these chats are always opportunistic chats
avatar.setAvatar(glideRequests, DcHelper.getContext(getContext()).getRecipient(contact), false);
avatar.setAvatar(glideRequests, new Recipient(getContext(), contact), false);
title.setText(contact.getDisplayName());
title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
subtitle.setText(contact.getAddr());
@@ -73,7 +73,7 @@ public class ConversationVideochatItem extends LinearLayout
body.setText(TextUtils.concat(line1, "\n", line2));
contactPhoto.setAvatar(glideRequests, dcContext.getRecipient(dcContact), true);
contactPhoto.setAvatar(glideRequests, new Recipient(getContext(), dcContact), true);
setSelected(batchSelected.contains(dcMsg));
setFooter(dcMsg, locale);
@@ -208,7 +208,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
groupName = ViewUtil.findById(this, R.id.group_name);
List<Recipient> initList = new LinkedList<>();
DcContact self = dcContext.getContact(DC_CONTACT_ID_SELF);
initList.add(dcContext.getRecipient(self));
initList.add(new Recipient(this, self));
SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(this, initList);
adapter.setOnRecipientDeletedListener(this);
lv.setAdapter(adapter);
@@ -503,7 +503,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
@Override
protected Recipient doInBackground(Integer... recipientIds) {
Integer recipientsId = recipientIds[0];
return activity.dcContext.getRecipient(ApplicationDcContext.RECIPIENT_TYPE_CHAT, recipientsId);
return new Recipient(activity, activity.dcContext.getChat(recipientsId));
}
@Override
@@ -291,7 +291,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity
private void share() {
MediaItem mediaItem = getCurrentMediaItem();
if (mediaItem != null) {
dcContext.openForViewOrShare(this, mediaItem.msgId, Intent.ACTION_SEND);
DcHelper.openForViewOrShare(this, mediaItem.msgId, Intent.ACTION_SEND);
}
}
@@ -16,6 +16,7 @@ import com.b44t.messenger.DcMsg;
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
import org.thoughtcrime.securesms.connect.DcEventCenter;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.util.SaveAttachmentTask;
@@ -91,6 +92,6 @@ public abstract class MessageSelectorFragment
}
protected void handleShare(final DcMsg dcMsg) {
dcContext.openForViewOrShare(getContext(), dcMsg.getId(), Intent.ACTION_SEND);
DcHelper.openForViewOrShare(getContext(), dcMsg.getId(), Intent.ACTION_SEND);
}
}
@@ -151,7 +151,7 @@ public class ProfileDocumentsFragment
return;
}
dcContext.openForViewOrShare(getActivity(), dcMsg.getId(), Intent.ACTION_VIEW);
DcHelper.openForViewOrShare(getActivity(), dcMsg.getId(), Intent.ACTION_VIEW);
}
@Override
@@ -171,7 +171,7 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter
DcChat chat = dcContext.getChat(chatId);
DcLot summary = itemDataSharedChats.getSummary(chatlistIndex, chat);
conversationListItem.bind(dcContext.getThreadRecord(summary, chat),
conversationListItem.bind(DcHelper.getThreadRecord(context, summary, chat),
itemDataSharedChats.getMsgId(chatlistIndex), summary, glideRequests,
locale, Collections.emptySet(), false);
conversationListItem.setOnClickListener(view -> clickListener.onSharedChatClicked(chatId));
@@ -99,7 +99,7 @@ public class WelcomeActivity extends BaseActionBarActivity implements DcEventCen
.ifNecessary()
.withPermanentDenialDialog(getString(R.string.perm_explain_access_to_storage_denied))
.onAllGranted(() -> {
File imexDir = dcContext.getImexDir();
File imexDir = DcHelper.getImexDir();
final String backupFile = dcContext.imexHasBackup(imexDir.getAbsolutePath());
if (backupFile != null) {
new AlertDialog.Builder(this)
@@ -182,7 +182,7 @@ public class AudioSlidePlayer {
// Failed to play media file, maybe another app can handle it
int msgId = getAudioSlide().getDcMsgId();
DcHelper.getContext(context).openForViewOrShare(context, msgId, Intent.ACTION_VIEW);
DcHelper.openForViewOrShare(context, msgId, Intent.ACTION_VIEW);
}
});
}
@@ -102,7 +102,7 @@ public class AccountManager {
appContext.dcContext.stopIo();
appContext.dcContext.unref();
appContext.dcContext = new ApplicationDcContext(context);
appContext.dcContext.setStockTranslations();
DcHelper.setStockTranslations(context);
}
@@ -41,13 +41,6 @@ public class ApplicationDcContext extends DcContext {
public static final String TAG = "DeltaChat";
@IntDef({RECIPIENT_TYPE_CHAT, RECIPIENT_TYPE_CONTACT})
public @interface RecipientType {
}
public static final int RECIPIENT_TYPE_CHAT = 0;
public static final int RECIPIENT_TYPE_CONTACT = 1;
public Context context;
public NotificationCenter notificationCenter;
@@ -55,38 +48,6 @@ public class ApplicationDcContext extends DcContext {
super("Android "+BuildConfig.VERSION_NAME, AccountManager.getInstance().getSelectedAccount(context).getAbsolutePath());
this.context = context;
// if ui-based migrations are needed, this is a good place
// (see eg. https://github.com/deltachat/deltachat-android/pull/1618 for an example)
// screen-lock is deprecated, inform users still using it
try {
if (!Prefs.getBooleanPreference(context, "pref_android_screen_lock_checked_1", false)) {
Prefs.setBooleanPreference(context, "pref_android_screen_lock_checked_1", true);
if (Prefs.isScreenLockEnabled(context)) {
Prefs.setScreenLockEnabled(context, false);
DcMsg msg = new DcMsg(this, DcMsg.DC_MSG_TEXT);
msg.setText("⚠️ You were using the function \"Screen lock\" " +
"that was removed for the following reasons:\n" +
"\n" +
"• It did not add much protection as one just has to repeat the system secret.\n" +
"\n" +
"• It was hard to maintain across different Android versions and is not even doable on some." +
" We like to put the resources to other things.\n" +
"\n" +
"• It is not planned/possible on iOS or Desktop this way" +
" and stands in the way of moving towards unified solutions.\n" +
"\n" +
"• Same or even better functionality is available by other apps or maybe by the device itself.\n" +
"\n" +
"\uD83D\uDC49 For the future, we suggest to keep your phone locked " +
"or use an appropriate app or check the device settings.");
addDeviceMsg("android-screen-lock-deprecated17", msg);
}
}
} catch (Exception e) {
e.printStackTrace();
}
new Thread(() -> {
DcEventEmitter emitter = getEventEmitter();
while (true) {
@@ -110,245 +71,6 @@ public class ApplicationDcContext extends DcContext {
}
}
public void setStockTranslations() {
// the integers are defined in the core and used only here, an enum or sth. like that won't have a big benefit
setStockTranslation(1, context.getString(R.string.chat_no_messages));
setStockTranslation(2, context.getString(R.string.self));
setStockTranslation(3, context.getString(R.string.draft));
setStockTranslation(7, context.getString(R.string.voice_message));
setStockTranslation(9, context.getString(R.string.image));
setStockTranslation(10, context.getString(R.string.video));
setStockTranslation(11, context.getString(R.string.audio));
setStockTranslation(12, context.getString(R.string.file));
setStockTranslation(13, context.getString(R.string.pref_default_status_text));
setStockTranslation(14, context.getString(R.string.group_hello_draft));
setStockTranslation(15, context.getString(R.string.systemmsg_group_name_changed));
setStockTranslation(16, context.getString(R.string.systemmsg_group_image_changed));
setStockTranslation(17, context.getString(R.string.systemmsg_member_added));
setStockTranslation(18, context.getString(R.string.systemmsg_member_removed));
setStockTranslation(19, context.getString(R.string.systemmsg_group_left));
setStockTranslation(23, context.getString(R.string.gif));
setStockTranslation(24, context.getString(R.string.encrypted_message));
setStockTranslation(29, context.getString(R.string.systemmsg_cannot_decrypt));
setStockTranslation(31, context.getString(R.string.systemmsg_read_receipt_subject));
setStockTranslation(32, context.getString(R.string.systemmsg_read_receipt_body));
setStockTranslation(33, context.getString(R.string.systemmsg_group_image_deleted));
setStockTranslation(35, context.getString(R.string.contact_verified));
setStockTranslation(36, context.getString(R.string.contact_not_verified));
setStockTranslation(37, context.getString(R.string.contact_setup_changed));
setStockTranslation(40, context.getString(R.string.chat_archived_chats_title));
setStockTranslation(42, context.getString(R.string.autocrypt_asm_subject));
setStockTranslation(43, context.getString(R.string.autocrypt_asm_general_body));
setStockTranslation(60, context.getString(R.string.login_error_cannot_login));
setStockTranslation(62, context.getString(R.string.systemmsg_action_by_user));
setStockTranslation(63, context.getString(R.string.systemmsg_action_by_me));
setStockTranslation(68, context.getString(R.string.device_talk));
setStockTranslation(69, context.getString(R.string.saved_messages));
setStockTranslation(70, context.getString(R.string.device_talk_explain));
setStockTranslation(71, context.getString(R.string.device_talk_welcome_message));
setStockTranslation(72, context.getString(R.string.systemmsg_unknown_sender_for_chat));
setStockTranslation(73, context.getString(R.string.systemmsg_subject_for_new_contact));
setStockTranslation(74, context.getString(R.string.systemmsg_failed_sending_to));
setStockTranslation(75, context.getString(R.string.systemmsg_ephemeral_timer_disabled));
setStockTranslation(76, context.getString(R.string.systemmsg_ephemeral_timer_enabled));
setStockTranslation(77, context.getString(R.string.systemmsg_ephemeral_timer_minute));
setStockTranslation(78, context.getString(R.string.systemmsg_ephemeral_timer_hour));
setStockTranslation(79, context.getString(R.string.systemmsg_ephemeral_timer_day));
setStockTranslation(80, context.getString(R.string.systemmsg_ephemeral_timer_week));
setStockTranslation(82, context.getString(R.string.videochat_invitation));
setStockTranslation(83, context.getString(R.string.videochat_invitation_body));
setStockTranslation(84, context.getString(R.string.configuration_failed_with_error));
setStockTranslation(88, context.getString(R.string.systemmsg_chat_protection_enabled));
setStockTranslation(89, context.getString(R.string.systemmsg_chat_protection_disabled));
setStockTranslation(90, context.getString(R.string.reply_noun));
setStockTranslation(93, context.getString(R.string.systemmsg_ephemeral_timer_minutes));
setStockTranslation(94, context.getString(R.string.systemmsg_ephemeral_timer_hours));
setStockTranslation(95, context.getString(R.string.systemmsg_ephemeral_timer_days));
setStockTranslation(96, context.getString(R.string.systemmsg_ephemeral_timer_weeks));
setStockTranslation(97, context.getString(R.string.forwarded));
}
public File getImexDir() {
// DIRECTORY_DOCUMENTS is only available since KitKat;
// as we also support Ice Cream Sandwich and Jellybean (2017: 11% in total), this is no option.
// Moreover, DIRECTORY_DOWNLOADS seems to be easier accessible by the user,
// eg. "Download Managers" are nearly always installed.
// CAVE: do not use DownloadManager to add the file as it is deleted on uninstall then ...
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
}
public static HashMap<String, Integer> sharedFiles = new HashMap<>();
public void openForViewOrShare(Context activity,
int msg_id, String cmd) {
if(!(activity instanceof Activity)) {
// would be nicer to accepting only Activity objects,
// however, typically in Android just Context objects are passed around (as this normally does not make a difference).
// Accepting only Activity here would force callers to cast, which would easily result in even more ugliness.
Toast.makeText(context, "openForViewOrShare() expects an Activity object", Toast.LENGTH_LONG).show();
return;
}
DcMsg msg = getMsg(msg_id);
String path = msg.getFile();
String mimeType = msg.getFilemime();
try {
File file = new File(path);
if (!file.exists()) {
Toast.makeText(context, context.getString(R.string.file_not_found, path), Toast.LENGTH_LONG).show();
return;
}
Uri uri;
if (path.startsWith(getBlobdir())) {
uri = Uri.parse("content://" + BuildConfig.APPLICATION_ID + ".attachments/" + Uri.encode(file.getName()));
sharedFiles.put("/" + file.getName(), 1); // as different Android version handle uris in putExtra differently, we also check them on our own
} else {
if (Build.VERSION.SDK_INT >= 24) {
uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", file);
} else {
uri = Uri.fromFile(file);
}
}
if (cmd.equals(Intent.ACTION_VIEW)) {
mimeType = checkMime(path, mimeType);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, mimeType);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity((Activity) activity, intent);
} else {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.putExtra(Intent.EXTRA_TEXT, msg.getText());
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
activity.startActivity(Intent.createChooser(intent, context.getString(R.string.chat_share_with_title)));
}
} catch (RuntimeException e) {
Toast.makeText(context, String.format("%s (%s)", context.getString(R.string.no_app_to_handle_data), mimeType), Toast.LENGTH_LONG).show();
Log.i(TAG, "opening of external activity failed.", e);
}
}
private void startActivity(Activity activity, Intent intent) {
// request for permission to install apks on API 26+ if intent mimetype is an apk
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
"application/vnd.android.package-archive".equals(intent.getType()) &&
!activity.getPackageManager().canRequestPackageInstalls()) {
activity.startActivity(new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES).setData(Uri.parse(String.format("package:%s", activity.getPackageName()))));
return;
}
activity.startActivity(intent);
}
private String checkMime(String path, String mimeType) {
if(mimeType == null || mimeType.equals("application/octet-stream")) {
path = path.replaceAll(" ", "");
String extension = MimeTypeMap.getFileExtensionFromUrl(path);
String newType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if(newType != null) return newType;
}
return mimeType;
}
public String getBlobdirFile(String filename, String ext) {
String outPath = null;
for (int i = 0; i < 1000; i++) {
String test = getBlobdir() + "/" + filename + (i == 0 ? "" : i < 100 ? "-" + i : "-" + (new Date().getTime() + i)) + ext;
if (!new File(test).exists()) {
outPath = test;
break;
}
}
if(outPath==null) {
// should not happen
outPath = getBlobdir() + "/" + Math.random();
}
return outPath;
}
public String getBlobdirFile(String path) {
String filename = path.substring(path.lastIndexOf('/')+1); // is the whole path if '/' is not found (lastIndexOf() returns -1 then)
String ext = "";
int point = filename.indexOf('.');
if(point!=-1) {
ext = filename.substring(point);
filename = filename.substring(0, point);
}
return getBlobdirFile(filename, ext);
}
public boolean isWebrtcConfigOk() {
String instance = getConfig(DcHelper.CONFIG_WEBRTC_INSTANCE);
return (instance != null && !instance.isEmpty());
}
/***********************************************************************************************
* create objects compatible to the database model of Signal
**********************************************************************************************/
@NonNull
public Recipient getRecipient(@RecipientType int recipientType, int id) {
switch (recipientType) {
case RECIPIENT_TYPE_CHAT:
return getRecipient(getChat(id));
case RECIPIENT_TYPE_CONTACT:
return getRecipient(getContact(id));
default:
throw new IllegalArgumentException("Wrong RecipientType");
}
}
@NonNull
public Recipient getRecipient(DcChat chat) {
return new Recipient(context, chat, null);
}
@NonNull
public Recipient getRecipient(DcContact contact) {
return new Recipient(context, null, contact);
}
@NonNull
public ThreadRecord getThreadRecord(DcLot summary, DcChat chat) { // adapted from ThreadDatabase.getCurrent()
int chatId = chat.getId();
String body = summary.getText1();
if (!body.isEmpty()) {
body += ": ";
}
body += summary.getText2();
Recipient recipient = getRecipient(chat);
long date = summary.getTimestamp();
int unreadCount = getFreshMsgCount(chatId);
return new ThreadRecord(body, recipient, date,
unreadCount, chatId,
chat.getVisibility(), chat.isProtected(), chat.isSendingLocations(), chat.isMuted(), chat.isContactRequest(), summary);
}
/***********************************************************************************************
* Tools
**********************************************************************************************/
public boolean isNetworkConnected() {
try {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()) {
return true;
}
} catch (Exception e) {
}
return false;
}
/***********************************************************************************************
* Event Handling
**********************************************************************************************/
@@ -28,7 +28,7 @@ public class AttachmentsContentProvider extends ContentProvider {
ApplicationDcContext dcContext = DcHelper.getContext(getContext());
String path = uri.getPath();
if (!dcContext.sharedFiles.containsKey(path)) {
if (!DcHelper.sharedFiles.containsKey(path)) {
throw new FileNotFoundException("File was not shared before.");
}
@@ -1,16 +1,42 @@
package org.thoughtcrime.securesms.connect;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;
import android.util.Log;
import android.webkit.MimeTypeMap;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.core.content.FileProvider;
import com.b44t.messenger.DcChat;
import com.b44t.messenger.DcContact;
import com.b44t.messenger.DcContext;
import com.b44t.messenger.DcLot;
import com.b44t.messenger.DcMsg;
import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.BuildConfig;
import org.thoughtcrime.securesms.ConversationActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.database.model.ThreadRecord;
import org.thoughtcrime.securesms.recipients.Recipient;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
public class DcHelper {
private static final String TAG = DcHelper.class.getSimpleName();
public static final String CONFIG_ADDRESS = "addr";
public static final String CONFIG_MAIL_SERVER = "mail_server";
public static final String CONFIG_MAIL_USER = "mail_user";
@@ -69,6 +95,216 @@ public class DcHelper {
dcContext.setConfig(key, value);
}
public static void setStockTranslations(Context context) {
DcContext dcContext = getContext(context);
// the integers are defined in the core and used only here, an enum or sth. like that won't have a big benefit
dcContext.setStockTranslation(1, context.getString(R.string.chat_no_messages));
dcContext.setStockTranslation(2, context.getString(R.string.self));
dcContext.setStockTranslation(3, context.getString(R.string.draft));
dcContext.setStockTranslation(7, context.getString(R.string.voice_message));
dcContext.setStockTranslation(8, context.getString(R.string.chat_contact_request));
dcContext.setStockTranslation(9, context.getString(R.string.image));
dcContext.setStockTranslation(10, context.getString(R.string.video));
dcContext.setStockTranslation(11, context.getString(R.string.audio));
dcContext.setStockTranslation(12, context.getString(R.string.file));
dcContext.setStockTranslation(13, context.getString(R.string.pref_default_status_text));
dcContext.setStockTranslation(14, context.getString(R.string.group_hello_draft));
dcContext.setStockTranslation(15, context.getString(R.string.systemmsg_group_name_changed));
dcContext.setStockTranslation(16, context.getString(R.string.systemmsg_group_image_changed));
dcContext.setStockTranslation(17, context.getString(R.string.systemmsg_member_added));
dcContext.setStockTranslation(18, context.getString(R.string.systemmsg_member_removed));
dcContext.setStockTranslation(19, context.getString(R.string.systemmsg_group_left));
dcContext.setStockTranslation(23, context.getString(R.string.gif));
dcContext.setStockTranslation(24, context.getString(R.string.encrypted_message));
dcContext.setStockTranslation(29, context.getString(R.string.systemmsg_cannot_decrypt));
dcContext.setStockTranslation(31, context.getString(R.string.systemmsg_read_receipt_subject));
dcContext.setStockTranslation(32, context.getString(R.string.systemmsg_read_receipt_body));
dcContext.setStockTranslation(33, context.getString(R.string.systemmsg_group_image_deleted));
dcContext.setStockTranslation(35, context.getString(R.string.contact_verified));
dcContext.setStockTranslation(36, context.getString(R.string.contact_not_verified));
dcContext.setStockTranslation(37, context.getString(R.string.contact_setup_changed));
dcContext.setStockTranslation(40, context.getString(R.string.chat_archived_chats_title));
dcContext.setStockTranslation(42, context.getString(R.string.autocrypt_asm_subject));
dcContext.setStockTranslation(43, context.getString(R.string.autocrypt_asm_general_body));
dcContext.setStockTranslation(60, context.getString(R.string.login_error_cannot_login));
dcContext.setStockTranslation(62, context.getString(R.string.systemmsg_action_by_user));
dcContext.setStockTranslation(63, context.getString(R.string.systemmsg_action_by_me));
dcContext.setStockTranslation(68, context.getString(R.string.device_talk));
dcContext.setStockTranslation(69, context.getString(R.string.saved_messages));
dcContext.setStockTranslation(70, context.getString(R.string.device_talk_explain));
dcContext.setStockTranslation(71, context.getString(R.string.device_talk_welcome_message));
dcContext.setStockTranslation(72, context.getString(R.string.systemmsg_unknown_sender_for_chat));
dcContext.setStockTranslation(73, context.getString(R.string.systemmsg_subject_for_new_contact));
dcContext.setStockTranslation(74, context.getString(R.string.systemmsg_failed_sending_to));
dcContext.setStockTranslation(75, context.getString(R.string.systemmsg_ephemeral_timer_disabled));
dcContext.setStockTranslation(76, context.getString(R.string.systemmsg_ephemeral_timer_enabled));
dcContext.setStockTranslation(77, context.getString(R.string.systemmsg_ephemeral_timer_minute));
dcContext.setStockTranslation(78, context.getString(R.string.systemmsg_ephemeral_timer_hour));
dcContext.setStockTranslation(79, context.getString(R.string.systemmsg_ephemeral_timer_day));
dcContext.setStockTranslation(80, context.getString(R.string.systemmsg_ephemeral_timer_week));
dcContext.setStockTranslation(82, context.getString(R.string.videochat_invitation));
dcContext.setStockTranslation(83, context.getString(R.string.videochat_invitation_body));
dcContext.setStockTranslation(84, context.getString(R.string.configuration_failed_with_error));
dcContext.setStockTranslation(88, context.getString(R.string.systemmsg_chat_protection_enabled));
dcContext.setStockTranslation(89, context.getString(R.string.systemmsg_chat_protection_disabled));
dcContext.setStockTranslation(90, context.getString(R.string.reply_noun));
dcContext.setStockTranslation(93, context.getString(R.string.systemmsg_ephemeral_timer_minutes));
dcContext.setStockTranslation(94, context.getString(R.string.systemmsg_ephemeral_timer_hours));
dcContext.setStockTranslation(95, context.getString(R.string.systemmsg_ephemeral_timer_days));
dcContext.setStockTranslation(96, context.getString(R.string.systemmsg_ephemeral_timer_weeks));
dcContext.setStockTranslation(97, context.getString(R.string.forwarded));
}
public static File getImexDir() {
// DIRECTORY_DOCUMENTS is only available since KitKat;
// as we also support Ice Cream Sandwich and Jellybean (2017: 11% in total), this is no option.
// Moreover, DIRECTORY_DOWNLOADS seems to be easier accessible by the user,
// eg. "Download Managers" are nearly always installed.
// CAVE: do not use DownloadManager to add the file as it is deleted on uninstall then ...
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
}
public static HashMap<String, Integer> sharedFiles = new HashMap<>();
public static void openForViewOrShare(Context activity, int msg_id, String cmd) {
DcContext dcContext = getContext(activity);
if(!(activity instanceof Activity)) {
// would be nicer to accepting only Activity objects,
// however, typically in Android just Context objects are passed around (as this normally does not make a difference).
// Accepting only Activity here would force callers to cast, which would easily result in even more ugliness.
Toast.makeText(activity, "openForViewOrShare() expects an Activity object", Toast.LENGTH_LONG).show();
return;
}
DcMsg msg = dcContext.getMsg(msg_id);
String path = msg.getFile();
String mimeType = msg.getFilemime();
try {
File file = new File(path);
if (!file.exists()) {
Toast.makeText(activity, activity.getString(R.string.file_not_found, path), Toast.LENGTH_LONG).show();
return;
}
Uri uri;
if (path.startsWith(dcContext.getBlobdir())) {
uri = Uri.parse("content://" + BuildConfig.APPLICATION_ID + ".attachments/" + Uri.encode(file.getName()));
sharedFiles.put("/" + file.getName(), 1); // as different Android version handle uris in putExtra differently, we also check them on our own
} else {
if (Build.VERSION.SDK_INT >= 24) {
uri = FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".fileprovider", file);
} else {
uri = Uri.fromFile(file);
}
}
if (cmd.equals(Intent.ACTION_VIEW)) {
mimeType = checkMime(path, mimeType);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, mimeType);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity((Activity) activity, intent);
} else {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.putExtra(Intent.EXTRA_TEXT, msg.getText());
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
activity.startActivity(Intent.createChooser(intent, activity.getString(R.string.chat_share_with_title)));
}
} catch (RuntimeException e) {
Toast.makeText(activity, String.format("%s (%s)", activity.getString(R.string.no_app_to_handle_data), mimeType), Toast.LENGTH_LONG).show();
Log.i(TAG, "opening of external activity failed.", e);
}
}
private static void startActivity(Activity activity, Intent intent) {
// request for permission to install apks on API 26+ if intent mimetype is an apk
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
"application/vnd.android.package-archive".equals(intent.getType()) &&
!activity.getPackageManager().canRequestPackageInstalls()) {
activity.startActivity(new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES).setData(Uri.parse(String.format("package:%s", activity.getPackageName()))));
return;
}
activity.startActivity(intent);
}
private static String checkMime(String path, String mimeType) {
if(mimeType == null || mimeType.equals("application/octet-stream")) {
path = path.replaceAll(" ", "");
String extension = MimeTypeMap.getFileExtensionFromUrl(path);
String newType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if(newType != null) return newType;
}
return mimeType;
}
public static String getBlobdirFile(DcContext dcContext, String filename, String ext) {
String outPath = null;
for (int i = 0; i < 1000; i++) {
String test = dcContext.getBlobdir() + "/" + filename + (i == 0 ? "" : i < 100 ? "-" + i : "-" + (new Date().getTime() + i)) + ext;
if (!new File(test).exists()) {
outPath = test;
break;
}
}
if(outPath==null) {
// should not happen
outPath = dcContext.getBlobdir() + "/" + Math.random();
}
return outPath;
}
public static String getBlobdirFile(DcContext dcContext, String path) {
String filename = path.substring(path.lastIndexOf('/')+1); // is the whole path if '/' is not found (lastIndexOf() returns -1 then)
String ext = "";
int point = filename.indexOf('.');
if(point!=-1) {
ext = filename.substring(point);
filename = filename.substring(0, point);
}
return getBlobdirFile(dcContext, filename, ext);
}
public static boolean isWebrtcConfigOk(DcContext dcContext) {
String instance = dcContext.getConfig(DcHelper.CONFIG_WEBRTC_INSTANCE);
return (instance != null && !instance.isEmpty());
}
@NonNull
public static ThreadRecord getThreadRecord(Context context, DcLot summary, DcChat chat) { // adapted from ThreadDatabase.getCurrent()
int chatId = chat.getId();
String body = summary.getText1();
if (!body.isEmpty()) {
body += ": ";
}
body += summary.getText2();
Recipient recipient = new Recipient(context, chat);
long date = summary.getTimestamp();
int unreadCount = getContext(context).getFreshMsgCount(chatId);
return new ThreadRecord(body, recipient, date,
unreadCount, chatId,
chat.getVisibility(), chat.isProtected(), chat.isSendingLocations(), chat.isMuted(), summary);
}
public static boolean isNetworkConnected(Context context) {
try {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()) {
return true;
}
} catch (Exception e) {
}
return false;
}
/**
* Gets a string you can show to the user with basic information about connectivity.
* @param context
@@ -39,7 +39,7 @@ public class ForegroundDetector implements Application.ActivityLifecycleCallback
if (refs == 0) {
Log.i("DeltaChat", "++++++++++++++++++ first ForegroundDetector.onActivityStarted() ++++++++++++++++++");
application.dcContext.maybeStartIo();
if (application.dcContext.isNetworkConnected()) {
if (DcHelper.isNetworkConnected(application)) {
new Thread(() -> {
Log.i("DeltaChat", "calling maybeNetwork()");
application.dcContext.maybeNetwork();
@@ -69,7 +69,7 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientM
this.recipient = null;
}
else {
this.recipient = DcHelper.getContext(getContext()).getRecipient(contact);
this.recipient = new Recipient(getContext(), contact);
this.recipient.addListener(this);
if (this.recipient.getName() != null) {
name = this.recipient.getName();
@@ -34,7 +34,7 @@ public class VideoSlide extends Slide {
private static Attachment constructVideoAttachment(Context context, Uri uri, long dataSize)
{
Uri thumbnailUri = Uri.fromFile(new File(DcHelper.getContext(context).getBlobdirFile("temp-preview.jpg")));
Uri thumbnailUri = Uri.fromFile(new File(DcHelper.getBlobdirFile(DcHelper.getContext(context), "temp-preview.jpg")));
MediaUtil.ThumbnailSize retWh = new MediaUtil.ThumbnailSize(0, 0);
MediaUtil.createVideoThumbnailIfNeeded(context, uri, thumbnailUri, retWh);
return constructAttachmentFromUri(context, uri, MediaUtil.VIDEO_UNSPECIFIED, dataSize, retWh.width, retWh.height, thumbnailUri, null, false);
@@ -391,7 +391,7 @@ public class NotificationCenter {
}
// set avatar
Recipient recipient = new Recipient(context, dcChat, null);
Recipient recipient = new Recipient(context, dcChat);
if (privacy.isDisplayContact()) {
try {
Drawable drawable;
@@ -217,7 +217,7 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
private void updateWebrtcSummary() {
Preference webrtcInstance = this.findPreference("pref_webrtc_instance");
if (webrtcInstance != null) {
webrtcInstance.setSummary(dcContext.isWebrtcConfigOk()?
webrtcInstance.setSummary(DcHelper.isWebrtcConfigOk(dcContext)?
dcContext.getConfig(DcHelper.CONFIG_WEBRTC_INSTANCE) : getString(R.string.none));
}
}
@@ -316,7 +316,7 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
if (i==0) {
new AlertDialog.Builder(getActivity())
.setTitle(R.string.pref_managekeys_export_secret_keys)
.setMessage(getActivity().getString(R.string.pref_managekeys_export_explain, dcContext.getImexDir().getAbsolutePath()))
.setMessage(getActivity().getString(R.string.pref_managekeys_export_explain, DcHelper.getImexDir().getAbsolutePath()))
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, (dialogInterface2, i2) -> startImex(DcContext.DC_IMEX_EXPORT_SELF_KEYS))
.show();
@@ -324,7 +324,7 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
else {
new AlertDialog.Builder(getActivity())
.setTitle(R.string.pref_managekeys_import_secret_keys)
.setMessage(getActivity().getString(R.string.pref_managekeys_import_explain, dcContext.getImexDir().getAbsolutePath()))
.setMessage(getActivity().getString(R.string.pref_managekeys_import_explain, DcHelper.getImexDir().getAbsolutePath()))
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, (dialogInterface2, i2) -> startImex(DcContext.DC_IMEX_IMPORT_SELF_KEYS))
.show();
@@ -9,6 +9,7 @@ import androidx.preference.Preference;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.Prefs;
@@ -65,7 +66,7 @@ public class AppearancePreferenceFragment extends ListSummaryPreferenceFragment
// (for pending activities, the locale is updated by calling DynamicLanguage.onResume)
Context applicationContext = this.getActivity().getApplicationContext();
DynamicLanguage.setContextLocale(applicationContext, DynamicLanguage.getSelectedLocale(applicationContext));
dcContext.setStockTranslations();
DcHelper.setStockTranslations(applicationContext);
}
public static CharSequence getSummary(Context context) {
@@ -119,7 +119,7 @@ public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceF
});
progressDialog.show();
imexDir = dcContext.getImexDir().getAbsolutePath();
imexDir = DcHelper.getImexDir().getAbsolutePath();
dcContext.stopIo();
dcContext.captureNextError();
dcContext.imex(progressWhat, imexDir);
@@ -122,7 +122,7 @@ public class QrShowFragment extends Fragment implements DcEventCenter.DcEventDel
private void setHintText() {
if (!dcContext.isNetworkConnected()) {
if (!DcHelper.isNetworkConnected(getContext())) {
hintBelowQr.setText(errorHint);
} else {
hintBelowQr.setText(hint);
@@ -132,7 +132,7 @@ public class QrShowFragment extends Fragment implements DcEventCenter.DcEventDel
@Override
public void onResume() {
super.onResume();
if (!dcContext.isNetworkConnected()) {
if (!DcHelper.isNetworkConnected(getContext())) {
Toast.makeText(getActivity(), R.string.qrshow_join_contact_no_connection_toast, Toast.LENGTH_LONG).show();
}
}
@@ -70,11 +70,7 @@ public class Recipient {
public static @NonNull Recipient fromChat(@NonNull Context context, int dcMsgId) {
ApplicationDcContext dcContext = DcHelper.getContext(context);
return fromChat(dcContext, dcMsgId);
}
public static @NonNull Recipient fromChat (@NonNull ApplicationDcContext dcContext, int dcMsgId) {
return dcContext.getRecipient(dcContext.getChat(dcContext.getMsg(dcMsgId).getChatId()));
return new Recipient(context, dcContext.getChat(dcContext.getMsg(dcMsgId).getChatId()));
}
@SuppressWarnings("ConstantConditions")
@@ -82,20 +78,28 @@ public class Recipient {
if (address == null) throw new AssertionError(address);
ApplicationDcContext dcContext = DcHelper.getContext(context);
if(address.isDcContact()) {
return dcContext.getRecipient(dcContext.getContact(address.getDcContactId()));
return new Recipient(context, dcContext.getContact(address.getDcContactId()));
} else if (address.isDcChat()) {
return dcContext.getRecipient(dcContext.getChat(address.getDcChatId()));
return new Recipient(context, dcContext.getChat(address.getDcChatId()));
}
else if(address.isEmail()) {
int contactId = dcContext.lookupContactIdByAddr(address.toEmailString());
if(contactId!=0) {
return dcContext.getRecipient(dcContext.getContact(contactId));
return new Recipient(context, dcContext.getContact(contactId));
}
}
return dcContext.getRecipient(dcContext.getContact(0));
return new Recipient(context, dcContext.getContact(0));
}
public Recipient(@NonNull Context context, @Nullable DcChat dcChat, @Nullable DcContact dcContact) {
public Recipient(@NonNull Context context, @NonNull DcChat dcChat) {
this(context, dcChat, null);
}
public Recipient(@NonNull Context context, @NonNull DcContact dcContact) {
this(context, null, dcContact);
}
private Recipient(@NonNull Context context, @Nullable DcChat dcChat, @Nullable DcContact dcContact) {
this.dcChat = dcChat;
this.dcContact = dcContact;
this.contactUri = null;
@@ -167,7 +171,7 @@ public class Recipient {
ApplicationDcContext dcContext = DcHelper.getContext(context);
int[] contactIds = dcContext.getChatContacts(dcChat.getId());
for (int contactId : contactIds) {
participants.add(dcContext.getRecipient(ApplicationDcContext.RECIPIENT_TYPE_CONTACT, contactId));
participants.add(new Recipient(context, dcContext.getContact(contactId)));
}
}
return participants;
@@ -201,7 +201,7 @@ class SearchListAdapter extends RecyclerView.Adapter<SearchListAdapter.Search
@Nullable String query)
{
ApplicationDcContext dcContext = DcHelper.getContext(context);
ThreadRecord threadRecord = dcContext.getThreadRecord(chatlistItem.summary, dcContext.getChat(chatlistItem.chatId));
ThreadRecord threadRecord = DcHelper.getThreadRecord(context, chatlistItem.summary, dcContext.getChat(chatlistItem.chatId));
root.bind(threadRecord, chatlistItem.msgId, chatlistItem.summary, glideRequests, locale, Collections.emptySet(), false, query);
root.setOnClickListener(view -> eventListener.onConversationClicked(chatlistItem));
}
@@ -59,7 +59,7 @@ public class DirectShareService extends ChooserTargetService {
Bundle bundle = new Bundle();
bundle.putInt(ShareActivity.EXTRA_CHAT_ID, chat.getId());
bundle.setClassLoader(getClassLoader());
Recipient recipient = DcHelper.getContext(this).getRecipient(chat);
Recipient recipient = new Recipient(this, chat);
Bitmap avatar;
try {
avatar = GlideApp.with(this)
@@ -122,7 +122,7 @@ public class SendRelayedMessageUtil {
ext = filename.substring(i);
filename = filename.substring(0, i);
}
String path = dcContext.getBlobdirFile(filename, ext);
String path = DcHelper.getBlobdirFile(dcContext, filename, ext);
// copy content to this file
if (path != null) {
@@ -856,7 +856,7 @@ public class VideoRecoder {
}
// recode
String tempPath = DcHelper.getContext(context).getBlobdirFile(inPath);
String tempPath = DcHelper.getBlobdirFile(DcHelper.getContext(context), inPath);
VideoRecoder videoRecoder = new VideoRecoder();
if (!videoRecoder.convertVideo(vei, tempPath)) {
logNtoast(context, String.format("recoding for %s failed: cannot convert to temporary file %s", inPath, tempPath));