Skip to content

Commit

Permalink
Fixes after changing targetSdk to 29, migrate to androidx.preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
arcao committed Nov 18, 2020
1 parent cd476fd commit df27319
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 162 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ dependencies {
implementation "androidx.cardview:cardview:$card_view_version"
implementation "com.google.android.material:material:$material_version"
implementation "androidx.constraintlayout:constraintlayout:$constraint_layout_version"
implementation "androidx.preference:preference:$preference_version"
implementation "androidx.preference:preference-ktx:$preference_version"

implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"

implementation "androidx.core:core-ktx:$core_version"
Expand All @@ -23,7 +23,7 @@ dependencies {
implementation "androidx.fragment:fragment-ktx:$fragment_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.multidex:multidex:$multidex_version"
implementation "androidx.paging:paging-runtime:$paging_version"
implementation "androidx.paging:paging-runtime-ktx:$paging_version"

coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:$desugar_jdk_libs_version"

Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@
<intent-filter>
<action android:name="locus.api.android.INTENT_ITEM_MAIN_FUNCTION_GC" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/arcao/feedback/FeedbackHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ class FeedbackHelper(
}
}

@Suppress("BlockingMethodInNonBlockingContext")
@Throws(IOException::class)
private suspend fun createReport(reportFile: File) {
reportFile.parentFile.mkdirs()
reportFile.parentFile?.mkdirs()

if (reportFile.exists()) {
Timber.d("Report file $reportFile already exist.")
Expand All @@ -78,6 +79,7 @@ class FeedbackHelper(
Timber.d("Report created.")
}

@Suppress("BlockingMethodInNonBlockingContext")
@Throws(IOException::class)
private suspend fun writeCollectors(zos: ZipOutputStream) {
for (collector in collectors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.util.SparseArray
import timber.log.Timber
import java.lang.reflect.Field
import java.lang.reflect.Modifier
import java.util.Locale

class ConfigurationCollector(private val context: Context) : Collector() {
override val name: String
Expand Down Expand Up @@ -122,7 +123,7 @@ class ConfigurationCollector(private val context: Context) : Collector() {
if (f.type == Int::class.javaPrimitiveType) {
result.append(getFieldValueName(conf, f))
} else if (f.get(conf) != null) {
result.append(f.get(conf).toString())
result.append(f.get(conf)?.toString())
}
result.append('\n')
}
Expand Down Expand Up @@ -156,7 +157,7 @@ class ConfigurationCollector(private val context: Context) : Collector() {
FIELD_SCREENLAYOUT -> return activeFlags(VALUE_ARRAYS[PREFIX_SCREENLAYOUT]!!, f.getInt(conf))
else -> {
val values =
VALUE_ARRAYS[fieldName.toUpperCase() + '_'] // Unknown field, return the raw int as String
VALUE_ARRAYS[fieldName.toUpperCase(Locale.ROOT) + '_'] // Unknown field, return the raw int as String
?: return f.getInt(conf).toString()

return values.get(f.getInt(conf)) // Unknown value, return the raw int as String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ConstantsCollector(private val source: Class<*>, private val prefix: Strin
result.append(
when (val value = field.get(null)) {
is Array<*> -> Arrays.toString(value)
else -> value.toString()
else -> value?.toString()
}
)
} catch (e: IllegalArgumentException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.arcao.feedback.collector

import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager
import androidx.preference.PreferenceManager

class SharedPreferencesCollector @JvmOverloads constructor(
private val context: Context,
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/arcao/geocaching4locus/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ package com.arcao.geocaching4locus
import android.app.Application
import android.content.Context
import android.os.Build
import android.preference.PreferenceManager
import android.webkit.CookieManager
import android.webkit.CookieSyncManager
import androidx.annotation.WorkerThread
import androidx.core.content.edit
import androidx.core.content.pm.PackageInfoCompat
import androidx.multidex.MultiDex
import androidx.preference.PreferenceManager
import com.arcao.feedback.feedbackModule
import com.arcao.geocaching4locus.authentication.util.isPremium
import com.arcao.geocaching4locus.base.constants.CrashlyticsConstants
Expand Down Expand Up @@ -46,7 +46,7 @@ class App : Application() {
putString(PrefConstants.DEVICE_ID, value)
}
}
value
value.orEmpty()
}

val version: String by lazy {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.arcao.geocaching4locus.authentication.util

import android.content.Context
import android.preference.PreferenceManager
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import com.arcao.geocaching4locus.base.constants.AppConstants
import com.arcao.geocaching4locus.base.constants.PrefConstants
import com.arcao.geocaching4locus.data.api.model.User
Expand Down Expand Up @@ -104,9 +104,9 @@ class AccountRestrictions internal constructor(context: Context) {
putString(PrefConstants.FILTER_TERRAIN_MAX, "5")

// multi-select filters (select all)
for (i in 0 until AppConstants.GEOCACHE_TYPES.size)
for (i in AppConstants.GEOCACHE_TYPES.indices)
putBoolean(PrefConstants.FILTER_CACHE_TYPE_PREFIX + i, true)
for (i in 0 until AppConstants.GEOCACHE_SIZES.size)
for (i in AppConstants.GEOCACHE_SIZES.indices)
putBoolean(PrefConstants.FILTER_CONTAINER_TYPE_PREFIX + i, true)
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ImportUrlViewModel(
return@computationContext null
}

val guid = guidMatcher.group(1)
val guid = guidMatcher.group(1) ?: return@computationContext null

return@computationContext getGeocacheCodeFromGuid(guid)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import android.os.Build
import android.os.Handler
import android.os.Looper
import android.os.SystemClock
import android.preference.PreferenceManager
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.annotation.StringRes
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import com.arcao.geocaching4locus.R
import com.arcao.geocaching4locus.base.constants.AppConstants
import com.arcao.geocaching4locus.base.constants.PrefConstants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SettingsActivity : AbstractActionBarActivity(),
showFragment(
supportFragmentManager.fragmentFactory.instantiate(
classLoader,
intent.getStringExtra(EXTRA_SHOW_FRAGMENT)
requireNotNull(intent?.getStringExtra(EXTRA_SHOW_FRAGMENT))
)
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.arcao.geocaching4locus.settings.manager

import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import com.arcao.geocaching4locus.base.constants.AppConstants
import com.arcao.geocaching4locus.base.constants.PrefConstants
import com.arcao.geocaching4locus.base.util.getParsedFloat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.arcao.geocaching4locus.settings.manager

import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager
import androidx.preference.PreferenceManager
import com.arcao.geocaching4locus.authentication.util.isPremium
import com.arcao.geocaching4locus.base.constants.AppConstants
import com.arcao.geocaching4locus.base.constants.PrefConstants
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/locus/api/manager/LocusMapManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ class LocusMapManager(

val parentDirectory = cacheFile.parentFile

if (!parentDirectory.mkdirs()) {
if (parentDirectory?.mkdirs() == false) {
Timber.w("Directory '%s' not created, maybe exists.", parentDirectory)
}

if (!parentDirectory.isDirectory)
if (parentDirectory?.isDirectory == false)
throw IllegalStateException("Directory $parentDirectory not exist.")

return cacheFile
Expand All @@ -97,7 +97,7 @@ class LocusMapManager(
val file = cacheFile

// make sure the path exist
file.parentFile.mkdirs()
file.parentFile?.mkdirs()

val fos = FileOutputStream(file)
fos.flush()
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/locus/api/mapper/GeocacheConverter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@ class GeocacheConverter(

var waypointType = AdditionalWaypointType.REFERENCE_POINT

if (nameMatcher.find() && nameMatcher.group(1).trim { it <= ' ' }.isNotEmpty()) {
name = nameMatcher.group(1).trim { it <= ' ' }
if (nameMatcher.find() && nameMatcher.group(1).orEmpty().trim { it <= ' ' }
.isNotEmpty()) {
name = nameMatcher.group(1).orEmpty().trim { it <= ' ' }

if (FINAL_WAYPOINT_NAME_PATTERN.matcher(name).matches()) {
waypointType = AdditionalWaypointType.FINAL_LOCATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object SpanFormatter {
/**
* Version of [String.format] that works on [Spanned] strings to preserve rich text formatting.
* Both the `format` as well as any `%s args` can be Spanned and will have their formatting preserved.
* Due to the way [Spannable]s work, any argument's spans will can only be included **once** in the result.
* Due to the way [Spanned]s work, any argument's spans will can only be included **once** in the result.
* Any duplicates will appear as text only.
*
* @param format the format string (see [String.format])
Expand All @@ -51,7 +51,7 @@ object SpanFormatter {
/**
* Version of [String.format] that works on [Spanned] strings to preserve rich text formatting.
* Both the `format` as well as any `%s args` can be Spanned and will have their formatting preserved.
* Due to the way [Spannable]s work, any argument's spans will can only be included **once** in the result.
* Due to the way [Spanned]s work, any argument's spans will can only be included **once** in the result.
* Any duplicates will appear as text only.
*
* @param locale the locale to apply; `null` value means no localization.
Expand All @@ -73,9 +73,9 @@ object SpanFormatter {
i = m.start()
val exprEnd = m.end()

val argTerm = m.group(1)
val modTerm = m.group(2)
val typeTerm = m.group(3)
val argTerm = m.group(1).orEmpty()
val modTerm = m.group(2).orEmpty()
val typeTerm = m.group(3).orEmpty()

val cookedArg: CharSequence

Expand Down Expand Up @@ -119,4 +119,4 @@ object SpanFormatter {

return spannableString
}
}
}
Loading

0 comments on commit df27319

Please sign in to comment.