|
18 | 18 | public class RNInstabug { |
19 | 19 |
|
20 | 20 | private static RNInstabug instance; |
21 | | - |
| 21 | + |
22 | 22 | private RNInstabug() {} |
23 | 23 |
|
24 | 24 |
|
@@ -133,4 +133,117 @@ public void setBaseUrlForDeprecationLogs() { |
133 | 133 | e.printStackTrace(); |
134 | 134 | } |
135 | 135 | } |
| 136 | + |
| 137 | + public static class Builder { |
| 138 | + |
| 139 | + /** |
| 140 | + * Application instance to initialize Instabug. |
| 141 | + */ |
| 142 | + private Application application; |
| 143 | + |
| 144 | + /** |
| 145 | + * The application token obtained from the Instabug dashboard. |
| 146 | + */ |
| 147 | + private String applicationToken; |
| 148 | + |
| 149 | + /** |
| 150 | + * The level of detail in logs that you want to print. |
| 151 | + */ |
| 152 | + private int logLevel = LogLevel.ERROR; |
| 153 | + |
| 154 | + /** |
| 155 | + * The Code Push version to be used for all reports. |
| 156 | + */ |
| 157 | + private String codePushVersion; |
| 158 | + |
| 159 | + /** |
| 160 | + * The events that trigger the SDK's user interface. |
| 161 | + */ |
| 162 | + private InstabugInvocationEvent[] invocationEvents; |
| 163 | + |
| 164 | + |
| 165 | + /** |
| 166 | + * Initialize Instabug SDK with application token |
| 167 | + * |
| 168 | + * @param application Application object for initialization of library |
| 169 | + * @param applicationToken The app's identifying token, available on your dashboard. |
| 170 | + */ |
| 171 | + public Builder(Application application, String applicationToken) { |
| 172 | + this.application = application; |
| 173 | + this.applicationToken = applicationToken; |
| 174 | + } |
| 175 | + |
| 176 | + /** |
| 177 | + * Initialize Instabug SDK with application token and invocation trigger events |
| 178 | + * |
| 179 | + * @param application Application object for initialization of library |
| 180 | + * @param applicationToken The app's identifying token, available on your dashboard. |
| 181 | + * @param invocationEvents The events that trigger the SDK's user interface. |
| 182 | + * <p>Choose from the available events listed in {@link InstabugInvocationEvent}.</p> |
| 183 | + */ |
| 184 | + public Builder(Application application, String applicationToken, InstabugInvocationEvent... invocationEvents) { |
| 185 | + this.application = application; |
| 186 | + this.applicationToken = applicationToken; |
| 187 | + this.invocationEvents = invocationEvents; |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * Sets the filtering level for printed SDK logs. |
| 192 | + * |
| 193 | + * @param logLevel The log filtering level to be set. |
| 194 | + * Choose from {@link LogLevel} constants: |
| 195 | + * {@link LogLevel#NONE}, {@link LogLevel#ERROR}, {@link LogLevel#DEBUG}, or {@link LogLevel#VERBOSE}. |
| 196 | + * <p>Default level is {@link LogLevel#ERROR}.</p> |
| 197 | + */ |
| 198 | + public Builder setLogLevel(int logLevel) { |
| 199 | + this.logLevel = logLevel; |
| 200 | + return this; |
| 201 | + } |
| 202 | + |
| 203 | + /** |
| 204 | + * Sets Code Push version to be used for all reports. |
| 205 | + * |
| 206 | + * @param codePushVersion the Code Push version to work with. |
| 207 | + */ |
| 208 | + public Builder setCodePushVersion(String codePushVersion) { |
| 209 | + this.codePushVersion = codePushVersion; |
| 210 | + return this; |
| 211 | + } |
| 212 | + |
| 213 | + /** |
| 214 | + * Sets the invocation triggering events for the SDK's user interface |
| 215 | + * |
| 216 | + * @param invocationEvents The events that trigger the SDK's user interface. |
| 217 | + * Choose from the available events listed in {@link InstabugInvocationEvent}. |
| 218 | + */ |
| 219 | + public Builder setInvocationEvents(InstabugInvocationEvent... invocationEvents) { |
| 220 | + this.invocationEvents = invocationEvents; |
| 221 | + return this; |
| 222 | + } |
| 223 | + |
| 224 | + /** |
| 225 | + * Builds the Instabug instance with the provided configurations. |
| 226 | + */ |
| 227 | + public void build() { |
| 228 | + try { |
| 229 | + RNInstabug.getInstance().setBaseUrlForDeprecationLogs(); |
| 230 | + RNInstabug.getInstance().setCurrentPlatform(); |
| 231 | + |
| 232 | + Instabug.Builder instabugBuilder = new Instabug.Builder(application, applicationToken) |
| 233 | + .setInvocationEvents(invocationEvents) |
| 234 | + .setSdkDebugLogsLevel(logLevel); |
| 235 | + |
| 236 | + if (codePushVersion != null) { |
| 237 | + instabugBuilder.setCodePushVersion(codePushVersion); |
| 238 | + } |
| 239 | + |
| 240 | + instabugBuilder.build(); |
| 241 | + |
| 242 | + // Temporarily disabling APM hot launches |
| 243 | + APM.setHotAppLaunchEnabled(false); |
| 244 | + } catch (Exception e) { |
| 245 | + e.printStackTrace(); |
| 246 | + } |
| 247 | + } |
| 248 | + } |
136 | 249 | } |
0 commit comments