Refactor accessory show methods for DevLoading

Summary:
Changelog:
    [Internal][Changed] - In order to make Dev Loading View cross platform, refactoring the accessary show methods.

Reviewed By: cortinico

Differential Revision: D41029102

fbshipit-source-id: 475949548fe98217e61d6cf64accbbdc0fb0f1c5
This commit is contained in:
Arushi Kesarwani
2022-11-07 11:31:55 -08:00
committed by Facebook GitHub Bot
parent 3d9a15da87
commit 7a327d9673
2 changed files with 23 additions and 32 deletions
@@ -22,8 +22,6 @@ import com.facebook.common.logging.FLog;
import com.facebook.react.R;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.ReactConstants;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;
/** Controller to display loading messages on top of the screen. All methods are thread safe. */
@@ -55,34 +53,6 @@ public class DevLoadingViewController {
});
}
public void showForUrl(String url) {
Context context = getContext();
if (context == null) {
return;
}
URL parsedURL;
try {
parsedURL = new URL(url);
} catch (MalformedURLException e) {
FLog.e(ReactConstants.TAG, "Bundle url format is invalid. \n\n" + e.toString());
return;
}
int port = parsedURL.getPort() != -1 ? parsedURL.getPort() : parsedURL.getDefaultPort();
showMessage(
context.getString(R.string.catalyst_loading_from_url, parsedURL.getHost() + ":" + port));
}
public void showForRemoteJSEnabled() {
Context context = getContext();
if (context == null) {
return;
}
showMessage(context.getString(R.string.catalyst_debug_connecting));
}
public void updateProgress(
final @Nullable String status, final @Nullable Integer done, final @Nullable Integer total) {
if (!sEnabled) {
@@ -752,13 +752,34 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
@UiThread
private void showDevLoadingViewForUrl(String bundleUrl) {
mDevLoadingViewController.showForUrl(bundleUrl);
if (mApplicationContext == null) {
return;
}
URL parsedURL;
try {
parsedURL = new URL(bundleUrl);
} catch (MalformedURLException e) {
FLog.e(ReactConstants.TAG, "Bundle url format is invalid. \n\n" + e.toString());
return;
}
int port = parsedURL.getPort() != -1 ? parsedURL.getPort() : parsedURL.getDefaultPort();
mDevLoadingViewController.showMessage(
mApplicationContext.getString(
R.string.catalyst_loading_from_url, parsedURL.getHost() + ":" + port));
mDevLoadingViewVisible = true;
}
@UiThread
protected void showDevLoadingViewForRemoteJSEnabled() {
mDevLoadingViewController.showForRemoteJSEnabled();
if (mApplicationContext == null) {
return;
}
mDevLoadingViewController.showMessage(
mApplicationContext.getString(R.string.catalyst_debug_connecting));
mDevLoadingViewVisible = true;
}