Skip to content

Commit 33fe18a

Browse files
committed
Various minor code style changes
1 parent 9d6e322 commit 33fe18a

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

app/src/main/java/org/musicbrainz/picard/barcodescanner/util/Preferences.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package org.musicbrainz.picard.barcodescanner.util
2222
import android.content.Context
2323
import android.content.SharedPreferences
2424
import org.musicbrainz.picard.barcodescanner.R
25+
import androidx.core.content.edit
2526

2627
class Preferences(private val mContext: Context) {
2728
private val mSettings: SharedPreferences = mContext.getSharedPreferences(
@@ -40,10 +41,10 @@ class Preferences(private val mContext: Context) {
4041
val port = mSettings.getInt(Constants.PREFERENCE_PICARD_PORT, defaultPort)
4142

4243
fun setIpAddressAndPort(ipAddress: String?, port: Int) {
43-
val editor = mSettings.edit()
44-
editor.putString(Constants.PREFERENCE_PICARD_IP_ADDRESS, ipAddress)
45-
editor.putInt(Constants.PREFERENCE_PICARD_PORT, port)
46-
editor.apply()
44+
mSettings.edit {
45+
putString(Constants.PREFERENCE_PICARD_IP_ADDRESS, ipAddress)
46+
putInt(Constants.PREFERENCE_PICARD_PORT, port)
47+
}
4748
}
4849

4950
val connectionConfigured: Boolean

app/src/main/java/org/musicbrainz/picard/barcodescanner/webservice/MusicBrainzClient.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class MusicBrainzClient {
3535

3636
private val instance: MusicBrainzApi by lazy {
3737
val retrofit = Retrofit.Builder()
38-
.baseUrl(baseUrl)
38+
.baseUrl(BASE_URL)
3939
.addConverterFactory(GsonConverterFactory.create(
4040
GsonBuilder().setStrictness(Strictness.LENIENT).create()))
4141
.client(okHttpClient)
@@ -45,14 +45,14 @@ class MusicBrainzClient {
4545
}
4646

4747
companion object {
48-
private const val baseUrl = "https://musicbrainz.org/ws/2/"
49-
private const val userAgent = "picard-android-barcodescanner/1.5"
48+
private const val BASE_URL = "https://musicbrainz.org/ws/2/"
49+
private const val USER_AGENT = "picard-android-barcodescanner/1.5"
5050
private val okHttpClient = HttpClient.newBuilder()
5151
.addInterceptor { chain ->
5252
val original = chain.request()
5353

5454
val requestBuilder = original.newBuilder()
55-
.header("User-Agent", userAgent)
55+
.header("User-Agent", USER_AGENT)
5656
.addHeader("Accept", "application/json")
5757
.method(original.method, original.body)
5858

app/src/main/java/org/musicbrainz/picard/barcodescanner/webservice/PicardClient.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
*/
2121
package org.musicbrainz.picard.barcodescanner.webservice
2222

23+
import android.annotation.SuppressLint
2324
import org.musicbrainz.picard.barcodescanner.data.PicardPingResult
2425
import org.musicbrainz.picard.barcodescanner.util.WebServiceUtils
2526
import retrofit2.Retrofit
2627
import retrofit2.converter.scalars.ScalarsConverterFactory
2728
import java.lang.Exception
2829
import java.util.concurrent.TimeUnit
2930

31+
@SuppressLint("DefaultLocale")
3032
class PicardClient(private val mIpAddress: String, private val mPort: Int) {
3133

3234
suspend fun openRelease(releaseId: String): Boolean {
@@ -41,10 +43,10 @@ class PicardClient(private val mIpAddress: String, private val mPort: Int) {
4143
suspend fun ping(): PicardPingResult {
4244
return try {
4345
val result = instance.ping()
44-
val match = pingResponseRegex.matchEntire((result))
46+
val match = PING_RESPONSE_REGEX.matchEntire((result))
4547
when {
4648
match != null -> PicardPingResult(true, getAppName(match.groupValues[1]))
47-
result == legacyPingResponse -> PicardPingResult(true, getAppName())
49+
result == LEGACY_PING_RESPONSE -> PicardPingResult(true, getAppName())
4850
else -> PicardPingResult(false, "")
4951
}
5052
} catch (e: Exception) {
@@ -53,12 +55,12 @@ class PicardClient(private val mIpAddress: String, private val mPort: Int) {
5355
}
5456

5557
private fun getAppName(version: String? = null): String {
56-
return picardAppName.format(version).trimEnd()
58+
return PICARD_APP_NAME.format(version).trimEnd()
5759
}
5860

5961
private val instance: PicardApi by lazy {
6062
val retrofit = Retrofit.Builder()
61-
.baseUrl(String.format(baseUrl, mIpAddress, mPort))
63+
.baseUrl(String.format(BASE_URL, mIpAddress, mPort))
6264
.addConverterFactory(ScalarsConverterFactory.create())
6365
.client(okHttpClient)
6466
.build()
@@ -67,10 +69,10 @@ class PicardClient(private val mIpAddress: String, private val mPort: Int) {
6769
}
6870

6971
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"
7476
private val okHttpClient = HttpClient.newBuilder()
7577
.connectTimeout(1000, TimeUnit.MILLISECONDS)
7678
.build()

0 commit comments

Comments
 (0)