- * http://www.apache.org/licenses/LICENSE-2.0 - *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.sendbird.syncmanager.sample.fcm;
-
-import android.util.Log;
-import android.widget.Toast;
-
-import com.google.firebase.iid.FirebaseInstanceId;
-import com.google.firebase.iid.FirebaseInstanceIdService;
-import com.sendbird.android.SendBird;
-import com.sendbird.android.SendBirdException;
-
-
-public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
-
- private static final String TAG = "MyFirebaseIIDService";
-
- /**
- * Called if InstanceID token is updated. This may occur if the security of
- * the previous token had been compromised. Note that this is called when the InstanceID token
- * is initially generated so this is where you would retrieve the token.
- */
- // [START refresh_token]
- @Override
- public void onTokenRefresh() {
- // Get updated InstanceID token.
- String refreshedToken = FirebaseInstanceId.getInstance().getToken();
- Log.d(TAG, "Refreshed token: " + refreshedToken);
-
- // If you want to send messages to this application instance or
- // manage this apps subscriptions on the server side, send the
- // Instance ID token to your app server.
- sendRegistrationToServer(refreshedToken);
- }
- // [END refresh_token]
-
- /**
- * Persist token to third-party servers.
- *
- * Modify this method to associate the user's FCM InstanceID token with any server-side account
- * maintained by your application.
- *
- * @param token The new token.
- */
- private void sendRegistrationToServer(String token) {
- // TODO: Implement this method to send token to your app server.
- SendBird.registerPushTokenForCurrentUser(token, new SendBird.RegisterPushTokenWithStatusHandler() {
- @Override
- public void onRegistered(SendBird.PushTokenRegistrationStatus pushTokenRegistrationStatus, SendBirdException e) {
- if (e != null) {
- Toast.makeText(MyFirebaseInstanceIDService.this, "" + e.getCode() + ":" + e.getMessage(), Toast.LENGTH_SHORT).show();
- return;
- }
-
- if (pushTokenRegistrationStatus == SendBird.PushTokenRegistrationStatus.PENDING) {
- Toast.makeText(MyFirebaseInstanceIDService.this, "Connection required to register push token.", Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
-}
\ No newline at end of file
diff --git a/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/fcm/MyFirebaseMessagingService.java b/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/fcm/MyFirebaseMessagingService.java
index 5e3080cf..ff5d3160 100644
--- a/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/fcm/MyFirebaseMessagingService.java
+++ b/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/fcm/MyFirebaseMessagingService.java
@@ -29,50 +29,34 @@
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
+import android.widget.Toast;
-import com.google.firebase.messaging.FirebaseMessagingService;
-import com.google.firebase.messaging.RemoteMessage;
import com.sendbird.syncmanager.sample.R;
import com.sendbird.syncmanager.sample.groupchannel.GroupChannelActivity;
import com.sendbird.syncmanager.sample.utils.PreferenceUtils;
+import com.google.firebase.messaging.FirebaseMessagingService;
+import com.google.firebase.messaging.RemoteMessage;
+import com.sendbird.android.SendBird;
+import com.sendbird.android.SendBirdException;
import org.json.JSONException;
import org.json.JSONObject;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
- private static final String TAG = "MyFirebaseMsgService";
-
- /**
- * Called when message is received.
- *
- * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
- */
- // [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
- // [START_EXCLUDE]
- // There are two types of messages data messages and notification messages. Data messages are handled
- // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
- // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
- // is in the foreground. When the app is in the background an automatically generated notification is displayed.
- // When the user taps on the notification they are returned to the app. Messages containing both notification
- // and data payloads are treated as notification messages. The Firebase console always sends notification
- // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
- // [END_EXCLUDE]
-
- // TODO(developer): Handle FCM messages here.
- // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
- Log.d(TAG, "From: " + remoteMessage.getFrom());
+
+ Log.d("FirebaseMsgService", "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
- Log.d(TAG, "Message data payload: " + remoteMessage.getData());
+ Log.d("FirebaseMsgService", "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
- Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
+ Log.d("FirebaseMsgService", "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
String channelUrl = null;
@@ -87,18 +71,35 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
// message, here is where that should be initiated. See sendNotification method below.
sendNotification(this, remoteMessage.getData().get("message"), channelUrl);
}
- // [END receive_message]
-
- /**
- * Create and show a simple notification containing the received FCM message.
- *
- * @param messageBody FCM message body received.
- */
- public static void sendNotification(Context context, String messageBody, String channelUrl) {
+
+ @Override
+ public void onNewToken(String token) {
+ Log.d("FirebaseMsgService", "Refreshed token: " + token);
+
+ sendRegistrationToServer(token);
+ }
+
+ private void sendRegistrationToServer(String token) {
+ SendBird.registerPushTokenForCurrentUser(token, new SendBird.RegisterPushTokenWithStatusHandler() {
+ @Override
+ public void onRegistered(SendBird.PushTokenRegistrationStatus pushTokenRegistrationStatus, SendBirdException e) {
+ if (e != null) {
+ Toast.makeText(MyFirebaseMessagingService.this, "" + e.getCode() + ":" + e.getMessage(), Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ if (pushTokenRegistrationStatus == SendBird.PushTokenRegistrationStatus.PENDING) {
+ Toast.makeText(MyFirebaseMessagingService.this, R.string.register_push_token, Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+ }
+
+ private void sendNotification(Context context, String messageBody, String channelUrl) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
final String CHANNEL_ID = "CHANNEL_ID";
- if (Build.VERSION.SDK_INT >= 26) { // Build.VERSION_CODES.O
+ if (Build.VERSION.SDK_INT >= 26) {
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, "CHANNEL_NAME", NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(mChannel);
}
@@ -106,13 +107,13 @@ public static void sendNotification(Context context, String messageBody, String
Intent intent = new Intent(context, GroupChannelActivity.class);
intent.putExtra("groupChannelUrl", channelUrl);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 /* Request code */, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.img_notification)
- .setColor(Color.parseColor("#7469C4")) // small icon background color
- .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.img_notification_large))
+ .setColor(Color.parseColor("#4c679c"))
+ .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher_round))
.setContentTitle(context.getResources().getString(R.string.app_name))
.setAutoCancel(true)
.setSound(defaultSoundUri)
@@ -123,9 +124,9 @@ public static void sendNotification(Context context, String messageBody, String
if (PreferenceUtils.getNotificationsShowPreviews()) {
notificationBuilder.setContentText(messageBody);
} else {
- notificationBuilder.setContentText("Somebody sent you a message.");
+ notificationBuilder.setContentText(getResources().getString(R.string.message_received));
}
- notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
+ notificationManager.notify(0, notificationBuilder.build());
}
}
\ No newline at end of file
diff --git a/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/groupchannel/GroupChannelListAdapter.java b/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/groupchannel/GroupChannelListAdapter.java
index 9022447d..22b4ac5b 100644
--- a/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/groupchannel/GroupChannelListAdapter.java
+++ b/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/groupchannel/GroupChannelListAdapter.java
@@ -280,7 +280,7 @@ void bind(final Context context, int position, final GroupChannel channel,
// If someone in the channel is typing, display the typing indicator.
if (channel.isTyping()) {
typingIndicatorContainer.setVisibility(View.VISIBLE);
- lastMessageText.setText(("Someone is typing"));
+ lastMessageText.setText(R.string.typing_indicator);
} else {
// Display typing indicator only when someone is typing
typingIndicatorContainer.setVisibility(View.GONE);
diff --git a/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/groupchannel/GroupChannelListFragment.java b/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/groupchannel/GroupChannelListFragment.java
index 2ff11879..c219abab 100644
--- a/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/groupchannel/GroupChannelListFragment.java
+++ b/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/groupchannel/GroupChannelListFragment.java
@@ -238,25 +238,27 @@ private void showChannelOptionsDialog(final GroupChannel channel) {
final boolean pushCurrentlyEnabled = channel.isPushEnabled();
options = pushCurrentlyEnabled
- ? new String[]{"Leave channel", "Turn push notifications OFF"}
- : new String[]{"Leave channel", "Turn push notifications ON"};
+ ? new String[]{getResources().getString(R.string.leave_channel),
+ getResources().getString(R.string.set_notification_off)}
+ : new String[]{getResources().getString(R.string.leave_channel),
+ getResources().getString(R.string.set_notification_on)};
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- builder.setTitle("Channel options")
+ builder.setTitle(R.string.channel_options)
.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
// Show a dialog to confirm that the user wants to leave the channel.
new AlertDialog.Builder(getActivity())
- .setTitle("Leave channel " + channel.getName() + "?")
- .setPositiveButton("Leave", new DialogInterface.OnClickListener() {
+ .setTitle(String.format(getResources().getString(R.string.leave_channel_question) + " ", channel.getName()))
+ .setPositiveButton(R.string.all_leave, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
leaveChannel(channel);
}
})
- .setNegativeButton("Cancel", null)
+ .setNegativeButton(R.string.cancel, null)
.create().show();
} else if (which == 1) {
setChannelPushPreferences(channel, !pushCurrentlyEnabled);
@@ -278,14 +280,15 @@ private void setChannelPushPreferences(final GroupChannel channel, final boolean
public void onResult(SendBirdException e) {
if (e != null) {
e.printStackTrace();
- Toast.makeText(getActivity(), "Error: " + e.getMessage(), Toast.LENGTH_SHORT)
+ Toast.makeText(getActivity(), getResources().getString(R.string.error)+ " " +
+ e.getMessage(), Toast.LENGTH_SHORT)
.show();
return;
}
- String toast = on
- ? "Push notifications have been turned ON"
- : "Push notifications have been turned OFF";
+ int toast = on
+ ? R.string.notification_on
+ : R.string.notification_off;
Toast.makeText(getActivity(), toast, Toast.LENGTH_SHORT)
.show();
diff --git a/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/groupchannel/GroupChatFragment.java b/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/groupchannel/GroupChatFragment.java
index 2ee0234e..a4b12eb5 100644
--- a/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/groupchannel/GroupChatFragment.java
+++ b/syncmanager/app/src/main/java/com/sendbird/syncmanager/sample/groupchannel/GroupChatFragment.java
@@ -466,9 +466,10 @@ private void showMessageOptionsDialog(final BaseMessage message, final int posit
String[] options;
if (message.getMessageId() == 0) {
- options = new String[] { "Delete message" };
+ options = new String[] { getResources().getString(R.string.delete_message) };
} else {
- options = new String[] { "Edit message", "Delete message" };
+ options = new String[] { getResources().getString(R.string.edit_message),
+ getResources().getString(R.string.delete_message) };
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
@@ -558,7 +559,7 @@ public void run() {
fetchInitialMessages();
}
} else {
- Toast.makeText(getContext(), "Failed to get channel.", Toast.LENGTH_SHORT).show();
+ Toast.makeText(getContext(), R.string.get_channel_failed, Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
@@ -663,7 +664,7 @@ public void onSent(UserMessage userMessage, SendBirdException e) {
}
}
})
- .setNegativeButton(R.string.delete_message, new DialogInterface.OnClickListener() {
+ .setNegativeButton(R.string.delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_NEGATIVE) {
@@ -690,11 +691,12 @@ private void displayTyping(List