Skip to content

Commit faf64bb

Browse files
author
Chenhe
committed
调整代码样式
1 parent 3af1432 commit faf64bb

File tree

15 files changed

+252
-151
lines changed

15 files changed

+252
-151
lines changed

app/src/main/java/cc/chenhe/qqnotifyevo/MyApplication.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class MyApplication : Application() {
3636
Thread.setDefaultUncaughtExceptionHandler(CrashHandler)
3737
Timber.tag(TAG).i("\n\n")
3838
Timber.tag(TAG).i("==================================================")
39-
Timber.tag(TAG).i("= App Create")
39+
Timber.tag(TAG).i("= App Create ver: ${getVersion(this)}")
4040
Timber.tag(TAG).i("==================================================\n")
4141
registerNotificationChannel()
4242

@@ -76,16 +76,19 @@ class MyApplication : Application() {
7676

7777
private fun registerNotificationChannel() {
7878
Timber.tag(TAG).d("Register system notification channels")
79-
val group = NotificationChannelGroup(NOTIFY_QQ_GROUP_ID, getString(R.string.notify_group_base))
79+
val group =
80+
NotificationChannelGroup(NOTIFY_QQ_GROUP_ID, getString(R.string.notify_group_base))
8081

8182

8283
val att = AudioAttributes.Builder()
83-
.setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT)
84-
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
85-
.build()
86-
val tipChannel = NotificationChannel(NOTIFY_SELF_TIPS_CHANNEL_ID,
87-
getString(R.string.notify_self_tips_channel_name),
88-
NotificationManager.IMPORTANCE_DEFAULT).apply {
84+
.setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT)
85+
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
86+
.build()
87+
val tipChannel = NotificationChannel(
88+
NOTIFY_SELF_TIPS_CHANNEL_ID,
89+
getString(R.string.notify_self_tips_channel_name),
90+
NotificationManager.IMPORTANCE_DEFAULT
91+
).apply {
8992
setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), att)
9093
}
9194

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import kotlin.math.min
2020
* @param period 缓存有效期(毫秒)。
2121
*/
2222
class AvatarManager private constructor(
23-
private val cacheDir: File,
24-
var period: Long
23+
private val cacheDir: File,
24+
var period: Long
2525
) {
2626

2727
companion object {
@@ -41,8 +41,9 @@ class AvatarManager private constructor(
4141
}
4242
}
4343

44-
private class AvatarLruCache : LruCache<Int, Bitmap>(min((Runtime.getRuntime().freeMemory() / 4),
45-
MAX_MEMORY_CACHE_SIZE).toInt()) {
44+
private class AvatarLruCache : LruCache<Int, Bitmap>(
45+
min((Runtime.getRuntime().freeMemory() / 4), MAX_MEMORY_CACHE_SIZE).toInt()
46+
) {
4647
override fun sizeOf(key: Int, value: Bitmap): Int {
4748
return value.allocationByteCount
4849
}
@@ -81,7 +82,8 @@ class AvatarManager private constructor(
8182
lru.put(conversionId, it)
8283
}
8384
} catch (e: Exception) {
84-
Timber.tag(TAG).e("Decode avatar file error, delete the cache. conversionId=$conversionId")
85+
Timber.tag(TAG)
86+
.e("Decode avatar file error, delete the cache. conversionId=$conversionId")
8587
e.printStackTrace()
8688
file.delete()
8789
lru.remove(conversionId)

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import java.util.*
2020
* 将会遍历所有历史会话并分别发送通知。
2121
*/
2222
class InnerNotificationProcessor(
23-
private val commander: Commander,
24-
context: Context
23+
private val commander: Commander,
24+
context: Context,
2525
) : NotificationProcessor(context) {
2626

2727
companion object {
@@ -57,14 +57,15 @@ class InnerNotificationProcessor(
5757
}
5858
}
5959

60-
private fun sendNotification(context: Context, tag: Tag, id: Int,
61-
notification: Notification) {
60+
private fun sendNotification(context: Context, tag: Tag, id: Int, notification: Notification) {
6261
NotificationManagerCompat.from(context).notify(id, notification)
6362
addNotifyId(tag, id)
6463
}
6564

66-
override fun renewQzoneNotification(context: Context, tag: Tag, conversation: Conversation,
67-
sbn: StatusBarNotification, original: Notification): Notification {
65+
override fun renewQzoneNotification(
66+
context: Context, tag: Tag, conversation: Conversation,
67+
sbn: StatusBarNotification, original: Notification
68+
): Notification {
6869

6970
val notification = createQZoneNotification(context, tag, conversation, original).apply {
7071
contentIntent = original.contentIntent
@@ -76,14 +77,20 @@ class InnerNotificationProcessor(
7677
return notification
7778
}
7879

79-
override fun renewConversionNotification(context: Context, tag: Tag, channel: NotifyChannel,
80-
conversation: Conversation, sbn: StatusBarNotification,
81-
original: Notification): Notification {
80+
override fun renewConversionNotification(
81+
context: Context,
82+
tag: Tag,
83+
channel: NotifyChannel,
84+
conversation: Conversation,
85+
sbn: StatusBarNotification,
86+
original: Notification
87+
): Notification {
8288
val history = getHistoryMessage(tag)
8389
var notification: Notification? = null
8490
for (c in history) {
8591
if (c.name != conversation.name || c.isGroup && channel != NotifyChannel.GROUP ||
86-
!c.isGroup && channel == NotifyChannel.GROUP) {
92+
!c.isGroup && channel == NotifyChannel.GROUP
93+
) {
8794
// 确保只刷新新增的通知
8895
continue
8996
}

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

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,24 @@ class NevoNotificationProcessor(context: Context) : NotificationProcessor(contex
2222
private const val REQ_MULTI_MSG_DONT_SHOW = 2
2323
}
2424

25-
override fun renewQzoneNotification(context: Context, tag: Tag, conversation: Conversation,
26-
sbn: StatusBarNotification, original: Notification): Notification {
25+
override fun renewQzoneNotification(
26+
context: Context,
27+
tag: Tag,
28+
conversation: Conversation,
29+
sbn: StatusBarNotification,
30+
original: Notification
31+
): Notification {
2732
return createQZoneNotification(context, tag, conversation, original)
2833
}
2934

30-
override fun renewConversionNotification(context: Context, tag: Tag, channel: NotifyChannel,
31-
conversation: Conversation, sbn: StatusBarNotification,
32-
original: Notification): Notification {
35+
override fun renewConversionNotification(
36+
context: Context,
37+
tag: Tag,
38+
channel: NotifyChannel,
39+
conversation: Conversation,
40+
sbn: StatusBarNotification,
41+
original: Notification
42+
): Notification {
3343
return createConversationNotification(context, tag, channel, conversation, original)
3444
}
3545

@@ -40,30 +50,42 @@ class NevoNotificationProcessor(context: Context) : NotificationProcessor(contex
4050
return
4151
}
4252
if (nevoMultiMsgTip(ctx)) {
43-
val dontShow = PendingIntent.getBroadcast(ctx, REQ_MULTI_MSG_DONT_SHOW,
44-
Intent(ctx, StaticReceiver::class.java).also {
45-
it.action = ACTION_MULTI_MSG_DONT_SHOW
46-
}, PendingIntent.FLAG_UPDATE_CURRENT)
53+
val dontShow = PendingIntent.getBroadcast(
54+
ctx, REQ_MULTI_MSG_DONT_SHOW,
55+
Intent(ctx, StaticReceiver::class.java).also {
56+
it.action = ACTION_MULTI_MSG_DONT_SHOW
57+
}, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
58+
)
4759

48-
val learnMore = PendingIntent.getActivity(ctx, REQ_MULTI_MSG_LEARN_MORE,
49-
Intent(ctx, PreferenceAty::class.java).also {
50-
it.putExtra(PreferenceAty.EXTRA_NEVO_MULTI_MSG, true)
51-
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
52-
}, PendingIntent.FLAG_UPDATE_CURRENT)
60+
val learnMore = PendingIntent.getActivity(
61+
ctx, REQ_MULTI_MSG_LEARN_MORE,
62+
Intent(ctx, PreferenceAty::class.java).also {
63+
it.putExtra(PreferenceAty.EXTRA_NEVO_MULTI_MSG, true)
64+
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
65+
}, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
66+
)
5367

5468
val style = NotificationCompat.BigTextStyle()
55-
.setBigContentTitle(ctx.getString(R.string.notify_multi_msg_title))
56-
.bigText(ctx.getString(R.string.notify_multi_msg_content))
69+
.setBigContentTitle(ctx.getString(R.string.notify_multi_msg_title))
70+
.bigText(ctx.getString(R.string.notify_multi_msg_content))
5771
val n = NotificationCompat.Builder(ctx, NOTIFY_SELF_TIPS_CHANNEL_ID)
58-
.setStyle(style)
59-
.setAutoCancel(true)
60-
.setContentTitle(ctx.getString(R.string.notify_multi_msg_title))
61-
.setContentText(ctx.getString(R.string.notify_multi_msg_content))
62-
.setSmallIcon(R.drawable.ic_notify_warning)
63-
.setContentIntent(learnMore)
64-
.addAction(R.drawable.ic_notify_action_dnot_show, ctx.getString(R.string.dont_show), dontShow)
65-
.addAction(R.drawable.ic_notify_action_learn_more, ctx.getString(R.string.learn_more), learnMore)
66-
.build()
72+
.setStyle(style)
73+
.setAutoCancel(true)
74+
.setContentTitle(ctx.getString(R.string.notify_multi_msg_title))
75+
.setContentText(ctx.getString(R.string.notify_multi_msg_content))
76+
.setSmallIcon(R.drawable.ic_notify_warning)
77+
.setContentIntent(learnMore)
78+
.addAction(
79+
R.drawable.ic_notify_action_dnot_show,
80+
ctx.getString(R.string.dont_show),
81+
dontShow
82+
)
83+
.addAction(
84+
R.drawable.ic_notify_action_learn_more,
85+
ctx.getString(R.string.learn_more),
86+
learnMore
87+
)
88+
.build()
6789

6890
NotificationManagerCompat.from(ctx).notify(NOTIFY_ID_MULTI_MSG, n)
6991
}

app/src/main/java/cc/chenhe/qqnotifyevo/log/LogWriter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import java.util.*
77
import kotlin.math.abs
88

99
class LogWriter(
10-
private val logDir: File,
11-
time: Long = System.currentTimeMillis()
10+
private val logDir: File,
11+
time: Long = System.currentTimeMillis()
1212
) : AutoCloseable {
1313

1414
companion object {

app/src/main/java/cc/chenhe/qqnotifyevo/preference/PermissionFr.kt

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,31 @@ class PermissionFr : PreferenceFragmentCompat() {
6666
}
6767
"auto_start" -> {
6868
AlertDialog.Builder(context)
69-
.setTitle(R.string.pref_auto_start)
70-
.setMessage(R.string.pref_auto_start_message)
71-
.setPositiveButton(R.string.confirm, null)
72-
.show()
69+
.setTitle(R.string.pref_auto_start)
70+
.setMessage(R.string.pref_auto_start_message)
71+
.setPositiveButton(R.string.confirm, null)
72+
.show()
7373
return true
7474
}
7575
}
7676
return super.onPreferenceTreeClick(preference)
7777
}
7878

7979
private fun refreshSummary() {
80-
notification.summary = getString(if (isNotificationListenerEnabled(ctx))
81-
R.string.pref_enable_permit else R.string.pref_disable_permit)
82-
83-
accessibility.summary = getString(if (isAccessibilitySettingsOn(ctx))
84-
R.string.pref_enable_permit else R.string.pref_disable_permit)
85-
86-
battery.summary = getString(if (isIgnoreBatteryOptimization(ctx))
87-
R.string.pref_battery_optimize_disable else R.string.pref_battery_optimize_enable)
80+
notification.summary = getString(
81+
if (isNotificationListenerEnabled(ctx))
82+
R.string.pref_enable_permit else R.string.pref_disable_permit
83+
)
84+
85+
accessibility.summary = getString(
86+
if (isAccessibilitySettingsOn(ctx))
87+
R.string.pref_enable_permit else R.string.pref_disable_permit
88+
)
89+
90+
battery.summary = getString(
91+
if (isIgnoreBatteryOptimization(ctx))
92+
R.string.pref_battery_optimize_disable else R.string.pref_battery_optimize_enable
93+
)
8894
}
8995

9096
private fun isNotificationListenerEnabled(context: Context): Boolean {
@@ -94,19 +100,24 @@ class PermissionFr : PreferenceFragmentCompat() {
94100

95101
private fun isAccessibilitySettingsOn(context: Context): Boolean {
96102
var accessibilityEnabled = 0
97-
val service = context.packageName + "/" + AccessibilityMonitorService::class.java.canonicalName
103+
val service =
104+
context.packageName + "/" + AccessibilityMonitorService::class.java.canonicalName
98105
try {
99-
accessibilityEnabled = Settings.Secure.getInt(context.applicationContext.contentResolver,
100-
Settings.Secure.ACCESSIBILITY_ENABLED)
106+
accessibilityEnabled = Settings.Secure.getInt(
107+
context.applicationContext.contentResolver,
108+
Settings.Secure.ACCESSIBILITY_ENABLED
109+
)
101110
} catch (e: Settings.SettingNotFoundException) {
102111
e.printStackTrace()
103112
}
104113

105114
val mStringColonSplitter = TextUtils.SimpleStringSplitter(':')
106115

107116
if (accessibilityEnabled == 1) {
108-
val settingValue = Settings.Secure.getString(context.applicationContext.contentResolver,
109-
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES)
117+
val settingValue = Settings.Secure.getString(
118+
context.applicationContext.contentResolver,
119+
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES
120+
)
110121
if (settingValue != null) {
111122
mStringColonSplitter.setString(settingValue)
112123
while (mStringColonSplitter.hasNext()) {
@@ -140,11 +151,12 @@ class PermissionFr : PreferenceFragmentCompat() {
140151
@SuppressLint("BatteryLife")
141152
private fun ignoreBatteryOptimization(activity: Activity) {
142153
val powerManager = activity.getSystemService(POWER_SERVICE) as PowerManager
143-
val hasIgnored: Boolean
144-
hasIgnored = powerManager.isIgnoringBatteryOptimizations(activity.packageName)
154+
val hasIgnored: Boolean = powerManager.isIgnoringBatteryOptimizations(activity.packageName)
145155
if (!hasIgnored) {
146-
Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
147-
Uri.parse("package:" + activity.packageName)).let {
156+
Intent(
157+
Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
158+
Uri.parse("package:" + activity.packageName)
159+
).let {
148160
activity.startActivity(it)
149161
}
150162
}

app/src/main/java/cc/chenhe/qqnotifyevo/preference/PreferenceAty.kt

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,22 @@ class PreferenceAty : AppCompatActivity() {
3737
initPreferenceFragment()
3838
} else {
3939
supportFragmentManager.beginTransaction()
40-
.replace(R.id.frameLayout, UpgradingFr())
41-
.commit()
40+
.replace(R.id.frameLayout, UpgradingFr())
41+
.commit()
4242
upgradeReceiver = object : BroadcastReceiver() {
4343
override fun onReceive(ctx: Context, i: Intent?) {
4444
if (i?.action == ACTION_APPLICATION_UPGRADE_COMPLETE) {
45-
LocalBroadcastManager.getInstance(this@PreferenceAty).unregisterReceiver(this)
45+
LocalBroadcastManager.getInstance(this@PreferenceAty)
46+
.unregisterReceiver(this)
4647
upgradeReceiver = null
4748
initPreferenceFragment()
4849
}
4950
}
5051
}
51-
LocalBroadcastManager.getInstance(this).registerReceiver(upgradeReceiver!!,
52-
IntentFilter(ACTION_APPLICATION_UPGRADE_COMPLETE))
52+
LocalBroadcastManager.getInstance(this).registerReceiver(
53+
upgradeReceiver!!,
54+
IntentFilter(ACTION_APPLICATION_UPGRADE_COMPLETE)
55+
)
5356
if (!UpgradeService.isRunningOrPrepared()) {
5457
// 避免极端情况下在注册监听器之前更新完成
5558
initPreferenceFragment()
@@ -72,8 +75,8 @@ class PreferenceAty : AppCompatActivity() {
7275
}
7376
mainPreferenceFr = MainPreferenceFr().also { fr ->
7477
supportFragmentManager.beginTransaction()
75-
.replace(R.id.frameLayout, fr)
76-
.commit()
78+
.replace(R.id.frameLayout, fr)
79+
.commit()
7780
}
7881
}
7982

@@ -87,18 +90,18 @@ class PreferenceAty : AppCompatActivity() {
8790
if (intent?.extras?.getBoolean(EXTRA_NEVO_MULTI_MSG, false) == true) {
8891
NotificationManagerCompat.from(this).cancel(NOTIFY_ID_MULTI_MSG)
8992
AlertDialog.Builder(this)
90-
.setTitle(R.string.tip)
91-
.setMessage(R.string.multi_msg_dialog)
92-
.setNeutralButton(R.string.multi_msg_dialog_neutral, null)
93-
.setPositiveButton(R.string.multi_msg_dialog_positive) { _, _ ->
94-
mainPreferenceFr?.setMode(MODE_LEGACY)
95-
}
96-
.setNegativeButton(R.string.dont_show) { _, _ ->
97-
sendBroadcast(Intent(this, StaticReceiver::class.java).also {
98-
it.action = ACTION_MULTI_MSG_DONT_SHOW
99-
})
100-
}
101-
.show()
93+
.setTitle(R.string.tip)
94+
.setMessage(R.string.multi_msg_dialog)
95+
.setNeutralButton(R.string.multi_msg_dialog_neutral, null)
96+
.setPositiveButton(R.string.multi_msg_dialog_positive) { _, _ ->
97+
mainPreferenceFr?.setMode(MODE_LEGACY)
98+
}
99+
.setNegativeButton(R.string.dont_show) { _, _ ->
100+
sendBroadcast(Intent(this, StaticReceiver::class.java).also {
101+
it.action = ACTION_MULTI_MSG_DONT_SHOW
102+
})
103+
}
104+
.show()
102105
}
103106
}
104107

0 commit comments

Comments
 (0)