Skip to content

Instantly share code, notes, and snippets.

@deniszink
Created March 21, 2017 14:10
Show Gist options
  • Save deniszink/5d5651494e064b7ccddb5102126a1ec1 to your computer and use it in GitHub Desktop.
Save deniszink/5d5651494e064b7ccddb5102126a1ec1 to your computer and use it in GitHub Desktop.
package com.wellaapp.presentation.quickblox.chat.callback
import android.support.design.widget.Snackbar
import android.util.Log
import android.view.View
import org.jivesoftware.smack.ConnectionListener
import org.jivesoftware.smack.XMPPConnection
open class VerboseQbChatConnectionListener(private val rootView: View) : ConnectionListener {
private var snackbar: Snackbar? = null
override fun connected(connection: XMPPConnection) {
Log.i(TAG, "connected()")
}
override fun authenticated(connection: XMPPConnection, authenticated: Boolean) {
Log.i(TAG, "authenticated()")
}
override fun connectionClosed() {
Log.i(TAG, "connectionClosed()")
}
override fun connectionClosedOnError(e: Exception) {
Log.i(TAG, "connectionClosedOnError(): " + e.message)
snackbar = Snackbar.make(rootView, "Chat connection has been dropped" , Snackbar.LENGTH_INDEFINITE)
snackbar?.show()
}
override fun reconnectingIn(seconds: Int) {
if (seconds % 5 == 0 && seconds != 0) {
Log.i(TAG, "reconnectingIn(): " + seconds)
snackbar = Snackbar.make(rootView,"Reconnecting in $seconds seconds", Snackbar.LENGTH_INDEFINITE)
snackbar!!.show()
}
}
override fun reconnectionSuccessful() {
Log.i(TAG, "reconnectionSuccessful()")
snackbar?.dismiss()
}
override fun reconnectionFailed(error: Exception) {
Log.i(TAG, "reconnectionFailed(): " + error.message)
}
companion object {
private val TAG = VerboseQbChatConnectionListener::class.java.simpleName
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment