-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from avohq/production-flavour-without-visual-i…
…nspector Add production flavour without visual inspector
- Loading branch information
Showing
23 changed files
with
349 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## 2.0.0 | ||
|
||
Splitting the lib into 2 flavours. | ||
|
||
`com.github.avohq.android-avo-inspector:dev:TAG` includes the visual debugger and a SYSTEM_ALERT_WINDOW permission | ||
|
||
`com.github.avohq.android-avo-inspector:prod:TAG` does not include the visual debugger and a SYSTEM_ALERT_WINDOW permission | ||
|
||
Suggested usage is: | ||
|
||
``` | ||
releaseImplementation 'com.github.avohq.android-avo-inspector:prod:TAG' | ||
debugImplementation 'com.github.avohq.android-avo-inspector:dev:TAG' | ||
``` | ||
|
||
### Breaking change | ||
|
||
- `Inspector.getVisualInspector()` now returns a nullable `Object` instead of nullable `DebuggerManager`. | ||
You can safely cast it to a nullable `DebuggerManager` in the `dev` build and it will always be `null` in the prod build. | ||
|
||
- Dependency reference is changed to `com.github.avohq.android-avo-inspector:dev:TAG` and `com.github.avohq.android-avo-inspector:prod:TAG` | ||
(used to be from `com.github.avohq:android-avo-inspector:TAG`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
avoinspector/src/androidTest/java/app/avo/inspector/ExampleInstrumentedTest.java
This file was deleted.
Oops, something went wrong.
116 changes: 116 additions & 0 deletions
116
avoinspector/src/development/java/app/avo/inspector/VisualInspector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package app.avo.inspector; | ||
|
||
import android.app.Activity; | ||
import android.app.Application; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import app.avo.androidanalyticsdebugger.DebuggerManager; | ||
import app.avo.androidanalyticsdebugger.DebuggerMode; | ||
import app.avo.androidanalyticsdebugger.EventProperty; | ||
import app.avo.androidanalyticsdebugger.PropertyError; | ||
|
||
public class VisualInspector { | ||
@Nullable | ||
DebuggerManager debugger; | ||
|
||
VisualInspector(@NonNull AvoInspectorEnv env, @NonNull Application application, @Nullable Activity rootActivityForVisualInspector) { | ||
if (env != AvoInspectorEnv.Prod) { | ||
debugger = new DebuggerManager(application); | ||
if (rootActivityForVisualInspector != null) { | ||
show(rootActivityForVisualInspector, VisualInspectorMode.BUBBLE); | ||
} | ||
} | ||
} | ||
|
||
@Nullable | ||
public Object getDebuggerManager() { | ||
return debugger; | ||
} | ||
|
||
void show(@NonNull Activity rootActivity, @NonNull VisualInspectorMode visualInspectorMode) { | ||
if (debugger == null) { | ||
debugger = new DebuggerManager(rootActivity.getApplication()); | ||
} | ||
debugger.showDebugger(rootActivity, visualInspectorMode == VisualInspectorMode.BAR ? DebuggerMode.bar : DebuggerMode.bubble); | ||
} | ||
|
||
void hide(@NonNull Activity rootActivity) { | ||
if (debugger != null) { | ||
debugger.hideDebugger(rootActivity); | ||
} | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
void showEventInVisualInspector(@NonNull String eventName, @Nullable Map<String, ?> mapParams, @Nullable JSONObject jsonParams) { | ||
List<EventProperty> props = new ArrayList<>(); | ||
if (mapParams != null) { | ||
for (Map.Entry<String, ?> param : mapParams.entrySet()) { | ||
String name = param.getKey(); | ||
Object value = param.getValue(); | ||
if (name != null) { | ||
String valueDescription; | ||
if (value == null) { | ||
valueDescription = "null"; | ||
} else if (value instanceof List) { | ||
valueDescription = new JSONArray((List) value).toString(); | ||
} else if (value instanceof Map) { | ||
try { | ||
valueDescription = new JSONObject((Map) value).toString(1) | ||
.replace("\n", "") | ||
.replace("\\", ""); | ||
} catch (JSONException ex) { | ||
valueDescription = new JSONObject((Map) value).toString() | ||
.replace("\\", ""); | ||
} | ||
} else { | ||
valueDescription = value.toString(); | ||
} | ||
props.add(new EventProperty("", name, valueDescription)); | ||
} | ||
} | ||
} | ||
if (jsonParams != null) { | ||
for (Iterator<String> it = jsonParams.keys(); it.hasNext(); ) { | ||
String name = it.next(); | ||
try { | ||
Object value = jsonParams.get(name); | ||
props.add(new EventProperty("", name, value != JSONObject.NULL ? value.toString() : "null")); | ||
} catch (JSONException ignored) { | ||
} | ||
} | ||
} | ||
|
||
if (debugger != null) { | ||
debugger.publishEvent(System.currentTimeMillis(), "Event: " + eventName, props, new ArrayList<PropertyError>()); | ||
} | ||
} | ||
|
||
void showSchemaInVisualInspector(@NonNull String eventName, @Nullable Map<String, AvoEventSchemaType> schema) { | ||
List<EventProperty> props = new ArrayList<>(); | ||
if (schema != null) { | ||
for (Map.Entry<String, AvoEventSchemaType> param : schema.entrySet()) { | ||
String name = param.getKey(); | ||
AvoEventSchemaType value = param.getValue(); | ||
if (name != null) { | ||
props.add(new EventProperty("", name, value != null ? value.getReadableName() : "null")); | ||
} | ||
} | ||
} | ||
if (debugger != null) { | ||
debugger.publishEvent(System.currentTimeMillis(), "Schema: " + eventName, props, new ArrayList<PropertyError>()); | ||
} | ||
} | ||
} |
Oops, something went wrong.