Skip to content

Commit b55c61d

Browse files
Fixed the migrations warning under Kotlin header #13282 (commons-app#6060)
* Fixed Migration warnings under Kotlin header * suppresses Lint --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
1 parent f1e8e48 commit b55c61d

File tree

13 files changed

+28
-20
lines changed

13 files changed

+28
-20
lines changed

app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class LoginActivity : AccountAuthenticatorActivity() {
146146
loginTwoFactor.removeTextChangedListener(textWatcher)
147147
}
148148
delegate.onDestroy()
149-
loginClient?.cancel()
149+
loginClient.cancel()
150150
binding = null
151151
super.onDestroy()
152152
}

app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class CustomSelectorActivity :
250250
val selectedImages: ArrayList<Image> =
251251
result.data!!
252252
.getParcelableArrayListExtra(CustomSelectorConstants.NEW_SELECTED_IMAGES)!!
253-
viewModel?.selectedImages?.value = selectedImages
253+
viewModel.selectedImages?.value = selectedImages
254254
}
255255
}
256256

app/src/main/java/fr/free/nrw/commons/description/DescriptionEditActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class DescriptionEditActivity :
240240
applicationContext,
241241
media,
242242
updatedWikiText,
243-
)?.subscribeOn(Schedulers.io())
243+
).subscribeOn(Schedulers.io())
244244
?.observeOn(AndroidSchedulers.mainThread())
245245
?.subscribe(Consumer<Boolean> { s: Boolean? -> Timber.d("Descriptions are added.") })
246246
?.let {

app/src/main/java/fr/free/nrw/commons/mwapi/OkHttpJsonApiClient.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class OkHttpJsonApiClient @Inject constructor(
175175
.build()
176176
val response: Response = okHttpClient.newCall(request).execute()
177177
if (response.body != null && response.isSuccessful) {
178-
val json: String = response.body!!.string() ?: return@fromCallable null
178+
val json: String = response.body!!.string()
179179
try {
180180
return@fromCallable gson.fromJson<UpdateAvatarResponse>(
181181
json,

app/src/main/java/fr/free/nrw/commons/upload/FileProcessor.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class FileProcessor
8686
*/
8787
fun getExifTagsToRedact(): Set<String> {
8888
val prefManageEXIFTags =
89-
defaultKvStore.getStringSet(Prefs.MANAGED_EXIF_TAGS) ?: emptySet()
89+
defaultKvStore.getStringSet(Prefs.MANAGED_EXIF_TAGS)
9090
val redactTags: Set<String> =
9191
context.resources.getStringArray(R.array.pref_exifTag_values).toSet()
9292
return redactTags - prefManageEXIFTags

app/src/main/java/fr/free/nrw/commons/upload/UploadResult.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ data class UploadResult(
1414
constructor(parcel: Parcel) : this(
1515
parcel.readString() ?: "",
1616
parcel.readString() ?: "",
17-
parcel.readInt() ?: 0,
17+
parcel.readInt(),
1818
parcel.readString() ?: "",
1919
) {
2020
}

app/src/main/java/fr/free/nrw/commons/upload/worker/UploadWorker.kt

+10-6
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class UploadWorker(
121121
private var notificationFinishingTitle: String?,
122122
var contribution: Contribution?,
123123
) {
124+
@SuppressLint("MissingPermission")
124125
fun onProgress(
125126
transferred: Long,
126127
total: Long,
@@ -175,6 +176,7 @@ class UploadWorker(
175176
.setProgress(100, 0, true)
176177
.setOngoing(true)
177178

179+
@SuppressLint("MissingPermission")
178180
override suspend fun doWork(): Result {
179181
try {
180182
var totalUploadsStarted = 0
@@ -298,7 +300,7 @@ class UploadWorker(
298300
* Upload the contribution
299301
* @param contribution
300302
*/
301-
@SuppressLint("StringFormatInvalid", "CheckResult")
303+
@SuppressLint("StringFormatInvalid", "CheckResult", "MissingPermission")
302304
private suspend fun uploadContribution(contribution: Contribution) {
303305
if (contribution.localUri == null || contribution.localUri.path == null) {
304306
Timber.e("""upload: ${contribution.media.filename} failed, file path is null""")
@@ -439,7 +441,7 @@ class UploadWorker(
439441
username,
440442
)
441443
CommonsApplication
442-
.instance!!
444+
.instance
443445
.clearApplicationData(appContext, logoutListener)
444446
}
445447
}
@@ -581,7 +583,7 @@ class UploadWorker(
581583
* Notify that the current upload has succeeded
582584
* @param contribution
583585
*/
584-
@SuppressLint("StringFormatInvalid")
586+
@SuppressLint("StringFormatInvalid", "MissingPermission")
585587
private fun showSuccessNotification(contribution: Contribution) {
586588
val displayTitle = contribution.media.displayTitle
587589
contribution.state = Contribution.STATE_COMPLETED
@@ -606,7 +608,7 @@ class UploadWorker(
606608
* Notify that the current upload has failed
607609
* @param contribution
608610
*/
609-
@SuppressLint("StringFormatInvalid")
611+
@SuppressLint("StringFormatInvalid", "MissingPermission")
610612
private fun showFailedNotification(contribution: Contribution) {
611613
val displayTitle = contribution.media.displayTitle
612614
currentNotification.setContentIntent(getPendingIntent(UploadProgressActivity::class.java))
@@ -626,7 +628,7 @@ class UploadWorker(
626628
)
627629
}
628630

629-
@SuppressLint("StringFormatInvalid")
631+
@SuppressLint("StringFormatInvalid", "MissingPermission")
630632
private fun showInvalidLoginNotification(contribution: Contribution) {
631633
val displayTitle = contribution.media.displayTitle
632634
currentNotification
@@ -648,7 +650,7 @@ class UploadWorker(
648650
/**
649651
* Shows a notification for a failed contribution upload.
650652
*/
651-
@SuppressLint("StringFormatInvalid")
653+
@SuppressLint("StringFormatInvalid", "MissingPermission")
652654
private fun showErrorNotification(contribution: Contribution) {
653655
val displayTitle = contribution.media.displayTitle
654656
currentNotification
@@ -671,6 +673,7 @@ class UploadWorker(
671673
* Notify that the current upload is paused
672674
* @param contribution
673675
*/
676+
@SuppressLint("MissingPermission")
674677
private fun showPausedNotification(contribution: Contribution) {
675678
val displayTitle = contribution.media.displayTitle
676679

@@ -695,6 +698,7 @@ class UploadWorker(
695698
* Notify that the current upload is cancelled
696699
* @param contribution
697700
*/
701+
@SuppressLint("MissingPermission")
698702
private fun showCancelledNotification(contribution: Contribution) {
699703
val displayTitle = contribution.media.displayTitle
700704
currentNotification.setContentIntent(getPendingIntent(UploadProgressActivity::class.java))

app/src/main/java/fr/free/nrw/commons/utils/CustomSelectorUtils.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class CustomSelectorUtils {
5555
val uploadableFile = PickedFiles.pickedExistingPicture(context, image.uri)
5656
val exifInterface: ExifInterface? =
5757
try {
58-
ExifInterface(uploadableFile.file!!)
58+
ExifInterface(uploadableFile.file)
5959
} catch (e: IOException) {
6060
Timber.e(e)
6161
null

app/src/main/java/fr/free/nrw/commons/utils/DownloadUtils.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ object DownloadUtils {
6262
) {
6363
val systemService =
6464
activity.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
65-
systemService?.enqueue(req)
65+
systemService.enqueue(req)
6666
}
6767
}

app/src/main/java/fr/free/nrw/commons/wikidata/WikidataEditService.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package fr.free.nrw.commons.wikidata
22

33
import android.annotation.SuppressLint
44
import android.content.Context
5+
import android.os.Build
6+
import androidx.annotation.RequiresApi
57
import com.google.gson.Gson
68
import fr.free.nrw.commons.R
79
import fr.free.nrw.commons.contributions.Contribution
@@ -111,12 +113,14 @@ class WikidataEditService @Inject constructor(
111113
.blockingFirst()
112114
}
113115

116+
@SuppressLint("StringFormatInvalid")
114117
private fun showSuccessToast(wikiItemName: String) {
115118
val successStringTemplate = context.getString(R.string.successful_wikidata_edit)
116119
val successMessage = String.format(Locale.getDefault(), successStringTemplate, wikiItemName)
117120
showLongToast(context, successMessage)
118121
}
119122

123+
@RequiresApi(Build.VERSION_CODES.N)
120124
@SuppressLint("CheckResult")
121125
private fun addCaption(
122126
fileEntityId: Long, languageCode: String,
@@ -176,7 +180,7 @@ class WikidataEditService @Inject constructor(
176180
SnakPartial(
177181
"value",
178182
MEDIA_LEGENDS.propertyName, MonoLingualText(
179-
WikiBaseMonolingualTextValue(value!!, key!!)
183+
WikiBaseMonolingualTextValue(value, key)
180184
)
181185
)
182186
)

app/src/test/kotlin/fr/free/nrw/commons/bookmarks/locations/BookmarkLocationControllerTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class BookmarkLocationControllerTest {
6868
@Test
6969
fun loadBookmarkedLocations() {
7070
val bookmarkedLocations =
71-
bookmarkLocationsController!!.loadFavoritesLocations()
71+
bookmarkLocationsController.loadFavoritesLocations()
7272
Assert.assertEquals(2, bookmarkedLocations.size.toLong())
7373
}
7474
}

app/src/test/kotlin/fr/free/nrw/commons/kvstore/JsonKvStoreTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class JsonKvStoreTest {
5050
fun getJson() {
5151
whenever(prefs.getString("key", null)).thenReturn(expected)
5252

53-
val result = store.getJson("key", Person::class.java)
53+
val result = store.getJson<Person>("key")
5454

5555
Assert.assertEquals(testData, result)
5656
}
@@ -70,7 +70,7 @@ class JsonKvStoreTest {
7070
fun getJsonHandlesMalformedJson() {
7171
whenever(prefs.getString("key", null)).thenReturn("junk")
7272

73-
val result = store.getJson("key", Person::class.java)
73+
val result = store.getJson<Person>("key")
7474

7575
Assert.assertNull(result)
7676
}

app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentPresenterTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class NearbyParentFragmentPresenterTest {
305305
whenever(nearbyParentFragmentView.mapFocus).thenReturn(LatLng(2.0, 1.0, 0.0F))
306306
// 111.19 km real distance, return false if 148306.444306 > currentLocationSearchRadius
307307
NearbyController.currentLocationSearchRadius = 148306.0
308-
val isClose = nearbyPresenter?.searchCloseToCurrentLocation()
308+
val isClose = nearbyPresenter.searchCloseToCurrentLocation()
309309
assertFalse(isClose!!.equals(false))
310310
}
311311

@@ -317,7 +317,7 @@ class NearbyParentFragmentPresenterTest {
317317
whenever(nearbyParentFragmentView.getCameraTarget()).thenReturn(LatLng(2.0, 1.0, 0.0F))
318318
// 111.19 km real distance, return false if 148253.333 > currentLocationSearchRadius
319319
NearbyController.currentLocationSearchRadius = 148307.0
320-
val isClose = nearbyPresenter?.searchCloseToCurrentLocation()
320+
val isClose = nearbyPresenter.searchCloseToCurrentLocation()
321321
assertTrue(isClose!!)
322322
}
323323

0 commit comments

Comments
 (0)