Reformat smaller parts of code

This commit is contained in:
Niko Diamadis
2023-01-12 17:56:45 +01:00
parent 8bf7b8e552
commit fc0825de3d
4 changed files with 15 additions and 26 deletions

View File

@@ -56,10 +56,7 @@ internal class Callback<T> private constructor(
return RetrofitCallback(merge(of(onSuccess, onError), errorCallback()))
}
private fun <T> of(
onSuccess: SuccessCallback<T>,
onError: ErrorCallback
): Callback<T> {
private fun <T> of(onSuccess: SuccessCallback<T>, onError: ErrorCallback): Callback<T> {
return Callback(onSuccess, onError)
}

View File

@@ -25,7 +25,6 @@ import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.github.gotify.BuildConfig
import com.github.gotify.MissedMessageUtil
import com.github.gotify.R
@@ -116,14 +115,10 @@ internal class MessagesActivity :
appsHolder.onUpdate { onUpdateApps(appsHolder.get()) }
if (appsHolder.wasRequested()) onUpdateApps(appsHolder.get()) else appsHolder.request()
val itemTouchHelper = ItemTouchHelper(
SwipeToDeleteCallback(
listMessageAdapter
)
)
val itemTouchHelper = ItemTouchHelper(SwipeToDeleteCallback(listMessageAdapter))
itemTouchHelper.attachToRecyclerView(messagesView)
val swipeRefreshLayout: SwipeRefreshLayout = binding.swipeRefresh
val swipeRefreshLayout = binding.swipeRefresh
swipeRefreshLayout.setOnRefreshListener { onRefresh() }
binding.drawerLayout.addDrawerListener(
object : SimpleDrawerListener() {
@@ -431,11 +426,11 @@ internal class MessagesActivity :
actionState: Int,
isCurrentlyActive: Boolean
) {
if (icon != null) {
icon?.let {
val itemView = viewHolder.itemView
val iconHeight = itemView.height / 3
val scale = iconHeight / icon!!.intrinsicHeight.toDouble()
val iconWidth = (icon!!.intrinsicWidth * scale).toInt()
val scale = iconHeight / it.intrinsicHeight.toDouble()
val iconWidth = (it.intrinsicWidth * scale).toInt()
val iconMarginLeftRight = 50
val iconMarginTopBottom = (itemView.height - iconHeight) / 2
val iconTop = itemView.top + iconMarginTopBottom
@@ -444,7 +439,7 @@ internal class MessagesActivity :
// Swiping to the right
val iconLeft = itemView.left + iconMarginLeftRight
val iconRight = itemView.left + iconMarginLeftRight + iconWidth
icon!!.setBounds(iconLeft, iconTop, iconRight, iconBottom)
it.setBounds(iconLeft, iconTop, iconRight, iconBottom)
background.setBounds(
itemView.left,
itemView.top,
@@ -455,7 +450,7 @@ internal class MessagesActivity :
// Swiping to the left
val iconLeft = itemView.right - iconMarginLeftRight - iconWidth
val iconRight = itemView.right - iconMarginLeftRight
icon!!.setBounds(iconLeft, iconTop, iconRight, iconBottom)
it.setBounds(iconLeft, iconTop, iconRight, iconBottom)
background.setBounds(
itemView.right + dX.toInt(),
itemView.top,
@@ -464,11 +459,11 @@ internal class MessagesActivity :
)
} else {
// View is unswiped
icon!!.setBounds(0, 0, 0, 0)
it.setBounds(0, 0, 0, 0)
background.setBounds(0, 0, 0, 0)
}
background.draw(c)
icon!!.draw(c)
it.draw(c)
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
}
@@ -535,8 +530,7 @@ internal class MessagesActivity :
private fun deleteApp(appId: Long) {
val settings = viewModel.settings
val client =
ClientFactory.clientToken(settings.url, settings.sslSettings(), settings.token)
val client = ClientFactory.clientToken(settings.url, settings.sslSettings(), settings.token)
client.createService(ApplicationApi::class.java)
.deleteApp(appId)
.enqueue(

View File

@@ -31,7 +31,7 @@ internal class PicassoHandler(private val context: Context, private val settings
PICASSO_CACHE_SIZE.toLong()
)
private val picasso: Picasso = makePicasso()
private val picasso = makePicasso()
private val appIdToAppImage = ConcurrentHashMap<Long, String>()
private fun makePicasso(): Picasso {

View File

@@ -21,8 +21,6 @@ import com.github.gotify.log.UncaughtExceptionHandler
import com.github.gotify.messages.Extras
import com.github.gotify.messages.MessagesActivity
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 java.util.concurrent.atomic.AtomicLong
@@ -167,15 +165,15 @@ internal class WebSocketService : Service() {
if (messages.size > 5) {
onGroupedMessages(messages)
} else {
for (message in messages) {
onMessage(message)
messages.forEach {
onMessage(it)
}
}
}
private fun onGroupedMessages(messages: List<Message>) {
var highestPriority = 0L
for (message in messages) {
messages.forEach { message ->
if (lastReceivedMessage.get() < message.id) {
lastReceivedMessage.set(message.id)
highestPriority = highestPriority.coerceAtLeast(message.priority)