-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Replace Volley with Glide in the EditPostSettings fragment #7985
Conversation
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.
@malinajirka I left some comments, but they are a bit nitpicky and more of a discussion type of comments. Let me know what you think!
I also tested the PR and it's working great!
return 0; | ||
} | ||
if (BuildConfig.DEBUG) { | ||
throw new IllegalStateException("Missing switch case."); |
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 think we should just use a lint rule for this. I assume we can't do it right away as there are probably some switch
statements that don't have all the branches, but we could fix them and enable the lint rule afterwards.
Even if this is the approach we decide to take, let's not make it a part of an unrelated PR and instead try to add it for each switch
statement as a single PR.
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.
We actually have this rule already enabled. This switch statement is part of the lint-baseline file, so it doesn't break the build.
I'll remove the if, as you suggested;).
@@ -205,8 +202,19 @@ String getErrorMessage(final Context context, final MediaModel media, final Medi | |||
return context.getString(R.string.error_media_parse_error); | |||
case GENERIC_ERROR: | |||
return context.getString(R.string.error_generic_error); | |||
case EXCEEDS_SITE_SPACE_QUOTA_LIMIT: |
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 am not sure how I feel about adding these missing cases with just null
values. I understand that technically there is no change. However, missing switch cases and specifically having them return null
values have different meanings to me.
I am also not sure whether it makes sense to make it a part of this PR. I really like that you are fixing a bunch of things and I am all for it. I just think it's better to keep the PRs focused if possible (which I fail myself at times). A different approach might have been to have a really small PR that adds Glide to EditPostSettingsFragment
and another one fixing these issues. In that case, I'd more confidently say that we should add proper error messages for the cases you just added.
Just my 2 cents.
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.
The goal here is to have all switch statements with explicitly specified cases. It all derives from Fail ASAP principle
-> when a method expects just certain enum values, it should throw an exception for all the other values (or at least log an error message). We can't just start throwing an exception or logging error messages in a legacy code, since even missing cases might be expected, so explicitly specifying all the cases is all we can do.
The biggest advantage is when we create a new enum value, lint won't let us build the project unless we add handling for the new enum value to all switch statements, which is very convenient.(we need to remove this switch statement from the lint-baseline obviously, but I do that from time to time not in each PR separately)
I am also not sure whether it makes sense to make it a part of this PR.
This is a topic worth discussing with everyone on the team.
Thank for bringing this up @oguzkocer. I want to write a post about both these topics in a near future. Basically one of the reasons why I don't put small refactoring changes in separate PR is that Android Studio warns me about these issues when committing a change, so it's super convenient to fix it right away.
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.
The goal here is to have all switch statements with explicitly specified cases.
Which I agree with you, but I don't see how it has anything to do with a PR titled as Replace Volley with Glide
.
The biggest advantage is when we create a new enum value, lint won't let us build the project unless we add handling for the new enum value to all switch statements, which is very convenient.
Again, I think I wasn't very clear in my comment. I have no arguments against having these missing cases. What I am worried about though is returning null
. As I also tried to explain in my previous comment, having a null
value for these cases means that we specifically want to return null
whereas not having the cases at all means we just made a mistake by not updating this switch case.
I just feel that a better way to fix these issues is to open a separate PR where we return specific error messages for the missing cases. Hope that clears it up!
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.
Which I agree with you, but I don't see how it has anything to do with a PR titled as Replace Volley with Glide.
I'll create a post about this topic. I feel like minor refactoring (without changing behavior) should be part of each commit/PR, even though it's not strictly related to the PR itself.
I just feel that a better way to fix these issues is to open a separate PR where we return specific error messages for the missing cases. Hope that clears it up!
I'm still not sure it's the way we should go. We'd change the behavior by returning specific error message and I don't think it's save to assume that all missing cases are errors -> they might be omitted on purpose, because the author wanted to return null. Explicitly returning null is definitely not ideal, but it's a change which doesn't change the behavior and moves us towards state, where it'll be safe to assume that lint takes care of warning us about all missing cases.
It would definitely be better to take one switch statement at a time and do research whether we can safely add an error message or throw an exception. But this approach would take a lot of time and would be error prone with very little gain. That's the main reason why I decided to start fixing such switch statements by returning a default value.
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 feel like minor refactoring (without changing behavior) should be part of each commit/PR, even though it's not strictly related to the PR itself.
I definitely agree with you. My concern was the change in the meaning and that it was not very relevant to the feature.
We'd change the behavior by returning specific error message and I don't think it's save to assume that all missing cases are errors -> they might be omitted on purpose, because the author wanted to return null
My concern was exactly this, by adding those cases we'd just be changing the meaning of that code from missing cases
to these cases are specifically returning null
.
It would definitely be better to take one switch statement at a time and do research whether we can safely add an error message or throw an exception.
If we are not willing to spend that time, we could at least write a comment in the code explaining why they are currently returning null.
@@ -2132,6 +2132,7 @@ | |||
<string name="plugin_detail_banner_desc">plugin banner</string> | |||
<string name="plugin_detail_logo_desc">plugin logo</string> | |||
<string name="post_cardview_featured_desc">featured image</string> | |||
<string name="post_settings_featured_desc">featured image</string> |
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.
Unless we expect the translations to be different, we should have a string for featured image
and either use it directly or reference it from these two string resources: post_cardview_featured_desc
& post_settings_featured_desc
. From their names, I don't think the translators would interpret them any differently.
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.
Good point:)
@@ -440,6 +422,7 @@ public void onScanCompleted(String path, Uri uri) { | |||
/* | |||
* returns true if the current user has permission to upload new media to the passed site | |||
*/ | |||
@SuppressWarnings("SimplifiableIfStatement") |
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.
This doesn't look like a very complicated if statement, why don't we just simplify it?
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 felt like the comment self-hosted sites don't have capabilities so always return true
won't be so clear, but you are right I guess.
Thank you @oguzkocer ! I've fixed all the issue you've pointed out and I left a comment with my reasoning. However, I'll create a post so we can have a discussion as a team. |
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 good
Fixes #7967
Replaces Volley with Glide in the EditPostSettings.
Adds support for adding animated feature images.
MaxHeight attribute of the ImageView is taken into account - it was ignored before.
To test: