Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
Fixed some NPEs
Browse files Browse the repository at this point in the history
  • Loading branch information
DreierF committed Aug 5, 2019
1 parent 7d2b983 commit 19577f0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -269,7 +268,7 @@ class BackupSettingsFragment : SettingsFragmentBase(), IAsyncBackupRestore.OnLoa
}
})
binding.recentBackupsList.adapter = adapter
backup!!.connect(
backup?.connect(
context!!,
object : IAsyncBackupRestore.ConnectionListener {
override fun onLoginCancelled() {
Expand All @@ -282,7 +281,7 @@ class BackupSettingsFragment : SettingsFragmentBase(), IAsyncBackupRestore.OnLoa

override fun onConnected() {
updateBackupLocation()
backup!!.getBackups(this@BackupSettingsFragment)
backup?.getBackups(this@BackupSettingsFragment)
}

override fun onConnectionSuspended() {
Expand All @@ -301,7 +300,7 @@ class BackupSettingsFragment : SettingsFragmentBase(), IAsyncBackupRestore.OnLoa
private fun onBackupsLoaded(list: List<BackupEntry>) {
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()) {
Expand Down Expand Up @@ -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()
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Weather> = ArrayList()

@SerializedName("wind")
var wind: Wind? = null

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 19577f0

Please sign in to comment.