Skip to content

Commit 7b3ca98

Browse files
committed
Deprecated preferences
1 parent f35fb17 commit 7b3ca98

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

  • ChangeLogLib/src/main/java/info/hannes/changelog

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

Lines changed: 11 additions & 4 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()
@@ -472,5 +477,7 @@ open class ChangeLog @JvmOverloads constructor(
472477
* Constant that used when no version code is available.
473478
*/
474479
protected const val NO_VERSION = -1
480+
481+
const val PREFERENCES_NAME = "changelog"
475482
}
476483
}

0 commit comments

Comments
 (0)