Refactor notifications to Kotlin & paging (#4026)

This refactors the NotificationsFragment and related classes to Kotlin &
paging.
While trying to preserve as much of the original behavior as possible,
this adds the following improvements as well:
- The "show notifications filter" preference was added again
- The "load more" button now has a background ripple effect when clicked
- The "legal" report category of Mastodon 4.2 is now supported in report
notifications
- Unknown notifications now display "unknown notification type" instead
of an empty line

Other code quality improvements:
- All views from xml layouts are now referenced via ViewBindings
- the classes responsible for showing system notifications were moved to
a new package `systemnotifications` while the classes from this
refactoring are in `notifications`
- the id of the local Tusky account is now called `tuskyAccountId` in
all places I could find

closes https://github.com/tuskyapp/Tusky/issues/3429

---------

Co-authored-by: Zongle Wang <wangzongler@gmail.com>
This commit is contained in:
Konrad Pozniak 2024-05-03 18:27:10 +02:00 committed by GitHub
commit b2c0b18c8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
121 changed files with 6992 additions and 4654 deletions

View file

@ -20,7 +20,6 @@ import at.connyduck.calladapter.networkresult.NetworkResult
import at.connyduck.calladapter.networkresult.fold
import at.connyduck.calladapter.networkresult.onFailure
import at.connyduck.calladapter.networkresult.onSuccess
import at.connyduck.calladapter.networkresult.runCatching
import com.keylesspalace.tusky.appstore.BlockEvent
import com.keylesspalace.tusky.appstore.EventHub
import com.keylesspalace.tusky.appstore.MuteConversationEvent
@ -29,17 +28,13 @@ import com.keylesspalace.tusky.appstore.PollVoteEvent
import com.keylesspalace.tusky.appstore.StatusChangedEvent
import com.keylesspalace.tusky.appstore.StatusDeletedEvent
import com.keylesspalace.tusky.entity.DeletedStatus
import com.keylesspalace.tusky.entity.Notification
import com.keylesspalace.tusky.entity.Poll
import com.keylesspalace.tusky.entity.Relationship
import com.keylesspalace.tusky.entity.Status
import com.keylesspalace.tusky.entity.Translation
import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.util.Single
import com.keylesspalace.tusky.util.getServerErrorMessage
import java.util.Locale
import javax.inject.Inject
import retrofit2.Response
/**
* Created by charlag on 3/24/18.
@ -66,10 +61,6 @@ class TimelineCases @Inject constructor(
}
}
fun reblogOld(statusId: String, reblog: Boolean): Single<Status> {
return Single { reblog(statusId, reblog) }
}
suspend fun favourite(statusId: String, favourite: Boolean): NetworkResult<Status> {
return if (favourite) {
mastodonApi.favouriteStatus(statusId)
@ -80,10 +71,6 @@ class TimelineCases @Inject constructor(
}
}
fun favouriteOld(statusId: String, favourite: Boolean): Single<Status> {
return Single { favourite(statusId, favourite) }
}
suspend fun bookmark(statusId: String, bookmark: Boolean): NetworkResult<Status> {
return if (bookmark) {
mastodonApi.bookmarkStatus(statusId)
@ -94,10 +81,6 @@ class TimelineCases @Inject constructor(
}
}
fun bookmarkOld(statusId: String, bookmark: Boolean): Single<Status> {
return Single { bookmark(statusId, bookmark) }
}
suspend fun muteConversation(statusId: String, mute: Boolean): NetworkResult<Status> {
return if (mute) {
mastodonApi.muteConversation(statusId)
@ -160,31 +143,6 @@ class TimelineCases @Inject constructor(
}
}
fun voteInPollOld(statusId: String, pollId: String, choices: List<Int>): Single<Poll> {
return Single { voteInPoll(statusId, pollId, choices) }
}
fun acceptFollowRequestOld(accountId: String): Single<Relationship> {
return Single { mastodonApi.authorizeFollowRequest(accountId) }
}
fun rejectFollowRequestOld(accountId: String): Single<Relationship> {
return Single { mastodonApi.rejectFollowRequest(accountId) }
}
fun notificationsOld(
maxId: String?,
sinceId: String?,
limit: Int?,
excludes: Set<Notification.Type>?
): Single<Response<List<Notification>>> {
return Single { runCatching { mastodonApi.notifications(maxId, sinceId, limit, excludes) } }
}
fun clearNotificationsOld(): Single<Unit> {
return Single { mastodonApi.clearNotifications() }
}
suspend fun translate(
statusId: String
): NetworkResult<Translation> {