Skip to content

Commit 7d5edfe

Browse files
authored
Merge pull request #270 from AppDevNext/DeprecatedPreferences
Deprecated preferences
2 parents f35fb17 + c018595 commit 7d5edfe

File tree

1 file changed

+12
-16
lines changed
  • ChangeLogLib/src/main/java/info/hannes/changelog

1 file changed

+12
-16
lines changed

ChangeLogLib/src/main/java/info/hannes/changelog/ChangeLog.kt

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package info.hannes.changelog
22

33
import android.app.AlertDialog
44
import android.content.Context
5+
import android.content.Context.MODE_PRIVATE
56
import android.content.SharedPreferences
67
import android.content.pm.PackageManager.NameNotFoundException
78
import android.os.Build
89
import android.os.Handler
910
import android.os.Looper
10-
import android.preference.PreferenceManager
1111
import android.util.Log
1212
import android.util.SparseArray
1313
import androidx.core.util.size
@@ -29,7 +29,7 @@ import java.util.Collections
2929
*/
3030
open class ChangeLog @JvmOverloads constructor(
3131
private val context: Context,
32-
preferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context),
32+
preferences: SharedPreferences = context.getSharedPreferences(PREFERENCES_NAME, MODE_PRIVATE),
3333
protected val css: String = DEFAULT_CSS,
3434
val callback: (() -> Unit)? = null
3535
) {
@@ -153,7 +153,11 @@ open class ChangeLog @JvmOverloads constructor(
153153
* @param context Context that is used to access the resources and to create the ChangeLog dialogs.
154154
* @param css CSS styles that will be used to format the change log.
155155
*/
156-
constructor(context: Context, css: String) : this(context, PreferenceManager.getDefaultSharedPreferences(context), css) {}
156+
constructor(context: Context, css: String) : this(
157+
context = context,
158+
preferences = context.getSharedPreferences(PREFERENCES_NAME, MODE_PRIVATE),
159+
css = css
160+
)
157161

158162
init {
159163
try {
@@ -228,7 +232,8 @@ open class ChangeLog @JvmOverloads constructor(
228232
* Write current version code to the preferences.
229233
*/
230234
protected fun updateVersionInPreferences() {
231-
val sp = PreferenceManager.getDefaultSharedPreferences(context)
235+
236+
val sp = context.getSharedPreferences(PREFERENCES_NAME, MODE_PRIVATE)
232237
val editor = sp.edit()
233238
editor.putInt(VERSION_KEY, currentVersionCode)
234239
editor.apply()
@@ -458,19 +463,10 @@ open class ChangeLog @JvmOverloads constructor(
458463
"li { margin-left: 0px; }" + "\n" +
459464
"ul { padding-left: 2em; }"
460465

461-
/**
462-
* Tag that is used when sending error/debug messages to the log.
463-
*/
464466
private const val LOG_TAG = "ChangeLog"
465467

466-
/**
467-
* This is the key used when storing the version code in SharedPreferences.
468-
*/
469-
protected const val VERSION_KEY = "ChangeLog_last_version_code"
470-
471-
/**
472-
* Constant that used when no version code is available.
473-
*/
474-
protected const val NO_VERSION = -1
468+
const val VERSION_KEY = "ChangeLog_last_version_code"
469+
const val NO_VERSION = -1
470+
const val PREFERENCES_NAME = "changelog"
475471
}
476472
}

0 commit comments

Comments
 (0)