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

Refactor generating InfoItemDialog's #7570

Merged
merged 11 commits into from
Feb 26, 2022
Merged

Conversation

TobiGr
Copy link
Member

@TobiGr TobiGr commented Dec 22, 2021

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Description of the changes in your PR

I stumbled on this while doing some other code improvements and did not like the old structure for a few reasons. Most importantly, separation of concerns was neglected and the code was not easy to understand, long and full of duplicate lines.

This PR refactors the way InfoItemDialogs are generated. This is necessary because the old way used the StreamDialogEntry enum for most of the dialogs' content generation process. This required static variables and methods to store the entries which are used for the dialog to be build (See e.g.enabledEntries and methods like generateCommands()). In other words, StreamDialogEntry wasn't an enumeration anymore.

To address this issue, a Builder is introduced for the InfoItemDialog's genration.

A second problem that introduced a structure which was atypical for an enumeration was the usage of non-final attributes within StreamDialogEntry instances. These were needed because the default actions needed to be overriden in some cases.

To address this problem, the StreamDialogEntry enumeration was renamed to StreamDialogDefaultEntry and a new StreamDialogEntry class is used instead.

ToDo

  • Add a few more comments
  • Use consistent names for methods that create the dialogs within the Fragments.
  • Reduce code duplication. Some parts have the same logic which decides which entries are added to the dialog. Maybe we can find a way to generalize this and extract those lines to the Builder.
  • Check why InfoItemDialog does not extend AlertDialog, but contains one.
    Answer: Extending AlertDialog and creating the contentView is a pain.
  • squash commits

Note

I am not happy that we have StreamDialogEntry and StreamDialogDefaultEntry. However, I am not sure if there is a better solution.

APK testing

The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR.

Due diligence

@TobiGr TobiGr added the codequality Improvements to the codebase to improve the code quality label Dec 22, 2021
@TobiGr TobiGr force-pushed the improvement/infoItemDialogBuilder branch 4 times, most recently from 0abd88f to dbc7218 Compare December 27, 2021 15:34
@sonarcloud
Copy link

sonarcloud bot commented Dec 27, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@TobiGr TobiGr marked this pull request as ready for review December 27, 2021 15:46
Copy link
Member

@litetex litetex left a comment

Choose a reason for hiding this comment

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

LGTM, some minor things I found while doing a quick review:

@litetex
Copy link
Member

litetex commented Jan 1, 2022

Did a quick test (searched something and clicked through the long-press dropdown) and almost everything seems to work as expected.
However when I try to mark a video as watched it isn't marked as watched immediately and you have to search the same term again. Not sure if this was so before but I think this should be fixed (maybe in a new issue/PR if it was so before).

@Stypox
Copy link
Member

Stypox commented Jan 7, 2022

However when I try to mark a video as watched it isn't marked as watched immediately and you have to search the same term again. Not sure if this was so before but I think this should be fixed (maybe in a new issue/PR if it was so before).

This never worked for search lists, and after (I think) #7050 it stopped working in the feed fragment, too. Could you look into it? Edit: see #7545

Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

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

Looks mostly good, thank you for this improvement :-)

In other words, StreamDialogEntry wasn't an enumeration anymore.

Maybe the DefaultStreamDialogEntry enum should be removed altogether and its entries should be moved to StreamDialogEntry as public static final StreamDialogEntry fields?

* Custom actions for entries can be set using
* {@link #setAction(StreamDialogDefaultEntry, StreamDialogEntry.StreamDialogEntryAction)}.
*/
public static class Builder {
Copy link
Member

Choose a reason for hiding this comment

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

In the Javadoc I'd explain that it can only be used to show a dialog for StreamInfoItems, not just any InfoItem

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about renaming the whole class to StreamInfoItemDialog to make it clear that the dialog only works with StreamInfoItems currently.
On the other hand, we could create more builders to match the missing InfoItems: channels and playlists. Their held() methods are not overridden in many cases.

@TobiGr TobiGr mentioned this pull request Feb 4, 2022
5 tasks
@TobiGr TobiGr force-pushed the improvement/infoItemDialogBuilder branch from dbc7218 to e5481ba Compare February 18, 2022 22:48
@TobiGr
Copy link
Member Author

TobiGr commented Feb 18, 2022

I rebased this PR. However, I screwed up while doing so. As a result my new commits are trash. Sorry for that.

@TobiGr TobiGr force-pushed the improvement/infoItemDialogBuilder branch from e5481ba to 7c97dc1 Compare February 18, 2022 23:03
Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

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

Almost ready

This commit refactors the way `InfoItemDialog`s are generated. This is necessary because the old way used  the `StreamDialogEntry` enum for most of the dialogs' content generation process. This required static variables and methods to store the entries which are used for the dialog to be build (See e.g.`enabledEntries` and methods like `generateCommands()`). In other words, `StreamDialogEntry` wasn't an enumeration anymore.

To address this issue, a `Builder` is introduced for the `InfoItemDialog`'s genration. The builder also comes with some default entries and and a specific order. Both can be used, but are not enforced. 

A second problem that introduced a structure which was atypical for an enumeration was the usage of non-final attributes within `StreamDialogEntry` instances. These were needed, because the default actions needed to overriden in some cases.

To address this problem, the `StreamDialogEntry` enumeration was renamed to `StreamDialogDefaultEntry` and a new `StreamDialogEntry` class is used instead.
Return this in InfoIrtemDialog.Builder methoods.
Move null checks for InfoIrtemDialog.Builder into constructor.
Fix and add some more docs.
@TobiGr TobiGr force-pushed the improvement/infoItemDialogBuilder branch from 7c97dc1 to ba0f0bc Compare February 20, 2022 19:22
@TobiGr TobiGr force-pushed the improvement/infoItemDialogBuilder branch from ba0f0bc to ee477b2 Compare February 20, 2022 19:26
@sonarcloud
Copy link

sonarcloud bot commented Feb 21, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@litetex litetex merged commit 37517c7 into dev Feb 26, 2022
@litetex litetex deleted the improvement/infoItemDialogBuilder branch February 26, 2022 15:18
@Stypox Stypox mentioned this pull request Apr 16, 2022
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codequality Improvements to the codebase to improve the code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants