Skip to content

Commit

Permalink
calls: implement a "Ask to Call" dialog when dialing a user
Browse files Browse the repository at this point in the history
  • Loading branch information
iTaysonLab committed Jan 30, 2021
1 parent dced108 commit d783ea6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
Expand Up @@ -219,7 +219,7 @@ public void setChecked(boolean checked, boolean animated) {
public void onClick(View v) {
CallLogRow row = (CallLogRow) v.getTag();
TLRPC.UserFull userFull = getMessagesController().getUserFull(row.user.id);
VoIPHelper.startCall(lastCallUser = row.user, row.video, row.video || userFull != null && userFull.video_calls_available, getParentActivity(), null);
VoIPHelper.startCall(lastCallUser = row.user, row.video, row.video || userFull != null && userFull.video_calls_available, getParentActivity(), null, CallLogActivity.this);
}
};

Expand Down Expand Up @@ -405,7 +405,7 @@ public void getOutline(View view, Outline outline) {
ContactsActivity contactsFragment = new ContactsActivity(args);
contactsFragment.setDelegate((user, param, activity) -> {
TLRPC.UserFull userFull = getMessagesController().getUserFull(user.id);
VoIPHelper.startCall(lastCallUser = user, false, userFull != null && userFull.video_calls_available, getParentActivity(), null);
VoIPHelper.startCall(lastCallUser = user, false, userFull != null && userFull.video_calls_available, getParentActivity(), null, CallLogActivity.this);
});
presentFragment(contactsFragment);
});
Expand Down Expand Up @@ -670,7 +670,7 @@ public void onRequestPermissionsResultFragment(int requestCode, String[] permiss
}
if (grantResults.length > 0 && allGranted) {
TLRPC.UserFull userFull = lastCallUser != null ? getMessagesController().getUserFull(lastCallUser.id) : null;
VoIPHelper.startCall(lastCallUser, requestCode == 102, requestCode == 102 || userFull != null && userFull.video_calls_available, getParentActivity(), null);
VoIPHelper.startCall(lastCallUser, requestCode == 102, requestCode == 102 || userFull != null && userFull.video_calls_available, getParentActivity(), null, CallLogActivity.this);
} else {
VoIPHelper.permissionDenied(getParentActivity(), null, requestCode);
}
Expand Down
8 changes: 4 additions & 4 deletions TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
Expand Up @@ -1870,7 +1870,7 @@ public void onItemClick(final int id) {
openSearchWithText(null);
} else if (id == call || id == video_call) {
if (currentUser != null && getParentActivity() != null) {
VoIPHelper.startCall(currentUser, id == video_call, userInfo != null && userInfo.video_calls_available, getParentActivity(), getMessagesController().getUserFull(currentUser.id));
VoIPHelper.startCall(currentUser, id == video_call, userInfo != null && userInfo.video_calls_available, getParentActivity(), getMessagesController().getUserFull(currentUser.id), ChatActivity.this);
}
} else if (id == text_bold) {
if (chatActivityEnterView != null) {
Expand Down Expand Up @@ -10808,7 +10808,7 @@ public void onRequestPermissionsResultFragment(int requestCode, String[] permiss
if (requestCode == 103) {
VoIPHelper.startCall(currentChat, createGroupCall, getParentActivity());
} else {
VoIPHelper.startCall(currentUser, requestCode == 102, userInfo != null && userInfo.video_calls_available, getParentActivity(), getMessagesController().getUserFull(currentUser.id));
VoIPHelper.startCall(currentUser, requestCode == 102, userInfo != null && userInfo.video_calls_available, getParentActivity(), getMessagesController().getUserFull(currentUser.id), ChatActivity.this);
}
} else {
VoIPHelper.permissionDenied(getParentActivity(), null, requestCode);
Expand Down Expand Up @@ -19122,7 +19122,7 @@ private void processSelectedOption(int option) {
}
case 18: {
if (currentUser != null) {
VoIPHelper.startCall(currentUser, selectedObject.isVideoCall(), userInfo != null && userInfo.video_calls_available, getParentActivity(), getMessagesController().getUserFull(currentUser.id));
VoIPHelper.startCall(currentUser, selectedObject.isVideoCall(), userInfo != null && userInfo.video_calls_available, getParentActivity(), getMessagesController().getUserFull(currentUser.id), ChatActivity.this);
}
break;
}
Expand Down Expand Up @@ -20709,7 +20709,7 @@ public void didPressOther(ChatMessageCell cell, float otherX, float otherY) {
MessageObject messageObject = cell.getMessageObject();
if (messageObject.type == 16) {
if (currentUser != null) {
VoIPHelper.startCall(currentUser, messageObject.isVideoCall(), userInfo != null && userInfo.video_calls_available, getParentActivity(), getMessagesController().getUserFull(currentUser.id));
VoIPHelper.startCall(currentUser, messageObject.isVideoCall(), userInfo != null && userInfo.video_calls_available, getParentActivity(), getMessagesController().getUserFull(currentUser.id), ChatActivity.this);
}
} else {
createMenu(cell, true, false, otherX, otherY, messageObject.isMusic());
Expand Down
Expand Up @@ -43,6 +43,7 @@
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Cells.CheckBoxCell;
import org.telegram.ui.Cells.TextCheckCell;
import org.telegram.ui.Components.AlertsCreator;
import org.telegram.ui.Components.BetterRatingView;
import org.telegram.ui.Components.EditTextBoldCursor;
import org.telegram.ui.Components.LayoutHelper;
Expand All @@ -63,6 +64,11 @@ public class VoIPHelper {

private static final int VOIP_SUPPORT_ID = 4244000;

// Stubs
public static void startCall(TLRPC.User user, boolean videoCall, boolean canVideoCall, final Activity activity, TLRPC.UserFull userFull, BaseFragment frag) {
AlertsCreator.createCallDialogAlert(frag, user, videoCall);
}

public static void startCall(TLRPC.User user, boolean videoCall, boolean canVideoCall, final Activity activity, TLRPC.UserFull userFull) {
if (userFull != null && userFull.phone_calls_private) {
new AlertDialog.Builder(activity)
Expand Down
Expand Up @@ -2184,7 +2184,7 @@ private boolean handleIntent(Intent intent, boolean isNew, boolean restore, bool
final boolean videoCall = videoCallUser;
contactsFragment.setDelegate((user, param, activity) -> {
final TLRPC.UserFull userFull = MessagesController.getInstance(currentAccount).getUserFull(user.id);
VoIPHelper.startCall(user, videoCall, userFull != null && userFull.video_calls_available, LaunchActivity.this, userFull);
VoIPHelper.startCall(user, videoCall, userFull != null && userFull.video_calls_available, LaunchActivity.this, userFull, contactsFragment);
});
actionBarLayout.presentFragment(contactsFragment, actionBarLayout.getLastFragment() instanceof ContactsActivity, true, true, false);
if (AndroidUtilities.isTablet()) {
Expand Down
Expand Up @@ -1638,7 +1638,7 @@ public void onItemClick(final int id) {
if (user_id != 0) {
TLRPC.User user = getMessagesController().getUser(user_id);
if (user != null) {
VoIPHelper.startCall(user, id == video_call_item, userInfo != null && userInfo.video_calls_available, getParentActivity(), userInfo);
VoIPHelper.startCall(user, id == video_call_item, userInfo != null && userInfo.video_calls_available, getParentActivity(), userInfo, ProfileActivity.this);
}
} else if (chat_id != 0) {
ChatObject.Call call = getMessagesController().getGroupCall(chat_id, false);
Expand Down Expand Up @@ -3561,7 +3561,7 @@ private boolean processOnClickOrPress(final int position) {
FileLog.e(e);
}
} else if (i == 2 || i == 3) {
VoIPHelper.startCall(user, i == 3, userInfo != null && userInfo.video_calls_available, getParentActivity(), userInfo);
VoIPHelper.startCall(user, i == 3, userInfo != null && userInfo.video_calls_available, getParentActivity(), userInfo, ProfileActivity.this);
}
});
showDialog(builder.create());
Expand Down Expand Up @@ -5831,7 +5831,7 @@ public void onRequestPermissionsResultFragment(int requestCode, String[] permiss
}
}
if (grantResults.length > 0 && allGranted) {
VoIPHelper.startCall(user, requestCode == 102, userInfo != null && userInfo.video_calls_available, getParentActivity(), userInfo);
VoIPHelper.startCall(user, requestCode == 102, userInfo != null && userInfo.video_calls_available, getParentActivity(), userInfo, ProfileActivity.this);
} else {
VoIPHelper.permissionDenied(getParentActivity(), null, requestCode);
}
Expand Down

0 comments on commit d783ea6

Please sign in to comment.