Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert NotificationsFragment and related code to Kotlin, use the Paging library #3159

Merged
merged 147 commits into from
Mar 10, 2023
Merged

Convert NotificationsFragment and related code to Kotlin, use the Paging library #3159

merged 147 commits into from
Mar 10, 2023

Conversation

nikclayton
Copy link
Contributor

@nikclayton nikclayton commented Jan 10, 2023

"Load more" is gone. When the user opens notifications their position in the list is restored (if the notification still exists) and new/old notifications are fetched in the background as the user scrolls.

If an error occurs during a network operation the user is shown the error, with an opportunity to retry it. If the UI opportunistically showed the operation as succeeding (e.g., try and bookmark a status in airplane mode with the previous code, it will show the bookmark as succeeding) the UI is reset to show the operation did not succeed.

Preference changes that affect the display of the list (e.g., toggling "Show media previews") do not reload the list.

Apart from the Kotlin re-write, the code has been split up in to:

  • NotificationsFragment
  • NotificationsViewModel
  • NotificationsRepository
  • NotificationsPagingSource

This significantly simplifies which code is responsible for what. For example, the Fragment, ViewModel, and Repository do not interact with the Mastodon API (for notifications), that is entirely within the PagingSource.

Fragment communicates actions to ViewModel by sending instances of UiAction. ViewModel communicates state to Fragment through different flows.

Preference changes are encapsulated in ViewModel, and are communicated through the UI state.

With no need for "Load more" support, the distinction between ".Concrete" and ".Placeholder" types is unnecessary, the ".Placeholder" type has been removed, and ".Concrete" merged in to "Notification".

EventHub is not needed in the Fragment. ViewModel still needs it for PreferenceChangedEvent, but in future work I plan to implement a PreferencesRepository that obsoletes it.

Separate ViewHolder classes have been created for all the notification types.

Fixes #2726, #1258

Nik Clayton added 30 commits January 9, 2023 15:48
- Use `lateinit` for `eventhub`, `adapter`, `preferences`, and `scrolllistener`
- Removed override for accountManager, it can be used from the superclass
- Add `?.` where non-nullity could not (yet) be guaranteed
- Remove `?` from type lists where non-nullity is guaranteed
- Explicitly convert lists to mutable where necessary
- Delete unused function `findReplyPosition`
The previous change meant some values are no longer nullable. Remove the
non-null assertions.
- Remove redundant constructor
- Move block outside of `()`
- Access the last value with `.last()`
- Access the last index with `.lastIndex`
- Replace logical-chain with `asRightOrNull` and `?.`
- `.isNotEmpty()`, not `!...isEmpty()`
Does not compile, this is the unchanged output of the "Convert to Kotlin"
function
Nik Clayton and others added 23 commits February 11, 2023 12:21
… 2kt-notifications-fragment

# Conflicts:
#	app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.kt
The popup window:

- Is inconsistent UI
- Requires a custom layout
- Didn't play nicely with viewbinding
# Conflicts:
#	app/src/main/java/com/keylesspalace/tusky/di/ViewModelFactory.kt
#	app/src/main/res/values/strings.xml
# Conflicts:
#	app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java
#	app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java
#	gradle/libs.versions.toml
# Conflicts:
#	app/src/main/java/com/keylesspalace/tusky/TabData.kt
#	app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java
#	app/src/main/res/menu/fragment_notifications.xml
@connyduck connyduck merged commit 4d401c7 into tuskyapp:develop Mar 10, 2023
@nikclayton nikclayton deleted the 2kt-notifications-fragment branch March 10, 2023 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Muting a post does not remove it from timeline
4 participants