Implement changes required by new Kotlin codebase
This commit is contained in:
@@ -49,7 +49,7 @@ internal object ClientFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun userApiWithToken(settings: Settings): UserApi? {
|
fun userApiWithToken(settings: Settings): UserApi? {
|
||||||
return clientToken(settings.url(), settings.sslSettings(), settings.token())
|
return clientToken(settings.url, settings.sslSettings(), settings.token)
|
||||||
.createService(UserApi::class.java)
|
.createService(UserApi::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,16 +59,18 @@ class InitializationActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private fun tryAuthenticate() {
|
private fun tryAuthenticate() {
|
||||||
ClientFactory.userApiWithToken(settings)
|
ClientFactory.userApiWithToken(settings)
|
||||||
.currentUser()
|
?.currentUser()
|
||||||
.enqueue(Callback.callInUI(this, { authenticated(it) }) { apiException ->
|
?.enqueue(
|
||||||
failed(apiException)
|
Callback.callInUI(this, { if (it != null) authenticated(it) }) { apiException ->
|
||||||
})
|
failed(apiException)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun failed(exception: ApiException) {
|
private fun failed(exception: ApiException) {
|
||||||
when (exception.code()) {
|
when (exception.code) {
|
||||||
0 -> {
|
0 -> {
|
||||||
dialog(getString(R.string.not_available, settings.url()))
|
dialog(getString(R.string.not_available, settings.url))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
401 -> {
|
401 -> {
|
||||||
@@ -77,9 +79,9 @@ class InitializationActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = exception.body()
|
var response = exception.body
|
||||||
response = response.substring(0, 200.coerceAtMost(response.length))
|
response = response.substring(0, 200.coerceAtMost(response.length))
|
||||||
dialog(getString(R.string.other_error, settings.url(), exception.code(), response))
|
dialog(getString(R.string.other_error, settings.url, exception.code, response))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun dialog(message: String) {
|
private fun dialog(message: String) {
|
||||||
@@ -94,7 +96,7 @@ class InitializationActivity : AppCompatActivity() {
|
|||||||
private fun authenticated(user: User) {
|
private fun authenticated(user: User) {
|
||||||
Log.i("Authenticated as ${user.name}")
|
Log.i("Authenticated as ${user.name}")
|
||||||
|
|
||||||
settings.user(user.name, user.isAdmin)
|
settings.setUser(user.name, user.isAdmin)
|
||||||
requestVersion {
|
requestVersion {
|
||||||
startActivity(Intent(this, MessagesActivity::class.java))
|
startActivity(Intent(this, MessagesActivity::class.java))
|
||||||
finish()
|
finish()
|
||||||
@@ -108,9 +110,11 @@ class InitializationActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun requestVersion(runnable: Runnable) {
|
private fun requestVersion(runnable: Runnable) {
|
||||||
requestVersion({ version: VersionInfo ->
|
requestVersion({ version: VersionInfo? ->
|
||||||
Log.i("Server version: ${version.version}@${version.buildDate}")
|
if (version != null) {
|
||||||
settings.serverVersion(version.version)
|
Log.i("Server version: ${version.version}@${version.buildDate}")
|
||||||
|
settings.serverVersion = version.version
|
||||||
|
}
|
||||||
runnable.run()
|
runnable.run()
|
||||||
}) { runnable.run() }
|
}) { runnable.run() }
|
||||||
}
|
}
|
||||||
@@ -119,8 +123,8 @@ class InitializationActivity : AppCompatActivity() {
|
|||||||
callback: SuccessCallback<VersionInfo>,
|
callback: SuccessCallback<VersionInfo>,
|
||||||
errorCallback: Callback.ErrorCallback
|
errorCallback: Callback.ErrorCallback
|
||||||
) {
|
) {
|
||||||
ClientFactory.versionApi(settings.url(), settings.sslSettings())
|
ClientFactory.versionApi(settings.url, settings.sslSettings())
|
||||||
.version
|
?.version
|
||||||
.enqueue(Callback.callInUI(this, callback, errorCallback))
|
?.enqueue(Callback.callInUI(this, callback, errorCallback))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,8 +104,8 @@ class LoginActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
ClientFactory.versionApi(fixedUrl, tempSslSettings())
|
ClientFactory.versionApi(fixedUrl, tempSslSettings())
|
||||||
.version
|
?.version
|
||||||
.enqueue(Callback.callInUI(this, onValidUrl(fixedUrl), onInvalidUrl(fixedUrl)))
|
?.enqueue(Callback.callInUI(this, onValidUrl(fixedUrl), onInvalidUrl(fixedUrl)))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
binding.checkurlProgress.visibility = View.GONE
|
binding.checkurlProgress.visibility = View.GONE
|
||||||
binding.checkurl.visibility = View.VISIBLE
|
binding.checkurl.visibility = View.VISIBLE
|
||||||
@@ -196,10 +196,10 @@ class LoginActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private fun onValidUrl(url: String): SuccessCallback<VersionInfo> {
|
private fun onValidUrl(url: String): SuccessCallback<VersionInfo> {
|
||||||
return SuccessCallback { version ->
|
return SuccessCallback { version ->
|
||||||
settings.url(url)
|
settings.url = url
|
||||||
binding.checkurlProgress.visibility = View.GONE
|
binding.checkurlProgress.visibility = View.GONE
|
||||||
binding.checkurl.visibility = View.VISIBLE
|
binding.checkurl.visibility = View.VISIBLE
|
||||||
binding.checkurl.text = getString(R.string.found_gotify_version, version.version)
|
binding.checkurl.text = getString(R.string.found_gotify_version, version?.version)
|
||||||
binding.username.visibility = View.VISIBLE
|
binding.username.visibility = View.VISIBLE
|
||||||
binding.username.requestFocus()
|
binding.username.requestFocus()
|
||||||
binding.password.visibility = View.VISIBLE
|
binding.password.visibility = View.VISIBLE
|
||||||
@@ -222,7 +222,7 @@ class LoginActivity : AppCompatActivity() {
|
|||||||
binding.login.visibility = View.GONE
|
binding.login.visibility = View.GONE
|
||||||
binding.loginProgress.visibility = View.VISIBLE
|
binding.loginProgress.visibility = View.VISIBLE
|
||||||
|
|
||||||
val client = ClientFactory.basicAuth(settings.url(), tempSslSettings(), username, password)
|
val client = ClientFactory.basicAuth(settings.url, tempSslSettings(), username, password)
|
||||||
client.createService(UserApi::class.java)
|
client.createService(UserApi::class.java)
|
||||||
.currentUser()
|
.currentUser()
|
||||||
.enqueue(Callback.callInUI(this, { newClientDialog(client) }) {
|
.enqueue(Callback.callInUI(this, { newClientDialog(client) }) {
|
||||||
@@ -256,16 +256,16 @@ class LoginActivity : AppCompatActivity() {
|
|||||||
val newClient = Client().name(nameProvider.text.toString())
|
val newClient = Client().name(nameProvider.text.toString())
|
||||||
client.createService(ClientApi::class.java)
|
client.createService(ClientApi::class.java)
|
||||||
.createClient(newClient)
|
.createClient(newClient)
|
||||||
.enqueue(Callback.callInUI(this, { onCreatedClient(it) }) {
|
.enqueue(Callback.callInUI(this, { if (it != null) onCreatedClient(it) }) {
|
||||||
onFailedToCreateClient()
|
onFailedToCreateClient()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onCreatedClient(client: Client) {
|
private fun onCreatedClient(client: Client) {
|
||||||
settings.token(client.token)
|
settings.token = client.token
|
||||||
settings.validateSSL(!disableSslValidation)
|
settings.validateSSL = !disableSslValidation
|
||||||
settings.cert(caCertContents)
|
settings.cert = caCertContents.toString()
|
||||||
|
|
||||||
Utils.showSnackBar(this, getString(R.string.created_client))
|
Utils.showSnackBar(this, getString(R.string.created_client))
|
||||||
startActivity(Intent(this, InitializationActivity::class.java))
|
startActivity(Intent(this, InitializationActivity::class.java))
|
||||||
@@ -284,10 +284,10 @@ class LoginActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun versionError(url: String, exception: ApiException): String {
|
private fun versionError(url: String, exception: ApiException): String {
|
||||||
return getString(R.string.version_failed_status_code, "$url/version", exception.code())
|
return getString(R.string.version_failed_status_code, "$url/version", exception.code)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tempSslSettings(): SSLSettings {
|
private fun tempSslSettings(): SSLSettings {
|
||||||
return SSLSettings(!disableSslValidation, caCertContents)
|
return SSLSettings(!disableSslValidation, caCertContents.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class ListMessageAdapter(
|
|||||||
holder.message!!.text = message.message.message
|
holder.message!!.text = message.message.message
|
||||||
}
|
}
|
||||||
holder.title!!.text = message.message.title
|
holder.title!!.text = message.message.title
|
||||||
picasso.load(Utils.resolveAbsoluteUrl("${settings.url()}/", message.image))
|
picasso.load(Utils.resolveAbsoluteUrl("${settings.url}/", message.image))
|
||||||
.error(R.drawable.ic_alarm)
|
.error(R.drawable.ic_alarm)
|
||||||
.placeholder(R.drawable.ic_placeholder)
|
.placeholder(R.drawable.ic_placeholder)
|
||||||
.into(holder.image)
|
.into(holder.image)
|
||||||
@@ -144,7 +144,7 @@ class ListMessageAdapter(
|
|||||||
if (dateTime != null) {
|
if (dateTime != null) {
|
||||||
text = if (relativeTimeFormat) {
|
text = if (relativeTimeFormat) {
|
||||||
// Relative time format
|
// Relative time format
|
||||||
Utils.dateToRelative(dateTime)
|
Utils.dateToRelative(dateTime!!)
|
||||||
} else {
|
} else {
|
||||||
// Absolute time format
|
// Absolute time format
|
||||||
val time = dateTime!!.toInstant().toEpochMilli()
|
val time = dateTime!!.toInstant().toEpochMilli()
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ class MessagesActivity : AppCompatActivity(), NavigationView.OnNavigationItemSel
|
|||||||
.get()
|
.get()
|
||||||
.load(
|
.load(
|
||||||
Utils.resolveAbsoluteUrl(
|
Utils.resolveAbsoluteUrl(
|
||||||
viewModel.settings.url() + "/", app.image
|
viewModel.settings.url + "/", app.image
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.error(R.drawable.ic_alarm)
|
.error(R.drawable.ic_alarm)
|
||||||
@@ -223,12 +223,12 @@ class MessagesActivity : AppCompatActivity(), NavigationView.OnNavigationItemSel
|
|||||||
val headerView: View = binding.navView.getHeaderView(0)
|
val headerView: View = binding.navView.getHeaderView(0)
|
||||||
val settings = viewModel.settings
|
val settings = viewModel.settings
|
||||||
val user = headerView.findViewById<TextView>(R.id.header_user)
|
val user = headerView.findViewById<TextView>(R.id.header_user)
|
||||||
user.text = settings.user().name
|
user.text = settings.user?.name
|
||||||
val connection = headerView.findViewById<TextView>(R.id.header_connection)
|
val connection = headerView.findViewById<TextView>(R.id.header_connection)
|
||||||
connection.text = getString(R.string.connection, settings.user().name, settings.url())
|
connection.text = getString(R.string.connection, settings.user?.name, settings.url)
|
||||||
val version = headerView.findViewById<TextView>(R.id.header_version)
|
val version = headerView.findViewById<TextView>(R.id.header_version)
|
||||||
version.text =
|
version.text =
|
||||||
getString(R.string.versions, BuildConfig.VERSION_NAME, settings.serverVersion())
|
getString(R.string.versions, BuildConfig.VERSION_NAME, settings.serverVersion)
|
||||||
val refreshAll = headerView.findViewById<ImageButton>(R.id.refresh_all)
|
val refreshAll = headerView.findViewById<ImageButton>(R.id.refresh_all)
|
||||||
refreshAll.setOnClickListener { view: View? ->
|
refreshAll.setOnClickListener { view: View? ->
|
||||||
onRefreshAll(
|
onRefreshAll(
|
||||||
@@ -480,7 +480,7 @@ class MessagesActivity : AppCompatActivity(), NavigationView.OnNavigationItemSel
|
|||||||
|
|
||||||
private inner class UpdateMissedMessages : AsyncTask<Long?, Void?, Boolean>() {
|
private inner class UpdateMissedMessages : AsyncTask<Long?, Void?, Boolean>() {
|
||||||
override fun doInBackground(vararg ids: Long?): Boolean {
|
override fun doInBackground(vararg ids: Long?): Boolean {
|
||||||
val id = Utils.first<Long>(ids)
|
val id = ids.first()!!
|
||||||
if (id == -1L) {
|
if (id == -1L) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -488,8 +488,7 @@ class MessagesActivity : AppCompatActivity(), NavigationView.OnNavigationItemSel
|
|||||||
viewModel.client.createService(
|
viewModel.client.createService(
|
||||||
MessageApi::class.java
|
MessageApi::class.java
|
||||||
)
|
)
|
||||||
)
|
).missingMessages(id).filterNotNull()
|
||||||
.missingMessages(id)
|
|
||||||
viewModel.messages.addMessages(newMessages)
|
viewModel.messages.addMessages(newMessages)
|
||||||
return newMessages.isNotEmpty()
|
return newMessages.isNotEmpty()
|
||||||
}
|
}
|
||||||
@@ -528,7 +527,7 @@ class MessagesActivity : AppCompatActivity(), NavigationView.OnNavigationItemSel
|
|||||||
private fun deleteApp(appId: Long) {
|
private fun deleteApp(appId: Long) {
|
||||||
val settings = viewModel.settings
|
val settings = viewModel.settings
|
||||||
val client =
|
val client =
|
||||||
ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token())
|
ClientFactory.clientToken(settings.url, settings.sslSettings(), settings.token)
|
||||||
client.createService(ApplicationApi::class.java)
|
client.createService(ApplicationApi::class.java)
|
||||||
.deleteApp(appId)
|
.deleteApp(appId)
|
||||||
.enqueue(
|
.enqueue(
|
||||||
@@ -561,7 +560,7 @@ class MessagesActivity : AppCompatActivity(), NavigationView.OnNavigationItemSel
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun doInBackground(vararg appIds: Long?): Long {
|
override fun doInBackground(vararg appIds: Long?): Long {
|
||||||
val appId = Utils.first<Long>(appIds)
|
val appId = appIds.first()!!
|
||||||
viewModel.messages.loadMoreIfNotPresent(appId)
|
viewModel.messages.loadMoreIfNotPresent(appId)
|
||||||
return appId
|
return appId
|
||||||
}
|
}
|
||||||
@@ -610,20 +609,19 @@ class MessagesActivity : AppCompatActivity(), NavigationView.OnNavigationItemSel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class DeleteClientAndNavigateToLogin :
|
private inner class DeleteClientAndNavigateToLogin : AsyncTask<Void?, Void?, Void?>() {
|
||||||
AsyncTask<Void?, Void?, Void?>() {
|
|
||||||
override fun doInBackground(vararg ignore: Void?): Void? {
|
override fun doInBackground(vararg ignore: Void?): Void? {
|
||||||
val settings = viewModel.settings
|
val settings = viewModel.settings
|
||||||
val api = ClientFactory.clientToken(
|
val api = ClientFactory.clientToken(
|
||||||
settings.url(), settings.sslSettings(), settings.token()
|
settings.url, settings.sslSettings(), settings.token
|
||||||
)
|
)
|
||||||
.createService(ClientApi::class.java)
|
.createService(ClientApi::class.java)
|
||||||
stopService(Intent(this@MessagesActivity, WebSocketService::class.java))
|
stopService(Intent(this@MessagesActivity, WebSocketService::class.java))
|
||||||
try {
|
try {
|
||||||
val clients = Api.execute(api.clients)
|
val clients = Api.execute(api.clients) ?: emptyList()
|
||||||
var currentClient: Client? = null
|
var currentClient: Client? = null
|
||||||
for (client in clients) {
|
for (client in clients) {
|
||||||
if (client.token == settings.token()) {
|
if (client.token == settings.token) {
|
||||||
currentClient = client
|
currentClient = client
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class MessagesModel(parentView: Activity) : ViewModel() {
|
|||||||
init {
|
init {
|
||||||
settings = Settings(parentView)
|
settings = Settings(parentView)
|
||||||
picassoHandler = PicassoHandler(parentView, settings)
|
picassoHandler = PicassoHandler(parentView, settings)
|
||||||
client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token())
|
client = ClientFactory.clientToken(settings.url, settings.sslSettings(), settings.token)
|
||||||
appsHolder = ApplicationHolder(parentView, client)
|
appsHolder = ApplicationHolder(parentView, client)
|
||||||
messages = MessageFacade(client.createService(MessageApi::class.java), appsHolder)
|
messages = MessageFacade(client.createService(MessageApi::class.java), appsHolder)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,8 @@ class ApplicationHolder(private val activity: Activity, private val client: ApiC
|
|||||||
.enqueue(
|
.enqueue(
|
||||||
Callback.callInUI(
|
Callback.callInUI(
|
||||||
activity,
|
activity,
|
||||||
{ apps: List<Application> ->
|
{ apps: List<Application>? ->
|
||||||
onReceiveApps(
|
if (apps != null) onReceiveApps(apps)
|
||||||
apps
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
) { e: ApiException -> onFailedApps(e) })
|
) { e: ApiException -> onFailedApps(e) })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class PicassoHandler(private val context: Context, private val settings: Setting
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
fun getImageFromUrl(url: String): Bitmap {
|
fun getImageFromUrl(url: String?): Bitmap {
|
||||||
return picasso.load(url).get()
|
return picasso.load(url).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ class PicassoHandler(private val context: Context, private val settings: Setting
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return getImageFromUrl(
|
return getImageFromUrl(
|
||||||
Utils.resolveAbsoluteUrl("${settings.url()}/", appIdToAppImage[appId])
|
Utils.resolveAbsoluteUrl("${settings.url}/", appIdToAppImage[appId])
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Log.e("Could not load image for notification", e)
|
Log.e("Could not load image for notification", e)
|
||||||
@@ -65,12 +65,12 @@ class PicassoHandler(private val context: Context, private val settings: Setting
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateAppIds() {
|
fun updateAppIds() {
|
||||||
ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token())
|
ClientFactory.clientToken(settings.url, settings.sslSettings(), settings.token)
|
||||||
.createService(ApplicationApi::class.java)
|
.createService(ApplicationApi::class.java)
|
||||||
.apps
|
.apps
|
||||||
.enqueue(Callback.call({ apps ->
|
.enqueue(Callback.call({ apps ->
|
||||||
appIdToAppImage.clear()
|
appIdToAppImage.clear()
|
||||||
appIdToAppImage.putAll(MessageImageCombiner.appIdToImage(apps))
|
appIdToAppImage.putAll(MessageImageCombiner.appIdToImage(apps ?: emptyList()))
|
||||||
}) { appIdToAppImage.clear() })
|
}) { appIdToAppImage.clear() })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import okhttp3.*
|
|||||||
|
|
||||||
internal class WebSocketConnection(
|
internal class WebSocketConnection(
|
||||||
private val baseUrl: String,
|
private val baseUrl: String,
|
||||||
settings: SSLSettings?,
|
settings: SSLSettings,
|
||||||
private val token: String,
|
private val token: String,
|
||||||
private val connectivityManager: ConnectivityManager,
|
private val connectivityManager: ConnectivityManager,
|
||||||
private val alarmManager: AlarmManager
|
private val alarmManager: AlarmManager
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ class WebSocketService : Service() {
|
|||||||
super.onCreate()
|
super.onCreate()
|
||||||
settings = Settings(this)
|
settings = Settings(this)
|
||||||
val client = ClientFactory.clientToken(
|
val client = ClientFactory.clientToken(
|
||||||
settings.url(),
|
settings.url,
|
||||||
settings.sslSettings(),
|
settings.sslSettings(),
|
||||||
settings.token()
|
settings.token
|
||||||
)
|
)
|
||||||
missingMessageUtil = MissedMessageUtil(client.createService(MessageApi::class.java))
|
missingMessageUtil = MissedMessageUtil(client.createService(MessageApi::class.java))
|
||||||
Log.i("Create ${javaClass.simpleName}")
|
Log.i("Create ${javaClass.simpleName}")
|
||||||
@@ -63,7 +63,7 @@ class WebSocketService : Service() {
|
|||||||
Log.w("Destroy ${javaClass.simpleName}")
|
Log.w("Destroy ${javaClass.simpleName}")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
Log.init(this)
|
Log.init(this)
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
connection!!.close()
|
connection!!.close()
|
||||||
@@ -80,16 +80,16 @@ class WebSocketService : Service() {
|
|||||||
showForegroundNotification(getString(R.string.websocket_init))
|
showForegroundNotification(getString(R.string.websocket_init))
|
||||||
|
|
||||||
if (lastReceivedMessage.get() == NOT_LOADED) {
|
if (lastReceivedMessage.get() == NOT_LOADED) {
|
||||||
missingMessageUtil.lastReceivedMessage { lastReceivedMessage.set(it) }
|
missingMessageUtil.lastReceivedMessage { lastReceivedMessage.set(it ?: 0L) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val cm = getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager
|
val cm = getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
val alarmManager = getSystemService(ALARM_SERVICE) as AlarmManager
|
val alarmManager = getSystemService(ALARM_SERVICE) as AlarmManager
|
||||||
|
|
||||||
connection = WebSocketConnection(
|
connection = WebSocketConnection(
|
||||||
settings.url(),
|
settings.url,
|
||||||
settings.sslSettings(),
|
settings.sslSettings(),
|
||||||
settings.token(),
|
settings.token,
|
||||||
cm,
|
cm,
|
||||||
alarmManager
|
alarmManager
|
||||||
)
|
)
|
||||||
@@ -105,7 +105,7 @@ class WebSocketService : Service() {
|
|||||||
onNetworkFailure(minutes)
|
onNetworkFailure(minutes)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.onMessage { onMessage(it) }
|
.onMessage { if (it != null) onMessage(it) }
|
||||||
.onReconnected { notifyMissedNotifications() }
|
.onReconnected { notifyMissedNotifications() }
|
||||||
.start()
|
.start()
|
||||||
|
|
||||||
@@ -120,9 +120,9 @@ class WebSocketService : Service() {
|
|||||||
getString(R.string.websocket_closed), getString(R.string.websocket_reconnect)
|
getString(R.string.websocket_closed), getString(R.string.websocket_reconnect)
|
||||||
)
|
)
|
||||||
ClientFactory.userApiWithToken(settings)
|
ClientFactory.userApiWithToken(settings)
|
||||||
.currentUser()
|
?.currentUser()
|
||||||
.enqueue(Callback.call({ doReconnect() }) { exception ->
|
?.enqueue(Callback.call({ doReconnect() }) { exception ->
|
||||||
if (exception.code() == 401) {
|
if (exception.code == 401) {
|
||||||
showForegroundNotification(
|
showForegroundNotification(
|
||||||
getString(R.string.user_action),
|
getString(R.string.user_action),
|
||||||
getString(R.string.websocket_closed_logout)
|
getString(R.string.websocket_closed_logout)
|
||||||
@@ -164,7 +164,7 @@ class WebSocketService : Service() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val messages = missingMessageUtil.missingMessages(messageId)
|
val messages = missingMessageUtil.missingMessages(messageId).filterNotNull()
|
||||||
|
|
||||||
if (messages.size > 5) {
|
if (messages.size > 5) {
|
||||||
onGroupedMessages(messages)
|
onGroupedMessages(messages)
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ class ShareActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val client = ClientFactory.clientToken(
|
val client = ClientFactory.clientToken(
|
||||||
settings.url(),
|
settings.url,
|
||||||
settings.sslSettings(),
|
settings.sslSettings(),
|
||||||
settings.token()
|
settings.token
|
||||||
)
|
)
|
||||||
appsHolder = ApplicationHolder(this, client)
|
appsHolder = ApplicationHolder(this, client)
|
||||||
appsHolder.onUpdate {
|
appsHolder.onUpdate {
|
||||||
@@ -116,7 +116,7 @@ class ShareActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
PushMessage({
|
PushMessage({
|
||||||
val pushClient = ClientFactory.clientToken(
|
val pushClient = ClientFactory.clientToken(
|
||||||
settings.url(),
|
settings.url,
|
||||||
settings.sslSettings(),
|
settings.sslSettings(),
|
||||||
appsHolder.get()[appIndex].token
|
appsHolder.get()[appIndex].token
|
||||||
)
|
)
|
||||||
@@ -150,7 +150,7 @@ class ShareActivity : AppCompatActivity() {
|
|||||||
) : AsyncTask<Message?, String?, String>() {
|
) : AsyncTask<Message?, String?, String>() {
|
||||||
@Deprecated("Deprecated in Java")
|
@Deprecated("Deprecated in Java")
|
||||||
override fun doInBackground(vararg messages: Message?): String {
|
override fun doInBackground(vararg messages: Message?): String {
|
||||||
return backgroundAction(Utils.first(messages))
|
return backgroundAction(messages.first())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Deprecated in Java")
|
@Deprecated("Deprecated in Java")
|
||||||
|
|||||||
Reference in New Issue
Block a user