diff --git a/app/src/main/java/de/dreier/mytargets/features/settings/backup/BackupSettingsFragment.kt b/app/src/main/java/de/dreier/mytargets/features/settings/backup/BackupSettingsFragment.kt index 812986826..9fbc6e60f 100644 --- a/app/src/main/java/de/dreier/mytargets/features/settings/backup/BackupSettingsFragment.kt +++ b/app/src/main/java/de/dreier/mytargets/features/settings/backup/BackupSettingsFragment.kt @@ -83,7 +83,7 @@ class BackupSettingsFragment : SettingsFragmentBase(), IAsyncBackupRestore.OnLoa * bar. If a sync is active or pending, the progress is shown. */ private val syncStatusObserver = SyncStatusObserver { - activity!!.runOnUiThread { + activity?.runOnUiThread { val account = GenericAccountService.account val syncActive = ContentResolver.isSyncActive(account, SyncUtils.CONTENT_AUTHORITY) val syncPending = ContentResolver.isSyncPending(account, SyncUtils.CONTENT_AUTHORITY) @@ -93,7 +93,7 @@ class BackupSettingsFragment : SettingsFragmentBase(), IAsyncBackupRestore.OnLoa binding.backupProgressBar.isIndeterminate = true binding.backupProgressBar.visibility = if (isRefreshing) VISIBLE else GONE if (wasRefreshing && !isRefreshing && backup != null) { - backup!!.getBackups(this) + backup?.getBackups(this) } } } @@ -183,8 +183,7 @@ class BackupSettingsFragment : SettingsFragmentBase(), IAsyncBackupRestore.OnLoa } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - Timber.d("onActivityResult: ") - backup!!.onActivityResult(requestCode, resultCode, data) + backup?.onActivityResult(requestCode, resultCode, data) if (requestCode == IMPORT_FROM_URI && resultCode == AppCompatActivity.RESULT_OK && data != null) { importFromUri(data.data) } @@ -203,7 +202,7 @@ class BackupSettingsFragment : SettingsFragmentBase(), IAsyncBackupRestore.OnLoa } private fun onBackupIntervalClicked() { - val backupIntervals = Arrays.asList(*EBackupInterval.values()) + val backupIntervals = listOf(*EBackupInterval.values()) MaterialDialog.Builder(context!!) .title(R.string.backup_interval) .items(backupIntervals) @@ -269,7 +268,7 @@ class BackupSettingsFragment : SettingsFragmentBase(), IAsyncBackupRestore.OnLoa } }) binding.recentBackupsList.adapter = adapter - backup!!.connect( + backup?.connect( context!!, object : IAsyncBackupRestore.ConnectionListener { override fun onLoginCancelled() { @@ -282,7 +281,7 @@ class BackupSettingsFragment : SettingsFragmentBase(), IAsyncBackupRestore.OnLoa override fun onConnected() { updateBackupLocation() - backup!!.getBackups(this@BackupSettingsFragment) + backup?.getBackups(this@BackupSettingsFragment) } override fun onConnectionSuspended() { @@ -301,7 +300,7 @@ class BackupSettingsFragment : SettingsFragmentBase(), IAsyncBackupRestore.OnLoa private fun onBackupsLoaded(list: List) { binding.recentBackupsProgress.visibility = GONE binding.recentBackupsList.visibility = VISIBLE - adapter!!.setList(list.toMutableList()) + adapter?.setList(list.toMutableList()) binding.lastBackupLabel.visibility = if (list.isNotEmpty()) VISIBLE else GONE updateLabelTimer?.cancel() if (list.isNotEmpty()) { @@ -359,7 +358,7 @@ class BackupSettingsFragment : SettingsFragmentBase(), IAsyncBackupRestore.OnLoa private fun restoreBackup(item: BackupEntry) { val progress = showRestoreProgressDialog() - backup!!.restoreBackup(item, + backup?.restoreBackup(item, object : IAsyncBackupRestore.BackupStatusListener { override fun onFinished() { progress.dismiss() @@ -374,10 +373,10 @@ class BackupSettingsFragment : SettingsFragmentBase(), IAsyncBackupRestore.OnLoa } private fun deleteBackup(backupEntry: BackupEntry) { - backup!!.deleteBackup(backupEntry, object : IAsyncBackupRestore.BackupStatusListener { + backup?.deleteBackup(backupEntry, object : IAsyncBackupRestore.BackupStatusListener { override fun onFinished() { adapter!!.remove(backupEntry) - backup!!.getBackups(this@BackupSettingsFragment) + backup?.getBackups(this@BackupSettingsFragment) } override fun onError(message: String) { diff --git a/app/src/main/java/de/dreier/mytargets/features/training/environment/CurrentWeather.kt b/app/src/main/java/de/dreier/mytargets/features/training/environment/CurrentWeather.kt index 3e1ee57e6..f11df0306 100644 --- a/app/src/main/java/de/dreier/mytargets/features/training/environment/CurrentWeather.kt +++ b/app/src/main/java/de/dreier/mytargets/features/training/environment/CurrentWeather.kt @@ -20,15 +20,20 @@ import de.dreier.mytargets.features.settings.SettingsManager import de.dreier.mytargets.shared.models.EWeather import de.dreier.mytargets.shared.models.Environment import java.util.* +import kotlin.math.pow +import kotlin.math.roundToInt class CurrentWeather { @SerializedName("cod") var httpCode: Int? = null + @SerializedName("name") var cityName: String = "" + @SerializedName("weather") var weather: List = ArrayList() + @SerializedName("wind") var wind: Wind? = null @@ -37,18 +42,18 @@ class CurrentWeather { } private fun kmhToBeaufort(kmh: Double): Int { - return Math.round(Math.pow(kmh / 3.01, 0.666666666)).toInt() + return (kmh / 3.01).pow(0.666666666).roundToInt() } fun toEnvironment(): Environment { - val code = Integer.parseInt(weather[0].icon!!.substring(0, 2)) + val code = Integer.parseInt(weather[0].icon?.substring(0, 2) ?: "1") val e = Environment() e.indoor = SettingsManager.indoor e.weather = imageCodeToWeather(code) e.windDirection = 0 e.location = cityName e.windDirection = 0 - e.windSpeed = kmhToBeaufort(mpsToKmh(wind!!.speed!!)) + e.windSpeed = kmhToBeaufort(mpsToKmh(wind?.speed ?: 0.0)) return e } diff --git a/build.gradle b/build.gradle index 88f2d4873..015063a99 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0-rc01' + classpath 'com.android.tools.build:gradle:3.5.0-rc02' classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.6' classpath 'com.google.gms:google-services:4.3.0' classpath 'com.google.firebase:firebase-plugins:2.0.0'