From 2356238887a280f4064cdc6c1bbd7dbc565f75b9 Mon Sep 17 00:00:00 2001 From: Lyubo Marinov Date: Mon, 21 Aug 2017 13:45:20 -0500 Subject: [PATCH] [Android] Reduce boilerplate/duplication --- .../sdk/{audiomode => }/AudioModeModule.java | 4 +- .../BluetoothHeadsetMonitor.java | 4 +- .../{externalapi => }/ExternalAPIModule.java | 4 +- .../org/jitsi/meet/sdk/JitsiMeetView.java | 24 +++++-- .../sdk/{proximity => }/ProximityModule.java | 4 +- ...ePackage.java => ReactPackageAdapter.java} | 16 +---- .../sdk/externalapi/ExternalAPIPackage.java | 64 ------------------- .../meet/sdk/proximity/ProximityPackage.java | 64 ------------------- 8 files changed, 31 insertions(+), 153 deletions(-) rename android/sdk/src/main/java/org/jitsi/meet/sdk/{audiomode => }/AudioModeModule.java (99%) rename android/sdk/src/main/java/org/jitsi/meet/sdk/{audiomode => }/BluetoothHeadsetMonitor.java (98%) rename android/sdk/src/main/java/org/jitsi/meet/sdk/{externalapi => }/ExternalAPIModule.java (97%) rename android/sdk/src/main/java/org/jitsi/meet/sdk/{proximity => }/ProximityModule.java (97%) rename android/sdk/src/main/java/org/jitsi/meet/sdk/{audiomode/AudioModePackage.java => ReactPackageAdapter.java} (77%) delete mode 100644 android/sdk/src/main/java/org/jitsi/meet/sdk/externalapi/ExternalAPIPackage.java delete mode 100644 android/sdk/src/main/java/org/jitsi/meet/sdk/proximity/ProximityPackage.java diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/audiomode/AudioModeModule.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/AudioModeModule.java similarity index 99% rename from android/sdk/src/main/java/org/jitsi/meet/sdk/audiomode/AudioModeModule.java rename to android/sdk/src/main/java/org/jitsi/meet/sdk/AudioModeModule.java index 491c86234..26e949beb 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/audiomode/AudioModeModule.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/AudioModeModule.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jitsi.meet.sdk.audiomode; +package org.jitsi.meet.sdk; import android.annotation.TargetApi; import android.content.BroadcastReceiver; @@ -51,7 +51,7 @@ import java.util.Map; * Before a call has started and after it has ended the * AudioModeModule.DEFAULT mode should be used. */ -public class AudioModeModule extends ReactContextBaseJavaModule { +class AudioModeModule extends ReactContextBaseJavaModule { /** * Constants representing the audio mode. * - DEFAULT: Used before and after every call. It represents the default diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/audiomode/BluetoothHeadsetMonitor.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/BluetoothHeadsetMonitor.java similarity index 98% rename from android/sdk/src/main/java/org/jitsi/meet/sdk/audiomode/BluetoothHeadsetMonitor.java rename to android/sdk/src/main/java/org/jitsi/meet/sdk/BluetoothHeadsetMonitor.java index 124754e30..52d83f0e8 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/audiomode/BluetoothHeadsetMonitor.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/BluetoothHeadsetMonitor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jitsi.meet.sdk.audiomode; +package org.jitsi.meet.sdk; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothHeadset; @@ -33,7 +33,7 @@ import android.util.Log; * Bluetooth headsets being connected / disconnected and notifies the module * about device changes when this occurs. */ -public class BluetoothHeadsetMonitor { +class BluetoothHeadsetMonitor { /** * {@link AudioModeModule} where this monitor reports. */ diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/externalapi/ExternalAPIModule.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/ExternalAPIModule.java similarity index 97% rename from android/sdk/src/main/java/org/jitsi/meet/sdk/externalapi/ExternalAPIModule.java rename to android/sdk/src/main/java/org/jitsi/meet/sdk/ExternalAPIModule.java index 698663818..0382af98e 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/externalapi/ExternalAPIModule.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/ExternalAPIModule.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jitsi.meet.sdk.externalapi; +package org.jitsi.meet.sdk; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; @@ -32,7 +32,7 @@ import java.util.HashMap; * object it will dim the screen and disable touch controls. The functionality * is used with the conference audio-only mode. */ -public class ExternalAPIModule extends ReactContextBaseJavaModule { +class ExternalAPIModule extends ReactContextBaseJavaModule { /** * React Native module name. */ diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java index 94773ac5b..1ecff365b 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java @@ -28,10 +28,14 @@ import android.widget.FrameLayout; import com.facebook.react.ReactInstanceManager; import com.facebook.react.ReactRootView; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.common.LifecycleState; import java.net.URL; +import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Set; import java.util.UUID; import java.util.WeakHashMap; @@ -52,6 +56,15 @@ public class JitsiMeetView extends FrameLayout { private static final Set views = Collections.newSetFromMap(new WeakHashMap()); + private static List createNativeModules( + ReactApplicationContext reactContext) { + return Arrays.asList( + new AudioModeModule(reactContext), + new ExternalAPIModule(reactContext), + new ProximityModule(reactContext) + ); + } + public static JitsiMeetView findViewByExternalAPIScope( String externalAPIScope) { synchronized (views) { @@ -86,10 +99,13 @@ public class JitsiMeetView extends FrameLayout { .addPackage(new com.oney.WebRTCModule.WebRTCModulePackage()) .addPackage(new com.RNFetchBlob.RNFetchBlobPackage()) .addPackage(new com.rnimmersive.RNImmersivePackage()) - .addPackage(new org.jitsi.meet.sdk.audiomode.AudioModePackage()) - .addPackage( - new org.jitsi.meet.sdk.externalapi.ExternalAPIPackage()) - .addPackage(new org.jitsi.meet.sdk.proximity.ProximityPackage()) + .addPackage(new ReactPackageAdapter() { + @Override + public List createNativeModules( + ReactApplicationContext reactContext) { + return JitsiMeetView.createNativeModules(reactContext); + } + }) .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build(); diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/proximity/ProximityModule.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/ProximityModule.java similarity index 97% rename from android/sdk/src/main/java/org/jitsi/meet/sdk/proximity/ProximityModule.java rename to android/sdk/src/main/java/org/jitsi/meet/sdk/ProximityModule.java index e605243ee..0dad3d16f 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/proximity/ProximityModule.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/ProximityModule.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jitsi.meet.sdk.proximity; +package org.jitsi.meet.sdk; import android.content.Context; import android.os.PowerManager; @@ -31,7 +31,7 @@ import com.facebook.react.bridge.UiThreadUtil; * object it will dim the screen and disable touch controls. The functionality * is used with the conference audio-only mode. */ -public class ProximityModule extends ReactContextBaseJavaModule { +class ProximityModule extends ReactContextBaseJavaModule { /** * React Native module name. */ diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/audiomode/AudioModePackage.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactPackageAdapter.java similarity index 77% rename from android/sdk/src/main/java/org/jitsi/meet/sdk/audiomode/AudioModePackage.java rename to android/sdk/src/main/java/org/jitsi/meet/sdk/ReactPackageAdapter.java index c2f311cfa..8b5becc9d 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/audiomode/AudioModePackage.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactPackageAdapter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jitsi.meet.sdk.audiomode; +package org.jitsi.meet.sdk; import com.facebook.react.ReactPackage; import com.facebook.react.bridge.JavaScriptModule; @@ -22,14 +22,10 @@ import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.uimanager.ViewManager; -import java.util.ArrayList; import java.util.Collections; import java.util.List; -/** - * Implements {@link ReactPackage} for {@link AudioModeModule}. - */ -public class AudioModePackage implements ReactPackage { +public class ReactPackageAdapter implements ReactPackage { /** * {@inheritDoc} */ @@ -40,17 +36,11 @@ public class AudioModePackage implements ReactPackage { /** * {@inheritDoc} - * - * @return List of native modules to be exposed by React Native. */ @Override public List createNativeModules( ReactApplicationContext reactContext) { - List modules = new ArrayList<>(); - - modules.add(new AudioModeModule(reactContext)); - - return modules; + return Collections.emptyList(); } /** diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/externalapi/ExternalAPIPackage.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/externalapi/ExternalAPIPackage.java deleted file mode 100644 index 446680d9b..000000000 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/externalapi/ExternalAPIPackage.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright @ 2017-present Atlassian Pty Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jitsi.meet.sdk.externalapi; - -import com.facebook.react.ReactPackage; -import com.facebook.react.bridge.JavaScriptModule; -import com.facebook.react.bridge.NativeModule; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.uimanager.ViewManager; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Implements {@link ReactPackage} for {@link ExternalAPIModule}. - */ -public class ExternalAPIPackage implements ReactPackage { - /** - * {@inheritDoc} - */ - @Override - public List> createJSModules() { - return Collections.emptyList(); - } - - /** - * {@inheritDoc} - * - * @return List of native modules to be exposed by React Native. - */ - @Override - public List createNativeModules( - ReactApplicationContext reactContext) { - List modules = new ArrayList<>(); - - modules.add(new ExternalAPIModule(reactContext)); - - return modules; - } - - /** - * {@inheritDoc} - */ - @Override - public List createViewManagers( - ReactApplicationContext reactContext) { - return Collections.emptyList(); - } -} diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/proximity/ProximityPackage.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/proximity/ProximityPackage.java deleted file mode 100644 index 42544cbbb..000000000 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/proximity/ProximityPackage.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright @ 2017-present Atlassian Pty Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jitsi.meet.sdk.proximity; - -import com.facebook.react.ReactPackage; -import com.facebook.react.bridge.JavaScriptModule; -import com.facebook.react.bridge.NativeModule; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.uimanager.ViewManager; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Implements {@link ReactPackage} for {@link ProximityModule}. - */ -public class ProximityPackage implements ReactPackage { - /** - * {@inheritDoc} - */ - @Override - public List> createJSModules() { - return Collections.emptyList(); - } - - /** - * {@inheritDoc} - * - * @return List of native modules to be exposed by React Native. - */ - @Override - public List createNativeModules( - ReactApplicationContext reactContext) { - List modules = new ArrayList<>(); - - modules.add(new ProximityModule(reactContext)); - - return modules; - } - - /** - * {@inheritDoc} - */ - @Override - public List createViewManagers( - ReactApplicationContext reactContext) { - return Collections.emptyList(); - } -}