This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88ee873
commit 1d15d51
Showing
20 changed files
with
237 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.huanchengfly.tieba.post.utils | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import kotlin.properties.ReadWriteProperty | ||
import kotlin.reflect.KProperty | ||
|
||
open class AppPreferencesUtils(context: Context) { | ||
private val preferences: SharedPreferences = | ||
context.getSharedPreferences("settings", Context.MODE_PRIVATE) | ||
//PreferenceManager.getDefaultSharedPreferences(context) | ||
|
||
var loadPictureWhenScroll by SharedPreferenceDelegates.boolean(true) | ||
|
||
private object SharedPreferenceDelegates { | ||
fun int(defaultValue: Int = 0) = object : ReadWriteProperty<AppPreferencesUtils, Int> { | ||
override fun getValue(thisRef: AppPreferencesUtils, property: KProperty<*>): Int { | ||
return thisRef.preferences.getInt(property.name, defaultValue) | ||
} | ||
|
||
override fun setValue( | ||
thisRef: AppPreferencesUtils, | ||
property: KProperty<*>, | ||
value: Int | ||
) { | ||
thisRef.preferences.edit().putInt(property.name, value).apply() | ||
} | ||
} | ||
|
||
fun long(defaultValue: Long = 0L) = | ||
object : ReadWriteProperty<AppPreferencesUtils, Long> { | ||
override fun getValue( | ||
thisRef: AppPreferencesUtils, | ||
property: KProperty<*> | ||
): Long { | ||
return thisRef.preferences.getLong(property.name, defaultValue) | ||
} | ||
|
||
override fun setValue( | ||
thisRef: AppPreferencesUtils, | ||
property: KProperty<*>, | ||
value: Long | ||
) { | ||
thisRef.preferences.edit().putLong(property.name, value).apply() | ||
} | ||
} | ||
|
||
fun boolean(defaultValue: Boolean = false) = | ||
object : ReadWriteProperty<AppPreferencesUtils, Boolean> { | ||
override fun getValue( | ||
thisRef: AppPreferencesUtils, | ||
property: KProperty<*> | ||
): Boolean { | ||
return thisRef.preferences.getBoolean(property.name, defaultValue) | ||
} | ||
|
||
override fun setValue( | ||
thisRef: AppPreferencesUtils, | ||
property: KProperty<*>, | ||
value: Boolean | ||
) { | ||
thisRef.preferences.edit().putBoolean(property.name, value).apply() | ||
} | ||
} | ||
|
||
fun float(defaultValue: Float = 0.0f) = | ||
object : ReadWriteProperty<AppPreferencesUtils, Float> { | ||
override fun getValue( | ||
thisRef: AppPreferencesUtils, | ||
property: KProperty<*> | ||
): Float { | ||
return thisRef.preferences.getFloat(property.name, defaultValue) | ||
} | ||
|
||
override fun setValue( | ||
thisRef: AppPreferencesUtils, | ||
property: KProperty<*>, | ||
value: Float | ||
) { | ||
thisRef.preferences.edit().putFloat(property.name, value).apply() | ||
} | ||
} | ||
|
||
fun string(defaultValue: String? = null) = | ||
object : ReadWriteProperty<AppPreferencesUtils, String?> { | ||
override fun getValue( | ||
thisRef: AppPreferencesUtils, | ||
property: KProperty<*> | ||
): String? { | ||
return thisRef.preferences.getString(property.name, defaultValue) | ||
} | ||
|
||
override fun setValue( | ||
thisRef: AppPreferencesUtils, | ||
property: KProperty<*>, | ||
value: String? | ||
) { | ||
thisRef.preferences.edit().putString(property.name, value).apply() | ||
} | ||
} | ||
|
||
fun stringSet(defaultValue: Set<String>? = null) = | ||
object : ReadWriteProperty<AppPreferencesUtils, Set<String>?> { | ||
override fun getValue( | ||
thisRef: AppPreferencesUtils, | ||
property: KProperty<*> | ||
): Set<String>? { | ||
return thisRef.preferences.getStringSet(property.name, defaultValue) | ||
} | ||
|
||
override fun setValue( | ||
thisRef: AppPreferencesUtils, | ||
property: KProperty<*>, | ||
value: Set<String>? | ||
) { | ||
thisRef.preferences.edit().putStringSet(property.name, value).apply() | ||
} | ||
} | ||
} | ||
|
||
val Context.appPreferences: AppPreferencesUtils | ||
get() = AppPreferencesUtils(this) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M6,4v3.17c0,0.53 0.21,1.04 0.59,1.42L10,12l-3.42,3.42c-0.37,0.38 -0.58,0.89 -0.58,1.42V20c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2v-3.16c0,-0.53 -0.21,-1.04 -0.58,-1.41L14,12l3.41,-3.4c0.38,-0.38 0.59,-0.89 0.59,-1.42V4c0,-1.1 -0.9,-2 -2,-2H8c-1.1,0 -2,0.9 -2,2z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M12,2C6.48,2 2,6.48 2,12c0,5.52 4.48,10 10,10s10,-4.48 10,-10C22,6.48 17.52,2 12,2zM9,12c-0.55,0 -1,-0.45 -1,-1V8c0,-0.55 0.45,-1 1,-1s1,0.45 1,1v3C10,11.55 9.55,12 9,12zM13,18h-2c-0.55,0 -1,-0.45 -1,-1v-0.89c0,-1 0.68,-1.92 1.66,-2.08C12.92,13.82 14,14.79 14,16v1C14,17.55 13.55,18 13,18zM16,11c0,0.55 -0.45,1 -1,1c-0.55,0 -1,-0.45 -1,-1V8c0,-0.55 0.45,-1 1,-1c0.55,0 1,0.45 1,1V11z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M19,19h2v2h-2v-2zM19,17h2v-2h-2v2zM3,13h2v-2L3,11v2zM3,17h2v-2L3,15v2zM3,9h2L5,7L3,7v2zM3,5h2L5,3L3,3v2zM7,5h2L9,3L7,3v2zM15,21h2v-2h-2v2zM11,21h2v-2h-2v2zM15,21h2v-2h-2v2zM7,21h2v-2L7,19v2zM3,21h2v-2L3,19v2zM21,8c0,-2.76 -2.24,-5 -5,-5h-5v2h5c1.65,0 3,1.35 3,3v5h2L21,8z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M23,12l-2.44,-2.79l0.34,-3.69l-3.61,-0.82L15.4,1.5L12,2.96L8.6,1.5L6.71,4.69L3.1,5.5L3.44,9.2L1,12l2.44,2.79l-0.34,3.7l3.61,0.82L8.6,22.5l3.4,-1.47l3.4,1.46l1.89,-3.19l3.61,-0.82l-0.34,-3.69L23,12zM9.38,16.01L7,13.61c-0.39,-0.39 -0.39,-1.02 0,-1.41l0.07,-0.07c0.39,-0.39 1.03,-0.39 1.42,0l1.61,1.62l5.15,-5.16c0.39,-0.39 1.03,-0.39 1.42,0l0.07,0.07c0.39,0.39 0.39,1.02 0,1.41l-5.92,5.94C10.41,16.4 9.78,16.4 9.38,16.01z" /> | ||
</vector> |
Oops, something went wrong.