Skip to content

Commit cbd5cea

Browse files
author
Chenhe
committed
新增特别关注群消息的通知渠道选项
1 parent 66d29c7 commit cbd5cea

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

app/src/main/java/cc/chenhe/qqnotifyevo/core/NotificationProcessor.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ abstract class NotificationProcessor(context: Context) {
295295
original.contentIntent, original.deleteIntent, special)
296296
deleteOldMessage(conversation, if (isMulti) 0 else matchMessageNum(title))
297297
Timber.tag(TAG).d("[${if (special) "GroupS" else "Group"}] Name: $name; Group: $groupName; Text: $text")
298-
return renewConversionNotification(context, tag, NotifyChannel.GROUP, conversation, sbn, original)
298+
val channel = if (special && specialGroupMsgChannel(ctx))
299+
NotifyChannel.FRIEND_SPECIAL
300+
else
301+
NotifyChannel.GROUP
302+
return renewConversionNotification(context, tag, channel, conversation, sbn, original)
299303
}
300304
}
301305

app/src/main/java/cc/chenhe/qqnotifyevo/utils/PreferencesUtils.kt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cc.chenhe.qqnotifyevo.utils
22

33
import android.content.Context
4+
import android.content.SharedPreferences
45
import android.content.pm.ApplicationInfo
56
import android.content.pm.PackageManager
67
import android.os.Build
@@ -36,14 +37,16 @@ const val ICON_TIM = 2
3637
@IntDef(ICON_AUTO, ICON_QQ, ICON_TIM)
3738
annotation class Icon
3839

40+
private fun sp(context: Context): SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
41+
3942
// ---------------------------------------------------------
4043
// Tips
4144
// ---------------------------------------------------------
4245
private const val PREF_NEVO_MULTI_MSG_TIP = "tip_nevo_multi_msg"
4346

4447

4548
fun 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
6063
fun 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

6972
fun 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
7780
fun 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

9099
fun 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

95104
fun 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

102111
fun 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

109117
fun getVersion(context: Context): String {
110118
var versionName = ""

app/src/main/res/values/strings.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@
140140
<string name="pref_cate_advanced_notify">通知</string>
141141
<string name="pref_advanced_show_special_prefix">显示特别关心前缀</string>
142142
<string name="pref_advanced_show_special_prefix_summary">添加[特别关心]或群聊中[特别关注]前缀</string>
143+
<string name="pref_advanced_special_group_channel">特别关注群消息的通知渠道</string>
144+
<string-array name="pref_advanced_special_group_channel_entries">
145+
<item>群消息</item>
146+
<item>特别关心消息</item>
147+
</string-array>
148+
<string-array name="pref_advanced_special_group_channel_values">
149+
<item>group</item>
150+
<item>special</item>
151+
</string-array>
143152
<!-- 其他 -->
144153
<string name="pref_cate_advanced_other">其他</string>
145154
<string name="pref_avatar_cache_period">头像缓存刷新间隔</string>

app/src/main/res/xml/pref_advanced.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
app:key="show_special_prefix"
99
app:summary="@string/pref_advanced_show_special_prefix_summary"
1010
app:title="@string/pref_advanced_show_special_prefix" />
11+
12+
<ListPreference
13+
app:defaultValue="group"
14+
app:entries="@array/pref_advanced_special_group_channel_entries"
15+
app:entryValues="@array/pref_advanced_special_group_channel_values"
16+
app:key="special_group_channel"
17+
app:title="@string/pref_advanced_special_group_channel"
18+
app:useSimpleSummaryProvider="true" />
1119
</PreferenceCategory>
1220

1321
<PreferenceCategory app:title="@string/pref_cate_advanced_other">

0 commit comments

Comments
 (0)