upgrade ktlint plugin to 12.0.3 (#4169)
There are some new rules, I think they mostly make sense, except for the max line length which I had to disable because we are over it in a lot of places. --------- Co-authored-by: Goooler <wangzongler@gmail.com>
This commit is contained in:
parent
33cd6fdb98
commit
5192fb08a5
215 changed files with 2813 additions and 1177 deletions
|
|
@ -14,10 +14,10 @@ import com.keylesspalace.tusky.entity.Notification
|
|||
import com.keylesspalace.tusky.network.MastodonApi
|
||||
import com.keylesspalace.tusky.util.HttpHeaderLink
|
||||
import com.keylesspalace.tusky.util.isLessThan
|
||||
import kotlinx.coroutines.delay
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.min
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
/** Models next/prev links from the "Links" header in an API response */
|
||||
data class Links(val next: String?, val prev: String?) {
|
||||
|
|
@ -55,12 +55,16 @@ class NotificationFetcher @Inject constructor(
|
|||
for (account in accountManager.getAllAccountsOrderedByActive()) {
|
||||
if (account.notificationsEnabled) {
|
||||
try {
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
val notificationManager = context.getSystemService(
|
||||
Context.NOTIFICATION_SERVICE
|
||||
) as NotificationManager
|
||||
|
||||
// Create sorted list of new notifications
|
||||
val notifications = fetchNewNotifications(account)
|
||||
.filter { filterNotification(notificationManager, account, it) }
|
||||
.sortedWith(compareBy({ it.id.length }, { it.id })) // oldest notifications first
|
||||
.sortedWith(
|
||||
compareBy({ it.id.length }, { it.id })
|
||||
) // oldest notifications first
|
||||
.toMutableList()
|
||||
|
||||
// TODO do this before filter above? But one could argue that (for example) a tab badge is also a notification
|
||||
|
|
@ -74,13 +78,18 @@ class NotificationFetcher @Inject constructor(
|
|||
// Err on the side of removing *older* notifications to make room for newer
|
||||
// notifications.
|
||||
val currentAndroidNotifications = notificationManager.activeNotifications
|
||||
.sortedWith(compareBy({ it.tag.length }, { it.tag })) // oldest notifications first
|
||||
.sortedWith(
|
||||
compareBy({ it.tag.length }, { it.tag })
|
||||
) // oldest notifications first
|
||||
|
||||
// Check to see if any notifications need to be removed
|
||||
val toRemove = currentAndroidNotifications.size + notifications.size - MAX_NOTIFICATIONS
|
||||
if (toRemove > 0) {
|
||||
// Prefer to cancel old notifications first
|
||||
currentAndroidNotifications.subList(0, min(toRemove, currentAndroidNotifications.size))
|
||||
currentAndroidNotifications.subList(
|
||||
0,
|
||||
min(toRemove, currentAndroidNotifications.size)
|
||||
)
|
||||
.forEach { notificationManager.cancel(it.tag, it.id) }
|
||||
|
||||
// Still got notifications to remove? Trim the list of new notifications,
|
||||
|
|
@ -106,7 +115,11 @@ class NotificationFetcher @Inject constructor(
|
|||
account,
|
||||
notificationsGroup.value.size == 1
|
||||
)
|
||||
notificationManager.notify(notification.id, account.id.toInt(), androidNotification)
|
||||
notificationManager.notify(
|
||||
notification.id,
|
||||
account.id.toInt(),
|
||||
androidNotification
|
||||
)
|
||||
|
||||
// Android will rate limit / drop notifications if they're posted too
|
||||
// quickly. There is no indication to the user that this happened.
|
||||
|
|
@ -158,7 +171,14 @@ class NotificationFetcher @Inject constructor(
|
|||
Log.d(TAG, "getting notification marker for ${account.fullName}")
|
||||
val remoteMarkerId = fetchMarker(authHeader, account)?.lastReadId ?: "0"
|
||||
val localMarkerId = account.notificationMarkerId
|
||||
val markerId = if (remoteMarkerId.isLessThan(localMarkerId)) localMarkerId else remoteMarkerId
|
||||
val markerId = if (remoteMarkerId.isLessThan(
|
||||
localMarkerId
|
||||
)
|
||||
) {
|
||||
localMarkerId
|
||||
} else {
|
||||
remoteMarkerId
|
||||
}
|
||||
val readingPosition = account.lastNotificationId
|
||||
|
||||
var minId: String? = if (readingPosition.isLessThan(markerId)) markerId else readingPosition
|
||||
|
|
|
|||
|
|
@ -66,7 +66,9 @@ fun showMigrationNoticeIfNecessary(
|
|||
|
||||
Snackbar.make(parent, R.string.tips_push_notification_migration, Snackbar.LENGTH_INDEFINITE)
|
||||
.setAnchorView(anchorView)
|
||||
.setAction(R.string.action_details) { showMigrationExplanationDialog(context, accountManager) }
|
||||
.setAction(
|
||||
R.string.action_details
|
||||
) { showMigrationExplanationDialog(context, accountManager) }
|
||||
.show()
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +77,9 @@ private fun showMigrationExplanationDialog(context: Context, accountManager: Acc
|
|||
if (currentAccountNeedsMigration(accountManager)) {
|
||||
setMessage(R.string.dialog_push_notification_migration)
|
||||
setPositiveButton(R.string.title_migration_relogin) { _, _ ->
|
||||
context.startActivity(LoginActivity.getIntent(context, LoginActivity.MODE_MIGRATION))
|
||||
context.startActivity(
|
||||
LoginActivity.getIntent(context, LoginActivity.MODE_MIGRATION)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
setMessage(R.string.dialog_push_notification_migration_other_accounts)
|
||||
|
|
@ -89,12 +93,21 @@ private fun showMigrationExplanationDialog(context: Context, accountManager: Acc
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun enableUnifiedPushNotificationsForAccount(context: Context, api: MastodonApi, accountManager: AccountManager, account: AccountEntity) {
|
||||
private suspend fun enableUnifiedPushNotificationsForAccount(
|
||||
context: Context,
|
||||
api: MastodonApi,
|
||||
accountManager: AccountManager,
|
||||
account: AccountEntity
|
||||
) {
|
||||
if (isUnifiedPushNotificationEnabledForAccount(account)) {
|
||||
// Already registered, update the subscription to match notification settings
|
||||
updateUnifiedPushSubscription(context, api, accountManager, account)
|
||||
} else {
|
||||
UnifiedPush.registerAppWithDialog(context, account.id.toString(), features = arrayListOf(UnifiedPush.FEATURE_BYTES_MESSAGE))
|
||||
UnifiedPush.registerAppWithDialog(
|
||||
context,
|
||||
account.id.toString(),
|
||||
features = arrayListOf(UnifiedPush.FEATURE_BYTES_MESSAGE)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +129,11 @@ private fun isUnifiedPushAvailable(context: Context): Boolean =
|
|||
fun canEnablePushNotifications(context: Context, accountManager: AccountManager): Boolean =
|
||||
isUnifiedPushAvailable(context) && !anyAccountNeedsMigration(accountManager)
|
||||
|
||||
suspend fun enablePushNotificationsWithFallback(context: Context, api: MastodonApi, accountManager: AccountManager) {
|
||||
suspend fun enablePushNotificationsWithFallback(
|
||||
context: Context,
|
||||
api: MastodonApi,
|
||||
accountManager: AccountManager
|
||||
) {
|
||||
if (!canEnablePushNotifications(context, accountManager)) {
|
||||
// No UP distributors
|
||||
NotificationHelper.enablePullNotifications(context)
|
||||
|
|
@ -151,9 +168,14 @@ fun disableAllNotifications(context: Context, accountManager: AccountManager) {
|
|||
|
||||
private fun buildSubscriptionData(context: Context, account: AccountEntity): Map<String, Boolean> =
|
||||
buildMap {
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
val notificationManager = context.getSystemService(
|
||||
Context.NOTIFICATION_SERVICE
|
||||
) as NotificationManager
|
||||
Notification.Type.visibleTypes.forEach {
|
||||
put("data[alerts][${it.presentation}]", NotificationHelper.filterNotification(notificationManager, account, it))
|
||||
put(
|
||||
"data[alerts][${it.presentation}]",
|
||||
NotificationHelper.filterNotification(notificationManager, account, it)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +218,12 @@ suspend fun registerUnifiedPushEndpoint(
|
|||
}
|
||||
|
||||
// Synchronize the enabled / disabled state of notifications with server-side subscription
|
||||
suspend fun updateUnifiedPushSubscription(context: Context, api: MastodonApi, accountManager: AccountManager, account: AccountEntity) {
|
||||
suspend fun updateUnifiedPushSubscription(
|
||||
context: Context,
|
||||
api: MastodonApi,
|
||||
accountManager: AccountManager,
|
||||
account: AccountEntity
|
||||
) {
|
||||
withContext(Dispatchers.IO) {
|
||||
api.updatePushNotificationSubscription(
|
||||
"Bearer ${account.accessToken}",
|
||||
|
|
@ -211,7 +238,11 @@ suspend fun updateUnifiedPushSubscription(context: Context, api: MastodonApi, ac
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun unregisterUnifiedPushEndpoint(api: MastodonApi, accountManager: AccountManager, account: AccountEntity) {
|
||||
suspend fun unregisterUnifiedPushEndpoint(
|
||||
api: MastodonApi,
|
||||
accountManager: AccountManager,
|
||||
account: AccountEntity
|
||||
) {
|
||||
withContext(Dispatchers.IO) {
|
||||
api.unsubscribePushNotifications("Bearer ${account.accessToken}", account.domain)
|
||||
.onFailure { throwable ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue