Skip to content

Commit

Permalink
Adds showWelcomeMessageWithMode , identifyUserWithEmail, logOut, setL…
Browse files Browse the repository at this point in the history
…ocale

1) Mapping locale, welcome message enums in android, ios and adding them to flutter.
2) Mapping of the following Apis in Android and IOS and adding them to flutter:
showWelcomeMessageWithMode:
identifyUserWithEmail:name:
logOut
setLocale
3) Calling all above Apis from Example App
  • Loading branch information
alyezz authored Mar 7, 2019
1 parent 4c414b0 commit 50312bd
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 19 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ The table below contains a list of APIs we're planning to implement for our 1.0
| API Method | Native Equivalent (Android/iOS) |
|------------|-----------------------------------------------------------------------------------------------------------------------------------------|
| `start(String token, List<InvocationEvent> invocationEvents)` | `new Instabug.Builder(this, "APP_TOKEN").build()`<br>`+ [Instabug startWithToken:invocationEvents:]` |
| | `Instabug.showWelcomeMessage(WelcomeMessage.State state)`<br>`+ [Instabug showWelcomeMessageWithMode:]` |
| | `Instabug.identifyUser(String username, String email)`<br>`+ [Instabug identifyUserWithEmail:name:]` |
| | `Instabug.logoutUser()`<br>`+ [Instabug logOut]` |
| | `Instabug.setLocale(Locale locale)`<br>`+ [Instabug setLocale:]` |
|`showWelcomeMessageWithMode(WelcomeMessageMode welcomeMessageMode)`| `Instabug.showWelcomeMessage(WelcomeMessage.State state)`<br>`+ [Instabug showWelcomeMessageWithMode:]` |
|`identifyUserWithEmail(String email, [String name])`| `Instabug.identifyUser(String username, String email)`<br>`+ [Instabug identifyUserWithEmail:name:]` |
|`logOut()`| `Instabug.logoutUser()`<br>`+ [Instabug logOut]` |
|`setLocale(Locale locale)`| `Instabug.setLocale(Locale locale)`<br>`+ [Instabug setLocale:]` |
| | `Instabug.setColorTheme(InstabugColorTheme theme)`<br>`+ [Instabug setColorTheme:]` |
| | `Instabug.addTags(String... tags)`<br>`+ [Instabug appendTags:]` |
| | `Instabug.resetTags()`<br>`+ [Instabug resetTags]` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import android.app.Application;

import com.instabug.library.Instabug;
import com.instabug.library.internal.module.InstabugLocale;
import com.instabug.library.invocation.InstabugInvocationEvent;
import com.instabug.library.ui.onboarding.WelcomeMessage;

import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -21,12 +23,14 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import android.os.Handler;
import android.os.Looper;
import android.util.Log;


// import com.instabug.library.InstabugColorTheme;
// import com.instabug.library.InstabugCustomTextPlaceHolder;
// import com.instabug.library.internal.module.InstabugLocale;
Expand Down Expand Up @@ -100,13 +104,96 @@ public void start(Application application, String token, ArrayList<String> invoc
new Instabug.Builder(application, token).setInvocationEvents(invocationEventsArray).build();
}


/**
* Shows the welcome message in a specific mode.
*
* @param welcomeMessageMode An enum to set the welcome message mode to
* live, or beta.
*/
public void showWelcomeMessageWithMode(String welcomeMessageMode) {
Instabug.showWelcomeMessage((WelcomeMessage.State) constants.get(welcomeMessageMode));
}

/**
* Set the user identity.
*
* @param userName Username.
* @param userEmail User's default email
*/
public void identifyUserWithEmail(String userEmail, String userName) {
Instabug.identifyUser(userEmail, userName);
}

/**
* Sets the default value of the user's email to null and show email field and remove user
* name from all reports
* It also reset the chats on device and removes user attributes, user data and completed
* surveys.
*/
public void logOut() {
Instabug.logoutUser();
}

/**
* Change Locale of Instabug UI elements(defaults to English)
*
* @param instabugLocale
*/
public void setLocale(String instabugLocale) {
Instabug.changeLocale((Locale) constants.get(instabugLocale));
}


public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
constants.put("InvocationEvent.none", InstabugInvocationEvent.NONE);
constants.put("InvocationEvent.screenshot", InstabugInvocationEvent.SCREENSHOT);
constants.put("InvocationEvent.twoFingersSwipeLeft", InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT);
constants.put("InvocationEvent.floatingButton", InstabugInvocationEvent.FLOATING_BUTTON);
constants.put("InvocationEvent.shake", InstabugInvocationEvent.SHAKE);

constants.put("WelcomeMessageMode.live", WelcomeMessage.State.LIVE);
constants.put("WelcomeMessageMode.beta", WelcomeMessage.State.BETA);
constants.put("WelcomeMessageMode.disabled", WelcomeMessage.State.DISABLED);

constants.put("Locale.Arabic",
new Locale(InstabugLocale.ARABIC.getCode(), InstabugLocale.ARABIC.getCountry()));
constants.put("Locale.ChineseSimplified",
new Locale(InstabugLocale.SIMPLIFIED_CHINESE.getCode(), InstabugLocale.SIMPLIFIED_CHINESE.getCountry()));
constants.put("Locale.ChineseTraditional",
new Locale(InstabugLocale.TRADITIONAL_CHINESE.getCode(), InstabugLocale.TRADITIONAL_CHINESE.getCountry()));
constants.put("Locale.Czech",
new Locale(InstabugLocale.CZECH.getCode(), InstabugLocale.CZECH.getCountry()));
constants.put("Locale.Danish",
new Locale(InstabugLocale.DANISH.getCode(), InstabugLocale.DANISH.getCountry()));
constants.put("Locale.Dutch",
new Locale(InstabugLocale.NETHERLANDS.getCode(), InstabugLocale.NETHERLANDS.getCountry()));
constants.put("Locale.English",
new Locale(InstabugLocale.ENGLISH.getCode(), InstabugLocale.ENGLISH.getCountry()));
constants.put("Locale.French",
new Locale(InstabugLocale.FRENCH.getCode(), InstabugLocale.FRENCH.getCountry()));
constants.put("Locale.German",
new Locale(InstabugLocale.GERMAN.getCode(), InstabugLocale.GERMAN.getCountry()));
constants.put("Locale.Italian",
new Locale(InstabugLocale.ITALIAN.getCode(), InstabugLocale.ITALIAN.getCountry()));
constants.put("Locale.Japanese",
new Locale(InstabugLocale.JAPANESE.getCode(), InstabugLocale.JAPANESE.getCountry()));
constants.put("Locale.Korean",
new Locale(InstabugLocale.KOREAN.getCode(), InstabugLocale.KOREAN.getCountry()));
constants.put("Locale.Polish",
new Locale(InstabugLocale.POLISH.getCode(), InstabugLocale.POLISH.getCountry()));
constants.put("Locale.PortugueseBrazil",
new Locale(InstabugLocale.PORTUGUESE_BRAZIL.getCode(), InstabugLocale.PORTUGUESE_BRAZIL.getCountry()));
constants.put("Locale.Russian",
new Locale(InstabugLocale.RUSSIAN.getCode(), InstabugLocale.RUSSIAN.getCountry()));
constants.put("Locale.Spanish",
new Locale(InstabugLocale.SPANISH.getCode(), InstabugLocale.SPANISH.getCountry()));
constants.put("Locale.Swedish",
new Locale(InstabugLocale.SWEDISH.getCode(), InstabugLocale.SWEDISH.getCountry()));
constants.put("Locale.Turkish",
new Locale(InstabugLocale.TURKISH.getCode(), InstabugLocale.TURKISH.getCountry()));

return constants;
}
}
14 changes: 8 additions & 6 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -41,12 +40,13 @@
/* Begin PBXFileReference section */
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
44074344FC9C61EF69573882 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
8A66ED0D8D8B0E4F8599CDAA /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; };
Expand All @@ -57,6 +57,7 @@
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A9EBB397F99FB54015C87211 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; };
BAC4880E1C40979FFB98D02A /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -76,6 +77,9 @@
13077D31F6E12C6C6AA74720 /* Pods */ = {
isa = PBXGroup;
children = (
44074344FC9C61EF69573882 /* Pods-Runner.debug.xcconfig */,
BAC4880E1C40979FFB98D02A /* Pods-Runner.release.xcconfig */,
8A66ED0D8D8B0E4F8599CDAA /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
sourceTree = "<group>";
Expand All @@ -91,7 +95,6 @@
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
3B80C3931E831B6300D905FE /* App.framework */,
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
9740EEBA1CF902C7004384FC /* Flutter.framework */,
Expand Down Expand Up @@ -211,7 +214,6 @@
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -227,7 +229,7 @@
inputFileListPaths = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
"${PODS_ROOT}/Instabug/Instabug.framework",
"${PODS_ROOT}/Instabug/Instabug.framework.dSYM",
Expand All @@ -242,7 +244,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
5 changes: 5 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class _MyAppState extends State<MyApp> {
if (Platform.isIOS) {
InstabugFlutter.start('9582e6cfe34e2b8897f48cfa3b617adb', [InvocationEvent.floatingButton, InvocationEvent.shake]);
}
InstabugFlutter.showWelcomeMessageWithMode(WelcomeMessageMode.beta);
InstabugFlutter.identifyUserWithEmail("[email protected]", "Aly Ezz");
InstabugFlutter.logOut();
InstabugFlutter.setLocale(Locale.German);

} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
Expand Down
90 changes: 81 additions & 9 deletions ios/Classes/InstabugFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@

@implementation InstabugFlutterPlugin

+ (NSDictionary *) constants {
return @{
@"InvocationEvent.shake": @(IBGInvocationEventShake),
@"InvocationEvent.screenshot": @(IBGInvocationEventScreenshot),
@"InvocationEvent.twoFingersSwipeLeft": @(IBGInvocationEventTwoFingersSwipeLeft),
@"InvocationEvent.floatingButton": @(IBGInvocationEventFloatingButton),
@"InvocationEvent.none": @(IBGInvocationEventNone),
};
};

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
Expand Down Expand Up @@ -63,4 +54,85 @@ + (void)startWithToken:(NSString *)token invocationEvents:(NSArray*)invocationEv
[Instabug startWithToken:token invocationEvents:invocationEvents];
}

/**
* Shows the welcome message in a specific mode.
*
* @param welcomeMessageMode An enum to set the welcome message mode to
* live, or beta.
*/
+ (void)showWelcomeMessageWithMode:(NSString *)welcomeMessageMode {
NSDictionary *constants = [self constants];
NSInteger welcomeMode = ((NSNumber *) constants[welcomeMessageMode]).integerValue;
[Instabug showWelcomeMessageWithMode:welcomeMode];
}

/**
* Set the user identity.
* Instabug will pre-fill the user email in reports.
*
* @param name Username.
* @param email User's default email
*/
+ (void)identifyUserWithEmail:(NSString *)email name:(NSString *) name {
if ([name isKindOfClass:[NSNull class]]) {
[Instabug identifyUserWithEmail:email name:nil];
} else {
[Instabug identifyUserWithEmail:email name:name];
}
}

/**
* Sets the default value of the user's email to null and show email field and remove user
* name from all reports
* It also reset the chats on device and removes user attributes, user data and completed
* surveys.
*/
+ (void)logOut {
[Instabug logOut];
}

/**
* Change Locale of Instabug UI elements(defaults to English)
*
* @param locale
*/
+ (void)setLocale:(NSString *)locale {
NSDictionary *constants = [self constants];
NSInteger localeInt = ((NSNumber *) constants[locale]).integerValue;
[Instabug setLocale:localeInt];
}

+ (NSDictionary *)constants {
return @{
@"InvocationEvent.shake": @(IBGInvocationEventShake),
@"InvocationEvent.screenshot": @(IBGInvocationEventScreenshot),
@"InvocationEvent.twoFingersSwipeLeft": @(IBGInvocationEventTwoFingersSwipeLeft),
@"InvocationEvent.floatingButton": @(IBGInvocationEventFloatingButton),
@"InvocationEvent.none": @(IBGInvocationEventNone),

@"WelcomeMessageMode.live": @(IBGWelcomeMessageModeLive),
@"WelcomeMessageMode.beta": @(IBGWelcomeMessageModeBeta),
@"WelcomeMessageMode.disabled": @(IBGWelcomeMessageModeDisabled),

@"Locale.Arabic": @(IBGLocaleArabic),
@"Locale.ChineseSimplified": @(IBGLocaleChineseSimplified),
@"Locale.ChineseTraditional": @(IBGLocaleChineseTraditional),
@"Locale.Czech": @(IBGLocaleCzech),
@"Locale.Danish": @(IBGLocaleDanish),
@"Locale.Dutch": @(IBGLocaleDutch),
@"Locale.English": @(IBGLocaleEnglish),
@"Locale.French": @(IBGLocaleFrench),
@"Locale.German": @(IBGLocaleGerman),
@"Locale.Italian": @(IBGLocaleItalian),
@"Locale.Japanese": @(IBGLocaleJapanese),
@"Locale.Korean": @(IBGLocaleKorean),
@"Locale.Polish": @(IBGLocalePolish),
@"Locale.PortugueseBrazil": @(IBGLocalePortugueseBrazil),
@"Locale.Russian": @(IBGLocaleRussian),
@"Locale.Spanish": @(IBGLocaleSpanish),
@"Locale.Swedish": @(IBGLocaleSwedish),
@"Locale.Turkish": @(IBGLocaleTurkish),
};
};

@end
Loading

0 comments on commit 50312bd

Please sign in to comment.