mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-03 01:39:18 +02:00
Compare commits
4 commits
320c120a61
...
7a11234431
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7a11234431 | ||
![]() |
0e91537a4d | ||
![]() |
b074bf1819 | ||
![]() |
b8d2552aa8 |
9 changed files with 124 additions and 34 deletions
|
@ -447,6 +447,14 @@
|
|||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".notifications.DeclineCallReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="org.thoughtcrime.securesms.notifications.DECLINE_CALL_NOTICED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".notifications.RemoteReplyReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="false">
|
||||
|
|
|
@ -51,7 +51,6 @@ import org.thoughtcrime.securesms.util.Prefs;
|
|||
import org.thoughtcrime.securesms.util.RelayUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import org.thoughtcrime.securesms.videochat.VideochatUtil;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
@ -82,7 +81,6 @@ public class ConversationListFragment extends BaseConversationListFragment
|
|||
eventCenter.addMultiAccountObserver(DcContext.DC_EVENT_INCOMING_MSG, this);
|
||||
eventCenter.addMultiAccountObserver(DcContext.DC_EVENT_MSGS_NOTICED, this);
|
||||
eventCenter.addMultiAccountObserver(DcContext.DC_EVENT_CHAT_DELETED, this);
|
||||
eventCenter.addMultiAccountObserver(DcContext.DC_EVENT_INCOMING_CALL, this);
|
||||
eventCenter.addObserver(DcContext.DC_EVENT_CHAT_MODIFIED, this);
|
||||
eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this);
|
||||
eventCenter.addObserver(DcContext.DC_EVENT_MSGS_CHANGED, this);
|
||||
|
@ -345,8 +343,6 @@ public class ConversationListFragment extends BaseConversationListFragment
|
|||
((ConversationListActivity) activity).refreshAvatar();
|
||||
}
|
||||
|
||||
} else if (event.getId() == DcContext.DC_EVENT_INCOMING_CALL) {
|
||||
VideochatUtil.joinCall(getActivity(), event.getData1Int(), event.getData2Str());
|
||||
} else {
|
||||
loadChatlistAsync();
|
||||
}
|
||||
|
|
|
@ -183,6 +183,14 @@ public class DcEventCenter {
|
|||
DcHelper.getNotificationCenter(context).notifyWebxdc(accountId, event.getData1Int(), event.getData2Int(), event.getData2Str());
|
||||
break;
|
||||
|
||||
case DcContext.DC_EVENT_INCOMING_CALL:
|
||||
DcHelper.getNotificationCenter(context).notifyCall(accountId, event.getData1Int(), event.getData2Str());
|
||||
break;
|
||||
|
||||
case DcContext.DC_EVENT_CALL_ENDED:
|
||||
DcHelper.getNotificationCenter(context).removeCallNotification(accountId, event.getData1Int());
|
||||
break;
|
||||
|
||||
case DcContext.DC_EVENT_MSGS_NOTICED:
|
||||
DcHelper.getNotificationCenter(context).removeNotifications(accountId, event.getData1Int());
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
// called when the user click the "clear" or "mark read" button in the system notification
|
||||
|
||||
package org.thoughtcrime.securesms.notifications;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.b44t.messenger.DcContext;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
public class DeclineCallReceiver extends BroadcastReceiver {
|
||||
public static final String DECLINE_ACTION = "org.thoughtcrime.securesms.notifications.DECLINE_CALL";
|
||||
public static final String ACCOUNT_ID_EXTRA = "account_id";
|
||||
public static final String CALL_ID_EXTRA = "call_id";
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, Intent intent) {
|
||||
if (!DECLINE_ACTION.equals(intent.getAction())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int accountId = intent.getIntExtra(ACCOUNT_ID_EXTRA, 0);
|
||||
final int callId = intent.getIntExtra(CALL_ID_EXTRA, 0);
|
||||
if (accountId == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Util.runOnAnyBackgroundThread(() -> {
|
||||
DcHelper.getNotificationCenter(context).removeCallNotification(accountId, callId);
|
||||
DcContext dcContext = DcHelper.getAccounts(context).getAccount(accountId);
|
||||
dcContext.endCall(callId);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -48,6 +48,7 @@ import org.thoughtcrime.securesms.util.JsonUtils;
|
|||
import org.thoughtcrime.securesms.util.Pair;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.videochat.VideochatActivity;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
|
@ -159,6 +160,34 @@ public class NotificationCenter {
|
|||
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | IntentUtils.FLAG_MUTABLE());
|
||||
}
|
||||
|
||||
private PendingIntent getAnswerIntent(ChatData chatData, int callId, String payload) {
|
||||
final Intent chatIntent = new Intent(context, ConversationActivity.class)
|
||||
.putExtra(ConversationActivity.ACCOUNT_ID_EXTRA, chatData.accountId)
|
||||
.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatData.chatId)
|
||||
.setAction(Intent.ACTION_VIEW);
|
||||
|
||||
String hash = "#offer=" + payload;
|
||||
Intent intent = new Intent(context, VideochatActivity.class);
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.putExtra(VideochatActivity.EXTRA_ACCOUNT_ID, chatData.accountId);
|
||||
intent.putExtra(VideochatActivity.EXTRA_CHAT_ID, chatData.chatId);
|
||||
intent.putExtra(VideochatActivity.EXTRA_CALL_ID, callId);
|
||||
intent.putExtra(VideochatActivity.EXTRA_HASH, hash);
|
||||
intent.setPackage(context.getPackageName());
|
||||
return TaskStackBuilder.create(context)
|
||||
.addNextIntentWithParentStack(chatIntent)
|
||||
.addNextIntent(intent)
|
||||
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT | IntentUtils.FLAG_MUTABLE());
|
||||
}
|
||||
|
||||
private PendingIntent getDeclineCallIntent(ChatData chatData, int callId) {
|
||||
Intent intent = new Intent(DeclineCallReceiver.DECLINE_ACTION);
|
||||
intent.setClass(context, DeclineCallReceiver.class);
|
||||
intent.putExtra(DeclineCallReceiver.ACCOUNT_ID_EXTRA, chatData.accountId);
|
||||
intent.putExtra(DeclineCallReceiver.CALL_ID_EXTRA, callId);
|
||||
intent.setPackage(context.getPackageName());
|
||||
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | IntentUtils.FLAG_MUTABLE());
|
||||
}
|
||||
|
||||
// Groups and Notification channel groups
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
@ -383,14 +412,18 @@ public class NotificationCenter {
|
|||
// add notifications & co.
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
public void addCallNotification(int accId, int chatId, int callId) {
|
||||
public void notifyCall(int accId, int callId, String payload) {
|
||||
Util.runOnAnyBackgroundThread(() -> {
|
||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||
DcContext dcContext = context.dcAccounts.getAccount(accId);
|
||||
int chatId = dcContext.getMsg(callId).getChatId();
|
||||
DcChat dcChat = dcContext.getChat(chatId);
|
||||
String name = dcChat.getName();
|
||||
ChatData chatData = new ChatData(accId, chatId);
|
||||
String notificationChannel = getCallNotificationChannel(notificationManager, chatData, name);
|
||||
|
||||
PendingIntent declineCallIntent = getDeclineCallIntent(chatData, callId);
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, notificationChannel)
|
||||
.setSmallIcon(R.drawable.icon_notification)
|
||||
.setColor(context.getResources().getColor(R.color.delta_primary))
|
||||
|
@ -401,9 +434,19 @@ public class NotificationCenter {
|
|||
.setTicker(name)
|
||||
.setContentTitle(name)
|
||||
.setContentText("Incoming Call")
|
||||
;
|
||||
// .setDeleteIntenta(getMarkAsReadIntent(chatData, msgId, false))
|
||||
// .setContentIntent(getOpenChatIntent(chatData));
|
||||
.setDeleteIntent(declineCallIntent);
|
||||
|
||||
builder.addAction(
|
||||
new NotificationCompat.Action.Builder(
|
||||
R.drawable.baseline_call_end_24,
|
||||
context.getString(R.string.end_call),
|
||||
declineCallIntent).build());
|
||||
|
||||
builder.addAction(
|
||||
new NotificationCompat.Action.Builder(
|
||||
R.drawable.baseline_call_24,
|
||||
context.getString(R.string.answer_call),
|
||||
getAnswerIntent(chatData, callId, payload)).build());
|
||||
|
||||
Bitmap bitmap = getAvatar(dcChat);
|
||||
if (bitmap != null) {
|
||||
|
@ -415,7 +458,7 @@ public class NotificationCenter {
|
|||
// add notification, we use one notification per chat,
|
||||
// esp. older android are not that great at grouping
|
||||
try {
|
||||
notificationManager.notify(String.valueOf(accId), ID_MSG_OFFSET + chatId, notif);
|
||||
notificationManager.notify("call-" + accId, callId, notif);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "cannot add notification", e);
|
||||
}
|
||||
|
@ -710,6 +753,14 @@ public class NotificationCenter {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void removeCallNotification(int accountId, int callId) {
|
||||
try {
|
||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||
String tag = "call-" + accountId;
|
||||
notificationManager.cancel(tag, callId);
|
||||
} catch (Exception e) { Log.w(TAG, e); }
|
||||
}
|
||||
|
||||
public void removeNotifications(int accountId, int chatId) {
|
||||
boolean removeSummary;
|
||||
synchronized (inboxes) {
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Objects;
|
|||
|
||||
public class VideochatActivity extends WebViewActivity implements DcEventCenter.DcEventDelegate {
|
||||
|
||||
public static final String EXTRA_ACCOUNT_ID = "acc_id";
|
||||
public static final String EXTRA_CHAT_ID = "chat_id";
|
||||
public static final String EXTRA_CALL_ID = "call_id";
|
||||
public static final String EXTRA_HASH = "hash";
|
||||
|
@ -36,13 +37,16 @@ public class VideochatActivity extends WebViewActivity implements DcEventCenter.
|
|||
@Override
|
||||
protected void onCreate(Bundle state, boolean ready) {
|
||||
super.onCreate(state, ready);
|
||||
this.dcContext = DcHelper.getContext(getApplicationContext());
|
||||
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
assert bundle != null;
|
||||
String hash = bundle.getString(EXTRA_HASH, "");
|
||||
chatId = bundle.getInt(EXTRA_CHAT_ID, 0);
|
||||
callId = bundle.getInt(EXTRA_CALL_ID, 0);
|
||||
int accId = bundle.getInt(EXTRA_ACCOUNT_ID, -1);
|
||||
this.dcContext = DcHelper.getAccounts(this).getAccount(accId);
|
||||
|
||||
DcHelper.getNotificationCenter(this).removeCallNotification(accId, callId);
|
||||
|
||||
WebSettings webSettings = webView.getSettings();
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
|
|
|
@ -3,10 +3,6 @@ package org.thoughtcrime.securesms.videochat;
|
|||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.b44t.messenger.DcMsg;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
|
@ -15,34 +11,17 @@ import org.thoughtcrime.securesms.permissions.Permissions;
|
|||
public class VideochatUtil {
|
||||
|
||||
public static void startCall(Activity activity, int chatId) {
|
||||
openCall(activity, chatId, 0, "#call");
|
||||
}
|
||||
|
||||
public static void joinCall(Activity activity, int callId, String payload) {
|
||||
DcContext dcContext = DcHelper.getContext(activity);
|
||||
DcMsg dcMsg = dcContext.getMsg(callId);
|
||||
int accId = dcContext.getAccountId();
|
||||
int chatId = dcMsg.getChatId();
|
||||
String hash = "#offer=" + payload;
|
||||
|
||||
//DcHelper.getNotificationCenter(activity).addCallNotification(accId, chatId, callId);
|
||||
openCall(activity, chatId, callId, hash);
|
||||
}
|
||||
|
||||
private static void openCall(Activity activity, int chatId, int callId, String hash) {
|
||||
DcContext dcContext = DcHelper.getContext(activity);
|
||||
int accId = dcContext.getAccountId();
|
||||
|
||||
Permissions.with(activity)
|
||||
.request(Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO)
|
||||
.ifNecessary()
|
||||
.withPermanentDenialDialog(activity.getString(R.string.perm_explain_access_to_camera_denied))
|
||||
.onAllGranted(() -> {
|
||||
int accId = DcHelper.getContext(activity).getAccountId();
|
||||
Intent intent = new Intent(activity, VideochatActivity.class);
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.putExtra(VideochatActivity.EXTRA_ACCOUNT_ID, accId);
|
||||
intent.putExtra(VideochatActivity.EXTRA_CHAT_ID, chatId);
|
||||
intent.putExtra(VideochatActivity.EXTRA_CALL_ID, callId);
|
||||
intent.putExtra(VideochatActivity.EXTRA_HASH, hash);
|
||||
intent.putExtra(VideochatActivity.EXTRA_HASH, "#call");
|
||||
activity.startActivity(intent);
|
||||
})
|
||||
.execute();
|
||||
|
|
5
src/main/res/drawable/baseline_call_end_24.xml
Normal file
5
src/main/res/drawable/baseline_call_end_24.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,9c-1.6,0 -3.15,0.25 -4.6,0.72v3.1c0,0.39 -0.23,0.74 -0.56,0.9 -0.98,0.49 -1.87,1.12 -2.66,1.85 -0.18,0.18 -0.43,0.28 -0.7,0.28 -0.28,0 -0.53,-0.11 -0.71,-0.29L0.29,13.08c-0.18,-0.17 -0.29,-0.42 -0.29,-0.7 0,-0.28 0.11,-0.53 0.29,-0.71C3.34,8.78 7.46,7 12,7s8.66,1.78 11.71,4.67c0.18,0.18 0.29,0.43 0.29,0.71 0,0.28 -0.11,0.53 -0.29,0.71l-2.48,2.48c-0.18,0.18 -0.43,0.29 -0.71,0.29 -0.27,0 -0.52,-0.11 -0.7,-0.28 -0.79,-0.74 -1.69,-1.36 -2.67,-1.85 -0.33,-0.16 -0.56,-0.5 -0.56,-0.9v-3.1C15.15,9.25 13.6,9 12,9z"/>
|
||||
|
||||
</vector>
|
|
@ -370,6 +370,8 @@
|
|||
|
||||
<string name="start_call">Call</string>
|
||||
<string name="video_calls">Video Calls</string>
|
||||
<string name="answer_call">Answer</string>
|
||||
<string name="end_call">Decline</string>
|
||||
|
||||
<!-- deprecated -->
|
||||
<string name="videochat">Video Chat</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue