Skip to content

Commit aabe6de

Browse files
author
Julian Kast
committed
Added unsubscribeButtonRequest method and fixed spacing
1 parent dbaf996 commit aabe6de

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

base/src/main/java/com/smartdevicelink/managers/screen/BaseSubscribeButtonManager.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public void dispose() {
6161
* @param listener - Is the listener that was sent by developer
6262
*/
6363
void addButtonListener(ButtonName buttonName, OnButtonListener listener) {
64-
6564
if (listener == null) {
6665
Log.e(TAG, "OnButtonListener cannot be null");
6766
return;
@@ -90,7 +89,6 @@ void addButtonListener(ButtonName buttonName, OnButtonListener listener) {
9089
* @param listener - the listener that was sent by developer
9190
*/
9291
void removeButtonListener(final ButtonName buttonName, final OnButtonListener listener) {
93-
9492
if (listener == null) {
9593
Log.e(TAG, "OnButtonListener cannot be null: ");
9694
return;
@@ -110,7 +108,16 @@ void removeButtonListener(final ButtonName buttonName, final OnButtonListener li
110108
onButtonListeners.get(buttonName).remove(listener);
111109
return;
112110
}
111+
unsubscribeButtonRequest(buttonName, listener);
112+
}
113113

114+
/**
115+
* Send the UnsubscribeButton RPC
116+
*
117+
* @param buttonName - ButtonName - name of button
118+
* @param listener - OnButtonListener - listener to get notified
119+
*/
120+
private void unsubscribeButtonRequest(final ButtonName buttonName, final OnButtonListener listener) {
114121
UnsubscribeButton unsubscribeButtonRequest = new UnsubscribeButton(buttonName);
115122
unsubscribeButtonRequest.setOnRPCResponseListener(new OnRPCResponseListener() {
116123
@Override
@@ -123,7 +130,6 @@ public void onError(int correlationId, Result resultCode, String info) {
123130
listener.onError("Attempt to unsubscribe to button named " + buttonName + " Failed. ResultCode: " + resultCode + " info: " + info);
124131
}
125132
});
126-
127133
internalInterface.sendRPC(unsubscribeButtonRequest);
128134
}
129135

@@ -135,9 +141,7 @@ public void onError(int correlationId, Result resultCode, String info) {
135141
*/
136142
private void subscribeButtonRequest(final ButtonName buttonName, final OnButtonListener listener) {
137143
SubscribeButton subscribeButtonRequest = new SubscribeButton(buttonName);
138-
139144
subscribeButtonRequest.setOnRPCResponseListener(new OnRPCResponseListener() {
140-
141145
@Override
142146
public void onResponse(int correlationId, RPCResponse response) {
143147
onButtonListeners.put(buttonName, new CopyOnWriteArrayList<OnButtonListener>());
@@ -149,7 +153,6 @@ public void onError(int correlationId, Result resultCode, String info) {
149153
listener.onError("Attempt to subscribe to button named " + buttonName + " Failed . ResultCode: " + resultCode + " info: " + info);
150154
}
151155
});
152-
153156
internalInterface.sendRPC(subscribeButtonRequest);
154157
}
155158

@@ -162,7 +165,6 @@ private void setRpcNotificationListeners() {
162165
public void onNotified(RPCNotification notification) {
163166
OnButtonPress onButtonPressNotification = (OnButtonPress) notification;
164167
CopyOnWriteArrayList<OnButtonListener> listeners = onButtonListeners.get(onButtonPressNotification.getButtonName());
165-
166168
if (listeners != null && listeners.size() > 0) {
167169
for (OnButtonListener listener : listeners) {
168170
listener.onPress(onButtonPressNotification.getButtonName(), onButtonPressNotification);

0 commit comments

Comments
 (0)