Преглед изворни кода

feat(android) use JitsiMeetView instead of JitsiMeetFragment

master
tmoldovan8x8 пре 3 година
родитељ
комит
6a1067733a
No account linked to committer's email address

+ 23
- 9
android/sdk/src/main/java/org/jitsi/meet/sdk/BaseReactView.java Прегледај датотеку

@@ -20,6 +20,7 @@ package org.jitsi.meet.sdk;
20 20
 import android.app.Activity;
21 21
 import android.content.Context;
22 22
 import android.os.Bundle;
23
+import android.util.AttributeSet;
23 24
 import android.widget.FrameLayout;
24 25
 import androidx.annotation.NonNull;
25 26
 import androidx.annotation.Nullable;
@@ -93,7 +94,7 @@ public abstract class BaseReactView<ListenerT>
93 94
      * inspired by postis which we use on Web for the similar purposes of the
94 95
      * iframe-based external API.
95 96
      */
96
-    protected final String externalAPIScope;
97
+    protected String externalAPIScope;
97 98
 
98 99
     /**
99 100
      * The listener (e.g. {@link JitsiMeetViewListener}) instance for reporting
@@ -109,16 +110,17 @@ public abstract class BaseReactView<ListenerT>
109 110
 
110 111
     public BaseReactView(@NonNull Context context) {
111 112
         super(context);
113
+        initialize((Activity)context);
114
+    }
112 115
 
113
-        setBackgroundColor(BACKGROUND_COLOR);
114
-
115
-        ReactInstanceManagerHolder.initReactInstanceManager((Activity)context);
116
+    public BaseReactView(Context context, AttributeSet attrs) {
117
+        super(context, attrs);
118
+        initialize((Activity)context);
119
+    }
116 120
 
117
-        // Hook this BaseReactView into ExternalAPI.
118
-        externalAPIScope = UUID.randomUUID().toString();
119
-        synchronized (views) {
120
-            views.add(this);
121
-        }
121
+    public BaseReactView(Context context, AttributeSet attrs, int defStyle) {
122
+        super(context, attrs, defStyle);
123
+        initialize((Activity)context);
122 124
     }
123 125
 
124 126
     /**
@@ -223,4 +225,16 @@ public abstract class BaseReactView<ListenerT>
223 225
     public void setListener(ListenerT listener) {
224 226
         this.listener = listener;
225 227
     }
228
+
229
+    private void initialize(Activity activity) {
230
+        setBackgroundColor(BACKGROUND_COLOR);
231
+
232
+        ReactInstanceManagerHolder.initReactInstanceManager(activity);
233
+
234
+        // Hook this BaseReactView into ExternalAPI.
235
+        externalAPIScope = UUID.randomUUID().toString();
236
+        synchronized (views) {
237
+            views.add(this);
238
+        }
239
+    }
226 240
 }

+ 40
- 18
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java Прегледај датотеку

@@ -16,6 +16,7 @@
16 16
 
17 17
 package org.jitsi.meet.sdk;
18 18
 
19
+import android.app.Activity;
19 20
 import android.content.BroadcastReceiver;
20 21
 import android.content.Context;
21 22
 import android.content.Intent;
@@ -32,11 +33,16 @@ import com.facebook.react.modules.core.PermissionListener;
32 33
 import org.jitsi.meet.sdk.log.JitsiMeetLogger;
33 34
 
34 35
 import java.util.HashMap;
35
-import android.app.Activity;
36 36
 
37 37
 /**
38
- * A base activity for SDK users to embed. It uses {@link JitsiMeetFragment} to do the heavy
39
- * lifting and wires the remaining Activity lifecycle methods so it works out of the box.
38
+ * A base activity for SDK users to embed.  It contains all the required wiring
39
+ * between the {@code JitsiMeetView} and the Activity lifecycle methods.
40
+ *
41
+ * In this activity we use a single {@code JitsiMeetView} instance. This
42
+ * instance gives us access to a view which displays the welcome page and the
43
+ * conference itself. All lifecycle methods associated with this Activity are
44
+ * hooked to the React Native subsystem via proxy calls through the
45
+ * {@code JitsiMeetActivityDelegate} static methods.
40 46
  */
41 47
 public class JitsiMeetActivity extends AppCompatActivity
42 48
     implements JitsiMeetActivityInterface {
@@ -52,6 +58,12 @@ public class JitsiMeetActivity extends AppCompatActivity
52 58
             onBroadcastReceived(intent);
53 59
         }
54 60
     };
61
+
62
+    /**
63
+     * Instance of the {@link JitsiMeetView} which this activity will display.
64
+     */
65
+    private JitsiMeetView jitsiView;
66
+
55 67
     // Helpers for starting the activity
56 68
     //
57 69
 
@@ -79,6 +91,7 @@ public class JitsiMeetActivity extends AppCompatActivity
79 91
         super.onCreate(savedInstanceState);
80 92
 
81 93
         setContentView(R.layout.activity_jitsi_meet);
94
+        this.jitsiView = findViewById(R.id.jitsiView);
82 95
 
83 96
         registerForBroadcastMessages();
84 97
 
@@ -87,6 +100,18 @@ public class JitsiMeetActivity extends AppCompatActivity
87 100
         }
88 101
     }
89 102
 
103
+    @Override
104
+    public void onResume() {
105
+        super.onResume();
106
+        JitsiMeetActivityDelegate.onHostResume(this);
107
+    }
108
+
109
+    @Override
110
+    public void onStop() {
111
+        JitsiMeetActivityDelegate.onHostPause(this);
112
+        super.onStop();
113
+    }
114
+
90 115
     @Override
91 116
     public void onDestroy() {
92 117
         // Here we are trying to handle the following corner case: an application using the SDK
@@ -97,6 +122,9 @@ public class JitsiMeetActivity extends AppCompatActivity
97 122
         // be operational so the external API won't be able to notify the native side that the
98 123
         // conference terminated. Thus, try our best to clean up.
99 124
         leave();
125
+
126
+        this.jitsiView = null;
127
+
100 128
         if (AudioModeModule.useConnectionService()) {
101 129
             ConnectionService.abortConnections();
102 130
         }
@@ -104,6 +132,8 @@ public class JitsiMeetActivity extends AppCompatActivity
104 132
 
105 133
         LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
106 134
 
135
+        JitsiMeetActivityDelegate.onHostDestroy(this);
136
+
107 137
         super.onDestroy();
108 138
     }
109 139
 
@@ -118,9 +148,7 @@ public class JitsiMeetActivity extends AppCompatActivity
118 148
     //
119 149
 
120 150
     protected JitsiMeetView getJitsiView() {
121
-        JitsiMeetFragment fragment
122
-            = (JitsiMeetFragment) getSupportFragmentManager().findFragmentById(R.id.jitsiFragment);
123
-        return fragment != null ? fragment.getJitsiView() : null;
151
+        return jitsiView;
124 152
     }
125 153
 
126 154
     public void join(@Nullable String url) {
@@ -132,20 +160,16 @@ public class JitsiMeetActivity extends AppCompatActivity
132 160
     }
133 161
 
134 162
     public void join(JitsiMeetConferenceOptions options) {
135
-        JitsiMeetView view = getJitsiView();
136
-
137
-        if (view != null) {
138
-            view.join(options);
163
+        if (this.jitsiView  != null) {
164
+            this.jitsiView .join(options);
139 165
         } else {
140 166
             JitsiMeetLogger.w("Cannot join, view is null");
141 167
         }
142 168
     }
143 169
 
144 170
     public void leave() {
145
-        JitsiMeetView view = getJitsiView();
146
-
147
-        if (view != null) {
148
-            view.leave();
171
+        if (this.jitsiView  != null) {
172
+            this.jitsiView .leave();
149 173
         } else {
150 174
             JitsiMeetLogger.w("Cannot leave, view is null");
151 175
         }
@@ -252,10 +276,8 @@ public class JitsiMeetActivity extends AppCompatActivity
252 276
 
253 277
     @Override
254 278
     protected void onUserLeaveHint() {
255
-        JitsiMeetView view = getJitsiView();
256
-
257
-        if (view != null) {
258
-            view.enterPictureInPicture();
279
+        if (this.jitsiView  != null) {
280
+            this.jitsiView .enterPictureInPicture();
259 281
         }
260 282
     }
261 283
 

+ 3
- 1
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetFragment.java Прегледај датотеку

@@ -17,7 +17,6 @@
17 17
 
18 18
 package org.jitsi.meet.sdk;
19 19
 
20
-import android.content.Intent;
21 20
 import android.os.Bundle;
22 21
 import androidx.annotation.NonNull;
23 22
 import androidx.annotation.Nullable;
@@ -37,7 +36,10 @@ import android.view.ViewGroup;
37 36
  * conference itself. All lifecycle methods associated with this Fragment are
38 37
  * hooked to the React Native subsystem via proxy calls through the
39 38
  * {@code JitsiMeetActivityDelegate} static methods.
39
+ *
40
+ * @deprecated use {@link JitsiMeetActivity} or directly {@link JitsiMeetView}
40 41
  */
42
+@Deprecated
41 43
 public class JitsiMeetFragment extends Fragment {
42 44
 
43 45
     /**

+ 21
- 7
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java Прегледај датотеку

@@ -18,6 +18,8 @@ package org.jitsi.meet.sdk;
18 18
 
19 19
 import android.content.Context;
20 20
 import android.os.Bundle;
21
+import android.util.AttributeSet;
22
+
21 23
 import androidx.annotation.NonNull;
22 24
 import androidx.annotation.Nullable;
23 25
 
@@ -28,7 +30,6 @@ import org.jitsi.meet.sdk.log.JitsiMeetLogger;
28 30
 import java.lang.reflect.Method;
29 31
 import java.util.Map;
30 32
 
31
-
32 33
 public class JitsiMeetView extends BaseReactView<JitsiMeetViewListener>
33 34
         implements OngoingConferenceTracker.OngoingConferenceListener {
34 35
 
@@ -95,14 +96,17 @@ public class JitsiMeetView extends BaseReactView<JitsiMeetViewListener>
95 96
 
96 97
     public JitsiMeetView(@NonNull Context context) {
97 98
         super(context);
99
+        initialize(context);
100
+    }
98 101
 
99
-        // Check if the parent Activity implements JitsiMeetActivityInterface,
100
-        // otherwise things may go wrong.
101
-        if (!(context instanceof JitsiMeetActivityInterface)) {
102
-            throw new RuntimeException("Enclosing Activity must implement JitsiMeetActivityInterface");
103
-        }
102
+    public JitsiMeetView(Context context, AttributeSet attrs) {
103
+        super(context, attrs);
104
+        initialize(context);
105
+    }
104 106
 
105
-        OngoingConferenceTracker.getInstance().addListener(this);
107
+    public JitsiMeetView(Context context, AttributeSet attrs, int defStyle) {
108
+        super(context, attrs, defStyle);
109
+        initialize(context);
106 110
     }
107 111
 
108 112
     @Override
@@ -207,4 +211,14 @@ public class JitsiMeetView extends BaseReactView<JitsiMeetViewListener>
207 211
         dispose();
208 212
         super.onDetachedFromWindow();
209 213
     }
214
+
215
+    private void initialize(@NonNull Context context) {
216
+        // Check if the parent Activity implements JitsiMeetActivityInterface,
217
+        // otherwise things may go wrong.
218
+        if (!(context instanceof JitsiMeetActivityInterface)) {
219
+            throw new RuntimeException("Enclosing Activity must implement JitsiMeetActivityInterface");
220
+        }
221
+
222
+        OngoingConferenceTracker.getInstance().addListener(this);
223
+    }
210 224
 }

+ 5
- 4
android/sdk/src/main/res/layout/activity_jitsi_meet.xml Прегледај датотеку

@@ -1,12 +1,13 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 3
     xmlns:tools="http://schemas.android.com/tools"
4
+    android:id="@+id/jitsi_layout"
4 5
     android:layout_width="match_parent"
5 6
     android:layout_height="match_parent"
6 7
     tools:context=".JitsiMeetActivity">
7
-    <fragment
8
+
9
+    <org.jitsi.meet.sdk.JitsiMeetView
10
+        android:id="@+id/jitsiView"
8 11
         android:layout_width="match_parent"
9
-        android:layout_height="match_parent"
10
-        android:name="org.jitsi.meet.sdk.JitsiMeetFragment"
11
-        android:id="@+id/jitsiFragment"/>
12
+        android:layout_height="match_parent" />
12 13
 </FrameLayout>

Loading…
Откажи
Сачувај