Reformat smaller parts of code
This commit is contained in:
@@ -56,10 +56,7 @@ internal class Callback<T> private constructor(
|
|||||||
return RetrofitCallback(merge(of(onSuccess, onError), errorCallback()))
|
return RetrofitCallback(merge(of(onSuccess, onError), errorCallback()))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T> of(
|
private fun <T> of(onSuccess: SuccessCallback<T>, onError: ErrorCallback): Callback<T> {
|
||||||
onSuccess: SuccessCallback<T>,
|
|
||||||
onError: ErrorCallback
|
|
||||||
): Callback<T> {
|
|
||||||
return Callback(onSuccess, onError)
|
return Callback(onSuccess, onError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import androidx.recyclerview.widget.DividerItemDecoration
|
|||||||
import androidx.recyclerview.widget.ItemTouchHelper
|
import androidx.recyclerview.widget.ItemTouchHelper
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|
||||||
import com.github.gotify.BuildConfig
|
import com.github.gotify.BuildConfig
|
||||||
import com.github.gotify.MissedMessageUtil
|
import com.github.gotify.MissedMessageUtil
|
||||||
import com.github.gotify.R
|
import com.github.gotify.R
|
||||||
@@ -116,14 +115,10 @@ internal class MessagesActivity :
|
|||||||
appsHolder.onUpdate { onUpdateApps(appsHolder.get()) }
|
appsHolder.onUpdate { onUpdateApps(appsHolder.get()) }
|
||||||
if (appsHolder.wasRequested()) onUpdateApps(appsHolder.get()) else appsHolder.request()
|
if (appsHolder.wasRequested()) onUpdateApps(appsHolder.get()) else appsHolder.request()
|
||||||
|
|
||||||
val itemTouchHelper = ItemTouchHelper(
|
val itemTouchHelper = ItemTouchHelper(SwipeToDeleteCallback(listMessageAdapter))
|
||||||
SwipeToDeleteCallback(
|
|
||||||
listMessageAdapter
|
|
||||||
)
|
|
||||||
)
|
|
||||||
itemTouchHelper.attachToRecyclerView(messagesView)
|
itemTouchHelper.attachToRecyclerView(messagesView)
|
||||||
|
|
||||||
val swipeRefreshLayout: SwipeRefreshLayout = binding.swipeRefresh
|
val swipeRefreshLayout = binding.swipeRefresh
|
||||||
swipeRefreshLayout.setOnRefreshListener { onRefresh() }
|
swipeRefreshLayout.setOnRefreshListener { onRefresh() }
|
||||||
binding.drawerLayout.addDrawerListener(
|
binding.drawerLayout.addDrawerListener(
|
||||||
object : SimpleDrawerListener() {
|
object : SimpleDrawerListener() {
|
||||||
@@ -431,11 +426,11 @@ internal class MessagesActivity :
|
|||||||
actionState: Int,
|
actionState: Int,
|
||||||
isCurrentlyActive: Boolean
|
isCurrentlyActive: Boolean
|
||||||
) {
|
) {
|
||||||
if (icon != null) {
|
icon?.let {
|
||||||
val itemView = viewHolder.itemView
|
val itemView = viewHolder.itemView
|
||||||
val iconHeight = itemView.height / 3
|
val iconHeight = itemView.height / 3
|
||||||
val scale = iconHeight / icon!!.intrinsicHeight.toDouble()
|
val scale = iconHeight / it.intrinsicHeight.toDouble()
|
||||||
val iconWidth = (icon!!.intrinsicWidth * scale).toInt()
|
val iconWidth = (it.intrinsicWidth * scale).toInt()
|
||||||
val iconMarginLeftRight = 50
|
val iconMarginLeftRight = 50
|
||||||
val iconMarginTopBottom = (itemView.height - iconHeight) / 2
|
val iconMarginTopBottom = (itemView.height - iconHeight) / 2
|
||||||
val iconTop = itemView.top + iconMarginTopBottom
|
val iconTop = itemView.top + iconMarginTopBottom
|
||||||
@@ -444,7 +439,7 @@ internal class MessagesActivity :
|
|||||||
// Swiping to the right
|
// Swiping to the right
|
||||||
val iconLeft = itemView.left + iconMarginLeftRight
|
val iconLeft = itemView.left + iconMarginLeftRight
|
||||||
val iconRight = itemView.left + iconMarginLeftRight + iconWidth
|
val iconRight = itemView.left + iconMarginLeftRight + iconWidth
|
||||||
icon!!.setBounds(iconLeft, iconTop, iconRight, iconBottom)
|
it.setBounds(iconLeft, iconTop, iconRight, iconBottom)
|
||||||
background.setBounds(
|
background.setBounds(
|
||||||
itemView.left,
|
itemView.left,
|
||||||
itemView.top,
|
itemView.top,
|
||||||
@@ -455,7 +450,7 @@ internal class MessagesActivity :
|
|||||||
// Swiping to the left
|
// Swiping to the left
|
||||||
val iconLeft = itemView.right - iconMarginLeftRight - iconWidth
|
val iconLeft = itemView.right - iconMarginLeftRight - iconWidth
|
||||||
val iconRight = itemView.right - iconMarginLeftRight
|
val iconRight = itemView.right - iconMarginLeftRight
|
||||||
icon!!.setBounds(iconLeft, iconTop, iconRight, iconBottom)
|
it.setBounds(iconLeft, iconTop, iconRight, iconBottom)
|
||||||
background.setBounds(
|
background.setBounds(
|
||||||
itemView.right + dX.toInt(),
|
itemView.right + dX.toInt(),
|
||||||
itemView.top,
|
itemView.top,
|
||||||
@@ -464,11 +459,11 @@ internal class MessagesActivity :
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// View is unswiped
|
// View is unswiped
|
||||||
icon!!.setBounds(0, 0, 0, 0)
|
it.setBounds(0, 0, 0, 0)
|
||||||
background.setBounds(0, 0, 0, 0)
|
background.setBounds(0, 0, 0, 0)
|
||||||
}
|
}
|
||||||
background.draw(c)
|
background.draw(c)
|
||||||
icon!!.draw(c)
|
it.draw(c)
|
||||||
}
|
}
|
||||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
|
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
|
||||||
}
|
}
|
||||||
@@ -535,8 +530,7 @@ internal class MessagesActivity :
|
|||||||
|
|
||||||
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(
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ internal class PicassoHandler(private val context: Context, private val settings
|
|||||||
PICASSO_CACHE_SIZE.toLong()
|
PICASSO_CACHE_SIZE.toLong()
|
||||||
)
|
)
|
||||||
|
|
||||||
private val picasso: Picasso = makePicasso()
|
private val picasso = makePicasso()
|
||||||
private val appIdToAppImage = ConcurrentHashMap<Long, String>()
|
private val appIdToAppImage = ConcurrentHashMap<Long, String>()
|
||||||
|
|
||||||
private fun makePicasso(): Picasso {
|
private fun makePicasso(): Picasso {
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ import com.github.gotify.log.UncaughtExceptionHandler
|
|||||||
import com.github.gotify.messages.Extras
|
import com.github.gotify.messages.Extras
|
||||||
import com.github.gotify.messages.MessagesActivity
|
import com.github.gotify.messages.MessagesActivity
|
||||||
import com.github.gotify.picasso.PicassoHandler
|
import com.github.gotify.picasso.PicassoHandler
|
||||||
import com.github.gotify.service.WebSocketConnection.BadRequestRunnable
|
|
||||||
import com.github.gotify.service.WebSocketConnection.OnNetworkFailureRunnable
|
|
||||||
import io.noties.markwon.Markwon
|
import io.noties.markwon.Markwon
|
||||||
import java.util.concurrent.atomic.AtomicLong
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
|
|
||||||
@@ -167,15 +165,15 @@ internal class WebSocketService : Service() {
|
|||||||
if (messages.size > 5) {
|
if (messages.size > 5) {
|
||||||
onGroupedMessages(messages)
|
onGroupedMessages(messages)
|
||||||
} else {
|
} else {
|
||||||
for (message in messages) {
|
messages.forEach {
|
||||||
onMessage(message)
|
onMessage(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onGroupedMessages(messages: List<Message>) {
|
private fun onGroupedMessages(messages: List<Message>) {
|
||||||
var highestPriority = 0L
|
var highestPriority = 0L
|
||||||
for (message in messages) {
|
messages.forEach { message ->
|
||||||
if (lastReceivedMessage.get() < message.id) {
|
if (lastReceivedMessage.get() < message.id) {
|
||||||
lastReceivedMessage.set(message.id)
|
lastReceivedMessage.set(message.id)
|
||||||
highestPriority = highestPriority.coerceAtLeast(message.priority)
|
highestPriority = highestPriority.coerceAtLeast(message.priority)
|
||||||
|
|||||||
Reference in New Issue
Block a user