-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Conversation
0abd88f
to
dbc7218
Compare
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this 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:
app/src/main/java/org/schabi/newpipe/info_list/InfoItemDialog.java
Outdated
Show resolved
Hide resolved
app/src/main/java/org/schabi/newpipe/info_list/InfoItemDialog.java
Outdated
Show resolved
Hide resolved
Did a quick test (searched something and clicked through the long-press dropdown) and almost everything seems to work as expected. |
|
There was a problem hiding this 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?
app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java
Outdated
Show resolved
Hide resolved
* Custom actions for entries can be set using | ||
* {@link #setAction(StreamDialogDefaultEntry, StreamDialogEntry.StreamDialogEntryAction)}. | ||
*/ | ||
public static class Builder { |
There was a problem hiding this comment.
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 StreamInfoItem
s, not just any InfoItem
There was a problem hiding this comment.
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.
app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/org/schabi/newpipe/info_list/InfoItemDialog.java
Outdated
Show resolved
Hide resolved
app/src/main/java/org/schabi/newpipe/util/StreamDialogDefaultEntry.java
Outdated
Show resolved
Hide resolved
app/src/main/java/org/schabi/newpipe/util/StreamDialogDefaultEntry.java
Outdated
Show resolved
Hide resolved
app/src/main/java/org/schabi/newpipe/util/StreamDialogDefaultEntry.java
Outdated
Show resolved
Hide resolved
app/src/main/java/org/schabi/newpipe/info_list/InfoItemDialog.java
Outdated
Show resolved
Hide resolved
dbc7218
to
e5481ba
Compare
I rebased this PR. However, I screwed up while doing so. As a result my new commits are trash. Sorry for that. |
e5481ba
to
7c97dc1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost ready
app/src/main/java/org/schabi/newpipe/info_list/dialog/StreamDialogEntry.java
Outdated
Show resolved
Hide resolved
app/src/main/java/org/schabi/newpipe/info_list/dialog/StreamDialogEntry.java
Show resolved
Hide resolved
app/src/main/java/org/schabi/newpipe/info_list/dialog/StreamDialogEntry.java
Show resolved
Hide resolved
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.
Improve docs
Return this in InfoIrtemDialog.Builder methoods. Move null checks for InfoIrtemDialog.Builder into constructor. Fix and add some more docs.
7c97dc1
to
ba0f0bc
Compare
ba0f0bc
to
ee477b2
Compare
Kudos, SonarCloud Quality Gate passed! |
What is it?
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
InfoItemDialog
s are generated. This is necessary because the old way used theStreamDialogEntry
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 likegenerateCommands()
). In other words,StreamDialogEntry
wasn't an enumeration anymore.To address this issue, a
Builder
is introduced for theInfoItemDialog
'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 toStreamDialogDefaultEntry
and a newStreamDialogEntry
class is used instead.ToDo
InfoItemDialog
does not extendAlertDialog
, but contains one.Answer: Extending AlertDialog and creating the
contentView
is a pain.Note
I am not happy that we have
StreamDialogEntry
andStreamDialogDefaultEntry
. 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