|
16 | 16 |
|
17 | 17 | package com.huawei.hms.rn.analytics; |
18 | 18 |
|
19 | | -import android.util.Log; |
20 | | - |
21 | 19 | import com.facebook.react.bridge.Promise; |
22 | 20 | import com.facebook.react.bridge.ReactApplicationContext; |
23 | | -import com.facebook.react.bridge.ReactContext; |
24 | 21 | import com.facebook.react.bridge.ReactContextBaseJavaModule; |
25 | 22 | import com.facebook.react.bridge.ReactMethod; |
26 | 23 | import com.facebook.react.bridge.ReadableArray; |
27 | 24 | import com.facebook.react.bridge.ReadableMap; |
28 | | -import com.huawei.hms.analytics.HiAnalytics; |
29 | | -import com.huawei.hms.analytics.type.ReportPolicy; |
30 | | -import com.huawei.hms.rn.analytics.logger.HMSLogger; |
31 | 25 |
|
32 | 26 | import java.lang.ref.WeakReference; |
33 | | -import java.util.ArrayList; |
34 | 27 |
|
| 28 | +import javax.annotation.Nonnull; |
35 | 29 |
|
36 | | -public class HmsAnalyticsModule extends ReactContextBaseJavaModule { |
| 30 | +public class HMSAnalyticsModule extends ReactContextBaseJavaModule { |
37 | 31 |
|
38 | | - private HmsAnalyticsWrapper hmsAnalyticsWrapper; |
39 | | - private WeakReference<ReactContext> weakContext; |
| 32 | + private final HMSAnalyticsWrapper hmsAnalyticsWrapper; |
40 | 33 |
|
41 | | - public HmsAnalyticsModule(ReactApplicationContext reactContext) { |
| 34 | + public HMSAnalyticsModule(ReactApplicationContext reactContext) { |
42 | 35 | super(reactContext); |
43 | | - |
44 | | - weakContext = new WeakReference<>(reactContext); |
45 | | - hmsAnalyticsWrapper = new HmsAnalyticsWrapper(reactContext); |
| 36 | + new WeakReference<>(reactContext); |
| 37 | + hmsAnalyticsWrapper = new HMSAnalyticsWrapper(reactContext); |
46 | 38 | } |
47 | 39 |
|
| 40 | + @Nonnull |
48 | 41 | @Override |
49 | 42 | public String getName() { |
50 | | - return "HmsAnalyticsModule"; |
| 43 | + return "HMSAnalyticsModule"; |
51 | 44 | } |
52 | 45 |
|
53 | 46 | @ReactMethod |
@@ -125,72 +118,34 @@ public void deleteUserProfile(String name, Promise promise) { |
125 | 118 | hmsAnalyticsWrapper.setUserProfile(name, null, promise); |
126 | 119 | } |
127 | 120 |
|
128 | | - /** |
129 | | - * Specifies whether to enable restriction of HUAWEI Analytics. The default value is false, which indicates that HUAWEI Analytics is enabled by default. |
130 | | - * @param enabled: Indicates whether to enable restriction of HUAWEI Analytics. The default value is false, which indicates that HUAWEI Analytics is enabled by default. |
131 | | - * - true: Enables restriction of HUAWEI Analytics. |
132 | | - * - false: Disables restriction of HUAWEI Analytics. |
133 | | - * @param promise: Promise instance. |
134 | | - */ |
135 | 121 | @ReactMethod |
136 | 122 | public void setRestrictionEnabled(Boolean enabled, Promise promise) { |
137 | 123 | hmsAnalyticsWrapper.setRestrictionEnabled(enabled, promise); |
138 | 124 | } |
139 | 125 |
|
140 | | - /** |
141 | | - * Obtains the restriction status of HUAWEI Analytics. |
142 | | - * @param promise: Promise instance. |
143 | | - */ |
144 | 126 | @ReactMethod |
145 | 127 | public void isRestrictionEnabled(Promise promise) { |
146 | 128 | hmsAnalyticsWrapper.isRestrictionEnabled(promise); |
147 | 129 | } |
148 | 130 |
|
149 | | - /** |
150 | | - * Sets the automatic event reporting policy. |
151 | | - * |
152 | | - * @param array: Policy for data reporting. |
153 | | - * @param promise: Promise instance. |
154 | | - */ |
155 | 131 | @ReactMethod |
156 | | - public void setReportPolicies(ReadableArray array, Promise promise){ |
| 132 | + public void setReportPolicies(ReadableArray array, Promise promise) { |
157 | 133 | hmsAnalyticsWrapper.setReportPolicies(array, promise); |
158 | 134 | } |
159 | 135 |
|
160 | | - /** |
161 | | - * Obtains the threshold for event reporting. |
162 | | - * |
163 | | - * @param reportPolicyType: Event reporting policy name. |
164 | | - * @param promise: Promise instance. |
165 | | - */ |
166 | 136 | @ReactMethod |
167 | | - public void getReportPolicyThreshold(String reportPolicyType, Promise promise){ |
| 137 | + public void getReportPolicyThreshold(String reportPolicyType, Promise promise) { |
168 | 138 | hmsAnalyticsWrapper.getReportPolicyThreshold(reportPolicyType, promise); |
169 | 139 | } |
170 | 140 |
|
171 | | - /** |
172 | | - * Enables HMSLogger logging functions. |
173 | | - */ |
174 | 141 | @ReactMethod |
175 | 142 | public void enableLogger(Promise promise) { |
176 | | - HMSLogger.getInstance(getContext()).enableLogger(); |
177 | | - promise.resolve(true); |
| 143 | + hmsAnalyticsWrapper.enableLogger(promise); |
178 | 144 | } |
179 | 145 |
|
180 | | - /** |
181 | | - * Disables HMSLogger logging functions. |
182 | | - */ |
183 | 146 | @ReactMethod |
184 | 147 | public void disableLogger(Promise promise) { |
185 | | - HMSLogger.getInstance(getContext()).disableLogger(); |
186 | | - promise.resolve(true); |
| 148 | + hmsAnalyticsWrapper.disableLogger(promise); |
187 | 149 | } |
188 | 150 |
|
189 | | - /** |
190 | | - * Returns context instance. |
191 | | - * @return Context |
192 | | - */ |
193 | | - private ReactContext getContext(){ |
194 | | - return weakContext.get(); |
195 | | - } |
196 | 151 | } |
0 commit comments