Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Call popup width issue on orientation change #13723

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,12 @@ class ConversationFragment :
super.onConfigurationChanged(newConfig)
ToolbarDependentMarginListener(binding.toolbar)
inlineQueryController.onOrientationChange(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)

// Recreate start call dialog on orientation change
val recipient: Recipient = viewModel.recipientSnapshot ?: return
CommunicationActions.startVoiceCall(this@ConversationFragment, recipient) {
YouAreAlreadyInACallSnackbar.show(requireView())
}
}

override fun onDestroyView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.ResultReceiver;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.TaskStackBuilder;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
Expand Down Expand Up @@ -62,6 +68,7 @@
public class CommunicationActions {

private static final String TAG = Log.tag(CommunicationActions.class);
private static AlertDialog alertDialog = null;

/**
* Start a voice call. Assumes that permission request results will be routed to a handler on the Fragment.
Expand Down Expand Up @@ -98,12 +105,19 @@ protected void onReceiveResult(int resultCode, Bundle resultData) {
onUserAlreadyInAnotherCall.onUserAlreadyInAnotherCall();
}
} else {
new MaterialAlertDialogBuilder(callContext.getContext())
if (alertDialog != null) {
alertDialog.dismiss();
alertDialog = null;
}

alertDialog = new MaterialAlertDialogBuilder(callContext.getContext())
.setMessage(R.string.CommunicationActions_start_voice_call)
.setPositiveButton(R.string.CommunicationActions_call, (d, w) -> startCallInternal(callContext, recipient, false, false))
.setNegativeButton(R.string.CommunicationActions_cancel, (d, w) -> d.dismiss())
.setCancelable(true)
.show();
.setCancelable(true).create();
adjustDialogSize(callContext, alertDialog);
alertDialog.show();

}
}
});
Expand Down Expand Up @@ -485,6 +499,41 @@ private static void handleUsernameLink(Activity activity, String link) {
});
}



/**
* Adjusts the size of the dialog window based on the device orientation.
*/
public static void adjustDialogSize(@NonNull CallContext callContext, DialogInterface dialog) {
Window window = ((AlertDialog) dialog).getWindow();

if (window != null) {
DisplayMetrics displayMetrics = new DisplayMetrics();
window.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

// Get current orientation
int orientation = callContext.getContext().getResources().getConfiguration().orientation;

// Set width and height based on orientation
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
// Case when both dialog and it's page opened in Portrait orientation
if (displayMetrics.heightPixels > displayMetrics.widthPixels) {
window.setLayout((int) (displayMetrics.widthPixels * 0.8), WindowManager.LayoutParams.WRAP_CONTENT);
} else { // When page opened in Portrait orientation and dialog showing in Landscape orientation
window.setLayout((int) (displayMetrics.heightPixels * 0.8), WindowManager.LayoutParams.WRAP_CONTENT);
}
} else {
// Case when both dialog and it's page opened in Landscape orientation
if (displayMetrics.widthPixels > displayMetrics.heightPixels) {
window.setLayout((int) (displayMetrics.widthPixels * 0.6), WindowManager.LayoutParams.WRAP_CONTENT);
} else {// When page opened in Landscape orientation and dialog showing in Portrait orientation
window.setLayout((int) (displayMetrics.heightPixels * 0.6), WindowManager.LayoutParams.WRAP_CONTENT);
}
}
}
}


private interface CallContext {
@NonNull Permissions.PermissionsBuilder getPermissionsBuilder();
void startActivity(@NonNull Intent intent);
Expand Down