Let kotlinter format the code
This commit is contained in:
@@ -3,10 +3,19 @@ package com.github.gotify
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.text.style.*
|
||||
import android.text.style.BackgroundColorSpan
|
||||
import android.text.style.BulletSpan
|
||||
import android.text.style.QuoteSpan
|
||||
import android.text.style.RelativeSizeSpan
|
||||
import android.text.style.StyleSpan
|
||||
import android.text.style.TypefaceSpan
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.squareup.picasso.Picasso
|
||||
import io.noties.markwon.*
|
||||
import io.noties.markwon.AbstractMarkwonPlugin
|
||||
import io.noties.markwon.Markwon
|
||||
import io.noties.markwon.MarkwonSpansFactory
|
||||
import io.noties.markwon.MarkwonVisitor
|
||||
import io.noties.markwon.RenderProps
|
||||
import io.noties.markwon.core.CorePlugin
|
||||
import io.noties.markwon.core.CoreProps
|
||||
import io.noties.markwon.core.MarkwonTheme
|
||||
@@ -17,7 +26,13 @@ import io.noties.markwon.image.picasso.PicassoImagesPlugin
|
||||
import io.noties.markwon.movement.MovementMethodPlugin
|
||||
import org.commonmark.ext.gfm.tables.TableCell
|
||||
import org.commonmark.ext.gfm.tables.TablesExtension
|
||||
import org.commonmark.node.*
|
||||
import org.commonmark.node.BlockQuote
|
||||
import org.commonmark.node.Code
|
||||
import org.commonmark.node.Emphasis
|
||||
import org.commonmark.node.Heading
|
||||
import org.commonmark.node.Link
|
||||
import org.commonmark.node.ListItem
|
||||
import org.commonmark.node.StrongEmphasis
|
||||
import org.commonmark.parser.Parser
|
||||
|
||||
internal object MarkwonFactory {
|
||||
|
||||
@@ -35,7 +35,8 @@ internal class MissedMessageUtil(private val api: MessageApi) {
|
||||
result.addAll(filtered)
|
||||
if (messages.size != filtered.size ||
|
||||
messages.size == 0 ||
|
||||
pagedMessages.paging.next == null) {
|
||||
pagedMessages.paging.next == null
|
||||
) {
|
||||
break
|
||||
}
|
||||
since = pagedMessages.paging.since
|
||||
|
||||
@@ -15,6 +15,12 @@ import com.google.android.material.snackbar.Snackbar
|
||||
import com.google.gson.Gson
|
||||
import com.squareup.picasso.Picasso.LoadedFrom
|
||||
import com.squareup.picasso.Target
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import okio.Buffer
|
||||
import org.threeten.bp.OffsetDateTime
|
||||
import java.io.BufferedReader
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
@@ -23,12 +29,6 @@ import java.net.MalformedURLException
|
||||
import java.net.URI
|
||||
import java.net.URISyntaxException
|
||||
import java.net.URL
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import okio.Buffer
|
||||
import org.threeten.bp.OffsetDateTime
|
||||
|
||||
internal object Utils {
|
||||
val JSON: Gson = JSON().gson
|
||||
@@ -52,11 +52,14 @@ internal object Utils {
|
||||
fun resolveAbsoluteUrl(baseURL: String, target: String?): String? {
|
||||
return if (target == null) {
|
||||
null
|
||||
} else try {
|
||||
} else {
|
||||
try {
|
||||
val targetUri = URI(target)
|
||||
if (targetUri.isAbsolute) {
|
||||
target
|
||||
} else URL(URL(baseURL), target).toString()
|
||||
} else {
|
||||
URL(URL(baseURL), target).toString()
|
||||
}
|
||||
} catch (e: MalformedURLException) {
|
||||
Log.e("Could not resolve absolute url", e)
|
||||
target
|
||||
@@ -65,6 +68,7 @@ internal object Utils {
|
||||
target
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun toDrawable(resources: Resources?, drawableReceiver: DrawableReceiver): Target {
|
||||
return object : Target {
|
||||
@@ -85,9 +89,7 @@ internal object Utils {
|
||||
var currentLine: String?
|
||||
try {
|
||||
BufferedReader(InputStreamReader(inputStream)).use { reader ->
|
||||
while (reader.readLine().also {
|
||||
currentLine = it
|
||||
} != null) {
|
||||
while (reader.readLine().also { currentLine = it } != null) {
|
||||
sb.append(currentLine).append("\n")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.github.gotify.api
|
||||
|
||||
import java.io.IOException
|
||||
import retrofit2.Call
|
||||
import java.io.IOException
|
||||
|
||||
internal object Api {
|
||||
@Throws(ApiException::class)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.github.gotify.api
|
||||
|
||||
import java.io.IOException
|
||||
import retrofit2.Response
|
||||
import java.io.IOException
|
||||
|
||||
internal class ApiException : Exception {
|
||||
var body: String = ""
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
|
||||
import com.github.gotify.SSLSettings
|
||||
import com.github.gotify.Utils
|
||||
import com.github.gotify.log.Log
|
||||
import okhttp3.OkHttpClient
|
||||
import java.io.IOException
|
||||
import java.security.GeneralSecurityException
|
||||
import java.security.KeyStore
|
||||
@@ -11,8 +12,10 @@ import java.security.SecureRandom
|
||||
import java.security.cert.Certificate
|
||||
import java.security.cert.CertificateFactory
|
||||
import java.security.cert.X509Certificate
|
||||
import javax.net.ssl.*
|
||||
import okhttp3.OkHttpClient
|
||||
import javax.net.ssl.SSLContext
|
||||
import javax.net.ssl.TrustManager
|
||||
import javax.net.ssl.TrustManagerFactory
|
||||
import javax.net.ssl.X509TrustManager
|
||||
|
||||
internal object CertUtils {
|
||||
@SuppressLint("CustomX509TrustManager")
|
||||
|
||||
@@ -37,7 +37,8 @@ internal object ClientFactory {
|
||||
): ApiClient {
|
||||
val client = defaultClient(
|
||||
arrayOf("clientTokenHeader"),
|
||||
"$baseUrl/", sslSettings
|
||||
"$baseUrl/",
|
||||
sslSettings
|
||||
)
|
||||
val tokenAuth = client.apiAuthorizations["clientTokenHeader"] as ApiKeyAuth
|
||||
tokenAuth.apiKey = token
|
||||
|
||||
@@ -31,8 +31,8 @@ import com.github.gotify.init.InitializationActivity
|
||||
import com.github.gotify.log.Log
|
||||
import com.github.gotify.log.LogsActivity
|
||||
import com.github.gotify.log.UncaughtExceptionHandler
|
||||
import java.security.cert.X509Certificate
|
||||
import okhttp3.HttpUrl
|
||||
import java.security.cert.X509Certificate
|
||||
|
||||
internal class LoginActivity : AppCompatActivity() {
|
||||
companion object {
|
||||
@@ -125,7 +125,9 @@ internal class LoginActivity : AppCompatActivity() {
|
||||
private fun toggleShowAdvanced() {
|
||||
val selectedCertName = if (caCertContents != null) {
|
||||
getNameOfCertContent(caCertContents!!)
|
||||
} else null
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
advancedDialog = AdvancedDialog(this, layoutInflater)
|
||||
.onDisableSSLChanged { _, disable ->
|
||||
|
||||
@@ -26,9 +26,9 @@ import com.github.gotify.databinding.MessageItemCompactBinding
|
||||
import com.github.gotify.messages.provider.MessageWithImage
|
||||
import com.squareup.picasso.Picasso
|
||||
import io.noties.markwon.Markwon
|
||||
import java.text.DateFormat
|
||||
import java.util.*
|
||||
import org.threeten.bp.OffsetDateTime
|
||||
import java.text.DateFormat
|
||||
import java.util.Date
|
||||
|
||||
internal class ListMessageAdapter(
|
||||
private val context: Context,
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.github.gotify.messages
|
||||
|
||||
import android.app.NotificationManager
|
||||
import android.content.*
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
@@ -45,21 +48,21 @@ import com.github.gotify.init.InitializationActivity
|
||||
import com.github.gotify.log.Log
|
||||
import com.github.gotify.log.LogsActivity
|
||||
import com.github.gotify.login.LoginActivity
|
||||
import com.github.gotify.messages.provider.*
|
||||
import com.github.gotify.messages.provider.MessageState
|
||||
import com.github.gotify.messages.provider.MessageWithImage
|
||||
import com.github.gotify.service.WebSocketService
|
||||
import com.github.gotify.settings.SettingsActivity
|
||||
import com.github.gotify.sharing.ShareActivity
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import com.google.android.material.snackbar.BaseTransientBottomBar.BaseCallback
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import java.io.IOException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.IOException
|
||||
|
||||
internal class MessagesActivity :
|
||||
AppCompatActivity(),
|
||||
NavigationView.OnNavigationItemSelectedListener
|
||||
{
|
||||
NavigationView.OnNavigationItemSelectedListener {
|
||||
private lateinit var binding: ActivityMessagesBinding
|
||||
private lateinit var viewModel: MessagesModel
|
||||
private var isLoadMore = false
|
||||
@@ -90,7 +93,8 @@ internal class MessagesActivity :
|
||||
val layoutManager = LinearLayoutManager(this)
|
||||
val messagesView: RecyclerView = binding.messagesView
|
||||
val dividerItemDecoration = DividerItemDecoration(
|
||||
messagesView.context, layoutManager.orientation
|
||||
messagesView.context,
|
||||
layoutManager.orientation
|
||||
)
|
||||
listMessageAdapter = ListMessageAdapter(
|
||||
this,
|
||||
@@ -132,7 +136,8 @@ internal class MessagesActivity :
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
swipeRefreshLayout.isEnabled = false
|
||||
messagesView
|
||||
|
||||
@@ -14,10 +14,10 @@ import com.github.gotify.log.Log
|
||||
import com.github.gotify.messages.provider.MessageImageCombiner
|
||||
import com.squareup.picasso.OkHttp3Downloader
|
||||
import com.squareup.picasso.Picasso
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import okhttp3.Cache
|
||||
import okhttp3.OkHttpClient
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
internal class PicassoHandler(private val context: Context, private val settings: Settings) {
|
||||
|
||||
@@ -11,10 +11,15 @@ import com.github.gotify.api.Callback.SuccessCallback
|
||||
import com.github.gotify.api.CertUtils
|
||||
import com.github.gotify.client.model.Message
|
||||
import com.github.gotify.log.Log
|
||||
import java.util.*
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import okhttp3.WebSocket
|
||||
import okhttp3.WebSocketListener
|
||||
import java.util.Calendar
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
import okhttp3.*
|
||||
|
||||
internal class WebSocketConnection(
|
||||
private val baseUrl: String,
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.github.gotify.service
|
||||
|
||||
import android.app.*
|
||||
import android.app.AlarmManager
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.app.Service
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.graphics.Color
|
||||
@@ -11,7 +15,12 @@ import android.os.IBinder
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.github.gotify.*
|
||||
import com.github.gotify.MarkwonFactory
|
||||
import com.github.gotify.MissedMessageUtil
|
||||
import com.github.gotify.NotificationSupport
|
||||
import com.github.gotify.R
|
||||
import com.github.gotify.Settings
|
||||
import com.github.gotify.Utils
|
||||
import com.github.gotify.api.Callback
|
||||
import com.github.gotify.api.ClientFactory
|
||||
import com.github.gotify.client.api.MessageApi
|
||||
@@ -107,7 +116,8 @@ internal class WebSocketService : Service() {
|
||||
|
||||
private fun onClose() {
|
||||
showForegroundNotification(
|
||||
getString(R.string.websocket_closed), getString(R.string.websocket_reconnect)
|
||||
getString(R.string.websocket_closed),
|
||||
getString(R.string.websocket_reconnect)
|
||||
)
|
||||
ClientFactory.userApiWithToken(settings)
|
||||
.currentUser()
|
||||
@@ -121,8 +131,10 @@ internal class WebSocketService : Service() {
|
||||
getString(R.string.websocket_closed_logout)
|
||||
)
|
||||
} else {
|
||||
Log.i("WebSocket closed but the user still authenticated, " +
|
||||
"trying to reconnect")
|
||||
Log.i(
|
||||
"WebSocket closed but the user still authenticated, " +
|
||||
"trying to reconnect"
|
||||
)
|
||||
doReconnect()
|
||||
}
|
||||
}
|
||||
@@ -146,7 +158,8 @@ internal class WebSocketService : Service() {
|
||||
val intervalUnit = resources
|
||||
.getQuantityString(R.plurals.websocket_retry_interval, minutes, minutes)
|
||||
showForegroundNotification(
|
||||
status, "${getString(R.string.websocket_reconnect)} $intervalUnit"
|
||||
status,
|
||||
"${getString(R.string.websocket_reconnect)} $intervalUnit"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -218,7 +231,10 @@ internal class WebSocketService : Service() {
|
||||
val notificationIntent = Intent(this, MessagesActivity::class.java)
|
||||
|
||||
val pendingIntent = PendingIntent.getActivity(
|
||||
this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE
|
||||
this,
|
||||
0,
|
||||
notificationIntent,
|
||||
PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
val notificationBuilder =
|
||||
NotificationCompat.Builder(this, NotificationSupport.Channel.FOREGROUND)
|
||||
@@ -297,7 +313,8 @@ internal class WebSocketService : Service() {
|
||||
)
|
||||
|
||||
val b = NotificationCompat.Builder(
|
||||
this, NotificationSupport.convertPriorityToChannel(priority)
|
||||
this,
|
||||
NotificationSupport.convertPriorityToChannel(priority)
|
||||
)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
@@ -358,7 +375,8 @@ internal class WebSocketService : Service() {
|
||||
)
|
||||
|
||||
val builder = NotificationCompat.Builder(
|
||||
this, NotificationSupport.convertPriorityToChannel(priority)
|
||||
this,
|
||||
NotificationSupport.convertPriorityToChannel(priority)
|
||||
)
|
||||
|
||||
builder.setAutoCancel(true)
|
||||
|
||||
@@ -17,6 +17,8 @@ internal object ThemeHelper {
|
||||
AppCompatDelegate.MODE_NIGHT_NO
|
||||
} else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
|
||||
AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
|
||||
} else AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
} else {
|
||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user