Comments (4)
Update on this:
Had to subclass ConversationActivity
, and set that as a delegate:
public class SupportActivity extends ConversationActivity {
@Override
public boolean shouldTriggerAction(MessageAction messageAction) {
if (messageAction.getUri().startsWith("special:")) {
//Do something special
return true;
} else {
return super.shouldTriggerAction(messageAction);
}
}
}
Smooch.getConversation().setDelegate(new SupportActivity());
This seems to do the trick, but I am not sure if it would break something internally. It is also an awful hack (you know, for the whole new SupportActivity()
thing). Any ideas?
from sunshine-conversations-android.
Hey Anas!
Since I am not interested in all the other methods, there is no way for me to use this without breaking the rest of the functionality.
I'm not sure what you mean here, can you clarify? Overriding the delegate object with empty implementations (for the void methods at least) shouldn't break any functionality.
from sunshine-conversations-android.
Hey Andrew,
So yeah, reading through it again, I definitely wasn't clear enough.
Here is my understanding of how Smooch initialization works:
1- When init
is called, a new "SmoochManager" is created. This manager takes care of launching the service, listens to the Application lifecycle, and does all the bookkeeping for the queue system. (Note that "SmoochManager" might not be the name of the actual class internally; this is just a name I made up, since the code is obfuscated).
2- This manager takes care of creating the Conversation
object.
3- Finally, ConversationActivity
implements the Delegate
interface. This suggests that it is the ConversationActivity
that is used as delegate at some point. (This is my assumption).
4- Based on the previous assumption, then, at some point, between init
and ConversationActivity.show()
are called, ConversationActivity
must be set as the Delegate
.
Now, to the problem:
- I can't seem to find at which point
ConversationActivity
(or any other object) becomes theDelegate
. The natural place would be inside theonCreate
ofConversationActivity
, but there is nothing there. - I haven't been able to find any other class that implements
Delegate
other thanConversationActivity
. - My understanding is that
Conversation
has a single reference to itsDelegate
. Thus, when providing a new object asDelegate
(throughSmooch.getConversation().setDelegate()
), it is the delegate that was set last that gets called back. (As opposed to, say, listeners, where you can have plenty of them).
Now, say I wanted to change the behaviour of Smooch when a MessageAction
is received I would have to set the delegate myself, after my init
:
Smooch.init(this, "TOKEN");
Smooch.getConversation().setDelegate(new Conversation.Delegate() {
@Override
public void onMessagesReceived(Conversation conversation, List<Message> list) { }
@Override
public void onUnreadCountChanged(Conversation conversation, int i) { }
@Override
public void onMessageSent(Message message, MessageUploadStatus messageUploadStatus) { }
@Override
public void onInitializationStatusChanged(InitializationStatus initializationStatus) { }
@Override
public void onPaymentProcessed(MessageAction messageAction, PaymentStatus paymentStatus) { }
@Override
public boolean shouldTriggerAction(MessageAction messageAction) {
if(messageAction.getUri().startsWith("special:") {
return false;
} else {
//Call super to handle the other cases
}
}
@Override
public void onCardSummaryLoaded(CardSummary cardSummary) { }
@Override
public void onSmoochShown() { }
@Override
public void onSmoochHidden() { }
});
Now, as you can see, there is no way for me to use the super
implementation of delegate. Basically, ConversationActivity
's implementation of Delegate
is not called here. This is bad, because ConversationActivity
is probably doing very important stuff in all these methods. This was the gist of what I put on that first comment.
The only alternative is to subclass ConversationActivity
, and override only the behaviour that I want to change (thus, my SupportActivity
). Passing this as the delegate requires doing this:
Smooch.getConversation().setDelegate(new SupportActivity());
which, to me, feels wrong, because:
- You are not supposed to call
new
on an Activity object - What happens if
setDelegate
is called some time later? (I don't know when that is done, so I don't have any way to confirm) - This feels very iOS-y, with an Activity implementing a
protocol
.
I feel that I have been reading way too much into all of this, and that the solution is probably simpler. Plus, the code works, so I hope you are able to see where my confusion is stemming from.
Also, thanks for taking a look into this, I know you guys must be super busy.
from sunshine-conversations-android.
Hey Anas, sorry it's taken us so long to get back to you.
The ConversationActivity
does in fact implement the delegate, but it is a separate delegate from the one you will be overriding by calling setDelegate()
.
For our ConversationActivity
, we are using the method setSmoochUiDelegate()
and it is being called in the activity's onPause
.
As long as you stick to using setDelegate()
, you will not run into any problems :)
from sunshine-conversations-android.
Related Issues (20)
- Latest Firebase HOT 6
- Duplicate class a.a found in modules core-9.0.0-runtime.jar HOT 1
- Android 12 support HOT 3
- Not finding 9.0.0 on jcenter? HOT 3
- Override Drawable Tint Color for Button HOT 1
- Logout CallBack ignored when Smooch not Initialized yet HOT 1
- latest firebase
- Crash by java.util.ConcurrentModificationException HOT 2
- App crash when i click `Share Localtion` HOT 1
- Region is not taken into account when requesting config
- Crash on MessageListAdapter HOT 10
- Problems with old versions of Smooch and not finding new 9.1.1 on building with gradle
- External Id Incorrectly Cached After Un-Successful Login Attempt.
- Crash NullPointerException Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference HOT 1
- io.smooch.ui.fragment.ConversationFragment.onCreateView
- io.smooch.ui.fragment.ConversationFragment.onCreateView does anybody know what is the problem?
- Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{....app/io.smooch.ui.widget.ImageActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.BaseBundle.getString(java.lang.String)' on a null object reference
- Crash when sharing location. Upgrade play-service-location dependency
- Logo toolbar default does not set using the logo in smooch dashboard (same as iOS SDK)
- App crashes - java.util.ConcurrentModificationException
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sunshine-conversations-android.