Skip to content
This repository was archived by the owner on Aug 16, 2025. It is now read-only.

Commit 1bea32c

Browse files
committed
fix linter warnings
1 parent 9ee620d commit 1bea32c

16 files changed

+158
-191
lines changed

src/main/AndroidManifest.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpx" />
8989
</intent-filter>
9090
<!-- intent filter for all gpx links, independent of mime types -->
91-
<intent-filter>
91+
<intent-filter android:autoVerify="true">
9292
<action android:name="android.intent.action.VIEW" />
9393

9494
<category android:name="android.intent.category.DEFAULT" />
@@ -139,7 +139,7 @@
139139

140140
<data android:scheme="mf-theme" />
141141
</intent-filter>
142-
<intent-filter>
142+
<intent-filter android:autoVerify="true">
143143
<action android:name="android.intent.action.VIEW" />
144144
<action android:name="android.intent.action.SEND" />
145145

@@ -150,7 +150,7 @@
150150
<data android:host="download.mapsforge.org" />
151151
<data android:pathPattern=".*\\.map" />
152152
</intent-filter>
153-
<intent-filter>
153+
<intent-filter android:autoVerify="true">
154154
<action android:name="android.intent.action.VIEW" />
155155
<action android:name="android.intent.action.SEND" />
156156

@@ -162,7 +162,7 @@
162162
<data android:pathPattern="/android/latest/.*\\.map\\.zip" />
163163
<data android:pathPattern="/android/latest/.*\\.zip" />
164164
</intent-filter>
165-
<intent-filter>
165+
<intent-filter android:autoVerify="true">
166166
<action android:name="android.intent.action.VIEW" />
167167
<action android:name="android.intent.action.SEND" />
168168

@@ -173,7 +173,7 @@
173173
<data android:host="ftp.gwdg.de" />
174174
<data android:pathPattern="/pub/misc/openstreetmap/openandromaps/mapsV4/.*\\.zip" />
175175
</intent-filter>
176-
<intent-filter>
176+
<intent-filter android:autoVerify="true">
177177
<action android:name="android.intent.action.VIEW" />
178178
<action android:name="android.intent.action.SEND" />
179179

src/main/kotlin/de/storchp/opentracks/osmplugin/BaseActivity.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import android.os.Build
55
import android.view.View
66
import android.view.WindowManager
77
import androidx.activity.result.ActivityResult
8-
import androidx.activity.result.ActivityResultCallback
98
import androidx.activity.result.ActivityResultLauncher
109
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
1110
import androidx.appcompat.app.AppCompatActivity
@@ -14,12 +13,11 @@ import de.storchp.opentracks.osmplugin.settings.SettingsActivity
1413
abstract class BaseActivity : AppCompatActivity() {
1514

1615
val settingsActivityResultLauncher: ActivityResultLauncher<Intent> =
17-
registerForActivityResult<Intent, ActivityResult>(
18-
StartActivityForResult(),
19-
ActivityResultCallback { result: ActivityResult? -> recreate() })
16+
registerForActivityResult(
17+
StartActivityForResult()
18+
) { result: ActivityResult? -> recreate() }
2019

21-
@Suppress("unused")
22-
fun openSettings(view: View?) {
20+
fun openSettings(@Suppress("unused") view: View?) {
2321
settingsActivityResultLauncher.launch(Intent(this, SettingsActivity::class.java))
2422
}
2523

src/main/kotlin/de/storchp/opentracks/osmplugin/ShowErrorActivity.kt

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.view.MenuItem
88
import android.view.ViewGroup.MarginLayoutParams
99
import androidx.activity.enableEdgeToEdge
1010
import androidx.appcompat.app.AppCompatActivity
11+
import androidx.core.net.toUri
1112
import androidx.core.view.ViewCompat
1213
import androidx.core.view.WindowInsetsCompat
1314
import androidx.core.view.updateLayoutParams
@@ -47,24 +48,23 @@ class ShowErrorActivity : AppCompatActivity() {
4748
return String.format(getString(R.string.error_crash_title), getString(R.string.app_name))
4849
}
4950

50-
private fun reportBug() {
51+
private fun reportBug(): Boolean {
5152
var uriUrl: Uri?
5253
try {
53-
uriUrl = Uri.parse(
54-
String.format(
55-
getString(R.string.report_issue_link),
56-
URLEncoder.encode(
57-
binding.textViewError.getText().toString(),
58-
StandardCharsets.UTF_8.toString()
59-
)
54+
uriUrl = String.format(
55+
getString(R.string.report_issue_link),
56+
URLEncoder.encode(
57+
binding.textViewError.getText().toString(),
58+
StandardCharsets.UTF_8.toString()
6059
)
61-
)
60+
).toUri()
6261
} catch (_: UnsupportedEncodingException) {
6362
// can't happen as UTF-8 is always available
64-
return
63+
return false
6564
}
6665
val intent = Intent(Intent.ACTION_VIEW, uriUrl)
6766
startActivity(intent)
67+
return true
6868
}
6969

7070
override fun onCreateOptionsMenu(menu: Menu): Boolean {
@@ -73,23 +73,20 @@ class ShowErrorActivity : AppCompatActivity() {
7373
}
7474

7575
override fun onOptionsItemSelected(item: MenuItem) =
76-
if (item.itemId == R.id.error_share) {
77-
onClickedShare()
78-
true
79-
} else if (item.itemId == R.id.error_report) {
80-
reportBug()
81-
true
82-
} else {
83-
super.onOptionsItemSelected(item)
76+
when (item.itemId) {
77+
R.id.error_share -> onClickedShare()
78+
R.id.error_report -> reportBug()
79+
else -> super.onOptionsItemSelected(item)
8480
}
8581

86-
private fun onClickedShare() {
82+
private fun onClickedShare(): Boolean {
8783
val intent = Intent(Intent.ACTION_SEND).apply {
8884
putExtra(Intent.EXTRA_SUBJECT, createErrorTitle())
8985
putExtra(Intent.EXTRA_TEXT, binding.textViewError.getText())
9086
setType("text/plain")
9187
}
9288
startActivity(intent)
89+
return true
9390
}
9491

9592
}

src/main/kotlin/de/storchp/opentracks/osmplugin/download/DownloadActivity.kt

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@ import android.view.ViewGroup.MarginLayoutParams
2020
import android.widget.Toast
2121
import androidx.activity.OnBackPressedCallback
2222
import androidx.activity.enableEdgeToEdge
23-
import androidx.activity.result.ActivityResult
24-
import androidx.activity.result.ActivityResultCallback
2523
import androidx.activity.result.ActivityResultLauncher
2624
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
2725
import androidx.appcompat.app.AlertDialog
26+
import androidx.core.net.toUri
2827
import androidx.core.view.ViewCompat
2928
import androidx.core.view.WindowInsetsCompat
3029
import androidx.core.view.updateLayoutParams
3130
import de.storchp.opentracks.osmplugin.BaseActivity
3231
import de.storchp.opentracks.osmplugin.R
3332
import de.storchp.opentracks.osmplugin.databinding.ActivityDownloadBinding
34-
import de.storchp.opentracks.osmplugin.download.DownloadActivity.DownloadBroadcastReceiver
35-
import de.storchp.opentracks.osmplugin.download.DownloadActivity.DownloadType
3633
import de.storchp.opentracks.osmplugin.settings.DirectoryChooserActivity
3734
import de.storchp.opentracks.osmplugin.settings.DirectoryChooserActivity.MapDirectoryChooserActivity
3835
import de.storchp.opentracks.osmplugin.settings.DirectoryChooserActivity.ThemeDirectoryChooserActivity
@@ -44,8 +41,6 @@ import java.io.FileOutputStream
4441
import java.io.IOException
4542
import java.io.InputStream
4643
import java.io.OutputStream
47-
import java.lang.Exception
48-
import java.lang.RuntimeException
4944
import java.util.concurrent.ExecutorService
5045
import java.util.concurrent.Executors
5146
import java.util.zip.ZipEntry
@@ -109,11 +104,7 @@ class DownloadActivity : BaseActivity() {
109104
)
110105
) {
111106
// OpenAndroMaps URIs need to be remapped - mf-v4-map://download.openandromaps.org/mapsV4/Germany/bayern.zip
112-
downloadUri = Uri.parse(
113-
OPENANDROMAPS_MAP_DOWNLOAD_URL + path.substring(
114-
8
115-
)
116-
)
107+
downloadUri = (OPENANDROMAPS_MAP_DOWNLOAD_URL + path.substring(8)).toUri()
117108
downloadType = DownloadType.MAP_ZIP
118109
} else {
119110
// try to replace MF_V4_MAP_SCHEME with https for unknown sources
@@ -127,11 +118,7 @@ class DownloadActivity : BaseActivity() {
127118
&& path.endsWith(".zip")
128119
) {
129120
// no remapping, as they have themes only on their homepage, not on their ftp site
130-
Uri.parse(
131-
OPENANDROMAPS_THEME_DOWNLOAD_URL + path.substring(
132-
8
133-
)
134-
)
121+
(OPENANDROMAPS_THEME_DOWNLOAD_URL + path.substring(8)).toUri()
135122
} else {
136123
// try to replace MF_THEME_SCHEME with https for unknown sources
137124
uri.buildUpon().scheme("https").build()
@@ -182,12 +169,13 @@ class DownloadActivity : BaseActivity() {
182169
}
183170

184171
val directoryIntentLauncher: ActivityResultLauncher<Intent> =
185-
registerForActivityResult<Intent, ActivityResult>(StartActivityForResult(),
186-
ActivityResultCallback { result ->
187-
if (result.resultCode == RESULT_OK) {
188-
startDownload()
189-
}
190-
})
172+
registerForActivityResult(
173+
StartActivityForResult()
174+
) { result ->
175+
if (result.resultCode == RESULT_OK) {
176+
startDownload()
177+
}
178+
}
191179

192180
fun startDownload() {
193181
val directoryUri = downloadType.getDirectoryUri()
@@ -210,12 +198,12 @@ class DownloadActivity : BaseActivity() {
210198
.setTitle(R.string.app_name)
211199
.setMessage(getString(downloadType.overwriteMessageId, filename))
212200
.setPositiveButton(
213-
android.R.string.ok,
214-
DialogInterface.OnClickListener { dialog: DialogInterface?, which: Int ->
215-
file.toFile().delete()
216-
dialog!!.dismiss()
217-
startDownload()
218-
})
201+
android.R.string.ok
202+
) { dialog: DialogInterface?, which: Int ->
203+
file.toFile().delete()
204+
dialog!!.dismiss()
205+
startDownload()
206+
}
219207
.setNegativeButton(android.R.string.cancel, null)
220208
.create().show()
221209
return
@@ -240,7 +228,7 @@ class DownloadActivity : BaseActivity() {
240228
binding.progressBar.setMax(100)
241229
binding.progressBar.progress = 0
242230

243-
executor.execute(Runnable {
231+
executor.execute {
244232
var progress = 0
245233
var isDownloadFinished = false
246234
while (!isDownloadFinished) {
@@ -276,18 +264,16 @@ class DownloadActivity : BaseActivity() {
276264
}
277265
}
278266
}
279-
})
267+
}
280268
}
281269

282-
private val mainHandler = Handler(Looper.getMainLooper(), object : Handler.Callback {
283-
override fun handleMessage(msg: Message): Boolean {
284-
if (msg.what == UPDATE_DOWNLOAD_PROGRESS) {
285-
val downloadProgress = msg.arg1
286-
binding.progressBar.progress = downloadProgress
287-
}
288-
return true
270+
private val mainHandler = Handler(Looper.getMainLooper()) { msg ->
271+
if (msg.what == UPDATE_DOWNLOAD_PROGRESS) {
272+
val downloadProgress = msg.arg1
273+
binding.progressBar.progress = downloadProgress
289274
}
290-
})
275+
true
276+
}
291277

292278
private inner class DownloadBroadcastReceiver : BroadcastReceiver() {
293279
override fun onReceive(context: Context?, intent: Intent) {
@@ -303,7 +289,7 @@ class DownloadActivity : BaseActivity() {
303289
if (status == DownloadManager.STATUS_SUCCESSFUL) {
304290
val uri =
305291
cursor.getString(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI))
306-
downloadEnded(Uri.parse(uri))
292+
downloadEnded(uri.toUri())
307293
}
308294
}
309295
}

src/main/kotlin/de/storchp/opentracks/osmplugin/download/DownloadItemType.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ enum class DownloadItemType(val iconResId: Int, val alt: String) {
88
}
99

1010
fun String.toDownloadItemType() =
11-
DownloadItemType.entries
12-
.filter { downloadItemType: DownloadItemType? -> downloadItemType!!.alt == this }
13-
.firstOrNull()
11+
DownloadItemType.entries.firstOrNull { it.alt == this }

src/main/kotlin/de/storchp/opentracks/osmplugin/download/DownloadMapItem.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ data class DownloadMapItem(
1111
) : Comparable<DownloadMapItem> {
1212
override fun toString() = this.name
1313

14-
override fun compareTo(o: DownloadMapItem) =
15-
if (downloadItemType != o.downloadItemType) {
16-
downloadItemType.compareTo(o.downloadItemType)
14+
override fun compareTo(other: DownloadMapItem) =
15+
if (downloadItemType != other.downloadItemType) {
16+
downloadItemType.compareTo(other.downloadItemType)
1717
} else {
18-
name.compareTo(o.name)
18+
name.compareTo(other.name)
1919
}
2020

2121
}

src/main/kotlin/de/storchp/opentracks/osmplugin/download/DownloadMapSelectionActivity.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.view.ViewGroup.MarginLayoutParams
99
import android.widget.AdapterView
1010
import android.widget.AdapterView.OnItemClickListener
1111
import androidx.activity.enableEdgeToEdge
12+
import androidx.core.net.toUri
1213
import androidx.core.view.ViewCompat
1314
import androidx.core.view.WindowInsetsCompat
1415
import androidx.core.view.updateLayoutParams
@@ -17,7 +18,6 @@ import de.storchp.opentracks.osmplugin.R
1718
import de.storchp.opentracks.osmplugin.databinding.ActivityDownloadMapSelectionBinding
1819
import org.jsoup.Jsoup
1920
import java.io.IOException
20-
import java.lang.RuntimeException
2121

2222
const val MAPS_V_5_DOWNLOAD_URI: String =
2323
"https://ftp-stud.hs-esslingen.de/pub/Mirrors/download.mapsforge.org/maps/v5/"
@@ -39,7 +39,7 @@ class DownloadMapSelectionActivity : BaseActivity() {
3939
}
4040
setContentView(binding.getRoot())
4141

42-
pageUri = Uri.parse(MAPS_V_5_DOWNLOAD_URI)
42+
pageUri = MAPS_V_5_DOWNLOAD_URI.toUri()
4343
val intent = getIntent()
4444
if (intent != null) {
4545
val mapDownloadUri = intent.data
@@ -80,7 +80,7 @@ class DownloadMapSelectionActivity : BaseActivity() {
8080
}
8181
}
8282

83-
Thread(Runnable {
83+
Thread {
8484
try {
8585
val doc = Jsoup.connect(pageUri.toString()).get()
8686
val rows = doc.select("tr")
@@ -111,11 +111,11 @@ class DownloadMapSelectionActivity : BaseActivity() {
111111
}
112112
}
113113
items.sorted()
114-
runOnUiThread(Runnable { adapter.addAll(items) })
114+
runOnUiThread({ adapter.addAll(items) })
115115
} catch (e: IOException) {
116116
throw RuntimeException(e)
117117
}
118-
}).start()
118+
}.start()
119119
}
120120

121121
override fun onOptionsItemSelected(item: MenuItem): Boolean {

0 commit comments

Comments
 (0)