Merge branch 'main' into adb/issue-4104

This commit is contained in:
adb
2025-12-10 12:18:39 +01:00
committed by GitHub
7 changed files with 47 additions and 8 deletions
@@ -37,8 +37,8 @@ public abstract class BaseActionBarActivity extends AppCompatActivity {
onPreCreate();
super.onCreate(savedInstanceState);
// Only enable Edge-to-Edge on API 30+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// Only enable Edge-to-Edge if it is well supported
if (ViewUtil.isEdgeToEdgeSupported()) {
// docs says to use: WindowCompat.enableEdgeToEdge(getWindow());
// but it actually makes things worse, the next takes care of setting the 3-buttons navigation bar background
EdgeToEdge.enable(this);
@@ -873,6 +873,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
ImageButton quickCameraToggle = ViewUtil.findById(this, R.id.quick_camera_toggle);
if (!ViewUtil.isEdgeToEdgeSupported()) {
// since insets will not be applied, we need to set top padding to avoid drawing behind toolbar
try (TypedArray typedArray = obtainStyledAttributes(new int[]{android.R.attr.actionBarSize})) {
int paddingTop = typedArray.getDimensionPixelSize(0, 0);
container.setPadding(container.getPaddingLeft(), paddingTop, container.getPaddingRight() , container.getPaddingBottom());
}
}
// apply padding top to avoid drawing behind top bar
ViewUtil.applyWindowInsets(findViewById(R.id.fragment_content), false, true, false, false);
// apply padding to root to avoid collision with system bars
@@ -50,6 +50,7 @@ import org.thoughtcrime.securesms.profiles.AvatarHelper;
import org.thoughtcrime.securesms.proxy.ProxySettingsActivity;
import org.thoughtcrime.securesms.qr.RegistrationQrActivity;
import org.thoughtcrime.securesms.relay.EditRelayActivity;
import org.thoughtcrime.securesms.relay.RelayListActivity;
import org.thoughtcrime.securesms.scribbles.ScribbleActivity;
import org.thoughtcrime.securesms.util.IntentUtils;
import org.thoughtcrime.securesms.util.Prefs;
@@ -106,11 +107,18 @@ public class InstantOnboardingActivity extends BaseActionBarActivity implements
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
boolean fromWelcome = getIntent().getBooleanExtra(FROM_WELCOME, false);
if (DcHelper.getContext(this).isConfigured() == 1) {
// if account is configured it means we didn't come from Welcome screen nor from QR scanner,
// instead, user clicked a dcaccount:// URI directly, so we need to switch to a new account:
AccountManager.getInstance().beginAccountCreation(this);
// instead, user clicked a dcaccount:// URI directly, so we need to just offer to add a new relay
Intent intent = new Intent(this, RelayListActivity.class);
String qrData = getIntent().getData().toString();
intent.putExtra(RelayListActivity.EXTRA_QR_DATA, qrData);
startActivity(intent);
finish();
return;
}
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(!fromWelcome) {
@Override
public void handleOnBackPressed() {
@@ -102,6 +102,8 @@ public class WebViewActivity extends PassphraseRequiredActionBarActivity
case "mailto":
case "openpgp4fpr":
case "geo":
case "dcaccount":
case "dclogin":
return openOnlineUrl(url);
}
}
@@ -17,6 +17,7 @@ import org.thoughtcrime.securesms.ConversationActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.connect.AccountManager;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.relay.RelayListActivity;
import org.thoughtcrime.securesms.util.IntentUtils;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.views.ProgressDialog;
@@ -282,7 +283,16 @@ public class QrCodeHandler {
Util.runOnMain(() -> {
if (!progressDialog.isShowing()) return; // canceled dialog, nothing to do
if (finalError != null) {
Toast.makeText(activity, finalError, Toast.LENGTH_LONG).show();
new AlertDialog.Builder(activity)
.setTitle(R.string.error)
.setMessage(finalError)
.setPositiveButton(R.string.ok, null)
.show();
} else {
showDoneToast(activity);
if (!(activity instanceof RelayListActivity)) {
activity.startActivity(new Intent(activity, RelayListActivity.class));
}
}
try {
progressDialog.dismiss();
@@ -37,6 +37,7 @@ public class RelayListActivity extends BaseActionBarActivity
implements RelayListAdapter.OnRelayClickListener, DcEventCenter.DcEventDelegate {
private static final String TAG = RelayListActivity.class.getSimpleName();
public static final String EXTRA_QR_DATA = "qr_data";
private RelayListAdapter adapter;
private Rpc rpc;
@@ -83,6 +84,12 @@ public class RelayListActivity extends BaseActionBarActivity
DcEventCenter eventCenter = DcHelper.getEventCenter(this);
eventCenter.addObserver(DcContext.DC_EVENT_CONFIGURE_PROGRESS, this);
String qrdata = getIntent().getStringExtra(EXTRA_QR_DATA);
if (qrdata != null) {
QrCodeHandler qrCodeHandler = new QrCodeHandler(this);
qrCodeHandler.handleQrData(qrdata);
}
}
@Override
@@ -299,6 +299,11 @@ public class ViewUtil {
return selection;
}
/** Return true if the system supports edge-to-edge properly */
public static boolean isEdgeToEdgeSupported() {
return Build.VERSION.SDK_INT >= VERSION_CODES.R;
}
/**
* Get combined insets from status bar, navigation bar and display cutout areas.
*
@@ -335,7 +340,7 @@ public class ViewUtil {
*/
public static void applyWindowInsetsAsMargin(@NonNull View view, boolean left, boolean top, boolean right, boolean bottom) {
// Only enable on API 30+ where WindowInsets APIs work correctly
if (Build.VERSION.SDK_INT < VERSION_CODES.R) return;
if (!isEdgeToEdgeSupported()) return;
// Store the original margin as a tag only if not already stored
// This prevents losing the true original margin on subsequent calls
@@ -406,7 +411,7 @@ public class ViewUtil {
*/
public static void applyWindowInsets(@NonNull View view, boolean left, boolean top, boolean right, boolean bottom) {
// Only enable on API 30+ where WindowInsets APIs work correctly
if (Build.VERSION.SDK_INT < VERSION_CODES.R) return;
if (!isEdgeToEdgeSupported()) return;
// Store the original padding as a tag only if not already stored
// This prevents losing the true original padding on subsequent calls
@@ -475,7 +480,7 @@ public class ViewUtil {
*/
public static void adjustToolbarForE2E(@NonNull AppCompatActivity activity) {
// Only enable on API 30+ where WindowInsets APIs work correctly
if (Build.VERSION.SDK_INT < VERSION_CODES.R) return;
if (!isEdgeToEdgeSupported()) return;
// The toolbar/app bar should extend behind the status bar with padding applied
View toolbar = activity.findViewById(R.id.toolbar);