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

RI: Fetch "Interests" tags from ReaderTagRepository #12490

Merged
merged 22 commits into from
Jul 24, 2020

Conversation

ashiagr
Copy link
Contributor

@ashiagr ashiagr commented Jul 21, 2020

Parent Issue: #12027

This PR

  • Updates ReaderTagRepository to return Interest API results to the Interests VM utilising ReaderRepositoryCommunication and FetchInterestTagsUseCase
  • Handles error

Looking for an early feedback before moving ahead, so marking it as draft.

To Test

Prerequisite - RI FF flag s enabled

  • Launch and go to Reader tab
  • Interests from server are shown

  • Enable Airplane mode
  • Launch and go to Reader tab
  • Error layout is displayed with Retry option
  • Disable Airplane mode
  • Click Retry
  • Error layout is hidden and interests are shown

To test remote request failure error, comment out SuccessWithData response and return RemoteRequestFailure here.


  • While the interests are shown, go to My Site -> Me -> App Settings and change interface language (e.g. Spanish)
  • Return to Reader tab
  • Notice that interests are shown in the selected language (returned from the server).

ToDo

  • Clicking "Comics" interest is not highlighting it 🤷‍♀️, although it enables Done button. Looking into it.
    UPDATE: There are duplicate tags with "Comics" title in the feed. There shouldn't be such a case in the final feed. I'll put a "unique" check to fix it. - 2843b0f
  • I'm looking for a better solution for language change support. I've removed isStarted check so that we can re-request interests from the server for the changed language but it now happens every time we toggle bottom tabs or rotate screen. I'm thinking to compare last and new language in the interests VM for this something like conditional re-request of tags here. - 7ac80c2
  • Do we want to show "Contact Support" on remote request failure? We haven't yet decided on the error layout design.
  • Tests for FetchInterestTagsUseCase not yet added. Will include along with other use cases to save interests and get user tags.

device-2020-07-21-190416

PR submission checklist:

  • I have considered adding unit tests where possible.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Jul 21, 2020

You can trigger optional UI/connected tests for these changes by visiting CircleCI here.

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Jul 21, 2020

You can test the changes on this Pull Request by downloading the APK here.

Comment on lines +31 to +36
eventBusWrapper.register(this)

ReaderUpdateServiceStarter.startService(
contextProvider.getContext(),
EnumSet.of(INTEREST_TAGS)
)
Copy link
Contributor Author

@ashiagr ashiagr Jul 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm registering to event bus inside the use case, I've not seen this practice elsewhere in the code. Let me know if you see any downside.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashiagr - There is similar logic in #12454, but I used init & stop to set up the bus to support multiple requests at the same time. Not sure if you'll need to do that here, but wanted to mention it. Also, in the same PR, I have a ReaderRepositoryDispatchingUseCase that I use for all the repo usecases to set up coroutine context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@malinajirka what do you think? Should we use init & stop pattern in this case? I'll make changes accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this useCase doesn't support parallel request by its nature, I think the current implementation looks good. I don't think we need to change anything.

@@ -2,6 +2,7 @@ package org.wordpress.android.ui.reader.repository

sealed class ReaderRepositoryCommunication {
object Success : ReaderRepositoryCommunication()
data class SuccessWithData<out T>(val data: T) : ReaderRepositoryCommunication()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing interests directly to the VM via SuccessWithData. We might want to keep a single Success state with an optional data param. Lmkwyt.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashiagr - I like this idea for those non-reactive repository situations and I can go with either option. In one situation we check for the class and the other a quick optional check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we'll have to keep just one Success state to avoid else condition in when clause as seen here.

@ashiagr ashiagr requested review from malinajirka and zwarm July 21, 2020 13:30
@ashiagr ashiagr changed the title RI: Fetch "Interests" tags from real API from ReaderTagRepository RI: Fetch "Interests" tags from ReaderTagRepository Jul 21, 2020
private final ReaderTagList mInterestTags;
private final boolean mDidSucceed;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added boolean to detect if request succeeded similar to SearchPostsEnded

Copy link
Contributor

@zwarm zwarm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far. Nice work.

Comment on lines +31 to +36
eventBusWrapper.register(this)

ReaderUpdateServiceStarter.startService(
contextProvider.getContext(),
EnumSet.of(INTEREST_TAGS)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashiagr - There is similar logic in #12454, but I used init & stop to set up the bus to support multiple requests at the same time. Not sure if you'll need to do that here, but wanted to mention it. Also, in the same PR, I have a ReaderRepositoryDispatchingUseCase that I use for all the repo usecases to set up coroutine context.

@@ -2,6 +2,7 @@ package org.wordpress.android.ui.reader.repository

sealed class ReaderRepositoryCommunication {
object Success : ReaderRepositoryCommunication()
data class SuccessWithData<out T>(val data: T) : ReaderRepositoryCommunication()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashiagr - I like this idea for those non-reactive repository situations and I can go with either option. In one situation we check for the class and the other a quick optional check.

Base automatically changed from issue/interests-endpoint-integration to develop July 22, 2020 12:54
@ashiagr ashiagr marked this pull request as ready for review July 22, 2020 13:51
@ashiagr
Copy link
Contributor Author

ashiagr commented Jul 22, 2020

@zwarm , @malinajirka - ready for another look 🙇‍♀️.

Copy link
Contributor

@zwarm zwarm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests pass as expected, nice work. I left one comment, but it won't stop approval. 👍

}
}

@Subscribe(threadMode = ThreadMode.MAIN)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashiagr Just curious if this could be a Background thread. It's been a while since I used GreenRobot, so maybe things have changed, but iirc the post request is not made on the Main thread, so it will thread switch to emit on Main. Or I may be completely off the mark. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to BACKGROUND thread in ad7c6b0.

@ashiagr ashiagr added this to the 15.5 milestone Jul 24, 2020
@zwarm zwarm merged commit 7e20200 into develop Jul 24, 2020
@ashiagr ashiagr modified the milestones: 15.5, 15.4 Jul 24, 2020
@ashiagr ashiagr deleted the issue/pass-interests-api-results-from-repo branch July 24, 2020 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants