Skip to content

Commit

Permalink
Merge pull request #19 from avohq/production-flavour-without-visual-i…
Browse files Browse the repository at this point in the history
…nspector

Add production flavour without visual inspector
  • Loading branch information
aleks-tpom6oh authored Feb 8, 2021
2 parents bdaaee5 + 87d73a9 commit 1b005ec
Show file tree
Hide file tree
Showing 23 changed files with 349 additions and 292 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
java-version: 1.8

- name: Run tests
run: ./gradlew --warning-mode=none test
run: ./gradlew --warning-mode=none testDevelopmentReleaseUnitTest
22 changes: 22 additions & 0 deletions CHANGELOG.md
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`)
51 changes: 43 additions & 8 deletions avoinspector/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

android {
compileSdkVersion 29
compileSdkVersion 30
buildToolsVersion "29.0.3"


defaultConfig {
minSdkVersion 14
targetSdkVersion 29
targetSdkVersion 30
versionCode 3
versionName "1.3.0"
versionName "2.0.0"

testInstrumentationRunner "AndroidJUnit4"
consumerProguardFiles 'consumer-rules.pro'

buildConfigField 'int', 'VERSION_CODE', "${versionCode}"
buildConfigField 'String', 'VERSION_NAME', "\"${versionName}\""
}

buildTypes {
Expand All @@ -22,13 +25,26 @@ android {
}
}

defaultPublishConfig "developmentRelease"

flavorDimensions "avoEnvironment"

productFlavors {
production {
dimension "avoEnvironment"
}
development {
dimension "avoEnvironment"
}
}

testOptions {
unitTests.returnDefaultValues = true
}
}

dependencies {
api 'com.github.avohq:android-analytics-debugger:1.0.6'
developmentApi 'com.github.avohq:android-analytics-debugger:1.0.6'

implementation 'io.sentry:sentry:1.7.30'

Expand All @@ -39,7 +55,26 @@ dependencies {
testImplementation 'com.segment.analytics.android:analytics:4.8.2'
testImplementation 'org.json:json:20190722'
testImplementation "org.mockito:mockito-core:2.28.2"
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

afterEvaluate {
publishing {
publications {
production(MavenPublication) {
from components.productionRelease

groupId = 'com.github.avohq'
artifactId = 'prod'
version = '2.0.0'
}

development(MavenPublication) {
from components.developmentRelease

groupId = 'com.github.avohq'
artifactId = 'dev'
version = '2.0.0'
}
}
}
}

This file was deleted.

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>());
}
}
}
Loading

0 comments on commit 1b005ec

Please sign in to comment.