11package cc.chenhe.qqnotifyevo.utils
22
33import android.content.Context
4+ import android.content.SharedPreferences
45import android.content.pm.ApplicationInfo
56import android.content.pm.PackageManager
67import android.os.Build
@@ -36,14 +37,16 @@ const val ICON_TIM = 2
3637@IntDef(ICON_AUTO , ICON_QQ , ICON_TIM )
3738annotation class Icon
3839
40+ private fun sp (context : Context ): SharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
41+
3942// ---------------------------------------------------------
4043// Tips
4144// ---------------------------------------------------------
4245private const val PREF_NEVO_MULTI_MSG_TIP = " tip_nevo_multi_msg"
4346
4447
4548fun nevoMultiMsgTip (context : Context , shouldShow : Boolean ) {
46- PreferenceManager .getDefaultSharedPreferences (context).edit {
49+ sp (context).edit {
4750 putBoolean(PREF_NEVO_MULTI_MSG_TIP , shouldShow)
4851 }
4952}
@@ -58,7 +61,7 @@ fun nevoMultiMsgTip(context: Context): Boolean = PreferenceManager
5861
5962@Mode
6063fun getMode (context : Context ): Int {
61- val mode = PreferenceManager .getDefaultSharedPreferences (context).getString(" mode" , " 0" ) ? : " 0"
64+ val mode = sp (context).getString(" mode" , " 0" ) ? : " 0"
6265 return when (mode.toInt()) {
6366 1 -> MODE_NEVO
6467 2 -> MODE_LEGACY
@@ -67,15 +70,15 @@ fun getMode(context: Context): Int {
6770}
6871
6972fun fetchMode (context : Context ): LiveData <Int > {
70- val source = SpStringLiveData (PreferenceManager .getDefaultSharedPreferences (context), " mode" , " 0" , true )
73+ val source = SpStringLiveData (sp (context), " mode" , " 0" , true )
7174 return Transformations .map(source) { src ->
7275 src!! .toInt()
7376 }
7477}
7578
7679@Icon
7780fun getIconMode (context : Context ): Int {
78- val icon = PreferenceManager .getDefaultSharedPreferences (context).getString(" icon_mode" , " 0" ) ? : " 0"
81+ val icon = sp (context).getString(" icon_mode" , " 0" ) ? : " 0"
7982 return when (icon.toInt()) {
8083 0 -> ICON_AUTO
8184 1 -> ICON_QQ
@@ -84,27 +87,32 @@ fun getIconMode(context: Context): Int {
8487 }
8588}
8689
87- fun showSpecialPrefix (context : Context ): Boolean = PreferenceManager .getDefaultSharedPreferences(context)
88- .getBoolean(" show_special_prefix" , false )
90+ fun showSpecialPrefix (context : Context ): Boolean = sp(context).getBoolean(" show_special_prefix" , false )
91+
92+ /* *
93+ * 特别关注的群消息通知渠道。
94+ *
95+ * @return `true` 为特别关心渠道,`false` 为群消息渠道。
96+ */
97+ fun specialGroupMsgChannel (context : Context ): Boolean = sp(context).getString(" special_group_channel" , " group" ) == " special"
8998
9099fun getAvatarCachePeriod (context : Context ): Long {
91- val s = PreferenceManager .getDefaultSharedPreferences (context).getString(" avatar_cache_period" , " 0" ) ? : " 0"
100+ val s = sp (context).getString(" avatar_cache_period" , " 0" ) ? : " 0"
92101 return s.toLong()
93102}
94103
95104fun fetchAvatarCachePeriod (context : Context ): LiveData <Long > {
96- val source = SpStringLiveData (PreferenceManager .getDefaultSharedPreferences (context), " avatar_cache_period" , " 0" , true )
105+ val source = SpStringLiveData (sp (context), " avatar_cache_period" , " 0" , true )
97106 return Transformations .map(source) { src ->
98107 src?.toLong() ? : 0L
99108 }
100109}
101110
102111fun getShowInRecent (context : Context ): Boolean {
103- return PreferenceManager .getDefaultSharedPreferences (context).getBoolean(" show_in_recent" , true )
112+ return sp (context).getBoolean(" show_in_recent" , true )
104113}
105114
106- fun fetchLog (context : Context ): SpBooleanLiveData = SpBooleanLiveData (PreferenceManager
107- .getDefaultSharedPreferences(context), " log" , false , init = true )
115+ fun fetchLog (context : Context ): SpBooleanLiveData = SpBooleanLiveData (sp(context), " log" , false , init = true )
108116
109117fun getVersion (context : Context ): String {
110118 var versionName = " "
0 commit comments