Skip to content

Commit

Permalink
Bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
zhxnlai committed Mar 6, 2019
1 parent bd48e90 commit d56dddd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
55 changes: 33 additions & 22 deletions demo/src/main/java/com/tinder/service/ChatRoomSocketIoService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

package com.tinder.service

import android.annotation.SuppressLint
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Intent
import android.os.Build
import android.os.Handler
import android.os.IBinder
import android.os.Messenger
import androidx.core.app.NotificationCompat
import androidx.lifecycle.LifecycleService
import com.tinder.R
import com.tinder.app.socketio.chatroom.api.AddUserTopic
Expand All @@ -36,6 +39,7 @@ class ChatRoomSocketIoService : LifecycleService() {
var incomingMessageCount = 0
private val messenger = Messenger(IncomingHandler())

@SuppressLint("CheckResult")
override fun onCreate() {
super.onCreate()

Expand Down Expand Up @@ -73,9 +77,11 @@ class ChatRoomSocketIoService : LifecycleService() {

val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager

val notificationChannel =
NotificationChannel(channelId, "Default", NotificationManager.IMPORTANCE_HIGH)
notificationManager.createNotificationChannel(notificationChannel)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationChannel =
NotificationChannel(channelId, "Default", NotificationManager.IMPORTANCE_HIGH)
notificationManager.createNotificationChannel(notificationChannel)
}

Timber.d("chatroom scarlet created")

Expand All @@ -94,37 +100,42 @@ class ChatRoomSocketIoService : LifecycleService() {
addUserTopic.observeSocketIoEvent()
.filter { it is SocketIoEvent.OnConnectionOpened }
.observeOn(Schedulers.io())
.subscribe({
addUserTopic.sendAddUser(username)

Timber.d("chatroom added user: $it")
val notification = createNotification {
setContentText("Joined chatroom")
}
notificationManager.notify(notificationIdCurrentState, notification)
}, { e ->
Timber.e(e)
})
.subscribe(
{
addUserTopic.sendAddUser(username)

Timber.d("chatroom added user: $it")
val notification = createNotification {
setContentText("Joined chatroom")
}
notificationManager.notify(notificationIdCurrentState, notification)
},
{ e ->
Timber.e(e)
})

Flowable.fromPublisher(AndroidLifecycle.ofLifecycleServiceStarted(application, this))
.subscribe({
.subscribe {
Timber.d("chatroom lifecycle: $it")

val notification = createNotification {
setContentText("Lifecycle State: $it")
}
notificationManager.notify(notificationIdCurrentState, notification)
})
}

Flowable.merge(
newMessageTopic.observeNewMessage().map { "${it.username}: ${it.message}" },
typingStartedTopic.observeTypingStarted().map { "${it.username} started typing" },
typingStoppedTopic.observeTypingStopped().map { "${it.username} stopped typing" }
newMessageTopic.observeNewMessage()
.map { "${it.username}: ${it.message}" },
typingStartedTopic.observeTypingStarted()
.map { "${it.username} started typing" },
typingStoppedTopic.observeTypingStopped()
.map { "${it.username} stopped typing" }
).subscribe {
Timber.d("chatroom new message: $it")

val notification = createNotification {
setContentText("$it")
setContentText(it)
}

val notificationId = notificationIdIncomingMessage + incomingMessageCount
Expand All @@ -139,8 +150,8 @@ class ChatRoomSocketIoService : LifecycleService() {
return messenger.binder
}

private fun createNotification(builder: Notification.Builder.() -> Unit): Notification {
return Notification.Builder(applicationContext, channelId)
private fun createNotification(builder: NotificationCompat.Builder.() -> Unit): Notification {
return NotificationCompat.Builder(applicationContext, channelId)
.setSmallIcon(R.drawable.ic_action_info)
.setWhen(System.currentTimeMillis())
.setContentTitle("Chat Room")
Expand Down
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

ext {
minSdkVersion = 28
minSdkVersion = 24
minSdkVersionAndroidLifecycle = 19
targetSdkVersion = 28
compileSdkVersion = 28
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

android.enableJetifier=true
android.useAndroidX=true
version=0.2.4-alpha1
version=0.2.4

0 comments on commit d56dddd

Please sign in to comment.