11package io .verloop .sdk ;
22
3+ import android .content .BroadcastReceiver ;
34import android .content .Context ;
45import android .content .Intent ;
6+ import android .content .IntentFilter ;
57import android .content .SharedPreferences ;
6- import android .os .Build ;
8+ import android .net .ConnectivityManager ;
9+ import android .support .v4 .content .LocalBroadcastManager ;
710import android .util .Log ;
811
912import java .util .UUID ;
@@ -37,12 +40,12 @@ public class Verloop {
3740 private String clientId ;
3841 private String fcmToken ;
3942 private boolean isStaging ;
43+ private LiveChatButtonClickListener buttonOnClickListener ;
44+
4045
4146 /**
42- *
43- *
4447 * @param context Context of an activity/service.
45- * @param config The <code>VerloopConfig</code> object for the current user.
48+ * @param config The <code>VerloopConfig</code> object for the current user.
4649 */
4750 public Verloop (Context context , VerloopConfig config ) {
4851 this .context = context ;
@@ -51,30 +54,29 @@ public Verloop(Context context, VerloopConfig config) {
5154 this .clientId = config .getClientId ();
5255 this .fcmToken = config .getFcmToken ();
5356 this .isStaging = config .getStaging ();
57+ this .buttonOnClickListener = config .getButtonOnClickListener ();
5458
5559 config .save (getPreferences ());
5660
5761 this .startService ();
5862 }
5963
6064 /**
65+ * @param userId User ID of the user you want to log in the app.
6166 * @deprecated Use {@link #login(VerloopConfig)} instead.
62- *
67+ * <p>
6368 * Login a different user than the one that this object was initialized with.
64- *
65- * @param userId User ID of the user you want to log in the app.
6669 */
6770 public void login (String userId ) {
6871 login (userId , null );
6972 }
7073
7174 /**
75+ * @param userId User ID of the user you want to log in the app.
76+ * @param fcmToken FCM Token of the user being logged in.
7277 * @deprecated Use {@link #login(VerloopConfig)} instead.
73- *
78+ * <p>
7479 * Login a different user than the one that this object was initialized with.
75- *
76- * @param userId User ID of the user you want to log in the app.
77- * @param fcmToken FCM Token of the user being logged in.
7880 */
7981 public void login (String userId , String fcmToken ) {
8082 stopService ();
@@ -129,6 +131,24 @@ public void showChat() {
129131
130132 Intent i = new Intent (context , VerloopActivity .class );
131133 context .startActivity (i );
134+
135+ if (buttonOnClickListener != null ){
136+ IntentFilter filter = new IntentFilter (ConnectivityManager .CONNECTIVITY_ACTION );
137+ filter .addAction (context .getPackageName () + ".BUTTON_CLICK_LISTENER_VERLOOP_INTERFACE" );
138+ LocalBroadcastManager .getInstance (context ).registerReceiver (new BroadcastReceiver () {
139+ @ Override
140+ public void onReceive (Context context , Intent intent ) {
141+
142+ String title = intent .getStringExtra (VerloopInterface .BUTTON_TITLE );
143+ String type = intent .getStringExtra (VerloopInterface .BUTTON_TYPE );
144+ String payload = intent .getStringExtra (VerloopInterface .BUTTON_PAYLOAD );
145+
146+ Log .d (TAG , "Button click event received Title: " + title + " Type: " + type + " Payload " + payload );
147+
148+ buttonOnClickListener .buttonClicked (title , type , payload );
149+ }
150+ }, filter );
151+ }
132152 }
133153
134154 private String retrieveUserId (VerloopConfig config ) {
0 commit comments