|
23 | 23 | import android.util.Pair;
|
24 | 24 | import android.view.Gravity;
|
25 | 25 | import android.view.View;
|
| 26 | +import android.view.ViewGroup; |
| 27 | +import android.widget.ArrayAdapter; |
26 | 28 | import android.widget.EditText;
|
27 | 29 | import android.widget.LinearLayout;
|
| 30 | +import android.widget.ListAdapter; |
28 | 31 | import android.widget.TextView;
|
29 | 32 | import android.widget.Toast;
|
30 | 33 | import androidx.annotation.Nullable;
|
|
63 | 66 | import java.net.MalformedURLException;
|
64 | 67 | import java.net.URL;
|
65 | 68 | import java.util.ArrayList;
|
| 69 | +import java.util.HashSet; |
66 | 70 | import java.util.LinkedHashMap;
|
67 | 71 | import java.util.List;
|
68 | 72 | import java.util.Locale;
|
69 | 73 | import java.util.Map;
|
| 74 | +import java.util.Set; |
70 | 75 |
|
71 | 76 | public abstract class DevSupportManagerBase implements DevSupportManager {
|
72 | 77 |
|
@@ -104,6 +109,7 @@ public interface CallbackWithBundleLoader {
|
104 | 109 | private boolean mIsReceiverRegistered = false;
|
105 | 110 | private boolean mIsShakeDetectorStarted = false;
|
106 | 111 | private boolean mIsDevSupportEnabled = false;
|
| 112 | + private boolean mIsPackagerConnected; |
107 | 113 | private @Nullable final RedBoxHandler mRedBoxHandler;
|
108 | 114 | private @Nullable String mLastErrorTitle;
|
109 | 115 | private @Nullable StackFrame[] mLastErrorStack;
|
@@ -340,6 +346,7 @@ public void showDevOptionsDialog() {
|
340 | 346 | return;
|
341 | 347 | }
|
342 | 348 | LinkedHashMap<String, DevOptionHandler> options = new LinkedHashMap<>();
|
| 349 | + Set<String> disabledItemKeys = new HashSet<>(); |
343 | 350 | /* register standard options */
|
344 | 351 | options.put(
|
345 | 352 | mApplicationContext.getString(R.string.catalyst_reload),
|
@@ -369,8 +376,15 @@ public void onOptionSelected() {
|
369 | 376 |
|
370 | 377 | if (mDevSettings.isDeviceDebugEnabled() && !mDevSettings.isRemoteJSDebugEnabled()) {
|
371 | 378 | // On-device JS debugging (CDP). Render action to open debugger frontend.
|
| 379 | + boolean isConnected = mIsPackagerConnected; |
| 380 | + String debuggerItemString = |
| 381 | + mApplicationContext.getString( |
| 382 | + isConnected ? R.string.catalyst_debug_open : R.string.catalyst_debug_open_disabled); |
| 383 | + if (!isConnected) { |
| 384 | + disabledItemKeys.add(debuggerItemString); |
| 385 | + } |
372 | 386 | options.put(
|
373 |
| - mApplicationContext.getString(R.string.catalyst_debug_open), |
| 387 | + debuggerItemString, |
374 | 388 | () ->
|
375 | 389 | mDevServerHelper.openDebugger(
|
376 | 390 | mCurrentContext,
|
@@ -505,11 +519,33 @@ public void onOptionSelected() {
|
505 | 519 | header.addView(jsExecutorLabel);
|
506 | 520 | }
|
507 | 521 |
|
| 522 | + ListAdapter adapter = |
| 523 | + new ArrayAdapter<String>( |
| 524 | + context, android.R.layout.simple_list_item_1, options.keySet().toArray(new String[0])) { |
| 525 | + @Override |
| 526 | + public boolean areAllItemsEnabled() { |
| 527 | + return false; |
| 528 | + } |
| 529 | + |
| 530 | + @Override |
| 531 | + public boolean isEnabled(int position) { |
| 532 | + return !disabledItemKeys.contains(getItem(position)); |
| 533 | + } |
| 534 | + |
| 535 | + @Override |
| 536 | + public View getView(int position, @Nullable View convertView, ViewGroup parent) { |
| 537 | + View view = super.getView(position, convertView, parent); |
| 538 | + view.setEnabled(isEnabled(position)); |
| 539 | + |
| 540 | + return view; |
| 541 | + } |
| 542 | + }; |
| 543 | + |
508 | 544 | mDevOptionsDialog =
|
509 | 545 | new AlertDialog.Builder(context)
|
510 | 546 | .setCustomTitle(header)
|
511 |
| - .setItems( |
512 |
| - options.keySet().toArray(new String[0]), |
| 547 | + .setAdapter( |
| 548 | + adapter, |
513 | 549 | (dialog, which) -> {
|
514 | 550 | optionHandlers[which].onOptionSelected();
|
515 | 551 | mDevOptionsDialog = null;
|
@@ -1022,12 +1058,12 @@ private void reload() {
|
1022 | 1058 | new PackagerCommandListener() {
|
1023 | 1059 | @Override
|
1024 | 1060 | public void onPackagerConnected() {
|
1025 |
| - // No-op |
| 1061 | + mIsPackagerConnected = true; |
1026 | 1062 | }
|
1027 | 1063 |
|
1028 | 1064 | @Override
|
1029 | 1065 | public void onPackagerDisconnected() {
|
1030 |
| - // No-op |
| 1066 | + mIsPackagerConnected = false; |
1031 | 1067 | }
|
1032 | 1068 |
|
1033 | 1069 | @Override
|
|
0 commit comments