20
20
*/
21
21
package org.musicbrainz.picard.barcodescanner.webservice
22
22
23
+ import android.annotation.SuppressLint
23
24
import org.musicbrainz.picard.barcodescanner.data.PicardPingResult
24
25
import org.musicbrainz.picard.barcodescanner.util.WebServiceUtils
25
26
import retrofit2.Retrofit
26
27
import retrofit2.converter.scalars.ScalarsConverterFactory
27
28
import java.lang.Exception
28
29
import java.util.concurrent.TimeUnit
29
30
31
+ @SuppressLint(" DefaultLocale" )
30
32
class PicardClient (private val mIpAddress : String , private val mPort : Int ) {
31
33
32
34
suspend fun openRelease (releaseId : String ): Boolean {
@@ -41,10 +43,10 @@ class PicardClient(private val mIpAddress: String, private val mPort: Int) {
41
43
suspend fun ping (): PicardPingResult {
42
44
return try {
43
45
val result = instance.ping()
44
- val match = pingResponseRegex .matchEntire((result))
46
+ val match = PING_RESPONSE_REGEX .matchEntire((result))
45
47
when {
46
48
match != null -> PicardPingResult (true , getAppName(match.groupValues[1 ]))
47
- result == legacyPingResponse -> PicardPingResult (true , getAppName())
49
+ result == LEGACY_PING_RESPONSE -> PicardPingResult (true , getAppName())
48
50
else -> PicardPingResult (false , " " )
49
51
}
50
52
} catch (e: Exception ) {
@@ -53,12 +55,12 @@ class PicardClient(private val mIpAddress: String, private val mPort: Int) {
53
55
}
54
56
55
57
private fun getAppName (version : String? = null): String {
56
- return picardAppName .format(version).trimEnd()
58
+ return PICARD_APP_NAME .format(version).trimEnd()
57
59
}
58
60
59
61
private val instance: PicardApi by lazy {
60
62
val retrofit = Retrofit .Builder ()
61
- .baseUrl(String .format(baseUrl , mIpAddress, mPort))
63
+ .baseUrl(String .format(BASE_URL , mIpAddress, mPort))
62
64
.addConverterFactory(ScalarsConverterFactory .create())
63
65
.client(okHttpClient)
64
66
.build()
@@ -67,10 +69,10 @@ class PicardClient(private val mIpAddress: String, private val mPort: Int) {
67
69
}
68
70
69
71
companion object {
70
- private const val baseUrl = " http://%s:%d/"
71
- private val pingResponseRegex = Regex (" MusicBrainz-Picard/(.*)" )
72
- private const val legacyPingResponse = " Nothing to see here"
73
- private const val picardAppName = " MusicBrainz Picard %s"
72
+ private const val BASE_URL = " http://%s:%d/"
73
+ private val PING_RESPONSE_REGEX = Regex (" MusicBrainz-Picard/(.*)" )
74
+ private const val LEGACY_PING_RESPONSE = " Nothing to see here"
75
+ private const val PICARD_APP_NAME = " MusicBrainz Picard %s"
74
76
private val okHttpClient = HttpClient .newBuilder()
75
77
.connectTimeout(1000 , TimeUnit .MILLISECONDS )
76
78
.build()
0 commit comments